diff --git a/include/FreeRTOS.h b/include/FreeRTOS.h index f1ab32c6c1b..91fbf2fdd49 100644 --- a/include/FreeRTOS.h +++ b/include/FreeRTOS.h @@ -117,19 +117,23 @@ #if ( configUSE_C_RUNTIME_TLS_SUPPORT == 1 ) #ifndef configTLS_BLOCK_TYPE - #error Missing definition: configTLS_BLOCK_TYPE must be defined in FreeRTOSConfig.h when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1. + #error Missing definition: configTLS_BLOCK_TYPE must be defined when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1. #endif #ifndef configINIT_TLS_BLOCK - #error Missing definition: configINIT_TLS_BLOCK must be defined in FreeRTOSConfig.h when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1. + #error Missing definition: configINIT_TLS_BLOCK must be defined when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1. #endif #ifndef configSET_TLS_BLOCK - #error Missing definition: configSET_TLS_BLOCK must be defined in FreeRTOSConfig.h when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1. + #error Missing definition: configSET_TLS_BLOCK must be defined when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1. + #endif + + #ifndef configRESET_TLS_BLOCK + #error Missing definition: configRESET_TLS_BLOCK must be defined when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1. #endif #ifndef configDEINIT_TLS_BLOCK - #error Missing definition: configDEINIT_TLS_BLOCK must be defined in FreeRTOSConfig.h when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1. + #error Missing definition: configDEINIT_TLS_BLOCK must be defined when configUSE_C_RUNTIME_TLS_SUPPORT is set to 1. #endif #endif /* if ( configUSE_C_RUNTIME_TLS_SUPPORT == 1 ) */ diff --git a/include/newlib-freertos.h b/include/newlib-freertos.h index 497ca529990..7e9d366433a 100644 --- a/include/newlib-freertos.h +++ b/include/newlib-freertos.h @@ -45,18 +45,42 @@ #ifndef configTLS_BLOCK_TYPE #define configTLS_BLOCK_TYPE struct _reent -#endif +#endif /* configTLS_BLOCK_TYPE */ #ifndef configINIT_TLS_BLOCK - #define configINIT_TLS_BLOCK( xTLSBlock, pxTopOfStack ) _REENT_INIT_PTR( &( xTLSBlock ) ) -#endif + #define configINIT_TLS_BLOCK( xTLSBlock, pxTopOfStack ) \ + do \ + { \ + _REENT_INIT_PTR( &( xTLSBlock ) ); \ + } \ + while( 0 ) +#endif /* configINIT_TLS_BLOCK */ #ifndef configSET_TLS_BLOCK - #define configSET_TLS_BLOCK( xTLSBlock ) _impure_ptr = &( xTLSBlock ) -#endif + #define configSET_TLS_BLOCK( xTLSBlock ) \ + do \ + { \ + _impure_ptr = &( xTLSBlock ); \ + } \ + while( 0 ) +#endif /* configSET_TLS_BLOCK */ + +#ifndef configRESET_TLS_BLOCK + #define configRESET_TLS_BLOCK() \ + do \ + { \ + _impure_ptr = _global_impure_ptr; \ + } \ + while( 0 ) +#endif /* configRESET_TLS_BLOCK */ #ifndef configDEINIT_TLS_BLOCK - #define configDEINIT_TLS_BLOCK( xTLSBlock ) _reclaim_reent( &( xTLSBlock ) ) -#endif + #define configDEINIT_TLS_BLOCK( xTLSBlock ) \ + do \ + { \ + _reclaim_reent( &( xTLSBlock ) ); \ + } \ + while( 0 ) +#endif /* configDEINIT_TLS_BLOCK */ #endif /* INC_NEWLIB_FREERTOS_H */ diff --git a/include/picolibc-freertos.h b/include/picolibc-freertos.h index 467f7a97091..314725d5bfd 100644 --- a/include/picolibc-freertos.h +++ b/include/picolibc-freertos.h @@ -41,27 +41,31 @@ #define configUSE_C_RUNTIME_TLS_SUPPORT 1 -#define configTLS_BLOCK_TYPE void * +#ifndef configTLS_BLOCK_TYPE + #define configTLS_BLOCK_TYPE void * +#endif #define picolibcTLS_SIZE ( ( portPOINTER_SIZE_TYPE ) _tls_size() ) #define picolibcSTACK_ALIGNMENT_MASK ( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) +/* + * Picolibc 1.8 and newer have explicit alignment values provided + * by the _tls_align() inline + */ #if __PICOLIBC_MAJOR__ > 1 || __PICOLIBC_MINOR__ >= 8 - -/* Picolibc 1.8 and newer have explicit alignment values provided - * by the _tls_align() inline */ #define picolibcTLS_ALIGNMENT_MASK ( ( portPOINTER_SIZE_TYPE ) ( _tls_align() - 1 ) ) -#else /* For older Picolibc versions, use the general port alignment value */ +#else #define picolibcTLS_ALIGNMENT_MASK ( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) #endif -/* Allocate thread local storage block off the end of the -* stack. The _tls_size() function returns the size (in -* bytes) of the total TLS area used by the application */ -#if ( portSTACK_GROWTH < 0 ) - +/* + * Allocate thread local storage block off the end of the + * stack. The _tls_size() function returns the size (in + * bytes) of the total TLS area used by the application. + */ +#if ( !defined( configINIT_TLS_BLOCK ) ) && ( portSTACK_GROWTH == -1 ) #define configINIT_TLS_BLOCK( xTLSBlock, pxTopOfStack ) \ do { \ pxTopOfStack = ( StackType_t * ) ( ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack ) \ @@ -71,20 +75,29 @@ xTLSBlock = pxTopOfStack; \ _init_tls( xTLSBlock ); \ } while( 0 ) -#else /* portSTACK_GROWTH */ + +#elif ( !defined( configINIT_TLS_BLOCK ) ) && ( portSTACK_GROWTH == 1 ) #define configINIT_TLS_BLOCK( xTLSBlock, pxTopOfStack ) \ do { \ xTLSBlock = ( void * ) ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack + \ picolibcTLS_ALIGNMENT_MASK ) & ~picolibcTLS_ALIGNMENT_MASK ); \ pxTopOfStack = ( StackType_t * ) ( ( ( ( ( portPOINTER_SIZE_TYPE ) xTLSBlock ) + \ picolibcTLS_SIZE ) + picolibcSTACK_ALIGNMENT_MASK ) & \ - ~picolibcSTACK_ALIGNMENT_MASK ); \ + ( ~picolibcSTACK_ALIGNMENT_MASK ) ); \ _init_tls( xTLSBlock ); \ } while( 0 ) -#endif /* portSTACK_GROWTH */ +#endif /* !configINIT_TLS_BLOCK && portSTACK_GROWTH */ + +#ifndef configSET_TLS_BLOCK + #define configSET_TLS_BLOCK( xTLSBlock ) _set_tls( xTLSBlock ) +#endif /* configSET_TLS_BLOCK */ -#define configSET_TLS_BLOCK( xTLSBlock ) _set_tls( xTLSBlock ) +#ifndef configRESET_TLS_BLOCK + #define configRESET_TLS_BLOCK( xTLSBlock ) +#endif /* configRESET_TLS_BLOCK */ -#define configDEINIT_TLS_BLOCK( xTLSBlock ) +#ifndef configDEINIT_TLS_BLOCK + #define configDEINIT_TLS_BLOCK( xTLSBlock ) +#endif /* configDEINIT_TLS_BLOCK */ #endif /* INC_PICOLIBC_FREERTOS_H */