C8051F32x firmware infrastructure
Sign in or create your account | Project List | Help
C8051F32x firmware infrastructure Commit Details
Date: | 2010-10-22 19:09:35 (12 years 11 months ago) |
---|---|
Author: | Werner Almesberger |
Commit: | e614d15feffe687ca3519c8b86ea333ccf22e294 |
Message: | Cleaned up command-line parsing. Added option -n to disable target
power. - f32x/c2-ben.c: removed #include <stdio.h> left over from debugging - f32x/f32x.c (main): command-line parsing now uses getopt() and is done before trying to talk to the target - f32x/c2-drv.h (c2_ops), f32x/c2.h (c2_init), f32x/c2.c (c2_init), f32x/c2-om.c (om_init): pass "power" argument along the init call chain - f32x/c2-ben.c (ben_init): added target power switching - f32x/f32x.c (usage, main): new option -n to disable target power |
Files: |
f32x/c2-ben.c (2 diffs) f32x/c2-drv.h (1 diff) f32x/c2-om.c (1 diff) f32x/c2.c (1 diff) f32x/c2.h (2 diffs) f32x/f32x.c (5 diffs) |
Change Details
f32x/c2-ben.c | ||
---|---|---|
9 | 9 | * the Free Software Foundation; either version 2 of the License, or |
10 | 10 | * (at your option) any later version. |
11 | 11 | */ |
12 | #include <stdio.h> | |
13 | 12 | |
14 | 13 | |
15 | 14 | #include "gpio-xburst.h" |
... | ... | |
24 | 23 | #include "c2-bitbang.c" |
25 | 24 | |
26 | 25 | |
27 | static void ben_init(void) | |
26 | static void ben_init(int power) | |
28 | 27 | { |
29 | 28 | gpio_init(); |
30 | gpio_low(POWER_OFF); | |
29 | if (power) | |
30 | gpio_low(POWER_OFF); | |
31 | else | |
32 | gpio_high(POWER_OFF); | |
31 | 33 | c2_init(); |
32 | 34 | |
33 | 35 | } |
f32x/c2-drv.h | ||
---|---|---|
25 | 25 | |
26 | 26 | |
27 | 27 | struct c2_ops { |
28 | void (*init)(void); | |
28 | void (*init)(int power); | |
29 | 29 | void (*reset)(void); |
30 | 30 | void (*addr_write)(uint8_t addr); |
31 | 31 | uint8_t (*addr_read)(void); |
f32x/c2-om.c | ||
---|---|---|
27 | 27 | #include "c2-bitbang.c" |
28 | 28 | |
29 | 29 | |
30 | static void om_init(void) | |
30 | static void om_init(int power) | |
31 | 31 | { |
32 | 32 | gpio_init(); |
33 | 33 | c2_init(); |
f32x/c2.c | ||
---|---|---|
50 | 50 | /* ----- C2 initialization ------------------------------------------------- */ |
51 | 51 | |
52 | 52 | |
53 | void c2_init(void) | |
53 | void c2_init(int power) | |
54 | 54 | { |
55 | 55 | extern struct c2_ops DRIVER; |
56 | 56 | |
57 | 57 | c2_ops = &DRIVER; |
58 | 58 | if (c2_ops->init) |
59 | c2_ops->init(); | |
59 | c2_ops->init(power); | |
60 | 60 | } |
61 | 61 | |
62 | 62 |
f32x/c2.h | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * f32x/c2.h - Basic C2 messages |
3 | 3 | * |
4 | * Written 2008 by Werner Almesberger | |
5 | * Copyright 2008 Werner Almesberger | |
4 | * Written 2008, 2010 by Werner Almesberger | |
5 | * Copyright 2008, 2010 Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
23 | 23 | void c2_data_write(uint32_t data, int bytes); |
24 | 24 | uint32_t c2_data_read(int bytes) ; |
25 | 25 | |
26 | void c2_init(void); | |
26 | void c2_init(int power); | |
27 | 27 | void c2_reset(void); |
28 | 28 | |
29 | 29 | #endif /* !C2_H */ |
f32x/f32x.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * f32x/f32x.c - Simple C8051F326/7 Flash programmer |
3 | 3 | * |
4 | * Written 2008, 2009 by Werner Almesberger | |
5 | * Copyright 2008, 2009 Werner Almesberger | |
4 | * Written 2008-2010 by Werner Almesberger | |
5 | * Copyright 2008-2010 Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
14 | 14 | #include <stdint.h> |
15 | 15 | #include <stdlib.h> |
16 | 16 | #include <stdio.h> |
17 | #include <unistd.h> | |
17 | 18 | #include <string.h> |
18 | 19 | #include <sys/types.h> |
19 | 20 | |
... | ... | |
164 | 165 | static void usage(const char *name) |
165 | 166 | { |
166 | 167 | fprintf(stderr, |
167 | "usage: %s [-p] file\n" | |
168 | " %s -d\n" | |
169 | " %s -e\n" | |
170 | " %s -b pin_setup\n" | |
171 | " %s\n\n" | |
168 | "usage: %s [-n] [-p] file\n" | |
169 | " %s [-n] -d\n" | |
170 | " %s [-n] -e\n" | |
171 | " %s [-n] -b pin_setup\n" | |
172 | " %s [-n]\n\n" | |
172 | 173 | " -b pin_setup\n" |
173 | 174 | " Perform a boundary scan. pin_setup sets all 14 pins in this order:\n" |
174 | 175 | " P0_0, P0_1, ..., P0_7, P2_0, ..., P2_5.\n" |
... | ... | |
177 | 178 | " order, with a dot between P0 and P2.\n" |
178 | 179 | " -d dump Flash content\n" |
179 | 180 | " -e erase whole Flash\n" |
180 | " -p Protect the data after writing\n" | |
181 | " -n do not provide power to the target (default: do provide power)\n" | |
182 | " -p protect the data after writing\n" | |
181 | 183 | "Invocation without argument resets the F32x.\n" |
182 | 184 | , name, name, name, name, name); |
183 | 185 | exit(1); |
... | ... | |
186 | 188 | |
187 | 189 | int main(int argc, char **argv) |
188 | 190 | { |
189 | c2_init(); | |
190 | identify(); | |
191 | enum { | |
192 | mode_default = 0, | |
193 | mode_flash, | |
194 | mode_dump, | |
195 | mode_erase, | |
196 | mode_scan, | |
197 | } mode = mode_default; | |
198 | int do_protect = 0, power = 1; | |
199 | int c; | |
200 | ||
201 | while ((c = getopt(argc, argv, "bdenp")) != EOF) | |
202 | switch (c) { | |
203 | case 'd': | |
204 | if (mode) | |
205 | usage(*argv); | |
206 | mode = mode_dump; | |
207 | break; | |
208 | case 'e': | |
209 | if (mode) | |
210 | usage(*argv); | |
211 | mode = mode_erase;; | |
212 | break; | |
213 | case 'b': | |
214 | if (mode) | |
215 | usage(*argv); | |
216 | mode = mode_scan;; | |
217 | break; | |
218 | case 'n': | |
219 | power = 0; | |
220 | break; | |
221 | case 'p': | |
222 | do_protect = 1; | |
223 | break; | |
224 | default: | |
225 | usage(*argv); | |
226 | } | |
191 | 227 | |
192 | switch (argc) { | |
193 | case 1: | |
194 | /* just reset */ | |
195 | break; | |
196 | case 2: | |
197 | if (!strcmp(argv[1], "-d")) | |
198 | dump_flash(0x4000); | |
199 | else if (!strcmp(argv[1], "-e")) | |
200 | erase_flash(); | |
201 | else if (*argv[1] == '-') | |
228 | switch (mode) { | |
229 | case mode_default: | |
230 | switch (argc-optind) { | |
231 | case 0: | |
232 | break; | |
233 | case 1: | |
234 | mode = mode_flash; | |
235 | break; | |
236 | default: | |
202 | 237 | usage(*argv); |
203 | else { | |
204 | do_flash(argv[1]); | |
205 | identify(); | |
206 | 238 | } |
207 | 239 | break; |
208 | case 3: | |
209 | if (!strcmp(argv[1], "-p")) { | |
210 | if (*argv[2] == '-') | |
211 | usage(*argv); | |
212 | do_flash(argv[2]); | |
213 | protect(); | |
214 | identify(); | |
215 | break; | |
216 | } | |
217 | if (strcmp(argv[1], "-b")) | |
240 | case mode_scan: | |
241 | if (argc != optind+1) | |
242 | usage(*argv); | |
243 | break; | |
244 | default: | |
245 | if (argc != optind) | |
218 | 246 | usage(*argv); |
219 | boundary(argv[2]); | |
247 | break; | |
248 | } | |
249 | ||
250 | c2_init(power); | |
251 | identify(); | |
252 | ||
253 | switch (mode) { | |
254 | case mode_default: | |
255 | /* just reset */ | |
256 | break; | |
257 | case mode_dump: | |
258 | dump_flash(0x4000); | |
259 | break; | |
260 | case mode_erase: | |
261 | erase_flash(); | |
262 | break; | |
263 | case mode_flash: | |
264 | do_flash(argv[optind]); | |
265 | if (do_protect) | |
266 | protect(); | |
267 | identify(); | |
268 | break; | |
269 | case mode_scan: | |
270 | boundary(argv[optind]); | |
220 | 271 | break; |
221 | 272 | default: |
222 | usage(*argv); | |
273 | abort(); | |
223 | 274 | } |
275 | ||
224 | 276 | c2_reset(); |
225 | 277 | |
226 | 278 | return 0; |
Branches:
master