@@ -650,6 +650,7 @@ int serial_tx_asynch(serial_t *obj_in, const void *tx, size_t tx_length, uint8_t
650
650
return 0 ;
651
651
}
652
652
653
+ obj -> tx_events = event ;
653
654
obj -> async_handler = (cy_israddress )handler ;
654
655
if (serial_irq_setup_channel (obj ) < 0 ) {
655
656
return 0 ;
@@ -662,17 +663,16 @@ int serial_tx_asynch(serial_t *obj_in, const void *tx, size_t tx_length, uint8_t
662
663
}
663
664
664
665
if (tx_length > 0 ) {
665
- obj -> tx_events = event ;
666
666
obj_in -> tx_buff .buffer = (void * )p_buf ;
667
667
obj_in -> tx_buff .length = tx_length ;
668
668
obj_in -> tx_buff .pos = 0 ;
669
669
obj -> tx_pending = true;
670
670
// Enable interrupts to complete transmission.
671
- Cy_SCB_SetRxInterruptMask (obj -> base , CY_SCB_TX_INTR_LEVEL | CY_SCB_UART_TX_DONE );
671
+ Cy_SCB_SetTxInterruptMask (obj -> base , CY_SCB_TX_INTR_LEVEL | CY_SCB_UART_TX_DONE );
672
672
673
673
} else {
674
674
// Enable interrupt to signal completing of the transmission.
675
- Cy_SCB_SetRxInterruptMask (obj -> base , CY_SCB_UART_TX_DONE );
675
+ Cy_SCB_SetTxInterruptMask (obj -> base , CY_SCB_UART_TX_DONE );
676
676
}
677
677
return tx_length ;
678
678
}
@@ -739,7 +739,7 @@ int serial_irq_handler_asynch(serial_t *obj_in)
739
739
// No more bytes to follow; check to see if we need to signal completion.
740
740
if (obj -> tx_events & SERIAL_EVENT_TX_COMPLETE ) {
741
741
// Disable FIFO interrupt as there are no more bytes to follow.
742
- Cy_SCB_SetRxInterruptMask (obj -> base , CY_SCB_UART_TX_DONE );
742
+ Cy_SCB_SetTxInterruptMask (obj -> base , CY_SCB_UART_TX_DONE );
743
743
} else {
744
744
// Nothing more to do, mark end of transmission.
745
745
serial_finish_tx_asynch (obj );
@@ -770,13 +770,12 @@ int serial_irq_handler_asynch(serial_t *obj_in)
770
770
if (rx_status & CY_SCB_RX_INTR_LEVEL ) {
771
771
uint8_t * ptr = obj_in -> rx_buff .buffer ;
772
772
ptr += obj_in -> rx_buff .pos ;
773
- while (obj_in -> rx_buff .pos < obj_in -> rx_buff .length ) {
773
+ uint32_t fifo_cnt = Cy_SCB_UART_GetNumInRxFifo (obj -> base );
774
+ while ((obj_in -> rx_buff .pos < obj_in -> rx_buff .length ) && fifo_cnt ) {
774
775
uint32_t c = Cy_SCB_UART_Get (obj -> base );
775
- if (c == CY_SCB_UART_RX_NO_DATA ) {
776
- break ;
777
- }
778
776
* ptr ++ = (uint8_t )c ;
779
777
++ (obj_in -> rx_buff .pos );
778
+ -- fifo_cnt ;
780
779
// Check for character match condition.
781
780
if (obj_in -> char_match != SERIAL_RESERVED_CHAR_MATCH ) {
782
781
if (c == obj_in -> char_match ) {
@@ -788,9 +787,13 @@ int serial_irq_handler_asynch(serial_t *obj_in)
788
787
}
789
788
}
790
789
}
790
+ if (obj_in -> rx_buff .pos == obj_in -> rx_buff .length ) {
791
+ cur_events |= SERIAL_EVENT_RX_COMPLETE & obj -> rx_events ;
792
+ }
791
793
}
792
794
793
- if (obj_in -> rx_buff .pos == obj_in -> rx_buff .length ) {
795
+ // Any event should end operation.
796
+ if (cur_events & SERIAL_EVENT_RX_ALL ) {
794
797
serial_finish_rx_asynch (obj );
795
798
}
796
799
0 commit comments