tmc_uart: Limit to only one active uart at a time on an mcu
The tmcuart_send command increases cpu usage on the micro-controller. Should multiple tmcuart_send commands be issued at the same time to a single AVR micro-controller, it could increase the load to the point that it introduces a failure. It could also lead to tmcuart_send transmission errors, which would cause retransmission requests, which further increase the load. Track and share mutexes so that only one tmcuart_send command can be active on a single mcu at a time. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
11b9b72b41
commit
9572ad4327
|
@ -53,13 +53,30 @@ class MCU_analog_mux:
|
||||||
# TMC uart communication
|
# TMC uart communication
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
# Share mutexes so only one active tmc_uart command on a single mcu at
|
||||||
|
# a time. This helps limit cpu usage on slower micro-controllers.
|
||||||
|
class PrinterTMCUartMutexes:
|
||||||
|
def __init__(self):
|
||||||
|
self.mcu_to_mutex = {}
|
||||||
|
def lookup_tmc_uart_mutex(mcu):
|
||||||
|
printer = mcu.get_printer()
|
||||||
|
pmutexes = printer.lookup_object('tmc_uart', None)
|
||||||
|
if pmutexes is None:
|
||||||
|
pmutexes = PrinterTMCUartMutexes()
|
||||||
|
printer.add_object('tmc_uart', pmutexes)
|
||||||
|
mutex = pmutexes.mcu_to_mutex.get(mcu)
|
||||||
|
if mutex is None:
|
||||||
|
mutex = printer.get_reactor().mutex()
|
||||||
|
pmutexes.mcu_to_mutex[mcu] = mutex
|
||||||
|
return mutex
|
||||||
|
|
||||||
TMC_BAUD_RATE = 9000
|
TMC_BAUD_RATE = 9000
|
||||||
|
|
||||||
# Code for sending messages on a TMC uart
|
# Code for sending messages on a TMC uart
|
||||||
class MCU_TMC_uart_bitbang:
|
class MCU_TMC_uart_bitbang:
|
||||||
def __init__(self, rx_pin_params, tx_pin_params, select_pins_desc):
|
def __init__(self, rx_pin_params, tx_pin_params, select_pins_desc):
|
||||||
self.mcu = rx_pin_params['chip']
|
self.mcu = rx_pin_params['chip']
|
||||||
self.mutex = self.mcu.get_printer().get_reactor().mutex()
|
self.mutex = lookup_tmc_uart_mutex(self.mcu)
|
||||||
self.pullup = rx_pin_params['pullup']
|
self.pullup = rx_pin_params['pullup']
|
||||||
self.rx_pin = rx_pin_params['pin']
|
self.rx_pin = rx_pin_params['pin']
|
||||||
self.tx_pin = tx_pin_params['pin']
|
self.tx_pin = tx_pin_params['pin']
|
||||||
|
|
Loading…
Reference in New Issue