NTURT Zephyr v0.0.1
NTURT common library for Zephyr RTOS
Loading...
Searching...
No Matches
States

Control system state machine. More...

+ Collaboration diagram for States:

Data Structures

struct  states_trans_cmd_info
 State transition command information. More...
 
struct  states_callback
 State transition callback. More...
 

Macros

#define STATES_CALLBACK_DEFINE_NAMED(_name, _states, _handler, _user_data)
 Same as STATES_CALLBACK_DEFINE, but with a custom name for the callback.
 
#define STATES_CALLBACK_DEFINE(states, handler, user_data)
 Define a callback for state transition.
 

Typedefs

typedef uint32_t states_t
 State machine states type, where each bit represents a state defined in states_state.
 
typedef void(* states_handler_t) (enum states_state state, bool is_entry, void *user_data)
 State transition handler type.
 

Enumerations

enum  states_state {
  STATE_INVALID = 0 , STATE_ERR_FREE = BIT(0) , STATE_READY = BIT(1) , STATE_RTD_BLINK = BIT(2) ,
  STATE_RTD_STEADY = BIT(3) , STATE_RTD_READY = BIT(4) , STATE_RTD_SOUND = BIT(5) , STATE_RUNNING = BIT(6) ,
  STATE_ERR = BIT(7) , STATE_ALL = UINT32_MAX , NUM_STATE = 8
}
 State machine states. More...
 
enum  states_trans_cmd {
  TRANS_CMD_INVALID = 0 , TRANS_CMD_ERR , TRANS_CMD_ERR_CLEAR , TRANS_CMD_PEDAL ,
  TRANS_CMD_PEDAL_CLEAR , TRANS_CMD_RTD , TRANS_CMD_RTD_FINISH , TRANS_CMD_DISABLE ,
  NUM_TRANS_CMD
}
 State transition commands. More...
 

Functions

states_t states_get ()
 Get the current states.
 
bool states_valid_transition (enum states_trans_cmd cmd)
 Test if a state transition command is valid.
 
void states_transition (enum states_trans_cmd cmd)
 Execute a state transition command to transition to a new state.
 
const char * states_state_str (enum states_state state)
 Get the string representation of a state.
 
int states_states_str (char *buf, size_t size, states_t states)
 Get the string representation of states separated by commas in the same semantic as snprintf.
 
const struct states_trans_cmd_infostates_transition_info (enum states_trans_cmd cmd)
 Get the information of a state transition.
 

Detailed Description

Control system state machine.

Macro Definition Documentation

◆ STATES_CALLBACK_DEFINE

#define STATES_CALLBACK_DEFINE ( states,
handler,
user_data )

#include <vcu/ctrl/states.h>

Value:
STATES_CALLBACK_DEFINE_NAMED(CONCAT(__states_handler_, handler), states, \
handler, user_data)
#define STATES_CALLBACK_DEFINE_NAMED(_name, _states, _handler, _user_data)
Same as STATES_CALLBACK_DEFINE, but with a custom name for the callback.
Definition states.h:35

Define a callback for state transition.

Parameters
[in]statesWhen transition from/to what states to call the callback. Multiple states_state can be specified using bitwise OR operator (|).
[in]handlerHandler of the state transition.
[in]user_dataPointer to custom data for the callback.
Note
Since the name of the callback is derived from the name of handler , if the same handler is used for multiple callbacks, STATES_CALLBACK_DEFINE_NAMED can be used instead to prevent linker errors.

◆ STATES_CALLBACK_DEFINE_NAMED

#define STATES_CALLBACK_DEFINE_NAMED ( _name,
_states,
_handler,
_user_data )

#include <vcu/ctrl/states.h>

Value:
static const STRUCT_SECTION_ITERABLE(states_callback, _name) = { \
.states = _states, \
.handler = _handler, \
.user_data = _user_data, \
}
State transition callback.
Definition states.h:126

Same as STATES_CALLBACK_DEFINE, but with a custom name for the callback.

Typedef Documentation

◆ states_handler_t

typedef void(* states_handler_t) (enum states_state state, bool is_entry, void *user_data)

#include <vcu/ctrl/states.h>

State transition handler type.

Parameters
[in]stateto transition from/to.
[in]is_entryTrue when transitioning to the state. False when transition from.
[in,out]user_dataPointer to custom data for the callback provided by STATES_CALLBACK_DEFINE.

◆ states_t

typedef uint32_t states_t

#include <vcu/ctrl/states.h>

State machine states type, where each bit represents a state defined in states_state.

Enumeration Type Documentation

◆ states_state

#include <vcu/ctrl/states.h>

State machine states.

Enumerator
STATE_INVALID 
STATE_ERR_FREE 
STATE_READY 
STATE_RTD_BLINK 
STATE_RTD_STEADY 
STATE_RTD_READY 
STATE_RTD_SOUND 
STATE_RUNNING 
STATE_ERR 
STATE_ALL 
NUM_STATE 

◆ states_trans_cmd

#include <vcu/ctrl/states.h>

State transition commands.

Enumerator
TRANS_CMD_INVALID 
TRANS_CMD_ERR 
TRANS_CMD_ERR_CLEAR 
TRANS_CMD_PEDAL 
TRANS_CMD_PEDAL_CLEAR 
TRANS_CMD_RTD 
TRANS_CMD_RTD_FINISH 
TRANS_CMD_DISABLE 
NUM_TRANS_CMD 

Function Documentation

◆ states_get()

states_t states_get ( )

#include <vcu/ctrl/states.h>

Get the current states.

Returns
states_t Current states.

◆ states_state_str()

const char * states_state_str ( enum states_state state)

#include <vcu/ctrl/states.h>

Get the string representation of a state.

Parameters
[in]stateState.
Returns
const char* String representation.

◆ states_states_str()

int states_states_str ( char * buf,
size_t size,
states_t states )

#include <vcu/ctrl/states.h>

Get the string representation of states separated by commas in the same semantic as snprintf.

Parameters
[out]bufBuffer to store the string representation.
[in]sizeSize of the buffer.
[in]statesStates.
Returns
int Number of bytes written to the buffer, excluding the null terminator which would be written if the buffer is large enough.

◆ states_transition()

void states_transition ( enum states_trans_cmd cmd)

#include <vcu/ctrl/states.h>

Execute a state transition command to transition to a new state.

Parameters
[in]cmdState transition command.
Warning
Must not be called from an ISR or within a state transition callback.

◆ states_transition_info()

const struct states_trans_cmd_info * states_transition_info ( enum states_trans_cmd cmd)

#include <vcu/ctrl/states.h>

Get the information of a state transition.

Parameters
[in]cmdState transition command.
Returns
const struct states_trans_cmd_info* Pointer to the state transition command information.

◆ states_valid_transition()

bool states_valid_transition ( enum states_trans_cmd cmd)

#include <vcu/ctrl/states.h>

Test if a state transition command is valid.

Parameters
[in]cmdState transition command.
Return values
trueIf the command can be executed.
falseIf the command cannot be executed.