File: eeprom_int.py

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 (57 lines) | stat: -rw-r--r-- 1,973 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
from simtestutil import SimTestCase, SimTestLoader
import pysimulavr

class TestCase(SimTestCase):
  
  data_load  = ( 0x00, 0x33)
  data_write = ( 0x00, 0x66)

  DELAY = 5000 # run 5 microseconds
  WDELAY_L = 9000000 # run 9 milliseconds
  WDELAY_M = 4500000 # run 4.5 milliseconds
  WDELAY_S = 3900000 # run 3.9 milliseconds

  def assertComplete(self):
    c = self.sim.getByteByName(self.dev, "complete")
    self.assertEqual(c, 1, "function isn't complete (complete=%d)" % c)

  def assertEepromData(self, data):
    for i in range(len(data)):
      d = data[i]
      v = self.dev.eeprom.ReadFromAddress(i)
      self.assertEqual(v, d, "data in EEPROM[%d]: value=0x%x, expected=0x%x" % (i, v, d))

  def test_00(self):
    """check write eeprom data with interrupt"""
    if self.processorName in ("at90s4433", "at90s8515"):
      self.WDELAY = self.WDELAY_M
    elif self.processorName in ("atmega16", "atmega128", "atmega8"):
      self.WDELAY = self.WDELAY_L
    else:
      self.WDELAY = self.WDELAY_S
    self.assertDevice()
    self.assertStartTime()
    # skip initialisation
    self.assertInitDone()
    # check, that we are not in idle loop ...
    self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 0, "not in idle loop")
    # run till in idle loop
    self.sim.doRun(self.sim.getCurrentTime() + self.DELAY)
    # check, that we are now in idle loop ...
    self.assertEqual(self.sim.getByteByName(self.dev, "in_loop"), 1, "in idle loop")
    # check EEPROM content
    self.assertEepromData(self.data_load)
    # write byte
    self.sim.setByteByName(self.dev, "complete", 2)
    self.sim.doRun(self.sim.getCurrentTime() + self.WDELAY)
    self.assertComplete()
    # check modified EEPROM content
    self.assertEepromData(self.data_write)

if __name__ == '__main__':
  
  from unittest import TextTestRunner
  tests = SimTestLoader("eeprom_int_at90s4433.elf").loadTestsFromTestCase(TestCase)
  TextTestRunner(verbosity = 2).run(tests)

# EOF