board.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #include "pico/bootrom.h"
  17. #define PLL_SYS_KHZ (133 * 1000)
  18. void isr_systick(void)
  19. {
  20. /* enter interrupt */
  21. #ifndef RT_USING_SMP
  22. rt_interrupt_enter();
  23. #endif
  24. rt_tick_increase();
  25. /* leave interrupt */
  26. #ifndef RT_USING_SMP
  27. rt_interrupt_leave();
  28. #endif
  29. }
  30. uint32_t systick_config(uint32_t ticks)
  31. {
  32. if ((ticks - 1UL) > M0PLUS_SYST_RVR_RELOAD_BITS)
  33. {
  34. return (1UL); /* Reload value impossible */
  35. }
  36. systick_hw->rvr = (uint32_t)(ticks - 1UL); /* set reload register */
  37. systick_hw->csr = M0PLUS_SYST_CSR_CLKSOURCE_BITS |
  38. M0PLUS_SYST_CSR_TICKINT_BITS |
  39. M0PLUS_SYST_CSR_ENABLE_BITS; /* Enable SysTick IRQ and SysTick Timer */
  40. return (0UL); /* Function successful */
  41. }
  42. void rt_hw_board_init()
  43. {
  44. set_sys_clock_khz(PLL_SYS_KHZ, true);
  45. #ifdef RT_USING_HEAP
  46. rt_system_heap_init(HEAP_BEGIN, HEAP_END);
  47. #endif
  48. #ifdef RT_USING_SMP
  49. extern rt_hw_spinlock_t _cpus_lock;
  50. rt_hw_spin_lock_init(&_cpus_lock);
  51. #endif
  52. alarm_pool_init_default();
  53. // Start and end points of the constructor list,
  54. // defined by the linker script.
  55. extern void (*__init_array_start)();
  56. extern void (*__init_array_end)();
  57. // Call each function in the list.
  58. // We have to take the address of the symbols, as __init_array_start *is*
  59. // the first function pointer, not the address of it.
  60. for (void (**p)() = &__init_array_start; p < &__init_array_end; ++p)
  61. {
  62. (*p)();
  63. }
  64. /* Configure the SysTick */
  65. systick_config(clock_get_hz(clk_sys) / RT_TICK_PER_SECOND);
  66. #ifdef RT_USING_COMPONENTS_INIT
  67. rt_components_board_init();
  68. #endif
  69. #ifdef RT_USING_SERIAL
  70. stdio_init_all();
  71. rt_hw_uart_init();
  72. #endif
  73. #ifdef RT_USING_CONSOLE
  74. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  75. #endif
  76. }
  77. #ifdef RT_USING_MSH
  78. static int pico_reboot(int argc, char *argv[])
  79. {
  80. reset_usb_boot(0, 0);
  81. return 0;
  82. }
  83. MSH_CMD_EXPORT_ALIAS(pico_reboot, reboot, reset Pico to BOOTSEL mode);
  84. #endif