updated on Thu Jan 19 20:01:47 UTC 2012
[aur-mirror.git] / avrdude-serjtag / patch-avr910.c.diff
blob2e83d7aebe9deddd83f311e3b5f40742e5fe33f0
1 --- avr910.c.orig 2009-03-06 21:09:11.000000000 +0100
2 +++ avr910.c 2009-08-02 22:43:51.000000000 +0200
3 @@ -55,6 +55,10 @@
4 unsigned char use_blockmode;
5 };
7 +static char is_usb = 0;
8 +#define READ_SIZE 64
9 +static unsigned char extra_buf[1024+7];
11 #define PDATA(pgm) ((struct pdata *)(pgm->cookie))
13 static void avr910_setup(PROGRAMMER * pgm)
14 @@ -154,6 +158,7 @@
15 return -1;
18 +static int can_cmd = 0;
21 * initialize the AVR device and prepare it to accept commands
22 @@ -175,11 +180,15 @@
23 avr910_send(pgm, "S", 1);
24 memset (id, 0, sizeof(id));
25 avr910_recv(pgm, id, sizeof(id)-1);
26 + is_usb = !strncmp(id, "USB910",6);
28 /* Get the HW and SW versions to see if the programmer is present. */
30 avr910_send(pgm, "V", 1);
31 avr910_recv(pgm, sw, sizeof(sw));
32 + if (sw[0] == '2') {
33 + can_cmd = 1;
34 + }
36 avr910_send(pgm, "v", 1);
37 avr910_recv(pgm, hw, sizeof(hw));
38 @@ -304,7 +313,7 @@
40 char buf[5];
42 - /* FIXME: Insert version check here */
43 + if (!can_cmd) return -1;
45 buf[0] = '.'; /* New Universal Command */
46 buf[1] = cmd[0];
47 @@ -320,7 +329,7 @@
48 res[2] = cmd[1];
49 res[3] = buf[0];
51 - return 0;
52 + return (buf[1] == 'Y')?0:-1;
56 @@ -518,35 +527,54 @@
57 avr910_set_addr(pgm, addr>>1);
59 while (addr < max_addr) {
60 - page_wr_cmd_pending = 1;
61 - buf[0] = cmd[addr & 0x01];
62 - buf[1] = m->buf[addr];
63 - avr910_send(pgm, buf, sizeof(buf));
64 - avr910_vfy_cmd_sent(pgm, "write byte");
65 + if (is_usb && m->paged) {
66 + int i;
67 + int idx = 0;
68 + extra_buf[idx++] = 'A';
69 + extra_buf[idx++] = (addr>>(8+1)) & 0xff;
70 + extra_buf[idx++] = (addr>>1) & 0xff;
71 + for (i=0; i< page_size; i++) {
72 + extra_buf[idx++] = cmd[(addr+i)&0x01];
73 + extra_buf[idx++] = (addr + i >= max_addr)?0xff:m->buf[addr+i];
74 + }
75 + extra_buf[idx++] = 'A';
76 + extra_buf[idx++] = (addr>>(8+1)) & 0xff;
77 + extra_buf[idx++] = (addr>>1) & 0xff;
78 + extra_buf[idx++] = 'm';
79 + avr910_send(pgm, extra_buf, idx);
80 + avr910_recv(pgm, extra_buf, 3 + page_size);
81 + addr += page_size;
82 + usleep(m->max_write_delay);
83 + } else {
84 + page_wr_cmd_pending = 1;
85 + buf[0] = cmd[addr & 0x01];
86 + buf[1] = m->buf[addr];
87 + avr910_send(pgm, buf, sizeof(buf));
88 + avr910_vfy_cmd_sent(pgm, "write byte");
90 - addr++;
91 - page_bytes--;
92 + addr++;
93 + page_bytes--;
95 - if (m->paged && (page_bytes == 0)) {
96 - /* Send the "Issue Page Write" if we have sent a whole page. */
97 + if (m->paged && (page_bytes == 0)) {
98 + /* Send the "Issue Page Write" if we have sent a whole page. */
100 - avr910_set_addr(pgm, page_addr>>1);
101 - avr910_send(pgm, "m", 1);
102 - avr910_vfy_cmd_sent(pgm, "flush page");
103 + avr910_set_addr(pgm, page_addr>>1);
104 + avr910_send(pgm, "m", 1);
105 + avr910_vfy_cmd_sent(pgm, "flush page");
107 - page_wr_cmd_pending = 0;
108 - usleep(m->max_write_delay);
109 - avr910_set_addr(pgm, addr>>1);
110 + page_wr_cmd_pending = 0;
111 + usleep(m->max_write_delay);
112 + avr910_set_addr(pgm, addr>>1);
114 - /* Set page address for next page. */
115 + /* Set page address for next page. */
117 - page_addr = addr;
118 - page_bytes = page_size;
120 - else if ((PDATA(pgm)->has_auto_incr_addr != 'Y') && ((addr & 0x01) == 0)) {
121 - avr910_set_addr(pgm, addr>>1);
122 + page_addr = addr;
123 + page_bytes = page_size;
125 + else if ((PDATA(pgm)->has_auto_incr_addr != 'Y') && ((addr & 0x01) == 0)) {
126 + avr910_set_addr(pgm, addr>>1);
130 report_progress (addr, max_addr, NULL);
133 @@ -676,24 +704,36 @@
134 avr910_set_addr(pgm, addr);
136 while (addr < max_addr) {
137 - avr910_send(pgm, &cmd, 1);
138 - if (cmd == 'R') {
139 - /* The 'R' command returns two bytes, MSB first, we need to put the data
140 - into the memory buffer LSB first. */
141 - avr910_recv(pgm, buf, 2);
142 - m->buf[addr*2] = buf[1]; /* LSB */
143 - m->buf[addr*2+1] = buf[0]; /* MSB */
145 - else {
146 - avr910_recv(pgm, (char *)&m->buf[addr], 1);
147 + if (is_usb && cmd == 'R') {
148 + int i;
149 + for (i=0; i<READ_SIZE/2; i++) {
150 + extra_buf[i] = 'R';
152 + avr910_send(pgm, extra_buf, READ_SIZE/2);
153 + avr910_recv(pgm, extra_buf, READ_SIZE);
154 + for (i=0; i< READ_SIZE; i+=2) {
155 + m->buf[addr*2+i] = extra_buf[i+1]; /* LSB */
156 + m->buf[addr*2+i+1] = extra_buf[i]; /* MSB */
158 + addr += READ_SIZE/2;
159 + } else {
160 + avr910_send(pgm, &cmd, 1);
161 + if (cmd == 'R') {
162 + /* The 'R' command returns two bytes, MSB first, we need to put the data
163 + into the memory buffer LSB first. */
164 + avr910_recv(pgm, buf, 2);
165 + m->buf[addr*2] = buf[1]; /* LSB */
166 + m->buf[addr*2+1] = buf[0]; /* MSB */
167 + } else {
168 + avr910_recv(pgm, (char *)&m->buf[addr], 1);
171 + addr++;
173 + if (PDATA(pgm)->has_auto_incr_addr != 'Y') {
174 + avr910_set_addr(pgm, addr);
178 - addr++;
180 - if (PDATA(pgm)->has_auto_incr_addr != 'Y') {
181 - avr910_set_addr(pgm, addr);
184 report_progress (addr, max_addr, NULL);