Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
pru_sm.c File Reference
#include <string.h>
#include "pru_sm.h"

Go to the source code of this file.

Functions

Static functions and variables
static pru_sm_state_t m_get_next_state (pru_sm_signal_type_t signal, pru_sm_state_vars_t *p_state)
 Find the next state given the current state and the state machine event. More...
 
API implementation
pru_sm_state_t pru_sm_execute (pru_sm_signal_type_t signal, pru_sm_state_vars_t *p_state)
 Execute state machine. More...
 

Function Documentation

static pru_sm_state_t m_get_next_state ( pru_sm_signal_type_t  signal,
pru_sm_state_vars_t p_state 
)
static

Find the next state given the current state and the state machine event.

Parameters
signalState machine signal.
p_statePointer to PRU state variable.
Returns
The resulting state.

Definition at line 30 of file pru_sm.c.

31 {
32  pru_sm_state_t next_state = p_state->current_state;
33 
34  switch(p_state->current_state)
35  {
36  case PRU_SM_STATE_NULL:
37  if( signal == PRU_SM_SIGNAL_POWER_APPLIED) next_state = PRU_SM_STATE_BOOT;
38  break;
39 
40  case PRU_SM_STATE_BOOT:
41  if( signal == PRU_SM_SIGNAL_CHARGE_START) next_state = PRU_SM_STATE_PRU_ON;
42  else if(signal == PRU_SM_SIGNAL_POWER_REMOVED) next_state = PRU_SM_STATE_NULL;
43  else if(signal == PRU_SM_SIGNAL_SYSTEM_ERROR) next_state = PRU_SM_STATE_SYSTEM_ERROR;
44  break;
45 
46  case PRU_SM_STATE_PRU_ON:
47  if( signal == PRU_SM_SIGNAL_CHARGE_STOP) next_state = PRU_SM_STATE_BOOT;
48  else if(signal == PRU_SM_SIGNAL_CHARGE_COMPLETE) next_state = PRU_SM_STATE_BOOT;
49  else if(signal == PRU_SM_SIGNAL_DISCONNECTED) next_state = PRU_SM_STATE_BOOT;
50  else if(signal == PRU_SM_SIGNAL_POWER_REMOVED) next_state = PRU_SM_STATE_NULL;
51  else if(signal == PRU_SM_SIGNAL_SYSTEM_ERROR) next_state = PRU_SM_STATE_SYSTEM_ERROR;
52  break;
53 
54  case PRU_SM_STATE_SYSTEM_ERROR:
55  if( signal == PRU_SM_SIGNAL_POWER_REMOVED) next_state = PRU_SM_STATE_NULL;
56  break;
57 
58  default:
59  break;
60  }
61 
62  return next_state; // No state change
63 }
pru_sm_state_t
PRU states.
Definition: pru_sm.h:26
pru_sm_state_t current_state
Definition: pru_sm.h:58