FreeRTOS Addons
|
#include <thread.hpp>
Public Member Functions | |
Thread (const char *Name, uint16_t StackDepth, UBaseType_t Priority) | |
Thread (const std::string Name, uint16_t StackDepth, UBaseType_t Priority) | |
Thread (uint16_t StackDepth, UBaseType_t Priority) | |
virtual | ~Thread () |
TaskHandle_t | GetHandle () |
std::string | GetName () |
char * | GetName () |
UBaseType_t | GetPriority () |
UBaseType_t | GetPriorityFromISR () |
void | Resume () |
void | ResumeFromISR () |
void | SetPriority (UBaseType_t NewPriority) |
bool | Start () |
bool | Start (int core) |
Starts the task on the indicated core. More... | |
void | Suspend () |
Static Public Member Functions | |
static void | EndScheduler () |
static void | StartScheduler () |
static void | Yield () |
Protected Member Functions | |
virtual void | Cleanup () |
void | Delay (const TickType_t Delay) |
void | DelayUntil (const TickType_t Period) |
void | ResetDelayUntil () |
virtual void | Run ()=0 |
bool | Wait (ConditionVariable &Cv, Mutex &CvLock, TickType_t Timeout=portMAX_DELAY) |
Friends | |
class | ConditionVariable |
Wrapper class around FreeRTOS's implementation of a task.
This is an abstract base class. To use this, you need to subclass it. All of your threads should be derived from the Thread class. Then implement the virtual Run function. This is a similar design to Java threading.
By default, we leverage C++ strings for the Thread Name. If this is not desirable, define CPP_FREERTOS_NO_CPP_STRINGS and the class will fall back to C character arrays.
Thread::Thread | ( | const std::string | Name, |
uint16_t | StackDepth, | ||
UBaseType_t | Priority | ||
) |
Thread::Thread | ( | uint16_t | StackDepth, |
UBaseType_t | Priority | ||
) |
|
virtual |
Our destructor. This must exist even if FreeRTOS is configured to disallow task deletion.
|
protectedvirtual |
Called on exit from your Run() routine.
It is optional whether you implement this or not.
If you allow your Thread to exit its Run method, implementing a Cleanup method allows you to call your Thread's destructor. If you decide to call delete in your Cleanup function, be aware that additional derived classes shouldn't call delete.
|
inlineprotected |
If we can't delete a task, it makes no sense to have a Cleanup routine. Delay this thread for at least Delay ticks.
Delay | How long to delay the thread. |
|
protected |
Delay this thread for Period ticks, taking into account the execution time of the thread.
This FreeRTOS permutation of delay can be used by periodic tasks to ensure a constant execution frequency.
Period | How long to delay the thread. |
|
inlinestatic |
End the scheduler.
|
inline |
Accessor to get the thread's backing task handle. There is no setter, on purpose.
|
inline |
Get the name of this thread.
|
inline |
Get the priority of this Thread.
|
inline |
Get the priority of this Thread from ISR context.
|
protected |
If you need to adjust or reset the period of the DelayUntil method.
|
inline |
Resume a specific thread.
|
inline |
Resume a specific thread from ISR context.
|
protectedpure virtual |
Implementation of your actual thread code. You must override this function.
Implemented in cpp_freertos::Task.
|
inline |
Set the priority of this thread.
NewPriority | The thread's new priority. |
bool Thread::Start | ( | ) |
Starts a thread.
This is the API call that actually starts the thread running. It creates a backing FreeRTOS task. By separating object creation from starting the Thread, it solves the pure virtual fuction call failure case. If we attempt to automatically call xTaskCreate from the base class constructor, in certain conditions the task starts to run "before" the derived class is constructed! So we don't do that anymore.
This may be called from your ctor once you have completed your objects construction (so as the last step).
This should only be called once ever!
bool Thread::Start | ( | int | core | ) |
Starts the task on the indicated core.
core |
|
inlinestatic |
Start the scheduler.
|
inline |
|
protected |
Have this thread wait on a condition variable.
Cv | The condition variable associated with the Wait. |
CvLock | The required condition variable lock. The Lock must be held before calling Wait. |
Timeout | Allows you to specify a timeout on the Wait, if desired. |
|
inlinestatic |
Yield the scheduler.
|
friend |
The Thread class and the ConditionVariable class are interdependent. If we allow the ConditionVariable class to access the internals of the Thread class, we can reduce the public interface, which is a good thing.