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 165

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
  DWORD dwNumDevices = 0;
180
  //char szDeviceName[100];
181
  //char szDeviceName[] = "Dual RS232 A"; // Original, unmodified FT2232 device name
182
  // We now open the device by its name
183
  char szDeviceName[] = "ORSoC OpenRISC debug cable A\0"; // ORSoC debug cable UART A name
184
  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
 
195
  /*
196
  //Status = JTAG_GetNumDevices(&dwNumDevices);
197
  Status = pFT2232cMpsseJtag->JTAG_GetNumDevices(&dwNumDevices);
198
  if (DEBUG_USB_DRVR_FUNCS)
199
    {
200
      if (Status == FTC_SUCCESS)
201
        printf("JTAG_GetNumDevices detected %ld available FT2232x device(s) connected to the system.\n", dwNumDevices);
202
      else
203
        {
204
          printf("GetNumDevices failed with status code 0x%lx\n", Status);
205
          exit(-1);
206
        }
207
    }
208
 
209
  if (dwNumDevices == 0)
210
    {
211
      printf("Error: USB Debugger device not detected\n");
212
      exit(-1);
213
    }
214
 
215
  Status = pFT2232cMpsseJtag->JTAG_GetDllVersion(szDllVersion, 10);
216
 
217
  if (DEBUG_USB_DRVR_FUNCS)
218
    printf("JTAG_GetDLLVersion returned Status: 0x%lx and version %s\n", Status, szDllVersion);
219
 
220
  */
221
  dwNumDevices = 1;
222
 
223
  if (Status == FTC_SUCCESS)
224
    {
225
 
226
 
227
      if (dwNumDevices == 1)
228
        {
229
          /*
230
          Status = pFT2232cMpsseJtag->JTAG_GetDeviceNameLocationID(0,szDeviceName,50, &dwLocationID);
231
 
232
          if (DEBUG_USB_DRVR_FUNCS)
233
            // In the Windows version it shows Dual RS323 A at: 0x321
234
            printf("JTAG_GetDeviceNameLocID: %s at: 0x%lx\n", szDeviceName, dwLocationID);
235
          */
236
          dwLocationID = 0;
237
 
238
          if (Status == FTC_SUCCESS)
239
            {
240
              Status = pFT2232cMpsseJtag->JTAG_OpenSpecifiedDevice(szDeviceName,dwLocationID, &ftHandle);
241
            }
242
        }
243
      else
244
        // When there's more than 1 device, will just open first device. Perhaps implement selection menu for
245
        // users in event that there's more than 1, but for now just hard code this to open the same device
246
        {
247
          //if (dwNumDevices == 2)
248
          //{
249
          Status=pFT2232cMpsseJtag->JTAG_GetDeviceNameLocationID(1,szDeviceName,50,&dwLocationID);
250
 
251
          if (Status == FTC_SUCCESS)
252
            {
253
              Status = pFT2232cMpsseJtag->JTAG_OpenSpecifiedDevice(szDeviceName, dwLocationID, &ftHandle);
254
            }
255
          //}
256
        }
257
 
258
      // Try initialising and obtaining a handle to a specific device
259
      if (Status == FTC_SUCCESS)
260
        {
261
          printf("Initialising USB JTAG interface\n");
262
          Status = pFT2232cMpsseJtag->JTAG_InitDevice(ftHandle, 0);
263
 
264
          // Set clock frequency
265
          // Frequency = 12Mhz/((1+divisor)*2), 
266
          // divisor=1000 => Freq=5995Hz~=6kHz, divisor=500=>Freq=12kHz
267
          if (DEBUG_USB_DRVR_FUNCS)
268
            printf("Setting JTAG clock frequency.  Divisor = %d, TCK ~= %dkHz.\n", USB_JTAG_CLK_DIVIDER, (12000000/((USB_JTAG_CLK_DIVIDER+1)*2))/1000);
269
          if (Status == FTC_SUCCESS)
270
            Status = pFT2232cMpsseJtag->JTAG_SetClock(ftHandle, USB_JTAG_CLK_DIVIDER, &dwClockFrequencyHz);
271
 
272
          if (Status == FTC_SUCCESS){
273
 
274
            Status = pFT2232cMpsseJtag->JTAG_GetClock(5, &dwClockFrequencyHz);
275
          }
276
 
277
        }
278
 
279
      //if (Status == FTC_SUCCESS)
280
      //  Status = JTAG_SetLoopback(ftHandle, true);        
281
      if (Status == FTC_SUCCESS)
282
        {
283
          if (DEBUG_USB_DRVR_FUNCS) // Let LED blink
284
            {
285
              // true=output, false=input
286
              LowInputOutputPinsData.bPin1InputOutputState = true;  // ADBUS4
287
              LowInputOutputPinsData.bPin2InputOutputState = true;  // ADBUS5
288
              LowInputOutputPinsData.bPin3InputOutputState = true;  // ADBUS6
289
              LowInputOutputPinsData.bPin4InputOutputState = true;  // ADBUS7
290
              LowInputOutputPinsData.bPin1LowHighState = false;     // ADBUS4
291
              LowInputOutputPinsData.bPin2LowHighState = false;     // ADBUS5
292
              LowInputOutputPinsData.bPin3LowHighState = true;      // ADBUS6
293
              LowInputOutputPinsData.bPin4LowHighState = true;      // ADBUS7
294
 
295
              HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0 Output
296
              HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1 Output
297
              HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2 Output
298
              HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3 Output
299
              HighInputOutputPinsData.bPin1LowHighState = true;     // ACBUS0
300
              HighInputOutputPinsData.bPin2LowHighState = true;     // ACBUS1
301
              HighInputOutputPinsData.bPin3LowHighState = true;     // ACBUS2  LED RXLEDA A1 OFF 
302
              HighInputOutputPinsData.bPin4LowHighState = false;    // ACBUS3  LED TXLEDA A2 ON
303
 
304
              Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
305
                                                                                true,
306
                                                                                &LowInputOutputPinsData,
307
                                                                                true,
308
                                                                                &HighInputOutputPinsData);
309
 
310
              LowInputOutputPinsData.bPin1InputOutputState = true;  // ADBUS4 
311
              LowInputOutputPinsData.bPin2InputOutputState = true;  // ADBUS5
312
              LowInputOutputPinsData.bPin3InputOutputState = true;  // ADBUS6
313
              LowInputOutputPinsData.bPin4InputOutputState = true;  // ADBUS7
314
              LowInputOutputPinsData.bPin1LowHighState = false;     // ADBUS4
315
              LowInputOutputPinsData.bPin2LowHighState = false;     // ADBUS5
316
              LowInputOutputPinsData.bPin3LowHighState = true;      // ADBUS6
317
              LowInputOutputPinsData.bPin4LowHighState = true;      // ADBUS7
318
 
319
              HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
320
              HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
321
              HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
322
              HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
323
              HighInputOutputPinsData.bPin1LowHighState = true;     // ACBUS0
324
              HighInputOutputPinsData.bPin2LowHighState = true;     // ACBUS1
325
              HighInputOutputPinsData.bPin3LowHighState = false;    // ACBUS2 LED RXLEDA A1 ON
326
              HighInputOutputPinsData.bPin4LowHighState = true;     // ACBUS3 LED TXLEDA A2 OFF
327
 
328
              Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
329
                                                                                true,
330
                                                                                &LowInputOutputPinsData,
331
                                                                                true,
332
                                                                                &HighInputOutputPinsData);
333
 
334
              LowInputOutputPinsData.bPin1InputOutputState = true;  // ADBUS4 - 
335
              LowInputOutputPinsData.bPin2InputOutputState = true;  // ADBUS5
336
              LowInputOutputPinsData.bPin3InputOutputState = true;  // ADBUS6
337
              LowInputOutputPinsData.bPin4InputOutputState = true;  // ADBUS7
338
              LowInputOutputPinsData.bPin1LowHighState = false;     // ADBUS4
339
              LowInputOutputPinsData.bPin2LowHighState = false;     // ADBUS5
340
              LowInputOutputPinsData.bPin3LowHighState = true;      // ADBUS6
341
              LowInputOutputPinsData.bPin4LowHighState = true;      // ADBUS7
342
 
343
              HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
344
              HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
345
              HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
346
              HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
347
              HighInputOutputPinsData.bPin1LowHighState = true;     // ACBUS0
348
              HighInputOutputPinsData.bPin2LowHighState = true;     // ACBUS1
349
              HighInputOutputPinsData.bPin3LowHighState = true;     // ACBUS2 LED RXLEDA A1 OFF
350
              HighInputOutputPinsData.bPin4LowHighState = true;     // ACBUS3 LED TXLEDA A2 OFF
351
 
352
              Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
353
                                                                                true,
354
                                                                                &LowInputOutputPinsData,
355
                                                                                true,
356
                                                                                &HighInputOutputPinsData);
357
 
358
              LowInputOutputPinsData.bPin1InputOutputState = true;  // ADBUS4 - 
359
              LowInputOutputPinsData.bPin2InputOutputState = true;  // ADBUS5
360
              LowInputOutputPinsData.bPin3InputOutputState = true;  // ADBUS6
361
              LowInputOutputPinsData.bPin4InputOutputState = true;  // ADBUS7
362
              LowInputOutputPinsData.bPin1LowHighState = false;     // ADBUS4
363
              LowInputOutputPinsData.bPin2LowHighState = false;     // ADBUS5
364
              LowInputOutputPinsData.bPin3LowHighState = true;      // ADBUS6
365
              LowInputOutputPinsData.bPin4LowHighState = true;      // ADBUS7
366
 
367
              HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
368
              HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
369
              HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
370
              HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
371
              HighInputOutputPinsData.bPin1LowHighState = true;     // ACBUS0
372
              HighInputOutputPinsData.bPin2LowHighState = true;     // ACBUS1
373
              HighInputOutputPinsData.bPin3LowHighState = false;    // ACBUS2 LED RXLEDA A1 ON
374
              HighInputOutputPinsData.bPin4LowHighState = false;    // ACBUS3 LED TXLEDA A2 ON
375
 
376
              Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
377
                                                                                true,
378
                                                                                &LowInputOutputPinsData,
379
                                                                                true,
380
                                                                                &HighInputOutputPinsData);
381
            }
382
 
383
          // Setup GPIO pins for JTAG
384
          LowInputOutputPinsData.bPin1InputOutputState = true; // ADBUS4 - 
385
          // set ADBUS4 to output 0 to enable JTAG buffers on Olimex devices
386
          LowInputOutputPinsData.bPin2InputOutputState = true; //ADBUS5
387
          LowInputOutputPinsData.bPin3InputOutputState = true;
388
          LowInputOutputPinsData.bPin4InputOutputState = true;
389
          //ADBUS4 = 0 (enable JTAG buffers on Olimex devices)
390
          LowInputOutputPinsData.bPin1LowHighState = false; // ADBUS4
391
          LowInputOutputPinsData.bPin2LowHighState = false; // ADBUS5
392
          LowInputOutputPinsData.bPin3LowHighState = true; // ADBUS6
393
          LowInputOutputPinsData.bPin4LowHighState = true; // ADBUS7
394
 
395
          HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
396
          HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
397
          HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
398
          HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
399
          HighInputOutputPinsData.bPin1LowHighState = true; // ACBUS0
400
          HighInputOutputPinsData.bPin2LowHighState = true; // ACBUS1
401
          HighInputOutputPinsData.bPin3LowHighState = false; // ACBUS2 LED RXLEDA A1 ON
402
          HighInputOutputPinsData.bPin4LowHighState = true; // ACBUS3
403
 
404
          Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
405
                                                                            true,
406
                                                                            &LowInputOutputPinsData,
407
                                                                            true,
408
                                                                            &HighInputOutputPinsData);
409
 
410
          if (Status == FTC_SUCCESS)
411
            Status = pFT2232cMpsseJtag->JTAG_GetGeneralPurposeInputOutputPins(ftHandle, true, &LowPinsInputData,
412
                                    true, &HighPinsInputData);
413
 
414
          if (DEBUG_USB_DRVR_FUNCS)
415
            printf("JTAG low gpio pins values: (ADBUS7-ADBUS4):%x%x%x%x\n",
416
                   (LowPinsInputData.bPin4LowHighState==true),
417
                   (LowPinsInputData.bPin3LowHighState==true),
418
                   (LowPinsInputData.bPin2LowHighState==true),
419
                   (LowPinsInputData.bPin1LowHighState==true));
420
 
421
          if (DEBUG_USB_DRVR_FUNCS)
422
            printf("JTAG high gpio pins values: (ACBUS3-ACBUS0): %x%x%x%x\n",
423
                   (HighPinsInputData.bPin4LowHighState==true),
424
                   (HighPinsInputData.bPin3LowHighState==true),
425
                   (HighPinsInputData.bPin2LowHighState==true),
426
                   (HighPinsInputData.bPin1LowHighState==true));
427
        }
428
    }
429
 
430
 
431
  if (Status == FTC_SUCCESS)
432
    return 0;
433
  else
434
    return 1;
435
 
436
}

powered by: WebSVN 2.1.0

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