Skip to content

Commit

Permalink
Static allocation of tasks and queues, if configSUPPORT_STATIC_ALLOCA…
Browse files Browse the repository at this point in the history
…TION == 1 (FreeRTOS#208)

Is not added to any ported network interfaced.
  • Loading branch information
Christian Jensen committed Mar 30, 2021
1 parent d034979 commit 35de87b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 11 deletions.
43 changes: 34 additions & 9 deletions FreeRTOS_IP.c
Original file line number Diff line number Diff line change
Expand Up @@ -1171,8 +1171,17 @@ BaseType_t FreeRTOS_IPInit( const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES
configASSERT( sizeof( UDPHeader_t ) == ipEXPECTED_UDPHeader_t_SIZE );

/* Attempt to create the queue used to communicate with the IP task. */
xNetworkEventQueue = xQueueCreate( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ) );
configASSERT( xNetworkEventQueue != NULL );
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
{
static StaticQueue_t xNetworkEventStaticQueue;
uint8_t ucNetworkEventQueueStorageArea[ipconfigEVENT_QUEUE_LENGTH * sizeof(IPStackEvent_t)];
xNetworkEventQueue = xQueueCreateStatic(ipconfigEVENT_QUEUE_LENGTH, sizeof(IPStackEvent_t), ucNetworkEventQueueStorageArea, &xNetworkEventStaticQueue);
}
#else
{
xNetworkEventQueue = xQueueCreate( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ) );
configASSERT( xNetworkEventQueue != NULL );
} /* configSUPPORT_STATIC_ALLOCATION */

if( xNetworkEventQueue != NULL )
{
Expand Down Expand Up @@ -1221,14 +1230,30 @@ BaseType_t FreeRTOS_IPInit( const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES

/* Prepare the sockets interface. */
vNetworkSocketsInit();

/* Create the task that processes Ethernet and stack events. */
xReturn = xTaskCreate( prvIPTask,
"IP-task",
ipconfigIP_TASK_STACK_SIZE_WORDS,
NULL,
ipconfigIP_TASK_PRIORITY,
&( xIPTaskHandle ) );
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
{
static StaticTask_t xIPTaskBuffer;
static StackType_t xIPTaskStack[ipconfigIP_TASK_STACK_SIZE_WORDS];
xIPTaskHandle = xTaskCreateStatic(prvIPTask,
"IP-Task",
ipconfigIP_TASK_STACK_SIZE_WORDS,
NULL,
ipconfigIP_TASK_PRIORITY,
xIPTaskStack,
&xIPTaskBuffer);
}
#else
{
xReturn = xTaskCreate( prvIPTask,
"IP-task",
ipconfigIP_TASK_STACK_SIZE_WORDS,
NULL,
ipconfigIP_TASK_PRIORITY,
&( xIPTaskHandle ) );
}
#endif /* configSUPPORT_STATIC_ALLOCATION */
}
else
{
Expand Down
15 changes: 14 additions & 1 deletion portable/BufferManagement/BufferAllocation_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,20 @@ BaseType_t xNetworkBuffersInitialise( void )
* here */
ipconfigBUFFER_ALLOC_INIT();

xNetworkBufferSemaphore = xSemaphoreCreateCounting( ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS );
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
{
static StaticSemaphore_t xNetworkBufferSemaphoreBuffer;
xNetworkBufferSemaphore = xSemaphoreCreateCountingStatic(
(UBaseType_t) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS,
(UBaseType_t) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS,
&xNetworkBufferSemaphoreBuffer);
}
#else
{
xNetworkBufferSemaphore = xSemaphoreCreateCounting((UBaseType_t) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, (UBaseType_t) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS);
}
#endif /* configSUPPORT_STATIC_ALLOCATION */

configASSERT( xNetworkBufferSemaphore != NULL );

if( xNetworkBufferSemaphore != NULL )
Expand Down
15 changes: 14 additions & 1 deletion portable/BufferManagement/BufferAllocation_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,20 @@ BaseType_t xNetworkBuffersInitialise( void )
* have not been initialised before. */
if( xNetworkBufferSemaphore == NULL )
{
xNetworkBufferSemaphore = xSemaphoreCreateCounting( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS );
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
{
static StaticSemaphore_t xNetworkBufferSemaphoreBuffer;
xNetworkBufferSemaphore = xSemaphoreCreateCountingStatic(
ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS,
ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS,
&xNetworkBufferSemaphoreBuffer);
}
#else
{
xNetworkBufferSemaphore = xSemaphoreCreateCounting(ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS);
}
#endif /* configSUPPORT_STATIC_ALLOCATION */

configASSERT( xNetworkBufferSemaphore != NULL );

if( xNetworkBufferSemaphore != NULL )
Expand Down

0 comments on commit 35de87b

Please sign in to comment.