|
RTOS Wrapper
API reference
|
Abstract class to assist in designing thread-based execution sequences. More...
#include <BaseThread.h>
Public Member Functions | |
| BaseThread (const char *threadName) | |
| Construct a new Base Thread object. | |
| BaseThread (const BaseThread &)=delete | |
| The Copy constructor is deleted to avoid copying instances. | |
| BaseThread & | operator= (const BaseThread &)=delete |
| The assignment operator constructor is deleted to avoid copying instances. | |
| virtual | ~BaseThread () noexcept |
| The destructor de-initializes the singleton. It is not likely to be called in released products, but is implemented to support unit testing. | |
| OS_Thread * | GetThreadId () noexcept |
| Get the pointer to the thread. | |
| bool | IsInitialized () const noexcept |
| This function checks if the class is initialized;. | |
| bool | EnsureInitialized () noexcept |
| Initialize the thread. | |
| bool | Suspend () noexcept |
| Suspend the underlying thread OS task. | |
| bool | Resume () noexcept |
| Resume the underlying thread OS task. | |
| bool | IsSuspended () noexcept |
| Check the status of the underlying thread OS task. | |
| bool | IsThreadCreated () noexcept |
| bool | IsThreadStopRequested () noexcept |
| bool | IsSetupComplete () const noexcept |
| bool | IsThreadRunning () const noexcept |
| bool | IsThreadStopped () const noexcept |
| bool | IsCleanupComplete () const noexcept |
| bool | IsThreadInStepDelay () const noexcept |
| bool | Start () noexcept |
| Starts the thread. | |
| virtual bool | StartAction () noexcept |
| Start Action that can be run to see if Start() qualifies to start thread. | |
| bool | Stop () noexcept |
| Stops the thread. | |
| virtual bool | Setup () noexcept=0 |
| Setup the thread. | |
| virtual uint32_t | Step () noexcept=0 |
| Steps the thread through a single execution cycle . | |
| virtual bool | Cleanup () noexcept=0 |
| Cleanup code that exists once the thread step sequence is stopped. The cleanup function should generally clear the setup flag to ensure the thread goes back through setup again. | |
| const char * | GetThreadName () noexcept |
| Returns the Base thread name. | |
| bool | StartThreadAndWaitToVerify (uint32_t startTimeoutMsec=1000) |
| [BLOCKING] Signals a BaseThread to start and waits to make sure it's started within the given timeout. | |
| bool | StopThreadAndWaitToVerify (uint32_t stopTimeoutMsec) |
| [BLOCKING] Signals a BaseThread to stop and waits to make sure it's started within the given timeout. | |
| uint32_t | GetStackHighWaterMark () const noexcept |
| Get the minimum remaining stack of the task. | |
| bool | ChangePriority (uint32_t newPriority) noexcept |
| Change the running priority of the thread. | |
Protected Member Functions | |
| void | WaitForStart () noexcept |
| Starts the thread. | |
| virtual bool | Initialize () noexcept=0 |
| Function to initialize thread. Generally, the initialize function should return false rather than causing a low level fault. | |
| virtual bool | ResetVariables () noexcept=0 |
| Resets all member variables to their initial states. | |
| bool | CreateBaseThread (uint8_t *stack, OS_Ulong stackSizeBytes, OS_Uint priority, OS_Uint preempt_threshold, OS_Ulong timeSliceAllowed, OS_Uint auto_start) noexcept |
| Function to Create TX thread. | |
| bool | CreateBaseThread (uint8_t *stack, OS_Ulong stackSizeBytes, OS_Uint priority, OS_Uint preempt_threshold, OS_Ulong timeSliceAllowed, OS_Uint auto_start, int core_id) noexcept |
| Pinned-to-core variant of CreateBaseThread (FreeRTOS / SMP). | |
| void | MarkSetupComplete () noexcept |
| Mark the setup as complete. | |
| void | ClearSetupComplete () noexcept |
| Clear the setup completion flag. | |
| void | MarkCleanupComplete () noexcept |
| Mark the cleanup as complete. | |
| void | ClearCleanupComplete () noexcept |
| Clear the cleanup flag. | |
| void | MarkThreadRunning () noexcept |
| Mark the thread as running. | |
| void | ClearThreadRunning () noexcept |
| Mark the thread as not running. | |
| void | MarkThreadStopRequested () noexcept |
| Indicate a request to stop the thread. | |
| void | ClearThreadStopRequested () noexcept |
| Clear the stop request for the thread. | |
| void | MarkThreadStepInDelay () noexcept |
| Indicate a request to stop the thread. | |
| void | ClearThreadStepInDelay () noexcept |
| Clear the stop request for the thread. | |
Static Protected Member Functions | |
| static void | ThreadEntry (OS_Ulong instanceAddress) |
| Thread entry that will be running. | |
Protected Attributes | |
| bool | initialized |
| OS_Thread | osThread |
| const char * | osThreadName |
| bool | osThreadCreated |
| SignalSemaphore | signalSemaphore |
Static Protected Attributes | |
| static constexpr char | baseThreadStartSemaphoreBaseName [] = "BaseThreadStartSem-" |
Private Attributes | |
| uint32_t | waitBeforeStep |
| uint32_t | minTimestampBeforeNextStep |
| std::atomic< bool > | threadRunning |
| std::atomic< bool > | threadStepInDelay |
| std::atomic< bool > | setupComplete |
| std::atomic< bool > | cleanupComplete |
| std::atomic< bool > | stopThreadRequested |
Abstract class to assist in designing thread-based execution sequences.
Threads are intended to run indefinitely but can be started and stopped multiple times. On start, the Setup() function is executed followed by a continuous loop awaiting a stop signal, repeatedly calling the Step() function. On a stop signal, the Exit() function is executed for cleanup.
| BaseThread::BaseThread | ( | const char * | threadName | ) |
Construct a new Base Thread object.
BASE THREAD ITEMS BASE NAMES.
| threadName | Name of the thread. |
| threadSemaphore | Semaphore associated with the thread. |
Base thread start semaphore base osThreadName that will be pre-fixed on the thread Name BASE THREAD
The constructor initializes the thread and prepares it to start
No code at this moment.
|
delete |
The Copy constructor is deleted to avoid copying instances.
|
virtualnoexcept |
The destructor de-initializes the singleton. It is not likely to be called in released products, but is implemented to support unit testing.
The destructor de-initializes the thread. It is not likely to be called in released products, but will support unit testing.
|
noexcept |
Change the running priority of the thread.
|
pure virtualnoexcept |
Cleanup code that exists once the thread step sequence is stopped. The cleanup function should generally clear the setup flag to ensure the thread goes back through setup again.
|
inlineprotectednoexcept |
Clear the cleanup flag.
|
inlineprotectednoexcept |
Clear the setup completion flag.
|
inlineprotectednoexcept |
Mark the thread as not running.
|
inlineprotectednoexcept |
Clear the stop request for the thread.
|
inlineprotectednoexcept |
Clear the stop request for the thread.
|
protectednoexcept |
Function to Create TX thread.
| name | Name of thread |
| stack | - statically allocated stack |
| stackSizeBytes | Number of bytes allocated |
| priority | - thread priority |
| preempt_threshold | - thread preemption priority |
| timeSliceAllowed | - Time slice allowed to run before being preempted. |
| auto_start | - Automatic start selection. |
| osThreadName | Name of thread |
| stack | - statically allocted stack |
| stackSizeBytes | Numer of bytes allocated |
| priority | - thread priority |
| preempt_threshold | - thread preemption priority |
| timeSliceAllowed | - |
| auto_start | - |
|
protectednoexcept |
Pinned-to-core variant of CreateBaseThread (FreeRTOS / SMP).
Identical to CreateBaseThread but pins the new task to core_id. Pass core_id < 0 (e.g. -1) for "no affinity" — equivalent to the non-pinned variant. On single-core builds the affinity is ignored.
| core_id | CPU core to pin the task to (0 or 1 on ESP32-S3). |
Then, if the thread is not already created, create it
Create the OS Thread (pinned to core_id if >= 0, no affinity otherwise).
If successfully created
Mark the base thread as created.
|
inlinenoexcept |
Initialize the thread.
This function initializes and creates the thread, setting up all necessary parameters. It must be called before the thread can be started.
|
noexcept |
Get the minimum remaining stack of the task.
|
inlinenoexcept |
Get the pointer to the thread.
|
noexcept |
Returns the Base thread name.
Returns the Base thread osThreadName.
|
protectedpure virtualnoexcept |
Function to initialize thread. Generally, the initialize function should return false rather than causing a low level fault.
|
inlinenoexcept |
|
inlinenoexcept |
This function checks if the class is initialized;.
|
inlinenoexcept |
|
noexcept |
Check the status of the underlying thread OS task.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlineprotectednoexcept |
Mark the cleanup as complete.
|
inlineprotectednoexcept |
Mark the setup as complete.
|
inlineprotectednoexcept |
Mark the thread as running.
|
inlineprotectednoexcept |
Indicate a request to stop the thread.
|
inlineprotectednoexcept |
Indicate a request to stop the thread.
|
delete |
The assignment operator constructor is deleted to avoid copying instances.
|
protectedpure virtualnoexcept |
Resets all member variables to their initial states.
This method is designed to reset all member variables to a known state, either to their initial values as set in the constructor, or to zero (or false, or other suitable default values). This can be useful in situations where the object needs to be reused or reinitialized.
|
noexcept |
Resume the underlying thread OS task.
|
pure virtualnoexcept |
Setup the thread.
This function setups up for execution of the thread whenever it is started or re-started. For example, this allows the valve manifold to be configured prior to starting thread thread. It can also be called prior to Start() e.g in response to settings Confirm.
|
noexcept |
Starts the thread.
This function starts the execution of the thread if not already running. This results in executing Setup() if it has not already been done. The base class implementation simply signals the associated semaphore.
The starting called may be ignored depending on case therefore a bool will be returned.
Run start action
If successful, signal the thread via the designated semaphore to start the process
Otherwise, indicate that we cannot start thread.
|
virtualnoexcept |
| bool BaseThread::StartThreadAndWaitToVerify | ( | uint32_t | startTimeoutMsec = 1000 | ) |
[BLOCKING] Signals a BaseThread to start and waits to make sure it's started within the given timeout.
| threadToStart | BaseThread to start |
| startTimeoutMsec | Timeout to make sure Thread has started in Milliseconds. |
Start the thread
Function that will test if the thread has been started
Expecting true within the timeout specified
Return result
Return false indicating Start() call failure
|
pure virtualnoexcept |
|
noexcept |
Stops the thread.
This function stops the execution of the thread. The thread can be resumed later by calling service_start(). The base class simple sets the variable indicating the thread should stop.
In case we are somehow suspended in our step, let's resume.
| bool BaseThread::StopThreadAndWaitToVerify | ( | uint32_t | stopTimeoutMsec | ) |
[BLOCKING] Signals a BaseThread to stop and waits to make sure it's started within the given timeout.
| threadToStop | BaseThread to stop |
| stopTimeoutMsec | Timeout to make sure Thread has stopped in Milliseconds. |
Stop the thread
Function that will test if the thread has been stopped
Expecting true within the timeout specified
Return result
Return false indicating Stop() call failure
|
noexcept |
Suspend the underlying thread OS task.
|
staticprotected |
Thread entry that will be running.
| instanceAddress |
Clear the thread running flag so that we can Start() properly.
Wait for a signal to start ( it occurs in BaseThread Start() )
Reset all necessary variables
< Thread should be marked as running immediately.
< Clear this flag in case CALLER didn't wait to send START command until the mode was completely stopped and then sent another STOP flag because CALLER doesn't see the mode starting, this should not be the case in the final product but necessary during development.
< Clear the cleanup complete flag.
Main control loop sequence
Calculate next timestamp to Step() again
Mark that we are going to a delay
Delay requested time
Clear that we are in a delay
Make sure to mark
Clean up before exiting the thread.
Let's set that the cleanup flag so that we can make that a cleanup is complete
Let's clear the setup complete flag so that a setup is ran before re-entering loop.
|
protectednoexcept |
Starts the thread.
Puts the caller thread in a waiting state until the service_start() is called.
This function waits for the thread to be signalled to start.
|
staticconstexprprotected |
|
private |
|
protected |
|
private |
|
protected |
|
protected |
|
protected |
|
private |
|
protected |
|
private |
|
private |
|
private |
|
private |