Browse Source

[imxrt 1170]Support us delay (#6424)

* add us delay

* formating file
xiao xie 2 years ago
parent
commit
52e1d76254

+ 0 - 4
bsp/imxrt/imxrt1170-nxp-evk/board/board.c

@@ -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();

+ 2 - 1
bsp/imxrt/libraries/drivers/SConscript

@@ -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)

+ 42 - 0
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;
+            }
+        }
+    }
+}