IAR PowerPac RTOS User Guide
IAR PowerPac RTOS User Guide IAR PowerPac RTOS User Guide
Prototypevoid OS_Q_Create (OS_Q* pQ,void*pData,OS_UINT Size);ParameterDescriptionpQPointer to a data structure of type OS_Q reserved for the management of the message queue.pDataPointer to a memory area used as data buffer for the queue.SizeSize in bytes of the data buffer.Table 73: OS_Q_Create() parameter listExample#define MEMORY_QSIZE 10000;static OS_Q _MemoryQ;static char _acMemQBuffer[MEMORY_QSIZE];void MEMORY_Init(void) {OS_Q_Create(&_MemoryQ, &_acMemQBuffer, sizeof(_acMemQBuffer));}OS_Q_Put()DescriptionStores a new message of given size in a queue.Prototypeint OS_Q_Put (OS_Q* pQ,const void* pSrc,OS_UINT Size);ParameterDescriptionpQpSrcSizeTable 74: OS_Q_Put() parameter listReturn value0: Success; message stored.1: Message could not be stored (queue is full).Additional InformationIf the queue is full, the function returns a value unequal to 0.This routine never suspends the calling task. It may therefore also be called from an interrupt routine.Examplechar MEMORY_Write(char* pData, int Len) {return OS_Q_Put(&_MemoryQ, pData, Len));}OS_Q_GetPtr()DescriptionRetrieves a message from a queue.Prototypeint OS_Q_GetPtr (OS_Q* pQ,void** ppData);ParameterDescriptionpQppDataTable 75: OS_Q_GetPtr() parameter listPointer to a data structure of type OS_Q reserved for the management of the message queue.Pointer to the message to storeSize of the message to storePointer to the queue.Address of pointer to the message to be retrieved from queue.72IAR PowerPac RTOSfor ARM CoresPPRTOS-2
QueuesReturn valueThe size of the retrieved message.Sets the pointer to the message that should be retrieved.Additional InformationIf the queue is empty, the calling task is suspended until the queue receives a new message. Because this routine mightrequire a suspension, it must not be called from an interrupt routine. Use OS_GetPtrCond() instead. The retrievedmessage is not removed from the queue. This has to be done by a call of OS_Q_Purge() after the message wasprocessed.Examplestatic void MemoryTask(void) {char MemoryEvent;int Len;char* pData;}while (1) {Len = OS_Q_GetPtr(&_MemoryQ, &pData); /* Get message */Memory_WritePacket(*(U32*)pData, pData+4, Len); /* Process message */OS_Q_Purge(&_MemoryQ); /* Delete message */}OS_Q_GetPtrCond()DescriptionRetrieves a message from a queue, if one message is available.Prototypeint OS_Q_GetPtrCond (OS_Q* pQ,void** ppData);ParameterDescriptionpQPointer to the queue.ppDataAddress of pointer to the message to be retrieved from queue.Table 76: OS_Q_GetPtrCond() parameter listReturn value0: No message available in queue.>0: Size of message that was retrieved from queue.Additional InformationIf the queue is empty, the function returns 0. The value of ppData is undefined. This function never suspends the callingtask. It may therefore also be called from an interrupt routine. If a message could be retrieved, it is not removed fromthe queue. This has to be done by a call of OS_Q_Purge() after the message was processed.Examplestatic void MemoryTask(void) {char MemoryEvent;int Len;char* pData;while (1) {Len = OS_Q_GetPtrCond(&_MemoryQ, &pData); /* Check message */if (Len > 0) {Memory_WritePacket(*(U32*)pData, pData+4, Len); /* Process message */OS_Q_Purge(&_MemoryQ); /* Delete message */} else {DoSomethingElse();}}}PPRTOS-273
- 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 and 54: Resource semaphoresOS_Request()Desc
- Page 55 and 56: Counting SemaphoresIntroductionCoun
- 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: QueuesWhy queues?In the preceding c
- 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
- Page 105 and 106: InterruptsNesting interrupt routine
- Page 107 and 108: Critical RegionsIntroductionCritica
- Page 109 and 110: System variablesIntroductionThe sys
- Page 111 and 112: Configuration for your targetsystem
- Page 113 and 114: Time measurementIntroductionIAR Pow
- Page 115 and 116: Time measurementPrototypeU32 OS_Get
- Page 117 and 118: Time measurementPrototypeOS_U32 OS_
- Page 119 and 120: RTOS-aware debuggingThis chapter de
- Page 121 and 122: RTOS-aware debuggingTimersA softwar
QueuesReturn valueThe size of the retrieved message.Sets the pointer to the message that should be retrieved.Additional InformationIf the queue is empty, the calling task is suspended until the queue receives a new message. Because this routine mightrequire a suspension, it must not be called from an interrupt routine. Use OS_GetPtrCond() instead. The retrievedmessage is not removed from the queue. This has to be done by a call of OS_Q_Purge() after the message wasprocessed.Examplestatic void MemoryTask(void) {char MemoryEvent;int Len;char* pData;}while (1) {Len = OS_Q_GetPtr(&_MemoryQ, &pData); /* Get message */Memory_WritePacket(*(U32*)pData, pData+4, Len); /* Process message */OS_Q_Purge(&_MemoryQ); /* Delete message */}OS_Q_GetPtrCond()DescriptionRetrieves a message from a queue, if one message is available.Prototypeint OS_Q_GetPtrCond (OS_Q* pQ,void** ppData);ParameterDescriptionpQPointer to the queue.ppDataAddress of pointer to the message to be retrieved from queue.Table 76: OS_Q_GetPtrCond() parameter listReturn value0: No message available in queue.>0: Size of message that was retrieved from queue.Additional InformationIf the queue is empty, the function returns 0. The value of ppData is undefined. This function never suspends the callingtask. It may therefore also be called from an interrupt routine. If a message could be retrieved, it is not removed fromthe queue. This has to be done by a call of OS_Q_Purge() after the message was processed.Examplestatic void MemoryTask(void) {char MemoryEvent;int Len;char* pData;while (1) {Len = OS_Q_GetPtrCond(&_MemoryQ, &pData); /* Check message */if (Len > 0) {Memory_WritePacket(*(U32*)pData, pData+4, Len); /* Process message */OS_Q_Purge(&_MemoryQ); /* Delete message */} else {DoSomethingElse();}}}PP<strong>RTOS</strong>-273