228 lines
6.0 KiB
C
228 lines
6.0 KiB
C
/* MSPDebug - debugging tool for MSP430 MCUs
|
|
* Copyright (C) 2009-2012 Daniel Beer
|
|
* Copyright (C) 2012-2015 Peter Bägel
|
|
*
|
|
* 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
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
/* Driver for parallel port interface like the Olimex MSP430-JTAG
|
|
* Starting point was the goodfet driver
|
|
*
|
|
* 2012-10-03 initial release Peter Bägel (DF5EQ)
|
|
* 2014-12-26 single step implemented Peter Bägel (DF5EQ)
|
|
* 2015-02-21 breakpoints implemented Peter Bägel (DF5EQ)
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "util.h"
|
|
#include "output.h"
|
|
#include "pif.h"
|
|
#include "jtaglib.h"
|
|
#include "ctrlc.h"
|
|
|
|
struct pif_device {
|
|
struct jtdev jtag;
|
|
};
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
static device_t pif_open(const struct device_args *args)
|
|
{
|
|
struct pif_device *dev;
|
|
|
|
if (!(args->flags & DEVICE_FLAG_TTY)) {
|
|
printc_err("pif: this driver does not support raw USB access\n");
|
|
return NULL;
|
|
}
|
|
|
|
if (!(args->flags & DEVICE_FLAG_JTAG)) {
|
|
printc_err("pif: this driver does not support Spy-Bi-Wire\n");
|
|
return NULL;
|
|
}
|
|
|
|
dev = malloc(sizeof(*dev));
|
|
if (!dev) {
|
|
printc_err("pif: malloc: %s\n", last_error());
|
|
return NULL;
|
|
}
|
|
|
|
memset(dev, 0, sizeof(*dev));
|
|
dev->jtag.base.type = &device_pif;
|
|
dev->jtag.base.max_breakpoints = 2; //supported by all devices
|
|
dev->jtag.base.need_probe = 1;
|
|
(&dev->jtag)->f = &jtdev_func_pif;
|
|
|
|
if ((&dev->jtag)->f->jtdev_open(&dev->jtag, args->path) < 0) {
|
|
printc_err("pif: can't open port\n");
|
|
free(dev);
|
|
return NULL;
|
|
}
|
|
|
|
if (jtag_dev_init(&dev->jtag) < 0) {
|
|
printc_err("pif: initialization failed\n");
|
|
free(dev);
|
|
return NULL;
|
|
}
|
|
|
|
return &dev->jtag.base;
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
static device_t gpio_open(const struct device_args *args)
|
|
{
|
|
struct pif_device *dev;
|
|
|
|
if (!(args->flags & DEVICE_FLAG_TTY)) {
|
|
printc_err("gpio: this driver does not support raw USB access\n");
|
|
return NULL;
|
|
}
|
|
|
|
if (!(args->flags & DEVICE_FLAG_JTAG)) {
|
|
printc_err("gpio: this driver does not support Spy-Bi-Wire\n");
|
|
return NULL;
|
|
}
|
|
|
|
dev = malloc(sizeof(*dev));
|
|
if (!dev) {
|
|
printc_err("gpio: malloc: %s\n", last_error());
|
|
return NULL;
|
|
}
|
|
|
|
memset(dev, 0, sizeof(*dev));
|
|
dev->jtag.base.type = &device_pif;
|
|
dev->jtag.base.max_breakpoints = 0;
|
|
(&dev->jtag)->f = &jtdev_func_gpio;
|
|
|
|
if ((&dev->jtag)->f->jtdev_open(&dev->jtag, args->path) < 0) {
|
|
printc_err("gpio: can't open port\n");
|
|
free(dev);
|
|
return NULL;
|
|
}
|
|
|
|
if (jtag_dev_init(&dev->jtag) < 0) {
|
|
printc_err("gpio: initialization failed\n");
|
|
free(dev);
|
|
return NULL;
|
|
}
|
|
|
|
return &dev->jtag.base;
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
static device_t bp_open(const struct device_args *args)
|
|
{
|
|
struct pif_device *dev;
|
|
|
|
if (!(args->flags & DEVICE_FLAG_TTY)) {
|
|
printc_err("bp: this driver does not support raw USB access\n");
|
|
return NULL;
|
|
}
|
|
|
|
if (!(args->flags & DEVICE_FLAG_JTAG)) {
|
|
printc_err("bp: this driver does not support Spy-Bi-Wire\n");
|
|
return NULL;
|
|
}
|
|
|
|
dev = malloc(sizeof(*dev));
|
|
if (!dev) {
|
|
printc_err("bp: malloc: %s\n", last_error());
|
|
return NULL;
|
|
}
|
|
|
|
memset(dev, 0, sizeof(*dev));
|
|
dev->jtag.base.type = &device_pif;
|
|
dev->jtag.base.max_breakpoints = 2; //supported by all devices
|
|
dev->jtag.base.need_probe = 1;
|
|
(&dev->jtag)->f = &jtdev_func_bp;
|
|
|
|
if ((&dev->jtag)->f->jtdev_open(&dev->jtag, args->path) < 0) {
|
|
printc_err("bp: can't open port\n");
|
|
free(dev);
|
|
return NULL;
|
|
}
|
|
|
|
if (jtag_dev_init(&dev->jtag) < 0) {
|
|
printc_err("bp: initialization failed\n");
|
|
free(dev);
|
|
return NULL;
|
|
}
|
|
|
|
return &dev->jtag.base;
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
static void pif_destroy(device_t dev_base)
|
|
{
|
|
struct pif_device *dev = (struct pif_device *)dev_base;
|
|
|
|
dev->jtag.failed = 0;
|
|
|
|
jtag_release_device(&dev->jtag, 0xfffe);
|
|
(&dev->jtag)->f->jtdev_close(&dev->jtag);
|
|
free(dev);
|
|
}
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
const struct device_class device_pif = {
|
|
.name = "pif",
|
|
.help = "Parallel Port JTAG",
|
|
.open = pif_open,
|
|
.destroy = pif_destroy,
|
|
.readmem = jtag_dev_readmem,
|
|
.writemem = jtag_dev_writemem,
|
|
.getregs = jtag_dev_getregs,
|
|
.setregs = jtag_dev_setregs,
|
|
.ctl = jtag_dev_ctl,
|
|
.poll = jtag_dev_poll,
|
|
.erase = jtag_dev_erase,
|
|
.getconfigfuses = jtag_dev_getconfigfuses
|
|
};
|
|
|
|
const struct device_class device_gpio = {
|
|
.name = "gpio",
|
|
.help = "/sys/class/gpio direct connect",
|
|
.open = gpio_open,
|
|
.destroy = pif_destroy,
|
|
.readmem = jtag_dev_readmem,
|
|
.writemem = jtag_dev_writemem,
|
|
.getregs = jtag_dev_getregs,
|
|
.setregs = jtag_dev_setregs,
|
|
.ctl = jtag_dev_ctl,
|
|
.poll = jtag_dev_poll,
|
|
.erase = jtag_dev_erase,
|
|
.getconfigfuses = jtag_dev_getconfigfuses
|
|
};
|
|
|
|
const struct device_class device_bp = {
|
|
.name = "bus-pirate",
|
|
.help = "Bus Pirate JTAG, MISO-TDO, MOSI-TDI, CS-TMS, AUX-RESET, CLK-TCK",
|
|
.open = bp_open,
|
|
.destroy = pif_destroy,
|
|
.readmem = jtag_dev_readmem,
|
|
.writemem = jtag_dev_writemem,
|
|
.getregs = jtag_dev_getregs,
|
|
.setregs = jtag_dev_setregs,
|
|
.ctl = jtag_dev_ctl,
|
|
.poll = jtag_dev_poll,
|
|
.erase = jtag_dev_erase,
|
|
.getconfigfuses = jtag_dev_getconfigfuses
|
|
};
|