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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Refactor the code so that message block framing, command parsing, and
command dispatch are distinct.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>