From c6325a02ff6f5ca680f41ad9c8a91b071ff668c8 Mon Sep 17 00:00:00 2001 From: Paul Bartell Date: Mon, 20 Mar 2023 11:05:53 -0700 Subject: Improve vAssertCalled function to include filename / line number info. --- .../Demo/CORTEX_M3_MPS2_QEMU_GCC/FreeRTOSConfig.h | 20 ++++++-- FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c | 55 +++++++++++----------- 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/FreeRTOSConfig.h b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/FreeRTOSConfig.h index 5455d1bcf..c312f4272 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/FreeRTOSConfig.h +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/FreeRTOSConfig.h @@ -39,13 +39,25 @@ * See https://www.freertos.org/a00110.html *----------------------------------------------------------*/ -#define configASSERT_DEFINED 1 -extern void vAssertCalled( void ); -#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled() +#define configASSERT_DEFINED 1 + +extern void vAssertCalled( const char * pcFileName, + int line ); + +#define __NAME_ARG__ ( __builtin_strrchr( __BASE_FILE__, '/' ) ? __builtin_strrchr( __BASE_FILE__, '/' ) + 1 : __BASE_FILE__ ) + +#define configASSERT( x ) \ + do { \ + if( ( x ) == 0 ) { \ + vAssertCalled( __NAME_ARG__, __LINE__ ); \ + } \ + } while( 0 ) + + #define configQUEUE_REGISTRY_SIZE 20 #ifdef PICOLIBC_TLS -#define configUSE_PICOLIBC_TLS 1 + #define configUSE_PICOLIBC_TLS 1 #endif #define configUSE_PREEMPTION 1 diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c index 9b534f38d..a8dd1e608 100644 --- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c +++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c @@ -32,6 +32,7 @@ #include #include #include +#include void vApplicationStackOverflowHook( TaskHandle_t pxTask, char * pcTaskName ); @@ -56,17 +57,17 @@ StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ]; int main() { #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 ) - { - main_blinky(); - } + { + main_blinky(); + } #elif ( mainCREATE_FULL_DEMO_ONLY == 1 ) - { - main_full(); - } + { + main_full(); + } #else - { - #error "Invalid Selection...\nPlease Select a Demo application from the main command" - } + { + #error "Invalid Selection...\nPlease Select a Demo application from the main command" + } #endif /* if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 ) */ return 0; } @@ -108,11 +109,11 @@ void vApplicationStackOverflowHook( TaskHandle_t pxTask, void vApplicationIdleHook( void ) { #if ( mainCREATE_FULL_DEMO_ONLY == 1 ) - { - /* Call the idle task processing used by the full demo. The simple - * blinky demo does not use the idle task hook. */ - vFullDemoIdleFunction(); - } + { + /* Call the idle task processing used by the full demo. The simple + * blinky demo does not use the idle task hook. */ + vFullDemoIdleFunction(); + } #endif } /*-----------------------------------------------------------*/ @@ -120,28 +121,28 @@ void vApplicationIdleHook( void ) void vApplicationTickHook( void ) { #if ( mainCREATE_FULL_DEMO_ONLY == 1 ) - { - vFullDemoTickHookFunction(); - } + { + vFullDemoTickHookFunction(); + } #endif /* mainSELECTED_APPLICATION */ } + /*-----------------------------------------------------------*/ -void vAssertCalled( void ) +void vAssertCalled( const char * pcFileName, + int line ) { - volatile unsigned long looping = 0; + printf( "Assertion failed at %s: %d\n", pcFileName, line ); + fflush( NULL ); - taskENTER_CRITICAL(); + while( 1 ) { - /* Use the debugger to set ul to a non-zero value in order to step out - * of this function to determine why it was called. */ - while( looping == 0LU ) - { - portNOP(); - } + asm ( "nop" ); } - taskEXIT_CRITICAL(); + + exit( 1 ); } + /*-----------------------------------------------------------*/ void vLoggingPrintf( const char * pcFormat, ... ) -- cgit v1.2.1