Nut/OS  5.0.5
API Reference
Message Queues

Message Queue Support. More...

Collaboration diagram for Message Queues:

Functions

NUTMSGQNutMsgQCreate (uint8_t bits)
 Allocate a new message que.
int NutMsgQBroadcast (uint8_t id, int param, void *data)
 Send a message to all message ques.
int NutMsgQPost (NUTMSGQ *que, uint8_t id, int param, void *data)
 Send a message to a que and return immediately.
int NutMsgQSend (NUTMSGQ *que, uint8_t id, int param, void *data)
 Send a message to a que and yields so that a waiting thread can act on the message.
int NutMsgQFull (NUTMSGQ *que)
 Checks the state of a que.
HANDLE NutMsgQStartTimer (NUTMSGQ *que, uint32_t ms, int param, void *data, uint8_t flags)
 Starts a periodic or one-shot timer on the given que.
void NutMsgQStopTimer (HANDLE timer)
 Stops a timer.
int NutMsgQGetMessage (NUTMSGQ *que, NUTMSG *msg, uint32_t timeout)
 Gets the next message from the que.
void NutMsgQFlush (NUTMSGQ *que)
 Removes all entries from a que.

Variables

NUTMSGQnutMsgQue
 global list of ques
NUTMSGTMRnutMsgFreeTimers

Detailed Description

Message Queue Support.


Function Documentation

NUTMSGQ* NutMsgQCreate ( uint8_t  bits)

Allocate a new message que.

Parameters:
bitssize of the que in bits
Returns:
Handle of the new que
Note:
que size will be 2^bits

References ASSERT, _NUTMSGQ::mq_mask, _NUTMSGQ::mq_next, NutHeapAllocClear, and nutMsgQue.

int NutMsgQBroadcast ( uint8_t  id,
int  param,
void *  data 
)

Send a message to all message ques.

Parameters:
idthe id of the sent message
paramthe param of the sent message
datathe data of the sent message
Returns:
0 if sent to all ques, < 0 if one or more ques were full

References _NUTMSGQ::mq_next, NutMsgQPost(), and nutMsgQue.

Here is the call graph for this function:

int NutMsgQPost ( NUTMSGQ que,
uint8_t  id,
int  param,
void *  data 
)

Send a message to a que and return immediately.

Parameters:
quethe que to send to
idthe id of the sent message
paramthe param of the sent message
datathe data of the sent message
Returns:
0 if sent, < 0 if the que is full

References _NUTMSG::data, _NUTMSG::id, _NUTMSGQ::mq_mask, _NUTMSGQ::mq_que, _NUTMSGQ::mq_wait, _NUTMSGQ::mq_write, NutEnterCritical, NutEventPostAsync(), NutExitCritical, NutJumpOutCritical, NutMsgQFull(), and _NUTMSG::param.

Referenced by NutMsgQBroadcast(), and NutMsgQSend().

Here is the call graph for this function:

int NutMsgQSend ( NUTMSGQ que,
uint8_t  id,
int  param,
void *  data 
)

Send a message to a que and yields so that a waiting thread can act on the message.

The sending thread should have a lower priority than the receiver thread

Parameters:
quethe que to send to
idthe id of the sent message
paramthe param of the sent message
datathe data of the sent message
Returns:
0 if sent, < 0 if the que is full

References NutMsgQPost(), and NutThreadYield().

Here is the call graph for this function:

int NutMsgQFull ( NUTMSGQ que)

Checks the state of a que.

Returns:
-1 if full

References _NUTMSGQ::mq_mask, _NUTMSGQ::mq_read, and _NUTMSGQ::mq_write.

Referenced by NutMsgQPost().

HANDLE NutMsgQStartTimer ( NUTMSGQ que,
uint32_t  ms,
int  param,
void *  data,
uint8_t  flags 
)

Starts a periodic or one-shot timer on the given que.

Parameters:
quethe que to send to
mstimeout length of the timer
paramthe param of the sent message
datathe data of the sent message
flags0 or TM_ONESHOT
Returns:
HANDLE of the new timer

References ASSERT, _NUTMSGQ::mq_timers, _NUTMSGTMR::mt_data, _NUTMSGTMR::mt_flags, _NUTMSGTMR::mt_handle, _NUTMSGTMR::mt_next, _NUTMSGTMR::mt_param, _NUTMSGTMR::mt_que, NULL, NutHeapAlloc, nutMsgFreeTimers, NutTimerStart(), and TM_ONESHOT.

Here is the call graph for this function:

void NutMsgQStopTimer ( HANDLE  timer)

Stops a timer.

Parameters:
timerHANDLE of the timer to stop
Note:
You must not stop a one shot that has already expired otherwise it *could* have been reused and you will end up stopping another timer

References _NUTMSG::data, _NUTMSG::id, _NUTMSGQ::mq_mask, _NUTMSGQ::mq_que, _NUTMSGQ::mq_read, _NUTMSGQ::mq_write, MSG_NULL, MSG_TIMER, _NUTMSGTMR::mt_handle, _NUTMSGTMR::mt_que, NutEnterCritical, NutExitCritical, and NutTimerStop().

Here is the call graph for this function:

int NutMsgQGetMessage ( NUTMSGQ que,
NUTMSG msg,
uint32_t  timeout 
)

Gets the next message from the que.

Parameters:
quethe que to wait on
msgpointer to memory to return data to
timeouthow long to wait for a message
Returns:
-1 on timeout, 0 if message retreived

References ASSERT, _NUTMSG::data, _NUTMSG::id, _NUTMSGQ::mq_mask, _NUTMSGQ::mq_que, _NUTMSGQ::mq_read, _NUTMSGQ::mq_wait, _NUTMSGQ::mq_write, MSG_TIMER, _NUTMSGTMR::mt_data, _NUTMSGTMR::mt_flags, _NUTMSGTMR::mt_param, NutEnterCritical, NutEventPostAsync(), NutEventWait(), NutExitCritical, NutJumpOutCritical, _NUTMSG::param, and TM_ONESHOT.

Here is the call graph for this function:

void NutMsgQFlush ( NUTMSGQ que)

Removes all entries from a que.

References _NUTMSGQ::mq_read, _NUTMSGQ::mq_wait, _NUTMSGQ::mq_write, NutEnterCritical, and NutExitCritical.


Variable Documentation

global list of ques

Referenced by NutMsgQBroadcast(), and NutMsgQCreate().