Hey,
I get the following errors when running my application and I am not sure how to debug this (The nrf thread viewer is empty when I start a debug session of my application).
The error started to occur, when I introduced a k_work item to offload the translation of received uart data as well as a K_MSGQ to communicate said data to my main loop. For uart I used 'uart_callback_set' to receive uart events.
The situation is something like the following:
sensor.h:
struct location_data { int64_t unix_time_ms; double longitude; double latitude; int source_mode; }; extern struct k_msgq gnss_message_queue;
sensor.c:
K_MSGQ_DEFINE(gnss_message_queue, sizeof(struct location_data), 4, 1); static uint8_t rx_buf[600]; struct uart_work_data { struct k_work work; uint8_t *buffer; size_t data_len; } w_data; void work_function(char* c, size_t data_len){ struct location_data data; translate_msg(c, data_len, &data); k_msgq_put(&gnss_message_queue, &data, K_MSEC(50)); } static void uart_work_handler(struct k_work *item) { struct uart_work_data *work_data = CONTAINER_OF(item, struct uart_work_data, work); work_function(work_data->buffer, work_data->data_len); } static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data) { switch (evt->type) { case UART_RX_RDY: uint8_t buffer[600]; size_t buffer_size = sizeof(buffer); size_t data_len = evt->data.rx.len; size_t offset = evt->data.rx.offset; memcpy(buffer, &evt->data.rx.buf[offset], data_len); w_data.buffer = buffer; w_data.data_len = data_len; k_work_submit(&w_data.work); break; case UART_RX_DISABLED: uart_rx_enable(dev, rx_buf, sizeof(rx_buf), SYS_FOREVER_US); break; } }
and the main.c:
#include "sensor.h" int main(void){ k_work_init(&w_data.work, uart_work_handler); struct location_data data; while(1) { if(k_msgq_get(&gnss_message_queue, &data, K_MSEC(50))) return; do_something(data); } }
Any help would be appreciated