Dear all,
Now I have 1 data like that:
typedef struct _MESSAGE
{
BYTE Type;
BYTE MsgId;
BYTE MsgIndex;
BYTE MsgSize;
} MESSAGE;
MESSAGE data;
How I send and recieve between 2 threads?
Thanks and best regards
send data between 2 threads
Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess
Re: send data between 2 threads
A common way to do this is using a mailbox / message queue. You might want to read this thread from the other day.
~ Tectu
~ Tectu
-
- Posts: 8
- Joined: Tue Sep 25, 2012 4:58 am
Re: send data between 2 threads
Hi,
But when I using maibox : msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t time);
It just support send msg_t = int32_t, but I want send struct, how can I do?
Best regards
But when I using maibox : msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t time);
It just support send msg_t = int32_t, but I want send struct, how can I do?
Best regards
- 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: send data between 2 threads
Hi,
In ChibiOS there are two mechanisms usable for this kind of tasks:
1) Mailboxes as suggested by Tectu.
2) Messages.
The Mailboxes are mono-directional queues of messages, best suited when you just want to send a message and do not wait for reception.
Messages are synchronous instead, you send a message and then the thread wait until the message is processed and an answer returned to the sender.
Giovanni
In ChibiOS there are two mechanisms usable for this kind of tasks:
1) Mailboxes as suggested by Tectu.
2) Messages.
The Mailboxes are mono-directional queues of messages, best suited when you just want to send a message and do not wait for reception.
Messages are synchronous instead, you send a message and then the thread wait until the message is processed and an answer returned to the sender.
Giovanni
- 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: send data between 2 threads
nupagachi85 wrote:Hi,
But when I using maibox : msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t time);
It just support send msg_t = int32_t, but I want send struct, how can I do?
Best regards
I suggest you use messages, this way you can allocate your struct into an automatic variable of the sender. In case you want to use mailboxes you could use two mailboxes:
1) Mailbox 1 is used to store pointers to unused message structures.
2) Mailbox 2 is used to send messages.
The sender takes a structure from #1, fills it and then sends it on #2. The receiver takes the message from #2, processes it and then returns it on #1. You need to pre-fill #1 on initialization.
Giovanni
-
- Posts: 417
- Joined: Tue Dec 21, 2010 10:19 am
- Location: Karlsruhe, Germany
- Been thanked: 1 time
- Contact:
Re: send data between 2 threads
nupagachi85 wrote:Hi,
But when I using maibox : msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t time);
It just support send msg_t = int32_t, but I want send struct, how can I do?
Best regards
Hi nupagachi85,
msg_t is guaranteed to be large enough to contain a pointer. So what you typically do for mailboxes, is to use a memory pool for your struct, and send only a pointer via messages. For synchronous messages, you do not even need the pool.
-
- Posts: 8
- Joined: Tue Sep 25, 2012 4:58 am
Re: send data between 2 threads
thanks for reply.
My app have a data like that. It is a struct. I don't find any example show me do that. I just a Newbie with chibios.
Do you help me a short code how to send and recieve it?
Thanks and best regards
My app have a data like that. It is a struct. I don't find any example show me do that. I just a Newbie with chibios.
Do you help me a short code how to send and recieve it?
Thanks and best regards
Re: send data between 2 threads
Did you take a look at the thread I linked? There is a discussion and another link about a module using this technique.
~ Tectu
~ Tectu
- 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: send data between 2 threads
There is a thread in the development regarding a FatFs wrapper that exchanges messages, you could use that for example.
Giovanni
Giovanni
Re: send data between 2 threads
@Giovanni: I just got in mind that both, the FatFSWrapper and ChibiOS/GFX do use one-way message queues.
~ Tectu
~ Tectu
Who is online
Users browsing this forum: No registered users and 10 guests