Messages or something else?

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

Messages or something else?

Post by king2 »

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!
User avatar
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?

Post by Giovanni »

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
king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

Re: Messages or something else?

Post by king2 »

Not simple for me.. :(
So, I have one message to send it to thread, and another message to get answer?
User avatar
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?

Post by Giovanni »

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
king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

Re: Messages or something else?

Post by king2 »

Thanks for pointing to right place!
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()'.
User avatar
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?

Post by Giovanni »

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
king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

Re: Messages or something else?

Post by king2 »

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 :)
Post Reply