summaryrefslogtreecommitdiff
path: root/Source/tasks.c
diff options
context:
space:
mode:
authorrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>2008-04-12 09:46:19 +0000
committerrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>2008-04-12 09:46:19 +0000
commit65d137beda95543d0c59f048e0a0a99f379fb6cd (patch)
tree9e9068006780ba81d0a4fa2e0b81de84a3446e4b /Source/tasks.c
parente8188ffbf76e1550c63aa274aab35a0fb19f83f6 (diff)
downloadfreertos-65d137beda95543d0c59f048e0a0a99f379fb6cd.tar.gz
freertos-65d137beda95543d0c59f048e0a0a99f379fb6cd.tar.bz2
freertos-65d137beda95543d0c59f048e0a0a99f379fb6cd.tar.xz
Introduce the application task hook feature.
git-svn-id: https://freertos.svn.sourceforge.net/svnroot/freertos/trunk@301 1d2547de-c912-0410-9cb9-b8ca96c0e9e2
Diffstat (limited to 'Source/tasks.c')
-rw-r--r--Source/tasks.c102
1 files changed, 71 insertions, 31 deletions
diff --git a/Source/tasks.c b/Source/tasks.c
index 994c2338..6aae804b 100644
--- a/Source/tasks.c
+++ b/Source/tasks.c
@@ -62,31 +62,6 @@
/*
- * Default a definitions for backwards compatibility with old
- * portmacro.h files.
- */
-#ifndef configMAX_TASK_NAME_LEN
- #define configMAX_TASK_NAME_LEN 16
-#endif
-
-#ifndef configIDLE_SHOULD_YIELD
- #define configIDLE_SHOULD_YIELD 1
-#endif
-
-#if configMAX_TASK_NAME_LEN < 1
- #undef configMAX_TASK_NAME_LEN
- #define configMAX_TASK_NAME_LEN 1
-#endif
-
-#ifndef INCLUDE_xTaskResumeFromISR
- #define INCLUDE_xTaskResumeFromISR 1
-#endif
-
-#ifndef INCLUDE_xTaskGetSchedulerState
- #define INCLUDE_xTaskGetSchedulerState 0
-#endif
-
-/*
* Task control block. A task control block (TCB) is allocated to each task,
* and stores the context of the task.
*/
@@ -110,6 +85,10 @@ typedef struct tskTaskControlBlock
#if ( configUSE_MUTEXES == 1 )
unsigned portBASE_TYPE uxBasePriority;
#endif
+
+ #if ( configUSE_APPLICATION_TASK_HOOK == 1 )
+ pdTASK_HOOK_CODE pxTaskHook;
+ #endif
} tskTCB;
@@ -1412,6 +1391,61 @@ inline void vTaskIncrementTick( void )
#endif
/*-----------------------------------------------------------*/
+#if ( configUSE_APPLICATION_TASK_HOOK == 1 )
+
+ void vTaskSetApplicationTaskHook( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction )
+ {
+ tskTCB *xTCB;
+
+ /* If xTask is NULL then we are setting our own task hook. */
+ if( xTask == NULL )
+ {
+ xTCB = ( tskTCB * ) pxCurrentTCB;
+ }
+ else
+ {
+ xTCB = ( tskTCB * ) xTask;
+ }
+
+ /* Save the hook function in the TCB. */
+ xTCB->pxTaskHook = pxHookFunction;
+ }
+
+#endif
+/*-----------------------------------------------------------*/
+
+#if ( configUSE_APPLICATION_TASK_HOOK == 1 )
+
+ portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter )
+ {
+ tskTCB *xTCB;
+ portBASE_TYPE xReturn;
+
+ /* If xTask is NULL then we are calling our own task hook. */
+ if( xTask == NULL )
+ {
+ xTCB = ( tskTCB * ) pxCurrentTCB;
+ }
+ else
+ {
+ xTCB = ( tskTCB * ) xTask;
+ }
+
+ if( xTCB->pxTaskHook != NULL )
+ {
+ xReturn = xTCB->pxTaskHook( pvParameter );
+ }
+ else
+ {
+ xReturn = pdFAIL;
+ }
+
+ return xReturn;
+ }
+
+#endif
+/*-----------------------------------------------------------*/
+
void vTaskSwitchContext( void )
{
traceTASK_SWITCHED_OUT();
@@ -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 );
pxTCB->pcTaskName[ ( unsigned portSHORT ) configMAX_TASK_NAME_LEN - ( unsigned portSHORT ) 1 ] = '\0';
- #if ( portCRITICAL_NESTING_IN_TCB == 1 )
- {
- pxTCB->uxCriticalNesting = ( unsigned portBASE_TYPE ) 0;
- }
- #endif
-
/* This is used as an array index so must ensure it's not too large. */
if( uxPriority >= configMAX_PRIORITIES )
{
@@ -1724,6 +1752,18 @@ static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed portCHAR * co
/* Event lists are always in priority order. */
listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), configMAX_PRIORITIES - ( portTickType ) uxPriority );
listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );
+
+ #if ( portCRITICAL_NESTING_IN_TCB == 1 )
+ {
+ pxTCB->uxCriticalNesting = ( unsigned portBASE_TYPE ) 0;
+ }
+ #endif
+
+ #if ( configUSE_APPLICATION_TASK_HOOK == 1 )
+ {
+ pxTCB->pxTaskHook = NULL;
+ }
+ #endif
}
/*-----------------------------------------------------------*/