Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configRESET_TLS_BLOCK macro, adjust formatting. #652

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions include/FreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) */

Expand Down
38 changes: 31 additions & 7 deletions include/newlib-freertos.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
43 changes: 28 additions & 15 deletions include/picolibc-freertos.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) \
Expand All @@ -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 */