OSTaskQPost

Description

OSTaskQPost() sends a message to a task through its local message queue. A message is a pointer-sized variable, and its use is application specific. If the task’s message queue is full, an error code is returned to the caller. In this case, OSTaskQPost() immediately returns to its caller, and the message is not placed in the message queue.

If the task receiving the message is waiting for a message to arrive, it will be made ready-to-run. If the receiving task has a higher priority than the task sending the message, the higher-priority task resumes, and the task sending the message is suspended; that is, a context switch occurs. A message can be posted as first-in first-out (FIFO), or last-in-first-out (LIFO), depending on the value specified in the opt argument. In either case, scheduling occurs unless opt is set to OS_OPT_POST_NO_SCHED.

Files

os.h/os_task.c

Prototype

void  OSTaskQPost (OS_TCB      *p_tcb,
                   void        *p_void,
                   OS_MSG_SIZE  msg_size,
                   OS_OPT       opt,
                   OS_ERR      *p_err)

Arguments

p_tcb

is a pointer to the TCB of the task. Note that it is possible to post a message to the calling task (i.e., self) by specifying a NULL pointer, or the address of its TCB.

p_void

is the actual message sent to the task. p_void is a pointer-sized variable and its meaning is application specific.

msg_size

specifies the size of the message posted (in number of bytes).

opt

determines the type of POST performed. Of course, it does not make sense to post LIFO and FIFO simultaneously, so these options are exclusive:

OS_OPT_POST_FIFO

POST message to task and place at the end of the queue if the task is not waiting for messages.

OS_OPT_POST_LIFO

POST message to task and place at the front of the queue if the task is not waiting for messages.

OS_OPT_POST_NO_SCHED

This option prevents calling the scheduler after the post and therefore the caller is resumed.

You should use this option if the task (or ISR) calling OSTaskQPost() will be doing additional posts, the user does not want to reschedule until all done, and multiple posts are to take effect simultaneously.

p_err

is a pointer to a variable that will contain an error code returned by this function.

OS_ERR_NONE

If the call was successful and the message was posted to the task’s message queue.

OS_ERR_MSG_POOL_EMPTY

If running out of OS_MSG to hold the message being posted.

OS_ERR_OPT_INVALID

If OS_CFG_ARG_CHK_EN is set to DEF_ENABLED in os_cfg.h: if a valid option is not specified.

OS_ERR_OS_NOT_RUNNING

If OS_CFG_INVALID_OS_CALLS_CHK_EN is set to DEF_ENABLED in os_cfg.h: if µC/OS-III is not running yet.

OS_ERR_Q_MAX

If the task’s message queue is full and cannot accept more messages.

OS_ERR_STATE_INVALID

If the task is in an invalid state.

Returned Value

None

Required Configuration

OS_CFG_TASK_Q_EN must be enabled in os_cfg.h. Refer to µC-OS-III Configuration Manual.

Callers

Application and ISRs.

Notes/Warnings

None

Example Usage

OSTaskQPost() example usage
OS_TCB       CommRxTaskTCB;
CPU_INT08U   CommRxBuf[100];
 
 
void CommTaskRx (void *p_arg)
{
    OS_ERR  err;
 
 
    (void)&p_arg;
    while (DEF_ON) {
        :
        OSTaskQPost(&CommRxTaskTCB,
                    (void *)&CommRxBuf[0],
                    sizeof(CommRxBuf),
                    OS_OPT_POST_FIFO,
                    &err);
        /* Check "err" */
        :
        :
    }
}