summaryrefslogtreecommitdiff
path: root/lib/simulator/engine/engine_external_interface_management.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/simulator/engine/engine_external_interface_management.tcl')
-rw-r--r--[-rwxr-xr-x]lib/simulator/engine/engine_external_interface_management.tcl162
1 files changed, 114 insertions, 48 deletions
diff --git a/lib/simulator/engine/engine_external_interface_management.tcl b/lib/simulator/engine/engine_external_interface_management.tcl
index 30a5aed..5a1f220 100755..100644
--- a/lib/simulator/engine/engine_external_interface_management.tcl
+++ b/lib/simulator/engine/engine_external_interface_management.tcl
@@ -2,7 +2,7 @@
# Part of MCU 8051 IDE ( http://mcu8051ide.sf.net )
############################################################################
-# Copyright (C) 2007-2009 by Martin Ošmera #
+# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera #
# martin.osmera@gmail.com #
# #
# This program is free software; you can redistribute it and#or modify #
@@ -21,6 +21,11 @@
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
############################################################################
+# >>> File inclusion guard
+if { ! [ info exists _ENGINE_EXTERNAL_INTERFACE_MANAGEMENT_TCL ] } {
+set _ENGINE_EXTERNAL_INTERFACE_MANAGEMENT_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
# Part of simulator engine functionality.
@@ -29,20 +34,25 @@
# EXTERNAL INTERFACE MANAGEMENT PROCEDURES
# --------------------------------------------------------------------------
+## Get value of bit X2 in CLKREG/CKCON if available
+ # @return Bool - X2 value (if unavailable then 0)
+public method get_X2 {} {
+ return $controllers_conf(X2)
+}
-## Get value of bit SMOD0 in PCON if avaliable
- # @return Bool - SMOD0 value (if unavaliable then 0)
+## Get value of bit SMOD0 in PCON if available
+ # @return Bool - SMOD0 value (if unavailable then 0)
public method get_SMOD0 {} {
return $controllers_conf(SMOD0)
}
-## Set value of bit FE in SCON if avaliable
- # @param Bool value - New value for SCON.FE (or SCON.SM0 if FE is not avaliable)
+## Set value of bit FE in SCON if available
+ # @param Bool value - New value for SCON.FE (or SCON.SM0 if FE is not available)
# @return void
public method sim_engine_set_FE {value} {
- if {$feature_avaliable(smod0)} {
+ if {$feature_available(smod0)} {
set controllers_conf(FE) $value
- } {
+ } else {
sim_engine_set_SM0 $value
}
}
@@ -54,12 +64,12 @@ public method sim_engine_set_SM0 {value} {
set controllers_conf(SM0) $value
}
-## Get value of bit FE in SCON if avaliable
- # @return Bool - FE value (if unavaliable then {})
+## Get value of bit FE in SCON if available
+ # @return Bool - FE value (if unavailable then {})
public method sim_engine_get_FE {} {
- if {!$feature_avaliable(smod0)} {
+ if {!$feature_available(smod0)} {
return {}
- } {
+ } else {
return $controllers_conf(FE)
}
}
@@ -71,9 +81,14 @@ public method sim_engine_get_SM0 {} {
}
## Get program run statistics
- # @return List - Array run_statistics converted to list
-public method get_run_statistics {} {
- return [array get run_statistics]
+ # @parm Int idx = {} - Index to the array ``run_statistics'', empty string means entire array
+ # @return List/Int - Array run_statistics converted to list or Int
+public method get_run_statistics {{idx {}}} {
+ if {$idx == {}} {
+ return [array get run_statistics]
+ } else {
+ return $run_statistics($idx)
+ }
}
## Retrieve filename from list of files from which this program has been compiled
@@ -97,9 +112,9 @@ public method simulator_get_filenumber {filename} {
## Get maximum valid interrupt priority level
# @return Int - 0..3
public method simulator_get_max_intr_priority {} {
- if {$feature_avaliable(iph)} {
+ if {$feature_available(iph)} {
return 3
- } {
+ } else {
return 1
}
}
@@ -185,7 +200,7 @@ private method set_interrupt_priority_flag {flag level} {
}
# Adjust register IPH
- if {$feature_avaliable(iph)} {
+ if {$feature_available(iph)} {
if {${::Simulator::reverse_run_steps}} {
stepback_reg_change S $symbol(IPH)
}
@@ -194,7 +209,7 @@ private method set_interrupt_priority_flag {flag level} {
if {$level / 2} {
set sfr($symbol(IPH)) [expr $sfr($symbol(IPH)) | $bit_mask]
# Clear priority bit
- } {
+ } else {
set sfr($symbol(IPH)) [expr $sfr($symbol(IPH)) & ($bit_mask ^ 255)]
}
@@ -210,7 +225,7 @@ private method set_interrupt_priority_flag {flag level} {
if {$level % 2} {
set sfr($symbol(IP)) [expr $sfr($symbol(IP)) | $bit_mask]
# Clear priority bit
- } {
+ } else {
set sfr($symbol(IP)) [expr $sfr($symbol(IP)) & ($bit_mask ^ 255)]
}
# Adjust internal engine configuration
@@ -277,7 +292,10 @@ public method simulator_clear_intr_flag {flag} {
# Adjust internal engine configuration
evaluate_sfr $addr
- $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags]
+
+ if {$::GUI_AVAILABLE} {
+ $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags]
+ }
}
## Force return from certain interrupt
@@ -299,11 +317,13 @@ public method simulator_cancel_interrupt {flag} {
incr run_statistics(8)
$this subprograms_return 1
- if {[llength $interrupts_in_progress]} {
- set vector [format %X [intr2vector [lindex $interrupts_in_progress end]]]
- simulator_Sbar [mc "Interrupt at vector 0x%s " $vector] 1 $this
- } {
- simulator_Sbar {} 0 $this
+ if {$::GUI_AVAILABLE} {
+ if {[llength $interrupts_in_progress]} {
+ set vector [format %X [intr2vector [lindex $interrupts_in_progress end]]]
+ simulator_Sbar [mc "Interrupt at vector 0x%s " $vector] 1 $this
+ } else {
+ simulator_Sbar {} 0 $this
+ }
}
set pch [stack_pop]
@@ -348,10 +368,10 @@ public method simulator_get_interrupts_in_progress_pb {} {
# @return List - Something like {IE0 TF0 IE1 TF1 RI TI CF}
public method simulator_get_intr_flags {} {
set result {IE0 TF0 IE1 TF1}
- if {$feature_avaliable(uart)} {lappend result RI TI}
- if {$feature_avaliable(spi)} {lappend result SPIF}
- if {$feature_avaliable(t2)} {lappend result TF2 EXF2}
- if {$feature_avaliable(acomparator)} {lappend result CF}
+ if {$feature_available(uart)} {lappend result RI TI}
+ if {$feature_available(spi)} {lappend result SPIF}
+ if {$feature_available(t2)} {lappend result TF2 EXF2}
+ if {$feature_available(acomparator)} {lappend result CF}
return $result
}
@@ -384,13 +404,15 @@ public method simulator_cancel_write_to_eeprom {} {
public method simulator_finalize_write_to_eeprom {} {
if {!$eeprom_size || !$eeprom_WR} {return}
- # Clear background highlight in EEPROM hexeditor
+ # Clear background highlight in EEPROM hex editor
foreach reg $eeprom_prev {
::X::sync_eeprom_clear_bg_hg [lindex $reg 0] $this
}
# Adjust engine configuration
- $this simulator_GUI_cancel_write_to_eeprom
+ if {$::GUI_AVAILABLE} {
+ $this simulator_GUI_cancel_write_to_eeprom
+ }
set eeprom_WR 0
set eeprom_WR_time 0
set eeprom_WR_ofs {}
@@ -419,17 +441,47 @@ public method simulator_line2address {line file} {
set line [expr $line]
if {[llength [array names line2PC -exact "$line,$file"]]} {
return $line2PC($line,$file)
- } {
+ } else {
return {}
}
}
+## Determinate list of all unreachable breakpoints in the code
+ # @return List - { { file_number line_number } ... }
+public method simulator_getInvalidBreakpoints {} {
+ # Local variables
+ set ln 0 ;# Int: Line number
+ set fn 0 ;# Int: File number
+ set idx 0 ;# Index in list of breakpoints
+
+ set list_of_breakpoints [list]
+ foreach {f b} [array get breakpoints] {
+ foreach l $b {
+ lappend list_of_breakpoints [list $f $l]
+ }
+ }
+
+ foreach ln_fn [array names line2PC] {
+ scan $ln_fn {%d,%d} ln fn
+
+ set idx [lsearch -ascii -exact $list_of_breakpoints [list $fn $ln]]
+
+ if {$idx != -1} {
+ set list_of_breakpoints [lreplace $list_of_breakpoints $idx $idx]
+ }
+ }
+
+ set list_of_breakpoints [lsort -integer -index 0 $list_of_breakpoints]
+ set list_of_breakpoints [lsort -integer -index 1 $list_of_breakpoints]
+ return $list_of_breakpoints
+}
+
## Set watchdog timer value
# This procedure does nothing on MCUs without watchdog timer
# @parm Int value - new value (0..8192)
# @return void
public method simulator_setWatchDogTimer {value} {
- if {!$feature_avaliable(wtd)} {return}
+ if {!$feature_available(wtd)} {return}
set watchdog_value $value
}
@@ -463,7 +515,7 @@ public method simulator_setWatchDogPrescalerValue {value} {
# @parm Bool bool - 0 == STOP; 1 == START
# @return void
public method simulator_startStopWatchDogTimer {bool} {
- if {!$feature_avaliable(wtd)} {return}
+ if {!$feature_available(wtd)} {return}
set controllers_conf(WatchDogTimer) $bool
}
@@ -481,8 +533,10 @@ public method simulator_subprog_call {value} {
stack_push [expr {($value & 0xFF00) >> 8}]
incr run_statistics(6)
$this subprograms_call 3 $pc $value
- $this stack_monitor_set_last_values_as 1 2
- $this stopwatch_refresh
+ if {$::GUI_AVAILABLE} {
+ $this stack_monitor_set_last_values_as 1 2
+ $this stopwatch_refresh
+ }
set pc $value
}
@@ -511,7 +565,7 @@ public method simulator_get_line_number {} {
return [lindex $Line($pc) 0]
}
-## Translate adress in program memory to line info
+## Translate address in program memory to line info
# @parm Int addr - Address to translate
# @return List - Line information list
public method simulator_address2line {addr} {
@@ -567,7 +621,7 @@ public method setSfr {addr val} {
{150} { ;# EECON
if {$sfr(150) & 1} {
set controllers_conf(WRTINH) 1
- } {
+ } else {
set controllers_conf(WRTINH) 0
}
}
@@ -577,7 +631,7 @@ public method setSfr {addr val} {
evaluate_sfr $addr 0
set stepback_ena $foo
- # If adress points to Primary Accumulator (Acc) -> reevaluate PSW
+ # If address points to Primary Accumulator (Acc) -> reevaluate PSW
if {$addr == 224} {
$this Simulator_GUI_sync S 208
}
@@ -690,8 +744,10 @@ public method getData {addr} {
# @parm Int addr - register address
# @return String - register value (2 hexadecimal digits)
public method getSfr {addr} {
+
# Get hexadecimal value
set result [format "%X" $sfr($addr)]
+
# Adjust the value
if {[string length $result] == 1} {
set result "0$result"
@@ -861,7 +917,7 @@ public method load_program_from_adf {adf_file} {
-icon warning \
-type ok \
-title [mc "Out of memory"] \
- -message [mc "%s has not enought program memory to load this program. Simulator will work but the loaded code is incomplite" [$this cget -P_option_mcu_type]]
+ -message [mc "%s has not enough program memory to load this program. Simulator will work but the loaded code is incomplete" [$this cget -P_option_mcu_type]]
return 0
}
set Line($addr) [list $lineNum $fileNum 0 0] ;# Set line number
@@ -875,7 +931,7 @@ public method load_program_from_adf {adf_file} {
# @parm File filename - Full name of source file from which SIM file was generaded
# @parm File cdb_file - CDB file ID (content of *.cdb file)
# @parm File ihx_file - HEX file ID (content of *.ihx or *.hex file)
- # @return void
+ # @return Bool - 1 == Success; 0 == Failure
public method load_program_from_cdb {filename cdb_file ihx_file} {
unload_program ;# Clear current content of the program memory
@@ -1023,6 +1079,12 @@ public method setEngineClock {clockkHz} {
set clock_kHz $clockkHz
}
+## Get MCU clock frequency
+ # @return - clock frequency in kHz
+public method getEngineClock {} {
+ return $clock_kHz
+}
+
## Get program uptime as human readable string
# @return String - the time (eg. '2 s 42 ms 987 us')
public method getTime {} {
@@ -1031,7 +1093,7 @@ public method getTime {} {
set s 0
set ms 0
set ns 0
- } {
+ } else {
set s [expr {int($overall_time * (0.012 / $clock_kHz))}]
set ms [expr {int($overall_time * (12000.0 / $clock_kHz)) % 1000000}]
set ns [expr {int($overall_time * (12000000.0 / $clock_kHz)) % 1000}]
@@ -1050,7 +1112,7 @@ public method getTime {} {
set len [string length $ns]
if {$len < 3} {
set ns_s "[string repeat { } [expr {3 - $len}]]$ns"
- } {
+ } else {
set ns_s $ns
}
@@ -1058,7 +1120,7 @@ public method getTime {} {
set len [string length $us]
if {$len < 3} {
set us_s "[string repeat { } [expr {3 - $len}]]$us"
- } {
+ } else {
set us_s $us
}
@@ -1066,19 +1128,19 @@ public method getTime {} {
set len [string length $ms]
if {$len < 3} {
set ms_s "[string repeat { } [expr {3 - $len}]]$ms"
- } {
+ } else {
set ms_s $ms
}
# Adjust seconds and minutes strings
if {[string length $s] == 1} {
set s_s " $s"
- } {
+ } else {
set s_s $s
}
if {[string length $m] == 1} {
set m_s " $m"
- } {
+ } else {
set m_s $m
}
@@ -1103,7 +1165,7 @@ public method getTime {} {
}
# Append micro-seconds
if {$us > 0 || $result != {}} {
- append result " ${us_s}us"
+ append result " ${us_s}µs"
}
# Append nano-seconds
if {$ns > 0 || $result != {}} {
@@ -1113,3 +1175,7 @@ public method getTime {} {
# Done ...
return [string trim $result]
}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard