2021-02-06 07:36:26 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006-2020, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
2021-02-11 16:18:33 +08:00
|
|
|
* 2021-02-11 supperthomas first version
|
2021-02-06 07:36:26 +08:00
|
|
|
*
|
|
|
|
*/
|
2021-02-11 16:18:33 +08:00
|
|
|
|
2021-02-06 07:36:26 +08:00
|
|
|
#include <rtthread.h>
|
|
|
|
#include <rthw.h>
|
2021-02-11 04:45:50 +08:00
|
|
|
#include <stdio.h>
|
2021-02-06 07:36:26 +08:00
|
|
|
#include "board.h"
|
2021-02-11 04:45:50 +08:00
|
|
|
#include "mxc_sys.h"
|
|
|
|
#ifdef RT_USING_SERIAL
|
|
|
|
#include "drv_usart.h"
|
|
|
|
#endif
|
2021-02-06 07:36:26 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the timer interrupt service routine.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void SysTick_Handler(void)
|
|
|
|
{
|
|
|
|
/* enter interrupt */
|
|
|
|
rt_interrupt_enter();
|
|
|
|
|
|
|
|
rt_tick_increase();
|
|
|
|
|
|
|
|
/* leave interrupt */
|
|
|
|
rt_interrupt_leave();
|
|
|
|
}
|
|
|
|
|
2021-02-11 10:57:00 +08:00
|
|
|
void rt_hw_systick_init(void)
|
2021-02-06 07:36:26 +08:00
|
|
|
{
|
2021-02-11 04:45:50 +08:00
|
|
|
uint32_t error;
|
2021-02-11 10:57:00 +08:00
|
|
|
error = SYS_SysTick_Config(SYS_SysTick_GetFreq() / RT_TICK_PER_SECOND, 1, MXC_TMR0);
|
2021-02-06 07:36:26 +08:00
|
|
|
|
2021-02-11 10:57:00 +08:00
|
|
|
if (error != E_NO_ERROR)
|
|
|
|
{
|
2021-02-26 23:24:30 +08:00
|
|
|
rt_kprintf("ERROR: Ticks is not valid");
|
2021-02-11 04:45:50 +08:00
|
|
|
}
|
2021-02-06 07:36:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rt_hw_board_init(void)
|
|
|
|
{
|
|
|
|
|
2021-02-11 10:57:00 +08:00
|
|
|
rt_hw_systick_init();
|
2021-02-06 07:36:26 +08:00
|
|
|
|
|
|
|
#if defined(RT_USING_HEAP)
|
2021-02-11 10:57:00 +08:00
|
|
|
rt_system_heap_init((void *)(HEAP_BEGIN), (void *)(HEAP_END));
|
2021-02-06 07:36:26 +08:00
|
|
|
#endif
|
2021-02-11 10:57:00 +08:00
|
|
|
|
2021-02-06 07:36:26 +08:00
|
|
|
#ifdef RT_USING_SERIAL
|
2021-02-11 04:45:50 +08:00
|
|
|
rt_hw_usart_init();
|
2021-02-06 07:36:26 +08:00
|
|
|
#endif
|
2021-02-11 10:57:00 +08:00
|
|
|
|
2022-01-08 23:29:41 +08:00
|
|
|
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
|
2021-02-06 07:36:26 +08:00
|
|
|
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
|
|
|
#endif
|
2021-02-11 10:57:00 +08:00
|
|
|
|
2021-02-06 07:36:26 +08:00
|
|
|
#ifdef RT_USING_COMPONENTS_INIT
|
|
|
|
rt_components_board_init();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-03-06 22:09:19 +08:00
|
|
|
void rt_hw_us_delay(rt_uint32_t us)
|
|
|
|
{
|
|
|
|
rt_uint32_t start, now, delta, reload, us_tick;
|
|
|
|
start = SysTick->VAL;
|
|
|
|
reload = SysTick->LOAD;
|
|
|
|
us_tick = SystemCoreClock / 1000000UL;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
now = SysTick->VAL;
|
|
|
|
delta = start >= now ? start - now : reload + start - now;
|
|
|
|
}
|
|
|
|
while (delta < us_tick * us);
|
|
|
|
}
|