Skip to content

Commit cd5577c

Browse files
authored
Merge pull request #2987 from kamtom480/spresense-raw-ticks
spresense: Fix port_get_raw_ticks
2 parents 47efd59 + ce337ea commit cd5577c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

ports/cxd56/supervisor/port.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <sys/boardctl.h>
3030
#include <sys/time.h>
3131

32+
#include <cxd56_rtc.h>
33+
3234
#include "sched/sched.h"
3335

3436
#include "boards/board.h"
@@ -45,7 +47,8 @@
4547
safe_mode_t port_init(void) {
4648
boardctl(BOARDIOC_INIT, 0);
4749

48-
board_init();
50+
// Wait until RTC is available
51+
while (g_rtc_enabled == false);
4952

5053
if (board_requests_safe_mode()) {
5154
return USER_SAFE_MODE;
@@ -121,14 +124,10 @@ void board_timerhook(void)
121124
}
122125

123126
uint64_t port_get_raw_ticks(uint8_t* subticks) {
124-
struct timeval tv;
125-
gettimeofday(&tv, NULL);
126-
long computed_subticks = tv.tv_usec * 1024 * 32 / 1000000;
127-
if (subticks != NULL) {
128-
*subticks = computed_subticks % 32;
129-
}
127+
uint64_t count = cxd56_rtc_count();
128+
*subticks = count % 32;
130129

131-
return tv.tv_sec * 1024 + computed_subticks / 32;
130+
return count / 32;
132131
}
133132

134133
// Enable 1/1024 second tick.

0 commit comments

Comments
 (0)