|
8 | 8 | #include <stdlib.h>
|
9 | 9 | #include <string.h>
|
10 | 10 | #include <hardware/sync.h>
|
| 11 | +#include "hardware/clocks.h" |
11 | 12 | #include "pico/stdlib.h"
|
12 | 13 | #include "pico/test.h"
|
13 | 14 | // Include sys/types.h before inttypes.h to work around issue with
|
@@ -74,6 +75,7 @@ static bool repeating_timer_callback(struct repeating_timer *t) {
|
74 | 75 | int issue_195_test(void);
|
75 | 76 | int issue_1812_test(void);
|
76 | 77 | int issue_1953_test(void);
|
| 78 | +int issue_2118_test(void); |
77 | 79 |
|
78 | 80 | int main() {
|
79 | 81 | setup_default_uart();
|
@@ -246,6 +248,8 @@ int main() {
|
246 | 248 |
|
247 | 249 | issue_1953_test();
|
248 | 250 |
|
| 251 | + issue_2118_test(); |
| 252 | + |
249 | 253 | PICOTEST_END_TEST();
|
250 | 254 | }
|
251 | 255 |
|
@@ -325,3 +329,38 @@ int issue_1953_test(void) {
|
325 | 329 | PICOTEST_END_SECTION();
|
326 | 330 | return 0;
|
327 | 331 | }
|
| 332 | + |
| 333 | +static int counter_2118; |
| 334 | +static bool timer_callback_issue_2118(repeating_timer_t *rt) { |
| 335 | + counter_2118++; |
| 336 | + return true; |
| 337 | +} |
| 338 | + |
| 339 | +int issue_2118_test(void) { |
| 340 | + PICOTEST_START_SECTION("Issue #2118 defect - failure to set an alarm"); |
| 341 | + |
| 342 | + // this problem only happens when running the clock fast as it requires the time between |
| 343 | + // alarm_pool_irq_handler handling an alarm and setting the next alarm to be <1us |
| 344 | + set_sys_clock_hz(200 * MHZ, true); |
| 345 | + setup_default_uart(); |
| 346 | + |
| 347 | + alarm_pool_t *pool = alarm_pool_create(2, 1); |
| 348 | + repeating_timer_t timer; |
| 349 | + alarm_pool_add_repeating_timer_ms(pool, -20, timer_callback_issue_2118, NULL, &timer); |
| 350 | + |
| 351 | + int iterations = 0; |
| 352 | + while(iterations < 100) { |
| 353 | + iterations++; |
| 354 | + sleep_ms(20); |
| 355 | + } |
| 356 | + PICOTEST_CHECK(counter_2118 >= 100, "Repeating timer failure"); |
| 357 | + |
| 358 | + alarm_pool_destroy(pool); |
| 359 | + hard_assert(timer_hw->armed == 0); // check destroying the pool unarms its timer |
| 360 | + |
| 361 | + set_sys_clock_hz(SYS_CLK_HZ, true); |
| 362 | + setup_default_uart(); |
| 363 | + |
| 364 | + PICOTEST_END_SECTION(); |
| 365 | + return 0; |
| 366 | +} |
0 commit comments