From 35de87bd3ebc89a5157e5dadfd9953cf89ece991 Mon Sep 17 00:00:00 2001 From: Christian Jensen Date: Tue, 30 Mar 2021 10:16:12 +0200 Subject: [PATCH 1/5] Static allocation of tasks and queues, if configSUPPORT_STATIC_ALLOCATION == 1 (#208) Is not added to any ported network interfaced. --- FreeRTOS_IP.c | 43 +++++++++++++++---- .../BufferManagement/BufferAllocation_1.c | 15 ++++++- .../BufferManagement/BufferAllocation_2.c | 15 ++++++- 3 files changed, 62 insertions(+), 11 deletions(-) diff --git a/FreeRTOS_IP.c b/FreeRTOS_IP.c index 4246252217..3b0801a76a 100644 --- a/FreeRTOS_IP.c +++ b/FreeRTOS_IP.c @@ -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 ) { @@ -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 { diff --git a/portable/BufferManagement/BufferAllocation_1.c b/portable/BufferManagement/BufferAllocation_1.c index 905cbdbf9b..894c7f4bcd 100644 --- a/portable/BufferManagement/BufferAllocation_1.c +++ b/portable/BufferManagement/BufferAllocation_1.c @@ -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 ) diff --git a/portable/BufferManagement/BufferAllocation_2.c b/portable/BufferManagement/BufferAllocation_2.c index 765db4ac83..42777a59cc 100644 --- a/portable/BufferManagement/BufferAllocation_2.c +++ b/portable/BufferManagement/BufferAllocation_2.c @@ -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 ) From 7ec214ca083b91be184190fb6fe32b408dbb4909 Mon Sep 17 00:00:00 2001 From: Christian Jensen Date: Tue, 30 Mar 2021 11:04:51 +0200 Subject: [PATCH 2/5] Build-check fix --- FreeRTOS_IP.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/FreeRTOS_IP.c b/FreeRTOS_IP.c index 3b0801a76a..8aeed1de93 100644 --- a/FreeRTOS_IP.c +++ b/FreeRTOS_IP.c @@ -1181,7 +1181,8 @@ BaseType_t FreeRTOS_IPInit( const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES { xNetworkEventQueue = xQueueCreate( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ) ); configASSERT( xNetworkEventQueue != NULL ); - } /* configSUPPORT_STATIC_ALLOCATION */ + } + #endif /* configSUPPORT_STATIC_ALLOCATION */ if( xNetworkEventQueue != NULL ) { From e2a1cbcf046ac6424666383bf294c8b574e36fa5 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere Date: Mon, 5 Apr 2021 11:32:27 -0700 Subject: [PATCH 3/5] Uncrustify --- FreeRTOS_IP.c | 66 +++++++++---------- .../BufferManagement/BufferAllocation_1.c | 24 +++---- .../BufferManagement/BufferAllocation_2.c | 24 +++---- 3 files changed, 57 insertions(+), 57 deletions(-) diff --git a/FreeRTOS_IP.c b/FreeRTOS_IP.c index 8aeed1de93..c12723285e 100644 --- a/FreeRTOS_IP.c +++ b/FreeRTOS_IP.c @@ -1171,18 +1171,18 @@ 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. */ - #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); - } + #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 ); - } - #endif /* configSUPPORT_STATIC_ALLOCATION */ + { + xNetworkEventQueue = xQueueCreate( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ) ); + configASSERT( xNetworkEventQueue != NULL ); + } + #endif /* configSUPPORT_STATIC_ALLOCATION */ if( xNetworkEventQueue != NULL ) { @@ -1231,29 +1231,29 @@ 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. */ - #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 ) ); - } + #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 /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ + { + xReturn = xTaskCreate( prvIPTask, + "IP-task", + ipconfigIP_TASK_STACK_SIZE_WORDS, + NULL, + ipconfigIP_TASK_PRIORITY, + &( xIPTaskHandle ) ); + } #endif /* configSUPPORT_STATIC_ALLOCATION */ } else diff --git a/portable/BufferManagement/BufferAllocation_1.c b/portable/BufferManagement/BufferAllocation_1.c index 894c7f4bcd..283ca0d2b6 100644 --- a/portable/BufferManagement/BufferAllocation_1.c +++ b/portable/BufferManagement/BufferAllocation_1.c @@ -176,20 +176,20 @@ BaseType_t xNetworkBuffersInitialise( void ) * here */ ipconfigBUFFER_ALLOC_INIT(); - #if( configSUPPORT_STATIC_ALLOCATION == 1 ) - { - static StaticSemaphore_t xNetworkBufferSemaphoreBuffer; - xNetworkBufferSemaphore = xSemaphoreCreateCountingStatic( - (UBaseType_t) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, - (UBaseType_t) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, - &xNetworkBufferSemaphoreBuffer); - } + #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); - } + { + xNetworkBufferSemaphore = xSemaphoreCreateCounting( ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, ( UBaseType_t ) ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ); + } #endif /* configSUPPORT_STATIC_ALLOCATION */ - + configASSERT( xNetworkBufferSemaphore != NULL ); if( xNetworkBufferSemaphore != NULL ) diff --git a/portable/BufferManagement/BufferAllocation_2.c b/portable/BufferManagement/BufferAllocation_2.c index 42777a59cc..b7fbed5954 100644 --- a/portable/BufferManagement/BufferAllocation_2.c +++ b/portable/BufferManagement/BufferAllocation_2.c @@ -102,20 +102,20 @@ BaseType_t xNetworkBuffersInitialise( void ) * have not been initialised before. */ if( xNetworkBufferSemaphore == NULL ) { - #if( configSUPPORT_STATIC_ALLOCATION == 1 ) - { - static StaticSemaphore_t xNetworkBufferSemaphoreBuffer; - xNetworkBufferSemaphore = xSemaphoreCreateCountingStatic( - ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, - ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, - &xNetworkBufferSemaphoreBuffer); - } + #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); - } + { + xNetworkBufferSemaphore = xSemaphoreCreateCounting( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ); + } #endif /* configSUPPORT_STATIC_ALLOCATION */ - + configASSERT( xNetworkBufferSemaphore != NULL ); if( xNetworkBufferSemaphore != NULL ) From b00064d6e52c8954cc07add2b18cfabf2af404c1 Mon Sep 17 00:00:00 2001 From: Aniruddha Kanhere Date: Mon, 5 Apr 2021 11:34:34 -0700 Subject: [PATCH 4/5] Uncrustify v2 --- FreeRTOS_IP.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FreeRTOS_IP.c b/FreeRTOS_IP.c index c12723285e..7970566a95 100644 --- a/FreeRTOS_IP.c +++ b/FreeRTOS_IP.c @@ -1245,7 +1245,7 @@ BaseType_t FreeRTOS_IPInit( const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES xIPTaskStack, &xIPTaskBuffer ); } - #else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ + #else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ { xReturn = xTaskCreate( prvIPTask, "IP-task", From 83210e1c65cc046d2bdc0b220fac9135297bef62 Mon Sep 17 00:00:00 2001 From: Christian Jensen Date: Tue, 6 Apr 2021 08:13:34 +0200 Subject: [PATCH 5/5] Update FreeRTOS_IP.c Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com> --- FreeRTOS_IP.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FreeRTOS_IP.c b/FreeRTOS_IP.c index 7970566a95..f5cf42ab49 100644 --- a/FreeRTOS_IP.c +++ b/FreeRTOS_IP.c @@ -1174,7 +1174,7 @@ BaseType_t FreeRTOS_IPInit( const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) { static StaticQueue_t xNetworkEventStaticQueue; - uint8_t ucNetworkEventQueueStorageArea[ ipconfigEVENT_QUEUE_LENGTH * sizeof( IPStackEvent_t ) ]; + static uint8_t ucNetworkEventQueueStorageArea[ ipconfigEVENT_QUEUE_LENGTH * sizeof( IPStackEvent_t ) ]; xNetworkEventQueue = xQueueCreateStatic( ipconfigEVENT_QUEUE_LENGTH, sizeof( IPStackEvent_t ), ucNetworkEventQueueStorageArea, &xNetworkEventStaticQueue ); } #else