Skip to content

Commit 0c6f0e4

Browse files
author
Cruz Monrreal
authored
Merge pull request #9368 from lrusinowicz/psoc6_serial_fixes
PSOC6: Fixes for serial hal driver, asynchronous mode.
2 parents b0b4013 + f09805c commit 0c6f0e4

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

targets/TARGET_Cypress/TARGET_PSOC6/serial_api.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ int serial_tx_asynch(serial_t *obj_in, const void *tx, size_t tx_length, uint8_t
650650
return 0;
651651
}
652652

653+
obj->tx_events = event;
653654
obj->async_handler = (cy_israddress)handler;
654655
if (serial_irq_setup_channel(obj) < 0) {
655656
return 0;
@@ -662,17 +663,16 @@ int serial_tx_asynch(serial_t *obj_in, const void *tx, size_t tx_length, uint8_t
662663
}
663664

664665
if (tx_length > 0) {
665-
obj->tx_events = event;
666666
obj_in->tx_buff.buffer = (void *)p_buf;
667667
obj_in->tx_buff.length = tx_length;
668668
obj_in->tx_buff.pos = 0;
669669
obj->tx_pending = true;
670670
// 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);
672672

673673
} else {
674674
// 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);
676676
}
677677
return tx_length;
678678
}
@@ -739,7 +739,7 @@ int serial_irq_handler_asynch(serial_t *obj_in)
739739
// No more bytes to follow; check to see if we need to signal completion.
740740
if (obj->tx_events & SERIAL_EVENT_TX_COMPLETE) {
741741
// 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);
743743
} else {
744744
// Nothing more to do, mark end of transmission.
745745
serial_finish_tx_asynch(obj);
@@ -770,13 +770,12 @@ int serial_irq_handler_asynch(serial_t *obj_in)
770770
if (rx_status & CY_SCB_RX_INTR_LEVEL) {
771771
uint8_t *ptr = obj_in->rx_buff.buffer;
772772
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) {
774775
uint32_t c = Cy_SCB_UART_Get(obj->base);
775-
if (c == CY_SCB_UART_RX_NO_DATA) {
776-
break;
777-
}
778776
*ptr++ = (uint8_t)c;
779777
++(obj_in->rx_buff.pos);
778+
--fifo_cnt;
780779
// Check for character match condition.
781780
if (obj_in->char_match != SERIAL_RESERVED_CHAR_MATCH) {
782781
if (c == obj_in->char_match) {
@@ -788,9 +787,13 @@ int serial_irq_handler_asynch(serial_t *obj_in)
788787
}
789788
}
790789
}
790+
if (obj_in->rx_buff.pos == obj_in->rx_buff.length) {
791+
cur_events |= SERIAL_EVENT_RX_COMPLETE & obj->rx_events;
792+
}
791793
}
792794

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) {
794797
serial_finish_rx_asynch(obj);
795798
}
796799

0 commit comments

Comments
 (0)