I have two threads in my app, one thread communicates with PC, another with device.
When I have received some command from PC, I should ask device about it's firmware version and return this to PC.
I think that message will be more suitable for this, unfortunately, I have not found any examples about messages.
May be, I should use something else for this?
If messages, how to do it right?
Which variables use as "tp" in different functions?
chMsgSend return pointer to data from another thread, so I cannot use it safely (data can be modified by responding thread after it answered)?
Which lock has to be used?
Thanks!
Messages or something else?
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Messages or something else?
You could use a pool of "message objects" of any size and exchange them using messages or mailboxes then return them to the pool when no more needed.
Giovanni
Giovanni
Re: Messages or something else?
Not simple for me.. 
So, I have one message to send it to thread, and another message to get answer?
So, I have one message to send it to thread, and another message to get answer?
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Messages or something else?
No, messages are always bidirectional, there is a message followed by a response, in the test suite there are several examples of use of messages.
Giovanni
Giovanni
Re: Messages or something else?
Thanks for pointing to right place!
But I have a question, I have written test code:
Should I use chSysLockFromIsr() because I using I-class function?
If I uncommect 'lock' lines, it falls with debug_msg = 'SV#6, misplaced @p chSysLockFromIsr()'.
But I have a question, I have written test code:
Code: Select all
//chSysLockFromIsr();
if (chMsgIsPendingI(currp)) {
tp = chMsgWait();
message = chMsgGet(tp);
*(unsigned char *)message = 0x55;
chMsgRelease(tp, message);
}
//chSysUnlockFromIsr();
Should I use chSysLockFromIsr() because I using I-class function?
If I uncommect 'lock' lines, it falls with debug_msg = 'SV#6, misplaced @p chSysLockFromIsr()'.
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Messages or something else?
Messages are not usable in ISRs, I assumed you needed to communicate between 2 threads, if this is the case the use the chSysLock() and chSysUnlock(), why did you use the "FromIsr" variant? "SV#6...." is telling you exactly that.
Note that you need to unlock before calling chMsgWait().
Giovanni
Note that you need to unlock before calling chMsgWait().
Giovanni
Re: Messages or something else?
I have used LockFromIsr because 'I' and the end of called function; I think that I should use chSysLock when calling S-functions and LockFromIsr when calling I-functions.
I was not right
I was not right