Rev 3 | Rev 5 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3 | Rev 4 | ||
|---|---|---|---|
| Line 95... | Line 95... | ||
| 95 | inline void |
95 | inline void |
| 96 | EnableSerialRxInterrupt (usart_ctl *instance) |
96 | EnableSerialRxInterrupt (usart_ctl *instance) |
| 97 | { |
97 | { |
| 98 | /* cheat here - this is a macro and I have the same Instance member as the HAL handle, with the same meaning */ |
98 | /* cheat here - this is a macro and I have the same Instance member as the HAL handle, with the same meaning */ |
| 99 | __HAL_UART_ENABLE_IT (instance, UART_IT_RXNE); |
99 | __HAL_UART_ENABLE_IT (instance, UART_IT_RXNE); |
| - | 100 | ||
| 100 | } |
101 | } |
| 101 | 102 | ||
| 102 | /****! |
103 | /****! |
| 103 | * @brief send a character to the serial USART via placing it in the serial buffer |
104 | * @brief send a character to the serial USART via placing it in the serial buffer |
| 104 | * |
105 | * |
| Line 136... | Line 137... | ||
| 136 | __disable_irq (); |
137 | __disable_irq (); |
| 137 | uint32_t rxStatus; // status from USART receiver |
138 | uint32_t rxStatus; // status from USART receiver |
| 138 | 139 | ||
| 139 | rxStatus = instance->Instance->SR;// read the status bits - this resets all the hardware signalling flags |
140 | rxStatus = instance->Instance->SR;// read the status bits - this resets all the hardware signalling flags |
| 140 | 141 | ||
| 141 | if (rxStatus & USART_SR_RXNE) |
142 | if ((rxStatus & USART_SR_RXNE)!= RESET) |
| 142 | { |
143 | { |
| 143 | // no error has occurred... |
144 | // no error has occurred... |
| 144 | uint8_t rxChar = (uint8_t) (instance->Instance->DR & 0xff);// read the bottom 8-bits only |
145 | uint8_t rxChar = (uint8_t) (instance->Instance->DR & 0xff);// read the bottom 8-bits only |
| 145 | 146 | ||
| 146 | if (!instance->rx_usart_buffer_full) |
147 | if (!instance->rx_usart_buffer_full) |
| Line 156... | Line 157... | ||
| 156 | instance->rx_usart_buffer_full = 1; /* buffer overrun */ |
157 | instance->rx_usart_buffer_full = 1; /* buffer overrun */ |
| 157 | } |
158 | } |
| 158 | } |
159 | } |
| 159 | } |
160 | } |
| 160 | /* check for transmitter interrupt : this code is used */ |
161 | /* check for transmitter interrupt : this code is used */ |
| 161 | if ((rxStatus & USART_SR_TXE) != RESET) |
162 | if (instance->tx_usart_running && ((rxStatus & USART_SR_TXE) != RESET)) |
| 162 | { |
163 | { |
| 163 | 164 | ||
| 164 | /* Only enable the transmitter when baud detect has completed or check expired. |
165 | /* Only enable the transmitter when baud detect has completed or check expired. |
| 165 | * and the software is ready for it to be enabled as programming mode is wanting |
166 | * and the software is ready for it to be enabled as programming mode is wanting |
| 166 | * to receive a response and that can get blocked if we're streaming a lot of debug messages*/ |
167 | * to receive a response and that can get blocked if we're streaming a lot of debug messages*/ |
| Line 233... | Line 234... | ||
| 233 | } |
234 | } |
| 234 | 235 | ||
| 235 | /***! |
236 | /***! |
| 236 | * @brief check if tx buffer is empty... |
237 | * @brief check if tx buffer is empty... |
| 237 | */ |
238 | */ |
| 238 | - | ||
| 239 | uint8_t |
239 | uint8_t |
| 240 | TxBufferEmpty (usart_ctl *instance) |
240 | TxBufferEmpty (usart_ctl *instance) |
| 241 | { |
241 | { |
| 242 | return (0 == instance->tx_usart_count); |
242 | return (0 == instance->tx_usart_count ); |
| - | 243 | } |
|
| - | 244 | ||
| - | 245 | /***! |
|
| - | 246 | * @brief wait for transmission to finish |
|
| - | 247 | */ |
|
| - | 248 | ||
| - | 249 | void TxWaitEmpty(usart_ctl *instance) |
|
| - | 250 | { |
|
| - | 251 | while (instance->tx_usart_count || |
|
| - | 252 | (instance->Instance->SR & USART_SR_TC) != RESET) {}; |
|
| 243 | } |
253 | } |
| 244 | 254 | ||
| 245 | /**** |
255 | /**** |
| 246 | * @brief Initialise control structure |
256 | * @brief Initialise control structure |
| 247 | */ |
257 | */ |
| 248 | void |
258 | void |
| 249 | init_usart_ctl (usart_ctl *instance, USART_TypeDef *hardware) |
259 | init_usart_ctl (usart_ctl *instance, USART_TypeDef * usart ) |
| 250 | { |
260 | { |
| - | 261 | ||
| 251 | instance->Instance = hardware; |
262 | instance->Instance = usart; |
| - | 263 | ||
| - | 264 | /* cheat here - this is a macro and I have the same Instance member as the HAL handle, with the same meaning */ |
|
| - | 265 | __HAL_UART_DISABLE_IT (instance, UART_IT_TXE); |
|
| - | 266 | __HAL_UART_DISABLE_IT (instance, UART_IT_RXNE); |
|
| 252 | 267 | ||
| 253 | instance->tx_usart_in_Ptr = 0; |
268 | instance->tx_usart_in_Ptr = 0; |
| 254 | instance->tx_usart_out_Ptr = 0; |
269 | instance->tx_usart_out_Ptr = 0; |
| 255 | instance->tx_usart_running = 0; |
270 | instance->tx_usart_running = 0; |
| 256 | instance->tx_usart_count = 0; |
271 | instance->tx_usart_count = 0; |