...
Description
Creates a message queue. A message queue allows tasks or ISRs to send pointer-sized variables (messages) to one or more tasks. The meaning of the messages sent are application specific.
Files
os.h/os_q.c
Prototype
Code Block |
---|
void OSQCreate (OS_Q *p_q,
CPU_CHAR *p_name,
OS_MSG_QTY max_qty,
OS_ERR *p_err) |
Arguments
p_q
is a pointer to the message queue control block. It is assumed that storage for the message queue will be allocated in the application. The user will need to declare a “global” variable as follows, and pass a pointer to this variable to OSQCreate()
:
...
OS_Q
...
MyMsgQ;
...
p_name
is a pointer to an ASCII string used to name the message queue. The name can be displayed by debuggers or µC/Probe.
Anchor
msg_qty
indicates the maximum size of the message queue (must be non-zero). If the user intends to not limit the size of the queue, simply pass a very large number. Of course, if there are not enough OS_MSGs
in the pool of OS_MSGs
, the post call (i.e., OSQPost()
) will simply fail and an error code will indicate that there are no more OS_MSGs
to use.
...
p_err
anchor
is a pointer to a variable that is used to hold an error code:
...
class | WebWorks_Indent_1 |
---|
...
OS_ERR_NONE
...
class | WebWorks_Indent_2 |
---|
...
If the call is successful and the mutex has been created.
...
class | WebWorks_Indent_1 |
---|
...
OS_ERR_CREATE_ISR
...
class | WebWorks_Indent_2 |
---|
...
If OS_CFG_CALLED_FROM_ISR_CHK_EN
set to
...
DEF_ENABLED
in os_cfg.h
: if attempting to create the message queue from an ISR.
...
class | WebWorks_Indent_1 |
---|
...
OS_ERR_ILLEGAL_CREATE_RUN_TIME
If OS_SAFETY_CRITICAL_IEC61508
is defined: you called this after calling OSStart()
and thus you are no longer allowed to create additional kernel objects.
OS_ERR_OBJ_PTR_NULL
...
class | WebWorks_Indent_2 |
---|
...
If OS_CFG_ARG_CHK_EN
is set to
...
DEF_ENABLED
in os_cfg.h
: if p_q
is a NULL
pointer.
...
class | WebWorks_Indent_1 |
---|
...
OS_ERR_Q_SIZE
...
class | WebWorks_Indent_2 |
---|
...
If OS_CFG_ARG_CHK_EN
is set to
...
DEF_ENABLED
in os_cfg.h
: if the size specified is 0.
...
Returned Value
...
class | WebWorks_Indent_1 |
---|
...
None
Required Configuration
OS_
...
CFG_
...
class | WebWorks_Indent_2 |
---|
...
Anchor
Q_EN
must be enabled in os_cfg.h
. Refer to µC-OS-III Configuration Manual.Callers
Application.
Notes/Warnings
- Queues must be created before they are used.
...
...
Example Usage
...
Code Block |
---|
...
HTML Table | ||
---|---|---|
summary | ||
class | Code_Listing | |
Table Row (tr) | ||
Table Cell (td) | ||
| ||
Anchor | 1050597 | 1050597 | OS_Q CommQ;
Anchor | 1050598 | 1050598 |
Anchor | 1050599 | 1050599 |
Anchor | 1050600 | 1050600 | void main (void)
Anchor | 1050601 | 1050601 | {
Anchor | 1050602 | 1050602 | OS_ERR err;
Anchor | 1050603 | 1050603 |
Anchor | 1050604 | 1050604 |
Anchor | 1050605 | 1050605 | OSInit(&err); /* Initialize µC/OS-III */
Anchor | 1050606 | 1050606 | :
Anchor | 1050607 | 1050607 | :
Anchor | 1050608 | 1050608 | OSQCreate(&CommQ,
Anchor | 1050609 | 1050609 | “Comm Queue”,
Anchor | 1050610 | 1050610 | 10,
Anchor | 1050611 | 1050611 | &err); /* Create COMM Q */
Anchor | 1050612 | 1050612 | /* Check “err” */
Anchor | 1050613 | 1050613 | :
Anchor | 1050614 | 1050614 | :
Anchor | 1050615 | 1050615 | OSStart(); /* Start Multitasking */
Anchor | 1050616 | 1050616 | }
Table Row (tr) | ||
Table Row (tr) | ||
Table Row (tr) | ||
Table Row (tr) | ||
Table Row (tr) | ||
Table Row (tr) | ||
Table Row (tr) | ||
Table Row (tr) | ||
Table Row (tr) | ||
Table Row (tr) | ||
Table Row (tr) | ||
Table Row (tr) | ||
Table Row (tr) | ||
Table Row (tr) |
| |
OS_Q CommQ;
void main (void)
{
OS_ERR err;
OSInit(&err); /* Initialize µC/OS-III */
:
:
OSQCreate(&CommQ,
"Comm Queue",
10,
&err); /* Create COMM Q */
/* Check "err" */
:
:
OSStart(); /* Start Multitasking */
} |