You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

154 lines
3.7 KiB

  1. # Defines basic Tcl procs for OpenOCD target module
  2. proc new_target_name { } {
  3. return [target number [expr [target count] - 1 ]]
  4. }
  5. global in_process_reset
  6. set in_process_reset 0
  7. # Catch reset recursion
  8. proc ocd_process_reset { MODE } {
  9. global in_process_reset
  10. if {$in_process_reset} {
  11. set in_process_reset 0
  12. return -code error "'reset' can not be invoked recursively"
  13. }
  14. set in_process_reset 1
  15. set success [expr [catch {ocd_process_reset_inner $MODE} result]==0]
  16. set in_process_reset 0
  17. if {$success} {
  18. return $result
  19. } else {
  20. return -code error $result
  21. }
  22. }
  23. proc ocd_process_reset_inner { MODE } {
  24. set targets [target names]
  25. # If this target must be halted...
  26. set halt -1
  27. if { 0 == [string compare $MODE halt] } {
  28. set halt 1
  29. }
  30. if { 0 == [string compare $MODE init] } {
  31. set halt 1;
  32. }
  33. if { 0 == [string compare $MODE run ] } {
  34. set halt 0;
  35. }
  36. if { $halt < 0 } {
  37. return -error "Invalid mode: $MODE, must be one of: halt, init, or run";
  38. }
  39. # Target event handlers *might* change which TAPs are enabled
  40. # or disabled, so we fire all of them. But don't issue any
  41. # target "arp_*" commands, which may issue JTAG transactions,
  42. # unless we know the underlying TAP is active.
  43. #
  44. # NOTE: ARP == "Advanced Reset Process" ... "advanced" is
  45. # relative to a previous restrictive scheme
  46. foreach t $targets {
  47. # New event script.
  48. $t invoke-event reset-start
  49. }
  50. # Use TRST or TMS/TCK operations to reset all the tap controllers.
  51. # TAP reset events get reported; they might enable some taps.
  52. init_reset $MODE
  53. # Examine all targets on enabled taps.
  54. foreach t $targets {
  55. if {[jtag tapisenabled [$t cget -chain-position]]} {
  56. $t arp_examine
  57. }
  58. }
  59. # Assert SRST, and report the pre/post events.
  60. # Note: no target sees SRST before "pre" or after "post".
  61. foreach t $targets {
  62. $t invoke-event reset-assert-pre
  63. }
  64. foreach t $targets {
  65. # C code needs to know if we expect to 'halt'
  66. if {[jtag tapisenabled [$t cget -chain-position]]} {
  67. $t arp_reset assert $halt
  68. }
  69. }
  70. foreach t $targets {
  71. $t invoke-event reset-assert-post
  72. }
  73. # Now de-assert SRST, and report the pre/post events.
  74. # Note: no target sees !SRST before "pre" or after "post".
  75. foreach t $targets {
  76. $t invoke-event reset-deassert-pre
  77. }
  78. foreach t $targets {
  79. # Again, de-assert code needs to know if we 'halt'
  80. if {[jtag tapisenabled [$t cget -chain-position]]} {
  81. $t arp_reset deassert $halt
  82. }
  83. }
  84. foreach t $targets {
  85. $t invoke-event reset-deassert-post
  86. }
  87. # Pass 1 - Now wait for any halt (requested as part of reset
  88. # assert/deassert) to happen. Ideally it takes effect without
  89. # first executing any instructions.
  90. if { $halt } {
  91. foreach t $targets {
  92. if {[jtag tapisenabled [$t cget -chain-position]] == 0} {
  93. continue
  94. }
  95. # Wait upto 1 second for target to halt. Why 1sec? Cause
  96. # the JTAG tap reset signal might be hooked to a slow
  97. # resistor/capacitor circuit - and it might take a while
  98. # to charge
  99. # Catch, but ignore any errors.
  100. catch { $t arp_waitstate halted 1000 }
  101. # Did we succeed?
  102. set s [$t curstate]
  103. if { 0 != [string compare $s "halted" ] } {
  104. return -error [format "TARGET: %s - Not halted" $t]
  105. }
  106. }
  107. }
  108. #Pass 2 - if needed "init"
  109. if { 0 == [string compare init $MODE] } {
  110. foreach t $targets {
  111. if {[jtag tapisenabled [$t cget -chain-position]] == 0} {
  112. continue
  113. }
  114. set err [catch "$t arp_waitstate halted 5000"]
  115. # Did it halt?
  116. if { $err == 0 } {
  117. $t invoke-event reset-init
  118. }
  119. }
  120. }
  121. foreach t $targets {
  122. $t invoke-event reset-end
  123. }
  124. }
  125. #########
  126. # Temporary migration aid. May be removed starting in January 2011.
  127. proc armv4_5 params {
  128. echo "DEPRECATED! use 'arm $params' not 'armv4_5 $params'"
  129. arm $params
  130. }