Skip to content

polymurph/tinyFSM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tinyFSM

lightweight threadsafe finite state machine (FSM) framework written in C.

This framework allows fast and easy implementation and has no dependencies to any libraryes.

How to implement tinyFSM

Implementation

First create a fsm object.

  fsm_t fsm;

It then needs to be initialized.

  fsmInit(&fsm, entryState, entryAction);

Once the fsm is initialized the fsm can be executed in a loop e.g.

  while(fsmRun(&fsm)!=FSM_RUNNING);

The constant checking if the return of FSM_RUNNING is done in order to stop looping if the FSM ended or a fault occured.

Creating states

The states must be of the form shown here.

void state_example(void)
{
  // your code here
}

It must have an c void as argument and return.

NOTE: no infinite loops are allowed inside this function, as this will inhibit the functionality of the FSM.

Creating actions

The action must be of the form shown here.

void action_example(void)
{
  // your code here
}

It must have an c void as argument and return.

NOTE: no infinite loops are allowed inside this function, as this will inhibit the functionality of the FSM.

Transitioning states

The followin example shows how a state can be transitioned.

void state_example(void)
{
  // your code here
  
  if(your condition){
    fsmTransitionState(&fsmObject, next_state, state_transition_action);
    return;
  }
}

Initial Author Edwin Koch This work is licensed under MIT. See the LICENSE file in the project root for more information.