-
Notifications
You must be signed in to change notification settings - Fork 4
/
JtagTypes.cpp
219 lines (174 loc) · 6.71 KB
/
JtagTypes.cpp
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include <AnalyzerHelpers.h>
#include <algorithm>
#include "JtagTypes.h"
struct JtagTAPStateChange
{
JtagTAPState tms_low_change;
JtagTAPState tms_high_change;
};
// This maps each TAP state into it's next state depending on the TMS line
const JtagTAPStateChange tap_state_change_map[] = {
{ RunTestIdle, TestLogicReset }, // TestLogicReset
{ RunTestIdle, SelectDRScan }, // RunTestIdle
{ CaptureDR, SelectIRScan }, // SelectDRScan
{ ShiftDR, Exit1DR }, // CaptureDR
{ ShiftDR, Exit1DR }, // ShiftDR
{ PauseDR, UpdateDR }, // Exit1DR
{ PauseDR, Exit2DR }, // PauseDR
{ ShiftDR, UpdateDR }, // Exit2DR
{ RunTestIdle, SelectDRScan }, // UpdateDR
{ CaptureIR, TestLogicReset }, // SelectIRScan
{ ShiftIR, Exit1IR }, // CaptureIR
{ ShiftIR, Exit1IR }, // ShiftIR
{ PauseIR, UpdateIR }, // Exit1IR
{ PauseIR, Exit2IR }, // PauseIR
{ ShiftIR, UpdateIR }, // Exit2IR
{ RunTestIdle, SelectDRScan }, // UpdateIR
};
JtagTAP_Controller::JtagTAP_Controller() : mCurrTAPState( RunTestIdle )
{
}
bool JtagTAP_Controller::AdvanceState( BitState tms_state )
{
JtagTAPState new_state;
if( tms_state == BIT_HIGH )
new_state = tap_state_change_map[ mCurrTAPState ].tms_high_change;
else
new_state = tap_state_change_map[ mCurrTAPState ].tms_low_change;
bool ret_val = new_state != mCurrTAPState;
mCurrTAPState = new_state;
return ret_val;
}
std::string JtagShiftedData::GetDecimalString( const std::vector<U8>& bits )
{
std::string ret_val( "0" );
std::vector<U8>::const_iterator bi( bits.begin() );
int carry, digit;
while( bi != bits.end() )
{
carry = *bi ? 1 : 0;
// multiply ret_val by 2 and add the carry bit
std::string::reverse_iterator ai( ret_val.rbegin() );
while( ai != ret_val.rend() )
{
digit = ( *ai - '0' ) * 2 + carry;
*ai = ( digit % 10 ) + '0';
carry = digit / 10;
++ai;
}
if( carry > 0 )
ret_val = char( carry + '0' ) + ret_val;
++bi;
}
return ret_val;
}
std::string JtagShiftedData::GetASCIIString( const std::vector<U8>& bits )
{
std::string ret_val;
// Check if the value of the number represented by bits is less than 0x100.
// If it is, we can make an ASCII out of it, otherwise use GetDecimalString()
std::vector<U8>::const_iterator srch_hi( std::find( bits.begin(), bits.end(), BIT_HIGH ) );
if( bits.end() - srch_hi <= 8 )
{
// Get the numerical value from the bits.
U64 val;
// Only get the 8 least significant bits
std::vector<U8>::const_iterator bsi( bits.end() - 8 );
for( val = 0; bsi != bits.end(); ++bsi )
val = ( val << 1 ) | ( *bsi == BIT_HIGH ? 1 : 0 );
// make a string out of that value
char number_str[ 32 ];
AnalyzerHelpers::GetNumberString( val, ASCII, 8, number_str, sizeof( number_str ) );
ret_val = number_str;
}
else
{
ret_val = '\'' + GetDecimalString( bits ) + '\'';
}
return ret_val;
}
std::string JtagShiftedData::GetHexOrBinaryString( const std::vector<U8>& bits, DisplayBase display_base )
{
std::string ret_val;
std::vector<U8>::const_iterator bsi( bits.begin() );
U64 val;
size_t remain_bits = bits.size(), chunk_bits, bit_cnt;
char number_str[ 128 ];
while( bsi != bits.end() )
{
chunk_bits = remain_bits % 64;
if( chunk_bits == 0 )
chunk_bits = 64;
// make a 64 bit value
for( bit_cnt = chunk_bits, val = 0; bsi != bits.end() && bit_cnt > 0; ++bsi, --bit_cnt )
{
val = ( val << 1 ) | ( *bsi == BIT_HIGH ? 1 : 0 );
}
// make a string out of that value
AnalyzerHelpers::GetNumberString( val, display_base, ( U32 )chunk_bits, number_str, sizeof( number_str ) );
// concat the 64bit chunks but chop off all but the first 0x or 0b
if( ret_val.empty() )
ret_val = number_str;
else
ret_val += ( number_str + 2 );
remain_bits -= chunk_bits;
}
return ret_val;
}
std::string JtagShiftedData::GetStringFromBitStates( const std::vector<U8>& bits, DisplayBase display_base, TdiTdoStringFormat format )
{
if( format == TdiTdoStringFormat::Ellipsis64 && bits.size() > 64 )
{
std::vector<U8> subset( bits.end() - 64, bits.end() );
return GetStringFromBitStates( subset, display_base, format ) + "...";
}
if( format == TdiTdoStringFormat::Ellipsis256 && bits.size() > 256 )
{
std::vector<U8> subset( bits.end() - 256, bits.end() );
return GetStringFromBitStates( subset, display_base, format ) + "...";
}
if( ( format == TdiTdoStringFormat::Break64 && bits.size() > 64 ) || ( format == TdiTdoStringFormat::Break256 && bits.size() > 256 ) )
{
// lets break the result into N shorter strings of length range_size.
// data is transmitted LSB first, as a signle, huge word. lets write out the data with the lower word first.
S32 range_size = ( format == TdiTdoStringFormat::Break64 ) ? 64 : 256;
S32 range_end = bits.size();
std::string result = "";
while( range_end > 0 )
{
S32 range_start = std::max( range_end - range_size, 0 );
std::vector<U8> subset( bits.begin() + range_start, bits.begin() + range_end );
range_end -= range_size;
result += "[" + GetStringFromBitStates( subset, display_base, format ) + "]";
if( range_end > 0 )
result += ", ";
}
return result;
}
std::string ret_val;
if( bits.size() > 64 )
{
if( display_base == Hexadecimal || display_base == Binary )
ret_val = GetHexOrBinaryString( bits, display_base );
else if( display_base == Decimal )
ret_val = GetDecimalString( bits );
else if( display_base == ASCII )
ret_val = GetASCIIString( bits );
else if( display_base == AsciiHex )
ret_val = GetASCIIString( bits ) + " (" + GetHexOrBinaryString( bits, Hexadecimal ) + ')';
}
else
{
// get the numerical value from the bits
std::vector<U8>::const_iterator bsi( bits.begin() );
U64 val;
// make a 64 bit value
for( val = 0; bsi != bits.end(); ++bsi )
val = ( val << 1 ) | ( *bsi == BIT_HIGH ? 1 : 0 );
// make a string out of that value
char number_str[ 128 ];
AnalyzerHelpers::GetNumberString( val, display_base, ( U32 )bits.size(), number_str, sizeof( number_str ) );
ret_val = number_str;
}
return ret_val;
}