2021-09-09 20:31:17 +08:00
|
|
|
/*
|
2023-02-11 08:14:33 +08:00
|
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
2021-09-09 20:31:17 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2021-08-20 breo.com first version
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "drv_common.h"
|
|
|
|
#include "board.h"
|
|
|
|
|
|
|
|
#ifdef RT_USING_SERIAL
|
2021-11-02 17:09:53 +08:00
|
|
|
#ifdef RT_USING_SERIAL_V2
|
|
|
|
#include "drv_usart_v2.h"
|
|
|
|
#else
|
|
|
|
#include "drv_usart.h"
|
|
|
|
#endif
|
2021-09-09 20:31:17 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef RT_USING_FINSH
|
|
|
|
#include <finsh.h>
|
|
|
|
static void reboot(uint8_t argc, char **argv)
|
|
|
|
{
|
|
|
|
rt_hw_cpu_reset();
|
|
|
|
}
|
2021-10-12 14:35:01 +08:00
|
|
|
MSH_CMD_EXPORT(reboot, Reboot System);
|
2021-09-09 20:31:17 +08:00
|
|
|
#endif /* RT_USING_FINSH */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will delay for some us.
|
|
|
|
*
|
|
|
|
* @param us the delay time of us
|
|
|
|
*/
|
|
|
|
void rt_hw_us_delay(rt_uint32_t us)
|
|
|
|
{
|
|
|
|
rt_uint32_t ticks;
|
|
|
|
rt_uint32_t told, tnow, tcnt = 0;
|
|
|
|
rt_uint32_t reload = SysTick->LOAD;
|
|
|
|
|
|
|
|
ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
|
|
|
|
told = SysTick->VAL;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
tnow = SysTick->VAL;
|
|
|
|
if (tnow != told)
|
|
|
|
{
|
|
|
|
if (tnow < told)
|
|
|
|
{
|
|
|
|
tcnt += told - tnow;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tcnt += reload - tnow + told;
|
|
|
|
}
|
|
|
|
told = tnow;
|
|
|
|
if (tcnt >= ticks)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|