Root/avrdude/patches/nanonote.patch

1Index: avrdude-5.11.1/Makefile.am
2===================================================================
3--- avrdude-5.11.1.orig/Makefile.am 2012-07-22 10:38:55.281926086 -0300
4+++ avrdude-5.11.1/Makefile.am 2012-07-22 10:39:01.946145199 -0300
5@@ -118,6 +118,8 @@
6     lists.c \
7     lists.h \
8     my_ddk_hidsdi.h \
9+ nanonote.c \
10+ nanonote.h \
11     par.c \
12     par.h \
13     pgm.c \
14Index: avrdude-5.11.1/config_gram.y
15===================================================================
16--- avrdude-5.11.1.orig/config_gram.y 2012-07-22 10:38:55.261925424 -0300
17+++ avrdude-5.11.1/config_gram.y 2012-07-22 10:39:01.946145199 -0300
18@@ -50,6 +50,7 @@
19 #include "jtagmkI.h"
20 #include "jtagmkII.h"
21 #include "avrftdi.h"
22+#include "nanonote.h"
23 
24 #if defined(WIN32NATIVE)
25 #define strtok_r( _s, _sep, _lasts ) \
26@@ -103,6 +104,7 @@
27 %token K_DRAGON_JTAG
28 %token K_DRAGON_PDI
29 %token K_DRAGON_PP
30+%token K_NANONOTE
31 %token K_STK500_DEVCODE
32 %token K_AVR910_DEVCODE
33 %token K_EEPROM
34@@ -587,6 +589,12 @@
35     }
36   } |
37 
38+ K_TYPE TKN_EQUAL K_NANONOTE {
39+ {
40+ nanonote_initpgm(current_prog);
41+ }
42+ } |
43+
44   K_DESC TKN_EQUAL TKN_STRING {
45     strncpy(current_prog->desc, $3->value.string, PGM_DESCLEN);
46     current_prog->desc[PGM_DESCLEN-1] = 0;
47Index: avrdude-5.11.1/lexer.l
48===================================================================
49--- avrdude-5.11.1.orig/lexer.l 2012-07-22 10:38:55.269925685 -0300
50+++ avrdude-5.11.1/lexer.l 2012-07-22 10:39:01.946145199 -0300
51@@ -168,6 +168,7 @@
52 min_write_delay { yylval=NULL; return K_MIN_WRITE_DELAY; }
53 miso { yylval=NULL; return K_MISO; }
54 mosi { yylval=NULL; return K_MOSI; }
55+nanonote { yylval=NULL; return K_NANONOTE; }
56 num_banks { yylval=NULL; return K_NUM_PAGES; }
57 num_pages { yylval=NULL; return K_NUM_PAGES; }
58 nvm_base { yylval=NULL; return K_NVM_BASE; }
59Index: avrdude-5.11.1/nanonote.c
60===================================================================
61--- /dev/null 1970-01-01 00:00:00.000000000 +0000
62+++ avrdude-5.11.1/nanonote.c 2012-07-22 10:47:07.398111708 -0300
63@@ -0,0 +1,378 @@
64+/*
65+ * avrdude - A Downloader/Uploader for AVR device programmers
66+ * Copyright (C) 2000, 2001, 2002, 2003 Brian S. Dean <bsd@bsdhome.com>
67+ * Copyright (C) 2005 Michael Holzt <kju-avr@fqdn.org>
68+ * Copyright (C) 2006 Joerg Wunsch <j@uriah.heep.sax.de>
69+ *
70+ * This program is free software; you can redistribute it and/or modify
71+ * it under the terms of the GNU General Public License as published by
72+ * the Free Software Foundation; either version 2 of the License, or
73+ * (at your option) any later version.
74+ *
75+ * This program is distributed in the hope that it will be useful,
76+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
77+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
78+ * GNU General Public License for more details.
79+ *
80+ * You should have received a copy of the GNU General Public License
81+ * along with this program; if not, write to the Free Software
82+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
83+ */
84+
85+/*
86+ * Posix serial bitbanging interface for avrdude.
87+ */
88+
89+
90+#include <stdint.h>
91+#include <stdlib.h>
92+#include <stdio.h>
93+#include <unistd.h>
94+#include <string.h>
95+#include <fcntl.h>
96+#include <sys/mman.h>
97+
98+#include "avr.h"
99+#include "pgm.h"
100+#include "bitbang.h"
101+
102+
103+struct pdata {
104+ unsigned clk; /* clock output on CLK; 0 if none */
105+};
106+
107+#define PDATA(pgm) ((struct pdata *) (pgm)->cookie)
108+
109+
110+static volatile void *mem;
111+
112+
113+#define PLL_CLK 336 /* PLL runs at 336 MHz */
114+
115+#define POWER_OFF 3, 2 /* PD02, drive low to enable power */
116+#define CMD 3, 8 /* PD08, CMD */
117+#define CLK 3, 9 /* PD09, CLK */
118+#define DAT0 3, 10 /* PD10, DAT0 */
119+#define DAT1 3, 11 /* PD11, DAT1 */
120+#define DAT2 3, 12 /* PD12, DAT2 */
121+#define DAT3 3, 13 /* PD13, DAT3 */
122+
123+
124+static struct {
125+ unsigned port;
126+ unsigned bit;
127+} pin_map[] = {
128+ { 0, 0 }, /* 0: not assigned */
129+ { DAT1 }, /* 1: PD11, DAT1 */
130+ { DAT0 }, /* 2: PD10, DAT0 */
131+ { 0, 0 }, /* 3: VSS */
132+ { CLK }, /* 4: PD09, CLK (also used for clock output) */
133+ { 0, 0 }, /* 5: VDD */
134+ { CMD }, /* 6: PD08, CMD */
135+ { DAT3 }, /* 7: PD13, DAT3 */
136+ { DAT2 } /* 8: PD12, DAT2 */
137+};
138+
139+#define PIN_IDX_CLK 4
140+
141+
142+#define BASE 0x10000000
143+#define REG_WINDOW 0x30000
144+
145+#define REG(off) (*(volatile uint32_t *) (mem+(off)))
146+
147+#define CGU(n) REG(0x00000+(n))
148+#define GPIO(n) REG(0x10000+(n))
149+#define MSC(n) REG(0x21000+(n))
150+
151+#define port_pin(port) GPIO(port*0x100)
152+#define port_dats(port) GPIO(port*0x100+0x14)
153+#define port_datc(port) GPIO(port*0x100+0x18)
154+#define port_funs(port) GPIO(port*0x100+0x44)
155+#define port_func(port) GPIO(port*0x100+0x48)
156+#define port_dirs(port) GPIO(port*0x100+0x64)
157+#define port_dirc(port) GPIO(port*0x100+0x68)
158+
159+#define MSC_STRPCL MSC(0x00) /* Start/stop MMC/SD clock */
160+#define MSC_CLKRT MSC(0x08) /* MSC Clock Rate */
161+
162+#define CLKGR CGU(0x0020) /* Clock Gate */
163+#define MSCCDR CGU(0x0068) /* MSC device clock divider */
164+
165+
166+static inline void gpio_high(unsigned port, unsigned bit)
167+{
168+ port_dats(port) = 1 << bit;
169+}
170+
171+
172+static void gpio_low(unsigned port, unsigned bit)
173+{
174+ port_datc(port) = 1 << bit;
175+}
176+
177+
178+static void gpio_set(unsigned port, unsigned bit, int value)
179+{
180+ if (value)
181+ gpio_high(port, bit);
182+ else
183+ gpio_low(port, bit);
184+}
185+
186+
187+static int gpio_get(unsigned port, unsigned bit)
188+{
189+ return (port_pin(port) >> bit) & 1;
190+}
191+
192+
193+static void gpio_output(unsigned port, unsigned bit)
194+{
195+ port_dirs(port) = 1 << bit;
196+}
197+
198+
199+static void gpio_input(unsigned port, unsigned bit)
200+{
201+ port_dirc(port) = 1 << bit;
202+}
203+
204+
205+static void gpio_function(unsigned port, unsigned bit, int on)
206+{
207+ if (on)
208+ port_funs(port) = 1 << bit;
209+ else
210+ port_func(port) = 1 << bit;
211+}
212+
213+
214+static int nanonote_setpin(PROGRAMMER *pgm, int pin, int value)
215+{
216+ if (pin & PIN_INVERSE) {
217+ value = !value;
218+ pin &= PIN_MASK;
219+ }
220+
221+ if (pin < 1 || pin >= sizeof(pin_map)/sizeof(*pin_map))
222+ return -1;
223+ if (!pin_map[pin].port)
224+ return -1;
225+
226+#if 0
227+fprintf(stderr, "pin %d (%u, %u) = %d\n",
228+pin, pin_map[pin].port, pin_map[pin].bit, value);
229+#endif
230+ gpio_set(pin_map[pin].port, pin_map[pin].bit, value);
231+
232+ /*
233+ * We get unstable results with values <= 16 but stable results
234+ * with 17 and above.
235+ */
236+ bitbang_delay(pgm->ispdelay+20);
237+
238+ return 0;
239+}
240+
241+
242+static int nanonote_getpin(PROGRAMMER *pgm, int pin)
243+{
244+ int invert = 0;
245+ int v;
246+
247+ if (pin & PIN_INVERSE) {
248+ invert = 1;
249+ pin &= PIN_MASK;
250+ }
251+
252+ if (pin < 1 || pin >= sizeof(pin_map)/sizeof(*pin_map))
253+ return -1;
254+ if (!pin_map[pin].port)
255+ return -1;
256+ if (pin == PIN_IDX_CLK && PDATA(pgm)->clk)
257+ return -1;
258+
259+ gpio_input(pin_map[pin].port, pin_map[pin].bit); /* @@@ hack */
260+ v = gpio_get(pin_map[pin].port, pin_map[pin].bit);
261+#if 0
262+fprintf(stderr, "pin %d (%u, %u): %d\n",
263+pin, pin_map[pin].port, pin_map[pin].bit, v);
264+#endif
265+ return invert ? !v : v;
266+}
267+
268+
269+static int nanonote_highpulsepin(PROGRAMMER *pgm, int pin)
270+{
271+ return -1;
272+}
273+
274+
275+static void nanonote_display(PROGRAMMER *pgm, const char *p)
276+{
277+ /* nothing */
278+}
279+
280+
281+static void misc_high(PROGRAMMER *pgm)
282+{
283+ gpio_high(POWER_OFF);
284+ gpio_high(DAT1);
285+ gpio_high(DAT0);
286+ gpio_high(CMD);
287+ gpio_high(DAT3);
288+ gpio_high(DAT2);
289+ gpio_function(CLK, 0); /* set CLK to GPIO */
290+ gpio_high(CLK);
291+}
292+
293+
294+static void nanonote_enable(PROGRAMMER *pgm)
295+{
296+ int div, log2 = 0;
297+
298+ misc_high(pgm);
299+ if (!PDATA(pgm)->clk)
300+ return;
301+
302+ /* give the bus clock output to the MMC controller */
303+ gpio_function(CLK, 1);
304+
305+ /*
306+ * set the MSC clock divider, dividing the 316 MHz system clock
307+ */
308+ div = PLL_CLK/PDATA(pgm)->clk;
309+ if (PLL_CLK % PDATA(pgm)->clk)
310+ div++;
311+ while (div > 32) {
312+ log2++;
313+ div = (div+1)/2;
314+ }
315+ MSCCDR = div-1;
316+
317+ /*
318+ * Enable the MSC clock. We need to do this before accessing any
319+ * registers of the MSC block !
320+ */
321+ CLKGR &= ~(1 << 7);
322+
323+ /* bus clock = MSC clock / 2^log2 */
324+ MSC_CLKRT = log2;
325+
326+ /* start MMC clock output */
327+ MSC_STRPCL = 2;
328+}
329+
330+
331+static void nanonote_disable(PROGRAMMER *pgm)
332+{
333+ misc_high(pgm);
334+}
335+
336+
337+static void nanonote_powerup(PROGRAMMER *pgm)
338+{
339+ gpio_low(POWER_OFF);
340+}
341+
342+
343+static void nanonote_powerdown(PROGRAMMER *pgm)
344+{
345+ gpio_input(DAT0);
346+ gpio_input(CLK);
347+ gpio_input(CMD);
348+ gpio_input(DAT3);
349+ gpio_input(DAT2);
350+ gpio_input(DAT1);
351+ gpio_high(POWER_OFF);
352+}
353+
354+
355+static int nanonote_open(PROGRAMMER *pgm, char *port)
356+{
357+ bitbang_check_prerequisites(pgm);
358+
359+ pgm->fd.ifd = open("/dev/mem", O_RDWR | O_SYNC);
360+ if (pgm->fd.ifd < 0) {
361+ perror("/dev/mem");
362+ return -1;
363+ }
364+ mem = mmap(NULL, REG_WINDOW, PROT_READ | PROT_WRITE, MAP_SHARED,
365+ pgm->fd.ifd, BASE);
366+ if (mem == MAP_FAILED) {
367+ perror("mmap");
368+ return -1;
369+ }
370+
371+ gpio_output(POWER_OFF);
372+ gpio_output(DAT0);
373+ gpio_output(CLK);
374+ gpio_output(CMD);
375+ gpio_output(DAT3);
376+ gpio_output(DAT2);
377+ gpio_output(DAT1);
378+
379+ nanonote_disable(pgm);
380+
381+ return 0;
382+}
383+
384+
385+static void nanonote_close(PROGRAMMER *pgm)
386+{
387+ if (pgm->fd.ifd != -1)
388+ close(pgm->fd.ifd);
389+}
390+
391+
392+static int nanonote_parseextparams(PROGRAMMER *pgm, LISTID extparms)
393+{
394+ LNODEID n;
395+ const char *param;
396+
397+ for (n = lfirst(extparms); n; n = lnext(n)) {
398+ param = ldata(n);
399+ if (sscanf(param, "clk=%u", &PDATA(pgm)->clk) == 1)
400+ continue;
401+ fprintf(stderr, "unrecognized parameter \"%s\"\n", param);
402+ return -1;
403+ }
404+
405+ return 0;
406+}
407+
408+
409+void nanonote_initpgm(PROGRAMMER *pgm)
410+{
411+ strcpy(pgm->type, "NANONOTE");
412+
413+ pgm->rdy_led = bitbang_rdy_led;
414+ pgm->err_led = bitbang_err_led;
415+ pgm->pgm_led = bitbang_pgm_led;
416+ pgm->vfy_led = bitbang_vfy_led;
417+ pgm->initialize = bitbang_initialize;
418+ pgm->display = nanonote_display;
419+ pgm->enable = nanonote_enable;
420+ pgm->disable = nanonote_disable;
421+ pgm->powerup = nanonote_powerup;
422+ pgm->powerdown = nanonote_powerdown;
423+ pgm->program_enable = bitbang_program_enable;
424+ pgm->chip_erase = bitbang_chip_erase;
425+ pgm->cmd = bitbang_cmd;
426+ pgm->open = nanonote_open;
427+ pgm->close = nanonote_close;
428+ pgm->setpin = nanonote_setpin;
429+ pgm->getpin = nanonote_getpin;
430+ pgm->highpulsepin = nanonote_highpulsepin;
431+ pgm->read_byte = avr_read_byte_default;
432+ pgm->write_byte = avr_write_byte_default;
433+ pgm->parseextparams = nanonote_parseextparams;
434+
435+ pgm->cookie = malloc(sizeof(struct pdata));
436+ if (!pgm->cookie) {
437+ perror("malloc");
438+ exit(1);
439+ }
440+ PDATA(pgm)->clk = 0;
441+}
442Index: avrdude-5.11.1/nanonote.h
443===================================================================
444--- /dev/null 1970-01-01 00:00:00.000000000 +0000
445+++ avrdude-5.11.1/nanonote.h 2012-07-22 10:39:01.946145199 -0300
446@@ -0,0 +1,6 @@
447+#ifndef nanonote_h
448+#define nanonote_h
449+
450+void nanonote_initpgm(PROGRAMMER *pgm);
451+
452+#endif
453

Archive Download this file

Branches:
master



interactive