systick.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "gd32f4xx.h"
  2. #include "systick.h"
  3. #include "FreeRTOS.h"
  4. __IO uint32_t uwTick;
  5. #define SYS_SUPPORT_OS 1
  6. volatile static uint32_t delay;
  7. /*!
  8. \brief configure systick
  9. \param[in] none
  10. \param[out] none
  11. \retval none
  12. */
  13. void systick_config(void)
  14. {
  15. /* setup systick timer for 1000Hz interrupts */
  16. if(SysTick_Config(SystemCoreClock / 1000U)) {
  17. /* capture error */
  18. while(1) {
  19. }
  20. }
  21. /* configure the systick handler priority */
  22. NVIC_SetPriority(SysTick_IRQn, 0x15U);
  23. }
  24. /*!
  25. \brief delay a time in milliseconds
  26. \param[in] count: count in milliseconds
  27. \param[out] none
  28. \retval none
  29. */
  30. void delay_1ms(uint32_t count)
  31. {
  32. delay = count;
  33. while(0U != delay) {
  34. }
  35. }
  36. /*!
  37. \brief delay decrement
  38. \param[in] none
  39. \param[out] none
  40. \retval none
  41. */
  42. void delay_decrement(void)
  43. {
  44. if(0U != delay) {
  45. delay--;
  46. }
  47. uwTick += 1;
  48. }
  49. void delay_us(uint32_t nus)
  50. {
  51. uint32_t j = 0;
  52. uint8_t i = 0;
  53. for(j = 0 ;j < nus;j++)
  54. {
  55. for(i=0;i<255;i++);
  56. }
  57. }
  58. uint32_t systick_get()
  59. {
  60. return uwTick;
  61. }