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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or_debug_proxy/] [src/] [linux_usb_driver_calls.c] - Blame information for rev 656

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

Line No. Rev Author Line
1 39 julius
/*$$HEADER*/
2
/******************************************************************************/
3
/*                                                                            */
4
/*                    H E A D E R   I N F O R M A T I O N                     */
5
/*                                                                            */
6
/******************************************************************************/
7
 
8
// Project Name                   : OpenRISC Debug Proxy
9
// File Name                      : linux_usb_driver_calls.c
10
// Prepared By                    : jb
11
// Project Start                  : 2008-10-01
12
 
13
/*$$COPYRIGHT NOTICE*/
14
/******************************************************************************/
15
/*                                                                            */
16
/*                      C O P Y R I G H T   N O T I C E                       */
17
/*                                                                            */
18
/******************************************************************************/
19
/*
20
  This library is free software; you can redistribute it and/or
21
  modify it under the terms of the GNU Lesser General Public
22
  License as published by the Free Software Foundation;
23
  version 2.1 of the License, a copy of which is available from
24
  http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt.
25
 
26
  This library is distributed in the hope that it will be useful,
27
  but WITHOUT ANY WARRANTY; without even the implied warranty of
28
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
29
  Lesser General Public License for more details.
30
 
31
  You should have received a copy of the GNU Lesser General Public
32
  License along with this library; if not, write to the Free Software
33
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
34
*/
35
 
36
/*$$DESCRIPTION*/
37
/******************************************************************************/
38
/*                                                                            */
39
/*                           D E S C R I P T I O N                            */
40
/*                                                                            */
41
/******************************************************************************/
42
//
43
// Some generically named functions for interfacing to the JTAG driver 
44
// functions, making the code calling these platform independant. The correct 
45
// driver calling file (either Cygwin or Linux driver) is included at compile 
46
// time.
47
// Also included in this file is the USB-JTAG chip initialisation function.
48
//
49
 
50
 
51
/*$$CHANGE HISTORY*/
52
/******************************************************************************/
53
/*                                                                            */
54
/*                         C H A N G E  H I S T O R Y                         */
55
/*                                                                            */
56
/******************************************************************************/
57
 
58
// Date         Version Description
59
//------------------------------------------------------------------------
60
// 081101               First revision                                  jb
61
 
62
#include <stdio.h>
63
 
64
#include "WinTypes.h"
65
 
66
#include "usb_driver_calls.h"
67
 
68
#include "usb_functions.h"
69
#include "or_debug_proxy.h"
70
 
71
#include "FT2232cMpsseJtag.h"
72
 
73 47 julius
 
74 39 julius
static FT2232cMpsseJtag *pFT2232cMpsseJtag = NULL;
75
 
76
// Global USB JTAG device handle
77
FTC_HANDLE ftHandle;
78
 
79
// Write data to external device:
80
//FTC_STATUS FT2232cMpsseJtag::JTAG_WriteDataToExternalDevice(FTC_HANDLE ftHandle, BOOL bInstructionTestData, DWORD dwNumBitsToWrite,
81
 
82
FTC_STATUS
83
FT2232_USB_JTAG_WriteDataToExternalDevice(
84
                                          //FTC_HANDLE ftHandle, 
85
                                          BOOL bInstructionTestData,
86
                                          DWORD dwNumBitsToWrite,
87
                                          PWriteDataByteBuffer pWriteDataBuffer,
88
                                          DWORD dwNumBytesToWrite,
89
                                          DWORD dwTapControllerState)
90
{
91
  // Call the driver from the libary compiled in Linux
92
  return pFT2232cMpsseJtag->JTAG_WriteDataToExternalDevice(
93
                                                           ftHandle,
94
                                                           bInstructionTestData,
95
                                                           dwNumBitsToWrite,
96
                                                           pWriteDataBuffer,
97
                                                           dwNumBytesToWrite,
98
                                                           dwTapControllerState);
99
}
100
 
101
 
102
// Read data from external device
103
FTC_STATUS
104
FT2232_USB_JTAG_ReadDataFromExternalDevice(
105
                                           //FTC_HANDLE ftHandle, 
106
                                            BOOL bInstructionTestData,
107
                                            DWORD dwNumBitsToRead,
108
                                            PReadDataByteBuffer pReadDataBuffer,
109
                                            LPDWORD lpdwNumBytesReturned,
110
                                            DWORD dwTapControllerState)
111
 
112
{
113
  return pFT2232cMpsseJtag->JTAG_ReadDataFromExternalDevice(
114
                                                            ftHandle,
115
                                                            bInstructionTestData,
116
                                                            dwNumBitsToRead,
117
                                                            pReadDataBuffer,
118
                                                            lpdwNumBytesReturned,
119
                                                            dwTapControllerState);
120
 
121
}
122
 
123
 
124
 
125
 
126
 
127
 
128
// Write Read
129
FTC_STATUS
130
FT2232_USB_JTAG_WriteReadDataToFromExternalDevice(
131
                                                  //FTC_HANDLE ftHandle, 
132
                                                  BOOL bInstructionTestData,
133
                                                  DWORD dwNumBitsToWriteRead,
134
                                                  PWriteDataByteBuffer pWriteDataBuffer,
135
                                                  DWORD dwNumBytesToWrite,
136
                                                  PReadDataByteBuffer pReadDataBuffer,
137
                                                  LPDWORD lpdwNumBytesReturned,
138
                                                  DWORD dwTapControllerState)
139
{
140
 
141
 return pFT2232cMpsseJtag->JTAG_WriteReadDataToFromExternalDevice(
142
                                                                  ftHandle,
143
                                                                  bInstructionTestData,
144
                                                                  dwNumBitsToWriteRead,
145
                                                                  pWriteDataBuffer,
146
                                                                  dwNumBytesToWrite,
147
                                                                  pReadDataBuffer,
148
                                                                  lpdwNumBytesReturned,
149
                                                                  dwTapControllerState);
150
 
151
}
152
 
153
 
154
 
155
// Close device
156
FTC_STATUS
157
FT2232_USB_JTAG_CloseDevice()
158
{
159
  return pFT2232cMpsseJtag->JTAG_CloseDevice(ftHandle);
160
}
161
 
162
 
163 47 julius
void reinit_usb_jtag(void)
164
{
165
  FTC_STATUS Status = FTC_SUCCESS;
166
  if (DEBUG_USB_DRVR_FUNCS) printf("linux_usb_driver_calls: reset_usb_jtag() - ");
167
  Status = pFT2232cMpsseJtag->JTAG_InitDevice(ftHandle, 0);
168
  if (DEBUG_USB_DRVR_FUNCS) printf("return Status: %d\n", (int) Status);
169
}
170 39 julius
 
171
// Set clock frequency
172
// Frequency = 12Mhz/((1+divisor)*2), 
173
// divisor=1000 => Freq=5995Hz~=6kHz, divisor=500=>Freq=12kHz
174
#define USB_JTAG_CLK_DIVIDER 0
175
 
176
int init_usb_jtag()
177
{
178
  FTC_STATUS Status = FTC_SUCCESS;
179
  //char szDeviceName[100];
180
  //char szDeviceName[] = "Dual RS232 A"; // Original, unmodified FT2232 device name
181
  // We now open the device by its name
182 529 julius
  //char szDeviceName[] = "ORSoC OpenRISC debug cable A\0"; // ORSoC debug cable UART A name
183
  char* szDeviceName;
184 39 julius
  DWORD dwLocationID = 0;
185
  DWORD dwClockFrequencyHz = 0;
186
  FTC_INPUT_OUTPUT_PINS LowInputOutputPinsData;
187
  FTC_INPUT_OUTPUT_PINS HighInputOutputPinsData;
188
  FTC_LOW_HIGH_PINS LowPinsInputData;
189
  FTC_LOW_HIGH_PINS HighPinsInputData;
190
 
191
  //char szDllVersion[10];
192
 
193
  // Has been changed to hardcode load device named "ORSoC OpenRISC debug cable A"; - jb 090301
194 529 julius
#define MAX_DEVICES             5
195
  char *  pcBufRead = NULL;
196
  char *  pcBufLD[MAX_DEVICES + 1];
197
  char    cBufLD[MAX_DEVICES][64];
198
  FT_STATUS       ftStatus;
199
  int     iNumDevs = 0;
200
  int     i;
201
 
202
  for(i = 0; i < MAX_DEVICES; i++) {
203
          pcBufLD[i] = cBufLD[i];
204
  }
205
  pcBufLD[MAX_DEVICES] = NULL;
206
 
207
  ftStatus = FT_ListDevices(pcBufLD, &iNumDevs, FT_LIST_ALL | FT_OPEN_BY_DESCRIPTION);
208 39 julius
 
209 529 julius
  if(ftStatus != FT_OK) {
210
          printf("Error: FT_ListDevices(%d)\n", (int) ftStatus);
211
          return 1;
212
  }
213
#if DEBUG_USB_DRVR_FUNCS==1
214
  for(i = 0; ( (i <MAX_DEVICES) && (i < iNumDevs) ); i++) {
215
          printf("Device %d Description - %s\n", i, cBufLD[i]);
216
  }
217
#endif
218 39 julius
 
219 646 yannv
  if (iNumDevs==2)
220
    szDeviceName = cBufLD[0]; // Should be first device
221
  else if (iNumDevs==4)
222
    szDeviceName = cBufLD[1]; // Should be second device
223
  else
224
    {
225
      printf("Unexpected number of FTDI ports %d\n", iNumDevs);
226
      return 1;
227
    }
228 39 julius
 
229
  if (Status == FTC_SUCCESS)
230
    {
231
 
232 529 julius
            dwLocationID = 0;
233
 
234
            if (Status == FTC_SUCCESS)
235 39 julius
            {
236 529 julius
#if DEBUG_USB_DRVR_FUNCS==1
237
                    printf("JTAG_OpenSpecifiedDevice %s\n", szDeviceName);
238
#endif
239
                    Status = pFT2232cMpsseJtag->JTAG_OpenSpecifiedDevice(szDeviceName,dwLocationID, &ftHandle);
240
#if DEBUG_USB_DRVR_FUNCS==1
241
                    printf("JTAG_OpenSpecifiedDevice status: %d (%s)\n",(int)Status, EN_Common_Errors[Status]);
242
#endif
243
 
244 39 julius
            }
245 529 julius
 
246
 
247 39 julius
      // Try initialising and obtaining a handle to a specific device
248
      if (Status == FTC_SUCCESS)
249
        {
250
          printf("Initialising USB JTAG interface\n");
251
          Status = pFT2232cMpsseJtag->JTAG_InitDevice(ftHandle, 0);
252
 
253
          // Set clock frequency
254
          // Frequency = 12Mhz/((1+divisor)*2), 
255
          // divisor=1000 => Freq=5995Hz~=6kHz, divisor=500=>Freq=12kHz
256
          if (DEBUG_USB_DRVR_FUNCS)
257
            printf("Setting JTAG clock frequency.  Divisor = %d, TCK ~= %dkHz.\n", USB_JTAG_CLK_DIVIDER, (12000000/((USB_JTAG_CLK_DIVIDER+1)*2))/1000);
258
          if (Status == FTC_SUCCESS)
259
            Status = pFT2232cMpsseJtag->JTAG_SetClock(ftHandle, USB_JTAG_CLK_DIVIDER, &dwClockFrequencyHz);
260
 
261
          if (Status == FTC_SUCCESS){
262
 
263
            Status = pFT2232cMpsseJtag->JTAG_GetClock(5, &dwClockFrequencyHz);
264
          }
265
 
266
        }
267
 
268
      //if (Status == FTC_SUCCESS)
269
      //  Status = JTAG_SetLoopback(ftHandle, true);        
270
      if (Status == FTC_SUCCESS)
271
        {
272
          if (DEBUG_USB_DRVR_FUNCS) // Let LED blink
273
            {
274
              // true=output, false=input
275
              LowInputOutputPinsData.bPin1InputOutputState = true;  // ADBUS4
276
              LowInputOutputPinsData.bPin2InputOutputState = true;  // ADBUS5
277
              LowInputOutputPinsData.bPin3InputOutputState = true;  // ADBUS6
278
              LowInputOutputPinsData.bPin4InputOutputState = true;  // ADBUS7
279
              LowInputOutputPinsData.bPin1LowHighState = false;     // ADBUS4
280
              LowInputOutputPinsData.bPin2LowHighState = false;     // ADBUS5
281
              LowInputOutputPinsData.bPin3LowHighState = true;      // ADBUS6
282
              LowInputOutputPinsData.bPin4LowHighState = true;      // ADBUS7
283
 
284
              HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0 Output
285
              HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1 Output
286
              HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2 Output
287
              HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3 Output
288
              HighInputOutputPinsData.bPin1LowHighState = true;     // ACBUS0
289
              HighInputOutputPinsData.bPin2LowHighState = true;     // ACBUS1
290
              HighInputOutputPinsData.bPin3LowHighState = true;     // ACBUS2  LED RXLEDA A1 OFF 
291
              HighInputOutputPinsData.bPin4LowHighState = false;    // ACBUS3  LED TXLEDA A2 ON
292
 
293
              Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
294
                                                                                true,
295
                                                                                &LowInputOutputPinsData,
296
                                                                                true,
297
                                                                                &HighInputOutputPinsData);
298
 
299
              LowInputOutputPinsData.bPin1InputOutputState = true;  // ADBUS4 
300
              LowInputOutputPinsData.bPin2InputOutputState = true;  // ADBUS5
301
              LowInputOutputPinsData.bPin3InputOutputState = true;  // ADBUS6
302
              LowInputOutputPinsData.bPin4InputOutputState = true;  // ADBUS7
303
              LowInputOutputPinsData.bPin1LowHighState = false;     // ADBUS4
304
              LowInputOutputPinsData.bPin2LowHighState = false;     // ADBUS5
305
              LowInputOutputPinsData.bPin3LowHighState = true;      // ADBUS6
306
              LowInputOutputPinsData.bPin4LowHighState = true;      // ADBUS7
307
 
308
              HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
309
              HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
310
              HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
311
              HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
312
              HighInputOutputPinsData.bPin1LowHighState = true;     // ACBUS0
313
              HighInputOutputPinsData.bPin2LowHighState = true;     // ACBUS1
314
              HighInputOutputPinsData.bPin3LowHighState = false;    // ACBUS2 LED RXLEDA A1 ON
315
              HighInputOutputPinsData.bPin4LowHighState = true;     // ACBUS3 LED TXLEDA A2 OFF
316
 
317
              Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
318
                                                                                true,
319
                                                                                &LowInputOutputPinsData,
320
                                                                                true,
321
                                                                                &HighInputOutputPinsData);
322
 
323
              LowInputOutputPinsData.bPin1InputOutputState = true;  // ADBUS4 - 
324
              LowInputOutputPinsData.bPin2InputOutputState = true;  // ADBUS5
325
              LowInputOutputPinsData.bPin3InputOutputState = true;  // ADBUS6
326
              LowInputOutputPinsData.bPin4InputOutputState = true;  // ADBUS7
327
              LowInputOutputPinsData.bPin1LowHighState = false;     // ADBUS4
328
              LowInputOutputPinsData.bPin2LowHighState = false;     // ADBUS5
329
              LowInputOutputPinsData.bPin3LowHighState = true;      // ADBUS6
330
              LowInputOutputPinsData.bPin4LowHighState = true;      // ADBUS7
331
 
332
              HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
333
              HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
334
              HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
335
              HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
336
              HighInputOutputPinsData.bPin1LowHighState = true;     // ACBUS0
337
              HighInputOutputPinsData.bPin2LowHighState = true;     // ACBUS1
338
              HighInputOutputPinsData.bPin3LowHighState = true;     // ACBUS2 LED RXLEDA A1 OFF
339
              HighInputOutputPinsData.bPin4LowHighState = true;     // ACBUS3 LED TXLEDA A2 OFF
340
 
341
              Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
342
                                                                                true,
343
                                                                                &LowInputOutputPinsData,
344
                                                                                true,
345
                                                                                &HighInputOutputPinsData);
346
 
347
              LowInputOutputPinsData.bPin1InputOutputState = true;  // ADBUS4 - 
348
              LowInputOutputPinsData.bPin2InputOutputState = true;  // ADBUS5
349
              LowInputOutputPinsData.bPin3InputOutputState = true;  // ADBUS6
350
              LowInputOutputPinsData.bPin4InputOutputState = true;  // ADBUS7
351
              LowInputOutputPinsData.bPin1LowHighState = false;     // ADBUS4
352
              LowInputOutputPinsData.bPin2LowHighState = false;     // ADBUS5
353
              LowInputOutputPinsData.bPin3LowHighState = true;      // ADBUS6
354
              LowInputOutputPinsData.bPin4LowHighState = true;      // ADBUS7
355
 
356
              HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
357
              HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
358
              HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
359
              HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
360
              HighInputOutputPinsData.bPin1LowHighState = true;     // ACBUS0
361
              HighInputOutputPinsData.bPin2LowHighState = true;     // ACBUS1
362
              HighInputOutputPinsData.bPin3LowHighState = false;    // ACBUS2 LED RXLEDA A1 ON
363
              HighInputOutputPinsData.bPin4LowHighState = false;    // ACBUS3 LED TXLEDA A2 ON
364
 
365
              Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
366
                                                                                true,
367
                                                                                &LowInputOutputPinsData,
368
                                                                                true,
369
                                                                                &HighInputOutputPinsData);
370
            }
371
 
372
          // Setup GPIO pins for JTAG
373
          LowInputOutputPinsData.bPin1InputOutputState = true; // ADBUS4 - 
374
          // set ADBUS4 to output 0 to enable JTAG buffers on Olimex devices
375
          LowInputOutputPinsData.bPin2InputOutputState = true; //ADBUS5
376
          LowInputOutputPinsData.bPin3InputOutputState = true;
377
          LowInputOutputPinsData.bPin4InputOutputState = true;
378
          //ADBUS4 = 0 (enable JTAG buffers on Olimex devices)
379
          LowInputOutputPinsData.bPin1LowHighState = false; // ADBUS4
380
          LowInputOutputPinsData.bPin2LowHighState = false; // ADBUS5
381
          LowInputOutputPinsData.bPin3LowHighState = true; // ADBUS6
382
          LowInputOutputPinsData.bPin4LowHighState = true; // ADBUS7
383
 
384
          HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
385
          HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
386
          HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
387
          HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
388
          HighInputOutputPinsData.bPin1LowHighState = true; // ACBUS0
389
          HighInputOutputPinsData.bPin2LowHighState = true; // ACBUS1
390
          HighInputOutputPinsData.bPin3LowHighState = false; // ACBUS2 LED RXLEDA A1 ON
391
          HighInputOutputPinsData.bPin4LowHighState = true; // ACBUS3
392
 
393
          Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
394
                                                                            true,
395
                                                                            &LowInputOutputPinsData,
396
                                                                            true,
397
                                                                            &HighInputOutputPinsData);
398
 
399
          if (Status == FTC_SUCCESS)
400
            Status = pFT2232cMpsseJtag->JTAG_GetGeneralPurposeInputOutputPins(ftHandle, true, &LowPinsInputData,
401
                                    true, &HighPinsInputData);
402
 
403
          if (DEBUG_USB_DRVR_FUNCS)
404
            printf("JTAG low gpio pins values: (ADBUS7-ADBUS4):%x%x%x%x\n",
405
                   (LowPinsInputData.bPin4LowHighState==true),
406
                   (LowPinsInputData.bPin3LowHighState==true),
407
                   (LowPinsInputData.bPin2LowHighState==true),
408
                   (LowPinsInputData.bPin1LowHighState==true));
409
 
410
          if (DEBUG_USB_DRVR_FUNCS)
411
            printf("JTAG high gpio pins values: (ACBUS3-ACBUS0): %x%x%x%x\n",
412
                   (HighPinsInputData.bPin4LowHighState==true),
413
                   (HighPinsInputData.bPin3LowHighState==true),
414
                   (HighPinsInputData.bPin2LowHighState==true),
415
                   (HighPinsInputData.bPin1LowHighState==true));
416
        }
417
    }
418
 
419
 
420
  if (Status == FTC_SUCCESS)
421
    return 0;
422
  else
423
    return 1;
424
 
425
}

powered by: WebSVN 2.1.0

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