comparison src/avr_jtag.c @ 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 61f27549de57
comparison
equal deleted inserted replaced
2:abf221bf3ce4 3:e410832c3280
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <string.h> 3 #include <string.h>
4 #include <util/delay.h>
4 #include "avriotools.h" 5 #include "avriotools.h"
5 #include "cmd_proto.h" 6 #include "cmd_proto.h"
6 #include "jtag.h" 7 #include "jtag.h"
7 8
8 #define BAUD_RATE 420000 9 #define BAUD_RATE 420000
9 10
10 static char client_buf[255 + CP_CMD_OVERHEAD]; 11 static char client_buf[256 + CP_CMD_OVERHEAD];
11 12
12 static 13 static
13 void ack(int seq) { 14 void ack(int seq) {
14 int i; 15 int i;
15 int sz; 16 int sz;
38 39
39 for(i = 0; i < bsz; i++) 40 for(i = 0; i < bsz; i++)
40 uart_putc(buf[i]); 41 uart_putc(buf[i]);
41 } 42 }
42 43
44 void flash_init(void) {
45 pin_mode(&PORTB, PINB4, PM_OUTPUT);
46 pin_mode(&PORTB, PINB5, PM_OUTPUT);
47 pin_lo(PORTB, PINB4);
48 pin_lo(PORTB, PINB5);
49 }
50
51 void flash_led(void) {
52 pin_hi(PORTB, PINB4);
53 _delay_ms(50);
54 pin_lo(PORTB, PINB4);
55 }
56
43 #define GET_DATA_BITS(data) ((data)[0] | ((data)[1] << 8)) 57 #define GET_DATA_BITS(data) ((data)[0] | ((data)[1] << 8))
44 58
45 int main(int argc, char * const argv[]) { 59 int main(int argc, char * const argv[]) {
46 cp_cmd_t *cmd; 60 cp_cmd_t *cmd;
47 cmd_proto_t *cp; 61 cmd_proto_t *cp;
48 int c, nbits; 62 int c, nbits;
49 int bsz; 63 int bsz;
50 char buf[16]; 64 static char buf[16];
51 65
66 flash_init();
67 flash_led();
68
69 uart_init(BAUD_RATE);
52 jtag_init(); 70 jtag_init();
53 uart_init(BAUD_RATE); 71 cp = cmd_proto_new();
54 72
55 cp = cmd_proto_new();
56
57 while(1) { 73 while(1) {
58 uart_getc(c); 74 uart_getc(c);
59 cmd = cmd_proto_rcv(cp, c); 75 cmd = cmd_proto_rcv(cp, c);
76 if(cmd == NULL)
77 continue;
60 78
61 if(cmd == &BAD_CMD) { 79 if(cmd == &BAD_CMD) {
62 nak(cmd->seq, "BAD CMD"); 80 nak(cmd->seq, "BAD CMD");
63 continue; 81 continue;
64 } 82 }
65 83
66 if(cmd == &CSUM_ERR_CMD) { 84 if(cmd == &CSUM_ERR_CMD) {
67 nak(cmd->seq, "CSUM ERR"); 85 nak(cmd->seq, "CSUM ERR");
68 continue; 86 continue;
69 } 87 }
70 88
71 switch(cmd->code) { 89 switch(cmd->code) {
72 case CPCMD_PING: 90 case CPCMD_PING:
73 memcpy(client_buf + CP_CMD_HEAD_SZ, cmd->data, cmd->data_sz); 91 memcpy(client_buf + CP_CMD_HEAD_SZ, cmd->data, cmd->data_sz);
74 bsz = cmd_proto_cmd_fill(client_buf, cmd->seq, 92 bsz = cmd_proto_cmd_fill(client_buf, cmd->seq,
75 CPCMD_PONG, cmd->data_sz); 93 CPCMD_PONG, cmd->data_sz);