2020-01-27 12:57 PM
2020-01-27 01:05 PM
Count in SysTick_Handler, perhaps have a simple dispatch engine?
static unsigned count = 0;
count++;
if (count == 40)
{
count = 0;
flag |= 1;
}
2020-01-27 02:43 PM
Generally this is a job for software timers. Typical RTOS has those integrated, but what astounds me, is the fact, that in a 21st century one still can't find a quality, flexible, small and simple open source C software timer libraries, which can be used with bare metal and cooperative schedulers. Google returns plenty of results, especially for Arduino, but all that I've seen are pretty badly designed and/or implemented. :(
As an example: https://electronics.stackexchange.com/questions/96537/deferred-callback-manager-software-timer-library-for-pic32
2020-01-27 05:34 PM
A brainless variant, for the <pick your own expletive> ST "HAL" library:
/* This overrides HAL_IncTick somewhere in the library */
extern volatile uint32_t uwTick;
extern HAL_TickFreqTypeDef uwTickFreq; /* time increment per tick, 1 = 1KHz */
volatile int the_flag = 0;
static uint8_t count_to_40 = 0;
void HAL_IncTick(void)
{
if (++count_to_40 == 40) {
the_flag = 1;
count_to_40 = 0; // reset?
}
// Increment the HAL counter, like the default HAL_IncTick()
// Assume uwTickFreq is 1 (1 ms/tick)
uwTick += 1U;
}