application: allow multiple ticks per seconds for periodic tasks
This commit is contained in:
parent
31997c2c4a
commit
f54d3f0fd2
|
@ -48,11 +48,22 @@
|
|||
#include "terminal.h" // handle the terminal interface
|
||||
#include "menu.h" // menu utilities
|
||||
|
||||
#define WATCHDOG_PERIOD 10000 /**< watchdog period in ms */
|
||||
/** watchdog period in ms */
|
||||
#define WATCHDOG_PERIOD 10000
|
||||
|
||||
/** set to 0 if the RTC is reset when the board is powered on, only indicates the uptime
|
||||
* set to 1 if VBAT can keep the RTC running when the board is unpowered, indicating the date and time
|
||||
*/
|
||||
#if defined(CORE_BOARD)
|
||||
#define RTC_DATE_TIME 1
|
||||
#else
|
||||
#define RTC_DATE_TIME 0
|
||||
#endif
|
||||
|
||||
/** number of RTC ticks per second
|
||||
* @note use integer divider of oscillator to keep second precision
|
||||
*/
|
||||
#define RTC_TICKS_SECOND 4
|
||||
|
||||
/** RTC time when device is started */
|
||||
static time_t time_start = 0;
|
||||
|
@ -374,9 +385,9 @@ void main(void)
|
|||
printf("setup internal RTC: ");
|
||||
#if defined(BLUE_PILL) || defined(STLINKV2) || defined(BLASTER) // for boards without a Low Speed External oscillator
|
||||
// note: the blue pill LSE oscillator is affected when toggling the onboard LED, thus prefer the HSE
|
||||
rtc_auto_awake(RCC_HSE, 8000000 / 128 - 1); // use High Speed External oscillator (8 MHz / 128) as RTC clock (VBAT can't be used to keep the RTC running)
|
||||
rtc_auto_awake(RCC_HSE, 8000000 / 128 / RTC_TICKS_SECOND - 1); // use High Speed External oscillator (8 MHz / 128) as RTC clock (VBAT can't be used to keep the RTC running)
|
||||
#else // for boards with an precise Low Speed External oscillator
|
||||
rtc_auto_awake(RCC_LSE, 32768 - 1); // ensure internal RTC is on, uses the 32.678 kHz LSE, and the prescale is set to our tick speed, else update backup registers accordingly (power off the micro-controller for the change to take effect)
|
||||
rtc_auto_awake(RCC_LSE, 32768 / RTC_TICKS_SECOND - 1); // ensure internal RTC is on, uses the 32.678 kHz LSE, and the prescale is set to our tick speed, else update backup registers accordingly (power off the micro-controller for the change to take effect)
|
||||
#endif
|
||||
rtc_interrupt_enable(RTC_SEC); // enable RTC interrupt on "seconds"
|
||||
nvic_enable_irq(NVIC_RTC_IRQ); // allow the RTC to interrupt
|
||||
|
@ -411,7 +422,9 @@ void main(void)
|
|||
if (rtc_internal_tick_flag) { // the internal RTC ticked
|
||||
rtc_internal_tick_flag = false; // reset flag
|
||||
action = true; // action has been performed
|
||||
led_toggle(); // toggle LED (good to indicate if main function is stuck)
|
||||
if (0 == (rtc_get_counter_val() % RTC_TICKS_SECOND)) { // one seond has passed
|
||||
led_toggle(); // toggle LED (good to indicate if main function is stuck)
|
||||
}
|
||||
}
|
||||
if (action) { // go to sleep if nothing had to be done, else recheck for activity
|
||||
action = false;
|
||||
|
|
Loading…
Reference in New Issue