Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

About Queue library (SDK 17.1.0)

Hi, Nordic

Recently, I'm experimenting with the queue library.

I found some strange problems:

1. When the data types of my data structure members are not unique, using queue will cause the whole system to crash without even error codes

typedef struct {
  bool flag;
  uint8_t data1;
  uint32_t data2;
  uint8_t data3;
  uint8_t data4;
  uint8_t data5;
  uint8_t data6;
} data_t;

NRF_QUEUE_DEF(data_t, m_data_queue, 255*sizeof(data_t), NRF_QUEUE_MODE_NO_OVERFLOW);

data_t test_data;

test_data.flag = true;
test_data.data1 = 0x01;
test_data.data2 = 0xAABBCC;
test_data.data3 = 0x03;
test_data.data4 = 0x04;
test_data.data5 = 0x05;
test_data.data6 = 0x06;

ret = nrf_queue_write(&m_data_queue, &test_data, sizeof(test_data));
APP_ERROR_CHECK(err_code);

data_t data_read;

ret = nrf_queue_read(&m_data_queue, &data_read, sizeof(data_read));
APP_ERROR_CHECK(err_code);

The whole system crashed before the program even performed error checking for queue writes

2. So I modified it according to other examples, as follows

typedef struct {
 uint8_t data[9];
} data_t;

NRF_QUEUE_DEF(uint8_t, m_data_queue, 255*sizeof(data_t), NRF_QUEUE_MODE_NO_OVERFLOW);

data_t test_data;

test_data.data[0] = true;
test_data.data[1] = 0x01;
test_data.data[2] = 0xAA
test_data.data[3] = 0xBB;
test_data.data[4] = 0xCC;
test_data.data[5] = 0x03;
test_data.data[6] = 0x04;
test_data.data[7] = 0x05;
test_data.data[8] = 0x06;

ret = nrf_queue_write(&m_data_queue, &test_data.data, sizeof(test_data));
APP_ERROR_CHECK(err_code);

data_t data_read;

ret = nrf_queue_read(&m_data_queue, &data_read.data, sizeof(data_read));
APP_ERROR_CHECK(err_code);

My questions are as follows:

In 1, do I have any misunderstandings? If so, please point it out!!!

In 2, can I change the data type in NRF_QUEUE_DEF from uint8_t to data_t?

In 2, I have 255 groups of data. What should I do if I want to take the 3rd to 5th bytes (0xaabbcc) in each group of data as a condition for overwriting the data content of the queue? Is it necessary to perform queue reading to read all the contents in the queue, open up a space to compare each group of data, and then write all the updated contents to the queue again? Is there a more elegant way, such as specifying the write location of the queue or other ways?

Regards,

June6

Related