IAR PowerPac RTOS User Guide
IAR PowerPac RTOS User Guide IAR PowerPac RTOS User Guide
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
- Page 3 and 4: PrefaceWelcome to the IAR PowerPac
- Page 5 and 6: ContentsPreface ...................
- Page 7 and 8: ContentsOS_WaitCSema() ............
- Page 9 and 10: ContentsOS_LeaveInterrupt() .......
- Page 11 and 12: Introduction to IAR PowerPacRTOSWha
- Page 13 and 14: Basic conceptsTasksIn this context,
- Page 15 and 16: Basic conceptsPREEMPTIVES MULTITASK
- Page 17 and 18: Basic conceptsMAILBOXES AND QUEUESA
- Page 19 and 20: Basic conceptsThe active task may b
- Page 21 and 22: Basic conceptsThe flowchart below i
- Page 23 and 24: Basic conceptsLIST OF LIBRARIESIn y
- Page 25 and 26: Task routinesIntroductionA task tha
- Page 27 and 28: Task routinesOS_CREATETASK() can be
- Page 29 and 30: Task routinesExampleThe following e
- Page 31 and 32: Task routinesExampleint sec,min;voi
- Page 33 and 34: Task routinesAdditional Information
- Page 35 and 36: Task routinesReturn valueOS_TASKID:
- Page 37 and 38: Software timersSoftware timerA soft
- Page 39 and 40: Software timers#define OS_CREATETIM
- Page 41 and 42: Software timersOS_SetTimerPeriod()D
- Page 43 and 44: Software timersAdditional Informati
- Page 45 and 46: Software timersAdditional Informati
- Page 47 and 48: Software timersExampleOS_TIMER TIME
- Page 49 and 50: Resource semaphoresIntroductionReso
- Page 51 and 52: Resource semaphoresResource semapho
- Page 53: Resource semaphoresOS_Request()Desc
- Page 57 and 58: Counting SemaphoresPrototypevoid OS
- Page 59 and 60: Counting SemaphoresReturn value0: I
- Page 61 and 62: MailboxesWhy mailboxes?In the prece
- Page 63 and 64: MailboxesMailboxes API function ove
- Page 65 and 66: MailboxesExampleSingle-byte mailbox
- Page 67 and 68: MailboxesPrototypevoid OS_GetMail (
- Page 69 and 70: MailboxesOS_WaitMail()DescriptionWa
- Page 71 and 72: QueuesWhy queues?In the preceding c
- Page 73 and 74: QueuesReturn valueThe size of the r
- Page 75 and 76: QueuesExamplestatic void MemoryTask
- Page 77 and 78: Task eventsIntroductionTask events
- Page 79 and 80: Task eventsExampleOS_WaitEventTimed
- Page 81 and 82: Task eventsPrototypechar OS_ClearEv
- Page 83 and 84: Event objectsIntroductionEvent obje
- Page 85 and 86: Event objectsExampleif (OS_EVENT_Wa
- Page 87 and 88: Event objectsExampleOS_EVENT_Reset(
- Page 89 and 90: Heap type memory managementANSI C o
- Page 91 and 92: Fixed block size memory poolsIntrod
- Page 93 and 94: Fixed block size memory poolsProtot
- Page 95 and 96: Fixed block size memory poolsProtot
- Page 97 and 98: StacksIntroductionThe stack is the
- Page 99 and 100: InterruptsIntroductionIn this chapt
- Page 101 and 102: InterruptsRules for interrupt handl
- Page 103 and 104: InterruptsOS_LeaveInterruptNoSwitch
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