systick.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (C) 2023 Daniele Lacamera <root@danielinux.net>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "systick.h"
  18. #include "task.h"
  19. #include <stdint.h>
  20. /*** SYSTICK ***/
  21. volatile uint32_t SystemCoreClock = 216000000;
  22. #define SYSTICK_BASE (0xE000E010)
  23. #define SYSTICK_CSR (*(volatile uint32_t *)(SYSTICK_BASE + 0x00))
  24. #define SYSTICK_RVR (*(volatile uint32_t *)(SYSTICK_BASE + 0x04))
  25. #define SYSTICK_CVR (*(volatile uint32_t *)(SYSTICK_BASE + 0x08))
  26. #define SYSTICK_CALIB (*(volatile uint32_t *)(SYSTICK_BASE + 0x0C))
  27. volatile unsigned int jiffies = 0;
  28. void systick_enable(void)
  29. {
  30. SYSTICK_RVR = ((SystemCoreClock / 1000) - 1);
  31. SYSTICK_CVR = 0;
  32. SYSTICK_CSR |= 0x07;
  33. }
  34. void systick_disable(void)
  35. {
  36. SYSTICK_CSR &= ~1;
  37. }
  38. void isr_systick(void)
  39. {
  40. ++jiffies;
  41. trigger_event(EV_SYSTICK);
  42. }
  43. uint32_t HAL_GetTick(void)
  44. {
  45. return jiffies;
  46. }