25 USART_Type *p_base_reg;
26 USART_SignalEvent_t cb_event;
27 USART_PARITY_Enum parity;
34 const uint8_t *p_tx_data;
41 .b_initialized =
false,
44 .parity = UART_PARITY_NONE,
70 VERIFY_UART_INST_VALID(e_uart);
71 VERIFY_UART_VOIDPTR_IS_NULL(pp_uart);
74 if ( e_uart == eUsart0 )
76 pUart = &customusart0;
79 NVIC_ClearPendingIRQ(USART0_IRQn);
80 NVIC_EnableIRQ(USART0_IRQn);
86 return ( DRV_ERROR_PARAMETER );
89 VERIFY_INIT(pUart->b_initialized);
92 hw_uart_reset(pUart->p_base_reg);
95 hw_uart_write_tx_en(pUart->p_base_reg,
ENABLE);
98 pUart->cb_event = cb_event;
99 pUart->b_block_rx =
true;
100 pUart->b_block_tx =
true;
101 pUart->b_initialized =
true;
113 VERIFY_UART_IS_NULL(p_uart);
115 VERIFY_UART_BASE_VALID(pUart->p_base_reg);
117 VERIFY_UNINIT(pUart->b_initialized);
119 return (pUart->tx_expected);
130void USART0_Exception_Handler(
void )
134 if (customusart0.p_base_reg->STS & USART_STS_RX_FE_Msk)
136 customusart0.p_base_reg->STS_b.RX_FE =
CLEAR;
138 hw_uart_write_rx_int_en(customusart0.p_base_reg,
DISABLE);
139 hw_uart_write_rx_en(customusart0.p_base_reg,
DISABLE);
141 if (customusart0.cb_event != NULL)
143 customusart0.cb_event(UART_EVT_RX_FE);
148 if (customusart0.p_base_reg->STS & USART_STS_RX_FULL_Msk)
152 if ( customusart0.rx_bytes < customusart0.rx_expected )
154 regData = customusart0.p_base_reg->DATA;
157 *customusart0.p_rx_data++ = (uint8_t)regData;
158 customusart0.rx_bytes++;
162 hw_uart_write_rx_int_en(customusart0.p_base_reg,
DISABLE);
163 hw_uart_write_rx_en(customusart0.p_base_reg,
DISABLE);
165 if (customusart0.cb_event != NULL)
167 customusart0.cb_event(UART_EVT_RX_PARITY_ERROR);
171 if ( customusart0.rx_bytes == customusart0.rx_expected )
177 if (customusart0.cb_event != NULL)
179 customusart0.cb_event(UART_EVT_RX_COMPLETE);
185 else if (customusart0.p_base_reg->STS & USART_STS_TX_EMPTY_Msk)
189 if (customusart0.tx_bytes == customusart0.tx_expected)
191 hw_uart_write_tx_int_en(customusart0.p_base_reg,
DISABLE);
193 if (customusart0.cb_event != NULL)
195 customusart0.cb_event(UART_EVT_TX_COMPLETE);
198 else if (customusart0.tx_bytes < customusart0.tx_expected)
200 customusart0.p_base_reg->DATA = customAddParity(&customusart0, (uint8_t)*customusart0.p_tx_data++);
201 customusart0.tx_bytes++;
206 if (customusart0.p_base_reg->STS & USART_STS_RX_OVER_Msk)
208 customusart0.p_base_reg->STS_b.RX_OVER =
CLEAR;
210 if (customusart0.cb_event != NULL)
212 customusart0.cb_event (UART_EVT_RX_OVER);
216 if (customusart0.p_base_reg->STS & USART_STS_TX_IDLE_Msk)
219 if (customusart0.cb_event != NULL)
221 customusart0.cb_event(UART_EVT_TX_IDLE);
224 if (customusart0.p_base_reg->STS & USART_STS_RX_BRK_Msk)
227 if (customusart0.cb_event != NULL)
229 customusart0.cb_event(UART_EVT_RX_BRK);
245void USART1_Exception_Handler(
void )
251 uint8_t computedData = data;
254 if (pUart->parity == UART_PARITY_NONE)
255 return (uint16_t)data;
257 computedData ^= computedData >> 4;
258 computedData ^= computedData >> 2;
259 computedData ^= computedData >> 1;
260 parity = computedData & 1;
261 if (pUart->parity == UART_PARITY_ODD)
262 return ((uint16_t)data | ((uint16_t)(!parity) << 8));
263 else if (pUart->parity == UART_PARITY_EVEN)
264 return ((uint16_t)data | ((uint16_t)(parity) << 8));
282 uint8_t computedData = (uint8_t)data;
283 bool parity = (bool)(data >> 8);
285 if (pUart->parity == UART_PARITY_NONE)
288 computedData ^= computedData >> 4;
289 computedData ^= computedData >> 2;
290 computedData ^= computedData >> 1;
291 if (pUart->parity == UART_PARITY_ODD)
292 return ((
bool)(computedData & 1) == (!parity));
293 else if (pUart->parity == UART_PARITY_EVEN)
294 return ((
bool)(computedData & 1) == parity);
uint32_t customUart_getTxExpected(void *p_uart)
uint32_t customUart_initialize(UsartInstance_Enum e_uart, USART_SignalEvent_t cb_event, void **pp_uart)
bool customCheckParity(usart_device_pt pUart, uint16_t data)
Header file for CustomUart.c.