diff options
Diffstat (limited to 'lib/simulator/engine')
-rw-r--r--[-rwxr-xr-x] | lib/simulator/engine/engine_auxiliary_alo_functions.tcl | 23 | ||||
-rw-r--r--[-rwxr-xr-x] | lib/simulator/engine/engine_backward_stepping.tcl | 13 | ||||
-rw-r--r--[-rwxr-xr-x] | lib/simulator/engine/engine_control.tcl | 174 | ||||
-rw-r--r--[-rwxr-xr-x] | lib/simulator/engine/engine_core.tcl | 31 | ||||
-rw-r--r--[-rwxr-xr-x] | lib/simulator/engine/engine_external_interface_management.tcl | 162 | ||||
-rw-r--r--[-rwxr-xr-x] | lib/simulator/engine/engine_hibernation.tcl | 39 | ||||
-rw-r--r--[-rwxr-xr-x] | lib/simulator/engine/engine_initialization_cleanup.tcl | 57 | ||||
-rw-r--r--[-rwxr-xr-x] | lib/simulator/engine/engine_instructions.tcl | 184 | ||||
-rw-r--r--[-rwxr-xr-x] | lib/simulator/engine/engine_mcu_configuration.tcl | 107 | ||||
-rw-r--r--[-rwxr-xr-x] | lib/simulator/engine/engine_memory_management.tcl | 85 | ||||
-rw-r--r--[-rwxr-xr-x] | lib/simulator/engine/engine_opcodes.tcl | 11 | ||||
-rw-r--r-- | lib/simulator/engine/engine_text_based_interface.tcl | 1087 | ||||
-rw-r--r--[-rwxr-xr-x] | lib/simulator/engine/engine_virtual_hw_controller.tcl | 143 |
13 files changed, 1709 insertions, 407 deletions
diff --git a/lib/simulator/engine/engine_auxiliary_alo_functions.tcl b/lib/simulator/engine/engine_auxiliary_alo_functions.tcl index d73b57e..8929268 100755..100644 --- a/lib/simulator/engine/engine_auxiliary_alo_functions.tcl +++ b/lib/simulator/engine/engine_auxiliary_alo_functions.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_AUXILIARY_ALO_FUNCTIONS_TCL ] } { +set _ENGINE_AUXILIARY_ALO_FUNCTIONS_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -71,7 +76,7 @@ private method alo_add {val} { incr val_h incr result -16 setBit $symbol(AC) 1 - } { + } else { setBit $symbol(AC) 0 } @@ -82,7 +87,7 @@ private method alo_add {val} { if {$result > 255} { incr result -256 setBit $symbol(C) 1 - } { + } else { setBit $symbol(C) 0 } @@ -91,7 +96,7 @@ private method alo_add {val} { setBit $symbol(OV) 1 } elseif {($val > 127) && ($sfr(224) > 127) && ($result < 128)} { setBit $symbol(OV) 1 - } { + } else { setBit $symbol(OV) 0 } @@ -139,7 +144,7 @@ private method alo_subb {val} { incr result_l 16 incr val_h setBit $symbol(AC) 1 - } { + } else { setBit $symbol(AC) 0 } @@ -150,7 +155,7 @@ private method alo_subb {val} { if {$result_h < 0} { incr result_h 16 setBit $symbol(C) 1 - } { + } else { setBit $symbol(C) 0 } @@ -162,10 +167,14 @@ private method alo_subb {val} { setBit $symbol(OV) 1 } elseif {($val < 128) && ($sfr(224) > 127) && ($result < 128)} { setBit $symbol(OV) 1 - } { + } else { setBit $symbol(OV) 0 } # Set Acc set sfr(224) $result } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_backward_stepping.tcl b/lib/simulator/engine/engine_backward_stepping.tcl index f7e1b66..7914c9b 100755..100644 --- a/lib/simulator/engine/engine_backward_stepping.tcl +++ b/lib/simulator/engine/engine_backward_stepping.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_BACKWARD_STEPPING_TCL ] } { +set _ENGINE_BACKWARD_STEPPING_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -113,7 +118,7 @@ public method stepback_discard_stack {} { public method simulator_get_SBS_len {} { if {${::Simulator::reverse_run_steps}} { return $stepback_length - } { + } else { return 0 } } @@ -124,3 +129,7 @@ public method simulator_get_SBS_len {} { public method simulator_set_SBS_len {value} { set stepback_length $value } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_control.tcl b/lib/simulator/engine/engine_control.tcl index efa00c9..6b76b5a 100755..100644 --- a/lib/simulator/engine/engine_control.tcl +++ b/lib/simulator/engine/engine_control.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_CONTROL_TCL ] } { +set _ENGINE_CONTROL_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -36,7 +41,7 @@ public method simulator_return_from_SP {intr__sub} { if {$intr__sub} { simulator_cancel_interrupt [lindex $inter_in_p_flags end] - } { + } else { ins_ret $this move_simulator_line $Line($pc) } @@ -88,17 +93,17 @@ public method simulator_resize_code_memory {new_size} { ## Get list of decimal address of implemented SFR # @return List - Implemented special function registers -public method simulator_get_avaliable_sfr {} { - return $avaliable_sfr +public method simulator_get_available_sfr {} { + return $available_sfr } -## Determinate whether the specified SFR is avaliable on the target MCU or not +## Determinate whether the specified SFR is available on the target MCU or not # @parm Int sfr_addr - Address of SFR register - # @return Bool - 1 == Avaliable; 0 == Not avaliable -public method simulator_is_sfr_avaliable {sfr_addr} { - if {[lsearch -ascii -exact $avaliable_sfr $sfr_addr] == -1} { + # @return Bool - 1 == available; 0 == Not available +public method simulator_is_sfr_available {sfr_addr} { + if {[lsearch -ascii -exact $available_sfr $sfr_addr] == -1} { return 0 - } { + } else { return 1 } } @@ -146,8 +151,9 @@ public method master_reset {mode} { set wdt_prescaler_val 0 ;# Int: Value of Watchdog prescaler set watchdog_value 0 ;# Int: Value of watchdog timer set eeprom_WR 0 ;# Bool: Data EEPROM write cycle in progress - - simulator_Sbar {} 0 $this ;# Clear simulator status bar + if {$::GUI_AVAILABLE} { + simulator_Sbar {} 0 $this ;# Clear simulator status bar + } set interrupt_on_next 0 ;# Bool: Engage interrupt routine on the next instruction cycle set interrupts_in_progress {} ;# Priority flags of interrupts which are in progress set inter_in_p_flags {} ;# Interrupt flags of interrupts which are in progress @@ -208,44 +214,44 @@ public method master_reset {mode} { foreach item $reset_reg_values_1 { set reg [lindex $item 0] switch -- $reg { - {T2CON} {if {!$feature_avaliable(t2)} {continue}} - {RCAP2L} {if {!$feature_avaliable(t2)} {continue}} - {RCAP2H} {if {!$feature_avaliable(t2)} {continue}} - {TL2} {if {!$feature_avaliable(t2)} {continue}} - {TH2} {if {!$feature_avaliable(t2)} {continue}} - {T2MOD} {if {!$feature_avaliable(t2mod)} {continue}} - {AUXR} {if {!$feature_avaliable(auxr)} {continue}} - {SCON} {if {!$feature_avaliable(uart)} {continue}} - {P0} {if {!$feature_avaliable(p0)} {continue}} - {P1} {if {!$feature_avaliable(p1)} {continue}} - {P2} {if {!$feature_avaliable(p2)} {continue}} - {P3} {if {!$feature_avaliable(p3)} {continue}} - {P4} {if {!$feature_avaliable(p4)} {continue}} - {ACSR} {if {!$feature_avaliable(acomparator)} {continue}} - {SADEN} {if {!$feature_avaliable(euart)} {continue}} - {SADDR} {if {!$feature_avaliable(euart)} {continue}} - {IPH} {if {!$feature_avaliable(iph)} {continue}} - {WDTCON} {if {!$feature_avaliable(wdtcon)} {continue}} + {T2CON} {if {!$feature_available(t2)} {continue}} + {RCAP2L} {if {!$feature_available(t2)} {continue}} + {RCAP2H} {if {!$feature_available(t2)} {continue}} + {TL2} {if {!$feature_available(t2)} {continue}} + {TH2} {if {!$feature_available(t2)} {continue}} + {T2MOD} {if {!$feature_available(t2mod)} {continue}} + {AUXR} {if {!$feature_available(auxr)} {continue}} + {SCON} {if {!$feature_available(uart)} {continue}} + {P0} {if {!$feature_available(p0)} {continue}} + {P1} {if {!$feature_available(p1)} {continue}} + {P2} {if {!$feature_available(p2)} {continue}} + {P3} {if {!$feature_available(p3)} {continue}} + {P4} {if {!$feature_available(p4)} {continue}} + {ACSR} {if {!$feature_available(acomparator)} {continue}} + {SADEN} {if {!$feature_available(euart)} {continue}} + {SADDR} {if {!$feature_available(euart)} {continue}} + {IPH} {if {!$feature_available(iph)} {continue}} + {WDTCON} {if {!$feature_available(wdtcon)} {continue}} {EECON} {if {!$eeprom_size} {continue}} - {SPCR} {if {!$feature_avaliable(spi)} {continue}} - {SPSR} {if {!$feature_avaliable(spi)} {continue}} + {SPCR} {if {!$feature_available(spi)} {continue}} + {SPSR} {if {!$feature_available(spi)} {continue}} {DP1H} { - if {!$feature_avaliable(ddp) || $feature_avaliable(hddptr)} { + if {!$feature_available(ddp) || $feature_available(hddptr)} { continue } } {DP1L} { - if {!$feature_avaliable(ddp) || $feature_avaliable(hddptr)} { + if {!$feature_available(ddp) || $feature_available(hddptr)} { continue } } {CLKREG} { - if {!$feature_avaliable(clkreg) && !$feature_avaliable(ckcon)} { + if {!$feature_available(clkreg) && !$feature_available(ckcon)} { continue } } {AUXR1} { - if {!$feature_avaliable(ddp) || $feature_avaliable(wdtcon)} { + if {!$feature_available(ddp) || $feature_available(wdtcon)} { continue } } @@ -256,10 +262,10 @@ public method master_reset {mode} { } # Restore bits which are not affected by reset - if {$feature_avaliable(pof) && $controllers_conf(POF)} { + if {$feature_available(pof) && $controllers_conf(POF)} { set sfr($symbol(PCON)) [expr {$sfr($symbol(PCON)) | 16}] } - if {$feature_avaliable(x2reset) && $controllers_conf(X2)} { + if {$feature_available(x2reset) && $controllers_conf(X2)} { set sfr($symbol(CLKREG)) [expr {$sfr($symbol(CLKREG)) | 1}] } @@ -275,17 +281,19 @@ public method master_reset {mode} { } # Synchronize with special GUI controls - $this simulator_GUI_cancel_write_to_eeprom ;# Abort data EEPROM write cycle - $this interrupt_monitor_reset ;# Reset interrupt monitor - $this subprograms_clear ;# Clear list subprograms - $this stopwatch_refresh ;# Stopwatch - $this stack_monitor_reset ;# clear stack monitor + if {$::GUI_AVAILABLE} { + $this simulator_GUI_cancel_write_to_eeprom ;# Abort data EEPROM write cycle + $this interrupt_monitor_reset ;# Reset interrupt monitor + $this subprograms_clear ;# Clear list subprograms + $this stopwatch_refresh ;# Stopwatch + $this stack_monitor_reset ;# clear stack monitor + } # Reset PALE (Peripheral Astraction Layer Engine) $this pale_reset for {set i 0} {$i < 5} {incr i} { set j 0 - foreach bit [split $feature_avaliable(port$i) {}] { + foreach bit [split $feature_available(port$i) {}] { if {$bit == 0} { $this pale_SLSF [list $i $j] 6 } @@ -344,10 +352,10 @@ public method stepback {} { simulator_set_special [lindex $stepback_spec $stepback_length] set opcode [getCode $pc] - if {[lsearch ${CompilerConsts::defined_OPCODE} $opcode] == -1} { + if {[lsearch ${::CompilerConsts::defined_OPCODE} $opcode] == -1} { incr run_statistics(4) -1 - } { - incr run_statistics(4) -[lindex $CompilerConsts::Opcode($opcode) 2] + } else { + incr run_statistics(4) -[lindex $::CompilerConsts::Opcode($opcode) 2] } incr run_statistics(0) [expr {int(($overall_time - $overall_time_org) * (12000000.0 / $clock_kHz))}] @@ -394,14 +402,17 @@ public method stepback {} { $this stack_monitor_pop } } - if {[llength $interrupts_in_progress]} { - simulator_Sbar [mc "Interrupt at vector 0x%s " [format %X [intr2vector [lindex $interrupts_in_progress end]]]] 1 $this - } { - simulator_Sbar {} 0 $this + if {$::GUI_AVAILABLE} { + if {[llength $interrupts_in_progress]} { + simulator_Sbar [mc "Interrupt at vector 0x%s " [format %X [intr2vector [lindex $interrupts_in_progress end]]]] 1 $this + } else { + simulator_Sbar {} 0 $this + } + + $this graph_stepback [expr {int(($overall_time_org - $overall_time) * 2)}] + $this interrupt_monitor_reevaluate + $this stopwatch_refresh } - $this graph_stepback [expr {int(($overall_time_org - $overall_time) * 2)}] - $this interrupt_monitor_reevaluate - $this stopwatch_refresh if {$eeprom_size} { for {set i 0} {$i < 32} {incr i} { ::X::sync_eeprom_write_buffer $i $this @@ -411,11 +422,13 @@ public method stepback {} { if {$eeprom_WR} { eeprom_controller [expr {int(($overall_time_org - $overall_time) * (-2))}] - } { - foreach reg $eeprom_prev { - ::X::sync_eeprom_clear_bg_hg [lindex $reg 0] $this + } else { + if {$::GUI_AVAILABLE} { + foreach reg $eeprom_prev { + ::X::sync_eeprom_clear_bg_hg [lindex $reg 0] $this + } + $this simulator_GUI_cancel_write_to_eeprom } - $this simulator_GUI_cancel_write_to_eeprom } $this Simulator_sync_PC_etc @@ -426,7 +439,7 @@ public method stepback {} { $this Simulator_GUI_sync S 224 if {!$stepback_length} { return 0 - } { + } else { return 1 } } @@ -449,7 +462,7 @@ public method step {} { return $Line($pc) # Invalid OP code - } { + } else { bell $this sim_txt_output [mc "No instruction found at 0x%s" [NumSystem::dec2hex $pc]] incr_pc 1 @@ -469,7 +482,7 @@ public method sim_stepover {} { set stepover_in_progress 0 # Engage - } { + } else { # Local variables set current_line 0 ;# Current line in source code set stepover_in_progress 1 ;# Bool: "Step over" mode flag @@ -486,7 +499,7 @@ public method sim_stepover {} { if {$code($pc) != {}} { set sync_ena 1 ;# Enable synchronization - while 1 { + while {1} { # Conditionaly abort simulation if {$break} { set break 0 @@ -536,7 +549,7 @@ public method sim_stepover {} { return $Line($pc) # No OP code - } { + } else { incr_pc 1 bell $this sim_txt_output [mc "No instruction found at 0x%s" [NumSystem::dec2hex $pc]] @@ -562,7 +575,7 @@ public method sim_run {} { set run_in_progress 0 ;# Bool: "Run" mode flag # Engage - } { + } else { set sync_ena 0 ;# Disabled synchronizations # Local variables @@ -570,9 +583,10 @@ public method sim_run {} { set simulation_in_progress 1 ;# Bool: Simulator engaged set idx 0 ;# Instruction index (GUI is updated after each 1000) set ::X::critical_procedure_in_progress 0 + set time_ms [clock milliseconds] ;# Int: High res. system timer, used here for regular GUI updates # Infinitely execute program instructions until break - while 1 { + while {1} { incr idx # Conditionaly abort simulation if {$break} { @@ -600,15 +614,19 @@ public method sim_run {} { # Execute instruction instruction_cycle - # Run update command after each 25 instructions - if {!($idx % 25)} { - update - } - # Update GUI after each 100 instructions - if {$idx >= 100} { - set idx 0 - $this Simulator_sync_PC_etc - update + if {$::GUI_AVAILABLE} { + if {([clock milliseconds] - $time_ms) > $GUI_UPDATE_INT} { + set idx 0 + $this Simulator_sync_PC_etc + update + set time_ms [clock milliseconds] + } + } else { + # Stop after 1000 instructions + if {$idx >= 1000} { + set idx 0 + set break 1 + } } # Handle breakpoints @@ -648,13 +666,13 @@ public method sim_animate {} { set animation_in_progress 0 ;# Bool: "Animation" mode flag # Engage - } { + } else { set animation_in_progress 1 ;# Bool: "Animation" mode flag set simulation_in_progress 1 ;# Bool: Simulator engaged set ::X::critical_procedure_in_progress 0 # Infinitely execute program instructions until break - while 1 { + while {1} { # Conditionaly abort simulation if {$break} { set simulation_in_progress 0 @@ -748,8 +766,8 @@ public method Simulator_shutdown {} { # @return void public method Simulator_initiate {} { set sync_ena 1 - simulator_system_power_on master_reset - + simulator_system_power_on # Reset watchdog set watchdog_value 0 @@ -757,3 +775,7 @@ public method Simulator_initiate {} { set break 0 } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_core.tcl b/lib/simulator/engine/engine_core.tcl index e974656..0c78129 100755..100644 --- a/lib/simulator/engine/engine_core.tcl +++ b/lib/simulator/engine/engine_core.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_CORE_TCL ] } { +set _ENGINE_CORE_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Implements virtual 8051 processor. This class is a part 8051 simulator. @@ -54,9 +59,9 @@ class Simulator_ENGINE { ## COMMON common symbol ;# Array of SFR symbolic names (eg. $symbol(P0) == "80") - common DEBUG 1 ;# Turn on debugging common PIN ;# Array describing pins with some special function common PORT_LATCHES ;# List: Port latch registers + common GUI_UPDATE_INT 66;# Int: Time interval [ms] in which the GUI is regulary updated in the run mode # Default values for SFR (values to set after reset) common reset_reg_values { @@ -77,10 +82,10 @@ class Simulator_ENGINE { } ## PUBLIC - public variable programming_language 0 ;# Int: ID of used programing language (0 == Assembler; 1 == C language) + public variable programming_language 0 ;# Int: ID of used programming language (0 == Assembler; 1 == C language) ## PRIVATE - private variable breakpoints ;# Array of Lists of breakpoints (by line numbers) -- (eg '{1 45 399}') + private variable breakpoints ;# Array of Lists of breakpoints -- (eg '$breakpoints($file_number) == {1 45 399}') private variable ram ;# Array of internal RAM; addr: 0..255; val: 0..255 private variable eram ;# Array of expanded RAM; addr: 0..4096; val: 0..255 @@ -102,13 +107,13 @@ class Simulator_ENGINE { private variable Line ;# $Line($PC) == {line in source code} {filenumber} {level} {block} private variable list_of_filenames ;# List of filenames for [lindex $Line($pc) 1] - private variable line2PC ;# $line2PC($line) == PC + private variable line2PC ;# $line2PC($line_number,$file_number) == PC private variable bank 0 ;# Current register bank (0..3) private variable pc 0 ;# Program counter private variable clock_kHz 0 ;# MCU clock in kHz private variable time 0 ;# Number of instruction cycles consumed by current instruction private variable sync_ena 0 ;# Bool: Enabled synchronization with an external interface - private variable address_error 0 ;# Bool: Addressing error occured + private variable address_error 0 ;# Bool: Addressing error occurred private variable break 0 ;# Bool: Immediately terminate the loaded program private variable simulation_in_progress 0 ;# Bool: Engine is running @@ -118,19 +123,19 @@ class Simulator_ENGINE { private variable ports_previous_state {} ;# List: {P0_hex P1_hex P2_hex P3_hex P4_hex} private variable rmw_instruction 0 ;# Bool: This instruction is one of READ-MODIFY-WRITE ones - private variable avaliable_sfr {} ;# List: Addresses of implemented SFR - private variable feature_avaliable ;# Array: Avaliable features + private variable available_sfr {} ;# List: Addresses of implemented SFR + private variable feature_available ;# Array: available features private variable restricted_bits {} ;# List: Decimal addresses of unimplemented bits private variable write_only_regs {} ;# List: Decimal addresses of write only registers - private variable incomplite_regs {} ;# List: Decimal addresses of not fully implemented registers - private variable incomplite_regs_mask ;# Array: key == dec. addr.; val == mask of implemented bits + private variable incomplete_regs {} ;# List: Decimal addresses of not fully implemented registers + private variable incomplete_regs_mask ;# Array: key == dec. addr.; val == mask of implemented bits private variable DPL {DP0L} ;# Address of current DPL register (DTPR) private variable DPH {DP0H} ;# Address of current DPH register (DTPR) private variable hidden_DPTR0 {0 0} ;# Value of DPTR0 (if dual DPTR is hidden) private variable hidden_DPTR1 {0 0} ;# Value of DPTR1 (if dual DPTR is hidden) - private variable watchdog_value 0 ;# Int: Current value of watchdog timer (if avaliable) + private variable watchdog_value 0 ;# Int: Current value of watchdog timer (if available) private variable wdtrst_prev_val 0 ;# Int: Previous value of register WDTRST private variable wdt_prescaler_val 0 ;# Int: Watchdog prescaler value (content) @@ -272,3 +277,7 @@ class Simulator_ENGINE { # Initialize NS variables Simulator_ENGINE::InitializeNS + +# >>> File inclusion guard +} +# <<< File inclusion guard 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 diff --git a/lib/simulator/engine/engine_hibernation.tcl b/lib/simulator/engine/engine_hibernation.tcl index 24d3adf..d5a5faa 100755..100644 --- a/lib/simulator/engine/engine_hibernation.tcl +++ b/lib/simulator/engine/engine_hibernation.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_HIBERNATION_TCL ] } { +set _ENGINE_HIBERNATION_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -39,16 +44,16 @@ public method simulator_get_special {} { $timer_0_running $timer_1_running $overall_time \ $overall_instructions $inter_in_p_flags $timer1_overflow - if {$feature_avaliable(t2)} { + if {$feature_available(t2)} { lappend result $timer_2_running $timer2_overflow } - if {$feature_avaliable(wtd)} { + if {$feature_available(wtd)} { lappend result $watchdog_value $wdtrst_prev_val } - if {$feature_avaliable(wdtcon)} { + if {$feature_available(wdtcon)} { lappend result $wdt_prescaler_val $controllers_conf(WatchDogPrescaler) } - if {$feature_avaliable(pwm)} { + if {$feature_available(pwm)} { lappend result $pwm_running $pwm_OCR } if {$eeprom_size} { @@ -64,13 +69,13 @@ public method simulator_get_special {} { lappend result $eeprom_WR_buff($i) } } - if {$feature_avaliable(hddptr)} { + if {$feature_available(hddptr)} { lappend result $hidden_DPTR0 $hidden_DPTR1 } - if {$feature_avaliable(acomparator)} { + if {$feature_available(acomparator)} { lappend result $anlcmp_running $anlcmp_output $anlcpm_db_timer } - if {$feature_avaliable(uart)} { + if {$feature_available(uart)} { lappend result \ $uart_clock_prescaler \ $uart_RX_clock \ @@ -100,25 +105,25 @@ public method simulator_set_special {list} { incr i } - if {$feature_avaliable(t2)} { + if {$feature_available(t2)} { set timer_2_running [lindex $list $i] incr i set timer2_overflow [lindex $list $i] incr i } - if {$feature_avaliable(wtd)} { + if {$feature_available(wtd)} { set watchdog_value [lindex $list $i] incr i set wdtrst_prev_val [lindex $list $i] incr i } - if {$feature_avaliable(wdtcon)} { + if {$feature_available(wdtcon)} { set wdt_prescaler_val [lindex $list $i] incr i set controllers_conf(WatchDogPrescaler) [lindex $list $i] incr i } - if {$feature_avaliable(pwm)} { + if {$feature_available(pwm)} { set pwm_running [lindex $list $i] incr i set pwm_OCR [lindex $list $i] @@ -142,13 +147,13 @@ public method simulator_set_special {list} { set eeprom_WR_buff($j) [lindex $list $i] } } - if {$feature_avaliable(hddptr)} { + if {$feature_available(hddptr)} { set hidden_DPTR0 [lindex $list $i] incr i set hidden_DPTR1 [lindex $list $i] incr i } - if {$feature_avaliable(acomparator)} { + if {$feature_available(acomparator)} { set anlcmp_running [lindex $list $i] incr i set anlcmp_output [lindex $list $i] @@ -156,7 +161,7 @@ public method simulator_set_special {list} { set anlcpm_db_timer [lindex $list $i] incr i } - if {$feature_avaliable(uart)} { + if {$feature_available(uart)} { set uart_clock_prescaler [lindex $list $i] incr i set uart_RX_clock [lindex $list $i] @@ -203,3 +208,7 @@ public method simulator_hib_append_SB_spec {list} { public method simulator_hib_append_SB_norm {list} { lappend stepback_normal $list } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_initialization_cleanup.tcl b/lib/simulator/engine/engine_initialization_cleanup.tcl index e8a1ffa..8865dd2 100755..100644 --- a/lib/simulator/engine/engine_initialization_cleanup.tcl +++ b/lib/simulator/engine/engine_initialization_cleanup.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_INITIALIZATION_CLEANUP_TCL ] } { +set _ENGINE_INITIALIZATION_CLEANUP_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -52,7 +57,7 @@ destructor { # This function is called after each simulator start # @return void private method simulator_system_power_on {} { - if {$feature_avaliable(wtd)} { + if {$feature_available(wtd)} { set sfr($symbol(WDTRST)) [undefined_octet] set wdtrst_prev_val $sfr($symbol(WDTRST)) if {$sync_ena} { @@ -60,7 +65,7 @@ private method simulator_system_power_on {} { } } - if {$feature_avaliable(uart)} { + if {$feature_available(uart)} { set sfr($symbol(SBUFR)) [undefined_octet] set sfr($symbol(SBUFT)) [undefined_octet] set controllers_conf(UART_M) 0 @@ -70,7 +75,7 @@ private method simulator_system_power_on {} { } } - if {$feature_avaliable(pof)} { + if {$feature_available(pof)} { set controllers_conf(POF) 1 set sfr($symbol(PCON)) 16 if {$sync_ena} { @@ -78,7 +83,7 @@ private method simulator_system_power_on {} { } } - if {$feature_avaliable(spi)} { + if {$feature_available(spi)} { set sfr($symbol(SPDR)) 0 if {$sync_ena} { catch {$this Simulator_GUI_sync S $symbol(SPDR)} @@ -103,7 +108,7 @@ public method simulator_initialize_mcu {} { + [$this cget -P_option_mcu_xcode])}] - # Parse processor definition and set array feature_avaliable + # Parse processor definition and set array feature_available foreach index { 5 6 7 9 10 11 17 20 21 22 23 24 25 26 @@ -118,24 +123,24 @@ public method simulator_initialize_mcu {} { auxrwdidle auxrdisrto xram xcode } { if {[lindex $proc_data $index] == {yes}} { - set feature_avaliable($name) 1 - } { - set feature_avaliable($name) 0 + set feature_available($name) 1 + } else { + set feature_available($name) 0 } } for {set i 12; set j 0} {$i < 17} {incr i; incr j} { set port_mask [lindex $proc_data $i] if {$port_mask != {} && $port_mask != {00000000}} { - set feature_avaliable(p$j) 1 - set feature_avaliable(port$j) $port_mask - } { - set feature_avaliable(p$j) 0 - set feature_avaliable(port$j) {00000000} + set feature_available(p$j) 1 + set feature_available(port$j) $port_mask + } else { + set feature_available(p$j) 0 + set feature_available(port$j) {00000000} } } - # Set incomplite_regs_mask, restricted_bits and incomplite_regs - array unset incomplite_regs_mask + # Set incomplete_regs_mask, restricted_bits and incomplete_regs + array unset incomplete_regs_mask set restricted_bits {} foreach reg_mask [lindex $proc_data 18] { set addr [string range $reg_mask 0 1] @@ -143,7 +148,7 @@ public method simulator_initialize_mcu {} { set addr [expr "0x$addr"] set mask [expr "0x$mask"] - set incomplite_regs_mask($addr) $mask + set incomplete_regs_mask($addr) $mask if {$addr > 127 && !($addr % 8)} { for {set i 1} {$i <= 128} {set i [expr {$i * 2}]; incr addr} { @@ -153,7 +158,7 @@ public method simulator_initialize_mcu {} { } } } - set incomplite_regs [array names incomplite_regs_mask] + set incomplete_regs [array names incomplete_regs_mask] # Determiate list of write-only registers set write_only_regs {} @@ -186,7 +191,7 @@ public method simulator_initialize_mcu {} { # Power on virtual uC and derminate list of implemented SFR simulator_system_power_on master_reset 0 - set avaliable_sfr [array names sfr] + set available_sfr [array names sfr] # Initialize/Clear code memory and data EEPROM simulator_clear_memory code @@ -312,18 +317,18 @@ proc InitializeNS {} { set PORT_LATCHES [list $symbol(P0) $symbol(P1) $symbol(P2) $symbol(P3) $symbol(P4)] } -## Shutdown simulator engine +## Stop simulator engine # @return void private method internal_shutdown {} { set break 1 $this Simulator_sync_clock } -## Determinate if the specified feature is avaliable on this MCU +## Determinate if the specified feature is available on this MCU # @parm String key - feature name (e.g. 'p0') # @return Bool - result (1 == yes; 0 == no) -public method get_feature_avaliable {key} { - return $feature_avaliable($key) +public method get_feature_available {key} { + return $feature_available($key) } ## Get number of implemented ports and list of port indexes @@ -331,10 +336,14 @@ public method get_feature_avaliable {key} { public method get_ports_info {} { set sum 0 for {set i 0} {$i < 5} {incr i} { - if {$feature_avaliable(p$i)} { + if {$feature_available(p$i)} { incr sum lappend lst $i } } return [list $sum $lst] } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_instructions.tcl b/lib/simulator/engine/engine_instructions.tcl index d732414..19c45af 100755..100644 --- a/lib/simulator/engine/engine_instructions.tcl +++ b/lib/simulator/engine/engine_instructions.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_INSTRUCTIONS_TCL ] } { +set _ENGINE_INSTRUCTIONS_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -41,7 +46,7 @@ private method ins_acall {haddr laddr} { stack_push [expr {($pc & 255)}] stack_push [expr {($pc & 0xFF00) >> 8}] - incr laddr [expr {$haddr << 8}] + incr laddr [expr {($haddr << 8) | $pc & 0x0f800}] incr run_statistics(6) $this subprograms_call 1 $pc $laddr $this stack_monitor_set_last_values_as 1 2 @@ -70,7 +75,7 @@ private method ins_add_D {addr} { } if {$addr < 128} { ins_add $ram($addr) - } { + } else { ins_add [read_sfr $addr] } } @@ -83,7 +88,7 @@ private method ins_add_ID {addr} { incr_pc 1 if {[check_address_validity I $addr]} { alo_add [undefined_octet] - } { + } else { alo_add $ram($addr) } evaluate_sfr 224 @@ -111,7 +116,7 @@ private method ins_addc_D {addr} { } if {$addr < 128} { ins_addc $ram($addr) - } { + } else { ins_addc [read_sfr $addr] } } @@ -125,7 +130,7 @@ private method ins_addc_ID {addr} { if {[check_address_validity I $addr]} { alo_addc [undefined_octet] return - } { + } else { alo_addc $ram($addr) } } @@ -136,7 +141,7 @@ private method ins_addc_ID {addr} { # @return void private method ins_ajmp {haddr laddr} { set time 2 - incr laddr [expr {$haddr << 8}] + incr laddr [expr {($haddr << 8) | $pc & 0x0f800}] set pc $laddr } @@ -155,7 +160,7 @@ private method ins_anl {addr val} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { set rmw_instruction 1 write_sfr $addr [expr {[read_sfr $addr] & $val}] evaluate_sfr $addr @@ -185,7 +190,7 @@ private method ins_anl_A_D {addr} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { ins_anl_A [read_sfr $addr] evaluate_sfr $addr } @@ -222,7 +227,7 @@ private method ins_anl_C_N {addr} { set time 2 if {[check_address_validity B $addr]} { setBit $symbol(C) [expr {rand() > 0.5}] - } { + } else { if {[getBit $addr]} {setBit $symbol(C) 0} } evaluate_bit $symbol(C) @@ -235,10 +240,10 @@ private method ins_anl_C_N {addr} { private method ins_cjne_AD {addr roff} { if {[check_address_validity D $addr]} { set val [undefined_octet] - } { + } else { if {$addr < 128} { set val $ram($addr) - } { + } else { set val $sfr($addr) } } @@ -254,15 +259,14 @@ private method ins_cjne {val0 val1 roff} { set time 2 if {$val0 != $val1} { - if {$val0 < $val1} { - setBit $symbol(C) 1 - } { - setBit $symbol(C) 0 - } - if {$roff > 127} {incr roff -256} incr_pc $roff } + if {$val0 < $val1} { + setBit $symbol(C) 1 + } else { + setBit $symbol(C) 0 + } } ## Instruction: CJNE @Ri, ... @@ -275,19 +279,18 @@ private method ins_cjne_ID {addr val1 roff} { if {[check_address_validity I $addr]} { set val0 [undefined_octet] - } { + } else { set val0 $ram($addr) } if {$val0 != $val1} { - if {$val0 < $val1} { - setBit $symbol(C) 1 - } { - setBit $symbol(C) 0 - } - if {$roff > 127} {incr roff -256} incr_pc $roff } + if {$val0 < $val1} { + setBit $symbol(C) 1 + } else { + setBit $symbol(C) 0 + } } ## Instruction: CLR @@ -309,7 +312,7 @@ private method ins_clr {opr} { setBit $symbol(C) 0 evaluate_bit $symbol(C) # Some bit - } { + } else { if {[check_address_validity B $opr]} {return} set rmw_instruction 1 setBit $opr 0 @@ -335,17 +338,17 @@ private method ins_cpl {opr} { } elseif {$opr == {C}} { if {[getBit $symbol(C)]} { setBit $symbol(C) 0 - } { + } else { setBit $symbol(C) 1 } evaluate_bit $symbol(C) # Some bit - } { + } else { if {[check_address_validity B $opr]} {return} set rmw_instruction 1 if {[getBit $opr]} { setBit $opr 0 - } { + } else { setBit $opr 1 } evaluate_bit $opr @@ -423,7 +426,7 @@ private method ins_div {} { setBit $symbol(OV) 1 set sfr(224) 0 set sfr($symbol(B)) 0 - } { + } else { setBit $symbol(OV) 0 set A $sfr(224) set sfr(224) [expr {$A / $sfr($symbol(B))}] @@ -449,7 +452,7 @@ private method ins_djnz {addr roff} { incr_pc $roff } evaluate_sfr $addr - } { + } else { if {$ram($addr) != 0} { if {$roff > 127} {incr roff -256} incr_pc $roff @@ -517,7 +520,7 @@ private method ins_jb {addr roff} { set time 2 if {[check_address_validity B $addr]} { set val [expr {rand() > 0.5}] - } { + } else { set val [getBit $addr] } if {$val} { @@ -534,7 +537,7 @@ private method ins_jnb {addr roff} { set time 2 if {[check_address_validity B $addr]} { set val [expr {rand() > 0.5}] - } { + } else { set val [getBit $addr] } if {!$val} { @@ -552,7 +555,7 @@ private method ins_jbc {addr roff} { set time 2 if {[check_address_validity B $addr]} { set val [expr {rand() > 0.5}] - } { + } else { set val [getBit $addr] } if {$val} { @@ -653,7 +656,7 @@ private method ins_mov {addr val} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { write_sfr $addr $val evaluate_sfr $addr } @@ -670,7 +673,7 @@ private method ins_mov_D {addr1 addr0} { if {[check_address_validity D $addr0]} {return} if {[check_address_validity D $addr1]} { set val [undefined_octet] - } { + } else { if {$addr1 < 128} { set val $ram($addr1) } { @@ -686,7 +689,7 @@ private method ins_mov_D {addr1 addr0} { if {$sync_ena} { $this Simulator_sync_reg $addr0 } - } { + } else { write_sfr $addr0 $val evaluate_sfr $addr0 } @@ -699,10 +702,10 @@ private method ins_mov_D {addr1 addr0} { private method ins_mov_ID2 {addr0 addr1} { if {[check_address_validity D $addr1]} { ins_mov_ID0 $addr0 [undefined_octet] - } { + } else { if {$addr1 < 128} { ins_mov_ID0 $addr0 $ram($addr1) - } { + } else { ins_mov_ID0 $addr0 [read_sfr $addr1] } } @@ -720,7 +723,7 @@ private method ins_mov_ID1 {addr addr_id} { if {[check_address_validity D $addr]} {return} if {[check_address_validity I $addr_id]} { set val [undefined_octet] - } { + } else { set val $ram($addr_id) } if {$addr < 128} { @@ -731,7 +734,7 @@ private method ins_mov_ID1 {addr addr_id} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { write_sfr $addr $val evaluate_sfr $addr } @@ -788,7 +791,7 @@ private method ins_mov_Rx_ADDR {idx addr} { } if {$addr < 128} { set ram($t_addr) $ram($addr) - } { + } else { set ram($t_addr) [read_sfr $addr] } @@ -806,21 +809,21 @@ private method ins_mov_bit {dest source} { if {$dest == {C}} { if {[check_address_validity B $source]} { set val [expr {rand() < 0.5}] - } { + } else { set val [getBit $source] } if {$val} { setBit $symbol(C) 1 - } { + } else { setBit $symbol(C) 0 } - } { + } else { set rmw_instruction 1 incr time if {[check_address_validity B $dest]} {return} if {[getBit $symbol(C)]} { setBit $dest 1 - } { + } else { setBit $dest 0 } } @@ -837,7 +840,7 @@ private method ins_movc {arg} { if {$arg == {DPTR}} { set addr [expr {($sfr(224) + $sfr($symbol($DPL))) + ($sfr($symbol($DPH)) << 8)}] # MOVC A, @A+PC - } { + } else { set addr $pc incr addr $sfr(224) } @@ -853,7 +856,7 @@ private method ins_movc {arg} { set sfr(224) [undefined_octet] } elseif {$code($addr) != {}} { set sfr(224) $code($addr) - } { + } else { set sfr(224) [undefined_octet] } @@ -885,14 +888,14 @@ private method ins_movx {opr0 opr1} { if {$Saddr < $eram_size && !$controllers_conf(EXTRAM)} { if {[check_address_validity E $Saddr]} { set sfr(224) [undefined_octet] - } { + } else { set sfr(224) $eram($Saddr) } # Read from data EEPROM } elseif {$Saddr < $eeprom_size && $controllers_conf(EEMEN)} { if {[check_address_validity P $Saddr]} { set sfr(224) [undefined_octet] - } { + } else { set complement_MSB 0 foreach reg $eeprom_prev { if {$Saddr == [lindex $reg 0]} { @@ -902,13 +905,13 @@ private method ins_movx {opr0 opr1} { } if {$complement_MSB} { set sfr(224) [expr {$eeprom($Saddr) ^ 0x80}] - } { + } else { set sfr(224) $eeprom($Saddr) } } # Read from external data memory } else { - if {$feature_avaliable(xram) && [$this pale_is_enabled]} { + if {$feature_available(xram) && [$this pale_is_enabled]} { for {set i -3} {$i < 0} {incr i} { if {!$controllers_conf(X2)} { $this pale_WPBBL $PIN(RD) {X} $i @@ -918,7 +921,7 @@ private method ins_movx {opr0 opr1} { $this pale_WPBBL $PIN(RD) {X} $i $this pale_WPBL 0 X $i $this pale_WPBL 2 X $i - } { + } else { incr i $this pale_WPBL 0 X [expr {int($i / 2)}] $this pale_WPBL 2 X [expr {int($i / 2)}] @@ -928,7 +931,7 @@ private method ins_movx {opr0 opr1} { } if {[check_address_validity X $Saddr]} { set sfr(224) [undefined_octet] - } { + } else { set sfr(224) $xram($Saddr) } } @@ -978,7 +981,7 @@ private method ins_movx {opr0 opr1} { set eeprom_WR_ofs "0x$offset" ::X::eeprom_write_buffer_set_offset $eeprom_WR_ofs $this - # Start EEPROM programing cycle + # Start EEPROM programming cycle if {!$controllers_conf(EELD)} { # Write data to data EEPROM set eeprom_prev {} @@ -993,7 +996,7 @@ private method ins_movx {opr0 opr1} { set eeprom_WR_buff($i) {} } - # Clear write buffer hexeditor + # Clear write buffer hex editor ::X::eeprom_write_buffer_set_offset {} $this ::X::clear_eeprom_write_buffer $this @@ -1017,7 +1020,7 @@ private method ins_movx {opr0 opr1} { # Write to external data memory } else { - if {$feature_avaliable(xram) && [$this pale_is_enabled]} { + if {$feature_available(xram) && [$this pale_is_enabled]} { for {set i -3} {$i < 0} {incr i} { if {!$controllers_conf(X2)} { $this pale_WPBBL $PIN(WR) {X} $i @@ -1027,7 +1030,7 @@ private method ins_movx {opr0 opr1} { $this pale_WPBBL $PIN(WR) {X} $i $this pale_WPBL 0 X $i $this pale_WPBL 2 X $i - } { + } else { incr i $this pale_WPBL 0 X [expr {int($i / 2)}] $this pale_WPBL 2 X [expr {int($i / 2)}] @@ -1037,6 +1040,7 @@ private method ins_movx {opr0 opr1} { } if {[check_address_validity X $Daddr]} {return} + stepback_reg_change X $Daddr set xram($Daddr) $sfr(224) } @@ -1062,7 +1066,7 @@ private method ins_mul {} { if {$result > 255} { set sfr(240) [expr {($result & 0xFF00) >> 8}] setBit $symbol(OV) 1 - } { + } else { set sfr(240) 0 setBit $symbol(OV) 0 } @@ -1096,7 +1100,7 @@ private method ins_orl {addr val} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { set rmw_instruction 1 write_sfr $addr [expr {[read_sfr $addr] | $val}] evaluate_sfr $addr @@ -1113,7 +1117,7 @@ private method ins_orl_D {addr0 addr1} { ins_orl $addr0 [undefined_octet] } elseif {$addr1 < 128} { ins_orl $addr0 $ram($addr1) - } { + } else { ins_orl $addr0 [read_sfr $addr1] } } @@ -1129,7 +1133,7 @@ private method ins_orl_ID {addr addr_id} { if {[check_address_validity D $addr]} {return} if {[check_address_validity I $addr_id]} { set val [undefined_octet] - } { + } else { set val $ram($addr_id) } if {$addr < 128} { @@ -1140,7 +1144,7 @@ private method ins_orl_ID {addr addr_id} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { set rmw_instruction 1 write_sfr $addr [expr {[read_sfr $addr] | $val}] evaluate_sfr $addr @@ -1157,7 +1161,7 @@ private method ins_orl_not_bit {addr} { setBit $symbol(C) [expr {rand() < 0.5}] } elseif {[getBit $symbol(C)] || ![getBit $addr]} { setBit $symbol(C) 1 - } { + } else { setBit $symbol(C) 0 } } @@ -1172,7 +1176,7 @@ private method ins_orl_bit {addr} { setBit $symbol(C) [expr {rand() < 0.5}] } elseif {[getBit $symbol(C)] || [getBit $addr]} { setBit $symbol(C) 1 - } { + } else { setBit $symbol(C) 0 } } @@ -1193,7 +1197,7 @@ private method ins_pop {addr} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { write_sfr $addr [stack_pop] evaluate_sfr $addr } @@ -1243,13 +1247,15 @@ private method ins_reti {} { $this interrupt_monitor_reti [lindex $inter_in_p_flags end] set interrupts_in_progress [lreplace $interrupts_in_progress end end] set inter_in_p_flags [lreplace $inter_in_p_flags end end] - 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 + } } - } { + } else { $this simulator_invalid_reti_dlg $pc $Line($pc) } @@ -1295,7 +1301,7 @@ private method ins_rlc {} { if {$sfr(224) > 255} { incr sfr(224) -256 setBit $symbol(C) 1 - } { + } else { setBit $symbol(C) 0 } @@ -1313,7 +1319,7 @@ private method ins_rr {} { } if {[expr {$sfr(224) % 2}]} { set C 1 - } { + } else { set C 0 } @@ -1335,7 +1341,7 @@ private method ins_rrc {} { } if {[expr {$sfr(224) % 2}]} { set C 1 - } { + } else { set C 0 } @@ -1347,7 +1353,7 @@ private method ins_rrc {} { if {$C} { setBit $symbol(C) 1 - } { + } else { setBit $symbol(C) 0 } @@ -1363,7 +1369,7 @@ private method ins_setb {opr} { if {$opr == {C}} { setBit $symbol(C) 1 - } { + } else { if {[check_address_validity B $opr]} {return} set rmw_instruction 1 setBit $opr 1 @@ -1399,7 +1405,7 @@ private method ins_subb_D {addr} { ins_subb [undefined_octet] } elseif {$addr < 128} { ins_subb $ram($addr) - } { + } else { ins_subb $sfr($addr) } } @@ -1412,7 +1418,7 @@ private method ins_subb_ID {addr} { incr_pc 1 if {[check_address_validity I $addr]} { ins_subb [undefined_octet] - } { + } else { alo_subb $ram($addr) } evaluate_sfr 224 @@ -1457,7 +1463,7 @@ private method ins_xch {addr} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { set sfr(224) [read_sfr $addr] write_sfr $addr $A evaluate_sfr $addr @@ -1499,14 +1505,14 @@ private method ins_xchd {addr} { set val [undefined_octet] } elseif {$addr < 128} { set val $ram($addr) - } { + } else { set val $sfr($addr) } if {${::Simulator::reverse_run_steps}} { stepback_reg_change S 224 if {$addr < 128} { stepback_reg_change I $addr - } { + } else { stepback_reg_change S $addr } } @@ -1518,7 +1524,7 @@ private method ins_xchd {addr} { set val [expr {($val & 240) + $nibble0}] if {$addr < 128} { set ram($addr) $val - } { + } else { set sfr($addr) $val } @@ -1545,7 +1551,7 @@ private method ins_xrl {addr val} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { set rmw_instruction 1 write_sfr $addr [expr {[read_sfr $addr] ^ $val}] evaluate_sfr $addr @@ -1561,7 +1567,7 @@ private method ins_xrl_D {addr0 addr1} { ins_xrl $addr0 [undefined_octet] } elseif {$addr1 < 128} { ins_xrl $addr0 $ram($addr1) - } { + } else { ins_xrl $addr0 [read_sfr $addr1] } } @@ -1577,7 +1583,7 @@ private method ins_xrl_ID {addr addr_id} { if {[check_address_validity I $addr_id]} { set val [undefined_octet] - } { + } else { set val $ram($addr_id) } if {$addr < 128} { @@ -1588,9 +1594,13 @@ private method ins_xrl_ID {addr addr_id} { if {$sync_ena} { $this Simulator_sync_reg $addr } - } { + } else { set rmw_instruction 1 write_sfr $addr [expr {[read_sfr $addr] ^ $val}] evaluate_sfr $addr } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_mcu_configuration.tcl b/lib/simulator/engine/engine_mcu_configuration.tcl index 7701583..2226a7d 100755..100644 --- a/lib/simulator/engine/engine_mcu_configuration.tcl +++ b/lib/simulator/engine/engine_mcu_configuration.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_MCU_CONFIGURATION_TCL ] } { +set _ENGINE_MCU_CONFIGURATION_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -53,7 +58,7 @@ private method increment_program_time {num} { return [watchdog_controller] } -## Adjust configuration acording to new value of the given bit +## Adjust configuration according to new value of the given bit # @parm Int addr - Bit address # @return void private method evaluate_bit {addr} { @@ -61,18 +66,18 @@ private method evaluate_bit {addr} { if {$sync_ena} { $this Simulator_sync_reg [getRegOfBit $addr] } - } { + } else { evaluate_sfr [getRegOfBit $addr] } } -## Evaluate list of interrupt priorities acording to values of IP and IPH +## Evaluate list of interrupt priorities according to values of IP and IPH # @return void private method evaluate_interrupt_priorities {} { # Determinate value of Interrupt Priority High register - if {$feature_avaliable(iph)} { + if {$feature_available(iph)} { set iph $sfr(183) - } { + } else { set iph 0 } @@ -115,17 +120,17 @@ private method evaluate_interrupt_priorities {} { foreach flag $controllers_conf(IP) ip $controllers_conf(IP_level) { switch -- $flag { PS { - if {$feature_avaliable(uart)} { + if {$feature_available(uart)} { lappend interrupt_pri_flg RI TI lappend interrupt_pri_num $ip $ip } - if {$feature_avaliable(spi)} { + if {$feature_available(spi)} { lappend interrupt_pri_flg SPIF lappend interrupt_pri_num $ip } } PT2 { - if {!$feature_avaliable(t2)} {continue} + if {!$feature_available(t2)} {continue} lappend interrupt_pri_flg EXF2 TF2 lappend interrupt_pri_num $ip $ip } @@ -146,7 +151,7 @@ private method evaluate_interrupt_priorities {} { lappend interrupt_pri_num $ip } PC { - if {!$feature_avaliable(acomparator)} {continue} + if {!$feature_available(acomparator)} {continue} lappend interrupt_pri_flg CF lappend interrupt_pri_num $ip } @@ -154,17 +159,16 @@ private method evaluate_interrupt_priorities {} { } # Adjust interrup monitor - $this interrupt_monitor_intr_prior $interrupt_pri_flg + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_prior $interrupt_pri_flg + } } -## Adjust configuration acording to new value of the given SFR - # @parm Int - Register address - # @parm Bool = 1 - Synchronize this SFR with external interface +## Adjust configuration according to new value of the given SFR + # @parm Int addr - Register address + # @parm Bool sync=1 - Synchronize this SFR with external interface # @return void -private method evaluate_sfr args { - set addr [lindex $args 0] - set sync [lindex $args 1] - +private method evaluate_sfr {addr {sync 1}} { switch -- $addr { 135 { ;# PCON 0x87 set SMOD0_prev $controllers_conf(SMOD0) @@ -179,7 +183,9 @@ private method evaluate_sfr args { write_conf 168 {EA EC ET2 ES ET1 EX1 ET0 EX0} # Inform interrupt monitor - $this interrupt_monitor_intr_ena_dis + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_ena_dis + } } 184 { ;# IP 0xB8 evaluate_interrupt_priorities @@ -190,7 +196,7 @@ private method evaluate_sfr args { # Determinate SM0 and FE if {$controllers_conf(SMOD0)} { set controllers_conf(FE) [expr {($sfr(152) & 0x80) ? 1 : 0}] - } { + } else { set controllers_conf(SM0) [expr {($sfr(152) & 0x80) ? 1 : 0}] } @@ -203,13 +209,17 @@ private method evaluate_sfr args { } # Inform interrupt monitor - $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + } } 136 { ;# TCON 0x88 write_conf 136 {TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0} # Inform interrupt monitor - $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + } } 137 { ;# TMOD 0x89 write_conf 137 {GATE1 CT1 M11 M01 GATE0 CT0 M10 M00} @@ -234,19 +244,18 @@ private method evaluate_sfr args { set bank [expr {($sfr(208) & 24) >> 3}] } 224 { ;# A 0xE0 - set A 0 set count 0 set mask 1 for {set i 0} {$i < 8} {incr i} { - if {[expr {$sfr(224) & $mask}] > 0} { + if {$sfr(224) & $mask} { incr count } set mask [expr {$mask << 1}] } - if {[expr {$count % 2}] == 1} { + if {$count % 2} { setBit $symbol(P) 1 - } { + } else { setBit $symbol(P) 0 } } @@ -256,11 +265,11 @@ private method evaluate_sfr args { write_conf 162 {- - - - - - - DPS} # Switch visible dual DPTR - if {!$feature_avaliable(hddptr)} { + if {!$feature_available(hddptr)} { if {$controllers_conf(DPS)} { set DPL {DP1L} set DPH {DP1H} - } { + } else { set DPL {DP0L} set DPH {DP0H} } @@ -269,13 +278,13 @@ private method evaluate_sfr args { } elseif {$DPS_org != $controllers_conf(DPS)} { if {$DPS_org} { set hidden_DPTR1 [list $sfr($symbol(DP0L)) $sfr($symbol(DP0H))] - } { + } else { set hidden_DPTR0 [list $sfr($symbol(DP0L)) $sfr($symbol(DP0H))] } if {$controllers_conf(DPS)} { set sfr($symbol(DP0L)) [lindex $hidden_DPTR1 0] set sfr($symbol(DP0H)) [lindex $hidden_DPTR1 1] - } { + } else { set sfr($symbol(DP0L)) [lindex $hidden_DPTR0 0] set sfr($symbol(DP0H)) [lindex $hidden_DPTR0 1] } @@ -290,13 +299,13 @@ private method evaluate_sfr args { } } 142 { ;# AUXR 0x8E - if {$feature_avaliable(wdtcon)} { - if {$feature_avaliable(intelpe)} { + if {$feature_available(wdtcon)} { + if {$feature_available(intelpe)} { write_conf 142 {- - - - - - IPE DISALE} - } { + } else { write_conf 142 {- - - - - - EXTRAM DISALE} } - } { + } else { write_conf 142 {- - - WDIDLE DISRTO - EXTRAM DISALE} } } @@ -306,7 +315,7 @@ private method evaluate_sfr args { set controllers_conf(WatchDogTimer) 1 set watchdog_value -$time - if {$feature_avaliable(wdtcon)} { + if {$feature_available(wdtcon)} { set controllers_conf(WDTEN) 1 set sfr(167) [expr {$sfr(167) | 1}] if {${::Simulator::reverse_run_steps}} { @@ -324,7 +333,9 @@ private method evaluate_sfr args { write_conf 200 {TF2 EXF2 RCLK TCLK EXEN2 TR2 CT2 CPRL2} # Inform interrupt monitor - $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + } } 201 { ;# T2MOD 0xC9 write_conf 201 {- - - - - - T2OE DCEN} @@ -342,7 +353,9 @@ private method evaluate_sfr args { }] # Inform interrupt monitor - $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + } } 183 { ;# IPH 0xB7 evaluate_interrupt_priorities @@ -354,12 +367,14 @@ private method evaluate_sfr args { write_conf 170 {SPIF WCOL LDEN - - - DISSO ENH} # Inform interrupt monitor - $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + } } 167 { ;# WDTCON/WDTPRG 0xA7 - if {$feature_avaliable(wdtprg)} { + if {$feature_available(wdtprg)} { write_conf 167 {- - - - - PS2 PS1 PS0} - } { + } else { write_conf 167 {PS2 PS1 PS0 WDIDLE DISRTO HWDT WSWRST WDTEN} } set controllers_conf(WatchDogPrescaler) 0 @@ -395,7 +410,7 @@ private method evaluate_sfr args { if {$controllers_conf(DPS)} { set DPL {DP1L} set DPH {DP1H} - } { + } else { set DPL {DP0L} set DPH {DP0H} } @@ -423,7 +438,7 @@ private method write_conf {addr key_list} { if {[expr {$sfr($addr) & $mask}] == 0} { set controllers_conf($key) 0 - } { + } else { set controllers_conf($key) 1 } } @@ -499,7 +514,7 @@ private method incr_8b {type addr val} { private method stack_pop {} { if {[check_address_validity I $sfr(129)]} { set result [undefined_octet] - } { + } else { if {${::Simulator::reverse_run_steps}} { stepback_reg_change I $sfr(129) } @@ -540,7 +555,7 @@ public method stack_push {val} { } if {[check_address_validity I $sfr(129)]} { return - } { + } else { if {${::Simulator::reverse_run_steps}} { stepback_reg_change I $sfr(129) } @@ -553,3 +568,7 @@ public method stack_push {val} { evaluate_sfr 129 $this stack_monitor_push $sfr(129) $val } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_memory_management.tcl b/lib/simulator/engine/engine_memory_management.tcl index acf2978..e3a5828 100755..100644 --- a/lib/simulator/engine/engine_memory_management.tcl +++ b/lib/simulator/engine/engine_memory_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_MEMORY_MANAGEMENT_TCL ] } { +set _ENGINE_MEMORY_MANAGEMENT_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -40,11 +45,11 @@ private method getNextOperand {} { bell $this sim_txt_output [mc "Incomplete instruction (undefined operand/value missing in memory) at 0x%s" [NumSystem::dec2hex $pc]] return [undefined_octet] - } { + } else { if {$code($pc) == {}} { $this sim_txt_output [mc "Incomplete instruction (undefined operand/value missing in memory) at 0x%s. Using 0FFh as operand !" [NumSystem::dec2hex $pc]] return 255 - } { + } else { return $code($pc) } } @@ -59,11 +64,11 @@ private method getLastOperand {} { bell $this sim_txt_output [mc "Incomplete instruction (undefined operand/value missing in memory) at 0x%s" [NumSystem::dec2hex $pc]] set result [undefined_octet] - } { + } else { if {$code($pc) == {}} { $this sim_txt_output [mc "Incomplete instruction (undefined operand/value missing in memory) at 0x%s. Using 0FFh as operand !" [NumSystem::dec2hex $pc]] set result 255 - } { + } else { set result $code($pc) } } @@ -92,7 +97,7 @@ public method setBit {addr value} { if {${::Simulator::reverse_run_steps}} { if {$regAddr < 128} { stepback_reg_change I $regAddr - } { + } else { stepback_reg_change S $regAddr } } @@ -114,7 +119,7 @@ public method setBit {addr value} { } elseif {([expr {$ram($regAddr) & $mask}] == 0) && $value} { set ram($regAddr) [expr {$ram($regAddr) ^ $mask}] } - } { + } else { set sfr_val [read_sfr $regAddr] if {([expr {$sfr_val & $mask}] > 0) && !$value} { write_sfr $regAddr [expr {$sfr_val ^ $mask}] @@ -125,7 +130,7 @@ public method setBit {addr value} { if {$regAddr > 127} { evaluate_sfr $regAddr - } { + } else { if {$sync_ena} { $this Simulator_sync_reg $regAddr } @@ -161,19 +166,19 @@ public method getBitByReg {regAddr bitNumber} { if {$regAddr < 0x80} { if {[expr {$ram($regAddr) & $mask}] == 0} { return 0 - } { + } else { return 1 } - } { - if {[lsearch -ascii -exact $PORT_LATCHES $regAddr] != -1} { + } else { + if {[lsearch -ascii -exact $PORT_LATCHES $regAddr] != -1} { set byte [read_sfr $regAddr] - } { - set byte $sfr($regAddr) - } + } else { + set byte $sfr($regAddr) + } if {[expr {$byte & $mask}] == 0} { return 0 - } { + } else { return 1 } } @@ -187,7 +192,7 @@ public method getRegOfBit {addr} { if {$addr > 127} { set reg [expr {$reg * 8}] - } { + } else { incr reg 32 } @@ -247,7 +252,9 @@ private method check_address_validity {location address} { } internal_shutdown - $this invalid_addressing_dialog $location $address + if {$::GUI_AVAILABLE} { + $this invalid_addressing_dialog $location $address + } set address_error 1 return 1 } @@ -255,8 +262,10 @@ private method check_address_validity {location address} { ## Check if the specified address at the given location is implemented in this MCU # @parm Char location - Memory type # D == IDATA direct addressing or SFR + # S == SFR only # I == IDATA indirect addressing (or operations on stack) # B == Bit area + # J == Special Function Bits only # X == XDATA # C == CODE # E == ERAM @@ -269,7 +278,12 @@ public method simulator_address_range {location address} { if {$address < 128 && $address < $iram_size} { return 1 } - if {[lsearch $avaliable_sfr $address] != -1} { + if {[lsearch $available_sfr $address] != -1} { + return 1 + } + } + {S} { ;# SFR only + if {[lsearch $available_sfr $address] != -1} { return 1 } } @@ -286,7 +300,15 @@ public method simulator_address_range {location address} { if {$reg_addr < 128 && $reg_addr < $iram_size} { return 1 } - if {[lsearch $avaliable_sfr $reg_addr] != -1} { + if {[lsearch $available_sfr $reg_addr] != -1} { + return 1 + } + } + {J} { ;# Special Function Bits only + if {[lsearch $restricted_bits $address] != -1} { + return 0 + } + if {[lsearch $available_sfr [getRegOfBit $address]] != -1} { return 1 } } @@ -316,7 +338,8 @@ public method simulator_address_range {location address} { ## Write value to SFR # - It does not check address validity ! - # - Purpose is to write zero to unimplemented bits + # - Purpose is to write zero to unimplemented bits and handle special funtions + # triggered by write to specific SFR # @parm Int addr - Target address (128..255) # @parm Int value - New value (0.255) # @return void @@ -341,15 +364,15 @@ private method write_sfr {addr value} { # Interrupts configuration related SFR -- skip next interrupt if {$addr == $symbol(IP) || $addr == $symbol(IE) || $addr == $symbol(IPH)} { set skip_interrupt 1 - } { + } else { set skip_interrupt 0 } # Write specified value into the SFR - if {[lsearch $incomplite_regs $addr] == -1} { + if {[lsearch $incomplete_regs $addr] == -1} { set sfr($addr) $value - } { - set sfr($addr) [expr {$value & $incomplite_regs_mask($addr)}] + } else { + set sfr($addr) [expr {$value & $incomplete_regs_mask($addr)}] } } @@ -361,7 +384,7 @@ private method write_sfr {addr value} { private method read_sfr {addr} { # Port latch set port_number [lsearch -ascii -exact $PORT_LATCHES $addr] - if {!$rmw_instruction && $port_number != -1} { + if {!$rmw_instruction && $port_number != -1 && [$this pale_is_enabled]} { set result [$this pale_RRPV $port_number] # Write only register @@ -373,15 +396,19 @@ private method read_sfr {addr} { return [undefined_octet] # Fully implemeneted register - } elseif {[lsearch $incomplite_regs $addr] == -1} { + } elseif {[lsearch $incomplete_regs $addr] == -1} { return $sfr($addr) # Partialy implemented register - } { + } else { return [expr { - ($incomplite_regs_mask($addr) & $sfr($addr)) + ($incomplete_regs_mask($addr) & $sfr($addr)) + - (($incomplite_regs_mask($addr) ^ 0x0FF) & [undefined_octet]) + (($incomplete_regs_mask($addr) ^ 0x0FF) & [undefined_octet]) }] } } + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_opcodes.tcl b/lib/simulator/engine/engine_opcodes.tcl index 6d43158..e06dc12 100755..100644 --- a/lib/simulator/engine/engine_opcodes.tcl +++ b/lib/simulator/engine/engine_opcodes.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_OPCODES_TCL ] } { +set _ENGINE_OPCODES_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -433,3 +438,7 @@ private method 108 {} {ins_xrl 224 $ram([R 4])} ;# 0x6C :: xrl A, R4 private method 109 {} {ins_xrl 224 $ram([R 5])} ;# 0x6D :: xrl A, R5 private method 110 {} {ins_xrl 224 $ram([R 6])} ;# 0x6E :: xrl A, R6 private method 111 {} {ins_xrl 224 $ram([R 7])} ;# 0x6F :: xrl A, R7 + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_text_based_interface.tcl b/lib/simulator/engine/engine_text_based_interface.tcl new file mode 100644 index 0000000..0b6448c --- /dev/null +++ b/lib/simulator/engine/engine_text_based_interface.tcl @@ -0,0 +1,1087 @@ +#!/usr/bin/tclsh +# Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) + +############################################################################ +# Copyright (C) 2011-2011 by Martin Ošmera # +# martin.osmera@gmail.com # +# # +# This program is free software; you can redistribute it and#or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation; either version 2 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program; if not, write to the # +# Free Software Foundation, Inc., # +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # +############################################################################ + +# >>> File inclusion guard +if { ! [ info exists _ENGINE_TEXT_BASED_INTERFACE_TCL ] } { +set _ENGINE_TEXT_BASED_INTERFACE_TCL _ +# <<< File inclusion guard + +# -------------------------------------------------------------------------- +# DESCRIPTION +# +# Command line interface for the simulator engine. Listens to simple commands, +# like `read-sfr-by-name PCON'. Each command must be on separate line, empty +# lines and everything after `#' characater are ignored. Response to every +# command is either `DONE' or +# `ERROR (line: <line_number>; command: <command>): <error_info>'. Some commands +# returns some values, in that case these values are printed before the `DONE' +# string. Commands are case insensitive, but the same may not apply for their +# arguments. +# +# Note: This interface is supposed to be available via main.tcl invoked with +# --simulator option. That means that to access this inteface it should be +# sufficient to run `mcu8051ide --simulator' command. +# +# List of commands: +# ================ +# +# COMMAND DESCRIPTION +# ------- ----------- +# echo-on +# echo-off +# set-mcu +# set-clock +# set-xcode +# set-xdata +# load-code +# load-code-adf +# load-code-cdb +# load-idata +# load-xdata +# load-eeprom +# load-eram +# dump-code +# dump-idata +# dump-xdata +# dump-eeprom +# dump-eram +# write-code +# write-idata +# write-xdata +# write-eeprom +# write-eram +# write-sfr +# write-sfr +# write-bit +# read-code +# read-idata +# read-xdata +# read-eeprom +# read-eram +# read-sfr +# read-sfr-by-name +# read-bit +# step +# step-back +# list-changes +# read-pc +# write-pc +# read-position +# reset +# run +# input +# output +# hibernate +# resume +# core-dump +# core-alter +# exit +# -------------------------------------------------------------------------- + +namespace eval SimulatorEngineCLI { + variable command_line + variable cmd_line_idx + variable simulator + variable line_counter + variable echo + variable error_reported + + class SimEngineWrapper { + inherit Simulator_ENGINE Pale + + common changed_registers [list] + + # TODO: get rid of these variables: + public variable procData {} + public variable P_option_mcu_type {} + public variable P_option_mcu_xdata 0 + public variable P_option_mcu_xcode 0 + public variable projectPath {.} + + public method is_ready {} { + if {[llength $procData]} { + return 1 + } else { + return 0 + } + } + + public method Simulator_GUI_sync args { + lappend changed_registers $args + } + + public method Simulator_sync_PC_etc {} { + } + + public method get_changed_registers {} { + return $changed_registers + } + + public method clear_changed_registers {} { + set changed_registers [list] + } + } + + proc enter_main_loop {} { + variable command_line + variable cmd_line_idx + variable simulator + variable line_counter 0 + variable echo 0 + variable error_reported + + set simulator [SimEngineWrapper #auto] + + namespace eval ::Simulator { + variable undefined_value 2 + variable reverse_run_steps 100 + } + + namespace eval ::X { + variable critical_procedure_in_progress 0 + } + + puts "READY" + + while {![eof stdin]} { + incr line_counter + set command_line [gets stdin] + set command_line [regsub {#.*$} $command_line {}] + set command_line [string trim $command_line] + set cmd_line_idx 1 + set error_reported 0 + + if {[catch { + set command [string tolower [lindex $command_line 0]] + }]} then { + set tmp $command_line + set command_line {<unknown>} + abort_now "Unable to understand line: \"$tmp\"" + } + + # Do nothing with an empty line + if {![string length $command_line]} { + continue + } + + if {$echo} { + puts "> $command_line" + } + if {[lsearch -ascii -exact {set-mcu echo-on echo-off} $command] == -1 && ![$simulator is_ready]} { + report_error "Processor type has to be specified first" + continue + } + if {[command_switch $command]} { + break + } + + if {!$error_reported} { + puts "OK" + } + } + puts "EXITING" + } + + proc command_switch {command} { + variable echo + switch -- $command { + {echo-on} { + expect_no_more_arguments + command__echo_on + } + {echo-off} { + expect_no_more_arguments + command__echo_off + } + {set-mcu} { + expect_string + expect_no_more_arguments + + command__set_mcu + } + {set-clock} { + expect_integer 1 99999 + expect_no_more_arguments + + command__set_clock + } + {set-xcode} { + expect_integer 0 65536 + expect_no_more_arguments + + command__set_xcode + } + {set-xdata} { + expect_integer 0 65536 + expect_no_more_arguments + + command__set_xdata + } + + {load-code} { + expect_no_more_arguments + command__load_code + } + {load-code-adf} { + expect_string + expect_no_more_arguments + + command__load_code_adf + } + {load-code-cdb} { + expect_string + expect_string + expect_string + expect_no_more_arguments + command__load_code_cdb + } + {load-idata} { + expect_no_more_arguments + command__load_idata + } + {load-xdata} { + expect_no_more_arguments + command__load_xdata + } + {load-eeprom} { + expect_no_more_arguments + command__load_eeprom + } + {load-eram} { + expect_no_more_arguments + command__load_eram + } + + {dump-code} { + expect_no_more_arguments + command__dump_code + } + {dump-idata} { + expect_no_more_arguments + command__dump_idata + } + {dump-xdata} { + expect_no_more_arguments + command__dump_xdata + } + {dump-eeprom} { + expect_no_more_arguments + command__dump_eeprom + } + {dump-eram} { + expect_no_more_arguments + command__dump_eram + } + + {write-code} { + expect_integer 0 65536 + expect_integer 0 256 + expect_no_more_arguments + + command__write_code + } + {write-idata} { + expect_integer 0 256 + expect_integer 0 256 + expect_no_more_arguments + + command__write_idata + } + {write-xdata} { + expect_integer 0 65536 + expect_integer 0 256 + expect_no_more_arguments + + command__write_xdata + } + {write-eeprom} { + expect_integer 0 65536 + expect_integer 0 256 + expect_no_more_arguments + + command__write_eeprom + } + {write-eram} { + expect_integer 0 65536 + expect_integer 0 256 + expect_no_more_arguments + + command__write_eram + } + {write-sfr} { + expect_integer 128 256 + expect_integer 0 256 + expect_no_more_arguments + + command__write_sfr + } + {write-sfr} { + expect_string + expect_integer 0 256 + expect_no_more_arguments + + command__write_sfr_by_name + } + {write-bit} { + expect_integer 0 256 + expect_integer 0 256 + expect_no_more_arguments + + command__write_bit + } + + {read-code} { + expect_integer 0 65536 + expect_no_more_arguments + + command__read_code + } + {read-idata} { + expect_integer 0 256 + expect_no_more_arguments + + command__read_idata + } + {read-xdata} { + expect_integer 0 65536 + expect_no_more_arguments + + command__read_xdata + } + {read-eeprom} { + expect_integer 0 65536 + expect_no_more_arguments + + command__read_eeprom + } + {read-eram} { + expect_integer 0 65536 + expect_no_more_arguments + + command__read_eram + } + {read-sfr} { + expect_integer 128 256 + expect_no_more_arguments + + command__read_sfr + } + {read-sfr-by-name} { + expect_string + expect_no_more_arguments + + command__read_sfr_by_name + } + {read-bit} { + expect_integer 0 256 + expect_no_more_arguments + + command__read_bit + } + + {step} { + expect_no_more_arguments + command__step + } + {step-back} { + expect_no_more_arguments + command__step_back + } + + {list-changes} { + expect_no_more_arguments + command__list_changes + } + {read-pc} { + expect_no_more_arguments + command__read_pc + } + {write-pc} { + expect_integer 0 65536 + expect_no_more_arguments + + command__write_pc + } + {read-position} { + expect_no_more_arguments + command__read_position + } + {reset} { + expect_no_more_arguments + command__reset + } + {run} { + expect_no_more_arguments + command__run + } + + {input} { + expect_integer 0 4 + expect_no_more_arguments + + command__input + } + {output} { + expect_integer 0 4 + expect_no_more_arguments + + command__output + } + + {hibernate} { + expect_string + expect_no_more_arguments + + command__hibernate + } + {resume} { + expect_string + expect_no_more_arguments + + command__resume + } + + {core-dump} { + expect_no_more_arguments + command__core_dump + } + {core-alter} { + expect_string + expect_no_more_arguments + + command__core_alter + } + + {exit} { + expect_no_more_arguments + return 1 + } + default { + report_error "Unrecognised command: \"$command\"" + } + } + return 0 + } + + proc abort_now {info} { + report_error $info + puts "ABORTING" + exit 1 + } + + proc report_error {info} { + variable error_reported + variable line_counter + variable command_line + + set error_reported 1 + puts stderr "ERROR (line: $line_counter; command: [lindex $command_line 0]): $info" + } + + proc expect_no_more_arguments {} { + variable command_line + variable cmd_line_idx + + if {[llength $command_line] > $cmd_line_idx} { + abort_now "Too many aguments given to to command [lindex $command_line 0]" + } + } + + proc expect_string {{max_length {}}} { + variable command_line + variable cmd_line_idx + + set arg [lindex $command_line $cmd_line_idx] + if {![string length $arg]} { + abort_now "Argument missing for command [lindex $command_line 0] at index $cmd_line_idx" + } elseif {$max_length != {} && [string length $arg] > $max_length} { + abort_now "Agrument given to command [lindex $command_line 0] at index $cmd_line_idx is too long, mimum allowed length is $max_length" + } + incr cmd_line_idx + } + + proc expect_integer {{min {}} {max {}}} { + variable command_line + variable cmd_line_idx + + set arg [lindex $command_line $cmd_line_idx] + if {![string is digit -strict $arg]} { + abort_now "Non integer agrument given to command [lindex $command_line 0] at index $cmd_line_idx" + } elseif {($min != {} && $arg < $min) || ($max != {} && $arg > $max)} { + abort_now "Integer agrument given to command [lindex $command_line 0] at index $cmd_line_idx is out of its allowed range \[$min;$max\]" + } + incr cmd_line_idx + } + + proc load_hex {set_command memory_size} { + variable simulator + + set hex_data {} + + while {![eof stdin]} { + set line [gets stdin] + append hex_data $line "\n" + + # Stop when EOF sequnce is found + if {[string range $line 7 8] == {01}} { + break + } + } + + ::IHexTools::free_resources + ::IHexTools::load_hex_data $hex_data + if {${::IHexTools::error_count}} { + report_error ${::IHexTools::error_string} + return + } + + if {${::IHexTools::highest_addr} >= $memory_size} { + report_error "You are attempting to load more data than the memory capacity allows. Capacity: $memory_size; Required: [expr {${::IHexTools::highest_addr} + 1}]" + } + + set val {} + for {set i 0} {$i < ${::IHexTools::highest_addr}} {incr i} { + set val [::IHexTools::get_value $i] + if {$val == -1} { + set val {} + } + $simulator $set_command $i $val + } + for {} {$i < $memory_size} {incr i} { + $simulator $set_command $i {} + } + } + + # ---------------------------------------------------------------------- + # COMMANDS + # ---------------------------------------------------------------------- + + proc command__echo_on {} { + variable echo 1 + } + proc command__echo_off {} { + variable echo 0 + } + proc command__set_mcu {} { + variable simulator + variable command_line + + set new_processor [string toupper [lindex $command_line 1]] + + if {[lsearch -ascii -exact [SelectMCU::get_available_processors] $new_processor] == -1} { + abort_now "Unsupported processor: [lindex $command_line 1]" + } + + $simulator configure -P_option_mcu_type $new_processor + set proc_data [SelectMCU::get_processor_details $new_processor] + if {$proc_data == {}} { + abort_now "Internal error" + } + $simulator configure -procData $proc_data + + $simulator simulator_initialize_mcu + } + proc command__set_clock {} { + variable simulator + variable command_line + + $simulator setEngineClock [lindex $command_line 1] + } + proc command__set_xcode {} { + variable simulator + variable command_line + + set arg [lindex $command_line 1] + + set icode [expr {[lindex [$simulator cget -procData] 2] * 1024}] + if {$arg > (0xFFFF - $icode)} { + abort_now "This MCU has CODE memory limit 0x10000 B (65536)" + } + + if {[lindex [$simulator cget -procData] 1] != {yes}} { + abort_now "This MCU cannot have connected external program memory" + } else { + $simulator configure -P_option_mcu_xcode $arg + $simulator simulator_resize_code_memory $arg + } + } + proc command__set_xdata {} { + variable simulator + variable command_line + + set arg [lindex $command_line 1] + if {[lindex [$simulator cget -procData] 0] != {yes}} { + abort_now "This MCU cannot have connected external data memory" + } else { + $simulator configure -P_option_mcu_xdata $arg + $simulator simulator_resize_xdata_memory $arg + } + } + proc command__reset {} { + variable simulator + $simulator master_reset - + } + + proc command__load_code {} { + variable simulator + variable command_line + + load_hex setCodeDEC [expr {[$simulator cget -P_option_mcu_xcode] + ([lindex [$simulator cget -procData] 2] * 1024)}] + } + + proc command__load_code_adf {} { + variable simulator + variable command_line + + if {[catch { + set file [open [lindex $command_line 1] {r}] + }]} then { + abort_now "Unable to open file: [lindex $command_line 1]" + } + + $simulator load_program_from_adf $file + foreach filename [$simulator simulator_get_list_of_filenames] { + $simulator Simulator_import_breakpoints $filename [list] + } + + catch { + close $file + } + } + proc command__load_code_cdb {} { + variable simulator + variable command_line + + set filename [lindex $command_line 1] + set cdb_flnm [lindex $command_line 2] + set ihx_flnm [lindex $command_line 3] + + set cdb_file {} + set ihx_file {} + + if {![file exists $filename]} { + report_error "File does not exist: \"$filename\"" + return + } + + if {[catch { + set cdb_file [open $cdb_flnm {r}] + }]} then { + report_error "Cannot open file: \"$cdb_flnm\"" + return + } + if {[catch { + set ihx_file [open $ihx_flnm {r}] + }]} then { + catch {close $cdb_file} + report_error "Cannot open file: \"$ihx_flnm\"" + return + } + + if {![$simulator load_program_from_cdb $filename $cdb_file $ihx_file]} { + report_error ${::IHexTools::error_string} + } else { + foreach filename [$simulator simulator_get_list_of_filenames] { + $simulator Simulator_import_breakpoints $filename [list] + } + } + + catch {close $cdb_file} + catch {close $ihx_file} + } + proc command__load_idata {} { + variable simulator + variable command_line + + load_hex setDataDEC [lindex [$simulator cget -procData] 3] + } + proc command__load_xdata {} { + variable simulator + variable command_line + + load_hex setXdataDEC [$simulator cget -P_option_mcu_xdata] + } + proc command__load_eeprom {} { + variable simulator + variable command_line + + load_hex setEepromDEC [lindex [$simulator cget -procData] 32] + } + proc command__load_eram {} { + variable simulator + variable command_line + + load_hex setEramDEC [lindex [$simulator cget -procData] 8] + } + proc command__dump_code {} { + variable simulator + variable command_line + + set capacity [expr {[$simulator cget -P_option_mcu_xcode] + ([lindex [$simulator cget -procData] 2] * 1024)}] + ::IHexTools::free_resources + for {set addr 0} {$addr < $capacity} {incr addr} { + ::IHexTools::content [$simulator getCode $addr] + } + puts -nonewline [::IHexTools::get_hex_data] + } + proc command__dump_idata {} { + variable simulator + variable command_line + + set capacity [lindex [$simulator cget -procData] 3] + ::IHexTools::free_resources + for {set addr 0} {$addr < $capacity} {incr addr} { + ::IHexTools::content [$simulator getData $addr] + } + puts -nonewline [::IHexTools::get_hex_data] + } + proc command__dump_xdata {} { + variable simulator + variable command_line + + set capacity [$simulator cget -P_option_mcu_xdata] + ::IHexTools::free_resources + for {set addr 0} {$addr < $capacity} {incr addr} { + ::IHexTools::content [$simulator getXdata $addr] + } + puts -nonewline [::IHexTools::get_hex_data] + } + proc command__dump_eeprom {} { + variable simulator + variable command_line + + set capacity [lindex [$simulator cget -procData] 32] + ::IHexTools::free_resources + for {set addr 0} {$addr < $capacity} {incr addr} { + ::IHexTools::content [$simulator getEeprom $addr] + } + puts -nonewline [::IHexTools::get_hex_data] + } + proc command__dump_eram {} { + variable simulator + variable command_line + + set capacity [lindex [$simulator cget -procData] 8] + ::IHexTools::free_resources + for {set addr 0} {$addr < $capacity} {incr addr} { + ::IHexTools::content [$simulator getEram $addr] + } + puts -nonewline [::IHexTools::get_hex_data] + } + proc command__write_code {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + set val [lindex $command_line 2] + + if {![$simulator simulator_address_range C $addr]} { + report_error "Invalid address: $addr" + } else { + $simulator setCodeDEC $addr $val + } + } + proc command__write_idata {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + set val [lindex $command_line 2] + + if {![$simulator simulator_address_range I $addr]} { + report_error "Invalid I-DATA address: $addr" + } else { + $simulator setDataDEC $addr $val + } + } + proc command__write_xdata {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + set val [lindex $command_line 2] + + if {![$simulator simulator_address_range X $addr]} { + report_error "Invalid X-DATA address: $addr" + } else { + $simulator setXdataDEC $addr $val + } + } + proc command__write_eeprom {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + set val [lindex $command_line 2] + + if {![$simulator simulator_address_range P $addr]} { + report_error "Invalid EEPROM address: $addr" + } else { + $simulator setEepromDEC $addr $val + } + } + proc command__write_eram {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + set val [lindex $command_line 2] + + if {![$simulator simulator_address_range E $addr]} { + report_error "Invalid ERAM address: $addr" + } else { + $simulator setEramDEC $addr $val + } + } + proc command__write_sfr {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + set val [lindex $command_line 2] + + if {![$simulator simulator_address_range S $addr]} { + report_error "Invalid SFR address: $addr" + } else { + if {$addr == $::Simulator_ENGINE::symbol(SBUFR)} { + set addr $::Simulator_ENGINE::symbol(SBUFT) + } + $simulator setSfrDEC $addr $val + } + } + proc command__write_sfr_by_name {} { + variable simulator + variable command_line + + set name [lindex $command_line 1] + set val [lindex $command_line 2] + + if {[lsearch -ascii -exact [array names ::Simulator_ENGINE::symbol] [string toupper $name]] == -1} { + report_error "Invalid SFR name: $name" + } else { + set addr $::Simulator_ENGINE::symbol([string toupper $name]) + + if {![$simulator simulator_address_range S $addr]} { + report_error "Invalid SFR address: $addr" + } else { + if {$addr == $::Simulator_ENGINE::symbol(SBUFR)} { + set addr $::Simulator_ENGINE::symbol(SBUFT) + } + $simulator setSfrDEC $addr $val + } + } + } + proc command__write_bit {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + set val [lindex $command_line 2] + + if {![$simulator simulator_address_range B $addr]} { + report_error "Invalid BIT address: $addr" + } else { + $simulator setBit $addr + } + } + proc command__read_code {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + + if {![$simulator simulator_address_range C $addr]} { + report_error "Invalid address: $addr" + } else { + puts [$simulator getCodeDEC $addr] + } + } + proc command__read_idata {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + + if {![$simulator simulator_address_range I $addr]} { + report_error "Invalid I-DATA address: $addr" + } else { + puts [$simulator getDataDEC $addr] + } + } + proc command__read_xdata {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + + if {![$simulator simulator_address_range X $addr]} { + report_error "Invalid X-DATA address: $addr" + } else { + puts [$simulator getXdataDEC $addr] + } + } + proc command__read_eeprom {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + + if {![$simulator simulator_address_range P $addr]} { + report_error "Invalid EEPROM address: $addr" + } else { + puts [$simulator getEepromDEC $addr] + } + } + proc command__read_eram {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + + if {![$simulator simulator_address_range E $addr]} { + report_error "Invalid ERAM address: $addr" + } else { + puts [$simulator getEramDEC $addr] + } + } + proc command__read_sfr {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + + if {![$simulator simulator_address_range S $addr]} { + report_error "Invalid SFR address: $addr" + } else { + puts [$simulator getSfrDEC $addr] + } + } + proc command__read_sfr_by_name {} { + variable simulator + variable command_line + + set name [lindex $command_line 1] + set val [lindex $command_line 2] + + if {[lsearch -ascii -exact [array names ::Simulator_ENGINE::symbol] [string toupper $name]] == -1} { + report_error "Invalid SFR name: $name" + } else { + set addr $::Simulator_ENGINE::symbol([string toupper $name]) + + if {![$simulator simulator_address_range S $addr]} { + report_error "Invalid SFR address: $addr" + } else { + puts [$simulator getSfrDEC $addr] + } + } + } + proc command__read_bit {} { + variable simulator + variable command_line + + set addr [lindex $command_line 1] + + if {![$simulator simulator_address_range B $addr]} { + report_error "Invalid BIT address: $addr" + } else { + puts [$simulator getBit $addr] + } + } + proc command__step {} { + variable simulator + + $simulator clear_changed_registers + $simulator step + } + proc command__step_back {} { + variable simulator + + $simulator clear_changed_registers + puts [$simulator stepback] + } + proc command__list_changes {} { + variable simulator + variable command_line + + puts [$simulator get_changed_registers] + } + proc command__read_pc {} { + variable simulator + + puts [$simulator getPC] + } + proc command__write_pc {} { + variable simulator + variable command_line + + $simulator setPC [lindex $command_line 1] + } + proc command__read_position {} { + variable simulator + variable command_line + + set pos [$simulator simulator_getCurrentLine] + puts "F: \"[$simulator simulator_get_filename [lindex $pos 1]]\"" + puts "L: [lindex $pos 0]" + puts "V: [lindex $pos 2]" + puts "B: [lindex $pos 3]" + } + proc command__run {} { + variable simulator + $simulator sim_run + } + proc command__input {} { + variable simulator + variable command_line + # TODO: Complete it + } + proc command__output {} { + variable simulator + variable command_line + # TODO: Complete it + } + proc command__hibernate {} { + variable simulator + variable command_line + # TODO: Complete it + } + proc command__resume {} { + variable simulator + variable command_line + # TODO: Complete it + } + proc command__core_dump {} { + variable simulator + variable command_line + # TODO: Complete it + } + proc command__core_alter {} { + variable simulator + variable command_line + # TODO: Complete it + } +} + +# >>> File inclusion guard +} +# <<< File inclusion guard diff --git a/lib/simulator/engine/engine_virtual_hw_controller.tcl b/lib/simulator/engine/engine_virtual_hw_controller.tcl index a597e27..a13c9b9 100755..100644 --- a/lib/simulator/engine/engine_virtual_hw_controller.tcl +++ b/lib/simulator/engine/engine_virtual_hw_controller.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_VIRTUAL_HW_CONTROLLER_TCL ] } { +set _ENGINE_VIRTUAL_HW_CONTROLLER_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Part of simulator engine functionality. @@ -39,9 +44,9 @@ private method instruction_cycle {} { stepback_save_spec # Execute instruction - if {$DEBUG} { + if {${::DEBUG}} { $code($pc) - } { + } else { if {[catch { $code($pc) } result]} then { @@ -50,7 +55,10 @@ private method instruction_cycle {} { internal_shutdown incr_pc 1 } - puts stderr $result + # OP code 165d is invalid on 8051 + if {$code($pc) != 165} { + puts stderr ${::errorInfo} + } } } @@ -100,9 +108,9 @@ private method instruction_cycle {} { set rmw_instruction 1 set ports_previous_state [list] for {set i 0; set addr 128} {$i < 5} {incr i; incr addr 16} { - if {$feature_avaliable(p$i)} { + if {$feature_available(p$i)} { lappend ports_previous_state $sfr($addr) - } { + } else { lappend ports_previous_state 0 } } @@ -112,7 +120,7 @@ private method instruction_cycle {} { if {[$this pale_is_enabled]} { if {$controllers_conf(CEN)} { anlcmp_controller - } { + } else { set anlcmp_running 0 $this pale_SLSF $PIN(ANL0) 0 $this pale_SLSF $PIN(ANL1) 0 @@ -120,7 +128,7 @@ private method instruction_cycle {} { } # UART controller - if {$feature_avaliable(uart)} { + if {$feature_available(uart)} { if {($uart_RX_in_progress || $uart_TX_in_progress) && ${::Simulator::reverse_run_steps}} { stepback_reg_change S $symbol(SBUFR) stepback_reg_change S $symbol(SBUFT) @@ -134,9 +142,9 @@ private method instruction_cycle {} { set intx 1 ;# State of pin INTx set ext_int 0 ;# Local external interrupt flag - # Analyze port state + # Anylize port state for {set i -$time} {$i < 0} {incr i} { - # Determinate value of input pin INTx + # Determinate value of input pin INTX set intx [$this pale_RRPPV $PIN(INT${int_src}) $i] # Detect falling edge on INTx @@ -149,7 +157,7 @@ private method instruction_cycle {} { } # Just copy inverted value from INTx to IEx - } { + } else { set ext_int [expr {!$intx}] } } @@ -170,7 +178,7 @@ private method instruction_cycle {} { if {!$pwm_running} { set pwm_running 1 $this pale_SLSF $PIN(T1) 3 - } { + } else { # Make backup for affected SFR if {${::Simulator::reverse_run_steps}} { stepback_reg_change S $symbol(TL0) @@ -181,7 +189,7 @@ private method instruction_cycle {} { # Timer 0 is forced into mode 2 (8-bit autoreload) # TL1 is incremented after each T0 overflow incr sfr($symbol(TL0)) $time - while 1 { + while {1} { if {$sfr($symbol(TL0)) > 255} { set sfr($symbol(TL0)) [expr {$sfr($symbol(TL0)) - 256 + $sfr($symbol(TH0))}] # Increment TL1 @@ -199,11 +207,11 @@ private method instruction_cycle {} { set time_back [expr {256 - $sfr($symbol(TL0))}] if {$time_back >= 0} { $this pale_WPBBL $PIN(T1) 0 - } { + } else { $this pale_WPBBL $PIN(T1) $time_back } } - } { + } else { break } } @@ -241,7 +249,7 @@ private method instruction_cycle {} { $this Simulator_GUI_sync S $symbol(TH0) } # Shutdown timer 0 - } { + } else { set timer_0_running 0 } @@ -263,7 +271,7 @@ private method instruction_cycle {} { } } # Shutdown timer 1 - } { + } else { set timer_1_running 0 } @@ -282,7 +290,7 @@ private method instruction_cycle {} { } # Increment timer 2 - if {$feature_avaliable(t2)} { + if {$feature_available(t2)} { if {$controllers_conf(TR2)} { if {${::Simulator::reverse_run_steps}} { stepback_reg_change S $symbol(TL2) @@ -299,17 +307,21 @@ private method instruction_cycle {} { $this Simulator_GUI_sync S $symbol(RCAP2H) } # Shutdown timer 2 - } { + } else { set timer_2_running 0 } } # Manage interrupt monitor - $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + if {$::GUI_AVAILABLE} { + $this interrupt_monitor_intr_flags [simulator_get_active_intr_flags] + } # Adjust stopwatch timer incr run_statistics(3) - $this stopwatch_refresh + if {$::GUI_AVAILABLE} { + $this stopwatch_refresh + } # Manage stack for stepback stack stepback_save_norm @@ -343,7 +355,7 @@ private method anlcmp_controller {} { set sample 1 } # Normal mode (sample every S4) - } { + } else { set sample 1 } # Sample port pins ANL0 and ANL1 @@ -418,7 +430,7 @@ private method timer_controller_2 {} { } # Timer 16-bit - } { + } else { set increment $time } @@ -431,11 +443,11 @@ private method timer_controller_2 {} { # 16-bit timer if {$timer_2_running && !$controllers_conf(CT2)} { set increment [expr {$time * 6}] - } { + } else { set increment 0 } if {[increment_timer2 $increment 1]} { - while 1 { + while {1} { set sfr($symbol(TH2)) $sfr($symbol(RCAP2H)) if {![increment_timer2 $sfr($symbol(RCAP2L)) 1]} { break @@ -444,7 +456,6 @@ private method timer_controller_2 {} { } # Detect transition on external input - puts "set controllers_conf(T2) [expr {!$controllers_conf(T2)}]" set controllers_conf(T2) [expr {!$controllers_conf(T2)}] } @@ -466,7 +477,7 @@ private method timer_controller_2 {} { set increment [expr {$increment * 6}] } if {[increment_timer2 $increment 1]} { - while 1 { + while {1} { set sfr($symbol(TH2)) $sfr($symbol(RCAP2H)) if {![increment_timer2 $sfr($symbol(RCAP2L)) 1]} { break @@ -518,7 +529,7 @@ private method timer_controller_2 {} { # Overflow if {$result == 1} { - while 1 { + while {1} { set sfr($symbol(TH2)) $sfr($symbol(RCAP2H)) if {![increment_timer2 $sfr($symbol(RCAP2L)) $updown]} { break @@ -531,7 +542,7 @@ private method timer_controller_2 {} { # Underflow if {!$updown || $result == -1} { - while 1 { + while {1} { set cur_val [expr {$sfr($symbol(TL2)) + ($sfr($symbol(TH2)) << 8)}] set min_val [expr {$sfr($symbol(RCAP2L)) + ($sfr($symbol(RCAP2H)) << 8)}] @@ -559,7 +570,7 @@ private method timer_controller_2 {} { # 16-bit Auto-reload (DCEN == 0) } elseif {$timer_2_running} { if {[increment_timer2 $increment 1]} { - while 1 { + while {1} { set sfr($symbol(TH2)) $sfr($symbol(RCAP2H)) if {![increment_timer2 $sfr($symbol(RCAP2L)) 1]} { break @@ -584,7 +595,7 @@ private method timer_controller_2 {} { private method increment_timer2 {increment_by updown} { if {$updown} { incr sfr($symbol(TL2)) $increment_by - } { + } else { incr sfr($symbol(TL2)) -$increment_by } @@ -637,7 +648,7 @@ private method uart_start_transmission {} { if {$controllers_conf(UART_M) == 0} { $this pale_SLSF $PIN(TXD) 2 $this pale_SLSF $PIN(RXD) 1 - } { + } else { $this pale_SLSF $PIN(TXD) 1 } } @@ -694,18 +705,18 @@ private method uart_controller {num} { if {$controllers_conf(UART_M) == 2} { if {$controllers_conf(SMOD)} { incr uart_RX_clock [expr {$uart_clock_prescaler / 2}] - } { + } else { incr uart_RX_clock [expr {$uart_clock_prescaler / 4}] } - } { + } else { # Timer 2 overflow if {$controllers_conf(RCLK)} { incr uart_RX_clock $timer2_overflow # Timer 1 overflow - } { + } else { if {$controllers_conf(SMOD)} { incr uart_RX_clock $timer1_overflow - } { + } else { incr uart_RX_clock [expr {$uart_clock_prescaler / 2}] } } @@ -741,7 +752,7 @@ private method uart_controller {num} { } # Frame error detection - if {$feature_avaliable(smod0) && !($uart_RX_shift_reg & 1)} { + if {$feature_available(smod0) && !($uart_RX_shift_reg & 1)} { set controllers_conf(FE) 1 if {$sync_ena} { $this Simulator_GUI_sync S $symbol(SCON) @@ -758,7 +769,7 @@ private method uart_controller {num} { setBit $symbol(RB8) [expr {$uart_RX_shift_reg & 2}] set sfr($symbol(SBUFR)) [expr {($uart_RX_shift_reg & 0x3FC) >> 2}] if {$controllers_conf(SM2)} { - if {$feature_avaliable(euart)} { + if {$feature_available(euart)} { # Check for broadcast address if {$sfr($symbol(SBUFR)) == ($sfr($symbol(SADEN)) | $sfr($symbol(SADDR)))} { setBit $symbol(RI) $controllers_conf(RB8) @@ -766,15 +777,15 @@ private method uart_controller {num} { } elseif {($sfr($symbol(SBUFR)) & $sfr($symbol(SADEN))) == ($sfr($symbol(SADDR)) & $sfr($symbol(SADEN)))} { setBit $symbol(RI) $controllers_conf(RB8) } - } { + } else { setBit $symbol(RI) $controllers_conf(RB8) } - } { + } else { setBit $symbol(RI) 1 } # Frame error - if {$feature_avaliable(smod0) && !($uart_RX_shift_reg & 1)} { + if {$feature_available(smod0) && !($uart_RX_shift_reg & 1)} { set controllers_conf(FE) 1 if {$sync_ena} { $this Simulator_GUI_sync S $symbol(SCON) @@ -801,7 +812,7 @@ private method uart_controller {num} { set uart_RX_shift_reg 0x1FE } # Mode 1, 2, 3 - Start bit starts reception - } { + } else { if {![$this pale_RRPPV $PIN(RXD)]} { set uart_RX_clock 0 set uart_RX_in_progress 1 @@ -845,7 +856,7 @@ private method uart_controller {num} { incr i $this pale_WPBBL $PIN(RXD) $bit_to_send $i $this pale_WPBBL $PIN(TXD) 1 $i - } { + } else { incr i $this pale_WPBBL $PIN(TXD) {|} [expr {int($i / 2)}] $this pale_WPBBL $PIN(RXD) $bit_to_send [expr {int($i / 2)}] @@ -874,18 +885,18 @@ private method uart_controller {num} { if {$controllers_conf(UART_M) == 2} { if {$controllers_conf(SMOD)} { incr uart_TX_clock [expr {$uart_clock_prescaler / 2}] - } { + } else { incr uart_TX_clock [expr {$uart_clock_prescaler / 4}] } - } { + } else { # Timer 2 overflow if {$controllers_conf(TCLK)} { incr uart_TX_clock $timer2_overflow # Timer 1 overflow - } { + } else { if {$controllers_conf(SMOD)} { incr uart_TX_clock $timer1_overflow - } { + } else { incr uart_TX_clock [expr {$uart_clock_prescaler / 2}] } } @@ -920,7 +931,7 @@ private method uart_controller {num} { if {$uart_clock_prescaler && $controllers_conf(UART_M)} { if {$controllers_conf(SMOD)} { set uart_clock_prescaler [expr {$uart_clock_prescaler % 2}] - } { + } else { set uart_clock_prescaler [expr {$uart_clock_prescaler % 4}] } } @@ -960,11 +971,11 @@ private method special_timer1_controller_T0_MOD_3 {} { } 2 { ;# Mode 2 - 8 bit auto-reload counter incr sfr($TL1) $time - while 1 { + while {1} { if {$sfr($TL1) > 255} { set sfr($TL1) [expr {$sfr($TL1) - 256 + $sfr($TH1)}] incr timer1_overflow - } { + } else { break } } @@ -988,7 +999,7 @@ private method timer_controller_01 {timer_num} { set timer_1_running 1 return } - } { + } else { if {!$timer_0_running} { set timer_0_running 1 return @@ -1014,7 +1025,7 @@ private method timer_controller_01 {timer_num} { set increment 0 } } - } { + } else { set increment $time # Trigered timer @@ -1036,7 +1047,7 @@ private method timer_controller_01 {timer_num} { setBit $symbol(TF1) 1 } # Increment TL0 - } { + } else { incr sfr($symbol(TL0)) $increment if {$sfr($symbol(TL0)) > 255} { set sfr($symbol(TL0)) [expr {$sfr($symbol(TL0)) - 256}] @@ -1088,14 +1099,14 @@ private method timer_controller_01 {timer_num} { } 2 { ;# Mode 2 - 8 bit auto-reload counter incr sfr($TL_addr) $increment - while 1 { + while {1} { if {$sfr($TL_addr) > 255} { set sfr($TL_addr) [expr {$sfr($TL_addr) - 256 + $sfr($TH_addr)}] setBit $symbol(TF${timer_num}) 1 if {$timer_num} { incr timer1_overflow } - } { + } else { break } } @@ -1118,7 +1129,7 @@ private method eeprom_controller {num} { internal_shutdown } - # Fill incomplite bytes with random values + # Fill incomplete bytes with random values set eeprom_prev_new [list] foreach reg $eeprom_prev { lappend eeprom_prev_new [lindex $reg 0] [undefined_octet] @@ -1177,7 +1188,7 @@ private method watchdog_controller {} { } if {$controllers_conf(WDTEN)} { set sfr(167) [expr {$sfr(167) | 1}] - } { + } else { set sfr(167) [expr {$sfr(167) - 1}] } if {$sync_ena} { @@ -1194,15 +1205,15 @@ private method watchdog_controller {} { set increment 0 if {$controllers_conf(WatchDogPrescaler)} { incr wdt_prescaler_val $time - while 1 { + while {1} { if {$wdt_prescaler_val >= $controllers_conf(WatchDogPrescaler)} { incr wdt_prescaler_val -$controllers_conf(WatchDogPrescaler) incr increment - } { + } else { break } } - } { + } else { set increment $time } @@ -1285,7 +1296,9 @@ private method interrupt_handler {IntName vector flag_bit immediately} { lappend inter_in_p_flags $flag_bit ;# List: Interrupt flags of interrupts which are in progress # Adjust status bar - simulator_Sbar [mc "Interrupt PC: 0x%s; line: %s; vector 0x%s " [format %X $pc] [lindex $Line($pc) 0] [format %X $vector]] 1 $this + if {$::GUI_AVAILABLE} { + simulator_Sbar [mc "Interrupt PC: 0x%s; line: %s; vector 0x%s " [format %X $pc] [lindex $Line($pc) 0] [format %X $vector]] 1 $this + } $this pale_interrupt $vector # Invoke LCALL to interrupt vector @@ -1378,14 +1391,14 @@ private method isInterruptActive {IntName} { } {PS} { ;# UART & SPI if {!$controllers_conf(ES)} {return 0} - if {$feature_avaliable(uart)} { + if {$feature_available(uart)} { if {$controllers_conf(TI)} { return {35 TI} } elseif {$controllers_conf(RI)} { return {35 RI} } } - if {$feature_avaliable(spi) && $controllers_conf(SPIE) && $controllers_conf(SPIF)} { + if {$feature_available(spi) && $controllers_conf(SPIE) && $controllers_conf(SPIF)} { return {35 SPIE} } } @@ -1411,3 +1424,7 @@ private method isInterruptActive {IntName} { } return 0 } + +# >>> File inclusion guard +} +# <<< File inclusion guard |