├── .sonarcloud.properties ├── .travis.yml ├── AUTHORS.txt ├── CMakeLists.txt ├── COPYING ├── DEVICES.txt ├── INSTALL.txt ├── README.md ├── cmake ├── Filename.cmake ├── FindReadline.cmake ├── Findcppcheck.cmake ├── Findcppcheck.cpp └── Subdirlist.cmake ├── examples ├── ATMEGA8A-pwm-to-sine │ ├── README.md │ ├── firmware.conf │ ├── firmware.hex │ ├── firmware │ │ ├── CMakeLists.txt │ │ ├── fuse.c │ │ └── main.c │ ├── ngspice-simulation.png │ ├── pwm-to-sine.cir │ └── pwm-to-sine.png └── CMakeLists.txt ├── include └── mcusim │ ├── avr │ ├── boot.h │ ├── builtins.h │ ├── common.h │ ├── cpufunc.h │ ├── crc16.h │ ├── delay.h │ ├── eeprom.h │ ├── fuse.h │ ├── interrupt.h │ ├── io.h │ ├── iom2560.h │ ├── iom328.h │ ├── iom328p.h │ ├── iom8a.h │ ├── iomxx0_1.h │ ├── lock.h │ ├── parity.h │ ├── pgmspace.h │ ├── portpins.h │ ├── power.h │ ├── sfr_defs.h │ ├── signal.h │ ├── signature.h │ ├── sim │ │ ├── bootloader.h │ │ ├── decoder.h │ │ ├── gdb.h │ │ ├── init.h │ │ ├── interrupt.h │ │ ├── io.h │ │ ├── io_regs.h │ │ ├── lua.h │ │ ├── luaapi.h │ │ ├── m2560 │ │ │ ├── m2560.h │ │ │ └── m2560_ioregs.h │ │ ├── m328 │ │ │ ├── m328.h │ │ │ ├── m328_ioregs.h │ │ │ └── m328p.h │ │ ├── m8 │ │ │ ├── m8_ioregs.h │ │ │ └── m8a.h │ │ ├── mcu_init.h │ │ ├── private │ │ │ ├── io_macro.h │ │ │ └── macro.h │ │ ├── sim.h │ │ ├── simcore.h │ │ ├── timer.h │ │ ├── usart.h │ │ ├── vcd.h │ │ └── wdt.h │ ├── sleep.h │ ├── version.h │ ├── wdt.h │ └── xmega.h │ ├── bit │ └── private │ │ └── macro.h │ ├── config.h │ ├── getopt.h │ ├── hex │ └── ihex.h │ ├── log.h │ ├── mcusim.h │ ├── pty.h │ └── tsq.h ├── misra ├── CMakeLists.txt ├── cppcheckdata.py ├── misra.cmake.in └── misra.py ├── scripts ├── CMakeLists.txt ├── install-hooks.sh ├── lua │ └── external │ │ ├── dht11.lua │ │ └── stop-in-5s.lua ├── mcusim.conf.in ├── pre-commit.sh └── reinstall-hooks.sh ├── sonar-project.properties ├── src ├── avr │ ├── avr_decoder.c │ ├── avr_gdb.c │ ├── avr_io.c │ ├── avr_lua.c │ ├── avr_luaapi.c │ ├── avr_m2560.c │ ├── avr_m328.c │ ├── avr_m328p.c │ ├── avr_m8a.c │ ├── avr_simcore.c │ ├── avr_timer.c │ ├── avr_vcd.c │ └── avr_wdt.c ├── msim_config.c ├── msim_getopt.c ├── msim_ihex.c ├── msim_log.c ├── msim_main.c ├── msim_pty.c └── msim_tsq.c ├── tests ├── CMakeLists.txt ├── atmega328 │ └── output-toggle │ │ ├── check-output.lua │ │ ├── firmware.c │ │ ├── firmware.hex │ │ ├── firmware.hex.txt │ │ ├── mcusim.conf │ │ └── stop-in-5s.lua ├── atmega328p │ ├── timer0-ctc │ │ ├── firmware.hex │ │ ├── main.c │ │ ├── mcusim.conf │ │ └── stop-test.lua │ ├── timer1-ctc-with-input-capture │ │ ├── CMakeLists.txt │ │ ├── check-pin.lua │ │ ├── firmware.hex │ │ ├── firmware.hex.txt │ │ ├── fuse.c │ │ ├── main.c │ │ ├── mcusim.conf │ │ └── toggle-icp1.lua │ ├── timer1-pcpwm │ │ ├── CMakeLists.txt │ │ ├── check-pb2-falls.lua │ │ ├── check-pb2-rises.lua │ │ ├── firmware.hex │ │ ├── firmware.hex.txt │ │ ├── fuse.c │ │ ├── main.c │ │ └── mcusim.conf │ ├── timer1-pfcpwm │ │ ├── CMakeLists.txt │ │ ├── check-pb2-falls.lua │ │ ├── check-pb2-rises.lua │ │ ├── firmware.hex │ │ ├── firmware.hex.txt │ │ ├── fuse.c │ │ ├── main.c │ │ └── mcusim.conf │ ├── toggle-pin │ │ ├── CMakeLists.txt │ │ ├── check-pin.lua │ │ ├── firmware.hex │ │ ├── firmware.hex.txt │ │ ├── fuse.c │ │ ├── main.c │ │ └── mcusim.conf │ └── wdt-interrupt │ │ ├── CMakeLists.txt │ │ ├── fuse.c │ │ ├── main.c │ │ └── mcusim.conf.off ├── atmega8a │ ├── timer0-ext-clock-source │ │ ├── CMakeLists.txt │ │ ├── check-timer0.lua │ │ ├── external-clock.lua │ │ ├── firmware.hex │ │ ├── fuse.c │ │ ├── main.c │ │ └── mcusim.conf │ ├── timer0-normal │ │ ├── .mcusim.flash │ │ ├── CMakeLists.txt │ │ ├── check-timer0.lua │ │ ├── firmware.hex │ │ ├── firmware.hex.txt │ │ ├── fuse.c │ │ ├── main.c │ │ └── mcusim.conf │ ├── timer1-fastpwm │ │ ├── CMakeLists.txt │ │ ├── firmware.hex │ │ ├── firmware.hex.txt │ │ ├── fuse.c │ │ ├── main.c │ │ ├── mcusim.conf │ │ └── stop-test.lua │ ├── timer1-normal │ │ ├── .mcusim.flash │ │ ├── CMakeLists.txt │ │ ├── check-timer1.lua │ │ ├── firmware.hex │ │ ├── fuse.c │ │ ├── main.c │ │ └── mcusim.conf │ ├── timer2-ctc │ │ ├── CMakeLists.txt │ │ ├── check_OCR2_updated.lua │ │ ├── firmware.hex │ │ ├── firmware.hex.txt │ │ ├── fuse.c │ │ ├── main.c │ │ ├── mcusim.conf │ │ └── stop-test.lua │ ├── timer2-fastpwm │ │ ├── CMakeLists.txt │ │ ├── check-pb3.lua │ │ ├── firmware.hex │ │ ├── firmware.hex.txt │ │ ├── fuse.c │ │ ├── main.c │ │ └── mcusim.conf │ ├── timer2-pcpwm │ │ ├── CMakeLists.txt │ │ ├── check-pb3-falls.lua │ │ ├── check-pb3-rises.lua │ │ ├── firmware.hex │ │ ├── firmware.hex.txt │ │ ├── fuse.c │ │ ├── main.c │ │ └── mcusim.conf │ ├── toggle-pin │ │ ├── CMakeLists.txt │ │ ├── fuse.c │ │ ├── m8a-clockpin.hex │ │ ├── m8a-clockpin.hex.txt │ │ ├── main.cpp │ │ ├── mcusim.conf │ │ └── stop-test.lua │ └── usart-optiboot │ │ ├── README │ │ ├── m8a-clockpin.hex │ │ ├── m8a-clockpin.hex.txt │ │ ├── mcusim.conf.off │ │ ├── optiboot_m8a_16MHz_57600.hex │ │ └── optiboot_m8a_16MHz_57600.hex.txt ├── ft │ ├── CMakeLists.txt │ ├── XlingFirmware.ft.c │ ├── XlingFirmware_1.ft.c │ ├── files │ │ ├── XlingFirmware.dm_0_0000.hex │ │ ├── XlingFirmware.dm_100_6F5.hex │ │ ├── XlingFirmware.dm_101_6F6.hex │ │ ├── XlingFirmware.dm_102_57B.hex │ │ ├── XlingFirmware.dm_10_249.hex │ │ ├── XlingFirmware.dm_11_24A.hex │ │ ├── XlingFirmware.dm_12_24B.hex │ │ ├── XlingFirmware.dm_13_251.hex │ │ ├── XlingFirmware.dm_14_252.hex │ │ ├── XlingFirmware.dm_15_253.hex │ │ ├── XlingFirmware.dm_16_254.hex │ │ ├── XlingFirmware.dm_17_259.hex │ │ ├── XlingFirmware.dm_18_25F.hex │ │ ├── XlingFirmware.dm_19_260.hex │ │ ├── XlingFirmware.dm_1_240.hex │ │ ├── XlingFirmware.dm_20_261.hex │ │ ├── XlingFirmware.dm_21_262.hex │ │ ├── XlingFirmware.dm_22_263.hex │ │ ├── XlingFirmware.dm_23_264.hex │ │ ├── XlingFirmware.dm_24_265.hex │ │ ├── XlingFirmware.dm_25_266.hex │ │ ├── XlingFirmware.dm_26_267.hex │ │ ├── XlingFirmware.dm_27_268.hex │ │ ├── XlingFirmware.dm_29_26A.hex │ │ ├── XlingFirmware.dm_2_241.hex │ │ ├── XlingFirmware.dm_30_26B.hex │ │ ├── XlingFirmware.dm_31_26C.hex │ │ ├── XlingFirmware.dm_32_26D.hex │ │ ├── XlingFirmware.dm_33_26E.hex │ │ ├── XlingFirmware.dm_34_26F.hex │ │ ├── XlingFirmware.dm_35_270.hex │ │ ├── XlingFirmware.dm_36_271.hex │ │ ├── XlingFirmware.dm_37_272.hex │ │ ├── XlingFirmware.dm_38_275.hex │ │ ├── XlingFirmware.dm_39_276.hex │ │ ├── XlingFirmware.dm_3_242.hex │ │ ├── XlingFirmware.dm_40_277.hex │ │ ├── XlingFirmware.dm_41_278.hex │ │ ├── XlingFirmware.dm_42_279.hex │ │ ├── XlingFirmware.dm_43_27C.hex │ │ ├── XlingFirmware.dm_44_27D.hex │ │ ├── XlingFirmware.dm_45_27E.hex │ │ ├── XlingFirmware.dm_46_27F.hex │ │ ├── XlingFirmware.dm_47_280.hex │ │ ├── XlingFirmware.dm_48_283.hex │ │ ├── XlingFirmware.dm_49_284.hex │ │ ├── XlingFirmware.dm_4_243.hex │ │ ├── XlingFirmware.dm_50_285.hex │ │ ├── XlingFirmware.dm_51_286.hex │ │ ├── XlingFirmware.dm_52_287.hex │ │ ├── XlingFirmware.dm_53_288.hex │ │ ├── XlingFirmware.dm_54_28D.hex │ │ ├── XlingFirmware.dm_55_28E.hex │ │ ├── XlingFirmware.dm_56_28F.hex │ │ ├── XlingFirmware.dm_57_290.hex │ │ ├── XlingFirmware.dm_58_291.hex │ │ ├── XlingFirmware.dm_59_576.hex │ │ ├── XlingFirmware.dm_5_244.hex │ │ ├── XlingFirmware.dm_60_577.hex │ │ ├── XlingFirmware.dm_61_578.hex │ │ ├── XlingFirmware.dm_62_579.hex │ │ ├── XlingFirmware.dm_63_6C0.hex │ │ ├── XlingFirmware.dm_64_6C1.hex │ │ ├── XlingFirmware.dm_65_6C2.hex │ │ ├── XlingFirmware.dm_66_6C3.hex │ │ ├── XlingFirmware.dm_67_6C4.hex │ │ ├── XlingFirmware.dm_68_6C5.hex │ │ ├── XlingFirmware.dm_69_6C6.hex │ │ ├── XlingFirmware.dm_6_245.hex │ │ ├── XlingFirmware.dm_70_6C7.hex │ │ ├── XlingFirmware.dm_71_6C8.hex │ │ ├── XlingFirmware.dm_72_6CD.hex │ │ ├── XlingFirmware.dm_73_6CE.hex │ │ ├── XlingFirmware.dm_74_6CF.hex │ │ ├── XlingFirmware.dm_75_6D0.hex │ │ ├── XlingFirmware.dm_76_6D1.hex │ │ ├── XlingFirmware.dm_77_6D2.hex │ │ ├── XlingFirmware.dm_78_6D3.hex │ │ ├── XlingFirmware.dm_79_6D4.hex │ │ ├── XlingFirmware.dm_7_246.hex │ │ ├── XlingFirmware.dm_80_6D5.hex │ │ ├── XlingFirmware.dm_81_6D6.hex │ │ ├── XlingFirmware.dm_82_6DB.hex │ │ ├── XlingFirmware.dm_83_6DC.hex │ │ ├── XlingFirmware.dm_84_6DD.hex │ │ ├── XlingFirmware.dm_85_6DE.hex │ │ ├── XlingFirmware.dm_86_6DF.hex │ │ ├── XlingFirmware.dm_87_6E0.hex │ │ ├── XlingFirmware.dm_88_6E1.hex │ │ ├── XlingFirmware.dm_89_6E2.hex │ │ ├── XlingFirmware.dm_8_247.hex │ │ ├── XlingFirmware.dm_90_6E3.hex │ │ ├── XlingFirmware.dm_91_6E4.hex │ │ ├── XlingFirmware.dm_92_6E9.hex │ │ ├── XlingFirmware.dm_93_6EA.hex │ │ ├── XlingFirmware.dm_94_6EB.hex │ │ ├── XlingFirmware.dm_95_6EC.hex │ │ ├── XlingFirmware.dm_96_6ED.hex │ │ ├── XlingFirmware.dm_97_6EE.hex │ │ ├── XlingFirmware.dm_98_6EF.hex │ │ ├── XlingFirmware.dm_99_6F4.hex │ │ ├── XlingFirmware.dm_9_248.hex │ │ ├── XlingFirmware.ft.conf │ │ ├── XlingFirmware.hex │ │ ├── XlingFirmware.hex.sha1 │ │ ├── XlingFirmware_1.dm_0_0000.hex │ │ ├── XlingFirmware_1.dm_10_589.hex │ │ ├── XlingFirmware_1.dm_11_58C.hex │ │ ├── XlingFirmware_1.dm_12_58F.hex │ │ ├── XlingFirmware_1.dm_13_592.hex │ │ ├── XlingFirmware_1.dm_14_593.hex │ │ ├── XlingFirmware_1.dm_15_594.hex │ │ ├── XlingFirmware_1.dm_1_57C.hex │ │ ├── XlingFirmware_1.dm_2_57D.hex │ │ ├── XlingFirmware_1.dm_3_57E.hex │ │ ├── XlingFirmware_1.dm_4_57F.hex │ │ ├── XlingFirmware_1.dm_5_580.hex │ │ ├── XlingFirmware_1.dm_6_581.hex │ │ ├── XlingFirmware_1.dm_7_582.hex │ │ ├── XlingFirmware_1.dm_8_585.hex │ │ ├── XlingFirmware_1.dm_9_586.hex │ │ ├── XlingFirmware_1.ft.conf │ │ ├── XlingFirmware_1.hex │ │ └── XlingFirmware_1.hex.sha1 │ └── tests.cmake.in └── tests.cmake.in └── xspice ├── CMakeLists.txt ├── ngspice-0001-add-library-name.patch ├── ngspice-0002-add-flags.patch.in ├── ngspice-30.tar.gz ├── patch-ngspice-sources └── src └── xspice └── icm └── mcusim ├── m8a ├── cfunc.mod.c └── ifspec.ifs ├── modpath.lst └── udnpath.lst /.sonarcloud.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcusim/MCUSim/3a5153f0e1d9abbc878e38e2f0edad78e906a0d1/.sonarcloud.properties -------------------------------------------------------------------------------- /AUTHORS.txt: -------------------------------------------------------------------------------- 1 | The following people have contributed in some way: 2 | 3 | Dmitry Salychev, 4 | Alexander Salychev, 5 | Pawel Obarzanek, 6 | Darren Kulp 7 | 8 | If someone helped in the development and has not been inserted in this list 9 | then this omission was unintentional. If you feel you should be on this list 10 | then please write to . Do not be shy, 11 | we would like to make a list as complete as possible. 12 | -------------------------------------------------------------------------------- /DEVICES.txt: -------------------------------------------------------------------------------- 1 | List of supported devices 2 | ------------------------- 3 | 4 | This is a list of microcontrollers supported by MCUSim. 5 | 6 | Second column of a table below is a short form which can be used as an 7 | MCU model in the configuration file. Supported peripherals are in a third 8 | column. 9 | 10 | Table of devices 11 | ---------------- 12 | 13 | Name Part Supported features 14 | 15 | ATmega8A m8a init, fuses, timers, interrupts (partially), 16 | USART (partially) 17 | ATmega8 m8 same as ATmega8A 18 | ATmega328P m328p init, fuses, timers (partially) 19 | ATmega328 m328 init 20 | 21 | -------------------------------------------------------------------------------- /cmake/Filename.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | # 4 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | # 6 | # MCUSim is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # MCUSim is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | # Helper function to add preprocesor definition of __MSIM_FILENAME__ to pass 21 | # the filename without directory path and a longest extension for 22 | # debugging use. 23 | # 24 | # Example: 25 | # 26 | # define_filename_for_sources(my_target) 27 | # 28 | # Will add -D__MSIM_FILENAME__="filename" for each source file depended on 29 | # by my_target, where filename is the name of the file. 30 | # 31 | # Source: https://stackoverflow.com/a/27990434 32 | # 33 | function(define_filename_for_sources targetname) 34 | get_target_property(source_files "${targetname}" SOURCES) 35 | 36 | foreach(sourcefile ${source_files}) 37 | # Get source file's current list of compile definitions. 38 | get_property(defs SOURCE "${sourcefile}" PROPERTY COMPILE_DEFINITIONS) 39 | 40 | # Add the filename compile definition to the list. 41 | get_filename_component(basename "${sourcefile}" NAME_WE) 42 | list(APPEND defs "__MSIM_FILENAME__=\"${basename}\"") 43 | 44 | # Set the updated compile definitions on the source file. 45 | set_property(SOURCE "${sourcefile}" PROPERTY COMPILE_DEFINITIONS ${defs}) 46 | endforeach() 47 | endfunction() 48 | -------------------------------------------------------------------------------- /cmake/FindReadline.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | # 4 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | # 6 | # MCUSim is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # MCUSim is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | # - Try to find readline include dirs and libraries 21 | # 22 | # Usage of this module as follows: 23 | # 24 | # find_package(Readline) 25 | # 26 | # Variables used by this module, they can change the default behaviour and need 27 | # to be set before calling find_package: 28 | # 29 | # Readline_ROOT_DIR Set this variable to the root installation of 30 | # readline if the module has problems finding the 31 | # proper installation path. 32 | # 33 | # Variables defined by this module: 34 | # 35 | # READLINE_FOUND System has readline, include and lib dirs found 36 | # Readline_INCLUDE_DIR The readline include directories. 37 | # Readline_LIBRARY The readline library. 38 | 39 | find_path(Readline_ROOT_DIR 40 | NAMES include/readline/readline.h 41 | ) 42 | find_path(Readline_INCLUDE_DIR 43 | NAMES readline/readline.h 44 | HINTS ${Readline_ROOT_DIR}/include 45 | ) 46 | find_library(Readline_LIBRARY 47 | NAMES readline 48 | HINTS ${Readline_ROOT_DIR}/lib 49 | ) 50 | 51 | if(Readline_INCLUDE_DIR AND Readline_LIBRARY AND Ncurses_LIBRARY) 52 | set(READLINE_FOUND TRUE) 53 | else(Readline_INCLUDE_DIR AND Readline_LIBRARY AND Ncurses_LIBRARY) 54 | FIND_LIBRARY(Readline_LIBRARY NAMES readline) 55 | include(FindPackageHandleStandardArgs) 56 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG Readline_INCLUDE_DIR Readline_LIBRARY) 57 | MARK_AS_ADVANCED(Readline_INCLUDE_DIR Readline_LIBRARY) 58 | endif(Readline_INCLUDE_DIR AND Readline_LIBRARY AND Ncurses_LIBRARY) 59 | 60 | mark_as_advanced( 61 | Readline_ROOT_DIR 62 | Readline_INCLUDE_DIR 63 | Readline_LIBRARY 64 | ) 65 | -------------------------------------------------------------------------------- /cmake/Findcppcheck.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * \file Findcppcheck.cpp 22 | * \brief Dummy C++ source file used by CMake module Findcppcheck.cmake 23 | * 24 | * \author 25 | * Ryan Pavlik, 2009-2010 26 | * 27 | * http://academic.cleardefinition.com/ 28 | * 29 | */ 30 | int 31 | main(int argc, char *argv[]) 32 | { 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /cmake/Subdirlist.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | # 4 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | # 6 | # MCUSim is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # MCUSim is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | # Macro to get names of all subdirectories in a directory. 21 | # 22 | # Example: 23 | # 24 | # subdirlist(SUBDIRS ${MY_CURRENT_DIR} 25 | # 26 | # Source: https://stackoverflow.com/a/7788165 27 | macro(subdirlist result curdir) 28 | FILE(GLOB children RELATIVE ${curdir} ${curdir}/*) 29 | SET(dirlist "") 30 | 31 | FOREACH(child ${children}) 32 | IF(IS_DIRECTORY ${curdir}/${child}) 33 | LIST(APPEND dirlist ${child}) 34 | ENDIF() 35 | ENDFOREACH() 36 | SET(${result} ${dirlist}) 37 | endmacro() 38 | -------------------------------------------------------------------------------- /examples/ATMEGA8A-pwm-to-sine/README.md: -------------------------------------------------------------------------------- 1 | What is it 2 | ---------- 3 | 4 | This directory contains all of the files required to simulate a transient 5 | response of the circuit in NGSpice which is built on ATmega8A microcontroller 6 | which generates a PWM signal and converts it to a sine wave. 7 | 8 | How to run this example 9 | ----------------------- 10 | 11 | Start NGSpice in interactive mode from the current directory, load MCUSim 12 | code model library (mcusim.cm) and perform a simulation: 13 | 14 | ngspice -> codemodel /mcusim.cm 15 | ngspice -> pwm-to-sine.cir 16 | 17 | It'll take some time and ~449217 data rows should be generated. 18 | -------------------------------------------------------------------------------- /examples/ATMEGA8A-pwm-to-sine/firmware.hex: -------------------------------------------------------------------------------- 1 | :1000000012C021C020C01FC040C01DC01CC01BC0EA 2 | :100010001AC019C018C017C016C015C014C013C02C 3 | :1000200012C011C010C011241FBECFE5D4E0DEBF46 4 | :10003000CDBF20E0A0E6B0E001C01D92A236B2071D 5 | :10004000E1F74ED050C0DCCF85B5806285BD85B567 6 | :100050008F7E85BD85B5806485BD85B5877F85BD6F 7 | :10006000BB9A14BC8FEF83BD1092610010926000A8 8 | :1000700089B7806489BF85B58B7F85BD85B5826072 9 | :1000800085BD85B58E7F85BD08951F920F920FB6F1 10 | :100090000F9211248F939F93809160009091610043 11 | :1000A000892B59F083B58D5C83BD83B58F3F89F46F 12 | :1000B00010926100109260000CC083B5835383BD21 13 | :1000C00083B5811106C081E090E090936100809338 14 | :1000D00060009F918F910F900FBE0F901F90189509 15 | :0A00E000B3DF7894FFCFF894FFCF50 16 | :00000001FF 17 | -------------------------------------------------------------------------------- /examples/ATMEGA8A-pwm-to-sine/firmware/fuse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | FUSES = { 22 | .low = LFUSE_DEFAULT | 0x3f, 23 | .high = HFUSE_DEFAULT & ~(1 << 4) 24 | }; 25 | -------------------------------------------------------------------------------- /examples/ATMEGA8A-pwm-to-sine/firmware/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #define F_CPU 16000000UL 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #define SET_BIT(byte, bit) ((byte)|=(1UL<<(bit))) 26 | #define CLEAR_BIT(byte, bit) ((byte)&=~(1UL<<(bit))) 27 | #define IS_SET(byte, bit) (((byte)&(1UL<<(bit)))>>(bit)) 28 | 29 | void timer2_init(void); 30 | 31 | static volatile int ocr2_up; 32 | 33 | int 34 | main(void) 35 | { 36 | timer2_init(); 37 | sei(); 38 | while (1) { 39 | } 40 | return 0; 41 | } 42 | 43 | void 44 | timer2_init(void) 45 | { 46 | /* Non-inverting compare match output mode: COM21:0 = 2 */ 47 | TCCR2 |= (1<. 18 | # 19 | 20 | # Configuration file for example circuits. 21 | cmake_minimum_required(VERSION 3.2) 22 | project(mcusim-examples NONE) 23 | 24 | # Version 25 | add_definitions(-DMSIM_VERSION="${MSIM_VERSION}") 26 | 27 | # Install examples 28 | install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ATMEGA8A-pwm-to-sine DESTINATION ${MSIM_EXAMPLE_DIR}) 29 | -------------------------------------------------------------------------------- /include/mcusim/avr/crc16.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* Copyright (c) 2005 Joerg Wunsch 21 | All rights reserved. 22 | 23 | Redistribution and use in source and binary forms, with or without 24 | modification, are permitted provided that the following conditions are met: 25 | 26 | * Redistributions of source code must retain the above copyright 27 | notice, this list of conditions and the following disclaimer. 28 | 29 | * Redistributions in binary form must reproduce the above copyright 30 | notice, this list of conditions and the following disclaimer in 31 | the documentation and/or other materials provided with the 32 | distribution. 33 | 34 | * Neither the name of the copyright holders nor the names of 35 | contributors may be used to endorse or promote products derived 36 | from this software without specific prior written permission. 37 | 38 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 39 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 40 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 41 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 42 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 43 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 44 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 45 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 46 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 47 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 48 | POSSIBILITY OF SUCH DAMAGE. */ 49 | 50 | /* $Id$ */ 51 | 52 | #ifndef _AVR_CRC16_H_ 53 | #define _AVR_CRC16_H_ 54 | 55 | #warning "This file has been moved to ." 56 | #include 57 | 58 | #endif /* _AVR_CRC16_H_ */ 59 | -------------------------------------------------------------------------------- /include/mcusim/avr/delay.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* Copyright (c) 2005 Joerg Wunsch 21 | All rights reserved. 22 | 23 | Redistribution and use in source and binary forms, with or without 24 | modification, are permitted provided that the following conditions are met: 25 | 26 | * Redistributions of source code must retain the above copyright 27 | notice, this list of conditions and the following disclaimer. 28 | 29 | * Redistributions in binary form must reproduce the above copyright 30 | notice, this list of conditions and the following disclaimer in 31 | the documentation and/or other materials provided with the 32 | distribution. 33 | 34 | * Neither the name of the copyright holders nor the names of 35 | contributors may be used to endorse or promote products derived 36 | from this software without specific prior written permission. 37 | 38 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 39 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 40 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 41 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 42 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 43 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 44 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 45 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 46 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 47 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 48 | POSSIBILITY OF SUCH DAMAGE. */ 49 | 50 | /* $Id$ */ 51 | 52 | #ifndef _AVR_DELAY_H_ 53 | #define _AVR_DELAY_H_ 54 | 55 | #warning "This file has been moved to ." 56 | #include 57 | 58 | #endif /* _AVR_DELAY_H_ */ 59 | -------------------------------------------------------------------------------- /include/mcusim/avr/parity.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* Copyright (c) 2005 Joerg Wunsch 21 | All rights reserved. 22 | 23 | Redistribution and use in source and binary forms, with or without 24 | modification, are permitted provided that the following conditions are met: 25 | 26 | * Redistributions of source code must retain the above copyright 27 | notice, this list of conditions and the following disclaimer. 28 | 29 | * Redistributions in binary form must reproduce the above copyright 30 | notice, this list of conditions and the following disclaimer in 31 | the documentation and/or other materials provided with the 32 | distribution. 33 | 34 | * Neither the name of the copyright holders nor the names of 35 | contributors may be used to endorse or promote products derived 36 | from this software without specific prior written permission. 37 | 38 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 39 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 40 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 41 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 42 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 43 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 44 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 45 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 46 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 47 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 48 | POSSIBILITY OF SUCH DAMAGE. */ 49 | 50 | /* $Id$ */ 51 | 52 | #ifndef _AVR_PARITY_H_ 53 | #define _AVR_PARITY_H_ 54 | 55 | #warning "This file has been moved to ." 56 | #include 57 | 58 | #endif /* _AVR_PARITY_H_ */ 59 | -------------------------------------------------------------------------------- /include/mcusim/avr/signal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* Copyright (c) 2002,2005,2006 Marek Michalkiewicz 21 | All rights reserved. 22 | 23 | Redistribution and use in source and binary forms, with or without 24 | modification, are permitted provided that the following conditions are met: 25 | 26 | * Redistributions of source code must retain the above copyright 27 | notice, this list of conditions and the following disclaimer. 28 | 29 | * Redistributions in binary form must reproduce the above copyright 30 | notice, this list of conditions and the following disclaimer in 31 | the documentation and/or other materials provided with the 32 | distribution. 33 | 34 | * Neither the name of the copyright holders nor the names of 35 | contributors may be used to endorse or promote products derived 36 | from this software without specific prior written permission. 37 | 38 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 39 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 40 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 41 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 42 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 43 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 44 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 45 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 46 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 47 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 48 | POSSIBILITY OF SUCH DAMAGE. */ 49 | 50 | /* $Id$ */ 51 | 52 | #ifndef _AVR_SIGNAL_H_ 53 | #define _AVR_SIGNAL_H_ 54 | 55 | #warning "This header file is obsolete. Use ." 56 | #include 57 | 58 | #endif /* _AVR_SIGNAL_H_ */ 59 | -------------------------------------------------------------------------------- /include/mcusim/avr/sim/bootloader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef MSIM_AVR_BLDR_H_ 20 | #define MSIM_AVR_BLDR_H_ 1 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include 27 | #include 28 | 29 | /* Forward declaration of the structure to describe AVR microcontroller 30 | * instance. */ 31 | struct MSIM_AVR; 32 | 33 | /* AVR instructions are 16-bits or 32-bits wide. This is why AVR program 34 | * memory is a linear and regular array of 16-bits words. However, MCUSim 35 | * treats program memory as an array of bytes. 36 | * 37 | * AVR program memory is little endian, so "start" is an address of the LSB 38 | * of the first instruction in bootloader, "end" - address of the MSB of 39 | * the last bootloader instruction. */ 40 | typedef struct MSIM_AVR_BLD { 41 | uint32_t start; /* First Bootloader byte in PM, in bytes */ 42 | uint32_t end; /* Last Bootloader byte in PM, in bytes */ 43 | uint32_t size; /* Bootloader size, in bytes */ 44 | } MSIM_AVR_BLD; 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* MSIM_AVR_BLDR_H_ */ 51 | -------------------------------------------------------------------------------- /include/mcusim/avr/sim/decoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef MSIM_AVR_DECODER_H_ 20 | #define MSIM_AVR_DECODER_H_ 1 21 | 22 | #ifndef MSIM_MAIN_HEADER_H_ 23 | #error "Please, include mcusim/mcusim.h instead of this header." 24 | #endif 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | int MSIM_AVR_Step(struct MSIM_AVR *mcu); 31 | 32 | int MSIM_AVR_Is32(unsigned int inst); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif /* MSIM_AVR_DECODER_H_ */ 39 | -------------------------------------------------------------------------------- /include/mcusim/avr/sim/gdb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef MSIM_AVR_GDB_H_ 20 | #define MSIM_AVR_GDB_H_ 1 21 | 22 | #ifndef MSIM_MAIN_HEADER_H_ 23 | #error "Please, include mcusim/mcusim.h instead of this header." 24 | #endif 25 | 26 | #include 27 | 28 | #include "mcusim/mcusim.h" 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | void MSIM_AVR_RSPInit(struct MSIM_AVR *mcu, uint16_t portn); 35 | void MSIM_AVR_RSPClose(struct MSIM_AVR *mcu); 36 | int MSIM_AVR_RSPHandle(struct MSIM_AVR *mcu); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* MSIM_AVR_GDB_H_ */ 43 | -------------------------------------------------------------------------------- /include/mcusim/avr/sim/init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef MSIM_AVR_INIT_H_ 20 | #define MSIM_AVR_INIT_H_ 1 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include 27 | 28 | typedef struct MSIM_InitArgs { 29 | uint8_t *pm; 30 | uint8_t *dm; 31 | uint32_t pmsz; 32 | uint32_t dmsz; 33 | } MSIM_InitArgs; 34 | 35 | /* Initialize MCU as ATmega8A */ 36 | int MSIM_M8AInit(struct MSIM_AVR *mcu, struct MSIM_InitArgs *args); 37 | 38 | /* Initialize MCU as ATmega328 */ 39 | int MSIM_M328Init(struct MSIM_AVR *mcu, struct MSIM_InitArgs *args); 40 | 41 | /* Initialize MCU as ATmega328P */ 42 | int MSIM_M328PInit(struct MSIM_AVR *mcu, struct MSIM_InitArgs *args); 43 | 44 | /* Initialize MCU as ATmega2560 */ 45 | int MSIM_M2560Init(struct MSIM_AVR *mcu, struct MSIM_InitArgs *args); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* MSIM_AVR_INIT_H_ */ 52 | -------------------------------------------------------------------------------- /include/mcusim/avr/sim/interrupt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef MSIM_AVR_INTERRUPT_H_ 20 | #define MSIM_AVR_INTERRUPT_H_ 1 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include 27 | 28 | #include "mcusim/avr/sim/io.h" 29 | 30 | /* AVR IRQ limit, i.e. maximum number of interrupt vectors. */ 31 | #define MSIM_AVR_IRQNUM 64 32 | 33 | /* Forward declaration of the structure to describe AVR microcontroller 34 | * instance. */ 35 | struct MSIM_AVR; 36 | 37 | /* Main structure to describe AVR interrupts within the simulated AVR 38 | * instance (reset address, IRQs, etc.) */ 39 | typedef struct MSIM_AVR_INT { 40 | uint32_t reset_pc; /* Reset address */ 41 | uint32_t ivt; /* Interrupt vectors table address */ 42 | uint8_t irq[MSIM_AVR_IRQNUM]; /* Flags for interrupt requests */ 43 | uint8_t exec_main; /* Exe instruction from the main 44 | program after an exit from ISR */ 45 | uint8_t trap_at_isr; /* Flag to enter stopped mode when 46 | interrupt occured */ 47 | } MSIM_AVR_INT; 48 | 49 | /* Interrupt vector */ 50 | typedef struct MSIM_AVR_INTVec { 51 | MSIM_AVR_IOBit enable; /* Interrupt "enabled" flag */ 52 | MSIM_AVR_IOBit raised; /* Interrupt flag */ 53 | uint8_t vector; /* Interrupt address (in IVT) */ 54 | uint8_t pending; /* Pending interrupt flag */ 55 | } MSIM_AVR_INTVec; 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* MSIM_AVR_INTERRUPT_H_ */ 62 | 63 | -------------------------------------------------------------------------------- /include/mcusim/avr/sim/io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef MSIM_AVR_IO_H_ 20 | #define MSIM_AVR_IO_H_ 1 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /* I/O register of the AVR microcontroller */ 27 | typedef struct MSIM_AVR_IOReg { 28 | char name[16]; 29 | int32_t off; /* Register address (in data space) */ 30 | uint8_t *addr; /* Pointer to the register in DM */ 31 | uint8_t reset; /* Value after MCU reset */ 32 | uint8_t mask; /* Access mask (1 - R/W or W, 0 - R) */ 33 | } MSIM_AVR_IOReg; 34 | 35 | /* 36 | * It provides a way to access bits of the AVR I/O register (or fuse byte) 37 | * in MCU-agnostic way: 38 | * 39 | * (DM(reg) >> bit) & mask 40 | */ 41 | typedef struct MSIM_AVR_IOBit { 42 | uint32_t reg; /* Register address (offset in data space) */ 43 | uint32_t mask; /* Bit mask */ 44 | uint8_t bit; /* Index of a bit in the register */ 45 | uint8_t mbits; /* Number of mask bits */ 46 | } MSIM_AVR_IOBit, MSIM_AVR_IOFuse; 47 | 48 | /* 49 | * An MCU-agnostic way to access and synchronize an I/O port. 50 | */ 51 | typedef struct MSIM_AVR_IOPort { 52 | MSIM_AVR_IOBit port; /* PORTx (in data space) */ 53 | MSIM_AVR_IOBit ddr; /* DDRx (in data space) */ 54 | MSIM_AVR_IOBit pin; /* PINx (in data space) */ 55 | uint8_t pending; /* Pending flag */ 56 | uint8_t ppin; /* Pending PINx value */ 57 | } MSIM_AVR_IOPort; 58 | 59 | int MSIM_AVR_IOSyncPinx(struct MSIM_AVR *mcu); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif /* MSIM_AVR_IO_H_ */ 66 | -------------------------------------------------------------------------------- /include/mcusim/avr/sim/lua.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef MSIM_AVR_LUA_H_ 20 | #define MSIM_AVR_LUA_H_ 1 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "mcusim/avr/sim/sim.h" 27 | 28 | /* Maximum number of device models defined as Lua scripts to be loaded 29 | * during a simulation. */ 30 | #define MSIM_AVR_LUAMODELS 256 31 | 32 | /* Load peripherals written in Lua from a given list file. */ 33 | int MSIM_AVR_LUALoadModel(struct MSIM_AVR *mcu, char *model); 34 | /* Close previously created Lua states. */ 35 | void MSIM_AVR_LUACleanModels(void); 36 | /* Call a "tick" function of the models during each cycle of simulation. */ 37 | void MSIM_AVR_LUATickModels(struct MSIM_AVR *mcu); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif /* MSIM_AVR_LUA_H_ */ 44 | -------------------------------------------------------------------------------- /include/mcusim/avr/sim/m2560/m2560.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef MSIM_AVR_M2560_H_ 20 | #define MSIM_AVR_M2560_H_ 1 21 | 22 | /* Include headers specific to the ATMega2560 */ 23 | #define _SFR_ASM_COMPAT 1 24 | #define __AVR_ATmega2560__ 1 25 | 26 | #include 27 | #include 28 | 29 | #include "mcusim/avr/io.h" 30 | #include "mcusim/avr/sim/m2560/m2560_ioregs.h" 31 | #include "mcusim/avr/sim/io_regs.h" 32 | #include "mcusim/avr/sim/sim.h" 33 | #include "mcusim/avr/sim/simcore.h" 34 | 35 | #define MCU_NAME "ATmega2560" 36 | #define RESET_PC 0x0000 /* Reset vector address, in bytes */ 37 | #define IVT_ADDR 0x0002 /* Interrupt vectors address, in bytes */ 38 | #define PC_BITS 17 /* PC bit capacity */ 39 | #define LBITS_DEFAULT 0xFF /* Default lock bits */ 40 | #define CLK_SOURCE AVR_INT_CAL_RC_CLK /* Calibrated Internal RC */ 41 | #define CLK_FREQ 1000000 /* Oscillator frequency, in Hz */ 42 | #define GP_REGS 32 /* GP registers, R0, R1, ..., R31 */ 43 | #define IO_REGS 480 /* I/O registers, PORTD, SREG, etc. */ 44 | #define BLS_START 0x03E000 /* First address in BLS, in bytes */ 45 | #define BLS_END 0x03FFFF /* Last address in BLS, in bytes */ 46 | #define BLS_SIZE 8192 /* BLS size, in bytes */ 47 | #define FLASHSTART 0x0000 48 | #define RAMSIZE 8192 /* Internal SRAM */ 49 | #define E2START 0x0000 50 | #define E2SIZE 4096 51 | 52 | #endif /* MSIM_AVR_M2560_H_ */ 53 | -------------------------------------------------------------------------------- /include/mcusim/avr/sim/m328/m328.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef MSIM_AVR_M328_H_ 20 | #define MSIM_AVR_M328_H_ 1 21 | 22 | /* Include headers specific to the ATMega328P */ 23 | #define _SFR_ASM_COMPAT 1 24 | #define __AVR_ATmega328__ 1 25 | 26 | #include 27 | #include 28 | 29 | #include "mcusim/avr/io.h" 30 | #include "mcusim/avr/sim/m328/m328_ioregs.h" 31 | #include "mcusim/avr/sim/io_regs.h" 32 | #include "mcusim/avr/sim/sim.h" 33 | #include "mcusim/avr/sim/simcore.h" 34 | 35 | const static struct MSIM_AVR ORIG_M328 = { 36 | .name = "ATmega328", 37 | .signature = { SIGNATURE_0, SIGNATURE_1, SIGNATURE_2 }, 38 | .pc = 0x0000, 39 | .pc_bits = 14, 40 | .freq = 1000000, /* Clock frequency, in Hz */ 41 | .clk_source = AVR_INT_CAL_RC_CLK, 42 | .lockbits = 0x3F, 43 | .regs_num = 32, /* # of general purpose registers */ 44 | .ioregs_num = 224, /* # of I/O registers */ 45 | .xmega = 0, 46 | .reduced_core = 0, 47 | .spm_pagesize = SPM_PAGESIZE, 48 | .flashstart = 0x0000, 49 | .flashend = FLASHEND, 50 | .ramstart = RAMSTART, 51 | .ramend = RAMEND, 52 | .ramsize = 2048, 53 | .e2start = 0x0000, 54 | .e2end = E2END, 55 | .e2size = 1024, 56 | .e2pagesize = E2PAGESIZE, 57 | .sfr_off = __SFR_OFFSET, 58 | .fuse = { LFUSE_DEFAULT, HFUSE_DEFAULT, 0xFF }, 59 | .bls = { /* Bootloader config */ 60 | .start = 0x7000, 61 | .end = 0x7FFF, 62 | .size = 4096, 63 | }, 64 | .intr = { 65 | .reset_pc = 0x0000, 66 | .ivt = 0x0004, 67 | }, 68 | }; 69 | 70 | #endif /* MSIM_AVR_M328_H_ */ 71 | -------------------------------------------------------------------------------- /include/mcusim/avr/sim/simcore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef MSIM_AVR_SIMCORE_H_ 20 | #define MSIM_AVR_SIMCORE_H_ 1 21 | 22 | #ifndef MSIM_MAIN_HEADER_H_ 23 | #error "Please, include mcusim/mcusim.h instead of this header." 24 | #endif 25 | 26 | #include 27 | #include 28 | #include "mcusim/mcusim.h" 29 | #include "mcusim/config.h" 30 | #include "mcusim/avr/sim/init.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | int MSIM_AVR_Init(MSIM_AVR *mcu, MSIM_CFG *conf); 37 | int MSIM_AVR_Simulate(MSIM_AVR *mcu, uint8_t ft); 38 | int MSIM_AVR_SimStep(MSIM_AVR *mcu, uint8_t ft); 39 | int MSIM_AVR_SaveProgMem(MSIM_AVR *mcu, const char *f); 40 | int MSIM_AVR_LoadProgMem(MSIM_AVR *mcu, const char *f); 41 | int MSIM_AVR_LoadDataMem(MSIM_AVR *mcu, const char *f); 42 | 43 | void MSIM_AVR_StackPush(MSIM_AVR *mcu, uint8_t val); 44 | uint8_t MSIM_AVR_StackPop(MSIM_AVR *mcu); 45 | 46 | void MSIM_AVR_PrintParts(void); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* MSIM_AVR_SIMCORE_H_ */ 53 | -------------------------------------------------------------------------------- /include/mcusim/avr/sim/usart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef MSIM_AVR_USART_H_ 20 | #define MSIM_AVR_USART_H_ 1 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | typedef struct MSIM_AVR_USART { 27 | uint32_t baud; /* Current baud rate value */ 28 | uint8_t txb; /* Transmit Buffer */ 29 | uint32_t rx_ticks; /* USART ticks passed since last Rx */ 30 | uint32_t tx_ticks; /* USART ticks passed since last Tx */ 31 | uint32_t rx_presc; /* Rx clock prescaler, (UBRR+1) */ 32 | uint32_t tx_presc; /* Tx clock prescaler, m*(UBRR+1) */ 33 | } MSIM_AVR_USART; 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif /* MSIM_AVR_USART_H_ */ 40 | -------------------------------------------------------------------------------- /include/mcusim/avr/sim/wdt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* 21 | * Model-independent AVR watchdog timer. 22 | * It's supposed to be suitable for any AVR MCU. 23 | */ 24 | #ifndef MSIM_AVR_WDT_H_ 25 | #define MSIM_AVR_WDT_H_ 1 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #include 32 | 33 | #include "mcusim/mcusim.h" 34 | #include "mcusim/avr/sim/io.h" 35 | #include "mcusim/avr/sim/interrupt.h" 36 | 37 | /* AVR Watchdog Timer */ 38 | typedef struct MSIM_AVR_WDT { 39 | MSIM_AVR_IOFuse wdton; /* WDT always-on bit */ 40 | MSIM_AVR_IOBit wde; /* WDT system reset enable bit */ 41 | MSIM_AVR_IOBit wdie; /* WDT interrupt enable bit */ 42 | MSIM_AVR_IOBit ce; /* Change Enable bit */ 43 | 44 | uint32_t oscf; /* Oscillator's frequency, in Hz */ 45 | uint32_t oscp; /* Oscillator's prescaler */ 46 | uint32_t scnt; /* System clock counter */ 47 | 48 | MSIM_AVR_IOBit wdp[4]; /* Watchdog prescaler */ 49 | uint32_t wdp_op[16]; /* Prescalers (# of cycles) */ 50 | uint32_t wdpval; /* Current prescaler */ 51 | 52 | MSIM_AVR_INTVec iv_tout; /* Timeout interrupt vector */ 53 | MSIM_AVR_INTVec iv_sysr; /* System reset vector */ 54 | } MSIM_AVR_WDT; 55 | 56 | int MSIM_AVR_WDTUpdate(struct MSIM_AVR *mcu); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* MSIM_AVR_WDT_H_ */ 63 | -------------------------------------------------------------------------------- /include/mcusim/bit/private/macro.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* Utility macro for bits and bytes. */ 21 | #ifndef MSIM_BIT_MACRO_H_ 22 | #define MSIM_BIT_MACRO_H_ 1 23 | 24 | /* Helps to test individual bits. */ 25 | #define IS_SET(b, bit) (((b)>>(bit))&1) 26 | #define IS_CLEAR(b, bit) ((~(((b)>>(bit))&1))&1) 27 | 28 | /* Helps to test change of an individual bit. */ 29 | #define IS_RISE(init, val, bit) ((!((init>>bit)&1)) & ((val>>bit)&1)) 30 | #define IS_FALL(init, val, bit) (((init>>bit)&1) & (!((val>>bit)&1))) 31 | 32 | /* Helps to manipulate individual bits. */ 33 | #define CLEAR(b, bit) ((b)=(uint8_t)((b)&(uint8_t)(~(1<<(bit))))) 34 | #define SET(b, bit) ((b)=(uint8_t)((b)|(uint8_t)(1<<(bit)))) 35 | 36 | #define UPDATE_BIT(val, i, b) do { \ 37 | if (b == 0U) { \ 38 | *val &= ~(1<. 18 | */ 19 | 20 | /* Functions to parse and save MCUSim configuration. */ 21 | #ifndef MSIM_CFG_H_ 22 | #define MSIM_CFG_H_ 1 23 | 24 | #include 25 | #include "mcusim/avr/sim/vcd.h" 26 | #include "mcusim/avr/sim/lua.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | /* Full path to the installed configuration file of MCUSim */ 33 | #define MSIM_CFG_FILE "@CMAKE_INSTALL_PREFIX@/@MSIM_CONF_DIR@/mcusim.conf" 34 | 35 | /* 36 | * This is a basic structure to describe an MCUSim configuration. 37 | * See mcusim.conf or mcusim.conf.in for detailed description of the fields. 38 | */ 39 | typedef struct MSIM_CFG { 40 | char mcu[64]; 41 | uint64_t mcu_freq; 42 | 43 | uint8_t mcu_lockbits; 44 | uint8_t has_lockbits; 45 | uint8_t mcu_efuse; 46 | uint8_t has_efuse; 47 | uint8_t mcu_hfuse; 48 | uint8_t has_hfuse; 49 | uint8_t mcu_lfuse; 50 | uint8_t has_lfuse; 51 | 52 | char firmware_file[4096]; 53 | uint8_t has_firmware_file; 54 | 55 | uint8_t reset_flash; 56 | uint8_t firmware_test; 57 | uint8_t trap_at_isr; 58 | uint32_t rsp_port; 59 | 60 | char lua_models[MSIM_AVR_LUAMODELS][4096]; 61 | uint32_t lua_models_num; 62 | 63 | char vcd_file[4096]; 64 | char dump_regs[MSIM_AVR_VCD_REGS][16]; 65 | uint32_t dump_regs_num; 66 | } MSIM_CFG; 67 | 68 | int MSIM_CFG_Read(MSIM_CFG *cfg, const char *f); 69 | int MSIM_CFG_PrintVersion(void); 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif /* MSIM_CFG_H_ */ 76 | -------------------------------------------------------------------------------- /include/mcusim/mcusim.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* Main header file which denotes a public API of the MCUSim library. */ 21 | #ifndef MSIM_MAIN_HEADER_H_ 22 | #define MSIM_MAIN_HEADER_H_ 1 23 | 24 | #include "mcusim/avr/sim/bootloader.h" 25 | #include "mcusim/avr/sim/decoder.h" 26 | #include "mcusim/avr/sim/gdb.h" 27 | #include "mcusim/avr/sim/interrupt.h" 28 | #include "mcusim/avr/sim/lua.h" 29 | #include "mcusim/avr/sim/sim.h" 30 | #include "mcusim/avr/sim/simcore.h" 31 | #include "mcusim/avr/sim/vcd.h" 32 | #include "mcusim/avr/sim/wdt.h" 33 | #include "mcusim/avr/sim/usart.h" 34 | #include "mcusim/avr/sim/io.h" 35 | #include "mcusim/avr/sim/timer.h" 36 | 37 | #include "mcusim/pty.h" 38 | #include "mcusim/log.h" 39 | #include "mcusim/config.h" 40 | 41 | #endif /* MSIM_MAIN_HEADER_H_ */ 42 | -------------------------------------------------------------------------------- /include/mcusim/pty.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* 21 | * There are some declarations and functions to pair a master pseudo-terminal 22 | * device (in POSIX terms) with USART within a simulated AVR microcontroller. 23 | */ 24 | #ifndef MSIM_PTY_H_ 25 | #define MSIM_PTY_H_ 1 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #include 32 | #include 33 | 34 | /* Size of the buffers to read/write data from/to pty. */ 35 | #define MSIM_PTY_BUFSIZE 16384 36 | 37 | /* Thread with buffer to read/write data from/to pty. */ 38 | typedef struct MSIM_PTY_Thread { 39 | pthread_mutex_t mutex; /* Lock before accessing any fields */ 40 | pthread_t thread; /* Current thread handle */ 41 | uint8_t stop_thr; /* Flag to exit the thread */ 42 | uint8_t buf[MSIM_PTY_BUFSIZE]; /* Buffer to read/write pty data */ 43 | uint32_t len; /* Length of the data in buffer */ 44 | } MSIM_PTY_Thread; 45 | 46 | /* A single pseudo-terminal (with master and slave parts) and additional data 47 | * to handle a separate thread to read from the master part of pty. */ 48 | typedef struct MSIM_PTY { 49 | char slave_name[128]; 50 | int32_t master_fd; 51 | int32_t slave_fd; 52 | struct MSIM_PTY_Thread read_thr; 53 | } MSIM_PTY; 54 | 55 | int MSIM_PTY_Open(struct MSIM_PTY *pty); 56 | int MSIM_PTY_Close(struct MSIM_PTY *pty); 57 | int MSIM_PTY_Write(struct MSIM_PTY *pty, uint8_t *buf, uint32_t len); 58 | int MSIM_PTY_Read(struct MSIM_PTY *pty, uint8_t *buf, uint32_t len); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif /* MSIM_PTY_H_ */ 65 | -------------------------------------------------------------------------------- /misra/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | # 4 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | # 6 | # MCUSim is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # MCUSim is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | # MCUSim configuration file to check code to be compliant with MISRA C:2012 21 | # rules. 22 | cmake_minimum_required(VERSION 3.2) 23 | project(MCUSim-misra C) 24 | 25 | # Version 26 | add_definitions(-DMSIM_VERSION="${MSIM_VERSION}") 27 | 28 | # Load modules from our source tree too 29 | set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") 30 | 31 | configure_file( 32 | ${CMAKE_CURRENT_SOURCE_DIR}/misra.cmake.in 33 | ${CMAKE_CURRENT_BINARY_DIR}/misra.cmake 34 | @ONLY 35 | ) 36 | add_custom_command( 37 | OUTPUT MISRA 38 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/misra.cmake 39 | ) 40 | add_custom_target(misra DEPENDS MISRA) 41 | -------------------------------------------------------------------------------- /misra/misra.cmake.in: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | # 4 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | # 6 | # MCUSim is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # MCUSim is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | # CMake script to check MISRA C:2012 rules by "make misra" command. 21 | file(GLOB_RECURSE C_FILES "@CMAKE_SOURCE_DIR@/src/*.c") 22 | 23 | # Load modules from our source tree too 24 | set(CMAKE_MODULE_PATH "@CMAKE_CURRENT_SOURCE_DIR@/../cmake") 25 | 26 | # Look for libraries, packages, etc. 27 | find_package(cppcheck REQUIRED) 28 | find_package(PythonInterp REQUIRED) 29 | 30 | if (CPPCHECK_FOUND AND PYTHONINTERP_FOUND) 31 | message(STATUS "cppcheck executable: ${CPPCHECK_EXECUTABLE}") 32 | message(STATUS "cppcheck version: ${CPPCHECK_VERSION}") 33 | message(STATUS "python executable: ${PYTHON_EXECUTABLE}") 34 | message(STATUS "python version: ${PYTHON_VERSION_STRING}") 35 | 36 | foreach(C_FILE ${C_FILES}) 37 | message(STATUS "[FILE]: ${C_FILE}") 38 | 39 | # Create dump for a file 40 | get_filename_component(WORKING_DIR ${C_FILE} DIRECTORY) 41 | execute_process( 42 | COMMAND ${CPPCHECK_EXECUTABLE} --dump ${C_FILE} 43 | RESULT_VARIABLE res 44 | WORKING_DIRECTORY ${WORKING_DIR} 45 | ) 46 | 47 | # Run cppcheck addon to check MISRA C rules 48 | if (EXISTS "@CMAKE_CURRENT_SOURCE_DIR@/MISRA_C_2012.txt") 49 | execute_process( 50 | COMMAND ${PYTHON_EXECUTABLE} @CMAKE_CURRENT_SOURCE_DIR@/misra.py --rule-texts=@CMAKE_CURRENT_SOURCE_DIR@/MISRA_C_2012.txt ${C_FILE}.dump 51 | RESULT_VARIABLE res 52 | WORKING_DIRECTORY ${WORKING_DIR} 53 | ) 54 | else() 55 | execute_process( 56 | COMMAND ${PYTHON_EXECUTABLE} @CMAKE_CURRENT_SOURCE_DIR@/misra.py ${C_FILE}.dump 57 | RESULT_VARIABLE res 58 | WORKING_DIRECTORY ${WORKING_DIR} 59 | ) 60 | endif() 61 | 62 | # Remove dump 63 | if (EXISTS ${C_FILE}.dump) 64 | file(REMOVE ${C_FILE}.dump) 65 | endif() 66 | endforeach() 67 | endif() 68 | -------------------------------------------------------------------------------- /scripts/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | # 4 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | # 6 | # MCUSim is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # MCUSim is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | # Configuration file for Lua scripts. 21 | cmake_minimum_required(VERSION 3.2) 22 | project(mcusim-scripts NONE) 23 | 24 | # Version 25 | add_definitions(-DMSIM_VERSION="${MSIM_VERSION}") 26 | 27 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/mcusim.conf.in 28 | ${CMAKE_BINARY_DIR}/mcusim.conf @ONLY) 29 | 30 | # Install configuration file 31 | install(FILES ${CMAKE_BINARY_DIR}/mcusim.conf DESTINATION ${MSIM_CONF_DIR}) 32 | 33 | # Install script models 34 | install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lua DESTINATION ${MSIM_SCRIPT_DIR}) 35 | -------------------------------------------------------------------------------- /scripts/install-hooks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | # 5 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | # 7 | # MCUSim is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # MCUSim is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | 21 | # Script to install git hooks in the current repository. Please, run it 22 | # from the repository root, i.e. 23 | # 24 | # ./scripts/install-hooks.sh 25 | # 26 | ln -s ../../scripts/pre-commit.sh ./.git/hooks/pre-commit 27 | if [ $? -ne 0 ]; then 28 | echo "[!] Git hooks are not installed." >&2 29 | echo "[!] Please, run this script from the repository root." >&2 30 | exit 1 31 | fi 32 | -------------------------------------------------------------------------------- /scripts/lua/external/stop-in-5s.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | 5 | Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | 7 | MCUSim is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | MCUSim is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | --]] 21 | 22 | --[[ Script which stops simulation in 5 seconds. --]] 23 | 24 | VERBOSE = true -- Switch on to enable verbose output 25 | TICK_TIME = 0.0 -- Clock period, in us 26 | TIMEOUT = 5000000 -- Stop simulation after timeout, in us 27 | 28 | ticks_left = 0 29 | 30 | -- This function will be called by the simulator only once to configure 31 | -- model before start of a simulation. 32 | function module_conf(mcu) 33 | TICK_TIME = (1.0/MSIM_Freq(mcu))*1000000.0 34 | ticks_left = TIMEOUT/TICK_TIME 35 | 36 | local timeout = ticks_left*TICK_TIME 37 | if VERBOSE then 38 | print("[stop-in-5s] Clock period: " .. TICK_TIME .. "us") 39 | print("[stop-in-5s] Timeout: " .. TIMEOUT .. "us") 40 | print("[stop-in-5s] Ticks left: " .. ticks_left) 41 | print("[stop-in-5s] Actual timeout: " .. timeout .. "us") 42 | end 43 | end 44 | 45 | -- This function will be called by the simulator periodically according to the 46 | -- main simulation loop, i.e. time passed between two neighbor calls to the 47 | -- function is a period. 48 | function module_tick(mcu) 49 | ticks_left = ticks_left - 1 50 | if ticks_left == 0 then 51 | MSIM_SetState(mcu, AVR_MSIM_STOP) 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /scripts/mcusim.conf.in: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | # 4 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | # 6 | # MCUSim is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # MCUSim is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | # This is an MCUSim configuration file. You may adjust it to setup your own 21 | # simulation. 22 | 23 | # Model of the simulated microcontroller. 24 | # 25 | # ATmega8: mcu m8 26 | # ATmega328: mcu m328 27 | # ATmega328p: mcu m328p 28 | mcu m8a 29 | 30 | # Microcontroller clock frequency (in Hz). 31 | mcu_freq 16000000 32 | 33 | # Microcontroller lock bits and fuse bytes. 34 | # 35 | #mcu_lockbits 0x00 36 | #mcu_efuse 0xFF 37 | mcu_hfuse 0xC9 38 | mcu_lfuse 0xEF 39 | 40 | # File to load a content of flash memory from. 41 | firmware_file firmware.hex 42 | 43 | # Reset flash memory flag. 44 | # 45 | # Flash memory of the microcontrollers can be preserved between the different 46 | # simulations by default. It means that the flash memory can be saved in a 47 | # separate utility file before the end of a simulation and loaded back during 48 | # the next one. 49 | # 50 | # Default value (yes) means that the firmware file has a priority over the 51 | # utility file. 52 | reset_flash yes 53 | 54 | # Lua models which will be loaded and used during the simulation. 55 | lua_model @CMAKE_INSTALL_PREFIX@/share/mcusim/models/avr/brief-usage.lua 56 | lua_model @CMAKE_INSTALL_PREFIX@/share/mcusim/models/avr/stop-in-5s.lua 57 | 58 | # Firmware test flag. Simulation can be started in a firmware test mode in 59 | # which simulator will not be waiting for any external event (like a command 60 | # from debugger) to continue with the simulation. 61 | firmware_test yes 62 | 63 | # Name of the VCD (Value Change Dump) file to be generated during the 64 | # simulation process to collect data and trace signals after the simulation. 65 | vcd_file trace.vcd 66 | 67 | # Microcontroller registers to be dumped to the VCD file. 68 | dump_reg PORTA 69 | dump_reg PORTB 70 | dump_reg PORTC 71 | 72 | # Port of the RSP target. AVR GDB can be used to connect to the port and 73 | # debug firmware of the microcontroller. 74 | rsp_port 12750 75 | 76 | # Flag to trap AVR GDB when interrupt occured. 77 | trap_at_isr no 78 | -------------------------------------------------------------------------------- /scripts/pre-commit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | # 5 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | # 7 | # MCUSim is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # MCUSim is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | # Pre-commit hook to check C coding style using Artistic Style. 22 | # http://astyle.sourceforge.net 23 | 24 | # Artisctic style configuration to check K&R coding style 25 | OPTIONS="--style=kr -t8 -xC80 -xL -xg -H -k3 -xW -xb -j -xB" 26 | 27 | # Check programs available within operating system 28 | ASTYLE=$(which astyle) 29 | if [ $? -ne 0 ]; then 30 | echo "[!] astyle not installed. Unable to check source file format policy." >&2 31 | exit 1 32 | fi 33 | DIFF=$(which diff) 34 | if [ $? -ne 0 ]; then 35 | echo "[!] diff not installed. Unable to check source file format policy." >&2 36 | exit 1 37 | fi 38 | GREP=$(which grep) 39 | if [ $? -ne 0 ]; then 40 | echo "[!] grep not installed. Unable to check source file format policy." >&2 41 | exit 1 42 | fi 43 | CMP=$(which cmp) 44 | if [ $? -ne 0 ]; then 45 | echo "[!] cmp not installed. Unable to check source file format policy." >&2 46 | exit 1 47 | fi 48 | LESS=$(which less) 49 | if [ $? -ne 0 ]; then 50 | echo "[!] less not installed. Unable to check source file format policy." >&2 51 | exit 1 52 | fi 53 | GIT=$(which git) 54 | 55 | RETURN=0 56 | FILES=`$GIT diff --cached --name-only --diff-filter=ACMR | $GREP -E "\.(c|cpp|h)$"` 57 | for FILE in $FILES; do 58 | $ASTYLE $OPTIONS < $FILE | $CMP -s $FILE - 59 | if [ $? -ne 0 ]; then 60 | echo "[!]" >&2 61 | echo "[!] $FILE does not follow the agreed coding standards." >&2 62 | echo "[!] These are lines which should be adjusted:" >&2 63 | echo "[!]" >&2 64 | $ASTYLE $OPTIONS < $FILE | $DIFF -u $FILE - | $LESS 65 | 66 | RETURN=1 67 | fi 68 | done 69 | 70 | if [ $RETURN -eq 1 ]; then 71 | echo "[I]" >&2 72 | echo "[I] These options of astyle used to check the files above:" >&2 73 | echo "[I] $ASTYLE $OPTIONS < FILE" >&2 74 | fi 75 | 76 | exit $RETURN 77 | -------------------------------------------------------------------------------- /scripts/reinstall-hooks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | # 5 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | # 7 | # MCUSim is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # MCUSim is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | 22 | # Script to re-install git hooks in the current repository. Please, run it 23 | # from the repository root, i.e. 24 | # 25 | # ./scripts/reinstall-hooks.sh 26 | # 27 | rm -f ./.git/hooks/pre-commit 28 | ln -s ../../scripts/pre-commit.sh ./.git/hooks/pre-commit 29 | if [ $? -ne 0 ]; then 30 | echo "[!] Git hooks are not re-installed." >&2 31 | echo "[!] Please, run this script from the repository root." >&2 32 | exit 1 33 | fi 34 | -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectKey=org.mcusim.mcusim-an-xspice-library-with-microcontrollers 2 | sonar.projectName=MCUSim is an XSPICE library with microcontrollers 3 | sonar.projectVersion=0.2-SNAPSHOT 4 | 5 | # ===================================================== 6 | # Meta-data for the project 7 | # ===================================================== 8 | 9 | sonar.links.homepage=https://github.com/mcusim/MCUSim 10 | sonar.links.ci=https://travis-ci.org/mcusim/MCUSim 11 | sonar.links.scm=https://trac.mcusim.org/ 12 | sonar.links.issue=https://trac.mcusim.org/ 13 | 14 | 15 | # ===================================================== 16 | # Properties that will be shared amongst all modules 17 | # ===================================================== 18 | 19 | # SQ standard properties 20 | sonar.sources=. 21 | 22 | # Properties specific to the C/C++ analyzer: 23 | sonar.cfamily.build-wrapper-output=bw-output 24 | sonar.cfamily.gcov.reportsPath=. 25 | -------------------------------------------------------------------------------- /src/avr/avr_io.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "mcusim/mcusim.h" 25 | #include "mcusim/log.h" 26 | #include "mcusim/avr/sim/private/macro.h" 27 | #include "mcusim/avr/sim/private/io_macro.h" 28 | 29 | /* 30 | * Synchronizes bits of the PINx register according to a value in the PORTx 31 | * register. The only bits which are configured to output will be updated. 32 | * 33 | * It's necessary to wait one clock cycle to be able to read back a software 34 | * assigned pin values from PINx. 35 | * 36 | * See figure 14-4, Synchronization when Reading a Software Assigned Pin Value, 37 | * ATmega328P Datasheet Rev. 8271J – 11/2015. 38 | */ 39 | int 40 | MSIM_AVR_IOSyncPinx(struct MSIM_AVR *mcu) 41 | { 42 | MSIM_AVR_IOPort *p; 43 | uint32_t portx, ddrx, pinx; 44 | 45 | for (uint32_t i = 0; i < ARRSZ(mcu->ioports); i++) { 46 | /* I/O port to work with */ 47 | p = &mcu->ioports[i]; 48 | 49 | /* Work with the first N initialized ports */ 50 | if (IS_IONOBYTE(p->port) || IS_IONOBYTE(p->ddr) || 51 | IS_IONOBYTE(p->pin)) { 52 | break; 53 | } 54 | 55 | /* Update PINx from a pending value */ 56 | if (p->pending == 1U) { 57 | IOBIT_WR(mcu, &p->pin, p->ppin); 58 | p->pending = 0; 59 | } 60 | 61 | /* Read PORTx, DDRx and PINx values */ 62 | portx = IOBIT_RD(mcu, &p->port); 63 | ddrx = IOBIT_RD(mcu, &p->ddr); 64 | pinx = IOBIT_RD(mcu, &p->pin); 65 | 66 | /* Calculate a pending PINx value */ 67 | p->ppin = (uint8_t)((pinx & ~ddrx) | (portx & ddrx)); 68 | p->pending = 1; 69 | } 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /src/avr/avr_m2560.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | #include 21 | #include "mcusim/mcusim.h" 22 | #include "mcusim/log.h" 23 | #include "mcusim/avr/sim/m2560/m2560.h" 24 | #include "mcusim/avr/sim/mcu_init.h" 25 | 26 | int 27 | MSIM_M2560Init(struct MSIM_AVR *mcu, struct MSIM_InitArgs *args) 28 | { 29 | return mcu_init(mcu, args); 30 | } 31 | -------------------------------------------------------------------------------- /src/avr/avr_m328.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | #include 21 | #include "mcusim/mcusim.h" 22 | #include "mcusim/log.h" 23 | #include "mcusim/avr/sim/m328/m328.h" 24 | #include "mcusim/avr/sim/mcu_init.h" 25 | 26 | int 27 | MSIM_M328Init(struct MSIM_AVR *mcu, struct MSIM_InitArgs *args) 28 | { 29 | return mcu_init(&ORIG_M328, mcu, args); 30 | } 31 | -------------------------------------------------------------------------------- /src/avr/avr_wdt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* A model-independent AVR Watchdog timer. */ 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "mcusim/mcusim.h" 27 | #include "mcusim/avr/sim/wdt.h" 28 | #include "mcusim/avr/sim/private/macro.h" 29 | #include "mcusim/avr/sim/private/io_macro.h" 30 | #include "mcusim/bit/private/macro.h" 31 | 32 | int 33 | MSIM_AVR_WDTUpdate(struct MSIM_AVR *mcu) 34 | { 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /src/msim_log.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | /* MCUSim logging functions */ 21 | #include 22 | 23 | #include "mcusim/mcusim.h" 24 | #include "mcusim/log.h" 25 | 26 | static enum MSIM_LOG_Level log_level = MSIM_LOG_LVLINFO; 27 | 28 | void 29 | MSIM_LOG_Log(enum MSIM_LOG_Level lvl, const char *lvlmsg, 30 | const char *file, uint32_t line, const char *msg) 31 | { 32 | if (log_level >= lvl) { 33 | printf("%s %s[%d]: %s\n", lvlmsg, file, line, msg); 34 | } 35 | } 36 | 37 | void 38 | MSIM_LOG_SetLevel(enum MSIM_LOG_Level level) 39 | { 40 | log_level = level; 41 | } 42 | 43 | enum MSIM_LOG_Level 44 | MSIM_LOG_GetLevel(void) { 45 | return log_level; 46 | } 47 | 48 | void 49 | MSIM_LOG_PrintMarkers(void) 50 | { 51 | MSIM_LOG_INFO("Markers: (--) informational, (DD) debug, " 52 | "(WW) warning, (EE) error, (!!) fatal."); 53 | } 54 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | # 4 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | # 6 | # MCUSim is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # MCUSim is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | # Configuration file for MCUSim simulation tests (run by 'make tests'). 21 | cmake_minimum_required(VERSION 3.2) 22 | project(MCUSim-tests C) 23 | 24 | # Version 25 | add_definitions(-DMSIM_VERSION="${MSIM_VERSION}") 26 | 27 | # ----------------------------------------------------------------------------- 28 | # Additional tests 29 | # ----------------------------------------------------------------------------- 30 | add_subdirectory(ft) # Firmware checks 31 | 32 | # ----------------------------------------------------------------------------- 33 | # Prepare files in the current binary directory 34 | # ----------------------------------------------------------------------------- 35 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests.cmake.in 36 | ${CMAKE_CURRENT_BINARY_DIR}/tests.cmake @ONLY) 37 | 38 | subdirlist(TEST_DIRS ${CMAKE_CURRENT_SOURCE_DIR}) 39 | foreach(TEST_DIR ${TEST_DIRS}) 40 | file(COPY ${TEST_DIR} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) 41 | endforeach() 42 | 43 | # ----------------------------------------------------------------------------- 44 | # Run tests by 'make tests' 45 | # ----------------------------------------------------------------------------- 46 | add_custom_command(OUTPUT SIMULATION-TESTS 47 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/tests.cmake) 48 | add_custom_target(tests DEPENDS SIMULATION-TESTS) 49 | -------------------------------------------------------------------------------- /tests/atmega328/output-toggle/check-output.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | 5 | Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | 7 | MCUSim is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | MCUSim is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | --]] 21 | 22 | --[[ 23 | This script checks for a simple pattern of port outputs. 24 | --]] 25 | 26 | VERBOSE = true -- Switch on to enable verbose output 27 | TICK_TIME = 0.0 -- clock period, in us 28 | 29 | ticks_passed = 0 30 | check_point = 0 -- PORTB is 0 at start, count up to 255 then 31 | -- and reset by overflow interrupt 32 | 33 | -- This function will be called by the simulator only once to configure 34 | -- model before start of a simulation. 35 | function module_conf(mcu) 36 | -- Re-calculate clock period, in us 37 | TICK_TIME = (1.0/MSIM_Freq(mcu))*1000000.0 38 | if VERBOSE then 39 | print("[PORTB checker] MCU clock: " .. MSIM_Freq(mcu)/1000 .. 40 | "kHz") 41 | print("[PORTB checker] MCU clock period: " .. TICK_TIME .. 42 | "us") 43 | end 44 | end 45 | 46 | -- This function will be called by the simulator periodically according to the 47 | -- main simulation loop, i.e. time passed between two neighbor calls to the 48 | -- function is a period. 49 | function module_tick(mcu) 50 | if check_point == 0 and AVR_ReadIO(mcu, PORTB) == 0 then 51 | print("[PORTB checker] check 1") 52 | check_point = check_point + 1 53 | elseif check_point == 1 and AVR_ReadIO(mcu, PORTB) == 255 then 54 | print("[PORTB checker] check 2") 55 | check_point = check_point + 1 56 | elseif check_point == 2 and AVR_ReadIO(mcu, PORTB) == 254 then 57 | print("[PORTB checker] check 3") 58 | check_point = check_point + 1 59 | elseif check_point == 3 and AVR_ReadIO(mcu, PORTB) == 255 then 60 | -- Test finished successfully 61 | MSIM_SetState(mcu, AVR_MSIM_STOP) 62 | print("[PORTB checker] ticks passed: " .. ticks_passed) 63 | elseif ticks_passed > 200 then 64 | -- Test failed 65 | MSIM_SetState(mcu, AVR_MSIM_TESTFAIL) 66 | print("[PORTB checker] ticks passed: " .. ticks_passed) 67 | end 68 | 69 | ticks_passed = ticks_passed + 1 70 | end 71 | -------------------------------------------------------------------------------- /tests/atmega328/output-toggle/firmware.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | int 22 | main(void) 23 | { 24 | for (int i = 0; i < 255; i++) { 25 | PORTB ^= (1<: 8 | 0: 0c 94 34 00 jmp 0x68 ; 0x68 9 | 4: 0c 94 3e 00 jmp 0x7c ; 0x7c 10 | 8: 0c 94 3e 00 jmp 0x7c ; 0x7c 11 | c: 0c 94 3e 00 jmp 0x7c ; 0x7c 12 | 10: 0c 94 3e 00 jmp 0x7c ; 0x7c 13 | 14: 0c 94 3e 00 jmp 0x7c ; 0x7c 14 | 18: 0c 94 3e 00 jmp 0x7c ; 0x7c 15 | 1c: 0c 94 3e 00 jmp 0x7c ; 0x7c 16 | 20: 0c 94 3e 00 jmp 0x7c ; 0x7c 17 | 24: 0c 94 3e 00 jmp 0x7c ; 0x7c 18 | 28: 0c 94 3e 00 jmp 0x7c ; 0x7c 19 | 2c: 0c 94 3e 00 jmp 0x7c ; 0x7c 20 | 30: 0c 94 3e 00 jmp 0x7c ; 0x7c 21 | 34: 0c 94 3e 00 jmp 0x7c ; 0x7c 22 | 38: 0c 94 3e 00 jmp 0x7c ; 0x7c 23 | 3c: 0c 94 3e 00 jmp 0x7c ; 0x7c 24 | 40: 0c 94 3e 00 jmp 0x7c ; 0x7c 25 | 44: 0c 94 3e 00 jmp 0x7c ; 0x7c 26 | 48: 0c 94 3e 00 jmp 0x7c ; 0x7c 27 | 4c: 0c 94 3e 00 jmp 0x7c ; 0x7c 28 | 50: 0c 94 3e 00 jmp 0x7c ; 0x7c 29 | 54: 0c 94 3e 00 jmp 0x7c ; 0x7c 30 | 58: 0c 94 3e 00 jmp 0x7c ; 0x7c 31 | 5c: 0c 94 3e 00 jmp 0x7c ; 0x7c 32 | 60: 0c 94 3e 00 jmp 0x7c ; 0x7c 33 | 64: 0c 94 3e 00 jmp 0x7c ; 0x7c 34 | 68: 11 24 eor r1, r1 35 | 6a: 1f be out 0x3f, r1 ; 63 36 | 6c: cf ef ldi r28, 0xFF ; 255 37 | 6e: d8 e0 ldi r29, 0x08 ; 8 38 | 70: de bf out 0x3e, r29 ; 62 39 | 72: cd bf out 0x3d, r28 ; 61 40 | 74: 0e 94 40 00 call 0x80 ; 0x80 41 | 78: 0c 94 4e 00 jmp 0x9c ; 0x9c 42 | 7c: 0c 94 00 00 jmp 0 ; 0x0 43 | 80: 8f ef ldi r24, 0xFF ; 255 44 | 82: 90 e0 ldi r25, 0x00 ; 0 45 | 84: 31 e0 ldi r19, 0x01 ; 1 46 | 86: 25 b1 in r18, 0x05 ; 5 47 | 88: 23 27 eor r18, r19 48 | 8a: 25 b9 out 0x05, r18 ; 5 49 | 8c: 25 b1 in r18, 0x05 ; 5 50 | 8e: 22 0f add r18, r18 51 | 90: 25 b9 out 0x05, r18 ; 5 52 | 92: 01 97 sbiw r24, 0x01 ; 1 53 | 94: c1 f7 brne .-16 ; 0x86 54 | 96: 90 e0 ldi r25, 0x00 ; 0 55 | 98: 80 e0 ldi r24, 0x00 ; 0 56 | 9a: 08 95 ret 57 | 9c: f8 94 cli 58 | 9e: ff cf rjmp .-2 ; 0x9e 59 | -------------------------------------------------------------------------------- /tests/atmega328/output-toggle/mcusim.conf: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | # 4 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | # 6 | # MCUSim is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # MCUSim is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | # This is an MCUSim configuration file. You may adjust it to setup your own 21 | # simulation. 22 | 23 | # Model of the simulated microcontroller. 24 | # 25 | # ATmega8: mcu m8 26 | # ATmega328: mcu m328 27 | # ATmega328p: mcu m328p 28 | mcu m328 29 | 30 | # Microcontroller clock frequency (in Hz). 31 | mcu_freq 16000000 32 | 33 | # Microcontroller lock bits and fuse bytes. 34 | # 35 | #mcu_lockbits 0x00 36 | #mcu_efuse 0xFF 37 | #mcu_hfuse 0xC9 38 | #mcu_lfuse 0xEF 39 | 40 | # File to load a content of flash memory from. 41 | firmware_file firmware.hex 42 | 43 | # Reset flash memory flag. 44 | # 45 | # Flash memory of the microcontrollers can be preserved between the different 46 | # simulations by default. Memory preserving means that the flash memory can be 47 | # saved in a separate utility file before the end of a simulation and 48 | # loaded back during the next one. 49 | # 50 | # Default value (no) means that the utility file has a priority over the one 51 | # provided by the 'firmware_file' option. 52 | reset_flash yes 53 | 54 | # Lua models which will be loaded and used during the simulation. 55 | lua_model check-output.lua 56 | lua_model stop-in-5s.lua 57 | 58 | # Firmware test flag. Simulation can be started in a firmware test mode in 59 | # which simulator will not be waiting for any external event (like a command 60 | # from debugger) to continue with the simulation. 61 | firmware_test yes 62 | 63 | # Name of the VCD (Value Change Dump) file to be generated during the 64 | # simulation process to collect data and trace signals after the simulation. 65 | vcd_file trace.vcd 66 | 67 | # Microcontroller registers to be dumped to the VCD file. 68 | #dump_reg PORTA 69 | #dump_reg PORTB 70 | #dump_reg PORTC 71 | 72 | # Port of the RSP target. AVR GDB can be used to connect to the port and 73 | # debug firmware of the microcontroller. 74 | rsp_port 12750 75 | 76 | # Flag to trap AVR GDB when interrupt occured. 77 | trap_at_isr no 78 | -------------------------------------------------------------------------------- /tests/atmega328/output-toggle/stop-in-5s.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | 5 | Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | 7 | MCUSim is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | MCUSim is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | --]] 21 | 22 | --[[ Script which stops simulation in 5 seconds. --]] 23 | 24 | VERBOSE = true -- Switch on to enable verbose output 25 | TICK_TIME = 0.0 -- Clock period, in us 26 | TIMEOUT = 5000000 -- Stop simulation after timeout, in us 27 | 28 | ticks_left = 0 29 | 30 | -- This function will be called by the simulator only once to configure 31 | -- model before start of a simulation. 32 | function module_conf(mcu) 33 | -- Re-calculate clock period, in us 34 | TICK_TIME = (1.0/MSIM_Freq(mcu))*1000000.0 35 | ticks_left = TIMEOUT/TICK_TIME 36 | if VERBOSE then 37 | print("[stop-in-5s] Timeout: " .. TIMEOUT .. "us") 38 | print("[stop-in-5s] MCU clock period: " .. TICK_TIME .. "us") 39 | print("[stop-in-5s] Ticks left: " .. ticks_left) 40 | print("[stop-in-5s] Actual timeout: " .. ticks_left*TICK_TIME 41 | .. "us") 42 | end 43 | end 44 | 45 | -- This function will be called by the simulator periodically according to the 46 | -- main simulation loop, i.e. time passed between two neighbor calls to the 47 | -- function is a period. 48 | function module_tick(mcu) 49 | ticks_left = ticks_left - 1 50 | if ticks_left == 0 then 51 | MSIM_SetState(mcu, AVR_MSIM_STOP) 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /tests/atmega328p/timer0-ctc/firmware.hex: -------------------------------------------------------------------------------- 1 | :100000000C9434000C943E000C943E000C943E0082 2 | :100010000C943E000C943E000C943E000C943E0068 3 | :100020000C943E000C943E000C943E000C943E0058 4 | :100030000C943E000C943E000C943E000C943E0048 5 | :100040000C946D000C943E000C943E000C943E0009 6 | :100050000C943E000C943E000C943E000C943E0028 7 | :100060000C943E000C943E0011241FBECFEFD8E04C 8 | :10007000DEBFCDBF0E9467000C947C000C94000092 9 | :1000800084B5806484BD84B58F7784BD84B5806178 10 | :1000900084BD84B58F7D84BD85B5877F85BD84B5DE 11 | :1000A000826084BD84B58E7F84BDEEE6F0E0808101 12 | :1000B0008160808385B5816085BD85B5826085BDA1 13 | :1000C00085B58B7F85BD87EC87BD88BD0895559A22 14 | :1000D000569A0E9440007894FFCF1F920F920FB65D 15 | :1000E0000F9211248F9387EC87BD88BD8F910F905D 16 | :0C00F0000FBE0F901F901895F894FFCFE2 17 | :00000001FF 18 | -------------------------------------------------------------------------------- /tests/atmega328p/timer0-ctc/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #define F_CPU 16000000UL 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #define SET_BIT(byte, bit) ((byte)|=(1UL<<(bit))) 27 | #define CLEAR_BIT(byte, bit) ((byte)&=~(1UL<<(bit))) 28 | #define IS_SET(byte, bit) (((byte)&(1UL<<(bit)))>>(bit)) 29 | 30 | void timer0_init(void); 31 | 32 | int 33 | main(void) 34 | { 35 | /* Set PIN5 and PIN6 as output */ 36 | SET_BIT(DDRD, PD5); 37 | SET_BIT(DDRD, PD6); 38 | 39 | timer0_init(); 40 | sei(); 41 | 42 | /* road to infinit */ 43 | while (1); 44 | 45 | return 0; 46 | } 47 | 48 | void 49 | timer0_init(void) 50 | { 51 | /* Compare match toggle output, channel A*/ 52 | SET_BIT(TCCR0A, COM0A0); 53 | CLEAR_BIT(TCCR0A, COM0A1); 54 | 55 | /* Compare match toggle output, channel B*/ 56 | SET_BIT(TCCR0A, COM0B0); 57 | CLEAR_BIT(TCCR0A, COM0B1); 58 | 59 | /* Waveform generation mode CTC enable */ //WGM02 = 0, WGM01 = 1, WGM00 = 0 60 | CLEAR_BIT(TCCR0B, WGM02); 61 | SET_BIT(TCCR0A, WGM01); 62 | CLEAR_BIT(TCCR0A, WGM00); 63 | 64 | /* Enable overflow interrupt */ 65 | SET_BIT(TIMSK0, TOIE0); //TOIE0 or TOIE? 66 | 67 | /* Start timer, prescaler to clk/64 */ 68 | SET_BIT(TCCR0B, CS00); 69 | SET_BIT(TCCR0B, CS01); 70 | CLEAR_BIT(TCCR0B, CS02); 71 | 72 | /* Set duty cycle, count from 0 | output freq = 625 Hz*/ 73 | OCR0A = 199; 74 | OCR0B = 199; 75 | } 76 | 77 | ISR(TIMER0_OVF_vect) 78 | { 79 | /* Update duty cycle */ 80 | OCR0A = 199; 81 | OCR0B = 199; 82 | } 83 | -------------------------------------------------------------------------------- /tests/atmega328p/timer0-ctc/stop-test.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | 5 | Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | 7 | MCUSim is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | MCUSim is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | --]] 21 | 22 | VERBOSE = true -- Switch on to enable verbose output 23 | TICK_TIME = 0.0 -- clock period, in us 24 | 25 | ticks_passed = 0 26 | check_point = 0 -- TCNT0 is 0 at start, count up to 255 then 27 | -- and reset by overflow interrupt 28 | 29 | -- This function will be called by the simulator only once to configure 30 | -- model before start of a simulation. 31 | function module_conf(mcu) 32 | -- Re-calculate clock period, in us 33 | TICK_TIME = (1.0/MSIM_Freq(mcu))*1000000.0 34 | if VERBOSE then 35 | print("[Test stopper] MCU clock: " .. MSIM_Freq(mcu)/1000 .. 36 | "kHz") 37 | print("[Test stopper] MCU clock period: " .. TICK_TIME .. 38 | "us") 39 | end 40 | end 41 | 42 | -- This function will be called by the simulator periodically according to the 43 | -- main simulation loop, i.e. time passed between two neighbor calls to the 44 | -- function is a period. 45 | function module_tick(mcu) 46 | if ticks_passed > 400000 then 47 | -- Test finished successfully 48 | MSIM_SetState(mcu, AVR_MSIM_STOP) 49 | print("[Test stopper] ticks passed: " .. ticks_passed) 50 | end 51 | 52 | ticks_passed = ticks_passed + 1 53 | end 54 | 55 | -------------------------------------------------------------------------------- /tests/atmega328p/timer1-ctc-with-input-capture/check-pin.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | 5 | Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | 7 | MCUSim is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | MCUSim is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | --]] 21 | HALF_PERIOD = 1272330 -- in 8MHz clock cycles 22 | ticks = 0 23 | pb0 = 0 24 | change = 0 25 | change_tick = 0 26 | 27 | -- This function will be called by the simulator only once to configure 28 | -- model before start of a simulation. 29 | function module_conf(mcu) 30 | end 31 | 32 | -- This function will be called by the simulator periodically according to the 33 | -- main simulation loop, i.e. time passed between two neighbor calls to the 34 | -- function is a period. 35 | function module_tick(mcu) 36 | if AVR_IOBit(mcu, PORTB, 0) ~= pb0 then 37 | pb0 = AVR_IOBit(mcu, PORTB, 0) 38 | if change == 2 and (ticks-change_tick) == HALF_PERIOD then 39 | print("[check-pin] tick:" .. ticks .. 40 | " previous tick:" .. change_tick .. 41 | " delta:" .. ticks-change_tick) 42 | elseif change == 6 and (ticks-change_tick) == HALF_PERIOD then 43 | print("[check-pin] tick:" .. ticks .. 44 | " previous tick:" .. change_tick .. 45 | " delta:" .. ticks-change_tick) 46 | elseif change == 9 and (ticks-change_tick) == HALF_PERIOD then 47 | print("[check-pin] tick:" .. ticks .. 48 | " previous tick:" .. change_tick .. 49 | " delta:" .. ticks-change_tick) 50 | -- Test finished successfully 51 | MSIM_SetState(mcu, AVR_MSIM_STOP) 52 | elseif change == 10 then 53 | -- Test failed 54 | MSIM_SetState(mcu, AVR_MSIM_TESTFAIL) 55 | print("[check-pin] ticks passed: " .. ticks) 56 | end 57 | 58 | change = change+1 59 | change_tick = ticks 60 | end 61 | 62 | ticks = ticks+1 63 | end 64 | -------------------------------------------------------------------------------- /tests/atmega328p/timer1-ctc-with-input-capture/firmware.hex: -------------------------------------------------------------------------------- 1 | :100000000C9434000C943E000C943E000C943E0082 2 | :100010000C943E000C943E000C943E000C943E0068 3 | :100020000C943E000C943E000C943E000C943E0058 4 | :100030000C943E000C943E000C943E000C943E0048 5 | :100040000C943E000C943E000C943E000C943E0038 6 | :100050000C943E000C943E000C943E000C943E0028 7 | :100060000C943E000C943E0011241FBECFEFD8E04C 8 | :10007000DEBFCDBF0E9440000C9451000C940000E4 9 | :100080008FEF84B915B891E085B1892785B92FEF35 10 | :1000900031EE84E0215030408040E1F700C00000A4 11 | :0600A000F3CFF894FFCF3E 12 | :00000001FF 13 | -------------------------------------------------------------------------------- /tests/atmega328p/timer1-ctc-with-input-capture/firmware.hex.txt: -------------------------------------------------------------------------------- 1 | 2 | /usr/home/dsl/git/MCUSim/tests/ATMEGA328-toggle-pin/build/firmware.hex: file format ihex 3 | 4 | 5 | Disassembly of section .sec1: 6 | 7 | 00000000 <.sec1>: 8 | 0: 0c 94 34 00 jmp 0x68 ; 0x68 9 | 4: 0c 94 3e 00 jmp 0x7c ; 0x7c 10 | 8: 0c 94 3e 00 jmp 0x7c ; 0x7c 11 | c: 0c 94 3e 00 jmp 0x7c ; 0x7c 12 | 10: 0c 94 3e 00 jmp 0x7c ; 0x7c 13 | 14: 0c 94 3e 00 jmp 0x7c ; 0x7c 14 | 18: 0c 94 3e 00 jmp 0x7c ; 0x7c 15 | 1c: 0c 94 3e 00 jmp 0x7c ; 0x7c 16 | 20: 0c 94 3e 00 jmp 0x7c ; 0x7c 17 | 24: 0c 94 3e 00 jmp 0x7c ; 0x7c 18 | 28: 0c 94 3e 00 jmp 0x7c ; 0x7c 19 | 2c: 0c 94 3e 00 jmp 0x7c ; 0x7c 20 | 30: 0c 94 3e 00 jmp 0x7c ; 0x7c 21 | 34: 0c 94 3e 00 jmp 0x7c ; 0x7c 22 | 38: 0c 94 3e 00 jmp 0x7c ; 0x7c 23 | 3c: 0c 94 3e 00 jmp 0x7c ; 0x7c 24 | 40: 0c 94 3e 00 jmp 0x7c ; 0x7c 25 | 44: 0c 94 3e 00 jmp 0x7c ; 0x7c 26 | 48: 0c 94 3e 00 jmp 0x7c ; 0x7c 27 | 4c: 0c 94 3e 00 jmp 0x7c ; 0x7c 28 | 50: 0c 94 3e 00 jmp 0x7c ; 0x7c 29 | 54: 0c 94 3e 00 jmp 0x7c ; 0x7c 30 | 58: 0c 94 3e 00 jmp 0x7c ; 0x7c 31 | 5c: 0c 94 3e 00 jmp 0x7c ; 0x7c 32 | 60: 0c 94 3e 00 jmp 0x7c ; 0x7c 33 | 64: 0c 94 3e 00 jmp 0x7c ; 0x7c 34 | 68: 11 24 eor r1, r1 35 | 6a: 1f be out 0x3f, r1 ; 63 36 | 6c: cf ef ldi r28, 0xFF ; 255 37 | 6e: d8 e0 ldi r29, 0x08 ; 8 38 | 70: de bf out 0x3e, r29 ; 62 39 | 72: cd bf out 0x3d, r28 ; 61 40 | 74: 0e 94 40 00 call 0x80 ; 0x80 41 | 78: 0c 94 51 00 jmp 0xa2 ; 0xa2 42 | 7c: 0c 94 00 00 jmp 0 ; 0x0 43 | 80: 8f ef ldi r24, 0xFF ; 255 44 | 82: 84 b9 out 0x04, r24 ; 4 45 | 84: 15 b8 out 0x05, r1 ; 5 46 | 86: 91 e0 ldi r25, 0x01 ; 1 47 | 88: 85 b1 in r24, 0x05 ; 5 48 | 8a: 89 27 eor r24, r25 49 | 8c: 85 b9 out 0x05, r24 ; 5 50 | 8e: 2f ef ldi r18, 0xFF ; 255 51 | 90: 31 ee ldi r19, 0xE1 ; 225 52 | 92: 84 e0 ldi r24, 0x04 ; 4 53 | 94: 21 50 subi r18, 0x01 ; 1 54 | 96: 30 40 sbci r19, 0x00 ; 0 55 | 98: 80 40 sbci r24, 0x00 ; 0 56 | 9a: e1 f7 brne .-8 ; 0x94 57 | 9c: 00 c0 rjmp .+0 ; 0x9e 58 | 9e: 00 00 nop 59 | a0: f3 cf rjmp .-26 ; 0x88 60 | a2: f8 94 cli 61 | a4: ff cf rjmp .-2 ; 0xa4 62 | -------------------------------------------------------------------------------- /tests/atmega328p/timer1-ctc-with-input-capture/fuse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | FUSES = { 22 | .low = LFUSE_DEFAULT | 0x3f, 23 | .high = HFUSE_DEFAULT & ~(1 << 4) 24 | }; 25 | -------------------------------------------------------------------------------- /tests/atmega328p/timer1-ctc-with-input-capture/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #define F_CPU 16000000UL 20 | #include 21 | #include 22 | 23 | int 24 | main(void) 25 | { 26 | DDRB = 0xFF; // sets PORTB to output 27 | PORTB = 0x00; // sets output pins to low 28 | while (1) { 29 | PORTB ^= (1<<0); 30 | _delay_ms(200); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/atmega328p/timer1-ctc-with-input-capture/mcusim.conf: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | # 4 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | # 6 | # MCUSim is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # MCUSim is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | # This is an MCUSim configuration file. You may adjust it to setup your own 21 | # simulation. 22 | 23 | # Model of the simulated microcontroller. 24 | # 25 | # ATmega8: mcu m8 26 | # ATmega328: mcu m328 27 | # ATmega328p: mcu m328p 28 | mcu m328p 29 | 30 | # Microcontroller clock frequency (in Hz). 31 | mcu_freq 16000000 32 | 33 | # Microcontroller lock bits and fuse bytes. 34 | # 35 | #mcu_lockbits 0x00 36 | mcu_efuse 0xF7 37 | mcu_hfuse 0xDB 38 | mcu_lfuse 0xFF 39 | 40 | # File to load a content of flash memory from. 41 | firmware_file firmware.hex 42 | 43 | # Reset flash memory flag. 44 | # 45 | # Flash memory of the microcontrollers can be preserved between the different 46 | # simulations by default. Memory preserving means that the flash memory can be 47 | # saved in a separate utility file before the end of a simulation and 48 | # loaded back during the next one. 49 | # 50 | # Default value (no) means that the utility file has a priority over the one 51 | # provided by the 'firmware_file' option. 52 | reset_flash yes 53 | 54 | # Lua models which will be loaded and used during the simulation. 55 | lua_model check-pin.lua 56 | 57 | # Firmware test flag. Simulation can be started in a firmware test mode in 58 | # which simulator will not be waiting for any external event (like a command 59 | # from debugger) to continue with the simulation. 60 | firmware_test yes 61 | 62 | # Name of the VCD (Value Change Dump) file to be generated during the 63 | # simulation process to collect data and trace signals after the simulation. 64 | vcd_file trace.vcd 65 | 66 | # Microcontroller registers to be dumped to the VCD file. 67 | dump_reg DDRB 68 | dump_reg PORTB0 69 | 70 | # Port of the RSP target. AVR GDB can be used to connect to the port and 71 | # debug firmware of the microcontroller. 72 | rsp_port 12750 73 | 74 | # Flag to trap AVR GDB when interrupt occured. 75 | trap_at_isr no 76 | -------------------------------------------------------------------------------- /tests/atmega328p/timer1-ctc-with-input-capture/toggle-icp1.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | 5 | Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | 7 | MCUSim is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | MCUSim is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | --]] 21 | HALF_PERIOD = 1272330 -- in 8MHz clock cycles 22 | ticks = 0 23 | pb0 = 0 24 | change = 0 25 | change_tick = 0 26 | 27 | -- This function will be called by the simulator only once to configure 28 | -- model before start of a simulation. 29 | function module_conf(mcu) 30 | end 31 | 32 | -- This function will be called by the simulator periodically according to the 33 | -- main simulation loop, i.e. time passed between two neighbor calls to the 34 | -- function is a period. 35 | function module_tick(mcu) 36 | if AVR_IOBit(mcu, PORTB, 0) ~= pb0 then 37 | pb0 = AVR_IOBit(mcu, PORTB, 0) 38 | if change == 2 and (ticks-change_tick) == HALF_PERIOD then 39 | print("[check-pin] tick:" .. ticks .. 40 | " previous tick:" .. change_tick .. 41 | " delta:" .. ticks-change_tick) 42 | elseif change == 6 and (ticks-change_tick) == HALF_PERIOD then 43 | print("[check-pin] tick:" .. ticks .. 44 | " previous tick:" .. change_tick .. 45 | " delta:" .. ticks-change_tick) 46 | elseif change == 9 and (ticks-change_tick) == HALF_PERIOD then 47 | print("[check-pin] tick:" .. ticks .. 48 | " previous tick:" .. change_tick .. 49 | " delta:" .. ticks-change_tick) 50 | -- Test finished successfully 51 | MSIM_SetState(mcu, AVR_MSIM_STOP) 52 | elseif change == 10 then 53 | -- Test failed 54 | MSIM_SetState(mcu, AVR_MSIM_TESTFAIL) 55 | print("[check-pin] ticks passed: " .. ticks) 56 | end 57 | 58 | change = change+1 59 | change_tick = ticks 60 | end 61 | 62 | ticks = ticks+1 63 | end 64 | -------------------------------------------------------------------------------- /tests/atmega328p/timer1-pcpwm/firmware.hex: -------------------------------------------------------------------------------- 1 | :100000000C9434000C9446000C9446000C9446006A 2 | :100010000C9446000C9446000C9446000C94460048 3 | :100020000C9446000C9446000C9446000C94D100AD 4 | :100030000C94E5000C948E000C9446000C94460041 5 | :100040000C9446000C9446000C9446000C94460018 6 | :100050000C9446000C9446000C9446000C94460008 7 | :100060000C9446000C94460011241FBECFEFD8E03C 8 | :10007000DEBFCDBF21E0A0E0B1E001C01D92A630FF 9 | :10008000B207E1F70E94F9000C94FD000C94000007 10 | :10009000E0E8F0E080818F77808380818F7B8083B0 11 | :1000A00080818062808380818F7E8083A1E8B0E040 12 | :1000B0008C9180618C938C91877F8C9380818260FE 13 | :1000C0008083808181608083229A109285001092C3 14 | :1000D000840080E094E0909389008093880080E819 15 | :1000E00093E090938B0080938A0010920501109208 16 | :1000F0000401EFE6F0E0808181608083808182608E 17 | :1001000080838081846080838C918B7F8C938C91A1 18 | :1001100082608C938C918E7F8C9308951F920F92A6 19 | :100120000FB60F9211242F938F939F938091040108 20 | :1001300090910501892BB1F080918A0090918B00FC 21 | :1001400080589F4F90938B0080938A0080918A0003 22 | :1001500090918B0081159440E1F41092050110926A 23 | :10016000040117C080918A0090918B0080589109FA 24 | :1001700090938B0080938A0080918A0090918B00ED 25 | :100180008038910531F481E090E0909305018093EF 26 | :1001900004019F918F912F910F900FBE0F901F9090 27 | :1001A00018951F920F920FB60F9211248F939F9361 28 | :1001B00081E090E090930301809302019F918F91E1 29 | :1001C0000F900FBE0F901F9018951F920F920FB6B1 30 | :1001D0000F9211248F939F9381E090E090930101FF 31 | :1001E000809300019F918F910F900FBE0F901F90F1 32 | :0E01F00018950E9448007894FFCFF894FFCF36 33 | :00000001FF 34 | -------------------------------------------------------------------------------- /tests/atmega328p/timer1-pcpwm/fuse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | FUSES = { 22 | .low = LFUSE_DEFAULT | 0x3f, 23 | .high = HFUSE_DEFAULT & ~(1 << 4) 24 | }; 25 | -------------------------------------------------------------------------------- /tests/atmega328p/timer1-pcpwm/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #define F_CPU 16000000UL 20 | #include 21 | #include 22 | #include 23 | 24 | #define SET_BIT(byte, bit) ((byte)|=(1UL<<(bit))) 25 | #define CLEAR_BIT(byte, bit) ((byte)&=~(1UL<<(bit))) 26 | #define IS_SET(byte, bit) (((byte)&(1UL<<(bit)))>>(bit)) 27 | 28 | void timer1_init(void); 29 | 30 | static volatile int ocr_up; 31 | static volatile int compa, compb; 32 | 33 | int 34 | main(void) 35 | { 36 | timer1_init(); 37 | sei(); 38 | 39 | while (1) {} 40 | return 0; 41 | } 42 | 43 | void 44 | timer1_init(void) 45 | { 46 | /* Channel A: Disconnected: COM1A1:0 = 0 47 | * Channel B: Non-inverting compare match mode: COM1B1:0 = 2 */ 48 | TCCR1A &= (uint8_t)(~(1<. 18 | */ 19 | #include 20 | 21 | FUSES = { 22 | .low = LFUSE_DEFAULT | 0x3f, 23 | .high = HFUSE_DEFAULT & ~(1 << 4) 24 | }; 25 | -------------------------------------------------------------------------------- /tests/atmega328p/toggle-pin/check-pin.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | 5 | Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | 7 | MCUSim is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | MCUSim is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | --]] 21 | HALF_PERIOD = 1272330 -- in 8MHz clock cycles 22 | ticks = 0 23 | pb0 = 0 24 | change = 0 25 | change_tick = 0 26 | 27 | -- This function will be called by the simulator only once to configure 28 | -- model before start of a simulation. 29 | function module_conf(mcu) 30 | end 31 | 32 | -- This function will be called by the simulator periodically according to the 33 | -- main simulation loop, i.e. time passed between two neighbor calls to the 34 | -- function is a period. 35 | function module_tick(mcu) 36 | if AVR_IOBit(mcu, PORTB, 0) ~= pb0 then 37 | pb0 = AVR_IOBit(mcu, PORTB, 0) 38 | if change == 2 and (ticks-change_tick) == HALF_PERIOD then 39 | print("[check-pin] tick:" .. ticks .. 40 | " previous tick:" .. change_tick .. 41 | " delta:" .. ticks-change_tick) 42 | elseif change == 6 and (ticks-change_tick) == HALF_PERIOD then 43 | print("[check-pin] tick:" .. ticks .. 44 | " previous tick:" .. change_tick .. 45 | " delta:" .. ticks-change_tick) 46 | elseif change == 9 and (ticks-change_tick) == HALF_PERIOD then 47 | print("[check-pin] tick:" .. ticks .. 48 | " previous tick:" .. change_tick .. 49 | " delta:" .. ticks-change_tick) 50 | -- Test finished successfully 51 | MSIM_SetState(mcu, AVR_MSIM_STOP) 52 | elseif change == 10 then 53 | -- Test failed 54 | MSIM_SetState(mcu, AVR_MSIM_TESTFAIL) 55 | print("[check-pin] ticks passed: " .. ticks) 56 | end 57 | 58 | change = change+1 59 | change_tick = ticks 60 | end 61 | 62 | ticks = ticks+1 63 | end 64 | -------------------------------------------------------------------------------- /tests/atmega328p/toggle-pin/firmware.hex: -------------------------------------------------------------------------------- 1 | :100000000C9434000C943E000C943E000C943E0082 2 | :100010000C943E000C943E000C943E000C943E0068 3 | :100020000C943E000C943E000C943E000C943E0058 4 | :100030000C943E000C943E000C943E000C943E0048 5 | :100040000C943E000C943E000C943E000C943E0038 6 | :100050000C943E000C943E000C943E000C943E0028 7 | :100060000C943E000C943E0011241FBECFEFD8E04C 8 | :10007000DEBFCDBF0E9440000C9451000C940000E4 9 | :100080008FEF84B915B891E085B1892785B92FEF35 10 | :1000900031EE84E0215030408040E1F700C00000A4 11 | :0600A000F3CFF894FFCF3E 12 | :00000001FF 13 | -------------------------------------------------------------------------------- /tests/atmega328p/toggle-pin/firmware.hex.txt: -------------------------------------------------------------------------------- 1 | 2 | /usr/home/dsl/git/MCUSim/tests/ATMEGA328-toggle-pin/build/firmware.hex: file format ihex 3 | 4 | 5 | Disassembly of section .sec1: 6 | 7 | 00000000 <.sec1>: 8 | 0: 0c 94 34 00 jmp 0x68 ; 0x68 9 | 4: 0c 94 3e 00 jmp 0x7c ; 0x7c 10 | 8: 0c 94 3e 00 jmp 0x7c ; 0x7c 11 | c: 0c 94 3e 00 jmp 0x7c ; 0x7c 12 | 10: 0c 94 3e 00 jmp 0x7c ; 0x7c 13 | 14: 0c 94 3e 00 jmp 0x7c ; 0x7c 14 | 18: 0c 94 3e 00 jmp 0x7c ; 0x7c 15 | 1c: 0c 94 3e 00 jmp 0x7c ; 0x7c 16 | 20: 0c 94 3e 00 jmp 0x7c ; 0x7c 17 | 24: 0c 94 3e 00 jmp 0x7c ; 0x7c 18 | 28: 0c 94 3e 00 jmp 0x7c ; 0x7c 19 | 2c: 0c 94 3e 00 jmp 0x7c ; 0x7c 20 | 30: 0c 94 3e 00 jmp 0x7c ; 0x7c 21 | 34: 0c 94 3e 00 jmp 0x7c ; 0x7c 22 | 38: 0c 94 3e 00 jmp 0x7c ; 0x7c 23 | 3c: 0c 94 3e 00 jmp 0x7c ; 0x7c 24 | 40: 0c 94 3e 00 jmp 0x7c ; 0x7c 25 | 44: 0c 94 3e 00 jmp 0x7c ; 0x7c 26 | 48: 0c 94 3e 00 jmp 0x7c ; 0x7c 27 | 4c: 0c 94 3e 00 jmp 0x7c ; 0x7c 28 | 50: 0c 94 3e 00 jmp 0x7c ; 0x7c 29 | 54: 0c 94 3e 00 jmp 0x7c ; 0x7c 30 | 58: 0c 94 3e 00 jmp 0x7c ; 0x7c 31 | 5c: 0c 94 3e 00 jmp 0x7c ; 0x7c 32 | 60: 0c 94 3e 00 jmp 0x7c ; 0x7c 33 | 64: 0c 94 3e 00 jmp 0x7c ; 0x7c 34 | 68: 11 24 eor r1, r1 35 | 6a: 1f be out 0x3f, r1 ; 63 36 | 6c: cf ef ldi r28, 0xFF ; 255 37 | 6e: d8 e0 ldi r29, 0x08 ; 8 38 | 70: de bf out 0x3e, r29 ; 62 39 | 72: cd bf out 0x3d, r28 ; 61 40 | 74: 0e 94 40 00 call 0x80 ; 0x80 41 | 78: 0c 94 51 00 jmp 0xa2 ; 0xa2 42 | 7c: 0c 94 00 00 jmp 0 ; 0x0 43 | 80: 8f ef ldi r24, 0xFF ; 255 44 | 82: 84 b9 out 0x04, r24 ; 4 45 | 84: 15 b8 out 0x05, r1 ; 5 46 | 86: 91 e0 ldi r25, 0x01 ; 1 47 | 88: 85 b1 in r24, 0x05 ; 5 48 | 8a: 89 27 eor r24, r25 49 | 8c: 85 b9 out 0x05, r24 ; 5 50 | 8e: 2f ef ldi r18, 0xFF ; 255 51 | 90: 31 ee ldi r19, 0xE1 ; 225 52 | 92: 84 e0 ldi r24, 0x04 ; 4 53 | 94: 21 50 subi r18, 0x01 ; 1 54 | 96: 30 40 sbci r19, 0x00 ; 0 55 | 98: 80 40 sbci r24, 0x00 ; 0 56 | 9a: e1 f7 brne .-8 ; 0x94 57 | 9c: 00 c0 rjmp .+0 ; 0x9e 58 | 9e: 00 00 nop 59 | a0: f3 cf rjmp .-26 ; 0x88 60 | a2: f8 94 cli 61 | a4: ff cf rjmp .-2 ; 0xa4 62 | -------------------------------------------------------------------------------- /tests/atmega328p/toggle-pin/fuse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | FUSES = { 22 | .low = LFUSE_DEFAULT | 0x3f, 23 | .high = HFUSE_DEFAULT & ~(1 << 4) 24 | }; 25 | -------------------------------------------------------------------------------- /tests/atmega328p/toggle-pin/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #define F_CPU 8000000UL 20 | #include 21 | #include 22 | 23 | int 24 | main(void) 25 | { 26 | DDRB = 0xFF; // sets PORTB to output 27 | PORTB = 0x00; // sets output pins to low 28 | while (1) { 29 | PORTB ^= (1<<0); 30 | _delay_ms(200); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/atmega328p/toggle-pin/mcusim.conf: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | # 4 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | # 6 | # MCUSim is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # MCUSim is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | # This is an MCUSim configuration file. You may adjust it to setup your own 21 | # simulation. 22 | 23 | # Model of the simulated microcontroller. 24 | # 25 | # ATmega8: mcu m8 26 | # ATmega328: mcu m328 27 | # ATmega328p: mcu m328p 28 | mcu m328p 29 | 30 | # Microcontroller clock frequency (in Hz). 31 | mcu_freq 8000000 32 | 33 | # Microcontroller lock bits and fuse bytes. 34 | # 35 | #mcu_lockbits 0x00 36 | mcu_efuse 0xF7 37 | mcu_hfuse 0xDB 38 | mcu_lfuse 0xFF 39 | 40 | # File to load a content of flash memory from. 41 | firmware_file firmware.hex 42 | 43 | # Reset flash memory flag. 44 | # 45 | # Flash memory of the microcontrollers can be preserved between the different 46 | # simulations by default. Memory preserving means that the flash memory can be 47 | # saved in a separate utility file before the end of a simulation and 48 | # loaded back during the next one. 49 | # 50 | # Default value (no) means that the utility file has a priority over the one 51 | # provided by the 'firmware_file' option. 52 | reset_flash yes 53 | 54 | # Lua models which will be loaded and used during the simulation. 55 | lua_model check-pin.lua 56 | 57 | # Firmware test flag. Simulation can be started in a firmware test mode in 58 | # which simulator will not be waiting for any external event (like a command 59 | # from debugger) to continue with the simulation. 60 | firmware_test yes 61 | 62 | # Name of the VCD (Value Change Dump) file to be generated during the 63 | # simulation process to collect data and trace signals after the simulation. 64 | vcd_file trace.vcd 65 | 66 | # Microcontroller registers to be dumped to the VCD file. 67 | dump_reg DDRB 68 | dump_reg PORTB0 69 | 70 | # Port of the RSP target. AVR GDB can be used to connect to the port and 71 | # debug firmware of the microcontroller. 72 | rsp_port 12750 73 | 74 | # Flag to trap AVR GDB when interrupt occured. 75 | trap_at_isr no 76 | -------------------------------------------------------------------------------- /tests/atmega328p/wdt-interrupt/fuse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | FUSES = { 22 | .low = LFUSE_DEFAULT | 0x3f, 23 | .high = HFUSE_DEFAULT & ~(1 << 4) 24 | }; 25 | -------------------------------------------------------------------------------- /tests/atmega328p/wdt-interrupt/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #define F_CPU 16000000UL 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #define SET_BIT(byte, bit) ((byte)|=(1UL<<(bit))) 26 | #define CLEAR_BIT(byte, bit) ((byte)&=~(1UL<<(bit))) 27 | #define IS_SET(byte, bit) (((byte)&(1UL<<(bit)))>>(bit)) 28 | 29 | static void 30 | wdt_init(void); 31 | 32 | int 33 | main(void) 34 | { 35 | /* Initialize WDT */ 36 | wdt_init(); 37 | 38 | /* 39 | * Let's run an infinite loop in the main program's body. 40 | * All of the interesting stuff will be done in the WDT ISR. 41 | */ 42 | while (1) {} 43 | 44 | return 0; 45 | } 46 | 47 | static void 48 | wdt_init(void) 49 | { 50 | /* Disable interupts */ 51 | cli(); 52 | 53 | /* Prepare WDT to be changed */ 54 | WDTCSR |= (1<. 19 | 20 | --]] 21 | VERBOSE = false -- Switch on to enable verbose output 22 | TICK_TIME = 0.0 -- clock period, in us 23 | 24 | ticks_passed = 0 25 | check_point = 0 -- TCNT0 is 0 at start, count up to 255 then 26 | -- and reset by overflow interrupt 27 | 28 | function module_conf(mcu) 29 | -- Re-calculate clock period, in us 30 | TICK_TIME = (1.0/MSIM_Freq(mcu))*1000000.0 31 | if VERBOSE then 32 | print("MCU clock: " .. MSIM_Freq(mcu)/1000 .. "kHz") 33 | print("MCU clock period: " .. TICK_TIME .. "us") 34 | end 35 | end 36 | 37 | function module_tick(mcu) 38 | if check_point == 0 and AVR_ReadIO(mcu, TCNT0) == 0 then 39 | check_point = check_point + 1 40 | elseif check_point == 1 and AVR_ReadIO(mcu, TCNT0) == 255 then 41 | check_point = check_point + 1 42 | elseif check_point == 2 and AVR_ReadIO(mcu, TCNT0) == 0 then 43 | -- Test finished successfully 44 | MSIM_SetState(mcu, AVR_MSIM_STOP) 45 | print("ticks passed: " .. ticks_passed) 46 | elseif ticks_passed > 100000 then 47 | -- Test failed 48 | MSIM_SetState(mcu, AVR_MSIM_TESTFAIL) 49 | print("ticks passed: " .. ticks_passed) 50 | end 51 | 52 | ticks_passed = ticks_passed + 1 53 | end 54 | 55 | -------------------------------------------------------------------------------- /tests/atmega8a/timer0-ext-clock-source/external-clock.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | 5 | Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | 7 | MCUSim is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | MCUSim is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | --]] 21 | VERBOSE = true -- Switch on to enable verbose output 22 | TICK_TIME = 0.0 -- clock period, in us 23 | DELAY = 3 -- Number of system clock cycles between two 24 | -- neighbor rises and falls of the external 25 | -- clock. 26 | 27 | clock_del = DELAY 28 | 29 | function module_conf(mcu) 30 | TICK_TIME = (1.0/MSIM_Freq(mcu))*1000000.0 31 | if VERBOSE then 32 | print("MCU clock: " .. MSIM_Freq(mcu)/1000 .. "kHz") 33 | print("MCU clock period: " .. TICK_TIME .. "us") 34 | end 35 | end 36 | 37 | function module_tick(mcu) 38 | if clock_del == 0 and AVR_IOBit(mcu, PIND, 4) then 39 | AVR_SetIOBit(mcu, PIND, 4, 0) 40 | clock_del = DELAY 41 | elseif clock_del == 0 and not AVR_IOBit(mcu, PIND, 4) then 42 | AVR_SetIOBit(mcu, PIND, 4, 1) 43 | clock_del = DELAY 44 | elseif clock_del ~= 0 then 45 | clock_del = clock_del-1 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /tests/atmega8a/timer0-ext-clock-source/firmware.hex: -------------------------------------------------------------------------------- 1 | :1000000012C021C020C01FC01EC01DC01CC01BC00C 2 | :100010001AC022C018C017C016C015C014C013C023 3 | :1000200012C011C010C011241FBECFE5D4E0DEBF46 4 | :10003000CDBF20E0A0E6B0E001C01D92A136B2071E 5 | :10004000E1F722D026C0DCCF83B7876083BF12BE22 6 | :1000500089B7816089BF08951F920F920FB60F92E2 7 | :1000600011248F93809160008F3F19F410926000EB 8 | :1000700005C0809160008F5F809360008F910F902A 9 | :100080000FBE0F901F90189510926000DDDF7894DE 10 | :06009000FFCFF894FFCF42 11 | :00000001FF 12 | -------------------------------------------------------------------------------- /tests/atmega8a/timer0-ext-clock-source/fuse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | FUSES = { 22 | .low = LFUSE_DEFAULT | 0x3f, 23 | .high = HFUSE_DEFAULT & ~(1 << 4) 24 | }; 25 | -------------------------------------------------------------------------------- /tests/atmega8a/timer0-ext-clock-source/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #define F_CPU 16000000UL 20 | #include 21 | #include 22 | #include 23 | 24 | #define SET_BIT(byte, bit) ((byte)|=(1UL<<(bit))) 25 | #define CLEAR_BIT(byte, bit) ((byte)&=~(1UL<<(bit))) 26 | #define IS_SET(byte, bit) (((byte)&(1UL<<(bit)))>>(bit)) 27 | 28 | #define DHT_PORT_OUT PORTB 29 | #define DHT_PORT_IN PINB 30 | #define DHT_PIN PB0 31 | 32 | void timer0_init(void); 33 | 34 | static volatile unsigned char intn = 0; 35 | 36 | int 37 | main(void) 38 | { 39 | timer0_init(); 40 | sei(); 41 | 42 | while (1) {} 43 | return 0; 44 | } 45 | 46 | void 47 | timer0_init(void) 48 | { 49 | /* External clock source on T0 pin, rising edge. */ 50 | TCCR0 |= (1<. 18 | # 19 | 20 | # This is an MCUSim configuration file. You may adjust it to setup your own 21 | # simulation. 22 | 23 | # Model of the simulated microcontroller. 24 | # 25 | # ATmega8: mcu m8 26 | # ATmega328: mcu m328 27 | # ATmega328p: mcu m328p 28 | mcu m8a 29 | 30 | # Microcontroller clock frequency (in Hz). 31 | mcu_freq 16000000 32 | 33 | # Microcontroller lock bits and fuse bytes. 34 | # 35 | #mcu_lockbits 0x00 36 | #mcu_efuse 0xFF 37 | mcu_hfuse 0xC9 38 | mcu_lfuse 0xEF 39 | 40 | # File to load a content of flash memory from. 41 | firmware_file firmware.hex 42 | 43 | # Reset flash memory flag. 44 | # 45 | # Flash memory of the microcontrollers can be preserved between the different 46 | # simulations by default. Memory preserving means that the flash memory can be 47 | # saved in a separate utility file before the end of a simulation and 48 | # loaded back during the next one. 49 | # 50 | # Default value (no) means that the utility file has a priority over the one 51 | # provided by the 'firmware_file' option. 52 | reset_flash yes 53 | 54 | # Lua models which will be loaded and used during the simulation. 55 | lua_model check-timer0.lua 56 | lua_model external-clock.lua 57 | 58 | # Firmware test flag. Simulation can be started in a firmware test mode in 59 | # which simulator will not be waiting for any external event (like a command 60 | # from debugger) to continue with the simulation. 61 | firmware_test yes 62 | 63 | # Name of the VCD (Value Change Dump) file to be generated during the 64 | # simulation process to collect data and trace signals after the simulation. 65 | vcd_file trace.vcd 66 | 67 | # Microcontroller registers to be dumped to the VCD file. 68 | #dump_reg PORTA 69 | #dump_reg PORTB 70 | #dump_reg PORTC 71 | 72 | # Port of the RSP target. AVR GDB can be used to connect to the port and 73 | # debug firmware of the microcontroller. 74 | rsp_port 12750 75 | 76 | # Flag to trap AVR GDB when interrupt occured. 77 | trap_at_isr no 78 | -------------------------------------------------------------------------------- /tests/atmega8a/timer0-normal/check-timer0.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | 5 | Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | 7 | MCUSim is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | MCUSim is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | --]] 21 | ticks_passed = 0 22 | check_point = 0 -- TCNT0 is 0 at start, count up to 255 then 23 | -- and reset by overflow interrupt 24 | 25 | function module_conf(mcu) 26 | end 27 | 28 | function module_tick(mcu) 29 | if check_point == 0 and AVR_ReadIO(mcu, TCNT0) == 0 then 30 | check_point = check_point + 1 31 | elseif check_point == 1 and AVR_ReadIO(mcu, TCNT0) == 255 then 32 | check_point = check_point + 1 33 | elseif check_point == 2 and AVR_ReadIO(mcu, TCNT0) == 0 then 34 | check_point = check_point + 1 35 | elseif check_point == 3 and AVR_ReadIO(mcu, TCNT0) == 255 then 36 | check_point = check_point + 1 37 | elseif check_point == 4 and AVR_ReadIO(mcu, TCNT0) == 64 then 38 | -- Test finished successfully 39 | MSIM_SetState(mcu, AVR_MSIM_STOP) 40 | print("ticks passed: " .. ticks_passed) 41 | elseif ticks_passed > 100000 then 42 | -- Test failed 43 | MSIM_SetState(mcu, AVR_MSIM_TESTFAIL) 44 | print("ticks passed: " .. ticks_passed) 45 | end 46 | 47 | ticks_passed = ticks_passed + 1 48 | end 49 | -------------------------------------------------------------------------------- /tests/atmega8a/timer0-normal/firmware.hex: -------------------------------------------------------------------------------- 1 | :1000000012C021C020C01FC01EC01DC01CC01BC00C 2 | :100010001AC051C018C017C016C015C014C013C0F4 3 | :1000200012C011C010C011241FBECFE5D4E0DEBF46 4 | :10003000CDBF20E0A0E6B0E001C01D92A136B2071E 5 | :10004000E1F702D059C0DCCFCF93DF93CDB7DEB755 6 | :1000500002D07894FFCFCF93DF93CDB7DEB782E5A0 7 | :1000600090E0FC01108289E590E029E530E0F9019B 8 | :1000700020812160FC01208383E590E023E530E0CE 9 | :10008000F90120812B7FFC01208383E590E023E5AB 10 | :1000900030E0F90120812260FC01208383E590E0BB 11 | :1000A00023E530E0F90120812E7FFC012083000050 12 | :1000B000DF91CF9108951F920F9200905F000F92F1 13 | :1000C00011248F93CF93DF93CDB7DEB7809160007B 14 | :1000D0008F3F19F41092600005C0809160008F5F1F 15 | :1000E000809360000000DF91CF918F910F9000927C 16 | :0C00F0005F000F901F901895F894FFCF50 17 | :00000001FF 18 | -------------------------------------------------------------------------------- /tests/atmega8a/timer0-normal/fuse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | FUSES = { 22 | .low = LFUSE_DEFAULT | 0x3f, 23 | .high = HFUSE_DEFAULT & ~(1 << 4) 24 | }; 25 | -------------------------------------------------------------------------------- /tests/atmega8a/timer0-normal/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #define F_CPU 16000000UL 20 | #include 21 | #include 22 | #include 23 | 24 | #define SET_BIT(byte, bit) ((byte)|=(1UL<<(bit))) 25 | #define CLEAR_BIT(byte, bit) ((byte)&=~(1UL<<(bit))) 26 | #define IS_SET(byte, bit) (((byte)&(1UL<<(bit)))>>(bit)) 27 | 28 | #define DHT_PORT_OUT PORTB 29 | #define DHT_PORT_IN PINB 30 | #define DHT_PIN PB0 31 | 32 | void timer0_init(void); 33 | 34 | static volatile unsigned char intn = 0; 35 | 36 | int 37 | main(void) 38 | { 39 | timer0_init(); 40 | sei(); 41 | while (1) { 42 | } 43 | 44 | return 0; 45 | } 46 | 47 | void 48 | timer0_init(void) 49 | { 50 | TCNT0 = 0; /* Counter to 0 */ 51 | TIMSK |= (1<. 18 | # 19 | 20 | # This is an MCUSim configuration file. You may adjust it to setup your own 21 | # simulation. 22 | 23 | # Model of the simulated microcontroller. 24 | # 25 | # ATmega8: mcu m8 26 | # ATmega328: mcu m328 27 | # ATmega328p: mcu m328p 28 | mcu m8a 29 | 30 | # Microcontroller clock frequency (in Hz). 31 | mcu_freq 16000000 32 | 33 | # Microcontroller lock bits and fuse bytes. 34 | # 35 | #mcu_lockbits 0x00 36 | #mcu_efuse 0xFF 37 | mcu_hfuse 0xC9 38 | mcu_lfuse 0xEF 39 | 40 | # File to load a content of flash memory from. 41 | firmware_file firmware.hex 42 | 43 | # Reset flash memory flag. 44 | # 45 | # Flash memory of the microcontrollers can be preserved between the different 46 | # simulations by default. Memory preserving means that the flash memory can be 47 | # saved in a separate utility file before the end of a simulation and 48 | # loaded back during the next one. 49 | # 50 | # Default value (no) means that the utility file has a priority over the one 51 | # provided by the 'firmware_file' option. 52 | reset_flash yes 53 | 54 | # Lua models which will be loaded and used during the simulation. 55 | lua_model check-timer0.lua 56 | 57 | # Firmware test flag. Simulation can be started in a firmware test mode in 58 | # which simulator will not be waiting for any external event (like a command 59 | # from debugger) to continue with the simulation. 60 | firmware_test yes 61 | 62 | # Name of the VCD (Value Change Dump) file to be generated during the 63 | # simulation process to collect data and trace signals after the simulation. 64 | vcd_file trace.vcd 65 | 66 | # Microcontroller registers to be dumped to the VCD file. 67 | dump_reg TCNT0 68 | dump_reg TCCR0 69 | dump_reg TIMSK0 70 | dump_reg TIFR0 71 | 72 | # Port of the RSP target. AVR GDB can be used to connect to the port and 73 | # debug firmware of the microcontroller. 74 | rsp_port 12750 75 | 76 | # Flag to trap AVR GDB when interrupt occured. 77 | trap_at_isr no 78 | -------------------------------------------------------------------------------- /tests/atmega8a/timer1-fastpwm/firmware.hex: -------------------------------------------------------------------------------- 1 | :1000000012C021C020C01FC01EC01DC01CC01BC00C 2 | :10001000A0C019C018C017C016C015C014C013C0A6 3 | :1000200012C011C010C011241FBECFE5D4E0DEBF46 4 | :10003000CDBF20E0A0E6B0E001C01D92A236B2071D 5 | :10004000E1F702D0DDC0DCCFCF93DF93CDB7DEB7D1 6 | :1000500002D07894FFCFCF93DF931F92CDB7DEB756 7 | :100060008FE490E02FE430E0F90120812068FC016A 8 | :1000700020838FE490E02FE430E0F90120812F7B92 9 | :10008000FC0120838FE490E02FE430E0F90120812F 10 | :100090002062FC0120838FE490E02FE430E0F9013E 11 | :1000A00020812F7EFC0120838EE490E02EE430E05E 12 | :1000B000F90120812861FC0120838FE490E02FE486 13 | :1000C00030E0F90120812360FC01208387E390E088 14 | :1000D00027E330E0F90120812660FC0120838CE4D5 15 | :1000E00090E0FC01118210828AE490E02FEF35E06D 16 | :1000F000FC013183208388E490E020E034E0FC01BF 17 | :100100003183208381E090E09093610080936000D0 18 | :1001100089E590E029E530E0F90120812460FC01C7 19 | :1001200020838EE490E0FC018081898389818B7F2C 20 | :10013000898389818260898389818E7F89838EE426 21 | :1001400090E02981FC01208300000F90DF91CF9186 22 | :1001500008951F920F9200905F000F9211242F9329 23 | :100160003F938F939F93EF93FF93CF93DF93CDB7FD 24 | :10017000DEB780916000909161000197C9F488E436 25 | :1001800090E028E430E0F90120813181205F3F4F89 26 | :10019000FC013183208388E490E0FC01808191811F 27 | :1001A0008F3F9540F0F0109261001092600019C0EE 28 | :1001B00088E490E028E430E0F90120813181205189 29 | :1001C0003109FC013183208388E490E0FC018081C7 30 | :1001D0009181892B31F481E090E0909361008093CC 31 | :1001E00060000000DF91CF91FF91EF919F918F917F 32 | :1001F0003F912F910F9000925F000F901F901895E4 33 | :04020000F894FFCFA0 34 | :00000001FF 35 | -------------------------------------------------------------------------------- /tests/atmega8a/timer1-fastpwm/fuse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | FUSES = { 22 | .low = LFUSE_DEFAULT | 0x3f, 23 | .high = HFUSE_DEFAULT & ~(1 << 4) 24 | }; 25 | -------------------------------------------------------------------------------- /tests/atmega8a/timer1-fastpwm/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #define F_CPU 16000000UL 20 | #include 21 | #include 22 | #include 23 | 24 | #define SET_BIT(byte, bit) ((byte)|=(1UL<<(bit))) 25 | #define CLEAR_BIT(byte, bit) ((byte)&=~(1UL<<(bit))) 26 | #define IS_SET(byte, bit) (((byte)&(1UL<<(bit)))>>(bit)) 27 | 28 | void timer1_init(void); 29 | 30 | static volatile int ocr1a_up; 31 | 32 | int 33 | main(void) 34 | { 35 | timer1_init(); 36 | sei(); 37 | 38 | while (1) { 39 | } 40 | return 0; 41 | } 42 | 43 | void 44 | timer1_init(void) 45 | { 46 | uint8_t tccr1b; 47 | 48 | /* Clear OC1A and OC1B on Compare Match and set OC1A and OC1B at 49 | * BOTTOM (non-inverting mode): COM1A1:0 = 2, COM1B1:0 = 2. */ 50 | TCCR1A |= (1<= 0x05FF) { 83 | ocr1a_up = 0; 84 | } 85 | } else { 86 | OCR1B -= 0x0010; 87 | if (OCR1B == 0x0000) { 88 | ocr1a_up = 1; 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /tests/atmega8a/timer1-fastpwm/stop-test.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | 5 | Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | 7 | MCUSim is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | MCUSim is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | --]] 21 | VERBOSE = true -- Switch on to enable verbose output 22 | TICK_TIME = 0.0 -- clock period, in us 23 | 24 | ticks_passed = 0 25 | 26 | -- This function will be called by the simulator only once to configure 27 | -- model before start of a simulation. 28 | function module_conf(mcu) 29 | -- Re-calculate clock period, in us 30 | TICK_TIME = (1.0/MSIM_Freq(mcu))*1000000.0 31 | if VERBOSE then 32 | print("[Test stopper] MCU clock: " .. MSIM_Freq(mcu)/1000 .. 33 | "kHz") 34 | print("[Test stopper] MCU clock period: " .. TICK_TIME .. 35 | "us") 36 | end 37 | end 38 | 39 | -- This function will be called by the simulator periodically according to the 40 | -- main simulation loop, i.e. time passed between two neighbor calls to the 41 | -- function is a period. 42 | function module_tick(mcu) 43 | if ticks_passed > 400000 then 44 | -- Test finished successfully 45 | MSIM_SetState(mcu, AVR_MSIM_STOP) 46 | print("[Test stopper] ticks passed: " .. ticks_passed) 47 | end 48 | 49 | ticks_passed = ticks_passed + 1 50 | end 51 | 52 | -------------------------------------------------------------------------------- /tests/atmega8a/timer1-normal/check-timer1.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | 5 | Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | 7 | MCUSim is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | MCUSim is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | --]] 21 | ticks_passed = 0 22 | check_point = 0 23 | 24 | function module_conf(mcu) 25 | end 26 | 27 | function module_tick(mcu) 28 | if check_point == 0 and AVR_ReadIO(mcu, TCNT1H) == 0 then 29 | check_point = check_point + 1 30 | elseif check_point == 1 and AVR_ReadIO(mcu, TCNT1H) == 255 then 31 | check_point = check_point + 1 32 | elseif check_point == 2 and AVR_ReadIO(mcu, TCNT1H) == 0 then 33 | check_point = check_point + 1 34 | elseif check_point == 3 and AVR_ReadIO(mcu, TCNT1H) == 255 then 35 | check_point = check_point + 1 36 | elseif check_point == 4 and AVR_ReadIO(mcu, TCNT1H) == 64 then 37 | -- Test finished successfully 38 | MSIM_SetState(mcu, AVR_MSIM_STOP) 39 | print("ticks passed: " .. ticks_passed) 40 | elseif ticks_passed > 1500000 then 41 | -- Test failed 42 | MSIM_SetState(mcu, AVR_MSIM_TESTFAIL) 43 | print("ticks passed: " .. ticks_passed) 44 | end 45 | 46 | ticks_passed = ticks_passed + 1 47 | end 48 | -------------------------------------------------------------------------------- /tests/atmega8a/timer1-normal/firmware.hex: -------------------------------------------------------------------------------- 1 | :1000000012C021C020C01FC01EC01DC01CC01BC00C 2 | :10001000B1C019C018C017C016C015C014C013C095 3 | :1000200012C011C010C011241FBECFE5D4E0DEBF46 4 | :10003000CDBF20E0A0E6B0E001C01D92A236B2071D 5 | :10004000E1F702D0BEC0DCCFCF93DF93CDB7DEB7F0 6 | :1000500002D07894FFCFCF93DF93CDB7DEB78FE494 7 | :1000600090E02FE430E0F90120812064FC0120833E 8 | :100070008FE490E02FE430E0F90120812F77FC013C 9 | :1000800020838FE490E02FE430E0F90120812061AB 10 | :10009000FC0120838FE490E02FE430E0F90120811F 11 | :1000A0002F7DFC0120838FE490E02FE430E0F90104 12 | :1000B00020812E7FFC0120838FE490E02FE430E04C 13 | :1000C000F90120812D7FFC0120838EE490E02EE455 14 | :1000D00030E0F9012081277FFC0120838EE490E04D 15 | :1000E0002EE430E0F90120812F7EFC01208387E39C 16 | :1000F00090E027E330E0F90120812860FC012083B3 17 | :1001000084E490E0FC0110828AE490E024EA36E086 18 | :10011000FC013183208388E490E02CED35E0FC0184 19 | :100120003183208389E590E029E530E0F9012081E1 20 | :100130002C61FC0120838EE490E02EE430E0F90194 21 | :1001400020812E7FFC0120838EE490E02EE430E0BD 22 | :10015000F90120812260FC0120838EE490E02EE4EE 23 | :1001600030E0F90120812B7FFC0120830000DF912A 24 | :10017000CF9108951F920F9200905F000F9211246B 25 | :100180002F938F939F93CF93DF93CDB7DEB780915B 26 | :1001900060009091610021E0892B09F020E0822F1E 27 | :1001A00090E090936100809360000000DF91CF9118 28 | :1001B0009F918F912F910F9000925F000F901F9051 29 | :0601C0001895F894FFCF32 30 | :00000001FF 31 | -------------------------------------------------------------------------------- /tests/atmega8a/timer1-normal/fuse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | FUSES = { 22 | .low = LFUSE_DEFAULT | 0x3f, 23 | .high = HFUSE_DEFAULT & ~(1 << 4) 24 | }; 25 | -------------------------------------------------------------------------------- /tests/atmega8a/timer1-normal/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #define F_CPU 16000000UL 20 | #include 21 | #include 22 | #include 23 | 24 | #define SET_BIT(byte, bit) ((byte)|=(1UL<<(bit))) 25 | #define CLEAR_BIT(byte, bit) ((byte)&=~(1UL<<(bit))) 26 | #define IS_SET(byte, bit) (((byte)&(1UL<<(bit)))>>(bit)) 27 | 28 | void timer1_init(void); 29 | 30 | static volatile int ocr2_up = 0; 31 | 32 | int 33 | main(void) 34 | { 35 | timer1_init(); 36 | sei(); 37 | 38 | while (1) { 39 | } 40 | return 0; 41 | } 42 | 43 | void 44 | timer1_init(void) 45 | { 46 | /* Toggle OC1A/OC1B on Compare Match */ 47 | TCCR1A |= (1<. 18 | # 19 | 20 | # Model of the simulated microcontroller. 21 | # ATmega8: mcu m8 22 | # ATmega328: mcu m328 23 | # ATmega328p: mcu m328p 24 | mcu m8a 25 | 26 | # Microcontroller clock frequency (in Hz). 27 | mcu_freq 16000000 28 | 29 | # Microcontroller lock bits and fuse bytes. 30 | # 31 | #mcu_lockbits 0x00 32 | #mcu_efuse 0xFF 33 | mcu_hfuse 0xC9 34 | mcu_lfuse 0xEF 35 | 36 | # File to load a content of flash memory from. 37 | firmware_file firmware.hex 38 | 39 | # Reset flash memory flag. 40 | # 41 | # Flash memory of the microcontrollers can be preserved between the different 42 | # simulations by default. Memory preserving means that the flash memory can be 43 | # saved in a separate utility file before the end of a simulation and 44 | # loaded back during the next one. 45 | # 46 | # Default value (no) means that the utility file has a priority over the one 47 | # provided by the 'firmware_file' option. 48 | reset_flash yes 49 | 50 | # Lua models which will be loaded and used during the simulation. 51 | lua_model check-timer1.lua 52 | 53 | # Firmware test flag. Simulation can be started in a firmware test mode in 54 | # which simulator will not be waiting for any external event (like a command 55 | # from debugger) to continue with the simulation. 56 | firmware_test yes 57 | 58 | # Name of the VCD (Value Change Dump) file to be generated during the 59 | # simulation process to collect data and trace signals after the simulation. 60 | vcd_file trace.vcd 61 | 62 | # Microcontroller registers to be dumped to the VCD file. 63 | dump_reg TCNT1 64 | dump_reg TCCR1A 65 | dump_reg TCCR1B 66 | dump_reg OCR1A 67 | dump_reg OCR1B 68 | dump_reg TIMSK 69 | dump_reg TIFR2 70 | dump_reg TIFR3 71 | dump_reg TIFR4 72 | 73 | # Port of the RSP target. AVR GDB can be used to connect to the port and 74 | # debug firmware of the microcontroller. 75 | rsp_port 12750 76 | 77 | # Flag to trap AVR GDB when interrupt occured. 78 | trap_at_isr no 79 | -------------------------------------------------------------------------------- /tests/atmega8a/timer2-ctc/check_OCR2_updated.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | 5 | Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | 7 | MCUSim is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | MCUSim is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | --]] 21 | VERBOSE = false -- Switch on to enable verbose output 22 | TICK_TIME = 0.0 -- clock period, in us 23 | 24 | ticks_passed = 0 25 | 26 | -- This function will be called by the simulator only once to configure 27 | -- model before start of a simulation. 28 | function module_conf(mcu) 29 | -- Re-calculate clock period, in us 30 | TICK_TIME = (1.0/MSIM_Freq(mcu))*1000000.0 31 | if VERBOSE then 32 | print("[check_OCR2_updated] MCU clock: " .. 33 | MSIM_Freq(mcu)/1000 .. "kHz") 34 | print("[check_OCR2_updated] MCU clock period: " .. 35 | TICK_TIME .. "us") 36 | end 37 | end 38 | 39 | -- This function will be called by the simulator periodically according to the 40 | -- main simulation loop, i.e. time passed between two neighbor calls to the 41 | -- function is a period. 42 | function module_tick(mcu) 43 | if AVR_ReadIO(mcu, OCR2) == 67 then 44 | if ticks_passed < 5000 then 45 | -- Test failed 46 | -- OCR2 updated too early 47 | MSIM_SetState(mcu, AVR_MSIM_TESTFAIL) 48 | print("[check_OCR2_updated] OCR2 updated too early") 49 | print("[check_OCR2_updated] ticks passed: " .. 50 | ticks_passed) 51 | else 52 | -- Test passed 53 | MSIM_SetState(mcu, AVR_MSIM_STOP) 54 | print("[check_OCR2_updated] OCR2 updated correctly") 55 | print("[check_OCR2_updated] ticks passed: " .. 56 | ticks_passed) 57 | end 58 | end 59 | ticks_passed = ticks_passed + 1 60 | end 61 | 62 | -------------------------------------------------------------------------------- /tests/atmega8a/timer2-ctc/firmware.hex: -------------------------------------------------------------------------------- 1 | :1000000012C021C020C041C01EC01DC01CC01BC0EA 2 | :100010001AC019C018C017C016C015C014C013C02C 3 | :1000200012C011C010C011241FBECFE5D4E0DEBF46 4 | :10003000CDBF20E0A0E6B0E001C01D92A236B2071D 5 | :10004000E1F743D045C0DCCF85B5886085BD85B577 6 | :100050008F7B85BDBB9A85B58F7D85BD85B580615C 7 | :1000600085BD109261001092600014BC8FEA83BDC0 8 | :1000700089B7806889BF85B58B7F85BD85B582606E 9 | :1000800085BD85B58E7F85BD08951F920F920FB6F1 10 | :100090000F9211248F939F93809160009091610043 11 | :1000A000039754F4809160009091610001969093C1 12 | :1000B00061008093600002C083E483BD9F918F91B3 13 | :1000C0000F900FBE0F901F901895BEDF7894FFCF52 14 | :0400D000F894FFCFD2 15 | :00000001FF 16 | -------------------------------------------------------------------------------- /tests/atmega8a/timer2-ctc/fuse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | FUSES = { 22 | .low = LFUSE_DEFAULT | 0x3f, 23 | .high = HFUSE_DEFAULT & ~(1 << 4) 24 | }; 25 | -------------------------------------------------------------------------------- /tests/atmega8a/timer2-ctc/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #define F_CPU 16000000UL 20 | #include 21 | #include 22 | #include 23 | 24 | #define SET_BIT(byte, bit) ((byte)|=(1UL<<(bit))) 25 | #define CLEAR_BIT(byte, bit) ((byte)&=~(1UL<<(bit))) 26 | #define IS_SET(byte, bit) (((byte)&(1UL<<(bit)))>>(bit)) 27 | 28 | void timer2_init(void); 29 | 30 | static volatile int cmp_count; 31 | 32 | int 33 | main(void) 34 | { 35 | /* Configure Timer/Counter2 before start. Global Interrupt Enable 36 | * bit is cleared by default (SREG I bit = 0). */ 37 | timer2_init(); 38 | 39 | /* Enable interrupts. */ 40 | sei(); 41 | /* Do nothing while waiting for the Timer/Counter2 interrupts. */ 42 | while (1) { 43 | } 44 | return 0; 45 | } 46 | 47 | void 48 | timer2_init(void) 49 | { 50 | /* CTC mode (WGM21:0 = 2), enable output on the pin */ 51 | TCCR2 |= (1<. 18 | # 19 | 20 | # This is an MCUSim configuration file. You may adjust it to setup your own 21 | # simulation. 22 | 23 | # Model of the simulated microcontroller. 24 | # 25 | # ATmega8: mcu m8 26 | # ATmega328: mcu m328 27 | # ATmega328p: mcu m328p 28 | mcu m8a 29 | 30 | # Microcontroller clock frequency (in Hz). 31 | mcu_freq 16000000 32 | 33 | # Microcontroller lock bits and fuse bytes. 34 | # 35 | #mcu_lockbits 0x00 36 | #mcu_efuse 0xFF 37 | mcu_hfuse 0xC9 38 | mcu_lfuse 0xEF 39 | 40 | # File to load a content of flash memory from. 41 | firmware_file firmware.hex 42 | 43 | # Reset flash memory flag. 44 | # 45 | # Flash memory of the microcontrollers can be preserved between the different 46 | # simulations by default. Memory preserving means that the flash memory can be 47 | # saved in a separate utility file before the end of a simulation and 48 | # loaded back during the next one. 49 | # 50 | # Default value (no) means that the utility file has a priority over the one 51 | # provided by the 'firmware_file' option. 52 | reset_flash yes 53 | 54 | # Lua models which will be loaded and used during the simulation. 55 | lua_model stop-test.lua 56 | lua_model check_OCR2_updated.lua 57 | 58 | # Firmware test flag. Simulation can be started in a firmware test mode in 59 | # which simulator will not be waiting for any external event (like a command 60 | # from debugger) to continue with the simulation. 61 | firmware_test yes 62 | 63 | # Name of the VCD (Value Change Dump) file to be generated during the 64 | # simulation process to collect data and trace signals after the simulation. 65 | vcd_file trace.vcd 66 | 67 | # Microcontroller registers to be dumped to the VCD file. 68 | dump_reg TCNT2 69 | dump_reg OCR2 70 | dump_reg TIFR7 71 | dump_reg PORTB3 72 | 73 | # Port of the RSP target. AVR GDB can be used to connect to the port and 74 | # debug firmware of the microcontroller. 75 | rsp_port 12750 76 | 77 | # Flag to trap AVR GDB when interrupt occured. 78 | trap_at_isr no 79 | -------------------------------------------------------------------------------- /tests/atmega8a/timer2-ctc/stop-test.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | 5 | Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | 7 | MCUSim is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | MCUSim is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | --]] 21 | VERBOSE = true -- Switch on to enable verbose output 22 | TICK_TIME = 0.0 -- clock period, in us 23 | 24 | ticks_passed = 0 25 | 26 | -- This function will be called by the simulator only once to configure 27 | -- model before start of a simulation. 28 | function module_conf(mcu) 29 | -- Re-calculate clock period, in us 30 | TICK_TIME = (1.0/MSIM_Freq(mcu))*1000000.0 31 | if VERBOSE then 32 | print("[Test stopper] MCU clock: " .. MSIM_Freq(mcu)/1000 .. 33 | "kHz") 34 | print("[Test stopper] MCU clock period: " .. TICK_TIME .. 35 | "us") 36 | end 37 | end 38 | 39 | -- This function will be called by the simulator periodically according to the 40 | -- main simulation loop, i.e. time passed between two neighbor calls to the 41 | -- function is a period. 42 | function module_tick(mcu) 43 | if ticks_passed > 400000 then 44 | -- Test finished successfully 45 | MSIM_SetState(mcu, AVR_MSIM_STOP) 46 | print("[Test stopper] ticks passed: " .. ticks_passed) 47 | end 48 | 49 | ticks_passed = ticks_passed + 1 50 | end 51 | 52 | -------------------------------------------------------------------------------- /tests/atmega8a/timer2-fastpwm/firmware.hex: -------------------------------------------------------------------------------- 1 | :1000000012C024C023C022C03CC020C01FC01EC0DC 2 | :100010001DC01CC01BC01AC019C018C017C016C014 3 | :1000200015C014C013C011241FBECFE5D4E0DEBF3D 4 | :10003000CDBF10E0A0E6B0E0E2EDF0E002C0059038 5 | :100040000D92A236B107D9F73FD041C0D9CF85B5BF 6 | :10005000806285BD85B58F7E85BD85B5886485BD8B 7 | :10006000BB9A14BC8CE383BD89B7806489BF85B516 8 | :100070008B7F85BD85B5826085BD85B58E7F85BD4D 9 | :1000800008951F920F920FB60F9211248F939F9392 10 | :100090008091600090916100019739F48EE183BDF9 11 | :1000A000109261001092600008C08CE383BD81E073 12 | :1000B00090E090936100809360009F918F910F90EA 13 | :1000C0000FBE0F901F901895C2DF7894FFCFF89461 14 | :0200D000FFCF60 15 | :0200D20001002B 16 | :00000001FF 17 | -------------------------------------------------------------------------------- /tests/atmega8a/timer2-fastpwm/fuse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | FUSES = { 22 | .low = LFUSE_DEFAULT | 0x3f, 23 | .high = HFUSE_DEFAULT & ~(1 << 4) 24 | }; 25 | -------------------------------------------------------------------------------- /tests/atmega8a/timer2-fastpwm/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #define F_CPU 16000000UL 20 | #include 21 | #include 22 | #include 23 | 24 | #define SET_BIT(byte, bit) ((byte)|=(1UL<<(bit))) 25 | #define CLEAR_BIT(byte, bit) ((byte)&=~(1UL<<(bit))) 26 | #define IS_SET(byte, bit) (((byte)&(1UL<<(bit)))>>(bit)) 27 | 28 | static volatile int ocr2_low = 1; 29 | 30 | void timer2_init(void); 31 | 32 | int 33 | main(void) 34 | { 35 | timer2_init(); 36 | sei(); 37 | 38 | while (1) {} 39 | return 0; 40 | } 41 | 42 | void 43 | timer2_init(void) 44 | { 45 | /* Non-inverting output mode: COM21:0 = 2 */ 46 | TCCR2 |= (1<. 18 | # 19 | 20 | # This is an MCUSim configuration file. You may adjust it to setup your own 21 | # simulation. 22 | 23 | # Model of the simulated microcontroller. 24 | # 25 | # ATmega8: mcu m8 26 | # ATmega328: mcu m328 27 | # ATmega328p: mcu m328p 28 | mcu m8a 29 | 30 | # Microcontroller clock frequency (in Hz). 31 | mcu_freq 16000000 32 | 33 | # Microcontroller lock bits and fuse bytes. 34 | # 35 | #mcu_lockbits 0x00 36 | #mcu_efuse 0xFF 37 | mcu_hfuse 0xC9 38 | mcu_lfuse 0xEF 39 | 40 | # File to load a content of flash memory from. 41 | firmware_file firmware.hex 42 | 43 | # Reset flash memory flag. 44 | # 45 | # Flash memory of the microcontrollers can be preserved between the different 46 | # simulations by default. Memory preserving means that the flash memory can be 47 | # saved in a separate utility file before the end of a simulation and 48 | # loaded back during the next one. 49 | # 50 | # Default value (no) means that the utility file has a priority over the one 51 | # provided by the 'firmware_file' option. 52 | reset_flash yes 53 | 54 | # Lua models which will be loaded and used during the simulation. 55 | lua_model check-pb3.lua 56 | 57 | # Firmware test flag. Simulation can be started in a firmware test mode in 58 | # which simulator will not be waiting for any external event (like a command 59 | # from debugger) to continue with the simulation. 60 | firmware_test yes 61 | 62 | # Name of the VCD (Value Change Dump) file to be generated during the 63 | # simulation process to collect data and trace signals after the simulation. 64 | vcd_file trace.vcd 65 | 66 | # Microcontroller registers to be dumped to the VCD file. 67 | dump_reg TCNT2 68 | dump_reg OCR2 69 | dump_reg TIFR6 70 | dump_reg PORTB3 71 | 72 | # Port of the RSP target. AVR GDB can be used to connect to the port and 73 | # debug firmware of the microcontroller. 74 | rsp_port 12750 75 | 76 | # Flag to trap AVR GDB when interrupt occured. 77 | trap_at_isr no 78 | -------------------------------------------------------------------------------- /tests/atmega8a/timer2-pcpwm/firmware.hex: -------------------------------------------------------------------------------- 1 | :1000000012C021C020C01FC08CC01DC01CC01BC09E 2 | :100010001AC019C018C017C016C015C014C013C02C 3 | :1000200012C011C010C011241FBECFE5D4E0DEBF46 4 | :10003000CDBF20E0A0E6B0E001C01D92A236B2071D 5 | :10004000E1F702D0BCC0DCCFCF93DF93CDB7DEB7F2 6 | :1000500002D07894FFCFCF93DF93CDB7DEB785E49E 7 | :1000600090E025E430E0F90120812062FC0120834A 8 | :1000700085E490E025E430E0F90120812F7EFC0149 9 | :10008000208385E490E025E430E0F90120812064BC 10 | :10009000FC01208385E490E025E430E0F901208133 11 | :1000A000277FFC01208387E390E027E330E0F9011C 12 | :1000B00020812860FC01208384E490E0FC01108210 13 | :1000C00083E490E02FEFFC012083109261001092F6 14 | :1000D000600089E590E029E530E0F90120812064A5 15 | :1000E000FC01208385E490E025E430E0F9012081E3 16 | :1000F0002B7FFC01208385E490E025E430E0F901CA 17 | :1001000020812260FC01208385E490E025E430E03A 18 | :10011000F90120812E7FFC0120830000DF91CF9127 19 | :1001200008951F920F9200905F000F9211242F9359 20 | :100130003F938F939F93EF93FF93CF93DF93CDB72D 21 | :10014000DEB78091600090916100892BA1F083E47B 22 | :1001500090E023E430E0F90120812B5FFC01208353 23 | :1001600083E490E0FC0180818F3FD1F41092610024 24 | :100170001092600015C083E490E023E430E0F901C0 25 | :1001800020812550FC01208383E490E0FC018081E4 26 | :10019000882331F481E090E09093610080936000C7 27 | :1001A0000000DF91CF91FF91EF919F918F913F914F 28 | :1001B0002F910F9000925F000F901F901895F89468 29 | :0201C000FFCF6F 30 | :00000001FF 31 | -------------------------------------------------------------------------------- /tests/atmega8a/timer2-pcpwm/fuse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | FUSES = { 22 | .low = LFUSE_DEFAULT | 0x3f, 23 | .high = HFUSE_DEFAULT & ~(1 << 4) 24 | }; 25 | -------------------------------------------------------------------------------- /tests/atmega8a/timer2-pcpwm/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #define F_CPU 16000000UL 20 | #include 21 | #include 22 | #include 23 | 24 | #define SET_BIT(byte, bit) ((byte)|=(1UL<<(bit))) 25 | #define CLEAR_BIT(byte, bit) ((byte)&=~(1UL<<(bit))) 26 | #define IS_SET(byte, bit) (((byte)&(1UL<<(bit)))>>(bit)) 27 | 28 | void timer2_init(void); 29 | 30 | static volatile int ocr2_up; 31 | 32 | int 33 | main(void) 34 | { 35 | timer2_init(); 36 | sei(); 37 | while (1) { 38 | } 39 | return 0; 40 | } 41 | 42 | void 43 | timer2_init(void) 44 | { 45 | /* Non-inverting compare match output mode: COM21:0 = 2 */ 46 | TCCR2 |= (1<. 18 | # 19 | 20 | # This is an MCUSim configuration file. You may adjust it to setup your own 21 | # simulation. 22 | 23 | # Model of the simulated microcontroller. 24 | # 25 | # ATmega8: mcu m8 26 | # ATmega328: mcu m328 27 | # ATmega328p: mcu m328p 28 | mcu m8a 29 | 30 | # Microcontroller clock frequency (in Hz). 31 | mcu_freq 16000000 32 | 33 | # Microcontroller lock bits and fuse bytes. 34 | # 35 | #mcu_lockbits 0x00 36 | #mcu_efuse 0xFF 37 | mcu_hfuse 0xC9 38 | mcu_lfuse 0xEF 39 | 40 | # File to load a content of flash memory from. 41 | firmware_file firmware.hex 42 | 43 | # Reset flash memory flag. 44 | # 45 | # Flash memory of the microcontrollers can be preserved between the different 46 | # simulations by default. Memory preserving means that the flash memory can be 47 | # saved in a separate utility file before the end of a simulation and 48 | # loaded back during the next one. 49 | # 50 | # Default value (no) means that the utility file has a priority over the one 51 | # provided by the 'firmware_file' option. 52 | reset_flash yes 53 | 54 | # Lua models which will be loaded and used during the simulation. 55 | lua_model check-pb3-rises.lua 56 | lua_model check-pb3-falls.lua 57 | 58 | # Firmware test flag. Simulation can be started in a firmware test mode in 59 | # which simulator will not be waiting for any external event (like a command 60 | # from debugger) to continue with the simulation. 61 | firmware_test yes 62 | 63 | # Name of the VCD (Value Change Dump) file to be generated during the 64 | # simulation process to collect data and trace signals after the simulation. 65 | vcd_file trace.vcd 66 | 67 | # Microcontroller registers to be dumped to the VCD file. 68 | dump_reg TCNT2 69 | dump_reg OCR2 70 | dump_reg TIFR6 71 | dump_reg PORTB3 72 | 73 | # Port of the RSP target. AVR GDB can be used to connect to the port and 74 | # debug firmware of the microcontroller. 75 | rsp_port 12750 76 | 77 | # Flag to trap AVR GDB when interrupt occured. 78 | trap_at_isr no 79 | -------------------------------------------------------------------------------- /tests/atmega8a/toggle-pin/fuse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | FUSES = { 22 | .low = LFUSE_DEFAULT | 0x3f, 23 | .high = HFUSE_DEFAULT & ~(1 << 4) 24 | }; 25 | -------------------------------------------------------------------------------- /tests/atmega8a/toggle-pin/m8a-clockpin.hex: -------------------------------------------------------------------------------- 1 | :1000000012C019C018C017C016C015C014C013C044 2 | :1000100012C011C010C00FC00EC00DC00CC00BC06C 3 | :100020000AC009C008C011241FBECFE5D4E0DEBF5E 4 | :10003000CDBF02D007C0E4CF11BA899A919A9198A6 5 | :08004000919AFDCFF894FFCF67 6 | :00000001FF 7 | -------------------------------------------------------------------------------- /tests/atmega8a/toggle-pin/m8a-clockpin.hex.txt: -------------------------------------------------------------------------------- 1 | 2 | /Users/dsalychev/git/atmega8a-clock-pin/release/m8a-clockpin.hex: file format ihex 3 | 4 | 5 | Disassembly of section .sec1: 6 | 7 | 00000000 <.sec1>: 8 | 0: 12 c0 rjmp .+36 ; 0x26 9 | 2: 19 c0 rjmp .+50 ; 0x36 10 | 4: 18 c0 rjmp .+48 ; 0x36 11 | 6: 17 c0 rjmp .+46 ; 0x36 12 | 8: 16 c0 rjmp .+44 ; 0x36 13 | a: 15 c0 rjmp .+42 ; 0x36 14 | c: 14 c0 rjmp .+40 ; 0x36 15 | e: 13 c0 rjmp .+38 ; 0x36 16 | 10: 12 c0 rjmp .+36 ; 0x36 17 | 12: 11 c0 rjmp .+34 ; 0x36 18 | 14: 10 c0 rjmp .+32 ; 0x36 19 | 16: 0f c0 rjmp .+30 ; 0x36 20 | 18: 0e c0 rjmp .+28 ; 0x36 21 | 1a: 0d c0 rjmp .+26 ; 0x36 22 | 1c: 0c c0 rjmp .+24 ; 0x36 23 | 1e: 0b c0 rjmp .+22 ; 0x36 24 | 20: 0a c0 rjmp .+20 ; 0x36 25 | 22: 09 c0 rjmp .+18 ; 0x36 26 | 24: 08 c0 rjmp .+16 ; 0x36 27 | 26: 11 24 eor r1, r1 28 | 28: 1f be out 0x3f, r1 ; 63 29 | 2a: cf e5 ldi r28, 0x5F ; 95 30 | 2c: d4 e0 ldi r29, 0x04 ; 4 31 | 2e: de bf out 0x3e, r29 ; 62 32 | 30: cd bf out 0x3d, r28 ; 61 33 | 32: 02 d0 rcall .+4 ; 0x38 34 | 34: 07 c0 rjmp .+14 ; 0x44 35 | 36: e4 cf rjmp .-56 ; 0x0 36 | 38: 11 ba out 0x11, r1 ; 17 37 | 3a: 89 9a sbi 0x11, 1 ; 17 38 | 3c: 91 9a sbi 0x12, 1 ; 18 39 | 3e: 91 98 cbi 0x12, 1 ; 18 40 | 40: 91 9a sbi 0x12, 1 ; 18 41 | 42: fd cf rjmp .-6 ; 0x3e 42 | 44: f8 94 cli 43 | 46: ff cf rjmp .-2 ; 0x46 44 | -------------------------------------------------------------------------------- /tests/atmega8a/toggle-pin/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | * 4 | * Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | * 6 | * MCUSim is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * MCUSim is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #define F_CPU 16000000UL 20 | #define __AVR_ATmega8A__ 1 21 | #include 22 | #include 23 | #include 24 | 25 | #define SET_BIT(byte, bit) ((byte)|=(1UL<<(bit))) 26 | #define CLEAR_BIT(byte, bit) ((byte)&=~(1UL<<(bit))) 27 | #define IS_SET(byte, bit) (((byte)&(1UL<<(bit)))>>(bit)) 28 | 29 | int 30 | main(void) 31 | { 32 | char cb; 33 | 34 | DDRD = 0; 35 | SET_BIT(DDRD, PD1); 36 | SET_BIT(PORTD, PD1); 37 | 38 | cb = 1; 39 | while (1) { 40 | if (cb) { 41 | CLEAR_BIT(PORTD, PD1); 42 | cb = 0; 43 | } else { 44 | SET_BIT(PORTD, PD1); 45 | cb = 1; 46 | } 47 | } 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /tests/atmega8a/toggle-pin/mcusim.conf: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | # 4 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | # 6 | # MCUSim is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # MCUSim is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | # This is an MCUSim configuration file. You may adjust it to setup your own 21 | # simulation. 22 | 23 | # Model of the simulated microcontroller. 24 | # 25 | # ATmega8: mcu m8 26 | # ATmega328: mcu m328 27 | # ATmega328p: mcu m328p 28 | mcu m8a 29 | 30 | # Microcontroller clock frequency (in Hz). 31 | mcu_freq 16000000 32 | 33 | # Microcontroller lock bits and fuse bytes. 34 | # 35 | #mcu_lockbits 0x00 36 | #mcu_efuse 0xFF 37 | mcu_hfuse 0xC9 38 | mcu_lfuse 0xEF 39 | 40 | # File to load a content of flash memory from. 41 | firmware_file m8a-clockpin.hex 42 | 43 | # Reset flash memory flag. 44 | # 45 | # Flash memory of the microcontrollers can be preserved between the different 46 | # simulations by default. Memory preserving means that the flash memory can be 47 | # saved in a separate utility file before the end of a simulation and 48 | # loaded back during the next one. 49 | # 50 | # Default value (no) means that the utility file has a priority over the one 51 | # provided by the 'firmware_file' option. 52 | reset_flash yes 53 | 54 | # Lua models which will be loaded and used during the simulation. 55 | lua_model stop-test.lua 56 | 57 | # Firmware test flag. Simulation can be started in a firmware test mode in 58 | # which simulator will not be waiting for any external event (like a command 59 | # from debugger) to continue with the simulation. 60 | firmware_test yes 61 | 62 | # Name of the VCD (Value Change Dump) file to be generated during the 63 | # simulation process to collect data and trace signals after the simulation. 64 | vcd_file trace.vcd 65 | 66 | # Microcontroller registers to be dumped to the VCD file. 67 | #dump_reg PORTA 68 | #dump_reg PORTB 69 | dump_reg PORTD1 70 | 71 | # Port of the RSP target. AVR GDB can be used to connect to the port and 72 | # debug firmware of the microcontroller. 73 | rsp_port 12750 74 | 75 | # Flag to trap AVR GDB when interrupt occured. 76 | trap_at_isr no 77 | -------------------------------------------------------------------------------- /tests/atmega8a/toggle-pin/stop-test.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | 5 | Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | 7 | MCUSim is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | MCUSim is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | --]] 21 | VERBOSE = true -- Switch on to enable verbose output 22 | TICK_TIME = 0.0 -- clock period, in us 23 | 24 | ticks_passed = 0 25 | check_point = 0 -- TCNT0 is 0 at start, count up to 255 then 26 | -- and reset by overflow interrupt 27 | 28 | -- This function will be called by the simulator only once to configure 29 | -- model before start of a simulation. 30 | function module_conf(mcu) 31 | -- Re-calculate clock period, in us 32 | TICK_TIME = (1.0/MSIM_Freq(mcu))*1000000.0 33 | if VERBOSE then 34 | print("[Test stopper] MCU clock: " .. MSIM_Freq(mcu)/1000 .. 35 | "kHz") 36 | print("[Test stopper] MCU clock period: " .. TICK_TIME .. 37 | "us") 38 | end 39 | end 40 | 41 | -- This function will be called by the simulator periodically according to the 42 | -- main simulation loop, i.e. time passed between two neighbor calls to the 43 | -- function is a period. 44 | function module_tick(mcu) 45 | if ticks_passed > 400000 then 46 | -- Test finished successfully 47 | MSIM_SetState(mcu, AVR_MSIM_STOP) 48 | print("[Test stopper] ticks passed: " .. ticks_passed) 49 | end 50 | 51 | ticks_passed = ticks_passed + 1 52 | end 53 | 54 | -------------------------------------------------------------------------------- /tests/atmega8a/usart-optiboot/m8a-clockpin.hex: -------------------------------------------------------------------------------- 1 | :1000000012C019C018C017C016C015C014C013C044 2 | :1000100012C011C010C00FC00EC00DC00CC00BC06C 3 | :100020000AC009C008C011241FBECFE5D4E0DEBF5E 4 | :10003000CDBF02D007C0E4CF11BA899A919A9198A6 5 | :08004000919AFDCFF894FFCF67 6 | :00000001FF 7 | -------------------------------------------------------------------------------- /tests/atmega8a/usart-optiboot/m8a-clockpin.hex.txt: -------------------------------------------------------------------------------- 1 | 2 | /Users/dsalychev/git/atmega8a-clock-pin/release/m8a-clockpin.hex: file format ihex 3 | 4 | 5 | Disassembly of section .sec1: 6 | 7 | 00000000 <.sec1>: 8 | 0: 12 c0 rjmp .+36 ; 0x26 9 | 2: 19 c0 rjmp .+50 ; 0x36 10 | 4: 18 c0 rjmp .+48 ; 0x36 11 | 6: 17 c0 rjmp .+46 ; 0x36 12 | 8: 16 c0 rjmp .+44 ; 0x36 13 | a: 15 c0 rjmp .+42 ; 0x36 14 | c: 14 c0 rjmp .+40 ; 0x36 15 | e: 13 c0 rjmp .+38 ; 0x36 16 | 10: 12 c0 rjmp .+36 ; 0x36 17 | 12: 11 c0 rjmp .+34 ; 0x36 18 | 14: 10 c0 rjmp .+32 ; 0x36 19 | 16: 0f c0 rjmp .+30 ; 0x36 20 | 18: 0e c0 rjmp .+28 ; 0x36 21 | 1a: 0d c0 rjmp .+26 ; 0x36 22 | 1c: 0c c0 rjmp .+24 ; 0x36 23 | 1e: 0b c0 rjmp .+22 ; 0x36 24 | 20: 0a c0 rjmp .+20 ; 0x36 25 | 22: 09 c0 rjmp .+18 ; 0x36 26 | 24: 08 c0 rjmp .+16 ; 0x36 27 | 26: 11 24 eor r1, r1 28 | 28: 1f be out 0x3f, r1 ; 63 29 | 2a: cf e5 ldi r28, 0x5F ; 95 30 | 2c: d4 e0 ldi r29, 0x04 ; 4 31 | 2e: de bf out 0x3e, r29 ; 62 32 | 30: cd bf out 0x3d, r28 ; 61 33 | 32: 02 d0 rcall .+4 ; 0x38 34 | 34: 07 c0 rjmp .+14 ; 0x44 35 | 36: e4 cf rjmp .-56 ; 0x0 36 | 38: 11 ba out 0x11, r1 ; 17 37 | 3a: 89 9a sbi 0x11, 1 ; 17 38 | 3c: 91 9a sbi 0x12, 1 ; 18 39 | 3e: 91 98 cbi 0x12, 1 ; 18 40 | 40: 91 9a sbi 0x12, 1 ; 18 41 | 42: fd cf rjmp .-6 ; 0x3e 42 | 44: f8 94 cli 43 | 46: ff cf rjmp .-2 ; 0x46 44 | -------------------------------------------------------------------------------- /tests/atmega8a/usart-optiboot/optiboot_m8a_16MHz_57600.hex: -------------------------------------------------------------------------------- 1 | :101E000001C0D8C01F92CDB7DEB711248FE594E092 2 | :101E10009EBF8DBF84B7882361F0982F9A7092304F 3 | :101E200041F081FF02C097EF94BF282E80E0AFD031 4 | :101E3000E7C085E08EBD82E08BB988E18AB986E88B 5 | :101E400080BD82E289B98EE0A2D0BD9A86E020E30F 6 | :101E50003CEF44E050E23DBD2CBD48BF08B602FE59 7 | :101E6000FDCF98B3952798BBA8955F9902C0815084 8 | :101E700091F7EE24E39425E0D22E31E1C32E80D0F9 9 | :101E8000813469F47DD0898386D089818238E9F0F4 10 | :101E9000813811F488E001C083E06ED06AC08234DA 11 | :101EA00011F484E103C0853419F485E07CD061C06D 12 | :101EB000853539F465D0882E63D0982E880C991C0E 13 | :101EC00057C0863521F484E06ED080E0E6CF8436BA 14 | :101ED00009F031C055D054D0182F52D0F82E012F10 15 | :101EE00080E6A82EB12C4CD0F50181935F01015002 16 | :101EF000D1F751D0F5E4FF1201C0FFCF83E0F40128 17 | :101F000087BFE89507B600FCFDCFA0E6B0E0F4017E 18 | :101F10008D919D910C01E7BEE895112412503296E7 19 | :101F20001111F6CFF401D7BEE89507B600FCFDCF3E 20 | :101F3000C7BEE8951EC0843771F422D021D0F82E98 21 | :101F40001FD029D08401F80185918F0115D0FA9412 22 | :101F5000F110F9CF0EC0853739F41DD08EE10CD0C9 23 | :101F600083E90AD087E099CF813511F488E00FD05A 24 | :101F700012D080E101D083CF5D9BFECF8CB9089554 25 | :101F80005F9BFECF5C9901C0A8958CB1089598E144 26 | :101F900091BD81BD0895F4DF803219F088E0F7DF4C 27 | :101FA000FFCF84E1E9CFCF93C82FEADFC150E9F733 28 | :101FB000CF91F1CFFC010A0167BFE895112407B664 29 | :101FC00000FCFDCF667029F0452B19F481E187BF35 30 | :041FD000E8950895F3 31 | :021FFE000008D9 32 | :0400000300001E00DB 33 | :00000001FF 34 | -------------------------------------------------------------------------------- /tests/ft/files/XlingFirmware.ft.conf: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | # 4 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | # 6 | # MCUSim is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # MCUSim is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | mcu m328p 20 | mcu_freq 16000000 21 | mcu_hfuse 0xD9 22 | mcu_lfuse 0x62 23 | firmware_file files/XlingFirmware.hex 24 | reset_flash yes 25 | firmware_test no 26 | rsp_port 12750 27 | trap_at_isr no 28 | -------------------------------------------------------------------------------- /tests/ft/files/XlingFirmware.hex.sha1: -------------------------------------------------------------------------------- 1 | SHA1 (./XlingFirmware.hex) = 44bf8399b80c35f381522f636038f90b2ee1faac 2 | -------------------------------------------------------------------------------- /tests/ft/files/XlingFirmware_1.ft.conf: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | # 4 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | # 6 | # MCUSim is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # MCUSim is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | mcu m328p 20 | mcu_freq 16000000 21 | mcu_hfuse 0xD9 22 | mcu_lfuse 0x62 23 | firmware_file files/XlingFirmware.hex 24 | reset_flash yes 25 | firmware_test no 26 | rsp_port 12750 27 | trap_at_isr no 28 | -------------------------------------------------------------------------------- /tests/ft/files/XlingFirmware_1.hex.sha1: -------------------------------------------------------------------------------- 1 | SHA1 (./XlingFirmware_1.hex) = 44bf8399b80c35f381522f636038f90b2ee1faac 2 | -------------------------------------------------------------------------------- /tests/ft/tests.cmake.in: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | # 4 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | # 6 | # MCUSim is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # MCUSim is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | # CMake script to run firmware checks by "make check" command. 21 | file(GLOB_RECURSE FM_TESTS "@CMAKE_CURRENT_BINARY_DIR@/*.ft") 22 | 23 | foreach(FM_TEST ${FM_TESTS}) 24 | message(STATUS "[CHECK]: ${FM_TEST}") 25 | 26 | get_filename_component(TEST_WORKING_DIR ${FM_TEST} DIRECTORY) 27 | 28 | # ----------------------------------------------------------------------------- 29 | # Configure address sanitizer 30 | # ----------------------------------------------------------------------------- 31 | set(WITH_ASAN @WITH_ASAN@) 32 | if (WITH_ASAN) 33 | find_program(SYMB llvm-symbolizer) 34 | message(STATUS "using LLVM symbolizer: ${SYMB}") 35 | 36 | set(ENV{ASAN_OPTIONS} "symbolize=1") 37 | set(ENV{ASAN_SYMBOLIZER_PATH} ${SYMB}) 38 | endif() 39 | 40 | # ----------------------------------------------------------------------------- 41 | # Run test 42 | # ----------------------------------------------------------------------------- 43 | execute_process( 44 | COMMAND ${FM_TEST} 45 | RESULT_VARIABLE test_res 46 | WORKING_DIRECTORY ${TEST_WORKING_DIR} 47 | TIMEOUT 30 48 | ) 49 | 50 | if (NOT "${test_res}" STREQUAL "0") 51 | message(FATAL_ERROR "failed: ${FM_TEST}") 52 | else() 53 | message(STATUS "[END]") 54 | endif() 55 | endforeach() 56 | -------------------------------------------------------------------------------- /tests/tests.cmake.in: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 3 | # 4 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 5 | # 6 | # MCUSim is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # MCUSim is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | 20 | # CMake script to run simulation tests by "make tests" command 21 | file(GLOB_RECURSE MSIM_TESTS "@CMAKE_CURRENT_BINARY_DIR@/mcusim.conf") 22 | 23 | foreach(MSIM_TEST ${MSIM_TESTS}) 24 | message(STATUS "[SIMULATION]: ${MSIM_TEST}") 25 | 26 | get_filename_component(TEST_WORKING_DIR ${MSIM_TEST} DIRECTORY) 27 | 28 | # ----------------------------------------------------------------------------- 29 | # Configure address sanitizer 30 | # ----------------------------------------------------------------------------- 31 | set(WITH_ASAN @WITH_ASAN@) 32 | if (WITH_ASAN) 33 | find_program(SYMB llvm-symbolizer) 34 | message(STATUS "using LLVM symbolizer: ${SYMB}") 35 | 36 | set(ENV{ASAN_OPTIONS} "symbolize=1") 37 | set(ENV{ASAN_SYMBOLIZER_PATH} ${SYMB}) 38 | endif() 39 | 40 | # ----------------------------------------------------------------------------- 41 | # Run test 42 | # ----------------------------------------------------------------------------- 43 | execute_process( 44 | COMMAND @CMAKE_CURRENT_BINARY_DIR@/../mcusim 45 | RESULT_VARIABLE test_res 46 | WORKING_DIRECTORY ${TEST_WORKING_DIR} 47 | TIMEOUT 30 48 | ) 49 | 50 | if (NOT "${test_res}" STREQUAL "0") 51 | message(FATAL_ERROR "failed: ${MSIM_TEST}") 52 | else() 53 | message(STATUS "[END]") 54 | endif() 55 | endforeach() 56 | -------------------------------------------------------------------------------- /xspice/ngspice-0001-add-library-name.patch: -------------------------------------------------------------------------------- 1 | --- src/xspice/icm/GNUmakefile.in 2018-09-24 12:15:18.991040000 +0200 2 | +++ src/xspice/icm/GNUmakefile.in 2018-09-24 11:58:58.281760000 +0200 3 | @@ -10 +10 @@ 4 | -CMDIRS = spice2poly digital analog xtradev xtraevt table 5 | +CMDIRS = spice2poly digital analog xtradev xtraevt table mcusim 6 | -------------------------------------------------------------------------------- /xspice/ngspice-0002-add-flags.patch.in: -------------------------------------------------------------------------------- 1 | --- src/xspice/icm/makedefs.in 2018-09-27 11:02:42.127054000 +0200 2 | +++ src/xspice/icm/makedefs.in 2018-09-27 17:19:30.411120000 +0200 3 | @@ -25 +25 @@ 4 | -EXTRA_CFLAGS = -fPIC 5 | +EXTRA_CFLAGS = -fPIC @MSIM_CFLAGS@ 6 | @@ -29 +29 @@ 7 | - EXTRA_CFLAGS = 8 | + EXTRA_CFLAGS = @MSIM_CFLAGS@ 9 | @@ -33 +33 @@ 10 | - EXTRA_CFLAGS = 11 | + EXTRA_CFLAGS = @MSIM_CFLAGS@ 12 | @@ -38 +38 @@ 13 | - EXTRA_CFLAGS = -KPIC 14 | + EXTRA_CFLAGS = -KPIC @MSIM_CFLAGS@ 15 | @@ -46 +46 @@ 16 | -LIBS = -lm 17 | +LIBS = -lm @MSIM_LIBS@ 18 | @@ -49 +49 @@ 19 | -LDFLAGS = -shared 20 | +LDFLAGS = -shared @MSIM_LDFLAGS@ 21 | @@ -54 +54 @@ 22 | - LDFLAGS = -bundle -flat_namespace -undefined suppress 23 | + LDFLAGS = -bundle -flat_namespace -undefined suppress @MSIM_LDFLAGS@ 24 | @@ -58 +58 @@ 25 | - LDFLAGS = -G 26 | + LDFLAGS = -G @MSIM_LDFLAGS@ 27 | -------------------------------------------------------------------------------- /xspice/ngspice-30.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcusim/MCUSim/3a5153f0e1d9abbc878e38e2f0edad78e906a0d1/xspice/ngspice-30.tar.gz -------------------------------------------------------------------------------- /xspice/patch-ngspice-sources: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This file is part of MCUSim, an XSPICE library with microcontrollers. 4 | # 5 | # Copyright (C) 2017-2019 MCUSim Developers, see AUTHORS.txt for contributors. 6 | # 7 | # MCUSim is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # MCUSim is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | 22 | # This script patches NGSpice sources to compile MCUSim code model library, 23 | # i.e. mcusim.cm. 24 | echo "Working directory is: `pwd`" 25 | 26 | echo "Copying directories..." 27 | for dir in $(find ../patches -type d -name '*'); do 28 | cp -p -R $dir ./ 29 | done 30 | 31 | echo "Applying MCUSim patches for NGSpice..." 32 | PATCH=`which patch` 33 | for line in $(find ../patches -name 'ngspice-*.patch*'); do 34 | echo $line 35 | $PATCH -p0 -f -u --silent --input=$line 36 | done 37 | -------------------------------------------------------------------------------- /xspice/src/xspice/icm/mcusim/modpath.lst: -------------------------------------------------------------------------------- 1 | m8a 2 | -------------------------------------------------------------------------------- /xspice/src/xspice/icm/mcusim/udnpath.lst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcusim/MCUSim/3a5153f0e1d9abbc878e38e2f0edad78e906a0d1/xspice/src/xspice/icm/mcusim/udnpath.lst --------------------------------------------------------------------------------