1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /********************** 头文件 *************************/
- #include "bsp_time.h"
- #include "mpu9250.h"
- /********************** 变量区 *************************/
- const nrf_drv_timer_t TIMER_INT = NRF_DRV_TIMER_INSTANCE(0);
- const uint32_t time_ms = 10; //Time(in miliseconds) between consecutive compare events.
- static uint32_t time_ticks;
- int8_t dex = 0;
- extern IMU_DAT_t m_IMU_DAT_t;
- extern void process_motion(IMU_DAT_t* p);
- extern motor_control_type m_motor_control;
- /********************** 函数声明区 *************************/
- /**********************************************************
- * 函数名字:HardwareTimer_handler
- * 函数作用:硬件定时器事件回调
- * 函数参数:event_type:事件类型
- * p_context: 上下文
- * 函数返回值:无
- ***********************************************************/
- volatile bool HardWareTime_10ms_Flag =false;
- void HardwareTimer_handler(nrf_timer_event_t event_type, void* p_context)
- {
- static uint8_t Led_Test =0;
- //static uint16_t press_temp=0;
- switch (event_type)
- {
- case NRF_TIMER_EVENT_COMPARE0:
- send_to_phone_process();
- gpio_mt_process();
- if(m_motor_control.flag)
- {
- if(m_motor_control.delay_ms >10){
- m_motor_control.delay_ms-=10;
- }
- else{
- m_motor_control.flag = false;
- nrf_gpio_pin_write(MT_EN,0);
- }
- }
- #if (MPU_SENSOR == MPU_SENSOR_6050)
- if(mpu6050_get_reg_data(m_IMU_DAT_t.h.gyr,m_IMU_DAT_t.h.acc)==0){ //读取 IMU 值
- #else
- if(MPU9250_ReadData(m_IMU_DAT_t.h.gyr,m_IMU_DAT_t.h.acc,m_IMU_DAT_t.h.mag,&(m_IMU_DAT_t.h.temperature))==0){
- #endif
- m_IMU_DAT_t.h.press = (uint16_t)(ReadPressure()>>8); //读取气压计值
- ReadPressure_Pre(); //准备下一次读取
- //m_IMU_DAT_t.h.press = press_temp;
- if(0 != m_IMU_DAT_t.h.press)
- {
- Led_Test++;
- if(Led_Test>10){
- nrf_gpio_pin_toggle(LED_G);
- Led_Test =0;
- }
- }
- else Led_Test =0;
- process_motion(&m_IMU_DAT_t);
- HardWareTime_10ms_Flag =true;
- }
- break;
- default:
- //Do nothing.
- break;
- }
- }
- /**********************************************************
- * 函数名字User_HardwareTime_Sete
- * 函数作用:硬件定时器的开关控制,默认为关闭状态
- * 函数参数:value: true 打开
- * false:关闭
- * 函数返回值:无
- ***********************************************************/
- void User_HardwareTime_Set(bool value)
- {
- static bool Hardflag =false;
- ret_code_t err_code;
- if(Hardflag == value)return;
- if(value){//打开硬件定时器
- nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
- err_code = nrf_drv_timer_init(&TIMER_INT, &timer_cfg, HardwareTimer_handler);
- APP_ERROR_CHECK(err_code);
- time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_INT, time_ms);
- nrf_drv_timer_extended_compare(
- &TIMER_INT, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
- nrf_drv_timer_enable(&TIMER_INT);
- }
- else{//打开软件定时器
- nrf_drv_timer_disable(&TIMER_INT);
- nrf_drv_timer_uninit(&TIMER_INT);
- }
- Hardflag =value;
- }
|