app_err.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "app_err.h"
  2. #include "usr_config.h"
  3. #include "bsp_time.h"
  4. #include "system.h"
  5. #include "hal_ble_client.h"
  6. #include "hal_ble_host.h"
  7. #include "nrf_delay.h"
  8. #include "app_flash.h"
  9. #include "hal_imu.h"
  10. #include "ble_comm.h"
  11. #include "app_error.h"
  12. #include "app_client_infomation.h"
  13. #include "app_util_platform.h"
  14. #include "nrf_strerror.h"
  15. #include "hal_flash.h"
  16. /********************** 函数声明区 *************************/
  17. static uint8_t errDex = 0;
  18. static uint8_t errTab[ERR_NUM_OF_T];
  19. //错误回调
  20. void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
  21. {
  22. Flash_SaveLog(id,pc,info);
  23. SEGGER_RTT_printf(0,"app_error_fault_handler,System reset\n");
  24. nrf_gpio_cfg_output(PIN_RESET_PIN); nrf_gpio_pin_write(PIN_RESET_PIN,0);
  25. }
  26. void app_err_Set(uint8_t errNum,uint8_t errTimes)
  27. {
  28. if(errNum>=ERR_NUM_OF_T) return;
  29. errTab[errNum] = errTimes;
  30. }
  31. void app_err_Process(void)
  32. {
  33. for(int i=0;i<ERR_NUM_OF_T;i++){
  34. if(errTab[i]>0){ errTab[i]--;
  35. uint8_t buf[16];
  36. uint8_t L=0;
  37. L=0;
  38. buf[L++] = errDex; //0左鞋1右鞋
  39. buf[L++] = i; //错误编号
  40. BLE_Client_Tx_Send(0,BLE_ERR,buf,L);
  41. }
  42. }
  43. static uint8_t timflag=0;
  44. timflag++;
  45. if(timflag>=5){ timflag =0;
  46. if(1 == mFlash.mFlashLog.Errorflag)app_client_infomation_Send_defineName(mFlash.mFlashLog.logData,strlen((const char *)mFlash.mFlashLog.logData));
  47. }
  48. }
  49. void cb_BLE_Host_R_ERR(void* handle)
  50. {
  51. BLE_Host_Rx_t* target = handle;
  52. BLE_Client_Tx_Send(0,BLE_ERR,target->pDat,target->datLen);
  53. }
  54. void app_err_Init(void)
  55. {
  56. if(mFlash.isHost==0) errDex = 1;
  57. memset(errTab,0,sizeof(errTab));
  58. Process_Start(3000,"app_err",app_err_Process);
  59. BLE_Host_Rx_Regist(BLE_ERR,cb_BLE_Host_R_ERR);
  60. }