97 lines
2.8 KiB
C
97 lines
2.8 KiB
C
#include "eeprom.h"
|
|
|
|
// The start address for the controller data
|
|
uint8_t EEMEM start_address_controller = 0x00;
|
|
|
|
// Where the writing of the fans points start
|
|
uint8_t EEMEM start_address_fan1 = 0x30;
|
|
uint8_t EEMEM start_address_fan2 = 0x60;
|
|
|
|
// The placement for the next datapoint form the fans.
|
|
uint8_t EEMEM current_address_fan1 = 0x30;
|
|
uint8_t EEMEM current_address_fan2 = 0x60;
|
|
|
|
// Checks if the EEPROM memory is ready to be written in.
|
|
void check_eeprom_is_ready(){
|
|
while(1){
|
|
if (eeprom_is_ready()){
|
|
break;
|
|
}else{
|
|
;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Takes inn a struct by the form of config_t
|
|
// Checks if the eeprom is ready to be written in
|
|
// Checks if it has been written information at the address
|
|
// If true, the infromation is replaced with the intaken struct
|
|
// else the intaken struct is written at the address.
|
|
void write_struct_in_EEPROM(config_t write_struct){
|
|
uint8_t struct_size;
|
|
struct_size = sizeof(write_struct);
|
|
|
|
check_eeprom_is_ready();
|
|
|
|
eeprom_update_block((void*) &write_struct,(void*) &start_address_controller, struct_size);
|
|
|
|
}
|
|
|
|
// Reads the memory block at the address 0x00
|
|
// returns a struct in form of config_t
|
|
config_t read_struct_from_EEPROM(){
|
|
//is eeprom ready??
|
|
config_t read_struct;
|
|
uint8_t struct_size = sizeof(read_struct);
|
|
|
|
check_eeprom_is_ready();
|
|
|
|
eeprom_read_block((void *) &read_struct,(void*) &start_address_controller, struct_size);
|
|
return read_struct;
|
|
}
|
|
|
|
// Takes inn a dataPoint and what data set it belongs to
|
|
// checks if EEPROM is ready
|
|
// If the dataset is 1, the datapoint is written at the address.
|
|
// If the dataset is 2 its written at another point.
|
|
void write_data_point_in_EEPROM(uint8_t data_point, uint8_t data){
|
|
|
|
check_eeprom_is_ready();
|
|
if (data == 1){
|
|
eeprom_update_byte(current_address_fan1, data_point);
|
|
current_address_fan1++;
|
|
} else if (data == 2){
|
|
eeprom_update_byte(current_address_fan2, data_point);
|
|
current_address_fan2++;
|
|
} else{
|
|
// error???
|
|
;
|
|
}
|
|
}
|
|
|
|
// Reads all the datapoints to the choosen data.
|
|
// it writes the data points in the USART stream.
|
|
void read_data_point_speed_info(uint8_t data){
|
|
uint8_t data_point = 0;
|
|
|
|
if (data == 1){
|
|
uint8_t len = current_address_fan1 - start_address_fan1;
|
|
|
|
check_eeprom_is_ready();
|
|
|
|
for (uint8_t i = 0; i <len; i++){
|
|
data_point = eeprom_read_byte(i);
|
|
printf("Fanspeed nr %u : %u", i, data_point);
|
|
}
|
|
} else if (data == 2){
|
|
uint8_t len = current_address_fan2 - start_address_fan2;
|
|
check_eeprom_is_ready();
|
|
|
|
for (uint8_t i = 0; i <len; i++){
|
|
data_point = eeprom_read_byte(i);
|
|
printf("Fanspeed nr %u : %u", i, data_point);
|
|
}
|
|
}
|
|
}
|