22 #include "softdevice_handler.h"
27 #include "nrf_assert.h"
29 #include "app_util_platform.h"
38 #define DEAD_BEEF 0xDEADBEEF
40 #define VRECT_MEAS_INTERVAL APP_TIMER_TICKS(50, APP_TIMER_PRESCALER)
42 #define VRECT_MEAS_INTERVAL APP_TIMER_TICKS(50, APP_TIMER_PRESCALER)
43 #define PRU_MULTI_PROFILE_TIMER_OP_QUEUE_SIZE (8 + PRU_MAX_APP_TIMERS)
45 static nrf_clock_lf_cfg_t clk_cfg = {
46 .source = NRF_CLOCK_LF_SRC_XTAL,
47 .xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM};
55 static const ble_gap_addr_t
PRU_ADDR = {.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
56 .addr = {0xe4, 0x33, 0xba, 0xab, 0xea, 0xee}};
58 static const ble_gap_addr_t
APP_PROFILE_ADDR = {.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC,
59 .addr = {0xc9, 0xff, 0xcc, 0xee, 0x11, 0xcc}};
62 static ble_enable_params_t
m_ble_enable_params = {.common_enable_params.vs_uuid_count = BLE_UUID_VS_COUNT_DEFAULT,
63 .gap_enable_params.periph_conn_count = 1,
64 .gatts_enable_params.attr_tab_size = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT};
85 switch(p_ble_evt->header.evt_id)
87 case BLE_GAP_EVT_CONNECTED:
98 case PROFILE_APPLICATION:
118 SOFTDEVICE_HANDLER_INIT(&
clk_cfg, NULL);
121 APP_ERROR_CHECK(err_code);
124 APP_ERROR_CHECK(err_code);
127 APP_ERROR_CHECK(err_code);
131 err_code = sd_nvic_SetPriority(SD_EVT_IRQn, APP_IRQ_PRIORITY_LOW);
132 APP_ERROR_CHECK(err_code);
149 err_code = app_timer_stop_all();
150 APP_ERROR_CHECK(err_code);
152 err_code = sd_softdevice_disable();
153 APP_ERROR_CHECK(err_code);
174 APP_ERROR_CHECK(err_code);
185 err_code = app_timer_stop_all();
186 APP_ERROR_CHECK(err_code);
189 err_code = sd_softdevice_disable();
190 APP_ERROR_CHECK(err_code);
194 APP_ERROR_CHECK(err_code);
221 APP_ERROR_CHECK(err_code);
237 APP_ERROR_CHECK(err_code);
241 err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &
PRU_ADDR);
242 APP_ERROR_CHECK(err_code);
248 err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &
APP_PROFILE_ADDR);
249 APP_ERROR_CHECK(err_code);
256 #ifdef DEBUG_OUT_ENABLE
State machine state variables.
void pru_on_ble_evt(ble_evt_t *p_ble_evt)
Handle BLE event.
static void m_ble_stack_init(void)
BLE stack initialization.
static bool m_profile_has_been_switched
static void m_ble_evt_dispatch(ble_evt_t *p_ble_evt)
Dispatches a BLE stack event to all profiles.
void app_profile_start(void)
Start profile. Is called every time profile is activated.
static void m_sys_evt_dispatch(uint32_t evt)
Dispatch system events to all profiles that require it.
void app_profile_on_ble_evt(ble_evt_t *p_ble_evt)
Handle BLE event.
int main()
Application main function.
void pru_init(app_sm_evt_handler_t sm_evt_handler)
Initialize PRU. This function must be called before any other PRU function can be called...
#define PRU_MULTI_PROFILE_TIMER_OP_QUEUE_SIZE
void pru_sensors_read_all(void)
Read PRU sensors.
void app_profile_stop(void)
Stop profile. Note: Needs to set the softdevice in a state where it is ok to initialize PRU profile...
void pru_sensors_init(pru_sm_handler_t pru_sm_handler)
Initialize sensors and read default values.
device_profile_t
Enum representing the current active profile.
device_profile_t m_current_profile
const pru_sensor_data_t * pru_sensors_data_get(void)
Get the latest data from the PRU sensors.
Definition of PRU reporting data.
static nrf_clock_lf_cfg_t clk_cfg
pru_sm_state_t prev_state
pru_sm_state_t current_state
void app_profile_on_sys_evt(uint32_t sys_evt)
Handle system event.
static void m_timers_init(void)
Init timers required by this module.
#define VRECT_MEAS_INTERVAL
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
Callback function for asserts in the SoftDevice.
static const ble_gap_addr_t PRU_ADDR
#define APP_TIMER_PRESCALER
pru_sm_signal_type_t
PRU state machine signal type.
#define PRU_BUTTON_PRESS_LENGTH_DFU_MS
APP_TIMER_DEF(m_vrect_read_timer)
static ble_enable_params_t m_ble_enable_params
BLE Enable params.
void debug(void)
Process debug commands.
void pru_start(void)
Enable the PRU profile. When enabled sensor reading and signal generation will be enabled...
static const ble_gap_addr_t APP_PROFILE_ADDR
static void vrect_read_timeout_handler(void *p_context)
Handler for reading VRECT.
void app_profile_init(void)
Initialize profile. Is only called once.
static void m_on_pru_sm_evt(pru_sm_signal_type_t signal, const pru_sm_state_vars_t *p_state_vars)
PRU state machine event handler. Used to see when charging has stopped.