diff --git a/prosjekt.X/eeprom.c b/prosjekt.X/eeprom.c index 202da14..5d9f39d 100644 --- a/prosjekt.X/eeprom.c +++ b/prosjekt.X/eeprom.c @@ -1,15 +1,21 @@ #include "eeprom.h" -bool alreadyWrittenAblock = false;//false -uint8_t EEMEM currentFanSpeedAddress = 0x30; -uint8_t EEMEM fanControllerStartAddress = 0x00; +// The start address for the controller data +uint8_t EEMEM startAddressController = 0x00; +// Where the writing of the fans points start +uint8_t EEMEM startAddressFan1 = 0x30; +uint8_t EEMEM startAddressFan2 = 0x60; -uint8_t EEMEM fanSpeedStartAddress = 0x30; +// The placement for the next datapoint form the fans. +uint8_t EEMEM currentAddressFan1 = 0x30; +uint8_t EEMEM currentAddressFan2 = 0x60; +// Checks if its written a struct in the memmory space. +bool alreadyWrittenABlock = false; +// Checks if the EEPROM memory is ready to be written in. void checkEEpromIsReady(){ - printf("checking eeprom"); while(1){ if (eeprom_is_ready()){ break; @@ -21,22 +27,28 @@ void checkEEpromIsReady(){ } } + +// 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 WriteStructInEEPROM(config_t writeStruct){ uint8_t structSize; structSize = sizeof(writeStruct); - //check if eeprom_is_ready() checkEEpromIsReady(); - if (alreadyWrittenAblock){ - eeprom_update_block((void*) &writeStruct,(void*) &fanControllerStartAddress, structSize); + if (alreadyWrittenABlock){ + eeprom_update_block((void*) &writeStruct,(void*) &startAddressController, structSize); }else{ - eeprom_write_block((void*)&writeStruct,(void*) &fanControllerStartAddress, structSize); - alreadyWrittenAblock = true;//true - //reurn something + eeprom_write_block((void*)&writeStruct,(void*) &startAddressController, structSize); + alreadyWrittenABlock = true; } } +// Reads the memory block at the address 0x00 +// returns a struct in form of config_t config_t ReadStructInEEPROM(){ //is eeprom ready?? config_t readStruct; @@ -44,26 +56,50 @@ config_t ReadStructInEEPROM(){ checkEEpromIsReady(); - eeprom_read_block((void *) &readStruct,(void*) &fanControllerStartAddress, structsize); + eeprom_read_block((void *) &readStruct,(void*) &startAddressController, structsize); return readStruct; } -void WriteFanSpeedInEEPROM(uint8_t fanSpeed){ +// 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 WriteDataPointInEEPROM(uint8_t dataPoint, uint8_t data){ checkEEpromIsReady(); - - eeprom_write_byte(currentFanSpeedAddress, fanSpeed); - currentFanSpeedAddress++; -} - -void ReadFanSpeedInfo(){ - uint8_t len = currentFanSpeedAddress - fanSpeedStartAddress; - uint8_t fanSpeedIterate = 0; - - checkEEpromIsReady(); - - for (uint8_t i = 0; i - + +// Struct for information on the controller. typedef struct { uint8_t fanSpeed; } config_t; - +// Check if EEPROM is ready to be written in void checkEEpromIsReady(); + +// Writes a struct in EEPROM void WriteStructInEEPROM(config_t writeStruct); + +// Read data from EEPROM and return it as a controller struct config_t ReadStructInEEPROM(); -void WriteFanSpeedInEEPROM(uint8_t fanSpeed); -void ReadFanSpeedInfo(); + +// Writes a datapoint in EEPROM +void WriteDataPointInEEPROM(uint8_t dataPoint, uint8_t data); + +// Reads all the dataPoints form EEPROM +void ReadDataPointSpeedInfo(uint8_t data); #ifdef __cplusplus