Problem with pointers when using k_fifo


Flavio Arieta <flavioarieta@...>
 

Hi,

I'm having some problems with k_fifo_put() and k_fifo_get() when using the following structure:

typedef struct application_queue_element {
    void *pkt;
    uint8_t type;
} application_queue_element_t;

The type receives 14 and pkt receives the address of a structure type variable defined as:

typedef struct request {
    uint8_t value;
    uint8_t flags;
} request_t;

I tried the following to put the data on the fifo:

application_queue_element_t app_pkt;
request_t dr;
app_pkt.pkt = &dr;
app_pkt.application_protocol_pkt_type = 14;
k_fifo_put(&ctx->recv_queue, &app_pkt);

Then to retrieve the data I made the following:

if (k_fifo_is_empty(&ctx->recv_queue) == 0) {
    application_queue_element_t *app_pkt_temp;
    app_pkt_temp = k_fifo_get(&ctx->recv_queue, K_NO_WAIT);
}

At the end app_pkt_temp have the right value for the app_pkt_temp->type but the wrong address for app_pkt_temp->pkt, which gives me 0x00000000 (should be something like 0x20007744) and therefore wrong values.
As it seems the reference to the dr variable is lost after it was put and then retrieved from the k_fifo.

Am I missing something when addind the data or got something wrong with the data structure?


PS: 1. Before putting the data inside the fifo I verified the app_pkt and it has all the data.
       2. I initialized the fifo, but on another function



Thanks,
Flávio Arieta Netto.

Join users@lists.zephyrproject.org to automatically receive all group messages.