How to use Objects FIFO?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

asdasdasd
Posts: 7
Joined: Tue Feb 09, 2021 12:20 pm
Has thanked: 6 times

How to use Objects FIFO?

Postby asdasdasd » Wed Jul 07, 2021 11:51 am

Hi,
I want to use FIFO object to transfer array data from one thread to another but the data received wrong .

At first I have initialize the FIFO:

Code: Select all

#define FIFO_obj_available 2
union U_g_b{
    GPS_b_msg GPS_b;
    uint8_t data[sizeof(GPS_b_msg)];
}u_msg_send,u_msg_rec;
#define FIFO_OBJ_SIZE sizeof(u_msg_send)
static objects_fifo_t fifo_buffer;
static uint8_t data_buffer[FIFO_obj_available][FIFO_OBJ_SIZE];
static msg_t msg_buffer[FIFO_OBJ_SIZE];

initialize fifo

Code: Select all

 chFifoObjectInit(&fifo_buffer, FIFO_OBJ_SIZE, FIFO_obj_available, data_buffer, msg_buffer);
 

IN send thread:

Code: Select all

u_msg_send.GPS_b.instance++;
chFifoSendObject(&fifo_buffer,u_msg_send.data);

IN rec thread:

Code: Select all

 chFifoReceiveObjectTimeout(&fifo_buffer,(void *)u_msg_rec.data,TIME_INFINITE);
    chprintf(debug_ch, "inst: %u . \n\r",u_msg_rec.GPS_b.instance);


why the data has received wrong?!.
is there any example ?
thanks for any help

asd.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: How to use Objects FIFO?

Postby Giovanni » Wed Jul 07, 2021 5:38 pm

Not sure but objects need to be aligned as structures, you are defining those are uint8_t arrays which could not be aligned correctly. Try defining your messages as structures instead.

There are examples in the OSLIB test suite look into /test/oslib/source/test

Giovanni


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 11 guests