Initial commit: MT firmware project
- BLE peripheral applications - dr_piezo and bladder_patch projects Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
223
project/ble_peripheral/ble_app_bladder_patch/main_timer.c
Normal file
223
project/ble_peripheral/ble_app_bladder_patch/main_timer.c
Normal file
@@ -0,0 +1,223 @@
|
||||
/*******************************************************************************
|
||||
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 "meas_pd_voltage_custom.h"
|
||||
#include "meas_pd_imm.h"
|
||||
#include "meas_pd_voltage_full.h"
|
||||
#include "mcp4725_i2c.h"
|
||||
#include "ad5272_i2c.h"
|
||||
#include "power_control.h"
|
||||
#include <cmd_parse.h>
|
||||
#include "meas_pd_48.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_pdread= 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;
|
||||
bool adc_enabled = false;
|
||||
static uint16_t cnt_adc = 0;
|
||||
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();
|
||||
|
||||
}
|
||||
if(go_pdread == true) {
|
||||
//DBG_PRINTF("PD48 ADC=%d\r\n",cnt_adc);
|
||||
main_timer_stop();
|
||||
go_pdread = false;
|
||||
m48_adc_start_init();
|
||||
}
|
||||
if(adc_enabled == true) {
|
||||
main_timer_stop();
|
||||
DBG_PRINTF("PD48 ADC=%d\r\n",cnt_adc);
|
||||
|
||||
|
||||
if(ble_got_new_data==false){
|
||||
|
||||
if (cnt_adc<500){
|
||||
cnt_adc++;
|
||||
|
||||
}
|
||||
else if (cnt_adc == 500){
|
||||
cnt_adc = 0;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user