1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
/* MSPDebug - gpio device interface
* Copyright (C) 2014 TTI GmbH - TGU Smartmote
* Author(s): Jan Willeke (willeke@smartmote.de)
*
* Linux /sys/class/gpio interface to msp430 jtag
* inspired by urjtag and jtdev.c
*
* 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"
#if defined(__linux__) || \
( defined(__FreeBSD__) || defined(__DragonFly__) )
/*===== includes =============================================================*/
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include "gpio.h"
/* pin mapping */
enum {
GPIO_TDI = 0,
GPIO_TCK,
GPIO_TMS,
GPIO_TDO,
GPIO_RST,
GPIO_TST,
GPIO_REQUIRED
};
unsigned int jtag_gpios[6];
int fd_gpios[6];
static int
gpio_open ()
{
int i, ret;
/* Export all gpios */
for (i = 0; i < GPIO_REQUIRED; i++)
{
unsigned int gpio = jtag_gpios[i];
ret = gpio_export (gpio);
if (ret)
{
printf("gpio[%d] %u cannot be exported\n", i, gpio);
return -1;
}
gpio_set_dir (gpio, (i == GPIO_TDO) ? 0 : 1);
fd_gpios[i] = gpio_open_fd(gpio);
if (fd_gpios[i] < 0)
{
printf("gpio: cannot open gpio[%d] %u\n", i, gpio);
return -1;
}
}
return 0;
}
static int
gpio_parse_config (const char *params)
{
struct option{
char* name;
int num;
};
static const struct option ops[] = {
{"tms=",GPIO_TMS},
{"tdi=",GPIO_TDI},
{"tdo=",GPIO_TDO},
{"tck=",GPIO_TCK},
{"rst=",GPIO_RST},
{"tst=",GPIO_TST}
};
int i;
for( i = 0;i < 6; i++) {
char* help;
help = strstr(params,ops[i].name);
if (help)
jtag_gpios[ops[i].num] = atoi(help+4);
else
return -1;
printf("gpio %s %d\n", ops[i].name,jtag_gpios[ops[i].num]);
}
return 0;
}
static int jtgpio_open(struct jtdev *p, const char *device)
{
if (gpio_parse_config(device)){
printf("gpio: failed parsing parameters\n");
return -1;
}
return gpio_open();
}
static void jtgpio_close(struct jtdev *p)
{
int i;
printf("JTAG_CLOSE\n");
for (i = 0; i < GPIO_REQUIRED; i++)
{
if (fd_gpios[i])
close (fd_gpios[i]);
gpio_unexport (jtag_gpios[i]);
}
}
static void jtgpio_power_on(struct jtdev *p)
{
printf("JTAG_power on\n");
}
static void jtgpio_power_off(struct jtdev *p)
{
printf("JTAG_power off\n");
}
static void jtgpio_connect(struct jtdev *p)
{
printf("JTAG_connct \n");
}
static void jtgpio_release(struct jtdev *p)
{
printf("JTAG_release\n");
}
static void jtgpio_tck(struct jtdev *p, int out)
{
gpio_set_value_fd (fd_gpios[GPIO_TCK], out);
}
static void jtgpio_tms(struct jtdev *p, int out)
{
gpio_set_value_fd (fd_gpios[GPIO_TMS], out);
}
static void jtgpio_tdi(struct jtdev *p, int out)
{
gpio_set_value_fd (fd_gpios[GPIO_TDI], out);
}
static void jtgpio_rst(struct jtdev *p, int out)
{
gpio_set_value_fd (fd_gpios[GPIO_RST], out);
}
static void jtgpio_tst(struct jtdev *p, int out)
{
gpio_set_value_fd (fd_gpios[GPIO_TST], out);
}
static int jtgpio_tdo_get(struct jtdev *p)
{
return gpio_get_value_fd (fd_gpios[GPIO_TDO],
jtag_gpios[GPIO_TDO]);
}
static void jtgpio_tclk(struct jtdev *p, int out)
{
gpio_set_value_fd (fd_gpios[GPIO_TDI], out);
}
static int jtgpio_tclk_get(struct jtdev *p)
{
return gpio_get_value_fd (fd_gpios[GPIO_TDI],
jtag_gpios[GPIO_TDI]);
}
static void jtgpio_tclk_strobe(struct jtdev *p, unsigned int count)
{
int i;
for (i=0;i<count;i++){
gpio_set_value_fd (fd_gpios[GPIO_TDI], 1);
gpio_set_value_fd (fd_gpios[GPIO_TDI], 0);
}
}
static void jtgpio_led_green(struct jtdev *p, int out)
{
printf("led green\n");
}
static void jtgpio_led_red(struct jtdev *p, int out)
{
printf("led red\n");
}
#else /* __linux__ */
static int jtgpio_open(struct jtdev *p, const char *device)
{
printc_err("jtdev: driver is not supported on this platform\n");
p->failed = 1;
return -1;
}
static void jtgpio_close(struct jtdev *p) { }
static void jtgpio_power_on(struct jtdev *p) { }
static void jtgpio_power_off(struct jtdev *p) { }
static void jtgpio_connect(struct jtdev *p) { }
static void jtgpio_release(struct jtdev *p) { }
static void jtgpio_tck(struct jtdev *p, int out) { }
static void jtgpio_tms(struct jtdev *p, int out) { }
static void jtgpio_tdi(struct jtdev *p, int out) { }
static void jtgpio_rst(struct jtdev *p, int out) { }
static void jtgpio_tst(struct jtdev *p, int out) { }
static int jtgpio_tdo_get(struct jtdev *p) { return 0; }
static void jtgpio_tclk(struct jtdev *p, int out) { }
static int jtgpio_tclk_get(struct jtdev *p) { return 0; }
static void jtgpio_tclk_strobe(struct jtdev *p, unsigned int count) { }
static void jtgpio_led_green(struct jtdev *p, int out) { }
static void jtgpio_led_red(struct jtdev *p, int out) { }
#endif
const struct jtdev_func jtdev_func_gpio = {
.jtdev_open = jtgpio_open,
.jtdev_close = jtgpio_close,
.jtdev_power_on = jtgpio_power_on,
.jtdev_power_off = jtgpio_power_off,
.jtdev_connect = jtgpio_connect,
.jtdev_release = jtgpio_release,
.jtdev_tck = jtgpio_tck,
.jtdev_tms = jtgpio_tms,
.jtdev_tdi = jtgpio_tdi,
.jtdev_rst = jtgpio_rst,
.jtdev_tst = jtgpio_tst,
.jtdev_tdo_get = jtgpio_tdo_get,
.jtdev_tclk = jtgpio_tclk,
.jtdev_tclk_get = jtgpio_tclk_get,
.jtdev_tclk_strobe = jtgpio_tclk_strobe,
.jtdev_led_green = jtgpio_led_green,
.jtdev_led_red = jtgpio_led_red
};
|