From 180f4d092917183fb27508f1ca7fb1eabf1b7d23 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 23 Nov 2016 09:42:35 +1100 Subject: [PATCH] FreeRTOS: Use C11 _Static_assert to verify static "dummy" structs at compile time Includes a tweak to make Static_task_t equal size to TCB_t when using MPU_WRAPPERS . Matches tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE macro in tasks.c. This isn't actually a bug (if static task allocation is off, there is no use for Static_task_t), but it allows us to make consistent compile-time checks that Static_task_t == TCB_t. --- components/freertos/include/freertos/FreeRTOS.h | 3 ++- components/freertos/include/freertos/list.h | 13 +++++++++++++ components/freertos/queue.c | 5 +++++ components/freertos/tasks.c | 4 ++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/components/freertos/include/freertos/FreeRTOS.h b/components/freertos/include/freertos/FreeRTOS.h index 67bdc6db12..4c60308f78 100644 --- a/components/freertos/include/freertos/FreeRTOS.h +++ b/components/freertos/include/freertos/FreeRTOS.h @@ -895,7 +895,8 @@ typedef struct xSTATIC_TCB uint32_t ulDummy18; uint32_t ucDummy19; #endif - #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) + #if( ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) \ + || ( portUSING_MPU_WRAPPERS == 1 ) ) uint8_t uxDummy20; #endif diff --git a/components/freertos/include/freertos/list.h b/components/freertos/include/freertos/list.h index b63df7f724..8606deba5a 100644 --- a/components/freertos/include/freertos/list.h +++ b/components/freertos/include/freertos/list.h @@ -190,6 +190,10 @@ struct xLIST_ITEM }; typedef struct xLIST_ITEM ListItem_t; /* For some reason lint wants this as two separate definitions. */ +#if __GNUC_PREREQ(4, 6) +_Static_assert(sizeof(StaticListItem_t) == sizeof(ListItem_t), "StaticListItem_t != ListItem_t"); +#endif + struct xMINI_LIST_ITEM { listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ @@ -199,6 +203,11 @@ struct xMINI_LIST_ITEM }; typedef struct xMINI_LIST_ITEM MiniListItem_t; +#if __GNUC_PREREQ(4, 6) +_Static_assert(sizeof(StaticMiniListItem_t) == sizeof(MiniListItem_t), "StaticMiniListItem_t != MiniListItem_t"); +#endif + + /* * Definition of the type of queue used by the scheduler. */ @@ -211,6 +220,10 @@ typedef struct xLIST listSECOND_LIST_INTEGRITY_CHECK_VALUE /*< Set to a known value if configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */ } List_t; +#if __GNUC_PREREQ(4, 6) +_Static_assert(sizeof(StaticList_t) == sizeof(List_t), "StaticList_t != List_t"); +#endif + /* * Access macro to set the owner of a list item. The owner of a list item * is the object (usually a TCB) that contains the list item. diff --git a/components/freertos/queue.c b/components/freertos/queue.c index f404a243e6..7c491f6952 100644 --- a/components/freertos/queue.c +++ b/components/freertos/queue.c @@ -179,6 +179,11 @@ typedef struct QueueDefinition name below to enable the use of older kernel aware debuggers. */ typedef xQUEUE Queue_t; +#if __GNUC_PREREQ(4, 6) +_Static_assert(sizeof(StaticQueue_t) == sizeof(Queue_t), "StaticQueue_t != Queue_t"); +#endif + + /*-----------------------------------------------------------*/ /* diff --git a/components/freertos/tasks.c b/components/freertos/tasks.c index 26103ee236..16cce3b967 100644 --- a/components/freertos/tasks.c +++ b/components/freertos/tasks.c @@ -242,6 +242,10 @@ typedef struct tskTaskControlBlock below to enable the use of older kernel aware debuggers. */ typedef tskTCB TCB_t; +#if __GNUC_PREREQ(4, 6) +_Static_assert(sizeof(StaticTask_t) == sizeof(TCB_t), "StaticTask_t != TCB_t"); +#endif + /* * Some kernel aware debuggers require the data the debugger needs access to to * be global, rather than file scope. -- 2.40.0