diff --git a/f32x/c2-ben.c b/f32x/c2-ben.c index 8e7b1eb..d0b0a92 100644 --- a/f32x/c2-ben.c +++ b/f32x/c2-ben.c @@ -9,7 +9,6 @@ * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ -#include #include "gpio-xburst.h" @@ -24,10 +23,13 @@ #include "c2-bitbang.c" -static void ben_init(void) +static void ben_init(int power) { gpio_init(); - gpio_low(POWER_OFF); + if (power) + gpio_low(POWER_OFF); + else + gpio_high(POWER_OFF); c2_init(); } diff --git a/f32x/c2-drv.h b/f32x/c2-drv.h index 6ad1485..c7be1cc 100644 --- a/f32x/c2-drv.h +++ b/f32x/c2-drv.h @@ -25,7 +25,7 @@ struct c2_ops { - void (*init)(void); + void (*init)(int power); void (*reset)(void); void (*addr_write)(uint8_t addr); uint8_t (*addr_read)(void); diff --git a/f32x/c2-om.c b/f32x/c2-om.c index 8d9ba48..c3778c1 100644 --- a/f32x/c2-om.c +++ b/f32x/c2-om.c @@ -27,7 +27,7 @@ #include "c2-bitbang.c" -static void om_init(void) +static void om_init(int power) { gpio_init(); c2_init(); diff --git a/f32x/c2.c b/f32x/c2.c index 62c5810..83b7c58 100644 --- a/f32x/c2.c +++ b/f32x/c2.c @@ -50,13 +50,13 @@ uint32_t c2_data_read(int bytes) /* ----- C2 initialization ------------------------------------------------- */ -void c2_init(void) +void c2_init(int power) { extern struct c2_ops DRIVER; c2_ops = &DRIVER; if (c2_ops->init) - c2_ops->init(); + c2_ops->init(power); } diff --git a/f32x/c2.h b/f32x/c2.h index 36135cd..5ce2a90 100644 --- a/f32x/c2.h +++ b/f32x/c2.h @@ -1,8 +1,8 @@ /* * f32x/c2.h - Basic C2 messages * - * Written 2008 by Werner Almesberger - * Copyright 2008 Werner Almesberger + * Written 2008, 2010 by Werner Almesberger + * Copyright 2008, 2010 Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,7 +23,7 @@ uint8_t c2_addr_read(void); void c2_data_write(uint32_t data, int bytes); uint32_t c2_data_read(int bytes) ; -void c2_init(void); +void c2_init(int power); void c2_reset(void); #endif /* !C2_H */ diff --git a/f32x/f32x.c b/f32x/f32x.c index c3d541d..f447d05 100644 --- a/f32x/f32x.c +++ b/f32x/f32x.c @@ -1,8 +1,8 @@ /* * f32x/f32x.c - Simple C8051F326/7 Flash programmer * - * Written 2008, 2009 by Werner Almesberger - * Copyright 2008, 2009 Werner Almesberger + * Written 2008-2010 by Werner Almesberger + * Copyright 2008-2010 Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -164,11 +165,11 @@ static void protect(void) static void usage(const char *name) { fprintf(stderr, -"usage: %s [-p] file\n" -" %s -d\n" -" %s -e\n" -" %s -b pin_setup\n" -" %s\n\n" +"usage: %s [-n] [-p] file\n" +" %s [-n] -d\n" +" %s [-n] -e\n" +" %s [-n] -b pin_setup\n" +" %s [-n]\n\n" " -b pin_setup\n" " Perform a boundary scan. pin_setup sets all 14 pins in this order:\n" " P0_0, P0_1, ..., P0_7, P2_0, ..., P2_5.\n" @@ -177,7 +178,8 @@ static void usage(const char *name) " order, with a dot between P0 and P2.\n" " -d dump Flash content\n" " -e erase whole Flash\n" -" -p Protect the data after writing\n" +" -n do not provide power to the target (default: do provide power)\n" +" -p protect the data after writing\n" "Invocation without argument resets the F32x.\n" , name, name, name, name, name); exit(1); @@ -186,41 +188,91 @@ static void usage(const char *name) int main(int argc, char **argv) { - c2_init(); - identify(); + enum { + mode_default = 0, + mode_flash, + mode_dump, + mode_erase, + mode_scan, + } mode = mode_default; + int do_protect = 0, power = 1; + int c; - switch (argc) { - case 1: - /* just reset */ - break; - case 2: - if (!strcmp(argv[1], "-d")) - dump_flash(0x4000); - else if (!strcmp(argv[1], "-e")) - erase_flash(); - else if (*argv[1] == '-') - usage(*argv); - else { - do_flash(argv[1]); - identify(); - } - break; - case 3: - if (!strcmp(argv[1], "-p")) { - if (*argv[2] == '-') + while ((c = getopt(argc, argv, "bdenp")) != EOF) + switch (c) { + case 'd': + if (mode) usage(*argv); - do_flash(argv[2]); - protect(); - identify(); - break; - } - if (strcmp(argv[1], "-b")) + mode = mode_dump; + break; + case 'e': + if (mode) + usage(*argv); + mode = mode_erase;; + break; + case 'b': + if (mode) + usage(*argv); + mode = mode_scan;; + break; + case 'n': + power = 0; + break; + case 'p': + do_protect = 1; + break; + default: + usage(*argv); + } + + switch (mode) { + case mode_default: + switch (argc-optind) { + case 0: + break; + case 1: + mode = mode_flash; + break; + default: + usage(*argv); + } + break; + case mode_scan: + if (argc != optind+1) usage(*argv); - boundary(argv[2]); break; default: - usage(*argv); + if (argc != optind) + usage(*argv); + break; } + + c2_init(power); + identify(); + + switch (mode) { + case mode_default: + /* just reset */ + break; + case mode_dump: + dump_flash(0x4000); + break; + case mode_erase: + erase_flash(); + break; + case mode_flash: + do_flash(argv[optind]); + if (do_protect) + protect(); + identify(); + break; + case mode_scan: + boundary(argv[optind]); + break; + default: + abort(); + } + c2_reset(); return 0;