Skip to content

Commit

Permalink
[WIN32-MingW Demo] TickType_t width is defined based on compiler type…
Browse files Browse the repository at this point in the history
….(32bit/64bit) (FreeRTOS#1199)

* [WIN32-MingW Demo] Add tick type width definition based on compiler type.(32bit/64bit)
32bit TickType_t is used if compiler is MinGW32. 64bit TickType_t is used if compiler is MinGW64.

Reason of change: Before this change, 32bit TickType_t is always used in MinGW demo. It is inefficient  for 64bit compiler. In addition, MinGW64 reported warnings for the cast operation between TickType_t and (void *) pointer because of different width. 64bit TickType_t should be used instead of 32bit if compiler is 64bit.

* [WIN32-MingW Demo] Change printf() format specifiers from %u to %llu.

Reason of change: %u specifier corrupts 64bit tick count because it supports only 32bit value. %llu can be used for both of 64bit value and 32bit value.(After casting to 64bit)

* [WIN32-MingW Demo] Change type of some variables from uint32_t to UBaseType_t.

Reason of change: These variables are cast to/from pointer type in existing codes. 64bit compiler(MinGW64) reports warnings for the cast operations between uint32_t and pointer type. UBaseType_t solves those warnings because it has same width as pointer type on both of MinGW32 and MinGW64.

* [WIN32-MingW Demo] Change type of some variables from uint32_t to UBaseType_t.

Same change as previous commit is applied to source codes which are built only on Debug configuration.

* [WIN32-MingW Demo] Add brackets to the condition in #if statement. Behavior is not changed. Reason of change is to follow coding style guide of FreeRTOS.

* Update "FreeRTOS/Source" submodule(FreeRTOS-kernel) to FreeRTOS#1008.

* [WIN32-MingW Demo] Change type of one more variable from uint32_t to UBaseType_t.

Additional modification for solving compiler warnings for the cast operation on MinGW64.

* Update FreeRTOS-kernel submodule version in manifest.yml.

* Modify prefix of variables to follow coding style guide.

* Code review suggestions

Signed-off-by: Gaurav Aggarwal <[email protected]>

---------

Signed-off-by: Gaurav Aggarwal <[email protected]>
Co-authored-by: ActoryOu <[email protected]>
Co-authored-by: Gaurav-Aggarwal-AWS <[email protected]>
Co-authored-by: Gaurav Aggarwal <[email protected]>
  • Loading branch information
4 people authored Mar 27, 2024
1 parent 273fb94 commit 076430b
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 59 deletions.
15 changes: 13 additions & 2 deletions FreeRTOS/Demo/WIN32-MingW/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 100 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 12 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configCHECK_FOR_STACK_OVERFLOW 0
Expand All @@ -61,6 +60,14 @@
#define configUSE_TASK_NOTIFICATIONS 1
#define configSUPPORT_STATIC_ALLOCATION 1

/* Tick type width is defined based on the compiler type (32bit or 64bit). */
#ifdef __x86_64__
#define configTICK_TYPE_WIDTH_IN_BITS TICK_TYPE_WIDTH_64_BITS
#else
#define configTICK_TYPE_WIDTH_IN_BITS TICK_TYPE_WIDTH_32_BITS
#endif


/* Software timer related configuration options. The maximum possible task
priority is configMAX_PRIORITIES - 1. The priority of the timer task is
deliberately set higher to ensure it is correctly capped back to
Expand Down Expand Up @@ -135,7 +142,11 @@ used with multiple project configurations. If it is
#define mtCOVERAGE_TEST_MARKER() __asm volatile( "NOP" )

/* Ensure the tick count overflows during the coverage test. */
#define configINITIAL_TICK_COUNT 0xffffd800UL
#if( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_64_BITS )
#define configINITIAL_TICK_COUNT 0xffffffffffffd800ULL
#else
#define configINITIAL_TICK_COUNT 0xffffd800UL
#endif

/* Allows tests of trying to allocate more than the heap has free. */
#define configUSE_MALLOC_FAILED_HOOK 0
Expand Down
64 changes: 32 additions & 32 deletions FreeRTOS/Demo/WIN32-MingW/code_coverage_additions.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,58 +86,58 @@ static BaseType_t prvTimerQuery( void );

static BaseType_t prvStaticAllocationsWithNullBuffers( void )
{
uint32_t ulReturned = 0;
UBaseType_t uxReturned = 0;
BaseType_t xReturn = pdPASS;
UBaseType_t uxDummy = 10;

/* Don't expect to create any of the objects as a NULL parameter is always
passed in place of a required buffer. Hence if all passes then none of the
|= will be against 0, and ulReturned will still be zero at the end of this
|= will be against 0, and uxReturned will still be zero at the end of this
function. */
ulReturned |= ( uint32_t ) xEventGroupCreateStatic( NULL );
uxReturned |= ( UBaseType_t ) xEventGroupCreateStatic( NULL );

/* Try creating a task twice, once with puxStackBuffer NULL, and once with
pxTaskBuffer NULL. */
ulReturned |= ( uint32_t ) xTaskCreateStatic( NULL, /* Task to run, not needed as the task is not created. */
"Dummy", /* Task name. */
configMINIMAL_STACK_SIZE,
NULL,
tskIDLE_PRIORITY,
NULL,
( StaticTask_t * ) &xReturn ); /* Dummy value just to pass a non NULL value in - won't get used. */

ulReturned |= ( uint32_t ) xTaskCreateStatic( NULL, /* Task to run, not needed as the task is not created. */
"Dummy", /* Task name. */
configMINIMAL_STACK_SIZE,
NULL,
tskIDLE_PRIORITY,
( StackType_t * ) &xReturn, /* Dummy value just to pass a non NULL value in - won't get used. */
NULL );

ulReturned |= ( uint32_t ) xQueueCreateStatic( uxDummy,
uxDummy,
( uint8_t * ) &xReturn, /* Dummy value just to pass a non NULL value in - won't get used. */
NULL );
uxReturned |= ( UBaseType_t ) xTaskCreateStatic( NULL, /* Task to run, not needed as the task is not created. */
"Dummy", /* Task name. */
configMINIMAL_STACK_SIZE,
NULL,
tskIDLE_PRIORITY,
NULL,
( StaticTask_t * ) &xReturn ); /* Dummy value just to pass a non NULL value in - won't get used. */

uxReturned |= ( UBaseType_t ) xTaskCreateStatic( NULL, /* Task to run, not needed as the task is not created. */
"Dummy", /* Task name. */
configMINIMAL_STACK_SIZE,
NULL,
tskIDLE_PRIORITY,
( StackType_t * ) &xReturn, /* Dummy value just to pass a non NULL value in - won't get used. */
NULL );

uxReturned |= ( UBaseType_t ) xQueueCreateStatic( uxDummy,
uxDummy,
( uint8_t * ) &xReturn, /* Dummy value just to pass a non NULL value in - won't get used. */
NULL );

/* Try creating a stream buffer twice, once with pucStreamBufferStorageArea
set to NULL, and once with pxStaticStreamBuffer set to NULL. */
ulReturned |= ( uint32_t ) xStreamBufferCreateStatic( uxDummy,
uxDummy,
NULL,
( StaticStreamBuffer_t * ) &xReturn ); /* Dummy value just to pass a non NULL value in - won't get used. */
uxReturned |= ( UBaseType_t ) xStreamBufferCreateStatic( uxDummy,
uxDummy,
NULL,
( StaticStreamBuffer_t * ) &xReturn ); /* Dummy value just to pass a non NULL value in - won't get used. */

ulReturned |= ( uint32_t ) xStreamBufferCreateStatic( uxDummy,
uxDummy,
( uint8_t * ) &xReturn, /* Dummy value just to pass a non NULL value in - won't get used. */
NULL );
uxReturned |= ( UBaseType_t ) xStreamBufferCreateStatic( uxDummy,
uxDummy,
( uint8_t * ) &xReturn, /* Dummy value just to pass a non NULL value in - won't get used. */
NULL );

/* Try to create a task with a stack that is too large to be allocated. */
if( xTaskCreate( NULL, "TooLarge", configTOTAL_HEAP_SIZE, NULL, tskIDLE_PRIORITY, NULL ) != errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY )
{
xReturn = pdFAIL;
}

if( ulReturned != 0 )
if( uxReturned != 0 )
{
/* Something returned a non-NULL value. */
xReturn = pdFAIL;
Expand Down
51 changes: 28 additions & 23 deletions FreeRTOS/Demo/WIN32-MingW/main_full.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,19 +386,21 @@ static void prvCheckTask( void * pvParameters )
#endif /* configSUPPORT_STATIC_ALLOCATION */

/* This is the only task that uses stdout so its ok to call printf()
* directly. */
* directly. %llu (long long unsigned) format specifier is used here
* to support both 32-bit values on MinGW32 and 64-bit values on
* MinGW64. */
vPortGetHeapStats( &xHeapStats );

configASSERT( xHeapStats.xAvailableHeapSpaceInBytes == xPortGetFreeHeapSize() );
configASSERT( xHeapStats.xMinimumEverFreeBytesRemaining == xPortGetMinimumEverFreeHeapSize() );

printf( "%s - tick count %u - free heap %u - min free heap %u - largest free block %u - number of free blocks %u\r\n",
printf( "%s - tick count %llu - free heap %llu - min free heap %llu - largest free block %llu - number of free blocks %llu\r\n",
pcStatusMessage,
xTaskGetTickCount(),
xHeapStats.xAvailableHeapSpaceInBytes,
xHeapStats.xMinimumEverFreeBytesRemaining,
xHeapStats.xSizeOfLargestFreeBlockInBytes,
xHeapStats.xNumberOfFreeBlocks );
( uint64_t ) xTaskGetTickCount(),
( uint64_t ) xHeapStats.xAvailableHeapSpaceInBytes,
( uint64_t ) xHeapStats.xMinimumEverFreeBytesRemaining,
( uint64_t ) xHeapStats.xSizeOfLargestFreeBlockInBytes,
( uint64_t ) xHeapStats.xNumberOfFreeBlocks );

fflush( stdout );
}
Expand Down Expand Up @@ -554,21 +556,22 @@ void vFullDemoTickHookFunction( void )
static void prvPendedFunction( void * pvParameter1,
uint32_t ulParameter2 )
{
static uint32_t ulLastParameter1 = 1000UL, ulLastParameter2 = 0UL;
uint32_t ulParameter1;
static UBaseType_t uxLastParameter1 = 1000UL;
static uint32_t ulLastParameter2 = 0UL;
UBaseType_t uxParameter1;

ulParameter1 = ( uint32_t ) pvParameter1;
uxParameter1 = ( UBaseType_t ) pvParameter1;

/* Ensure the parameters are as expected. */
configASSERT( ulParameter1 == ( ulLastParameter1 + 1 ) );
configASSERT( uxParameter1 == ( uxLastParameter1 + 1 ) );
configASSERT( ulParameter2 == ( ulLastParameter2 + 1 ) );

/* Remember the parameters for the next time the function is called. */
ulLastParameter1 = ulParameter1;
uxLastParameter1 = uxParameter1;
ulLastParameter2 = ulParameter2;

/* Remove compiler warnings in case configASSERT() is not defined. */
( void ) ulLastParameter1;
( void ) uxLastParameter1;
( void ) ulLastParameter2;
}
/*-----------------------------------------------------------*/
Expand Down Expand Up @@ -622,17 +625,18 @@ static void prvDemonstrateTimerQueryFunctions( void )

static void prvDemonstratePendingFunctionCall( void )
{
static uint32_t ulParameter1 = 1000UL, ulParameter2 = 0UL;
static UBaseType_t uxParameter1 = 1000UL;
static uint32_t ulParameter2 = 0UL;
const TickType_t xDontBlock = 0; /* This is called from the idle task so must *not* attempt to block. */

/* prvPendedFunction() just expects the parameters to be incremented by one
* each time it is called. */

ulParameter1++;
uxParameter1++;
ulParameter2++;

/* Pend the function call, sending the parameters. */
xTimerPendFunctionCall( prvPendedFunction, ( void * ) ulParameter1, ulParameter2, xDontBlock );
xTimerPendFunctionCall( prvPendedFunction, ( void * ) uxParameter1, ulParameter2, xDontBlock );
}
/*-----------------------------------------------------------*/

Expand Down Expand Up @@ -869,12 +873,12 @@ static void prvPermanentlyBlockingNotificationTask( void * pvParameters )

static void prvReloadModeTestTimerCallback( TimerHandle_t xTimer )
{
uint32_t ulTimerID;
UBaseType_t uxTimerID;

/* Increment the timer's ID to show the callback has executed. */
ulTimerID = ( uint32_t ) pvTimerGetTimerID( xTimer );
ulTimerID++;
vTimerSetTimerID( xTimer, ( void * ) ulTimerID );
uxTimerID = ( UBaseType_t ) pvTimerGetTimerID( xTimer );
uxTimerID++;
vTimerSetTimerID( xTimer, ( void * ) uxTimerID );
}
/*-----------------------------------------------------------*/

Expand Down Expand Up @@ -906,15 +910,15 @@ static void prvDemonstrateChangingTimerReloadMode( void * pvParameters )
vTimerSetTimerID( xTimer, ( void * ) 0 );
xTimerStart( xTimer, portMAX_DELAY );
vTaskDelay( 3UL * x50ms );
configASSERT( ( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) ) == 1UL );
configASSERT( ( ( UBaseType_t ) ( pvTimerGetTimerID( xTimer ) ) ) == 1UL );

/* Now change the timer to be an auto-reload timer and check it executes
* the expected number of times. */
vTimerSetReloadMode( xTimer, pdTRUE );
vTimerSetTimerID( xTimer, ( void * ) 0 );
xTimerStart( xTimer, 0 );
vTaskDelay( ( 3UL * x50ms ) + ( x50ms / 2UL ) ); /* Three full periods. */
configASSERT( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) == 3UL );
configASSERT( ( UBaseType_t ) ( pvTimerGetTimerID( xTimer ) ) == 3UL );
configASSERT( xTimerStop( xTimer, 0 ) != pdFAIL );

/* Now change the timer back to be a one-shot timer and check it only
Expand All @@ -924,9 +928,10 @@ static void prvDemonstrateChangingTimerReloadMode( void * pvParameters )
xTimerStart( xTimer, 0 );
vTaskDelay( 3UL * x50ms );
configASSERT( xTimerStop( xTimer, 0 ) != pdFAIL );
configASSERT( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) == 1UL );
configASSERT( ( UBaseType_t ) ( pvTimerGetTimerID( xTimer ) ) == 1UL );

/* Clean up at the end. */
xTimerDelete( xTimer, portMAX_DELAY );
vTaskDelete( NULL );
}
/*-----------------------------------------------------------*/
2 changes: 1 addition & 1 deletion FreeRTOS/Source
Submodule Source updated 36 files
+10 −4 include/FreeRTOS.h
+83 −153 portable/ARMv8M/non_secure/portable/GCC/ARM_CM23/mpu_wrappers_v2_asm.c
+83 −153 portable/ARMv8M/non_secure/portable/GCC/ARM_CM23_NTZ/mpu_wrappers_v2_asm.c
+82 −152 portable/ARMv8M/non_secure/portable/GCC/ARM_CM33/mpu_wrappers_v2_asm.c
+82 −152 portable/ARMv8M/non_secure/portable/GCC/ARM_CM33_NTZ/mpu_wrappers_v2_asm.c
+70 −140 portable/ARMv8M/non_secure/portable/IAR/ARM_CM23/mpu_wrappers_v2_asm.S
+70 −140 portable/ARMv8M/non_secure/portable/IAR/ARM_CM23_NTZ/mpu_wrappers_v2_asm.S
+70 −140 portable/ARMv8M/non_secure/portable/IAR/ARM_CM33/mpu_wrappers_v2_asm.S
+70 −140 portable/ARMv8M/non_secure/portable/IAR/ARM_CM33_NTZ/mpu_wrappers_v2_asm.S
+83 −153 portable/GCC/ARM_CM23/non_secure/mpu_wrappers_v2_asm.c
+83 −153 portable/GCC/ARM_CM23_NTZ/non_secure/mpu_wrappers_v2_asm.c
+82 −152 portable/GCC/ARM_CM33/non_secure/mpu_wrappers_v2_asm.c
+82 −152 portable/GCC/ARM_CM33_NTZ/non_secure/mpu_wrappers_v2_asm.c
+82 −152 portable/GCC/ARM_CM35P/non_secure/mpu_wrappers_v2_asm.c
+82 −152 portable/GCC/ARM_CM35P_NTZ/non_secure/mpu_wrappers_v2_asm.c
+82 −152 portable/GCC/ARM_CM3_MPU/mpu_wrappers_v2_asm.c
+82 −152 portable/GCC/ARM_CM4_MPU/mpu_wrappers_v2_asm.c
+82 −152 portable/GCC/ARM_CM55/non_secure/mpu_wrappers_v2_asm.c
+82 −152 portable/GCC/ARM_CM55_NTZ/non_secure/mpu_wrappers_v2_asm.c
+82 −152 portable/GCC/ARM_CM85/non_secure/mpu_wrappers_v2_asm.c
+82 −152 portable/GCC/ARM_CM85_NTZ/non_secure/mpu_wrappers_v2_asm.c
+70 −140 portable/IAR/ARM_CM23/non_secure/mpu_wrappers_v2_asm.S
+70 −140 portable/IAR/ARM_CM23_NTZ/non_secure/mpu_wrappers_v2_asm.S
+70 −140 portable/IAR/ARM_CM33/non_secure/mpu_wrappers_v2_asm.S
+70 −140 portable/IAR/ARM_CM33_NTZ/non_secure/mpu_wrappers_v2_asm.S
+70 −140 portable/IAR/ARM_CM35P/non_secure/mpu_wrappers_v2_asm.S
+70 −140 portable/IAR/ARM_CM35P_NTZ/non_secure/mpu_wrappers_v2_asm.S
+70 −140 portable/IAR/ARM_CM4F_MPU/mpu_wrappers_v2_asm.S
+70 −140 portable/IAR/ARM_CM55/non_secure/mpu_wrappers_v2_asm.S
+70 −140 portable/IAR/ARM_CM55_NTZ/non_secure/mpu_wrappers_v2_asm.S
+70 −140 portable/IAR/ARM_CM85/non_secure/mpu_wrappers_v2_asm.S
+70 −140 portable/IAR/ARM_CM85_NTZ/non_secure/mpu_wrappers_v2_asm.S
+11 −0 portable/MSVC-MingW/port.c
+10 −1 portable/MSVC-MingW/portmacro.h
+70 −140 portable/RVDS/ARM_CM4_MPU/mpu_wrappers_v2_asm.c
+1 −1 portable/ThirdParty/GCC/RP2040/include/portmacro.h
2 changes: 1 addition & 1 deletion manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license: "MIT"

dependencies:
- name: "FreeRTOS-Kernel"
version: "30f6061f4"
version: "625b24a10"
repository:
type: "git"
url: "https://github.com/FreeRTOS/FreeRTOS-Kernel.git"
Expand Down

0 comments on commit 076430b

Please sign in to comment.