mirror of
git://projects.qi-hardware.com/f32xbase.git
synced 2024-11-23 23:03:09 +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:
parent
8325a06f61
commit
e614d15fef
@ -9,7 +9,6 @@
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#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();
|
||||
if (power)
|
||||
gpio_low(POWER_OFF);
|
||||
else
|
||||
gpio_high(POWER_OFF);
|
||||
c2_init();
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "c2-bitbang.c"
|
||||
|
||||
|
||||
static void om_init(void)
|
||||
static void om_init(int power)
|
||||
{
|
||||
gpio_init();
|
||||
c2_init();
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 */
|
||||
|
118
f32x/f32x.c
118
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 <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@ -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] == '-')
|
||||
while ((c = getopt(argc, argv, "bdenp")) != EOF)
|
||||
switch (c) {
|
||||
case 'd':
|
||||
if (mode)
|
||||
usage(*argv);
|
||||
else {
|
||||
do_flash(argv[1]);
|
||||
identify();
|
||||
}
|
||||
mode = mode_dump;
|
||||
break;
|
||||
case 3:
|
||||
if (!strcmp(argv[1], "-p")) {
|
||||
if (*argv[2] == '-')
|
||||
case 'e':
|
||||
if (mode)
|
||||
usage(*argv);
|
||||
do_flash(argv[2]);
|
||||
protect();
|
||||
identify();
|
||||
mode = mode_erase;;
|
||||
break;
|
||||
}
|
||||
if (strcmp(argv[1], "-b"))
|
||||
case 'b':
|
||||
if (mode)
|
||||
usage(*argv);
|
||||
boundary(argv[2]);
|
||||
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);
|
||||
break;
|
||||
default:
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user