/******************************************************************************* TEST medi50 Dec 23 ******************************************************************************/ #include "sdk_common.h" #include #include #include #include #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 #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)); }