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

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

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

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

Saved successfully!

Ooh no, something went wrong!