diff options
| author | xiao xie <[email protected]> | 2022-09-13 19:53:30 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-09-13 07:53:30 -0400 |
| commit | 52e1d76254dc3ae7f5ebc1e4c1ca21586cd4ce76 (patch) | |
| tree | 6e14f55132dc48f245f7d65496e6e8415cdc5dec | |
| parent | 8d0392e34423e2e498e0c54d568987b6b9d385ac (diff) | |
[imxrt 1170]Support us delay (#6424)
* add us delay
* formating file
| -rw-r--r-- | bsp/imxrt/imxrt1170-nxp-evk/board/board.c | 4 | ||||
| -rw-r--r-- | bsp/imxrt/libraries/drivers/SConscript | 3 | ||||
| -rw-r--r-- | bsp/imxrt/libraries/drivers/drv_common.c | 42 |
3 files changed, 44 insertions, 5 deletions
diff --git a/bsp/imxrt/imxrt1170-nxp-evk/board/board.c b/bsp/imxrt/imxrt1170-nxp-evk/board/board.c index 7bfc5f832f..66e5d4fc90 100644 --- a/bsp/imxrt/imxrt1170-nxp-evk/board/board.c +++ b/bsp/imxrt/imxrt1170-nxp-evk/board/board.c @@ -1273,10 +1273,6 @@ void imxrt_can_pins_init(void) } #endif -void rt_hw_us_delay(rt_uint32_t us) -{ -} - void rt_hw_board_init() { BOARD_ConfigMPU(); diff --git a/bsp/imxrt/libraries/drivers/SConscript b/bsp/imxrt/libraries/drivers/SConscript index cb4be65b6a..ab3534b4a3 100644 --- a/bsp/imxrt/libraries/drivers/SConscript +++ b/bsp/imxrt/libraries/drivers/SConscript @@ -76,7 +76,8 @@ if GetDepend('RT_USING_USB_HOST'): if GetDepend('BSP_USING_PULSE_ENCODER'): src += ['drv_pulse_encoder.c'] - + +src += ['drv_common.c'] path = [cwd] group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path, CPPDEFINES=CPPDEFINES) diff --git a/bsp/imxrt/libraries/drivers/drv_common.c b/bsp/imxrt/libraries/drivers/drv_common.c new file mode 100644 index 0000000000..c86c55c9ac --- /dev/null +++ b/bsp/imxrt/libraries/drivers/drv_common.c @@ -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; + } + } + } +} |
