Skip to content

Commit 31c3734

Browse files
committed
Test ticker: remove attach/detach, not good for timing
Use 2 tickers, one at periods 0,2,4... and other one 1,3,5,... This way we get a callback every 1 millisecond, do not require attach/detach that was causing drifts for some platforms that have 16bit tickers, and are very close to the 5 percent tolerance.
1 parent 3db2e35 commit 31c3734

File tree

1 file changed

+5
-24
lines changed

1 file changed

+5
-24
lines changed

TESTS/mbed_drivers/ticker/main.cpp

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,13 @@ void ticker_callback_0(void) {
5858
}
5959

6060
void ticker_callback_1_led(void) {
61+
++callback_trigger_count;
6162
led1 = !led1;
6263
}
6364

6465
void ticker_callback_2_led(void) {
65-
led2 = !led2;
66-
}
67-
68-
void ticker_callback_1_switch_to_2(void) {
69-
++callback_trigger_count;
70-
ticker1->detach();
71-
ticker1->attach_us(ticker_callback_2_switch_to_1, ONE_MILLI_SEC);
72-
ticker_callback_1_led();
73-
}
74-
75-
void ticker_callback_2_switch_to_1(void) {
7666
++callback_trigger_count;
77-
ticker2->detach();
78-
ticker2->attach_us(ticker_callback_1_switch_to_2, ONE_MILLI_SEC);
79-
ticker_callback_2_led();
80-
}
81-
82-
void wait_and_print() {
83-
while (ticker_count <= total_ticks) {
84-
if (print_tick) {
85-
print_tick = false;
86-
greentea_send_kv("tick", ticker_count++);
87-
}
88-
}
67+
led2 = !led2;
8968
}
9069

9170
void test_case_1x_ticker() {
@@ -122,7 +101,9 @@ void test_case_2x_callbacks() {
122101
callback_trigger_count = 0;
123102

124103
greentea_send_kv("timing_drift_check_start", 0);
125-
ticker1->attach_us(ticker_callback_1_switch_to_2, ONE_MILLI_SEC);
104+
ticker1->attach_us(&ticker_callback_2_led, 2*ONE_MILLI_SEC);
105+
wait_us(1000);
106+
ticker2->attach_us(&ticker_callback_1_led, 2*ONE_MILLI_SEC);
126107

127108
// wait for 1st signal from host
128109
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));

0 commit comments

Comments
 (0)