From c6487d94726e204b09c8bd98aba2e1ce9fd6011e Mon Sep 17 00:00:00 2001 From: Tony Josi Date: Thu, 18 Apr 2024 14:42:53 +0530 Subject: [PATCH 1/3] Fix build with C90 (#1036) * Fix build with C90 * Fix formatting --- include/task.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/task.h b/include/task.h index 08452a9b2..f98d84cf2 100644 --- a/include/task.h +++ b/include/task.h @@ -180,9 +180,10 @@ typedef struct xTASK_STATUS /* Possible return values for eTaskConfirmSleepModeStatus(). */ typedef enum { - eAbortSleep = 0, /* A task has been made ready or a context switch pended since portSUPPRESS_TICKS_AND_SLEEP() was called - abort entering a sleep mode. */ - eStandardSleep, /* Enter a sleep mode that will not last any longer than the expected idle time. */ + eAbortSleep = 0, /* A task has been made ready or a context switch pended since portSUPPRESS_TICKS_AND_SLEEP() was called - abort entering a sleep mode. */ + eStandardSleep /* Enter a sleep mode that will not last any longer than the expected idle time. */ #if ( INCLUDE_vTaskSuspend == 1 ) + , eNoTasksWaitingTimeout /* No tasks are waiting for a timeout so it is safe to enter a sleep mode that can only be exited by an external interrupt. */ #endif /* INCLUDE_vTaskSuspend */ } eSleepModeStatus; From e143832ad41bcee55cb8103aa82944534225fd3a Mon Sep 17 00:00:00 2001 From: Devaraj Ranganna Date: Thu, 18 Apr 2024 13:25:14 +0100 Subject: [PATCH 2/3] tf-m: Update tf-m to TF-Mv2.0.0 release (#1038) The `portable/ThirdParty/GCC/ARM_TFM/README.md` and `portable/ThirdParty/GCC/ARM_TFM/os_wrapper_freertos.c` are updated to support `TF-Mv2.0.0` of trusted-firmware-m release. Signed-off-by: Devaraj Ranganna --- portable/ThirdParty/GCC/ARM_TFM/README.md | 38 +++++++++---------- .../GCC/ARM_TFM/os_wrapper_freertos.c | 6 +-- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/portable/ThirdParty/GCC/ARM_TFM/README.md b/portable/ThirdParty/GCC/ARM_TFM/README.md index ae2962447..7df149f54 100644 --- a/portable/ThirdParty/GCC/ARM_TFM/README.md +++ b/portable/ThirdParty/GCC/ARM_TFM/README.md @@ -7,16 +7,17 @@ platform. The Platform Security Architecture (PSA) makes it quicker, easier and cheaper to design security into a device from the ground up. PSA is made up of four key -stages: analyze, architect, implement, and certify. See [PSA Resource Page](https://developer.arm.com/architectures/security-architectures/platform-security-architecture). +stages: analyze, architect, implement, and certify. See [PSA Resource Page](https://www.arm.com/architecture/security-features/platform-security). TF-M is an open source project. It provides a reference implementation of PSA -for Arm M-profile architecture. Please get the details from this [link](https://www.trustedfirmware.org/about/). +for Arm M-profile architecture. Please get the details from this [link](https://www.trustedfirmware.org/projects/tf-m/). # Derivation of the source code -* ```os_wrapper_freertos.c``` - The implementation of APIs which are defined in ```\ns_interface\os_wrapper\mutex.h``` by tf-m-tests - (tag: TF-Mv1.5.0 & TF-Mv1.6.0). The implementation is based on FreeRTOS mutex type semaphore. +* `os_wrapper_freertos.c` + The implementation of APIs which are defined in `/interface/include/os_wrapper/mutex.h` + in trusted-firmware-m (tag: TF-Mv2.0.0). The implementation is based on + FreeRTOS mutex type semaphore. # Usage notes @@ -28,53 +29,52 @@ To build a project based on this port: ### Get the TF-M source code -See the [link](https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git/) to get the source code. This port is supported by TF-M version **tag: TF-Mv1.5.0** & **tag: TF-Mv1.6.0**. +See the [link](https://git.trustedfirmware.org/TF-M/trusted-firmware-m.git/) to get the source code. This port is supported by TF-M version **tag: TF-Mv2.0.0**. ### Build TF-M -Please refer to this [link](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/tfm/building/tfm_build_instruction.html) to build the secure side. -_**Note:** ```TFM_NS_MANAGE_NSID``` must be configured as "OFF" when building TF-M_. +Please refer to this [link](https://trustedfirmware-m.readthedocs.io/en/latest/getting_started/) to build the secure side. +_**Note:** `TFM_NS_MANAGE_NSID` must be configured as "OFF" when building TF-M_. ## Build the Non-Secure Side -Please copy all the files in ```freertos_kernel\portable\GCC\ARM_CM[23|33|55|85]_NTZ``` into the ```freertos_kernel\portable\ThirdParty\GCC\ARM_TFM``` folder before using this port. Note that TrustZone is enabled in this port. The TF-M runs in the Secure Side. +Please copy all the files in `freertos_kernel/portable/GCC/ARM_CM[23|33|55|85]_NTZ` into the `freertos_kernel/portable/ThirdParty/GCC/ARM_TFM` folder before using this port. Note that TrustZone is enabled in this port. The TF-M runs in the Secure Side. -Please call the API ```tfm_ns_interface_init()``` which is defined in ```\app\tfm_ns_interface.c``` by tf-m-tests -(tag: TF-Mv1.5.0 & TF-Mv1.6.0) at the very beginning of your application. Otherwise, it will always fail when calling a TF-M service in the Nonsecure Side. +Please call the API `tfm_ns_interface_init()` which is defined in `/interface/src/os_wrapper/tfm_ns_interface_rtos.c` by trusted-firmware-m (tag: TF-Mv2.0.0) at the very beginning of your application. Otherwise, it will always fail when calling a TF-M service in the Nonsecure Side. ### Configuration in FreeRTOS kernel -* ```configRUN_FREERTOS_SECURE_ONLY``` +* `configRUN_FREERTOS_SECURE_ONLY` This macro should be configured as 0. In this port, TF-M runs in the Secure Side while FreeRTOS Kernel runs in the Non-Secure Side. -* ```configENABLE_FPU``` +* `configENABLE_FPU` The setting of this macro is decided by the setting in Secure Side which is platform-specific. If the Secure Side enables Non-Secure access to FPU, then this macro can be configured as 0 or 1. Otherwise, this macro can only be configured as 0. Please note that Cortex-M23 does not support FPU. Please refer to [TF-M documentation](https://tf-m-user-guide.trustedfirmware.org/integration_guide/tfm_fpu_support.html) for FPU usage on the Non-Secure side. -* ```configENABLE_MVE``` +* `configENABLE_MVE` The setting of this macro is decided by the setting in Secure Side which is platform-specific. If the Secure Side enables Non-Secure access to MVE, then this macro can be configured as 0 or 1. Otherwise, this macro can only be configured as 0. Please note that only Cortex-M55 and Cortex-M85 support MVE. Please refer to [TF-M documentation](https://tf-m-user-guide.trustedfirmware.org/integration_guide/tfm_fpu_support.html) for MVE usage on the Non-Secure side. -* ```configENABLE_TRUSTZONE``` +* `configENABLE_TRUSTZONE` This macro should be configured as 0 because TF-M doesn't use the secure context management function of FreeRTOS. New secure context management might be introduced when TF-M supports multiple secure context. ### Integrate TF-M Non-Secure interface with FreeRTOS project To enable calling TF-M services by the Non-Secure Side, the files below should be included in the FreeRTOS project and built together. -* files in ```trusted-firmware-m\build\install\interface\src``` +* files in `trusted-firmware-m/build/api_ns/interface/src` These files contain the implementation of PSA Functional Developer APIs which can be called by Non-Secure Side directly and PSA Firmware Framework APIs in the IPC model. These files should be taken as part of the Non-Secure source code. -* files in ```trusted-firmware-m\build\install\interface\include``` +* files in `trusted-firmware-m/build/api_ns/interface/include` These files are the necessary header files to call TF-M services. -* ```trusted-firmware-m\build\install\interface\lib\s_veneers.o``` +* `trusted-firmware-m/build/api_ns/interface/lib/s_veneers.o` This object file contains all the Non-Secure callable functions exported by TF-M and it should be linked when generating the Non-Secure image. -*Copyright (c) 2020-2022, Arm Limited. All rights reserved.* +*Copyright (c) 2020-2024, Arm Limited. All rights reserved.* diff --git a/portable/ThirdParty/GCC/ARM_TFM/os_wrapper_freertos.c b/portable/ThirdParty/GCC/ARM_TFM/os_wrapper_freertos.c index 8eb453930..35add2b5a 100644 --- a/portable/ThirdParty/GCC/ARM_TFM/os_wrapper_freertos.c +++ b/portable/ThirdParty/GCC/ARM_TFM/os_wrapper_freertos.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020, Arm Limited. All rights reserved. + * Copyright (c) 2019-2024, Arm Limited. All rights reserved. * * SPDX-License-Identifier: MIT * @@ -24,8 +24,8 @@ /* * This file contains the implementation of APIs which are defined in - * os_wrapper/mutex.h by TF-M(tag: TF-Mv1.1). The implementation is based - * on FreeRTOS mutex type semaphore. + * \interface/include/os_wrapper/mutex.h by TF-M(tag: TF-Mv2.0.0). + * The implementation is based on FreeRTOS mutex type semaphore. */ #include "os_wrapper/mutex.h" From bbc058967be6446f5e4cf486cad736856b53dd69 Mon Sep 17 00:00:00 2001 From: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com> Date: Thu, 18 Apr 2024 19:08:51 +0530 Subject: [PATCH 3/3] Fix cmake example errors (#1037) Add typecasts to prevent compiler warnings. Remove ULL suffix to adhere to C90. --- examples/cmake_example/CMakeLists.txt | 3 +- include/event_groups.h | 24 +++++++------- include/list.h | 48 +++++++++++++-------------- list.c | 6 ++-- portable/template/portmacro.h | 2 +- tasks.c | 18 +++++----- 6 files changed, 51 insertions(+), 50 deletions(-) diff --git a/examples/cmake_example/CMakeLists.txt b/examples/cmake_example/CMakeLists.txt index bff9317de..7b31cc52a 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 8ff26799b..09a5ab53a 100644 --- a/include/event_groups.h +++ b/include/event_groups.h @@ -40,20 +40,20 @@ * 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 ) 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/include/list.h b/include/list.h index 0de51bb5a..b64450c72 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 ) 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,17 +371,17 @@ 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 ); \ - \ - ( ( pxList )->uxNumberOfItems ) += ( UBaseType_t ) 1U; \ + * 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/list.c b/list.c index 87fa7aba3..fc99538b2 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 ); diff --git a/portable/template/portmacro.h b/portable/template/portmacro.h index 199053208..3b5da0dd2 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 5cec846d0..7f808cc4f 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 ) @@ -291,11 +291,11 @@ * 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 ) 0x8000000000000000ULL ) + #define taskEVENT_LIST_ITEM_VALUE_IN_USE ( ( uint64_t ) 0x8000000000000000 ) #endif /* Indicates that the task is not actively running on any core. */ @@ -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 ) ) @@ -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 ) { @@ -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 ) */ @@ -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 )