app_err.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "hal_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. __disable_irq();
  25. NVIC_SystemReset();
  26. }
  27. void app_err_Set(uint8_t errNum,uint8_t errTimes)
  28. {
  29. if(errNum>=ERR_NUM_OF_T) return;
  30. errTab[errNum] = errTimes;
  31. }
  32. void app_err_Process(void)
  33. {
  34. for(int i=0;i<ERR_NUM_OF_T;i++){
  35. if(errTab[i]>0){ errTab[i]--;
  36. uint8_t buf[16];
  37. uint8_t L=0;
  38. L=0;
  39. buf[L++] = errDex; //0左鞋1右鞋
  40. buf[L++] = i; //错误编号
  41. BLE_Client_Tx_Send(0,BLE_Client_T_ERR,buf,L);
  42. }
  43. }
  44. static uint8_t timflag=0;
  45. timflag++;
  46. if(timflag>=5){ timflag =0;
  47. if(1 == mFlash.mFlashLog.Errorflag)app_client_infomation_Send_defineName(mFlash.mFlashLog.logData,strlen((const char *)mFlash.mFlashLog.logData));
  48. }
  49. }
  50. void cb_BLE_Host_R_ERR(void* handle)
  51. {
  52. BLE_Host_Rx_t* target = handle;
  53. BLE_Client_Tx_Send(0,BLE_Client_T_ERR,target->pDat,target->datLen);
  54. }
  55. void app_err_Init(void)
  56. {
  57. if(mFlash.isHost==0) errDex = 1;
  58. memset(errTab,0,sizeof(errTab));
  59. Process_Start(3000,"app_err",app_err_Process);
  60. BLE_Host_Rx_Regist(BLE_Host_R_ERR,cb_BLE_Host_R_ERR);
  61. }