summaryrefslogtreecommitdiff
path: root/src/br24t_eeprom_driver.c
diff options
context:
space:
mode:
authorBrett Weiland <brett_weiland@bpcsapce.com>2023-01-12 13:41:48 -0600
committerBrett Weiland <brett_weiland@bpcsapce.com>2023-01-12 13:41:48 -0600
commitb666668d0e6b67e4632e65486cae814ab5abbc39 (patch)
tree0cf0c2d689799c5e98d505e632248fdc5ed5a072 /src/br24t_eeprom_driver.c
parent94304b11e7220f060dbc345de5fa1952d0465016 (diff)
updating for linkedin
Diffstat (limited to 'src/br24t_eeprom_driver.c')
-rw-r--r--src/br24t_eeprom_driver.c71
1 files changed, 58 insertions, 13 deletions
diff --git a/src/br24t_eeprom_driver.c b/src/br24t_eeprom_driver.c
index 2fc0bd0..68e64cb 100644
--- a/src/br24t_eeprom_driver.c
+++ b/src/br24t_eeprom_driver.c
@@ -21,22 +21,66 @@
#ifdef FLASH_EEPROM
+int main() {
+ LED_DEBUG_DDR |= _BV(LED_DEBUG); //TODO move to debug file or somethin
+ LED_DEBUG_PORT &= ~(_BV(LED_DEBUG));
+ i2c_init();
+
+ uart_debug_init();
+ FILE stdout_replacement = FDEV_SETUP_STREAM((void *)uart_debug_sendbyte, NULL, _FDEV_SETUP_WRITE);
+ FILE stdin_replacement = FDEV_SETUP_STREAM(NULL, (void *)uart_debug_recvbyte, _FDEV_SETUP_READ);
+ stdout = &stdout_replacement;
+ stdin = &stdin_replacement;
+ printf("booted\r\n\r\n");
+
+ uart_flash_init();
+ flash_eeprom();
+ return 0;
+
+}
+
void flash_eeprom() {
- uint16_t page_len;
- uint8_t on_byte;
+ unsigned int page_len;
+ unsigned int on_byte;
uint8_t eeprom_buffer_out[EEPROM_PAGE_SIZE];
uint8_t eeprom_buffer_in[EEPROM_PAGE_SIZE];
+
+ /**
+ FILE master_f = FDEV_SETUP_STREAM((void *)uart_flash_sendbyte, NULL, _FDEV_SETUP_WRITE);
+ **/
+ FILE master_fin = FDEV_SETUP_STREAM(NULL, (void *)uart_flash_recvbyte, _FDEV_SETUP_READ);
+ FILE master_fout = FDEV_SETUP_STREAM((void *)uart_flash_sendbyte, NULL, _FDEV_SETUP_WRITE);
- fread(&page_len, 1, 1, stdin);
+ FILE master_f;
+ char temp_buffer[15];
+ int blah = 0;
+ int debug = 0;
+ unsigned int tots_blah = 0;
+ for(;;) {
+ if(blah > 9) blah = 0;
+ blah++;
+ tots_blah++;
+ debug = fread(temp_buffer, 12, 1, &master_fin);
+ printf("PACKET %i : fread status: %i, error: %i, eof: %i\r\n", tots_blah, debug, ferror(&master_fin), feof(&master_fin));
+ printf("recv: %s\r\n\r\n\r\n", temp_buffer);
+ snprintf(temp_buffer, 12, "debugstr %i\r\n", blah);
+ printf("sending \"%s\"...\r\n", temp_buffer);
+ fwrite(temp_buffer, 12, 1, &master_fout);
+ memset(temp_buffer, 0, 12);
+ }
+
+ printf("waiting for master\r\n");
+
+ fread(&page_len, 1, 1, &master_f);
+ printf("%i pages total\r\n", page_len);
- for(int page = 0; page < page_len; page -= page_len) {
+ for(int page = 0; page < page_len; page++) {
+ printf("writing page %i...\r\n", page);
+
- fread(eeprom_buffer_out, EEPROM_PAGE_SIZE, 1, stdin);
- //fread(eeprom_buffer_out, 11, 1, stdin);
- fputc(PAGE_WRITE_CORRUPTED, stdout);
+ fread(eeprom_buffer_out, EEPROM_PAGE_SIZE, 1, &master_f);
+ fputc(PAGE_WRITE_CORRUPTED, &master_f);
- DEBUG_LED_ON();
- for(;;);
i2c_start(EEPROM_I2C_ADDR, I2C_READ);
i2c_send((uint8_t)(page * EEPROM_PAGE_SIZE) & 0xff);
@@ -53,11 +97,12 @@ void flash_eeprom() {
eeprom_buffer_in[on_byte] = i2c_recv();
i2c_stop();
- if(!memcmp(eeprom_buffer_in, eeprom_buffer_out, EEPROM_PAGE_SIZE)) {
- fputc(PAGE_WRITE_CORRUPTED, stdout);
- for(;;); //TODO error here
+ if(memcmp(eeprom_buffer_in, eeprom_buffer_out, EEPROM_PAGE_SIZE)) {
+ fputc(PAGE_WRITE_CORRUPTED, &master_f);
+ printf("invalid checksum on page %i!", page);
}
- fputc(PAGE_WRITE_OK, stdout);
+ fputc(PAGE_WRITE_OK, &master_f);
}
+ printf("If you ever read this, you should be happy\r\n");
}
#endif