Documente Academic
Documente Profesional
Documente Cultură
OSQCreate()
Function
Prototype
OS_EVENT *
OSQCreate
(void **start,
INT16U size);
Location:
src/uC/os_q.c
Arguments
Returns
Notes
start
A pointer to the event
base address of control block allocated to
storage area
the queue is returned if
the call succeeds. If it
size
fails a NULL pointer is
number of
returned.
elements in the
storage area
Example:
begin (void)
{
*((int *)0x80) = (int)OSCtxSw;
OSInit();
TaskCreate("StartTask",StartTask,StartTask_ID);
OSStart();
}
void StartTask(void *data)
{
ScopeInit();
TickInit();
.
.
TxQueueA = OSQCreate (TxQueueTblA, FIFO_SIZE);
TxQueueB = OSQCreate (TxQueueTblB, FIFO_SIZE);
.
.
OSTaskDel(OS_PRIO_SELF); /* This task only runs once */
}
OSQPend()
Function
Prototype
Arguments
Returns
Notes
void *
OSQPend
(OS_EVENT
*pevent,
INT16U
timeout, INT8U
* err) ;
pevent
Pointer to queue from which the message is
to be recieved. This is the same pointer
that was returned when the queue was
created using OSQCreate()
If successful OSQPend
returns a message sent by a
task and *err contains
OS_NO_ERR. If
unsuccessful a NULL
pointer is returned and *err
contains one of the error
codes as specified in the
arguments field.
Always create
queues before
using them and
don't call this
function from
inside an ISR
Location:
src/uC/os_q.c
timeout
Pass in 0 if you want to wait forever for a
message. Pass a value in ticks (0 - 65535)
to give up on receiving the message after
the period has lapsed. The function will
return and the task will resume once the
number of ticks has expired.
err
OS_NO_ERR
Message was received
OS_TIMEOUT
Message was not received withing the
specified timeout.
OS_ERR_EVENT_TYPE
pevent is not pointing to a message queue
OS_ERR_PEVENT_NULL
pevent is a NULL pointer
OS_ERR_PEND_ISR
This function was called from an ISR and
uC/OS-II must suspend the task. To avoid
Messages are
placed in the
queue by one
task and
retreived by
another.
Call this
function to
retrieve
possible
messages.
If multiple
tasks are
waiting for a
message the
highest priority
task is resumed.
OSQPost()
Function
Prototype
INT8U
OSQPost
(OS_EVENT
*pevent, void
*msg) ;
Location:
src/uC/os_q.c
Arguments
pevent
Pointer to the queue into
which the message is
deposited. Use the pointer that
was returned when the queue
was created using
OSQCreate()
msg
Pointer- sized variable that is
user defined. Don't post a
NULL pointer.
Returns
OS_NO_ERR
Message was deposited in the
queue.
OS_Q_FULL
No room in the queue.
OS_ERR_EVENT_TYPE
pevent is not pointing to a
message queue.
OS_ERR_PEVENT_NULL
pevent is a NULL pointer.
OS_ERR_POST_NULL_PTR
msg is a NULL pointer.
Example:
void LedBufferPost(char num, char state)
{
INT8U err;
if (LedBufferIndex >=10)
Notes
Always create Queues
before using them and
never pass in NULL
pointers as arguments.
Use this function to
send a message to
another task via a
previously created
queue.
If multiple tasks are
waiting for a message
the highest priority
task is resumed.
LedBufferIndex=0;
LedBuffer[LedBufferIndex].LedNum = num;
LedBuffer[LedBufferIndex].State = state;
err = OSQPost(LEDQueue, (void *)&LedBuffer[LedBufferIndex++]);
}