On Thursday, August 19, 2010 15:17:41 Frans Meulenbroeks wrote: > 2010/8/19 Mike Frysinger <[email protected]>: > > On Thursday, August 19, 2010 12:15:45 Frans Meulenbroeks wrote: > >> Hm. I thought about open/close too. Triggered by your comments I wrote > >> a small test app. > >> If I use fopen/fclose and in a while loop do: > >> fputc('0', fp); > >> fputc('1', fp); > >> I get a wave with period 1.96 uS. > >> If I move to open/close with a while loop like: > >> write(fd, "0", 1); > >> write(fd, "1", 1); > >> the period reduces to 1.53 uS. > >> Same hw (1.2 ghz ppc) > > > > but what is the difference in your jtag transfers ? > > I've no idea, I just crafted a small test program that toggles the gpio > flag. I didn't get to converting the whole gpio module
the gpio cable driver is trivially simple and takes no time at all to convert.
i however have no hardware readily available to test this.
--- src/tap/cable/gpio.c (revision 1830)
+++ src/tap/cable/gpio.c (working copy)
@@ -56,7 +56,7 @@ typedef struct {
unsigned int jtag_gpios[4];
int signals;
uint32_t lastout;
- FILE *fp_gpios[4];
+ int fd_gpios[4];
} gpio_params_t;
static int gpio_export (unsigned int gpio, int export)
@@ -113,11 +113,12 @@ static int gpio_direction (unsigned int
return URJ_STATUS_OK;
}
-static int gpio_set_value (FILE *fp, int value)
+static int gpio_set_value (int fd, int value)
{
- int ret;
+ ssize_t ret;
+ char gpio_value = '0' + value;
- ret = fprintf (fp, "%u", value ? 1 : 0);
+ ret = write (fd, &gpio_value, 1);
if (ret != 1)
{
urj_warning (_("Error setting value gpio\n"));
@@ -127,20 +128,19 @@ static int gpio_set_value (FILE *fp, int
return URJ_STATUS_OK;
}
-static int gpio_get_value (FILE *fp, unsigned int gpio)
+static int gpio_get_value (int fd, unsigned int gpio)
{
- int ret;
- int value;
-
- ret = fscanf (fp, "%i", &value);
+ ssize_t ret;
+ char value;
+ ret = read (fd, &value, 1);
if (ret != 1)
{
urj_warning (_("Error getting value of gpio %u\n"), gpio);
return URJ_STATUS_FAIL;
}
- return value;
+ return value == '1';
}
static int
@@ -163,23 +163,14 @@ gpio_open (urj_cable_t *cable)
}
gpio_direction (gpio, (i == GPIO_TDO) ? 0 : 1);
- p->fp_gpios[i] = NULL;
snprintf (fname, sizeof (fname), "%sgpio%u/value", GPIO_PATH, gpio);
fname[sizeof (fname) - 1] = '\0';
- if (i != GPIO_TDO)
- p->fp_gpios[i] = fopen (fname, "w");
- else
- p->fp_gpios[i] = fopen (fname, "r");
- if (!p->fp_gpios[i])
+ p->fd_gpios[i] = open (fname, O_RDWR);
+ if (p->fd_gpios[i] == -1)
{
urj_warning (_("%s: cannot open gpio[%d] %u\n"), fname, i, gpio);
return URJ_STATUS_FAIL;
}
- if (setvbuf(p->fp_gpios[i], (char *)NULL, _IONBF, 0))
- {
- urj_warning (_("gpio[%d] %u still in buffered mode\n"), i, gpio);
- return URJ_STATUS_FAIL;
- }
}
return URJ_STATUS_OK;
@@ -193,8 +184,7 @@ gpio_close (urj_cable_t *cable)
for (i = 0; i < GPIO_REQUIRED; i++)
{
- if (p->fp_gpios[i])
- fclose (p->fp_gpios[i]);
+ close (p->fd_gpios[i]);
gpio_export (p->jtag_gpios[i], 0);
}
@@ -318,14 +308,14 @@ gpio_clock (urj_cable_t *cable, int tms,
tms = tms ? 1 : 0;
tdi = tdi ? 1 : 0;
- gpio_set_value (p->fp_gpios[GPIO_TMS], tms);
- gpio_set_value (p->fp_gpios[GPIO_TDI], tdi);
+ gpio_set_value (p->fd_gpios[GPIO_TMS], tms);
+ gpio_set_value (p->fd_gpios[GPIO_TDI], tdi);
for (i = 0; i < n; i++)
{
- gpio_set_value (p->fp_gpios[GPIO_TCK], 0);
- gpio_set_value (p->fp_gpios[GPIO_TCK], 1);
- gpio_set_value (p->fp_gpios[GPIO_TCK], 0);
+ gpio_set_value (p->fd_gpios[GPIO_TCK], 0);
+ gpio_set_value (p->fd_gpios[GPIO_TCK], 1);
+ gpio_set_value (p->fd_gpios[GPIO_TCK], 0);
}
}
@@ -334,14 +324,14 @@ gpio_get_tdo ( urj_cable_t *cable )
{
gpio_params_t *p = cable->params;
- gpio_set_value(p->fp_gpios[GPIO_TCK], 0);
- gpio_set_value(p->fp_gpios[GPIO_TDI], 0);
- gpio_set_value(p->fp_gpios[GPIO_TMS], 0);
+ gpio_set_value(p->fd_gpios[GPIO_TCK], 0);
+ gpio_set_value(p->fd_gpios[GPIO_TDI], 0);
+ gpio_set_value(p->fd_gpios[GPIO_TMS], 0);
p->lastout &= ~(URJ_POD_CS_TMS | URJ_POD_CS_TDI | URJ_POD_CS_TCK);
urj_tap_cable_wait (cable);
- return gpio_get_value (p->fp_gpios[GPIO_TDO], p->jtag_gpios[GPIO_TDO]);
+ return gpio_get_value (p->fd_gpios[GPIO_TDO], p->jtag_gpios[GPIO_TDO]);
}
static int
@@ -369,11 +359,11 @@ gpio_set_signal (urj_cable_t *cable, int
if (mask != 0)
{
if (mask & URJ_POD_CS_TMS)
- gpio_set_value (p->fp_gpios[GPIO_TMS], val & URJ_POD_CS_TMS);
+ gpio_set_value (p->fd_gpios[GPIO_TMS], val & URJ_POD_CS_TMS);
if (mask & URJ_POD_CS_TDI)
- gpio_set_value (p->fp_gpios[GPIO_TDI], val & URJ_POD_CS_TDI);
+ gpio_set_value (p->fd_gpios[GPIO_TDI], val & URJ_POD_CS_TDI);
if (mask & URJ_POD_CS_TCK)
- gpio_set_value (p->fp_gpios[GPIO_TCK], val & URJ_POD_CS_TCK);
+ gpio_set_value (p->fd_gpios[GPIO_TCK], val & URJ_POD_CS_TCK);
}
p->lastout = val & mask;
-mike
signature.asc
Description: This is a digitally signed message part.
------------------------------------------------------------------------------ This SF.net email is sponsored by Make an app they can't live without Enter the BlackBerry Developer Challenge http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________ UrJTAG-development mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/urjtag-development
