@@ -77,20 +77,56 @@ impl From<u8> for TransferInfo {
77
77
}
78
78
}
79
79
80
- const MAX_CHAIN_LENGTH : usize = 16 ;
80
+ #[ derive( Debug , Default , Clone , Copy , PartialEq , Eq ) ]
81
+ pub struct TapConfig {
82
+ /// The number of bits in the IR register.
83
+ pub ir_length : u8 ,
84
+ /// The number of bypass bits before the IR register.
85
+ pub ir_before : u16 ,
86
+ /// The number of bypass bits after the IR register.
87
+ pub ir_after : u16 ,
88
+ }
89
+
90
+ impl TapConfig {
91
+ /// Empty value for array initialization
92
+ pub const INIT : Self = Self {
93
+ ir_length : 0 ,
94
+ ir_before : 0 ,
95
+ ir_after : 0 ,
96
+ } ;
97
+ }
81
98
82
99
/// JTAG interface configuraiton.
83
100
pub struct Config {
84
101
/// The number of devices on the JTAG chain.
85
102
pub device_count : u8 ,
86
103
/// The position of the selected device.
87
104
pub index : u8 ,
88
- /// The length of the IR register for each device.
89
- pub ir_length : [ u8 ; MAX_CHAIN_LENGTH ] ,
90
- /// The number of bypass bits before the IR register for each device.
91
- pub ir_before : [ u16 ; MAX_CHAIN_LENGTH ] ,
92
- /// The number of bypass bits after the IR register for each device.
93
- pub ir_after : [ u16 ; MAX_CHAIN_LENGTH ] ,
105
+ /// TAPs on the scan chain.
106
+ pub scan_chain : & ' static mut [ TapConfig ] ,
107
+ }
108
+
109
+ impl Config {
110
+ pub fn new ( chain_buffer : & ' static mut [ TapConfig ] ) -> Self {
111
+ Self {
112
+ device_count : 0 ,
113
+ index : 0 ,
114
+ scan_chain : chain_buffer,
115
+ }
116
+ }
117
+
118
+ /// Returns information about the currently selected TAP.
119
+ pub fn current_tap ( & self ) -> TapConfig {
120
+ self . scan_chain [ self . index as usize ]
121
+ }
122
+
123
+ pub ( crate ) fn update_device_count ( & mut self , count : u8 ) -> bool {
124
+ if count as usize >= self . scan_chain . len ( ) {
125
+ return false ;
126
+ }
127
+ self . device_count = count;
128
+ true
129
+ }
94
130
}
95
131
96
132
impl Config {
@@ -158,10 +194,10 @@ pub trait Jtag<DEPS>: From<DEPS> {
158
194
const EXIT1_IR_TO_IDLE : & [ bool ] = & [ true , false ] ;
159
195
self . tms_sequence ( IDLE_TO_SHIFT_IR ) ;
160
196
161
- let device_index = self . config ( ) . index as usize ;
162
- let ir_length = self . config ( ) . ir_length [ device_index ] ;
163
- let bypass_before = self . config ( ) . ir_before [ device_index ] ;
164
- let bypass_after = self . config ( ) . ir_after [ device_index ] ;
197
+ let tap = self . config ( ) . current_tap ( ) ;
198
+ let ir_length = tap . ir_length ;
199
+ let bypass_before = tap . ir_before ;
200
+ let bypass_after = tap . ir_after ;
165
201
166
202
// Send the bypass bits before the IR.
167
203
bypass_bits ( self , bypass_before, false ) ;
@@ -344,7 +380,7 @@ fn shift_dr<DEPS>(jtag: &mut impl Jtag<DEPS>, data: u32, bypass_after: u16) -> u
344
380
) ;
345
381
346
382
captured_dr >>= 1 ;
347
- captured_dr |= ( captured_byte << 31 ) as u32 ;
383
+ captured_dr |= ( captured_byte as u32 ) << 31 ;
348
384
349
385
if bypass_after > 0 {
350
386
if bypass_after > 1 {
0 commit comments