2022-03-23 11:03:48 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2022-03-02 FMD-AE first version
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "board.h"
|
|
|
|
|
|
|
|
#ifdef RT_USING_SERIAL
|
|
|
|
#include "drv_usart.h"
|
|
|
|
#endif /* RT_USING_SERIAL */
|
|
|
|
|
|
|
|
#define DBG_TAG "drv_common"
|
|
|
|
#define DBG_LVL DBG_INFO
|
|
|
|
#include <rtdbg.h>
|
|
|
|
|
|
|
|
#ifdef RT_USING_FINSH
|
|
|
|
#include <finsh.h>
|
|
|
|
|
|
|
|
static void reboot(uint8_t argc, char **argv)
|
|
|
|
{
|
|
|
|
rt_hw_cpu_reset();
|
|
|
|
}
|
|
|
|
MSH_CMD_EXPORT(reboot, Reboot System);
|
|
|
|
#endif /* RT_USING_FINSH */
|
|
|
|
|
|
|
|
__IO uint32_t uwTick;
|
|
|
|
static uint32_t _systick_ms = 1;
|
|
|
|
|
|
|
|
void IncTick(void)
|
|
|
|
{
|
|
|
|
uwTick += _systick_ms;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* This is the timer interrupt service routine.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void SysTick_Handler(void)
|
|
|
|
{
|
|
|
|
/* enter interrupt */
|
|
|
|
rt_interrupt_enter();
|
|
|
|
|
|
|
|
if (SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk)
|
|
|
|
IncTick();
|
|
|
|
|
|
|
|
rt_tick_increase();
|
|
|
|
|
|
|
|
/* leave interrupt */
|
|
|
|
rt_interrupt_leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t GetTick(void)
|
|
|
|
{
|
|
|
|
if (SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk)
|
|
|
|
IncTick();
|
|
|
|
|
|
|
|
return uwTick;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuspendTick(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResumeTick(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Delay(__IO uint32_t Delay)
|
|
|
|
{
|
|
|
|
if (rt_thread_self())
|
|
|
|
{
|
|
|
|
rt_thread_mdelay(Delay);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (rt_uint32_t count = 0; count < Delay; count++)
|
|
|
|
{
|
|
|
|
rt_hw_us_delay(1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will initial FT32 board.
|
|
|
|
*/
|
2022-12-12 02:12:03 +08:00
|
|
|
rt_weak void rt_hw_board_init()
|
2022-03-23 11:03:48 +08:00
|
|
|
{
|
|
|
|
SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
|
|
|
|
/* Heap initialization */
|
|
|
|
#if defined(RT_USING_HEAP)
|
|
|
|
rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Pin driver initialization is open by default */
|
|
|
|
#ifdef RT_USING_PIN
|
|
|
|
rt_hw_pin_init();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* USART driver initialization is open by default */
|
|
|
|
#ifdef RT_USING_SERIAL
|
|
|
|
rt_hw_usart_init();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Set the shell console output device */
|
|
|
|
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
|
|
|
|
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Board underlying hardware initialization */
|
|
|
|
#ifdef RT_USING_COMPONENTS_INIT
|
|
|
|
rt_components_board_init();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|