board.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-01-28 flybreak first version
  9. * 2023-01-22 rose_man add RT_USING_SMP
  10. */
  11. #include <rthw.h>
  12. #include <rtthread.h>
  13. #include <stdio.h>
  14. #include "board.h"
  15. #include "hardware/structs/systick.h"
  16. #define PLL_SYS_KHZ (133 * 1000)
  17. void isr_systick(void)
  18. {
  19. /* enter interrupt */
  20. #ifndef RT_USING_SMP
  21. rt_interrupt_enter();
  22. #endif
  23. rt_tick_increase();
  24. /* leave interrupt */
  25. #ifndef RT_USING_SMP
  26. rt_interrupt_leave();
  27. #endif
  28. }
  29. uint32_t systick_config(uint32_t ticks)
  30. {
  31. if ((ticks - 1UL) > M0PLUS_SYST_RVR_RELOAD_BITS)
  32. {
  33. return (1UL); /* Reload value impossible */
  34. }
  35. mpu_hw->rvr = (uint32_t)(ticks - 1UL); /* set reload register */
  36. mpu_hw->csr = M0PLUS_SYST_CSR_CLKSOURCE_BITS |
  37. M0PLUS_SYST_CSR_TICKINT_BITS |
  38. M0PLUS_SYST_CSR_ENABLE_BITS; /* Enable SysTick IRQ and SysTick Timer */
  39. return (0UL); /* Function successful */
  40. }
  41. void rt_hw_board_init()
  42. {
  43. set_sys_clock_khz(PLL_SYS_KHZ, true);
  44. #ifdef RT_USING_HEAP
  45. rt_system_heap_init(HEAP_BEGIN, HEAP_END);
  46. #endif
  47. #ifdef RT_USING_SMP
  48. extern rt_hw_spinlock_t _cpus_lock;
  49. rt_hw_spin_lock_init(&_cpus_lock);
  50. #endif
  51. alarm_pool_init_default();
  52. // Start and end points of the constructor list,
  53. // defined by the linker script.
  54. extern void (*__init_array_start)();
  55. extern void (*__init_array_end)();
  56. // Call each function in the list.
  57. // We have to take the address of the symbols, as __init_array_start *is*
  58. // the first function pointer, not the address of it.
  59. for (void (**p)() = &__init_array_start; p < &__init_array_end; ++p) {
  60. (*p)();
  61. }
  62. /* Configure the SysTick */
  63. systick_config(frequency_count_khz(CLOCKS_FC0_SRC_VALUE_ROSC_CLKSRC)*10000/RT_TICK_PER_SECOND);
  64. #ifdef RT_USING_COMPONENTS_INIT
  65. rt_components_board_init();
  66. #endif
  67. #ifdef RT_USING_SERIAL
  68. stdio_init_all();
  69. rt_hw_uart_init();
  70. #endif
  71. #ifdef RT_USING_CONSOLE
  72. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  73. #endif
  74. }