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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or_debug_proxy/] [src/] [linux_usb_driver_calls.c] - Blame information for rev 1779

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1779 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
static FT2232cMpsseJtag *pFT2232cMpsseJtag = NULL;
74
 
75
// Global USB JTAG device handle
76
FTC_HANDLE ftHandle;
77
 
78
// Write data to external device:
79
//FTC_STATUS FT2232cMpsseJtag::JTAG_WriteDataToExternalDevice(FTC_HANDLE ftHandle, BOOL bInstructionTestData, DWORD dwNumBitsToWrite,
80
 
81
FTC_STATUS
82
FT2232_USB_JTAG_WriteDataToExternalDevice(
83
                                          //FTC_HANDLE ftHandle, 
84
                                          BOOL bInstructionTestData,
85
                                          DWORD dwNumBitsToWrite,
86
                                          PWriteDataByteBuffer pWriteDataBuffer,
87
                                          DWORD dwNumBytesToWrite,
88
                                          DWORD dwTapControllerState)
89
{
90
  // Call the driver from the libary compiled in Linux
91
  return pFT2232cMpsseJtag->JTAG_WriteDataToExternalDevice(
92
                                                           ftHandle,
93
                                                           bInstructionTestData,
94
                                                           dwNumBitsToWrite,
95
                                                           pWriteDataBuffer,
96
                                                           dwNumBytesToWrite,
97
                                                           dwTapControllerState);
98
}
99
 
100
 
101
// Read data from external device
102
FTC_STATUS
103
FT2232_USB_JTAG_ReadDataFromExternalDevice(
104
                                           //FTC_HANDLE ftHandle, 
105
                                            BOOL bInstructionTestData,
106
                                            DWORD dwNumBitsToRead,
107
                                            PReadDataByteBuffer pReadDataBuffer,
108
                                            LPDWORD lpdwNumBytesReturned,
109
                                            DWORD dwTapControllerState)
110
 
111
{
112
  return pFT2232cMpsseJtag->JTAG_ReadDataFromExternalDevice(
113
                                                            ftHandle,
114
                                                            bInstructionTestData,
115
                                                            dwNumBitsToRead,
116
                                                            pReadDataBuffer,
117
                                                            lpdwNumBytesReturned,
118
                                                            dwTapControllerState);
119
 
120
}
121
 
122
 
123
 
124
 
125
 
126
 
127
// Write Read
128
FTC_STATUS
129
FT2232_USB_JTAG_WriteReadDataToFromExternalDevice(
130
                                                  //FTC_HANDLE ftHandle, 
131
                                                  BOOL bInstructionTestData,
132
                                                  DWORD dwNumBitsToWriteRead,
133
                                                  PWriteDataByteBuffer pWriteDataBuffer,
134
                                                  DWORD dwNumBytesToWrite,
135
                                                  PReadDataByteBuffer pReadDataBuffer,
136
                                                  LPDWORD lpdwNumBytesReturned,
137
                                                  DWORD dwTapControllerState)
138
{
139
 
140
 return pFT2232cMpsseJtag->JTAG_WriteReadDataToFromExternalDevice(
141
                                                                  ftHandle,
142
                                                                  bInstructionTestData,
143
                                                                  dwNumBitsToWriteRead,
144
                                                                  pWriteDataBuffer,
145
                                                                  dwNumBytesToWrite,
146
                                                                  pReadDataBuffer,
147
                                                                  lpdwNumBytesReturned,
148
                                                                  dwTapControllerState);
149
 
150
}
151
 
152
 
153
 
154
// Close device
155
FTC_STATUS
156
FT2232_USB_JTAG_CloseDevice()
157
{
158
  return pFT2232cMpsseJtag->JTAG_CloseDevice(ftHandle);
159
}
160
 
161
 
162
 
163
// Set clock frequency
164
// Frequency = 12Mhz/((1+divisor)*2), 
165
// divisor=1000 => Freq=5995Hz~=6kHz, divisor=500=>Freq=12kHz
166
#define USB_JTAG_CLK_DIVIDER 0
167
 
168
int init_usb_jtag()
169
{
170
  FTC_STATUS Status = FTC_SUCCESS;
171
  DWORD dwNumDevices = 0;
172
  //char szDeviceName[100];
173
  //char szDeviceName[] = "Dual RS232 A"; // Original, unmodified FT2232 device name
174
  // We now open the device by its name
175
  char szDeviceName[] = "ORSoC OpenRISC debug cable A\0"; // ORSoC debug cable UART A name
176
  DWORD dwLocationID = 0;
177
  DWORD dwClockFrequencyHz = 0;
178
  FTC_INPUT_OUTPUT_PINS LowInputOutputPinsData;
179
  FTC_INPUT_OUTPUT_PINS HighInputOutputPinsData;
180
  FTC_LOW_HIGH_PINS LowPinsInputData;
181
  FTC_LOW_HIGH_PINS HighPinsInputData;
182
 
183
  //char szDllVersion[10];
184
 
185
  // Has been changed to hardcode load device named "ORSoC OpenRISC debug cable A"; - jb 090301
186
 
187
  /*
188
  //Status = JTAG_GetNumDevices(&dwNumDevices);
189
  Status = pFT2232cMpsseJtag->JTAG_GetNumDevices(&dwNumDevices);
190
  if (DEBUG_USB_DRVR_FUNCS)
191
    {
192
      if (Status == FTC_SUCCESS)
193
        printf("JTAG_GetNumDevices detected %ld available FT2232x device(s) connected to the system.\n", dwNumDevices);
194
      else
195
        {
196
          printf("GetNumDevices failed with status code 0x%lx\n", Status);
197
          exit(-1);
198
        }
199
    }
200
 
201
  if (dwNumDevices == 0)
202
    {
203
      printf("Error: USB Debugger device not detected\n");
204
      exit(-1);
205
    }
206
 
207
  Status = pFT2232cMpsseJtag->JTAG_GetDllVersion(szDllVersion, 10);
208
 
209
  if (DEBUG_USB_DRVR_FUNCS)
210
    printf("JTAG_GetDLLVersion returned Status: 0x%lx and version %s\n", Status, szDllVersion);
211
 
212
  */
213
  dwNumDevices = 1;
214
 
215
  if (Status == FTC_SUCCESS)
216
    {
217
 
218
 
219
      if (dwNumDevices == 1)
220
        {
221
          /*
222
          Status = pFT2232cMpsseJtag->JTAG_GetDeviceNameLocationID(0,szDeviceName,50, &dwLocationID);
223
 
224
          if (DEBUG_USB_DRVR_FUNCS)
225
            // In the Windows version it shows Dual RS323 A at: 0x321
226
            printf("JTAG_GetDeviceNameLocID: %s at: 0x%lx\n", szDeviceName, dwLocationID);
227
          */
228
          dwLocationID = 0;
229
 
230
          if (Status == FTC_SUCCESS)
231
            {
232
              Status = pFT2232cMpsseJtag->JTAG_OpenSpecifiedDevice(szDeviceName,dwLocationID, &ftHandle);
233
            }
234
        }
235
      else
236
        // When there's more than 1 device, will just open first device. Perhaps implement selection menu for
237
        // users in event that there's more than 1, but for now just hard code this to open the same device
238
        {
239
          //if (dwNumDevices == 2)
240
          //{
241
          Status=pFT2232cMpsseJtag->JTAG_GetDeviceNameLocationID(1,szDeviceName,50,&dwLocationID);
242
 
243
          if (Status == FTC_SUCCESS)
244
            {
245
              Status = pFT2232cMpsseJtag->JTAG_OpenSpecifiedDevice(szDeviceName, dwLocationID, &ftHandle);
246
            }
247
          //}
248
        }
249
 
250
      // Try initialising and obtaining a handle to a specific device
251
      if (Status == FTC_SUCCESS)
252
        {
253
          printf("Initialising USB JTAG interface\n");
254
          Status = pFT2232cMpsseJtag->JTAG_InitDevice(ftHandle, 0);
255
 
256
          // Set clock frequency
257
          // Frequency = 12Mhz/((1+divisor)*2), 
258
          // divisor=1000 => Freq=5995Hz~=6kHz, divisor=500=>Freq=12kHz
259
          if (DEBUG_USB_DRVR_FUNCS)
260
            printf("Setting JTAG clock frequency.  Divisor = %d, TCK ~= %dkHz.\n", USB_JTAG_CLK_DIVIDER, (12000000/((USB_JTAG_CLK_DIVIDER+1)*2))/1000);
261
          if (Status == FTC_SUCCESS)
262
            Status = pFT2232cMpsseJtag->JTAG_SetClock(ftHandle, USB_JTAG_CLK_DIVIDER, &dwClockFrequencyHz);
263
 
264
          if (Status == FTC_SUCCESS){
265
 
266
            Status = pFT2232cMpsseJtag->JTAG_GetClock(5, &dwClockFrequencyHz);
267
          }
268
 
269
        }
270
 
271
      //if (Status == FTC_SUCCESS)
272
      //  Status = JTAG_SetLoopback(ftHandle, true);        
273
      if (Status == FTC_SUCCESS)
274
        {
275
          if (DEBUG_USB_DRVR_FUNCS) // Let LED blink
276
            {
277
              // true=output, false=input
278
              LowInputOutputPinsData.bPin1InputOutputState = true;  // ADBUS4
279
              LowInputOutputPinsData.bPin2InputOutputState = true;  // ADBUS5
280
              LowInputOutputPinsData.bPin3InputOutputState = true;  // ADBUS6
281
              LowInputOutputPinsData.bPin4InputOutputState = true;  // ADBUS7
282
              LowInputOutputPinsData.bPin1LowHighState = false;     // ADBUS4
283
              LowInputOutputPinsData.bPin2LowHighState = false;     // ADBUS5
284
              LowInputOutputPinsData.bPin3LowHighState = true;      // ADBUS6
285
              LowInputOutputPinsData.bPin4LowHighState = true;      // ADBUS7
286
 
287
              HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0 Output
288
              HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1 Output
289
              HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2 Output
290
              HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3 Output
291
              HighInputOutputPinsData.bPin1LowHighState = true;     // ACBUS0
292
              HighInputOutputPinsData.bPin2LowHighState = true;     // ACBUS1
293
              HighInputOutputPinsData.bPin3LowHighState = true;     // ACBUS2  LED RXLEDA A1 OFF 
294
              HighInputOutputPinsData.bPin4LowHighState = false;    // ACBUS3  LED TXLEDA A2 ON
295
 
296
              Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
297
                                                                                true,
298
                                                                                &LowInputOutputPinsData,
299
                                                                                true,
300
                                                                                &HighInputOutputPinsData);
301
 
302
              LowInputOutputPinsData.bPin1InputOutputState = true;  // ADBUS4 
303
              LowInputOutputPinsData.bPin2InputOutputState = true;  // ADBUS5
304
              LowInputOutputPinsData.bPin3InputOutputState = true;  // ADBUS6
305
              LowInputOutputPinsData.bPin4InputOutputState = true;  // ADBUS7
306
              LowInputOutputPinsData.bPin1LowHighState = false;     // ADBUS4
307
              LowInputOutputPinsData.bPin2LowHighState = false;     // ADBUS5
308
              LowInputOutputPinsData.bPin3LowHighState = true;      // ADBUS6
309
              LowInputOutputPinsData.bPin4LowHighState = true;      // ADBUS7
310
 
311
              HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
312
              HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
313
              HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
314
              HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
315
              HighInputOutputPinsData.bPin1LowHighState = true;     // ACBUS0
316
              HighInputOutputPinsData.bPin2LowHighState = true;     // ACBUS1
317
              HighInputOutputPinsData.bPin3LowHighState = false;    // ACBUS2 LED RXLEDA A1 ON
318
              HighInputOutputPinsData.bPin4LowHighState = true;     // ACBUS3 LED TXLEDA A2 OFF
319
 
320
              Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
321
                                                                                true,
322
                                                                                &LowInputOutputPinsData,
323
                                                                                true,
324
                                                                                &HighInputOutputPinsData);
325
 
326
              LowInputOutputPinsData.bPin1InputOutputState = true;  // ADBUS4 - 
327
              LowInputOutputPinsData.bPin2InputOutputState = true;  // ADBUS5
328
              LowInputOutputPinsData.bPin3InputOutputState = true;  // ADBUS6
329
              LowInputOutputPinsData.bPin4InputOutputState = true;  // ADBUS7
330
              LowInputOutputPinsData.bPin1LowHighState = false;     // ADBUS4
331
              LowInputOutputPinsData.bPin2LowHighState = false;     // ADBUS5
332
              LowInputOutputPinsData.bPin3LowHighState = true;      // ADBUS6
333
              LowInputOutputPinsData.bPin4LowHighState = true;      // ADBUS7
334
 
335
              HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
336
              HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
337
              HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
338
              HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
339
              HighInputOutputPinsData.bPin1LowHighState = true;     // ACBUS0
340
              HighInputOutputPinsData.bPin2LowHighState = true;     // ACBUS1
341
              HighInputOutputPinsData.bPin3LowHighState = true;     // ACBUS2 LED RXLEDA A1 OFF
342
              HighInputOutputPinsData.bPin4LowHighState = true;     // ACBUS3 LED TXLEDA A2 OFF
343
 
344
              Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
345
                                                                                true,
346
                                                                                &LowInputOutputPinsData,
347
                                                                                true,
348
                                                                                &HighInputOutputPinsData);
349
 
350
              LowInputOutputPinsData.bPin1InputOutputState = true;  // ADBUS4 - 
351
              LowInputOutputPinsData.bPin2InputOutputState = true;  // ADBUS5
352
              LowInputOutputPinsData.bPin3InputOutputState = true;  // ADBUS6
353
              LowInputOutputPinsData.bPin4InputOutputState = true;  // ADBUS7
354
              LowInputOutputPinsData.bPin1LowHighState = false;     // ADBUS4
355
              LowInputOutputPinsData.bPin2LowHighState = false;     // ADBUS5
356
              LowInputOutputPinsData.bPin3LowHighState = true;      // ADBUS6
357
              LowInputOutputPinsData.bPin4LowHighState = true;      // ADBUS7
358
 
359
              HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
360
              HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
361
              HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
362
              HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
363
              HighInputOutputPinsData.bPin1LowHighState = true;     // ACBUS0
364
              HighInputOutputPinsData.bPin2LowHighState = true;     // ACBUS1
365
              HighInputOutputPinsData.bPin3LowHighState = false;    // ACBUS2 LED RXLEDA A1 ON
366
              HighInputOutputPinsData.bPin4LowHighState = false;    // ACBUS3 LED TXLEDA A2 ON
367
 
368
              Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
369
                                                                                true,
370
                                                                                &LowInputOutputPinsData,
371
                                                                                true,
372
                                                                                &HighInputOutputPinsData);
373
            }
374
 
375
          // Setup GPIO pins for JTAG
376
          LowInputOutputPinsData.bPin1InputOutputState = true; // ADBUS4 - 
377
          // set ADBUS4 to output 0 to enable JTAG buffers on Olimex devices
378
          LowInputOutputPinsData.bPin2InputOutputState = true; //ADBUS5
379
          LowInputOutputPinsData.bPin3InputOutputState = true;
380
          LowInputOutputPinsData.bPin4InputOutputState = true;
381
          //ADBUS4 = 0 (enable JTAG buffers on Olimex devices)
382
          LowInputOutputPinsData.bPin1LowHighState = false; // ADBUS4
383
          LowInputOutputPinsData.bPin2LowHighState = false; // ADBUS5
384
          LowInputOutputPinsData.bPin3LowHighState = true; // ADBUS6
385
          LowInputOutputPinsData.bPin4LowHighState = true; // ADBUS7
386
 
387
          HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
388
          HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
389
          HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
390
          HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
391
          HighInputOutputPinsData.bPin1LowHighState = true; // ACBUS0
392
          HighInputOutputPinsData.bPin2LowHighState = true; // ACBUS1
393
          HighInputOutputPinsData.bPin3LowHighState = false; // ACBUS2 LED RXLEDA A1 ON
394
          HighInputOutputPinsData.bPin4LowHighState = true; // ACBUS3
395
 
396
          Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
397
                                                                            true,
398
                                                                            &LowInputOutputPinsData,
399
                                                                            true,
400
                                                                            &HighInputOutputPinsData);
401
 
402
          if (Status == FTC_SUCCESS)
403
            Status = pFT2232cMpsseJtag->JTAG_GetGeneralPurposeInputOutputPins(ftHandle, true, &LowPinsInputData,
404
                                    true, &HighPinsInputData);
405
 
406
          if (DEBUG_USB_DRVR_FUNCS)
407
            printf("JTAG low gpio pins values: (ADBUS7-ADBUS4):%x%x%x%x\n",
408
                   (LowPinsInputData.bPin4LowHighState==true),
409
                   (LowPinsInputData.bPin3LowHighState==true),
410
                   (LowPinsInputData.bPin2LowHighState==true),
411
                   (LowPinsInputData.bPin1LowHighState==true));
412
 
413
          if (DEBUG_USB_DRVR_FUNCS)
414
            printf("JTAG high gpio pins values: (ACBUS3-ACBUS0): %x%x%x%x\n",
415
                   (HighPinsInputData.bPin4LowHighState==true),
416
                   (HighPinsInputData.bPin3LowHighState==true),
417
                   (HighPinsInputData.bPin2LowHighState==true),
418
                   (HighPinsInputData.bPin1LowHighState==true));
419
        }
420
    }
421
 
422
 
423
  if (Status == FTC_SUCCESS)
424
    return 0;
425
  else
426
    return 1;
427
 
428
}

powered by: WebSVN 2.1.0

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