hal_soft_time.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "sdk_common.h"
  2. #include "bsp_time.h"
  3. #include "nrf_drv_timer.h"
  4. #include "SEGGER_RTT.h"
  5. #include "system.h"
  6. #include "nrf_drv_rtc.h"
  7. #include "hal_soft_time.h"
  8. #include "system.h"
  9. static bsp_soft_time_t mIbsp_soft_time_t={0};
  10. void hal_soft_time_create(bsp_soft_time_t *soft_time_p){
  11. if(NULL == soft_time_p)return;
  12. bsp_soft_time_t *head_soft_time =&mIbsp_soft_time_t;
  13. while(head_soft_time->next){
  14. head_soft_time = head_soft_time->next;
  15. }
  16. soft_time_p->next = NULL;
  17. head_soft_time->tim = TIME_GetTicks();
  18. head_soft_time->next = soft_time_p;
  19. }
  20. void hal_soft_time_stop(bsp_soft_time_t *soft_time_p){
  21. if(NULL == soft_time_p)return;
  22. soft_time_p->state = 0;
  23. }
  24. void hal_soft_time_restart(bsp_soft_time_t *soft_time_p){
  25. if(NULL == soft_time_p)return;
  26. soft_time_p->state = 1;
  27. }
  28. void hal_soft_time_Process(void)
  29. {
  30. bsp_soft_time_t *head_soft_time =&mIbsp_soft_time_t;
  31. while(head_soft_time->next){
  32. if(head_soft_time->next->state){
  33. if((TIME_GetTicks()-head_soft_time->tim) >= head_soft_time->next->peroid){
  34. head_soft_time->tim = TIME_GetTicks();
  35. head_soft_time->next->cb();
  36. }
  37. }
  38. head_soft_time = head_soft_time->next;
  39. }
  40. }
  41. void hal_soft_time_init(void){
  42. Process_Start(0,"hal_soft_time",hal_soft_time_Process);
  43. }