Message Queues
[Application Candies]

Collaboration diagram for Message Queues:

Detailed Description

Message Queue Support.


Functions

NUTMSGQNutMsgQCreate (u_char bits)
 Allocate a new message que.
int NutMsgQBroadcast (u_char id, int param, void *data)
 Send a message to all message ques.
int NutMsgQPost (NUTMSGQ *que, u_char id, int param, void *data)
 Send a message to a que and return immediately.
int NutMsgQSend (NUTMSGQ *que, u_char 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, u_long ms, int param, void *data, u_char 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, u_long 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


Function Documentation

NUTMSGQ* NutMsgQCreate ( u_char  bits  ) 

Allocate a new message que.

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

Definition at line 96 of file msg.c.

References ASSERT, _NUTMSGQ::mq_mask, _NUTMSGQ::mq_next, and NutHeapAllocClear().

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

Send a message to all message ques.

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

Definition at line 129 of file msg.c.

References _NUTMSGQ::mq_next, and NutMsgQPost().

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

Send a message to a que and return immediately.

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

Definition at line 154 of file msg.c.

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().

int NutMsgQSend ( NUTMSGQ que,
u_char  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:
que the que to send to
id the id of the sent message
param the param of the sent message
data the data of the sent message
Returns:
0 if sent, < 0 if the que is full

Definition at line 194 of file msg.c.

References NutMsgQPost(), and NutThreadYield().

int NutMsgQFull ( NUTMSGQ que  ) 

Checks the state of a que.

Returns:
-1 if full

Definition at line 208 of file msg.c.

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

Referenced by NutMsgQPost().

HANDLE NutMsgQStartTimer ( NUTMSGQ que,
u_long  ms,
int  param,
void *  data,
u_char  flags 
)

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

Parameters:
que the que to send to
ms timeout length of the timer
param the param of the sent message
data the data of the sent message
flags 0 or TM_ONESHOT
Returns:
HANDLE of the new timer

Definition at line 250 of file msg.c.

References ASSERT, _NUTMSGQ::mq_timers, NutHeapAlloc(), nutMsgFreeTimers, NutTimerStart(), and TM_ONESHOT.

void NutMsgQStopTimer ( HANDLE  timer  ) 

Stops a timer.

Parameters:
timer HANDLE 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

Definition at line 302 of file msg.c.

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

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

Gets the next message from the que.

Parameters:
que the que to wait on
msg pointer to memory to return data to
timeout how long to wait for a message
Returns:
-1 on timeout, 0 if message retreived

Definition at line 342 of file msg.c.

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

void NutMsgQFlush ( NUTMSGQ que  ) 

Removes all entries from a que.

Definition at line 380 of file msg.c.

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


Variable Documentation

global list of ques

Definition at line 83 of file msg.c.

Definition at line 85 of file msg.c.

Referenced by NutMsgQStartTimer().


© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/