summaryrefslogtreecommitdiff
path: root/src/br24t_eeprom_driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/br24t_eeprom_driver.c')
-rw-r--r--src/br24t_eeprom_driver.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/br24t_eeprom_driver.c b/src/br24t_eeprom_driver.c
index 53165d3..2fc0bd0 100644
--- a/src/br24t_eeprom_driver.c
+++ b/src/br24t_eeprom_driver.c
@@ -1,6 +1,12 @@
+#include <avr/io.h>
#include <stdio.h>
+#include <string.h>
+#include <util/delay.h>
#include "i2c.h"
#include "br24t_eeprom_driver.h"
+#include "uart.h"
+#include "pins.h"
+#include "debug.h"
#define EEPROM_ADDR 0x57
#define EEPROM_PAGE_SIZE 64
@@ -13,29 +19,24 @@
#define PAGE_WRITE_CORRUPTED 0x01
#define PAGE_WRITE_UNKNOWN_ERROR 0xff
-//we need another function cause it's got a 16 bit register address
#ifdef FLASH_EEPROM
void flash_eeprom() {
- uint16_t data_len;
- uint32_t syn = 0;
+ uint16_t page_len;
uint8_t on_byte;
uint8_t eeprom_buffer_out[EEPROM_PAGE_SIZE];
uint8_t eeprom_buffer_in[EEPROM_PAGE_SIZE];
- while(syn != MAGIC_SYN) fread(&syn, 4, 1, stdin); //not sure we _really_ need to do this?
+ fread(&page_len, 1, 1, stdin);
- //this feels ugly
- syn = MAGIC_ACK;
- fwrite(&syn, 4, 1, stdout);
-
- //get amount of data we'll be using
- data_len = uart_recvbyte();
- data_len |= (uart_recvbyte() >> 8);
-
- for(int page = 0; page < (data_len / EEPROM_PAGE_SIZE); data_len -= EEPROM_PAGE_SIZE) {
+ for(int page = 0; page < page_len; page -= page_len) {
fread(eeprom_buffer_out, EEPROM_PAGE_SIZE, 1, stdin);
+ //fread(eeprom_buffer_out, 11, 1, stdin);
+ fputc(PAGE_WRITE_CORRUPTED, stdout);
+
+ DEBUG_LED_ON();
+ for(;;);
i2c_start(EEPROM_I2C_ADDR, I2C_READ);
i2c_send((uint8_t)(page * EEPROM_PAGE_SIZE) & 0xff);
@@ -52,9 +53,9 @@ void flash_eeprom() {
eeprom_buffer_in[on_byte] = i2c_recv();
i2c_stop();
- if(memcmp(eeprom_buffer_in, eeprom_buffer_out, EEPROM_PAGE_SIZE)) {
+ if(!memcmp(eeprom_buffer_in, eeprom_buffer_out, EEPROM_PAGE_SIZE)) {
fputc(PAGE_WRITE_CORRUPTED, stdout);
- error();
+ for(;;); //TODO error here
}
fputc(PAGE_WRITE_OK, stdout);
}