FreeRTOS Emulator with SDL2 Based Graphics and Input Library
1.0
A POSIX wrapper to run FreeRTOS on an x86 machine with some basic input and output libraries aimed at making teaching FreeRTOS simpler.
|
This basic state machine implementation shows the basic concept of a state machine where each state is represented by a data object that contains function points to an init, enter, run and exit function. More...
Functions | |
unsigned char | uStatesInit (void) |
Initialized the states stored in the state machine by calling their probe functions, if set. More... | |
unsigned char | uStatesRun (void) |
Ticks the state machine over. More... | |
int | xStatesAdd (void(*probe)(void), void(*enter)(void), void(*run)(void), void(*exit)(void), int ID, char *name) |
Adds a state to the state machine. More... | |
void | vStatesSetCallback (void(*callback)(void)) |
Sets the callback function for the state machine. More... | |
void | vStatesSetData (void *data) |
Sets the data of the current state. More... | |
void | vStatesSetInput (unsigned char input) |
Sets the input variable stored in the state machine. More... | |
unsigned char | uStatesSetState (unsigned int state_id) |
Sets the next state of the state machine using the state's ID. More... | |
void * | pStatesGetData (void) |
Returns a pointer to the data stored in the current state. More... | |
char * | pStatesGetStateName (void) |
Returns the string of the current state's name. More... | |
unsigned char | uStatesGetInput (void) |
Retrieves the input vector stored within the state machine. More... | |
int | xStatesGetStateID (void) |
Returns the ID of the current state. More... | |
int | xStatesGetStateCount (void) |
Returns the number of states currently stored within the state machine. More... | |
int | xStatesIncrementState (void) |
Increments the state to the next in the linked list of states. More... | |
int | xStatesDecrementState (void) |
Decrements the state to the previous in the linked list of states. More... | |
void | vStatesClearInput (void) |
Clears the 8 bit input vector stored in the state machine. More... | |
This basic state machine implementation shows the basic concept of a state machine where each state is represented by a data object that contains function points to an init, enter, run and exit function.
Basic use of this framework requires the user to firstly add the states using
The handler functions take the form seen in xStatesAdd().
Once the states have been added an optional callback can be set for the state machine. It runs after the execution of each state machine cycle. This is set using
The states can then be initialized such that their probe functions are called. This is done using
The initial state can be set using
Otherwise the first state added is run by default. This call is the same that is used to change state during the machines execution.
void* pStatesGetData | ( | void | ) |
Returns a pointer to the data stored in the current state.
The data is stored using a void pointer and must be type cast once returned.
char* pStatesGetStateName | ( | void | ) |
Returns the string of the current state's name.
unsigned char uStatesGetInput | ( | void | ) |
Retrieves the input vector stored within the state machine.
unsigned char uStatesInit | ( | void | ) |
Initialized the states stored in the state machine by calling their probe functions, if set.
First added state is the initial state if possible
unsigned char uStatesRun | ( | void | ) |
Ticks the state machine over.
A call to states_run will cause the state machine to check if a state change is pending, if so then the appropriate exit and enter functions for the current and next states will be called. The run function of the next state will be run after the state change. If there is no state change to be done then the run function of the current state is simply called.
SM callback if set
unsigned char uStatesSetState | ( | unsigned int | state_id | ) |
Sets the next state of the state machine using the state's ID.
To change state in the state machine you must set the next state's ID which will then be handled during the next call to states_run. This will ensure the the current state's exit function is called before the next state's enter function is called.
state_id | ID of the state that is to be run next |
void vStatesClearInput | ( | void | ) |
Clears the 8 bit input vector stored in the state machine.
void vStatesSetCallback | ( | void(*)(void) | callback | ) |
Sets the callback function for the state machine.
The callback function is run at the end of each cycle of th state machine, the cycle being called using states_run.
callback | A function pointer to the function that is to be called |
void vStatesSetData | ( | void * | data | ) |
Sets the data of the current state.
data | A void pointer to the data structure that is to be stored in the current state |
void vStatesSetInput | ( | unsigned char | input | ) |
Sets the input variable stored in the state machine.
The input variable of the state machine is a buffer to hold input that can be set from within the input function (interupts, polling, etc.)
input | 8 bit input vector |
int xStatesAdd | ( | void(*)(void) | probe, |
void(*)(void) | enter, | ||
void(*)(void) | run, | ||
void(*)(void) | exit, | ||
int | ID, | ||
char * | name | ||
) |
Adds a state to the state machine.
probe | A function pointer to the state's init function |
enter | A function pointer to the state's enter function |
run | A function pointer to the state's run function |
exit | A function pointer to the state's exit function |
ID | The state's unique ID number |
name | A string representation of the state's name |
int xStatesDecrementState | ( | void | ) |
Decrements the state to the previous in the linked list of states.
int xStatesGetStateCount | ( | void | ) |
Returns the number of states currently stored within the state machine.
int xStatesGetStateID | ( | void | ) |
Returns the ID of the current state.
int xStatesIncrementState | ( | void | ) |
Increments the state to the next in the linked list of states.