Commit Graph

906 Commits

Author SHA1 Message Date
Kevin O'Connor 7a265f159a armcm_irq: Fix jump target alignment
The jump target needs to be 4 byte aligned (not 2^4 bytes).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-13 11:47:00 -04:00
Kevin O'Connor 0225d17343 stm32f1: Use __always_inline on timer_read_time
Some older versions of gcc need the __always_inline directive in order
to inline timer_read_time.  Inlining that function is important for
performance on the stm32f1.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-11 22:20:02 -04:00
Kevin O'Connor 7cbc44b8d3 stm32f1: Use -O2 optimization and inline timer_read_time()
As long as timer_read_time() is inlined, I get better performance with
gcc -O2 optimization.  The binary is also dramatically smaller and O2
better matches the other platforms.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-11 10:50:51 -04:00
Kevin O'Connor 102ec4938d stm32f1: Use the main lib/cmsis-core directory for cmsis includes
Use the main cmsis header files with stm32f1.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-11 10:50:51 -04:00
Kevin O'Connor 75fa74313c stm32f1: Add support for building with bootloader support
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-11 10:50:51 -04:00
Kevin O'Connor 215b4c5a1e stm32f1: Move assembler build rules together
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-11 10:50:51 -04:00
Kevin O'Connor b8745bc973 stm32f1: Pull the USB D+ line low briefly to signal a device connect
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-11 10:50:51 -04:00
Kevin O'Connor bc5e961d73 stm32f1: Initial support for serial over USB
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-11 10:50:51 -04:00
Kevin O'Connor 1302514ea8 stm32f1: Serial should have a higher irq priority than timers
It's possible for the code to stay in the timer irq for up to 100ms,
so serial irqs should have a higher irq priority to prevent them from
being starved.  (The timer code disables irqs during event dispatch,
so serial irqs would only be permitted between events anyway.)

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-11 10:50:51 -04:00
Kevin O'Connor 978b321f80 avr: Disable usb serial interrupts while processing data
There's no need to keep taking interrupts if the high-level code is
busy processing messages.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-02 22:17:39 -04:00
Kevin O'Connor 7c7573f69f avr: No need to reset ep0 interrupts on a shutdown
The usb_cdc code will arrange to call usb_read_ep0_setup() after a
shutdown, so no need to have an explicit shutdown handler.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-02 21:41:36 -04:00
Kevin O'Connor efd9e7a6df usb_cdc: Try to read new data before processing data blocks
Call usb_read_bulk_out() before calling command_find_and_dispatch() as
this optimizes the common case where each usb packet contains a single
new message block.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-02 21:38:58 -04:00
Kevin O'Connor fe98dd3585 usb_cdc: Wake usb_bulk_out_task() on a shutdown
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-02 21:33:46 -04:00
Kevin O'Connor d348f0da87 avr: Allow the serial port to be selected on the atmega2560/1280
Allow the serial port to be selected on the atmega2560 and atmega1280
chips in Kconfig.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-01 22:30:58 -04:00
Kevin O'Connor 357b2f477c buttons: Clear pressed/last_pressed state on new buttons_query command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-01 12:40:28 -04:00
Kevin O'Connor c68c0c6526 avr: Increase stack size to 256 for all AVR targets
Recent code additions have increased the stack usage and it is no
longer clear that everything will fit in 128 bytes.  Increase all
targets to 256 bytes (the atmega2560 was already at 256 bytes).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-10-01 10:33:18 -04:00
Kevin O'Connor b3a6fbed74 usbstd: Force usb_string_descriptor data field to match unicode string
Fix travis-ci build failure by forcing the data field of the struct
usb_string_descriptor to be the same type as a 16bit unicode string.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-09-30 23:50:51 -04:00
Kevin O'Connor d05aa81927 avr: Use generic usb_cdc code for usb serial support
Use the generic usb_cdc driver code instead of the "pjrc" usb driver
code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-09-30 22:55:21 -04:00
Kevin O'Connor c0311bee33 usb_cdc: Perform basic request validation
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-09-30 22:32:19 -04:00
Kevin O'Connor 93e4897044 usb_cdc: Add usb_read_ep0_setup() interface function
Use new usb_read_ep0_setup() function when reading a setup packet -
this allows the low-level usb hardware code to better handle errors.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-09-30 22:32:19 -04:00
Kevin O'Connor 731236cf20 usb_cdc: Add support for usb_send_ep0_progmem()
Add support for explicitly sending to the ep0 pipe from constant
"progmem" memory on the AVR.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-09-30 22:32:19 -04:00
Kevin O'Connor 92aea93500 usb_cdc: Fix handling of zero-length-packets
A zero length packet should only be sent at the end of a transmission
if the host is expecting more data.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-09-30 22:32:19 -04:00
Kevin O'Connor be1effebc3 usb_cdc: Rework transfer state tracking code
Maintain the state tracking code entirely within a usb_do_xfer()
method.  This simplifies the callers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-09-30 22:32:19 -04:00
Kevin O'Connor 6ab16d2407 usb_cdc: Rename interface functions to avoid the term "setup"
Use "ep0" when referring to endpoint0 - don't use "setup" as that can
be confused with the low-level usb setup token.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-09-30 14:09:55 -04:00
Kevin O'Connor ca7a80a946 tmc2208: Initial support for configuring TMC2208 drivers
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:51:27 -04:00
Kevin O'Connor e5d95fdd00 stm32f1: Add support for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:45:01 -04:00
Kevin O'Connor 983c84b12f pru: Add wrappers for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:45:01 -04:00
Kevin O'Connor 75de9cb4c0 simulator: Add support for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:45:01 -04:00
Kevin O'Connor fa3d2b97bd samd21: Add support for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:45:01 -04:00
Kevin O'Connor eec58b99fe sam4e8e: Add support for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:44:59 -04:00
Kevin O'Connor 109eff0191 sam3x8e: Add support for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:40:38 -04:00
Kevin O'Connor 5a993b743e lpc176x: Add support for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:40:38 -04:00
Kevin O'Connor 1ae67441c3 avr: Add support for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:40:38 -04:00
Kevin O'Connor 34fe4cce14 sched: Don't require 2ms pad in sched_add_timer()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 12:40:38 -04:00
Kevin O'Connor 0bce44e1bb avr: Disable HAVE_GPIO_BITBANGING on atmega168
The atmega168 doesn't have enough flash space to fit all features -
disable the "bit banging" interfaces to make room.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 11:20:29 -04:00
Kevin O'Connor a20d9d3bd5 samd21: Enable HAVE_GPIO_BITBANGING
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 11:11:28 -04:00
Kevin O'Connor 82a542faed Kconfig: Rename HAVE_USER_INTERFACE to HAVE_GPIO_BITBANGING
Rename the HAVE_USER_INTERFACE definition in preparation for other
"bit banging" interfaces.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 11:09:47 -04:00
Kevin O'Connor 051e8724a0 sam4e8e: Use local copy of bossac for flashing
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 08:54:43 -04:00
Kevin O'Connor 22f0db06a1 sam3x8e: Use local copy of bossac for flashing
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-27 08:54:43 -04:00
Florian Heilmann b065f51454 sam4e8e: Fix bug in sam4e gpio.c (#563)
The bank_id was calculated erroneously. Also unify gpio_in_setup and gpio_out_setup a bit. Also disable make flash for the sam4e8e port as it currently references a version of bossac that is not present on all systems.

Signed-off-by: Florian Heilmann <Florian.Heilmann@gmx.net>
2018-08-24 13:17:53 -04:00
Kevin O'Connor 5fb1c76c0e samd21: Fix description of bootloader offset
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-08 19:56:43 -04:00
Florian Heilmann 64e6d85898 sam4e8e: Add the SAM4e8e port
This can be flashed to e.g. the duet wifi using bossac. It requires a
later version as is currently included in the klipper repo (1.8
vs. 1.2). Comms are currently via UART0 only, USB serial is still TBD

Signed-off-by: Florian Heilmann <Florian.Heilmann@gmx.net>
2018-08-08 10:44:49 -04:00
Kevin O'Connor f067d0cc78 samd21: Minor fixes to usbserial
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-08 10:43:57 -04:00
Kevin O'Connor 0daf19c003 samd21: Add support for USB
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-07 00:03:41 -04:00
Kevin O'Connor cf2393efc8 samd21: Add support for gpio pins
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-07 00:03:21 -04:00
Kevin O'Connor 74cf4dc9e0 samd21: Initial support for SAMD21 micro-controllers
Add initial support for the Atmel SAMD21 micro-controllers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-07 00:03:18 -04:00
Kevin O'Connor 50142cc1b3 armcm_irq: Enhance clear_active_irq() so it works on cortex-m0
Minor rework of the assembler so that it does not require thumb-2
instructions.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-06 23:36:05 -04:00
Kevin O'Connor 635a199a47 usb_cdc: Allow USB endpoint ids to be board specific
It's common for boards to have restrictions on the type of each
endpoint.  So, make it possible for the board to select the endpoint
ids for each endpoint.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-06 23:36:05 -04:00
Kevin O'Connor f4910e119a lpc176x: Use common cmsis-core files
No need to include separate cmsis files from the mbed project - the
standard CMSIS_5 files work fine.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-06 23:36:05 -04:00
Kevin O'Connor e1146c04fd sam3x8e: Use SAM3X CMSIS files instead of arduino CMSIS files
Update the sam3x8e port use the most recent SAM3X CMSIS files from
Atmel.  The Atmel files appear to have a more consistent license and
it is unclear if there were Arduino specific changes in the CMSIS
files obtained from the Arduino repo.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-08-06 23:36:05 -04:00
Kevin O'Connor 7a9553b38a thermocouple: Minor fixes
Send the temperature before checking for an out of range error (that
makes it easier to debug).

The query_thermocouple clock parameter is unpredictable and a value of
zero can't be used to disable the query - use rest_ticks instead.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-25 09:06:50 -04:00
Ricardo Amezquita 756514adef thermocouple: Add support for MAX6675 chip
The MAX6675 chip has a different read sequence than the MAX31855 chip.

Signed-off-by: Ricardo Amézquita <ramezquitao@cihologramas.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-24 11:16:05 -04:00
Kevin O'Connor eba252d3fd thermocouple: Add initial support for common SPI temperature sensing chips
Signed-off-by: Petri Honkala <cruwaller@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-24 11:16:05 -04:00
Ricardo Amezquita 940db6bd70 linux: Add support for bi-directional SPI communication
Signed-off-by: Ricardo Amézquita <ramezquitao@cihologramas.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-24 11:16:05 -04:00
Kevin O'Connor e2b4b1616f lpc176x: Add support for SPI
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-18 10:11:29 -04:00
Pascal Albert 244d0aa65b atmega1284p: Add choice between UART0 or UART1 to Kconfig
Signed-off-by: Pascal Albert <lucky@foxserver.org>
2018-07-13 19:58:04 -04:00
Kevin O'Connor 32a85edb16 spidev: Minor rework to spidev_transfer()
Gcc does a better job of inlining code if spidev_transfer() is
reworked slightly.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-11 19:43:20 -04:00
Kevin O'Connor 733506dfb2 sam3x8e: Configure spi transfer in spi_prepare()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-11 19:40:51 -04:00
Kevin O'Connor d9f960fb0c avr: Configure spi transfer in spi_prepare()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-11 19:40:21 -04:00
Kevin O'Connor 5294b3cd2d simulator: Rework dummy simulator code to user timer_irq / serial_irq
Change the simulator to use the generic timer_irq.c and serial_irq.c
code for (dummy) timer and io handling.  This is just to make the code
a better example for other developers (most micro-controllers will use
the timer_irq.c and serial_irq.c code).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-11 14:35:24 -04:00
Grigori Goronzy 2991c7a831 stm32f1: implement spi_prepare
Implement spi_prepare to fix the undefined behavior on SPI transaction
start.

Tested with the following command sequence:

allocate_oids count=2
config_spi oid=0 bus=0 pin=PA8 mode=3 rate=1000000 shutdown_msg=
config_spi oid=1 bus=0 pin=PA8 mode=1 rate=1000000 shutdown_msg=
spi_send oid=0 data=30313233343536373839
spi_transfer oid=1 data=3031

Discussion about this here:
https://github.com/KevinOConnor/klipper/pull/453#issuecomment-403131149

Signed-off-by: Grigori Goronzy <greg@chown.ath.cx>
2018-07-08 09:25:11 -04:00
Grigori Goronzy ebd9035325 SPI: introduce spi_prepare function
The SPI interface needs to be enabled and configured to the correct
settings of a given oid before CS is asserted. The new function
spi_prepare() allows ports to do that.

This port only introduces the new function in all ports with no
implementation and adds the call to the Klipper generic firmware code.
That means everything still works as before. Ports need to be changed
to fix the underlying issue.

Discussion about the motivation here:
https://github.com/KevinOConnor/klipper/pull/453#issuecomment-403131149

Signed-off-by: Grigori Goronzy <greg@chown.ath.cx>
2018-07-08 09:25:11 -04:00
Grigori Goronzy 5c7c8c984b stm32f1: add SPI support
Add basic SPI support and associated documentation.

v2: remove baud rate check, fix baud rate calculations
v3: finish transaction with BSY check, disable SPI when not in use

Signed-off-by: Grigori Goronzy <greg@chown.ath.cx>
2018-07-07 11:05:33 -04:00
Kevin O'Connor 1eb416002b sam3x8e: Read from the SPI_RDR on SPI send even if no data needed
Be sure to read the SPI_RDR as that clears the RDRF flag.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-05 10:29:52 -04:00
Kevin O'Connor 0dbfa915de adccmds: Add support for min/max temperature check filtering
Extend the ADC out of range check so that it is possible to sample
multiple times before going into a shutdown state.  This reduces the
chance that measurement noise will cause an error.  In an actual over
temperature (or under temperature event) it is expected that the
sensor will consistently report the problem, so extra checks for an
additional second or two should not substantially increase risk.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-07-02 13:56:34 -04:00
Kevin O'Connor 38d7b9ada0 buttons: Add initial support for detecting button presses
Add mcu support for periodically polling for a button press.  Add host
code support for registering buttons and invoking callbacks for them.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-06-30 14:28:51 -04:00
Kevin O'Connor d725160706 mcp4451: Add initial support for programming the mcp4451 on lpc176x
Add support for programming smoothieboard current.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-06-29 21:20:12 -04:00
Kevin O'Connor efb27f095c build: Cleanup whitespace errors
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-06-28 13:00:20 -04:00
Grigori Goronzy 6078145dcd stm32f1: fix ADC pin list
For some reason, the upper two pin definitions were missing. Found while
writing the port documentation.

Signed-off-by: Grigori Goronzy <greg@chown.ath.cx>
2018-06-27 18:22:06 -04:00
Kevin O'Connor 06ef60011e gpiocmds: Add update_digital_out command
Add a command that can immediately set the value of a digital output
pin created with config_digital_out.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-06-27 12:10:39 -04:00
Kevin O'Connor 7aec52dfb3 avr: Don't set SS high on spi_init()
The AVR requires that the SS pin be an output pin for correct SPI
operation.  Some boards use the SS pin to control devices separate
from SPI, however.  Don't change the output level if the pin is
already an output, and prefer setting it low if it is not already an
output pin.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-06-27 12:10:25 -04:00
Kevin O'Connor d651851567 pru: Disable ADC reading directly from the PRU
The PRU code size has grown too close to the maximum - remove the ADC
code to reduce its overall size.  (On the beaglebone, the Linux
process can, and typically does, do the ADC reading.)

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-06-27 12:10:25 -04:00
Kevin O'Connor f08a0c5e93 lcd_st7920: Use a longer delay at the start of each command/data
It appears the st7920 requires a longer delay when switching from
command to data mode (and vice-versa).  Slower MCUs don't show a
problem because the klipper command processing time results in a
sufficient delay.  However, some of the faster MCUs can process
klipper commands fast enough that the next st7920 transfer is sent too
fast.  Add an additional delay to account for this.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-06-22 23:47:09 -04:00
Kevin O'Connor 4fbecfa1fc lpc176x: Build with LCD support
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-06-18 12:46:08 -04:00
Kevin O'Connor b93fd5b1b5 basecmd: Rename get_status to get_clock
Change the get_status command to get_clock.  Don't report the shutdown
status in the new get_clock command.

The primary purpose of this change is to force the host code to report
a firmware version mismatch with older firmwares as recent changes
(namely the ordering of message block acks) have subtle
incompatibilities if different host/mcu code is used.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-29 10:57:29 -04:00
Kevin O'Connor 879c45db19 mcu: Do not automatically restart MCU with new config if it is shutdown
Normally, the MCU is restarted on a config change.  However, that
should not be done automatically if the MCU is in a shutdown state.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-29 10:57:29 -04:00
Kevin O'Connor d798fae20b serialqueue: Limit message transmission to available receive buffer size
If the mcu is using a traditional serial port, then only send a new
message block if there is space available in the mcu receive buffer.
This should make it significantly less likely that high load on the
mcu will result in retransmits.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-28 11:12:30 -04:00
Kevin O'Connor 75f8709947 command: Wait to send ack until after processing commands
Send the ack after processing commands - this gives the host code more
information on serial buffer utilization.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-28 10:43:40 -04:00
Kevin O'Connor 528f9f7604 command: Add command_find_and_dispatch() helper
Add a helper function that calls command_find_block() followed by
command_dispatch().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-28 10:43:39 -04:00
Kevin O'Connor c8af3feee6 command: Add a command_encode_and_frame() helper
Add a helper function that calls command_encodef() followed by
command_add_frame().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-28 10:43:39 -04:00
Kevin O'Connor cb4e165071 command: Prefer uint8_t* for buffers; prefer uint8_fast_t for lengths
Prefer using 'uint8_t' buffers as it is too easy to run into C sign
extension problems with 'char' buffers.  Prefer using 'uint_fast8_t'
for buffer lengths as gcc does a better job compiling them on 32bit
mcus.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-28 10:43:39 -04:00
Kevin O'Connor 2994638380 lpc176x: Add a dummy "make flash" command to advise users on how to flash
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-25 11:58:23 -04:00
Kevin O'Connor 4344f7fc10 lpc176x: Add build rules for smoothieware bootloader support
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-25 11:52:13 -04:00
Kevin O'Connor c381d03aad lpc176x: Initial support for serial over usb
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-25 11:52:13 -04:00
Kevin O'Connor c812a40a37 lpc176x: Add ADC support
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-25 11:52:13 -04:00
Kevin O'Connor 65613aeddf lpc176x: Enable watchdog
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-25 11:52:13 -04:00
Kevin O'Connor c78b90767f lpc176x: Add support for GPIO pins
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-25 11:52:13 -04:00
Kevin O'Connor 970831ee0d lpc176x: Add initial support for LPC176x processors
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-25 11:52:13 -04:00
Kevin O'Connor c2d48aba87 byteorder: Add a header file defining common byteswap functions
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-21 09:44:40 -04:00
Kevin O'Connor 70068985a7 stepper: Introduce and use gpio_out_toggle_noirq()
The gpio_out_toggle() function in the sam3x8e and stm32f1 code was
only valid if it was called with irqs disabled.

Commits 018c5daa and 9c52ad43 enabled the lcd code which called
gpio_out_toggle() with irqs enabled.  This could cause corruption of
the gpio state.

Introduce a gpio_out_toggle_noirq() function that will only be invoked
with irqs disabled, and fix gpio_out_toggle() on sam3x8e and stm32f1
so that it safe to call even if irqs are enabled.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-15 17:09:11 -04:00
Kevin O'Connor f70fefa06f linux: Convert linux SPI code to use the generic spicmds.c code
Use the generic spi send/receive code on Linux.  Update the replicape
code to use the updated command format.

Also, update the replicape code to turn off the stepper motors on a
shutdown event.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-07 09:10:34 -04:00
Kevin O'Connor 31ae74c56c sam3x8e: Add SPI support
Signed-off-by: Petri Honkala <cruwaller@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-07 09:10:34 -04:00
Kevin O'Connor 22487d95e9 spicmds: Rework SPI message transmission
Improve the SPI message transmit system.  Add support for bus speed
and bus mode.  Add support for sending SPI messages on shutdown.

Signed-off-by: Petri Honkala <cruwaller@gmail.com>
Signed-off-by: Douglas Hammond <wizhippo@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-07 09:10:34 -04:00
Kevin O'Connor 9c52ad4310 stm32f1: Enable lcd chip support
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-07 01:03:25 -04:00
Kevin O'Connor 018c5daa94 sam3x8e: Enable lcd chip support
Testing shows the hd44780 and st7920 chips do work on the Due.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-05-07 01:03:01 -04:00
Kevin O'Connor 4a8f9407b8 avr: Do not use Idle mode
The AVR chips (bizarrely) start an ADC conversion when entering Idle
mode.  This behavior can cause the ADC to be busy when a sample is
required.  Worse, if a series of events cause the cpu to enter and
leave Idle mode with a timing similar to the ADC checking rate then it
can cause the ADC to show as busy for extended periods.  This could
cause high MCU load and possibly lead to a "Rescheduled timer in the
past" shutdown.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-04-28 21:26:42 -04:00
Kevin O'Connor 46cf3ef145 avr: Explicitly set ADCSRA on each conversion start
Don't logically or the ADSC bit on the start of a conversion -
explicitly set the full contents of the register.  Also, clear the
ADIF flag on each write.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-04-25 19:13:44 -04:00
Kevin O'Connor cf475a9a39 avr: Clean up serial port register aliases
Define unique register aliases for all of the hardware serial port
definitions.  This makes it easier to deal with the AVR chips that use
different register names.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-04-25 10:55:18 -04:00
Kevin O'Connor 6793970198 serial_irq: Add new generic/serial_irq.c code
Extract out common code from avr/serial.c, sam3x8e/serial.c, and
stm32f1/serial.c into a new generic/serial_irq.c file.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-04-20 11:19:37 -04:00
Kevin O'Connor add370230f stm32f1: Use generic timer_irq.c dispatch code
With the optimized timer_read_time() it is no longer necessary to
implement custom timer dispatch code - use the generic mechanism in
timer_irq.c.  This simplifies the code and provides a small
performance increase.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-04-20 11:19:37 -04:00
Kevin O'Connor 2bf9e27b9e stm32f1: Use different method for handling 16bit -> 32bit timer conversion
Implement 32bit timer conversion without disabling interrupts.  This
uses the 16th bit of timer_high as a rollover detection flag.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-04-20 11:19:37 -04:00
Kevin O'Connor 06a4753f73 stm32f1: Prefer uint32_t over uint16_t in timer.c
The ARM architecture handles 32bit values faster than 16bit values -
use uint32_t where possible.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-04-20 11:19:37 -04:00
Grigori Goronzy 75d5737211 Add STM32F103 port
Add a fully functional STM32F1 port, currently mostly targeting STM32F103
microcontrollers. This requires an 8 MHz XTAL. The maximum possible step rate
is around 282K steps per second.

This uses stm32flash to burn the firmware. The bootloader needs to be started
by setting BOOT0 to 1 and resetting the MCU. There is no automatic bootloader,
unlike on Arduino.

Signed-off-by: Grigori Goronzy <greg@kinoho.net>
2018-04-09 18:08:29 -04:00
Kevin O'Connor afc9bcf27b lcd_hd44780: Add micro-controller code for the HD44780 LCD chip
Add support for passing messages to an HD44780 chip via a 4-bit
bit-banging interface.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-06 11:30:34 -05:00
Kevin O'Connor 9140f36d99 lcd_st7920: Add micro-controller code for the ST7920 LCD chip
Add support for passing messages to an ST7920 chip via a SPI
bit-banging interface.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-03-06 11:30:30 -05:00
Douglas Hammond d139389267 avr: Add at90usb646 support
Signed-off-by: Douglas Hammond wizhippo@gmail.com
2018-02-25 10:23:00 -05:00
Kevin O'Connor b7b216af7f avr: Round hardware pwm clock ticks to nearest divisor
Instead of rounding down to the nearest supported pwm divisor, round
to the nearest divisor.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-29 11:54:15 -05:00
Kevin O'Connor d891baa860 avr: Clear the TCNT1 register on timer startup
Just to be safe, clear the TCNT1 register during init.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-07 22:22:08 -05:00
Kevin O'Connor f6cd51bfb7 avr: Clear the ADCSRA/ADCSRB registers on ADC init
When initializing the ADC, explicitly clear the registers (instead of
logically or'ing them with their previous values).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-07 22:13:39 -05:00
Kevin O'Connor 5a86391f78 avr: Only use the avrdude "wiring" protocol on atmega2560 devices
It appears the most common type of avrdude protocol for devices other
than the atmega2560 is the "arduino" protocol.  Update the build to
select a different protocol based on the avr processor type.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2018-01-05 10:02:15 -05:00
Kevin O'Connor d303e556ad sched: Interrupts must be disabled during setjmp() call
On the AVR platform (and possibly others) the longjmp() call will
restore the interrupt state saved during the setjmp() call.  So, the
setjmp() call must be invoked with interrupts disabled to ensure that
shutdown handling is run with interrupts disabled.  This fixes
potential corruption of the shutdown processing on AVR.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-21 12:54:33 -05:00
Kevin O'Connor 57c27f75ae gpiocmds: Clear SPF_NEXT_* flags on new schedule_soft_pwm_out
Properly handle the (unlikely) case that a schedule_soft_pwm_out
command is received before a previous command is fully processed,

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-16 20:21:38 -05:00
Kevin O'Connor 319221ee23 docs: Provide additional information on "make flash" failures
Add some additional information on "make flash" problems.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-12-11 17:33:29 -05:00
Kevin O'Connor 03e97c2d95 linux: Remove unneeded includes from timer.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-23 22:20:53 -04:00
Kevin O'Connor 75ba375b8a pru: Don't reset the ADC reset complete flag if a shutdown occurs
Only set the have_done_reset flag if the reset completes successfully.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-18 13:05:36 -04:00
Kevin O'Connor cbd06f1433 linux: Fix typo causing config_reset to not fully restart
A typo in the code caused the wrong config_reset code to be run.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-15 21:05:08 -04:00
Kevin O'Connor 1c59a0d30a linux: Open watchdog device after console
Only open the watchdog device after the console has been opened.  The
machine should not reboot in the unlikely event the console can't be
opened.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-15 21:05:08 -04:00
Kevin O'Connor d222ec1024 linux: Make sure to close fd on analog/pca9685 init failure
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-14 00:22:21 -04:00
Kevin O'Connor 674f584190 pca9685: Fix missing devices_count increment
The devices_count was not being incremented on each device add.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-13 22:05:19 -04:00
Kevin O'Connor 3c4d14bfa9 pca9685: Support default values
Allow the pwm pin to have a non-zero default value.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor db97f36631 gpiocmds: Allow the start value for a pin to differ from the default_value
Allow the start value to be different from the default/shutdown value
for the pin.  This will be useful for "heater fans" that should
startup in the off state, and transition to full on in a shutdown
state.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor d03cf2b83f adccmds: Continue to query analog inputs after a shutdown
Continue to sample the ADC input pins even if the MCU goes into a
shutdown state.  This enables the printer to continue reporting
temperatures even on an mcu error.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor 744c6d114e sched: Don't shutdown on a "timer in the past" if already shutdown
A shutdown will not help if the mcu is already in a shutdown state.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor 3b9b4e4d6f endstop: Eliminate end_stop_set_oversample command
Pass the sample_ticks and sample_count parameters directly in the
end_stop_home command instead.  This simplifies the code.

Also, simplify calculation of next wakeup time in
end_stop_oversample_event().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-12 11:59:27 -04:00
Kevin O'Connor fb0f344346 avr: Add support for atmega1284p
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-05 13:51:05 -04:00
Kevin O'Connor eaeb831107 endstop: Fix typo in comment
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-02 11:00:23 -04:00
Kevin O'Connor ece1f71c64 endstop: Support oversampling of the endstop
Some printers can show occasional noise on the endstop pin.  Support
sampling the endstop pin multiple times to attempt to filter out this
noise.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-10-01 19:15:55 -04:00
Kevin O'Connor 5a85c1667a pru: Update installation and flash scripts
Update the scripts used to install and "flash" the pru
micro-controller code.  Also, add a "flash" script for the linux
micro-controller code.  This makes it easier to install Klipper on a
Beaglebone board that uses a Replicape.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor 16d2ec3a90 linux: Add support for analog IIO devices
Add support for reading analog values via the standard Linux IIO
interface.  This can be used on Replicape boards to sample analog
input pins.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor 4d60567bc6 linux: Add support for spidev devices
Add support for sending SPI messages to devices via the standard Linux
SPI interface.  This can be used to configure the shift registers on
Replicape boards.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor 73a1c9d249 linux: Add support for pca9685 i2c pwm devices
Add support for controlling pca9685 PWM drivers using the standard
Linux I2C interface.  The pca9685 device is found on Replicape boards.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor d851882278 linux: Initial support for running Klipper in a Linux real-time process
Add support for compiling the Klipper micro-controller code as a
real-time process capable of running on standard Linux systems.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-20 12:55:28 -04:00
Kevin O'Connor 2a6a9eb52f pru: Avoid calling "slp" instruction on pru0
If pru0 waits in sleep mode then a full beaglebone reboot is needed to
reprogram the pru0 firmware.  For now, avoid using the "slp"
instruction as a workaround.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-11 13:12:18 -04:00
Kevin O'Connor d618affd63 pru: Batch outgoing writes
Allow pru0 to gather multiple outgoing message blocks into a single
rpmsg.  This can reduce communication overhead.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-08 11:50:21 -04:00
Kevin O'Connor 121c747cc8 pru: Fix race condition in clearing of irq flags
Each irq flag must only be cleared after it has been serviced.  This
fixes a race condition that could cause incoming commands to be
delayed for extended period.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-08 11:50:21 -04:00
Kevin O'Connor 09e32d1b84 mcu: Provide some further help on common MCU shutdown errors
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-05 22:12:15 -04:00
Kevin O'Connor 68fc6abf74 avr: Check that FLASH_DEVICE is set on "make flash" command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-05 22:12:15 -04:00
Kevin O'Connor 7083a33ecd pru: Support config_reset command to manually reset mcu
Add support for resetting the MCU via a software only mechanism.  This
is useful on the PRU.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-03 23:16:38 -04:00
Kevin O'Connor 7b7f57e01c pru: Only sleep the pru0 if the incoming queue is fully empty
It's possible for multiple blocks to be pending on the incoming
"rpmsg" stream.  Don't sleep unless the input is confirmed to be
empty.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-09-03 23:15:49 -04:00
Kevin O'Connor 0adea120cd pru: Compile the irq_poll() function with -O2 optimization
Compile the PRU binary with -Os optimization, but request that the
timer dispatch code be compiled with -O2 optimization.  This improves
the performance of timers slightly.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-15 11:05:30 -04:00
Kevin O'Connor 71bb7acb8e pru: Compile with -Os instead of -O2
The gcc -Os option significantly reduces the size of the PRU binary
and it has little impact on performance.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-14 21:08:28 -04:00
Kevin O'Connor f8bd8b97be command: Don't pass max_size to command_encodef()
The command_encodef() can read the max_size parameter directly from
the 'struct command_encoder' passed into it.  Also, there is no need
to check that a message will fit in a buffer if the buffer is declared
to be MESSAGE_MAX in size.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-14 18:32:15 -04:00
Kevin O'Connor f3da473285 docs: Update Code_Overview.md with PRU and command_dispatch() changes
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-11 12:06:19 -04:00
Kevin O'Connor d8225642fa stepper: Revert f8b0c884
Go back to scheduling the unstep time instead of busy waiting in the
timer dispatch.  With the unstep time increased to 2us, it no longer
makes sense to spin while waiting for the unstep.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-11 10:36:02 -04:00
Kevin O'Connor 8ebba6d27a avr: Make sure timer_high and timer_event() stay in sync
Schedule the next wakeup time of timer_event() using timer_high.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-11 09:32:06 -04:00
Kevin O'Connor 1051a52755 timer_irq: Rework timer irq handler to check for tasks pending
Allow timer_dispatch_many() to run for extended periods if there are
no tasks pending.  This reduces the amount of lost cpu time spent
entering and exiting the irq handler.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-09 21:08:40 -04:00
Kevin O'Connor a38082016d sched: Reduce the amount of time irqs are disabled in sleep check
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-09 12:55:44 -04:00
Kevin O'Connor 156e9b7556 sched: Write out a message on startup
Send a "startup" message after completing the mcu init functions.
This may help detect mcu reboots during debugging.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor f886212b44 avr: Rework timer irq handler to check for tasks pending
Allow the timer dispatch irq handler to run for extended periods if
there are no tasks pending.  This reduces the amount of lost cpu time
spent entering and exiting the irq handler.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor 2c272f99a3 sched: Implement generic sleep mechanism based on tasks pending
Track when tasks are pending and spin in irq_wait() when no tasks are
pending.  This improves the mechanism for sleeping the processor -
it's simpler for the board specific code and it reduces the
possibility of the processor sleeping when tasks are busy.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor a9982beacf sched: Introduce sched_wake_tasks() function to wake up tasks
Add function to indicate when tasks need to be run.  This will allow
the scheduler code to know if there are any tasks that need to be
processed.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor e9d2ec7c41 avr: Tune the low-level timer entry and exit heuristics
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor 78982ebb51 avr: Implement internal avr specific timer to handle 16bit overflows
Don't rely on the generic scheduler code to always have a timer no
more than 1ms in the future.  Instead, create an avr specific timer
that will be called every 0x8000 ticks.  This simplifies the generic
code and it reduces the amount of code that needs to be run every
millisecond.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:28 -04:00
Kevin O'Connor 6a63c27542 sched: Support adding timers to the start of timer_list
If sched_add_timer() is called on a timer that would make it the new
head of the list, then add it and signal the board code that the timer
should be rescheduled.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:27 -04:00
Kevin O'Connor 62f77f6bc5 sched: Don't count milliseconds in the periodic timer
It's not necessary to keep a millisecond counter.  Replace the two
users of sched_check_periodic() with explicit task wakeup flags.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:27 -04:00
Kevin O'Connor 88a10fb31c sam3x8e: Fix watchdog timeout calculation
Fix error causing the watchdog to be set to an ~4ms timeout instead of
500ms.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-08 00:27:27 -04:00
Kevin O'Connor e12527b895 avr: Move prescaler and sleep initialization from timer.c to main.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-07 19:39:57 -04:00
Kevin O'Connor 114c8c5b6d avr: Enable watchdog code even on simulavr
The simulavr simulator will warn when writing to the watchdog
registers, but running code closer to what real hardware runs is worth
a few extra warnings.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-07 19:39:57 -04:00
Kevin O'Connor d50f4e23e0 pwmcmds: Update event prototypes to use uint_fast8_t
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-06 20:24:22 -04:00
Kevin O'Connor dca0fc91ea pru: Improve comments in pru0.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-08-02 11:02:45 -04:00
Kevin O'Connor 4a6254fac3 build: Allow boards to disable digital input/output support
Allow the micro-controller code to be built without support for
regular gpio pins.  In this case, the code for endstops, steppers, and
gpiocmds will be disabled.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-20 10:44:31 -04:00
Kevin O'Connor 649d26e093 basecmd: Move low-level alloc code into basecmd.c
Implement new dynmem_start() and dynmem_end() functions instead of
alloc_chunk() and alloc_chunks() in the board code.  This simplifies
the board code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-20 10:44:31 -04:00
Kevin O'Connor 118fd21cb8 irq: Support sleeping when mcu is idle
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-17 15:02:43 -04:00
Kevin O'Connor 3ac60b31a2 pru: Move peripheral init from pru0 to pru1
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-17 11:16:55 -04:00
Kevin O'Connor c105ff1c51 pru: Move ADC code from gpio.c to new file adc.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-12 23:03:14 -04:00
Kevin O'Connor ae9bc93ccc avr: Fix readl() typo in serial.c
The code should have used a readb() call instead of readl().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-12 23:03:12 -04:00
Kevin O'Connor b32ba3727b pru: Add support for "make flash" rule
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-05 12:50:54 -04:00
Kevin O'Connor 09140a51d5 sched: Pass shutdown reason code via longjmp() parameter
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-07-04 12:49:58 -04:00
Kevin O'Connor c8dca0a56c pru: Use a pointer when working with send_data array items
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-30 19:54:40 -04:00
Kevin O'Connor da3569c490 pru: Add hack to shutdown the PRU from a simple command request
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-30 19:54:33 -04:00
Kevin O'Connor e8356afa26 pru: Rework command processing so that most of it is done on pru0
Change the command dispatch and response generation so that most of
the work is done on pru0 instead of pru1.  This allows more code to
fit into the limited space on pru1.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-30 19:53:04 -04:00
Kevin O'Connor c1bd628ce5 command: Directly call command_sendf() for ack/nak messages
Don't use the sendf() macro for ack and nak messages - directly call
the command_sendf() code instead.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:59 -04:00
Kevin O'Connor 849096d5f3 sam3x8e: Integrate serial console functions
Now that console_get_input(), console_pop_input(),
console_get_output() and console_push_output() are local functions,
integrate them into their callers.  This simplifies the code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:59 -04:00
Kevin O'Connor e681369a1a avr: Integrate usb serial console functions
Now that console_get_input(), console_pop_input(),
console_get_output() and console_push_output() are local functions,
integrate them into their callers.  This simplifies the code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:59 -04:00
Kevin O'Connor faa29c8062 avr: Integrate serial console functions
Now that console_get_input(), console_pop_input(),
console_get_output() and console_push_output() are local functions,
integrate them into their callers.  This simplifies the code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:58 -04:00
Kevin O'Connor 44f2a2a952 command: Move low-level sendf transmission into board code
Export a new console_sendf() function from the board code instead of
console_get_output() and console_push_output().  This enables more
flexibility in how the board specific code produces output.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:58 -04:00
Kevin O'Connor 292453d306 command: Move command_task() to board specific code
Move the command_task() code from the generic code to the board
specific code.  This enables more flexibility in how the board
specific code processes input.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:58 -04:00
Kevin O'Connor 1ae78d08e9 command: Encode MESSAGE_MIN in command_parser->max_size
Add the message minimum into the stored constant so it does not need
to be added at run-time.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:58 -04:00
Kevin O'Connor 1c3cbe9456 command: Refactor message block generation
Separate out the buffer management, message encoding, and message
framing code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:58 -04:00
Kevin O'Connor 88f4c38dca command: Refactor the command reading task
Refactor the code so that message block framing, command parsing, and
command dispatch are distinct.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-29 13:33:58 -04:00
Kevin O'Connor b310501970 sam3x8e: Use readl/writel instead of readb/writeb() in serial.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-22 10:51:49 -04:00
Kevin O'Connor bd48c3a083 pru: Remove unnecessary barrier() calls
The writel() call already implements a barrier() internally.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-16 14:26:37 -04:00
Kevin O'Connor c60e4aceed stepper: Increase the step delay time from 1us to 2us
Increase the step delay time so that it works with the common DRV8825
stepper drivers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-13 11:53:10 -04:00
Kevin O'Connor 46846d4297 avr: Enable CLEAR_PRESCALER by default on at90usb1286
It appears this option is commonly needed on the at90usb1286 avr chip
(the printrboard requires it), so default it on.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-09 18:42:40 -04:00
Kevin O'Connor b8094de129 avr: Support using serial instead of usb on AT90USB1286
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-06-05 12:30:49 -04:00
Kevin O'Connor 73207a12ba avr: Allow atmega328 to select a cpu speed of 20Mhz
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-29 14:24:18 -04:00
Kevin O'Connor 3af87e1c42 avr: Add SIMULAVR build option; don't show WATCHDOG or SERIAL_BAUD_U2X
Add a CONFIG_SIMULAVR option to the Kbuild menus and don't directly
prompt users for CONFIG_WATCHDOG or CONFIG_SERIAL_BAUD_U2X.  The only
reason to disable these options would be if one were running on
simulavr.  This simplifies the user visible menu options.

Also, only show CONFIG_CLEAR_PRESCALER for at90usb1286 chips.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-28 11:04:59 -04:00
Kevin O'Connor d2547ce6b0 avr: Add support for atmega328 chip
The atmega328 is basically the same as the atmega168 - it just adds
some additional memory.  Allow the chip to be selected during the
build.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-28 10:45:32 -04:00
Kevin O'Connor 7e3d7e071f avr: Reorder Kconfig entries so that atmega2560 at 16mhz is default
Reorder the MCU list so that newer chips are at the top of the list.
This causes the very popular atmega2560 to be the default chip
selected.

Reorder the frequency list so that higher frequencies are at the top
of the list.  Restrict the 20Mhz frequency to only chips that support
that speed.  This causes the popular 16Mhz frequency to be the default
speed on AVR.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-28 09:59:51 -04:00
Kevin O'Connor d4bed025ed command: Store the command parsing information directly in array
Instead of defining an array of pointers, just define the array
directly.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-26 13:25:51 -04:00
Kevin O'Connor a82e949c00 build: Use compile_time_request system for init, tasks, and shutdown
Avoid using linker magic to define the init, task, and shutdown
functions.  Instead, use the compile_time_request system.  This
simplifies the build and produces more efficient code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-26 12:39:34 -04:00
Kevin O'Connor ca9756413f sched: Allow shutdown_reason to be uint8
Store the shutdown_reason code in an 8-bit integer - this produces
better code on AVR.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-26 12:32:05 -04:00
Kevin O'Connor b9940f0e0d build: Avoid linker magic in compile_time_request.c unique id generation
Avoid generating unique ids via memory locations and linker scripts.
Instead, generate them using code produced by buildcommands.py.
Utilize gcc's ability to perform static string comparisons at compile
time to produce a unique id for each unique string.

This fixes a build failure on ARM introduced in 142b92b8.  It also
reduces the complexity of the build.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-26 12:32:02 -04:00
Kevin O'Connor c9b6662138 pru: Add support for ADC input
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-17 19:46:12 -04:00
Kevin O'Connor b85755c0ff pru: Move communication code to second PRU
Perform input and output in the second PRU so that more space is
available in the primary PRU.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-17 10:46:38 -04:00
Kevin O'Connor 2255176228 pru: Initial support for the Beaglebone PRU
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 15:15:52 -04:00
Kevin O'Connor 969ee4c8f9 irq: Add an irq_poll() stub for board code
Allow the board specific code to run checks prior to running each
task.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 15:00:45 -04:00
Kevin O'Connor c35278e217 build: Avoid using noinline in common code
It's not necessary to use noinline for parsef() and stop_steppers().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:59 -04:00
Kevin O'Connor 039d3f0523 stepper: It is not necessary to ensure gpio_out_write value is 0 or 1
The gpio_out_write() and gpio_out_setup() calls will check for zero
and non-zero, so it is not necessary to explicitly convert to 0/1 in
the stepper.c code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:59 -04:00
Kevin O'Connor d56f8407a5 debugcmds: Move debugging commands from basecmd.c to new file
Move the implementation of debug commands to their own file.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:59 -04:00
Kevin O'Connor 142b92b883 command: Use "i" instead of "m" constraint in _DECL_REQUEST_ID
On some architectures, gcc will allocate a register for inline
assembler with an "m" constraint.  Use "i" to avoid that.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:59 -04:00
Kevin O'Connor c292006421 gpiocmds: Change MAX_SOFT_PWM from 255 to 256
Change the range of values used for software PWM to avoid doing an
integer division in the main code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:59 -04:00
Kevin O'Connor 5c4cc0d646 pwmcmds: Export the maximum PWM value
Instead of assuming the maximum PWM value is 255, export a constant
from the firmware to the host with the maximum value.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:59 -04:00
Kevin O'Connor a361b92184 gpio: Fix off-by-one in declaration of ADC_MAX
The maximum value for the ADC is 1023 for 10bit samples and 4095 for
12bit samples.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:59 -04:00
Kevin O'Connor 37572bc217 command: Only implement 16bit signed conversion on AVR
On regular 32bit machines there is no need to implement explicit
signed conversion on 16bit integers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:02:04 -04:00
Kevin O'Connor 450c14b286 build: Rename makefile CFLAGS-y to CFLAGS and LDFLAGS-y to CFLAGS_klipper.elf
Rename some makefile variables.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-15 14:01:56 -04:00
Kevin O'Connor 33dfc386c9 avr: Merge misc.c into main.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-11 13:56:21 -04:00
Kevin O'Connor f331936969 basecmd: Avoid calling malloc() from main code
Introduce a new board function alloc_chunk() to allocate dynamic
memory.  This allows the board code to implement memory allocations
without using the standard malloc() interface.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-05-11 13:56:21 -04:00
Kevin O'Connor 1878da228d build: Add workaround to suppress broken avr-gcc "misspelled" warnings
Detect avr gcc v4.8.1 and then disable warnings during the klipper.o
linking to suppress bogus "misspelled signal handler" warnings.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-04-24 08:54:10 -04:00
Kevin O'Connor 37865d69a2 basecmd: Add debugging commands for testing communication
Add "debug_ping" and "debug_nop" testing commands.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-04-23 13:37:49 -04:00
Kevin O'Connor 83eba902a3 build: Support makefile rule with default flashing commands
Support a "make flash FLASH_DEVICE=/dev/ttyACM0" rule with the default
commands for flashing a device.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-04-21 11:01:07 -04:00
Kevin O'Connor 7a7b98cc31 sam3x8e: Rework adc pin search to be more clear
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-04-11 10:01:22 -04:00
Kevin O'Connor 15d5837322 avr: Rework adc and pwm pin search to be more clear
Rework the pin search loop.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-04-11 10:01:22 -04:00
Kevin O'Connor f9ebb8b23e avr: Move code around in gpio.c
Move the PWM, ADC, and SPI pin tables closer to their corresponding
code.  This is code movement only - no code changes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-04-11 10:00:54 -04:00
Kevin O'Connor 77b94451de avr: Fix irqstatus_t typo in gpio_pwm_setup
The flags and cs variables should be uint8_t not irqstatus_t.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-04-11 09:49:35 -04:00
Kevin O'Connor 57f279677f endstop: Support halting more than one stepper on trigger
Extend the endstop code so that more than one stepper can be halted
during endstop homing.  Some kinematic setups (eg, corexy) require an
endstop to support this.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-04-03 17:27:10 -04:00
Kevin O'Connor fff73c7735 avr: Invert diff in timer checks
Minor optimization on avr.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-04-03 10:39:49 -04:00
Kevin O'Connor e44678ceba avr: Implement reset command
Support restarting the mcu using the watchdog feature of AVR chips via
a new reset command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-04-02 23:19:29 -04:00
Kevin O'Connor 85c0e9c574 sam3x8e: Implement reset command
Support restarting the mcu via a new reset command.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-04-02 23:19:25 -04:00
Kevin O'Connor 0c3ec7f9a5 avr: Do not use --relax linker option
The relax option corrupts the compilation on at least some versions of
gcc/binutils (eg, on fedora's avr-gcc 6.2.0 / binutils 2.27) due to
corruption of switch tables that use jump offsets.  This issue is also
the root cause that resulted in commit d67f962a.  Since the --relax
option provides minimal size / performance improvements it can simply
be dropped.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-04-02 23:19:19 -04:00
Kevin O'Connor 7c991399ac timer: Remove dup timer_shutdown code
Commmit a1c61563 renamed timer_shutdown() to timer_reset() but
neglected to delete timer_shutdown().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-31 19:20:45 -04:00
Kevin O'Connor a1c61563a0 avr: Fix bug causing timer_read_time() to not be in sync with scheduler
Commit 16e3dbb1 changed the avr implementation of timer_read_time().
Unfortunately, it raised the possibility for timer_read_time() to be
out of sync with the scheduler's understanding of the current time.
In particular, it was common for the timer irq to overflow the 16bit
hardware counter once at startup, and this would lead to
timer_read_time() always returning a time ~4ms ahead of the scheduler
on 16Mhz chips.  This resulted in "Move queue empty" errors.

To resolve this issue, only increment timer_high from timer_periodic()
and make sure the timer irqs start immediately after timer_init().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-31 14:36:57 -04:00
Kevin O'Connor 63b6bab5c3 sam3x8e: Align the TC0_Handler timer irq handler
The code alignment of the TC0_Handler function seems to noticeably
impact performance benchmarks.  Set the function alignment to 16 bytes
to improve testing consistency.  An alignment of 16 doesn't
necessarily improve performance, but it seems to improve testing
consistency on code changes unrelated to timer dispatch.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-30 12:04:08 -04:00
Kevin O'Connor eb4eeb6f73 timer_irq: Integrate timer_try_set_next() into timer_dispatch_many()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-30 11:25:23 -04:00
Kevin O'Connor 6988507998 timer_irq: Rename generic/timer.c to generic/timer_irq.c
Rename the file to make it clear that the code is helper functions for
boards with irq based timers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-30 11:24:44 -04:00
Kevin O'Connor 65be6d5146 avr: Integrate timer_try_set_next() into the irq handler
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-30 11:24:44 -04:00
Kevin O'Connor 6d05dd07f5 sched: Move timer dispatch loop to board code
Rename sched_timer_kick() to sched_timer_dispatch() and move its loop
into its callers in the board code.  This eliminates the need to
export timer_try_set_next() from the board code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-30 11:24:42 -04:00
Kevin O'Connor 7436ec093a sched: Rename reschedule_timer() to insert_timer() and use in sched_add_timer()
Use the same code in both rescheduling of a timer and adding a new
timer.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-30 10:57:35 -04:00
Kevin O'Connor 2b735daae5 timer: Make sure to reset the timer repeat checks on a shutdown
Reset the timer repeat checks on shutdown, otherwise it is possible to
get into an infinite shutdown loop.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-30 10:57:35 -04:00
Kevin O'Connor f8b0c884b0 stepper: Improve performance of scheduled unsteps
On faster MCUs where a delay is needed between step and unstep use a
"busy loop" in the scheduler instead of trying to schedule to the
unstep time.  This reduces the chance of jitter in the scheduler
accumulating.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-30 10:57:35 -04:00
Kevin O'Connor 18f4d343f5 avr: Remove F_CPU compile time definition
Directly use the Kconfig defined CONFIG_CLOCK_FREQ in the code and
avoid defining F_CPU.  Also, remove the unnecessary O2 option - that
is already the default from the main makefile.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-30 10:56:17 -04:00
Kevin O'Connor 31e78c90e2 avr: Minor optimization for timer_read_time() / timer_periodic()
Tell the compiler that the TOV1 bit is rarely set.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-27 13:37:20 -04:00
Kevin O'Connor 59b71d5d05 sched: Be explicit with loading of the waketime variable
Explicilty load the timer waketime variable into local variables in
sched_timer_kick().  Change the optimization level from Os to O2.
This helps gcc to avoid unnecessary reloads from memory in the common
stepper_event() case.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-26 22:45:58 -04:00
Kevin O'Connor 4dfa6c6ee4 avr: Introduce optimized timer_is_before()
Provide hand-coded assembler for timer_is_before() on AVR as that code
is used frequently in the time-critical timer dispatch loop and gcc
doesn't do a good job at compiling that comparison code.  Remove the
no longer needed waketime+1 hack from reschedule_timer().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-26 22:45:58 -04:00
Kevin O'Connor 60e488eb17 timer: Allow board code to define its own timer_is_before implementation
Move sched_is_before() from sched.c to timer_is_before() in the board
specific timer code.  This allows the board code to provide its own
definition.

Also, remove the sched_from_us() and sched_read_time() wrapper
functions and change the callers to directly invoke timer_from_us() /
timer_read_time().

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-26 22:45:58 -04:00
Kevin O'Connor 14340ac4df timer: Organize timer_try_set_next() with priority for repeat timers
Organize the code flow to optimize for repeat timers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-26 22:01:07 -04:00
Kevin O'Connor d67f962a38 command: Simplify sendf() switch
Commit f28eb902 reworked the switch to fix int16 encoding.  However,
at least one version of avr gcc doesn't like that switch layout (it
uses a jump table).  Reorg the switch to avoid that issue.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-26 21:55:24 -04:00
Kevin O'Connor f28eb902df command: Fix encoding of 16bit signed integers
The code wasn't properly sign-extending 16bit integers which caused
int16_t reports in output() to appear as uint16_t.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-24 15:31:26 -04:00
Kevin O'Connor 9702d522a4 sched: Report the time of a shutdown
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-24 15:05:52 -04:00
Kevin O'Connor e5d7e593ec generic: Move generic parts of sam3x8e timer.c to generic directory
Most of sam3x8e/timer.c is going to be platform agnostic for any board
with standard irq handling.  Move the generic code into a new file
generic/timer.c.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-11 12:15:07 -05:00
Kevin O'Connor 69b927bfe9 sched: Move functions within sched.c
Just code movement - no code changes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-11 11:14:06 -05:00
Kevin O'Connor 944d176856 sched: Rename sched_timer() to sched_add_timer()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-11 11:14:06 -05:00
Kevin O'Connor cdd5a772e8 sched: Don't overwrite shutdown reason if shutdown called while shutdown
If a shutdown occurs while the machine is already shutdown, then keep
the original shutdown reason code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-10 23:24:20 -05:00
Kevin O'Connor 0a3c23bcf6 sched: Avoid rescheduling the currently active timer
It's tricky to reschedule the timer irq correctly (due to race
conditions with the irq) and in practice it's very rarely needed.
Handle the special cases in the generic sched.c code so that the board
code doesn't have to handle it.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-10 23:24:15 -05:00
Kevin O'Connor cb286ede9d sched: Use a sentinel timer at the end of the timer_list
Introduce a dummy sentinel timer object that is always the last item
on timer_list.  This optimizes the timer_list walking code as it no
longer needs to check for NULL when traversing the list.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-10 16:14:49 -05:00
Kevin O'Connor 16e3dbb18c avr: Optimize 16bit timer upscaling
The hardware timer overflow bit can be used to optimize the conversion
from 16bit timers to 32bit timers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-10 13:31:38 -05:00
Kevin O'Connor a38437f378 stepper: Introduce stepper_get_position command and remove from endstop.c
Move the logic to calculate and report the stepper's current position
from endstop.c to stepper.c.  This localizes the stepper code into
stepper.c.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-09 14:54:52 -05:00
Kevin O'Connor 8d6ecd9af8 endstop: No need to store pin_value
The pin_value can be stored in the existing flags variable.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-09 14:50:40 -05:00
Kevin O'Connor 342a7096ea basecmd: Remove unimplemented command_reset()
It's better to not have the unimplemented command defined so that the
host can detect when it is actually implemented.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-09 14:18:24 -05:00
Kevin O'Connor 60a4bda9d4 basecmd: Use oid_ prefix for the oid manipulation functions
Consistently use an "oid_" prefix on the oid functions - this makes
them similar to other functions with a common prefix.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-09 13:49:03 -05:00
Kevin O'Connor 37bac916e7 basecmd: Generalize the "move queue" runtime storage
Detect the maximum size of each "move queue" item during the
configuration phase instead of using the stepper move struct.  This
allows the stepper code to be contained entirely in stepper.c and it
allows for future run time allocations from other types of objects.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-08 13:37:51 -05:00
Kevin O'Connor affdbbf9ca sam3x8e: Fix typo in gpio_in_setup() shutdown message
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-08 13:17:45 -05:00
Kevin O'Connor c19af4fb2b serialhdl: Load the mcu's 64bit clock at start of connection
Store a full 64bit uptime in the mcu and query it at the start of each
connection.  This ensures the host's 64bit clock is always in synch
with the mcu's clock.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-03-03 22:02:27 -05:00
Kevin O'Connor 38e9484f9f armcm_irq: Move ARM Cortex-M irq handling to new file
The irq handling in sam3x8e isn't specific to the sam3x8e proccessor -
it's generic for all armcm type machines.  So, move the definitions
into a new file generic/armcm-irq.c

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-19 11:00:46 -05:00
Kevin O'Connor fec12030a9 sam3x8e/timer: Be careful of races in timer_set_next()
It's possible for sched_del_timer() to be called on a timer that fires
just after sched_del_timer disables irqs but before the next timer is
scheduled.  In this case be sure to clear the irq pending status flag
after scheduling the next timer so that a delayed irq doesn't cause
the wrong timer to be run.  For the same reason, make sure to check
the irq pending status flag at the start of the timer irq.

Also, as a safety check, make sure timer_set_next() isn't called from
within the timer irq dispatch loop.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-14 22:15:51 -05:00
Kevin O'Connor 5beceaae5c io.h: read/write[bwl] should use barrier
Add barrier() calls to low-level read/write io calls so that their
callers don't need to.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-02-02 10:46:42 -05:00
Kevin O'Connor 262ccbcf30 serial: Be careful with comparison of transmit_max to transmit_pos
There is a small possibility that a shutdown could occur between
clearing transmit_max and clearing transmit_pos - so make sure to
handle the case where transmit_pos > transmit_max.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-01-14 12:11:30 -05:00
Kevin O'Connor 7567885115 sched: Minor change - remove unneeded header files
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-01-14 11:32:27 -05:00
Kevin O'Connor ed715ec437 command: No need to disable irqs in sendf reentrant check
As long as the code is careful when writing the in_sendf variable it
should be safe to update it without having to disable irqs.

Also, make sure in_sendf is cleared on shutdown.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-01-14 11:32:27 -05:00
Kevin O'Connor 9a44a20a9d command: Check for reentrant calls to sendf()
Allow sendf() to be called from irq and timer context - check for the
case where sendf() is called while already in sendf() and simply
discard those messages.  This makes it safe to use output() debugging
calls even in irq and timer context.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-01-13 12:10:00 -05:00
Kevin O'Connor 3a7a77d49e basecmd: Improve accuracy of stats "sumsq" variable
Use a base of 256 instead of 65536 when calculating the sum of the
square of the clock differences in the stats.  This makes the
calculation more accurate.  Export the new base via DECL_CONSTANT for
the host to access.  Use DIV_ROUND_UP() when adjusting for the base to
ensure no lost ticks.  Do the division after multiplication in the
common case where the time between stats_task() invocations is less
than 64K ticks.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-01-09 23:08:23 -05:00
Kevin O'Connor f75430e95f gpio: Fix sam38xe ADC startup check
The status register needs to be inspected, not the enable register.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2017-01-01 22:10:24 -05:00
Kevin O'Connor 618fe0e6fb sam3x8e: Add support for ADC pins
Support analog-to-digital inputs.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-23 17:06:11 -05:00
Kevin O'Connor 872b08601a mcu: Obtain the maximum adc value from the firmware
Don't assume the hardware ADC has 10bit resultion - instead have the
firmware define a constant and read that constant in the host.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-23 17:06:10 -05:00
Kevin O'Connor fe95ea221b build: Define DECL_CONSTANT mechanism for defining exported constants
Add a DECL_CONSTANT macro to allow the firmware to define constants
that are to be exported to the host during the "identify" phase.  This
replaces the existing hardcoded mechanism of scanning the Kconfig
header file for certain constants.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-12-23 17:06:10 -05:00
Kevin O'Connor 9ad8153d33 stepper: Reset the next step time on a stepper stop
Automatically reset the next step time to zero on a stepper_stop()
call.  This makes the host code simpler as it no longer needs to
schedule an explicit reset_step_clock command on the step after a
homing operation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-14 13:10:14 -05:00
Kevin O'Connor afecf7ce36 stepper: Default to a high direction pin meaning positive direction
Invert the default meaning of the stepper direction pin.  Instead of
treating a low value as position motion, treat a high value as
positive motion.  This matches what other firmwares do, and it matches
what common stepper motor drivers document.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-08 10:39:32 -05:00
Kevin O'Connor 7c8addc5c5 gpio: Merge gpio_adc_sample_time() into gpio_adc_sample()
Return the number of clock ticks to wait directly from
gpio_adc_sample().  This simplifies the ADC interface.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-11-02 17:36:43 -04:00
Kevin O'Connor 77d486f8d2 sam3x8e: Rework timer priority code to use time instead of event count
Rework the timer prioritization code so that is compares against the
current time instead of the number of repeat timers in a given
interrupt.  This makes the code slightly faster and it should provide
better protection against task starvation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-31 11:48:27 -04:00
Kevin O'Connor 233a90ce8b sam3x8e: Clear all bits of PSR register when clearing IRQ status
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-31 11:47:57 -04:00
Kevin O'Connor 884cee27eb sched: Improve AVR optimization of reschedule_timer()
Tweak the AVR register pressure optimization in reschedule_timer() to
optimize it further.  This improves the performance of AVR timers when
there are several pending timers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-19 13:35:48 -04:00
Kevin O'Connor 0f87493487 timer: Rework AVR timer priority code to use time instead of event count
Rework the timer prioritization code so that is compares against the
current time instead of the number of repeat timers in a given
interrupt.  This makes the code slightly faster and it should provide
better protection against task starvation.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-19 13:35:48 -04:00
Kevin O'Connor 8be8cb7a91 serial: Increase AVR serial receive buffer
Increase the size of the serial receive buffer.  With transmit rates
of 250000 baud, it only takes a little over a millisecond to overflow
the existing buffer.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-10-18 15:01:29 -04:00
Kevin O'Connor c8ff439722 stepper: Disable "no next step" check for some count=1 queue_step commands
It's possible for a "count=1" stepper move immediately after a
set_next_step_dir or reset_step_clock command to be valid and have an
interval less than min_stop_interval.  Make sure this case does not
result in a shutdown.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-09-22 11:15:17 -04:00
Kevin O'Connor b0b2e9c4aa build: Avoid objcopy --dump-section flag
Commit da305e6b changed the objcopy command to use the --dump-section
flag.  However, the 2.24 version of avr-objcopy (which is common on
raspbian installs) does not support this flag.  Avoid using
--dump-section and continue to use the -j option instead.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-07-10 21:46:57 -04:00
Kevin O'Connor cc62a3dbf3 sam3x8e: Add initial support for Arduino Due boards
This adds basic support for running on the Atmel SAM3x8e
micro-controllers that are found in the Arudino Due boards.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-14 14:27:30 -04:00
Kevin O'Connor 6220cdda92 stepper: Support rescheduling of step events on faster MCUs
On faster MCUs the step and unstep events may be too close for the
stepper motor driver.  Add a CONFIG_NO_UNSTEP_DELAY build option and
support the case where it is not set.  This allows faster MCUs to
schedule two events for each step (one for the step and one for the
unstep).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-14 14:24:14 -04:00
Kevin O'Connor da305e6b61 build: Update declfuncs.lds.S to only use progmem sections on AVR
On non-avr platforms the declfunc stuff still needs to be in the
binary in a rodata section.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-14 14:00:57 -04:00
Kevin O'Connor e59951c8ae avr/serial: Separate out low-level hardware manipulation to its own function
Introduce enable_tx_irq() for manipulating the AVR hardware.  This
keeps the low-level hardware code together.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-14 14:00:57 -04:00
Kevin O'Connor ea5f825a91 build: Default to O2 optimization
Default to O2 and set Os in the AVR makefile.  Platforms besides AVR
are likely to produce better code with O2 so make that the default.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-14 14:00:57 -04:00
Kevin O'Connor b3e4ff7ef0 sched: Use 'unsigned int' instead of 'uint16_t' for shutdown reason
Use 'unsigned int' instead of 'uint16_t' as is faster on some
platforms.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-14 14:00:57 -04:00
Kevin O'Connor b0524947e5 sched: Use uint_fast8_t for return type of timers
Some architectures are faster passing regular integers than 8bit
integers.  Use uint_fast8_t so that the architecture chooses the
appropriate type.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-14 14:00:53 -04:00
Kevin O'Connor fa85094cbb irq: Allow boards to define the return type of irq_save()
The AVR wants a uint8_t return type for irq_save(), but other
architectures will generally prefer int.  Allow the board to configure
the size of the flag by introducing an irqstatus_t typedef.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-13 23:18:59 -04:00
Kevin O'Connor 9dd101c26f irq: Prefer irq_disable/enable instead of irq_save/restore in cmds/tasks
Task and command handlers always run with irqs enabled, so it is not
necessary to save/restore the irq state when disabling irqs in these
handlers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-13 23:18:59 -04:00
Kevin O'Connor 4fcf5a31f5 pwmcmds: Add Kconfig option to allow boards to disable hardware PWM commands
Some boards may not support hardware based PWM.  Update the build so
that those commands do not need to be compiled if they are not
available.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-13 23:18:59 -04:00
Kevin O'Connor c20f993747 spicmds: Add Kconfig option to allow boards to disable SPI commands
Some boards may not support SPI transfers.  Update the build so that
those commands do not need to be compiled if they are not available.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-13 23:18:59 -04:00
Kevin O'Connor 71947d6bea gpiocmds: Add Kconfig option to allow boards to disable ADC commands
Some boards may not support the ADC hardware.  Update the build so
that those commands do not need to be compiled if they are not
available.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-13 23:18:59 -04:00
Kevin O'Connor 220a1e4197 compiler.h: Check if __aligned and __section macros are already defined
Don't define these macros if they are already - doing so causes
compiler warnings.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-13 23:18:59 -04:00
Kevin O'Connor 4dd3478fc1 Makefile: Move listing of directories to create to board makefiles
Rename DIRS to dirs-y and populate it in the per-board Makefile rules.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-13 23:18:59 -04:00
Kevin O'Connor 8e1c0941b0 generic: Add new file generic/io.h and move read/writeb() to it
Move the definitions of the readb() style functions to a new header
generic/io.h.  This eliminates the dependency of stdint.h on
compiler.h.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-13 23:18:59 -04:00
Kevin O'Connor 62f96f0911 generic: Move simulator/gpio.h to generic/gpio.h
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-13 23:18:59 -04:00
Kevin O'Connor 73f3b0636a generic: Move simulator/irq.h to new file generic/irq.h
Move the generic irq definitions into generic/irq.h and move the
simulator irq code into main.c.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-13 23:18:58 -04:00
Kevin O'Connor 9f8817a47e generic: Move board timer.h files into generic/misc.h
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-13 23:18:58 -04:00
Kevin O'Connor 9971f999b3 generic: Create generic board infrastructure and move misc.h to it
Instead of creating a misc.h file in each board directory, create a
generic board directory and declare misc.h there.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-13 23:18:58 -04:00
Kevin O'Connor bd07cd1193 sched: Optimize timer list handling
Rework the timer list rescheduling to be more optimized.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-13 15:34:56 -04:00
Kevin O'Connor a6de2184ba stepper: Optimize for case where add is zero
At high rates, the "add" field is frequently zero.  It's possible to
optimize for that case.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-13 15:34:56 -04:00
Kevin O'Connor e4859d2e9a gpio: Fix off-by-one bug in check for the maximum gpio port
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-13 15:34:23 -04:00
Kevin O'Connor 91e7807af6 avr: Add config option to clear the CPU prescaler
Some AVR chips ship with a 1/8th clock divisor set.  Add a compile
time option to manually clear this field at startup.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-05 10:52:46 -04:00
Kevin O'Connor b52b65624b avr: Separate out gpio pwm pin definitions from pwm register definitions
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-05 10:52:46 -04:00
Kevin O'Connor 2a17d9457a avr: Eliminate gpio_adc_info struct in gpio adc pin definitions
The gpio_adc_info only contains a single uint8_t field - it's simpler
to use an array of uint8_t instead.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-05 10:52:46 -04:00
Kevin O'Connor 7531d0c678 avr: Define timer1 timers and prevent their use as PWM at runtime
Instead of commenting out the timer1 pwm definitions, detect them at
runtime.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-05 10:52:45 -04:00
Kevin O'Connor 3eafc83458 avr: Initial support for Atmel AT90USB1286 mcu
Add GPIO definitions for the AT90USB1286.  Add code for communicating
over USB port on AT90USB1286.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-05 10:52:45 -04:00
Kevin O'Connor ed103822f5 sched: Change sched_from_ms() to sched_from_us()
Some code may require micro-second precision so update sched_from_ms()
to use micro-seconds.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-02 17:52:11 -04:00
Kevin O'Connor d68cb264c4 stepper: Use stepper_stop() instead of stepper_reset() in stepper_shutdown()
The stepper_stop() function is equivalent to stepper_reset() during a
shutdown event.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-02 17:52:05 -04:00
Kevin O'Connor 45ba03efa3 timer: Move union u32_u16_u from compiler.h to avr/timer.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-06-01 09:54:13 -04:00
Kevin O'Connor f582a36e4d Initial commit of source code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2016-05-25 11:37:40 -04:00