Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
ptu_latching_fault.c File Reference
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "ptu_latching_fault.h"
#include "ptu_config.h"
#include "ptu_sensors.h"
#include "ptu_power_ctl.h"
#include "ptu_test_mux.h"

Go to the source code of this file.

Functions

API implementation
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...
 

Static functions and variables

enum  lf_timer_state_t { LF_TIMER_STATE_BEACON_OFF, LF_TIMER_STATE_BEACON_SHORT }
 Enumerator describing what m_short_beacon_timer_id is being used for. More...
 
static ptu_sm_handler_t m_ptu_sm_execute
 
static lf_status_t m_lf_status
 
 APP_TIMER_DEF (m_clear_latching_fault_timer_id)
 
 APP_TIMER_DEF (m_short_beacon_timer_id)
 
 APP_TIMER_DEF (m_reset_nof_consecutive_latching_fault_count_timer_id)
 
static void m_reset_nof_consecutive_latching_fault_count_timer_handler (void *p_context)
 Clear number of consecutive latching faults timer handler. More...
 
static void m_latch_fault_attempt_to_clear_timer_handler (void *p_context)
 Latch fault entry handler. More...
 
static bool m_no_devices_on_pad (const ptu_sensor_data_t *p_sensor_data)
 Check if no load variation has been seen for PTU_PRU_NO_LOAD_VAR_NO_DEVICES_MS milliseconds, implying that no devices are on the pad. More...
 
static void m_latch_fault_short_beacon_timer_handler (void *p_context)
 Latch fault short beacon timer handler. More...
 

Enumeration Type Documentation

Enumerator describing what m_short_beacon_timer_id is being used for.

Enumerator
LF_TIMER_STATE_BEACON_OFF 

Multiple latching faults beacon sequence

LF_TIMER_STATE_BEACON_SHORT 

Multiple latching faults beacon sequence

Definition at line 34 of file ptu_latching_fault.c.

35 {
lf_timer_state_t
Enumerator describing what m_short_beacon_timer_id is being used for.

Function Documentation

APP_TIMER_DEF ( m_clear_latching_fault_timer_id  )

Clear latching fault timer

APP_TIMER_DEF ( m_short_beacon_timer_id  )

Beacon timer

APP_TIMER_DEF ( m_reset_nof_consecutive_latching_fault_count_timer_id  )

Reset number of consecutive latching faults timer

static void m_reset_nof_consecutive_latching_fault_count_timer_handler ( void *  p_context)
static

Clear number of consecutive latching faults timer handler.

Parameters
[in]p_contextGeneric context to sent to handler.

Definition at line 63 of file ptu_latching_fault.c.

64 {
65  m_lf_status.successive_faults = 0;
66  m_lf_status.persistent = false;
67 }
static lf_status_t m_lf_status
static void m_latch_fault_attempt_to_clear_timer_handler ( void *  p_context)
static

Latch fault entry handler.

Parameters
[in]p_contextGeneric context to sent to handler.

Definition at line 74 of file ptu_latching_fault.c.

75 {
76  m_ptu_sm_execute(PTU_SM_SIGNAL_LATCHING_FAULT_CLEARED_BY_USER);
77 }
static ptu_sm_handler_t m_ptu_sm_execute
static bool m_no_devices_on_pad ( const ptu_sensor_data_t p_sensor_data)
static

Check if no load variation has been seen for PTU_PRU_NO_LOAD_VAR_NO_DEVICES_MS milliseconds, implying that no devices are on the pad.

Parameters
p_sensor_dataPointer to PTU sensor data.
Returns
true if no devices on pad, false otherwise.

Definition at line 86 of file ptu_latching_fault.c.

87 {
88  static uint8_t load_var_detect_count = 0;
89 
90  if((p_sensor_data->res_impedance < PTU_Z_TX_IN_NO_LOAD))
91  {
92  load_var_detect_count = 0;
93  return false;
94  }
95 
97  {
98  load_var_detect_count = 0;
99  return true;
100  }
101 
102  return false;
103 }
#define PTU_BEACON_CYCLE_PERIOD_MS
Definition: ptu_config.h:182
#define PTU_LATCH_FAULT_NO_LOAD_VAR_NO_DEVICES_MS
Definition: ptu_config.h:210
uint16_t res_impedance
#define PTU_Z_TX_IN_NO_LOAD
Definition: ptu_config.h:71
static void m_latch_fault_short_beacon_timer_handler ( void *  p_context)
static

Latch fault short beacon timer handler.

Parameters
[in]p_contextGeneric context to sent to handler.

Definition at line 109 of file ptu_latching_fault.c.

110 {
111  uint32_t err_code;
112  const ptu_sensor_data_t * p_sensor_data;
113 
114 
115  if(PTU_SM_CURRENT_STATE() != PTU_SM_STATE_LATCH_FAULT)
116  {
117  return;
118  }
119 
120  switch(m_lf_status.timer_state)
121  {
122  case LF_TIMER_STATE_BEACON_OFF: // start short beacon
123 
125  APP_ERROR_CHECK(err_code);
126 
127  err_code = ptu_tmux_poweramp_enable_set(true);
128  APP_ERROR_CHECK(err_code);
129 
130  err_code = TIMER_START(m_short_beacon_timer_id, PTU_BEACON_DURATION_SHORT_MS, NULL);
131  APP_ERROR_CHECK(err_code);
132 
134  break;
135 
136  case LF_TIMER_STATE_BEACON_SHORT: // end short beacon
137  // sensors needs to be read before disabling poweramp in order for load variation detection to be performed.
138  err_code = ptu_sensors_read();
139  APP_ERROR_CHECK(err_code);
140 
141  err_code = ptu_tmux_poweramp_enable_set(false);
142  APP_ERROR_CHECK(err_code);
143 
144  err_code = TIMER_START(m_short_beacon_timer_id, (PTU_BEACON_CYCLE_PERIOD_MS - PTU_BEACON_DURATION_SHORT_MS), NULL);
145  APP_ERROR_CHECK(err_code);
146 
148 
149  err_code = ptu_sensors_data_get(&p_sensor_data);
150  APP_ERROR_CHECK(err_code);
151 
152  // Non-persistent latching fault has been cleared by seeing a load variation
153  if(!m_lf_status.persistent && p_sensor_data->load_var_detected)
154  {
155  m_ptu_sm_execute(PTU_SM_SIGNAL_LATCHING_FAULT_CLEARED_BY_USER);
156  }
157 
158  // User has cleared persistent latching fault by removing all devices from pad
159  else if(m_lf_status.persistent && m_no_devices_on_pad(p_sensor_data))
160  {
161  m_lf_status.successive_faults = 0;
162  m_lf_status.persistent = false;
163  m_ptu_sm_execute(PTU_SM_SIGNAL_LATCHING_FAULT_CLEARED_BY_USER);
164  }
165  break;
166 
167  default:
168  break;
169  }
170 }
#define PTU_BEACON_DURATION_SHORT_MS
Definition: ptu_config.h:184
uint32_t ptu_sensors_read(void)
Read sensors. This function should typically be called regularly by a timer and can generate events b...
Definition: ptu_sensors.c:303
#define PTU_BEACON_CYCLE_PERIOD_MS
Definition: ptu_config.h:182
#define PTU_POWERAMP_INPUT_BEACON_SHORT
Definition: ptu_hw_config.h:59
static lf_status_t m_lf_status
uint32_t ptu_tmux_poweramp_enable_set(bool enable)
Test wrapper for ptu_hal_poweramp_enable_set().
Definition: ptu_test_mux.c:69
uint32_t ptu_power_ctrl_set_poweramp_input(uint16_t level)
Perform power control adjustments.
static ptu_sm_handler_t m_ptu_sm_execute
static bool m_no_devices_on_pad(const ptu_sensor_data_t *p_sensor_data)
Check if no load variation has been seen for PTU_PRU_NO_LOAD_VAR_NO_DEVICES_MS milliseconds, implying that no devices are on the pad.
#define TIMER_START(timer_id, ms, p_ctx)
Definition: wpt.h:32
uint32_t ptu_sensors_data_get(const ptu_sensor_data_t **sensors_data)
Get the latest data read from the PTU sensors.
Definition: ptu_sensors.c:404
#define PTU_SM_CURRENT_STATE()
Definition: ptu.h:36
Definition of PTU sensor data.
Definition: ptu_hw_config.h:99
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.

Variable Documentation

ptu_sm_handler_t m_ptu_sm_execute
static

Profiles state machine handler

Definition at line 52 of file ptu_latching_fault.c.

lf_status_t m_lf_status
static

Latching fault status

Definition at line 56 of file ptu_latching_fault.c.