From: richardbarry Date: Wed, 26 Jun 2013 11:37:08 +0000 (+0000) Subject: Add Newlib reent support. X-Git-Tag: V7.5.0~38 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=da1b35c3274266e2328c952b78b969206f11d8ac;p=freertos Add Newlib reent support. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1952 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- diff --git a/FreeRTOS/Source/include/FreeRTOS.h b/FreeRTOS/Source/include/FreeRTOS.h index 852e24c79..060523fee 100644 --- a/FreeRTOS/Source/include/FreeRTOS.h +++ b/FreeRTOS/Source/include/FreeRTOS.h @@ -576,6 +576,10 @@ typedef portBASE_TYPE (*pdTASK_HOOK_CODE)( void * ); #define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 0 #endif +#ifndef configUSE_NEWLIB_REENTRANT + #define configUSE_NEWLIB_REENTRANT 0 +#endif + /* For backward compatability. */ #define eTaskStateGet eTaskGetState diff --git a/FreeRTOS/Source/tasks.c b/FreeRTOS/Source/tasks.c index e4e42c5a3..b8dd771ca 100644 --- a/FreeRTOS/Source/tasks.c +++ b/FreeRTOS/Source/tasks.c @@ -146,6 +146,14 @@ typedef struct tskTaskControlBlock unsigned long ulRunTimeCounter; /*< Stores the amount of time the task has spent in the Running state. */ #endif + #if ( configUSE_NEWLIB_REENTRANT == 1 ) + /* Allocate a Newlib reent structure that is specific to this task. + Note Newlib support has been included by popular demand, but is not + used by the FreeRTOS maintainers themselves, and therefore receives + less rigorous testing than the rest of the FreeRTOS code. */ + struct _reent xNewLib_reent; + #endif + } tskTCB; @@ -1858,6 +1866,14 @@ void vTaskSwitchContext( void ) taskSELECT_HIGHEST_PRIORITY_TASK(); traceTASK_SWITCHED_IN(); + + #if ( configUSE_NEWLIB_REENTRANT == 1 ) + { + /* Switch Newlib's _impure_ptr variable to point to the _reent + structure specific to this task. */ + _impure_ptr = &( pxCurrentTCB->xNewLib_reent ); + } + #endif /* configUSE_NEWLIB_REENTRANT */ } } /*-----------------------------------------------------------*/ @@ -2319,6 +2335,13 @@ portBASE_TYPE x; ( void ) usStackDepth; } #endif /* portUSING_MPU_WRAPPERS */ + + #if ( configUSE_NEWLIB_REENTRANT == 1 ) + { + /* Initialise this task's Newlib reent structure. */ + _REENT_INIT_PTR( ( &( pxTCB->xNewLib_reent ) ) ); + } + #endif /* configUSE_NEWLIB_REENTRANT */ } /*-----------------------------------------------------------*/