UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
demo_rtc.c
1 /* firmware.h contains all relevant headers */
2 #include "../firmware.h"
3 
4 #include <stdio.h>
5 
6 #define UART_INTERFACE UART_CAMERA
7 
8 int main(void)
9 {
10  uint32_t clock;
11  uint64_t clock_ms;
12  uint32_t setclock = 1000000;
13  char output[100];
14 
15  Board_init();
16 
17  LED_on(LED_B);
18 
19  UART_init(UART_INTERFACE, 9600);
20  UART_puts(UART_INTERFACE, "\r\nRTC Demo\r\n");
21 
22  RTC_init();
23 
24  uint8_t i=0;
25  while(1)
26  {
27  LED_on(LED_B);
28 
29  if(i<10)
30  {
31  i++;
32  }
33  else if(i==10)
34  {
35  i = 20;
36 
37  sprintf(output,"Manually setting clock to: %+011ld\r\n", setclock);
38  UART_puts(UART_INTERFACE, output);
39 
40  RTC_setTime(&setclock);
41  }
42 
43  RTC_getTime(&clock);
44  RTC_getTime_ms(&clock_ms);
45 
46  sprintf(output,"Time : %011"PRIu32"\r\n", clock);
47  UART_puts(UART_INTERFACE, output);
48  sprintf(output,"Time (ms): %011"PRIu64"\r\n", clock_ms);
49  UART_puts(UART_INTERFACE, output);
50 
51  LED_off(LED_B);
52 
53  Delay_ms(1000);
54  }
55 }
void Delay_ms(uint32_t milliseconds)
Definition: delay.c:19
void RTC_getTime(uint32_t *time)
Definition: rtc.c:20
void UART_init(uint8_t uart_num, uint32_t baudrate)
Definition: uart.c:78
void RTC_setTime(uint32_t *time)
Definition: rtc.c:46
void RTC_getTime_ms(uint64_t *time_ms)
Definition: rtc.c:33
void LED_off(uint8_t led_num)
Definition: led.c:20
int main(void)
Runs all module tests.
Definition: test.c:19
void UART_puts(uint8_t uart_num, char *str)
Definition: uart.c:129
void Board_init(void)
Definition: board.c:13
void LED_on(uint8_t led_num)
Definition: led.c:15
void RTC_init(void)
Definition: rtc.c:15