Skip to content

Commit cb37a01

Browse files
author
Liyou Zhou
committed
Use only lower 16bit of lp_ticker as minar clock
In order to create timer overflow faster. Used for minar testing.
1 parent 5b273d8 commit cb37a01

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

minar-platform/minar_platform_types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ namespace platform {
2727
enum Constants{
2828
// ticks per second (maximum resolution). This is what the OS works with.
2929
Time_Base = MINAR_PLATFORM_TIME_BASE,
30+
31+
#if YOTTA_CFG_MINAR_TEST_CLOCK_OVERFLOW
32+
#warning "testing clock overflow"
33+
// use only lower 16bits of timer for testing timer overflow
34+
Time_Mask = UINT32_MAX >> 16
35+
#else
3036
// 32 bits of time for mbed platforms
3137
Time_Mask = 0xFFFFFFFFu
38+
#endif
3239
};
3340

3441
typedef uint32_t irqstate_t;

source/mbed_platform.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#include "mbed-hal/sleep_api.h"
2222
#include "cmsis-core/core_generic.h"
2323

24+
#if YOTTA_CFG_MINAR_TEST_CLOCK_OVERFLOW
25+
#include "mbed-drivers/test_env.h"
26+
#endif
27+
2428
/// @name Local Constants
2529
const static minar::platform::tick_t Minimum_Sleep = MINAR_PLATFORM_MINIMUM_SLEEP; // in Platform_Time_Base units
2630

@@ -53,16 +57,36 @@ void sleep(){
5357
}
5458

5559
tick_t getTime() {
60+
#if YOTTA_CFG_MINAR_TEST_CLOCK_OVERFLOW
61+
return lp_ticker_read() & Time_Mask;
62+
#else
5663
return lp_ticker_read();
64+
#endif
5765
}
5866

5967
uint32_t getTimeOverflows(){
6068
return lp_ticker_get_overflows_counter();
6169
}
6270

6371
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
6486
// use real-now for front-most end of do-not-sleep range check
6587
const tick_t real_now = getTime();
88+
#endif
89+
6690
if(timeIsInPeriod(now, until, real_now + Minimum_Sleep)){
6791
// in this case too soon to go to sleep, just return
6892
return;

0 commit comments

Comments
 (0)