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:
Kevin O'Connor 2022-07-25 19:01:17 -04:00
parent 2d74b3d358
commit 751bff7d38
3 changed files with 17 additions and 4 deletions

View File

@ -231,8 +231,7 @@ class Printer:
run_result = self.run_result
try:
if run_result == 'firmware_restart':
for n, m in self.lookup_objects(module='mcu'):
m.microcontroller_restart()
self.send_event("klippy:firmware_restart")
self.send_event("klippy:disconnect")
except:
logging.exception("Unhandled exception during post run")

View File

@ -563,6 +563,7 @@ class MCU:
self._restart_method = config.getchoice('restart_method',
rmethods, None)
self._reset_cmd = self._config_reset_cmd = None
self._is_mcu_bridge = False
self._emergency_stop_cmd = None
self._is_shutdown = self._is_timeout = False
self._shutdown_clock = 0
@ -589,9 +590,11 @@ class MCU:
self._mcu_tick_stddev = 0.
self._mcu_tick_awake = 0.
# 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",
self._mcu_identify)
printer.register_event_handler("klippy:connect", self._connect)
printer.register_event_handler("klippy:shutdown", self._shutdown)
printer.register_event_handler("klippy:disconnect", self._disconnect)
# Serial callbacks
@ -794,6 +797,10 @@ class MCU:
mbaud = msgparser.get_constant('SERIAL_BAUD', None)
if self._restart_method is None and mbaud is None and not ext_only:
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()
self._get_status_info['mcu_version'] = version
self._get_status_info['mcu_build_versions'] = build_versions
@ -911,7 +918,9 @@ class MCU:
chelper.run_hub_ctrl(0)
self._reactor.pause(self._reactor.monotonic() + 2.)
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':
self._restart_rpi_usb()
elif self._restart_method == 'command':
@ -920,6 +929,8 @@ class MCU:
self._restart_cheetah()
else:
self._restart_arduino()
def _firmware_restart_bridge(self):
self._firmware_restart(True)
# Misc external commands
def is_fileoutput(self):
return self._printer.get_start_args().get('debugoutput') is not None

View File

@ -13,6 +13,7 @@
#include "board/pgm.h" // PROGMEM
#include "board/usb_cdc_ep.h" // USB_CDC_EP_BULK_IN
#include "byteorder.h" // cpu_to_le16
#include "command.h" // DECL_CONSTANT
#include "generic/usbstd.h" // struct usb_device_descriptor
#include "sched.h" // sched_wake_task
#include "usb_cdc.h" // usb_notify_ep0
@ -125,6 +126,8 @@ enum {
HS_TX_LOCAL = 4,
};
DECL_CONSTANT("CANBUS_BRIDGE", 1);
void
canbus_notify_tx(void)
{