|
@ -12,6 +12,7 @@ |
|
|
#define SENSOR0_ID 0 |
|
|
#define SENSOR0_ID 0 |
|
|
#define SENSOR1_ID 3 |
|
|
#define SENSOR1_ID 3 |
|
|
#define SENSOR2_ID 4 |
|
|
#define SENSOR2_ID 4 |
|
|
|
|
|
static const nrfx_timer_t m_timer = NRFX_TIMER_INSTANCE(1); /**< Timer used for channel sweeps and tx with duty cycle. */ |
|
|
|
|
|
|
|
|
/******************************************************************************* |
|
|
/******************************************************************************* |
|
|
* STRUCT * |
|
|
* STRUCT * |
|
@ -26,16 +27,20 @@ typedef struct { |
|
|
*******************************************************************************/ |
|
|
*******************************************************************************/ |
|
|
|
|
|
|
|
|
static adscfg_t m_prvads0cfg[] = // |
|
|
static adscfg_t m_prvads0cfg[] = // |
|
|
{{0x00, 0x00}, {0x01, 0x19}, {0x02, 0x11}, {0x03, 0x00}, {0x04, 0x00}, {0x05, 0x00}, {0x06, 0x00}, {0x07, 0x0f}, {0x08, 0xff}, {0x09, 0x00}, {0x0a, 0x07}, {0x0b, 0x07}, {0x0c, 0x74}, {0x0d, 0x01}, {0x0e, 0x02}, {0x0f, 0x03}, {0x10, 0x04}, |
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
{0x00, 0x00}, {0x01, 0x19}, {0x02, 0x11}, {0x03, 0x00}, {0x04, 0x00}, {0x05, 0x00}, {0x06, 0x00}, {0x07, 0x0f}, {0x08, 0xff}, {0x09, 0x00}, {0x0a, 0x07}, {0x0b, 0x07}, {0x0c, 0x74}, {0x0d, 0x01}, {0x0e, 0x02}, {0x0f, 0x03}, {0x10, 0x04}, |
|
|
{0x11, 0x00}, {0x12, 0x05}, {0x13, 0x39}, {0x14, 0x36}, {0x15, 0x06}, {0x16, 0x00}, {0x17, 0x05}, {0x18, 0x00}, {0x19, 0x00}, {0x1a, 0x00}, {0x1b, 0x00}, {0x1c, 0x00}, {0x1d, 0x00}, {0x21, 0x01}, {0x22, 0x20}, {0x23, 0x20}, {0x24, 0x02}, |
|
|
{0x11, 0x00}, {0x12, 0x05}, {0x13, 0x39}, {0x14, 0x36}, {0x15, 0x06}, {0x16, 0x00}, {0x17, 0x05}, {0x18, 0x00}, {0x19, 0x00}, {0x1a, 0x00}, {0x1b, 0x00}, {0x1c, 0x00}, {0x1d, 0x00}, {0x21, 0x01}, {0x22, 0x20}, {0x23, 0x20}, {0x24, 0x02}, |
|
|
{0x25, 0x00}, {0x26, 0x00}, {0x27, 0x08}, {0x28, 0x08}, {0x29, 0x00}, {0x2a, 0x00}, {0x2b, 0x00}, {0x2c, 0x00}, {0x2d, 0x00}, {0x2e, 0x33}, {0x2f, 0x30}, {0x30, 0x00}, {0x31, 0x00}, {0x32, 0x00}, {0x33, 0x00}, {0x34, 0x00}, {0x35, 0x00}, |
|
|
{0x25, 0x00}, {0x26, 0x00}, {0x27, 0x08}, {0x28, 0x08}, {0x29, 0x00}, {0x2a, 0x00}, {0x2b, 0x00}, {0x2c, 0x00}, {0x2d, 0x00}, {0x2e, 0x33}, {0x2f, 0x30}, {0x30, 0x00}, {0x31, 0x00}, {0x32, 0x00}, {0x33, 0x00}, {0x34, 0x00}, {0x35, 0x00}, |
|
|
{0x36, 0x00}, {0x37, 0x00}, {0x38, 0x00}, {0x39, 0x00}, {0x3a, 0x00}, {0x3b, 0x00}, {0x3c, 0x00}, {0x3d, 0x00}, {0x3e, 0x00}, {0x3f, 0x00}, {0x40, 0xff}, {0x50, 0x00}, {0x60, 0x00}, {0x62, 0x00}}; |
|
|
|
|
|
|
|
|
{0x36, 0x00}, {0x37, 0x00}, {0x38, 0x00}, {0x39, 0x00}, {0x3a, 0x00}, {0x3b, 0x00}, {0x3c, 0x00}, {0x3d, 0x00}, {0x3e, 0x00}, {0x3f, 0x00}, {0x40, 0xff}, {0x50, 0x00}, {0x60, 0x00}, {0x62, 0x00}, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
static adscfg_t m_prvads1cfg[] = // |
|
|
static adscfg_t m_prvads1cfg[] = // |
|
|
{{0x00, 0x00}, {0x01, 0x19}, {0x02, 0x11}, {0x03, 0x00}, {0x04, 0x00}, {0x05, 0x00}, {0x06, 0x00}, {0x07, 0x0f}, {0x08, 0xff}, {0x09, 0x00}, {0x0a, 0x07}, {0x0b, 0x07}, {0x0c, 0x74}, {0x0d, 0x01}, {0x0e, 0x02}, {0x0f, 0x03}, {0x10, 0x04}, |
|
|
|
|
|
{0x11, 0x00}, {0x12, 0x05}, {0x13, 0x39}, {0x14, 0x36}, {0x15, 0x06}, {0x16, 0x00}, {0x17, 0x05}, {0x18, 0x00}, {0x19, 0x00}, {0x1a, 0x00}, {0x1b, 0x00}, {0x1c, 0x00}, {0x1d, 0x00}, {0x21, 0x01}, {0x22, 0x20}, {0x23, 0x20}, {0x24, 0x02}, |
|
|
|
|
|
{0x25, 0x00}, {0x26, 0x00}, {0x27, 0x08}, {0x28, 0x08}, {0x29, 0x00}, {0x2a, 0x00}, {0x2b, 0x00}, {0x2c, 0x00}, {0x2d, 0x00}, {0x2e, 0x33}, {0x2f, 0x30}, {0x30, 0x00}, {0x31, 0x00}, {0x32, 0x00}, {0x33, 0x00}, {0x34, 0x00}, {0x35, 0x00}, |
|
|
|
|
|
{0x36, 0x00}, {0x37, 0x00}, {0x38, 0x00}, {0x39, 0x00}, {0x3a, 0x00}, {0x3b, 0x00}, {0x3c, 0x00}, {0x3d, 0x00}, {0x3e, 0x00}, {0x3f, 0x00}, {0x40, 0xff}, {0x50, 0x00}, {0x60, 0x00}, {0x62, 0x00}}; |
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
{0x00, 0x00}, {0x01, 0x0c}, {0x02, 0x14}, {0x03, 0x00}, {0x04, 0x00}, {0x05, 0x00}, {0x06, 0x00}, {0x07, 0x0f}, {0x08, 0xff}, {0x09, 0x00}, {0x0a, 0x00}, {0x0b, 0x07}, {0x0c, 0x78}, {0x0d, 0x00}, {0x0e, 0x00}, {0x0f, 0x00}, {0x10, 0x04}, |
|
|
|
|
|
{0x11, 0x00}, {0x12, 0x07}, {0x13, 0x3b}, {0x14, 0x24}, {0x15, 0x04}, {0x16, 0x00}, {0x17, 0x05}, {0x18, 0x00}, {0x19, 0x00}, {0x1a, 0x00}, {0x1b, 0x00}, {0x1c, 0x00}, {0x1d, 0x00}, {0x21, 0x01}, {0x22, 0x20}, {0x23, 0x20}, {0x24, 0x02}, |
|
|
|
|
|
{0x25, 0x00}, {0x26, 0x00}, {0x27, 0x08}, {0x28, 0x40}, {0x29, 0x00}, {0x2a, 0x00}, {0x2b, 0x00}, {0x2c, 0x00}, {0x2d, 0x00}, {0x2e, 0x33}, {0x2f, 0x30}, {0x30, 0x00}, {0x31, 0x00}, {0x32, 0x00}, {0x33, 0x00}, {0x34, 0x00}, {0x35, 0x00}, |
|
|
|
|
|
{0x36, 0x00}, {0x37, 0x00}, {0x38, 0x00}, {0x39, 0x00}, {0x3a, 0x00}, {0x3b, 0x00}, {0x3c, 0x00}, {0x3d, 0x00}, {0x3e, 0x00}, {0x3f, 0x00}, {0x40, 0xff}, {0x50, 0x00}, {0x60, 0x00}, {0x62, 0x00}, |
|
|
|
|
|
}; |
|
|
/******************************************************************************* |
|
|
/******************************************************************************* |
|
|
* VARIABLE * |
|
|
* VARIABLE * |
|
|
*******************************************************************************/ |
|
|
*******************************************************************************/ |
|
@ -124,7 +129,17 @@ static inline void prvf_light_block_cache_clear(void) { m_little_frame_index = 0 |
|
|
static inline void prvf_light_block_trigger_event() { |
|
|
static inline void prvf_light_block_trigger_event() { |
|
|
static app_event_t event; |
|
|
static app_event_t event; |
|
|
event.eventType = kevent_capture_little_data_block_event; |
|
|
event.eventType = kevent_capture_little_data_block_event; |
|
|
memcpy(event.val.little_data_block.data, m_sensor_little_frame_cache, LITTLE_DATA_BLOCK_FRAME_NUM); |
|
|
|
|
|
|
|
|
// memcpy(event.val.little_data_block.data, m_sensor_little_frame_cache, LITTLE_DATA_BLOCK_FRAME_NUM * sizeof(one_frame_data_t)); |
|
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < LITTLE_DATA_BLOCK_FRAME_NUM; i++) { |
|
|
|
|
|
event.val.little_data_block.data[i].data0 = m_sensor_little_frame_cache[0].data0; |
|
|
|
|
|
event.val.little_data_block.data[i].data1 = m_sensor_little_frame_cache[0].data1; |
|
|
|
|
|
event.val.little_data_block.data[i].data2 = m_sensor_little_frame_cache[0].data2; |
|
|
|
|
|
// event.val.little_data_block.data[0].data0 = 1111111111; |
|
|
|
|
|
// event.val.little_data_block.data[0].data1 = 2222222222; |
|
|
|
|
|
// event.val.little_data_block.data[0].data2 = 3333333333; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
event.val.little_data_block.frameIndex = m_frame_index - LITTLE_DATA_BLOCK_FRAME_NUM; |
|
|
event.val.little_data_block.frameIndex = m_frame_index - LITTLE_DATA_BLOCK_FRAME_NUM; |
|
|
AppEvent_pushEvent(&event); |
|
|
AppEvent_pushEvent(&event); |
|
|
} |
|
|
} |
|
@ -227,22 +242,22 @@ static void ads1293_init() { |
|
|
{ |
|
|
{ |
|
|
// nrf_gpio_cfg_input(ADS1293_READY_PIN, NRF_GPIO_PIN_PULLUP); |
|
|
// nrf_gpio_cfg_input(ADS1293_READY_PIN, NRF_GPIO_PIN_PULLUP); |
|
|
// ZERROR_CHECK(nrfx_gpiote_init()); |
|
|
// ZERROR_CHECK(nrfx_gpiote_init()); |
|
|
nrf_drv_gpiote_in_config_t inConfig = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false); // 双边沿中断触发 |
|
|
|
|
|
inConfig.pull = NRF_GPIO_PIN_PULLUP; // 默认上拉 |
|
|
|
|
|
inConfig.sense = NRF_GPIOTE_POLARITY_LOTOHI; // 上升沿触发 |
|
|
|
|
|
|
|
|
|
|
|
ZERROR_CHECK(nrfx_gpiote_in_init(ADS1293_READY_PIN, &inConfig, ads1293_ready_pin_irq)); |
|
|
|
|
|
nrfx_gpiote_in_event_enable(ADS1293_READY_PIN, true); |
|
|
|
|
|
|
|
|
// nrf_drv_gpiote_in_config_t inConfig = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false); // 双边沿中断触发 |
|
|
|
|
|
// inConfig.pull = NRF_GPIO_PIN_PULLUP; // 默认上拉 |
|
|
|
|
|
// inConfig.sense = NRF_GPIOTE_POLARITY_LOTOHI; // 上升沿触发 |
|
|
|
|
|
// ZERROR_CHECK(nrfx_gpiote_in_init(ADS1293_READY_PIN, &inConfig, ads1293_ready_pin_irq)); |
|
|
|
|
|
// nrfx_gpiote_in_event_enable(ADS1293_READY_PIN, true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
{} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @brief 数据准备号中断回调函数 |
|
|
|
|
|
* |
|
|
|
|
|
* @param pin |
|
|
|
|
|
* @param action |
|
|
|
|
|
*/ |
|
|
|
|
|
static void ads1293_ready_pin_irq(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { |
|
|
|
|
|
|
|
|
void ads1293_sample_one_frame(); |
|
|
|
|
|
void nrfx_timer_event_handler(nrf_timer_event_t event_type, void* p_context) { // |
|
|
|
|
|
ads1293_sample_one_frame(); |
|
|
|
|
|
} |
|
|
|
|
|
static void ads1293_ready_pin_irq(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { ads1293_sample_one_frame(); } |
|
|
|
|
|
static void ads1293_sample_one_frame() { |
|
|
if (!m_work_flag) { |
|
|
if (!m_work_flag) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
@ -310,20 +325,41 @@ static void ads1293_uninit() { |
|
|
|
|
|
|
|
|
void hwss_init(void) { |
|
|
void hwss_init(void) { |
|
|
/** |
|
|
/** |
|
|
* @brief 初始化ads1293硬件接口 |
|
|
|
|
|
|
|
|
* @brief 初始化定时器 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
nrfx_err_t err; |
|
|
|
|
|
nrfx_timer_config_t timer_cfg = { |
|
|
|
|
|
.frequency = NRF_TIMER_FREQ_125kHz, |
|
|
|
|
|
.mode = NRF_TIMER_MODE_TIMER, |
|
|
|
|
|
.bit_width = NRF_TIMER_BIT_WIDTH_24, |
|
|
|
|
|
.p_context = NULL, |
|
|
|
|
|
.interrupt_priority = NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
err = nrfx_timer_init(&m_timer, &timer_cfg, nrfx_timer_event_handler); |
|
|
|
|
|
if (err != NRFX_SUCCESS) { |
|
|
|
|
|
NRF_LOG_ERROR("nrfx_timer_init failed with: %d\n", err); |
|
|
|
|
|
} |
|
|
|
|
|
uint32_t timer_ticks = nrfx_timer_ms_to_ticks(&m_timer, 2); // 500HZ |
|
|
|
|
|
nrfx_timer_extended_compare(&m_timer, NRF_TIMER_CC_CHANNEL0, timer_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void hwss_load(void) { ads1293_init(); } |
|
|
void hwss_load(void) { ads1293_init(); } |
|
|
void hwss_unload(void) { ads1293_uninit(); } |
|
|
|
|
|
|
|
|
void hwss_unload(void) { |
|
|
|
|
|
nrfx_timer_disable(&m_timer); |
|
|
|
|
|
ads1293_uninit(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void hwss_start_capture(void) { |
|
|
void hwss_start_capture(void) { |
|
|
m_drop_state_triggered = false; |
|
|
m_drop_state_triggered = false; |
|
|
m_work_flag = true; |
|
|
m_work_flag = true; |
|
|
ads1293_start_conversion(&m_ads1293_0); |
|
|
ads1293_start_conversion(&m_ads1293_0); |
|
|
ads1293_start_conversion(&m_ads1293_1); |
|
|
ads1293_start_conversion(&m_ads1293_1); |
|
|
|
|
|
nrfx_timer_enable(&m_timer); |
|
|
} |
|
|
} |
|
|
void hwss_stop_capture(void) { |
|
|
void hwss_stop_capture(void) { |
|
|
|
|
|
nrfx_timer_disable(&m_timer); |
|
|
|
|
|
|
|
|
m_work_flag = false; |
|
|
m_work_flag = false; |
|
|
ads1293_stop_conversion(&m_ads1293_0); |
|
|
ads1293_stop_conversion(&m_ads1293_0); |
|
|
ads1293_stop_conversion(&m_ads1293_1); |
|
|
ads1293_stop_conversion(&m_ads1293_1); |
|
|