On Thursday, August 19, 2010 12:13:22 Frans Meulenbroeks wrote: > 2010/8/19 Mike Frysinger <[email protected]>: > > On Thursday, August 19, 2010 03:23:48 Frans Meulenbroeks wrote: > >> improve the speed of gpio_set_valuea by using fputc instead of fprintf > >> the overhead of fputc is less as no format string needs to be scanned > >> and processed. Also used value + '0' so no conversion is needed > > > > i'd like an ack from Stefano, but this looks fine > > > > couldnt you also use fgetc() in get_value ? > > > > perhaps we should add to the top of both funcs that we assume the sysfs > > layer is working only with '1' and '0'. that would keep things from > > doing fprintf/fscanf. i think that's an OK assumption to make. > > Technically using fgetc in get_value could be done. > Then again I don't expect that one to be used often. > If we want to optimize get_value, I think it is better to take the > open and close calls out of the function (like currently is the case > for the set function).
err, that's odd ... we already cached a fp to that. how about this patch:
--- src/tap/cable/gpio.c (revision 1828)
+++ src/tap/cable/gpio.c (working copy)
@@ -127,26 +127,12 @@ static int gpio_set_value (FILE *fp, int
return URJ_STATUS_OK;
}
-static int gpio_get_value (unsigned int gpio)
+static int gpio_get_value (FILE *fp, unsigned int gpio)
{
int ret;
int value;
- char fname[50];
- FILE *fp;
-
- snprintf (fname, sizeof (fname),
- "%sgpio%u/value", GPIO_PATH, gpio);
- fname[sizeof (fname) - 1] = '\0';
-
- fp = fopen (fname, "r");
- if (!fp)
- {
- urj_warning (_("%s: cannot open to read GPIO %u\n"), fname, gpio);
- return URJ_STATUS_FAIL;
- }
ret = fscanf (fp, "%i", &value);
- fclose (fp);
if (ret != 1)
{
@@ -355,7 +341,7 @@ gpio_get_tdo ( urj_cable_t *cable )
urj_tap_cable_wait (cable);
- return (gpio_get_value (p->jtag_gpios[GPIO_TDO]));
+ return gpio_get_value (p->fp_gpios[GPIO_TDO], p->jtag_gpios[GPIO_TDO]);
}
static int
-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
