summaryrefslogtreecommitdiffstats
path: root/sw/programmer/avr
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sw/programmer/avr/fileinfo.h13
-rw-r--r--sw/programmer/avr/main.c42
-rw-r--r--sw/programmer/avr/makefile2
3 files changed, 27 insertions, 30 deletions
diff --git a/sw/programmer/avr/fileinfo.h b/sw/programmer/avr/fileinfo.h
deleted file mode 100644
index 6c831ed..0000000
--- a/sw/programmer/avr/fileinfo.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef __FILEINFO_H__
-#define __FILEINFO_H__
-
-#include <stdio.h>
-
-struct file_info
-{
- size_t size;
- size_t blklen;
- uint16_t start_addr;
-};
-
-#endif
diff --git a/sw/programmer/avr/main.c b/sw/programmer/avr/main.c
index 90d05fa..9cdc35d 100644
--- a/sw/programmer/avr/main.c
+++ b/sw/programmer/avr/main.c
@@ -1,5 +1,6 @@
-#include "fileinfo.h"
#include "usart.h"
+
+#include <stdio.h>
#include <util/delay.h>
#define EEPROM_TICK_MS 10
@@ -18,6 +19,11 @@
#define EEPROM_RD 1
#define EEPROM_CLK 2
+struct file_blk
+{
+ uint16_t addr;
+ uint16_t size;
+};
void eeprom_write(uint16_t addr, uint8_t byte);
void eeprom_tick();
@@ -25,10 +31,10 @@ void eeprom_tick();
int main(void)
{
uint8_t *buffer, i;
- uint16_t addr;
size_t read;
+ char str[64];
- struct file_info *finfo = malloc(sizeof(struct file_info));
+ struct file_blk *blk = malloc(sizeof(struct file_blk));
DDRB = 0x7F;
DDRC = 0x83;
@@ -36,28 +42,32 @@ int main(void)
/* get configuration */
usart_init(1200);
+ usart_print("programmer Ready\n<waiting for binary>\n\r");
- usart_print("EEPROM Programmer\n\r");
-
- do {
- usart_print("Waiting for configuration\n\r");
- read = usart_read((uint8_t *) finfo, sizeof(struct file_info));
- } while (read != sizeof(struct file_info));
+ while (usart_read((uint8_t *) blk, sizeof(struct file_blk))) {
+ buffer = malloc(blk->size);
+ read = usart_read(buffer, blk->size);
- usart_print("Programmer Ready\n<waiting for binary>\n\r");
+#ifdef DEBUG
+ sprintf(str, "info : reading block from addr %d of size %d\n\r",
+ blk->addr, blk->size);
+ usart_print(str);
- buffer = malloc(finfo->blklen);
- addr = finfo->start_addr;
+ if (read != blk->size) {
+ sprintf(str, "error: expected %d but read %d\n\r",
+ blk->size, read);
+ usart_print(str);
+ }
+#endif
- /* read file */
- while ((read = usart_read(buffer, finfo->blklen))) {
for (i = 0; i < read; i++) {
- eeprom_write(addr + i, *(buffer++));
+ eeprom_write(blk->addr +i, buffer[i]);
}
- addr += finfo->blklen;
+ free(buffer);
}
+ free(blk);
return 0;
}
diff --git a/sw/programmer/avr/makefile b/sw/programmer/avr/makefile
index 95fb5fe..ba2a709 100644
--- a/sw/programmer/avr/makefile
+++ b/sw/programmer/avr/makefile
@@ -12,7 +12,7 @@ PORT := /dev/ttyUSB0
MCU := atmega328p
CFLAGS := -g -Wall -mcall-prologues -mmcu=$(MCU) -Os -I . \
- -DF_CPU=1000000UL
+ -DF_CPU=1000000UL -DDEBUG
LDFLAGS := -Wl,-gc-sections -Wl,-relax
.PHONY: all clean program