summaryrefslogtreecommitdiff
path: root/lib/simulator/engine/engine_virtual_hw_controller.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/simulator/engine/engine_virtual_hw_controller.tcl')
-rw-r--r--[-rwxr-xr-x]lib/simulator/engine/engine_virtual_hw_controller.tcl143
1 files changed, 80 insertions, 63 deletions
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