systick.c 780 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * (c) danielinux 2019
  3. *
  4. * GPLv.2
  5. *
  6. * See LICENSE for details
  7. */
  8. #include "system.h"
  9. #include "systick.h"
  10. #include <stdint.h>
  11. /*** SYSTICK ***/
  12. #define SYSTICK_BASE (0xE000E010)
  13. #define SYSTICK_CSR (*(volatile uint32_t *)(SYSTICK_BASE + 0x00))
  14. #define SYSTICK_RVR (*(volatile uint32_t *)(SYSTICK_BASE + 0x04))
  15. #define SYSTICK_CVR (*(volatile uint32_t *)(SYSTICK_BASE + 0x08))
  16. #define SYSTICK_CALIB (*(volatile uint32_t *)(SYSTICK_BASE + 0x0C))
  17. volatile unsigned int jiffies = 0;
  18. void systick_enable(void)
  19. {
  20. SYSTICK_RVR = ((cpu_freq / 1000) - 1);
  21. SYSTICK_CVR = 0;
  22. SYSTICK_CSR |= 0x07;
  23. }
  24. void systick_disable(void)
  25. {
  26. SYSTICK_CSR &= ~1;
  27. }
  28. void isr_systick(void)
  29. {
  30. ++jiffies;
  31. }
  32. uint32_t HAL_GetTick(void)
  33. {
  34. return jiffies;
  35. }