File: ext_pcint.py

package info (click to toggle)
simulavr 1.0.0%2Bgit20160221.e53413b-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,740 kB
  • sloc: cpp: 35,491; python: 6,995; ansic: 3,567; makefile: 1,075; sh: 653; asm: 414; tcl: 320; javascript: 32
file content (139 lines) | stat: -rw-r--r-- 3,517 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
137
138
139
from simtestutil import SimTestLoader

import ext_int0

class TestCase(ext_int0.TestCaseBase):
  
  portmask = {
    "atmega48":   0x7f, # only 7 bit at port C
    "attiny2313": 0xff,
  }
  bit0name = {
    "atmega48":   "C0",
    "attiny2313": "B0",
  }
  bit3name = {
    "atmega48":   "C3",
    "attiny2313": "B3",
  }
  
  def setControl(self, ctrl):
    self.handshake(4, ctrl)
    
  def assertPortValue(self, val):
    val = val & self.portmask[self.processorName]
    v = self.handshake(5)
    self.assertEqual(v, val, "port input value wrong: got=%d, exp=%d" % (v, val))
    
  def test_00(self):
    """check interrupt on any change"""
    self.assertDevice()
    self.assertStartTime()
    # skip initialisation
    self.assertInitDone()
    # create Pin
    p = ext_int0.XPin(self.dev, self.sim, self.bit0name[self.processorName])
    # check port value
    self.assertPortValue(0xff)
    # ext pin = low
    p.SetPin("L")
    # mask only bit 0
    self.setControl(1)
    self.resetFlag()
    self.enableIRQ()
    # counter is 0?
    self.assertCounter(0, 10000)
    # ext pin = high
    p.SetPin("H")
    # counter is 1?
    self.assertCounter(1, 20000)
    # ext pin = low
    p.SetPin("L")
    # counter is 2?
    self.assertCounter(2, 20000)
    # ext pin = high
    p.SetPin("H")
    # counter is 3?
    self.assertCounter(3, 20000)
    
  def test_01(self):
    """check masking input bits"""
    self.assertDevice()
    self.assertStartTime()
    # skip initialisation
    self.assertInitDone()
    # create Pin
    p0 = ext_int0.XPin(self.dev, self.sim, self.bit0name[self.processorName])
    p3 = ext_int0.XPin(self.dev, self.sim, self.bit3name[self.processorName])
    # check port value
    self.assertPortValue(0xff)
    # ext pin 0 = low, pin 3 = high
    p0.SetPin("L")
    p3.SetPin("H")
    # mask only bit 0
    self.setControl(1)
    self.resetFlag()
    self.enableIRQ()
    # counter is 0?
    self.assertCounter(0, 10000)
    # ext pin 3 = low
    p3.SetPin("L")
    # counter is 0?
    self.assertCounter(0, 20000)
    # ext pin 0 = high
    p0.SetPin("H")
    # counter is 1?
    self.assertCounter(1, 20000)
    # mask bit 0 and 3
    self.setControl(9)
    # ext pin 3 = high
    p3.SetPin("H")
    # counter is 3?
    self.assertCounter(2, 20000)
    
  def test_02(self):
    """check set and reset flag bit"""
    self.assertDevice()
    self.assertStartTime()
    # skip initialisation
    self.assertInitDone()
    # create Pin
    p0 = ext_int0.XPin(self.dev, self.sim, self.bit0name[self.processorName])
    p3 = ext_int0.XPin(self.dev, self.sim, self.bit3name[self.processorName])
    # check port value
    self.assertPortValue(0xff)
    # ext pin 0 = low, pin 3 = high
    p0.SetPin("L")
    p3.SetPin("H")
    # check port value
    self.assertPortValue(0xfe)
    # mask bit 0 and 3
    self.setControl(9)
    self.resetFlag()
    # check flag
    self.assertFlagReg(False)
    # ext pin 3 = low
    p3.SetPin("L")
    # check port value
    self.assertPortValue(0xf6)
    # check flag
    self.assertFlagReg(True)
    # reset flag
    self.resetFlag()
    self.assertFlagReg(False)
    # mask bit 3
    self.setControl(8)
    # ext pin 0 = high
    p0.SetPin("H")
    # check port value
    self.assertPortValue(0xf7)
    # check flag
    self.assertFlagReg(False)
    
if __name__ == '__main__':
  
  from unittest import TextTestRunner
  tests = SimTestLoader("ext_int2_atmega16.elf").loadTestsFromTestCase(TestCase)
  TextTestRunner(verbosity = 2).run(tests)

# EOF