Skip to content

Commit 4fe4e5d

Browse files
committed
boards: Tock: Use read only syscalls
Signed-off-by: Alistair Francis <[email protected]>
1 parent 216776f commit 4fe4e5d

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/boards/Tock/rtc-board.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "libtock/timer.h"
2222
#include "libtock/alarm.h"
23+
#include "libtock/read_only_state.h"
2324

2425
// MCU Wake Up Time
2526
#define MIN_ALARM_DELAY 3 // in ticks
@@ -41,6 +42,8 @@ typedef struct
4142
uint32_t Time; // Reference time
4243
}RtcTimerContext_t;
4344

45+
void* read_only_state_buffer = NULL;
46+
4447
static tock_timer_t timer;
4548
static uint32_t alarm_set_time = 0;
4649

@@ -61,6 +64,9 @@ static RtcTimerContext_t RtcTimerContext;
6164

6265
void RtcInit( void )
6366
{
67+
read_only_state_buffer = malloc(READ_ONLY_STATEBUFFER_LEN);
68+
69+
read_only_state_allocate_region(read_only_state_buffer, READ_ONLY_STATEBUFFER_LEN);
6470
}
6571

6672
uint32_t RtcSetTimerContext( void )
@@ -152,18 +158,24 @@ void RtcStartAlarm( uint32_t timeout )
152158

153159
uint32_t RtcGetTimerValue( void )
154160
{
155-
uint32_t now;
156-
alarm_internal_read(&now);
157-
158-
return now;
161+
if (read_only_state_buffer == NULL) {
162+
uint32_t now;
163+
alarm_internal_read(&now);
164+
return now;
165+
} else {
166+
return read_only_state_get_ticks(read_only_state_buffer);
167+
}
159168
}
160169

161170
uint32_t RtcGetTimerElapsedTime( void )
162171
{
163-
uint32_t now;
164-
alarm_internal_read(&now);
165-
166-
return now - alarm_set_time;
172+
if (read_only_state_buffer == NULL) {
173+
uint32_t now;
174+
alarm_internal_read(&now);
175+
return now - alarm_set_time;
176+
} else {
177+
return read_only_state_get_ticks(read_only_state_buffer) - alarm_set_time;
178+
}
167179
}
168180

169181
uint32_t RtcGetCalendarTime( uint16_t *milliseconds )

0 commit comments

Comments
 (0)