Esempio n. 1
0
    def simulate(self):
        elf = self.cc.output

        # run
        firmware = Firmware(elf)
        avr = Avr(mcu=self.cc.mcu, f_cpu=self.cc.f_cpu)
        avr.load_firmware(firmware)
#        udpReader = UdpReader()
#        udp = Udp(avr)
#        udp.connect()
#        udpReader.start()

        simvcd = None
        if self.vcd:
            simvcd = VcdFile(avr, period=1000, filename=self.vcd)
            connect_pins_by_rule('''
                                avr.D0 ==> vcd
                                avr.D1 ==> vcd
                                avr.D2 ==> vcd
                                avr.D3 ==> vcd
                                avr.D4 ==> vcd
                                avr.D5 ==> vcd
                                avr.D6 ==> vcd
                                avr.D7 ==> vcd

                                avr.B0 ==> vcd
                                avr.B1 ==> vcd
                                avr.B2 ==> vcd
                                avr.B3 ==> vcd
                                avr.B4 ==> vcd
                                avr.B5 ==> vcd
                                ''',
                                 dict(
                                 avr=avr,
                                 ),
                                 vcd=simvcd,
                                 )
            simvcd.start()

# not working
#        if self.serial_in:
#            avr.uart.send_string(self.serial_in)
        avr.move_time_marker(self.timespan)

        while avr.time_passed() < self.timespan * 0.99:
            time.sleep(0.05)

        if simvcd:
            simvcd.terminate()
#        udpReader.terminate()

        log.debug('cycles=%s' % avr.cycle)
        log.debug('mcu time=%s' % avr.time_passed())
#        time.sleep(1)
        self.serial_data = avr.uart.buffer
        self.serial = ''.join(self.serial_data)
        avr.terminate()
Esempio n. 2
0
    def simulate(self):
        if not self.external_elf:
            elf = self.cc.output
        else:
            elf = self.external_elf

        # run
        firmware = Firmware(elf)
        avr = Avr(mcu=self.cc.mcu, f_cpu=self.cc.f_cpu)
        avr.uart.char_logger = self.serial_char_logger
        avr.uart.line_logger = self.serial_line_logger
        avr.load_firmware(firmware)
#        udpReader = UdpReader()
#        udp = Udp(avr)
#        udp.connect()
#        udpReader.start()

        simvcd = None
        if self.vcd:
            simvcd = VcdFile(avr, period=1000, filename=self.vcd)
            connect_pins_by_rule('''
                                avr.D0 ==> vcd
                                avr.D1 ==> vcd
                                avr.D2 ==> vcd
                                avr.D3 ==> vcd
                                avr.D4 ==> vcd
                                avr.D5 ==> vcd
                                avr.D6 ==> vcd
                                avr.D7 ==> vcd

                                avr.B0 ==> vcd
                                avr.B1 ==> vcd
                                avr.B2 ==> vcd
                                avr.B3 ==> vcd
                                avr.B4 ==> vcd
                                avr.B5 ==> vcd
                                ''',
                                 dict(
                                 avr=avr,
                                 ),
                                 vcd=simvcd,
                                 )
            simvcd.start()

# not working
#        if self.serial_in:
#            avr.uart.send_string(self.serial_in)

        if self.fps:
            dt_real = 1. / self.fps
            dt_mcu = dt_real * self.speed
            count = int(self.timespan * self.fps / self.speed)
            for _ in range(count):
                time.sleep(dt_real)

        avr.goto_time(self.timespan)
        while avr.time_passed() < self.timespan * 0.99:
            time.sleep(0.05)

        if simvcd:
            simvcd.terminate()
#        udpReader.terminate()

        log.debug('cycles=%s' % avr.cycle)
        log.debug('mcu time=%s' % avr.time_passed())
#        time.sleep(1)
        self.serial_data = avr.uart.buffer
        self.serial = ''.join(self.serial_data)
        avr.terminate()
Esempio n. 3
0
    def simulate(self):
        if not self.external_elf:
            elf = self.cc.output
        else:
            elf = self.external_elf

        # run
        firmware = Firmware(elf)
        avr = Avr(mcu=self.cc.mcu, f_cpu=self.cc.f_cpu)
        avr.uart.char_logger = self.serial_char_logger
        avr.uart.line_logger = self.serial_line_logger
        avr.load_firmware(firmware)
        #        udpReader = UdpReader()
        #        udp = Udp(avr)
        #        udp.connect()
        #        udpReader.start()

        simvcd = None
        if self.vcd:
            simvcd = VcdFile(avr, period=1000, filename=self.vcd)
            connect_pins_by_rule(
                '''
                                avr.D0 ==> vcd
                                avr.D1 ==> vcd
                                avr.D2 ==> vcd
                                avr.D3 ==> vcd
                                avr.D4 ==> vcd
                                avr.D5 ==> vcd
                                avr.D6 ==> vcd
                                avr.D7 ==> vcd

                                avr.B0 ==> vcd
                                avr.B1 ==> vcd
                                avr.B2 ==> vcd
                                avr.B3 ==> vcd
                                avr.B4 ==> vcd
                                avr.B5 ==> vcd
                                ''',
                dict(avr=avr, ),
                vcd=simvcd,
            )
            simvcd.start()

# not working
#        if self.serial_in:
#            avr.uart.send_string(self.serial_in)

        if self.fps:
            dt_real = 1. / self.fps
            dt_mcu = dt_real * self.speed
            count = int(self.timespan * self.fps / self.speed)
            for _ in range(count):
                time.sleep(dt_real)

        avr.goto_time(self.timespan)
        while avr.time_passed() < self.timespan * 0.99:
            time.sleep(0.05)

        if simvcd:
            simvcd.terminate()
#        udpReader.terminate()

        log.debug('cycles=%s' % avr.cycle)
        log.debug('mcu time=%s' % avr.time_passed())
        #        time.sleep(1)
        self.serial_data = avr.uart.buffer
        self.serial = ''.join(self.serial_data)
        avr.terminate()
Esempio n. 4
0
class TestBase(unittest.TestCase):

    def setUp(self):
        self.first = True
        self.startAvr();
        pass

    def tearDown(self):
        self.uartBridge.terminate()        
        self.avr.terminate()
        pass

    def messageSanityCheck(self, bytes, commandId, expectedSize, first):
        '''
        Check that the response has correct size, message Id, checksum 
        @param bytes: list of bytes
        @param commandId: message identifier
        @param expectedSize: expected size of the response
        @param first: is is a first response  
        @raise exception: unittest.TestCase.assertEqual 
        @return: None
        '''
        if (expectedSize != None):
            self.assertEqual(len(bytes), expectedSize, "Message length "+str(len(bytes))+", expected size "+str(expectedSize));
        self.assertEqual(bytes[0], 0x7f, "1st sync byte is "+str(bytes[0]));                             
        self.assertEqual(bytes[1], 0xef, "2nd sync byte is "+str(bytes[1]));                             
        if (first):                                                                                      
            self.assertEqual(bytes[2], commandId, "Message id "+str(bytes[2]));                               
        else:                                                                                            
            self.assertEqual(bytes[2], commandId | 0x80, "Message id "+str(bytes[2]));                               
        self.assertEqual(bytes[3], expectedSize-4, "Payload size is "+str(bytes[3]));                              
                                                                                                         
        bytesWithoutChecksum = bytes[:-1]                                                                
        csExpected = calculateChecksum(bytesWithoutChecksum)                                             
        csActual = bytes[len(bytes)-1]                                                                              
        self.assertEqual(csActual, csExpected, "Checksum is "+hex(csActual)+" instead "+hex(csExpected));

    def startAvr(self):
        self.avr = Avr(mcu='atmega88',f_cpu=8000000)
        
        self.udp = Udp(self.avr)
        self.udp.connect()

        self.uartBridge = UartBridge()
        
        firmware = Firmware(ELFNAME)
        self.avr.load_firmware(firmware);

        self.uartBridge.start();
        self.avr.run()
        #self.time_passed();
        
    def time_passed(self, timeout=0.99):
        while self.avr.time_passed() < 0.1 * timeout:
            time.sleep(0.05)
    

    def sendCommand(self, command, payload):
        syncBytes = [0x7f, 0xef];
        command = syncBytes + command + [len(payload)+1] + payload;
        cs = calculateChecksum(command)
        command = command + [cs];
        
        s = str(bytearray(command))
        self.uartBridge.send_str(s);
        self.time_passed(0.05*len(s))