tmc2130: Hold a mutex during MCU_TMC_SPI get/set_register()

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-06-10 09:46:40 -04:00 committed by KevinOConnor
parent 3a3dfd51b9
commit 1f3b74d2f7
1 changed files with 8 additions and 5 deletions

View File

@ -173,6 +173,7 @@ class TMCCurrentHelper:
class MCU_TMC_SPI: class MCU_TMC_SPI:
def __init__(self, config, name_to_reg, fields): def __init__(self, config, name_to_reg, fields):
self.printer = config.get_printer() self.printer = config.get_printer()
self.mutex = self.printer.get_reactor().mutex()
self.spi = bus.MCU_SPI_from_config(config, 3, default_speed=4000000) self.spi = bus.MCU_SPI_from_config(config, 3, default_speed=4000000)
self.name_to_reg = name_to_reg self.name_to_reg = name_to_reg
self.fields = fields self.fields = fields
@ -180,6 +181,7 @@ class MCU_TMC_SPI:
return self.fields return self.fields
def get_register(self, reg_name): def get_register(self, reg_name):
reg = self.name_to_reg[reg_name] reg = self.name_to_reg[reg_name]
with self.mutex:
self.spi.spi_send([reg, 0x00, 0x00, 0x00, 0x00]) self.spi.spi_send([reg, 0x00, 0x00, 0x00, 0x00])
if self.printer.get_start_args().get('debugoutput') is not None: if self.printer.get_start_args().get('debugoutput') is not None:
return 0 return 0
@ -193,6 +195,7 @@ class MCU_TMC_SPI:
reg = Registers[reg_name] reg = Registers[reg_name]
data = [(reg | 0x80) & 0xff, (val >> 24) & 0xff, (val >> 16) & 0xff, data = [(reg | 0x80) & 0xff, (val >> 24) & 0xff, (val >> 16) & 0xff,
(val >> 8) & 0xff, val & 0xff] (val >> 8) & 0xff, val & 0xff]
with self.mutex:
self.spi.spi_send(data, minclock) self.spi.spi_send(data, minclock)