Nordic Semiconductor nRF5 AirFuel SDK
version 2.2.0
|
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "ptu_sensors.h"
#include "nrf_assert.h"
#include "ptu_registry.h"
#include "ptu_test_mux.h"
Go to the source code of this file.
Macros | |
#define | PTU_SIZEOF_LOAD_VAL_BUF 8 |
Size of P_TX_IN load variation buffer. | |
#define | PTU_SENSORS_PTX_LOAD_VARIATION_MAX_PERIOD_MS 15 |
Maximum allowed period for having a 100Hz +/- 20% load variation. | |
#define | PTU_SENSORS_PTX_LOAD_VARIATION_MIN_PERIOD_MS 6 |
Minimum allowed period for having a 100Hz +/- 20% load variation. | |
#define | PTU_SENSORS_PTX_LOAD_VARIATION_MAX_PERIOD_TICKS APP_TIMER_TICKS(PTU_SENSORS_PTX_LOAD_VARIATION_MAX_PERIOD_MS, APP_TIMER_PRESCALER) |
Max allowed period in ticks. | |
#define | PTU_SENSORS_PTX_LOAD_VARIATION_MIN_PERIOD_TICKS APP_TIMER_TICKS(PTU_SENSORS_PTX_LOAD_VARIATION_MIN_PERIOD_MS, APP_TIMER_PRESCALER) |
Min allowed period in ticks. | |
#define | PREV(val) ((val - 1) < 0 ? PTU_SIZEOF_LOAD_VAL_BUF - 1 : (val - 1)) |
Get previous index in circular buffer. | |
#define | NEXT(val) ((val + 1) % PTU_SIZEOF_LOAD_VAL_BUF) |
Get next index in circular buffer. | |
#define | GOTO_NEXT_IDX(idx) (idx = NEXT(idx)) |
Circular buffer index update. | |
#define | GET_BIT(val, idx) ((val >> idx) & 1) |
Read bit value. | |
Functions | |
API implementation | |
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... | |
Static functions and variables | |
typedef struct ptu_load_var_measurement_s | ptu_sensors_load_variation_sample_t |
Struct representing a single P_TX sample. | |
static ptu_sensors_load_variation_sample_t | m_lbe_samples [PTU_SIZEOF_LOAD_VAL_BUF] |
Buffer used for storing P_TX_IN load variation data. | |
static ptu_sensor_data_t | m_ptu_sensor_data |
The latest version of the sensor data. | |
static ptu_sm_handler_t | m_sm_handler |
State machine event handler. | |
APP_TIMER_DEF (m_load_var_detected_timer_id) | |
Load variation detect timer ID. | |
static void | m_load_var_detect () |
static void | m_rogue_object_detect (void) |
static void | m_load_var_detected_timer_handler (void *p_context) |
static bool | m_find_first_top (uint8_t *p_first_top, uint8_t last_updated_idx) |
static bool | m_find_bottom (uint8_t *p_bottom, uint8_t first_top) |
static bool | m_find_second_top_and_validate (uint8_t first_top, uint8_t bottom) |
static void | m_save_ptx_sample (uint8_t last_updated_index) |
|
static |
Function storing measured resonator impedance to buffer and using max/min values of this buffer to determine whether a load variation has been detected.
Definition at line 62 of file ptu_sensors.c.
|
static |
Function detecting rogue object based on power delievered to power amplifier and reported power consumption from registered PRUs.
Definition at line 118 of file ptu_sensors.c.
|
static |
Load variation detect timer handler.
p_context | context data. |
Definition at line 151 of file ptu_sensors.c.
|
static |
Locate the first sample where the the next value is smaller.
p_first_top | Pointer to where the resulting index will be stored. |
last_updated_idx | Tells what index was last updated. |
Definition at line 162 of file ptu_sensors.c.
|
static |
Locate the first sample where PTX delta from first top is sufficient for Long Beacon Extension.
p_bottom | Pointer to where the resulting index will be stored. |
first_top | Index of first top sample. |
Definition at line 185 of file ptu_sensors.c.
|
static |
Locate the second top in the extended beacon sample list, and check if the load variation is valid.
This function will start looking at the first sample AFTER the given first top. The initial bottom is assumed to be the first sample AFTER the given first top. However, if the current sample has lower value than the previous one, it will be assigned as the new bottom.
The function will return immediately when it sees a valid load variation.
first_top | Index of first top sample. |
bottom | Pointer to current bottom sample.. |
Definition at line 214 of file ptu_sensors.c.
|
static |
Store current ticks and ptx value in a list of samples
last_updated_index | Where should we store the sample |
Definition at line 263 of file ptu_sensors.c.