73 const XMC_UART_CH_STATUS_FLAG_t uart_event_status_flags[
UART_EVENT_MAX] = {
74 XMC_UART_CH_STATUS_FLAG_SYNCHRONIZATION_BREAK_DETECTED,
75 XMC_UART_CH_STATUS_FLAG_RECEIVER_NOISE_DETECTED,
76 XMC_UART_CH_STATUS_FLAG_FORMAT_ERROR_IN_STOP_BIT_0,
77 XMC_UART_CH_STATUS_FLAG_FORMAT_ERROR_IN_STOP_BIT_1,
78 XMC_UART_CH_STATUS_FLAG_COLLISION_DETECTED
80 const XMC_UART_CH_EVENT_t uart_event_conf_flags[
UART_EVENT_MAX] = {
81 XMC_UART_CH_EVENT_SYNCHRONIZATION_BREAK,
82 XMC_UART_CH_EVENT_RECEIVER_NOISE,
83 XMC_UART_CH_EVENT_FORMAT_ERROR,
84 XMC_UART_CH_EVENT_FORMAT_ERROR,
85 XMC_UART_CH_EVENT_COLLISION
90 #ifdef UART_TX_INTERRUPT_USED
92 void UART_lTransmitHandler(
const UART_t *
const handle);
94 #ifdef UART_RX_INTERRUPT_USED
96 void UART_lReceiveHandler(
const UART_t *
const handle);
98 static void UART_lReconfigureRxFIFO(
const UART_t *
const handle, uint32_t data_size);
100 #ifdef UART_TX_DIRECT_USED
102 static UART_STATUS_t UART_lStartTransmitPolling (
const UART_t *
const handle, uint8_t* data_ptr, uint32_t count);
104 #ifdef UART_RX_DIRECT_USED
106 static UART_STATUS_t UART_lStartReceivePolling (
const UART_t *
const handle, uint8_t* data_ptr, uint32_t count);
109 void UART_lProtocolHandler(
const UART_t *
const handle);
124 DAVE_APP_VERSION_t version;
126 version.major = UART_MAJOR_VERSION;
127 version.minor = UART_MINOR_VERSION;
128 version.patch = UART_PATCH_VERSION;
146 XMC_ASSERT(
"UART_Init : UART APP handle invalid", (((handle != NULL)&&
176 #ifdef UART_TX_INTERRUPT_USED
178 ret_stat = UART_StartTransmitIRQ(handle, data_ptr, count);
181 #ifdef UART_TX_DMA_USED
183 ret_stat = UART_StartTransmitDMA(handle, data_ptr, count);
186 #ifdef UART_TX_DIRECT_USED
188 ret_stat = UART_lStartTransmitPolling(handle, data_ptr, count);
217 #ifdef UART_RX_INTERRUPT_USED
219 ret_stat = UART_StartReceiveIRQ(handle, data_ptr, count);
222 #ifdef UART_RX_DMA_USED
224 ret_stat = UART_StartReceiveDMA(handle, data_ptr, count);
227 #ifdef UART_RX_DIRECT_USED
229 ret_stat = UART_lStartReceivePolling(handle, data_ptr, count);
238 #if (defined UART_TX_INTERRUPT_USED || defined UART_TX_DMA_USED)
253 #ifdef UART_TX_DMA_USED
254 const UART_DMA_CONFIG_t * ptr_dma_config = handle->
config->transmit_dma_config;
255 XMC_DMA_t * ptr_gpdma = handle->
config->global_dma->dma;
258 XMC_ASSERT(
"UART_AbortTransmit: UART APP handle invalid", ((handle != NULL)&&
262 handle->runtime->tx_busy = false;
263 handle->runtime->tx_data = NULL;
265 switch(handle->config->transmit_mode)
267 #ifdef UART_TX_INTERRUPT_USED
273 XMC_USIC_CH_TXFIFO_DisableEvent(handle->
channel,(uint32_t)XMC_USIC_CH_TXFIFO_EVENT_CONF_STANDARD);
274 XMC_USIC_CH_TXFIFO_Flush(handle->
channel);
279 XMC_USIC_CH_DisableEvent(handle->
channel, (uint32_t)XMC_USIC_CH_EVENT_TRANSMIT_BUFFER);
281 XMC_USIC_CH_SetTransmitBufferStatus(handle->
channel, XMC_USIC_CH_TBUF_STATUS_SET_IDLE);
284 #ifdef UART_TX_DMA_USED
287 if (XMC_DMA_CH_IsEnabled(ptr_gpdma, ptr_dma_config->dma_channel))
289 XMC_DMA_CH_Disable(ptr_gpdma, ptr_dma_config->dma_channel);
290 while(XMC_DMA_CH_IsEnabled(ptr_gpdma, ptr_dma_config->dma_channel)==
true)
293 XMC_USIC_CH_DisableEvent(handle->
channel, (uint32_t)XMC_USIC_CH_EVENT_TRANSMIT_BUFFER);
295 XMC_USIC_CH_SetTransmitBufferStatus(handle->
channel, XMC_USIC_CH_TBUF_STATUS_SET_IDLE);
306 #if (defined UART_RX_INTERRUPT_USED || defined UART_RX_DMA_USED)
321 #ifdef UART_RX_DMA_USED
322 const UART_DMA_CONFIG_t * ptr_dma_config = handle->
config->receive_dma_config;
323 XMC_DMA_t * ptr_gpdma = handle->
config->global_dma->dma;
325 XMC_ASSERT(
"UART_AbortReceive: UART APP handle invalid", ((handle != NULL)&&
329 handle->runtime->rx_busy = false;
330 handle->runtime->rx_data = NULL;
331 switch(handle->config->receive_mode)
333 #ifdef UART_RX_INTERRUPT_USED
338 XMC_USIC_CH_RXFIFO_DisableEvent(handle->
channel,
339 ((uint32_t)XMC_USIC_CH_RXFIFO_EVENT_CONF_STANDARD |
340 (uint32_t)XMC_USIC_CH_RXFIFO_EVENT_CONF_ALTERNATE));
344 XMC_UART_CH_DisableEvent(handle->
channel,
345 ((uint32_t)XMC_USIC_CH_EVENT_STANDARD_RECEIVE |
346 (uint32_t)XMC_USIC_CH_EVENT_ALTERNATIVE_RECEIVE));
350 #ifdef UART_RX_DMA_USED
353 if (XMC_DMA_CH_IsEnabled(ptr_gpdma, ptr_dma_config->dma_channel))
355 XMC_DMA_CH_Disable(ptr_gpdma, ptr_dma_config->dma_channel);
356 while(XMC_DMA_CH_IsEnabled(ptr_gpdma, ptr_dma_config->dma_channel)==
true)
359 XMC_UART_CH_DisableEvent(handle->
channel,
360 ((uint32_t)XMC_USIC_CH_EVENT_STANDARD_RECEIVE |
361 (uint32_t)XMC_USIC_CH_EVENT_ALTERNATIVE_RECEIVE));
393 XMC_ASSERT(
"UART_SetBaudrate: UART APP handle invalid", ((handle != NULL)&&
401 XMC_GPIO_SetMode(ptr_tx_conf->
port, ptr_tx_conf->
pin, XMC_GPIO_MODE_INPUT_TRISTATE);
404 if (XMC_UART_CH_Stop(handle->
channel) == XMC_UART_CH_STATUS_OK)
411 XMC_UART_CH_SetSamplePoint(handle->
channel, (uint32_t)(oversampling >> 1U)+1U);
414 XMC_UART_CH_Start(handle->
channel);
418 XMC_GPIO_Init(ptr_tx_conf->
port, ptr_tx_conf->
pin, ptr_tx_conf->
config);
429 #ifdef UART_TX_INTERRUPT_USED
450 UART_STATUS_t UART_StartTransmitIRQ(
const UART_t *
const handle, uint8_t* data_ptr, uint32_t count)
455 XMC_ASSERT(
"UART_StartTransmitIRQ: UART APP handle invalid", ((handle != NULL)&&
461 if (ptr_runtime->
tx_busy ==
false)
464 if ((data_ptr != NULL) && (count > 0U))
467 ptr_runtime->
tx_data = data_ptr;
477 XMC_USIC_CH_TXFIFO_Flush(handle->
channel);
479 XMC_USIC_CH_TXFIFO_EnableEvent(handle->
channel,(uint32_t)XMC_USIC_CH_TXFIFO_EVENT_CONF_STANDARD);
483 XMC_USIC_CH_EnableEvent(handle->
channel, (uint32_t)XMC_USIC_CH_EVENT_TRANSMIT_BUFFER);
499 #ifdef UART_RX_INTERRUPT_USED
522 UART_STATUS_t UART_StartReceiveIRQ(
const UART_t *
const handle, uint8_t* data_ptr, uint32_t count)
527 XMC_ASSERT(
"UART_StartReceiveIRQ: UART APP handle invalid", ((handle != NULL)&&
530 if (handle->config->receive_mode == UART_TRANSFER_MODE_INTERRUPT)
533 if (ptr_runtime->
rx_busy ==
false)
536 if ((data_ptr != NULL) && (count > 0U))
540 ptr_runtime->
rx_data = data_ptr;
549 XMC_USIC_CH_RXFIFO_Flush(handle->
channel);
552 UART_lReconfigureRxFIFO(handle, count);
554 XMC_USIC_CH_RXFIFO_EnableEvent(handle->
channel,
555 (uint32_t)((uint32_t)XMC_USIC_CH_RXFIFO_EVENT_CONF_STANDARD |
556 (uint32_t)XMC_USIC_CH_RXFIFO_EVENT_CONF_ALTERNATE));
560 XMC_USIC_CH_EnableEvent(handle->
channel,
561 (uint32_t)((uint32_t)XMC_USIC_CH_EVENT_STANDARD_RECEIVE | (uint32_t)XMC_USIC_CH_EVENT_ALTERNATIVE_RECEIVE));
575 #ifdef UART_TX_DMA_USED
594 UART_STATUS_t UART_StartTransmitDMA(
const UART_t *
const handle, uint8_t* data_ptr, uint32_t count)
598 const UART_DMA_CONFIG_t * ptr_dma_config = handle->
config->transmit_dma_config;
599 XMC_DMA_t * ptr_gpdma = handle->
config->global_dma->dma;
601 XMC_ASSERT(
"UART_StartTransmitDMA: UART APP handle invalid", (((handle != NULL)&&
607 if (ptr_runtime->
tx_busy ==
false)
610 if ((data_ptr != NULL) && ((count > 0U) &&(count <= UART_DMA_MAXCOUNT)))
613 ptr_runtime->
tx_data = data_ptr;
620 XMC_UART_CH_EnableEvent(handle->
channel, (uint32_t)XMC_UART_CH_EVENT_TRANSMIT_BUFFER);
624 XMC_DMA_CH_SetBlockSize(ptr_gpdma, ptr_dma_config->dma_channel, count);
625 XMC_DMA_CH_SetSourceAddress(ptr_gpdma, ptr_dma_config->dma_channel, (uint32_t)data_ptr);
626 XMC_DMA_CH_SetDestinationAddress(ptr_gpdma, ptr_dma_config->dma_channel,
627 (uint32_t)&(handle->
channel->TBUF[0]));
628 XMC_DMA_CH_Enable(ptr_gpdma, ptr_dma_config->dma_channel);
640 #ifdef UART_RX_DMA_USED
661 UART_STATUS_t UART_StartReceiveDMA(
const UART_t *
const handle, uint8_t* data_ptr, uint32_t count)
665 const UART_DMA_CONFIG_t * ptr_dma_config = handle->
config->receive_dma_config;
666 XMC_DMA_t * ptr_gpdma = handle->
config->global_dma->dma;
668 XMC_ASSERT(
"UART_StartReceiveDMA: UART APP handle invalid", (((handle != NULL)&&
671 if (handle->config->receive_mode == UART_TRANSFER_MODE_DMA)
674 if (ptr_runtime->
rx_busy ==
false)
677 if ((data_ptr != NULL) && ((count > 0U) && (count <= UART_DMA_MAXCOUNT)))
681 ptr_runtime->
rx_data = data_ptr;
686 XMC_USIC_CH_EnableEvent(handle->
channel,
687 (uint32_t)((uint32_t)XMC_USIC_CH_EVENT_STANDARD_RECEIVE | (uint32_t)XMC_USIC_CH_EVENT_ALTERNATIVE_RECEIVE));
691 XMC_DMA_CH_SetBlockSize(ptr_gpdma, ptr_dma_config->dma_channel, count);
692 XMC_DMA_CH_SetSourceAddress(ptr_gpdma, ptr_dma_config->dma_channel, (uint32_t)&(handle->
channel->RBUF));
693 XMC_DMA_CH_SetDestinationAddress(ptr_gpdma, ptr_dma_config->dma_channel, (uint32_t)data_ptr);
694 XMC_DMA_CH_Enable(ptr_gpdma, ptr_dma_config->dma_channel);
706 #ifdef UART_TX_DIRECT_USED
721 static UART_STATUS_t UART_lStartTransmitPolling(
const UART_t *
const handle, uint8_t* data_ptr, uint32_t count)
726 XMC_ASSERT(
"UART_Transmit: UART APP handle invalid", (((handle != NULL)&&
729 if ((data_ptr != NULL) && (count > 0U))
738 XMC_USIC_CH_TXFIFO_Flush(handle->
channel);
741 for (loc_index = 0U; loc_index < count; loc_index++)
748 while (XMC_USIC_CH_TXFIFO_IsFull(handle->
channel) ==
true)
752 XMC_UART_CH_Transmit(handle->
channel, (uint16_t)data_ptr[loc_index]);
758 while (XMC_USIC_CH_TXFIFO_IsEmpty(handle->
channel) ==
false)
770 #ifdef UART_RX_DIRECT_USED
785 static UART_STATUS_t UART_lStartReceivePolling(
const UART_t *
const handle, uint8_t* data_ptr, uint32_t count)
791 XMC_ASSERT(
"UART_Receive: UART APP handle invalid", ((handle != NULL)&&
794 if ((data_ptr != NULL) && (count > 0U))
804 XMC_USIC_CH_RXFIFO_Flush(handle->
channel);
806 for (loc_index = 0U; loc_index < count; loc_index++)
812 while(XMC_USIC_CH_RXFIFO_IsEmpty(handle->
channel) ==
true)
819 loc_status = XMC_UART_CH_GetStatusFlag(handle->
channel);
820 while (!(loc_status & ((uint32_t)XMC_UART_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION |
821 (uint32_t)XMC_UART_CH_STATUS_FLAG_RECEIVE_INDICATION)))
823 loc_status = XMC_UART_CH_GetStatusFlag(handle->
channel);
828 XMC_UART_CH_ClearStatusFlag(handle->
channel,
829 ((uint32_t)XMC_UART_CH_STATUS_FLAG_RECEIVE_INDICATION | (uint32_t)XMC_UART_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION));
831 data_ptr[loc_index] = (uint8_t)XMC_UART_CH_GetReceivedData(handle->
channel);
841 #ifdef UART_TX_INTERRUPT_USED
850 void UART_lTransmitHandler(
const UART_t *
const handle)
860 while (XMC_USIC_CH_TXFIFO_IsFull(handle->
channel) ==
false)
883 if (XMC_USIC_CH_TXFIFO_IsEmpty(handle->
channel) ==
true)
888 XMC_USIC_CH_TXFIFO_DisableEvent(handle->
channel,(uint32_t)XMC_USIC_CH_TXFIFO_EVENT_CONF_STANDARD);
893 XMC_USIC_CH_DisableEvent(handle->
channel, (uint32_t)XMC_USIC_CH_EVENT_TRANSMIT_BUFFER);
897 while (XMC_USIC_CH_GetTransmitBufferStatus(handle->
channel) == XMC_USIC_CH_TBUF_STATUS_BUSY)
905 if (handle->
config->tx_cbhandler != NULL)
908 handle->
config->tx_cbhandler();
915 #ifdef UART_RX_INTERRUPT_USED
924 void UART_lReceiveHandler(
const UART_t *
const handle)
931 while (XMC_USIC_CH_RXFIFO_IsEmpty(handle->
channel) ==
false)
945 XMC_USIC_CH_RXFIFO_DisableEvent(handle->
channel,
946 (uint32_t)((uint32_t)XMC_USIC_CH_RXFIFO_EVENT_CONF_STANDARD |
947 (uint32_t)XMC_USIC_CH_RXFIFO_EVENT_CONF_ALTERNATE));
948 if (handle->
config->rx_cbhandler != NULL)
951 handle->
config->rx_cbhandler();
959 UART_lReconfigureRxFIFO(handle,
977 XMC_USIC_CH_DisableEvent(handle->
channel,
978 (uint32_t)((uint32_t)XMC_USIC_CH_EVENT_ALTERNATIVE_RECEIVE | (uint32_t)XMC_USIC_CH_EVENT_STANDARD_RECEIVE));
980 if (handle->
config->rx_cbhandler != NULL)
983 handle->
config->rx_cbhandler();
999 static void UART_lReconfigureRxFIFO(
const UART_t *
const handle, uint32_t data_size)
1002 uint32_t ret_limit_val = 0U;
1007 if (data_size < fifo_size)
1009 ret_limit_val = (uint32_t)(data_size - 1U);
1013 ret_limit_val = (uint32_t)(fifo_size - 1U);
1016 XMC_USIC_CH_RXFIFO_SetSizeTriggerLimit(handle->
channel,
1021 #ifdef UART_PROTOCOL_EVENT_USED
1030 void UART_lProtocolHandler(
const UART_t *
const handle)
1033 uint32_t psr_status = XMC_UART_CH_GetStatusFlag(handle->
channel);
1036 uint32_t pcr_conf = handle->
channel->PCR_ASCMode;
1050 if ((pcr_conf & (uint32_t)uart_event_conf_flags[loc_index]) &&
1051 (psr_status & (uint32_t)uart_event_status_flags[loc_index]))
1053 XMC_UART_CH_ClearStatusFlag(handle->
channel, (uint32_t)uart_event_status_flags[(uint32_t)loc_index]);
1055 if ((callback_arr[(uint32_t)loc_index] != NULL))
1057 callback_arr[(uint32_t)loc_index]();