Ejemplo n.º 1
0
    def test_build(self):
        tdir = tmpdir()
        try:

            f = self.feature
            scfg = (
                ZERO_CFG
                + """
            #undef %s  
            #define %s  1
            """
                % (f, f)
            )

            (root / "Nanpy").copytree(tdir / "Nanpy")
            ino = tdir / "Nanpy" / "Nanpy.ino"
            cfg = tdir / "Nanpy" / "cfg.h"

            cfg.write_text(scfg)

            cc = Arduino(mcu=self.mcu)
            print cc.mcu, ino
            cc.build(ino)
            ok_(cc.size().ok)
        finally:
            tdir.rmtree()
Ejemplo n.º 2
0
def warnings(
    filename,
    board='pro',
    hwpack='arduino',
    mcu='',
    f_cpu='',
    extra_lib='',
    ver='',
    #                 home='auto',
    backend='arscons',
):
    '''
    build Arduino sketch and display results
    '''
    cc = Arduino(
        board=board,
        hwpack=hwpack,
        mcu=mcu,
        f_cpu=f_cpu,
        extra_lib=extra_lib,
        ver=ver,
        #                 home=home,
        backend=backend,
    )
    cc.build(filename)

    print 'backend:', cc.backend
    print 'MCU:', cc.mcu_compiler()
    #    print 'avr-gcc:', AvrGcc().version()

    print
    print('=============================================')
    print('SIZE')
    print('=============================================')
    print 'program:', cc.size().program_bytes
    print 'data:', cc.size().data_bytes

    core_warnings = [x for x in cc.warnings if 'gcc' in x
                     ] + [x for x in cc.warnings if 'core' in x]
    lib_warnings = [x for x in cc.warnings if 'lib_' in x]
    notsketch_warnings = core_warnings + lib_warnings
    sketch_warnings = [x for x in cc.warnings if x not in notsketch_warnings]

    print
    print('=============================================')
    print('WARNINGS')
    print('=============================================')
    print
    print('core')
    print('-------------------')
    print('\n'.join(core_warnings))
    print
    print('lib')
    print('-------------------')
    print('\n'.join(lib_warnings))
    print
    print('sketch')
    print('-------------------')
    print('\n'.join(sketch_warnings))
Ejemplo n.º 3
0
def test():
    cc = Arduino()
    cc.build(cc.minprog)
    size = cc.size()
    assert size.program_bytes > 0
    assert size.program_percentage > 0
    assert size.data_bytes > 0
    assert size.data_percentage > 0
Ejemplo n.º 4
0
def warnings(filename,
             board='pro',
             hwpack='arduino',
             mcu='',
                 f_cpu='',
                 extra_lib='',
                 ver='',
             #                 home='auto',
                 backend='arscons',
             ):
    '''
    build Arduino sketch and display results
    '''
    cc = Arduino(
        board=board,
        hwpack=hwpack,
        mcu=mcu,
        f_cpu=f_cpu,
        extra_lib=extra_lib,
        ver=ver,
        #                 home=home,
        backend=backend,
    )
    cc.build(filename)

    print 'backend:', cc.backend
    print 'MCU:', cc.mcu_compiler()
#    print 'avr-gcc:', AvrGcc().version()

    print
    print('=============================================')
    print('SIZE')
    print('=============================================')
    print 'program:', cc.size().program_bytes
    print 'data:', cc.size().data_bytes

    core_warnings = [x for x in cc.warnings if 'gcc' in x] + [
        x for x in cc.warnings if 'core' in x]
    lib_warnings = [x for x in cc.warnings if 'lib_' in x]
    notsketch_warnings = core_warnings + lib_warnings
    sketch_warnings = [x for x in cc.warnings if x not in notsketch_warnings]

    print
    print('=============================================')
    print('WARNINGS')
    print('=============================================')
    print
    print('core')
    print('-------------------')
    print('\n'.join(core_warnings))
    print
    print('lib')
    print('-------------------')
    print('\n'.join(lib_warnings))
    print
    print('sketch')
    print('-------------------')
    print('\n'.join(sketch_warnings))
Ejemplo n.º 5
0
    def test_build(self):
        tdir = tmpdir()
        try:

            f = self.feature
            scfg = '#define %s  1' % f

            (root / 'Nanpy').copytree(tdir / 'Nanpy')
            ino = tdir / 'Nanpy' / 'Nanpy.ino'
            cfg = tdir / 'Nanpy' / 'cfg.h'

            cfg.write_text(scfg)

            cc = Arduino(mcu=self.mcu)
            print cc.mcu, ino
            cc.build(ino)
            ok_(cc.size().ok)
        finally:
            tdir.rmtree()
Ejemplo n.º 6
0
    def test_build(self):
        tdir = tmpdir()
        try:

            f = self.feature
            scfg = '#define %s  1' % f

            (root / 'Nanpy').copytree(tdir / 'Nanpy')
            ino = tdir / 'Nanpy' / 'Nanpy.ino'
            cfg = tdir / 'Nanpy' / 'cfg.h'

            cfg.write_text(scfg)

            cc = Arduino(mcu=self.mcu)
            print cc.mcu, ino
            cc.build(ino)
            ok_(cc.size().ok)
        finally:
            tdir.rmtree()
Ejemplo n.º 7
0
    def test_build(self):
        tdir = tmpdir()
        try:

            p = self.project


            (ROOT / p).copytree(tdir / p)
            ino = first((tdir / p).files('*.ino'))
            if not ino:
                ino = first((tdir / p).files('*.pde'))
            assert ino
                
            cc = Arduino(mcu=self.mcu)
            print cc.mcu, ino
            cc.build(ino)
            ok_(cc.size().ok)
        finally:
            tdir.rmtree()
Ejemplo n.º 8
0
def test_targets():
    boards = 'lilypad mega2560 mega'.split()
#     for ver in ARDUINO_VERSIONS:
#         set_arduino_home(ver)
    if 1:
        for b in boards:

            cc = Arduino(
                board=b,
                #                             home=h,
            )

            try:
                cc.build(Path(__file__).parent / 'min.pde')
                print( '    program size = %s' % cc.size().program_bytes )
                cc.build(cc.minprog)
                print( '    program size = %s' % cc.size().program_bytes )
            except ArduinoCompileError as e:
                print( '    compile error: %s' % cc.error_text.splitlines() )
                raise e
Ejemplo n.º 9
0
class ArduinoSim(object):
    '''arduino code builder and simulator for serial testing'''
    def __init__(self,
                 snippet=None,
                 mcu='atmega48',
                 f_cpu=16000000,
                 extra_lib=None,
                 timespan=0.1,
                 vcd=None,
                 template=None,
                 code=None,
                 serial_in=None,
                 serial_char_logger=None,
                 serial_line_logger=None,
                 fps=None,
                 speed=1,
                 external_elf=None
                 ):
        self.cc = Arduino(mcu=mcu, f_cpu=f_cpu, extra_lib=extra_lib)
        if template:
            self.template = template
        else:
            self.template = TEMPLATE
        self.snippet = snippet
        self.code = code
        self.timespan = timespan  # 10ms
        self.vcd = vcd
        self.serial = ''
        self.serial_in = serial_in
        self.serial_char_logger = serial_char_logger
        self.serial_line_logger = serial_line_logger
        self.fps = fps
        self.speed = speed
        self.external_elf = external_elf

    @property
    def mcu(self):
        return self.cc.mcu

    @mcu.setter
    def mcu(self, value):
        self.cc.mcu = value

    def build(self):
        code = self.code
        if not self.external_elf:
            if not code:
                code = self.template.replace('snippet', self.snippet)
            log.debug('code=%s' % code)
            self.cc.build(code)

    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()

    def run(self):
        if not self.external_elf:
            self.build()
        self.simulate()

    def get_serial(self):
        self.run()
        return self.serial

    def size(self):
        self.build()
        return self.cc.size()
Ejemplo n.º 10
0
def check_build(ex, hwpack, board):
    cc = Arduino(hwpack=hwpack, board=board)
#    cc.extra_lib = root
    print cc.hwpack, cc.board, ex
    cc.build(ex)
    assert cc.size().ok
Ejemplo n.º 11
0
class ArduinoSim(object):
    '''arduino code builder and simulator for serial testing'''
    def __init__(self,
                 snippet=None,
                 mcu='atmega48',
                 f_cpu=16000000,
                 extra_lib=None,
                 timespan=0.1,
                 vcd=None,
                 template=None,
                 code=None,
                 serial_in=None,
                 serial_char_logger=None,
                 serial_line_logger=None,
                 fps=None,
                 speed=1,
                 external_elf=None):
        self.cc = Arduino(mcu=mcu, f_cpu=f_cpu, extra_lib=extra_lib)
        if template:
            self.template = template
        else:
            self.template = TEMPLATE
        self.snippet = snippet
        self.code = code
        self.timespan = timespan  # 10ms
        self.vcd = vcd
        self.serial = ''
        self.serial_in = serial_in
        self.serial_char_logger = serial_char_logger
        self.serial_line_logger = serial_line_logger
        self.fps = fps
        self.speed = speed
        self.external_elf = external_elf

    @property
    def mcu(self):
        return self.cc.mcu

    @mcu.setter
    def mcu(self, value):
        self.cc.mcu = value

    def build(self):
        code = self.code
        if not self.external_elf:
            if not code:
                code = self.template.replace('snippet', self.snippet)
            log.debug('code=%s' % code)
            self.cc.build(code)

    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()

    def run(self):
        if not self.external_elf:
            self.build()
        self.simulate()

    def get_serial(self):
        self.run()
        return self.serial

    def size(self):
        self.build()
        return self.cc.size()
Ejemplo n.º 12
0
class ArduinoSim(object):
    '''arduino code builder and simulator for serial testing'''
    def __init__(self,
                 snippet=None,
                 mcu='atmega328',
                 f_cpu=16000000,
                 extra_lib=None,
                 timespan=0.01,
                 vcd=None,
                 template=None,
                 code=None,
                 ):
        self.cc = Arduino(mcu=mcu, f_cpu=f_cpu, extra_lib=extra_lib)
        if template:
            self.template = template
        else:
            self.template = TEMPLATE
        self.snippet = snippet
        self.code = code
        self.timespan = timespan # 10ms
        self.vcd = vcd
        self.serial = ''
    
    @property
    def mcu(self):
        return self.cc.mcu

    @mcu.setter
    def mcu(self, value):
        self.cc.mcu = value
   
    def build(self):
        code = self.code
        if not code:
            code = self.template.replace('snippet', self.snippet)
        log.debug('code=%s' % code)
        self.cc.build(code)

    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()
            
        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 = udpReader.read()    
        
    def run(self):
        self.build()
        self.simulate()

    def get_serial(self):
        self.run()
        return self.serial
    
    def size(self):
        self.build()
        return self.cc.size()
Ejemplo n.º 13
0
def check_build(ex, mcu):
    cc = Arduino(mcu=mcu)
    #    cc.extra_lib = root
    print cc.mcu, ex
    cc.build(ex)
    assert cc.size().ok
Ejemplo n.º 14
0
def check_build(ex, mcu):
    cc = Arduino(mcu=mcu)
    #    cc.extra_lib = root
    print cc.mcu, ex
    cc.build(ex)
    assert cc.size().ok