-
Notifications
You must be signed in to change notification settings - Fork 2
/
JTAG-Scan-Tool.c
105 lines (87 loc) · 3.56 KB
/
JTAG-Scan-Tool.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "JTAG-MPSSE-Blaster.h"
void* get_supported_hardware(int index);
unsigned char tdoData[8];
unsigned int tdoBitCount;
void StoreTDO(void* serverInstance, unsigned char* buffer, unsigned long size)
{
for (unsigned long i = 0; i < size; i++)
{
unsigned char actual = 1 & (buffer[i / 8] >> (i % 8));
tdoData[tdoBitCount / 8] |= actual << (tdoBitCount % 8);
tdoBitCount++;
}
}
int main(void)
{
JtagClientOperations const* clientOperations = (JtagClientOperations*)get_supported_hardware(0);
if (clientOperations)
{
JTAGServerOperations serverOperations = { 0 };
serverOperations.StoreTDO = StoreTDO;
char portName[64];
for (;;)
{
int portsFound = FALSE;
printf("Device:\t\t[%s]\n\n", clientOperations->Name);
for (int portNumber = 0; clientOperations->ScanPorts(portNumber, portName, 64); portNumber++)
{
JTAGClientData* clientData;
memset(tdoData, 0, sizeof(tdoData));
tdoBitCount = 0;
if (clientOperations->OpenHardware(&clientData, portName, &serverOperations, NULL) && clientData)
{
portsFound = TRUE;
clientOperations->ClockRaw(clientData, 1, 1, 12, 0);
clientOperations->ClockRaw(clientData, 0, 1, 1, 0);
clientOperations->ClockRaw(clientData, 1, 1, 1, 0);
clientOperations->ClockRaw(clientData, 0, 1, 10, 0);
clientOperations->ClockRaw(clientData, 0, 1, 1, 0);
clientOperations->ClockRaw(clientData, 0, 0, 6, 0);
clientOperations->ClockRaw(clientData, 0, 1, 2, 0);
clientOperations->ClockRaw(clientData, 0, 0, 2, 0);
clientOperations->ClockRaw(clientData, 0, 1, 2, 0);
clientOperations->ClockRaw(clientData, 0, 0, 1, 0);
clientOperations->ClockRaw(clientData, 0, 1, 7, 0);
clientOperations->ClockRaw(clientData, 0, 0, 2, 0);
clientOperations->Flush(clientData, TRUE, 0);
clientOperations->CloseHardware(clientData);
printf(" Port:\t\t\t[%s]\n", portName);
printf(" Raw TDO bits:\t\t");
for (unsigned int tdoBytePosition = 0; tdoBytePosition < tdoBitCount; tdoBytePosition++)
{
if (tdoBytePosition && !(tdoBytePosition % 8))
{
printf(" ");
}
printf("%d", (tdoData[tdoBytePosition / 8] >> (tdoBytePosition % 8)) & 1);
}
printf("\n Raw TDO bytes:\t");
for (unsigned int tdoBytePosition = 0; tdoBytePosition <= tdoBitCount / 8; tdoBytePosition++)
{
printf("%02X ", tdoData[tdoBytePosition]);
}
printf("\n JTAG IDCode:\t\t%08X\n\n", *(int*)(tdoData + 2));
}
else
{
printf(" Unable to open port [%s]\n", portName);
getchar();
}
}
if (!portsFound)
{
printf(" No ports available on the device\n");
}
getchar();
}
}
else
{
printf("No devices\n");
getchar();
}
return 0;
}