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.


Luiz Augusto von Dentz
 

Hi Flavio,

On Wed, Jun 28, 2017 at 2:42 PM, Flavio Arieta <flavioarieta@gmail.com> wrote:
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;
k_fifo/k_queue do store their list nodes in the elements you push to
it, so you need something like this:

typedef struct application_queue_element {
void *_reserved; /* Used by k_fifo implementation. */
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.

_______________________________________________
Zephyr-users mailing list
Zephyr-users@lists.zephyrproject.org
https://lists.zephyrproject.org/mailman/listinfo/zephyr-users


--
Luiz Augusto von Dentz


Flavio Arieta <flavioarieta@...>
 

First, I'm sorry for the late reply.

Thanks that solved my problem, I've read the manual saying about the OS reserved space on queue elements but completely forgot about it.



2017-06-28 8:50 GMT-03:00 Luiz Augusto von Dentz <luiz.dentz@...>:
Hi Flavio,

On Wed, Jun 28, 2017 at 2:42 PM, Flavio Arieta <flavioarieta@...> wrote:
> 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;

k_fifo/k_queue do store their list nodes in the elements you push to
it, so you need something like this:

typedef struct application_queue_element {
     void *_reserved; /* Used by k_fifo implementation. */
     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.
>
> _______________________________________________
> Zephyr-users mailing list
> Zephyr-users@lists.zephyrproject.org
> https://lists.zephyrproject.org/mailman/listinfo/zephyr-users
>



--
Luiz Augusto von Dentz



Kind regards,
Flávio Arieta Netto.