Content originally posted in LPCWare by Belias on Wed Jul 02 07:05:49 MST 2014 When using the LPC11U6X ROM API for U(S)ART, is it possible and allowed to do the following (having two different callback functions for rx and tx):
/* UART write finished callback */
static void writeCallback(uint32_t err_code, uint32_t n) {
if (err_code != LPC_OK) {
errorUART();
}
(*tx_done_handler)();
}
/* UART read finished callback */
static void readCallback(uint32_t err_code, uint32_t n) {
if (err_code != LPC_OK) {
errorUART();
}
(*rx_done_handler)();
}
void send_BT_UART(const char *send_data, uint32_t length) {
UART_PARAM_T param;
param.buffer = (uint8_t *) send_data;
param.size = length;
/* Interrupt mode, do not append CR/LF to sent data */
param.transfer_mode = TX_MODE_BUF_EMPTY;
param.driver_mode = DRIVER_MODE_INTERRUPT;
/* Setup the transmit callback, this will get called when the
transfer is complete */
param.callback_func_pt = (UART_CALLBK_T) writeCallback;
if (LPC_UARTND_API->uart_put_line(uartHandle, ¶m)) {
errorUART();
}
}
void recv_BT_UART(char *receive_buffer, uint32_t length) {
UART_PARAM_T param;
param.buffer = (uint8_t *) receive_buffer;
param.size = length;
/* Receive data up to the CR/LF character in polling mode. Will
truncate at length if too long.*/
param.transfer_mode = RX_MODE_BUF_FULL;
param.driver_mode = DRIVER_MODE_INTERRUPT;
/* Setup the receive callback, this will get called when the
transfer is complete */
param.callback_func_pt = (UART_CALLBK_T) readCallback;
if (LPC_UARTND_API->uart_get_line(uartHandle, ¶m)) {
errorUART();
}
}
And calling send_BT_UART() and recv_BT_UART() before the callback strikes?
send_BT_UART(...)
// Do not wait for callback
recv_BT_UART(...)
I think that it might be possible that when calling LPC_UARTND_API->uart_get_line that the callback which send_BT_UART() sets gets overwritten by recv_BT_UART(). Is this true? Is there a workaround, that when using a single callback I can find out if it originates from an rx or an tx operation?