- binary_tx_handler를 dr_binary_tx_safe로 전체 교체 (APP_ERROR_CHECK 제거) - data_tx_handler APP_ERROR_CHECK → DBG_PRINTF 교체 - memset/memcpy 하드코딩 크기를 define 상수로 교체 (버퍼 오버런 수정) - SERIAL_NO_LENGTH, HW_NO_LENGTH, PASSKEY_LENGTH를 main.h로 통합 - 미사용 HW 드라이버/EEPROM 코드 삭제, TWI를 i2c_manager.c로 통합 - EEPROM → FDS 전환, 코드 리뷰 현황 문서 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
191 lines
4.2 KiB
C
191 lines
4.2 KiB
C
/*******************************************************************************
|
|
TEST medi50 Dec 23
|
|
******************************************************************************/
|
|
|
|
#include "sdk_common.h"
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "nrf.h"
|
|
#include "nrf_drv_saadc.h"
|
|
#include "nrf_drv_ppi.h"
|
|
#include "nrf_drv_timer.h"
|
|
#include "boards.h"
|
|
#include "app_error.h"
|
|
#include "nrf_delay.h"
|
|
#include "app_util_platform.h"
|
|
#include "nrf_pwr_mgmt.h"
|
|
|
|
#include "nrf_log.h"
|
|
#include "nrf_drv_gpiote.h"
|
|
#include "battery_saadc.h"
|
|
#include "app_timer.h"
|
|
|
|
#include "main.h"
|
|
#include "app_raw_main.h"
|
|
#include "main_timer.h"
|
|
#include "tmp235_q1.h"
|
|
//#include "fstorage.h"
|
|
#include "power_control.h"
|
|
#include <cmd_parse.h>
|
|
#include "debug_print.h"
|
|
#include "i2c_manager.h" //add cj
|
|
APP_TIMER_DEF(m_main_loop_timer_id);
|
|
|
|
#if FEATURE_DETAIL_VALUE_FULL
|
|
#define MAIN_LOOP_INTERVAL 80 /* 디테일 프린트아웃이 있을경우 Full_Mode Main Prosessing 수행하는 타이머 */
|
|
|
|
//extern bool pd_adc_full_a_start;
|
|
//extern bool pd_adc_full_b_start;
|
|
//extern bool pd_adc_full_c_start;
|
|
//extern bool pd_adc_full_d_start;
|
|
//extern bool pd_adc_full_end;
|
|
|
|
extern which_cmd_t cmd_type_t;
|
|
#else
|
|
#define MAIN_LOOP_INTERVAL 10
|
|
#endif
|
|
bool go_batt= false;
|
|
bool go_temp= false;
|
|
bool go_device_power_off = false;
|
|
bool go_sleep_mode_enter = false;
|
|
bool go_NVIC_SystemReset = false;
|
|
bool motion_raw_data_enabled = false;
|
|
bool ble_got_new_data = false;
|
|
bool motion_data_once = false;
|
|
void main_loop(void * p_context) /* For x ms */
|
|
{
|
|
UNUSED_PARAMETER(p_context);
|
|
|
|
#if FEATURE_DETAIL_VALUE_FULL
|
|
// if(pd_adc_full_a_start == true) { // A mode
|
|
// main_timer_stop();
|
|
// printf("main_loop_A\r\n");
|
|
// full_adc_start();
|
|
// }else if(pd_adc_full_b_start == true) { // B mode
|
|
// main_timer_stop();
|
|
// printf("main_loop_B\r\n");
|
|
// full_adc_start();
|
|
// }else if(pd_adc_full_c_start == true) { // C mode
|
|
// main_timer_stop();
|
|
// printf("main_loop_C\r\n");
|
|
// full_adc_start();
|
|
// }else if(pd_adc_full_d_start == true) { // D mode
|
|
// main_timer_stop();
|
|
// printf("main_loop_D\r\n");
|
|
// full_adc_start();
|
|
// }else if(pd_adc_full_end == true) { // Completed
|
|
// pd_adc_full_end = false;
|
|
// main_timer_stop();
|
|
// printf("main_loop_END\r\n");
|
|
|
|
// if(cmd_type_t == CMD_BLE) {
|
|
// full_send_timer_start();
|
|
// }
|
|
// }
|
|
#endif
|
|
|
|
// For Motion Data Sampling
|
|
|
|
if(motion_raw_data_enabled == true) {
|
|
main_timer_stop();
|
|
if(motion_data_once == true)
|
|
{
|
|
|
|
hw_i2c_init_once();
|
|
icm42670_main();
|
|
}
|
|
else{
|
|
|
|
if(ble_got_new_data==false){
|
|
//for(uint16_t i=0 ; i<60 ;i++)
|
|
//{
|
|
DBG_PRINTF("IMU \r\n");
|
|
|
|
icm42670_main();
|
|
nrf_delay_ms(10);
|
|
motion_raw_data_enabled = true;
|
|
main_timer_start();
|
|
}
|
|
// else if(ble_got_new_data==true){
|
|
// motion_data_once = true;
|
|
// }
|
|
}
|
|
}
|
|
|
|
|
|
if(go_batt == true) {
|
|
DBG_PRINTF("IMU BATT\r\n");
|
|
main_timer_stop();
|
|
go_batt = false;
|
|
// go_temp = true;
|
|
battery_level_meas();
|
|
// nrf_delay_ms(20);
|
|
// m48_adc_start_init();
|
|
// main_timer_start();
|
|
}
|
|
|
|
|
|
if(go_temp == true) {
|
|
DBG_PRINTF("IMU Temp\r\n");
|
|
main_timer_stop();
|
|
// go_batt = false;
|
|
go_temp = false;
|
|
motion_data_once = true;
|
|
tmp235_voltage_level_meas();
|
|
// motion_raw_data_enabled = true;
|
|
// main_timer_start();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For System Control */
|
|
|
|
|
|
|
|
if(go_device_power_off == true){
|
|
main_timer_stop();
|
|
|
|
DBG_PRINTF("Off main_timer\r\n");
|
|
device_power_off();
|
|
}
|
|
|
|
if(go_sleep_mode_enter == true){
|
|
main_timer_stop();
|
|
|
|
DBG_PRINTF("sleep main timer\r\n");
|
|
|
|
|
|
sleep_mode_enter();
|
|
}
|
|
|
|
if(go_NVIC_SystemReset == true) {
|
|
|
|
|
|
|
|
main_timer_stop();
|
|
|
|
NVIC_SystemReset();
|
|
}
|
|
}
|
|
|
|
|
|
void main_timer_start(void)
|
|
{
|
|
APP_ERROR_CHECK(app_timer_start(m_main_loop_timer_id, APP_TIMER_TICKS(MAIN_LOOP_INTERVAL), NULL));
|
|
}
|
|
|
|
void main_timer_stop(void)
|
|
{
|
|
APP_ERROR_CHECK(app_timer_stop(m_main_loop_timer_id));
|
|
}
|
|
|
|
void main_timer_init(void)
|
|
{
|
|
APP_ERROR_CHECK(app_timer_create(&m_main_loop_timer_id, APP_TIMER_MODE_SINGLE_SHOT, main_loop));
|
|
}
|
|
|