Messages are sent in the form of generic pointers to memory. TiROS handles these message pointers in an opaque manner and does not care what they point to. It is important to note that the maximum size of the message queue has to be known when the message queue is intialized. It cannot be resized on the fly. A message server can wait on a message queue or poll it (with the O_NONBLOCKING option). A message client can send a message on the queue which will unblock any waiting server. If multiple tasks are waiting on the same message queue, the one with the highest priority will be unblocked first.
NOTE: A custom type mqind_t is used for the queue length. This is of type unsigned integer. By default, it is an 8-bit integer (max val of 255). This can be overridden (see tr_types.h).
NOTE: Always initialize before use.
#define TST_QSZ 4 osword_t tst_Q[msgQ_MEMSZ(TST_QSZ)]; // Previously initialized void task1(void *dummy) { int8_t rc; osptr_t rx_val; while(1) { rc = msgQ_recv( (msgQ_t*)tst_Q, 0, 0, &rx_val); if (rc == SUCCESS) { do_something(rx_val); } } } void task2(void *dummy) { int8_t rc; while(1) { rc = msgQ_send( (msgQ_t*)tst_Q, 7); // Send 7 to task1 } }
Defines | |
#define | msgQ_MEMSZ(qlen) |
Functions | |
void | msgQ_init (msgQ_t *m, mqind_t qlen) |
mqind_t | msgQ_count (msgQ_t *m) |
int8_t | msgQ_send (msgQ_t *m, osptr_t tx_value) |
int8_t | msgQ_recv (msgQ_t *m, const trtime_t *timeout, uint8_t options, osptr_t *rx_value) |
#define msgQ_MEMSZ | ( | qlen | ) |
Initialize a message queue.
Calling Context:
m | Pointer to message queue | |
qlen | Length of the queue. NOTE: The queue memory is contained in the msgQ structure. It is EXTREMELY IMPORTANT that the qlen argument to this call be less than or equal to the length of the message queue that was used as an argument for msgQ_MEMSZ( ). Failing to follow this rule will result in buffer overflows. |
msgQ_t *m; qlen = 10; osword_t dummy[ msgQ_MEMSZ(qlen)]; m = (msgQ_t *) dummy; msgQ_init(m, qlen);
The number of messages in the queue.
Calling Context:
Note: The message queue must be initialized before this call, else the return value is meaningless
m | Pointer to the message queue |
Post a message to the queue.
Calling Context:
In the current implementation, if the queue is full, an error is returned. The task is not allowed to block here. This may be changed in the future.
m | Pointer to message queue | |
tx_value | The value to be added to the queue. |
Wait for message.
Calling Context:
m | Pointer to message queue | |
timeout | Timeout. This can be 0 for infinite timeout. | |
options | [O_NONBLOCKING | O_RELATIVE_TIME ]. | |
[out] | rx_value | Pointer to memory where the message should be stored. |