Pumpkin, Inc.

Pumpkin User Forums

messages and responses

For issues specific to Microchip's PICmicro® MCUs, including compilers (e.g. HI-TECH PICC & PICC-18, Microchip MPLAB®-C18) and IDEs (e.g. Microchip MPLAB®).

messages and responses

Postby kamyip » Thu May 27, 2004 8:39 am

Hi Andrew,

I'm into a new project now that is some sort of control system. The control system will on an ad-hoc basis rx sensor information from external source through a bus system.

I'm thinking of an interrupt routines that will rx these info as needed and put a time stamp on it then put it in a queue. The controller will react on it as required.

What is the recommended way of doing the above using Salvo? The guarantee responce spec time is 0.5s.

over2u :-)

kamyip
 
Posts: 46
Joined: Mon Apr 15, 2002 11:00 pm

Re: messages and responses

Postby aek » Thu May 27, 2004 9:41 am

0.5s is an eternity ...

Well, a message queue is well-suited to what you want to do, since you need to pass information on more than one thing (timestamp and value) to a waiting task.

The important thing about messages and message queues in Salvo is to remember that when signaling a message or message queue, only the message is passed to the waiting task.

If, for example, you used message queues, and you called OSSignalMsgQ() twice within 0.5s (and the data changed between the first and second signaling), and the task successfully waited the message after the second signaling, when it dereferenced the message pointer to extract the data, it would get the same data (the second "data set") both times.

Why? Because the act of signaling a message or message queue does not also save what's pointed to by the message pointer in some sort of buffer. If it did, it would take an indeterminate and potentially huge amount of data.

So, what you probably want to do is create a buffer for the actual data (structs) that you get via the ISR. Put a struct into the buffer and call OSSignalMsgQ() with a pointer to the buffer element. In the task that calls OS_WaitMsgQ(), after you dereference the pointer and extract the data, remove that struct from your buffer.

IOW, if you want "data persistence" when passing messages or message queues, you need to ensure that the data is still in the form that it was in when the message was signaled. You can do that by passing consts (see the example in the Salvo User FAQ) as messages, or by managing your own buffers when using Salvo message queues.

Now, I'll point out that since 0.5s is incredibly long, you could probably get by just fine with something even simpler, like just using a binSem to tell the waiting task that new data has arrived. The only way you could "lose" data would be if it took 0.5s between when the data arrived and when the task successfully waited the binSem via OS_WaitBinSem(). In a scheme like this, you only get "the last" data when you successfully wait the binSem. If you can't afford to ever miss data, then you need to buffer the incoming data, and then use some sort of event to alert the waiting task that data is available. You can do this with message queues or sems, since both event types can store the fact that multiple events have happened. BinSems and messages can't do that ...

Make sense?

Keep in mind that the need to buffer data in these examples is because of the approach Salvo takes -- namely, to use as little dedicated RAM as possible. Some much bigger OS'es can buffer everything automatically for you. On a PIC, of course, there just isn't enough memory for that sort of thing, so it's up to the programmer to implement an efficient memory-buffering scheme where needed.

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm

Re: messages and responses

Postby kamyip » Fri May 28, 2004 5:46 am

Ok, I think msg queue is the way to go. I'll try it out....


thanks

kamyip
 
Posts: 46
Joined: Mon Apr 15, 2002 11:00 pm


Return to PICmicro MCUs

Who is online

Users browsing this forum: No registered users and 1 guest

cron