IAR PowerPac RTOS User Guide

IAR PowerPac RTOS User Guide IAR PowerPac RTOS User Guide

ie.ksu.edu.tw
from ie.ksu.edu.tw More from this publisher
11.07.2015 Views

OS_GetSemaValue()DescriptionReturns the value of the usage counter of a specified resource semaphore.Prototypeint OS_GetSemaValue (OS_SEMA* pSema);ParameterDescriptionpRSemaPointer to the data structure for a resource semaphore.Table 45: OS_GetSemaValue() parameter listReturn valueThe counter of the semaphore.A value of 0 means the resource is available.OS_GetResourceOwner()DescriptionReturns a pointer to the task that is currently using (blocking) a resource.PrototypeOS_TASK* OS_GetResourceOwner (OS_RSEMA* pSema);ParameterDescriptionpRSemaTable 46: OS_GetResourceOwner() parameter listReturn valuePointer to the task that is blocking the resource.A value of 0 means the resource is available.OS_DeleteRSema()DescriptionDeletes a specified resource semaphore. The memory of that semaphore may be reused for other purposes or may beused for creating another resources semaphore using the same memory.Prototypevoid OS_DeleteRSema (OS_RSEMA* pRSema);ParameterDescriptionpRSemaTable 47: OS_DeleteRSema parameter listAdditional InformationPointer to the data structure for a resource semaphore.Pointer to a data structure of type OS_RSEMA.Before deleting a resource semaphore, make sure that no task is claiming the resources semaphore. The debug versionof IAR PowerPac RTOS will call OS_Error(), if a resources semaphore is deleted when it is already used. In systemswith dynamic creation of resource semaphores, it is required to delete a resource semaphore, before re-creating it.Otherwise the semaphore handling will not work correctly.54IAR PowerPac RTOSfor ARM CoresPPRTOS-2

Counting SemaphoresIntroductionCounting semaphores are counters that are managed by IAR PowerPac RTOS. They are not as widely used as resourcesemaphores, events or mailboxes, but they can be very useful sometimes. They are used in situations where a task needsto wait for something that can be signaled one or more times. The semaphores can be accessed from any point, anytask, or any interrupt in any way.Example of using counting semaphoresOS_STACKPTR int Stack0[96], Stack1[64]; /* Task stacks */OS_TASK TCB0, TCB1; /* Data-area for tasks (task-control-blocks) */OS_CSEMA SEMALCD;void Task0(void) {Loop:Disp("Task0 will wait for task 1 to signal");OS_WaitCSema(&SEMALCD);Disp("Task1 has signaled !!");OS_Delay(100);goto Loop;}void Task1(void) {Loop:OS_Delay(5000);OS_SignalCSema(&SEMALCD);goto Loop;}void InitTask(void) {OS_CREATECSEMA(&SEMALCD); /* Create Semaphore */OS_CREATETASK(&TCB0, NULL, Task0, 100, Stack0); /* Create Task0 */OS_CREATETASK(&TCB1, NULL, Task1, 50, Stack1); /* Create Task1 */}Counting semaphores API function overviewRoutineDescriptionOS_CREATECSEMA()Macro that creates a counting semaphore with an initial count value of zero.OS_CreateCSema()Creates a counting semaphore with a specified initial count value.OS_SignalCSema()Increments the counter of a semaphore.OS_SignalCSemaMaxIncrements the counter of a semaphore up to a specified maximum value.OS_WaitCSema()Decrements the counter of a semaphore.OS_CSemaRequest()Decrements the counter of a semaphore, if available.OS_WaitCSemaTimedDecrements a semaphore counter if the semaphore is available within a specified time.OS_GetCSemaValue() Returns the counter value of a specified semaphore.OS_SetCSemaValue() Sets the counter value of a specified semaphore.OS_DeleteCSema()Returns the counter value of a specified semaphore.Table 48: Counting semaphores API overviewOS_CREATECSEMA()DescriptionMacro that creates a counting semaphore with an initial count value of zero.PPRTOS-2 55

Counting SemaphoresIntroductionCounting semaphores are counters that are managed by <strong>IAR</strong> <strong>PowerPac</strong> <strong>RTOS</strong>. They are not as widely used as resourcesemaphores, events or mailboxes, but they can be very useful sometimes. They are used in situations where a task needsto wait for something that can be signaled one or more times. The semaphores can be accessed from any point, anytask, or any interrupt in any way.Example of using counting semaphoresOS_STACKPTR int Stack0[96], Stack1[64]; /* Task stacks */OS_TASK TCB0, TCB1; /* Data-area for tasks (task-control-blocks) */OS_CSEMA SEMALCD;void Task0(void) {Loop:Disp("Task0 will wait for task 1 to signal");OS_WaitCSema(&SEMALCD);Disp("Task1 has signaled !!");OS_Delay(100);goto Loop;}void Task1(void) {Loop:OS_Delay(5000);OS_SignalCSema(&SEMALCD);goto Loop;}void InitTask(void) {OS_CREATECSEMA(&SEMALCD); /* Create Semaphore */OS_CREATETASK(&TCB0, NULL, Task0, 100, Stack0); /* Create Task0 */OS_CREATETASK(&TCB1, NULL, Task1, 50, Stack1); /* Create Task1 */}Counting semaphores API function overviewRoutineDescriptionOS_CREATECSEMA()Macro that creates a counting semaphore with an initial count value of zero.OS_CreateCSema()Creates a counting semaphore with a specified initial count value.OS_SignalCSema()Increments the counter of a semaphore.OS_SignalCSemaMaxIncrements the counter of a semaphore up to a specified maximum value.OS_WaitCSema()Decrements the counter of a semaphore.OS_CSemaRequest()Decrements the counter of a semaphore, if available.OS_WaitCSemaTimedDecrements a semaphore counter if the semaphore is available within a specified time.OS_GetCSemaValue() Returns the counter value of a specified semaphore.OS_SetCSemaValue() Sets the counter value of a specified semaphore.OS_DeleteCSema()Returns the counter value of a specified semaphore.Table 48: Counting semaphores API overviewOS_CREATECSEMA()DescriptionMacro that creates a counting semaphore with an initial count value of zero.PP<strong>RTOS</strong>-2 55

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!