app_power.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "app_power.h"
  2. #include "nrf_gpio.h"
  3. #include "usr_config.h"
  4. #include "bsp_time.h"
  5. #include "system.h"
  6. #include "hal_mt.h"
  7. #include "hal_battery.h"
  8. #include "app_charge.h"
  9. #include "hal_ble_client.h"
  10. #include "nrf_delay.h"
  11. #include "app_flash.h"
  12. #include "bsp_wdt.h"
  13. #include "app_timer.h"
  14. #include "system.h"
  15. #include "bsp_pwm.h"
  16. #include "app_client.h"
  17. #include "hal_ble_uart0.h"
  18. #include "hal_led.h"
  19. #include "lsm6ds3tr_c.h"
  20. #include "hal_ser_imu_mode_manage.h"
  21. #include "app_math.h"
  22. /********************** 变量区 *************************/
  23. /********************** 函数声明区 *************************/
  24. void PWR_Off(void)
  25. {
  26. UART0_unInit(PIN_TXD_BLE,PIN_RXD_BLE);
  27. LED_Close_Enforce();
  28. hal_ser_imu_mode_manage_set_required(HAL_SER_IMU_MODE_MANAGE_STANDBY, HAL_SER_IMU_MODE_MANAGE_IMU_MODE_OFF);
  29. hal_ser_imu_mode_manage_set_required(HAL_SER_IMU_MODE_MANAGE_NORMAL, HAL_SER_IMU_MODE_MANAGE_IMU_MODE_OFF);
  30. hal_ser_imu_mode_manage_set_required(HAL_SER_IMU_MODE_MANAGE_SELF_CHECK, HAL_SER_IMU_MODE_MANAGE_IMU_MODE_OFF);
  31. hal_ser_imu_mode_manage_set_required(HAL_SER_IMU_MODE_MANAGE_GAME, HAL_SER_IMU_MODE_MANAGE_IMU_MODE_OFF);
  32. hal_ser_imu_mode_manage_set_required(HAL_SER_IMU_MODE_MANAGE_REALSTEP, HAL_SER_IMU_MODE_MANAGE_IMU_MODE_OFF);
  33. drv_lsm_power_off();
  34. drv_qmc6310_power_off();
  35. nrf_gpio_pin_write(PIN_MT_EN,0);
  36. nrf_delay_ms(200);
  37. nrf_gpio_cfg_sense_input(PIN_CHARGING, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);//IO
  38. uint32_t err_code = sd_power_system_off();
  39. SEGGER_RTT_printf(0,"power off...BAT:%d,ERR:%d\n",GetBatteryPersent(),err_code);
  40. //APP_ERROR_CHECK(err_code);
  41. }
  42. static void PWR_Process(void)
  43. {
  44. if((0 == GetBatteryPersent() && app_charge_Getstate()==BLE_CHARGE_PULLOUT)){
  45. SEGGER_RTT_printf(0,"BatteryPersent:%d\n",GetBatteryPersent());
  46. SEGGER_RTT_printf(0,"power off...\n");
  47. //保存数据到flash
  48. if(Flash_SaveStep() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Power,"save step fail");
  49. if(Flash_SaveInfomation() != ZONE_OP_SUCCESS)Except_TxError(EXCEPT_Power,"save information fail");
  50. MT_Run(1000);
  51. feed_watchdog();
  52. for(uint8_t temp = 0;temp < 10; temp++){
  53. app_client_DataUpdate_Send();
  54. nrf_delay_ms(100);
  55. }
  56. PWR_Off();
  57. }
  58. }
  59. void PWR_Init(void)
  60. {
  61. Process_Start(10000,"PWR_Process",PWR_Process);
  62. }