Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSOC6: Fixes for serial hal driver, asynchronous mode. #9368

Merged
merged 2 commits into from
Jan 24, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions targets/TARGET_Cypress/TARGET_PSOC6/serial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ int serial_tx_asynch(serial_t *obj_in, const void *tx, size_t tx_length, uint8_t
return 0;
}

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

if (tx_length > 0) {
obj->tx_events = event;
obj_in->tx_buff.buffer = (void *)p_buf;
obj_in->tx_buff.length = tx_length;
obj_in->tx_buff.pos = 0;
obj->tx_pending = true;
// Enable interrupts to complete transmission.
Cy_SCB_SetRxInterruptMask(obj->base, CY_SCB_TX_INTR_LEVEL | CY_SCB_UART_TX_DONE);
Cy_SCB_SetTxInterruptMask(obj->base, CY_SCB_TX_INTR_LEVEL | CY_SCB_UART_TX_DONE);

} else {
// Enable interrupt to signal completing of the transmission.
Cy_SCB_SetRxInterruptMask(obj->base, CY_SCB_UART_TX_DONE);
Cy_SCB_SetTxInterruptMask(obj->base, CY_SCB_UART_TX_DONE);
}
return tx_length;
}
Expand Down Expand Up @@ -739,7 +739,7 @@ int serial_irq_handler_asynch(serial_t *obj_in)
// No more bytes to follow; check to see if we need to signal completion.
if (obj->tx_events & SERIAL_EVENT_TX_COMPLETE) {
// Disable FIFO interrupt as there are no more bytes to follow.
Cy_SCB_SetRxInterruptMask(obj->base, CY_SCB_UART_TX_DONE);
Cy_SCB_SetTxInterruptMask(obj->base, CY_SCB_UART_TX_DONE);
} else {
// Nothing more to do, mark end of transmission.
serial_finish_tx_asynch(obj);
Expand Down Expand Up @@ -770,13 +770,12 @@ int serial_irq_handler_asynch(serial_t *obj_in)
if (rx_status & CY_SCB_RX_INTR_LEVEL) {
uint8_t *ptr = obj_in->rx_buff.buffer;
ptr += obj_in->rx_buff.pos;
while (obj_in->rx_buff.pos < obj_in->rx_buff.length) {
uint32_t fifo_cnt = Cy_SCB_UART_GetNumInRxFifo(obj->base);
while ((obj_in->rx_buff.pos < obj_in->rx_buff.length) && fifo_cnt) {
uint32_t c = Cy_SCB_UART_Get(obj->base);
if (c == CY_SCB_UART_RX_NO_DATA) {
break;
}
*ptr++ = (uint8_t)c;
++(obj_in->rx_buff.pos);
--fifo_cnt;
// Check for character match condition.
if (obj_in->char_match != SERIAL_RESERVED_CHAR_MATCH) {
if (c == obj_in->char_match) {
Expand All @@ -788,11 +787,12 @@ int serial_irq_handler_asynch(serial_t *obj_in)
}
}
}
if (obj_in->rx_buff.pos == obj_in->rx_buff.length) {
serial_finish_rx_asynch(obj);
cur_events |= SERIAL_EVENT_RX_COMPLETE & obj->rx_events;
}
}

if (obj_in->rx_buff.pos == obj_in->rx_buff.length) {
serial_finish_rx_asynch(obj);
}

Cy_SCB_ClearRxInterrupt(obj->base, rx_status);

Expand Down