~ubuntu-branches/ubuntu/raring/avrdude/raring

« back to all changes in this revision

Viewing changes to ppiwin.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2008-07-19 03:22:50 UTC
  • mfrom: (2.1.7 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080719032250-rpu0ljaplx3abxk9
Tags: 5.5-4
* Switch patch system to quilt.
* debian/control
  - Add Build-Depends on quilt.
  - Bump Standards-Version to 3.8.0. Add debian/README.source as recommended
    by the new policy.
* debian/rules
  - Include patchsys-quilt.mk instead of simple-patchsys.mk.
* debian/patches/series
  - Add all existing patches.
* Refresh all patches. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
19
 */
20
20
 
21
 
/* $Id: ppiwin.c,v 1.10 2006/08/20 06:49:11 joerg_wunsch Exp $ */
 
21
/* $Id: ppiwin.c,v 1.12 2007/01/24 21:07:54 joerg_wunsch Exp $ */
22
22
 
23
23
/*
24
24
This is the parallel port interface for Windows built using Cygwin.
43
43
#include <windows.h>
44
44
#include <sys/time.h>
45
45
#include <windows.h>
 
46
 
 
47
#include "avrdude.h"
 
48
#include "serial.h"
46
49
#include "ppi.h"
47
50
 
48
 
extern char *progname;
49
 
 
50
 
 
51
 
 
52
51
#define DEVICE_LPT1 "lpt1"
53
52
#define DEVICE_LPT2 "lpt2"
54
53
#define DEVICE_LPT3 "lpt3"
74
73
 
75
74
/* FUNCTION PROTOTYPES */
76
75
static int winnt_pp_open(void);
77
 
static unsigned short port_get(int fd, int reg);
 
76
static unsigned short port_get(union filedescriptor *fdp, int reg);
78
77
static unsigned char reg2offset(int reg);
79
78
static unsigned char inb(unsigned short port);
80
79
static void outb(unsigned char value, unsigned short port);
83
82
 
84
83
/* FUNCTION DEFINITIONS */
85
84
 
86
 
int ppi_open(char *port)
 
85
void ppi_open(char *port, union filedescriptor *fdp)
87
86
{
88
87
    unsigned char i;
89
88
    int fd;
93
92
    if(fd < 0)
94
93
    {
95
94
        fprintf(stderr, "%s: can't open device \"giveio\"\n\n", progname);
96
 
        return(-1);
 
95
        fdp->ifd = -1;
 
96
        return;
97
97
    }
98
98
 
99
99
    /* Search the windows port names for a match */
110
110
    if(fd < 0)
111
111
    {
112
112
        fprintf(stderr, "%s: can't open device \"%s\"\n\n", progname, port);
113
 
        return(-1);
 
113
        fdp->ifd = -1;
 
114
        return;
114
115
    }
115
116
 
116
 
    return(fd);
 
117
    fdp->ifd = fd;
117
118
}
118
119
 
119
120
 
158
159
 
159
160
 
160
161
 
161
 
void ppi_close(int fd)
 
162
void ppi_close(union filedescriptor *fdp)
162
163
{
163
164
    return;
164
165
}
168
169
/*
169
170
 * set the indicated bit of the specified register.
170
171
 */
171
 
int ppi_set(int fd, int reg, int bit)
 
172
int ppi_set(union filedescriptor *fdp, int reg, int bit)
172
173
{
173
174
    unsigned char v;
174
175
    unsigned short port;
175
176
 
176
 
    port = port_get(fd, reg);
 
177
    port = port_get(fdp, reg);
177
178
    v = inb(port);
178
179
    v |= bit;
179
180
    outb(v, port);
184
185
/*
185
186
 * clear the indicated bit of the specified register.
186
187
 */
187
 
int ppi_clr(int fd, int reg, int bit)
 
188
int ppi_clr(union filedescriptor *fdp, int reg, int bit)
188
189
{
189
190
    unsigned char v;
190
191
    unsigned short port;
191
192
 
192
 
    port = port_get(fd, reg);
 
193
    port = port_get(fdp, reg);
193
194
    v = inb(port);
194
195
    v &= ~bit;
195
196
    outb(v, port);
201
202
/*
202
203
 * get the indicated bit of the specified register.
203
204
 */
204
 
int ppi_get(int fd, int reg, int bit)
 
205
int ppi_get(union filedescriptor *fdp, int reg, int bit)
205
206
{
206
207
    unsigned char v;
207
208
 
208
 
    v = inb(port_get(fd, reg));
 
209
    v = inb(port_get(fdp, reg));
209
210
    v &= bit;
210
211
 
211
212
    return(v);
217
218
/*
218
219
 * toggle the indicated bit of the specified register.
219
220
 */
220
 
int ppi_toggle(int fd, int reg, int bit)
 
221
int ppi_toggle(union filedescriptor *fdp, int reg, int bit)
221
222
{
222
223
    unsigned char v;
223
224
    unsigned short port;
224
225
 
225
 
    port = port_get(fd, reg);
 
226
    port = port_get(fdp, reg);
226
227
 
227
228
    v = inb(port);
228
229
    v ^= bit;
235
236
/*
236
237
 * get all bits of the specified register.
237
238
 */
238
 
int ppi_getall(int fd, int reg)
 
239
int ppi_getall(union filedescriptor *fdp, int reg)
239
240
{
240
241
    unsigned char v;
241
242
 
242
 
    v = inb(port_get(fd, reg));
 
243
    v = inb(port_get(fdp, reg));
243
244
 
244
245
    return((int)v);
245
246
}
250
251
/*
251
252
 * set all bits of the specified register to val.
252
253
 */
253
 
int ppi_setall(int fd, int reg, int val)
 
254
int ppi_setall(union filedescriptor *fdp, int reg, int val)
254
255
{
255
 
    outb((unsigned char)val, port_get(fd, reg));
 
256
    outb((unsigned char)val, port_get(fdp, reg));
256
257
    return 0;
257
258
}
258
259
 
260
261
 
261
262
 
262
263
/* Calculate port address to access. */
263
 
static unsigned short port_get(int fd, int reg)
 
264
static unsigned short port_get(union filedescriptor *fdp, int reg)
264
265
{
265
 
    return((unsigned short)(fd + reg2offset(reg)));
 
266
    return((unsigned short)(fdp->ifd + reg2offset(reg)));
266
267
}
267
268
 
268
269
 
318
319
}
319
320
 
320
321
#if !defined(HAVE_GETTIMEOFDAY)
 
322
struct timezone;
321
323
int gettimeofday(struct timeval *tv, struct timezone *unused){
322
324
// i've found only ms resolution, avrdude expects us
323
325