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

Subversion Repositories adv_debug_sys

[/] [adv_debug_sys/] [tags/] [ADS_RELEASE_1_1_0/] [Software/] [adv_jtag_bridge/] [cable_parallel.c] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 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
 
110
  retval = cable_parallel_inout(value, &in);
111
 
112
  if(in & 0x10) /* S6 pin 13 */
113
    *inval = 1;
114
  else
115
    *inval = 0;
116
 
117
  return retval;
118
}
119
 
120
/*----------------------------------------------[ xess specific functions ]---*/
121
int cable_xess_out(uint8_t value)
122
{
123
  uint8_t out = 0;
124
 
125
  /* First convert the bits in value byte to the ones that the cable wants */
126
  if(value & TCLK_BIT)
127
    out |= 0x04; /* D2 pin 4 */
128
  if(value & TRST_BIT)
129
    out |= 0x08; /* D3 pin 5 */
130
  if(value & TDI_BIT)
131
    out |= 0x10; /* D4 pin 6 */
132
  if(value & TMS_BIT)
133
    out |= 0x20; /* D3 pin 5 */
134
 
135
  return cable_parallel_out(out);
136
}
137
 
138
uint8_t cable_xess_inout(uint8_t value, uint8_t *inval)
139
{
140
  uint8_t in;
141
  int retval;
142
 
143
  retval = cable_parallel_inout(value, &in);
144
 
145
  if(in & 0x20) /* S5 pin 12*/
146
    *inval = 1;
147
  else
148
    *inval = 0;
149
 
150
  return retval;
151
}
152
 
153
 
154
/*----------------------------------------------[ common helper functions ]---*/
155
// 'static' for internal access only
156
 
157
static int cable_parallel_out(uint8_t value)
158
{
159
  outb(value, LPT_WRITE);
160
  return APP_ERR_NONE;
161
}
162
 
163
static int cable_parallel_inout(uint8_t value, uint8_t *inval)
164
{
165
  *inval = inb(LPT_READ);
166
  outb(value, LPT_WRITE);
167
 
168
  return APP_ERR_NONE;
169
}

powered by: WebSVN 2.1.0

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