aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/generic/armcm_timer.c14
-rw-r--r--src/generic/armcm_timer.h8
-rw-r--r--src/lpc176x/internal.h2
-rw-r--r--src/lpc176x/main.c14
-rw-r--r--src/lpc176x/usbserial.c1
-rw-r--r--src/stm32f0/internal.h1
-rw-r--r--src/stm32f0/main.c9
-rw-r--r--src/stm32f1/internal.h2
-rw-r--r--src/stm32f1/main.c14
-rw-r--r--src/stm32f1/usbserial.c1
10 files changed, 24 insertions, 42 deletions
diff --git a/src/generic/armcm_timer.c b/src/generic/armcm_timer.c
index a9c8ab9f..7f11cd68 100644
--- a/src/generic/armcm_timer.c
+++ b/src/generic/armcm_timer.c
@@ -54,6 +54,20 @@ timer_kick(void)
SCB->ICSR = SCB_ICSR_PENDSTSET_Msk;
}
+// Implement simple early-boot delay mechanism
+void
+udelay(uint32_t usecs)
+{
+ if (!(CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk)) {
+ CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
+ DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
+ }
+
+ uint32_t end = timer_read_time() + timer_from_us(usecs);
+ while (timer_is_before(timer_read_time(), end))
+ ;
+}
+
void
timer_init(void)
{
diff --git a/src/generic/armcm_timer.h b/src/generic/armcm_timer.h
new file mode 100644
index 00000000..5e118380
--- /dev/null
+++ b/src/generic/armcm_timer.h
@@ -0,0 +1,8 @@
+#ifndef __GENERIC_ARMCM_TIMER_H
+#define __GENERIC_ARMCM_TIMER_H
+
+#include <stdint.h> // uint32_t
+
+void udelay(uint32_t usecs);
+
+#endif // serial_irq.h
diff --git a/src/lpc176x/internal.h b/src/lpc176x/internal.h
index 985c30df..5dcf99a4 100644
--- a/src/lpc176x/internal.h
+++ b/src/lpc176x/internal.h
@@ -18,6 +18,4 @@ int is_enabled_pclock(uint32_t pclk);
void enable_pclock(uint32_t pclk);
void gpio_peripheral(uint32_t gpio, int func, int pullup);
-void udelay(uint32_t usecs);
-
#endif // internal.h
diff --git a/src/lpc176x/main.c b/src/lpc176x/main.c
index c417a2c7..d522a014 100644
--- a/src/lpc176x/main.c
+++ b/src/lpc176x/main.c
@@ -67,20 +67,6 @@ command_reset(uint32_t *args)
}
DECL_COMMAND_FLAGS(command_reset, HF_IN_SHUTDOWN, "reset");
-// Implement simple early-boot delay mechanism
-void
-udelay(uint32_t usecs)
-{
- if (!(CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk)) {
- CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
- DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
- }
-
- uint32_t end = timer_read_time() + timer_from_us(usecs);
- while (timer_is_before(timer_read_time(), end))
- ;
-}
-
// Main entry point
int
main(void)
diff --git a/src/lpc176x/usbserial.c b/src/lpc176x/usbserial.c
index 0d91d28a..b6779ed1 100644
--- a/src/lpc176x/usbserial.c
+++ b/src/lpc176x/usbserial.c
@@ -7,6 +7,7 @@
#include <string.h> // memcpy
#include "LPC17xx.h" // LPC_SC
#include "autoconf.h" // CONFIG_SMOOTHIEWARE_BOOTLOADER
+#include "board/armcm_timer.h" // udelay
#include "board/irq.h" // irq_disable
#include "board/misc.h" // timer_read_time
#include "byteorder.h" // cpu_to_le32
diff --git a/src/stm32f0/internal.h b/src/stm32f0/internal.h
index 5247a9c7..35c3000f 100644
--- a/src/stm32f0/internal.h
+++ b/src/stm32f0/internal.h
@@ -9,7 +9,6 @@
extern uint8_t const avail_pins[];
-void udelay(uint32_t usecs);
void gpio_init(void);
void TimerInit(void);
diff --git a/src/stm32f0/main.c b/src/stm32f0/main.c
index 89d8a6e5..1a167a32 100644
--- a/src/stm32f0/main.c
+++ b/src/stm32f0/main.c
@@ -84,15 +84,6 @@ void clock_config(void)
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
}
-// Implement simple early-boot delay mechanism
-void
-udelay(uint32_t usecs)
-{
- uint32_t end = timer_read_time() + timer_from_us(usecs);
- while (timer_is_before(timer_read_time(), end))
- ;
-}
-
void
watchdog_reset(void)
{
diff --git a/src/stm32f1/internal.h b/src/stm32f1/internal.h
index e509927b..4c4394fd 100644
--- a/src/stm32f1/internal.h
+++ b/src/stm32f1/internal.h
@@ -10,6 +10,4 @@
extern GPIO_TypeDef *const digital_regs[];
extern uint32_t const digital_pins[];
-void udelay(uint32_t usecs);
-
#endif // internal.h
diff --git a/src/stm32f1/main.c b/src/stm32f1/main.c
index 258578da..d9bdbb24 100644
--- a/src/stm32f1/main.c
+++ b/src/stm32f1/main.c
@@ -131,20 +131,6 @@ void io_config(void)
LL_DBGMCU_SetTracePinAssignment(LL_DBGMCU_TRACE_NONE);
}
-// Implement simple early-boot delay mechanism
-void
-udelay(uint32_t usecs)
-{
- if (!(CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk)) {
- CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
- DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
- }
-
- uint32_t end = timer_read_time() + timer_from_us(usecs);
- while (timer_is_before(timer_read_time(), end))
- ;
-}
-
// Main entry point
int
main(void)
diff --git a/src/stm32f1/usbserial.c b/src/stm32f1/usbserial.c
index 7eeb3421..3bdf86a8 100644
--- a/src/stm32f1/usbserial.c
+++ b/src/stm32f1/usbserial.c
@@ -6,6 +6,7 @@
#include <string.h> // NULL
#include "autoconf.h" // CONFIG_STM_FLASH_START_2000
+#include "board/armcm_timer.h" // udelay
#include "board/gpio.h" // gpio_out_setup
#include "board/io.h" // writeb
#include "board/irq.h" // irq_disable