Browse Source

update

master
zhaohe 1 year ago
parent
commit
689c5ce45e
  1. 22
      README.md
  2. 2
      app/config/sdk_config.h
  3. 4
      app/src/basic_service/device_state.c
  4. 4
      app/src/basic_service/device_state.h
  5. 6
      app/src/basic_service/device_version_info_mgr.c
  6. 15
      app/src/board/ads129x/ads129x.c
  7. 4
      app/src/board/ads129x/ads129x.h
  8. 1
      app/src/board/app_board.c
  9. 37
      app/src/main.c
  10. 2
      app/src/one_conduction_main.c
  11. 18
      app/src/service/heart_wave_sample_service/heart_wave_sample_service.c
  12. 29
      bak/zapp_timer.c
  13. 17
      bak/zapp_timer.h
  14. 2
      libznordic

22
README.md

@ -79,6 +79,28 @@ board_init
README:
外设 ---> 初始化
使用
app_board(在状态切换的时候,切换)
------->
切换状态
实时切换状态并使用 依然归类到整机状态中去
------>
1. 外设状态 <---> 系统状态绑定
外设临时状态切换
调用方法
1. 外设的切换发生在系统状态机的切换:
1. 外设再被调用时,检查自己的状态,如果状态不满足打印警报或者错误日志。
2. 外设再被调用时,检查自己的状态,如果状态不满足,但允许自行切换状态,则自行进行状态切换
3. 服务本身不负责状态的切换。

2
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"

4
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));

4
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();

6
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));
}

15
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]);

4
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();

1
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); //

37
app/src/main.c

@ -1,4 +1,3 @@
#if 1
#include "znordic.h"
//
#include <stdarg.h>
@ -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

2
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();
}

18
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) {

29
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);
}

17
bak/zapp_timer.h

@ -0,0 +1,17 @@
#pragma once
#include <stdbool.h>
#include <stdint.h>
#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);

2
libznordic

@ -1 +1 @@
Subproject commit 01225055c1cbd6e6b3bc50a5f084d4e515063512
Subproject commit 30b93787c0e760b623df1656c3002ed742f1fff8
Loading…
Cancel
Save