Skip to content

Commit 3562cb8

Browse files
committed
freertos: Add GetStaticBuffer functions
This commit adds the various ...GetStaticBuffer() functions from upstream FreeRTOS. See FreeRTOS/FreeRTOS-Kernel#641 for more details.
1 parent 7b41d60 commit 3562cb8

25 files changed

+775
-2
lines changed

components/freertos/FreeRTOS-Kernel-SMP/event_groups.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,42 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup )
665665
}
666666
/*-----------------------------------------------------------*/
667667

668+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
669+
BaseType_t xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup,
670+
StaticEventGroup_t ** ppxEventGroupBuffer )
671+
{
672+
BaseType_t xReturn;
673+
EventGroup_t * pxEventBits = xEventGroup;
674+
675+
configASSERT( pxEventBits );
676+
configASSERT( ppxEventGroupBuffer );
677+
678+
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
679+
{
680+
/* Check if the event group was statically allocated. */
681+
if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdTRUE )
682+
{
683+
*ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
684+
xReturn = pdTRUE;
685+
}
686+
else
687+
{
688+
xReturn = pdFALSE;
689+
}
690+
}
691+
#else /* configSUPPORT_DYNAMIC_ALLOCATION */
692+
{
693+
/* Event group must have been statically allocated. */
694+
*ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
695+
xReturn = pdTRUE;
696+
}
697+
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
698+
699+
return xReturn;
700+
}
701+
#endif /* configSUPPORT_STATIC_ALLOCATION */
702+
/*-----------------------------------------------------------*/
703+
668704
/* For internal use only - execute a 'set bits' command that was pended from
669705
* an interrupt. */
670706
portTIMER_CALLBACK_ATTRIBUTE

components/freertos/FreeRTOS-Kernel-SMP/include/freertos/event_groups.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,28 @@ EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ) PRIVILEG
753753
*/
754754
void vEventGroupDelete( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION;
755755

756+
/**
757+
* event_groups.h
758+
* @code{c}
759+
* BaseType_t xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup,
760+
* StaticEventGroup_t ** ppxEventGroupBuffer );
761+
* @endcode
762+
*
763+
* Retrieve a pointer to a statically created event groups's data structure
764+
* buffer. It is the same buffer that is supplied at the time of creation.
765+
*
766+
* @param xEventGroup The event group for which to retrieve the buffer.
767+
*
768+
* @param ppxEventGroupBuffer Used to return a pointer to the event groups's
769+
* data structure buffer.
770+
*
771+
* @return pdTRUE if the buffer was retrieved, pdFALSE otherwise.
772+
*/
773+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
774+
BaseType_t xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup,
775+
StaticEventGroup_t ** ppxEventGroupBuffer ) PRIVILEGED_FUNCTION;
776+
#endif /* configSUPPORT_STATIC_ALLOCATION */
777+
756778
/* For internal use only. */
757779
void vEventGroupSetBitsCallback( void * pvEventGroup,
758780
const uint32_t ulBitsToSet ) PRIVILEGED_FUNCTION;

components/freertos/FreeRTOS-Kernel-SMP/include/freertos/message_buffer.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,37 @@ typedef void * MessageBufferHandle_t;
210210
#define xMessageBufferCreateStatic( xBufferSizeBytes, pucMessageBufferStorageArea, pxStaticMessageBuffer ) \
211211
( MessageBufferHandle_t ) xStreamBufferGenericCreateStatic( xBufferSizeBytes, 0, pdTRUE, pucMessageBufferStorageArea, pxStaticMessageBuffer )
212212

213+
/**
214+
* message_buffer.h
215+
*
216+
* @code{c}
217+
* BaseType_t xMessageBufferGetStaticBuffers( MessageBufferHandle_t xMessageBuffer,
218+
* uint8_t ** ppucMessageBufferStorageArea,
219+
* StaticMessageBuffer_t ** ppxStaticMessageBuffer );
220+
* @endcode
221+
*
222+
* Retrieve pointers to a statically created message buffer's data structure
223+
* buffer and storage area buffer. These are the same buffers that are supplied
224+
* at the time of creation.
225+
*
226+
* @param xMessageBuffer The message buffer for which to retrieve the buffers.
227+
*
228+
* @param ppucMessageBufferStorageArea Used to return a pointer to the
229+
* message buffer's storage area buffer.
230+
*
231+
* @param ppxStaticMessageBuffer Used to return a pointer to the message
232+
* buffer's data structure buffer.
233+
*
234+
* @return pdTRUE if buffers were retrieved, pdFALSE otherwise..
235+
*
236+
* \defgroup xMessageBufferGetStaticBuffers xMessageBufferGetStaticBuffers
237+
* \ingroup MessageBufferManagement
238+
*/
239+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
240+
#define xMessageBufferGetStaticBuffers( xMessageBuffer, ppucMessageBufferStorageArea, ppxStaticMessageBuffer ) \
241+
xStreamBufferGetStaticBuffers( ( xMessageBuffer ), ( ppucMessageBufferStorageArea ), ( ppxStaticMessageBuffer ) )
242+
#endif /* configSUPPORT_STATIC_ALLOCATION */
243+
213244
/**
214245
* message_buffer.h
215246
*

components/freertos/FreeRTOS-Kernel-SMP/include/freertos/queue.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,35 @@ typedef struct QueueDefinition * QueueSetMemberHandle_t;
233233
#define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) )
234234
#endif /* configSUPPORT_STATIC_ALLOCATION */
235235

236+
/**
237+
* queue. h
238+
* @code{c}
239+
* BaseType_t xQueueGetStaticBuffers( QueueHandle_t xQueue,
240+
* uint8_t ** ppucQueueStorage,
241+
* StaticQueue_t ** ppxStaticQueue );
242+
* @endcode
243+
*
244+
* Retrieve pointers to a statically created queue's data structure buffer
245+
* and storage area buffer. These are the same buffers that are supplied
246+
* at the time of creation.
247+
*
248+
* @param xQueue The queue for which to retrieve the buffers.
249+
*
250+
* @param ppucQueueStorage Used to return a pointer to the queue's storage
251+
* area buffer.
252+
*
253+
* @param ppxStaticQueue Used to return a pointer to the queue's data
254+
* structure buffer.
255+
*
256+
* @return pdTRUE if buffers were retrieved, pdFALSE otherwise.
257+
*
258+
* \defgroup xQueueGetStaticBuffers xQueueGetStaticBuffers
259+
* \ingroup QueueManagement
260+
*/
261+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
262+
#define xQueueGetStaticBuffers( xQueue, ppucQueueStorage, ppxStaticQueue ) xQueueGenericGetStaticBuffers( ( xQueue ), ( ppucQueueStorage ), ( ppxStaticQueue ) )
263+
#endif /* configSUPPORT_STATIC_ALLOCATION */
264+
236265
/**
237266
* queue. h
238267
* <pre>
@@ -1558,6 +1587,18 @@ BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION;
15581587
const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
15591588
#endif
15601589

1590+
/*
1591+
* Generic version of the function used to retrieve the buffers of statically
1592+
* created queues. This is called by other functions and macros that retrieve
1593+
* the buffers of other statically created RTOS objects that use the queue
1594+
* structure as their base.
1595+
*/
1596+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1597+
BaseType_t xQueueGenericGetStaticBuffers( QueueHandle_t xQueue,
1598+
uint8_t ** ppucQueueStorage,
1599+
StaticQueue_t ** ppxStaticQueue ) PRIVILEGED_FUNCTION;
1600+
#endif
1601+
15611602
/*
15621603
* Queue sets provide a mechanism to allow a task to block (pend) on a read
15631604
* operation from multiple queues or semaphores simultaneously.

components/freertos/FreeRTOS-Kernel-SMP/include/freertos/semphr.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,4 +1170,25 @@ typedef QueueHandle_t SemaphoreHandle_t;
11701170
*/
11711171
#define uxSemaphoreGetCount( xSemaphore ) uxQueueMessagesWaiting( ( QueueHandle_t ) ( xSemaphore ) )
11721172

1173+
/**
1174+
* semphr.h
1175+
* @code{c}
1176+
* BaseType_t xSemaphoreGetStaticBuffer( SemaphoreHandle_t xSemaphore );
1177+
* @endcode
1178+
*
1179+
* Retrieve pointer to a statically created binary semaphore, counting semaphore,
1180+
* or mutex semaphore's data structure buffer. This is the same buffer that is
1181+
* supplied at the time of creation.
1182+
*
1183+
* @param xSemaphore The semaphore for which to retrieve the buffer.
1184+
*
1185+
* @param ppxSemaphoreBuffer Used to return a pointer to the semaphore's
1186+
* data structure buffer.
1187+
*
1188+
* @return pdTRUE if buffer was retrieved, pdFALSE otherwise.
1189+
*/
1190+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1191+
#define xSemaphoreGetStaticBuffer( xSemaphore, ppxSemaphoreBuffer ) xQueueGenericGetStaticBuffers( ( QueueHandle_t ) ( xSemaphore ), NULL, ( ppxSemaphoreBuffer ) )
1192+
#endif /* configSUPPORT_STATIC_ALLOCATION */
1193+
11731194
#endif /* SEMAPHORE_H */

components/freertos/FreeRTOS-Kernel-SMP/include/freertos/stream_buffer.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,38 @@ typedef struct StreamBufferDef_t * StreamBufferHandle_t;
219219
#define xStreamBufferCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pucStreamBufferStorageArea, pxStaticStreamBuffer ) \
220220
xStreamBufferGenericCreateStatic( xBufferSizeBytes, xTriggerLevelBytes, pdFALSE, pucStreamBufferStorageArea, pxStaticStreamBuffer )
221221

222+
/**
223+
* stream_buffer.h
224+
*
225+
* @code{c}
226+
* BaseType_t xStreamBufferGetStaticBuffers( StreamBufferHandle_t xStreamBuffer,
227+
* uint8_t ** ppucStreamBufferStorageArea,
228+
* StaticStreamBuffer_t ** ppxStaticStreamBuffer );
229+
* @endcode
230+
*
231+
* Retrieve pointers to a statically created stream buffer's data structure
232+
* buffer and storage area buffer. These are the same buffers that are supplied
233+
* at the time of creation.
234+
*
235+
* @param xStreamBuffer The stream buffer for which to retrieve the buffers.
236+
*
237+
* @param ppucStreamBufferStorageArea Used to return a pointer to the stream
238+
* buffer's storage area buffer.
239+
*
240+
* @param ppxStaticStreamBuffer Used to return a pointer to the stream
241+
* buffer's data structure buffer.
242+
*
243+
* @return pdTRUE if buffers were retrieved, pdFALSE otherwise.
244+
*
245+
* \defgroup xStreamBufferGetStaticBuffers xStreamBufferGetStaticBuffers
246+
* \ingroup StreamBufferManagement
247+
*/
248+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
249+
BaseType_t xStreamBufferGetStaticBuffers( StreamBufferHandle_t xStreamBuffer,
250+
uint8_t ** ppucStreamBufferStorageArea,
251+
StaticStreamBuffer_t ** ppxStaticStreamBuffer ) PRIVILEGED_FUNCTION;
252+
#endif /* configSUPPORT_STATIC_ALLOCATION */
253+
222254
/**
223255
* stream_buffer.h
224256
*

components/freertos/FreeRTOS-Kernel-SMP/include/freertos/task.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,36 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lin
17041704
*/
17051705
TaskHandle_t xTaskGetHandle( const char * pcNameToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
17061706

1707+
/**
1708+
* task. h
1709+
* @code{c}
1710+
* BaseType_t xTaskGetStaticBuffers( TaskHandle_t xTask,
1711+
* StackType_t ** ppuxStackBuffer,
1712+
* StaticTask_t ** ppxTaskBuffer );
1713+
* @endcode
1714+
*
1715+
* Retrieve pointers to a statically created task's data structure
1716+
* buffer and stack buffer. These are the same buffers that are supplied
1717+
* at the time of creation.
1718+
*
1719+
* @param xTask The task for which to retrieve the buffers.
1720+
*
1721+
* @param ppuxStackBuffer Used to return a pointer to the task's stack buffer.
1722+
*
1723+
* @param ppxTaskBuffer Used to return a pointer to the task's data structure
1724+
* buffer.
1725+
*
1726+
* @return pdTRUE if buffers were retrieved, pdFALSE otherwise.
1727+
*
1728+
* \defgroup xTaskGetStaticBuffers xTaskGetStaticBuffers
1729+
* \ingroup TaskUtils
1730+
*/
1731+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1732+
BaseType_t xTaskGetStaticBuffers( TaskHandle_t xTask,
1733+
StackType_t ** ppuxStackBuffer,
1734+
StaticTask_t ** ppxTaskBuffer ) PRIVILEGED_FUNCTION;
1735+
#endif /* configSUPPORT_STATIC_ALLOCATION */
1736+
17071737
/**
17081738
* task.h
17091739
* <PRE>UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );</PRE>

components/freertos/FreeRTOS-Kernel-SMP/include/freertos/timers.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,25 @@ TickType_t xTimerGetPeriod( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
13071307
*/
13081308
TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
13091309

1310+
/**
1311+
* BaseType_t xTimerGetStaticBuffer( TimerHandle_t xTimer,
1312+
* StaticTimer_t ** ppxTimerBuffer );
1313+
*
1314+
* Retrieve pointer to a statically created timer's data structure
1315+
* buffer. This is the same buffer that is supplied at the time of
1316+
* creation.
1317+
*
1318+
* @param xTimer The timer for which to retrieve the buffer.
1319+
*
1320+
* @param ppxTimerBuffer Used to return a pointer to the timers's data
1321+
* structure buffer.
1322+
*
1323+
* @return pdTRUE if the buffer was retrieved, pdFALSE otherwise.
1324+
*/
1325+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1326+
BaseType_t xTimerGetStaticBuffer( TimerHandle_t xTimer,
1327+
StaticTimer_t ** ppxTimerBuffer ) PRIVILEGED_FUNCTION;
1328+
#endif /* configSUPPORT_STATIC_ALLOCATION */
13101329
/*
13111330
* Functions beyond this part are not part of the public API and are intended
13121331
* for use by the kernel only.

components/freertos/FreeRTOS-Kernel-SMP/queue.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,55 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
379379
#endif /* configSUPPORT_STATIC_ALLOCATION */
380380
/*-----------------------------------------------------------*/
381381

382+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
383+
384+
BaseType_t xQueueGenericGetStaticBuffers( QueueHandle_t xQueue,
385+
uint8_t ** ppucQueueStorage,
386+
StaticQueue_t ** ppxStaticQueue )
387+
{
388+
BaseType_t xReturn;
389+
Queue_t * const pxQueue = xQueue;
390+
391+
configASSERT( pxQueue );
392+
configASSERT( ppxStaticQueue );
393+
394+
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
395+
{
396+
/* Check if the queue was statically allocated. */
397+
if( pxQueue->ucStaticallyAllocated == ( uint8_t ) pdTRUE )
398+
{
399+
if( ppucQueueStorage != NULL )
400+
{
401+
*ppucQueueStorage = ( uint8_t * ) pxQueue->pcHead;
402+
}
403+
404+
*ppxStaticQueue = ( StaticQueue_t * ) pxQueue;
405+
xReturn = pdTRUE;
406+
}
407+
else
408+
{
409+
xReturn = pdFALSE;
410+
}
411+
}
412+
#else /* configSUPPORT_DYNAMIC_ALLOCATION */
413+
{
414+
/* Queue must have been statically allocated. */
415+
if( ppucQueueStorage != NULL )
416+
{
417+
*ppucQueueStorage = ( uint8_t * ) pxQueue->pcHead;
418+
}
419+
420+
*ppxStaticQueue = ( StaticQueue_t * ) pxQueue;
421+
xReturn = pdTRUE;
422+
}
423+
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
424+
425+
return xReturn;
426+
}
427+
428+
#endif /* configSUPPORT_STATIC_ALLOCATION */
429+
/*-----------------------------------------------------------*/
430+
382431
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
383432

384433
QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,

components/freertos/FreeRTOS-Kernel-SMP/stream_buffer.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,34 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
367367
#endif /* ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
368368
/*-----------------------------------------------------------*/
369369

370+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
371+
BaseType_t xStreamBufferGetStaticBuffers( StreamBufferHandle_t xStreamBuffer,
372+
uint8_t ** ppucStreamBufferStorageArea,
373+
StaticStreamBuffer_t ** ppxStaticStreamBuffer )
374+
{
375+
BaseType_t xReturn;
376+
const StreamBuffer_t * const pxStreamBuffer = xStreamBuffer;
377+
378+
configASSERT( pxStreamBuffer );
379+
configASSERT( ppucStreamBufferStorageArea );
380+
configASSERT( ppxStaticStreamBuffer );
381+
382+
if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_STATICALLY_ALLOCATED ) != ( uint8_t ) 0 )
383+
{
384+
*ppucStreamBufferStorageArea = pxStreamBuffer->pucBuffer;
385+
*ppxStaticStreamBuffer = ( StaticStreamBuffer_t * ) pxStreamBuffer;
386+
xReturn = pdTRUE;
387+
}
388+
else
389+
{
390+
xReturn = pdFALSE;
391+
}
392+
393+
return xReturn;
394+
}
395+
#endif /* configSUPPORT_STATIC_ALLOCATION */
396+
/*-----------------------------------------------------------*/
397+
370398
void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer )
371399
{
372400
StreamBuffer_t * pxStreamBuffer = xStreamBuffer;

0 commit comments

Comments
 (0)