335 lines
15 KiB
C
335 lines
15 KiB
C
/*
|
|
* FreeRTOS Kernel V10.0.0
|
|
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
* the Software without restriction, including without limitation the rights to
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
* subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software. If you wish to use our Amazon
|
|
* FreeRTOS name, please do so in a fair use way that does not cause confusion.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* http://www.FreeRTOS.org
|
|
* http://aws.amazon.com/freertos
|
|
*
|
|
* 1 tab == 4 spaces!
|
|
*/
|
|
|
|
|
|
#ifndef INC_TASK_H
|
|
#define INC_TASK_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include "portmacro_cmsis.h"
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
// copied from InfiniTime/src/FreeRTOSConfig.h
|
|
#define configTICK_RATE_HZ 1024
|
|
#define configSTACK_DEPTH_TYPE uint16_t
|
|
/*-----------------------------------------------------------
|
|
* TASK UTILITIES
|
|
*----------------------------------------------------------*/
|
|
|
|
/**
|
|
* task. h
|
|
* <PRE>TickType_t xTaskGetTickCount( void );</PRE>
|
|
*
|
|
* @return The count of ticks since vTaskStartScheduler was called.
|
|
*
|
|
* \defgroup xTaskGetTickCount xTaskGetTickCount
|
|
* \ingroup TaskUtils
|
|
*/
|
|
TickType_t xTaskGetTickCount();
|
|
|
|
|
|
typedef void (*TaskFunction_t)(void *instance);
|
|
|
|
/**
|
|
* task. h
|
|
*
|
|
* Type by which tasks are referenced. For example, a call to xTaskCreate
|
|
* returns (via a pointer parameter) an TaskHandle_t variable that can then
|
|
* be used as a parameter to vTaskDelete to delete the task.
|
|
*
|
|
* \defgroup TaskHandle_t TaskHandle_t
|
|
* \ingroup Tasks
|
|
*/
|
|
//typedef void * TaskHandle_t;
|
|
typedef struct TaskHandle_t {
|
|
void *thread_handle;
|
|
TaskFunction_t task_fn;
|
|
void *instance;
|
|
}TaskHandle_t;
|
|
|
|
/* Task states returned by eTaskGetState. */
|
|
enum eTaskState
|
|
{
|
|
eRunning = 0, /* A task is querying the state of itself, so must be running. */
|
|
eReady, /* The task being queried is in a read or pending ready list. */
|
|
eBlocked, /* The task being queried is in the Blocked state. */
|
|
eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
|
|
eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */
|
|
eInvalid /* Used as an 'invalid state' value. */
|
|
};
|
|
|
|
/* Actions that can be performed when vTaskNotify() is called. */
|
|
enum eNotifyAction
|
|
{
|
|
eNoAction = 0, /* Notify the task without updating its notify value. */
|
|
eSetBits, /* Set bits in the task's notification value. */
|
|
eIncrement, /* Increment the task's notification value. */
|
|
eSetValueWithOverwrite, /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */
|
|
eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */
|
|
};
|
|
|
|
/* Definitions returned by xTaskGetSchedulerState(). taskSCHEDULER_SUSPENDED is
|
|
0 to generate more optimal code when configASSERT() is defined as the constant
|
|
is used in assert() statements. */
|
|
#define taskSCHEDULER_SUSPENDED ( ( BaseType_t ) 0 )
|
|
#define taskSCHEDULER_NOT_STARTED ( ( BaseType_t ) 1 )
|
|
#define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 )
|
|
|
|
/* Used with the uxTaskGetSystemState() function to return the state of each task
|
|
in the system. */
|
|
typedef struct TaskStatus_t {
|
|
TaskHandle_t xHandle; /* The handle of the task to which the rest of the information in the structure relates. */
|
|
const char *pcTaskName; /* A pointer to the task's name. This value will be invalid if the task was deleted since the structure was populated! */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
|
|
UBaseType_t xTaskNumber; /* A number unique to the task. */
|
|
eTaskState eCurrentState; /* The state in which the task existed when the structure was populated. */
|
|
UBaseType_t uxCurrentPriority; /* The priority at which the task was running (may be inherited) when the structure was populated. */
|
|
UBaseType_t uxBasePriority; /* The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex. Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */
|
|
uint32_t ulRunTimeCounter; /* The total run time allocated to the task so far, as defined by the run time stats clock. See http://www.freertos.org/rtos-run-time-stats.html. Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */
|
|
//StackType_t *pxStackBase; /* Points to the lowest address of the task's stack area. */
|
|
uint16_t usStackHighWaterMark; /* The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */
|
|
}TaskStatus_t;
|
|
|
|
/**
|
|
* configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
|
|
* uxTaskGetSystemState() to be available.
|
|
*
|
|
* uxTaskGetSystemState() populates an TaskStatus_t structure for each task in
|
|
* the system. TaskStatus_t structures contain, among other things, members
|
|
* for the task handle, task name, task priority, task state, and total amount
|
|
* of run time consumed by the task. See the TaskStatus_t structure
|
|
* definition in this file for the full member list.
|
|
*
|
|
* NOTE: This function is intended for debugging use only as its use results in
|
|
* the scheduler remaining suspended for an extended period.
|
|
*
|
|
* @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures.
|
|
* The array must contain at least one TaskStatus_t structure for each task
|
|
* that is under the control of the RTOS. The number of tasks under the control
|
|
* of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.
|
|
*
|
|
* @param uxArraySize The size of the array pointed to by the pxTaskStatusArray
|
|
* parameter. The size is specified as the number of indexes in the array, or
|
|
* the number of TaskStatus_t structures contained in the array, not by the
|
|
* number of bytes in the array.
|
|
*
|
|
* @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in
|
|
* FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the
|
|
* total run time (as defined by the run time stats clock, see
|
|
* http://www.freertos.org/rtos-run-time-stats.html) since the target booted.
|
|
* pulTotalRunTime can be set to NULL to omit the total run time information.
|
|
*
|
|
* @return The number of TaskStatus_t structures that were populated by
|
|
* uxTaskGetSystemState(). This should equal the number returned by the
|
|
* uxTaskGetNumberOfTasks() API function, but will be zero if the value passed
|
|
* in the uxArraySize parameter was too small.
|
|
*/
|
|
UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime);
|
|
|
|
/**
|
|
* task. h
|
|
* <pre>void vTaskDelay( const TickType_t xTicksToDelay );</pre>
|
|
*
|
|
* Delay a task for a given number of ticks. The actual time that the
|
|
* task remains blocked depends on the tick rate. The constant
|
|
* portTICK_PERIOD_MS can be used to calculate real time from the tick
|
|
* rate - with the resolution of one tick period.
|
|
*
|
|
* INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
|
|
* See the configuration section for more information.
|
|
*
|
|
*
|
|
* vTaskDelay() specifies a time at which the task wishes to unblock relative to
|
|
* the time at which vTaskDelay() is called. For example, specifying a block
|
|
* period of 100 ticks will cause the task to unblock 100 ticks after
|
|
* vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
|
|
* of controlling the frequency of a periodic task as the path taken through the
|
|
* code, as well as other task and interrupt activity, will effect the frequency
|
|
* at which vTaskDelay() gets called and therefore the time at which the task
|
|
* next executes. See vTaskDelayUntil() for an alternative API function designed
|
|
* to facilitate fixed frequency execution. It does this by specifying an
|
|
* absolute time (rather than a relative time) at which the calling task should
|
|
* unblock.
|
|
*
|
|
* @param xTicksToDelay The amount of time, in tick periods, that
|
|
* the calling task should block.
|
|
*
|
|
* Example usage:
|
|
|
|
void vTaskFunction( void * pvParameters )
|
|
{
|
|
// Block for 500ms.
|
|
const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
|
|
|
|
for( ;; )
|
|
{
|
|
// Simply toggle the LED every 500ms, blocking between each toggle.
|
|
vToggleLED();
|
|
vTaskDelay( xDelay );
|
|
}
|
|
}
|
|
|
|
* \defgroup vTaskDelay vTaskDelay
|
|
* \ingroup TaskCtrl
|
|
*/
|
|
void vTaskDelay( const TickType_t xTicksToDelay );
|
|
|
|
/**
|
|
* task. h
|
|
*<pre>
|
|
BaseType_t xTaskCreate(
|
|
TaskFunction_t pvTaskCode,
|
|
const char * const pcName,
|
|
configSTACK_DEPTH_TYPE usStackDepth,
|
|
void *pvParameters,
|
|
UBaseType_t uxPriority,
|
|
TaskHandle_t *pvCreatedTask
|
|
);</pre>
|
|
*
|
|
* Create a new task and add it to the list of tasks that are ready to run.
|
|
*
|
|
* Internally, within the FreeRTOS implementation, tasks use two blocks of
|
|
* memory. The first block is used to hold the task's data structures. The
|
|
* second block is used by the task as its stack. If a task is created using
|
|
* xTaskCreate() then both blocks of memory are automatically dynamically
|
|
* allocated inside the xTaskCreate() function. (see
|
|
* http://www.freertos.org/a00111.html). If a task is created using
|
|
* xTaskCreateStatic() then the application writer must provide the required
|
|
* memory. xTaskCreateStatic() therefore allows a task to be created without
|
|
* using any dynamic memory allocation.
|
|
*
|
|
* See xTaskCreateStatic() for a version that does not use any dynamic memory
|
|
* allocation.
|
|
*
|
|
* xTaskCreate() can only be used to create a task that has unrestricted
|
|
* access to the entire microcontroller memory map. Systems that include MPU
|
|
* support can alternatively create an MPU constrained task using
|
|
* xTaskCreateRestricted().
|
|
*
|
|
* @param pvTaskCode Pointer to the task entry function. Tasks
|
|
* must be implemented to never return (i.e. continuous loop).
|
|
*
|
|
* @param pcName A descriptive name for the task. This is mainly used to
|
|
* facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default
|
|
* is 16.
|
|
*
|
|
* @param usStackDepth The size of the task stack specified as the number of
|
|
* variables the stack can hold - not the number of bytes. For example, if
|
|
* the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
|
|
* will be allocated for stack storage.
|
|
*
|
|
* @param pvParameters Pointer that will be used as the parameter for the task
|
|
* being created.
|
|
*
|
|
* @param uxPriority The priority at which the task should run. Systems that
|
|
* include MPU support can optionally create tasks in a privileged (system)
|
|
* mode by setting bit portPRIVILEGE_BIT of the priority parameter. For
|
|
* example, to create a privileged task at priority 2 the uxPriority parameter
|
|
* should be set to ( 2 | portPRIVILEGE_BIT ).
|
|
*
|
|
* @param pvCreatedTask Used to pass back a handle by which the created task
|
|
* can be referenced.
|
|
*
|
|
* @return pdPASS if the task was successfully created and added to a ready
|
|
* list, otherwise an error code defined in the file projdefs.h
|
|
*/
|
|
BaseType_t xTaskCreate(
|
|
TaskFunction_t pxTaskCode,
|
|
const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
|
|
const configSTACK_DEPTH_TYPE usStackDepth,
|
|
void * const pvParameters,
|
|
UBaseType_t uxPriority,
|
|
TaskHandle_t * const pxCreatedTask );
|
|
|
|
/**
|
|
* task. h
|
|
* <PRE>BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );</PRE>
|
|
*
|
|
* configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
|
|
* to be available.
|
|
*
|
|
* When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
|
|
* "notification value", which is a 32-bit unsigned integer (uint32_t).
|
|
*
|
|
* Events can be sent to a task using an intermediary object. Examples of such
|
|
* objects are queues, semaphores, mutexes and event groups. Task notifications
|
|
* are a method of sending an event directly to a task without the need for such
|
|
* an intermediary object.
|
|
*
|
|
* A notification sent to a task can optionally perform an action, such as
|
|
* update, overwrite or increment the task's notification value. In that way
|
|
* task notifications can be used to send data to a task, or be used as light
|
|
* weight and fast binary or counting semaphores.
|
|
*
|
|
* xTaskNotifyGive() is a helper macro intended for use when task notifications
|
|
* are used as light weight and faster binary or counting semaphore equivalents.
|
|
* Actual FreeRTOS semaphores are given using the xSemaphoreGive() API function,
|
|
* the equivalent action that instead uses a task notification is
|
|
* xTaskNotifyGive().
|
|
*
|
|
* When task notifications are being used as a binary or counting semaphore
|
|
* equivalent then the task being notified should wait for the notification
|
|
* using the ulTaskNotificationTake() API function rather than the
|
|
* xTaskNotifyWait() API function.
|
|
*
|
|
* See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
|
|
*
|
|
* @param xTaskToNotify The handle of the task being notified. The handle to a
|
|
* task can be returned from the xTaskCreate() API function used to create the
|
|
* task, and the handle of the currently running task can be obtained by calling
|
|
* xTaskGetCurrentTaskHandle().
|
|
*
|
|
* @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the
|
|
* eAction parameter set to eIncrement - so pdPASS is always returned.
|
|
*
|
|
* \defgroup xTaskNotifyGive xTaskNotifyGive
|
|
* \ingroup TaskNotifications
|
|
*/
|
|
BaseType_t xTaskNotifyGive(TaskHandle_t xTaskToNotify);
|
|
//#define xTaskNotifyGive( xTaskToNotify ) xTaskGenericNotify( ( xTaskToNotify ), ( 0 ), eIncrement, NULL )
|
|
//BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue );
|
|
|
|
/*
|
|
* Return the handle of the calling task.
|
|
*/
|
|
TaskHandle_t xTaskGetCurrentTaskHandle();
|
|
|
|
/*
|
|
* Returns the scheduler state as taskSCHEDULER_RUNNING,
|
|
* taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
|
|
*/
|
|
BaseType_t xTaskGetSchedulerState();
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* INC_TASK_H */
|