changeset 3:e410832c3280

Issue of avr-ld. - For some unknown reason, avr-ld can not handle multiple objects well. - Fixed by compile all source at once.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 22 Feb 2009 01:40:36 +0800
parents abf221bf3ce4
children 6b1594fb668f
files src/Makefile src/avr_jtag.c src/cmd_proto.c tests/cp_ping.py tests/cptest.c
diffstat 5 files changed, 33 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile	Sat Feb 21 23:06:50 2009 +0800
+++ b/src/Makefile	Sun Feb 22 01:40:36 2009 +0800
@@ -1,4 +1,4 @@
-CFLAGS =	-DF_CPU=16000000UL -mmcu=atmega168 -I../include -O2
+CFLAGS =	-DF_CPU=16000000UL -mmcu=atmega168 -I../include -O
 AVR_JTAG_OBJS =	\
 	avr_jtag.o	\
 	avriotools.o	\
@@ -13,8 +13,8 @@
 avr_jtag.hex: avr_jtag
 	$(OBJCOPY) -O ihex -R .eeprom $(.ALLSRC) $@
 
-avr_jtag: $(AVR_JTAG_OBJS)
-	$(CC) -o $@ $(.ALLSRC)
+avr_jtag: $(AVR_JTAG_OBJS:C/\.o/.c/)
+	$(CC) $(CFLAGS) -o $@ $(.ALLSRC)
 
 $(AVR_JTAG_OBJS): ${@:C/\.o/.c/}
 	$(CC) $(CFLAGS) -c $(.ALLSRC)
@@ -30,4 +30,4 @@
 			echo "delete $$f"; \
 			rm -f $$f; \
 		fi; \
-	done
\ No newline at end of file
+	done
--- a/src/avr_jtag.c	Sat Feb 21 23:06:50 2009 +0800
+++ b/src/avr_jtag.c	Sun Feb 22 01:40:36 2009 +0800
@@ -1,13 +1,14 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <util/delay.h>
 #include "avriotools.h"
 #include "cmd_proto.h"
 #include "jtag.h"
 
 #define BAUD_RATE 420000
 
-static char client_buf[255 + CP_CMD_OVERHEAD];
+static char client_buf[256 + CP_CMD_OVERHEAD];
 
 static
 void ack(int seq) {
@@ -40,6 +41,19 @@
 	uart_putc(buf[i]);
 }
 
+void flash_init(void) {
+    pin_mode(&PORTB, PINB4, PM_OUTPUT);
+    pin_mode(&PORTB, PINB5, PM_OUTPUT);
+    pin_lo(PORTB, PINB4);
+    pin_lo(PORTB, PINB5);
+}
+
+void flash_led(void) {
+    pin_hi(PORTB, PINB4);
+    _delay_ms(50);
+    pin_lo(PORTB, PINB4);
+}
+
 #define GET_DATA_BITS(data) ((data)[0] | ((data)[1] << 8))
 
 int main(int argc, char * const argv[]) {
@@ -47,16 +61,20 @@
     cmd_proto_t *cp;
     int c, nbits;
     int bsz;
-    char buf[16];
+    static char buf[16];
     
-    jtag_init();
+    flash_init();
+    flash_led();
+    
     uart_init(BAUD_RATE);
-
+    jtag_init();
     cp = cmd_proto_new();
-    
+
     while(1) {
 	uart_getc(c);
 	cmd = cmd_proto_rcv(cp, c);
+	if(cmd == NULL)
+	    continue;
 
 	if(cmd == &BAD_CMD) {
 	    nak(cmd->seq, "BAD CMD");
@@ -67,7 +85,7 @@
 	    nak(cmd->seq, "CSUM ERR");
 	    continue;
 	}
-	
+
 	switch(cmd->code) {
 	case CPCMD_PING:
 	    memcpy(client_buf + CP_CMD_HEAD_SZ, cmd->data, cmd->data_sz);
--- a/src/cmd_proto.c	Sat Feb 21 23:06:50 2009 +0800
+++ b/src/cmd_proto.c	Sun Feb 22 01:40:36 2009 +0800
@@ -12,10 +12,12 @@
     ST_WAIT_CSUM
 };
 
+#define BUF_SZ 512
+
 cmd_proto_t *cmd_proto_new(void) {
     cmd_proto_t *cp;
 
-    cp = (cmd_proto_t *)malloc(sizeof(cmd_proto_t) + 512);
+    cp = (cmd_proto_t *)malloc(sizeof(cmd_proto_t) + BUF_SZ);
     if(cp == NULL)
 	return NULL;
     
--- a/tests/cp_ping.py	Sat Feb 21 23:06:50 2009 +0800
+++ b/tests/cp_ping.py	Sun Feb 22 01:40:36 2009 +0800
@@ -1,7 +1,6 @@
 import struct
 
 CP_CMD_PING = 1
-CP_CMD_PONG = 2
 
 def csum_add(csum, c):
     return (((csum << 3) | (csum >> 5)) ^ c) & 0xff
--- a/tests/cptest.c	Sat Feb 21 23:06:50 2009 +0800
+++ b/tests/cptest.c	Sun Feb 22 01:40:36 2009 +0800
@@ -30,9 +30,9 @@
     flash_init();
     
     uart_init(BAUD_RATE);
-
+    
     cp = cmd_proto_new();
-
+    
     while(1) {
 	uart_getc(c);
 	cmd = cmd_proto_rcv(cp, c);