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.
This commit is contained in:
Uwe Bonnes 2021-07-25 23:48:35 +02:00 committed by UweBonnes
parent 0c63903071
commit 6d6a67b44b
5 changed files with 23 additions and 10 deletions

View File

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

View File

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

View File

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

View File

@ -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)
{
time_ms += SYSTICKMS;
if (morse_tick >= MORSECNT) {
if(running_status)
gpio_toggle(LED_PORT, LED_IDLE_RUN);
time_ms += 100;
SET_ERROR_STATE(morse_update());
morse_tick = 0;
} else {
morse_tick++;
}
}
uint32_t platform_time_ms(void)

View File

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