tests: Revert a uart patch
We do need the translation, as it's not one, but generation of \n\r
Signed-off-by: Michel Pollet <buserror@gmail.com>
cores: Added mega16m1
Could work for megaXm1 ?
Signed-off-by: Markus Lampert <mlampert@telus.net>
Signed-off-by: Michel Pollet <buserror@gmail.com>
lin: Added module
- added core module for atmega16m1,
standard peripherals and LIN-in-UART mode
Signed-off-by: Markus Lampert <mlampert@telus.net>
Signed-off-by: Michel Pollet <buserror@gmail.com>
core: Added a log level
added log_level to avr_t to control the output of the
simavr library (minimal usage)
Signed-off-by: Markus Lampert <mlampert@telus.net>
Signed-off-by: Michel Pollet <buserror@gmail.com>
uart: Do not assume all interupt vectors are available, etc
LIN uart doesn't have them (?)
- fixed uart code to only trigger rxt if more pending
characters are in the input buffer
- fixed uart-echo test code to not get stuck in
endless loop upon receiving '\r'
Signed-off-by: Markus Lampert <mlampert@telus.net>
Signed-off-by: Michel Pollet <buserror@gmail.com>
core: added new states
States cpu_Done and cpu_Crashed allow graceful exit
and cleanup of simavr applications.
Signed-off-by: Markus Lampert <mlampert@telus.net>
Signed-off-by: Michel Pollet <buserror@gmail.com>
core: Fixed opcode printing on access violation
No functional change
Signed-off-by: Markus Lampert <mlampert@telus.net>
Signed-off-by: Michel Pollet <buserror@gmail.com>
adc: Added VCC/4 reading
For mega16m1
Signed-off-by: Markus Lampert <mlampert@telus.net>
Signed-off-by: Michel Pollet <buserror@gmail.com>
misc: formatting, typos
Also removed test case that doesn't actualy test anything
Signed-off-by: Michel Pollet <buserror@gmail.com>
ioport: Added avr_iopin_t
Descriptor for pin name/pin number
Signed-off-by: Michel Pollet <buserror@gmail.com>
vcd: change VCD time base to 1 ns to handle higher AVR speeds (e.g. 20 MHz / max. frequency: 1000 MHz)
- increase VCD log size to 5kB
Signed-off-by: Stephan Veigl <veigl@gmx.net>
Signed-off-by: Michel Pollet <buserror@gmail.com>
irq: add avr_unconnect_irq() and avr_irq_unregister_notify()
Signed-off-by: Stephan Veigl <veigl@gmx.net>
bitbang: add new bitbang sub-module
Signed-off-by: Stephan Veigl <veigl@gmx.net>
test: fix test cases and add new test function
- add tests_assert_uart_receive_avr() function (called by tests_assert_uart_receive() and test cases)
- fix DDR settings
Signed-off-by: Stephan Veigl <veigl@gmx.net>
Update .gitignore.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
Signed-off-by: Michel Pollet <buserror@gmail.com>
vcd: change VCD time base to 1 ns to handle higher AVR speeds (e.g. 20 MHz / max. frequency: 1000 MHz)
- increase VCD log size to 5kB
- add test files
Signed-off-by: Stephan Veigl <veigl@gmx.net>
simavr: change hard-coded value to define: AVR_IOPORT_OUTPUT
Signed-off-by: Stephan Veigl <veigl@gmx.net>
output: add NO_COLOR define to disable / enable color output for simavr core messages and UART
Signed-off-by: Stephan Veigl <veigl@gmx.net>
doc: add doxygen file
Signed-off-by: Stephan Veigl <veigl@gmx.net>
cores: Add mega1281
Signed-off-by: HATATANI Shinta <gamaguchi@gmail.com>
Signed-off-by: Michel Pollet <buserror@gmail.com>
cores: Added mega8, old generation
Possibly would work with mega16, 32 ?
Signed-off-by: Michel Pollet <buserror@gmail.com>
examples: Working i2c master test board
Write a few bytes to an i2c eeprom, read them back...
Signed-off-by: Michel Pollet <buserror@gmail.com>
parts: Adds generic i2c eeprom slave
This part simulates an i2c eeprom, it handles most modes, including
"multiple addresses" ones, and ones with multiple byte offset bytes.
Signed-off-by: Michel Pollet <buserror@gmail.com>
twi: Fully functional master
Now works properly, tested against Atmel's code. See
examples/board_i2ctest for a demo
Signed-off-by: Michel Pollet <buserror@gmail.com>
examples: Fix firmware pathnames
Twas borken since I changed the build system. Now works
Signed-off-by: Michel Pollet <buserror@gmail.com>
example: Added i2ctest
This example need some polish. It simulates an AVR with an
i2c eeprom of 1024 bytes. The eeprom is "generic" an will go to the
parts/ directory when this is fully working.
Right now write the eeprom works, but there is a stray byte somewhere;
the bug /could/ be in the atmel code tho, wich I had to fix and tweak.
Signed-off-by: Michel Pollet <buserror@gmail.com>
twi: Update, 95% functional master code
Still need a bit of polish, but the logic works. Works with the
interupt based Atmel application note code.
Signed-off-by: Michel Pollet <buserror@gmail.com>
run_avr: Added a signal handler
Catches control-C to make sure any VCD file is flushed
Signed-off-by: Michel Pollet <buserror@gmail.com>
cores: Fix TWI interupt flag
This flag was using the wrong register
Signed-off-by: Michel Pollet <buserror@gmail.com>
test: Updated uart_echo
Now set a baud rate, to excersize the new logic in the uart
simulator.
Also added a VCD file
Signed-off-by: Michel Pollet <buserror@gmail.com>
cores: Added UART bit rate flags
Updated the cores that have UART(s) with extra flags.
Signed-off-by: Michel Pollet <buserror@gmail.com>
uart: Added logic to regulate data rate
Now uses a data rate thst is proportional to speed.
Could be made a bit better by using the cycle clock count directly,
but this method is a bit clearer
Signed-off-by: Michel Pollet <buserror@gmail.com>
misc: Fixes various typos
Author: Sami Liedes <sliedes@cc.hut.fi>
Signed-off-by: Michel Pollet <buserror@gmail.com>
Fix interupt -> interrupt typo, including in some function names.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
Do not let code clear the UDRE flag in USART.
It's a read only location and clearing it may break software that
assumes it cannot be cleared.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
Merge remote-tracking branch 'sliedes/to-upstream' into dev-home
Tweak struct avr_t to always include a pointer to trace data structure.
Previously the size of struct avr_t was dependent on whether the
preprocessor macro CONFIG_SIMAVR_TRACE was defined. This was problematic
since it meant that applications that link to simavr need to define it
the same way as it is defined in simavr Makefiles.
Change it to a single pointer to a struct, which is allocated iff
tracing is compiled in and a NULL pointer otherwise.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
Automate test cases.
This patch implements a framework for test cases. Each test case is
compiled into an individual executable. All test cases can be run by
invoking the command `make run_tests', which runs the shell script
run_tests.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
Include sim_gdb.h from sim_gdb.c. Also fix prototype in .h.
sim_gdb.c did not include sim_gdb.h. Also there was a slight
difference in the prototype in the header and the implementation in
the .c, causing a warning.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
uart: Touchup on the xon/xoff IRQs
Set/reset XON & XOFF irqs following the status
of the fifo. It means they can be added to a VCD
file and help debug a "part".
Signed-off-by: Michel Pollet <buserror@gmail.com>
uart: Added a comment
As to why somehow we don'r write a value in the interupt
clearing logic
Signed-off-by: Michel Pollet <buserror@gmail.com>
twi: Placeholder example board
Uses AVR application note implementation of master/slave mode
Placeholder, non functional
Signed-off-by: Michel Pollet <buserror@gmail.com>
twi: New master implementation
Yanked the old overengineered version, replaced it with a KISS
version. Untested, work in progress. Needs a new testing harness
Signed-off-by: Michel Pollet <buserror@gmail.com>
regbits: Added a "raw" variant to get/set
Allows comparing to "real life" constants, used in Twi module
Signed-off-by: Michel Pollet <buserror@gmail.com>
part: Made irq_names static
Have to to have several of them...
Signed-off-by: Michel Pollet <buserror@gmail.com>
Makefile: Fix for x86_64
silly architecture names...
Signed-off-by: Michel Pollet <buserror@gmail.com>
Makefile updates
Changed the makefiles to derivate the target architecture from
gcc itself, and compile all the objects into obj-$arch. This
allows several compilers to be used to build simavr, at the same
time without interferences.
This allow arm cross compilation to live in the same tree as
the x86 one...
Signed-off-by: Michel Pollet <buserror@gmail.com>
Updated gitignore
Added obj-* and *.vcd
Signed-off-by: Michel Pollet <buserror@gmail.com>
Remove unused variable from avr_service_interrupts().
The done flag is nowadays redundant as it's never read after it's set.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
Fix LD, ST, LPM, STS, MUL to take the correct number of cycles.
They are now the ATMega timings. Need to figure out how to take
ATTiny into account. Before this change they weren't correct for
either.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
fix typos in comments.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
Silence gcc warnings by using PRIu64 in CRASH() printf().
Actually we define a PRI_avr_cycle_count preprocessor macro in
sim_avr.h in the style of PRI* in inttypes.h.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
Fix compilation with TRACE on.
The MOV instruction's TRACE() used the undefined variable vd.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
Fix compilation on non-32-bit platforms.
The addition of -Werror to the compilation flags broke building on
64-bit hosts because casts between pointers and integers of different
sizes cause warnings on gcc -Wall. Fix this by always casting the
pointers to intptr_t first.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
irq: Add names to most io module external irqs
Nothing to be shown for this work so far, the cool stuff hopefully
will come later...
Signed-off-by: Michel Pollet <buserror@gmail.com>
doc: Updated callgraph .pdf
Just a minor update
Signed-off-by: Michel Pollet <buserror@gmail.com>
examples: Updated to new part prototypes
Followup on previous checkin, the board examples now use
"names" when possible.
Signed-off-by: Michel Pollet <buserror@gmail.com>
parts: Updated to name their IRQs
First bits of the system that provide names for the IRQs
Signed-off-by: Michel Pollet <buserror@gmail.com>
simavr: Updare simavr core to new IRQ prototypes
Mostly prototypes changes and some gratuitous reformatting
Signed-off-by: Michel Pollet <buserror@gmail.com>
irq: Introduce a "irq pool"
The goal is to be able to name IRQs, so a couple fields are
added.
It is not functional for now, as the task is to first convert
all the code to the new prototype.
Also introduce a 2011 way of formatting prototypes
Signed-off-by: Michel Pollet <buserror@gmail.com>
simavr: Added -Werror and fixed warnings
Added -Werror to compilation to make sure the next wave of changes
can't easily break things
Signed-off-by: Michel Pollet <buserror@gmail.com>
core: Add a muxer for IO writes
It turns out that some core (tiny85 at the very least) are competing
for IO writes on some register.
This patch introduces a muxer callback that can call multiple clients
without impacting performance for the rest of the cores.
The system could be extended for IO read if it proves necessary.
Signed-off-by: Michel Pollet <buserror@gmail.com>
core: Introduce run() and sleep() callbacks
It seems that the default 'run_avr' function was penalized by
some tests made that were only useful when gdb was active.
This patch introduces two version of the critical run_avr, one for
"raw" running, and one for gdb.
It also introduces a sleep() callback for similar reasons. Ir can
also be used to run unit testing at 100% speed instead of having
random sleep code during execution.
Signed-off-by: Michel Pollet <buserror@gmail.com>
Fix SBIS etc trace output.
SBIS used to print the io register wrong. The other fixes add spaces
in the correct places in "Will branch" and "Will not branch" messages.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
avr_loadcode(): If too much code, bail out instead of crashing.
Check that the code to be loaded actually fits in the flash.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
avr_register_io_[read,write](): fail if overriding earlier registration.
The avr_register_io_*() functions do not maintain a chain of
callbacks. This can be confusing if someone like me tries to use them
to listen to some I/O events (for which you should use the avr_irq_*
stuff).
Make this more explicit by checking in the register functions if we
already have a callback and failing with an error message if so.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
board_hd44780: New sample code
Emulated a complete HD44780 LCd screen, and uses a standard
AVR driver to write on it.
Signed-off-by: Michel Pollet <buserror@gmail.com>
vcd: Increase trace buffer size
Ran into the 128 limit at some point..
Signed-off-by: Michel Pollet <buserror@gmail.com>
Makefiles: Some fixups
+ add -fPIC to -shared for the shared library
+ .axf rule try to comoile all dependencies
Signed-off-by: Michel Pollet <buserror@gmail.com>
Merge git://gitorious.org/~luki/simavr/lukis-simavr into dev-home
Makefile: Add building of shared library on linux
Disabled for non linux platform, as it need more work
than just a gcc -shared
Author: Martin Glueck <martin@mangari.org>
Edit: Michel Pollet <buserror@gmail.com>
core: Added ATtiny x4
Untested. Also added to sim_avr.c
Author: Martin Glueck <martin@mangari.org>
Edit: Michel Pollet <buserror@gmail.com>
core: Remove the run() callback
run() callback was unused but was still using cycles
Signed-off-by: Michel Pollet <buserror@gmail.com>
Makefiles: Explicitely link opengl
needed with modern linker
Signed-off-by: Michel Pollet <buserror@gmail.com>
timer: Fix a subtle off-by-one bug in TCNT reading.
There's a subtle bug in TCNT (timer counter) reading which only causes
the counter to ever run from 0 to TOP-1, while it should stay in the
TOP value for a full timer cycle before resetting to 0 (but the
interrupt needs to come when TOP is first reached).
Interestingly, this causes Arduino's micros() function to occasionally
return incorrect values. micros() function relies on TCNT0 not
transitioning from <= 254 to 0 in only a few cycles with /64
prescaler.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
timers: don't reconfigure for minor changes
Prevents the timer to be reset when changing non important
bits, like the edge detector etc
Signed-off-by: Michel Pollet <buserror@gmail.com>
timers: Print a warning on unsuported timer modes
and also don't [rint one for "mormal" mode
Signed-off-by: Michel Pollet <buserror@gmail.com>
Store the next cycle count where the earliest cycle timer needs to be run.
This speeds up cycle timer processing significantly and almost doubles
the speed of the overall simulation.
Signed-off-by: Sami Liedes <sliedes@cc.hut.fi>
Rework avr_service_interrupts() to use ffs() too for speed.
Use ffs() for finding timers from cycle timer map.
This optimization speeds up avr_cycle_timer_process() considerably. It
used to be a major bottleneck in my test case (52% of CPU time spent
in that routine), now it's about half that.
Return zeros when GDB reads just past end of stack.
GDB likes to read the topmost value of stack when using the
"stepi" (step instruction) command. Unfortunately this does not work
when the stack is empty, causing an error message and GDB confusion.
Hack the GDB stub code to just return zeros if GDB tries to read two
bytes just past the end of stack.
NOTE: This may need to be modified to support also longer reads for
bigger AVRs where code pointers are longer than two bytes (e.g.
ATMega2560). As simavr doesn't support atm2560 yet, I'm implementing
it this way now.
Enable interrupt handling for Fast PWM timers too
Arduino seems to use that.
UART: Fixed UDRC/E behaviour
The interrupt is suposed to fire as soon as it is
enabled is the UDR is empty.
Signed-off-by: Michel Pollet <buserror@gmail.com>
cycle timers: Added avr_cycle_timer_status()
Allows verification wether a timer is running, and
until when it is.
Signed-off-by: Michel Pollet <buserror@gmail.com>
simduino: added init/deinit functions for avr_t initialization
fixes a crash (free of mmap'ed memory)
nicer cleanup by munmap + close the file
Signed-off-by: Christian Balles <code@ballessay.de>
core: added extra init/deinit functions to avr_t
allows programs like the simduino example to modify the init/deinit function
to fix a crash
Signed-off-by: Christian Balles <code@ballessay.de>
misc: Typos
Fixed a few comments
Signed-off-by: Michel Pollet <buserror@gmail.com>
core: Added a bit of documentation
Fixed some of the copy/paste errors in comments
Signed-off-by: Michel Pollet <buserror@gmail.com>
gdb: Adds the 'reset' command
Apparently needed for compatibility with AVRStudio debugger
Signed-off-by: Michel Pollet <buserror@gmail.com>
console: Implement debug console register
Used in pair with the console register declaration, just
prints what's sent to that debug register.
Signed-off-by: Michel Pollet <buserror@gmail.com>
mcu_section: Added New CONSOLE Tag
CONSOLE tag allow declaring a register for dumping debug output
oh the terminal without using an UART
Also cleaned up and documented the header file further
Signed-off-by: Michel Pollet <buserror@gmail.com>
tests: Update them so they work...
They relied on bugs that were fixed in simavr since..
Signed-off-by: Michel Pollet <buserror@gmail.com>
IOs: Use new IRQ alloc function
All converted to the brand new way...
Signed-off-by: Michel Pollet <buserror@gmail.com>
IRQs: A bit of sanity when freeing
Check the parameters...
Signed-off-by: Michel Pollet <buserror@gmail.com>
simavr: Deallocate resources
Deallocate memory and IO modules at teardown
Signed-off-by: Michel Pollet <buserror@gmail.com>
eeprom: Added a dealloc function
frees the eeprom memory at teardown time
Signed-off-by: Michel Pollet <buserror@gmail.com>
ios: Added a way to set and teardown modules IRQs
Added a function to set the io module IRQ, and added a way
to deallocate them at teardown time.
Signed-off-by: Michel Pollet <buserror@gmail.com>
misc: Made (most) of the headers c++ friendly
No functional changes
Signed-off-by: Michel Pollet <buserror@gmail.com>
misc: Fixed clang static analizer warnings
One genuine bug too. The rest was cosmetic.
Signed-off-by: Michel Pollet <buserror@gmail.com>
ioport: Added an IRQ for the port pin direction changes
New IRQ for client code (ie "board code") will be called
when the AVR firmware changes the DDR register.
Signed-off-by: Michel Pollet <buserror@gmail.com>