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 534

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 529 julius
  szDeviceName = cBufLD[0]; // Should be first device
220 39 julius
 
221
  if (Status == FTC_SUCCESS)
222
    {
223
 
224 529 julius
            dwLocationID = 0;
225
 
226
            if (Status == FTC_SUCCESS)
227 39 julius
            {
228 529 julius
#if DEBUG_USB_DRVR_FUNCS==1
229
                    printf("JTAG_OpenSpecifiedDevice %s\n", szDeviceName);
230
#endif
231
                    Status = pFT2232cMpsseJtag->JTAG_OpenSpecifiedDevice(szDeviceName,dwLocationID, &ftHandle);
232
#if DEBUG_USB_DRVR_FUNCS==1
233
                    printf("JTAG_OpenSpecifiedDevice status: %d (%s)\n",(int)Status, EN_Common_Errors[Status]);
234
#endif
235
 
236 39 julius
            }
237 529 julius
 
238
 
239 39 julius
      // Try initialising and obtaining a handle to a specific device
240
      if (Status == FTC_SUCCESS)
241
        {
242
          printf("Initialising USB JTAG interface\n");
243
          Status = pFT2232cMpsseJtag->JTAG_InitDevice(ftHandle, 0);
244
 
245
          // Set clock frequency
246
          // Frequency = 12Mhz/((1+divisor)*2), 
247
          // divisor=1000 => Freq=5995Hz~=6kHz, divisor=500=>Freq=12kHz
248
          if (DEBUG_USB_DRVR_FUNCS)
249
            printf("Setting JTAG clock frequency.  Divisor = %d, TCK ~= %dkHz.\n", USB_JTAG_CLK_DIVIDER, (12000000/((USB_JTAG_CLK_DIVIDER+1)*2))/1000);
250
          if (Status == FTC_SUCCESS)
251
            Status = pFT2232cMpsseJtag->JTAG_SetClock(ftHandle, USB_JTAG_CLK_DIVIDER, &dwClockFrequencyHz);
252
 
253
          if (Status == FTC_SUCCESS){
254
 
255
            Status = pFT2232cMpsseJtag->JTAG_GetClock(5, &dwClockFrequencyHz);
256
          }
257
 
258
        }
259
 
260
      //if (Status == FTC_SUCCESS)
261
      //  Status = JTAG_SetLoopback(ftHandle, true);        
262
      if (Status == FTC_SUCCESS)
263
        {
264
          if (DEBUG_USB_DRVR_FUNCS) // Let LED blink
265
            {
266
              // true=output, false=input
267
              LowInputOutputPinsData.bPin1InputOutputState = true;  // ADBUS4
268
              LowInputOutputPinsData.bPin2InputOutputState = true;  // ADBUS5
269
              LowInputOutputPinsData.bPin3InputOutputState = true;  // ADBUS6
270
              LowInputOutputPinsData.bPin4InputOutputState = true;  // ADBUS7
271
              LowInputOutputPinsData.bPin1LowHighState = false;     // ADBUS4
272
              LowInputOutputPinsData.bPin2LowHighState = false;     // ADBUS5
273
              LowInputOutputPinsData.bPin3LowHighState = true;      // ADBUS6
274
              LowInputOutputPinsData.bPin4LowHighState = true;      // ADBUS7
275
 
276
              HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0 Output
277
              HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1 Output
278
              HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2 Output
279
              HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3 Output
280
              HighInputOutputPinsData.bPin1LowHighState = true;     // ACBUS0
281
              HighInputOutputPinsData.bPin2LowHighState = true;     // ACBUS1
282
              HighInputOutputPinsData.bPin3LowHighState = true;     // ACBUS2  LED RXLEDA A1 OFF 
283
              HighInputOutputPinsData.bPin4LowHighState = false;    // ACBUS3  LED TXLEDA A2 ON
284
 
285
              Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
286
                                                                                true,
287
                                                                                &LowInputOutputPinsData,
288
                                                                                true,
289
                                                                                &HighInputOutputPinsData);
290
 
291
              LowInputOutputPinsData.bPin1InputOutputState = true;  // ADBUS4 
292
              LowInputOutputPinsData.bPin2InputOutputState = true;  // ADBUS5
293
              LowInputOutputPinsData.bPin3InputOutputState = true;  // ADBUS6
294
              LowInputOutputPinsData.bPin4InputOutputState = true;  // ADBUS7
295
              LowInputOutputPinsData.bPin1LowHighState = false;     // ADBUS4
296
              LowInputOutputPinsData.bPin2LowHighState = false;     // ADBUS5
297
              LowInputOutputPinsData.bPin3LowHighState = true;      // ADBUS6
298
              LowInputOutputPinsData.bPin4LowHighState = true;      // ADBUS7
299
 
300
              HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
301
              HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
302
              HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
303
              HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
304
              HighInputOutputPinsData.bPin1LowHighState = true;     // ACBUS0
305
              HighInputOutputPinsData.bPin2LowHighState = true;     // ACBUS1
306
              HighInputOutputPinsData.bPin3LowHighState = false;    // ACBUS2 LED RXLEDA A1 ON
307
              HighInputOutputPinsData.bPin4LowHighState = true;     // ACBUS3 LED TXLEDA A2 OFF
308
 
309
              Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
310
                                                                                true,
311
                                                                                &LowInputOutputPinsData,
312
                                                                                true,
313
                                                                                &HighInputOutputPinsData);
314
 
315
              LowInputOutputPinsData.bPin1InputOutputState = true;  // ADBUS4 - 
316
              LowInputOutputPinsData.bPin2InputOutputState = true;  // ADBUS5
317
              LowInputOutputPinsData.bPin3InputOutputState = true;  // ADBUS6
318
              LowInputOutputPinsData.bPin4InputOutputState = true;  // ADBUS7
319
              LowInputOutputPinsData.bPin1LowHighState = false;     // ADBUS4
320
              LowInputOutputPinsData.bPin2LowHighState = false;     // ADBUS5
321
              LowInputOutputPinsData.bPin3LowHighState = true;      // ADBUS6
322
              LowInputOutputPinsData.bPin4LowHighState = true;      // ADBUS7
323
 
324
              HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
325
              HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
326
              HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
327
              HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
328
              HighInputOutputPinsData.bPin1LowHighState = true;     // ACBUS0
329
              HighInputOutputPinsData.bPin2LowHighState = true;     // ACBUS1
330
              HighInputOutputPinsData.bPin3LowHighState = true;     // ACBUS2 LED RXLEDA A1 OFF
331
              HighInputOutputPinsData.bPin4LowHighState = true;     // ACBUS3 LED TXLEDA A2 OFF
332
 
333
              Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
334
                                                                                true,
335
                                                                                &LowInputOutputPinsData,
336
                                                                                true,
337
                                                                                &HighInputOutputPinsData);
338
 
339
              LowInputOutputPinsData.bPin1InputOutputState = true;  // ADBUS4 - 
340
              LowInputOutputPinsData.bPin2InputOutputState = true;  // ADBUS5
341
              LowInputOutputPinsData.bPin3InputOutputState = true;  // ADBUS6
342
              LowInputOutputPinsData.bPin4InputOutputState = true;  // ADBUS7
343
              LowInputOutputPinsData.bPin1LowHighState = false;     // ADBUS4
344
              LowInputOutputPinsData.bPin2LowHighState = false;     // ADBUS5
345
              LowInputOutputPinsData.bPin3LowHighState = true;      // ADBUS6
346
              LowInputOutputPinsData.bPin4LowHighState = true;      // ADBUS7
347
 
348
              HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
349
              HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
350
              HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
351
              HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
352
              HighInputOutputPinsData.bPin1LowHighState = true;     // ACBUS0
353
              HighInputOutputPinsData.bPin2LowHighState = true;     // ACBUS1
354
              HighInputOutputPinsData.bPin3LowHighState = false;    // ACBUS2 LED RXLEDA A1 ON
355
              HighInputOutputPinsData.bPin4LowHighState = false;    // ACBUS3 LED TXLEDA A2 ON
356
 
357
              Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
358
                                                                                true,
359
                                                                                &LowInputOutputPinsData,
360
                                                                                true,
361
                                                                                &HighInputOutputPinsData);
362
            }
363
 
364
          // Setup GPIO pins for JTAG
365
          LowInputOutputPinsData.bPin1InputOutputState = true; // ADBUS4 - 
366
          // set ADBUS4 to output 0 to enable JTAG buffers on Olimex devices
367
          LowInputOutputPinsData.bPin2InputOutputState = true; //ADBUS5
368
          LowInputOutputPinsData.bPin3InputOutputState = true;
369
          LowInputOutputPinsData.bPin4InputOutputState = true;
370
          //ADBUS4 = 0 (enable JTAG buffers on Olimex devices)
371
          LowInputOutputPinsData.bPin1LowHighState = false; // ADBUS4
372
          LowInputOutputPinsData.bPin2LowHighState = false; // ADBUS5
373
          LowInputOutputPinsData.bPin3LowHighState = true; // ADBUS6
374
          LowInputOutputPinsData.bPin4LowHighState = true; // ADBUS7
375
 
376
          HighInputOutputPinsData.bPin1InputOutputState = true; // ACBUS0
377
          HighInputOutputPinsData.bPin2InputOutputState = true; // ACBUS1
378
          HighInputOutputPinsData.bPin3InputOutputState = true; // ACBUS2
379
          HighInputOutputPinsData.bPin4InputOutputState = true; // ACBUS3
380
          HighInputOutputPinsData.bPin1LowHighState = true; // ACBUS0
381
          HighInputOutputPinsData.bPin2LowHighState = true; // ACBUS1
382
          HighInputOutputPinsData.bPin3LowHighState = false; // ACBUS2 LED RXLEDA A1 ON
383
          HighInputOutputPinsData.bPin4LowHighState = true; // ACBUS3
384
 
385
          Status = pFT2232cMpsseJtag->JTAG_SetGeneralPurposeInputOutputPins(ftHandle,
386
                                                                            true,
387
                                                                            &LowInputOutputPinsData,
388
                                                                            true,
389
                                                                            &HighInputOutputPinsData);
390
 
391
          if (Status == FTC_SUCCESS)
392
            Status = pFT2232cMpsseJtag->JTAG_GetGeneralPurposeInputOutputPins(ftHandle, true, &LowPinsInputData,
393
                                    true, &HighPinsInputData);
394
 
395
          if (DEBUG_USB_DRVR_FUNCS)
396
            printf("JTAG low gpio pins values: (ADBUS7-ADBUS4):%x%x%x%x\n",
397
                   (LowPinsInputData.bPin4LowHighState==true),
398
                   (LowPinsInputData.bPin3LowHighState==true),
399
                   (LowPinsInputData.bPin2LowHighState==true),
400
                   (LowPinsInputData.bPin1LowHighState==true));
401
 
402
          if (DEBUG_USB_DRVR_FUNCS)
403
            printf("JTAG high gpio pins values: (ACBUS3-ACBUS0): %x%x%x%x\n",
404
                   (HighPinsInputData.bPin4LowHighState==true),
405
                   (HighPinsInputData.bPin3LowHighState==true),
406
                   (HighPinsInputData.bPin2LowHighState==true),
407
                   (HighPinsInputData.bPin1LowHighState==true));
408
        }
409
    }
410
 
411
 
412
  if (Status == FTC_SUCCESS)
413
    return 0;
414
  else
415
    return 1;
416
 
417
}

powered by: WebSVN 2.1.0

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