UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
rtc.c
1 
10 #include "board.h"
11 #include "../rtc.h"
12 
13 #include <time.h>
14 
15 void RTC_init(void)
16 {
17  return;
18 }
19 
20 void RTC_getTime(uint32_t *time)
21 {
22  struct timespec tp;
23 
24  if(clock_gettime(CLOCK_REALTIME, &tp) != 0)
25  {
26  *time = 0;
27  return;
28  }
29 
30  *time = ((uint32_t)tp.tv_sec);
31 }
32 
33 void RTC_getTime_ms(uint64_t *time_ms)
34 {
35  struct timespec tp;
36 
37  if(clock_gettime(CLOCK_REALTIME, &tp) != 0)
38  {
39  *time_ms = 0;
40  return;
41  }
42 
43  *time_ms = ((uint64_t)tp.tv_sec * 1000 + (uint64_t)tp.tv_nsec / 1000000);
44 }
45 
46 void RTC_setTime(uint32_t *time)
47 {
48  (void) time;
49 
50  return;
51 }
52 
53 bool RTC_timerElapsed_ms(uint64_t start_time_ms, uint64_t period_ms)
54 {
55  uint64_t current_time_ms;
56  RTC_getTime_ms(&current_time_ms);
57 
58  if(current_time_ms < start_time_ms || current_time_ms > (start_time_ms + period_ms))
59  {
60  return true;
61  }
62  else
63  {
64  return false;
65  }
66 }
67 
void RTC_getTime(uint32_t *time)
Definition: rtc.c:20
void RTC_setTime(uint32_t *time)
Definition: rtc.c:46
bool RTC_timerElapsed_ms(uint64_t start_time_ms, uint64_t period_ms)
Definition: rtc.c:53
void RTC_getTime_ms(uint64_t *time_ms)
Definition: rtc.c:33
void RTC_init(void)
Definition: rtc.c:15