Browse Source

timeout: Make sure we wait at least the period requested (#900, #902)

Fixes bug introduced with last commit( Recover from bad AP access)

Let STM32 timers run at 100 Hz against 10 Hz before.

Programming STM32F103 failed random (#900) with 20 ms timeout requested
against the 100 ms timeout granularity provided up to now.

STM32 Firmware only ticked at 10 hertz, so the sequence "low_access",
"set timeout", "send out 8 bit command", "read 3 bit result" when
reading "wait" and timer increment tick happening during that sequence
will already hits the timeout even so only mininal time has elapsed
and not the requested timeout.
pull/905/head
Uwe Bonnes 3 years ago
committed by UweBonnes
parent
commit
6d6a67b44b
  1. 6
      src/include/general.h
  2. 2
      src/platforms/hosted/platform.h
  3. 3
      src/platforms/launchpad-icdi/platform.c
  4. 18
      src/platforms/stm32/timing_stm32.c
  5. 4
      src/timing.c

6
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

2
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

3
src/platforms/launchpad-icdi/platform.c

@ -25,9 +25,6 @@
#include <libopencm3/cm3/systick.h>
#include <libopencm3/lm4f/usb.h>
#define SYSTICKHZ 100
#define SYSTICKMS (1000 / SYSTICKHZ)
#define PLL_DIV_80MHZ 5
#define PLL_DIV_25MHZ 16

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

4
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;
}

Loading…
Cancel
Save