Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
PTU sensors API

API.

uint32_t ptu_sensors_init (ptu_sm_handler_t sm_handler)
 Initialize PTU Sensors. This function must be called before any other PTU Sensors function can be called. More...
 
uint32_t ptu_sensors_read (void)
 Read sensors. This function should typically be called regularly by a timer and can generate events by calling ptu_evt_handler(). More...
 
uint32_t ptu_sensors_data_get (const ptu_sensor_data_t **sensors_data)
 Get the latest data read from the PTU sensors. More...
 
void ptu_sensors_clear_long_beacon_extension_load_variation_buffer (void)
 Empty buffer containing load variation sample data for Long Beacon Extension.
 
bool ptu_sensors_valid_long_beacon_extension_load_variation_found (void)
 Check if a valid PTX load variation has occured. More...
 

Detailed Description

Function Documentation

uint32_t ptu_sensors_init ( ptu_sm_handler_t  sm_handler)

Initialize PTU Sensors. This function must be called before any other PTU Sensors function can be called.

Parameters
sm_handlerState machine event handler
Returns
NRF_ERROR_INVALID_PARAM if sm_handler is NULL, otherwise NRF_SUCCESS.

Definition at line 284 of file ptu_sensors.c.

285 {
286  uint32_t err_code;
287 
288  if(sm_handler == NULL)
289  return NRF_ERROR_INVALID_PARAM;
290 
291  m_sm_handler = sm_handler;
292 
293  err_code = app_timer_create(&m_load_var_detected_timer_id,
294  APP_TIMER_MODE_SINGLE_SHOT,
296  APP_ERROR_CHECK(err_code);
297 
298  memset(&m_ptu_sensor_data, 0, sizeof(ptu_sensor_data_t));
299 
300  return NRF_SUCCESS;
301 }
static ptu_sensor_data_t m_ptu_sensor_data
The latest version of the sensor data.
Definition: ptu_sensors.c:53
static ptu_sm_handler_t m_sm_handler
State machine event handler.
Definition: ptu_sensors.c:55
static void m_load_var_detected_timer_handler(void *p_context)
Definition: ptu_sensors.c:151
Definition of PTU sensor data.
Definition: ptu_hw_config.h:99
uint32_t ptu_sensors_read ( void  )

Read sensors. This function should typically be called regularly by a timer and can generate events by calling ptu_evt_handler().

Return values
NRF_SUCCESSSensor readings updated successfully.

Definition at line 303 of file ptu_sensors.c.

304 {
305  uint32_t err_code;
306  bool poweramp_on;
307 
308  // Read all sensors
310  if (err_code != NRF_SUCCESS) return err_code;
311 
313  if (err_code != NRF_SUCCESS) return err_code;
314 
316  if (err_code != NRF_SUCCESS) return err_code;
317 
319  if (err_code != NRF_SUCCESS) return err_code;
320 
322  {
324  {
326  }
327  }
328  else
329  {
331  {
333  }
334  }
335 
336  // Derive load impedance from vtx and itx if resonator is on
337  err_code = ptu_tmux_poweramp_enable_get(&poweramp_on);
338  if (err_code != NRF_SUCCESS) return err_code;
339 
340  if(poweramp_on)
341  {
342  if(m_ptu_sensor_data.i_ina > 0)
343  {
345  }
346  else
347  {
348  m_ptu_sensor_data.res_impedance = 0xffff; // "infinite"
349  }
350 
351  // Load variatio detection
353 
354  // Rogue object detection
356 
357  // Load detection
359  {
361  }
362  else
363  {
365  }
366  }
367 
368  // Check for event conditions:
369  bool b_under_temperature = false;
370  bool b_over_temperature = false;
371  bool b_itx_over_current = false;
372  bool b_itx_under_current = false;
373 
375  {
376  b_under_temperature = true;
377  }
379  {
380  b_over_temperature = true;
381  }
382 
384  {
385  b_itx_under_current = true;
386  }
388  {
389  b_itx_over_current = true;
390  }
391 
392  if (b_over_temperature || b_under_temperature || b_itx_over_current || b_itx_under_current)
393  {
394  m_sm_handler(PTU_SM_SIGNAL_LOCAL_FAULT);
395  }
396  else
397  {
398  m_sm_handler(PTU_SM_SIGNAL_LOCAL_FAULT_CLEARED);
399  }
400 
401  return NRF_SUCCESS;
402 }
#define PTU_ITX_MAX
Definition: ptu_hw_config.h:86
static ptu_sensor_data_t m_ptu_sensor_data
The latest version of the sensor data.
Definition: ptu_sensors.c:53
uint32_t ptu_tmux_temperature_get(int16_t *p_temperature)
Test wrapper for ptu_hal_temperature_get().
Definition: ptu_test_mux.c:114
#define PTU_ITX_MIN
Definition: ptu_hw_config.h:87
uint32_t ptu_tmux_vtx_get(uint16_t *p_vtx)
Test wrapper for ptu_hal_vtx_get().
Definition: ptu_test_mux.c:100
static void m_load_var_detect()
Definition: ptu_sensors.c:62
#define PTU_TEMPERATURE_WARNING_SET
Definition: ptu_hw_config.h:91
#define PTU_TEMPERATURE_MIN
Definition: ptu_hw_config.h:89
static void m_rogue_object_detect(void)
Definition: ptu_sensors.c:118
uint16_t res_impedance
#define PTU_TEMPERATURE_WARNING_CLEAR
Definition: ptu_hw_config.h:92
uint32_t ptu_tmux_ptx_get(uint16_t *p_ptx)
Test wrapper for ptu_hal_ptx_get().
Definition: ptu_test_mux.c:107
static ptu_sm_handler_t m_sm_handler
State machine event handler.
Definition: ptu_sensors.c:55
uint32_t ptu_tmux_poweramp_enable_get(bool *enable)
Test wrapper for ptu_hal_poweramp_enable_get();.
Definition: ptu_test_mux.c:79
#define PTU_Z_TX_IN_NO_LOAD
Definition: ptu_config.h:71
#define PTU_TEMPERATURE_MAX
Definition: ptu_hw_config.h:88
uint32_t ptu_tmux_itx_get(uint16_t *p_itx)
Test wrapper for ptu_hal_itx_get().
Definition: ptu_test_mux.c:93
uint32_t ptu_sensors_data_get ( const ptu_sensor_data_t **  sensors_data)

Get the latest data read from the PTU sensors.

Parameters
[out]sensors_datais a pointer to where a pointer to the latest read sensor data shall be written.
Returns
NRF_SUCCESS if sensor data was successully read.

Definition at line 404 of file ptu_sensors.c.

405 {
406  ASSERT(sensors_data != NULL);
407 
408  *sensors_data = &m_ptu_sensor_data;
409  return NRF_SUCCESS;
410 }
static ptu_sensor_data_t m_ptu_sensor_data
The latest version of the sensor data.
Definition: ptu_sensors.c:53
bool ptu_sensors_valid_long_beacon_extension_load_variation_found ( void  )

Check if a valid PTX load variation has occured.

Once called, this function will store a touple containing the current ticks value, and the current PTX value to a list of samples. This list of samples is then checked to see whether or not a valid load variation can be found. The overall algorithm is: Find the first top, find the bottom, find the second top, is the time between the two tops OK?

Finding the first top: This is done by simply comparing the value at the a point with the next sample value, if the next value is smaller we have a valid top.

Finding the bottom: We jump to the next sample as long as the difference between the value at the current sample and the first top is NOT sufficient (smaller than 0.5W). Note that when we have found the bottom, we will still check whether or not a LOWER bottom exists, in which case the bottom-pointer will be updated.

Finding the second top: The second top does not need to be a top, just a point that is sufficiently higher than bottom (0.5W above). NOTE: This implementation will accept a load where the second top is lower than the first top, as long as its delta from the bottom is sufficient.

Checking the time is a simple check of the time delta between the first top and the second top. If its accepted, the function will report that a valid PTX load variation has been found.

Returns
true if valid PTX load variation has been seen.

Definition at line 417 of file ptu_sensors.c.

418 {
419  static uint8_t last_updated_index = 0;
420  uint8_t first_top, bottom;
421 
422  // Jump to next index of sample buffer and update its value
423  GOTO_NEXT_IDX(last_updated_index);
424 
425  m_save_ptx_sample(last_updated_index);
426 
427  // Find first top of wave
428  if(!m_find_first_top(&first_top, last_updated_index))
429  return false;
430 
431  // Find the bottom
432  if(!m_find_bottom(&bottom, first_top))
433  return false;
434 
435  // Find the second top and validate load variation
436  return m_find_second_top_and_validate(first_top, bottom);
437 }
static bool m_find_second_top_and_validate(uint8_t first_top, uint8_t bottom)
Definition: ptu_sensors.c:214
static bool m_find_bottom(uint8_t *p_bottom, uint8_t first_top)
Definition: ptu_sensors.c:185
static bool m_find_first_top(uint8_t *p_first_top, uint8_t last_updated_idx)
Definition: ptu_sensors.c:162
#define GOTO_NEXT_IDX(idx)
Circular buffer index update.
Definition: ptu_sensors.c:36
static void m_save_ptx_sample(uint8_t last_updated_index)
Definition: ptu_sensors.c:263