From e30658d432c89a39bdb57abef297fd1055ab738b Mon Sep 17 00:00:00 2001 From: pmoegenburg Date: Tue, 29 Aug 2023 17:36:05 -0400 Subject: [PATCH 01/68] Adds interrupt for motor driver. Successfully built gantry firmware --- gantry/core/tasks_proto.cpp | 14 ++++++-- gantry/core/tasks_rev1.cpp | 19 ++++++++--- gantry/firmware/interfaces_proto.cpp | 24 ++++++++++---- gantry/firmware/interfaces_rev1.cpp | 24 ++++++++++---- gantry/firmware/main_proto.cpp | 6 ++-- gantry/firmware/main_rev1.cpp | 6 ++-- gantry/firmware/motor_hardware.c | 27 +++++++++++++-- gantry/firmware/motor_hardware.h | 3 +- gantry/firmware/stm32g4xx_it.c | 1 + include/can/core/ids.hpp | 3 ++ include/can/core/message_handlers/motion.hpp | 2 +- include/can/core/messages.hpp | 18 ++++++++++ include/gantry/core/can_task.hpp | 6 ++-- include/gantry/core/interfaces_proto.hpp | 4 ++- include/gantry/core/interfaces_rev1.hpp | 4 ++- include/gantry/core/tasks_proto.hpp | 7 ++-- include/gantry/core/tasks_rev1.hpp | 7 ++-- include/motor-control/core/tasks/messages.hpp | 6 ++-- .../core/tasks/motion_controller_task.hpp | 33 +++++++++++++++---- .../core/tasks/tmc2130_motor_driver_task.hpp | 7 ++++ .../core/tasks/tmc2160_motor_driver_task.hpp | 19 +++++++++++ .../core/tasks/tmc_motor_driver_common.hpp | 3 +- .../firmware/stepper_motor/motor_hardware.hpp | 1 + include/spi/core/writer.hpp | 4 +-- 24 files changed, 202 insertions(+), 46 deletions(-) diff --git a/gantry/core/tasks_proto.cpp b/gantry/core/tasks_proto.cpp index de020ffc3..c059698aa 100644 --- a/gantry/core/tasks_proto.cpp +++ b/gantry/core/tasks_proto.cpp @@ -55,18 +55,18 @@ static auto eeprom_data_rev_update_builder = /** * Start gantry tasks. */ -void gantry::tasks::start_tasks( +auto gantry::tasks::start_tasks( can::bus::CanBus& can_bus, motion_controller::MotionController& motion_controller, spi::hardware::SpiDeviceBase& spi_device, tmc2130::configs::TMC2130DriverConfig& driver_configs, motor_hardware_task::MotorHardwareTask& mh_tsk, i2c::hardware::I2CBase& i2c2, - eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface) { + eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface) -> interfaces::diag0_handler { auto& can_writer = can_task::start_writer(can_bus); can_task::start_reader(can_bus); auto& motion = mc_task_builder.start(5, "motion controller", - motion_controller, ::queues, ::queues); + motion_controller, ::queues, ::queues, ::queues); auto& tmc2130_driver = motor_driver_task_builder.start( 5, "tmc2130 driver", driver_configs, ::queues, spi_task_client); auto& move_group = @@ -116,6 +116,14 @@ void gantry::tasks::start_tasks( ::queues.usage_storage_queue = &usage_storage_task.get_queue(); mh_tsk.start_task(); + + return gantry::tasks::call_run_diag0_interrupt; +} + +void gantry::tasks::call_run_diag0_interrupt() { + if (gantry::tasks::get_tasks().motion_controller) { + return gantry::tasks::get_tasks().motion_controller->run_diag0_interrupt(); + } } gantry::queues::QueueClient::QueueClient(can::ids::NodeId this_fw) diff --git a/gantry/core/tasks_rev1.cpp b/gantry/core/tasks_rev1.cpp index 95c81ba29..da7c69db8 100644 --- a/gantry/core/tasks_rev1.cpp +++ b/gantry/core/tasks_rev1.cpp @@ -17,6 +17,8 @@ static auto queues = gantry::queues::QueueClient{utils::get_node_id()}; static auto spi_task_client = spi::writer::Writer(); +//check how spi_task_client is used here +//we want an interrupt from spi, see past work static auto mc_task_builder = freertos_task::TaskStarter<512, @@ -30,6 +32,7 @@ static auto move_status_task_builder = freertos_task::TaskStarter< static auto spi_task_builder = freertos_task::TaskStarter<512, spi::tasks::Task>{}; +//look at this class's setup, functionality template