File: atmega48.tcl

package info (click to toggle)
simulavr 1.0.0%2Bgit20160221.e53413b-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 5,748 kB
  • sloc: cpp: 35,491; python: 6,991; ansic: 3,567; makefile: 1,072; sh: 653; asm: 414; tcl: 320
file content (136 lines) | stat: -rw-r--r-- 3,331 bytes parent folder | download | duplicates (2)
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
#
#  Anacomp user extension set for simulavr.tcl
#
#  $Id$
#

switch ${extensionPoint} {
  Initialization {}

  CPU {
    if { ! [info exists dev1] } {
      error "MCU Device Required"
    }

    #
    # 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
  }

  Gui {
  }

  GdbCommands {
    if { ! [info exists f] } {
      error "File handle required"
    }
  }
}