I am using UART on the Fanstel BLG840F to communicate from the 9160 to the 52840. So far I have successfully been able to communicate from the 52840 to the 9160 but have not been able to send UART messages back from the 9160 to the 52840. I am using shared UART functions between the boards with a single function to handle sending:
int uart_send(struct uart_data_t *uart_data)
{
int status = uart_tx(device_uart, uart_data->data, uart_data->length, SYS_FOREVER_MS);
if (status != 0)
{
printk("uart_tx ( error: %d )\n", status);
// Add to tx queue to try and process / send later ...
k_fifo_put(&fifo_uart_tx_data, uart_data);
}
printk("data sent: %s \n", uart_data);
return status;
}
and a registered event handler:
static void on_uart_event(const struct device *dev, struct uart_event *evt, void *user_data)
{
struct uart_data_t *uart_data;
static uint8_t *aborted_buf;
static size_t aborted_len;
switch (evt->type)
{
//put this in ifdef block
case UART_RX_RDY:
{
printk("UART_RX_RDY\n");
uart_data = CONTAINER_OF(evt->data.rx.buf, struct uart_data_t, data); // where does third parameter data come from?
printk("uart_rx called with data: %s", uart_data->data);
hive_uart_queue_rx_data_buffer(uart_data);
uart_rx_disable(device_uart);
break;
}
case UART_RX_DISABLED:
{
printk("UART_RX_DISABLED\n");
start_receiving();
break;
}
case UART_RX_BUF_REQUEST:
{
printk("UART_RX_BUF_REQUEST\n");
struct uart_data_t *uart_data = hive_uart_allocate_data_buffer();
if (uart_data == NULL)
{
break;
}
uart_rx_buf_rsp(device_uart, uart_data->data, sizeof(uart_data->data));
break;
}
case UART_RX_BUF_RELEASED:
{
printk("UART_RX_BUF_RELEASED\n");
uart_data = CONTAINER_OF(evt->data.rx_buf.buf, struct uart_data_t, data);
k_free(uart_data);
break;
}
case UART_TX_DONE:
{
printk("UART_TX_DONE\n");
if ((evt->data.tx.len == 0) || (!evt->data.tx.buf))
{
return;
}
if (aborted_buf)
{
uart_data = CONTAINER_OF(aborted_buf, struct uart_data_t, data);
aborted_buf = NULL;
aborted_len = 0;
}
else
{
uart_data = CONTAINER_OF(evt->data.tx.buf, struct uart_data_t, data);
}
k_free(uart_data);
// See if there's anything waiting in the queue ...
uart_data = k_fifo_get(&fifo_uart_tx_data, K_NO_WAIT);
if (!uart_data)
{
return;
}
if (uart_tx(device_uart, uart_data->data, uart_data->length, SYS_FOREVER_MS))
{
printk("(UART_TX_DONE) Failed to send data over UART\n");
// Add back to queue to try again ...
k_fifo_put(&fifo_uart_tx_data, uart_data);
}
break;
}
case UART_TX_ABORTED:
{
if (!aborted_buf)
{
aborted_buf = (uint8_t *)evt->data.tx.buf;
}
aborted_len += evt->data.tx.len;
uart_data = CONTAINER_OF(aborted_buf, struct uart_data_t, data);
if (uart_tx(device_uart, &uart_data->data[aborted_len], uart_data->length - aborted_len, SYS_FOREVER_MS))
{
printk("(UART_TX_ABORTED) Failed to send data over UART\n");
// Add to queue to try again later ...
k_fifo_put(&fifo_uart_tx_data, uart_data);
}
break;
}
default:
{
printk("UART event received: %d\n", evt->type);
break;
}
}
}
Calling the UART send function on the 52840 triggers the UART_RX_RDY case correctly on the 9160, but calling the UART send function on the 9160 does not trigger the UART_RX_RDY on the 52840. Does each board need a separate event handler and separate UART function or can they be shared in this way and I have setup something on the 9160 side incorrectly?
Thanks
