board.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2017-07-24 Tanek the first version
  9. * 2018-11-12 Ernest Chen modify copyright
  10. */
  11. #include <stdint.h>
  12. #include <rthw.h>
  13. #include <rtthread.h>
  14. #define _SCB_BASE (0xE000E010UL)
  15. #define _SYSTICK_CTRL (*(rt_uint32_t *)(_SCB_BASE + 0x0))
  16. #define _SYSTICK_LOAD (*(rt_uint32_t *)(_SCB_BASE + 0x4))
  17. #define _SYSTICK_VAL (*(rt_uint32_t *)(_SCB_BASE + 0x8))
  18. #define _SYSTICK_CALIB (*(rt_uint32_t *)(_SCB_BASE + 0xC))
  19. #define _SYSTICK_PRI (*(rt_uint8_t *)(0xE000ED23UL))
  20. // Updates the variable SystemCoreClock and must be called
  21. // whenever the core clock is changed during program execution.
  22. extern void SystemCoreClockUpdate(void);
  23. // Holds the system core clock, which is the system clock
  24. // frequency supplied to the SysTick timer and the processor
  25. // core clock.
  26. extern uint32_t SystemCoreClock;
  27. static uint32_t _SysTick_Config(rt_uint32_t ticks)
  28. {
  29. if ((ticks - 1) > 0xFFFFFF)
  30. {
  31. return 1;
  32. }
  33. _SYSTICK_LOAD = ticks - 1;
  34. _SYSTICK_PRI = 0xFF;
  35. _SYSTICK_VAL = 0;
  36. _SYSTICK_CTRL = 0x07;
  37. return 0;
  38. }
  39. #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
  40. #define RT_HEAP_SIZE 1024
  41. static uint32_t rt_heap[RT_HEAP_SIZE]; // heap default size: 4K(1024 * 4)
  42. RT_WEAK void *rt_heap_begin_get(void)
  43. {
  44. return rt_heap;
  45. }
  46. RT_WEAK void *rt_heap_end_get(void)
  47. {
  48. return rt_heap + RT_HEAP_SIZE;
  49. }
  50. #endif
  51. /**
  52. * This function will initial your board.
  53. */
  54. void rt_hw_board_init()
  55. {
  56. /* System Clock Update */
  57. SystemCoreClockUpdate();
  58. /* System Tick Configuration */
  59. _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  60. /* Call components board initial (use INIT_BOARD_EXPORT()) */
  61. #ifdef RT_USING_COMPONENTS_INIT
  62. rt_components_board_init();
  63. #endif
  64. #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
  65. rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
  66. #endif
  67. }
  68. void SysTick_Handler(void)
  69. {
  70. /* enter interrupt */
  71. rt_interrupt_enter();
  72. rt_tick_increase();
  73. /* leave interrupt */
  74. rt_interrupt_leave();
  75. }