Commit Graph

80 Commits

Author SHA1 Message Date
Markus Hitter 5a8dcf8e97 ARM: add a board configuration for Gen7-ARM.
Wohoo, this is the first ARM board in Configtool. Let's see how
Configtool deals with it :-)
2015-08-12 14:26:36 +02:00
Markus Hitter 66dcde54dc mendel.c: move io_init() to pinio.c.
Also rename it to pinio_init(). Other than that a simple
copy/paste operation, with replacing tabs by spaces. No functional
change.
2015-08-12 14:26:35 +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 083f8f9b22 Make use of PULLUP_ON() and PULLUP_OFF().
This should not change behaviour, but later enable proper
operation on ARM.
2015-08-12 14:26:35 +02:00
Markus Hitter 2c90a2dfc7 ARM: get FastIO for writing into place.
Only SET_OUTPUT() and WRITE() for now, reading follows later.

A loop like this:

  SET_OUTPUT(PIO0_1);
  for (;;) {
    WRITE(PIO0_1, 0);
    WRITE(PIO0_1, 1);
  }

toggles a pin at about 5.3 MHz. The low period is 63 ns on the
scope, so 3 clock cycles. With this loop, the binary is 1648
bytes.

Assembly shows four instructions inside the loop, which is about
as good as it can get:

  movs  r2, #0
  str   r2, [r3, #8]
  adds  r2, #2
  str   r2, [r3, #8]

For comparison, using the MBED provided gpio routines give a
toggle frequency of about 300 kHz, with a low period of 72 clock
cycles. Microoptimisation isn't just the last few percent ...

Tested with this code before main():

static void delay(uint32_t delay) {
  while (delay) {
    __ASM volatile ("nop");
    delay--;
  }
}

... and in main():

  SET_OUTPUT(PIO0_1);
  SET_OUTPUT(PIO0_2);
  SET_OUTPUT(PIO0_3);
  SET_OUTPUT(PIO0_4);
  __ASM (".balign 16");
  while (1) {
    // 1 pulse on pin 1, two pulses on pin 2, ...
    WRITE(PIO0_1, 0);
    WRITE(PIO0_1, 1);
    WRITE(PIO0_2, 0);
    WRITE(PIO0_2, 1);
    WRITE(PIO0_2, 0);
    WRITE(PIO0_2, 1);
    WRITE(PIO0_3, 0);
    WRITE(PIO0_3, 1);
    WRITE(PIO0_3, 0);
    WRITE(PIO0_3, 1);
    WRITE(PIO0_3, 0);
    WRITE(PIO0_3, 1);
    // PIO0_4 needs a pullup 10k to 3.3V
    // to show a visible signal.
    WRITE(PIO0_4, 0);
    delay(10);
    WRITE(PIO0_4, 1);
    delay(10);
    WRITE(PIO0_4, 0);
    delay(10);
    WRITE(PIO0_4, 1);
    delay(10);
    WRITE(PIO0_4, 0);
    delay(10);
    WRITE(PIO0_4, 1);
    delay(10);
    WRITE(PIO0_4, 0);
    delay(10);
    WRITE(PIO0_4, 1);
    delay(1000);
  }

With a 10k pullup, PIO0_4 has a rise time of about 1 microsecond.
2015-08-12 14:26:34 +02:00
Markus Hitter 43b2ac6e0b ARM: get sersendf.c/.h in.
Needed a bit a tweak to adjust va_arg() to 32 bit. Tests ran fine,
at the end it turned out mendel.c had an obsolete #include.
2015-08-12 14:26:34 +02:00
Markus Hitter 5dec638919 ARM: get sermsg.c/.h in.
Compiled flawlessly, ran all test flawlessly, and at the end it
turned out mendel.c had an obsolete #include. Very nice.
2015-08-12 14:26:34 +02:00
Markus Hitter 4cfeca08e1 ARM: get serial working based on MBED code.
Pretty complex, this MBED system, it requires no less than
24 additional files. This will be fleshd out before too long.

    SIZES          ARM...     lpc1114
    FLASH  :  5956 bytes          19%
    RAM    :   176 bytes           5%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:34 +02:00
Markus Hitter 575174940f ARM: get a minimum amount of Teacup compiled for ARM.
Makefile can't even upload, yet.

    SIZES          ARM...     lpc1114
    FLASH  :   944 bytes           3%
    RAM    :   132 bytes           4%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:33 +02:00
Markus Hitter 77630167e7 Serial: postpone sending "ok" until a slot is free.
Previously acknoledgement was sent as soon as the command was
parsed. Accordingly, the host would send the next command and
this command would wait in the RX buffer without being parsed.

This worked reasonably, unless an incoming line of G-code was
longer than the RX buffer, in which case the line end was dropped
and parsing of the line never completed. With a 64 bytes buffer
on AVR this was rarely the case, with the 16 bytes hardware buffer
on ARM LPC1114 it happens regularly. And there's no recovering
from such a situation.

This should solve issue #52.
2015-08-04 23:03:51 +02:00
Markus Hitter 6b66d7870a mendel.c: remove another three redundant #includes.
No functional change.
2015-07-30 21:46:14 +02:00
Markus Hitter 4fdb2dac9e Remove file fuses.h.
Contents apparently nowhere used. Also not updated for often used
MCUs like ATmega2560 or ATmega1284P, so it can't be that
important.
2015-07-27 16:41:48 +02:00
Markus Hitter 3d005c4d60 mendel.c: remove redundant #include. 2015-07-27 16:34:13 +02:00
Phil Hord 503d2c75a1 Fix typos: "whether" and whitespace. 2015-07-17 16:16:42 +02:00
Markus Hitter 75df5e3a0a SD card: don't read into a buffer, parse directly instead.
Formerly we took efforts to read only small chunks into a
(small) buffer, just to read this buffer byte by byte yet
again for parsing. It's more efficient and requires less
code to parse the character at read time directly. This
way we can read in chunks of exactly one line, making the
buffer obsolete.

First step is to implement this in mendel.c and in sd.c/.h.
This gets rid of the buffer already.

Very inefficient in pff.c and pff_diskio.c so far, more
than 40 minutes / less than 500 bytes/s for reading this
1 MB comments file. Reason is, for every single byte a
whole sector is read. Nevertheless, this attempt appears
to be on the right track.

Binary is 156 bytes smaller, 16 bytes less RAM:
               ATmega...     '168   '328(P)   '644(P)     '1280
   FLASH:   22052 bytes   153.82%    71.78%    34.73%    17.09%
     RAM:    1331 bytes   129.98%    64.99%    32.50%    16.25%
  EEPROM:      32 bytes     3.12%     1.56%     1.56%     0.78%
2015-07-17 13:30:55 +02:00
Markus Hitter c42ccfff38 mendel.c: when to include simulator.h matters.
This partially fixes building the simulator. It was found by
running the new regression tests.
2015-07-13 14:02:39 +02:00
Markus Hitter df451d72fd mendel.c: set SIMINFO serial port only when BAUD is available.
This was found by running the new regression tests.
2015-07-13 14:01:27 +02:00
Markus Hitter 53dfab3be3 G-code parser: check for end of line in the parser.
This raises abstraction and even makes the binary a bit smaller
(2 bytes without SD, 14 bytes with SD).

A G-code file with 16'384 lines of comments, 64 bytes per line
( = 1 MB file size), is read and parsed from SD card in 2:47
minutes, or at a speed of 5924 bytes/second.
2015-07-10 14:19:48 +02:00
Markus Hitter 23be2d1449 SD card: finally(!) implement printing from SD card.
Turned out to be pretty easy with all the more complex bits
already in place.

Strategy is to always parse a full line from one of the sources.
Accordingly, simply sending a character on the serial line stops
reading from SD until the line coming in over serial is completed.
2015-07-07 19:07:35 +02:00
Markus Hitter c7b134bc65 SD card: change demo code for performance measurement.
As we're around here, lets see how fast this implementation is.
All measurements are raw reading performance, without actual
parsing of the G-code.

With SPI_2X disabled (see line 8 in spi.h), performance is
195 seconds per megabyte, equivalent to about 50'000 baud.

With SPI_2X enabled, performance is 159 seconds per megabyte,
or 60'000 baud.

Still, SPI_2X is left disabled to increase reliability. Reading
from SD is faster by design, because there is no checksumming and
also no waiting for the "ok" to be sent back. In case reading
G-code from SD ever becomes a bottleneck, there are even more
opportunities in addition to enabling SPI_2X, like making sdbuffer
bigger, like micro-optimizing spi_rw() and similar stuff.
2015-07-07 14:36:46 +02:00
Markus Hitter d3f548a895 SD card: actually read the characters from the file.
Next to the implementation of sd_read_byte() as well as M24 and
M25, yet another demo: read the file and write it to the serial
line, to show correctness of the implementation.
2015-07-07 14:36:44 +02:00
Markus Hitter 30ce8eb1b4 SD card: remove the demonstration code.
We're about to do some real stuff ...
2015-07-05 23:32:48 +02:00
Markus Hitter 9de0c65460 SD card: add the layer between hardware and Petit FatFs.
This is all the commands to read from and write to SPI,
initializing the card, read in blocks and so on. This should
make Petit FatFs actually usable.

So far read-only and no M-codes to let end users play with
this stuff.

The demonstration code was changed to list the SD card's
top level directory over and over again.
2015-07-05 23:32:48 +02:00
Markus Hitter 63c4dbaea9 mendel.c: do module enabling differently.
Same result, but 8 bytes less binary size. With SD card disabled,
binary size is now the same as before getting SPI running.
2015-07-05 23:32:48 +02:00
Markus Hitter 1fb3ece31e SD card: establish spi.c/.h and sd.c/.h and get SPI running.
For now this is just a nice demonstration on how to send bytes
over SPI. Add SD_CARD_SELECT_PIN to your configuration board
file manually to see data signals on MOSI dancing on the scope.

The TODO's about SS in arduino*.h were wrong, SS does have a
chip-specific special meaning (used in SPI multi-master or SPI
slave mode). Still, a #define MAX6675_SELECT_PIN is missing.

Squashed in this commit from the SPI development topic branch to
get this first step working:

Author: jbernardis <jeff.bernardis@gmail.com>
2015-02-04 22:35:07
mendel.c: disable SPI in power management only when not needed.

If we want to talk to a SD card connected to SPI, we need SPI
powered, of course.

From Traumflug: nice catch, Jeff!
2015-07-05 23:32:46 +02:00
Markus Hitter a217465e65 SIMINFO: fetch device name from Makefile / compile parameters.
It's also possible to do this by stringifying MCU, but this
requires double redirection, which isn't easily readable in a .c
file. For stringification, see the bottom example at
https://gcc.gnu.org/onlinedocs/cpp/Stringification.html
2015-04-21 02:51:31 +02:00
Markus Hitter f6115688c5 Move Intercom temp sensor initialisation from mendel.c to temp.c. 2014-12-26 19:41:38 +01:00
Markus Hitter a9f1d00865 Move MAX6675 initialisation from mendel.c to temp.c.
Also note a misplaced and misnamed pin.
2014-12-26 19:41:38 +01:00
Markus Hitter 5cc84a069a Canned G-code: setup right in config.h.
This works with Arduino IDE as well and should be easier to figure
for inexperienced users.
2014-08-31 19:31:39 +02:00
Markus Hitter 7f990a298c Canned G-code: don't miss first character. 2014-08-31 19:22:24 +02:00
Markus Hitter 1e97e51d2a Canned G-code: fix reading flash memory. 2014-08-31 19:20:50 +02:00
Michael Moon aed4bfdb5b Canned G-code: implement continuous replay of G-code stored on flash. 2014-08-31 19:19:21 +02:00
David Forrest 2bf98feaaa mendel.c: Enable DEBUG_LED_PIN output if defined. 2014-05-29 21:48:46 +02:00
Phil Hord 96b7b8e6c9 Update URLs for new github location 2014-03-04 19:57:08 +01:00
Phil Hord 21e5343552 Add config.h wrapper to simplify test automation
Test code which wants to customize config.h can do so without
touching config.h itself by wrapping config.h in a macro variable
which is passed in to the compiler.  It defaults to "config.h" if
no override is provided.

This change would break makefile dependency checking since the selection
of a different header file on the command line is not noticed by make
as a build-trigger.  To solve this, we add a layer to the BUILDDIR path
so build products are now specific to the USER_CONFIG choice if it is
not "config.h".
2014-03-04 19:56:23 +01:00
Markus Hitter 71ae941a09 Add simulation info for SimulAVR.
This shouldn't change the running binary at all, so it shouldn't
harm. However, it allows to run Teacup inside SimulAVR and accessing
Teacups' serial line through the console/terminal.

For detailed instructions, see http://reprap.org/wiki/SimulAVR .
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
Markus Hitter 01f7c99881 config.h: introduce PS_MOSFET_PIN for Sanguish support. 2013-10-27 20:01:51 +01:00
Markus Hitter 5d6de1761b Enable internal pullups for endstops on demand, only.
The binary size impact is moderate, like 18 bytes plus
4 bytes per endstop defined.

The story is a follows:

The endstop logic can be used to use a touch probe with PCB
milling. Connect the (conductive) PCB surface to GND, the
spindle/mill bit to the signal line, turn the internal pullups
on and there you go.

However, doing so with pullups always enabled and while milling
under (conductive) water showed polished mill and drill bits to
become matte after a few hours of usage. Obviously, this small
0.5 mA current from the pullup resistors going through the
rotating mill bit is sufficient to get some spark erosion going.
That's bad, as spark erosion happening also means tools become
dull faster than neccessary.

With this patch, pullups are turned on while being used, only,
so this sparc erosion should go away.
2012-12-03 19:48:13 +01:00
Markus Hitter d3af5460f1 Move heater initialisation from mendel.c to heater.c.
This enhances encapsulation.

An attempt to initialise only the timers in use was abandoned.
This isn't only unneccessary, as pins are still in normal
operation mode unless their bits in TCCR0A/TCCR2A/... are set,
even with the timer behind the pins running, it's also at least
tricky to sort pins and their timer bits at compile time. Doing
the sorting at runtime would cause additional binary size.
2012-11-08 16:22:46 +01:00
David Forrest 52ce6b5f52 More enablement of ATmega32U chip.
- ATmega32U timer 4 register handling differs from other AVRs:
  Change heater.c and mendel.c.
- LUFA USB recognition expanded in Makefile.
- Add section for __AVR_ATmega32U4__ in arduino.h.
2012-10-14 22:56:09 +02:00
Markus Hitter f06b013179 clock.c: introduce clock().
This simplifies calls to clock_10ms() a bit and saves 18 bytes
binary size.
2012-09-29 23:00:24 +02:00
Markus Hitter eaf6c453be Introduce gcode_init() and honor E_ABSOLUTE as the default. 2012-05-11 13:50:51 +02:00
Markus Hitter 5f9ae5b087 Implement M82/M83 and handle relative movements entirely different.
Instead of converting them to absolute first, then back to
relative and having all the fuzz with working on the queue's
start vs. working at the queue's end, mark a movement as relative
and use this directly.
2012-05-11 13:50:33 +02:00
Markus Hitter 86e20580f8 Make fast PWM optional.
In some cases the heater switching MOSFETs overheat and using a lower
PWM frequency is advised. See also:
http://reprap.org/wiki/Gen7_Research#Heat_vs._PWM_Frequency
2012-03-03 16:56:36 +01:00
Markus Hitter 2eff194cdf Rename STEPPER_ENABLE_INVERT to STEPPER_INVERT_ENABLE.
No functional change, just match the naming of single stepper
enable pins.
2011-10-05 14:13:28 +02:00
Markus Hitter a33964fc51 Clean up enable pin handling.
This includes:

- Initialize them in mendel.c.

- While running, switch the pin only.

- Sort mendel.c the same order as in pinio.h.

- Remove the requirement of a parameter for this flag, like
  it's with all other flags.
2011-10-05 14:13:25 +02:00
Markus Hitter 090da8ddad Clean up handling PS_ON_PIN and STEPPER_ENABLE_PIN.
This means moving power_on() from a macro to a function and
initializing the STEPPER_ENABLE_PIN in mendel.c.
2011-10-05 14:13:15 +02:00
Markus Hitter 51be23177a dda: move dda->n out into a new state variable
This required to also introduce dda_init() and re-adjust the
number of accelerating steps a bit.

Goal of this is to make look-ahead possible by just reducing
the number of deceleration steps and acceleration steps of
the next move. dda->c and dda->n no longer go down to their
initial values, then.

Also, quite a number of variables in the dda struct are used only when
the dda is live, so there is no need to store that for each
movement of the queue.
2011-05-15 20:34:35 +02:00