OpenCores
URL https://opencores.org/ocsvn/adv_debug_sys/adv_debug_sys/trunk

Subversion Repositories adv_debug_sys

[/] [adv_debug_sys/] [trunk/] [Software/] [adv_jtag_bridge/] [cable_parallel.c] - Blame information for rev 31

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 nyawn
/* cable_parallel.c - Parallel cable drivers (XPC3 and XESS) for the Advanced JTAG Bridge
2
   Copyright (C) 2001 Marko Mlinar, markom@opencores.org
3
   Copyright (C) 2004 György Jeney, nog@sdf.lonestar.org
4
 
5
 
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 2 of the License, or
9
   (at your option) any later version.
10
 
11
   This program is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
 
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
 
21
 
22
#include <stdio.h>
23
#include <sys/io.h>  // for inb(), outb()
24
#include <sys/types.h>
25
#include <unistd.h>
26
 
27
#include "cable_common.h"
28
#include "errcodes.h"
29
 
30
 
31
#define LPT_READ (base+1)
32
#define LPT_WRITE base
33
 
34
// Common functions used by both cable types
35
static int cable_parallel_out(uint8_t value);
36
static int cable_parallel_inout(uint8_t value, uint8_t *inval);
37
 
38
 
39
static int base = 0x378;
40
 
41
 
42
 
43
/////////////////////////////////////////////////////////////////////////////////
44
/*-------------------------------------[ Parallel port specific functions ]---*/
45
///////////////////////////////////////////////////////////////////////////////
46
 
47
int cable_parallel_init()
48
{
49
 
50
  //#ifndef WIN32
51
  if (ioperm(base, 3, 1)) {
52
    fprintf(stderr, "Couldn't get the port at %x\n", base);
53
    perror("Root privileges are required.\n");
54
    return APP_ERR_INIT_FAILED;
55
  }
56
  printf("Connected to parallel port at %x\n", base);
57
  printf("Dropping root privileges.\n");
58
  setreuid(getuid(), getuid());
59
  //#endif
60
 
61
  return APP_ERR_NONE;
62
}
63
 
64
 
65
int cable_parallel_opt(int c, char *str)
66
{
67
  switch(c) {
68
  case 'p':
69
    if(!sscanf(str, "%x", &base)) {
70
      fprintf(stderr, "p parameter must have a hex number as parameter\n");
71
      return APP_ERR_BAD_PARAM;
72
    }
73
    break;
74
  default:
75
    fprintf(stderr, "Unknown parameter '%c'\n", c);
76
    return APP_ERR_BAD_PARAM;
77
  }
78
  return APP_ERR_NONE;
79
}
80
 
81
/*-----------------------------------------[ Physical board wait function ]---*/
82
void cable_parallel_phys_wait()
83
{
84 31 nyawn
  /* Multiple users have reported poor performance of parallel cables,
85
   * which has been traced to usleep() sleeping much longer than
86
   * microseconds.  The same users have reported error-free functionality
87
   * and an order of magnitude improvement in upload speed.
88
   * If you get strange data errors while running, add this sleep back
89
   * in, or perhaps a busy-wait delay.
90
   */
91
  /* usleep(10); */
92 21 nyawn
}
93
 
94
/*----------------------------------------------[ xpc3 specific functions ]---*/
95
int cable_xpc3_out(uint8_t value)
96
{
97
  uint8_t out = 0;
98
 
99
  /* First convert the bits in value byte to the ones that the cable wants */
100
  if(value & TCLK_BIT)
101
    out |= 0x02; /* D1 pin 3 */
102
  if(value & TRST_BIT)
103
    out |= 0x10; /* Not used */
104
  if(value & TDI_BIT)
105
    out |= 0x01; /* D0 pin 2 */
106
  if(value & TMS_BIT)
107
    out |= 0x04; /* D2 pin 4 */
108
 
109
  return cable_parallel_out(out);
110
}
111
 
112
int cable_xpc3_inout(uint8_t value, uint8_t *inval)
113
{
114
  uint8_t in;
115
  int retval;
116
  uint8_t out = 0;
117
 
118
  /* First convert the bits in value byte to the ones that the cable wants */
119
  if(value & TCLK_BIT)
120
    out |= 0x02; /* D1 pin 3 */
121
  if(value & TRST_BIT)
122
    out |= 0x10; /* Not used */
123
  if(value & TDI_BIT)
124
    out |= 0x01; /* D0 pin 2 */
125
  if(value & TMS_BIT)
126
    out |= 0x04; /* D2 pin 4 */
127
 
128
  retval = cable_parallel_inout(out, &in);
129
 
130
  if(in & 0x10) /* S6 pin 13 */
131
    *inval = 1;
132
  else
133
    *inval = 0;
134
 
135
  return retval;
136
}
137
 
138
/*----------------------------------------------[ xess specific functions ]---*/
139
int cable_xess_out(uint8_t value)
140
{
141
  uint8_t out = 0;
142
 
143
  /* First convert the bits in value byte to the ones that the cable wants */
144
  if(value & TCLK_BIT)
145
    out |= 0x04; /* D2 pin 4 */
146
  if(value & TRST_BIT)
147
    out |= 0x08; /* D3 pin 5 */
148
  if(value & TDI_BIT)
149
    out |= 0x10; /* D4 pin 6 */
150
  if(value & TMS_BIT)
151
    out |= 0x20; /* D3 pin 5 */
152
 
153
  return cable_parallel_out(out);
154
}
155
 
156
uint8_t cable_xess_inout(uint8_t value, uint8_t *inval)
157
{
158
  uint8_t in;
159
  int retval;
160 22 nyawn
  uint8_t out = 0;
161 21 nyawn
 
162 22 nyawn
  /* First convert the bits in value byte to the ones that the cable wants */
163
  if(value & TCLK_BIT)
164
    out |= 0x04; /* D2 pin 4 */
165
  if(value & TRST_BIT)
166
    out |= 0x08; /* D3 pin 5 */
167
  if(value & TDI_BIT)
168
    out |= 0x10; /* D4 pin 6 */
169
  if(value & TMS_BIT)
170
    out |= 0x20; /* D3 pin 5 */
171 21 nyawn
 
172 22 nyawn
  retval = cable_parallel_inout(out, &in);
173
 
174 21 nyawn
  if(in & 0x20) /* S5 pin 12*/
175
    *inval = 1;
176
  else
177
    *inval = 0;
178
 
179
  return retval;
180
}
181
 
182
 
183
/*----------------------------------------------[ common helper functions ]---*/
184
// 'static' for internal access only
185
 
186
static int cable_parallel_out(uint8_t value)
187
{
188
  outb(value, LPT_WRITE);
189
  return APP_ERR_NONE;
190
}
191
 
192
static int cable_parallel_inout(uint8_t value, uint8_t *inval)
193
{
194
  *inval = inb(LPT_READ);
195
  outb(value, LPT_WRITE);
196
 
197
  return APP_ERR_NONE;
198
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.