]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/include/task.h
Minor updates to comment block for xTaskCheckForTimeOut().
[freertos] / FreeRTOS / Source / include / task.h
index 446f6fa88eeb7c39694fa03524bf06b0e887ccc6..6d9548ea18087bdefc623f6c1904a2c3cff798dd 100644 (file)
@@ -1,6 +1,6 @@
 /*\r
- * FreeRTOS Kernel V10.1.1\r
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
+ * FreeRTOS Kernel V10.2.1\r
+ * Copyright (C) 2019 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
@@ -43,11 +43,19 @@ extern "C" {
  * MACROS AND DEFINITIONS\r
  *----------------------------------------------------------*/\r
 \r
-#define tskKERNEL_VERSION_NUMBER "V10.1.1"\r
+#define tskKERNEL_VERSION_NUMBER "V10.2.1"\r
 #define tskKERNEL_VERSION_MAJOR 10\r
-#define tskKERNEL_VERSION_MINOR 1\r
+#define tskKERNEL_VERSION_MINOR 2\r
 #define tskKERNEL_VERSION_BUILD 1\r
 \r
+/* MPU region parameters passed in ulParameters\r
+ * of MemoryRegion_t struct. */\r
+#define tskMPU_REGION_READ_ONLY                        ( 1UL << 0UL )\r
+#define tskMPU_REGION_READ_WRITE               ( 1UL << 1UL )\r
+#define tskMPU_REGION_EXECUTE_NEVER            ( 1UL << 2UL )\r
+#define tskMPU_REGION_NORMAL_MEMORY            ( 1UL << 3UL )\r
+#define tskMPU_REGION_DEVICE_MEMORY            ( 1UL << 4UL )\r
+\r
 /**\r
  * task. h\r
  *\r
@@ -114,7 +122,7 @@ typedef struct xTASK_PARAMETERS
 {\r
        TaskFunction_t pvTaskCode;\r
        const char * const pcName;      /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
-       uint16_t usStackDepth;\r
+       configSTACK_DEPTH_TYPE usStackDepth;\r
        void *pvParameters;\r
        UBaseType_t uxPriority;\r
        StackType_t *puxStackBuffer;\r
@@ -306,13 +314,13 @@ is used in assert() statements. */
         // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time\r
         // the new task attempts to access it.\r
         xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );\r
-     configASSERT( xHandle );\r
+        configASSERT( xHandle );\r
 \r
         // Use the handle to delete the task.\r
-     if( xHandle != NULL )\r
-     {\r
-            vTaskDelete( xHandle );\r
-     }\r
+        if( xHandle != NULL )\r
+        {\r
+               vTaskDelete( xHandle );\r
+        }\r
  }\r
    </pre>\r
  * \defgroup xTaskCreate xTaskCreate\r
@@ -376,9 +384,9 @@ is used in assert() statements. */
  * memory to be allocated dynamically.\r
  *\r
  * @return If neither pxStackBuffer or pxTaskBuffer are NULL, then the task will\r
- * be created and pdPASS is returned.  If either pxStackBuffer or pxTaskBuffer\r
- * are NULL then the task will not be created and\r
- * errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY is returned.\r
+ * be created and a handle to the created task is returned.  If either\r
+ * pxStackBuffer or pxTaskBuffer are NULL then the task will not be created and\r
+ * NULL is returned.\r
  *\r
  * Example usage:\r
    <pre>\r
@@ -490,9 +498,9 @@ static const TaskParameters_t xCheckTaskParameters =
        // for full information.\r
        {\r
                // Base address                                 Length  Parameters\r
-        { cReadWriteArray,                             32,             portMPU_REGION_READ_WRITE },\r
-        { cReadOnlyArray,                              32,             portMPU_REGION_READ_ONLY },\r
-        { cPrivilegedOnlyAccessArray,  128,    portMPU_REGION_PRIVILEGED_READ_WRITE }\r
+               { cReadWriteArray,                              32,             portMPU_REGION_READ_WRITE },\r
+               { cReadOnlyArray,                               32,             portMPU_REGION_READ_ONLY },\r
+               { cPrivilegedOnlyAccessArray,   128,    portMPU_REGION_PRIVILEGED_READ_WRITE }\r
        }\r
 };\r
 \r
@@ -576,9 +584,9 @@ static const TaskParameters_t xCheckTaskParameters =
        // for full information.\r
        {\r
                // Base address                                 Length  Parameters\r
-        { cReadWriteArray,                             32,             portMPU_REGION_READ_WRITE },\r
-        { cReadOnlyArray,                              32,             portMPU_REGION_READ_ONLY },\r
-        { cPrivilegedOnlyAccessArray,  128,    portMPU_REGION_PRIVILEGED_READ_WRITE }\r
+               { cReadWriteArray,                              32,             portMPU_REGION_READ_WRITE },\r
+               { cReadOnlyArray,                               32,             portMPU_REGION_READ_ONLY },\r
+               { cPrivilegedOnlyAccessArray,   128,    portMPU_REGION_PRIVILEGED_READ_WRITE }\r
        }\r
 \r
        &xTaskBuffer; // Holds the task's data structure.\r
@@ -1728,6 +1736,36 @@ void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unquali
  */\r
 void vTaskGetRunTimeStats( char *pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
 \r
+/**\r
+* task. h\r
+* <PRE>uint32_t ulTaskGetIdleRunTimeCounter( void );</PRE>\r
+*\r
+* configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS\r
+* must both be defined as 1 for this function to be available.  The application\r
+* must also then provide definitions for\r
+* portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()\r
+* to configure a peripheral timer/counter and return the timers current count\r
+* value respectively.  The counter should be at least 10 times the frequency of\r
+* the tick count.\r
+*\r
+* Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total\r
+* accumulated execution time being stored for each task.  The resolution\r
+* of the accumulated time value depends on the frequency of the timer\r
+* configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.\r
+* While uxTaskGetSystemState() and vTaskGetRunTimeStats() writes the total\r
+* execution time of each task into a buffer, ulTaskGetIdleRunTimeCounter()\r
+* returns the total execution time of just the idle task.\r
+*\r
+* @return The total run time of the idle task.  This is the amount of time the\r
+* idle task has actually been executing.  The unit of time is dependent on the\r
+* frequency configured using the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and\r
+* portGET_RUN_TIME_COUNTER_VALUE() macros.\r
+*\r
+* \defgroup ulTaskGetIdleRunTimeCounter ulTaskGetIdleRunTimeCounter\r
+* \ingroup TaskUtils\r
+*/\r
+uint32_t ulTaskGetIdleRunTimeCounter( void ) PRIVILEGED_FUNCTION;\r
+\r
 /**\r
  * task. h\r
  * <PRE>BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );</PRE>\r
@@ -2163,6 +2201,103 @@ uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait
  */\r
 BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );\r
 \r
+/**\r
+ * task.h\r
+ * <pre>void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut )</pre>\r
+ *\r
+ * Capture the current time for future use with xTaskCheckForTimeOut().\r
+ *\r
+ * @param pxTimeOut Pointer to a timeout object into which the current time\r
+ * is to be captured.  The captured time includes the tick count and the number\r
+ * of times the tick count has overflowed since the system first booted.\r
+ * \defgroup vTaskSetTimeOutState vTaskSetTimeOutState\r
+ * \ingroup TaskCtrl\r
+ */\r
+void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;\r
+\r
+/**\r
+ * task.h\r
+ * <pre>BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait );</pre>\r
+ *\r
+ * Determines if pxTicksToWait ticks has passed since a time was captured\r
+ * using a call to vTaskSetTimeOutState().  The captured time includes the tick\r
+ * count and the number of times the tick count has overflowed.\r
+ *\r
+ * @param pxTimeOut The time status as captured previously using\r
+ * vTaskSetTimeOutState. If the timeout has not yet occurred, it is updated\r
+ * to reflect the current time status.\r
+ * @param pxTicksToWait The number of ticks to check for timeout i.e. if\r
+ * pxTicksToWait ticks have passed since pxTimeOut was last updated (either by\r
+ * vTaskSetTimeOutState() or xTaskCheckForTimeOut()), the timeout has occurred.\r
+ * If the timeout has not occurred, pxTIcksToWait is updated to reflect the\r
+ * number of remaining ticks.\r
+ *\r
+ * @return If timeout has occurred, pdTRUE is returned. Otherwise pdFALSE is\r
+ * returned and pxTicksToWait is updated to reflect the number of remaining\r
+ * ticks.\r
+ *\r
+ * @see https://www.freertos.org/xTaskCheckForTimeOut.html\r
+ *\r
+ * Example Usage:\r
+ * <pre>\r
+       // Driver library function used to receive uxWantedBytes from an Rx buffer\r
+       // that is filled by a UART interrupt. If there are not enough bytes in the\r
+       // Rx buffer then the task enters the Blocked state until it is notified that\r
+       // more data has been placed into the buffer. If there is still not enough\r
+       // data then the task re-enters the Blocked state, and xTaskCheckForTimeOut()\r
+       // is used to re-calculate the Block time to ensure the total amount of time\r
+       // spent in the Blocked state does not exceed MAX_TIME_TO_WAIT. This\r
+       // continues until either the buffer contains at least uxWantedBytes bytes,\r
+       // or the total amount of time spent in the Blocked state reaches\r
+       // MAX_TIME_TO_WAIT – at which point the task reads however many bytes are\r
+       // available up to a maximum of uxWantedBytes.\r
+\r
+       size_t xUART_Receive( uint8_t *pucBuffer, size_t uxWantedBytes )\r
+       {\r
+       size_t uxReceived = 0;\r
+       TickType_t xTicksToWait = MAX_TIME_TO_WAIT;\r
+       TimeOut_t xTimeOut;\r
+\r
+               // Initialize xTimeOut.  This records the time at which this function\r
+               // was entered.\r
+               vTaskSetTimeOutState( &xTimeOut );\r
+\r
+               // Loop until the buffer contains the wanted number of bytes, or a\r
+               // timeout occurs.\r
+               while( UART_bytes_in_rx_buffer( pxUARTInstance ) < uxWantedBytes )\r
+               {\r
+                       // The buffer didn't contain enough data so this task is going to\r
+                       // enter the Blocked state. Adjusting xTicksToWait to account for\r
+                       // any time that has been spent in the Blocked state within this\r
+                       // function so far to ensure the total amount of time spent in the\r
+                       // Blocked state does not exceed MAX_TIME_TO_WAIT.\r
+                       if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) != pdFALSE )\r
+                       {\r
+                               //Timed out before the wanted number of bytes were available,\r
+                               // exit the loop.\r
+                               break;\r
+                       }\r
+\r
+                       // Wait for a maximum of xTicksToWait ticks to be notified that the\r
+                       // receive interrupt has placed more data into the buffer.\r
+                       ulTaskNotifyTake( pdTRUE, xTicksToWait );\r
+               }\r
+\r
+               // Attempt to read uxWantedBytes from the receive buffer into pucBuffer.\r
+               // The actual number of bytes read (which might be less than\r
+               // uxWantedBytes) is returned.\r
+               uxReceived = UART_read_from_receive_buffer( pxUARTInstance,\r
+                                                                                                       pucBuffer,\r
+                                                                                                       uxWantedBytes );\r
+\r
+               return uxReceived;\r
+       }\r
+ </pre>\r
+ * \defgroup xTaskCheckForTimeOut xTaskCheckForTimeOut\r
+ * \ingroup TaskCtrl\r
+ */\r
+BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;\r
+\r
 /*-----------------------------------------------------------\r
  * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES\r
  *----------------------------------------------------------*/\r
@@ -2266,7 +2401,7 @@ void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, const Tick
  * Sets the pointer to the current TCB to the TCB of the highest priority task\r
  * that is ready to run.\r
  */\r
-void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;\r
+portDONT_DISCARD void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;\r
 \r
 /*\r
  * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE.  THEY ARE USED BY\r
@@ -2279,17 +2414,6 @@ TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION;
  */\r
 TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;\r
 \r
-/*\r
- * Capture the current time status for future reference.\r
- */\r
-void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;\r
-\r
-/*\r
- * Compare the time status now with that previously captured to see if the\r
- * timeout has expired.\r
- */\r
-BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;\r
-\r
 /*\r
  * Shortcut used by the queue implementation to prevent unnecessary call to\r
  * taskYIELD();\r
@@ -2345,8 +2469,21 @@ void vTaskSetTaskNumber( TaskHandle_t xTask, const UBaseType_t uxHandle ) PRIVIL
  */\r
 void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION;\r
 \r
+/* Correct the tick count value after the application code has held\r
+interrupts disabled for an extended period.  xTicksToCatchUp is the number\r
+of tick interrupts that have been missed due to interrupts being disabled.\r
+Its value is not computed automatically, so must be computed by the\r
+application writer.\r
+\r
+This function is similar to vTaskStepTick(), however, unlike\r
+vTaskStepTick(), xTaskCatchUpTicks() may move the tick count forward past a\r
+time at which a task should be removed from the blocked state.  That means\r
+tasks may have to be removed from the blocked state as the tick count is\r
+moved. */\r
+BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp ) PRIVILEGED_FUNCTION;\r
+\r
 /*\r
- * Only avilable when configUSE_TICKLESS_IDLE is set to 1.\r
+ * Only available when configUSE_TICKLESS_IDLE is set to 1.\r
  * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port\r
  * specific sleep function to determine if it is ok to proceed with the sleep,\r
  * and if it is ok to proceed, if it is ok to sleep indefinitely.\r