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

Subversion Repositories jtag_stapl_player

[/] [jtag_stapl_player/] [trunk/] [jamstub.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sukhanov
/****************************************************************************/
2
/*                                                                                                                                                      */
3
/*      Module:                 jamstub.c                                                                                               */
4
/*                                                                                                                                                      */
5
/*                                      Copyright (C) Altera Corporation 1997-2000                              */
6
/*                                                                                                                                                      */
7
/*      Description:    Main source file for stand-alone JAM test utility.              */
8
/*                                                                                                                                                      */
9
/*                                      Supports Altera ByteBlaster hardware download cable             */
10
/*                                      on Windows 95 and Windows NT operating systems.                 */
11
/*                                      (A device driver is required for Windows NT.)                   */
12
/*                                                                                                                                                      */
13
/*                                      Also supports BitBlaster hardware download cable on             */
14
/*                                      Windows 95, Windows NT, and UNIX platforms.                             */
15
/*                                                                                                                                                      */
16
/*      Revisions:              1.1     added dynamic memory allocation                                         */
17
/*                                      1.11 added multi-page memory allocation for file_buffer */
18
/*                    to permit DOS version to read files larger than 64K   */
19
/*                                      1.2 fixed control port initialization for ByteBlaster   */
20
/*                                      2.2 updated usage message, added support for alternate  */
21
/*                                        cable types, moved porting macros in jamport.h,               */
22
/*                                        fixed bug in delay calibration code for 16-bit port   */
23
/*                                                                                                                                                      */
24
/****************************************************************************/
25
/****************************************************************************/
26
/*                                                                                                                                                      */
27
/*      Actel version 1.1             May 2003                                                                  */
28
/*                                                                                                                                                      */
29
/****************************************************************************/
30
/****************************************************************************/
31
/*                                                                                                                                                      */
32
/*      Andrei Sukhanov v3.2    August: 2014                                                                            */
33
/*                                                                                                                                                      */
34
/****************************************************************************/
35
#ifndef NO_ALTERA_STDIO
36
#define NO_ALTERA_STDIO
37
#endif
38
 
39
#if ( _MSC_VER >= 800 )
40
#pragma warning(disable:4115)
41
#pragma warning(disable:4201)
42
#pragma warning(disable:4214)
43
#pragma warning(disable:4514)
44
#endif
45
 
46
#include "jamport.h"
47
 
48
#if PORT == WINDOWS
49
#include <windows.h>
50
#else
51
typedef int BOOL;
52
typedef unsigned short WORD;
53
typedef unsigned long DWORD;
54
#define TRUE 1
55
#define FALSE 0
56
#endif
57
 
58
#include <stdio.h>
59
#include <stdlib.h>
60
#include <string.h>
61
#include "io.h"
62
#include <fcntl.h>
63
#include <malloc.h>
64
#include <time.h>
65
//&RA/#include <conio.h>
66
#include <ctype.h>
67
#include <sys/types.h>
68
#include <sys/stat.h>
69
 
70
#if PORT == DOS
71
#include <bios.h>
72
#endif
73
 
74
#include "jamexprt.h"
75
 
76
#ifdef FS2
77
#include "abiactel.h"
78
#endif
79
 
80
#define WPI 1   //Raspberry Pi P1 pins using WiringPi library
81
#define JTAGIO WPI
82
 
83
#if JTAGIO == WPI
84
#include <unistd.h>
85
#include <ctype.h>
86
#include <wiringPi.h>
87
#define WPI_JTAG1_TCK   7       //P1.7
88
#define WPI_JTAG1_TDO   2       //P1.13
89
#define WPI_JTAG1_TMS   0        //P1.11
90
#define WPI_JTAG1_TDI   1       //P1.12
91
#define WPI_JTAG2_TCK 3   //P1.15
92
#define WPI_JTAG2_TDO 6   //P1.22
93
#define WPI_JTAG2_TMS 4   //P1.16
94
#define WPI_JTAG2_TDI 5   //P1.18
95
int     jtag_cable_WPI = 0;
96
#endif
97
 
98
#if PORT == WINDOWS
99
#define PGDC_IOCTL_GET_DEVICE_INFO_PP 0x00166A00L
100
#define PGDC_IOCTL_READ_PORT_PP       0x00166A04L
101
#define PGDC_IOCTL_WRITE_PORT_PP      0x0016AA08L
102
#define PGDC_IOCTL_PROCESS_LIST_PP    0x0016AA1CL
103
#define PGDC_READ_INFO                0x0a80
104
#define PGDC_READ_PORT                0x0a81
105
#define PGDC_WRITE_PORT               0x0a82
106
#define PGDC_PROCESS_LIST             0x0a87
107
#define PGDC_HDLC_NTDRIVER_VERSION    2
108
#define PORT_IO_BUFFER_SIZE           256
109
#endif
110
 
111
#if PORT == WINDOWS
112
#ifdef __BORLANDC__
113
/* create dummy inp() and outp() functions for Borland 32-bit compile */
114
WORD inp(WORD address) { address = address; return(0); }
115
void outp(WORD address, WORD data) { address = address; data = data; }
116
#else
117
#pragma intrinsic (inp, outp)
118
#endif
119
#endif
120
 
121
/*
122
*       For Borland C compiler (16-bit), set the stack size
123
*/
124
#if PORT == DOS
125
#ifdef __BORLANDC__
126
extern unsigned int _stklen = 50000;
127
#endif
128
#endif
129
 
130
/************************************************************************
131
*
132
*       Global variables
133
*/
134
 
135
/* file buffer for JAM input file */
136
#if PORT == DOS
137
char **file_buffer = NULL;
138
#else
139
char *file_buffer = NULL;
140
#endif
141
long file_pointer = 0L;
142
long file_length = 0L;
143
 
144
/* delay count for one millisecond delay */
145
long one_ms_delay = 0L;
146
 
147
/* delay count to reduce the maximum TCK frequency */
148
int tck_delay = 0;
149
 
150
/* serial port interface available on all platforms */
151
BOOL jtag_hardware_initialized = FALSE;
152
int reset_jtag = 1;
153
char *serial_port_name = NULL;
154
BOOL specified_com_port = FALSE;
155
int com_port = -1;
156
void initialize_jtag_hardware(void);
157
void close_jtag_hardware(void);
158
 
159
#if PORT == WINDOWS || PORT == DOS
160
/* parallel port interface available on PC only */
161
BOOL specified_lpt_port = FALSE;
162
BOOL specified_lpt_addr = FALSE;
163
int lpt_port = 1;
164
int initial_lpt_ctrl = 0;
165
WORD lpt_addr = 0x3bc;
166
WORD lpt_addr_table[3] = { 0x3bc, 0x378, 0x278 };
167
BOOL alternative_cable_l = FALSE;
168
BOOL alternative_cable_x = FALSE;
169
void write_byteblaster(int port, int data);
170
int read_byteblaster(int port);
171
#endif
172
 
173
#if PORT==WINDOWS
174
#ifndef __BORLANDC__
175
WORD lpt_addresses_from_registry[4] = { 0 };
176
#endif
177
#endif
178
 
179
#if PORT == WINDOWS
180
/* variables to manage cached I/O under Windows NT */
181
BOOL windows_nt = FALSE;
182
int port_io_count = 0;
183
HANDLE nt_device_handle = INVALID_HANDLE_VALUE;
184
struct PORT_IO_LIST_STRUCT
185
{
186
        USHORT command;
187
        USHORT data;
188
} port_io_buffer[PORT_IO_BUFFER_SIZE];
189
extern void flush_ports(void);
190
BOOL initialize_nt_driver(void);
191
#endif
192
 
193
/* function prototypes to allow forward reference */
194
extern void delay_loop(long count);
195
//&RA
196
extern JAM_RETURN_TYPE jam_set_ir_preamble(int count, int start_index, int *data);
197
extern JAM_RETURN_TYPE jam_set_ir_postamble(int count, int start_index, int *data);
198
extern JAM_RETURN_TYPE jam_set_dr_preamble(int count, int start_index, int *data);
199
extern JAM_RETURN_TYPE jam_set_dr_postamble(int count, int start_index, int *data);
200
/*
201
*       This structure stores information about each available vector signal
202
*/
203
struct VECTOR_LIST_STRUCT
204
{
205
        char *signal_name;
206
        int  hardware_bit;
207
        int  vector_index;
208
};
209
 
210
/*
211
*       Vector signals for ByteBlaster:
212
*
213
*       tck (dclk)    = register 0, bit 0
214
*       tms (nconfig) = register 0, bit 1
215
*       tdi (data)    = register 0, bit 6
216
*       tdo (condone) = register 1, bit 7 (inverted!)
217
*       nstatus       = register 1, bit 4 (not inverted)
218
*/
219
struct VECTOR_LIST_STRUCT vector_list[] =
220
{
221
        /* add a record here for each vector signal */
222
        { "**TCK**",   0, -1 },
223
        { "**TMS**",   1, -1 },
224
        { "**TDI**",   6, -1 },
225
        { "**TDO**",   7, -1 },
226
        { "TCK",       0, -1 },
227
        { "TMS",       1, -1 },
228
        { "TDI",       6, -1 },
229
        { "TDO",       7, -1 },
230
        { "DCLK",      0, -1 },
231
        { "NCONFIG",   1, -1 },
232
        { "DATA",      6, -1 },
233
        { "CONF_DONE", 7, -1 },
234
        { "NSTATUS",   4, -1 }
235
};
236
 
237
#define VECTOR_SIGNAL_COUNT ((int)(sizeof(vector_list)/sizeof(vector_list[0])))
238
 
239
long verbose = 0;
240
 
241
/************************************************************************
242
*
243
*       Customized interface functions for JAM interpreter I/O:
244
*
245
*       jam_getc()
246
*       jam_seek()
247
*       jam_jtag_io()
248
*       jam_message()
249
*       jam_delay()
250
*/
251
 
252
int jam_getc(void)
253
{
254
        int ch = EOF;
255
 
256
        if (file_pointer < file_length)
257
        {
258
#if PORT == DOS
259
                ch = (int) file_buffer[file_pointer >> 14L][file_pointer & 0x3fffL];
260
                ++file_pointer;
261
#else
262
                ch = (int) file_buffer[file_pointer++];
263
#endif
264
        }
265
 
266
        return (ch);
267
}
268
 
269
int jam_seek(long offset)
270
{
271
        int return_code = EOF;
272
 
273
        if ((offset >= 0L) && (offset < file_length))
274
        {
275
                file_pointer = offset;
276
                return_code = 0;
277
        }
278
 
279
        return (return_code);
280
}
281
 
282
int jam_jtag_io(int tms, int tdi, int read_tdo)
283
{
284
        int data = 0;
285
        int tdo = 0;
286
        int i = 0;
287
        int result = 0;
288
        char ch_data = 0;
289
 
290
        //printf("io(%1i,%1i,%1i\n",tms,tdi,tdo);//&RA
291
        if (!jtag_hardware_initialized)
292
        {
293
                initialize_jtag_hardware();
294
                jtag_hardware_initialized = TRUE;
295
        }
296
 
297
        if (specified_com_port)
298
        {
299
                ch_data = (char)
300
                        ((tdi ? 0x01 : 0) | (tms ? 0x02 : 0) | 0x60);
301
 
302
                write(com_port, &ch_data, 1);
303
 
304
                if (read_tdo)
305
                {
306
                        ch_data = 0x7e;
307
                        write(com_port, &ch_data, 1);
308
                        for (i = 0; (i < 100) && (result != 1); ++i)
309
                        {
310
                                result = read(com_port, &ch_data, 1);
311
                        }
312
                        if (result == 1)
313
                        {
314
                                tdo = ch_data & 0x01;
315
                        }
316
                        else
317
                        {
318
                                printf( "Error:  BitBlaster not responding\n");
319
                        }
320
                }
321
 
322
                ch_data = (char)
323
                        ((tdi ? 0x01 : 0) | (tms ? 0x02 : 0) | 0x64);
324
 
325
                write(com_port, &ch_data, 1);
326
        }
327
        else
328
        {
329
#if PORT == WINDOWS || PORT == DOS
330
                data = (alternative_cable_l ? ((tdi ? 0x01 : 0) | (tms ? 0x04 : 0)) :
331
                       (alternative_cable_x ? ((tdi ? 0x01 : 0) | (tms ? 0x04 : 0) | 0x10) :
332
                       ((tdi ? 0x40 : 0) | (tms ? 0x02 : 0))));
333
 
334
                write_byteblaster(0, data);
335
 
336
                if (read_tdo)
337
                {
338
                        tdo = read_byteblaster(1);
339
                        tdo = (alternative_cable_l ? ((tdo & 0x40) ? 1 : 0) :
340
                              (alternative_cable_x ? ((tdo & 0x10) ? 1 : 0) :
341
                              ((tdo & 0x80) ? 0 : 1)));
342
                }
343
 
344
                write_byteblaster(0, data | (alternative_cable_l ? 0x02 : (alternative_cable_x ? 0x02: 0x01)));
345
 
346
                write_byteblaster(0, data);
347
#else
348
#if JTAGIO == WPI
349
                data = tdi ? 1 : 0;
350
                if(jtag_cable_WPI == 0)
351
                {
352
                        digitalWrite(WPI_JTAG1_TMS,tms);
353
                        digitalWrite(WPI_JTAG1_TDI,data);
354
                          if (tck_delay != 0) delay_loop(tck_delay);
355
                        digitalWrite(WPI_JTAG1_TCK,1);
356
                          if (tck_delay != 0) delay_loop(tck_delay);
357
                        tdo = digitalRead(WPI_JTAG1_TDO);
358
                        digitalWrite(WPI_JTAG1_TCK,0);
359
                }
360
                else
361
                {
362
            digitalWrite(WPI_JTAG2_TMS,tms);
363
            digitalWrite(WPI_JTAG2_TDI,data);
364
            digitalWrite(WPI_JTAG2_TCK,1);
365
            tdo = digitalRead(WPI_JTAG2_TDO);
366
            digitalWrite(WPI_JTAG2_TCK,0);
367
                }
368
                if (verbose&2) printf("tms/i/o=%1i,%1i,%1i\n",tms,data,tdo); //&RA
369
#else
370
                /* parallel port interface not available */
371
                tdo = 0;
372
#endif  //JTAGIO
373
#endif
374
        }
375
 
376
        if (tck_delay != 0) delay_loop(tck_delay);
377
 
378
        return (tdo);
379
}
380
 
381
void jam_message(char *message_text)
382
{
383
        puts(message_text);
384
        fflush(stdout);
385
}
386
 
387
void jam_export_integer(char *key, long value)
388
{
389
        //&RA140507//if (verbose)
390
        {
391
                printf("Export: key = \"%s\", value = %ld\n", key, value);
392
                fflush(stdout);
393
        }
394
}
395
 
396
#define HEX_LINE_CHARS 72
397
#define HEX_LINE_BITS (HEX_LINE_CHARS * 4)
398
 
399
char conv_to_hex(int value)
400
{
401
        char c;
402
 
403
        if (value > 9)
404
        {
405
                c = (char) (value + ('A' - 10));
406
        }
407
        else
408
        {
409
                c = (char) (value + '0');
410
        }
411
 
412
        return (c);
413
}
414
 
415
void jam_export_boolean_array(char *key, unsigned char *data, long count)
416
{
417
        unsigned int size, line, lines, linebits, value, j, k;
418
        char string[HEX_LINE_CHARS + 1];
419
        long i, offset;
420
 
421
        //&RA140507//if (verbose)
422
        {
423
                if (count > HEX_LINE_BITS)
424
                {
425
                        printf("Export: key = \"%s\", %ld bits, value = HEX\n", key, count);
426
                        lines = (unsigned int)
427
                                ((count + (HEX_LINE_BITS - 1)) / HEX_LINE_BITS);
428
 
429
                        for (line = 0; line < lines; ++line)
430
                        {
431
                                if (line < (lines - 1))
432
                                {
433
                                        linebits = HEX_LINE_BITS;
434
                                        size = HEX_LINE_CHARS;
435
                                        offset = count - ((line + 1) * HEX_LINE_BITS);
436
                                }
437
                                else
438
                                {
439
                                        linebits = (unsigned int)
440
                                                (count - ((lines - 1) * HEX_LINE_BITS));
441
                                        size = (linebits + 3) / 4;
442
                                        offset = 0L;
443
                                }
444
 
445
                                string[size] = '\0';
446
                                j = size - 1;
447
                                value = 0;
448
 
449
                                for (k = 0; k < linebits; ++k)
450
                                {
451
                                        i = k + offset;
452
                                        if (data[i >> 3] & (1 << (i & 7))) value |= (1 << (i & 3));
453
                                        if ((i & 3) == 3)
454
                                        {
455
                                                string[j] = conv_to_hex(value);
456
                                                value = 0;
457
                                                --j;
458
                                        }
459
                                }
460
                                if ((k & 3) > 0) string[j] = conv_to_hex(value);
461
 
462
                                printf("%s\n", string);
463
                        }
464
 
465
                        fflush(stdout);
466
                }
467
                else
468
                {
469
                        size = (unsigned int) ((count + 3) / 4);
470
                        string[size] = '\0';
471
                        j = size - 1;
472
                        value = 0;
473
 
474
                        for (i = 0; i < count; ++i)
475
                        {
476
                                if (data[i >> 3] & (1 << (i & 7))) value |= (1 << (i & 3));
477
                                if ((i & 3) == 3)
478
                                {
479
                                        string[j] = conv_to_hex(value);
480
                                        value = 0;
481
                                        --j;
482
                                }
483
                        }
484
                        if ((i & 3) > 0) string[j] = conv_to_hex(value);
485
 
486
                        printf("Export: key = \"%s\", %ld bits, value = HEX %s\n",
487
                                key, count, string);
488
                        fflush(stdout);
489
                }
490
        }
491
}
492
 
493
void jam_delay(long microseconds)
494
{
495
#ifdef FS2
496
        U32 hz;
497
        AbiGetTckRate(&hz);
498
        AbiJtagWait((U32) (1e-6 * microseconds * hz));
499
#else
500
 
501
 
502
#if PORT == WINDOWS
503
        /* if Windows NT, flush I/O cache buffer before delay loop */
504
        if (windows_nt && (port_io_count > 0)) flush_ports();
505
#endif
506
 
507
        delay_loop(microseconds *
508
                ((one_ms_delay / 1000L) + ((one_ms_delay % 1000L) ? 1 : 0)));
509
 
510
#endif
511
}
512
 
513
int jam_vector_map
514
(
515
        int signal_count,
516
        char **signals
517
)
518
{
519
        int signal, vector, ch_index, diff;
520
        int matched_count = 0;
521
        char l, r;
522
 
523
        for (vector = 0; (vector < VECTOR_SIGNAL_COUNT); ++vector)
524
        {
525
                vector_list[vector].vector_index = -1;
526
        }
527
 
528
        for (signal = 0; signal < signal_count; ++signal)
529
        {
530
                diff = 1;
531
                for (vector = 0; (diff != 0) && (vector < VECTOR_SIGNAL_COUNT);
532
                        ++vector)
533
                {
534
                        if (vector_list[vector].vector_index == -1)
535
                        {
536
                                ch_index = 0;
537
                                do
538
                                {
539
                                        l = signals[signal][ch_index];
540
                                        r = vector_list[vector].signal_name[ch_index];
541
                                        diff = (((l >= 'a') && (l <= 'z')) ? (l - ('a' - 'A')) : l)
542
                                                - (((r >= 'a') && (r <= 'z')) ? (r - ('a' - 'A')) : r);
543
                                        ++ch_index;
544
                                }
545
                                while ((diff == 0) && (l != '\0') && (r != '\0'));
546
 
547
                                if (diff == 0)
548
                                {
549
                                        vector_list[vector].vector_index = signal;
550
                                        ++matched_count;
551
                                }
552
                        }
553
                }
554
        }
555
 
556
        return (matched_count);
557
}
558
 
559
int jam_vector_io
560
(
561
        int signal_count,
562
        long *dir_vect,
563
        long *data_vect,
564
        long *capture_vect
565
)
566
{
567
        int signal, vector, bit;
568
        int matched_count = 0;
569
        int data = 0;
570
        int mask = 0;
571
        int dir = 0;
572
        int i = 0;
573
        int result = 0;
574
        char ch_data = 0;
575
 
576
        if (!jtag_hardware_initialized)
577
        {
578
                initialize_jtag_hardware();
579
                jtag_hardware_initialized = TRUE;
580
        }
581
 
582
        /*
583
        *       Collect information about output signals
584
        */
585
        for (vector = 0; vector < VECTOR_SIGNAL_COUNT; ++vector)
586
        {
587
                signal = vector_list[vector].vector_index;
588
 
589
                if ((signal >= 0) && (signal < signal_count))
590
                {
591
                        bit = (1 << vector_list[vector].hardware_bit);
592
 
593
                        mask |= bit;
594
                        if (data_vect[signal >> 5] & (1L << (signal & 0x1f))) data |= bit;
595
                        if (dir_vect[signal >> 5] & (1L << (signal & 0x1f))) dir |= bit;
596
 
597
                        ++matched_count;
598
                }
599
        }
600
 
601
        /*
602
        *       Write outputs to hardware interface, if any
603
        */
604
        if (dir != 0)
605
        {
606
                if (specified_com_port)
607
                {
608
                        ch_data = (char) (((data >> 6) & 0x01) | (data & 0x02) |
609
                                          ((data << 2) & 0x04) | ((data << 3) & 0x08) | 0x60);
610
                        write(com_port, &ch_data, 1);
611
                }
612
                else
613
                {
614
#if PORT == WINDOWS || PORT == DOS
615
 
616
                        write_byteblaster(0, data);
617
 
618
#endif
619
                }
620
        }
621
 
622
        /*
623
        *       Read the input signals and save information in capture_vect[]
624
        */
625
        if ((dir != mask) && (capture_vect != NULL))
626
        {
627
                if (specified_com_port)
628
                {
629
                        ch_data = 0x7e;
630
                        write(com_port, &ch_data, 1);
631
                        for (i = 0; (i < 100) && (result != 1); ++i)
632
                        {
633
                                result = read(com_port, &ch_data, 1);
634
                        }
635
                        if (result == 1)
636
                        {
637
                                data = ((ch_data << 7) & 0x80) | ((ch_data << 3) & 0x10);
638
                        }
639
                        else
640
                        {
641
                                printf( "Error:  BitBlaster not responding\n");
642
                        }
643
                }
644
                else
645
                {
646
#if PORT == WINDOWS || PORT == DOS
647
 
648
                        data = read_byteblaster(1) ^ 0x80; /* parallel port inverts bit 7 */
649
 
650
#endif
651
                }
652
 
653
                for (vector = 0; vector < VECTOR_SIGNAL_COUNT; ++vector)
654
                {
655
                        signal = vector_list[vector].vector_index;
656
 
657
                        if ((signal >= 0) && (signal < signal_count))
658
                        {
659
                                bit = (1 << vector_list[vector].hardware_bit);
660
 
661
                                if ((dir & bit) == 0)    /* if it is an input signal... */
662
                                {
663
                                        if (data & bit)
664
                                        {
665
                                                capture_vect[signal >> 5] |= (1L << (signal & 0x1f));
666
                                        }
667
                                        else
668
                                        {
669
                                                capture_vect[signal >> 5] &= ~(unsigned long)
670
                                                        (1L << (signal & 0x1f));
671
                                        }
672
                                }
673
                        }
674
                }
675
        }
676
 
677
        return (matched_count);
678
}
679
 
680
 
681
int jam_set_frequency(long hertz)
682
{
683
        if (verbose)
684
        {
685
                printf("Frequency: %ld Hz\n", hertz);
686
                fflush(stdout);
687
        }
688
 
689
#ifdef FS2
690
        AbiSetTckRate(hertz);
691
        if (verbose) {
692
                U32 h;
693
                AbiGetTckRate(&h);
694
                printf("Actual Frequency: %ld Hz\n", h);
695
        }
696
#else
697
 
698
 
699
 
700
        if (hertz == -1)
701
        {
702
                /* no frequency limit */
703
                tck_delay = 0;
704
        }
705
        else if (hertz == 0)
706
        {
707
                /* stop the clock */
708
                tck_delay = -1;
709
        }
710
        else
711
        {
712
                /* set the clock delay to the period */
713
                /* corresponding to the selected frequency */
714
                tck_delay = (one_ms_delay * 1000) / hertz;
715
        }
716
#endif
717
        return (0);
718
}
719
 
720
void *jam_malloc(unsigned int size)
721
{
722
        return (malloc(size));
723
}
724
 
725
void jam_free(void *ptr)
726
{
727
        free(ptr);
728
}
729
static void io_setup()
730
{
731
#if JTAGIO == WPI
732
    if (wiringPiSetup() == -1)
733
      printf("ERROR in wiringPiSetup()\n");
734
    else
735
    {
736
                if(jtag_cable_WPI == 0)
737
                {
738
                        pinMode(WPI_JTAG1_TCK,OUTPUT);
739
                        pinMode(WPI_JTAG1_TMS,OUTPUT);
740
                        pinMode(WPI_JTAG1_TDI,OUTPUT);
741
                        pinMode(WPI_JTAG1_TDO,INPUT);
742
                }
743
                else
744
                {
745
            pinMode(WPI_JTAG2_TCK,OUTPUT);
746
            pinMode(WPI_JTAG2_TMS,OUTPUT);
747
            pinMode(WPI_JTAG2_TDI,OUTPUT);
748
            pinMode(WPI_JTAG2_TDO,INPUT);
749
                }
750
    }
751
    if (verbose&4) printf("IO setup\n");
752
#endif
753
}
754
static void io_shutdown(void)
755
{
756
#if JTAGIO == WPI
757
    if(reset_jtag)
758
    {
759
        if(jtag_cable_WPI == 0)
760
        {
761
        pinMode (WPI_JTAG1_TCK,INPUT);
762
        pinMode (WPI_JTAG1_TMS,INPUT);
763
        pinMode (WPI_JTAG1_TDI,INPUT);
764
        pinMode (WPI_JTAG1_TDO,INPUT);
765
        }
766
        else
767
        {
768
            pinMode (WPI_JTAG2_TCK,INPUT);
769
        pinMode (WPI_JTAG2_TMS,INPUT);
770
        pinMode (WPI_JTAG2_TDI,INPUT);
771
        pinMode (WPI_JTAG2_TDO,INPUT);
772
        }
773
    if (verbose&4) printf("IO shutdown\n");
774
    }
775
#endif
776
}
777
 
778
/************************************************************************
779
*
780
*       get_tick_count() -- Get system tick count in milliseconds
781
*
782
*       for DOS, use BIOS function _bios_timeofday()
783
*       for WINDOWS use GetTickCount() function
784
*       for UNIX use clock() system function
785
*/
786
DWORD get_tick_count(void)
787
{
788
        DWORD tick_count = 0L;
789
 
790
#if PORT == WINDOWS
791
        tick_count = GetTickCount();
792
#elif PORT == DOS
793
        _bios_timeofday(_TIME_GETCLOCK, (long *)&tick_count);
794
        tick_count *= 55L;      /* convert to milliseconds */
795
#else
796
        /* assume clock() function returns microseconds */
797
        //&RA//tick_count = (DWORD) (clock() / 1000L);
798
        //clock_t       clk;
799
        //DWORD clk_per_ms = CLOCKS_PER_SEC/1000L;
800
        //clk = clock();
801
        tick_count = (DWORD) (clock() / (CLOCKS_PER_SEC/1000L));
802
#endif
803
 
804
        return (tick_count);
805
}
806
 
807
#define DELAY_SAMPLES 10
808
#define DELAY_CHECK_LOOPS 10000
809
 
810
void calibrate_delay(void)
811
{
812
        int sample = 0;
813
        int count = 0;
814
        DWORD tick_count1 = 0L;
815
        DWORD tick_count2 = 0L;
816
 
817
        one_ms_delay = 0L;
818
 
819
//#if PORT == WINDOWS || PORT == DOS
820
        for (sample = 0; sample < DELAY_SAMPLES; ++sample)
821
        {
822
                count = 0;
823
                tick_count1 = get_tick_count();
824
                while ((tick_count2 = get_tick_count()) == tick_count1) {};
825
                do { delay_loop(DELAY_CHECK_LOOPS); count++; } while
826
                        ((tick_count1 = get_tick_count()) == tick_count2);
827
                one_ms_delay += ((DELAY_CHECK_LOOPS * (DWORD)count) /
828
                        (tick_count1 - tick_count2));
829
        }
830
 
831
        one_ms_delay /= DELAY_SAMPLES;
832
        //if(verbose)
833
        //{
834
        //      printf("Checking calibrated delay for 10 s\n");
835
        //      delay_loop(10000*one_ms_delay);
836
        //      printf("10s passed\n");
837
        //}
838
//#else
839
//      one_ms_delay = 1000L;
840
//#endif
841
}
842
 
843
char *error_text[] =
844
{
845
/* JAMC_SUCCESS            0 */ "success",
846
/* JAMC_OUT_OF_MEMORY      1 */ "out of memory",
847
/* JAMC_IO_ERROR           2 */ "file access error",
848
/* JAMC_SYNTAX_ERROR       3 */ "syntax error",
849
/* JAMC_UNEXPECTED_END     4 */ "unexpected end of file",
850
/* JAMC_UNDEFINED_SYMBOL   5 */ "undefined symbol",
851
/* JAMC_REDEFINED_SYMBOL   6 */ "redefined symbol",
852
/* JAMC_INTEGER_OVERFLOW   7 */ "integer overflow",
853
/* JAMC_DIVIDE_BY_ZERO     8 */ "divide by zero",
854
/* JAMC_CRC_ERROR          9 */ "CRC mismatch",
855
/* JAMC_INTERNAL_ERROR    10 */ "internal error",
856
/* JAMC_BOUNDS_ERROR      11 */ "bounds error",
857
/* JAMC_TYPE_MISMATCH     12 */ "type mismatch",
858
/* JAMC_ASSIGN_TO_CONST   13 */ "assignment to constant",
859
/* JAMC_NEXT_UNEXPECTED   14 */ "NEXT unexpected",
860
/* JAMC_POP_UNEXPECTED    15 */ "POP unexpected",
861
/* JAMC_RETURN_UNEXPECTED 16 */ "RETURN unexpected",
862
/* JAMC_ILLEGAL_SYMBOL    17 */ "illegal symbol name",
863
/* JAMC_VECTOR_MAP_FAILED 18 */ "vector signal name not found",
864
/* JAMC_USER_ABORT        19 */ "execution cancelled",
865
/* JAMC_STACK_OVERFLOW    20 */ "stack overflow",
866
/* JAMC_ILLEGAL_OPCODE    21 */ "illegal instruction code",
867
/* JAMC_PHASE_ERROR       22 */ "phase error",
868
/* JAMC_SCOPE_ERROR       23 */ "scope error",
869
/* JAMC_ACTION_NOT_FOUND  24 */ "action not found",
870
};
871
 
872
#define MAX_ERROR_CODE (int)((sizeof(error_text)/sizeof(error_text[0]))+1)
873
 
874
/************************************************************************/
875
 
876
int main(int argc, char **argv)
877
{
878
        BOOL help = FALSE;
879
        BOOL error = FALSE;
880
        char *filename = NULL;
881
        long offset = 0L;
882
        long error_line = 0L;
883
        JAM_RETURN_TYPE crc_result = JAMC_SUCCESS;
884
        JAM_RETURN_TYPE exec_result = JAMC_SUCCESS;
885
        unsigned short expected_crc = 0;
886
        unsigned short actual_crc = 0;
887
        char key[33] = {0};
888
        char value[257] = {0};
889
        int exit_status = 0;
890
        int arg = 0;
891
        int exit_code = 0;
892
        int format_version = 0;
893
        time_t start_time = 0;
894
        time_t end_time = 0;
895
        int time_delta = 0;
896
        char *workspace = NULL;
897
        char *action = NULL;
898
        int interactive = 0;
899
        char action_string[80];
900
        char *init_list[10];
901
        int init_count = 0;
902
        FILE *fp = NULL;
903
        struct stat sbuf;
904
        long workspace_size = 0;
905
        char *exit_string = NULL;
906
        //int reset_jtag = 1;
907
        int tms,tdi,tdo;
908
 
909
        verbose = FALSE;
910
 
911
        init_list[0] = NULL;
912
 
913
        for (arg = 1; arg < argc; arg++)
914
        {
915
#if PORT == UNIX
916
                if (argv[arg][0] == '-')
917
#else
918
                if ((argv[arg][0] == '-') || (argv[arg][0] == '/'))
919
#endif
920
                {
921
                        switch(toupper(argv[arg][1]))
922
                        {
923
                        case 'A':                               /* set action name */
924
                                action = &argv[arg][2];
925
                                if (action[0] == '"') ++action;
926
                                break;
927
 
928
#if PORT == WINDOWS || PORT == DOS
929
                        case 'C':                               /* Use alternative ISP download cable */
930
                                if(toupper(argv[arg][2]) == 'L')
931
                                        alternative_cable_l = TRUE;
932
                                else if(toupper(argv[arg][2]) == 'X')
933
                                        alternative_cable_x = TRUE;
934
                                break;
935
#endif
936
 
937
                        case 'D':                               /* initialization list */
938
                                if (argv[arg][2] == '"')
939
                                {
940
                                        init_list[init_count] = &argv[arg][3];
941
                                }
942
                                else
943
                                {
944
                                        init_list[init_count] = &argv[arg][2];
945
                                }
946
                                init_list[++init_count] = NULL;
947
                                break;
948
 
949
#if PORT == WINDOWS || PORT == DOS
950
                        case 'P':                               /* set LPT port address */
951
                                specified_lpt_port = TRUE;
952
                                if (sscanf(&argv[arg][2], "%d", &lpt_port) != 1) error = TRUE;
953
                                if ((lpt_port < 1) || (lpt_port > 3)) error = TRUE;
954
                                if (error)
955
                                {
956
                                        if (sscanf(&argv[arg][2], "%x", &lpt_port) == 1)
957
                                        {
958
                                                if ((lpt_port == 0x278) ||
959
                                                        (lpt_port == 0x27c) ||
960
                                                        (lpt_port == 0x378) ||
961
                                                        (lpt_port == 0x37c) ||
962
                                                        (lpt_port == 0x3b8) ||
963
                                                        (lpt_port == 0x3bc))
964
                                                {
965
                                                        error = FALSE;
966
                                                        specified_lpt_addr = TRUE;
967
                                                        lpt_addr = (WORD) lpt_port;
968
                                                        lpt_port = 1;
969
                                                }
970
                                        }
971
                                }
972
                                break;
973
#endif
974
 
975
                        case 'R':               /* don't reset the JTAG chain after use */
976
                                reset_jtag = 0;
977
                                break;
978
 
979
                        case 'S':                               /* set serial port address */
980
                                serial_port_name = &argv[arg][2];
981
                                specified_com_port = TRUE;
982
                                break;
983
 
984
                        case 'M':                               /* set memory size */
985
                                if (sscanf(&argv[arg][2], "%ld", &workspace_size) != 1)
986
                                        error = TRUE;
987
                                if (workspace_size == 0) error = TRUE;
988
                                break;
989
 
990
                        case 'H':                               /* help */
991
                                help = TRUE;
992
                                break;
993
 
994
                        case 'V':                               /* verbose */
995
                                if (sscanf(&argv[arg][2], "%ld", &verbose) != 1)
996
                                {
997
                                        verbose = 1;
998
        /* print out the version string and coiyright message */
999
        printf("STAPL Player Version 3.2\n");
1000
        printf("Ported to RPi from Jam STAPL Player Version 2.2\nCopyright (C) 1997-2000 Altera Corporation\n");
1001
                                }
1002
                                break;
1003
 
1004
                        case 'J':
1005
                                tms = (argv[arg][2]=='1') ? 1 : 0;
1006
                                tdi = (argv[arg][3]=='1') ? 1 : 0;
1007
                                tdo = jam_jtag_io(tms,tdi,1);
1008
                                printf("TDO(%i,%i)=%d\n",tms,tdi,tdo);
1009
                                break;
1010
                        case 'P':
1011
                                sscanf(&argv[arg][4],"%d",&tdo);//get numerical value
1012
                                if (argv[arg][2]=='e')
1013
                                {
1014
                                        if (argv[arg][3]=='i')
1015
                                                jam_set_ir_preamble(tdo,0,0);
1016
                                        else if (argv[arg][3]=='d')
1017
                                                jam_set_dr_preamble(tdo,0,0);
1018
                                }
1019
                                else if (argv[arg][2]=='o')
1020
                                {
1021
                    if (argv[arg][3]=='i')
1022
                                                jam_set_ir_postamble(tdo,0,0);
1023
                    else if (argv[arg][3]=='d')
1024
                                                jam_set_dr_postamble(tdo,0,0);
1025
                                }
1026
                                else
1027
                                {
1028
                                        printf("Wrong PRE/POST syntax\n");
1029
                                        error = TRUE;
1030
                                }
1031
                                break;
1032
#if JTAGIO == WPI
1033
                        case 'G':
1034
                                jtag_cable_WPI = 1;
1035
                                break;
1036
#endif
1037
                        case 'I':
1038
                                interactive = 1;
1039
                                break;
1040
                        default:
1041
                                error = TRUE;
1042
                                break;
1043
                        }
1044
                }
1045
                else
1046
                {
1047
                        /* it's a filename */
1048
                        if (filename == NULL)
1049
                        {
1050
                                filename = argv[arg];
1051
                        }
1052
                        else
1053
                        {
1054
                                /* error -- we already found a filename */
1055
                                error = TRUE;
1056
                        }
1057
                }
1058
 
1059
                if (error)
1060
                {
1061
                        printf( "Illegal argument: \"%s\"\n", argv[arg]);
1062
                        help = TRUE;
1063
                        error = FALSE;
1064
                }
1065
        }
1066
 
1067
#if PORT == WINDOWS || PORT == DOS
1068
        if (specified_lpt_port && specified_com_port)
1069
        {
1070
                printf( "Error:  -s and -p options may not be used together\n\n");
1071
                help = TRUE;
1072
        }
1073
#endif
1074
 
1075
        if (help)
1076
        {
1077
                printf( "Usage:  stapl player [options] <filename>\n");
1078
                printf( "\nAvailable options:\n");
1079
                printf( "    -h          : show help message\n");
1080
                printf( "    -v          : show verbose messages\n");
1081
                printf( "    -a<action>  : specify action name (Jam STAPL)\n");
1082
                printf( "    -d<var=val> : initialize variable to specified value (Jam 1.1)\n");
1083
                printf( "    -d<proc=1>  : enable optional procedure (Jam STAPL)\n");
1084
                printf( "    -d<proc=0>  : disable recommended procedure (Jam STAPL)\n");
1085
#if PORT == WINDOWS || PORT == DOS
1086
                printf( "    -p<port>    : parallel port number or address (for ByteBlaster)\n");
1087
                printf( "    -c<cable>   : alternative download cable compatibility: -cl or -cx\n");
1088
#endif
1089
                printf( "    -s<port>    : serial port name (for BitBlaster)\n");
1090
                printf( "    -r          : don't reset JTAG TAP after use\n");
1091
                //&RA
1092
                printf( "    -j<TMS><TDI>: execute JTAG cycle with TMS and TDI\n");
1093
        printf( "    -p(e/o)(i/d) val; set (PRE/POST)(IR/DR) chain parameter:\n");
1094
#if JTAGIO == WPI
1095
        printf( "    -g                  : use alternative GPIO set (WPI_JTAG2_xxx)\n");
1096
#endif
1097
                exit_status = 1;
1098
        }
1099
        if(filename == NULL)
1100
                exit_status = 1;
1101
        else if ((workspace_size > 0) &&
1102
                ((workspace = (char *) malloc((size_t) workspace_size)) == NULL))
1103
        {
1104
                printf( "Error: can't allocate memory (%d Kbytes)\n",
1105
                        (int) (workspace_size / 1024L));
1106
                exit_status = 1;
1107
        }
1108
        else if (access(filename, 0) != 0)
1109
        {
1110
                printf( "Error: can't access file \"%s\"\n", filename);
1111
                exit_status = 1;
1112
        }
1113
        else
1114
        {
1115
                /* get length of file */
1116
                if (stat(filename, &sbuf) == 0) file_length = sbuf.st_size;
1117
 
1118
                if ((fp = fopen(filename, "rb")) == NULL)
1119
                {
1120
                        printf( "Error: can't open file \"%s\"\n", filename);
1121
                        exit_status = 1;
1122
                }
1123
                else
1124
                {
1125
                        /*
1126
                        *       Read entire file into a buffer
1127
                        */
1128
#if PORT == DOS
1129
                        int pages = 1 + (int) (file_length >> 14L);
1130
                        int page;
1131
                        file_buffer = (char **) malloc((size_t) (pages * sizeof(char *)));
1132
                        for (page = 0; page < pages; ++page)
1133
                        {
1134
                                /* allocate enough 16K blocks to store the file */
1135
                                file_buffer[page] = (char *) malloc (0x4000);
1136
                                if (file_buffer[page] == NULL)
1137
                                {
1138
                                        /* flag error and break out of loop */
1139
                                        file_buffer = NULL;
1140
                                        page = pages;
1141
                                }
1142
                        }
1143
#else
1144
                        file_buffer = (char *) malloc((size_t) file_length);
1145
#endif
1146
                        if (file_buffer == NULL)
1147
                        {
1148
                                printf( "Error: can't allocate memory (%d Kbytes)\n",
1149
                                        (int) (file_length / 1024L));
1150
                                exit_status = 1;
1151
                        }
1152
                        else
1153
                        {
1154
#if PORT == DOS
1155
                                int pages = 1 + (int) (file_length >> 14L);
1156
                                int page;
1157
                                size_t page_size = 0x4000;
1158
                                for (page = 0; (page < pages) && (exit_status == 0); ++page)
1159
                                {
1160
                                        if (page == (pages - 1))
1161
                                        {
1162
                                                /* last page may not be full 16K bytes */
1163
                                                page_size = (size_t) (file_length & 0x3fffL);
1164
                                        }
1165
                                        if (fread(file_buffer[page], 1, page_size, fp) != page_size)
1166
                                        {
1167
                                                printf( "Error reading file \"%s\"\n", filename);
1168
                                                exit_status = 1;
1169
                                        }
1170
                                }
1171
#else
1172
                                if (fread(file_buffer, 1, (size_t) file_length, fp) !=
1173
                                        (size_t) file_length)
1174
                                {
1175
                                        printf( "Error reading file \"%s\"\n", filename);
1176
                                        exit_status = 1;
1177
                                }
1178
#endif
1179
                        }
1180
 
1181
                        fclose(fp);
1182
                }
1183
 
1184
                if (exit_status == 0)
1185
                {
1186
                        /*
1187
                        *       Get Operating System type
1188
                        */
1189
#if PORT == WINDOWS
1190
                        windows_nt = !(GetVersion() & 0x80000000);
1191
#endif
1192
 
1193
                        /*
1194
                        *       Calibrate the delay loop function
1195
                        */
1196
                        calibrate_delay();
1197
 
1198
                        /*
1199
                        *       Check CRC
1200
                        */
1201
                        crc_result = jam_check_crc(
1202
#if PORT==DOS
1203
                                0L, 0L,
1204
#else
1205
                                file_buffer, file_length,
1206
#endif
1207
                                &expected_crc, &actual_crc);
1208
 
1209
                        if (verbose || (crc_result == JAMC_CRC_ERROR))
1210
                        {
1211
                                switch (crc_result)
1212
                                {
1213
                                case JAMC_SUCCESS:
1214
                                        printf("CRC matched: CRC value = %04X\n", actual_crc);
1215
                                        break;
1216
 
1217
                                case JAMC_CRC_ERROR:
1218
                                        printf("CRC mismatch: expected %04X, actual %04X\n",
1219
                                                expected_crc, actual_crc);
1220
                                        break;
1221
 
1222
                                case JAMC_UNEXPECTED_END:
1223
                                        printf("Expected CRC not found, actual CRC value = %04X\n",
1224
                                                actual_crc);
1225
                                        break;
1226
 
1227
                                default:
1228
                                        printf("CRC function returned error code %d\n", crc_result);
1229
                                        break;
1230
                                }
1231
                        }
1232
 
1233
                        /*
1234
                        *       Dump out NOTE fields
1235
                        */
1236
                        if (verbose)
1237
                        {
1238
                                while (jam_get_note(
1239
#if PORT==DOS
1240
                                        0L, 0L,
1241
#else
1242
                                        file_buffer, file_length,
1243
#endif
1244
                                        &offset, key, value, 256) == 0)
1245
                                {
1246
                                        printf("NOTE \"%s\" = \"%s\"\n", key, value);
1247
                                }
1248
                        }
1249
 
1250
 
1251
#ifdef FS2
1252
                        { HRESULT h;
1253
                        h=AbiInit();
1254
                        h=AbiOpenPort("lpt1");
1255
                        if (h == GOOD) {
1256
                                h=AbiSetSupply(ABI_VDDP, ABI_POWER, 2500);
1257
                                if (h == GOOD) {
1258
                                        //h=AbiSetSupply(ABI_VDDL, ABI_GROUND, 2500);//ProASIC;
1259
                                        h=AbiSetSupply(ABI_VDDL, ABI_POWER, 2500);//ProASICplus;
1260
                                        if (h == GOOD) {
1261
                                                //h=AbiSetSupply(ABI_VPP, ABI_POWER, 16500);//ProASIC;
1262
                                                h=AbiSetSupply(ABI_VPP, ABI_POWER, 16200);//ProASICplus;
1263
                                                if (h == GOOD) {
1264
                                                        //h=AbiSetSupply(ABI_VPN, ABI_POWER, -12000);//ProASIC;
1265
                                                        h=AbiSetSupply(ABI_VPN, ABI_POWER, -13600);//ProASICplus;
1266
                                                }
1267
                                        }
1268
                                }
1269
                        }
1270
 
1271
                        if (h != GOOD) {
1272
                                        printf("FS2 error = %lu\n", h);
1273
                                        exit(1);
1274
                        }
1275
                        }
1276
#endif
1277
 
1278
 
1279
                        /*
1280
                        *       Execute the JAM program
1281
                        */
1282
                        while(1)
1283
                        {
1284
                        if(interactive)
1285
                        {
1286
                          printf("Enter action:");
1287
                          if(fgets(action_string,80,stdin) == NULL)
1288
                            strcpy(action_string," ");
1289
                          action_string[strlen(action_string)-1]=0; //trim the newline
1290
                          action = action_string;
1291
                        }
1292
                        time(&start_time);
1293
                        exec_result = jam_execute(
1294
#if PORT==DOS
1295
                                0L, 0L,
1296
#else
1297
                                file_buffer, file_length,
1298
#endif
1299
                                workspace, workspace_size, action, init_list,
1300
                                reset_jtag, &error_line, &exit_code, &format_version);
1301
                        time(&end_time);
1302
 
1303
#ifdef FS2
1304
                        { HRESULT h;
1305
 
1306
                        h=AbiSetSupply(ABI_VPN, ABI_HIZ, -13600);//ProASICplus;
1307
                        h=AbiSetSupply(ABI_VPP, ABI_HIZ, 16200);//ProASICplus;
1308
//                      h=AbiSetSupply(ABI_VPN, ABI_HIZ, -12000);//ProASIC;
1309
//                      h=AbiSetSupply(ABI_VPP, ABI_HIZ, 16500);//ProASIC;
1310
                        h=AbiSetSupply(ABI_VDDP, ABI_HIZ, 2500);
1311
                        h=AbiSetSupply(ABI_VDDL, ABI_HIZ, 2500);
1312
                        h=AbiCleanup();
1313
                        }
1314
#endif
1315
 
1316
 
1317
                        if (exec_result == JAMC_SUCCESS)
1318
                        {
1319
                                if (format_version == 2)
1320
                                {
1321
                                        switch (exit_code)
1322
                                        {
1323
                                        case  0: exit_string = "Success"; break;
1324
                                        case  1: exit_string = "Checking chain failure"; break;
1325
                                        case  2: exit_string = "Reading IDCODE failure"; break;
1326
                                        case  3: exit_string = "Reading USERCODE failure"; break;
1327
                                        case  4: exit_string = "Reading UESCODE failure"; break;
1328
                                        case  5: exit_string = "Entering ISP failure"; break;
1329
                                        case  6: exit_string = "Unrecognized device"; break;
1330
                                        case  7: exit_string = "Device revision is not supported"; break;
1331
                                        case  8: exit_string = "Erase failure"; break;
1332
                                        case  9: exit_string = "Device is not blank"; break;
1333
                                        case 10: exit_string = "Device programming failure"; break;
1334
                                        case 11: exit_string = "Device verify failure"; break;
1335
                                        case 12: exit_string = "Read failure"; break;
1336
                                        case 13: exit_string = "Calculating checksum failure"; break;
1337
                                        case 14: exit_string = "Setting security bit failure"; break;
1338
                                        case 15: exit_string = "Querying security bit failure"; break;
1339
                                        case 16: exit_string = "Exiting ISP failure"; break;
1340
                                        case 17: exit_string = "Performing system test failure"; break;
1341
                                        default: exit_string = "Unknown exit code"; break;
1342
                                        }
1343
                                }
1344
                                else
1345
                                {
1346
                                        switch (exit_code)
1347
                                        {
1348
                                        case 0: exit_string = "Success"; break;
1349
                                        case 1: exit_string = "Illegal initialization values"; break;
1350
                                        case 2: exit_string = "Unrecognized device"; break;
1351
                                        case 3: exit_string = "Device revision is not supported"; break;
1352
                                        case 4: exit_string = "Device programming failure"; break;
1353
                                        case 5: exit_string = "Device is not blank"; break;
1354
                                        case 6: exit_string = "Device verify failure"; break;
1355
                                        case 7: exit_string = "SRAM configuration failure"; break;
1356
                                        default: exit_string = "Unknown exit code"; break;
1357
                                        }
1358
                                }
1359
 
1360
                                printf("Exit code = %d... %s\n", exit_code, exit_string);
1361
                        }
1362
                        else if ((format_version == 2) &&
1363
                                (exec_result == JAMC_ACTION_NOT_FOUND))
1364
                        {
1365
                                if ((action == NULL) || (*action == '\0'))
1366
                                {
1367
                                        printf("Error: no action specified for Jam file.\nProgram terminated.\n");
1368
                                }
1369
                                else
1370
                                {
1371
                                        printf("Error: action \"%s\" is not supported for this Jam file.\nProgram terminated.\n", action);
1372
                                }
1373
                        }
1374
                        else if (exec_result < MAX_ERROR_CODE)
1375
                        {
1376
                                printf("Error on line %ld: %s.\nProgram terminated.\n",
1377
                                        error_line, error_text[exec_result]);
1378
                        }
1379
                        else
1380
                        {
1381
                                printf("Unknown error code %d\n", exec_result);
1382
                        }
1383
 
1384
                        /*
1385
                        *       Print out elapsed time
1386
                        */
1387
                        if (verbose || 1)
1388
                        {
1389
                                time_delta = (int) (end_time - start_time);
1390
                                printf("Elapsed time = %02u:%02u:%02u\n",
1391
                                        time_delta / 3600,                      /* hours */
1392
                                        (time_delta % 3600) / 60,       /* minutes */
1393
                                        time_delta % 60);                       /* seconds */
1394
                        }
1395
                        if(!interactive)        break;
1396
                        }
1397
                }
1398
        }
1399
 
1400
        if (jtag_hardware_initialized) close_jtag_hardware();
1401
 
1402
        if (workspace != NULL) free(workspace);
1403
        if (file_buffer != NULL) free(file_buffer);
1404
 
1405
        return (exit_status);
1406
}
1407
 
1408
#if PORT==WINDOWS
1409
#ifndef __BORLANDC__
1410
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1411
*
1412
*       SEARCH_DYN_DATA
1413
*
1414
*       Searches recursively in Windows 95/98 Registry for parallel port info
1415
*       under HKEY_DYN_DATA registry key.  Called by search_local_machine().
1416
*/
1417
void search_dyn_data
1418
(
1419
        char *dd_path,
1420
        char *hardware_key,
1421
        int lpt
1422
)
1423
{
1424
        DWORD index;
1425
        DWORD size;
1426
        DWORD type;
1427
        LONG result;
1428
        HKEY key;
1429
        int length;
1430
        WORD address;
1431
        char buffer[1024];
1432
        FILETIME last_write = {0};
1433
        WORD *word_ptr;
1434
        int i;
1435
 
1436
        length = strlen(dd_path);
1437
 
1438
        if (RegOpenKeyEx(
1439
                HKEY_DYN_DATA,
1440
                dd_path,
1441
                0L,
1442
                KEY_READ,
1443
                &key)
1444
                == ERROR_SUCCESS)
1445
        {
1446
                size = 1023;
1447
 
1448
                if (RegQueryValueEx(
1449
                        key,
1450
                        "HardWareKey",
1451
                        NULL,
1452
                        &type,
1453
                        (unsigned char *) buffer,
1454
                        &size)
1455
                        == ERROR_SUCCESS)
1456
                {
1457
                        if ((type == REG_SZ) && (stricmp(buffer, hardware_key) == 0))
1458
                        {
1459
                                size = 1023;
1460
 
1461
                                if (RegQueryValueEx(
1462
                                        key,
1463
                                        "Allocation",
1464
                                        NULL,
1465
                                        &type,
1466
                                        (unsigned char *) buffer,
1467
                                        &size)
1468
                                        == ERROR_SUCCESS)
1469
                                {
1470
                                        /*
1471
                                        *       By "inspection", I have found five cases: size 32, 48,
1472
                                        *       56, 60, and 80 bytes.  The port address seems to be
1473
                                        *       located at different offsets in the buffer for these
1474
                                        *       five cases, as shown below.  If a valid port address
1475
                                        *       is not found, or the size is not one of these known
1476
                                        *       sizes, then I search through the entire buffer and
1477
                                        *       look for a value which is a valid port address.
1478
                                        */
1479
 
1480
                                        word_ptr = (WORD *) buffer;
1481
 
1482
                                        if ((type == REG_BINARY) && (size == 32))
1483
                                        {
1484
                                                address = word_ptr[10];
1485
                                        }
1486
                                        else if ((type == REG_BINARY) && (size == 48))
1487
                                        {
1488
                                                address = word_ptr[18];
1489
                                        }
1490
                                        else if ((type == REG_BINARY) && (size == 56))
1491
                                        {
1492
                                                address = word_ptr[22];
1493
                                        }
1494
                                        else if ((type == REG_BINARY) && (size == 60))
1495
                                        {
1496
                                                address = word_ptr[24];
1497
                                        }
1498
                                        else if ((type == REG_BINARY) && (size == 80))
1499
                                        {
1500
                                                address = word_ptr[24];
1501
                                        }
1502
                                        else address = 0;
1503
 
1504
                                        /* if not found, search through entire buffer */
1505
                                        i = 0;
1506
                                        while ((i < (int) (size / 2)) &&
1507
                                                (address != 0x278) &&
1508
                                                (address != 0x27C) &&
1509
                                                (address != 0x378) &&
1510
                                                (address != 0x37C) &&
1511
                                                (address != 0x3B8) &&
1512
                                                (address != 0x3BC))
1513
                                        {
1514
                                                if ((word_ptr[i] == 0x278) ||
1515
                                                        (word_ptr[i] == 0x27C) ||
1516
                                                        (word_ptr[i] == 0x378) ||
1517
                                                        (word_ptr[i] == 0x37C) ||
1518
                                                        (word_ptr[i] == 0x3B8) ||
1519
                                                        (word_ptr[i] == 0x3BC))
1520
                                                {
1521
                                                        address = word_ptr[i];
1522
                                                }
1523
                                                ++i;
1524
                                        }
1525
 
1526
                                        if ((address == 0x278) ||
1527
                                                (address == 0x27C) ||
1528
                                                (address == 0x378) ||
1529
                                                (address == 0x37C) ||
1530
                                                (address == 0x3B8) ||
1531
                                                (address == 0x3BC))
1532
                                        {
1533
                                                lpt_addresses_from_registry[lpt] = address;
1534
                                        }
1535
                                }
1536
                        }
1537
                }
1538
 
1539
                index = 0;
1540
 
1541
                do
1542
                {
1543
                        size = 1023;
1544
 
1545
                        result = RegEnumKeyEx(
1546
                                key,
1547
                                index++,
1548
                                buffer,
1549
                                &size,
1550
                                NULL,
1551
                                NULL,
1552
                                NULL,
1553
                                &last_write);
1554
 
1555
                        if (result == ERROR_SUCCESS)
1556
                        {
1557
                                dd_path[length] = '\\';
1558
                                dd_path[length + 1] = '\0';
1559
                                strcpy(&dd_path[length + 1], buffer);
1560
 
1561
                                search_dyn_data(dd_path, hardware_key, lpt);
1562
 
1563
                                dd_path[length] = '\0';
1564
                        }
1565
                }
1566
                while (result == ERROR_SUCCESS);
1567
 
1568
                RegCloseKey(key);
1569
        }
1570
}
1571
 
1572
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1573
*
1574
*       SEARCH_LOCAL_MACHINE
1575
*
1576
*       Searches recursively in Windows 95/98 Registry for parallel port info
1577
*       under HKEY_LOCAL_MACHINE\Enum.  When parallel port is found, calls
1578
*       search_dyn_data() to get the port address.
1579
*/
1580
void search_local_machine
1581
(
1582
        char *lm_path,
1583
        char *dd_path
1584
)
1585
{
1586
        DWORD index;
1587
        DWORD size;
1588
        DWORD type;
1589
        LONG result;
1590
        HKEY key;
1591
        int length;
1592
        char buffer[1024];
1593
        FILETIME last_write = {0};
1594
 
1595
        length = strlen(lm_path);
1596
 
1597
        if (RegOpenKeyEx(
1598
                HKEY_LOCAL_MACHINE,
1599
                lm_path,
1600
                0L,
1601
                KEY_READ,
1602
                &key)
1603
                == ERROR_SUCCESS)
1604
        {
1605
                size = 1023;
1606
 
1607
                if (RegQueryValueEx(
1608
                        key,
1609
                        "PortName",
1610
                        NULL,
1611
                        &type,
1612
                        (unsigned char *) buffer,
1613
                        &size)
1614
                        == ERROR_SUCCESS)
1615
                {
1616
                        if ((type == REG_SZ) &&
1617
                                (size == 5) &&
1618
                                (buffer[0] == 'L') &&
1619
                                (buffer[1] == 'P') &&
1620
                                (buffer[2] == 'T') &&
1621
                                (buffer[3] >= '1') &&
1622
                                (buffer[3] <= '4') &&
1623
                                (buffer[4] == '\0'))
1624
                        {
1625
                                /* we found the entry in HKEY_LOCAL_MACHINE, now we need to */
1626
                                /* find the corresponding entry under HKEY_DYN_DATA.  */
1627
                                /* add 5 to lm_path to skip over "Enum" and backslash */
1628
                                search_dyn_data(dd_path, &lm_path[5], (buffer[3] - '1'));
1629
                        }
1630
                }
1631
 
1632
                index = 0;
1633
 
1634
                do
1635
                {
1636
                        size = 1023;
1637
 
1638
                        result = RegEnumKeyEx(
1639
                                key,
1640
                                index++,
1641
                                buffer,
1642
                                &size,
1643
                                NULL,
1644
                                NULL,
1645
                                NULL,
1646
                                &last_write);
1647
 
1648
                        if (result == ERROR_SUCCESS)
1649
                        {
1650
                                lm_path[length] = '\\';
1651
                                lm_path[length + 1] = '\0';
1652
                                strcpy(&lm_path[length + 1], buffer);
1653
 
1654
                                search_local_machine(lm_path, dd_path);
1655
 
1656
                                lm_path[length] = '\0';
1657
                        }
1658
                }
1659
                while (result == ERROR_SUCCESS);
1660
 
1661
                RegCloseKey(key);
1662
        }
1663
}
1664
 
1665
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1666
*
1667
*       GET_LPT_ADDRESSES_FROM_REGISTRY
1668
*
1669
*       Searches Win95/98 registry recursively to get I/O port addresses for
1670
*       parallel ports.
1671
*/
1672
void get_lpt_addresses_from_registry()
1673
{
1674
        char lm_path[1024];
1675
        char dd_path[1024];
1676
 
1677
        strcpy(lm_path, "Enum");
1678
        strcpy(dd_path, "Config Manager");
1679
        search_local_machine(lm_path, dd_path);
1680
}
1681
#endif
1682
#endif
1683
 
1684
void initialize_jtag_hardware()
1685
{
1686
#ifdef JTAGIO
1687
        io_setup();
1688
#else
1689
        if (specified_com_port)
1690
        {
1691
                com_port = open(serial_port_name, O_RDWR);
1692
                if (com_port == -1)
1693
                {
1694
                        printf( "Error: can't open serial port \"%s\"\n",
1695
                                serial_port_name);
1696
                }
1697
                else
1698
                {
1699
                        int i = 0, result = 0;
1700
                        char data = 0;
1701
 
1702
                        data = 0x7e;
1703
                        write(com_port, &data, 1);
1704
 
1705
                        for (i = 0; (i < 100) && (result != 1); ++i)
1706
                        {
1707
                                result = read(com_port, &data, 1);
1708
                        }
1709
 
1710
                        if (result == 1)
1711
                        {
1712
                                data = 0x70; write(com_port, &data, 1); /* TDO echo off */
1713
                                data = 0x72; write(com_port, &data, 1); /* auto LEDs off */
1714
                                data = 0x74; write(com_port, &data, 1); /* ERROR LED off */
1715
                                data = 0x76; write(com_port, &data, 1); /* DONE LED off */
1716
                                data = 0x60; write(com_port, &data, 1); /* signals low */
1717
                        }
1718
                        else
1719
                        {
1720
                                printf( "Error: BitBlaster is not responding on %s\n",
1721
                                        serial_port_name);
1722
                                close(com_port);
1723
                                com_port = -1;
1724
                        }
1725
                }
1726
        }
1727
        else
1728
        {
1729
#if PORT == WINDOWS || PORT == DOS
1730
 
1731
#if PORT == WINDOWS
1732
                if (windows_nt)
1733
                {
1734
                        initialize_nt_driver();
1735
                }
1736
                else
1737
                {
1738
#ifdef __BORLANDC__
1739
                        printf( "Error: parallel port access is not available\n");
1740
#else
1741
                        if (!specified_lpt_addr)
1742
                        {
1743
                                get_lpt_addresses_from_registry();
1744
 
1745
                                lpt_addr = 0;
1746
 
1747
                                if (specified_lpt_port)
1748
                                {
1749
                                        lpt_addr = lpt_addresses_from_registry[lpt_port - 1];
1750
                                }
1751
 
1752
                                if (lpt_addr == 0)
1753
                                {
1754
                                        if (lpt_addresses_from_registry[3] != 0)
1755
                                                lpt_addr = lpt_addresses_from_registry[3];
1756
                                        if (lpt_addresses_from_registry[2] != 0)
1757
                                                lpt_addr = lpt_addresses_from_registry[2];
1758
                                        if (lpt_addresses_from_registry[1] != 0)
1759
                                                lpt_addr = lpt_addresses_from_registry[1];
1760
                                        if (lpt_addresses_from_registry[0] != 0)
1761
                                                lpt_addr = lpt_addresses_from_registry[0];
1762
                                }
1763
 
1764
                                if (lpt_addr == 0)
1765
                                {
1766
                                        if (specified_lpt_port)
1767
                                        {
1768
                                                lpt_addr = lpt_addr_table[lpt_port - 1];
1769
                                        }
1770
                                        else
1771
                                        {
1772
                                                lpt_addr = lpt_addr_table[0];
1773
                                        }
1774
                                }
1775
                        }
1776
                        initial_lpt_ctrl = windows_nt ? 0x0c : read_byteblaster(2);
1777
#endif
1778
                }
1779
#endif
1780
 
1781
#if PORT == DOS
1782
                /*
1783
                *       Read word at specific memory address to get the LPT port address
1784
                */
1785
                WORD *bios_address = (WORD *) 0x00400008;
1786
 
1787
                if (!specified_lpt_addr)
1788
                {
1789
                        lpt_addr = bios_address[lpt_port - 1];
1790
 
1791
                        if ((lpt_port != 0x278) &&
1792
                                (lpt_port != 0x27c) &&
1793
                                (lpt_port != 0x378) &&
1794
                                (lpt_port != 0x37c) &&
1795
                                (lpt_port != 0x3b8) &&
1796
                                (lpt_port != 0x3bc))
1797
                        {
1798
                                lpt_addr = lpt_addr_table[lpt_port - 1];
1799
                        }
1800
                }
1801
                initial_lpt_ctrl = read_byteblaster(2);
1802
#endif
1803
 
1804
                /* set AUTO-FEED low to enable ByteBlaster (value to port inverted) */
1805
                /* set DIRECTION low for data output from parallel port */
1806
                write_byteblaster(2, (initial_lpt_ctrl | 0x02) & 0xDF);
1807
#endif
1808
        }
1809
#endif //JTAGIO
1810
}
1811
 
1812
void close_jtag_hardware()
1813
{
1814
#ifdef JTAGIO
1815
    io_shutdown();
1816
#else
1817
        if (specified_com_port)
1818
        {
1819
                if (com_port != -1) close(com_port);
1820
        }
1821
        else
1822
        {
1823
#if PORT == WINDOWS || PORT == DOS
1824
                /* set AUTO-FEED high to disable ByteBlaster */
1825
                write_byteblaster(2, initial_lpt_ctrl & 0xfd);
1826
 
1827
#if PORT == WINDOWS
1828
                if (windows_nt && (nt_device_handle != INVALID_HANDLE_VALUE))
1829
                {
1830
                        if (port_io_count > 0) flush_ports();
1831
 
1832
                        CloseHandle(nt_device_handle);
1833
                }
1834
#endif
1835
#endif
1836
        }
1837
#endif //JTAGIO
1838
}
1839
 
1840
#if PORT == WINDOWS
1841
/**************************************************************************/
1842
/*                                                                        */
1843
 
1844
BOOL initialize_nt_driver()
1845
 
1846
/*                                                                        */
1847
/*  Uses CreateFile() to open a connection to the Windows NT device       */
1848
/*  driver.                                                               */
1849
/*                                                                        */
1850
/**************************************************************************/
1851
{
1852
        BOOL status = FALSE;
1853
 
1854
        ULONG buffer[1];
1855
        ULONG returned_length = 0;
1856
        char nt_lpt_str[] = { '\\', '\\', '.', '\\',
1857
                'A', 'L', 'T', 'L', 'P', 'T', '1', '\0' };
1858
 
1859
 
1860
        nt_lpt_str[10] = (char) ('1' + (lpt_port - 1));
1861
 
1862
        nt_device_handle = CreateFile(
1863
                nt_lpt_str,
1864
                GENERIC_READ | GENERIC_WRITE,
1865
                0,
1866
                NULL,
1867
                OPEN_EXISTING,
1868
                FILE_ATTRIBUTE_NORMAL,
1869
                NULL);
1870
 
1871
        if (nt_device_handle == INVALID_HANDLE_VALUE)
1872
        {
1873
                printf(
1874
                        "I/O error:  cannot open device %s\nCheck port number and device driver installation",
1875
                        nt_lpt_str);
1876
        }
1877
        else
1878
        {
1879
                if (DeviceIoControl(
1880
                        nt_device_handle,                       /* Handle to device */
1881
                        PGDC_IOCTL_GET_DEVICE_INFO_PP,  /* IO Control code */
1882
                        (ULONG *)NULL,                                  /* Buffer to driver. */
1883
                        0,                                                               /* Length of buffer in bytes. */
1884
                        &buffer,                                                /* Buffer from driver. */
1885
                        sizeof(ULONG),                                  /* Length of buffer in bytes. */
1886
                        &returned_length,                               /* Bytes placed in data_buffer. */
1887
                        NULL))                                                  /* Wait for operation to complete */
1888
                {
1889
                        if (returned_length == sizeof(ULONG))
1890
                        {
1891
                                if (buffer[0] == PGDC_HDLC_NTDRIVER_VERSION)
1892
                                {
1893
                                        status = TRUE;
1894
                                }
1895
                                else
1896
                                {
1897
                                        printf(
1898
                                                "I/O error:  device driver %s is not compatible\n(Driver version is %lu, expected version %lu.\n",
1899
                                                nt_lpt_str,
1900
                                                (unsigned long) buffer[0],
1901
                                                (unsigned long) PGDC_HDLC_NTDRIVER_VERSION);
1902
                                }
1903
                        }
1904
                        else
1905
                        {
1906
                                printf( "I/O error:  device driver %s is not compatible.\n",
1907
                                        nt_lpt_str);
1908
                        }
1909
                }
1910
 
1911
                if (!status)
1912
                {
1913
                        CloseHandle(nt_device_handle);
1914
                        nt_device_handle = INVALID_HANDLE_VALUE;
1915
                }
1916
        }
1917
 
1918
        if (!status)
1919
        {
1920
                /* error message already given */
1921
                exit(1);
1922
        }
1923
 
1924
        return (status);
1925
}
1926
#endif
1927
 
1928
#if PORT == WINDOWS || PORT == DOS
1929
/**************************************************************************/
1930
/*                                                                        */
1931
 
1932
void write_byteblaster
1933
(
1934
        int port,
1935
        int data
1936
)
1937
 
1938
/*                                                                        */
1939
/**************************************************************************/
1940
{
1941
#if PORT == WINDOWS
1942
        BOOL status = FALSE;
1943
 
1944
        int returned_length = 0;
1945
        int buffer[2];
1946
 
1947
 
1948
        if (windows_nt)
1949
        {
1950
                /*
1951
                *       On Windows NT, access hardware through device driver
1952
                */
1953
                if (port == 0)
1954
                {
1955
                        port_io_buffer[port_io_count].data = (USHORT) data;
1956
                        port_io_buffer[port_io_count].command = PGDC_WRITE_PORT;
1957
                        ++port_io_count;
1958
 
1959
                        if (port_io_count >= PORT_IO_BUFFER_SIZE) flush_ports();
1960
                }
1961
                else
1962
                {
1963
                        if (port_io_count > 0) flush_ports();
1964
 
1965
                        buffer[0] = port;
1966
                        buffer[1] = data;
1967
 
1968
                        status = DeviceIoControl(
1969
                                nt_device_handle,                       /* Handle to device */
1970
                                PGDC_IOCTL_WRITE_PORT_PP,       /* IO Control code for write */
1971
                                (ULONG *)&buffer,                       /* Buffer to driver. */
1972
                                2 * sizeof(int),                        /* Length of buffer in bytes. */
1973
                                (ULONG *)NULL,                          /* Buffer from driver.  Not used. */
1974
                                0,                                                       /* Length of buffer in bytes. */
1975
                                (ULONG *)&returned_length,      /* Bytes returned.  Should be zero. */
1976
                                NULL);                                          /* Wait for operation to complete */
1977
 
1978
                        if ((!status) || (returned_length != 0))
1979
                        {
1980
                                printf( "I/O error:  Cannot access ByteBlaster hardware\n");
1981
                                CloseHandle(nt_device_handle);
1982
                                exit(1);
1983
                        }
1984
                }
1985
        }
1986
        else
1987
#endif
1988
        {
1989
                /*
1990
                *       On Windows 95, access hardware directly
1991
                */
1992
                outp((WORD)(port + lpt_addr), (WORD)data);
1993
        }
1994
}
1995
 
1996
/**************************************************************************/
1997
/*                                                                        */
1998
 
1999
int read_byteblaster
2000
(
2001
        int port
2002
)
2003
 
2004
/*                                                                        */
2005
/**************************************************************************/
2006
{
2007
        int data = 0;
2008
 
2009
#if PORT == WINDOWS
2010
 
2011
        BOOL status = FALSE;
2012
 
2013
        int returned_length = 0;
2014
 
2015
 
2016
        if (windows_nt)
2017
        {
2018
                /* flush output cache buffer before reading from device */
2019
                if (port_io_count > 0) flush_ports();
2020
 
2021
                /*
2022
                *       On Windows NT, access hardware through device driver
2023
                */
2024
                status = DeviceIoControl(
2025
                        nt_device_handle,                       /* Handle to device */
2026
                        PGDC_IOCTL_READ_PORT_PP,        /* IO Control code for Read */
2027
                        (ULONG *)&port,                         /* Buffer to driver. */
2028
                        sizeof(int),                            /* Length of buffer in bytes. */
2029
                        (ULONG *)&data,                         /* Buffer from driver. */
2030
                        sizeof(int),                            /* Length of buffer in bytes. */
2031
                        (ULONG *)&returned_length,      /* Bytes placed in data_buffer. */
2032
                        NULL);                                          /* Wait for operation to complete */
2033
 
2034
                if ((!status) || (returned_length != sizeof(int)))
2035
                {
2036
                        printf( "I/O error:  Cannot access ByteBlaster hardware\n");
2037
                        CloseHandle(nt_device_handle);
2038
                        exit(1);
2039
                }
2040
        }
2041
        else
2042
#endif
2043
        {
2044
                /*
2045
                *       On Windows 95, access hardware directly
2046
                */
2047
                data = inp((WORD)(port + lpt_addr));
2048
        }
2049
 
2050
        return (data & 0xff);
2051
}
2052
 
2053
#if PORT == WINDOWS
2054
void flush_ports(void)
2055
{
2056
        ULONG n_writes = 0L;
2057
        BOOL status;
2058
 
2059
        status = DeviceIoControl(
2060
                nt_device_handle,                       /* handle to device */
2061
                PGDC_IOCTL_PROCESS_LIST_PP,     /* IO control code */
2062
                (LPVOID)port_io_buffer,         /* IN buffer (list buffer) */
2063
                port_io_count * sizeof(struct PORT_IO_LIST_STRUCT),/* length of IN buffer in bytes */
2064
                (LPVOID)port_io_buffer, /* OUT buffer (list buffer) */
2065
                port_io_count * sizeof(struct PORT_IO_LIST_STRUCT),/* length of OUT buffer in bytes */
2066
                &n_writes,                                      /* number of writes performed */
2067
                0);                                                      /* wait for operation to complete */
2068
 
2069
        if ((!status) || ((port_io_count * sizeof(struct PORT_IO_LIST_STRUCT)) != n_writes))
2070
        {
2071
                printf( "I/O error:  Cannot access ByteBlaster hardware\n");
2072
                CloseHandle(nt_device_handle);
2073
                exit(1);
2074
        }
2075
 
2076
        port_io_count = 0;
2077
}
2078
#endif /* PORT == WINDOWS */
2079
#endif /* PORT == WINDOWS || PORT == DOS */
2080
 
2081
#if !defined (DEBUG)
2082
#pragma optimize ("ceglt", off)
2083
#endif
2084
 
2085
void delay_loop(long count)
2086
{
2087
        while (count != 0L) count--;
2088
}

powered by: WebSVN 2.1.0

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