]> git.sur5r.net Git - freertos/blobdiff - Source/tasks.c
Add in a couple of extra list macros for use with FreeRTOS+UDP.
[freertos] / Source / tasks.c
index 3a4b21d75a53403df05280c6c01e133d75693d53..85e41a05f614bb735dd6ac96f53c89f8d795b15b 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-    FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+    FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.\r
        \r
 \r
     ***************************************************************************\r
     FreeRTOS WEB site.\r
 \r
     1 tab == 4 spaces!\r
+    \r
+    ***************************************************************************\r
+     *                                                                       *\r
+     *    Having a problem?  Start by reading the FAQ "My application does   *\r
+     *    not run, what could be wrong?                                      *\r
+     *                                                                       *\r
+     *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
+     *                                                                       *\r
+    ***************************************************************************\r
 \r
-    http://www.FreeRTOS.org - Documentation, latest information, license and\r
-    contact details.\r
-\r
-    http://www.SafeRTOS.com - A version that is certified for use in safety\r
-    critical systems.\r
-\r
-    http://www.OpenRTOS.com - Commercial support, development, porting,\r
-    licensing and training services.\r
+    \r
+    http://www.FreeRTOS.org - Documentation, training, latest information, \r
+    license and contact details.\r
+    \r
+    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
+    including FreeRTOS+Trace - an indispensable productivity tool.\r
+\r
+    Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
+    the code with commercial support, indemnification, and middleware, under \r
+    the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
+    provide a safety engineered and independently SIL3 certified version under \r
+    the SafeRTOS brand: http://www.SafeRTOS.com.\r
 */\r
 \r
 \r
@@ -100,7 +113,8 @@ typedef struct tskTaskControlBlock
        #endif\r
 \r
        #if ( configUSE_TRACE_FACILITY == 1 )\r
-               unsigned portBASE_TYPE  uxTCBNumber;    /*< This is used for tracing the scheduler and making debugging easier only. */\r
+               unsigned portBASE_TYPE  uxTCBNumber;    /*< This stores a number that increments each time a TCB is created.  It allows debuggers to determine when a task has been deleted and then recreated. */\r
+               unsigned portBASE_TYPE  uxTaskNumber;   /*< This stores a number specifically for use by third party trace code. */\r
        #endif\r
 \r
        #if ( configUSE_MUTEXES == 1 )\r
@@ -194,58 +208,6 @@ PRIVILEGED_DATA static portTickType xNextTaskUnblockTime                                           = ( portTickType )
 #define tskDELETED_CHAR                ( ( signed char ) 'D' )\r
 #define tskSUSPENDED_CHAR      ( ( signed char ) 'S' )\r
 \r
-/*\r
- * Macros and private variables used by the trace facility.\r
- */\r
-#if ( configUSE_TRACE_FACILITY == 1 )\r
-\r
-       #define tskSIZE_OF_EACH_TRACE_LINE                      ( ( unsigned long ) ( sizeof( unsigned long ) + sizeof( unsigned long ) ) )\r
-       PRIVILEGED_DATA static volatile signed char * volatile pcTraceBuffer;\r
-       PRIVILEGED_DATA static signed char *pcTraceBufferStart;\r
-       PRIVILEGED_DATA static signed char *pcTraceBufferEnd;\r
-       PRIVILEGED_DATA static signed portBASE_TYPE xTracing = pdFALSE;\r
-       static unsigned portBASE_TYPE uxPreviousTask = 255U;\r
-       PRIVILEGED_DATA static char pcStatusString[ 50 ];\r
-\r
-#endif\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-/*\r
- * Macro that writes a trace of scheduler activity to a buffer.  This trace\r
- * shows which task is running when and is very useful as a debugging tool.\r
- * As this macro is called each context switch it is a good idea to undefine\r
- * it if not using the facility.\r
- */\r
-#if ( configUSE_TRACE_FACILITY == 1 )\r
-\r
-       #define vWriteTraceToBuffer()                                                                                                                                   \\r
-       {                                                                                                                                                                                               \\r
-               if( xTracing != pdFALSE )                                                                                                                                       \\r
-               {                                                                                                                                                                                       \\r
-                       if( uxPreviousTask != pxCurrentTCB->uxTCBNumber )                                                                               \\r
-                       {                                                                                                                                                                               \\r
-                               if( ( pcTraceBuffer + tskSIZE_OF_EACH_TRACE_LINE ) < pcTraceBufferEnd )                         \\r
-                               {                                                                                                                                                                       \\r
-                                       uxPreviousTask = pxCurrentTCB->uxTCBNumber;                                                                             \\r
-                                       *( unsigned long * ) pcTraceBuffer = ( unsigned long ) xTickCount;                              \\r
-                                       pcTraceBuffer += sizeof( unsigned long );                                                                               \\r
-                                       *( unsigned long * ) pcTraceBuffer = ( unsigned long ) uxPreviousTask;                  \\r
-                                       pcTraceBuffer += sizeof( unsigned long );                                                                               \\r
-                               }                                                                                                                                                                       \\r
-                               else                                                                                                                                                            \\r
-                               {                                                                                                                                                                       \\r
-                                       xTracing = pdFALSE;                                                                                                                             \\r
-                               }                                                                                                                                                                       \\r
-                       }                                                                                                                                                                               \\r
-               }                                                                                                                                                                                       \\r
-       }\r
-\r
-#else\r
-\r
-       #define vWriteTraceToBuffer()\r
-\r
-#endif\r
 /*-----------------------------------------------------------*/\r
 \r
 /*\r
@@ -256,6 +218,7 @@ PRIVILEGED_DATA static portTickType xNextTaskUnblockTime                                            = ( portTickType )
  * executing task has been rescheduled.\r
  */\r
 #define prvAddTaskToReadyQueue( pxTCB )                                                                                                                                                                        \\r
+       traceMOVED_TASK_TO_READY_STATE( pxTCB )                                                                                                                                                         \\r
        if( ( pxTCB )->uxPriority > uxTopReadyPriority )                                                                                                                                        \\r
        {                                                                                                                                                                                                                                       \\r
                uxTopReadyPriority = ( pxTCB )->uxPriority;                                                                                                                                             \\r
@@ -333,7 +296,7 @@ portTickType xItemValue;                                                                                                                            \
 #define prvGetTCBFromHandle( pxHandle ) ( ( ( pxHandle ) == NULL ) ? ( tskTCB * ) pxCurrentTCB : ( tskTCB * ) ( pxHandle ) )\r
 \r
 /* Callback function prototypes. --------------------------*/\r
-extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName );\r
+extern void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName );\r
 extern void vApplicationTickHook( void );\r
                \r
 /* File private functions. --------------------------------*/\r
@@ -504,7 +467,7 @@ tskTCB * pxNewTCB;
                #endif\r
 \r
                /* Check the alignment of the initialised stack. */\r
-               configASSERT( ( ( ( unsigned long ) pxNewTCB->pxTopOfStack & ( unsigned long ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
+               portALIGNMENT_ASSERT_pxCurrentTCB( ( ( ( unsigned long ) pxNewTCB->pxTopOfStack & ( unsigned long ) portBYTE_ALIGNMENT_MASK ) == 0UL ) );\r
 \r
                if( ( void * ) pxCreatedTask != NULL )\r
                {\r
@@ -565,6 +528,7 @@ tskTCB * pxNewTCB;
                        prvAddTaskToReadyQueue( pxNewTCB );\r
 \r
                        xReturn = pdPASS;\r
+                       portSETUP_TCB( pxNewTCB );\r
                        traceTASK_CREATE( pxNewTCB );\r
                }\r
                taskEXIT_CRITICAL();\r
@@ -818,7 +782,7 @@ tskTCB * pxNewTCB;
                        priority of the calling function. */\r
                        pxTCB = prvGetTCBFromHandle( pxTask );\r
 \r
-                       traceTASK_PRIORITY_SET( pxTask, uxNewPriority );\r
+                       traceTASK_PRIORITY_SET( pxTCB, uxNewPriority );\r
 \r
                        #if ( configUSE_MUTEXES == 1 )\r
                        {\r
@@ -1048,29 +1012,34 @@ tskTCB * pxNewTCB;
        {\r
        portBASE_TYPE xYieldRequired = pdFALSE;\r
        tskTCB *pxTCB;\r
+       unsigned portBASE_TYPE uxSavedInterruptStatus;\r
 \r
                configASSERT( pxTaskToResume );\r
 \r
                pxTCB = ( tskTCB * ) pxTaskToResume;\r
 \r
-               if( xTaskIsTaskSuspended( pxTCB ) == pdTRUE )\r
+               uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
                {\r
-                       traceTASK_RESUME_FROM_ISR( pxTCB );\r
-\r
-                       if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )\r
-                       {\r
-                               xYieldRequired = ( pxTCB->uxPriority >= pxCurrentTCB->uxPriority );\r
-                               vListRemove(  &( pxTCB->xGenericListItem ) );\r
-                               prvAddTaskToReadyQueue( pxTCB );\r
-                       }\r
-                       else\r
+                       if( xTaskIsTaskSuspended( pxTCB ) == pdTRUE )\r
                        {\r
-                               /* We cannot access the delayed or ready lists, so will hold this\r
-                               task pending until the scheduler is resumed, at which point a\r
-                               yield will be performed if necessary. */\r
-                               vListInsertEnd( ( xList * ) &( xPendingReadyList ), &( pxTCB->xEventListItem ) );\r
+                               traceTASK_RESUME_FROM_ISR( pxTCB );\r
+\r
+                               if( uxSchedulerSuspended == ( unsigned portBASE_TYPE ) pdFALSE )\r
+                               {\r
+                                       xYieldRequired = ( pxTCB->uxPriority >= pxCurrentTCB->uxPriority );\r
+                                       vListRemove(  &( pxTCB->xGenericListItem ) );\r
+                                       prvAddTaskToReadyQueue( pxTCB );\r
+                               }\r
+                               else\r
+                               {\r
+                                       /* We cannot access the delayed or ready lists, so will hold this\r
+                                       task pending until the scheduler is resumed, at which point a\r
+                                       yield will be performed if necessary. */\r
+                                       vListInsertEnd( ( xList * ) &( xPendingReadyList ), &( pxTCB->xEventListItem ) );\r
+                               }\r
                        }\r
                }\r
+               portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
 \r
                return xYieldRequired;\r
        }\r
@@ -1445,44 +1414,6 @@ unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void )
 #endif\r
 /*----------------------------------------------------------*/\r
 \r
-#if ( configUSE_TRACE_FACILITY == 1 )\r
-\r
-       void vTaskStartTrace( signed char * pcBuffer, unsigned long ulBufferSize )\r
-       {\r
-               configASSERT( pcBuffer );\r
-               configASSERT( ulBufferSize );\r
-\r
-               taskENTER_CRITICAL();\r
-               {\r
-                       pcTraceBuffer = ( signed char * )pcBuffer;\r
-                       pcTraceBufferStart = pcBuffer;\r
-                       pcTraceBufferEnd = pcBuffer + ( ulBufferSize - tskSIZE_OF_EACH_TRACE_LINE );\r
-                       xTracing = pdTRUE;\r
-               }\r
-               taskEXIT_CRITICAL();\r
-       }\r
-\r
-#endif\r
-/*----------------------------------------------------------*/\r
-\r
-#if ( configUSE_TRACE_FACILITY == 1 )\r
-\r
-       unsigned long ulTaskEndTrace( void )\r
-       {\r
-       unsigned long ulBufferLength;\r
-\r
-               taskENTER_CRITICAL();\r
-                       xTracing = pdFALSE;\r
-               taskEXIT_CRITICAL();\r
-\r
-               ulBufferLength = ( unsigned long ) ( pcTraceBuffer - pcTraceBufferStart );\r
-\r
-               return ulBufferLength;\r
-       }\r
-\r
-#endif\r
-/*----------------------------------------------------------*/\r
-\r
 #if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )\r
 \r
        xTaskHandle xTaskGetIdleTaskHandle( void )\r
@@ -1709,7 +1640,6 @@ void vTaskSwitchContext( void )
                listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &( pxReadyTasksLists[ uxTopReadyPriority ] ) );\r
        \r
                traceTASK_SWITCHED_IN();\r
-               vWriteTraceToBuffer();\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -1905,6 +1835,42 @@ void vTaskMissedYield( void )
 {\r
        xMissedYield = pdTRUE;\r
 }\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_TRACE_FACILITY == 1 )\r
+       unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask )\r
+       {\r
+       unsigned portBASE_TYPE uxReturn;\r
+       tskTCB *pxTCB;\r
+       \r
+               if( xTask != NULL )\r
+               {\r
+                       pxTCB = ( tskTCB * ) xTask;\r
+                       uxReturn = pxTCB->uxTaskNumber;\r
+               }\r
+               else\r
+               {\r
+                       uxReturn = 0U;\r
+               }\r
+               \r
+               return uxReturn;\r
+       }\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_TRACE_FACILITY == 1 )\r
+       void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle )\r
+       {\r
+       tskTCB *pxTCB;\r
+       \r
+               if( xTask != NULL )\r
+               {\r
+                       pxTCB = ( tskTCB * ) xTask;\r
+                       pxTCB->uxTaskNumber = uxHandle;\r
+               }\r
+       }\r
+#endif\r
+\r
 \r
 /*\r
  * -----------------------------------------------------------\r
@@ -2199,6 +2165,7 @@ tskTCB *pxNewTCB;
        {\r
        volatile tskTCB *pxNextTCB, *pxFirstTCB;\r
        unsigned short usStackRemaining;\r
+       PRIVILEGED_DATA static char pcStatusString[ configMAX_TASK_NAME_LEN + 30 ];\r
 \r
                /* Write the details of all the TCB's in pxList into the buffer. */\r
                listGET_OWNER_OF_NEXT_ENTRY( pxFirstTCB, pxList );\r
@@ -2348,7 +2315,8 @@ tskTCB *pxNewTCB;
        static void prvDeleteTCB( tskTCB *pxTCB )\r
        {\r
                /* This call is required specifically for the TriCore port.  It must be\r
-               above the vPortFree() calls. */\r
+               above the vPortFree() calls.  The call is also used by ports/demos that\r
+               want to allocate and clean RAM statically. */\r
                portCLEAN_UP_TCB( pxTCB );\r
 \r
                /* Free up the memory allocated by the scheduler for the task.  It is up to\r
@@ -2436,6 +2404,8 @@ tskTCB *pxNewTCB;
                                /* Just inherit the priority. */\r
                                pxTCB->uxPriority = pxCurrentTCB->uxPriority;\r
                        }\r
+\r
+                       traceTASK_PRIORITY_INHERIT( pxTCB, pxCurrentTCB->uxPriority );\r
                }\r
        }\r
 \r
@@ -2456,8 +2426,9 @@ tskTCB *pxNewTCB;
                                Remove ourselves from the ready list we currently appear in. */\r
                                vListRemove( &( pxTCB->xGenericListItem ) );\r
 \r
-                               /* Disinherit the priority before adding ourselves into the new\r
+                               /* Disinherit the priority before adding the task into the new\r
                                ready list. */\r
+                               traceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority );\r
                                pxTCB->uxPriority = pxTCB->uxBasePriority;\r
                                listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) pxTCB->uxPriority );\r
                                prvAddTaskToReadyQueue( pxTCB );\r