diff --git a/src/include/general.h b/src/include/general.h index ba329d21..25f83a4b 100644 --- a/src/include/general.h +++ b/src/include/general.h @@ -164,5 +164,11 @@ static inline void DEBUG_WIRE(const char *format, ...) #undef MAX #define MAX(x, y) (((x) > (y)) ? (x) : (y)) +#if !defined(SYSTICKHZ) +# define SYSTICKHZ 100 +#endif +#define SYSTICKMS (1000 / SYSTICKHZ) +#define MORSECNT ((SYSTICKHZ / 10) - 1) + #endif diff --git a/src/platforms/hosted/platform.h b/src/platforms/hosted/platform.h index bf3fa141..339fec85 100644 --- a/src/platforms/hosted/platform.h +++ b/src/platforms/hosted/platform.h @@ -10,6 +10,8 @@ void platform_buffer_flush(void); #define SET_IDLE_STATE(x) #define SET_RUN_STATE(x) +#define SYSTICKHZ 1000 + #define VENDOR_ID_BMP 0x1d50 #define PRODUCT_ID_BMP_BL 0x6017 #define PRODUCT_ID_BMP 0x6018 diff --git a/src/platforms/launchpad-icdi/platform.c b/src/platforms/launchpad-icdi/platform.c index d62a8cda..83189192 100644 --- a/src/platforms/launchpad-icdi/platform.c +++ b/src/platforms/launchpad-icdi/platform.c @@ -25,9 +25,6 @@ #include #include -#define SYSTICKHZ 100 -#define SYSTICKMS (1000 / SYSTICKHZ) - #define PLL_DIV_80MHZ 5 #define PLL_DIV_25MHZ 16 diff --git a/src/platforms/stm32/timing_stm32.c b/src/platforms/stm32/timing_stm32.c index dbf5cc3a..9f9c6984 100644 --- a/src/platforms/stm32/timing_stm32.c +++ b/src/platforms/stm32/timing_stm32.c @@ -27,12 +27,14 @@ uint8_t running_status; static volatile uint32_t time_ms; uint32_t swd_delay_cnt = 0; +static int morse_tick; + void platform_timing_init(void) { /* Setup heartbeat timer */ systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); /* Interrupt us at 10 Hz */ - systick_set_reload(rcc_ahb_frequency / (8 * 10) ); + systick_set_reload(rcc_ahb_frequency / (8 * SYSTICKHZ) ); /* SYSTICK_IRQ with low priority */ nvic_set_priority(NVIC_SYSTICK_IRQ, 14 << 4); systick_interrupt_enable(); @@ -48,12 +50,16 @@ void platform_delay(uint32_t ms) void sys_tick_handler(void) { - if(running_status) - gpio_toggle(LED_PORT, LED_IDLE_RUN); - - time_ms += 100; + time_ms += SYSTICKMS; - SET_ERROR_STATE(morse_update()); + if (morse_tick >= MORSECNT) { + if(running_status) + gpio_toggle(LED_PORT, LED_IDLE_RUN); + SET_ERROR_STATE(morse_update()); + morse_tick = 0; + } else { + morse_tick++; + } } uint32_t platform_time_ms(void) diff --git a/src/timing.c b/src/timing.c index 1717bf5a..6c9a6da9 100644 --- a/src/timing.c +++ b/src/timing.c @@ -21,10 +21,12 @@ void platform_timeout_set(platform_timeout *t, uint32_t ms) { + if (ms <= SYSTICKMS) + ms = SYSTICKMS; t->time = platform_time_ms() + ms; } bool platform_timeout_is_expired(platform_timeout *t) { - return platform_time_ms() >= t->time; + return platform_time_ms() > t->time; }