#include <scheduler_task.hpp>
Public Member Functions | |
const char * | getTaskName (void) const |
uint32_t | getFreeStack (void) const |
uint32_t | getRunCount (void) const |
TaskHandle_t | getTaskHandle (void) const |
uint8_t | getTaskPriority (void) const |
void | suspend (void) const |
void | resume (void) const |
Static Public Member Functions | |
static scheduler_task * | getTaskPtrByName (const char *) |
static bool | addSharedObject (const char *name, void *obj_ptr) |
static void * | getSharedObject (const char *name) |
static bool | addSharedObject (uint8_t index, void *obj_ptr) |
static void * | getSharedObject (uint8_t index) |
Protected Member Functions | |
scheduler_task (const char *name, uint32_t stack, uint8_t priority, void *param=0) | |
virtual | ~scheduler_task () |
virtual bool | init (void) |
virtual bool | regTlm (void) |
virtual bool | taskEntry (void) |
virtual bool | run (void *param)=0 |
void | setRunDuration (uint32_t milliseconds) |
uint32_t | getRunDuration (void) const |
void | setStatUpdateRate (uint32_t rateMs) |
Friends | |
bool | scheduler_init_all (bool register_task_tlm) |
void | scheduler_c_task_private (void *param) |
static uint8_t | getSysCpuPercent (void) |
Get total system CPU percent. More... | |
static uint8_t | getSysIdlePercent (void) |
Get total system IDLE percent. More... | |
uint8_t | getTaskCpuPercent (void) const |
Get CPU usage of this task. More... | |
Detailed Description
Scheduler task. This class should be inherited and at minimum, you would need to override the run() function to execute as part of your task. Note that the run() function should return as the scheduler is responsible for the FreeRTOS task loop.
All tasks perform init() one after another, followed by taskEntry(). Only after all tasks perform their init() and taskEntry(), the run() method begins to loop, so this solves the initialization dependency problem.
The order of operations is the following :
- All tasks call their: init()
- All tasks call their: regTlm()
- FreeRTOS is started
- All tasks call their: taskEntry()
- All tasks enter loop to call run() method
Note that until you get to the run() function, you are essentially in a "thread safe" mode since context or task switch will not occur.
Example task that prints a message every 1000ms :
Constructor & Destructor Documentation
|
protected |
Constructor
- Parameters
-
name The task's name stack The task's stack size in bytes priority FreeRTOS task priority param OPTIONAL param to pass to your run() when it's called.
|
inlineprotectedvirtual |
Member Function Documentation
|
static |
Add/Get a shared object pointer by name such that multiple classes of this type can communicate between themselves.
- Note
- It is recommended to use the later version of addSharedObject() and getSharedObject() because it is faster. Consider this version of overloaded API deprecated – :)
- Note
- These functions are declared static because that way, any code in any context can get a shared object. So a C function (ie terminal cmd) can get a shared object and queue data for a task. Here is the usage (use the scope operator directly):
|
static |
Add or get a shared object by an index number. This provides a better alternative to sharing handles because strcmp() doesn't take place, instead the getSharedObject() simply returns the handle at the index.
This index is best utilized by using an enumeration, such as this:
- Note
- These functions are declared static because that way, any code in any context can get a shared object. So a C function (ie terminal cmd) can get a shared object and queue data for a task. Here is the usage (use the scope operator directly):
|
inline |
|
inline |
|
inlineprotected |
- Returns
- the run duration set by setRunDuration()
|
static |
|
static |
|
static |
Get total system CPU percent.
|
static |
Get total system IDLE percent.
uint8_t scheduler_task::getTaskCpuPercent | ( | void | ) | const |
Get CPU usage of this task.
CPU usage API
- Note
- static functions can be called from any function, even not belonging to this class.
|
inline |
|
inline |
Get methods Tasks can get each others' pointers by using their task names. After obtaining the pointer, they can get each other's CPU usage, and task handle.
|
inline |
|
static |
Get a task pointer by name This is declared static such that any code in any context can retrieve a task pointer by name. Here is the usage (use the scope operator directly):
Static functions:
|
inlineprotectedvirtual |
Optional: Override this function to initialize anything before FreeRTOS starts.
- Returns
- true upon success.
- Warning
- DO NOT USE FreeRTOS blocking API in this function
|
inlineprotectedvirtual |
Optional: Override this function to register your telemetry before FreeRTOS starts.
- Returns
- true upon success.
- Warning
- DO NOT USE FreeRTOS blocking API in this function
|
inline |
|
protectedpure virtual |
MUST override this function to run your tasks' code
- Parameters
-
param The same pointer as the constructor's param
- Returns
- false if something unexpected occurs. In this case, the task will be suspended from doing further work.
|
inlineprotected |
This can be used to set a desired time that the run() method will be called. For example, if frequency is set to 1000, then the run() will be called every 1 second regardless the duration that your run() method. If your run() takes longer than the milliseconds you set, then it will be called without a delay.
- Parameters
-
milliseconds The frequency to call your run() function. Set this to zero to disable this functionality.
- Note
- By default, run() method is called continuously without a delay.
|
inlineprotected |
Set the update rate in milliseconds that the free stack size is calculated at. Default rate is 60 seconds; zero is to disable it.
|
inline |
Suspend and resume functions. Obviously you can suspend yourself but someone else will have to resume you ;)
|
inlineprotectedvirtual |
Optional : Override this function which is called ONCE after FreeRTOS starts If your task depends on someone else's init(), then you can put your relevant code here that is called after everyone's init(). You CAN use FreeRTOS API but note that all other tasks will wait for everyone's taskEntry() to take place before the run() method is called.
- Warning
- Do not suspend your task otherwise all tasks will get suspended.
- Returns
- true upon success.
Friends And Related Function Documentation
|
friend |
This is the C task that is created multiple times. Each task receives its own parameter therefore differentiating between different tasks.
|
friend |
Give access to our private members to these functions
The documentation for this class was generated from the following files:
- /var/www/html/SJSU-DEV-Linux/firmware/default/lib/L3_Utils/scheduler_task.hpp
- /var/www/html/SJSU-DEV-Linux/firmware/default/lib/L3_Utils/src/scheduler_task.cpp