Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
ptu_latching_fault.h File Reference
#include <stdint.h>
#include "ptu.h"

Go to the source code of this file.

Functions

uint32_t ptu_latching_fault_entered (ptu_sm_state_t previous)
 Handle the entry of latching fault state. More...
 
uint32_t ptu_latching_fault_init (ptu_sm_handler_t sm_handler)
 Initialize latching fault module. More...
 

Function Documentation

uint32_t ptu_latching_fault_entered ( ptu_sm_state_t  previous)

Handle the entry of latching fault state.

Parameters
previousThe previous state of the PTU state machine.
Returns
INVALID_STATE if current state is not latching fault, SUCCESS otherwise.

Definition at line 179 of file ptu_latching_fault.c.

180 {
181  uint32_t err_code;
182 
183  if(PTU_SM_CURRENT_STATE() != PTU_SM_STATE_LATCH_FAULT)
184  {
185  return NRF_ERROR_INVALID_STATE;
186  }
187 
189 
190  err_code = TIMER_START(m_short_beacon_timer_id, PTU_LATCH_FAULT_ENTRY_DELAY_MS, NULL);
191  APP_ERROR_CHECK(err_code);
192 
193  err_code = TIMER_START(m_reset_nof_consecutive_latching_fault_count_timer_id, PTU_LATCH_FAULT_NO_ERR_CLR_TIMEOUT_MS, NULL);
194  APP_ERROR_CHECK(err_code);
195 
196  if(m_lf_status.successive_faults ++ < PTU_LATCH_FAULT_MAX_AUTO_CLR_ATTEMPTS)
197  {
198  err_code = TIMER_START(m_clear_latching_fault_timer_id, PTU_LATCH_FAULT_EXIT_ATTEMPT_DELAY_MS, NULL);
199  APP_ERROR_CHECK(err_code);
200  }
201 
202  else
203  {
204  // Count of successive latching faults indicates that PTU is now in persistent latching fault
205  m_lf_status.persistent = true;
206  }
207 
208  return NRF_SUCCESS;
209 }
static lf_status_t m_lf_status
#define PTU_LATCH_FAULT_ENTRY_DELAY_MS
Definition: ptu_config.h:205
#define TIMER_START(timer_id, ms, p_ctx)
Definition: wpt.h:32
#define PTU_LATCH_FAULT_NO_ERR_CLR_TIMEOUT_MS
Definition: ptu_config.h:209
#define PTU_LATCH_FAULT_EXIT_ATTEMPT_DELAY_MS
Definition: ptu_config.h:206
#define PTU_SM_CURRENT_STATE()
Definition: ptu.h:36
#define PTU_LATCH_FAULT_MAX_AUTO_CLR_ATTEMPTS
Definition: ptu_config.h:207
uint32_t ptu_latching_fault_init ( ptu_sm_handler_t  sm_handler)

Initialize latching fault module.

Parameters
sm_handlerThe state machine handler of the PTU.
Returns
INVALID_PARAM if sm_handler is NULL, SUCCESS otherwise.

Definition at line 212 of file ptu_latching_fault.c.

213 {
214  uint32_t err_code;
215 
216  if(sm_handler == NULL)
217  {
218  return NRF_ERROR_INVALID_PARAM;
219  }
220 
221  m_ptu_sm_execute = sm_handler;
222 
223  memset(&m_lf_status, 0, sizeof(lf_status_t));
224 
225  err_code = app_timer_create(&m_clear_latching_fault_timer_id,
226  APP_TIMER_MODE_SINGLE_SHOT,
228  APP_ERROR_CHECK(err_code);
229 
230  err_code = app_timer_create(&m_short_beacon_timer_id,
231  APP_TIMER_MODE_SINGLE_SHOT,
233  APP_ERROR_CHECK(err_code);
234 
235  err_code = app_timer_create(&m_reset_nof_consecutive_latching_fault_count_timer_id,
236  APP_TIMER_MODE_SINGLE_SHOT,
238  APP_ERROR_CHECK(err_code);
239 
240  return NRF_SUCCESS;
241 }
static lf_status_t m_lf_status
static ptu_sm_handler_t m_ptu_sm_execute
static void m_reset_nof_consecutive_latching_fault_count_timer_handler(void *p_context)
Clear number of consecutive latching faults timer handler.
static void m_latch_fault_attempt_to_clear_timer_handler(void *p_context)
Latch fault entry handler.
static void m_latch_fault_short_beacon_timer_handler(void *p_context)
Latch fault short beacon timer handler.