startup: Fixed measure_clk to return kHz instead of MHz.
[fw/openocd] / src / jtag / startup.tcl
1 # Defines basic Tcl procs for OpenOCD JTAG module
2
3 # Executed during "init". Can be overridden
4 # by board/target/... scripts
5 proc jtag_init {} {
6         if {[catch {jtag arp_init} err]!=0} {
7                 # try resetting additionally
8                 init_reset startup
9         }
10 }
11
12 # This reset logic may be overridden by board/target/... scripts as needed
13 # to provide a reset that, if possible, is close to a power-up reset.
14 #
15 # Exit requirements include:  (a) JTAG must be working, (b) the scan
16 # chain was validated with "jtag arp_init" (or equivalent), (c) nothing
17 # stays in reset.  No TAP-specific scans were performed.  It's OK if
18 # some targets haven't been reset yet; they may need TAP-specific scans.
19 #
20 # The "mode" values include:  halt, init, run (from "reset" command);
21 # startup (at OpenOCD server startup, when JTAG may not yet work); and
22 # potentially more (for reset types like cold, warm, etc)
23 proc init_reset { mode } {
24         if {[using_jtag]} {
25                 jtag arp_init-reset
26         }
27 }
28
29 #########
30
31 # TODO: power_restore and power_dropout are currently neither
32 # documented nor supported except on ZY1000.
33
34 proc power_restore {} {
35         echo "Sensed power restore, running reset init and halting GDB."
36         reset init
37         
38         # Halt GDB so user can deal with a detected power restore.
39         #
40         # After GDB is halted, then output is no longer forwarded
41         # to the GDB console.
42         set targets [target names]      
43         foreach t $targets {
44                 # New event script.
45                 $t invoke-event arp_halt_gdb
46         }       
47 }
48
49 add_help_text power_restore "Overridable procedure run when power restore is detected. Runs 'reset init' by default."
50
51 proc power_dropout {} {
52         echo "Sensed power dropout."
53 }
54
55 #########
56
57 # TODO: srst_deasserted and srst_asserted are currently neither
58 # documented nor supported except on ZY1000.
59
60 proc srst_deasserted {} {
61         echo "Sensed nSRST deasserted, running reset init and halting GDB."
62         reset init
63
64         # Halt GDB so user can deal with a detected reset.
65         #
66         # After GDB is halted, then output is no longer forwarded
67         # to the GDB console.
68         set targets [target names]      
69         foreach t $targets {
70                 # New event script.
71                 $t invoke-event arp_halt_gdb
72         }               
73 }
74
75 add_help_text srst_deasserted "Overridable procedure run when srst deassert is detected. Runs 'reset init' by default."
76
77 proc srst_asserted {} {
78         echo "Sensed nSRST asserted."
79 }
80
81 # measure actual JTAG clock
82 proc measure_clk {} {
83         set start_time [ms];
84         set iterations 10000000;
85         runtest $iterations;
86         echo "Running at more than [expr $iterations.0 / ([ms]-$start_time)] kHz";
87 }
88
89 add_help_text measure_clk "Runs a test to measure the JTAG clk. Useful with RCLK / RTCK."
90
91 proc default_to_jtag { f args } {
92         if [catch {transport select} current_transport] {
93                 echo "Info : session transport was not selected, defaulting to JTAG"
94                 transport select jtag
95                 eval $f $args
96         } {
97                 error "session transport is \"$current_transport\" but your config requires JTAG"
98         }
99 }
100
101 proc jtag args {
102         eval default_to_jtag jtag $args
103 }
104
105 proc jtag_rclk args {
106         eval default_to_jtag jtag_rclk $args
107 }
108
109 proc jtag_ntrst_delay args {
110         eval default_to_jtag jtag_ntrst_delay $args
111 }
112
113 proc jtag_ntrst_assert_width args {
114         eval default_to_jtag jtag_ntrst_assert_width $args
115 }
116
117 # BEGIN MIGRATION AIDS ...  these adapter operations originally had
118 # JTAG-specific names despite the fact that the operations were not
119 # specific to JTAG, or otherewise had troublesome/misleading names.
120 #
121 # FIXME phase these aids out after about April 2011
122 #
123 proc jtag_khz args {
124         echo "DEPRECATED! use 'adapter_khz' not 'jtag_khz'"
125         eval adapter_khz $args
126 }
127
128 proc jtag_nsrst_delay args {
129         echo "DEPRECATED! use 'adapter_nsrst_delay' not 'jtag_nsrst_delay'"
130         eval adapter_nsrst_delay $args
131 }
132
133 proc jtag_nsrst_assert_width args {
134         echo "DEPRECATED! use 'adapter_nsrst_assert_width' not 'jtag_nsrst_assert_width'"
135         eval adapter_nsrst_assert_width $args
136 }
137
138 # stlink migration helpers
139 proc stlink_device_desc args {
140         echo "DEPRECATED! use 'hla_device_desc' not 'stlink_device_desc'"
141         eval hla_device_desc $args
142 }
143
144 proc stlink_serial args {
145         echo "DEPRECATED! use 'hla_serial' not 'stlink_serial'"
146         eval hla_serial $args
147 }
148
149 proc stlink_layout args {
150         echo "DEPRECATED! use 'hla_layout' not 'stlink_layout'"
151         eval hla_layout $args
152 }
153
154 proc stlink_vid_pid args {
155         echo "DEPRECATED! use 'hla_vid_pid' not 'stlink_vid_pid'"
156         eval hla_vid_pid $args
157 }
158
159 proc stlink args {
160         echo "DEPRECATED! use 'hla' not 'stlink'"
161         eval hla $args
162 }
163
164 # END MIGRATION AIDS