예제 #1
0
 def __init__(self, filename=None):
     if get_simavr_logger() is None:
         init_simavr_logger()
     self.filename = None
     self.backend = elf_firmware_t()
     if filename:
         self.read(filename)
예제 #2
0
    def __init__(self, firmware=None, mcu=None, f_cpu=None, avcc=5, vcc=5):
        '''

        :param mcu: mcu name
        :param f_cpu: frequency in hertz
        :param avcc: avcc in Volt
        :param vcc: vcc in Volt
        '''
        if get_simavr_logger() is None:
            init_simavr_logger()  # Only init logger when it was not initialized before
        self.callbacks_keepalive = [] # External callback instances are stored here just to avoid GC destroying them too early
        self._irq_helper = IRQHelper(self)
        self.avrsize = None
        self.time_marker = 0.0
        self.mcu = mcu
        self.f_cpu = f_cpu
        self._avcc = avcc
        self._vcc = vcc

        if firmware:
            if not self.mcu:
                self.mcu = str(firmware.mcu)
            if not self.f_cpu:
                self.f_cpu = firmware.frequency

        assert self.mcu
        assert self.f_cpu

        log.debug('mcu=%s f_cpu=%s' % (self.mcu, self.f_cpu))

        self.backend = avr_make_mcu_by_name(self.mcu)
        if not self.backend:
            raise UnkwownAvrError('unknown AVR: ' + self.mcu)

        avr_init(self.backend)
        self.backend.frequency = self.f_cpu  # Propagate the freq to the backend

        self._set_voltages()

        avr_start_thread(self.backend)
        self.pause()
        if firmware:
            self.load_firmware(firmware)
        self.uart = Uart(self)
        self.uart.connect()
예제 #3
0
파일: test_1log.py 프로젝트: ponty/pysimavr
def test_custom_logger():
    loggerMethod = Mock()
    #Register custom callback method for simav logs
    logger.init_simavr_logger(loggerMethod)
    avr = Avr(mcu='atmega48', f_cpu=8000000)
    #Let the simavr run in background until it sadly crashes on ramend
    avr.run() 
    while avr.cycle < 8000 and avr.state == cpu_Running :
        time.sleep(0.1)
        
    # Expected:
    #('Starting atmega48 - flashend 0fff ramend 02ff e2end 00ff\n', 3)
    #('atmega48 init\n', 3)
    #('atmega48 reset\n', 3)
    #('avr_sadly_crashed\n', 1)
    eq_(loggerMethod.call_count, 4, "number of callback invocations")
    loggerMethod.assert_called_with('avr_sadly_crashed\n', 1)    
    avr.terminate()
예제 #4
0
def test_custom_logger():
    loggerMethod = Mock()
    #Register custom callback method for simav logs
    logger.init_simavr_logger(loggerMethod)
    avr = Avr(mcu='atmega48', f_cpu=8000000)
    #Let the simavr run in background until it sadly crashes on ramend
    avr.run()
    while avr.cycle < 8000 and avr.state == cpu_Running:
        time.sleep(0.1)

    # Expected:
    #('Starting atmega48 - flashend 0fff ramend 02ff e2end 00ff\n', 3)
    #('atmega48 init\n', 3)
    #('atmega48 reset\n', 3)
    #('avr_sadly_crashed\n', 1)
    eq_(loggerMethod.call_count, 4, "number of callback invocations")
    loggerMethod.assert_called_with('avr_sadly_crashed\n', 1)
    avr.terminate()
예제 #5
0
파일: avr.py 프로젝트: ponty/pysimavr
    def __init__(self, firmware=None, mcu=None, f_cpu=None, avcc=5, vcc=5):
        '''

        :param mcu: mcu name
        :param f_cpu: frequency in hertz
        :param avcc: avcc in Volt
        :param vcc: vcc in Volt
        '''
        if get_simavr_logger() is None:
            init_simavr_logger() #Only init logger when it was not initialized before
        self.avrsize = None
        self.time_marker = 0.0
        self.mcu = mcu
        self.f_cpu = f_cpu
        self._avcc = avcc
        self._vcc = vcc

        if firmware:
            if not self.mcu:
                self.mcu = str(firmware.mcu)
            if not self.f_cpu:
                self.f_cpu = firmware.frequency

        assert self.mcu
        assert self.f_cpu

        log.debug('mcu=%s f_cpu=%s' % (self.mcu, self.f_cpu))

        self.backend = avr_make_mcu_by_name(self.mcu)
        if not self.backend:
            raise UnkwownAvrError('unknown AVR: ' + self.mcu)

        avr_init(self.backend)
        self.backend.frequency = self.f_cpu #Propagate the freq to the backend

        self._set_voltages()

        avr_start_thread(self.backend)
        self.pause()
        if firmware:
            self.load_firmware(firmware)
        self.uart = Uart(self)
        self.uart.connect()
예제 #6
0
파일: avr.py 프로젝트: sanakhan22/pysimavr
    def __init__(self, firmware=None, mcu=None, f_cpu=None, avcc=5, vcc=5):
        '''

        :param mcu: mcu name
        :param f_cpu: frequency in hertz
        :param avcc: avcc in Volt
        :param vcc: vcc in Volt
        '''
        init_simavr_logger()
        self.avrsize = None
        self.time_marker = 0.0
        self.mcu = mcu
        self.f_cpu = f_cpu
        self._avcc = avcc
        self._vcc = vcc

        if firmware:
            if not self.mcu:
                self.mcu = str(firmware.mcu)
            if not self.f_cpu:
                self.f_cpu = firmware.frequency

        assert self.mcu
        assert self.f_cpu

        log.debug('mcu=%s f_cpu=%s' % (self.mcu, self.f_cpu))

        self.backend = avr_make_mcu_by_name(self.mcu)
        if not self.backend:
            raise UnkwownAvrError('unknown AVR: ' + self.mcu)

        avr_init(self.backend)

        self._set_voltages()

        avr_start_thread(self.backend)
        self.pause()
        if firmware:
            self.load_firmware(firmware)
        self.uart = Uart(self)
        self.uart.connect()