[imxrt 1170]Support us delay (#6424)

* add us delay

* formating file
This commit is contained in:
xiao xie 2022-09-13 19:53:30 +08:00 committed by GitHub
parent 8d0392e344
commit 52e1d76254
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 5 deletions

View File

@ -1273,10 +1273,6 @@ void imxrt_can_pins_init(void)
} }
#endif #endif
void rt_hw_us_delay(rt_uint32_t us)
{
}
void rt_hw_board_init() void rt_hw_board_init()
{ {
BOARD_ConfigMPU(); BOARD_ConfigMPU();

View File

@ -76,7 +76,8 @@ if GetDepend('RT_USING_USB_HOST'):
if GetDepend('BSP_USING_PULSE_ENCODER'): if GetDepend('BSP_USING_PULSE_ENCODER'):
src += ['drv_pulse_encoder.c'] src += ['drv_pulse_encoder.c']
src += ['drv_common.c']
path = [cwd] path = [cwd]
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path, CPPDEFINES=CPPDEFINES) group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path, CPPDEFINES=CPPDEFINES)

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-09-13 xjy198903 first implementation
*/
#include <rtthread.h>
#include "clock_config.h"
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;
}
}
}
}