Skip to content

Commit

Permalink
boards: Tock: Use read only syscalls
Browse files Browse the repository at this point in the history
Signed-off-by: Alistair Francis <[email protected]>
  • Loading branch information
alistair23 committed Nov 25, 2022
1 parent 216776f commit 4fe4e5d
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/boards/Tock/rtc-board.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "libtock/timer.h"
#include "libtock/alarm.h"
#include "libtock/read_only_state.h"

// MCU Wake Up Time
#define MIN_ALARM_DELAY 3 // in ticks
Expand All @@ -41,6 +42,8 @@ typedef struct
uint32_t Time; // Reference time
}RtcTimerContext_t;

void* read_only_state_buffer = NULL;

static tock_timer_t timer;
static uint32_t alarm_set_time = 0;

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

void RtcInit( void )
{
read_only_state_buffer = malloc(READ_ONLY_STATEBUFFER_LEN);

read_only_state_allocate_region(read_only_state_buffer, READ_ONLY_STATEBUFFER_LEN);
}

uint32_t RtcSetTimerContext( void )
Expand Down Expand Up @@ -152,18 +158,24 @@ void RtcStartAlarm( uint32_t timeout )

uint32_t RtcGetTimerValue( void )
{
uint32_t now;
alarm_internal_read(&now);

return now;
if (read_only_state_buffer == NULL) {
uint32_t now;
alarm_internal_read(&now);
return now;
} else {
return read_only_state_get_ticks(read_only_state_buffer);
}
}

uint32_t RtcGetTimerElapsedTime( void )
{
uint32_t now;
alarm_internal_read(&now);

return now - alarm_set_time;
if (read_only_state_buffer == NULL) {
uint32_t now;
alarm_internal_read(&now);
return now - alarm_set_time;
} else {
return read_only_state_get_ticks(read_only_state_buffer) - alarm_set_time;
}
}

uint32_t RtcGetCalendarTime( uint16_t *milliseconds )
Expand Down

0 comments on commit 4fe4e5d

Please sign in to comment.