Skip to content

Commit

Permalink
Created EEPROM test to read/write data to/from the root portion of th…
Browse files Browse the repository at this point in the history
…e EEPROM. Not yet tested
  • Loading branch information
ameall committed Jan 28, 2024
1 parent d6649ae commit 518e74a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions Core/Inc/eepromdirectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,6 @@ void log_fault(uint32_t fault_code);

void get_faults();

bool test_EEPROM();

#endif
47 changes: 47 additions & 0 deletions Core/Src/eepromdirectory.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,51 @@ void get_faults()
curr_reg += 4;
}
}
}

bool test_EEPROM(){
//TODO: Write code for and verify this first, and then move onto fault log test after verification
// Data read/write test
// Check if data in memory address
// If there is, store it so can re-write later
// Write data to set address
// Read data from set address
// Compare written and read data and make sure they're identical
// printf whether the written and read data values were identical
// If there was previously data in the EEPROM chip, rewrite it

// Define the root index of the EEPROM chip
uint8_t reg_to_write;
uint8_t root_address = eeprom_get_index((char*)("ROOT"));

// Grab the initial data in the given address
uint8_t initial_data = eeprom_read_data_address(root_address, &reg_to_write, 1);

if (initial_data != 0){
printf("Initial data read from EEPROM", initial_data);
}

// Write a known data value to a certain address in EEPROM and read it back
uint8_t known_data = 22;
eeprom_write_data_address(root_address, &reg_to_write, 1);
uint8_t data_read = eeprom_read_data_address(root_address, &reg_to_write, 1);

// Check whether the written/read data from the EEPROM matches
if (data_read == known_data){
printf("Data was successfully written and read from EEPROM");
}
else{
printf("Data was not successfully written/read from EEPROM");
}

// Write data previously stored in EEPROM address back to EEPROM
eeprom_write_data_address(root_address, &reg_to_write, 1);

//TODO: Verify that simple read/write test code works before moving onto testing this
// Fault read/write test
// Check if there are faults currently stored
// If there are, read the 5 faults and save them so can re-write later
// Write a fault to the fault log and check that the fault was written
// printf whether the fault was correctly written/read
// If there was previously data in the fault log, rewrite it to the log
}

0 comments on commit 518e74a

Please sign in to comment.