UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
configuration.c
Go to the documentation of this file.
1 
9 #include "../firmware.h"
10 
11 static void Configuration_save_to_eeprom(void);
12 static bool Configuration_load_from_eeprom(void);
13 static void Configuration_load_defaults(void);
14 static void Configuration_update_checksum(void);
15 
16 void Configuration_Init(void)
17 {
18  if(Configuration_load_from_eeprom() == false)
19  {
20  /* Load defaults and save EEPROM copy */
21  Configuration_load_defaults();
22  Configuration_save_to_eeprom();
23  }
24 
25 
26 
27 }
28 
29 static void Configuration_save_to_eeprom(void)
30 {
31  EEPROM_write(EEPROM_CONFIGURATION_DATA_ADDRESS, (uint32_t*)(&spacecraft_configuration), sizeof(configuration_t));
32 }
33 
34 static bool Configuration_load_from_eeprom(void)
35 {
36  if(EEPROM_selfTest() == false)
37  return false;
38 
39  EEPROM_read(EEPROM_CONFIGURATION_DATA_ADDRESS, (uint32_t*)(&spacecraft_configuration), sizeof(configuration_t));
40 
41  return Configuration_verify_checksum();
42 }
43 
44 bool Configuration_verify_checksum(void)
45 {
46  uint16_t checksum;
47 
48  checksum = Util_crc16((uint8_t *)(&(spacecraft_configuration.data)), sizeof(configuration_data_t));
49 
50  return (checksum == spacecraft_configuration.checksum);
51 }
52 
53 static void Configuration_load_defaults(void)
54 {
55  /* Set defaults.. */
56 
57 
58  Configuration_update_checksum();
59 }
60 
61 static void Configuration_update_checksum(void)
62 {
63  spacecraft_configuration.checksum = Util_crc16((uint8_t *)(&(spacecraft_configuration.data)), sizeof(configuration_data_t));
64 }
65 
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 EEPROM_read(uint32_t address, uint32_t *data, uint32_t length)
Definition: eeprom.c:31
uint16_t Util_crc16(const uint8_t *buf, uint32_t size)
Definition: crc.c:100