Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
pru_sm.c
Go to the documentation of this file.
1 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
2  *
3  * The information contained herein is property of Nordic Semiconductor ASA.
4  * Terms and conditions of usage are described in detail in NORDIC
5  * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
6  *
7  * Licensees are granted free, non-transferable use of the information. NO
8  * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
9  * the file.
10  *
11  */
12 
15 #include <string.h>
16 #include "pru_sm.h"
17 
18 /******************************************************************************/
21 /******************************************************************************/
22 
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 }
66 /******************************************************************************/
69 /******************************************************************************/
70 
72 {
73  static pru_sm_state_t current_state = PRU_SM_STATE_NULL;
74 
75  if(signal != PRU_SM_SIGNAL_NULL && p_state != NULL)
76  {
77  p_state->next_state = m_get_next_state(signal, p_state);
78  p_state->prev_state = p_state->current_state;
79  p_state->current_state = p_state->next_state;
80  current_state = p_state->current_state;
81  }
82 
83  return current_state;
84 }
85 
State machine state variables.
Definition: pru_sm.h:55
pru_sm_state_t
PRU states.
Definition: pru_sm.h:26
pru_sm_state_t prev_state
Definition: pru_sm.h:57
pru_sm_state_t current_state
Definition: pru_sm.h:58
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.
Definition: pru_sm.c:30
pru_sm_signal_type_t
PRU state machine signal type.
Definition: pru_sm.h:36
pru_sm_state_t next_state
Definition: pru_sm.h:59
pru_sm_state_t pru_sm_execute(pru_sm_signal_type_t signal, pru_sm_state_vars_t *p_state)
Execute state machine.
Definition: pru_sm.c:71