@@ -29,6 +29,30 @@ static bool timeIsInPeriod(minar::platform::tick_t start, minar::platform::tick_
29
29
30
30
// /////////////////////////////////////////////////////////////////////////////
31
31
32
+ // functions and variables for keeping track of uptime and duty-cycle
33
+ static uint64_t total_sleep = 0 ;
34
+ static uint64_t total_active = 0 ;
35
+ static minar::platform::tick_t last_wakeup = 0 ;
36
+ static minar::platform::tick_t last_gotosleep = 0 ;
37
+
38
+ namespace minar {
39
+ namespace stats {
40
+
41
+ /* Return uptime in seconds. */
42
+ uint64_t getUptime () {
43
+ return (total_active + total_sleep) / MINAR_PLATFORM_TIME_BASE;
44
+ }
45
+
46
+ /* Return seconds spent in non-sleep mode. */
47
+ uint64_t getActive () {
48
+ return total_active / MINAR_PLATFORM_TIME_BASE;
49
+ }
50
+
51
+ };
52
+ };
53
+
54
+ // /////////////////////////////////////////////////////////////////////////////
55
+
32
56
namespace minar {
33
57
namespace platform {
34
58
@@ -69,12 +93,25 @@ void sleepFromUntil(tick_t now, tick_t until){
69
93
} else {
70
94
const uint32_t next_int = lp_ticker_get_compare_match ();
71
95
96
+ #if YOTTA_CFG_MINAR_STATS
97
+ // update stats
98
+ tick_t now = lp_ticker_read ();
99
+ total_active += now - last_wakeup;
100
+ total_sleep += last_wakeup - last_gotosleep;
101
+ last_gotosleep = now;
102
+ #endif
103
+
72
104
if (timeIsInPeriod (now, until, next_int)){
73
105
lp_ticker_sleep_until (now, until);
74
106
} else {
75
107
// existing compare match is sooner, go to sleep
76
108
sleep ();
77
109
}
110
+
111
+ #if YOTTA_CFG_MINAR_STATS
112
+ // update stats
113
+ last_wakeup = lp_ticker_read ();
114
+ #endif
78
115
}
79
116
}
80
117
0 commit comments