2003-03-18 Marcel Telka <marcel@telka.sk>
* include/parport.h: New file. Added parport driver support. All cable drivers modified. * src/tap/parport.c: Ditto. * src/tap/parport/direct.c: Ditto. * src/jtag.c (jtag_parse_line) <cable>: Added parport driver support. * include/Makefile.am (noinst_HEADERS): Added parport.h. * src/tap/cable/generic.c: New file withgGeneric functions for cable drivers. All cable drivers modified. * src/tap/cable/generic.h: Ditto. * src/tap/Makefile.am (libtap_a_SOURCES): Added parport.c, parport/direct.c, cable/generic.h, and cable/generic.c. * include/cable.h: Added dynamic cable objects. Added cable interpose functions. All callers changed. * src/tap/cable.c: Ditto. * include/chain.h (chain_connect): Function removed. (chain_disconnect): New function. * src/tap/chain.c (chain_free): Modified for chain_disconnect() call. (chain_connect): Removed. (chain_disconnect): New function. git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@397 b68d4a1b-bc3d-0410-92ed-d4ac073336b7master
parent
5c062c7022
commit
9406ed47c7
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Parallel Port Connection Driver Interface
|
||||
* Copyright (C) 2003 ETC s.r.o.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Written by Marcel Telka <marcel@telka.sk>, 2003.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PARPORT_H
|
||||
#define PARPORT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct parport_t parport_t;
|
||||
|
||||
#include "cable.h"
|
||||
|
||||
typedef struct {
|
||||
const char *type;
|
||||
cable_t *(*connect)( const char **, int );
|
||||
void (*parport_free)( parport_t * );
|
||||
int (*open)( parport_t * );
|
||||
int (*close)( parport_t * );
|
||||
int (*set_data)( parport_t *, uint8_t );
|
||||
int (*get_data)( parport_t * );
|
||||
int (*get_status)( parport_t * );
|
||||
int (*set_control)( parport_t *, uint8_t );
|
||||
} parport_driver_t;
|
||||
|
||||
struct parport_t {
|
||||
parport_driver_t *driver;
|
||||
void *params;
|
||||
cable_t *cable;
|
||||
};
|
||||
|
||||
int parport_open( parport_t *port );
|
||||
int parport_close( parport_t *port );
|
||||
int parport_set_data( parport_t *port, uint8_t data );
|
||||
int parport_get_data( parport_t *port );
|
||||
int parport_get_status( parport_t *port );
|
||||
int parport_set_control( parport_t *port, uint8_t data );
|
||||
|
||||
extern parport_driver_t *parport_drivers[];
|
||||
|
||||
#endif /* PARPORT_H */
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2003 ETC s.r.o.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Written by Marcel Telka <marcel@telka.sk>, 2003.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "cable.h"
|
||||
#include "parport.h"
|
||||
#include "chain.h"
|
||||
|
||||
#include "generic.h"
|
||||
|
||||
cable_t *
|
||||
generic_connect( cable_driver_t *cable_driver, parport_t *port )
|
||||
{
|
||||
generic_params_t *params = malloc( sizeof *params );
|
||||
cable_t *cable = malloc( sizeof *cable );
|
||||
if (!params || !cable) {
|
||||
free( params );
|
||||
free( cable );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cable->driver = cable_driver;
|
||||
cable->port = port;
|
||||
cable->params = params;
|
||||
cable->chain = NULL;
|
||||
|
||||
return cable;
|
||||
}
|
||||
|
||||
void
|
||||
generic_disconnect( cable_t *cable )
|
||||
{
|
||||
cable_done( cable );
|
||||
chain_disconnect( cable->chain );
|
||||
}
|
||||
|
||||
void
|
||||
generic_cable_free( cable_t *cable )
|
||||
{
|
||||
cable->port->driver->parport_free( cable->port );
|
||||
free( cable->params );
|
||||
free( cable );
|
||||
}
|
||||
|
||||
void
|
||||
generic_done( cable_t *cable )
|
||||
{
|
||||
parport_close( cable->port );
|
||||
}
|
||||
|
||||
int
|
||||
generic_get_trst( cable_t *cable )
|
||||
{
|
||||
return PARAM_TRST(cable);
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2003 ETC s.r.o.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Written by Marcel Telka <marcel@telka.sk>, 2003.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef GENERIC_H
|
||||
#define GENERIC_H
|
||||
|
||||
#include "cable.h"
|
||||
#include "parport.h"
|
||||
|
||||
typedef struct {
|
||||
int trst;
|
||||
} generic_params_t;
|
||||
|
||||
#define PARAM_TRST(cable) ((generic_params_t *) cable->params)->trst
|
||||
|
||||
cable_t *generic_connect( cable_driver_t *cable_driver, parport_t *port );
|
||||
void generic_disconnect( cable_t *cable );
|
||||
void generic_cable_free( cable_t *cable );
|
||||
void generic_done( cable_t *cable );
|
||||
int generic_get_trst( cable_t *cable );
|
||||
|
||||
#endif /* GENERIC_H */
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2003 ETC s.r.o.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Written by Marcel Telka <marcel@telka.sk>, 2003.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "parport.h"
|
||||
|
||||
extern parport_driver_t direct_parport_driver;
|
||||
|
||||
parport_driver_t *parport_drivers[] = {
|
||||
&direct_parport_driver,
|
||||
NULL /* last must be NULL */
|
||||
};
|
||||
|
||||
int
|
||||
parport_open( parport_t *port )
|
||||
{
|
||||
return port->driver->open( port );
|
||||
}
|
||||
|
||||
int
|
||||
parport_close( parport_t *port )
|
||||
{
|
||||
return port->driver->close( port );
|
||||
}
|
||||
|
||||
int
|
||||
parport_set_data( parport_t *port, uint8_t data )
|
||||
{
|
||||
return port->driver->set_data( port, data );
|
||||
}
|
||||
|
||||
int
|
||||
parport_get_data( parport_t *port )
|
||||
{
|
||||
return port->driver->get_data( port );
|
||||
}
|
||||
|
||||
int
|
||||
parport_get_status( parport_t *port )
|
||||
{
|
||||
return port->driver->get_status( port );
|
||||
}
|
||||
|
||||
int
|
||||
parport_set_control( parport_t *port, uint8_t data )
|
||||
{
|
||||
return port->driver->set_control( port, data );
|
||||
}
|
@ -0,0 +1,216 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Direct Parallel Port Connection Driver
|
||||
* Copyright (C) 2003 ETC s.r.o.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Written by Marcel Telka <marcel@telka.sk>, 2003.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "gettext.h"
|
||||
#define _(s) gettext(s)
|
||||
#define N_(s) gettext_noop(s)
|
||||
#define P_(s,p,n) ngettext(s,p,n)
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/io.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "parport.h"
|
||||
#include "cable.h"
|
||||
|
||||
parport_driver_t direct_parport_driver;
|
||||
|
||||
typedef struct port_node_t port_node_t;
|
||||
|
||||
struct port_node_t {
|
||||
parport_t *port;
|
||||
port_node_t *next;
|
||||
};
|
||||
|
||||
static port_node_t *ports = NULL; /* direct parallel ports */
|
||||
|
||||
typedef struct {
|
||||
unsigned int port;
|
||||
} direct_params_t;
|
||||
|
||||
static parport_t *
|
||||
direct_parport_alloc( unsigned int port )
|
||||
{
|
||||
direct_params_t *params = malloc( sizeof *params );
|
||||
parport_t *parport = malloc( sizeof *parport );
|
||||
port_node_t *node = malloc( sizeof *node );
|
||||
|
||||
if (!node || !parport || !params) {
|
||||
free( node );
|
||||
free( parport );
|
||||
free( params );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
params->port = port;
|
||||
|
||||
parport->params = params;
|
||||
parport->driver = &direct_parport_driver;
|
||||
parport->cable = NULL;
|
||||
|
||||
node->port = parport;
|
||||
node->next = ports;
|
||||
|
||||
ports = node;
|
||||
|
||||
return parport;
|
||||
}
|
||||
|
||||
static void
|
||||
direct_parport_free( parport_t *port )
|
||||
{
|
||||
port_node_t **prev;
|
||||
|
||||
for (prev = &ports; *prev; prev = &((*prev)->next))
|
||||
if ((*prev)->port == port)
|
||||
break;
|
||||
|
||||
if (*prev) {
|
||||
port_node_t *pn = *prev;
|
||||
*prev = pn->next;
|
||||
free( pn );
|
||||
}
|
||||
|
||||
free( port->params );
|
||||
free( port );
|
||||
}
|
||||
|
||||
static cable_t *
|
||||
direct_connect( const char **par, int parnum )
|
||||
{
|
||||
int i;
|
||||
unsigned int port;
|
||||
port_node_t *pn;
|
||||
parport_t *parport;
|
||||
cable_t *cable;
|
||||
|
||||
if (parnum != 2) {
|
||||
printf( _("Syntax error!\n") );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((sscanf( par[0], "0x%x", &port ) != 1) && (sscanf( par[0], "%d", &port ) != 1)) {
|
||||
printf( _("Invalid port address!\n") );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (pn = ports; pn; pn = pn->next) {
|
||||
unsigned int aport;
|
||||
|
||||
aport = ((direct_params_t*) pn->port->params)->port;
|
||||
if (abs( aport - port ) < 3) {
|
||||
printf( _("Disconnecting %s from parallel port at 0x%x\n"), pn->port->cable->driver->description, aport );
|
||||
pn->port->cable->driver->disconnect( pn->port->cable );
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp( par[1], "none" ) == 0) {
|
||||
printf( _("Changed cable to 'none'\n") );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; cable_drivers[i]; i++)
|
||||
if (strcmp( par[1], cable_drivers[i]->name ) == 0)
|
||||
break;
|
||||
|
||||
if (!cable_drivers[i]) {
|
||||
printf( _("Unknown cable: %s\n"), par[1] );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
printf( _("Initializing %s on parallel port at 0x%x\n"), cable_drivers[i]->description, port );
|
||||
|
||||
parport = direct_parport_alloc( port );
|
||||
if (!parport) {
|
||||
printf( _("%s(%d) Out of memory.\n"), __FILE__, __LINE__ );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cable = cable_drivers[i]->connect( cable_drivers[i], parport );
|
||||
if (!cable)
|
||||
direct_parport_free( parport );
|
||||
|
||||
return cable;
|
||||
}
|
||||
|
||||
static int
|
||||
direct_open( parport_t *parport )
|
||||
{
|
||||
unsigned int port = ((direct_params_t *) parport->params)->port;
|
||||
return ((port + 3 <= 0x400) && ioperm( port, 3, 1 )) || ((port + 3 > 0x400) && iopl( 3 ));
|
||||
}
|
||||
|
||||
static int
|
||||
direct_close( parport_t *parport )
|
||||
{
|
||||
unsigned int port = ((direct_params_t *) parport->params)->port;
|
||||
return (port + 3 <= 0x400) ? ioperm( port, 3, 0 ) : iopl( 0 );
|
||||
}
|
||||
|
||||
static int
|
||||
direct_set_data( parport_t *parport, uint8_t data )
|
||||
{
|
||||
unsigned int port = ((direct_params_t *) parport->params)->port;
|
||||
outb( data, port );
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
direct_get_data( parport_t *parport )
|
||||
{
|
||||
unsigned int port = ((direct_params_t *) parport->params)->port;
|
||||
return inb( port );
|
||||
}
|
||||
|
||||
static int
|
||||
direct_get_status( parport_t *parport )
|
||||
{
|
||||
unsigned int port = ((direct_params_t *) parport->params)->port;
|
||||
return inb( port + 1 ) ^ 0x80; /* BUSY is inverted */
|
||||
}
|
||||
|
||||
static int
|
||||
direct_set_control( parport_t *parport, uint8_t data )
|
||||
{
|
||||
unsigned int port = ((direct_params_t *) parport->params)->port;
|
||||
outb( data, port + 2 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
parport_driver_t direct_parport_driver = {
|
||||
"parallel",
|
||||
direct_connect,
|
||||
direct_parport_free,
|
||||
direct_open,
|
||||
direct_close,
|
||||
direct_set_data,
|
||||
direct_get_data,
|
||||
direct_get_status,
|
||||
direct_set_control
|
||||
};
|
Loading…
Reference in New Issue