Skip to content

Commit 7360359

Browse files
committed
pbio/drv/clock_test: Fix counting clock.
It did not advance, and even if it did it would use its own counter in different places.
1 parent 8a2ac99 commit 7360359

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

bricks/simhub/mpconfigport.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,8 @@
6565
// every couple of MicroPython byte codes. This also polls to the event loop.
6666
#define PYBRICKS_VM_HOOK_LOOP_EXTRA \
6767
do { \
68-
static uint32_t count; \
69-
if ((count % 16) == 0) { \
70-
extern void pbio_test_clock_tick(uint32_t ticks); \
71-
pbio_test_clock_tick(1); \
72-
} \
68+
extern void pbio_clock_test_advance_eventually(void); \
69+
pbio_clock_test_advance_eventually(); \
7370
} while (0);
7471
#else
7572
// When using the wall clock, time advances automatically but we still need to

lib/pbio/drv/clock/clock_test.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ void pbio_test_clock_tick(uint32_t ticks) {
2626
pbio_os_request_poll();
2727
}
2828

29+
/**
30+
* Simulates incrementing the clock after a certain number of CPU cycles.
31+
*
32+
* This should be called from loops that take a very small but nonzero amount
33+
* of time.
34+
*/
35+
void pbio_clock_test_advance_eventually(void) {
36+
37+
static uint32_t count = 0;
38+
39+
if (++count % 16) {
40+
return;
41+
}
42+
43+
pbio_test_clock_tick(1);
44+
}
45+
2946
void pbdrv_clock_init(void) {
3047
}
3148

0 commit comments

Comments
 (0)