mcu: Delay reset signaling for usb to canbus bridge nodes
An mcu device acting as an "mcu bridge" should only be reset after other normal devices are reset - otherwise the bridge wont be able to pass along the reset message to the downstream mcus. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
2d74b3d358
commit
751bff7d38
|
@ -231,8 +231,7 @@ class Printer:
|
||||||
run_result = self.run_result
|
run_result = self.run_result
|
||||||
try:
|
try:
|
||||||
if run_result == 'firmware_restart':
|
if run_result == 'firmware_restart':
|
||||||
for n, m in self.lookup_objects(module='mcu'):
|
self.send_event("klippy:firmware_restart")
|
||||||
m.microcontroller_restart()
|
|
||||||
self.send_event("klippy:disconnect")
|
self.send_event("klippy:disconnect")
|
||||||
except:
|
except:
|
||||||
logging.exception("Unhandled exception during post run")
|
logging.exception("Unhandled exception during post run")
|
||||||
|
|
|
@ -563,6 +563,7 @@ class MCU:
|
||||||
self._restart_method = config.getchoice('restart_method',
|
self._restart_method = config.getchoice('restart_method',
|
||||||
rmethods, None)
|
rmethods, None)
|
||||||
self._reset_cmd = self._config_reset_cmd = None
|
self._reset_cmd = self._config_reset_cmd = None
|
||||||
|
self._is_mcu_bridge = False
|
||||||
self._emergency_stop_cmd = None
|
self._emergency_stop_cmd = None
|
||||||
self._is_shutdown = self._is_timeout = False
|
self._is_shutdown = self._is_timeout = False
|
||||||
self._shutdown_clock = 0
|
self._shutdown_clock = 0
|
||||||
|
@ -589,9 +590,11 @@ class MCU:
|
||||||
self._mcu_tick_stddev = 0.
|
self._mcu_tick_stddev = 0.
|
||||||
self._mcu_tick_awake = 0.
|
self._mcu_tick_awake = 0.
|
||||||
# Register handlers
|
# Register handlers
|
||||||
printer.register_event_handler("klippy:connect", self._connect)
|
printer.register_event_handler("klippy:firmware_restart",
|
||||||
|
self._firmware_restart)
|
||||||
printer.register_event_handler("klippy:mcu_identify",
|
printer.register_event_handler("klippy:mcu_identify",
|
||||||
self._mcu_identify)
|
self._mcu_identify)
|
||||||
|
printer.register_event_handler("klippy:connect", self._connect)
|
||||||
printer.register_event_handler("klippy:shutdown", self._shutdown)
|
printer.register_event_handler("klippy:shutdown", self._shutdown)
|
||||||
printer.register_event_handler("klippy:disconnect", self._disconnect)
|
printer.register_event_handler("klippy:disconnect", self._disconnect)
|
||||||
# Serial callbacks
|
# Serial callbacks
|
||||||
|
@ -794,6 +797,10 @@ class MCU:
|
||||||
mbaud = msgparser.get_constant('SERIAL_BAUD', None)
|
mbaud = msgparser.get_constant('SERIAL_BAUD', None)
|
||||||
if self._restart_method is None and mbaud is None and not ext_only:
|
if self._restart_method is None and mbaud is None and not ext_only:
|
||||||
self._restart_method = 'command'
|
self._restart_method = 'command'
|
||||||
|
if msgparser.get_constant('CANBUS_BRIDGE', 0):
|
||||||
|
self._is_mcu_bridge = True
|
||||||
|
self._printer.register_event_handler("klippy:firmware_restart",
|
||||||
|
self._firmware_restart_bridge)
|
||||||
version, build_versions = msgparser.get_version_info()
|
version, build_versions = msgparser.get_version_info()
|
||||||
self._get_status_info['mcu_version'] = version
|
self._get_status_info['mcu_version'] = version
|
||||||
self._get_status_info['mcu_build_versions'] = build_versions
|
self._get_status_info['mcu_build_versions'] = build_versions
|
||||||
|
@ -911,7 +918,9 @@ class MCU:
|
||||||
chelper.run_hub_ctrl(0)
|
chelper.run_hub_ctrl(0)
|
||||||
self._reactor.pause(self._reactor.monotonic() + 2.)
|
self._reactor.pause(self._reactor.monotonic() + 2.)
|
||||||
chelper.run_hub_ctrl(1)
|
chelper.run_hub_ctrl(1)
|
||||||
def microcontroller_restart(self):
|
def _firmware_restart(self, force=False):
|
||||||
|
if self._is_mcu_bridge and not force:
|
||||||
|
return
|
||||||
if self._restart_method == 'rpi_usb':
|
if self._restart_method == 'rpi_usb':
|
||||||
self._restart_rpi_usb()
|
self._restart_rpi_usb()
|
||||||
elif self._restart_method == 'command':
|
elif self._restart_method == 'command':
|
||||||
|
@ -920,6 +929,8 @@ class MCU:
|
||||||
self._restart_cheetah()
|
self._restart_cheetah()
|
||||||
else:
|
else:
|
||||||
self._restart_arduino()
|
self._restart_arduino()
|
||||||
|
def _firmware_restart_bridge(self):
|
||||||
|
self._firmware_restart(True)
|
||||||
# Misc external commands
|
# Misc external commands
|
||||||
def is_fileoutput(self):
|
def is_fileoutput(self):
|
||||||
return self._printer.get_start_args().get('debugoutput') is not None
|
return self._printer.get_start_args().get('debugoutput') is not None
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "board/pgm.h" // PROGMEM
|
#include "board/pgm.h" // PROGMEM
|
||||||
#include "board/usb_cdc_ep.h" // USB_CDC_EP_BULK_IN
|
#include "board/usb_cdc_ep.h" // USB_CDC_EP_BULK_IN
|
||||||
#include "byteorder.h" // cpu_to_le16
|
#include "byteorder.h" // cpu_to_le16
|
||||||
|
#include "command.h" // DECL_CONSTANT
|
||||||
#include "generic/usbstd.h" // struct usb_device_descriptor
|
#include "generic/usbstd.h" // struct usb_device_descriptor
|
||||||
#include "sched.h" // sched_wake_task
|
#include "sched.h" // sched_wake_task
|
||||||
#include "usb_cdc.h" // usb_notify_ep0
|
#include "usb_cdc.h" // usb_notify_ep0
|
||||||
|
@ -125,6 +126,8 @@ enum {
|
||||||
HS_TX_LOCAL = 4,
|
HS_TX_LOCAL = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DECL_CONSTANT("CANBUS_BRIDGE", 1);
|
||||||
|
|
||||||
void
|
void
|
||||||
canbus_notify_tx(void)
|
canbus_notify_tx(void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue