Skip to content

Commit 07a2355

Browse files
committed
Reducing number of timeouts to decrease drift
1 parent e678325 commit 07a2355

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

TESTS/mbed_drivers/timeout/main.cpp

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,20 @@
2020

2121
using namespace utest::v1;
2222

23-
Timeout timer;
23+
Timeout timeout;
2424
DigitalOut led(LED1);
2525
volatile int ticker_count = 0;
2626
volatile bool print_tick = false;
2727
static const int total_ticks = 10;
28-
29-
namespace {
30-
const int MS_INTERVALS = 1000;
31-
}
28+
const int ONE_SECOND_US = 1000000;
3229

3330
void send_kv_tick() {
3431
if (ticker_count <= total_ticks) {
32+
timeout.attach_us(send_kv_tick, ONE_SECOND_US);
3533
print_tick = true;
3634
}
3735
}
3836

39-
void toggleOff(void);
40-
41-
void toggleOn(void) {
42-
static int toggle_counter = 0;
43-
timer.attach_us(toggleOff, 500);
44-
45-
if (toggle_counter == MS_INTERVALS) {
46-
send_kv_tick();
47-
toggle_counter = 0;
48-
} else {
49-
toggle_counter++;
50-
}
51-
}
52-
53-
void toggleOff(void) {
54-
timer.attach_us(toggleOn, 500);
55-
}
56-
5737
void wait_and_print() {
5838
while(ticker_count <= total_ticks) {
5939
if (print_tick) {
@@ -65,7 +45,7 @@ void wait_and_print() {
6545
}
6646

6747
void test_case_ticker() {
68-
toggleOn();
48+
timeout.attach_us(send_kv_tick, ONE_SECOND_US);
6949
wait_and_print();
7050
}
7151

0 commit comments

Comments
 (0)