You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.9 KiB

  1. #include <stdbool.h> //定义布尔
  2. #include "lib_config.h"
  3. #include "system_ES8P5066.h"
  4. uint32_t g_sys_sick = 0;
  5. /***********************************************************************************************************************
  6. * ======================================================ticket======================================================= *
  7. ***********************************************************************************************************************/
  8. void SysTick_IRQHandler(void) { g_sys_sick++; }
  9. void systicket_init(void) {
  10. SYSTICK_InitStruType x; //
  11. x.SysTick_Value = SystemCoreClock / 1000; //
  12. x.SysTick_ClkSource = SysTick_ClkS_Cpu; //时钟48M
  13. x.SysTick_ITEnable = Enable; //
  14. SysTick_Init(&x); //现在滴答定时器时钟用的48M,重装载值4800 t=1s/f(f=48M/48000)
  15. SysTick_Disable(); //
  16. SysTick_Enable();
  17. }
  18. /**
  19. * @brief
  20. */
  21. uint32_t systicket_get_now_ms(void) { return g_sys_sick; }
  22. /**
  23. * @brief ticket过去了多久
  24. *
  25. * @param ticket
  26. * @return uint32_t
  27. */
  28. uint32_t systicket_haspassedms(uint32_t ticket) {
  29. uint32_t nowticket = systicket_get_now_ms();
  30. if (nowticket >= ticket) {
  31. return nowticket - ticket;
  32. }
  33. return UINT32_MAX - ticket + nowticket;
  34. }
  35. /**
  36. * @brief ms
  37. *
  38. * @param nTime
  39. */
  40. void systicket_delay_ms(uint32_t nTime) {
  41. uint32_t TimingDelay = 0;
  42. TimingDelay = systicket_get_now_ms();
  43. // printf("nTime%d\r\n",nTime);
  44. while (systicket_haspassedms(TimingDelay) < nTime)
  45. ;
  46. }
  47. // void systicket_do_debug_light_state(void) {
  48. // static uint32_t lastprocess = 0;
  49. // static uint8_t debug_led_state = 1;
  50. // if (systicket_haspassedms(lastprocess) > 1000) {
  51. // lastprocess = systicket_get_now_ms();
  52. // debug_led_state = !debug_led_state;
  53. // systicket_debug_set(debug_led_state);
  54. // }
  55. // }