From 0c0f9f3f624021d52006486e2f4c5a11c2740e8c Mon Sep 17 00:00:00 2001 From: Rahul Kar Date: Thu, 18 Apr 2024 08:33:47 +0000 Subject: [PATCH 1/6] Fix UBaseType_t conversion in list.c --- list.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/list.c b/list.c index 87fa7aba30b..fc99538b24b 100644 --- a/list.c +++ b/list.c @@ -130,7 +130,7 @@ void vListInsertEnd( List_t * const pxList, /* Remember which list the item is in. */ pxNewListItem->pxContainer = pxList; - ( pxList->uxNumberOfItems ) += ( UBaseType_t ) 1U; + ( pxList->uxNumberOfItems ) = ( UBaseType_t ) ( pxList->uxNumberOfItems + 1U ); traceRETURN_vListInsertEnd(); } @@ -205,7 +205,7 @@ void vListInsert( List_t * const pxList, * item later. */ pxNewListItem->pxContainer = pxList; - ( pxList->uxNumberOfItems ) += ( UBaseType_t ) 1U; + ( pxList->uxNumberOfItems ) = ( UBaseType_t ) ( pxList->uxNumberOfItems + 1U ); traceRETURN_vListInsert(); } @@ -237,7 +237,7 @@ UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove ) } pxItemToRemove->pxContainer = NULL; - ( pxList->uxNumberOfItems ) -= ( UBaseType_t ) 1U; + ( pxList->uxNumberOfItems ) = ( UBaseType_t ) ( pxList->uxNumberOfItems - 1U ); traceRETURN_uxListRemove( pxList->uxNumberOfItems ); From 910891f21d0c24fa7992b8d843e6b685d9a2ebc1 Mon Sep 17 00:00:00 2001 From: Rahul Kar Date: Thu, 18 Apr 2024 08:42:13 +0000 Subject: [PATCH 2/6] Fix UBaseType_t conversion for increment and decrement operations --- include/list.h | 4 ++-- tasks.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/list.h b/include/list.h index 0de51bb5ae9..62a83a2278e 100644 --- a/include/list.h +++ b/include/list.h @@ -334,7 +334,7 @@ typedef struct xLIST } \ \ ( pxItemToRemove )->pxContainer = NULL; \ - ( ( pxList )->uxNumberOfItems ) -= ( UBaseType_t ) 1U; \ + ( ( pxList )->uxNumberOfItems ) = ( UBaseType_t ) ( ( ( pxList )->uxNumberOfItems ) - 1U ); \ } while( 0 ) /* @@ -381,7 +381,7 @@ typedef struct xLIST /* Remember which list the item is in. */ \ ( pxNewListItem )->pxContainer = ( pxList ); \ \ - ( ( pxList )->uxNumberOfItems ) += ( UBaseType_t ) 1U; \ + ( ( pxList )->uxNumberOfItems ) = ( UBaseType_t ) ( ( ( pxList )->uxNumberOfItems ) + 1U ); \ } while( 0 ) /* diff --git a/tasks.c b/tasks.c index 5cec846d0bb..1d473a78c98 100644 --- a/tasks.c +++ b/tasks.c @@ -255,7 +255,7 @@ pxTemp = pxDelayedTaskList; \ pxDelayedTaskList = pxOverflowDelayedTaskList; \ pxOverflowDelayedTaskList = pxTemp; \ - xNumOfOverflows += ( BaseType_t ) 1; \ + xNumOfOverflows = ( BaseType_t )( xNumOfOverflows + 1 ); \ prvResetNextTaskUnblockTime(); \ } while( 0 ) @@ -2022,7 +2022,7 @@ static void prvInitialiseNewTask( TaskFunction_t pxTaskCode, * updated. */ taskENTER_CRITICAL(); { - uxCurrentNumberOfTasks += ( UBaseType_t ) 1U; + uxCurrentNumberOfTasks = ( UBaseType_t ) ( uxCurrentNumberOfTasks + 1U ); if( pxCurrentTCB == NULL ) { @@ -3816,7 +3816,7 @@ void vTaskSuspendAll( void ) /* The scheduler is suspended if uxSchedulerSuspended is non-zero. An increment * is used to allow calls to vTaskSuspendAll() to nest. */ - uxSchedulerSuspended += ( UBaseType_t ) 1U; + uxSchedulerSuspended = ( UBaseType_t ) ( uxSchedulerSuspended + 1U ); /* Enforces ordering for ports and optimised compilers that may otherwise place * the above increment elsewhere. */ @@ -3969,7 +3969,7 @@ BaseType_t xTaskResumeAll( void ) * previous call to vTaskSuspendAll(). */ configASSERT( uxSchedulerSuspended != 0U ); - uxSchedulerSuspended -= ( UBaseType_t ) 1U; + uxSchedulerSuspended = ( UBaseType_t )( uxSchedulerSuspended - 1U ); portRELEASE_TASK_LOCK(); if( uxSchedulerSuspended == ( UBaseType_t ) 0U ) From 1ec813b158f1219ef9da5bf497932b068df8c05a Mon Sep 17 00:00:00 2001 From: Rahul Kar Date: Thu, 18 Apr 2024 08:45:58 +0000 Subject: [PATCH 3/6] Fix 'int' to 'BaseType_t' conversion issue --- tasks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks.c b/tasks.c index 1d473a78c98..acf303e7085 100644 --- a/tasks.c +++ b/tasks.c @@ -903,7 +903,7 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION; /* System idle tasks are being assigned a priority of tskIDLE_PRIORITY - 1 here. */ if( ( pxCurrentTCBs[ xCoreID ]->uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) != 0U ) { - xCurrentCoreTaskPriority = xCurrentCoreTaskPriority - 1; + xCurrentCoreTaskPriority = ( BaseType_t ) ( xCurrentCoreTaskPriority - 1 ); } if( ( taskTASK_IS_RUNNING( pxCurrentTCBs[ xCoreID ] ) != pdFALSE ) && ( xYieldPendings[ xCoreID ] == pdFALSE ) ) @@ -3594,7 +3594,7 @@ static BaseType_t prvCreateIdleTasks( void ) } else { - vApplicationGetPassiveIdleTaskMemory( &pxIdleTaskTCBBuffer, &pxIdleTaskStackBuffer, &uxIdleTaskStackSize, xCoreID - 1 ); + vApplicationGetPassiveIdleTaskMemory( &pxIdleTaskTCBBuffer, &pxIdleTaskStackBuffer, &uxIdleTaskStackSize, ( BaseType_t ) ( xCoreID - 1 ) ); } } #endif /* if ( configNUMBER_OF_CORES == 1 ) */ From cd2096abc1b31d1d29274deb467b61bc9a4f896e Mon Sep 17 00:00:00 2001 From: Rahul Kar Date: Thu, 18 Apr 2024 09:25:57 +0000 Subject: [PATCH 4/6] Fix formatting --- include/list.h | 46 +++++++++++++++++++++++----------------------- tasks.c | 4 ++-- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/list.h b/include/list.h index 62a83a2278e..b64450c72eb 100644 --- a/include/list.h +++ b/include/list.h @@ -322,19 +322,19 @@ typedef struct xLIST #define listREMOVE_ITEM( pxItemToRemove ) \ do { \ /* The list item knows which list it is in. Obtain the list from the list \ - * item. */ \ - List_t * const pxList = ( pxItemToRemove )->pxContainer; \ - \ - ( pxItemToRemove )->pxNext->pxPrevious = ( pxItemToRemove )->pxPrevious; \ - ( pxItemToRemove )->pxPrevious->pxNext = ( pxItemToRemove )->pxNext; \ - /* Make sure the index is left pointing to a valid item. */ \ - if( pxList->pxIndex == ( pxItemToRemove ) ) \ - { \ - pxList->pxIndex = ( pxItemToRemove )->pxPrevious; \ - } \ - \ - ( pxItemToRemove )->pxContainer = NULL; \ - ( ( pxList )->uxNumberOfItems ) = ( UBaseType_t ) ( ( ( pxList )->uxNumberOfItems ) - 1U ); \ + * item. */ \ + List_t * const pxList = ( pxItemToRemove )->pxContainer; \ + \ + ( pxItemToRemove )->pxNext->pxPrevious = ( pxItemToRemove )->pxPrevious; \ + ( pxItemToRemove )->pxPrevious->pxNext = ( pxItemToRemove )->pxNext; \ + /* Make sure the index is left pointing to a valid item. */ \ + if( pxList->pxIndex == ( pxItemToRemove ) ) \ + { \ + pxList->pxIndex = ( pxItemToRemove )->pxPrevious; \ + } \ + \ + ( pxItemToRemove )->pxContainer = NULL; \ + ( ( pxList )->uxNumberOfItems ) = ( UBaseType_t ) ( ( ( pxList )->uxNumberOfItems ) - 1U ); \ } while( 0 ) /* @@ -371,16 +371,16 @@ typedef struct xLIST \ /* Insert a new list item into ( pxList ), but rather than sort the list, \ * makes the new list item the last item to be removed by a call to \ - * listGET_OWNER_OF_NEXT_ENTRY(). */ \ - ( pxNewListItem )->pxNext = pxIndex; \ - ( pxNewListItem )->pxPrevious = pxIndex->pxPrevious; \ - \ - pxIndex->pxPrevious->pxNext = ( pxNewListItem ); \ - pxIndex->pxPrevious = ( pxNewListItem ); \ - \ - /* Remember which list the item is in. */ \ - ( pxNewListItem )->pxContainer = ( pxList ); \ - \ + * listGET_OWNER_OF_NEXT_ENTRY(). */ \ + ( pxNewListItem )->pxNext = pxIndex; \ + ( pxNewListItem )->pxPrevious = pxIndex->pxPrevious; \ + \ + pxIndex->pxPrevious->pxNext = ( pxNewListItem ); \ + pxIndex->pxPrevious = ( pxNewListItem ); \ + \ + /* Remember which list the item is in. */ \ + ( pxNewListItem )->pxContainer = ( pxList ); \ + \ ( ( pxList )->uxNumberOfItems ) = ( UBaseType_t ) ( ( ( pxList )->uxNumberOfItems ) + 1U ); \ } while( 0 ) diff --git a/tasks.c b/tasks.c index acf303e7085..2ec9d6d835f 100644 --- a/tasks.c +++ b/tasks.c @@ -255,7 +255,7 @@ pxTemp = pxDelayedTaskList; \ pxDelayedTaskList = pxOverflowDelayedTaskList; \ pxOverflowDelayedTaskList = pxTemp; \ - xNumOfOverflows = ( BaseType_t )( xNumOfOverflows + 1 ); \ + xNumOfOverflows = ( BaseType_t ) ( xNumOfOverflows + 1 ); \ prvResetNextTaskUnblockTime(); \ } while( 0 ) @@ -3969,7 +3969,7 @@ BaseType_t xTaskResumeAll( void ) * previous call to vTaskSuspendAll(). */ configASSERT( uxSchedulerSuspended != 0U ); - uxSchedulerSuspended = ( UBaseType_t )( uxSchedulerSuspended - 1U ); + uxSchedulerSuspended = ( UBaseType_t ) ( uxSchedulerSuspended - 1U ); portRELEASE_TASK_LOCK(); if( uxSchedulerSuspended == ( UBaseType_t ) 0U ) From 7e923ed682829d6006dcadc83394a13b6570673a Mon Sep 17 00:00:00 2001 From: Rahul Kar Date: Thu, 18 Apr 2024 10:10:36 +0000 Subject: [PATCH 5/6] Fix C90 errors for unsigned long long integers --- examples/cmake_example/CMakeLists.txt | 3 ++- include/event_groups.h | 8 ++++---- portable/template/portmacro.h | 2 +- tasks.c | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/cmake_example/CMakeLists.txt b/examples/cmake_example/CMakeLists.txt index bff9317de4a..7b31cc52a09 100644 --- a/examples/cmake_example/CMakeLists.txt +++ b/examples/cmake_example/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.15) - project(example) set(FREERTOS_KERNEL_PATH "../../") @@ -71,3 +70,5 @@ add_executable(${PROJECT_NAME} ) target_link_libraries(${PROJECT_NAME} freertos_kernel freertos_config) + +set_property(TARGET freertos_kernel PROPERTY C_STANDARD 90) \ No newline at end of file diff --git a/include/event_groups.h b/include/event_groups.h index 8ff26799b77..fd5655c5e12 100644 --- a/include/event_groups.h +++ b/include/event_groups.h @@ -50,10 +50,10 @@ #define eventWAIT_FOR_ALL_BITS ( ( uint32_t ) 0x04000000UL ) #define eventEVENT_BITS_CONTROL_BYTES ( ( uint32_t ) 0xff000000UL ) #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_64_BITS ) - #define eventCLEAR_EVENTS_ON_EXIT_BIT ( ( uint64_t ) 0x0100000000000000ULL ) - #define eventUNBLOCKED_DUE_TO_BIT_SET ( ( uint64_t ) 0x0200000000000000ULL ) - #define eventWAIT_FOR_ALL_BITS ( ( uint64_t ) 0x0400000000000000ULL ) - #define eventEVENT_BITS_CONTROL_BYTES ( ( uint64_t ) 0xff00000000000000ULL ) + #define eventCLEAR_EVENTS_ON_EXIT_BIT ( ( uint64_t ) 0x0100000000000000 ) + #define eventUNBLOCKED_DUE_TO_BIT_SET ( ( uint64_t ) 0x0200000000000000 ) + #define eventWAIT_FOR_ALL_BITS ( ( uint64_t ) 0x0400000000000000 ) + #define eventEVENT_BITS_CONTROL_BYTES ( ( uint64_t ) 0xff00000000000000 ) #endif /* if ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS ) */ /* *INDENT-OFF* */ diff --git a/portable/template/portmacro.h b/portable/template/portmacro.h index 1990532081c..3b5da0dd27f 100644 --- a/portable/template/portmacro.h +++ b/portable/template/portmacro.h @@ -40,7 +40,7 @@ typedef unsigned char UBaseType_t; #define portMAX_DELAY ( TickType_t ) 0xffffffffUL #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_64_BITS ) typedef uint64_t TickType_t; - #define portMAX_DELAY ( TickType_t ) 0xffffffffffffffffULL + #define portMAX_DELAY ( TickType_t ) 0xffffffffffffffff #else #error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width. #endif diff --git a/tasks.c b/tasks.c index 2ec9d6d835f..9092ca10323 100644 --- a/tasks.c +++ b/tasks.c @@ -295,7 +295,7 @@ #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS ) #define taskEVENT_LIST_ITEM_VALUE_IN_USE ( ( uint32_t ) 0x80000000UL ) #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_64_BITS ) - #define taskEVENT_LIST_ITEM_VALUE_IN_USE ( ( uint64_t ) 0x8000000000000000ULL ) + #define taskEVENT_LIST_ITEM_VALUE_IN_USE ( ( uint64_t ) 0x8000000000000000 ) #endif /* Indicates that the task is not actively running on any core. */ From e6bcec1969eb9f9c4c36aaf7f2f02b7372152d0a Mon Sep 17 00:00:00 2001 From: Rahul Kar Date: Thu, 18 Apr 2024 12:28:53 +0000 Subject: [PATCH 6/6] Code review suggestions --- include/event_groups.h | 16 ++++++++-------- tasks.c | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/event_groups.h b/include/event_groups.h index fd5655c5e12..09a5ab53ac1 100644 --- a/include/event_groups.h +++ b/include/event_groups.h @@ -40,15 +40,15 @@ * item value. It is important they don't clash with the * taskEVENT_LIST_ITEM_VALUE_IN_USE definition. */ #if ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS ) - #define eventCLEAR_EVENTS_ON_EXIT_BIT ( ( uint16_t ) 0x0100U ) - #define eventUNBLOCKED_DUE_TO_BIT_SET ( ( uint16_t ) 0x0200U ) - #define eventWAIT_FOR_ALL_BITS ( ( uint16_t ) 0x0400U ) - #define eventEVENT_BITS_CONTROL_BYTES ( ( uint16_t ) 0xff00U ) + #define eventCLEAR_EVENTS_ON_EXIT_BIT ( ( uint16_t ) 0x0100 ) + #define eventUNBLOCKED_DUE_TO_BIT_SET ( ( uint16_t ) 0x0200 ) + #define eventWAIT_FOR_ALL_BITS ( ( uint16_t ) 0x0400 ) + #define eventEVENT_BITS_CONTROL_BYTES ( ( uint16_t ) 0xff00 ) #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS ) - #define eventCLEAR_EVENTS_ON_EXIT_BIT ( ( uint32_t ) 0x01000000UL ) - #define eventUNBLOCKED_DUE_TO_BIT_SET ( ( uint32_t ) 0x02000000UL ) - #define eventWAIT_FOR_ALL_BITS ( ( uint32_t ) 0x04000000UL ) - #define eventEVENT_BITS_CONTROL_BYTES ( ( uint32_t ) 0xff000000UL ) + #define eventCLEAR_EVENTS_ON_EXIT_BIT ( ( uint32_t ) 0x01000000 ) + #define eventUNBLOCKED_DUE_TO_BIT_SET ( ( uint32_t ) 0x02000000 ) + #define eventWAIT_FOR_ALL_BITS ( ( uint32_t ) 0x04000000 ) + #define eventEVENT_BITS_CONTROL_BYTES ( ( uint32_t ) 0xff000000 ) #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_64_BITS ) #define eventCLEAR_EVENTS_ON_EXIT_BIT ( ( uint64_t ) 0x0100000000000000 ) #define eventUNBLOCKED_DUE_TO_BIT_SET ( ( uint64_t ) 0x0200000000000000 ) diff --git a/tasks.c b/tasks.c index 9092ca10323..7f808cc4fb8 100644 --- a/tasks.c +++ b/tasks.c @@ -291,9 +291,9 @@ * responsibility of whichever module is using the value to ensure it gets set back * to its original value when it is released. */ #if ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS ) - #define taskEVENT_LIST_ITEM_VALUE_IN_USE ( ( uint16_t ) 0x8000U ) + #define taskEVENT_LIST_ITEM_VALUE_IN_USE ( ( uint16_t ) 0x8000 ) #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS ) - #define taskEVENT_LIST_ITEM_VALUE_IN_USE ( ( uint32_t ) 0x80000000UL ) + #define taskEVENT_LIST_ITEM_VALUE_IN_USE ( ( uint32_t ) 0x80000000 ) #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_64_BITS ) #define taskEVENT_LIST_ITEM_VALUE_IN_USE ( ( uint64_t ) 0x8000000000000000 ) #endif