Commit Graph

1299 Commits

Author SHA1 Message Date
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 facd1ee606 pinio.h: implement PULLUP_ON() and PULLUP_OFF().
On ARM enabling the pullup on an input pin isn't done by writing
a 1 to the pin, but by setting the corresponding register.
Accordingly we need a distinct function for this.
2015-08-12 14:26:35 +02:00
Markus Hitter 45bcef395e ARM: implement SET_INPUT() and READ().
Tested and found to work. Excellent.

Test code before main():

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

Test code in main():

  SET_INPUT(PIO0_1);
  SET_INPUT(PIO0_2);
  SET_INPUT(PIO0_3);
  SET_INPUT(PIO0_4);

  delay(5000000);
  while (1) {
    sersendf_P(PSTR("\nPIO0_1  PIO"));
    delay(100000);
    sersendf_P(PSTR("0_2  PIO0_3"));
    delay(100000);
    sersendf_P(PSTR("  PIO0_4\n"));
    delay(100000);
    sersendf_P(PSTR("  %sx"), READ(PIO0_1));
    delay(100000);
    sersendf_P(PSTR("    %sx"), READ(PIO0_2));
    delay(100000);
    sersendf_P(PSTR("    %sx"), READ(PIO0_3));
    delay(100000);
    // PIO0_4 works, but the chip doesn't allow to set a pullup.
    sersendf_P(PSTR("    %sx\n"), READ(PIO0_4));
    delay(5000000);
  }
2015-08-12 14:26:35 +02:00
Markus Hitter 072e3f8ae5 ARM: also set GPIO function and mode.
This also implements more of the FastIO infrastructure.
Unfortunately, definitions aren't exactly straightforward, so we
need lots of tabular data. For example, for the pin function I
I had to step through the user manual, pin by pin.

We also learned a lesson here: Cortex-M0 has a 4 word ( = 16 bytes)
prefetch engine. Loops not starting at such a boundary take
additional 4 clock cycles, making them slower. The tight loop used
for testing previously happened to be 16-byte aligne by accident.
Adding just one line of code in the SET_OUTPUT() macro misaligned
it, so loop repetition rate dropped from 5.3 MHz to 3.7 MHz.

There are many measures to align code to 16-byte boundaries:

 - -falign-functions=16 as gcc flag.

 - -falign-loops=16 as gcc flag, found to not work.

 - -falign-labels=16 as gcc flag, worked for aligning the loop,
   but also bloated the binary by 10%.

 - __attribute__ ((aligned(16))) attached to functions (not
   tested)

 - Adding this just before the loop worked fine and increased the
   binary by just 16 bytes:

     __ASM (".balign 16");

Take care of this when relying on exact execution times, e.g. when
implementing delay_us()!
2015-08-12 14:26:35 +02:00
Markus Hitter c66bf0a8de pinio.h: remove TOGGLE(), GET_INPUT(), GET_OUTPUT() macros.
Nowhere used, which unlikely changes in the forseeable future.
2015-08-12 14:26:35 +02:00
Markus Hitter 2b52233a2d pinio.h: apply the formatting used for ARM for AVR as well.
No functinal change.
2015-08-12 14:26:34 +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 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
Markus Hitter 32480bdfb6 ARM: silence warning in mbed-system_LPC11xx.c.
No functional change, just moved declarations to a more
appropriate place.
2015-08-12 14:26:34 +02:00
Markus Hitter a336ae57e3 ARM: get rid of mbed-core_cmFunc.h and mbed-core_cmInstr.h.
Since MBED's serial_api is no longer in use, they're no longer
needed either. Except for a simple assembler instruction, which
was inserted directly.
2015-08-12 14:26:34 +02:00
Markus Hitter 5b8068d228 sersendf.c/.h: remove sersendf() (not sersendf_P()).
Was commented out already and probably never used.
2015-08-12 14:26:34 +02:00
Markus Hitter 485427017d sersendf.c: explicitely cast to the requested size.
This adds 48 bytes binary size but should help to avoid confusion
when using sersendf_P() for debugging.
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 829e4d475b Makefiles: add a hint on how to list these predefined macros.
No functional change.
2015-08-12 14:26:34 +02:00
Markus Hitter ce40b678f6 Solve the pgmspace.h problem centrally.
We previously put replacements for the von Neuman architecture
into arduino.h already, now let's complete this by having only
one #include <avr/pgmspace.h> in arduino.h. Almost all sources
include arduino.h anyways, so this is mostly a code reduction.
2015-08-12 14:26:34 +02:00
Markus Hitter 52f5a56d71 ARM: move serial handling code directly into serial-arm.c.
This makes another seven mbed files obsolete and reduces binary
size by another 100 bytes Flash and 16 bytes RAM:

    SIZES          ARM...     lpc1114
    FLASH  :  1624 bytes           5%
    RAM    :   140 bytes           4%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:34 +02:00
Markus Hitter 776f90ff2c ARM: simplify serial and get rid of mbed-pinmap_common.c.
We have only one UART, we use only one UART, so it's pointless to
do pin mapping calculations at runtime.

Binary size down by 268 bytes:
    SIZES          ARM...     lpc1114
    FLASH  :  1724 bytes           6%
    RAM    :   156 bytes           4%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:34 +02:00
Markus Hitter a5cb1bd31a ARM: get rid of mbed-mbed_error.h and mbed-error.c.
Same functionality, drastically smaller binary:

    SIZES          ARM...     lpc1114
    FLASH  :  1992 bytes           7%
    RAM    :   156 bytes           4%
    EEPROM :     0 bytes           0%

That's a reduction by 3948 bytes Flash and 20 bytes RAM.
2015-08-12 14:26:34 +02:00
Markus Hitter 848369608b ARM: get rid of mbed-mbed_assert.h.
No functional change, binary size 16 bytes smaller.
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 9e9e946c6d Makefile-ARM: get uploading to work. 2015-08-12 14:26:34 +02:00
Markus Hitter 3cc81cdba8 Makefile-ARM: adjust sizes reporting to our only target. 2015-08-12 14:26:33 +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 24b2cd1d02 ARM: start generic port by splitting out AVR specific serial code.
This shows the new strategy to deal with architecture-specific
code:

 - Keep common code as before.

 - Keep the header file unchanged as well, no architecture
   specific headers.

 - Move architecture specific code to an architecture specific
   file and wrap the whole contents into an architecture test.

 - Also wrap the whole contents with #ifdef TEACUP_C_INCLUDE.
   Without this wrapping, Arduino IDE as well as Configtool would
   compile the stuff twice, because they compile everything
   unconditionally.

 - Last not least, #define TEACUP_C_INCLUDE and #include all
   architecture specific files unconditionally.

Build tests were successful with the Makefile, with Configtool
and with Arduino 1.5.8, so this strategy is expected to work.

Regarding the copy operation of this commit: code unchanged,
other than rewriting of all the comments for the current idea of
'proper' formatting, getting rid of tabs and some other whitespace
editing.
2015-08-12 14:26:33 +02:00
Markus Hitter 43626b2ba2 boardpanel.py: fix getCPUInfo(), don't report tuples.
This was forgotten with the recent move to storing configuration
items as tuples (value, enabled). It should fix the refusal to
build reported in issue #86.
2015-08-12 14:18:40 +02:00
Markus Hitter cf3b94b980 heater.c/.h: get rid of heaters_all_off().
Nowhere used and exactly duplicated heaters_all_zero().
2015-08-07 16:16:05 +02:00
Markus Hitter 36c2e09788 temp.c: remove a number of obsolete #includes. 2015-08-07 16:16:05 +02:00
Markus Hitter 4353403695 gcode_process.c: replace some sersendf() with serial_writestr().
sersendf_P() is only needed for formatted strings, plain strings
can be sent simpler.

Saves 48 bytes binary size on AVR.
2015-08-07 16:16:05 +02:00
Markus Hitter 9c194b42f6 Messages: more newlines needed.
The recent switch to send 'ok' postponed requires also sending a
newline in a few places, because this 'ok' is no longer at the
start of the line. Now it appears in its own line.

Some whitespace at line end was removed in heater.c.

Costs 14 bytes binary size on AVR.
2015-08-07 16:15:17 +02:00
Markus Hitter 9075459659 dda_queue.c: remove trigraphs in queue_full() and queue_empty().
Saves just 2 bytes binary size, but better than moving the work
to the trash.
2015-08-04 23:03:51 +02:00
Markus Hitter fa8ec35bc1 run-in-simulavr.sh: report LED on time in clocks instead of ns. 2015-08-04 23:03:51 +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 a1feb32fe3 serial.c/.h: remove serial_writeblock() and ..._P().
Never used, all "blocks" we write are strings.
2015-08-04 23:01:43 +02:00
Markus Hitter 7c8f1cec87 .gitignore: make room for private stuff.
These files for local configurations tend to pile up and having
them just lying around clutters a 'git status'. Putting them
into private/ makes them invisible for Git now.

As we're on the topic, I use such Makefile targets for my printers:

sells: private/config.sells.h
sells: private/board.sells.h private/printer.sells.h
	@echo "Compiling and uploading for the Sells Mendel."
	$(MAKE) -f Makefile-AVR USER_CONFIG=private/config.sells.h \
	  MCU=atmega1284p F_CPU=20000000UL all
	avrdude -s -V -c stk500v2 -b 115200 -p $(MCU) -P /dev/ttyUSB0 \
	        -U flash:w:$(PROGRAM).hex
2015-08-04 13:48:30 +02:00
Markus Hitter eb166ce3ef timer.h: remove some obsolete stuff, replace char with uint8_t.
No functional change.
2015-08-03 12:11:19 +02:00
Markus Hitter 2af689a4db gcode_process.c: remove a redundant #ifdef DEBUG and similar. 2015-08-01 18:27:39 +02:00
Markus Hitter 99fdb99203 clock.c: make stuff used only in clock.c static to this file.
Better encapsulation, no functional change, no binary size change.
2015-08-01 16:22:10 +02:00
Markus Hitter 03ab34729e serial.h: remove an obsolete #include. 2015-07-31 02:01:36 +02:00
Markus Hitter 4e30501868 dda_lookahead.c: remove unused code. 2015-07-30 23:14:01 +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 421fe3d641 Tools: add git-regtest.
This is a tool to run regression tests over a whole series of
commits. Typical usage:

  git checkout <topic branch>
  tools/git-regtest experimental

This runs 'make regressiontest' for every single commit between
experimental and HEAD of the topic branch. Very convenient to make
sure not a single commit introduces regressions.

If there are regressions, the tools stops at the commit bringing
in the regression, so you immediately know where to look.
2015-07-30 17:15:57 +02:00
Markus Hitter 5846961744 Tools: add git-step-rebase.
This is a tool for rebasing step by step, like described in
issue #81. It reliefs from all the manual typing, just rebase
a topic branch like this:

  git checkout <topic branch>
  tools/git-step-rebase experimental

Linking or copying this script somewhere into the PATH even allows
to use it from within git:

  git step-rebase ...
2015-07-30 16:21:32 +02:00
Markus Hitter 42b96e0e27 SD card: commit SD_CARD_SELECT_PIN to all the board files.
For the bigger boards like RAMPS or Rumba the pin numbers were
taken from Marlin. For the smaller boards, the pin is commented
out.
2015-07-30 15:31:57 +02:00
Phil Hord 15e8dec9b2 board.gen3.h: restore {TX,RX}_ENABLE_PIN defs.
These were dropped accidentally, I assume, during the Configtool
template conversion. Without them the INTERCOM feature does not
compile and so board.gen3.h is broken.

Add the gen3 config to testcases and regressiontests to ensure
this does not drop again.
2015-07-29 21:05:38 +02:00
Phil Hord 22b640697b Replace SIMULATOR with __AVR__ in several places.
Previously some features were excluded based on whether SIMULATOR
was defined. But in fact these should have been included when __AVR__
was defined. These used to be the same thing, but now with ARM coming
into the picture, they are not. Fix the situation so AVR includes are
truly only used when __AVR__ is defined.

The _crc16_update function appears to be specific to AVR; I've kept the
alternate implementation limited to AVR in that case in crc.c. I think
this is the right thing to do, but I am not sure. Maybe ARM has some
equivalent function in their libraries.
2015-07-29 21:05:38 +02:00
jbernardis c92dcb02e2 Configtool: thermistor table entries are now distributed by ADC.
Previously they were evenly spaced across the temperature range,
now they're evenly distributed across the ADC range ... which
is not entirely the same.

This is related to issue #176.
2015-07-27 18:04:41 +02:00
jbernardis a40f818068 Configtool: fix the logic to accept floating input.
Previously if did not read back in the table information correctly.

This is related to issue #176.
2015-07-27 18:04:32 +02:00
jbernardis feb57c3eb0 Configtool: Steinhart-Hart temperature fields should allow floats.
This is, the parameter entry fields in the GUI, not in the
generated temperature table. Allowing floats is a tiny bit more
precise and also, more importantly, less confusing for the user.
--Traumflug

This is related to issue #176.
2015-07-27 18:04:02 +02:00