1
0
mirror of git://projects.qi-hardware.com/f32xbase.git synced 2024-11-27 18:10:38 +02:00

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
This commit is contained in:
Werner Almesberger 2010-10-22 14:09:35 -03:00
parent 8325a06f61
commit e614d15fef
6 changed files with 101 additions and 47 deletions

View File

@ -9,7 +9,6 @@
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
*/ */
#include <stdio.h>
#include "gpio-xburst.h" #include "gpio-xburst.h"
@ -24,10 +23,13 @@
#include "c2-bitbang.c" #include "c2-bitbang.c"
static void ben_init(void) static void ben_init(int power)
{ {
gpio_init(); gpio_init();
gpio_low(POWER_OFF); if (power)
gpio_low(POWER_OFF);
else
gpio_high(POWER_OFF);
c2_init(); c2_init();
} }

View File

@ -25,7 +25,7 @@
struct c2_ops { struct c2_ops {
void (*init)(void); void (*init)(int power);
void (*reset)(void); void (*reset)(void);
void (*addr_write)(uint8_t addr); void (*addr_write)(uint8_t addr);
uint8_t (*addr_read)(void); uint8_t (*addr_read)(void);

View File

@ -27,7 +27,7 @@
#include "c2-bitbang.c" #include "c2-bitbang.c"
static void om_init(void) static void om_init(int power)
{ {
gpio_init(); gpio_init();
c2_init(); c2_init();

View File

@ -50,13 +50,13 @@ uint32_t c2_data_read(int bytes)
/* ----- C2 initialization ------------------------------------------------- */ /* ----- C2 initialization ------------------------------------------------- */
void c2_init(void) void c2_init(int power)
{ {
extern struct c2_ops DRIVER; extern struct c2_ops DRIVER;
c2_ops = &DRIVER; c2_ops = &DRIVER;
if (c2_ops->init) if (c2_ops->init)
c2_ops->init(); c2_ops->init(power);
} }

View File

@ -1,8 +1,8 @@
/* /*
* f32x/c2.h - Basic C2 messages * f32x/c2.h - Basic C2 messages
* *
* Written 2008 by Werner Almesberger * Written 2008, 2010 by Werner Almesberger
* Copyright 2008 Werner Almesberger * Copyright 2008, 2010 Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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); void c2_data_write(uint32_t data, int bytes);
uint32_t c2_data_read(int bytes) ; uint32_t c2_data_read(int bytes) ;
void c2_init(void); void c2_init(int power);
void c2_reset(void); void c2_reset(void);
#endif /* !C2_H */ #endif /* !C2_H */

View File

@ -1,8 +1,8 @@
/* /*
* f32x/f32x.c - Simple C8051F326/7 Flash programmer * f32x/f32x.c - Simple C8051F326/7 Flash programmer
* *
* Written 2008, 2009 by Werner Almesberger * Written 2008-2010 by Werner Almesberger
* Copyright 2008, 2009 Werner Almesberger * Copyright 2008-2010 Werner Almesberger
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -14,6 +14,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
@ -164,11 +165,11 @@ static void protect(void)
static void usage(const char *name) static void usage(const char *name)
{ {
fprintf(stderr, fprintf(stderr,
"usage: %s [-p] file\n" "usage: %s [-n] [-p] file\n"
" %s -d\n" " %s [-n] -d\n"
" %s -e\n" " %s [-n] -e\n"
" %s -b pin_setup\n" " %s [-n] -b pin_setup\n"
" %s\n\n" " %s [-n]\n\n"
" -b pin_setup\n" " -b pin_setup\n"
" Perform a boundary scan. pin_setup sets all 14 pins in this order:\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" " 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" " order, with a dot between P0 and P2.\n"
" -d dump Flash content\n" " -d dump Flash content\n"
" -e erase whole Flash\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" "Invocation without argument resets the F32x.\n"
, name, name, name, name, name); , name, name, name, name, name);
exit(1); exit(1);
@ -186,41 +188,91 @@ static void usage(const char *name)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
c2_init(); enum {
identify(); mode_default = 0,
mode_flash,
mode_dump,
mode_erase,
mode_scan,
} mode = mode_default;
int do_protect = 0, power = 1;
int c;
switch (argc) { while ((c = getopt(argc, argv, "bdenp")) != EOF)
case 1: switch (c) {
/* just reset */ case 'd':
break; if (mode)
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] == '-')
usage(*argv); usage(*argv);
do_flash(argv[2]); mode = mode_dump;
protect(); break;
identify(); case 'e':
break; if (mode)
} usage(*argv);
if (strcmp(argv[1], "-b")) 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); usage(*argv);
boundary(argv[2]);
break; break;
default: 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(); c2_reset();
return 0; return 0;