OSDN Git Service

Prepare for ADFE-FlashWriter 1.0.4
[pf3gnuchains/urjtag.git] / jtag / include / cable.h
1 /*
2  * $Id$
3  *
4  * Cable driver interface
5  * Copyright (C) 2003 ETC s.r.o.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20  * 02111-1307, USA.
21  *
22  * Written by Marcel Telka <marcel@telka.sk>, 2003.
23  *
24  */
25
26 #ifndef CABLE_H
27 #define CABLE_H
28
29 #include <stdint.h>
30
31 typedef struct cable_t cable_t;
32
33 #include "usbconn.h"
34 #include "parport.h"
35 #include "chain.h"
36 #include "pod.h"
37
38 typedef struct cable_driver_t cable_driver_t;
39
40 typedef enum
41 {
42    OPTIONALLY,
43    TO_OUTPUT,
44    COMPLETELY
45 }
46 cable_flush_amount_t;
47
48 struct cable_driver_t {
49         const char *name;
50         const char *description;
51         int (*connect)( char *params[], cable_t *cable );
52         void (*disconnect)( cable_t *cable );
53         void (*cable_free)( cable_t *cable );
54         int (*init)( cable_t * );
55         void (*done)( cable_t * );
56         void (*set_frequency)( cable_t *, uint32_t freq );
57         void (*clock)( cable_t *, int, int, int );
58         int (*get_tdo)( cable_t * );
59         int (*transfer)( cable_t *, int, char *, char * );
60         int (*set_signal)( cable_t *, int, int );
61         int (*get_signal)( cable_t *, pod_sigsel_t );
62         void (*flush)( cable_t *, cable_flush_amount_t );
63         void (*help)( const char * );
64 };
65
66 typedef struct cable_queue_t cable_queue_t;
67
68 struct cable_queue_t {
69         enum {
70                 CABLE_CLOCK,
71                 CABLE_GET_TDO,
72                 CABLE_TRANSFER,
73                 CABLE_SET_SIGNAL,
74                 CABLE_GET_SIGNAL
75         } action;
76         union {
77                 struct {
78                         int tms;
79                         int tdi;
80                         int n;
81                 } clock;
82                 struct {
83             pod_sigsel_t sig;
84                         int mask;
85                         int val;
86                 } value;
87                 struct {
88                         int len;
89                         char *in;
90                         char *out;
91                 } transfer;
92                 struct {
93                         int len;
94                         int res;
95                         char *out;
96                 } xferred;
97         } arg;
98 };
99
100 typedef struct cable_queue_info_t cable_queue_info_t;
101
102 struct cable_queue_info_t {
103         cable_queue_t *data;
104         int     max_items;
105         int num_items;
106         int next_item;
107         int next_free;
108 };
109
110 struct cable_t {
111         cable_driver_t *driver;
112         union {
113                 usbconn_t *usb;
114                 parport_t *port;
115         } link;
116         void *params;
117         chain_t *chain;
118         cable_queue_info_t todo;
119         cable_queue_info_t done;
120         uint32_t delay;
121         uint32_t frequency;
122 };
123
124 void cable_free( cable_t *cable );
125 int cable_init( cable_t *cable );
126 void cable_done( cable_t *cable );
127 void cable_flush( cable_t *cable, cable_flush_amount_t );
128 void cable_clock( cable_t *cable, int tms, int tdi, int n );
129    int cable_defer_clock( cable_t *cable, int tms, int tdi, int n );
130 int cable_get_tdo( cable_t *cable );
131    int cable_get_tdo_late( cable_t *cable );
132    int cable_defer_get_tdo( cable_t *cable );
133 int cable_set_signal( cable_t *cable, int mask, int val );
134   int cable_defer_set_signal( cable_t *cable, int mask, int val );
135 int cable_get_signal( cable_t *cable, pod_sigsel_t sig );
136    int cable_get_signal_late( cable_t *cable, pod_sigsel_t sig );
137    int cable_defer_get_signal( cable_t *cable, pod_sigsel_t sig );
138 int cable_transfer( cable_t *cable, int len, char *in, char *out );
139    int cable_transfer_late( cable_t *cable, char *out );
140    int cable_defer_transfer( cable_t *cable, int len, char *in, char *out );
141
142 void cable_set_frequency( cable_t *cable, uint32_t frequency );
143 uint32_t cable_get_frequency( cable_t *cable );
144 void cable_wait( cable_t *cable );
145 void cable_purge_queue( cable_queue_info_t *q, int io );
146 int cable_add_queue_item( cable_t *cable, cable_queue_info_t *q );
147 int cable_get_queue_item( cable_t *cable, cable_queue_info_t *q );
148
149 extern cable_driver_t *cable_drivers[];
150
151 #endif /* CABLE_H */