Commit Graph

1296 Commits

Author SHA1 Message Date
Markus Hitter 857fef578b heater-arm.c: turn on only timers needed.
OK, that's kind of nitpicking ...

Test: PWM pins should work as before.
2015-08-13 16:41:33 +02:00
Markus Hitter 1aeb04329c heater-arm.c: implement heater_set().
Works very nicely from full off (M106 S0) to full on (M106 S255).

Test: M106 should work now as expected. M106 S0 should turn full
off, M106 S255 should turn full on, both without any spike on the
scope.
2015-08-13 16:41:33 +02:00
Markus Hitter d7b59e2d33 ARM: implement heater-arm.c partially.
Currently at a fixed frequency of 1 kHz and with a fixed duty
cycle of 10%, but PWM does work.

As it turns out, PIO0_11 is not usable for PWM, because its timer
is already in use for the Step timer, and had to be disabled for
Gen7-ARM.

Test: define a heater in board.gen7-arm.h and a square signal
of 1 kHz with 10% duty cycle should appear on the heater pin.
2015-08-13 16:41:33 +02:00
Markus Hitter ee43a86474 ARM: split out heater-avr.c from heater.c.
Also move #defines from heater.c to heater.h

This operation became bigger than expected, because PID handling
hat to be separated from heater handling. Code and strategy wasn't
changed, but some chunks of code had to be moved.
2015-08-13 16:41:26 +02:00
Markus Hitter 8f24fbaad4 ARM: get temp.c in.
No code changes, but quite a few removals of __ARMEL_NOTYET__
guards. 20 such guards left.

Test: M105 should work and report plausible temperatures.

Current code size:

    SIZES          ARM...     lpc1114
    FLASH  :  9460 bytes          29%
    RAM    :  1258 bytes          31%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:37 +02:00
Markus Hitter 6b6aa84124 Makefile-ARM: disable Link Time Optimisation (-flto).
LTO makes generated assembly unreadable and also produces, despite
its intention, bigger binaries, currently by 90 bytes.
2015-08-12 14:26:37 +02:00
Markus Hitter 1a2973a2de analog-avr.c: take the opportunity to rewrite analog_read() here.
The former implementation easily led to memory corruption, because
no range check happened.

Costs 22 bytes binary size, unfortunately.
2015-08-12 14:26:37 +02:00
Markus Hitter 7805e741cd analog-arm.c: read not by ADC channel number, but by Teacup number.
Analog reading should be complete by now :-)
2015-08-12 14:26:37 +02:00
Markus Hitter 708289714f analog-arm.c: use configured analog pins, not two fixed ones.
An obvious neccessity, just not done before to show better how
stuff works.
2015-08-12 14:26:37 +02:00
Markus Hitter f81000a4b6 ARM: implement analog-arm.c.
Very simple, because the LPC1114 features a hardware scan mode,
which automatically scans a given set of pins in freerunning mode
and stores all the values separately. No need for an interrupt!

Not yet done: configure not PIO1_0 and PIO1_1, but the pins
actually defined in the board file.

For testing, add this to ifclock(clock_flag_1s) in clock.c:
  uint8_t i;

  for (i = 0; i <= 7; i++) {
    sersendf_P(PSTR("%lu "), analog_read(i));
  }
  serial_writechar('\n');

This should print all 8 ADC values repeatedly. Only two pins are
actually set up, these values should change depending on the
thermistor temperature. More precisely: depending on the voltage
on the pin.
2015-08-12 14:26:37 +02:00
Markus Hitter 56f6b381fd ARM: split out analog-avr.c from analog.c. 2015-08-12 14:26:37 +02:00
Markus Hitter 05c7cf067f ARM: get dda_lookahead.c in.
Not much to say, simply works.
2015-08-12 14:26:37 +02:00
Markus Hitter 7afbc70d58 Step timer: reset timer after pauses instead of doing a guess.
We know already wether we start from a pause or not, so let's
take advantage of this knowledge instead of checking for
plausibility of a timer delay at interrupt time.

Costs just 8 bytes binary size:

    SIZES          ARM...     lpc1114
    FLASH  :  7764 bytes          24%
    RAM    :   960 bytes          24%
    EEPROM :     0 bytes           0%

Due to the less code at interrupt time, maximum step rate was
raised from 127.9 kHz to 130.6 kHz.
2015-08-12 14:26:37 +02:00
Markus Hitter f32693bf4e ARM: extend the SysTick handler to also call dda_clock().
As dda_clock() is potantially too slow for high step rates, we
call it with a secondary interrupt with slightly slower priority.
This makes sure the slow part is ignored on high system load,
still reasonably synchonized with the clock tick.

Test: steppers should move and accelerate now.

Current binary size:

    SIZES          ARM...     lpc1114
    FLASH  :  7756 bytes          24%
    RAM    :   960 bytes          24%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:37 +02:00
Markus Hitter 5d8e866501 Move interrupt busy detection from dda_clock() to clock tick ISR.
The reason is, interrupts can't be re-entered on ARM, so we need
a different mechanism.
2015-08-12 14:26:37 +02:00
Markus Hitter a171a0c57f ARM: implement the stepper interrupt.
Works nicely, much less code than on AVR, because we have 32-bit
hardware timers.

Test: steppers should move. Only slowly, because dda_clock() isn't
called, yet, so no acceleration.

Pulse time on the Debug LED is 5.21 us or 250 clock ticks.
2015-08-12 14:26:37 +02:00
Markus Hitter 5a8d51cb19 ARM: get dda_maths.c, dda_kinematics.c and dda.c in.
All in one chunk, because it's all hardware-independent and doing
them one by one would end up on not more than some typing
exercises.

Compiles fine. For testing, remove if (DEBUG... for M114 in
gcode_process.c. Then one can see how the queue fills up when
sending movements and M114 repeatedly. This time with actual
coordinates.

No stepper movements, yet, because set_timer() is still empty.
2015-08-12 14:26:37 +02:00
Markus Hitter 692a6daeb2 ARM: get dda_queue.c in.
Compiles fine. For testing, remove if (DEBUG... for M114 in
gcode_process.c. Then one can see how the queue fills up when
sending movements and M114 repeatedly.

queue_step() isn't called, yet, the stepper timer is still missing.
2015-08-12 14:26:37 +02:00
Markus Hitter c118d00383 ARM: get clock.c in.
No code changes neccessary.

This code in ifclock(clock_flag_1s) in clock.c should give a nice,
accurate clock:

    static uint8_t minutes = 0, seconds = 0;

    seconds++;
    if ( ! (seconds % 60)) {
      seconds = 0;
      minutes++;
    }
    sersendf_P(PSTR("%su:"), minutes);
    if (seconds < 10)
      serial_writechar('0');
    sersendf_P(PSTR("%su\n"), seconds);

Current sizes are:

    SIZES          ARM...     lpc1114
    FLASH  :  4440 bytes          14%
    RAM    :   200 bytes           5%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:36 +02:00
Markus Hitter ec8f0133bf ARM: port memory_barrier.h.
This is just a best guess, because none of the compiled code uses
it so far, but a pretty safe one.
2015-08-12 14:26:36 +02:00
Markus Hitter 137a638658 ARM: get timer.c in, so far only with the system clock.
This test code in SysTickHanlder() should give you a rather
accurate clock with only a few seconds deviation per hour:

  #include "serial.h"
  #include "sersendf.h"
  void SysTick_Handler(void) {
    static uint32_t count = 0;
    static uint8_t minutes = 0, seconds = 0;

    count++;

    if ( ! (count % 500)) {   // A full second.
      seconds++;
      if ( ! (seconds % 60)) {
        seconds = 0;
        minutes++;
      }
      sersendf_P(PSTR("%su:"), minutes);
      if (seconds < 10)
        serial_writechar('0');
      sersendf_P(PSTR("%su\n"), seconds);
    }
  [...]
2015-08-12 14:26:36 +02:00
Markus Hitter feeb411eec ARM: split timer.c into platform specific files.
AVR and simulator are kept together, because the simulator
apparently simulates much of the AVR timer infrastructure.

ARM variant is empty, so far.
2015-08-12 14:26:36 +02:00
Markus Hitter e434423dd9 heater.c, sd.c: apply the changed order of SET_OUTPUT() here, too.
Now it's changed everywhere.
2015-08-12 14:26:36 +02:00
Markus Hitter 4faa3cbf8f ARM: bring in pinio.c.
This enables pinio_init(), power_on() and power_off(). Now one
can turn on the power supply with M119 and turn it off with M2.

Code changes were neccessary. Setting a pin first, then making
it an output doesn't work on ARM. A pin has to be an output
before it permanently accepts a given state. As I was never
sure the former strategy actually worked on AVR, the order of
these two steps was changed for both, AVR and ARM.
2015-08-12 14:26:36 +02:00
Markus Hitter 96f7dbd2b1 ARM: bring in gcode_process.c.
Again, the whole file compiled flawlessly without change. Still,
to get it linked as well, most of the functionality had to
be #ifdef'd out.

Nevertheless, the firmware shows first signs of life, e.g. M115
works.
2015-08-12 14:26:36 +02:00
Markus Hitter 7be5212f06 ARM: introduce sei() and cli().
No test, because it's tricky to test, but it compiles and the
firmware still works as before.
2015-08-12 14:26:36 +02:00
Markus Hitter 608506719b gcode_parse.h: order variables reasonably in groups of 4 bytes.
This uses 4 bytes less RAM, without any loss, due to fewer holes
in variable arrangements.

The general strategy is simple:

 - Ideally, all variables are aligned in groups of 4 bytes
   (32 bits). This allows fastest access on 32-bit CPUs and doesn't
   change anything on 8 or 16 bit ones.

 - 1x 32-bits variable = 4 bytes = 4-byte group.

 - 2x 16-bits variable together = 4-byte group.

 - 4x 8-bits variable together = 4-byte group.

 - Have as few incomplete groups as possible.

Another strategy is to simply order variables by size.

There's a compiler flag to pack such variable arrangements, but
this costs Flash size and processing time.
2015-08-12 14:26:36 +02:00
Markus Hitter e5729d6743 ARM: get gcode_parse.c in.
Just did it, no code changes neccessary. Except ajusting the
boundaries to not yet ported code.

Successful tests: controller answers with "ok", just like an AVR.

Binary size raised, of course:

    SIZES          ARM...     lpc1114
    FLASH  :  3064 bytes          10%
    RAM    :   194 bytes           5%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:36 +02:00
Markus Hitter ab910ee1c4 ARM: add Gen7-ARM to the series of regression tests.
Now ARM based boards are covered as well :-)
2015-08-12 14:26:36 +02:00
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 2dd35e6529 ARM: prettify cmsis-system_lpc11xx.c/.h.
Again, remove trailing whitespace and such stuff.
2015-08-12 14:26:36 +02:00
Markus Hitter b1490658cf ARM: rename mbed-system_LPC11xx.c/.h to cmsis-system_lpc11xx.c/.h.
Last part of the effort to rename all CMSIS-provided files to
"cmsis-".
2015-08-12 14:26:36 +02:00
Markus Hitter ccbe3fbfbb ARM: prettify cmsis-core_cm0.h.
This is just wording for the Teacup changes notes consistent with
the other cmsis- files.
2015-08-12 14:26:36 +02:00
Markus Hitter 052706975d ARM: rename mbed-core_cm0.h to cmsis-core_cm0.h.
Part of the effort to rename all CMSIS-provided files to "cmsis-".
2015-08-12 14:26:36 +02:00
Markus Hitter d1c624f0c5 ARM: prettify cmsis-lpc11xx.h.
This is, remove trailing whitespace and such stuff. Log of all
changes near the top of the file.
2015-08-12 14:26:36 +02:00
Markus Hitter a7240523e1 ARM: rename mbed-LPC11xx.h to cmsis-lpc11xx.h.
Part of the effort to rename all CMSIS-provided files to "cmsis-".
2015-08-12 14:26:36 +02:00
Markus Hitter 4ff26e1776 ARM: prettify current cmsis- files.
This is, reformat the "Changes for Teacup" section, change tabs
for spaces, remove trailing whitespace and keep the file as close
to the original as possible.
2015-08-12 14:26:35 +02:00
Markus Hitter 5fa7bfbf81 ARM: rename arm-startup_lpc11xx.s to cmsis-startup_lpc11xx.s. 2015-08-12 14:26:35 +02:00
Markus Hitter f2005f0018 ARM: rename arm-lpc-1114.ld to cmsis-lpc1114.ld.
This is the start of renaming all CMSIS related files to
"cmsis-...".
2015-08-12 14:26:35 +02:00
Markus Hitter e8299deb86 serial-arm.c: don't calculate serial line parameters at runtime.
This is a pretty complex and, as system clock and baudrate are
known at compile time and never changed at runtime, unneccessary.
Replacing this calculation with fixed values makes the binary
a whopping 564 bytes smaller.

However, how to get these values? Well, we do kind of an
easter-egg. If parameters arenot known, we calculate them at
runtime anyways, and also report them to the user. So she can
insert them into the code and after doing so, whoops, serial
fast and binary small :-)

With known parameters:

    SIZES          ARM...     lpc1114
    FLASH  :  1092 bytes           4%
    RAM    :   132 bytes           4%
    EEPROM :     0 bytes           0%

Without (1428 bytes more):

    SIZES          ARM...     lpc1114
    FLASH  :  2520 bytes           8%
    RAM    :   132 bytes           4%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:35 +02:00
Markus Hitter fc124c14d4 serial-arm.c: allow sending arbitrarily long messages.
On ARM we use only the 16 byte hardware buffer for sending and
receiving over the serial line, which is often too short for
debugging messages. This implementation works fine and still
neither blocks nor introduces delays for short messages.

Costs 72 bytes binary size, mostly because it's the first usage
of delay_us():
    SIZES          ARM...     lpc1114
    FLASH  :  1656 bytes           6%
    RAM    :   136 bytes           4%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:35 +02:00
Markus Hitter 8f90e63e85 serial-arm.c: don't store a pointer to the serial port.
As this pointer isn't used anywhere else, it's pointless. Saves
4 bytes binary size and 4 bytes RAM.

    SIZES          ARM...     lpc1114
    FLASH  :  1584 bytes           5%
    RAM    :   136 bytes           4%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:35 +02:00
Markus Hitter 8377de8d66 ARM: get delay.c in.
Accuracy is pretty good, see committed comments :-)

Code used for testing, in main():

  uint32_t i;

  SET_OUTPUT(PIO0_1);
  while (1) {
    // 10 seconds for each frequency, so we
    // can measure all three with one upload.
    for (i = 10000; i > 0; i--) {
      WRITE(PIO0_1, 1);
      delay_us(1000);
      WRITE(PIO0_1, 0);
      delay_us(1000);
    }
    for (i = 1000; i > 0; i--) {
      WRITE(PIO0_1, 1);
      delay_us(10000);
      WRITE(PIO0_1, 0);
      delay_us(10000);
    }
    for (i = 200; i > 0; i--) {
      WRITE(PIO0_1, 1);
      delay_us(65000);
      WRITE(PIO0_1, 0);
      delay_us(65000);
    }
  }
2015-08-12 14:26:35 +02:00
Markus Hitter 6c31471ffd ARM: split out architecture specific parts for delay.c
(Hopefully) no functional change.

Also remove these wd_reset()s in delay_us() to match the behaviour
promised in delay.h. Not that this matters much, watchdog is
disabled by default.
2015-08-12 14:26:35 +02:00
Markus Hitter e2df7733ee ARM: move system definitions from .c to .h.
More precisely, from mbed-system_LPC11xx.c to
mbed-system_LPC11xx.h. This way these definitions are available
elsewhere in the code.
2015-08-12 14:26:35 +02:00
Markus Hitter 52e2585f13 ARM: use arduino.h for UART pinout.
This removes another 36 bytes binary size and six(!) MBED files.

The mess of MBED files is now pretty much resolved, only a few
essential ones left.
2015-08-12 14:26:35 +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 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