Skip to content

Commit 7b12bc8

Browse files
committed
Fix port_get_raw_ticks() for these ports:
o broadcom: return subticks o cxd56: return subticks only when pointer is non-null o litex: zero subticks, port is accurate only to ticks o raspberrypi: correct subtick calculation
1 parent 04b17e1 commit 7b12bc8

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

ports/broadcom/supervisor/port.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) {
143143
}
144144
COMPLETE_MEMORY_READS;
145145
uint64_t microseconds = hi << 32 | lo;
146-
return 1024 * (microseconds / 1000000) + (microseconds % 1000000) / 977;
146+
int64_t all_subticks = microseconds * 512 / 15625;
147+
if (subticks != NULL) {
148+
*subticks = all_subticks % 32;
149+
}
150+
return all_subticks / 32;
147151
}
148152

149153
void TIMER_1_IRQHandler(void) {

ports/cxd56/supervisor/port.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ void board_timerhook(void) {
124124

125125
uint64_t port_get_raw_ticks(uint8_t *subticks) {
126126
uint64_t count = cxd56_rtc_count();
127-
*subticks = count % 32;
127+
if (subticks != NULL) {
128+
*subticks = count % 32;
129+
}
128130

129131
return count / 32;
130132
}

ports/litex/supervisor/port.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) {
114114
common_hal_mcu_disable_interrupts();
115115
uint64_t raw_tick_snapshot = raw_ticks;
116116
common_hal_mcu_enable_interrupts();
117+
if (subticks != NULL) {
118+
*subticks = 0;
119+
}
117120
return raw_tick_snapshot;
118121
}
119122

ports/raspberrypi/supervisor/port.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,11 @@ static volatile bool ticks_enabled;
491491
static volatile bool _woken_up;
492492

493493
uint64_t port_get_raw_ticks(uint8_t *subticks) {
494-
uint64_t microseconds = time_us_64();
494+
int64_t all_subticks = time_us_64() * 512 / 15625;
495495
if (subticks != NULL) {
496-
*subticks = (uint8_t)(((microseconds % 1000000) % 977) / 31);
496+
*subticks = all_subticks % 32;
497497
}
498-
return 1024 * (microseconds / 1000000) + (microseconds % 1000000) / 977;
498+
return all_subticks / 32;
499499
}
500500

501501
static void _tick_callback(uint alarm_num) {

0 commit comments

Comments
 (0)