|
21 | 21 | #include "mbed-hal/sleep_api.h"
|
22 | 22 | #include "cmsis-core/core_generic.h"
|
23 | 23 |
|
| 24 | +#if YOTTA_CFG_MINAR_TEST_CLOCK_OVERFLOW |
| 25 | +#include "mbed-drivers/test_env.h" |
| 26 | +#endif |
| 27 | + |
24 | 28 | /// @name Local Constants
|
25 | 29 | const static minar::platform::tick_t Minimum_Sleep = MINAR_PLATFORM_MINIMUM_SLEEP; // in Platform_Time_Base units
|
26 | 30 |
|
@@ -53,16 +57,36 @@ void sleep(){
|
53 | 57 | }
|
54 | 58 |
|
55 | 59 | tick_t getTime() {
|
| 60 | +#if YOTTA_CFG_MINAR_TEST_CLOCK_OVERFLOW |
| 61 | + return lp_ticker_read() & Time_Mask; |
| 62 | +#else |
56 | 63 | return lp_ticker_read();
|
| 64 | +#endif |
57 | 65 | }
|
58 | 66 |
|
59 | 67 | uint32_t getTimeOverflows(){
|
60 | 68 | return lp_ticker_get_overflows_counter();
|
61 | 69 | }
|
62 | 70 |
|
63 | 71 | void sleepFromUntil(tick_t now, tick_t until){
|
| 72 | + |
| 73 | +#if YOTTA_CFG_MINAR_TEST_CLOCK_OVERFLOW |
| 74 | + MBED_HOSTTEST_ASSERT(now <= Time_Mask && until <= Time_Mask); |
| 75 | + tick_t timer_top_bits = lp_ticker_read() & ~Time_Mask; |
| 76 | + now += timer_top_bits; |
| 77 | + until += timer_top_bits; |
| 78 | + |
| 79 | + if (until < now) { |
| 80 | + until += Time_Mask; |
| 81 | + } |
| 82 | + |
| 83 | + const tick_t real_now = timer_top_bits + getTime(); |
| 84 | + //printf("sleepFromUntil %lx %lx real_now %lx\r\n", now, until, real_now); |
| 85 | +#else |
64 | 86 | // use real-now for front-most end of do-not-sleep range check
|
65 | 87 | const tick_t real_now = getTime();
|
| 88 | +#endif |
| 89 | + |
66 | 90 | if(timeIsInPeriod(now, until, real_now + Minimum_Sleep)){
|
67 | 91 | // in this case too soon to go to sleep, just return
|
68 | 92 | return;
|
|
0 commit comments