From 8b73051ecef56bd8acccbcba98a72cbeed21fdee Mon Sep 17 00:00:00 2001 From: Elp03 Date: Wed, 6 Mar 2024 14:49:16 +0100 Subject: [PATCH 01/11] add eeprom code, not work --- .gitignore | 4 +- prosjekt.X/main.c | 160 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 157 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index d14efc5..f31b37b 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,6 @@ # Large Files *.exe *.zip -*.pdf \ No newline at end of file +*.pdf +/prosjekt.X/build/ +/prosjekt.X/dist/ \ No newline at end of file diff --git a/prosjekt.X/main.c b/prosjekt.X/main.c index 5f964b3..9e43e92 100644 --- a/prosjekt.X/main.c +++ b/prosjekt.X/main.c @@ -4,15 +4,163 @@ * * Created on March 6, 2024, 12:34 PM */ - +/* + * File: main.c + * Author: athamantis + * + * Created on 01 March 2024, 10:34 + */ +#include #include #include +#include +#define F_CPU 4E6 +#include +#include +#include +#define USART3_BAUD_RATE(BAUD_RATE) ((float)(F_CPU * 64 / (16 *(float) BAUD_RATE)) + 0.5) +#include -/* - * - */ -int main(int argc, char** argv) { +// Init UART comunication +void USART3_init(void) { + // Enable resiver pin + PORTB.DIR &= ~PIN1_bm; + // Enable sender pin + PORTB.DIR |= PIN0_bm; + USART3.BAUD = (uint16_t) USART3_BAUD_RATE(115200); + USART3.CTRLB |= USART_TXEN_bm; - return (EXIT_SUCCESS); + // Enabled in the USART register + USART3.CTRLB |= USART_RXEN_bm; +} + +// Use printline __________________________ +static void USART3_sendChar(char c) { + while (!(USART3.STATUS & USART_DREIF_bm)) { + ; + } + USART3.TXDATAL = c; +} + +static int USART3_printChar(char c, FILE *stream) { + USART3_sendChar(c); + return 0; +} +static FILE USART_stream = FDEV_SETUP_STREAM(USART3_printChar, NULL, _FDEV_SETUP_WRITE); + +uint8_t USART3_read() { + while (!(USART3.STATUS & USART_RXCIF_bm)) { + ; + } + return USART3.RXDATAL; +} + +/* + * make a struct + * a space is reserved for that struct + * make a function that write the struct to the space + * + * a running counter for where the fanspeed data should be set + * make a function that write the mesured fanSpeed + * + * read the memory for the struct + * read the memory for the fanspeed + */ + +uint8_t fanControllerStartAddress = 0x00; +bool alreadyWrittenAblock = false;//false + +uint8_t fanSpeedStartAddress = 0x30; +uint8_t currentFanSpeedAddress = 0x30; + +typedef struct { + uint8_t fanSpeed; +} config_t; + +void checkEEpromIsReady(){ + printf("checking eeprom"); + if (eeprom_is_ready()){ + printf("it is"); + }else{ + printf("its not"); + } +} + +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); + }else{ + eeprom_write_block((config_t*) &writeStruct, &fanControllerStartAddress, structSize); + alreadyWrittenAblock = true;//true + //reurn something + } +} + +config_t ReadStructInEEPROM(){ + //is eeprom ready?? + config_t readStruct; + uint8_t structsize = sizeof(readStruct); + + //checkEEpromIsReady(); + + eeprom_read_block((void *) &readStruct,(void*) &fanControllerStartAddress, structsize); + return readStruct; +} + +void WriteFanSpeedInEEPROM(uint8_t fanSpeed){ + + //checkEEpromIsReady(); + + eeprom_write_byte(currentFanSpeedAddress, fanSpeed); + currentFanSpeedAddress++; +} + +void ReadFanSpeedInfo(){ + //read the space as an array or?? + //eeprom_read_block(); + //this write it too or? + uint8_t len = currentFanSpeedAddress - fanSpeedStartAddress; + uint8_t fanSpeedIterate = 0; + + //checkEEpromIsReady(); + + for (uint8_t i = 0; i Date: Wed, 6 Mar 2024 15:24:34 +0100 Subject: [PATCH 02/11] Fix eeprom EEPROM works --- prosjekt.X/defmplabxtrace.log | 0 prosjekt.X/defmplabxtrace.log.inx | Bin 0 -> 25 bytes prosjekt.X/main.c | 8 ++++---- prosjekt.X/nbproject/configurations.xml | 5 ++++- 4 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 prosjekt.X/defmplabxtrace.log create mode 100644 prosjekt.X/defmplabxtrace.log.inx diff --git a/prosjekt.X/defmplabxtrace.log b/prosjekt.X/defmplabxtrace.log new file mode 100644 index 0000000..e69de29 diff --git a/prosjekt.X/defmplabxtrace.log.inx b/prosjekt.X/defmplabxtrace.log.inx new file mode 100644 index 0000000000000000000000000000000000000000..29197e3a865f7122649ec45edb31854093b4a422 GIT binary patch literal 25 NcmZQzKn1)oE&u?I01f~E literal 0 HcmV?d00001 diff --git a/prosjekt.X/main.c b/prosjekt.X/main.c index 9e43e92..b0fc258 100644 --- a/prosjekt.X/main.c +++ b/prosjekt.X/main.c @@ -67,11 +67,11 @@ uint8_t USART3_read() { * read the memory for the fanspeed */ -uint8_t fanControllerStartAddress = 0x00; +uint8_t EEMEM fanControllerStartAddress = 0x00; bool alreadyWrittenAblock = false;//false -uint8_t fanSpeedStartAddress = 0x30; -uint8_t currentFanSpeedAddress = 0x30; +uint8_t EEMEM fanSpeedStartAddress = 0x30; +uint8_t EEMEM currentFanSpeedAddress = 0x30; typedef struct { uint8_t fanSpeed; @@ -96,7 +96,7 @@ void WriteStructInEEPROM(config_t writeStruct){ if (alreadyWrittenAblock){ eeprom_update_block((void*) &writeStruct,(void*) &fanControllerStartAddress, structSize); }else{ - eeprom_write_block((config_t*) &writeStruct, &fanControllerStartAddress, structSize); + eeprom_write_block(&writeStruct, &fanControllerStartAddress, structSize); alreadyWrittenAblock = true;//true //reurn something } diff --git a/prosjekt.X/nbproject/configurations.xml b/prosjekt.X/nbproject/configurations.xml index d7f88a4..72c428b 100644 --- a/prosjekt.X/nbproject/configurations.xml +++ b/prosjekt.X/nbproject/configurations.xml @@ -28,7 +28,7 @@ AVR128DB48 - noID + nEdbgTool XC8 2.45 2 @@ -165,6 +165,9 @@ + + + From 7008037de9be61159ca35a17a7a48d04b61daf8f Mon Sep 17 00:00:00 2001 From: Elp03 Date: Wed, 6 Mar 2024 15:27:30 +0100 Subject: [PATCH 03/11] Fix EEPROM is ready --- prosjekt.X/main.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/prosjekt.X/main.c b/prosjekt.X/main.c index b0fc258..66887ff 100644 --- a/prosjekt.X/main.c +++ b/prosjekt.X/main.c @@ -79,10 +79,14 @@ typedef struct { void checkEEpromIsReady(){ printf("checking eeprom"); - if (eeprom_is_ready()){ - printf("it is"); - }else{ - printf("its not"); + while(1){ + if (eeprom_is_ready()){ + break; + printf("it is"); + }else{ + ; + printf("its not"); + } } } @@ -107,7 +111,7 @@ config_t ReadStructInEEPROM(){ config_t readStruct; uint8_t structsize = sizeof(readStruct); - //checkEEpromIsReady(); + checkEEpromIsReady(); eeprom_read_block((void *) &readStruct,(void*) &fanControllerStartAddress, structsize); return readStruct; @@ -115,7 +119,7 @@ config_t ReadStructInEEPROM(){ void WriteFanSpeedInEEPROM(uint8_t fanSpeed){ - //checkEEpromIsReady(); + checkEEpromIsReady(); eeprom_write_byte(currentFanSpeedAddress, fanSpeed); currentFanSpeedAddress++; @@ -128,7 +132,7 @@ void ReadFanSpeedInfo(){ uint8_t len = currentFanSpeedAddress - fanSpeedStartAddress; uint8_t fanSpeedIterate = 0; - //checkEEpromIsReady(); + checkEEpromIsReady(); for (uint8_t i = 0; i Date: Wed, 6 Mar 2024 15:49:48 +0100 Subject: [PATCH 04/11] fix source files --- prosjekt.X/eeprom.c | 69 +++++++++++++++++++++++ prosjekt.X/eeprom.h | 41 ++++++++++++++ prosjekt.X/main.c | 75 +------------------------ prosjekt.X/nbproject/configurations.xml | 2 + 4 files changed, 114 insertions(+), 73 deletions(-) create mode 100644 prosjekt.X/eeprom.c create mode 100644 prosjekt.X/eeprom.h diff --git a/prosjekt.X/eeprom.c b/prosjekt.X/eeprom.c new file mode 100644 index 0000000..202da14 --- /dev/null +++ b/prosjekt.X/eeprom.c @@ -0,0 +1,69 @@ +#include "eeprom.h" + +bool alreadyWrittenAblock = false;//false +uint8_t EEMEM currentFanSpeedAddress = 0x30; +uint8_t EEMEM fanControllerStartAddress = 0x00; + + +uint8_t EEMEM fanSpeedStartAddress = 0x30; + + +void checkEEpromIsReady(){ + printf("checking eeprom"); + while(1){ + if (eeprom_is_ready()){ + break; + printf("it is"); + }else{ + ; + printf("its not"); + } + } +} + +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); + }else{ + eeprom_write_block((void*)&writeStruct,(void*) &fanControllerStartAddress, structSize); + alreadyWrittenAblock = true;//true + //reurn something + } +} + +config_t ReadStructInEEPROM(){ + //is eeprom ready?? + config_t readStruct; + uint8_t structsize = sizeof(readStruct); + + checkEEpromIsReady(); + + eeprom_read_block((void *) &readStruct,(void*) &fanControllerStartAddress, structsize); + return readStruct; +} + +void WriteFanSpeedInEEPROM(uint8_t fanSpeed){ + + 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 +#include +#include +#include +#include +#include + + + +typedef struct { + uint8_t fanSpeed; +} config_t; + + +void checkEEpromIsReady(); +void WriteStructInEEPROM(config_t writeStruct); +config_t ReadStructInEEPROM(); +void WriteFanSpeedInEEPROM(uint8_t fanSpeed); +void ReadFanSpeedInfo(); + + +#ifdef __cplusplus +} +#endif + +#endif /* EEPROM_H */ + diff --git a/prosjekt.X/main.c b/prosjekt.X/main.c index 66887ff..dedbf52 100644 --- a/prosjekt.X/main.c +++ b/prosjekt.X/main.c @@ -10,6 +10,8 @@ * * Created on 01 March 2024, 10:34 */ + +#include "eeprom.h" #include #include #include @@ -67,79 +69,6 @@ uint8_t USART3_read() { * read the memory for the fanspeed */ -uint8_t EEMEM fanControllerStartAddress = 0x00; -bool alreadyWrittenAblock = false;//false - -uint8_t EEMEM fanSpeedStartAddress = 0x30; -uint8_t EEMEM currentFanSpeedAddress = 0x30; - -typedef struct { - uint8_t fanSpeed; -} config_t; - -void checkEEpromIsReady(){ - printf("checking eeprom"); - while(1){ - if (eeprom_is_ready()){ - break; - printf("it is"); - }else{ - ; - printf("its not"); - } - } -} - -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); - }else{ - eeprom_write_block(&writeStruct, &fanControllerStartAddress, structSize); - alreadyWrittenAblock = true;//true - //reurn something - } -} - -config_t ReadStructInEEPROM(){ - //is eeprom ready?? - config_t readStruct; - uint8_t structsize = sizeof(readStruct); - - checkEEpromIsReady(); - - eeprom_read_block((void *) &readStruct,(void*) &fanControllerStartAddress, structsize); - return readStruct; -} - -void WriteFanSpeedInEEPROM(uint8_t fanSpeed){ - - checkEEpromIsReady(); - - eeprom_write_byte(currentFanSpeedAddress, fanSpeed); - currentFanSpeedAddress++; -} - -void ReadFanSpeedInfo(){ - //read the space as an array or?? - //eeprom_read_block(); - //this write it too or? - uint8_t len = currentFanSpeedAddress - fanSpeedStartAddress; - uint8_t fanSpeedIterate = 0; - - checkEEpromIsReady(); - - for (uint8_t i = 0; i main.c + eeprom.h + eeprom.c Date: Wed, 6 Mar 2024 20:05:52 +0100 Subject: [PATCH 05/11] fix comments and variable names --- prosjekt.X/eeprom.c | 90 +++++++++++++++++++++++++++++++-------------- prosjekt.X/eeprom.h | 17 +++++++-- 2 files changed, 76 insertions(+), 31 deletions(-) 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 From c48f87bcea7902ec76ab9c7be056455a4f556fab Mon Sep 17 00:00:00 2001 From: Elp03 Date: Wed, 13 Mar 2024 10:34:46 +0100 Subject: [PATCH 06/11] write to update, and uart away. --- prosjekt.X/eeprom.c | 15 ++---- prosjekt.X/main.c | 67 ------------------------- prosjekt.X/nbproject/configurations.xml | 3 ++ 3 files changed, 7 insertions(+), 78 deletions(-) diff --git a/prosjekt.X/eeprom.c b/prosjekt.X/eeprom.c index 5d9f39d..2cc7d24 100644 --- a/prosjekt.X/eeprom.c +++ b/prosjekt.X/eeprom.c @@ -11,9 +11,6 @@ uint8_t EEMEM startAddressFan2 = 0x60; 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(){ while(1){ @@ -39,12 +36,8 @@ void WriteStructInEEPROM(config_t writeStruct){ checkEEpromIsReady(); - if (alreadyWrittenABlock){ - eeprom_update_block((void*) &writeStruct,(void*) &startAddressController, structSize); - }else{ - eeprom_write_block((void*)&writeStruct,(void*) &startAddressController, structSize); - alreadyWrittenABlock = true; - } + eeprom_update_block((void*) &writeStruct,(void*) &startAddressController, structSize); + } // Reads the memory block at the address 0x00 @@ -68,10 +61,10 @@ void WriteDataPointInEEPROM(uint8_t dataPoint, uint8_t data){ checkEEpromIsReady(); if (data == 1){ - eeprom_write_byte(currentAddressFan1, dataPoint); + eeprom_update_byte(currentAddressFan1, dataPoint); currentAddressFan1++; } else if (data == 2){ - eeprom_write_byte(currentAddressFan2, dataPoint); + eeprom_update_byte(currentAddressFan2, dataPoint); currentAddressFan2++; } else{ // error??? diff --git a/prosjekt.X/main.c b/prosjekt.X/main.c index dedbf52..f22e602 100644 --- a/prosjekt.X/main.c +++ b/prosjekt.X/main.c @@ -23,77 +23,10 @@ #define USART3_BAUD_RATE(BAUD_RATE) ((float)(F_CPU * 64 / (16 *(float) BAUD_RATE)) + 0.5) #include -// Init UART comunication -void USART3_init(void) { - // Enable resiver pin - PORTB.DIR &= ~PIN1_bm; - // Enable sender pin - PORTB.DIR |= PIN0_bm; - USART3.BAUD = (uint16_t) USART3_BAUD_RATE(115200); - USART3.CTRLB |= USART_TXEN_bm; - - // Enabled in the USART register - USART3.CTRLB |= USART_RXEN_bm; -} - -// Use printline __________________________ -static void USART3_sendChar(char c) { - while (!(USART3.STATUS & USART_DREIF_bm)) { - ; - } - USART3.TXDATAL = c; -} - -static int USART3_printChar(char c, FILE *stream) { - USART3_sendChar(c); - return 0; -} -static FILE USART_stream = FDEV_SETUP_STREAM(USART3_printChar, NULL, _FDEV_SETUP_WRITE); - -uint8_t USART3_read() { - while (!(USART3.STATUS & USART_RXCIF_bm)) { - ; - } - return USART3.RXDATAL; -} - -/* - * make a struct - * a space is reserved for that struct - * make a function that write the struct to the space - * - * a running counter for where the fanspeed data should be set - * make a function that write the mesured fanSpeed - * - * read the memory for the struct - * read the memory for the fanspeed - */ - void main() { - USART3_init(); - stdout = &USART_stream; - - config_t fanController; - - fanController.fanSpeed = 8; while(1){ - printf("in loop\n"); - printf("Write the struct \n"); - WriteStructInEEPROM(fanController); - - printf("Read struct\n"); - config_t recivedFancontroller = ReadStructInEEPROM(); - - printf("writing in eeprom\n"); - WriteFanSpeedInEEPROM(2); - WriteFanSpeedInEEPROM(3); - WriteFanSpeedInEEPROM(5); - - printf("reading from eeprom\n"); - ReadFanSpeedInfo(); - _delay_ms(500); } } diff --git a/prosjekt.X/nbproject/configurations.xml b/prosjekt.X/nbproject/configurations.xml index 917cf54..808b914 100644 --- a/prosjekt.X/nbproject/configurations.xml +++ b/prosjekt.X/nbproject/configurations.xml @@ -145,6 +145,9 @@ + + + From 4a8b6137d140fee8638b974935649dee05830b58 Mon Sep 17 00:00:00 2001 From: Elp03 Date: Wed, 13 Mar 2024 11:48:58 +0100 Subject: [PATCH 07/11] Change namingsheme --- prosjekt.X/eeprom.c | 68 ++++++++++++------------- prosjekt.X/eeprom.h | 10 ++-- prosjekt.X/nbproject/configurations.xml | 2 +- 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/prosjekt.X/eeprom.c b/prosjekt.X/eeprom.c index 2cc7d24..4eea0c2 100644 --- a/prosjekt.X/eeprom.c +++ b/prosjekt.X/eeprom.c @@ -1,25 +1,23 @@ #include "eeprom.h" // The start address for the controller data -uint8_t EEMEM startAddressController = 0x00; +uint8_t EEMEM start_address_controller = 0x00; // Where the writing of the fans points start -uint8_t EEMEM startAddressFan1 = 0x30; -uint8_t EEMEM startAddressFan2 = 0x60; +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 currentAddressFan1 = 0x30; -uint8_t EEMEM currentAddressFan2 = 0x60; +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 checkEEpromIsReady(){ +void check_eeprom_is_ready(){ while(1){ if (eeprom_is_ready()){ break; - printf("it is"); }else{ ; - printf("its not"); } } } @@ -30,42 +28,42 @@ void checkEEpromIsReady(){ // 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); +void write_struct_in_EEPROM(config_t write_struct){ + uint8_t struct_size; + struct_size = sizeof(write_struct); - checkEEpromIsReady(); + check_eeprom_is_ready(); - eeprom_update_block((void*) &writeStruct,(void*) &startAddressController, structSize); + 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 ReadStructInEEPROM(){ +config_t read_struct_from_EEPROM(){ //is eeprom ready?? - config_t readStruct; - uint8_t structsize = sizeof(readStruct); + config_t read_struct; + uint8_t struct_size = sizeof(read_struct); - checkEEpromIsReady(); + check_eeprom_is_ready(); - eeprom_read_block((void *) &readStruct,(void*) &startAddressController, structsize); - return readStruct; + 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 WriteDataPointInEEPROM(uint8_t dataPoint, uint8_t data){ +void write_data_point_in_EEPROM(uint8_t data_point, uint8_t data){ - checkEEpromIsReady(); + check_eeprom_is_ready(); if (data == 1){ - eeprom_update_byte(currentAddressFan1, dataPoint); - currentAddressFan1++; + eeprom_update_byte(current_address_fan1, data_point); + current_address_fan1++; } else if (data == 2){ - eeprom_update_byte(currentAddressFan2, dataPoint); - currentAddressFan2++; + eeprom_update_byte(current_address_fan2, data_point); + current_address_fan2++; } else{ // error??? ; @@ -74,25 +72,25 @@ void WriteDataPointInEEPROM(uint8_t dataPoint, uint8_t data){ // Reads all the datapoints to the choosen data. // it writes the data points in the USART stream. -void ReadDataPointSpeedInfo(uint8_t data){ - uint8_t dataPoint = 0; +void read_data_point_speed_info(uint8_t data){ + uint8_t data_point = 0; if (data == 1){ - uint8_t len = currentAddressFan1 - startAddressFan1; + uint8_t len = current_address_fan1 - start_address_fan1; - checkEEpromIsReady(); + check_eeprom_is_ready(); for (uint8_t i = 0; i + eeprom.h main.c - eeprom.h eeprom.c Date: Wed, 13 Mar 2024 12:03:40 +0100 Subject: [PATCH 08/11] Fix names --- prosjekt.X/eeprom.c | 30 +++++++++++++++--------------- prosjekt.X/eeprom.h | 8 ++++---- prosjekt.X/main.c | 17 ++--------------- 3 files changed, 21 insertions(+), 34 deletions(-) diff --git a/prosjekt.X/eeprom.c b/prosjekt.X/eeprom.c index 4eea0c2..586ad1a 100644 --- a/prosjekt.X/eeprom.c +++ b/prosjekt.X/eeprom.c @@ -28,7 +28,7 @@ void check_eeprom_is_ready(){ // 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){ +void write_struct_from_EEPROM(config_t write_struct){ uint8_t struct_size; struct_size = sizeof(write_struct); @@ -38,7 +38,7 @@ void write_struct_in_EEPROM(config_t write_struct){ } -// Reads the memory block at the address 0x00 +// Reads the memory block at the address start_address_controller // returns a struct in form of config_t config_t read_struct_from_EEPROM(){ //is eeprom ready?? @@ -55,14 +55,14 @@ config_t read_struct_from_EEPROM(){ // 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){ +void write_data_point_in_EEPROM(uint8_t byte, uint8_t fan_num){ check_eeprom_is_ready(); - if (data == 1){ - eeprom_update_byte(current_address_fan1, data_point); + if (fan_num == 1){ + eeprom_update_byte(current_address_fan1, byte); current_address_fan1++; - } else if (data == 2){ - eeprom_update_byte(current_address_fan2, data_point); + } else if (fan_num == 2){ + eeprom_update_byte(current_address_fan2, byte); current_address_fan2++; } else{ // error??? @@ -72,25 +72,25 @@ void write_data_point_in_EEPROM(uint8_t data_point, uint8_t data){ // 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; +void read_data_point_speed_info(uint8_t fan_num){ + uint8_t byte = 0; - if (data == 1){ + if (fan_num == 1){ uint8_t len = current_address_fan1 - start_address_fan1; check_eeprom_is_ready(); for (uint8_t i = 0; i #include #include -#include #define F_CPU 4E6 -#include -#include -#include -#define USART3_BAUD_RATE(BAUD_RATE) ((float)(F_CPU * 64 / (16 *(float) BAUD_RATE)) + 0.5) -#include - void main() { From bf4f3aaa8124fc2b43865aa4c75dfe0b8ad9925c Mon Sep 17 00:00:00 2001 From: Elp03 Date: Tue, 19 Mar 2024 14:02:10 +0100 Subject: [PATCH 09/11] fix return array --- prosjekt.X/eeprom.c | 9 ++++++--- prosjekt.X/eeprom.h | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/prosjekt.X/eeprom.c b/prosjekt.X/eeprom.c index 586ad1a..dd93d99 100644 --- a/prosjekt.X/eeprom.c +++ b/prosjekt.X/eeprom.c @@ -72,7 +72,7 @@ void write_data_point_in_EEPROM(uint8_t byte, uint8_t fan_num){ // 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 fan_num){ +uint8_t read_data_point_speed_info(uint8_t fan_num, uint8_t *array){ uint8_t byte = 0; if (fan_num == 1){ @@ -81,7 +81,8 @@ void read_data_point_speed_info(uint8_t fan_num){ check_eeprom_is_ready(); for (uint8_t i = 0; i Date: Wed, 20 Mar 2024 10:52:38 +0100 Subject: [PATCH 10/11] Fix return error --- prosjekt.X/eeprom.c | 7 ++++--- prosjekt.X/eeprom.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/prosjekt.X/eeprom.c b/prosjekt.X/eeprom.c index dd93d99..0a7e4d8 100644 --- a/prosjekt.X/eeprom.c +++ b/prosjekt.X/eeprom.c @@ -55,18 +55,19 @@ config_t read_struct_from_EEPROM(){ // 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 byte, uint8_t fan_num){ +int write_data_point_in_EEPROM(uint8_t byte, uint8_t fan_num){ check_eeprom_is_ready(); if (fan_num == 1){ eeprom_update_byte(current_address_fan1, byte); current_address_fan1++; + return 1; } else if (fan_num == 2){ eeprom_update_byte(current_address_fan2, byte); current_address_fan2++; + return 1; } else{ - // error??? - ; + return 0; } } diff --git a/prosjekt.X/eeprom.h b/prosjekt.X/eeprom.h index f3b12ac..b584713 100644 --- a/prosjekt.X/eeprom.h +++ b/prosjekt.X/eeprom.h @@ -36,7 +36,7 @@ void write_struct_from_EEPROM(config_t write_struct); config_t read_struct_from_EEPROM(); // Writes a datapoint in EEPROM -void write_data_point_from_EEPROM(uint8_t byte, uint8_t fan_num); +int write_data_point_from_EEPROM(uint8_t byte, uint8_t fan_num); // Reads all the dataPoints form EEPROM uint8_t read_data_point_speed_info(uint8_t fan_num, uint8_t *array); From 7bcec13f6e60464d2a969cdff1715fe453f4efb3 Mon Sep 17 00:00:00 2001 From: Elp03 Date: Wed, 20 Mar 2024 10:53:46 +0100 Subject: [PATCH 11/11] Merge two lines --- prosjekt.X/eeprom.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/prosjekt.X/eeprom.c b/prosjekt.X/eeprom.c index 0a7e4d8..5dd4616 100644 --- a/prosjekt.X/eeprom.c +++ b/prosjekt.X/eeprom.c @@ -29,8 +29,7 @@ void check_eeprom_is_ready(){ // If true, the infromation is replaced with the intaken struct // else the intaken struct is written at the address. void write_struct_from_EEPROM(config_t write_struct){ - uint8_t struct_size; - struct_size = sizeof(write_struct); + uint8_t struct_size = sizeof(write_struct); check_eeprom_is_ready();