Host C Specs


Directory: src/c/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 21 / 0 / 21
Functions: 100.0% 4 / 0 / 4
Branches: 100.0% 8 / 0 / 8

core/clock/time_config.c
Line Branch Exec Source
1 /**
2 * @file time_config.c
3 * @brief What a time store reconfigure runs, and the check for whether two sets of its rules run
4 * the same tickers.
5 *
6 * @ingroup lib_core
7 */
8 #include "clock/time_config.h"
9
10 #include <stdint.h>
11
12 #include "io/store_live.h"
13
14 #define TICKER_MINUTE 0x1 ///< The minute tick
15 #define TICKER_HOUR 0x2 ///< The hour tick, run only with the minute tick off
16 #define TICKER_BEATS 0x4 ///< The .beats timer
17
18 /**
19 * @brief The tickers a set of rules runs, one bit each, in the same order the store starts them.
20 *
21 * @param cfg The rules.
22 * @return The tickers, or 0 when none runs.
23 */
24 24 static uint8_t tickers(TimeConfig cfg)
25 {
26
2/2
✓ Branch 2 → 3 taken 9 times.
✓ Branch 2 → 4 taken 15 times.
24 if (!cfg.live)
27 {
28 9 return 0;
29 }
30
31 15 uint8_t running = 0;
32
2/2
✓ Branch 4 → 5 taken 12 times.
✓ Branch 4 → 6 taken 3 times.
15 if (cfg.minute_tick)
33 {
34 12 running |= TICKER_MINUTE;
35 }
36
2/2
✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 8 taken 2 times.
3 else if (cfg.hourly)
37 {
38 1 running |= TICKER_HOUR;
39 }
40
41
2/2
✓ Branch 8 → 9 taken 4 times.
✓ Branch 8 → 10 taken 11 times.
15 if (cfg.beats)
42 {
43 4 running |= TICKER_BEATS;
44 }
45
46 15 return running;
47 }
48
49 12 bool time_config_same_tickers(TimeConfig a, TimeConfig b)
50 {
51 12 return tickers(a) == tickers(b);
52 }
53
54 8 TimeConfig time_config_reconfigured(TimeConfig cfg, bool pinned)
55 {
56 8 cfg.live = store_live_after_reconfigure(cfg.live, pinned);
57 8 return cfg;
58 }
59
60 5 bool time_config_reconfigure(TimeConfig *running, TimeConfig cfg, bool pinned)
61 {
62 5 TimeConfig next = time_config_reconfigured(cfg, pinned);
63 5 bool same = time_config_same_tickers(next, *running);
64 5 *running = next;
65 5 return !same;
66 }
67