2021-01-28 19:59:31 +08:00
|
|
|
/*
|
2023-02-02 12:19:33 +08:00
|
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
2021-01-28 19:59:31 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
2021-01-28 22:22:57 +08:00
|
|
|
* Date Author Notes
|
|
|
|
* 2021-01-28 flybreak first version
|
2023-02-02 12:19:33 +08:00
|
|
|
* 2023-01-22 rose_man add RT_USING_SMP
|
2021-01-28 19:59:31 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rthw.h>
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "board.h"
|
|
|
|
#include "hardware/structs/systick.h"
|
2023-09-27 12:01:55 +08:00
|
|
|
#include "pico/bootrom.h"
|
2021-01-28 19:59:31 +08:00
|
|
|
|
2022-01-12 18:56:35 +08:00
|
|
|
#define PLL_SYS_KHZ (133 * 1000)
|
|
|
|
|
2021-01-28 19:59:31 +08:00
|
|
|
void isr_systick(void)
|
|
|
|
{
|
|
|
|
/* enter interrupt */
|
2023-02-02 12:19:33 +08:00
|
|
|
#ifndef RT_USING_SMP
|
2021-01-28 19:59:31 +08:00
|
|
|
rt_interrupt_enter();
|
2023-02-02 12:19:33 +08:00
|
|
|
#endif
|
2021-01-28 19:59:31 +08:00
|
|
|
|
|
|
|
rt_tick_increase();
|
|
|
|
|
|
|
|
/* leave interrupt */
|
2023-02-02 12:19:33 +08:00
|
|
|
#ifndef RT_USING_SMP
|
2021-01-28 19:59:31 +08:00
|
|
|
rt_interrupt_leave();
|
2023-02-02 12:19:33 +08:00
|
|
|
#endif
|
2021-01-28 19:59:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t systick_config(uint32_t ticks)
|
|
|
|
{
|
2023-09-27 12:01:55 +08:00
|
|
|
if ((ticks - 1UL) > M0PLUS_SYST_RVR_RELOAD_BITS)
|
|
|
|
{
|
|
|
|
return (1UL); /* Reload value impossible */
|
|
|
|
}
|
2021-01-28 19:59:31 +08:00
|
|
|
|
2023-09-28 08:46:43 +08:00
|
|
|
systick_hw->rvr = (uint32_t)(ticks - 1UL); /* set reload register */
|
|
|
|
systick_hw->csr = M0PLUS_SYST_CSR_CLKSOURCE_BITS |
|
2021-01-28 19:59:31 +08:00
|
|
|
M0PLUS_SYST_CSR_TICKINT_BITS |
|
|
|
|
M0PLUS_SYST_CSR_ENABLE_BITS; /* Enable SysTick IRQ and SysTick Timer */
|
2023-09-27 12:01:55 +08:00
|
|
|
return (0UL); /* Function successful */
|
2021-01-28 19:59:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rt_hw_board_init()
|
|
|
|
{
|
2022-01-12 18:56:35 +08:00
|
|
|
set_sys_clock_khz(PLL_SYS_KHZ, true);
|
|
|
|
|
2023-02-02 12:19:33 +08:00
|
|
|
#ifdef RT_USING_HEAP
|
2021-03-24 18:37:28 +08:00
|
|
|
rt_system_heap_init(HEAP_BEGIN, HEAP_END);
|
2023-02-02 12:19:33 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef RT_USING_SMP
|
|
|
|
extern rt_hw_spinlock_t _cpus_lock;
|
|
|
|
rt_hw_spin_lock_init(&_cpus_lock);
|
|
|
|
#endif
|
2021-03-24 18:02:11 +08:00
|
|
|
|
|
|
|
alarm_pool_init_default();
|
|
|
|
|
|
|
|
// Start and end points of the constructor list,
|
|
|
|
// defined by the linker script.
|
|
|
|
extern void (*__init_array_start)();
|
|
|
|
extern void (*__init_array_end)();
|
|
|
|
|
|
|
|
// Call each function in the list.
|
|
|
|
// We have to take the address of the symbols, as __init_array_start *is*
|
|
|
|
// the first function pointer, not the address of it.
|
2023-09-27 12:01:55 +08:00
|
|
|
for (void (**p)() = &__init_array_start; p < &__init_array_end; ++p)
|
|
|
|
{
|
2021-03-24 18:02:11 +08:00
|
|
|
(*p)();
|
|
|
|
}
|
|
|
|
|
2021-01-28 19:59:31 +08:00
|
|
|
/* Configure the SysTick */
|
2023-09-27 12:01:55 +08:00
|
|
|
systick_config(clock_get_hz(clk_sys) / RT_TICK_PER_SECOND);
|
2023-02-02 12:19:33 +08:00
|
|
|
|
|
|
|
#ifdef RT_USING_COMPONENTS_INIT
|
|
|
|
rt_components_board_init();
|
|
|
|
#endif
|
2021-01-28 19:59:31 +08:00
|
|
|
|
2023-02-02 12:19:33 +08:00
|
|
|
#ifdef RT_USING_SERIAL
|
2021-01-28 19:59:31 +08:00
|
|
|
stdio_init_all();
|
|
|
|
rt_hw_uart_init();
|
2023-02-02 12:19:33 +08:00
|
|
|
#endif
|
2021-01-28 19:59:31 +08:00
|
|
|
|
2022-01-12 18:56:35 +08:00
|
|
|
#ifdef RT_USING_CONSOLE
|
2023-09-27 12:01:55 +08:00
|
|
|
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
2021-01-28 19:59:31 +08:00
|
|
|
#endif
|
|
|
|
}
|
2023-09-27 12:01:55 +08:00
|
|
|
|
|
|
|
#ifdef RT_USING_MSH
|
|
|
|
static int pico_reboot(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
reset_usb_boot(0, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
MSH_CMD_EXPORT_ALIAS(pico_reboot, reboot, reset Pico to BOOTSEL mode);
|
|
|
|
#endif
|