0
2.6kviews
Explain the operation and significance of following MicroCOS-II functions.(any three)

OSInit()

OSSemPend() & OSSemPost()

OSTaskCreate()

OSMBoxPost() & OSMBoxPend()

Mumbai University > Electronics Engineering > Sem 6 > Embedded System and RTOS

1 Answer
0
27views

a. OSInit():

  1. uC/OS-II requires OSInit() to be called before any other services.
  2. This function initializes the variables and data structures of uC/OS-II. OSInit() creates and idle task OS_TaskIdle() which is ready to run. The priority of this task is always set to OS_LOWEST_PRIO.
  3. If OS_TASK_EN is set and OS_TASK_CREATE_EXT are both set then static task is created OS_TaskStat() and it is made ready to run. The priority of task is set to OS_LOWEST_PRIO-1

Function description: void OSI nit(void);

b. OSSemPend() & OSSemPost()

  1. OSSemPend():
  • This function is used by the task for acquiring a semaphore.
  • The availability of semaphore is signified if the count associated with the semaphore is greater than 0.
  • If the semaphore is available then the access is granted to the task calling this function and the count is decremented by 1.
  • If the semaphore is not available then the task is blocked and is put in semaphore wait queue list.
  • The task can wait till the semaphore becomes available or till a timeout occurs.
  • The timeout parameter is specified in terms of the clock ticks. This parameter can take any value ranging till 65535. A ‘0’ value indicates block until semaphore becomes available

    Function description: void OSSemPend(OS_EVENT *pevent, INT16U timeout, INT8U *err); pevent: is a pointer to the semaphore.

timeout: allows the task to resume execution if a message is not received from the mailbox within the specified number of clock ticks

err: is a pointer to a variable that holds an error code. Errors codes signify timeout, call from ISR error, pevent is NULL pointer error, pevent is not pointing to mailbox error or no error.

  1. OSSemPost():
  • A task can use this to signal the availability of a semaphore to any other task waiting for the same semaphore.
  • The count associated with the semaphore is incremented by 1 and the access is granted to the highest priority task waiting for the semaphore.
  • If the task signaling the availability of semaphore has the lower priority than the task waiting for the semaphore them the lower priority task is preempted, i.e. the lower priority task is blocked and the higher priority task is allowed to execute.

    Function description: INT8U OSSemPost(OS_EVENT *pevent);

    pevent: is a pointer to the semaphore.

c. OSTaskCreate():

  1. Creates a task to be managed by uC/OS-II.
  2. Task can be created before the start of multitasking or by a running task. A task cannot be created in an ISR.
  3. A task always contains an infinite loop which doesn’t return a value.
  4. Depending on the nature of stack frame, the task can have interrupts

Enabled or disabled.

Function description: INT8U OSTaskCreate(void (*task)(void *pd), void *pdata,OS_STK *ptos,INT8U prio); task: is a pointer to the task’s code. pdata: is a pointer to an optional data area used to pass parameters to the task when it is created ptos: is a pointer to the task’s top-of-stack. The stack is used to store local variables, function parameters, return addresses, and CPU registers during an interrupt. The size of the stack is determined by the task’s requirements. prio: is the task priority. A unique priority number must be assigned to each task, and the lower the number, the higher the priority

d. OSMboxPost() & OSMboxPend()

  1. OSMboxPost():
  • This function posts a message to mailbox.
  • The parameters include the pointer to mailbox, obtained after creation of mailbox, and a pointer to the message
  • If the mailbox is not empty then the posting fails and the task returns immediately.
  • If the message is successfully posted to the mailbox then it is routed to the highest priority task waiting for the message.

    Function description: INT8U OSMboxPost(OS_EVENT *pevent, void *msg); pevent: is a pointer to the mailbox into which the message is deposited msg: is the actual message sent to the task. It is a pointer-sized variable and is application specific.

  1. OSMboxPend():
  • This function is used for retrieving messages from the mailbox.
  • If the message is available in the mailbox at time of calling this function then it is retrieved and the message is deleted from the mailbox.
  • If the mailbox is not available then the task calling the function is blocked and put in a message wait list queue associated with the mailbox.
  • There is a timeout parameter associated with the waiting time of the task in the mailbox. This parameter can take values ranging from 0 to 65535. A ‘0’ value indicates blocking until the message is available to the task.

    Function description: void *OSMboxPend(OS_EVENT *pevent, INT16U timeout, INT8U *err); pevent: is a pointer to the mailbox into which the message is deposited timeout: allows the task to resume execution if a message is not received from the mailbox within the specified number of clock ticks. err: is a pointer to a variable that holds an error code. Errors codes signify timeout, call from ISR error, pevent is NULL pointer error, pevent is not pointing to mailbox error or no error.

Please log in to add an answer.