UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
demo_eeprom.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 written, read;
11  char output[100];
12 
13  Board_init();
14 
15  LED_on(LED_B);
16 
17  UART_init(UART_INTERFACE, 9600);
18  UART_puts(UART_INTERFACE, "\r\nEEPROM Demo\r\n");
19 
20  EEPROM_init();
21 
22  if(EEPROM_selfTest() == false)
23  {
24  UART_puts(UART_INTERFACE, "\r\nSelftest: FAIL\r\n");
25  LED_off(LED_B);
26  while(1) {};
27  }
28  UART_puts(UART_INTERFACE, "\r\nSelftest: OK\r\n");
29 
30  while(1)
31  {
32  LED_on(LED_B);
33 
34  written = Random(UINT_MAX-1);
35  EEPROM_write(0x00000000, &written, 4);
36 
37  sprintf(output,"Written: 0x%08lx\r\n", written);
38  UART_puts(UART_INTERFACE, output);
39 
40  EEPROM_read(0x00000000, &read, 4);
41 
42  sprintf(output,"Read: 0x%08lx\r\n", read);
43  UART_puts(UART_INTERFACE, output);
44 
45  LED_off(LED_B);
46 
47  Delay_ms(5000);
48  }
49 }
void Delay_ms(uint32_t milliseconds)
Definition: delay.c:19
void EEPROM_write(uint32_t address, uint32_t *data, uint32_t length)
Definition: eeprom.c:23
bool EEPROM_selfTest(void)
Definition: eeprom.c:18
void UART_init(uint8_t uart_num, uint32_t baudrate)
Definition: uart.c:78
uint32_t Random(uint32_t max)
Definition: random.c:21
void EEPROM_read(uint32_t address, uint32_t *data, uint32_t length)
Definition: eeprom.c:31
void LED_off(uint8_t led_num)
Definition: led.c:20
void EEPROM_init(void)
Definition: eeprom.c:13
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