board.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2006-2019, 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. extern void SystemCoreClockUpdate(void);
  21. extern uint32_t SystemCoreClock;
  22. static uint32_t _SysTick_Config(rt_uint32_t ticks)
  23. {
  24. if ((ticks - 1) > 0xFFFFFF)
  25. {
  26. return 1;
  27. }
  28. _SYSTICK_LOAD = ticks - 1;
  29. _SYSTICK_PRI = 0xFF;
  30. _SYSTICK_VAL = 0;
  31. _SYSTICK_CTRL = 0x07;
  32. return 0;
  33. }
  34. #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
  35. #define RT_HEAP_SIZE 1024
  36. static uint32_t rt_heap[RT_HEAP_SIZE]; // heap default size: 4K(1024 * 4)
  37. RT_WEAK void *rt_heap_begin_get(void)
  38. {
  39. return rt_heap;
  40. }
  41. RT_WEAK void *rt_heap_end_get(void)
  42. {
  43. return rt_heap + RT_HEAP_SIZE;
  44. }
  45. #endif
  46. /* This function will initial your board. */
  47. void rt_hw_board_init()
  48. {
  49. /* System Clock Update */
  50. SystemCoreClockUpdate();
  51. /* System Tick Configuration */
  52. _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  53. /* Call components board initial (use INIT_BOARD_EXPORT()) */
  54. #ifdef RT_USING_COMPONENTS_INIT
  55. rt_components_board_init();
  56. #endif
  57. #ifdef RT_USING_CONSOLE
  58. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  59. #endif
  60. #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
  61. rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
  62. #endif
  63. }
  64. void SysTick_Handler(void)
  65. {
  66. /* enter interrupt */
  67. rt_interrupt_enter();
  68. rt_tick_increase();
  69. /* leave interrupt */
  70. rt_interrupt_leave();
  71. }