C8051F32x firmware infrastructure

Sign in or create your account | Project List | Help

C8051F32x firmware infrastructure Commit Details

Date:2010-10-22 19:09:35 (13 years 5 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
99 * the Free Software Foundation; either version 2 of the License, or
1010 * (at your option) any later version.
1111 */
12#include <stdio.h>
1312
1413
1514#include "gpio-xburst.h"
...... 
2423#include "c2-bitbang.c"
2524
2625
27static void ben_init(void)
26static void ben_init(int power)
2827{
2928    gpio_init();
30    gpio_low(POWER_OFF);
29    if (power)
30        gpio_low(POWER_OFF);
31    else
32        gpio_high(POWER_OFF);
3133    c2_init();
3234
3335}
f32x/c2-drv.h
2525
2626
2727struct c2_ops {
28    void (*init)(void);
28    void (*init)(int power);
2929    void (*reset)(void);
3030    void (*addr_write)(uint8_t addr);
3131    uint8_t (*addr_read)(void);
f32x/c2-om.c
2727#include "c2-bitbang.c"
2828
2929
30static void om_init(void)
30static void om_init(int power)
3131{
3232    gpio_init();
3333    c2_init();
f32x/c2.c
5050/* ----- C2 initialization ------------------------------------------------- */
5151
5252
53void c2_init(void)
53void c2_init(int power)
5454{
5555    extern struct c2_ops DRIVER;
5656
5757    c2_ops = &DRIVER;
5858    if (c2_ops->init)
59        c2_ops->init();
59        c2_ops->init(power);
6060}
6161
6262
f32x/c2.h
11/*
22 * f32x/c2.h - Basic C2 messages
33 *
4 * Written 2008 by Werner Almesberger
5 * Copyright 2008 Werner Almesberger
4 * Written 2008, 2010 by Werner Almesberger
5 * Copyright 2008, 2010 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
2323void c2_data_write(uint32_t data, int bytes);
2424uint32_t c2_data_read(int bytes) ;
2525
26void c2_init(void);
26void c2_init(int power);
2727void c2_reset(void);
2828
2929#endif /* !C2_H */
f32x/f32x.c
11/*
22 * f32x/f32x.c - Simple C8051F326/7 Flash programmer
33 *
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
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
1414#include <stdint.h>
1515#include <stdlib.h>
1616#include <stdio.h>
17#include <unistd.h>
1718#include <string.h>
1819#include <sys/types.h>
1920
...... 
164165static void usage(const char *name)
165166{
166167    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"
172173" -b pin_setup\n"
173174" Perform a boundary scan. pin_setup sets all 14 pins in this order:\n"
174175" P0_0, P0_1, ..., P0_7, P2_0, ..., P2_5.\n"
...... 
177178" order, with a dot between P0 and P2.\n"
178179" -d dump Flash content\n"
179180" -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"
181183"Invocation without argument resets the F32x.\n"
182184  , name, name, name, name, name);
183185    exit(1);
...... 
186188
187189int main(int argc, char **argv)
188190{
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        }
191227
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:
202237            usage(*argv);
203        else {
204            do_flash(argv[1]);
205            identify();
206238        }
207239        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)
218246            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]);
220271        break;
221272    default:
222        usage(*argv);
273        abort();
223274    }
275
224276    c2_reset();
225277
226278    return 0;

Archive Download the corresponding diff file

Branches:
master



interactive