@@ -77,20 +77,56 @@ impl From<u8> for TransferInfo {
7777 }
7878}
7979
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+ }
8198
8299/// JTAG interface configuraiton.
83100pub struct Config {
84101 /// The number of devices on the JTAG chain.
85102 pub device_count : u8 ,
86103 /// The position of the selected device.
87104 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+ }
94130}
95131
96132impl Config {
@@ -158,10 +194,10 @@ pub trait Jtag<DEPS>: From<DEPS> {
158194 const EXIT1_IR_TO_IDLE : & [ bool ] = & [ true , false ] ;
159195 self . tms_sequence ( IDLE_TO_SHIFT_IR ) ;
160196
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 ;
165201
166202 // Send the bypass bits before the IR.
167203 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
344380 ) ;
345381
346382 captured_dr >>= 1 ;
347- captured_dr |= ( captured_byte << 31 ) as u32 ;
383+ captured_dr |= ( captured_byte as u32 ) << 31 ;
348384
349385 if bypass_after > 0 {
350386 if bypass_after > 1 {
0 commit comments