Commit Graph

28 Commits

Author SHA1 Message Date
Markus Hitter d2fcc57ed4 Introduce #ifdef SPI.
It's better to separate this by function than by usage.
2015-08-13 17:12:12 +02:00
Markus Hitter d337fd18ad mendel.c: move CPU initialisation to cpu.c (cpu-avr.c).
No functional change, but more code separated by architecture.
2015-08-12 14:26:35 +02:00
Markus Hitter 370bb9f93c Move pin I/O macros from arduino.h to pinio.h.
arduino.h is now free of function definitions.
2015-08-12 14:26:34 +02:00
Phil Hord 573dbfe576 Simulator: record serial data as comments, not as G-code.
We cheated before and sent the serial data in the simulator into
the G-code reporter so it could be line-buffered and then recorded
as comments in the trace-log. But this confuses the simulator
console output and is harder to manage. Revert to sending serial-out
data directly to the comment engine.

Also be less chatty about startup when connecting to a UART.
2015-07-17 16:34:20 +02:00
Markus Hitter 7e649c83dc SD card: remove sd_read_char() also from the simulator.
This is related to the commit
  "SD card: move parsing closer to the metal."
2015-07-17 16:06:19 +02:00
Phil Hord 8a11a76063 Simulator: fix switch handling error.
getopt_long() requires a null entry at the end of the longopts
array. It also reports an error already when some switch is
wrong, so just exit silently when we get an unexpected value.
2015-07-17 16:03:31 +02:00
Phil Hord ad2a76b2df Add simulator SD card (and SPI, PFF) support.
Add simulator for SD card driver, plus add stubs for SPI and PFF
primarily to prevent the on-device code from being picked up by
the makefiles for the simulator.
2015-07-17 16:02:59 +02:00
Markus Hitter 8b88334b06 Rename setTimer() to timer_set() for more consistency.
Pure cosmetical change.

Performance check:

$ cd testcases
$ ./run-in-simulavr.sh short-moves.gcode smooth-curves.gcode triangle-odd.gcode
[...]
    SIZES             ATmega...  '168    '328(P)    '644(P)    '1280
    FLASH  : 20518 bytes         144%        67%        33%      16%
    RAM    :  2188 bytes         214%       107%        54%      27%
    EEPROM :    32 bytes           4%         2%         2%       1%

short-moves.gcode statistics:
LED on occurences: 838.
LED on time minimum: 302 clock cycles.
LED on time maximum: 713 clock cycles.
LED on time average: 308.72 clock cycles.

smooth-curves.gcode statistics:
LED on occurences: 8585.
LED on time minimum: 307 clock cycles.
LED on time maximum: 710 clock cycles.
LED on time average: 358.051 clock cycles.

triangle-odd.gcode statistics:
LED on occurences: 1636.
LED on time minimum: 302 clock cycles.
LED on time maximum: 708 clock cycles.
LED on time average: 330.322 clock cycles.
2015-04-21 02:51:32 +02:00
Phil Hord 76bf5ef75a Datalog: show traced data as signed ints, not unsigned. 2014-08-31 19:09:37 +02:00
David Forrest f3666fc43f heater_sim.c: Note that the heater isn't implemented in the simulator. 2014-08-31 19:06:23 +02:00
Phil Hord 5cd6cf50d8 Zungmann's fixes to compile simulator on Mac OS X, part 1.
Compiling for Mac OS X needs some customizations noticed by zungmann
in the reprap forum:

http://forums.reprap.org/read.php?147,33082,279050#msg-279050
2014-03-04 19:57:41 +01:00
Phil Hord ed7f3ad559 simulator: Respect XYZE_INVERT_DIR settings
Simulator assumes a basic set of config pins.  Most it ignores
and redefines.  But the INVERT_DIR pins it did not, and these
could be useful to simulate.  So teach Simulator to respect them.
2014-03-04 19:57:19 +01:00
Phil Hord 96495fb9bb simulator: Make time-scale=0 a cmdline option
Teach the simulator to run with no delays when time-scale=0.

Let the user specify the time-scale on the command line.
2013-12-06 19:24:58 +01:00
Phil Hord c7b43782ce datalog: add a tip showing gnuplot usage
Add a comment to the datalog output showing how it can be viewed with
gnuplot.  It would be trivial to add this as a .plot script, but it's
even easier in the datalog output.
2013-12-06 19:24:58 +01:00
Phil Hord cfa4857550 simulator: cmdline switches for output options
Teach simulator several command line options to control console output
of info messages, gcode traces, data_recorder output, etc.

Also move gcode output to sim_gcode instead of sending directly to
datarecorder.
2013-12-06 19:24:58 +01:00
Phil Hord 8874397b45 Make data logging optional (internal)
If the recorder is initialized with a filename, write trace data
to that file.  But if it is not initialized, don't complain and
don't write the data anywhere.
2013-12-06 19:24:58 +01:00
Phil Hord 36747e5703 Teach simulator to process gcode files directly
The simulator runs as a device simulator complete with serial port
so it can communicate with printer software like pronterface. But
often we just want to stream it a file of gcode commands and get
some output.  Teach the simulator to take a regular file as input
and process it as a file of gcode commands if it is not a device.
2013-12-06 19:24:58 +01:00
Phil Hord daec29f69c Simulator: slow to 1/10th real-time
Reduce the simulated timer to 1/10 actual time.  There is no need
for the simulator to run at full speed for now, and some PCs may
not be able to attain real-time speed anyway due to PC clock
speed, scheduler slack or OS differences.

Maybe the simulated timer interrupt is not needed at all and some
cooperative timer interrupt could be used instead.  Such a setup
may even run faster as it could also run >1.0x time when there is
nothing to do.  This bears investigation later.  For now, the
simulated timer interrupt seems more realistic and possibly valuable.
2013-12-06 19:24:58 +01:00
Phil Hord cf015623e3 simulator: Add position to datalog.out
Cleanup datalog output a bit.
  * Add close/flush on exit in case we have pending data
  * Use hash for comment characters to be compatible with gnuplot
  * Report x/y/z/e position in array
2013-12-06 19:24:58 +01:00
Phil Hord 1db17acc03 Simulator: don't try to schedule zero time. 2013-12-06 19:24:58 +01:00
Phil Hord 2b8a5d3b5a simulator: record g-codes in datalog
Add comment stream to datalog output so we can store g-codes and
other events that occur during simulation.
2013-12-06 19:24:58 +01:00
Phil Hord 18c68b5fe4 simulator: Add nano-timer to datalog 2013-12-06 19:24:58 +01:00
Phil Hord 3ff7e86728 Simulator cleanup 2013-12-06 19:24:58 +01:00
Phil Hord 18ea439788 simulator: fix timer overflow problem
Next-interrupt-time calculations were made in 16-bit registers but
moved to 32-bit ones for convenience.  But they forgot to round off
at 16-bits.  Force the round-off so we do not wait forever.
2013-12-06 19:24:58 +01:00
Phil Hord 1e2824d56b WIP: Add simulator data-logging.
Record simulation run-time data in file 'datalog.out' so it
can be analyzed after-the-fact or during the run.

This feature is evolving. Eventually it should be compatible with
some logic analyzer GUIs such as gtkwave or even gnuplot.
2013-12-06 19:24:58 +01:00
Phil Hord a81f35022a Add debug pin-tracing code for investigation. 2013-12-06 19:24:58 +01:00
Phil Hord b65efe9b03 Move argc/argv processing deeper into simulator.
Less magic == more better.
2013-12-06 19:24:58 +01:00
Phil Hord 452e2e5cd9 Restore simulation build target.
This code was accidentally removed long ago in a botched merge. This
patch recovers it and makes it build again. I've done minimal testing
and some necessary cleanup. It compiles and runs, but it probably still
has a few dust bunnies here and there.

I added registers and pin definitions to simulator.h and
simulator/simulator.c which I needed to match my Gen7-based config.
Other configs or non-AVR ports will need to define more or different
registers. Some registers are 16-bits, some are 8-bit, and some are just
constant values (enums). A more clever solution would read in the
chip-specific header and produce saner definitions which covered all
GPIOs. But this commit just takes the quick and easy path to support my
own hardware.

Most of this code originated in these commits:

	commit cbf41dd4ad
	Author: Stephan Walter <stephan@walter.name>
	Date:   Mon Oct 18 20:28:08 2010 +0200

	    document simulation

	commit 3028b297f3
	Author: Stephan Walter <stephan@walter.name>
	Date:   Mon Oct 18 20:15:59 2010 +0200

	    Add simulation code: use "make sim"

Additional tweaks:

Revert va_args processing for AVR, but keep 'int' generalization
for simulation. gcc wasn't lying. The sim really aborts without this.

Remove delay(us) from simulator (obsolete).

Improve the README.sim to demonstrate working pronterface connection
to sim. Also fix the build instructions.

Appease all stock configs.

Stub out intercom and shush usb_serial when building simulator.

Pretend to be all chip-types for config appeasement.

Replace sim_timer with AVR-simulator timer:

The original sim_timer and sim_clock provided direct replacements
for timer/clock.c in the main code. But when the main code changed,
simcode did not. The main clock.c was dropped and merged into timer.c.
Also, the timer.c now has movement calculation code in it in some
cases (ACCELERATION_TEMPORAL) and it would be wrong to teach the
simulator to do the same thing. Instead, teach the simulator to
emulate the AVR Timer1 functionality, reacting to values written to
OCR1A and OCR1B timer comparison registers.

Whenever OCR1A/B are changed, the sim_setTimer function needs to be
called. It is called automatically after a timer event, so changes
within the timer ISRs do not need to bother with this.

A C++ class could make this requirement go away by noticing the
assignment. On the other hand, a chip-agnostic timer.c would help
make the main code more portable. The latter cleanup is probably
better for us in the long run.
2013-12-06 19:24:58 +01:00