diff --git a/Makefile b/Makefile index 8bf2dde..dde0448 100644 --- a/Makefile +++ b/Makefile @@ -119,7 +119,7 @@ OBJ=\ transport/olimex_iso.o \ transport/rf2500.o \ transport/ti3410.o \ - transport/uif.o \ + transport/comport.o \ drivers/device.o \ drivers/bsl.o \ drivers/fet.o \ diff --git a/drivers/fet.c b/drivers/fet.c index 56b4100..f16c8e7 100644 --- a/drivers/fet.c +++ b/drivers/fet.c @@ -34,7 +34,7 @@ #include "output.h" #include "opdb.h" -#include "uif.h" +#include "comport.h" #include "olimex_iso.h" #include "rf2500.h" #include "ti3410.h" @@ -1120,7 +1120,7 @@ static device_t fet_open_olimex_iso_mk2(const struct device_args *args) uint32_t version; if (args->flags & DEVICE_FLAG_TTY) - trans = uif_open(args->path, UIF_TYPE_OLIMEX); + trans = comport_open(args->path, 115200); else trans = cdc_acm_open(args->path, args->requested_serial, 115200, 0x15ba, 0x0100); @@ -1143,7 +1143,7 @@ static device_t fet_open_olimex_iso_mk2(const struct device_args *args) delay_s(15); if (args->flags & DEVICE_FLAG_TTY) - trans = uif_open(args->path, UIF_TYPE_OLIMEX); + trans = comport_open(args->path, 115200); else trans = cdc_acm_open(args->path, args->requested_serial, @@ -1181,7 +1181,7 @@ static device_t fet_open_olimex(const struct device_args *args) transport_t trans; if (args->flags & DEVICE_FLAG_TTY) - trans = uif_open(args->path, UIF_TYPE_OLIMEX); + trans = comport_open(args->path, 115200); else trans = cdc_acm_open(args->path, args->requested_serial, 115200, 0x15ba, 0x0031); @@ -1214,7 +1214,7 @@ static device_t fet_open_olimex_v1(const struct device_args *args) transport_t trans; if (args->flags & DEVICE_FLAG_TTY) - trans = uif_open(args->path, UIF_TYPE_OLIMEX_V1); + trans = comport_open(args->path, 500000); else trans = cp210x_open(args->path, args->requested_serial, 500000, 0x15ba, 0x0002); @@ -1247,7 +1247,7 @@ static device_t fet_open_olimex_iso(const struct device_args *args) transport_t trans; if (args->flags & DEVICE_FLAG_TTY) - trans = uif_open(args->path, UIF_TYPE_OLIMEX_ISO); + trans = comport_open(args->path, 200000); else trans = olimex_iso_open(args->path, args->requested_serial); @@ -1279,7 +1279,7 @@ static device_t fet_open_uif(const struct device_args *args) transport_t trans; if (args->flags & DEVICE_FLAG_TTY) - trans = uif_open(args->path, UIF_TYPE_FET); + trans = comport_open(args->path, 460800); else trans = ti3410_open(args->path, args->requested_serial); diff --git a/transport/uif.c b/transport/comport.c similarity index 60% rename from transport/uif.c rename to transport/comport.c index ffc8663..9e77b30 100644 --- a/transport/uif.c +++ b/transport/comport.c @@ -1,5 +1,5 @@ /* MSPDebug - debugging tool for the eZ430 - * Copyright (C) 2009, 2010 Daniel Beer + * Copyright (C) 2009-2012 Daniel Beer * * 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,12 +23,12 @@ #include #include -#include "uif.h" +#include "comport.h" #include "util.h" #include "output.h" #include "sport.h" -struct uif_transport { +struct comport_transport { struct transport base; sport_t serial_fd; @@ -36,14 +36,14 @@ struct uif_transport { static int serial_send(transport_t tr_base, const uint8_t *data, int len) { - struct uif_transport *tr = (struct uif_transport *)tr_base; + struct comport_transport *tr = (struct comport_transport *)tr_base; #ifdef DEBUG_SERIAL debug_hexdump("Serial transfer out:", data, len); #endif if (sport_write_all(tr->serial_fd, data, len) < 0) { - pr_error("uif: write error"); + pr_error("comport: write error"); return -1; } @@ -52,12 +52,12 @@ static int serial_send(transport_t tr_base, const uint8_t *data, int len) static int serial_recv(transport_t tr_base, uint8_t *data, int max_len) { - struct uif_transport *tr = (struct uif_transport *)tr_base; + struct comport_transport *tr = (struct comport_transport *)tr_base; int r; r = sport_read(tr->serial_fd, data, max_len); if (r < 0) { - pr_error("uif: read error"); + pr_error("comport: read error"); return -1; } @@ -69,7 +69,7 @@ static int serial_recv(transport_t tr_base, uint8_t *data, int max_len) static void serial_destroy(transport_t tr_base) { - struct uif_transport *tr = (struct uif_transport *)tr_base; + struct comport_transport *tr = (struct comport_transport *)tr_base; sport_close(tr->serial_fd); free(tr); @@ -77,10 +77,10 @@ static void serial_destroy(transport_t tr_base) static int serial_flush(transport_t tr_base) { - struct uif_transport *tr = (struct uif_transport *)tr_base; + struct comport_transport *tr = (struct comport_transport *)tr_base; if (sport_flush(tr->serial_fd) < 0) { - pr_error("uif: flush failed"); + pr_error("comport: flush failed"); return -1; } @@ -89,7 +89,7 @@ static int serial_flush(transport_t tr_base) static int serial_set_modem(transport_t tr_base, transport_modem_t state) { - struct uif_transport *tr = (struct uif_transport *)tr_base; + struct comport_transport *tr = (struct comport_transport *)tr_base; int bits = 0; if (state & TRANSPORT_MODEM_DTR) @@ -99,14 +99,14 @@ static int serial_set_modem(transport_t tr_base, transport_modem_t state) bits |= SPORT_MC_RTS; if (sport_set_modem(tr->serial_fd, bits) < 0) { - pr_error("uif: failed to set modem control lines\n"); + pr_error("comport: failed to set modem control lines\n"); return -1; } return 0; } -static const struct transport_class uif_transport = { +static const struct transport_class comport_transport = { .destroy = serial_destroy, .send = serial_send, .recv = serial_recv, @@ -114,48 +114,29 @@ static const struct transport_class uif_transport = { .set_modem = serial_set_modem }; -transport_t uif_open(const char *device, uif_type_t type) +transport_t comport_open(const char *device, int baud_rate) { - struct uif_transport *tr = malloc(sizeof(*tr)); + struct comport_transport *tr = malloc(sizeof(*tr)); if (!tr) { - pr_error("uif: couldn't allocate memory"); + pr_error("comport: couldn't allocate memory"); return NULL; } - tr->base.ops = &uif_transport; - - switch (type) { - case UIF_TYPE_FET: - printc("Trying to open UIF on %s...\n", device); - tr->serial_fd = sport_open(device, 460800, 0); - break; - - case UIF_TYPE_OLIMEX: - printc("Trying to open Olimex (V2) on %s...\n", device); - tr->serial_fd = sport_open(device, 115200, 0); - if (sport_set_modem(tr->serial_fd, 0) < 0) - pr_error("warning: uif: failed to set " - "modem control lines"); - break; - - case UIF_TYPE_OLIMEX_V1: - printc("Trying to open Olimex (V1) on %s...\n", device); - tr->serial_fd = sport_open(device, 500000, 0); - break; - - case UIF_TYPE_OLIMEX_ISO: - printc("Trying to open Olimex (ISO) on %s...\n", device); - tr->serial_fd = sport_open(device, 200000, 0); - break; - } + tr->base.ops = &comport_transport; + printc("Trying to open %s at %d bps...\n", device, baud_rate); + tr->serial_fd = sport_open(device, baud_rate, 0); if (SPORT_ISERR(tr->serial_fd)) { - printc_err("uif: can't open serial device: %s: %s\n", + printc_err("comport: can't open serial device: %s: %s\n", device, last_error()); free(tr); return NULL; } + if (sport_set_modem(tr->serial_fd, 0) < 0) + pr_error("warning: comport: failed to set " + "modem control lines"); + return (transport_t)tr; } diff --git a/transport/uif.h b/transport/comport.h similarity index 65% rename from transport/uif.h rename to transport/comport.h index 9e670f8..850c9c5 100644 --- a/transport/uif.h +++ b/transport/comport.h @@ -1,5 +1,5 @@ /* MSPDebug - debugging tool for MSP430 MCUs - * Copyright (C) 2009, 2010 Daniel Beer + * Copyright (C) 2009-2012 Daniel Beer * * 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 @@ -16,22 +16,15 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef UIF_H_ -#define UIF_H_ +#ifndef COMPORT_H_ +#define COMPORT_H_ #include "transport.h" -typedef enum { - UIF_TYPE_FET, - UIF_TYPE_OLIMEX, - UIF_TYPE_OLIMEX_V1, - UIF_TYPE_OLIMEX_ISO -} uif_type_t; - -/* This function is for opening an eZ430-F2013 or FET430UIF device via - * a kernel-supported serial interface. The argument given should be the - * filename of the relevant tty device. +/* This function is for opening a system serial device. The argument + * given should be the filename of the relevant tty device (POSIX) or a + * COM port name (Windows). */ -transport_t uif_open(const char *device, uif_type_t type); +transport_t comport_open(const char *device, int baud_rate); #endif diff --git a/ui/main.c b/ui/main.c index 732ebe0..df290c9 100644 --- a/ui/main.c +++ b/ui/main.c @@ -46,9 +46,6 @@ #include "fet_db.h" #include "flash_bsl.h" #include "gdbc.h" - -#include "uif.h" -#include "rf2500.h" #include "tilib.h" #include "goodfet.h"