board.c 2.5 KB

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