From 3b0c8c699ed9c745d3deb4d8a2e9404c3bf0a55b Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 2 Jan 2013 09:58:45 -0300 Subject: [PATCH] lpc111x-isp/lpc111x.c: define IO pins via array, not #defines --- lpc111x-isp/lpc111x.c | 55 ++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/lpc111x-isp/lpc111x.c b/lpc111x-isp/lpc111x.c index 5e82852..ff323dc 100644 --- a/lpc111x-isp/lpc111x.c +++ b/lpc111x-isp/lpc111x.c @@ -25,14 +25,6 @@ #include -#define TGT_nRESET UBB_CMD -#define TGT_nISP UBB_DAT1 -#define TGT_TX UBB_DAT3 -#define TGT_RX UBB_DAT2 - -#define HOST_RX TGT_TX -#define HOST_TX TGT_RX - #define BPS 115200 #define MAX_BUF 10000 /* receive buffer */ @@ -53,6 +45,27 @@ #define SECTOR 4096 #define PAGE 256 + +enum { + pin_rxd, /* RXD pin on the device (PIO1_6) */ + pin_txd, /* TXD pin on the device (PIO1_7) */ + pin_nisp, /* nISP: ISP mode selection (PIO0_1) */ + pin_nreset, /* nRESET pin (PIO0_0) */ + pin_end /* last value */ +}; + +static struct pin { + const char *name; + const char *alt_name; + uint32_t pin; +} pin[] = { + [pin_rxd] = { "RXD", "P1_6", UBB_DAT2 }, + [pin_txd] = { "TXD", "P1_7", UBB_DAT3 }, + [pin_nisp] = { "nISP", "P0_1", UBB_DAT1 }, + [pin_nreset] = { "nRESET", "P0_0", UBB_CMD }, + [pin_end] = { NULL } +}; + static int verbose = 0; static int quiet = 0; @@ -210,9 +223,9 @@ static int autobaud(void) const char *res; for (i = 0; i != AUTOBAUD_TRIES; i++) { - CLR(TGT_nRESET); + CLR(pin[pin_nreset].pin); usleep(10); /* DS Table 9 pg 29 says min 50 ns */ - SET(TGT_nRESET); + SET(pin[pin_nreset].pin); usleep(5*1000); /* UM 26.3.1 pg 408 says max 3 ms */ @@ -542,13 +555,13 @@ static void start_isp(int power) usleep(100*1000); - SET(TGT_nRESET); - OUT(TGT_nRESET); + SET(pin[pin_nreset].pin); + OUT(pin[pin_nreset].pin); - CLR(TGT_nISP); - OUT(TGT_nISP); + CLR(pin[pin_nisp].pin); + OUT(pin[pin_nisp].pin); - if (swuart_open(HOST_TX, HOST_RX, BPS) < 0) { + if (swuart_open(pin[pin_rxd].pin, pin[pin_txd].pin, BPS) < 0) { perror("swuart_open"); exit(1); } @@ -579,16 +592,16 @@ static void run_target(int power) if (power) ubb_power(1); - SET(TGT_nRESET); - OUT(TGT_nRESET); + SET(pin[pin_nreset].pin); + OUT(pin[pin_nreset].pin); - IN(TGT_nISP); + IN(pin[pin_nisp].pin); - CLR(TGT_nRESET); + CLR(pin[pin_nreset].pin); usleep(10); /* DS Table 9 pg 29 says min 50 ns */ - SET(TGT_nRESET); + SET(pin[pin_nreset].pin); - ubb_close(UBB_nPWR | TGT_nRESET | TGT_nISP); + ubb_close(UBB_nPWR | pin[pin_nreset].pin | pin[pin_nisp].pin); }