aboutsummaryrefslogtreecommitdiffstats
path: root/src/linux
Commit message (Collapse)AuthorAgeFilesLines
* sched: Improve timer vs task priority checkKevin O'Connor2024-10-261-1/+1
| | | | | | | | | | | | | | | Rename sched_tasks_busy() to sched_check_set_tasks_busy() and change it to only return true if tasks are active (running or requested) for two consecutive calls. This makes it less likely that timers will yield to tasks except when tasks really are notably backlogged. This also makes it less likely that multiple steppers controlling the same rail will be interrupted by tasks mid-step. This should slightly improve the timing, and make it less likely that a halt during homing/probing will occur with these steppers taking a different number of total steps. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: forward i2c errors to i2ccmdTimofey Titovets2024-10-261-7/+15
| | | | Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
* i2c: handle errors at i2ccmdsTimofey Titovets2024-10-262-4/+9
| | | | Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
* linux: Don't use absolute paths for includeMichael 'ASAP' Weinrich2024-04-032-2/+2
| | | | | | | | Not all systems (i.e. Nix) repect the standard Linux filesystem hierarchy, instead relative paths should be used and allowing GCC to rely on it's builtin search paths. Signed-off-by: Michael 'ASAP' Weinrich <michael@a5ap.net>
* linux: Allow for more i2c busesCarl Richard Theodor Schneider2024-03-211-1/+1
| | | | | | | | | | | | | | | Similar to commit df79893, this allows klipper to use up to /dev/i2c-14. Similar to before, this limit is arbitrary. This is required for some other SoCs, which have even more i2c buses available, e.g. the rk3399: $ ls -1 /dev/i2c-* /dev/i2c-0 /dev/i2c-3 /dev/i2c-7 Signed-off-by: Carl Richard Theodor Schneider <dev.github@crtified.me>
* Kconfig: Support selecting optional features on chips with small flash sizeKevin O'Connor2023-06-081-3/+2
| | | | | | | | | | | | | Add a new HAVE_LIMITED_CODE_SIZE symbol that enables a menu to select optional features. This symbol is enabled on chips with small build sizes. Replace the HAVE_GPIO_BITBANGING with four new symbols: WANT_GPIO_BITBANGING, WANT_DISPLAYS, WANT_SENSORS, WANT_SOFTWARE_SPI, and WANT_SOFTWARE_I2C. This allows users a little more flexibility when selecting features they need. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* scripts: Fix flash linux when OUT argument provided (#6133)visilya2023-04-071-1/+1
| | | Signed-off-by: Ilya Vislotsky <write2ilya@gmail.com>
* linux: Lock Memory and Increase Priority (#6131)Dr. Matthew Swabey2023-03-271-2/+9
| | | | | | | | | | | | | | | | | Realtime programming best practice is to lock realtime code memory to prevent paging which will lead to unbounded latencies. The Linux MCU process has well bounded memory and small RAM footprint so locking the entire process' RAM has no downsides and will improve behavior when the system comes under memory pressure. (See bootlin training and Linux Foundation documentation linked below.) RT process priority ranges from 0-99 (although POSIX only requires 32), boost MCU process priority to half the max/2 to improve robustness when the system comes under pressure from other RT Kernel or user processes. Reference links: bootlin: https://bootlin.com/doc/training/preempt-rt/preempt-rt-slides.pdf Linux Foundation: https://wiki.linuxfoundation.org/realtime/documentation/howto/applications/application_base#howto_build_a_simple_rt_application Signed-off-by: Matthew Swabey <matthew@swabey.org>
* linux: Fast Linux MCU i2c_read() with I2C_RDRW (#6101)Dr. Matthew Swabey2023-03-142-8/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | Reading an I2C device from the Linux MCU used a separate write(2) to select the target register & read(2) to get the value(s). This implementation uses ioctl(file, I2C_RDWR, ...) to skip a large bus idle period and extra process sleep by combining them like the stm32. I2C_RDRW requires I2C_FUNC_I2C flag in the I2C driver. I2C_FUNC_I2C is defined in: BCM2835: Pi 1 Models A, A+, B, B+, the Raspberry Pi Zero, the Raspberry Pi Zero W, and the Raspberry Pi Compute Module 1 BCM2836: Pi 2 Model B Identical to BCM2835 except Cortex BCM2837: Pi 3 Model B, later models of the Raspberry Pi 2 Model B, and the Raspberry Pi Compute Module 3 BCM2837B0: Pi 3 Models A+, B+, and the Raspberry Pi Compute Module 3+ BCM2711: Pi 4 Model B, the Raspberry Pi 400, and the Raspberry Pi Compute Module 4 RK3xxx: Rockchips SoCs NanoPi, RockPi, Tinker, etc. SUNXI: H2, H3, etc. Orange Pi AMLOGIC: S905x, Banana Pi, Odroid, etc. TEGRA: NVidia Jetson etc. MediaTek: Several SBCs in other ranges Signed-off-by: Matthew Swabey <matthew@swabey.org>
* linux: add -I attribute for user defined socket pathsStefan Dej2023-01-171-3/+7
| | | | Signed-off-by: Stefan Dej <meteyou@gmail.com>
* linux: add 'GPIOI' for linux process (#5926)BIGTREETECH2022-12-112-3/+4
| | | Signed-off-by: Alan.Ma from BigTreeTech tech@biqu3d.com
* linux: use correct gpio bias flags (#5878)Eric Callahan2022-11-081-3/+3
| | | Signed-off-by: Eric Callahan <arksine.code@gmail.com>
* ds18b20: Allow some read errorsfunctionpointer2022-06-081-22/+33
| | | | | | | | | | | | | | | | | | | | | Allows a limited number of DS18B20 read failures before stopping the printer. This is designed to tolerate spurious read errors, while still stopping for serious issues. The printer will stop when the sensor fails to report a value five times in a row. Implementation works as follows: The MCU reports any read errors using a new "fault" parameter in its answers. The Python code tracks the number of errors and triggers the shutdown. This paves the way for more sophisticated error handling in the future, as well as an example for other sensors to follow. Signed-off-by: Lorenzo Pfeifer <Lorenzo.Pfeifer+github@googlemail.com>
* linux: Update i2c.c (#5295)Blinker732022-03-141-1/+1
| | | | | | | | | | | | | | | Similarly to commit 8cf1b512 for SPI, the Rpi4 has more i2c busses to offer This change allows klipper to use up to I2c bus 6 /boot/configtxt dtparam=i2c_arm=on dtoverlay=i2c6 and pi@fluiddpi:~ $ ls -1 /dev/i2c* /dev/i2c-1 /dev/i2c-6 Signed-off-by: Sylvain Dansereau <brutus_dansereau@hotmail.com>
* linux: Use Unix signals to notify when a timer is pendingKevin O'Connor2021-11-025-57/+105
| | | | | | | Use Unix signals in software timer implementation. This makes the code a little more efficient. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Support spidev4 through spidev7Kevin O'Connor2021-09-151-0/+4
| | | | | | The rpi4 has additional spi devices. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* Revert "linux: Raise an error if configuring a pullup when that is not ↵Kevin O'Connor2021-05-271-3/+0
| | | | | | | | | | | supported" This reverts commit 70ea0806d96df5a8ea83793da46f2676d9695e69. The above commit breaks software spi on linux hosts. Revert that commit until an improved error check can be implemented. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Raise an error if configuring a pullup when that is not supportedKevin O'Connor2021-04-251-0/+3
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Minor formatting, variable name, and error reporting changesKevin O'Connor2021-04-251-62/+53
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Don't use timer_repeat_until for linux "irq" pollingKevin O'Connor2021-04-211-29/+9
| | | | | | Use a simpler counter system to prioritize tasks and irqs when busy. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Rework timer_check_periodic() to use ticksKevin O'Connor2021-04-193-14/+14
| | | | | | Avoid using a 'struct timespec' to simplify the code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Move timer fields into a structKevin O'Connor2021-04-191-31/+37
| | | | | | Storing the fields in a struct allows gcc to optimize memory pointers. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Avoid calling timer_read_time() in timer_dispatch() when not neededKevin O'Connor2021-04-181-3/+15
| | | | | | | The timer_read_time() call can be expensive - when the next timer is definitely pending, avoid making that call. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Simplify timer dispatch codeKevin O'Connor2021-04-181-54/+50
| | | | | | | | Implement rescheduling math using the simple 32-bit timer instead of the Unix timespec struct. This makes the code simpler and doesn't adversely impact the overall performance. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Fix local timer_repeat_until cache in timer.cKevin O'Connor2021-04-181-1/+1
| | | | | | | Make sure to update the local copy of timer_repeat_until when updating it. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* ds18b20: Segmentation fault on 64bit Raspberry PiEvgeny Chukreev2021-03-191-1/+1
| | | | Signed-off-by: Evgeny Chukreev <Evgeny.Chukreev@gmail.com>
* ds18b20: new module for 1-wire temperature sensor (#3462)Alan Lord2021-02-022-1/+276
| | | | | | | | | Initial commit of code to support 1-wire (Dallas) sensors such as the DS18B20. Requires Linux kernel drivers to create a file in /sysfs which is read by this module, and temperature typically returned to a temperature_fan. Signed-off-by: Alan Lord <alanslists@gmail.com> Signed-off-by: Josh Headapohl <joshhead@gmail.com>
* pca9685: Use move queue for pwm updatesKevin O'Connor2020-12-041-13/+58
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* command: Fix handling of buffer passing in args[] on 64bit mcuKevin O'Connor2020-10-301-0/+6
| | | | | | | | If the buffer pointer can't fit in a uint32_t then pass a relative buffer offset instead. This fixes buffer handling on 64bit linux mcus. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Fix spi handling with more than one spi deviceKevin O'Connor2020-10-251-0/+1
| | | | | | Reported by @opensource-alt. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Set the SPI mode in spidev.cKevin O'Connor2020-07-311-0/+5
| | | | | | Fix omission causing the SPI mode to not be set on the linux mcu. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Disable hardware pwm when it is set to zeroKevin O'Connor2020-07-202-13/+12
| | | | | | | | | | | Only write "1" to the "enable" file when a non-zero pwm width is requested. Write "0" to the "enable" file when a zero pwm width is requested. This fixes a problem on the replicape servo lines that prevented them from being fully disabled. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Wait in timer dispatch for up to 2usKevin O'Connor2020-06-071-2/+2
| | | | | | | Use 2us in the linux timer dispatch code to unify linux timer dispatch logic with the common timer_irq.c code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Ability to use multiple GPIO chips (#2935)Lucio Tarantino2020-06-063-20/+48
| | | Signed-off-by: Lucio Tarantino <lucio.tarantino@gmail.com>
* linux: userspace GPIO controlandryblack2020-05-179-22/+186
| | | | | | Allow use host GPIO pins for non-realtime purposes. Signed-off-by: Andrey Kunitsyn <blackicebox@gmail.com>
* htu21d: Support for HTI21D family sensor on I2C bus (#2803)Lucio Tarantino2020-05-031-1/+2
| | | Signed-off-by: Lucio Tarantino <lucio.tarantino@gmail.com>
* linux: Adapt servo0 channels for beagleboard kernel 4.14.108-ti (#2746)Janne Grunau2020-05-031-12/+29
| | | | | | | | | | | | | | The beagleboard TI kernel 4.14 and 4.19 contain a commit which change the device names ("pwm: Create device class for pwm channels") from pwmN to pwm-${chip}:N. This commit was never merged into the upstream kernel. Decrease the number of pwm channels to a more reasonable 16. Increase the number of pwm chips to 8 since the replicape servo pwm outputs are on pwmchip4. Update replicape code to detect appropriate channel. Signed-off-by: Janne Grunau <janne-gh@jannau.net>
* linux: change clock frequencyandryblack2020-05-021-1/+1
| | | | | | Increase timer resolution for linux mcu Signed-off-by: Andrey Kunitsyn <blackicebox@gmail.com>
* linux: implement i2cArksine2020-01-134-1/+112
| | | | Signed-off-by: Eric Callahan <arksine.code@gmail.com>
* spicmds: Rework spi config commandsKevin O'Connor2019-08-061-2/+2
| | | | | | | | | | Rework the spi_config commands so that bus configuration and shutdown message configuration is done separately from the main "config_spi" command. This makes the spi configuration more flexible. It's now possible to use software spi without a CS pin. It's now possible to define multiple SPI messages to send on a shutdown event. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: add support for Linux hardware PWMJanne Grunau2019-04-056-4/+110
| | | | | | | | | | The replicape servo pins (P9_14/P9_16) are muxed to the SOCs hardware PWM unit driven by a 13MHz GP timer. They have to be driven by the linux host mcu. This commits adds hardware PWM support using the linux sysfs user space interface. Signed-off-by: Janne Grunau <janne-3d@jannau.net> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Convert SPI to use enumerationsKevin O'Connor2019-04-041-1/+10
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Use enumerations for pin mappingsKevin O'Connor2019-03-171-0/+2
| | | | Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* command: Always pass a string to the DECL_CONSTANT() macroKevin O'Connor2019-03-174-4/+4
| | | | | | | | Make it clear that the name of the constant being defined is a string. When the value being defined is also a string, use a new DECL_CONSTANT_STR() macro. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* linux: Add support for bi-directional SPI communicationRicardo Amezquita2018-07-242-5/+33
| | | | | Signed-off-by: Ricardo Amézquita <ramezquitao@cihologramas.com> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* SPI: introduce spi_prepare functionGrigori Goronzy2018-07-082-0/+6
| | | | | | | | | | | | | | | | 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>
* command: Add command_find_and_dispatch() helperKevin O'Connor2018-05-281-3/+1
| | | | | | | Add a helper function that calls command_find_block() followed by command_dispatch(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* command: Add a command_encode_and_frame() helperKevin O'Connor2018-05-281-2/+1
| | | | | | | Add a helper function that calls command_encodef() followed by command_add_frame(). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
* command: Prefer uint8_t* for buffers; prefer uint8_fast_t for lengthsKevin O'Connor2018-05-281-4/+4
| | | | | | | | | 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>
* stepper: Introduce and use gpio_out_toggle_noirq()Kevin O'Connor2018-05-151-0/+1
| | | | | | | | | | | | | | | 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>