mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2024-12-24 05:19:55 +02:00
lpc111x-isp/lpc111x.c: new option -P function=signal to reassign pins
This commit is contained in:
parent
3b0c8c699e
commit
376aa543a9
@ -17,6 +17,7 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <strings.h> /* for strcasecmp, strncasecmp */
|
||||
#include <alloca.h>
|
||||
#include <assert.h>
|
||||
#include <sys/types.h>
|
||||
@ -58,7 +59,7 @@ static struct pin {
|
||||
const char *name;
|
||||
const char *alt_name;
|
||||
uint32_t pin;
|
||||
} pin[] = {
|
||||
} pins[] = {
|
||||
[pin_rxd] = { "RXD", "P1_6", UBB_DAT2 },
|
||||
[pin_txd] = { "TXD", "P1_7", UBB_DAT3 },
|
||||
[pin_nisp] = { "nISP", "P0_1", UBB_DAT1 },
|
||||
@ -66,6 +67,19 @@ static struct pin {
|
||||
[pin_end] = { NULL }
|
||||
};
|
||||
|
||||
static const struct signal {
|
||||
const char *name;
|
||||
uint32_t pin;
|
||||
} signals[] = {
|
||||
{ "CMD", UBB_CMD },
|
||||
{ "CLK", UBB_CLK },
|
||||
{ "DAT0", UBB_DAT0 },
|
||||
{ "DAT1", UBB_DAT1 },
|
||||
{ "DAT2", UBB_DAT2 },
|
||||
{ "DAT3", UBB_DAT3 },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static int verbose = 0;
|
||||
static int quiet = 0;
|
||||
|
||||
@ -223,9 +237,9 @@ static int autobaud(void)
|
||||
const char *res;
|
||||
|
||||
for (i = 0; i != AUTOBAUD_TRIES; i++) {
|
||||
CLR(pin[pin_nreset].pin);
|
||||
CLR(pins[pin_nreset].pin);
|
||||
usleep(10); /* DS Table 9 pg 29 says min 50 ns */
|
||||
SET(pin[pin_nreset].pin);
|
||||
SET(pins[pin_nreset].pin);
|
||||
|
||||
usleep(5*1000); /* UM 26.3.1 pg 408 says max 3 ms */
|
||||
|
||||
@ -555,13 +569,13 @@ static void start_isp(int power)
|
||||
|
||||
usleep(100*1000);
|
||||
|
||||
SET(pin[pin_nreset].pin);
|
||||
OUT(pin[pin_nreset].pin);
|
||||
SET(pins[pin_nreset].pin);
|
||||
OUT(pins[pin_nreset].pin);
|
||||
|
||||
CLR(pin[pin_nisp].pin);
|
||||
OUT(pin[pin_nisp].pin);
|
||||
CLR(pins[pin_nisp].pin);
|
||||
OUT(pins[pin_nisp].pin);
|
||||
|
||||
if (swuart_open(pin[pin_rxd].pin, pin[pin_txd].pin, BPS) < 0) {
|
||||
if (swuart_open(pins[pin_rxd].pin, pins[pin_txd].pin, BPS) < 0) {
|
||||
perror("swuart_open");
|
||||
exit(1);
|
||||
}
|
||||
@ -592,16 +606,16 @@ static void run_target(int power)
|
||||
if (power)
|
||||
ubb_power(1);
|
||||
|
||||
SET(pin[pin_nreset].pin);
|
||||
OUT(pin[pin_nreset].pin);
|
||||
SET(pins[pin_nreset].pin);
|
||||
OUT(pins[pin_nreset].pin);
|
||||
|
||||
IN(pin[pin_nisp].pin);
|
||||
IN(pins[pin_nisp].pin);
|
||||
|
||||
CLR(pin[pin_nreset].pin);
|
||||
CLR(pins[pin_nreset].pin);
|
||||
usleep(10); /* DS Table 9 pg 29 says min 50 ns */
|
||||
SET(pin[pin_nreset].pin);
|
||||
SET(pins[pin_nreset].pin);
|
||||
|
||||
ubb_close(UBB_nPWR | pin[pin_nreset].pin | pin[pin_nisp].pin);
|
||||
ubb_close(UBB_nPWR | pins[pin_nreset].pin | pins[pin_nisp].pin);
|
||||
}
|
||||
|
||||
|
||||
@ -610,18 +624,67 @@ static void run_target(int power)
|
||||
|
||||
static void usage(const char *name)
|
||||
{
|
||||
const struct signal *signal;
|
||||
int i;
|
||||
|
||||
fprintf(stderr,
|
||||
"usage: %s [-n] [-q] [-v ...] [file.bin]\n"
|
||||
" %s [-n] -r\n\n"
|
||||
" -n don't power the device\n"
|
||||
" -q suppress basic progress messages\n"
|
||||
" -r reset the target and let it run\n"
|
||||
" -v increase verbosity level\n"
|
||||
"usage: %s [-P function=signal ...] [-n] [-q] [-v ...] [file.bin]\n"
|
||||
" %s [-P function=signal ...] [-n] -r\n\n"
|
||||
" -n don't power the device\n"
|
||||
" -q suppress basic progress messages\n"
|
||||
" -P function=signal assign a 8:10 interface signal to a function "
|
||||
"(see below)\n"
|
||||
" -r reset the target and let it run\n"
|
||||
" -v increase verbosity level\n\n"
|
||||
"Functions: RXD (P1_6), TXD (P1_7), nISP (P0_1), nRESET (P0_0)\n"
|
||||
"Signals: CMD, CLK, DAT0, DAT1, DAT2, DAT3\n"
|
||||
, name, name);
|
||||
|
||||
fprintf(stderr, "Default mapping:");
|
||||
for (i = 0; i != pin_end; i++) {
|
||||
for (signal = signals; signal->pin != pins[i].pin; signal++);
|
||||
fprintf(stderr, " -P %s=%s", pins[i].name, signal->name);
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
static void assign_pin(const char *name, const char *s)
|
||||
{
|
||||
const char *eq;
|
||||
struct pin *pin;
|
||||
const struct signal *signal;
|
||||
|
||||
eq = strchr(s, '=');
|
||||
if (!eq)
|
||||
usage(name);
|
||||
|
||||
for (pin = pins; pin->name; pin++) {
|
||||
if (strlen(pin->name) == eq-s &&
|
||||
!strncasecmp(pin->name, s, eq-s))
|
||||
break;
|
||||
if (strlen(pin->alt_name) == eq-s &&
|
||||
!strncasecmp(pin->alt_name, s, eq-s))
|
||||
break;
|
||||
}
|
||||
if (!pin->name) {
|
||||
fprintf(stderr, "unknown function \"%.*s\"\n", eq-s, s);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (signal = signals; signal->name; signal++)
|
||||
if (!strcasecmp(signal->name, eq+1))
|
||||
break;
|
||||
if (!signal->name) {
|
||||
fprintf(stderr, "unknown signal \"%s\"\n", eq+1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pin->pin = signal->pin;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE *file = NULL;
|
||||
@ -629,11 +692,14 @@ int main(int argc, char **argv)
|
||||
int run = 0;
|
||||
int c;
|
||||
|
||||
while ((c = getopt(argc, argv, "nqrv")) != EOF)
|
||||
while ((c = getopt(argc, argv, "nP:qrv")) != EOF)
|
||||
switch (c) {
|
||||
case 'n':
|
||||
power = 0;
|
||||
break;
|
||||
case 'P':
|
||||
assign_pin(*argv, optarg);
|
||||
break;
|
||||
case 'q':
|
||||
quiet = 1;
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user