1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#! @TCL_WISH@
#load the avr-simulator package
load @top_builddir@/src/.libs/libsimulavr.so
puts "simulavr loaded"
#
# Create new ATMega48 device
#
set dev1 [new_AvrDevice_atmega48]
SimulationMember_trace_on_set $dev1 1
#load elf file to the device
AvrDevice_Load $dev1 "./atmega48.elf"
#set the clock cycle time [ns]
# 1000000000ns/1000000MHz == 1000ns
AvrDevice_SetClockFreq $dev1 1000
#systemclock must know that this device will be stepped from application
set sc [GetSystemClock]
$sc Add $dev1
#
# Create the nets/wires for the SPI bus interface.
#
set netSS [new_Net]
set netSCK [new_Net]
set netMOSI [new_Net]
set netMISO [new_Net]
#
# Set the MOSI pin of the ATMega48 to pullup.
#
[AvrDevice_GetPin $dev1 "B2"] SetOutState $Pin_PULLUP
#
# Attach the ATMega48 SPI bus pins to their nets.
#
$netSS Add [AvrDevice_GetPin $dev1 "B2"]
$netSCK Add [AvrDevice_GetPin $dev1 "B5"]
$netMOSI Add [AvrDevice_GetPin $dev1 "B3"]
$netMISO Add [AvrDevice_GetPin $dev1 "B4"]
#
# Create a SPI bus stimulator. This stimulator continuously
# sends the contents of the "spidata" file to the SPI bus
# /SS, SCLK, and MOSI.
#
SpiSource spiSource "spidata" $netSS $netSCK $netMOSI
#
# Create a SPI bus monitor. This monitor watches the
# state of the /SS, SCLK and MISO SPI signals decodes
# them, and prints the decoded bytes to stdout.
#
SpiSink spiSink $netSS $netSCK $netMISO
#
# String variables for the IRQ output PinMonitor
#
set irqMonPinNameStr "B0"
set irqMonPinDescStr "PORTB0"
set irqMonPinHighStr "NEGATE"
set irqMonPinLowStr "ASSERT"
#
# This commented line did not work since the string "constants" are
# apparently de-allocated after the constructor, and the
# PinMonitor class keeps the pointers, not a copy to
# the strings!
#
# PinMonitor irqmon $dev1 "B0" "/IOP_IRQ" "NEGATE" "ASSERT"
#
# This works, however, because the string variables do not get de-allocated.
#
PinMonitor irqmon $dev1 $irqMonPinNameStr $irqMonPinDescStr $irqMonPinHighStr $irqMonPinLowStr
#
# Create the nets for the analog inputs.
#
set netADC6 [new_Net]
set netADC7 [new_Net]
set netC5 [new_Net]
set netAref [new_Net]
#
# Attach the appropriate ATMega48 analog input pins to their nets.
#
$netADC6 Add [AvrDevice_GetPin $dev1 "ADC6"]
$netADC7 Add [AvrDevice_GetPin $dev1 "ADC7"]
$netC5 Add [AvrDevice_GetPin $dev1 "C5"]
#
# Create the analog simulations for each of the
# three analog inputs that we are demonstrating.
#
AdcPin adc6PinSource "anadata1" $netADC6
AdcPin adc7PinSource "anadata2" $netADC7
AdcPin pc5PinSource "anadata3" $netC5
#
# Attach the AREF input pin to its nets.
#
$netAref Add [AvrDevice_GetPin $dev1 "AREF"]
#
# Create an analog input simulation pin for the reference input.
#
set aRef [new_AdcAnalogPin]
#
# Set the analog voltage reference pin type to ANALOG.
#
$aRef SetOutState $Pin_ANALOG
#
# Attach the simulated voltage reference pin to the AREF net.
#
$netAref Add $aRef
#
# Set the value of the voltage reference (5 volts?)
#
$aRef setAnalogValue 5000000
#
# Add the simulation members to the simulation clock.
#
$sc Add spiSource
$sc Add spiSink
$sc Add adc6PinSource
$sc Add adc7PinSource
$sc Add pc5PinSource
#
# Create a GDB server.
# For the purposes of this demonstration, the GDB server
# does not wait for GDB to attach. Change the last argument
# from 0 to 1 to cause it to wait for a GDB attach before execution.
#
GdbServer gdb1 $dev1 1212 0 0
#
# Add the GDB server to the simulation.
#
$sc Add gdb1
#
# Run the simulation
#
$sc Endless
exit
|