app_power_NoPowerEnPin.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "hal_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_dataupdate.h"
  17. #include "hal_ble_uart0.h"
  18. #include "hal_led.h"
  19. #include "lsm6ds3tr_c.h"
  20. #include "hal_imu.h"
  21. #include "app_math.h"
  22. /********************** 变量区 *************************/
  23. /********************** 函数声明区 *************************/
  24. void PWR_Off(void)
  25. {
  26. UART0_unInit();
  27. LED_Close_Enforce();
  28. Battery_Enable(false);
  29. IMU_PowerOffProcess();
  30. nrf_gpio_pin_write(PIN_MT_EN,0);
  31. nrf_delay_ms(200);
  32. nrf_gpio_cfg_sense_input(PIN_CHARGING, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);//IO
  33. uint32_t err_code = sd_power_system_off();
  34. SEGGER_RTT_printf(0,"power off...BAT:%d,ERR:%d\n",GetBatteryPersent(),err_code);
  35. //APP_ERROR_CHECK(err_code);
  36. }
  37. static void PWR_Process(void)
  38. {
  39. #if WATCHDOG_ENANBLE
  40. feed_watchdog();
  41. #endif
  42. if(1 == (Battery_BatteryIs_0() && app_charge_Getstate()==BLE_Client_T_CHARGE_PULLOUT)){
  43. SEGGER_RTT_printf(0,"BatteryPersent:%d\n",GetBatteryPersent());
  44. SEGGER_RTT_printf(0,"power off...\n");
  45. //保存数据到flash
  46. Flash_SaveStep();
  47. Flash_SaveInfomation();
  48. MT_Run(1000);
  49. for(uint8_t temp = 0;temp < 10; temp++){
  50. app_client_DataUpdate_Send();
  51. nrf_delay_ms(100);
  52. }
  53. PWR_Off();
  54. }
  55. }
  56. void PWR_Init(void)
  57. {
  58. Process_Start(1000,"PWR_Process",PWR_Process);
  59. }