]> git.sur5r.net Git - freertos/commitdiff
Introduce the application task hook feature.
authorrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sat, 12 Apr 2008 09:46:19 +0000 (09:46 +0000)
committerrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sat, 12 Apr 2008 09:46:19 +0000 (09:46 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@301 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

Source/tasks.c

index 994c23387f646741b67800ecc08e76aefef79453..6aae804b7db195d1edb8ab8479d8ac27dee9673f 100644 (file)
 #define tskIDLE_STACK_SIZE     configMINIMAL_STACK_SIZE\r
 \r
 \r
-/*\r
- * Default a definitions for backwards compatibility with old\r
- * portmacro.h files.\r
- */\r
-#ifndef configMAX_TASK_NAME_LEN\r
-       #define configMAX_TASK_NAME_LEN 16\r
-#endif\r
-\r
-#ifndef configIDLE_SHOULD_YIELD\r
-       #define configIDLE_SHOULD_YIELD         1\r
-#endif\r
-\r
-#if configMAX_TASK_NAME_LEN < 1\r
-       #undef configMAX_TASK_NAME_LEN\r
-       #define configMAX_TASK_NAME_LEN 1\r
-#endif\r
-\r
-#ifndef INCLUDE_xTaskResumeFromISR\r
-       #define INCLUDE_xTaskResumeFromISR 1\r
-#endif\r
-\r
-#ifndef INCLUDE_xTaskGetSchedulerState\r
-       #define INCLUDE_xTaskGetSchedulerState 0\r
-#endif\r
-\r
 /*\r
  * Task control block.  A task control block (TCB) is allocated to each task,\r
  * and stores the context of the task.\r
@@ -110,6 +85,10 @@ typedef struct tskTaskControlBlock
        #if ( configUSE_MUTEXES == 1 )\r
                unsigned portBASE_TYPE uxBasePriority;\r
        #endif\r
+\r
+       #if ( configUSE_APPLICATION_TASK_HOOK == 1 )\r
+               pdTASK_HOOK_CODE pxTaskHook;\r
+       #endif\r
                \r
 } tskTCB;\r
 \r
@@ -1412,6 +1391,61 @@ inline void vTaskIncrementTick( void )
 #endif\r
 /*-----------------------------------------------------------*/\r
 \r
+#if ( configUSE_APPLICATION_TASK_HOOK == 1 )\r
+\r
+       void vTaskSetApplicationTaskHook( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction )\r
+       {\r
+       tskTCB *xTCB;\r
+\r
+               /* If xTask is NULL then we are setting our own task hook. */\r
+               if( xTask == NULL )\r
+               {\r
+                       xTCB = ( tskTCB * ) pxCurrentTCB;\r
+               }\r
+               else\r
+               {\r
+                       xTCB = ( tskTCB * ) xTask;\r
+               }\r
+               \r
+               /* Save the hook function in the TCB. */\r
+               xTCB->pxTaskHook = pxHookFunction;\r
+       }\r
+       \r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( configUSE_APPLICATION_TASK_HOOK == 1 )\r
+\r
+       portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter )\r
+       {\r
+       tskTCB *xTCB;\r
+       portBASE_TYPE xReturn;\r
+\r
+               /* If xTask is NULL then we are calling our own task hook. */\r
+               if( xTask == NULL )\r
+               {\r
+                       xTCB = ( tskTCB * ) pxCurrentTCB;\r
+               }\r
+               else\r
+               {\r
+                       xTCB = ( tskTCB * ) xTask;\r
+               }\r
+\r
+               if( xTCB->pxTaskHook != NULL )\r
+               {\r
+                       xReturn = xTCB->pxTaskHook( pvParameter );\r
+               }\r
+               else\r
+               {\r
+                       xReturn = pdFAIL;\r
+               }\r
+\r
+               return xReturn;\r
+       }\r
+       \r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
 void vTaskSwitchContext( void )\r
 {\r
        traceTASK_SWITCHED_OUT();\r
@@ -1695,12 +1729,6 @@ static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed portCHAR * co
        strncpy( ( char * ) pxTCB->pcTaskName, ( const char * ) pcName, ( unsigned portSHORT ) configMAX_TASK_NAME_LEN );\r
        pxTCB->pcTaskName[ ( unsigned portSHORT ) configMAX_TASK_NAME_LEN - ( unsigned portSHORT ) 1 ] = '\0';\r
 \r
-       #if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
-       {\r
-               pxTCB->uxCriticalNesting = ( unsigned portBASE_TYPE ) 0;\r
-       }\r
-       #endif\r
-\r
        /* This is used as an array index so must ensure it's not too large. */\r
        if( uxPriority >= configMAX_PRIORITIES )\r
        {\r
@@ -1724,6 +1752,18 @@ static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed portCHAR * co
        /* Event lists are always in priority order. */\r
        listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) uxPriority );\r
        listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );\r
+\r
+       #if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
+       {\r
+               pxTCB->uxCriticalNesting = ( unsigned portBASE_TYPE ) 0;\r
+       }\r
+       #endif\r
+\r
+       #if ( configUSE_APPLICATION_TASK_HOOK == 1 )\r
+       {\r
+               pxTCB->pxTaskHook = NULL;\r
+       }\r
+       #endif  \r
 }\r
 /*-----------------------------------------------------------*/\r
 \r