2012-10-11 22:33:20 +00:00
|
|
|
/* MSPDebug - debugging tool for MSP430 MCUs
|
|
|
|
* Copyright (C) 2009-2012 Daniel Beer
|
|
|
|
* Copyright (C) 2012 Peter Bägel
|
|
|
|
*
|
2013-12-11 01:57:54 +00:00
|
|
|
* ppdev/ppi abstraction inspired by uisp src/DARPA.C
|
|
|
|
* originally written by Sergey Larin;
|
|
|
|
* corrected by Denis Chertykov, Uros Platise and Marek Michalkiewicz.
|
|
|
|
*
|
2012-10-11 22:33:20 +00:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "jtdev.h"
|
|
|
|
#include "output.h"
|
|
|
|
|
2013-12-11 10:17:07 +00:00
|
|
|
#if defined(__linux__) || \
|
|
|
|
( defined(__FreeBSD__) || defined(__DragonFly__) )
|
2012-10-11 22:33:20 +00:00
|
|
|
/*===== includes =============================================================*/
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2013-12-11 01:57:54 +00:00
|
|
|
|
|
|
|
#if defined(__linux__)
|
|
|
|
|
2012-10-11 22:33:20 +00:00
|
|
|
#include <linux/ppdev.h>
|
2013-12-11 01:57:54 +00:00
|
|
|
|
|
|
|
#define par_claim(fd) ioctl(fd, PPCLAIM, NULL)
|
|
|
|
#define par_write_data(fd, ptr) ioctl(fd, PPWDATA, ptr)
|
|
|
|
#define par_write_control(fd, ptr) ioctl(fd, PPWCONTROL, ptr)
|
|
|
|
#define par_release(fd) ioctl(fd, PPRELEASE, NULL)
|
|
|
|
#define par_read_status(fd, ptr) ioctl(fd, PPRSTATUS, ptr)
|
|
|
|
|
2013-12-11 10:17:07 +00:00
|
|
|
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
2013-12-11 01:57:54 +00:00
|
|
|
|
2013-12-12 09:49:48 +00:00
|
|
|
#if defined(__FreeBSD__)
|
2013-12-11 01:57:54 +00:00
|
|
|
#include <dev/ppbus/ppi.h>
|
|
|
|
#include <dev/ppbus/ppbconf.h>
|
2013-12-12 09:49:48 +00:00
|
|
|
#else /* __DragonFly__ */
|
|
|
|
#include <dev/misc/ppi/ppi.h>
|
|
|
|
#include <bus/ppbus/ppbconf.h>
|
|
|
|
#endif
|
2013-12-11 01:57:54 +00:00
|
|
|
|
|
|
|
#define par_claim(fd) (0)
|
|
|
|
#define par_write_data(fd, ptr) ioctl(fd, PPISDATA, ptr)
|
|
|
|
#define par_write_control(fd, ptr) ioctl(fd, PPISCTRL, ptr)
|
|
|
|
#define par_release(fd) (0)
|
|
|
|
#define par_read_status(fd, ptr) ioctl(fd, PPIGSTATUS, ptr)
|
|
|
|
|
2013-12-11 10:17:07 +00:00
|
|
|
#endif /* __linux__ || (__FreeBSD__ || __DragonFly__) */
|
2013-12-11 01:57:54 +00:00
|
|
|
|
2012-10-11 22:33:20 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
/*===== private symbols ======================================================*/
|
|
|
|
|
|
|
|
/*--- port data (out) ---*/
|
|
|
|
#define DATA0 ((unsigned char)0x01)
|
|
|
|
#define DATA1 ((unsigned char)0x02)
|
|
|
|
#define DATA2 ((unsigned char)0x04)
|
|
|
|
#define DATA3 ((unsigned char)0x08)
|
|
|
|
#define DATA4 ((unsigned char)0x10)
|
|
|
|
#define DATA5 ((unsigned char)0x20)
|
|
|
|
#define DATA6 ((unsigned char)0x40)
|
|
|
|
#define DATA7 ((unsigned char)0x80)
|
|
|
|
|
|
|
|
/*--- port status (in) ---*/
|
|
|
|
#define ERR ((unsigned char)0x08)
|
|
|
|
#define SEL ((unsigned char)0x10)
|
|
|
|
#define PE ((unsigned char)0x20)
|
|
|
|
#define ACK ((unsigned char)0x40)
|
|
|
|
#define BUSY ((unsigned char)0x80)
|
|
|
|
|
|
|
|
/*--- port control (out) ---*/
|
2013-12-11 01:57:54 +00:00
|
|
|
#ifndef STROBE
|
2012-10-11 22:33:20 +00:00
|
|
|
#define STROBE ((unsigned char)0x01) /* inverted by PC-hardware */
|
2013-12-11 01:57:54 +00:00
|
|
|
#endif
|
|
|
|
#ifndef AUTOFEED
|
2012-10-11 22:33:20 +00:00
|
|
|
#define AUTOFEED ((unsigned char)0x02)
|
2013-12-11 01:57:54 +00:00
|
|
|
#endif
|
|
|
|
#ifndef INIT
|
2012-10-11 22:33:20 +00:00
|
|
|
#define INIT ((unsigned char)0x04)
|
2013-12-11 01:57:54 +00:00
|
|
|
#endif
|
|
|
|
#ifndef SELECTIN
|
2012-10-11 22:33:20 +00:00
|
|
|
#define SELECTIN ((unsigned char)0x08)
|
2013-12-11 01:57:54 +00:00
|
|
|
#endif
|
2012-10-11 22:33:20 +00:00
|
|
|
#define IRQEN ((unsigned char)0x10)
|
|
|
|
|
|
|
|
/*--- JTAG signal mapping ---*/
|
|
|
|
#define TEST INIT
|
|
|
|
#define TDO PE
|
|
|
|
#define TDI DATA0
|
|
|
|
#define TMS DATA1
|
|
|
|
#define TCK DATA2
|
|
|
|
#define XOUT DATA3
|
|
|
|
#define POWER (DATA4 | DATA7)
|
|
|
|
#define RESET STROBE
|
|
|
|
#define ENABLE (SELECTIN | AUTOFEED)
|
|
|
|
#define LED_GREEN DATA5
|
|
|
|
#define LED_RED DATA6
|
|
|
|
|
|
|
|
#define TCLK TDI
|
|
|
|
|
|
|
|
/*===== public functions =====================================================*/
|
|
|
|
|
|
|
|
static void do_ppwdata(struct jtdev *p)
|
|
|
|
{
|
2013-12-11 01:57:54 +00:00
|
|
|
if (par_write_data(p->port, &p->data_register) < 0) {
|
2013-12-11 10:17:07 +00:00
|
|
|
pr_error("jtdev: par_write_data");
|
2012-10-11 22:33:20 +00:00
|
|
|
p->failed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_ppwcontrol(struct jtdev *p)
|
|
|
|
{
|
2013-12-11 01:57:54 +00:00
|
|
|
if (par_write_control(p->port, &p->control_register) < 0) {
|
2013-12-11 10:17:07 +00:00
|
|
|
pr_error("jtdev: par_write_control");
|
2012-10-11 22:33:20 +00:00
|
|
|
p->failed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static int jtpif_open(struct jtdev *p, const char *device)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
|
|
|
p->port = open(device, O_RDWR);
|
|
|
|
if (p->port < 0) {
|
|
|
|
printc_err("jtdev: can't open %s: %s\n",
|
|
|
|
device, last_error());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-12-11 01:57:54 +00:00
|
|
|
if (par_claim(p->port) < 0) {
|
2013-12-11 10:17:07 +00:00
|
|
|
printc_err("jtdev: par_claim: %s: %s\n",
|
2012-10-11 22:33:20 +00:00
|
|
|
device, last_error());
|
|
|
|
close(p->port);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
p->data_register = 0;
|
|
|
|
p->control_register = 0;
|
|
|
|
p->failed = 0;
|
|
|
|
|
|
|
|
do_ppwdata(p);
|
|
|
|
do_ppwcontrol(p);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_close(struct jtdev *p)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
2013-12-11 01:57:54 +00:00
|
|
|
if (par_release(p->port) < 0)
|
2012-10-11 22:33:20 +00:00
|
|
|
pr_error("warning: jtdev: failed to release port");
|
|
|
|
|
|
|
|
close(p->port);
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_power_on(struct jtdev *p)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
|
|
|
/* power supply on */
|
|
|
|
p->data_register |= POWER;
|
|
|
|
do_ppwdata(p);
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_power_off(struct jtdev *p)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
|
|
|
/* power supply off */
|
|
|
|
p->data_register &= ~POWER;
|
|
|
|
do_ppwdata(p);
|
|
|
|
|
|
|
|
/* a high, inactive reset also powers the target */
|
|
|
|
/* reset pin is inverted by PC hardware */
|
|
|
|
p->control_register |= RESET;
|
|
|
|
do_ppwcontrol(p);
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_connect(struct jtdev *p)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
|
|
|
p->control_register |= (TEST | ENABLE);
|
|
|
|
do_ppwcontrol(p);
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_release(struct jtdev *p)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
|
|
|
p->control_register &= ~(TEST | ENABLE);
|
|
|
|
do_ppwcontrol(p);
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_tck(struct jtdev *p, int out)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
|
|
|
if (out)
|
|
|
|
p->data_register |= TCK;
|
|
|
|
else
|
|
|
|
p->data_register &= ~TCK;
|
|
|
|
|
|
|
|
do_ppwdata(p);
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_tms(struct jtdev *p, int out)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
|
|
|
if (out)
|
|
|
|
p->data_register |= TMS;
|
|
|
|
else
|
|
|
|
p->data_register &= ~TMS;
|
|
|
|
|
|
|
|
do_ppwdata(p);
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_tdi(struct jtdev *p, int out)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
|
|
|
if (out)
|
|
|
|
p->data_register |= TDI;
|
|
|
|
else
|
|
|
|
p->data_register &= ~TDI;
|
|
|
|
|
|
|
|
do_ppwdata(p);
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_rst(struct jtdev *p, int out)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
|
|
|
/* reset pin is inverted by PC hardware */
|
|
|
|
if (out)
|
|
|
|
p->control_register &= ~RESET;
|
|
|
|
else
|
|
|
|
p->control_register |= RESET;
|
|
|
|
|
|
|
|
do_ppwcontrol(p);
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_tst(struct jtdev *p, int out)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
|
|
|
if (out)
|
|
|
|
p->control_register |= TEST;
|
|
|
|
else
|
|
|
|
p->control_register &= ~TEST;
|
|
|
|
|
|
|
|
do_ppwcontrol(p);
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static int jtpif_tdo_get(struct jtdev *p)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
|
|
|
uint8_t input;
|
|
|
|
|
2013-12-11 01:57:54 +00:00
|
|
|
if (par_read_status(p->port, &input) < 0) {
|
2013-12-11 10:17:07 +00:00
|
|
|
pr_error("jtdev: par_read_status:");
|
2012-10-11 22:33:20 +00:00
|
|
|
p->failed = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (input & TDO) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_tclk(struct jtdev *p, int out)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
|
|
|
if (out)
|
|
|
|
p->data_register |= TCLK;
|
|
|
|
else
|
|
|
|
p->data_register &= ~TCLK;
|
|
|
|
|
|
|
|
do_ppwdata(p);
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static int jtpif_tclk_get(struct jtdev *p)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
|
|
|
return (p->data_register & TCLK) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_tclk_strobe(struct jtdev *p, unsigned int count)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
2015-02-03 18:42:23 +00:00
|
|
|
jtpif_tclk(p, 1);
|
|
|
|
jtpif_tclk(p, 0);
|
2012-10-11 22:33:20 +00:00
|
|
|
|
|
|
|
if (p->failed)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_led_green(struct jtdev *p, int out)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
|
|
|
if (out)
|
|
|
|
p->data_register |= LED_GREEN;
|
|
|
|
else
|
|
|
|
p->data_register &= ~LED_GREEN;
|
|
|
|
|
|
|
|
do_ppwdata(p);
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_led_red(struct jtdev *p, int out)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
|
|
|
if (out)
|
|
|
|
p->data_register |= LED_RED;
|
|
|
|
else
|
|
|
|
p->data_register &= ~LED_RED;
|
|
|
|
|
|
|
|
do_ppwdata(p);
|
|
|
|
}
|
|
|
|
#else /* __linux__ */
|
2015-02-03 18:42:23 +00:00
|
|
|
static int jtpif_open(struct jtdev *p, const char *device)
|
2012-10-11 22:33:20 +00:00
|
|
|
{
|
2013-12-11 10:17:07 +00:00
|
|
|
printc_err("jtdev: driver is not supported on this platform\n");
|
2012-10-11 22:33:20 +00:00
|
|
|
p->failed = 1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_close(struct jtdev *p) { }
|
2012-10-11 22:33:20 +00:00
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_power_on(struct jtdev *p) { }
|
|
|
|
static void jtpif_power_off(struct jtdev *p) { }
|
|
|
|
static void jtpif_connect(struct jtdev *p) { }
|
|
|
|
static void jtpif_release(struct jtdev *p) { }
|
2012-10-11 22:33:20 +00:00
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_tck(struct jtdev *p, int out) { }
|
|
|
|
static void jtpif_tms(struct jtdev *p, int out) { }
|
|
|
|
static void jtpif_tdi(struct jtdev *p, int out) { }
|
|
|
|
static void jtpif_rst(struct jtdev *p, int out) { }
|
|
|
|
static void jtpif_tst(struct jtdev *p, int out) { }
|
|
|
|
static int jtpif_tdo_get(struct jtdev *p) { return 0; }
|
2012-10-11 22:33:20 +00:00
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_tclk(struct jtdev *p, int out) { }
|
|
|
|
static int jtpif_tclk_get(struct jtdev *p) { return 0; }
|
|
|
|
static void jtpif_tclk_strobe(struct jtdev *p, unsigned int count) { }
|
2012-10-11 22:33:20 +00:00
|
|
|
|
2015-02-03 18:42:23 +00:00
|
|
|
static void jtpif_led_green(struct jtdev *p, int out) { }
|
|
|
|
static void jtpif_led_red(struct jtdev *p, int out) { }
|
2012-10-11 22:33:20 +00:00
|
|
|
#endif
|
2015-02-03 18:42:23 +00:00
|
|
|
|
|
|
|
const struct jtdev_func jtdev_func_pif = {
|
|
|
|
.jtdev_open = jtpif_open,
|
|
|
|
.jtdev_close = jtpif_close,
|
|
|
|
.jtdev_power_on = jtpif_power_on,
|
|
|
|
.jtdev_power_off = jtpif_power_off,
|
|
|
|
.jtdev_connect = jtpif_connect,
|
|
|
|
.jtdev_release = jtpif_release,
|
|
|
|
.jtdev_tck = jtpif_tck,
|
|
|
|
.jtdev_tms = jtpif_tms,
|
|
|
|
.jtdev_tdi = jtpif_tdi,
|
|
|
|
.jtdev_rst = jtpif_rst,
|
|
|
|
.jtdev_tst = jtpif_tst,
|
|
|
|
.jtdev_tdo_get = jtpif_tdo_get,
|
|
|
|
.jtdev_tclk = jtpif_tclk,
|
|
|
|
.jtdev_tclk_get = jtpif_tclk_get,
|
|
|
|
.jtdev_tclk_strobe = jtpif_tclk_strobe,
|
|
|
|
.jtdev_led_green = jtpif_led_green,
|
|
|
|
.jtdev_led_red = jtpif_led_red
|
|
|
|
};
|
|
|
|
|