/*\r
- * FreeRTOS Kernel V10.0.1\r
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
+ * FreeRTOS Kernel V10.1.0\r
+ * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
*\r
* Permission is hereby granted, free of charge, to any person obtaining a copy of\r
* this software and associated documentation files (the "Software"), to deal in\r
* and stores task state information, including a pointer to the task's context\r
* (the task's run time environment, including register values)\r
*/\r
-typedef struct xTaskControlBlock\r
+typedef struct tskTaskControlBlock\r
{\r
volatile StackType_t *pxTopOfStack; /*< Points to the location of the last item placed on the tasks stack. THIS MUST BE THE FIRST MEMBER OF THE TCB STRUCT. */\r
\r
uint8_t ucDelayAborted;\r
#endif\r
\r
+ #if( configUSE_POSIX_ERRNO == 1 )\r
+ int iTaskErrno;\r
+ #endif\r
+\r
} tskTCB;\r
\r
/* The old tskTCB name is maintained above then typedefed to the new TCB_t name\r
\r
/* Lists for ready and blocked tasks. --------------------*/\r
PRIVILEGED_DATA static List_t pxReadyTasksLists[ configMAX_PRIORITIES ];/*< Prioritised ready tasks. */\r
+PRIVILEGED_DATA static List_t xDelayedTaskList1; /*< Delayed tasks. */\r
+PRIVILEGED_DATA static List_t xDelayedTaskList2; /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */\r
PRIVILEGED_DATA static List_t * volatile pxDelayedTaskList; /*< Points to the delayed task list currently being used. */\r
PRIVILEGED_DATA static List_t * volatile pxOverflowDelayedTaskList; /*< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */\r
PRIVILEGED_DATA static List_t xPendingReadyList; /*< Tasks that have been readied while the scheduler was suspended. They will be moved to the ready list when the scheduler is resumed. */\r
\r
#endif\r
\r
+/* Global POSIX errno. Its value is changed upon context switching to match\r
+the errno of the currently running task. */\r
+#if ( configUSE_POSIX_ERRNO == 1 )\r
+ int FreeRTOS_errno = 0;\r
+#endif\r
+\r
/* Other file private variables. --------------------------------*/\r
PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType_t ) 0U;\r
PRIVILEGED_DATA static volatile TickType_t xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT;\r
accessed from a critical section. */\r
PRIVILEGED_DATA static volatile UBaseType_t uxSchedulerSuspended = ( UBaseType_t ) pdFALSE;\r
\r
+#if ( configGENERATE_RUN_TIME_STATS == 1 )\r
+\r
+ PRIVILEGED_DATA static uint32_t ulTaskSwitchedInTime = 0UL; /*< Holds the value of a timer/counter the last time a task was switched in. */\r
+ PRIVILEGED_DATA static uint32_t ulTotalRunTime = 0UL; /*< Holds the total amount of execution time as defined by the run time counter clock. */\r
+\r
+#endif\r
+\r
/*lint -restore */\r
\r
/*-----------------------------------------------------------*/\r
}\r
else\r
{\r
- xTCB = ( TCB_t * ) xTask;\r
+ xTCB = xTask;\r
}\r
\r
/* Save the hook function in the TCB. A critical section is required as\r
/* If xTask is NULL then we are calling our own task hook. */\r
if( xTask == NULL )\r
{\r
- xTCB = ( TCB_t * ) pxCurrentTCB;\r
+ xTCB = pxCurrentTCB;\r
}\r
else\r
{\r
\r
#if ( configGENERATE_RUN_TIME_STATS == 1 )\r
{\r
- PRIVILEGED_DATA static uint32_t ulTaskSwitchedInTime = 0UL; /*< Holds the value of a timer/counter the last time a task was switched in. */\r
- PRIVILEGED_DATA static uint32_t ulTotalRunTime = 0UL; /*< Holds the total amount of execution time as defined by the run time counter clock. */\r
-\r
#ifdef portALT_GET_RUN_TIME_COUNTER_VALUE\r
portALT_GET_RUN_TIME_COUNTER_VALUE( ulTotalRunTime );\r
#else\r
/* Check for stack overflow, if configured. */\r
taskCHECK_FOR_STACK_OVERFLOW();\r
\r
+ /* Before the currently running task is switched out, save its errno. */\r
+ #if( configUSE_POSIX_ERRNO == 1 )\r
+ {\r
+ pxCurrentTCB->iTaskErrno = FreeRTOS_errno;\r
+ }\r
+ #endif\r
+\r
/* Select a new task to run using either the generic C or port\r
optimised asm code. */\r
taskSELECT_HIGHEST_PRIORITY_TASK(); /*lint !e9079 void * is used as this macro is used with timers and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */\r
traceTASK_SWITCHED_IN();\r
\r
+ /* After the new task is switched in, update the global errno. */\r
+ #if( configUSE_POSIX_ERRNO == 1 )\r
+ {\r
+ FreeRTOS_errno = pxCurrentTCB->iTaskErrno;\r
+ }\r
+ #endif\r
+\r
#if ( configUSE_NEWLIB_REENTRANT == 1 )\r
{\r
/* Switch Newlib's _impure_ptr variable to point to the _reent\r
\r
if( xTask != NULL )\r
{\r
- pxTCB = ( TCB_t * ) xTask;\r
+ pxTCB = xTask;\r
uxReturn = pxTCB->uxTaskNumber;\r
}\r
else\r
\r
if( xTask != NULL )\r
{\r
- pxTCB = ( TCB_t * ) xTask;\r
+ pxTCB = xTask;\r
pxTCB->uxTaskNumber = uxHandle;\r
}\r
}\r
static void prvInitialiseTaskLists( void )\r
{\r
UBaseType_t uxPriority;\r
-PRIVILEGED_DATA static List_t xDelayedTaskList1; /*< Delayed tasks. */\r
-PRIVILEGED_DATA static List_t xDelayedTaskList2; /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */\r
\r
for( uxPriority = ( UBaseType_t ) 0U; uxPriority < ( UBaseType_t ) configMAX_PRIORITIES; uxPriority++ )\r
{\r
\r
/* Write the rest of the string. */\r
sprintf( pcWriteBuffer, "\t%c\t%u\t%u\t%u\r\n", cStatus, ( unsigned int ) pxTaskStatusArray[ x ].uxCurrentPriority, ( unsigned int ) pxTaskStatusArray[ x ].usStackHighWaterMark, ( unsigned int ) pxTaskStatusArray[ x ].xTaskNumber ); /*lint !e586 sprintf() allowed as this is compiled with many compilers and this is a utility function only - not part of the core kernel implementation. */\r
- pcWriteBuffer += strlen( pcWriteBuffer ); /*lint !e9016 Pointer arithmetic ok on char pointers. */\r
+ pcWriteBuffer += strlen( pcWriteBuffer ); /*lint !e9016 Pointer arithmetic ok on char pointers especially as in this case where it best denotes the intent of the code. */\r
}\r
\r
/* Free the array again. NOTE! If configSUPPORT_DYNAMIC_ALLOCATION\r
#endif\r
}\r
\r
- pcWriteBuffer += strlen( pcWriteBuffer ); /*lint !e9016 Pointer arithmetic ok on char pointers. */\r
+ pcWriteBuffer += strlen( pcWriteBuffer ); /*lint !e9016 Pointer arithmetic ok on char pointers especially as in this case where it best denotes the intent of the code. */\r
}\r
}\r
else\r
\r
#if ( configUSE_MUTEXES == 1 )\r
\r
- void *pvTaskIncrementMutexHeldCount( void )\r
+ TaskHandle_t pvTaskIncrementMutexHeldCount( void )\r
{\r
/* If xSemaphoreCreateMutex() is called before any tasks have been created\r
then pxCurrentTCB will be NULL. */\r
uint8_t ucOriginalNotifyState;\r
\r
configASSERT( xTaskToNotify );\r
- pxTCB = ( TCB_t * ) xTaskToNotify;\r
+ pxTCB = xTaskToNotify;\r
\r
taskENTER_CRITICAL();\r
{\r
\r
default:\r
/* Should not get here if all enums are handled.\r
- Artificially force an assert. */\r
- configASSERT( ( volatile uint32_t ) 0 );\r
+ Artificially force an assert by testing a value the\r
+ compiler can't assume is const. */\r
+ configASSERT( pxTCB->ulNotifiedValue == ~0UL );\r
\r
break;\r
}\r
http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
\r
- pxTCB = ( TCB_t * ) xTaskToNotify;\r
+ pxTCB = xTaskToNotify;\r
\r
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
{\r
\r
default:\r
/* Should not get here if all enums are handled.\r
- Artificially force an assert. */\r
- configASSERT( ( volatile uint32_t ) 0 );\r
+ Artificially force an assert by testing a value the\r
+ compiler can't assume is const. */\r
+ configASSERT( pxTCB->ulNotifiedValue == ~0UL );\r
break;\r
}\r
\r
http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
\r
- pxTCB = ( TCB_t * ) xTaskToNotify;\r
+ pxTCB = xTaskToNotify;\r
\r
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
{\r
\r
#include "freertos_tasks_c_additions.h"\r
\r
- static void freertos_tasks_c_additions_init( void )\r
- {\r
- #ifdef FREERTOS_TASKS_C_ADDITIONS_INIT\r
+ #ifdef FREERTOS_TASKS_C_ADDITIONS_INIT\r
+ static void freertos_tasks_c_additions_init( void )\r
+ {\r
FREERTOS_TASKS_C_ADDITIONS_INIT();\r
- #endif\r
- }\r
+ }\r
+ #endif\r
\r
#endif\r
\r