3 # This reset logic may be overridden by board/target/... scripts as needed
4 # to provide a reset that, if possible, is close to a power-up reset.
6 # Exit requirements include: (a) JTAG must be working, (b) the scan
7 # chain was validated with "jtag arp_init" (or equivalent), (c) nothing
8 # stays in reset. No TAP-specific scans were performed. It's OK if
9 # some targets haven't been reset yet; they may need TAP-specific scans.
11 # The "mode" values include: halt, init, run (from "reset" command);
12 # startup (at OpenOCD server startup, when JTAG may not yet work); and
13 # potentially more (for reset types like cold, warm, etc)
14 proc init_reset
{ mode
} {
19 global in_process_reset
20 set in_process_reset
0
22 # Catch reset recursion
23 proc ocd_process_reset
{ MODE
} {
24 global in_process_reset
25 if {$in_process_reset} {
26 set in_process_reset
0
27 return -code error "'reset' can not be invoked recursively"
30 set in_process_reset
1
31 set success [expr [catch {ocd_process_reset_inner
$MODE} result
]==0]
32 set in_process_reset
0
37 return -code error $result
41 proc ocd_process_reset_inner
{ MODE
} {
42 set targets
[target names
]
44 # If this target must be halted...
46 if { 0 == [string compare
$MODE halt
] } {
49 if { 0 == [string compare
$MODE init
] } {
52 if { 0 == [string compare
$MODE run
] } {
56 return -error "Invalid mode: $MODE, must be one of: halt, init, or run";
59 # Target event handlers *might* change which TAPs are enabled
60 # or disabled, so we fire all of them. But don't issue any
61 # target "arp_*" commands, which may issue JTAG transactions,
62 # unless we know the underlying TAP is active.
64 # NOTE: ARP == "Advanced Reset Process" ... "advanced" is
65 # relative to a previous restrictive scheme
69 $t invoke-event reset-start
72 # Use TRST or TMS/TCK operations to reset all the tap controllers.
73 # TAP reset events get reported; they might enable some taps.
76 # Examine all targets on enabled taps.
78 if {[jtag tapisenabled
[$t cget
-chain-position
]]} {
83 # Assert SRST, and report the pre/post events.
84 # Note: no target sees SRST before "pre" or after "post".
86 $t invoke-event reset-assert-pre
89 # C code needs to know if we expect to 'halt'
90 if {[jtag tapisenabled
[$t cget
-chain-position
]]} {
91 $t arp_reset assert
$halt
95 $t invoke-event reset-assert-post
98 # Now de-assert SRST, and report the pre/post events.
99 # Note: no target sees !SRST before "pre" or after "post".
101 $t invoke-event reset-deassert-pre
104 # Again, de-assert code needs to know if we 'halt'
105 if {[jtag tapisenabled
[$t cget
-chain-position
]]} {
106 $t arp_reset deassert
$halt
110 $t invoke-event reset-deassert-post
113 # Pass 1 - Now wait for any halt (requested as part of reset
114 # assert/deassert) to happen. Ideally it takes effect without
115 # first executing any instructions.
118 if {[jtag tapisenabled
[$t cget
-chain-position
]] == 0} {
122 # Wait upto 1 second for target to halt. Why 1sec? Cause
123 # the JTAG tap reset signal might be hooked to a slow
124 # resistor/capacitor circuit - and it might take a while
127 # Catch, but ignore any errors.
128 catch { $t arp_waitstate halted
1000 }
133 if { 0 != [string compare
$s "halted" ] } {
134 return -error [format "TARGET: %s - Not halted" $t]
139 #Pass 2 - if needed "init"
140 if { 0 == [string compare init
$MODE] } {
142 if {[jtag tapisenabled
[$t cget
-chain-position
]] == 0} {
146 set err
[catch "$t arp_waitstate halted 5000"]
149 $t invoke-event reset-init
155 $t invoke-event reset-end
161 # Temporary migration aid. May be removed starting in January 2011.
162 proc armv4_5 params
{
163 echo
"DEPRECATED! use 'arm $params' not 'armv4_5 $params'"