UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
rtc.c
1 
10 #include "board.h"
11 #include "../rtc.h"
12 #include "../delay.h"
13 
14 /* Required for 'struct tm' prototypes in driverlib/hibernate.h */
15 #include <time.h>
16 
17 #include "driverlib/sysctl.h"
18 #include "driverlib/hibernate.h"
19 
20 void RTC_init(void)
21 {
22  if(HibernateIsActive() == false)
23  {
24  /* Enable Hibernation Peripheral */
25  HibernateEnableExpClk(SysCtlClockGet());
26 
27  /* Give time for 32KHz Crystal Osc to stabilise */
28  Delay_ms(1500);
29 
30  /* Enable 32KHz Osc as RTC Clock */
31  HibernateClockConfig(HIBERNATE_OSC_HIGHDRIVE);
32 
33  /* Enable RTC */
34  HibernateRTCEnable();
35  }
36 }
37 
38 void RTC_getTime(uint32_t *time)
39 {
40  *time = HibernateRTCGet();
41 }
42 
43 void RTC_getTime_ms(uint64_t *time_ms)
44 {
45  *time_ms = ((uint64_t)HibernateRTCGet() * 1000) + (((uint64_t)HibernateRTCSSGet() * 1000) / 32768);
46 }
47 
48 void RTC_setTime(uint32_t *time)
49 {
50  HibernateRTCSet(*time);
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 Delay_ms(uint32_t milliseconds)
Definition: delay.c:19
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