comparison src/avr_jtag.c @ 10:cc106f278d7d

Get identify of components
author Thinker K.F. Li <thinker@branda.to>
date Tue, 24 Feb 2009 13:32:04 +0800
parents 61f27549de57
children
comparison
equal deleted inserted replaced
9:705da39cdf91 10:cc106f278d7d
6 #include "cmd_proto.h" 6 #include "cmd_proto.h"
7 #include "jtag.h" 7 #include "jtag.h"
8 8
9 #define BAUD_RATE 420000 9 #define BAUD_RATE 420000
10 10
11 static char client_buf[256 + CP_CMD_OVERHEAD]; 11 static unsigned char client_buf[256 + CP_CMD_OVERHEAD];
12 12
13 static 13 static
14 void ack(int seq) { 14 void ack(int seq) {
15 int i; 15 int i;
16 int sz; 16 int sz;
20 for(i = 0; i < sz; i++) 20 for(i = 0; i < sz; i++)
21 uart_putc(client_buf[i]); 21 uart_putc(client_buf[i]);
22 } 22 }
23 23
24 static 24 static
25 void nak(int seq, const char *msg) { 25 void nak(int seq, const unsigned char *msg) {
26 int i; 26 int i;
27 int sz; 27 int sz;
28 28
29 memcpy(client_buf + CP_CMD_HEAD_SZ, msg, strlen(msg)); 29 memcpy(client_buf + CP_CMD_HEAD_SZ, msg, strlen(msg));
30 sz = cmd_proto_cmd_fill(client_buf, seq, CPCMD_NAK, 7); 30 sz = cmd_proto_cmd_fill(client_buf, seq, CPCMD_NAK, 7);
32 for(i = 0; i < sz; i++) 32 for(i = 0; i < sz; i++)
33 uart_putc(client_buf[i]); 33 uart_putc(client_buf[i]);
34 } 34 }
35 35
36 static 36 static
37 void send_client(const char *buf, int bsz) { 37 void send_client(const unsigned char *buf, int bsz) {
38 int i; 38 int i;
39 39
40 for(i = 0; i < bsz; i++) 40 for(i = 0; i < bsz; i++)
41 uart_putc(buf[i]); 41 uart_putc(buf[i]);
42 } 42 }
43 43
44 void flash_init(void) { 44 #define GET_DATA_BITS(data) (((unsigned int)(data)[0]) | \
45 pin_mode(&PORTB, PINB4, PM_OUTPUT); 45 ((unsigned int)(data)[1] << 8))
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
57 #define GET_DATA_BITS(data) ((data)[0] | ((data)[1] << 8))
58 46
59 int main(int argc, char * const argv[]) { 47 int main(int argc, char * const argv[]) {
60 cp_cmd_t *cmd; 48 cp_cmd_t *cmd;
61 cmd_proto_t *cp; 49 cmd_proto_t *cp;
62 int c, nbits; 50 int c;
51 unsigned int nbits;
63 int bsz; 52 int bsz;
64 static char buf[16]; 53 static unsigned char buf[16];
65
66 flash_init();
67 flash_led();
68 54
69 uart_init(BAUD_RATE); 55 uart_init(BAUD_RATE);
70 jtag_init(); 56 jtag_init();
71 cp = cmd_proto_new(); 57 cp = cmd_proto_new();
72 58