Skip to content

Instantly share code, notes, and snippets.

@mvduin
Created March 13, 2017 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvduin/92361f46efe0f27002f141f80e2024b2 to your computer and use it in GitHub Desktop.
Save mvduin/92361f46efe0f27002f141f80e2024b2 to your computer and use it in GitHub Desktop.
proc _icepick_ir { jrc ir valbits {regbits 0} } {
set ::$jrc.valbits $valbits
set ::$jrc.regbits $regbits
irscan $jrc $ir
}
proc icepick_ir_bypass { jrc } { _icepick_ir $jrc 0x3f 1 }
proc icepick_ir_idcode { jrc } { _icepick_ir $jrc 0x04 32 }
proc icepick_ir_ipcode { jrc } { _icepick_ir $jrc 0x05 32 }
proc icepick_ir_usrcode { jrc } { _icepick_ir $jrc 0x08 32 }
proc icepick_ir_connect { jrc } { _icepick_ir $jrc 0x07 4 3 }
# requires connect
proc icepick_ir_router { jrc } { _icepick_ir $jrc 0x02 24 7 }
proc icepick_ir_private { jrc } { _icepick_ir $jrc 0x1f 1 }
proc _unhex args {
set res [list]
foreach x $args {
lappend res [expr 0x$x]
}
return $res
}
proc _icepick_read { jrc {reg 0} } {
set regbits [set ::$jrc.regbits]
set valbits [set ::$jrc.valbits]
if { $regbits == 0 } {
set value [ drscan $jrc $valbits 0 -endstate DRPAUSE ]
set value [expr 0x$value]
drscan $jrc $valbits $value -endstate DRPAUSE
return $value
}
drscan $jrc $valbits 0 $regbits $reg 1 0
set res [ drscan $jrc $valbits 0 $regbits $reg 1 0 -endstate DRPAUSE ]
return [ _unhex {*}$res ]
}
proc _icepick_write { jrc value {reg 0} } {
set regbits [set ::$jrc.regbits]
set valbits [set ::$jrc.valbits]
if { $regbits == 0 } {
set res [ drscan $jrc $valbits $value ]
} else {
set res [ drscan $jrc $valbits $value $regbits $reg 1 1 ]
}
return [ _unhex {*}$res ]
}
proc icepick_connect_write { jrc value } {
icepick_ir_connect $jrc
set old [ _icepick_write $jrc $value ]
if { $old != [list $value 0 0] } {
if { [ _icepick_read $jrc ] != [list $value 0 0] } {
error "Unable to write ICEPick connect register"
} else {
echo "ICEPick connect [lindex $old 0] -> $value"
}
}
}
proc icepick_connect { jrc } { icepick_connect_write $jrc 9 }
proc icepick_disconnect { jrc } { icepick_connect_write $jrc 6 }
proc icepick_setup { jrc } {
icepick_connect $jrc
icepick_ir_router $jrc
_icepick_write $jrc 0x0210a0 0x01
_icepick_write $jrc 0x0759a0 0x02
}
proc icepick_coreenable { jrc core } {
icepick_setup $jrc
set reg [expr 0x60 | $core]
_icepick_write $jrc 0x002008 0x60
icepick_ir_bypass $jrc
runtest 10
}
# Configure the icepick control register
proc icepick_tapenable { jrc port } {
icepick_setup $jrc
set reg [expr 0x20 | $port]
_icepick_write $jrc 0x102048 $reg
_icepick_write $jrc 0x102148 $reg
icepick_ir_bypass $jrc
runtest 10
}
proc icepick_tapdisable { jrc port } {
icepick_ir_router $jrc
set reg [expr 0x20 | $port]
_icepick_write $jrc 0 $reg
icepick_ir_bypass $jrc
runtest 10
}
# This function uses the ICEPick to send a warm system reset
proc icepick_wreset {jrc} {
# send a router write, block is 0, register is 1, value is 0x2100
icepick_router $jrc 1 0x0 0x1 0x002101
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment