diff options
Diffstat (limited to 'src/fsm/common.c')
-rw-r--r-- | src/fsm/common.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/fsm/common.c b/src/fsm/common.c index ca4c009..517eb80 100644 --- a/src/fsm/common.c +++ b/src/fsm/common.c @@ -26,6 +26,7 @@ #include "FreeRTOS.h" #include "timers.h" #include <stm32f4xx.h> +#include <time.h> static uint64_t common_timestamp = 0; // milliseconds since startup static TimerHandle_t common_timer; @@ -60,6 +61,22 @@ uint64_t timestamp_now(void) return common_timestamp; } +int dayofweek(uint8_t day, uint8_t month, uint16_t year) +{ + /* Zeller's congruence for the Gregorian calendar. + * With 0=Monday, ... 5=Saturday, 6=Sunday + */ + if (month < 3) { + month += 12; + year--; + } + int k = year % 100; + int j = year / 100; + int h = day + 13*(month+1)/5 + k + k/4 + j/4 + 5*j; + return (h + 5) % 7 + 1; +} + + // Return either 0 or 1, somewhat randomly int random_bool(void) { |