From 689c5ce45e5fafcbce4503f0f326d1d620e0ca37 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Thu, 2 May 2024 10:28:44 +0800 Subject: [PATCH] update --- README.md | 22 +++++++++++++ app/config/sdk_config.h | 2 +- app/src/basic_service/device_state.c | 4 ++- app/src/basic_service/device_state.h | 4 +-- app/src/basic_service/device_version_info_mgr.c | 6 ++-- app/src/board/ads129x/ads129x.c | 15 ++++++--- app/src/board/ads129x/ads129x.h | 4 ++- app/src/board/app_board.c | 1 - app/src/main.c | 37 +++++++++++++++++++--- app/src/one_conduction_main.c | 2 +- .../heart_wave_sample_service.c | 18 ++++++++++- bak/zapp_timer.c | 29 +++++++++++++++++ bak/zapp_timer.h | 17 ++++++++++ libznordic | 2 +- 14 files changed, 144 insertions(+), 19 deletions(-) create mode 100644 bak/zapp_timer.c create mode 100644 bak/zapp_timer.h diff --git a/README.md b/README.md index 6e55f32..9c03556 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,28 @@ board_init +README: + 外设 ---> 初始化 + 使用 + + app_board(在状态切换的时候,切换) + -------> + 切换状态 + + + 实时切换状态并使用 依然归类到整机状态中去 + ------> + + 1. 外设状态 <---> 系统状态绑定 + + 外设临时状态切换 + 调用方法 + + +1. 外设的切换发生在系统状态机的切换: + 1. 外设再被调用时,检查自己的状态,如果状态不满足打印警报或者错误日志。 + 2. 外设再被调用时,检查自己的状态,如果状态不满足,但允许自行切换状态,则自行进行状态切换 + 3. 服务本身不负责状态的切换。 diff --git a/app/config/sdk_config.h b/app/config/sdk_config.h index d1db7a5..aaa5b2e 100644 --- a/app/config/sdk_config.h +++ b/app/config/sdk_config.h @@ -3,6 +3,6 @@ #define NRF_LOG_ENABLED 1 #define NRF_LOG_BACKEND_UART_ENABLED 1 #define NRF_LOG_BACKEND_UART_TX_PIN 41 -#define DEBUG +#define APP_TIMER_CONFIG_USE_SCHEDULER 1 #include "libznordic/zsdk_config/zsdk_ble_slave_config.h" \ No newline at end of file diff --git a/app/src/basic_service/device_state.c b/app/src/basic_service/device_state.c index 84f2892..08cc3f0 100644 --- a/app/src/basic_service/device_state.c +++ b/app/src/basic_service/device_state.c @@ -2,6 +2,7 @@ #include "device_state.h" #include "znordic.h" +#include "basic_service/app_event_distribute.h" /*********************************************************************************************************************** * 状态机 * ***********************************************************************************************************************/ @@ -9,6 +10,7 @@ static device_state_t m_device_state = kdevice_state_standby; // static uint32_t m_change_to_cur_state_tp = 0; // 切换到当前状态的时间戳 static on_state_change_t m_onstate_change; APP_TIMER_DEF(m_state_machine_driver_tmr); // 状态机驱动定时器 +// static zapp_timer_context m_state_machine_driver_tmr_context; static void state_machine_driver_tmr_cb(void* p_context) { // static app_event_t appevent; @@ -31,7 +33,7 @@ void ds_change_to_state(device_state_t tostate) { uint32_t ds_cur_state_haspassed_ms() { return znordic_haspassed_ms(m_change_to_cur_state_tp); } device_state_t ds_now_state() { return m_device_state; } -device_state_t ds_init(on_state_change_t onstate_change) { +void ds_init(on_state_change_t onstate_change) { m_onstate_change = onstate_change; ZERROR_CHECK(app_timer_create(&m_state_machine_driver_tmr, APP_TIMER_MODE_REPEATED, state_machine_driver_tmr_cb)); ZERROR_CHECK(app_timer_start(m_state_machine_driver_tmr, APP_TIMER_TICKS(300), NULL)); diff --git a/app/src/basic_service/device_state.h b/app/src/basic_service/device_state.h index c139f74..48ad08a 100644 --- a/app/src/basic_service/device_state.h +++ b/app/src/basic_service/device_state.h @@ -5,9 +5,9 @@ #include "aproject_config/config.h" #include "basic_service/app_event.h" -typedef void(*on_state_change_t)(device_state_t from, device_state_t to); +typedef void (*on_state_change_t)(device_state_t from, device_state_t to); -device_state_t ds_init(on_state_change_t onstate_change); +void ds_init(on_state_change_t onstate_change); void ds_change_to_state(device_state_t state); uint32_t ds_cur_state_haspassed_ms(); device_state_t ds_now_state(); diff --git a/app/src/basic_service/device_version_info_mgr.c b/app/src/basic_service/device_version_info_mgr.c index dc31614..1b8d268 100644 --- a/app/src/basic_service/device_version_info_mgr.c +++ b/app/src/basic_service/device_version_info_mgr.c @@ -8,10 +8,12 @@ void device_info_read_sn(sn_t *sn) { uint32_t lot = NRF_UICR->CUSTOMER[0]; uint32_t id = NRF_UICR->CUSTOMER[1]; static char sn_str[15]; - sprintf(sn_str, CATEGORY "%04d%05d", lot, id); if (lot == 0 || id == 0 || lot == 0xffffffff || id == 0xffffffff) { - sprintf(sn_str, "iflytop_test"); + sprintf(sn_str, "%s-%s","iflytop",CATEGORY); + } else { + sprintf(sn_str, "%s%04d%05d", CATEGORY, lot, id); } + memcpy(sn->sn, sn_str, sizeof(sn->sn)); } diff --git a/app/src/board/ads129x/ads129x.c b/app/src/board/ads129x/ads129x.c index d968786..1e65c69 100644 --- a/app/src/board/ads129x/ads129x.c +++ b/app/src/board/ads129x/ads129x.c @@ -177,13 +177,13 @@ static bool ads129x_write_reg(ads129x_regs_t* writeval) { * EXTERN * ***********************************************************************************************************************/ void ads129x_read_data_loop() { + app_timer_pause(); + app_sched_execute(); + ads129x_capture_data_t capture_data; while (true) { - while (ADS129X_DRDY_GET()) - ; - ads129x_read_data(&capture_data); - ZLOGI("{%d} %x", capture_data.ch1data, capture_data.loffstate); + ZLOGI("%d {%d} %x", ADS129X_DRDY_GET(), capture_data.ch1data, capture_data.loffstate); } } @@ -210,6 +210,8 @@ uint8_t ads129x_init(ads129x_cfg_t* cfg) { port_ads129x_delay_ms(100); nrf_gpio_pin_set(ads129x_cfg->pwdnpin); + return 0; + } uint8_t ads129x_start_capture(bool test) { @@ -249,8 +251,13 @@ uint8_t ads129x_start_capture(bool test) { port_delay_ms(10); ads129X_send_cmd(ADS129X_COMMAND_START); /* 发送开始数据转换(等效于拉高START引脚) */ port_delay_ms(10); + + ads129x_read_data_loop(); + return 0; } +uint8_t ads129x_stop_capture() {} + static int32_t i24toi32(uint8_t* p_i32) { int32_t rev = 0; rev = (((int32_t)p_i32[0]) << 16) | (((int32_t)p_i32[1]) << 8) | ((int32_t)p_i32[2]); diff --git a/app/src/board/ads129x/ads129x.h b/app/src/board/ads129x/ads129x.h index e25c894..7eb972a 100644 --- a/app/src/board/ads129x/ads129x.h +++ b/app/src/board/ads129x/ads129x.h @@ -36,9 +36,11 @@ typedef struct { /** * @brief 初始化SPI */ -uint8_t ads129x_init(ads129x_cfg_t *cfg); +uint8_t ads129x_init(ads129x_cfg_t* cfg); uint8_t ads129x_start_capture(bool test); +uint8_t ads129x_stop_capture(); + uint8_t ads129x_enter_low_power_mode(); uint8_t ads129x_enter_lead_off_detect_mode(); diff --git a/app/src/board/app_board.c b/app/src/board/app_board.c index a693e52..7ffa098 100644 --- a/app/src/board/app_board.c +++ b/app/src/board/app_board.c @@ -71,7 +71,6 @@ static void __ads1291_init() { znrf_gpio_cfg_output(ADS1291_SPI_CS0_PIN, NRF_GPIO_PIN_NOPULL); // --------------------------------------------------------------------------- - nrf_gpio_cfg_input(ADS1291_READY_PIN, NRF_GPIO_PIN_NOPULL); { nrf_gpio_cfg_input(ADS1291_READY_PIN, NRF_GPIO_PIN_PULLUP); nrf_drv_gpiote_in_config_t inConfig = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false); // diff --git a/app/src/main.c b/app/src/main.c index 5044b76..18bfdad 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -1,4 +1,3 @@ -#if 1 #include "znordic.h" // #include @@ -32,6 +31,39 @@ void on_service_init(void) { } extern void one_conduction_main(); +/*lint -save -e14 */ +/** + * Function is implemented as weak so that it can be overwritten by custom application error handler + * when needed. + */ +void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info) { + __disable_irq(); + NRF_LOG_FINAL_FLUSH(); + + switch (id) { + case NRF_FAULT_ID_SDK_ASSERT: { + assert_info_t *p_info = (assert_info_t *)info; + NRF_LOG_ERROR("ASSERTION FAILED at %s:%u", p_info->p_file_name, p_info->line_num); + break; + } + case NRF_FAULT_ID_SDK_ERROR: { + error_info_t *p_info = (error_info_t *)info; + NRF_LOG_ERROR("ERROR %u [%s] at %s:%u\r\nPC at: 0x%08x", p_info->err_code, nrf_strerror_get(p_info->err_code), p_info->p_file_name, p_info->line_num, pc); + NRF_LOG_ERROR("End of error report"); + break; + } + default: + NRF_LOG_ERROR("UNKNOWN FAULT at 0x%08X", pc); + break; + } + + NRF_BREAKPOINT_COND; + // On assert, the system can only recover with a reset. + + NRF_LOG_WARNING("System reset"); + NVIC_SystemReset(); +} + int main() { APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, 20); znordic_init_without_wd(); @@ -53,6 +85,3 @@ int main() { *******************************************************************************/ znordic_loop(); } -#else -#include "ads1293_simple_tester.c" -#endif \ No newline at end of file diff --git a/app/src/one_conduction_main.c b/app/src/one_conduction_main.c index e39ee98..692da7c 100644 --- a/app/src/one_conduction_main.c +++ b/app/src/one_conduction_main.c @@ -387,6 +387,6 @@ void one_conduction_main() { hwss_init(); ds_init(on_state_change); - ds_change_to_state(kdevice_state_poweron); + // ds_change_to_state(kdevice_state_poweron); znordic_loop(); } diff --git a/app/src/service/heart_wave_sample_service/heart_wave_sample_service.c b/app/src/service/heart_wave_sample_service/heart_wave_sample_service.c index b74ddd9..53aecea 100644 --- a/app/src/service/heart_wave_sample_service/heart_wave_sample_service.c +++ b/app/src/service/heart_wave_sample_service/heart_wave_sample_service.c @@ -3,6 +3,7 @@ #include "basic_service/app_event.h" #include "basic_service/app_event_distribute.h" #include "board/ads129x/ads129x.h" +#include "board/app_board.h" #include "board/board_ecg_sensor.h" #include "heart_ware_sample_data_mgr.h" #include "heart_wave_sample_data_pre_process.h" @@ -16,13 +17,27 @@ typedef enum { static capture_state_t m_prepare_capture_state = kidle; static uint32_t m_start_capture_tp; +static void on_ads129x_ready_irq(app_board_irq_event_t event) { + // static ads129x_capture_data_t capture_data; + // ads129x_read_data(&capture_data); + // ZLOGI("1"); + // static uint16_t data; + // data += 100; + // hwsd_mgr_push_one_frame(data); +} + +void hwss_init(void) { + // + app_board_reg_irq_listener(kon_irq_ads1291_ready_pin, on_ads129x_ready_irq); +} -void hwss_init(void) {} void hwss_start_prepare_capture(void) { m_start_capture_tp = znordic_getpower_on_s(); m_prepare_capture_state = kprepare; hwsd_pre_processer_init(); hwsd_mgr_reset_buffer(); + + ads129x_start_capture(true); } void hwss_start_capture(void) { m_start_capture_tp = znordic_getpower_on_s(); @@ -31,6 +46,7 @@ void hwss_start_capture(void) { void hwss_stop_capture(void) { m_prepare_capture_state = kidle; hwsd_mgr_reset_buffer(); + ads129x_stop_capture(); } float hwss_read_val(void) { diff --git a/bak/zapp_timer.c b/bak/zapp_timer.c new file mode 100644 index 0000000..efaa974 --- /dev/null +++ b/bak/zapp_timer.c @@ -0,0 +1,29 @@ +#include "zapp_timer.h" + +static void app_timer_timeout_handler(void* p_context) { // + zapp_timer_context* zcontext = (zapp_timer_context*)p_context; + ZASSERT(zcontext != NULL); + ZASSERT(zcontext->mark = 0xAABBCCDD); + + if (zcontext->timeout_handler) zcontext->timeout_handler(zcontext->usrcontext); +} + +ret_code_t zapp_timer_create(zapp_timer_context* context, // + app_timer_id_t* p_timer_id, app_timer_mode_t mode, app_timer_timeout_handler_t timeout_handler) { + context->timeout_handler = timeout_handler; + context->mark = 0xAABBCCDD; + ret_code_t ret = app_timer_create(p_timer_id, mode, app_timer_timeout_handler); + if (ret != NRF_SUCCESS) { + return ret; + } + (*p_timer_id)->p_context = context; + return ret; +} + +ret_code_t zapp_timer_start(app_timer_id_t timer_id, uint32_t timeout_ticks, void* p_context) { // + zapp_timer_context* zcontext = (zapp_timer_context*)timer_id->p_context; + ZASSERT(zcontext != NULL); + ZASSERT(zcontext->mark = 0xAABBCCDD); + zcontext->usrcontext = p_context; + return app_timer_start(timer_id, timeout_ticks, zcontext); +} diff --git a/bak/zapp_timer.h b/bak/zapp_timer.h new file mode 100644 index 0000000..f73f008 --- /dev/null +++ b/bak/zapp_timer.h @@ -0,0 +1,17 @@ +#pragma once +#include +#include + +#include "znordic.h" + +typedef void (*app_event_listener_t)(void* p_event_data, uint16_t event_size); + +typedef struct { + uint32_t mark; + app_timer_timeout_handler_t timeout_handler; + void* usrcontext; +} zapp_timer_context; + +ret_code_t zapp_timer_create(zapp_timer_context* context, // + app_timer_id_t const* p_timer_id, app_timer_mode_t mode, app_timer_timeout_handler_t timeout_handler); +ret_code_t zapp_timer_start(app_timer_id_t timer_id, uint32_t timeout_ticks, void* p_context); \ No newline at end of file diff --git a/libznordic b/libznordic index 0122505..30b9378 160000 --- a/libznordic +++ b/libznordic @@ -1 +1 @@ -Subproject commit 01225055c1cbd6e6b3bc50a5f084d4e515063512 +Subproject commit 30b93787c0e760b623df1656c3002ed742f1fff8