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 22

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
  usleep(10);
85
}
86
 
87
/*----------------------------------------------[ xpc3 specific functions ]---*/
88
int cable_xpc3_out(uint8_t value)
89
{
90
  uint8_t out = 0;
91
 
92
  /* First convert the bits in value byte to the ones that the cable wants */
93
  if(value & TCLK_BIT)
94
    out |= 0x02; /* D1 pin 3 */
95
  if(value & TRST_BIT)
96
    out |= 0x10; /* Not used */
97
  if(value & TDI_BIT)
98
    out |= 0x01; /* D0 pin 2 */
99
  if(value & TMS_BIT)
100
    out |= 0x04; /* D2 pin 4 */
101
 
102
  return cable_parallel_out(out);
103
}
104
 
105
int cable_xpc3_inout(uint8_t value, uint8_t *inval)
106
{
107
  uint8_t in;
108
  int retval;
109
  uint8_t out = 0;
110
 
111
  /* First convert the bits in value byte to the ones that the cable wants */
112
  if(value & TCLK_BIT)
113
    out |= 0x02; /* D1 pin 3 */
114
  if(value & TRST_BIT)
115
    out |= 0x10; /* Not used */
116
  if(value & TDI_BIT)
117
    out |= 0x01; /* D0 pin 2 */
118
  if(value & TMS_BIT)
119
    out |= 0x04; /* D2 pin 4 */
120
 
121
  retval = cable_parallel_inout(out, &in);
122
 
123
  if(in & 0x10) /* S6 pin 13 */
124
    *inval = 1;
125
  else
126
    *inval = 0;
127
 
128
  return retval;
129
}
130
 
131
/*----------------------------------------------[ xess specific functions ]---*/
132
int cable_xess_out(uint8_t value)
133
{
134
  uint8_t out = 0;
135
 
136
  /* First convert the bits in value byte to the ones that the cable wants */
137
  if(value & TCLK_BIT)
138
    out |= 0x04; /* D2 pin 4 */
139
  if(value & TRST_BIT)
140
    out |= 0x08; /* D3 pin 5 */
141
  if(value & TDI_BIT)
142
    out |= 0x10; /* D4 pin 6 */
143
  if(value & TMS_BIT)
144
    out |= 0x20; /* D3 pin 5 */
145
 
146
  return cable_parallel_out(out);
147
}
148
 
149
uint8_t cable_xess_inout(uint8_t value, uint8_t *inval)
150
{
151
  uint8_t in;
152
  int retval;
153 22 nyawn
  uint8_t out = 0;
154 21 nyawn
 
155 22 nyawn
  /* First convert the bits in value byte to the ones that the cable wants */
156
  if(value & TCLK_BIT)
157
    out |= 0x04; /* D2 pin 4 */
158
  if(value & TRST_BIT)
159
    out |= 0x08; /* D3 pin 5 */
160
  if(value & TDI_BIT)
161
    out |= 0x10; /* D4 pin 6 */
162
  if(value & TMS_BIT)
163
    out |= 0x20; /* D3 pin 5 */
164 21 nyawn
 
165 22 nyawn
  retval = cable_parallel_inout(out, &in);
166
 
167 21 nyawn
  if(in & 0x20) /* S5 pin 12*/
168
    *inval = 1;
169
  else
170
    *inval = 0;
171
 
172
  return retval;
173
}
174
 
175
 
176
/*----------------------------------------------[ common helper functions ]---*/
177
// 'static' for internal access only
178
 
179
static int cable_parallel_out(uint8_t value)
180
{
181
  outb(value, LPT_WRITE);
182
  return APP_ERR_NONE;
183
}
184
 
185
static int cable_parallel_inout(uint8_t value, uint8_t *inval)
186
{
187
  *inval = inb(LPT_READ);
188
  outb(value, LPT_WRITE);
189
 
190
  return APP_ERR_NONE;
191
}

powered by: WebSVN 2.1.0

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