Skip to content

Commit

Permalink
Merge branch 'main' into EXEC-343-lld-cap-probe-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoegenburg committed May 31, 2024
2 parents 3b46335 + 8738ed7 commit eacd462
Show file tree
Hide file tree
Showing 107 changed files with 468 additions and 1,459 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
build-and-test:
name: Run all tests
runs-on: "ubuntu-20.04"
timeout-minutes: 20
timeout-minutes: 10
steps:
- name: Checkout ot3-firmware repo
uses: actions/checkout@v4
Expand Down
24 changes: 4 additions & 20 deletions gantry/core/tasks_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,18 @@ static auto eeprom_data_rev_update_builder =
/**
* Start gantry tasks.
*/
auto gantry::tasks::start_tasks(
void gantry::tasks::start_tasks(
can::bus::CanBus& can_bus,
motion_controller::MotionController<lms::BeltConfig>& 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)
-> interfaces::diag0_handler {
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface) {
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, ::queues, ::queues);
auto& motion = mc_task_builder.start(5, "motion controller",
motion_controller, ::queues, ::queues);
auto& tmc2130_driver = motor_driver_task_builder.start(
5, "tmc2130 driver", driver_configs, ::queues, spi_task_client);
auto& move_group =
Expand Down Expand Up @@ -118,15 +116,6 @@ auto 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)
Expand All @@ -142,11 +131,6 @@ void gantry::queues::QueueClient::send_motor_driver_queue(
motor_driver_queue->try_write(m);
}

void gantry::queues::QueueClient::send_motor_driver_queue_isr(
const tmc2130::tasks::TaskMessage& m) {
static_cast<void>(motor_driver_queue->try_write_isr(m));
}

void gantry::queues::QueueClient::send_move_group_queue(
const move_group_task::TaskMessage& m) {
move_group_queue->try_write(m);
Expand Down
24 changes: 4 additions & 20 deletions gantry/core/tasks_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,18 @@ static auto tail_accessor = eeprom::dev_data::DevDataTailAccessor{queues};
/**
* Start gantry ::tasks.
*/
auto gantry::tasks::start_tasks(
void gantry::tasks::start_tasks(
can::bus::CanBus& can_bus,
motion_controller::MotionController<lms::BeltConfig>& motion_controller,
spi::hardware::SpiDeviceBase& spi_device,
tmc2160::configs::TMC2160DriverConfig& driver_configs,
motor_hardware_task::MotorHardwareTask& mh_tsk,
i2c::hardware::I2CBase& i2c2,
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface)
-> interfaces::diag0_handler {
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface) {
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, ::queues, ::queues);
auto& motion = mc_task_builder.start(5, "motion controller",
motion_controller, ::queues, ::queues);
auto& tmc2160_driver = motor_driver_task_builder.start(
5, "tmc2160 driver", driver_configs, ::queues, spi_task_client);
auto& move_group =
Expand Down Expand Up @@ -117,15 +115,6 @@ auto 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)
Expand All @@ -141,11 +130,6 @@ void gantry::queues::QueueClient::send_motor_driver_queue(
motor_driver_queue->try_write(m);
}

void gantry::queues::QueueClient::send_motor_driver_queue_isr(
const tmc2160::tasks::TaskMessage& m) {
static_cast<void>(motor_driver_queue->try_write_isr(m));
}

void gantry::queues::QueueClient::send_move_group_queue(
const move_group_task::TaskMessage& m) {
move_group_queue->try_write(m);
Expand Down
37 changes: 12 additions & 25 deletions gantry/firmware/interfaces_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,10 @@ struct motion_controller::HardwareConfig motor_pins_x {
.port = GPIOB,
.pin = GPIO_PIN_7,
.active_setting = GPIO_PIN_RESET},
.estop_in =
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET},
.diag0 = {
.estop_in = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOC,
.pin = GPIO_PIN_5,
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET}
};

Expand Down Expand Up @@ -131,21 +125,15 @@ struct motion_controller::HardwareConfig motor_pins_y {
.port = GPIOB,
.pin = GPIO_PIN_5,
.active_setting = GPIO_PIN_RESET},
.estop_in =
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET},
.diag0 = {
.estop_in = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOC,
.pin = GPIO_PIN_5,
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET}
};

static tmc2130::configs::TMC2130DriverConfig gantry_x_driver_configs{
.registers = {.gconfig = {.en_pwm_mode = 1, .diag0_error = 1},
.registers = {.gconfig = {.en_pwm_mode = 1},
.ihold_irun = {.hold_current = 0x2,
.run_current = 0x18,
.hold_current_delay = 0x7},
Expand All @@ -168,7 +156,7 @@ static tmc2130::configs::TMC2130DriverConfig gantry_x_driver_configs{
}};

static tmc2130::configs::TMC2130DriverConfig gantry_y_driver_configs{
.registers = {.gconfig = {.en_pwm_mode = 1, .diag0_error = 1},
.registers = {.gconfig = {.en_pwm_mode = 1},
.ihold_irun = {.hold_current = 0x2,
.run_current = 0x18,
.hold_current_delay = 0x7},
Expand Down Expand Up @@ -244,8 +232,8 @@ static stall_check::StallCheck stallcheck(
* Handler of motor interrupts.
*/
static motor_handler::MotorInterruptHandler motor_interrupt(
motor_queue, gantry::queues::get_queues(), gantry::queues::get_queues(),
motor_hardware_iface, stallcheck, update_position_queue);
motor_queue, gantry::queues::get_queues(), motor_hardware_iface, stallcheck,
update_position_queue);

static auto encoder_background_timer =
motor_encoder::BackgroundTimer(motor_interrupt, motor_hardware_iface);
Expand Down Expand Up @@ -281,14 +269,13 @@ static constexpr auto can_bit_timings =
can::bit_timings::BitTimings<170 * can::bit_timings::MHZ, 100,
500 * can::bit_timings::KHZ, 800>{};

void interfaces::initialize(diag0_handler* call_diag0_handler) {
void interfaces::initialize() {
// Initialize SPI
if (initialize_spi(get_axis_type()) != HAL_OK) {
Error_Handler();
}

initialize_timer(call_motor_handler, call_diag0_handler,
enc_overflow_callback);
initialize_timer(call_motor_handler, enc_overflow_callback);

// Start the can bus
canbus.start(can_bit_timings);
Expand Down
39 changes: 12 additions & 27 deletions gantry/firmware/interfaces_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,10 @@ struct motion_controller::HardwareConfig motor_pins_x {
.port = GPIOB,
.pin = GPIO_PIN_7,
.active_setting = GPIO_PIN_RESET},
.estop_in =
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET},
.diag0 = {
.estop_in = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOC,
.pin = GPIO_PIN_5,
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET}
};

Expand Down Expand Up @@ -131,21 +125,15 @@ struct motion_controller::HardwareConfig motor_pins_y {
.port = GPIOB,
.pin = GPIO_PIN_7,
.active_setting = GPIO_PIN_RESET},
.estop_in =
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET},
.diag0 = {
.estop_in = {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
.port = GPIOC,
.pin = GPIO_PIN_5,
.port = GPIOA,
.pin = GPIO_PIN_10,
.active_setting = GPIO_PIN_RESET}
};

static tmc2160::configs::TMC2160DriverConfig motor_driver_config_x{
.registers = {.gconfig = {.en_pwm_mode = 0, .diag0_error = 1},
.registers = {.gconfig = {.en_pwm_mode = 0},
.ihold_irun = {.hold_current = 16,
.run_current = 31,
.hold_current_delay = 0x7},
Expand All @@ -171,7 +159,6 @@ static tmc2160::configs::TMC2160DriverConfig motor_driver_config_x{
.freewheel = 0,
.pwm_reg = 0x7,
.pwm_lim = 0xC},
.drvconf = {.ot_select = 0},
.glob_scale = {.global_scaler = 0xA7}},
.current_config =
{
Expand All @@ -185,7 +172,7 @@ static tmc2160::configs::TMC2160DriverConfig motor_driver_config_x{
}};

static tmc2160::configs::TMC2160DriverConfig motor_driver_config_y{
.registers = {.gconfig = {.en_pwm_mode = 0, .diag0_error = 1},
.registers = {.gconfig = {.en_pwm_mode = 0},
.ihold_irun = {.hold_current = 16,
.run_current = 31,
.hold_current_delay = 0x7},
Expand All @@ -211,7 +198,6 @@ static tmc2160::configs::TMC2160DriverConfig motor_driver_config_y{
.freewheel = 0,
.pwm_reg = 0x7,
.pwm_lim = 0xC},
.drvconf = {.ot_select = 0},
.glob_scale = {.global_scaler = 0xA7}},
.current_config =
{
Expand Down Expand Up @@ -271,8 +257,8 @@ static stall_check::StallCheck stallcheck(
* Handler of motor interrupts.
*/
static motor_handler::MotorInterruptHandler motor_interrupt(
motor_queue, gantry::queues::get_queues(), gantry::queues::get_queues(),
motor_hardware_iface, stallcheck, update_position_queue);
motor_queue, gantry::queues::get_queues(), motor_hardware_iface, stallcheck,
update_position_queue);

static auto encoder_background_timer =
motor_encoder::BackgroundTimer(motor_interrupt, motor_hardware_iface);
Expand Down Expand Up @@ -309,14 +295,13 @@ static constexpr auto can_bit_timings =
can::bit_timings::BitTimings<170 * can::bit_timings::MHZ, 100,
500 * can::bit_timings::KHZ, 800>{};

void interfaces::initialize(diag0_handler* call_diag0_handler) {
void interfaces::initialize() {
// Initialize SPI
if (initialize_spi(get_axis_type()) != HAL_OK) {
Error_Handler();
}

initialize_timer(call_motor_handler, call_diag0_handler,
enc_overflow_callback);
initialize_timer(call_motor_handler, enc_overflow_callback);

// Start the can bus
canbus.start(can_bit_timings);
Expand Down
6 changes: 2 additions & 4 deletions gantry/firmware/main_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#include "gantry/core/tasks_proto.hpp"
#include "i2c/firmware/i2c_comms.hpp"

static interfaces::diag0_handler call_diag0_handler = nullptr;

static auto i2c_comms2 = i2c::hardware::I2C();
static auto i2c_handles = I2CHandlerStruct{};

Expand Down Expand Up @@ -46,11 +44,11 @@ auto main() -> int {

app_update_clear_flags();

interfaces::initialize(&call_diag0_handler);
interfaces::initialize();
i2c_setup(&i2c_handles);
i2c_comms2.set_handle(i2c_handles.i2c2);

call_diag0_handler = gantry::tasks::start_tasks(
gantry::tasks::start_tasks(
interfaces::get_can_bus(), interfaces::get_motor().motion_controller,
interfaces::get_spi(), interfaces::get_driver_config(),
interfaces::get_motor_hardware_task(), i2c_comms2, eeprom_hw_iface);
Expand Down
6 changes: 2 additions & 4 deletions gantry/firmware/main_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#include "gantry/core/tasks_rev1.hpp"
#include "i2c/firmware/i2c_comms.hpp"

static interfaces::diag0_handler call_diag0_handler = nullptr;

static auto i2c_comms2 = i2c::hardware::I2C();
static auto i2c_handles = I2CHandlerStruct{};

Expand Down Expand Up @@ -46,11 +44,11 @@ auto main() -> int {

app_update_clear_flags();

interfaces::initialize(&call_diag0_handler);
interfaces::initialize();
i2c_setup(&i2c_handles);
i2c_comms2.set_handle(i2c_handles.i2c2);

call_diag0_handler = gantry::tasks::start_tasks(
gantry::tasks::start_tasks(
interfaces::get_can_bus(), interfaces::get_motor().motion_controller,
interfaces::get_spi(), interfaces::get_driver_config(),
interfaces::get_motor_hardware_task(), i2c_comms2, eeprom_hw_iface);
Expand Down
Loading

0 comments on commit eacd462

Please sign in to comment.