board.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-08-06 whik first version
  9. */
  10. #include <stdint.h>
  11. #include <rthw.h>
  12. #include <rtthread.h>
  13. #define _SCB_BASE (0xE000E010UL)
  14. #define _SYSTICK_CTRL (*(rt_uint32_t *)(_SCB_BASE + 0x0))
  15. #define _SYSTICK_LOAD (*(rt_uint32_t *)(_SCB_BASE + 0x4))
  16. #define _SYSTICK_VAL (*(rt_uint32_t *)(_SCB_BASE + 0x8))
  17. #define _SYSTICK_CALIB (*(rt_uint32_t *)(_SCB_BASE + 0xC))
  18. #define _SYSTICK_PRI (*(rt_uint8_t *)(0xE000ED23UL))
  19. extern void SystemCoreClockUpdate(void);
  20. extern uint32_t SystemCoreClock;
  21. static uint32_t _SysTick_Config(rt_uint32_t ticks)
  22. {
  23. if ((ticks - 1) > 0xFFFFFF)
  24. {
  25. return 1;
  26. }
  27. _SYSTICK_LOAD = ticks - 1;
  28. _SYSTICK_PRI = 0xFF;
  29. _SYSTICK_VAL = 0;
  30. _SYSTICK_CTRL = 0x07;
  31. return 0;
  32. }
  33. #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
  34. #define RT_HEAP_SIZE 1024
  35. static uint32_t rt_heap[RT_HEAP_SIZE]; // heap default size: 4K(1024 * 4)
  36. RT_WEAK void *rt_heap_begin_get(void)
  37. {
  38. return rt_heap;
  39. }
  40. RT_WEAK void *rt_heap_end_get(void)
  41. {
  42. return rt_heap + RT_HEAP_SIZE;
  43. }
  44. #endif
  45. /* This function will initial your board. */
  46. void rt_hw_board_init()
  47. {
  48. /* System Clock Update */
  49. SystemCoreClockUpdate();
  50. /* System Tick Configuration */
  51. _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  52. /* Call components board initial (use INIT_BOARD_EXPORT()) */
  53. #ifdef RT_USING_COMPONENTS_INIT
  54. rt_components_board_init();
  55. #endif
  56. #ifdef RT_USING_CONSOLE
  57. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  58. #endif
  59. #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP)
  60. rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
  61. #endif
  62. }
  63. void SysTick_Handler(void)
  64. {
  65. /* enter interrupt */
  66. rt_interrupt_enter();
  67. rt_tick_increase();
  68. /* leave interrupt */
  69. rt_interrupt_leave();
  70. }