app_err.c 1.6 KB

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