Skip to content

Commit

Permalink
Merge branch 'main' into RET-1025_handle_motor_driver_errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoegenburg authored Feb 15, 2024
2 parents 36af4ba + 65d6a31 commit acc0fc5
Show file tree
Hide file tree
Showing 38 changed files with 926 additions and 346 deletions.
18 changes: 9 additions & 9 deletions bootloader/firmware/stm32G4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ foreach_revision(
macro(pipettes_single_bootloader_loop)

target_compile_definitions(${REVISION_TARGET} PUBLIC PIPETTE_TYPE_DEFINE=SINGLE_CHANNEL node_id_pipette_dynamic)

target_link_libraries(${REVISION_TARGET}
PUBLIC STM32G491RETx_bootloader
STM32G4xx_Drivers_Bootloader
Expand Down Expand Up @@ -132,26 +132,26 @@ set(_pipette_sources ${_g4_sources} ./pipette_handle_messages.c)
foreach_revision(
PROJECT_NAME bootloader-pipettes-single
CALL_FOREACH_REV pipettes_single_bootloader_loop
REVISIONS b1 c2 d1
SOURCES _pipette_sources _pipette_sources _pipette_sources
REVISIONS b1 c2 d1 e1
SOURCES _pipette_sources _pipette_sources _pipette_sources _pipette_sources
NO_CREATE_IMAGE_HEX
NO_CREATE_INSTALL_RULES
)

foreach_revision(
PROJECT_NAME bootloader-pipettes-multi
CALL_FOREACH_REV pipettes_multi_bootloader_loop
SOURCES _pipette_sources _pipette_sources _pipette_sources
REVISIONS b1 c2 d1
SOURCES _pipette_sources _pipette_sources _pipette_sources _pipette_sources
REVISIONS b1 c2 d1 e1
NO_CREATE_IMAGE_HEX
NO_CREATE_INSTALL_RULES
)

foreach_revision(
PROJECT_NAME bootloader-pipettes-96
CALL_FOREACH_REV pipettes_ninety_six_bootloader_loop
REVISIONS b1 c1 d2
SOURCES _pipette_sources _pipette_sources _pipette_sources
REVISIONS b1 c1 d2 e1
SOURCES _pipette_sources _pipette_sources _pipette_sources _pipette_sources
NO_CREATE_IMAGE_HEX
NO_CREATE_INSTALL_RULES
)
Expand All @@ -170,8 +170,8 @@ endmacro()
foreach_revision(
PROJECT_NAME bootloader-hepa-uv
CALL_FOREACH_REV hepauv_bootloader_loop
REVISIONS b1
SOURCES hepauv_sources
REVISIONS a1 b1
SOURCES hepauv_sources hepauv_sources
NO_CREATE_IMAGE_HEX
NO_CREATE_INSTALL_RULES
)
Expand Down
16 changes: 16 additions & 0 deletions cpp-utils/include/ot_utils/freertos/freertos_timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
#include "task.h"
#include "timers.h"

constexpr auto ROUNDED_DIV(uint32_t A, uint32_t B) noexcept -> uint32_t {
return (((A) + ((B) / 2)) / (B));
}

constexpr auto TICKS_TO_MS(uint32_t ticks) noexcept -> uint32_t {
return (uint32_t)ROUNDED_DIV((ticks) * 1000, (uint32_t)configTICK_RATE_HZ);
}

namespace ot_utils {
namespace freertos_timer {

Expand Down Expand Up @@ -54,6 +62,14 @@ class FreeRTOSTimer {
}
}

auto get_remaining_time() -> uint32_t {
/*
The time in ms remaining before this timer expires and the callback is executed.
*/
if (!is_running()) { return uint32_t(0); }
return TICKS_TO_MS(xTimerGetExpiryTime( timer ) - xTaskGetTickCount());
}

void start() { xTimerStart(timer, 1); }

void stop() { xTimerStop(timer, 1); }
Expand Down
3 changes: 3 additions & 0 deletions eeprom/tests/test_eeprom_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class MockHardwareIface : public hardware_iface::EEPromHardwareIface {
using hardware_iface::EEPromHardwareIface::EEPromHardwareIface;

public:
MockHardwareIface()
: EEPromHardwareIface(
hardware_iface::EEPromChipType::MICROCHIP_24AA02T) {}
void set_write_protect(bool enabled) { set_calls.push_back(enabled); }
std::vector<bool> set_calls{};
};
Expand Down
35 changes: 31 additions & 4 deletions hepa-uv/core/can_tasks.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include <span>

#include "eeprom/core/message_handler.hpp"
#include "hepa-uv/core/can_task.hpp"
#include "hepa-uv/core/hepa_task.hpp"
#include "hepa-uv/core/hepauv_info.hpp"
#include "hepa-uv/core/message_handler.hpp"

using namespace can::dispatch;

Expand All @@ -9,6 +13,13 @@ static auto& main_queues = hepauv_tasks::get_main_queues();
auto can_sender_queue = freertos_message_queue::FreeRTOSMessageQueue<
can::message_writer_task::TaskMessage>{};

/** The parsed message handler */
static auto hepauv_info_handler =
hepauv_info::HepaUVInfoMessageHandler{main_queues, main_queues};

static auto hepa_fan_handler = hepa::message_handler::HepaHandler{main_queues};
static auto uv_light_handler = uv::message_handler::UVHandler{main_queues};

/** Handler of system messages. */
static auto system_message_handler =
can::message_handlers::system::SystemMessageHandler{
Expand All @@ -22,6 +33,23 @@ static auto system_message_handler =
static auto system_dispatch_target =
can_task::SystemDispatchTarget{system_message_handler};

/** Handler for eeprom messages.*/
static auto eeprom_message_handler =
eeprom::message_handler::EEPromHandler{main_queues, main_queues};
static auto eeprom_dispatch_target =
can::dispatch::DispatchParseTarget<decltype(eeprom_message_handler),
can::messages::WriteToEEPromRequest,
can::messages::ReadFromEEPromRequest>{
eeprom_message_handler};

static auto hepauv_info_dispatch_target =
can_task::HepaUVInfoDispatchTarget{hepauv_info_handler};

static auto hepa_dispatch_target =
can_task::HepaDispatchTarget{hepa_fan_handler};

static auto uv_dispatch_target = can_task::UVDispatchTarget{uv_light_handler};

struct CheckForNodeId {
can::ids::NodeId node_id;
auto operator()(uint32_t arbitration_id) const {
Expand All @@ -41,7 +69,8 @@ static auto main_dispatcher = can::dispatch::Dispatcher(
return ((node_id == can::ids::NodeId::broadcast) ||
(node_id == can::ids::NodeId::hepa_uv));
},
system_dispatch_target);
system_dispatch_target, hepauv_info_dispatch_target, eeprom_dispatch_target,
hepa_dispatch_target, uv_dispatch_target);

auto static reader_message_buffer =
freertos_message_buffer::FreeRTOSMessageBuffer<1024>{};
Expand All @@ -62,8 +91,6 @@ void callback(void*, uint32_t identifier, uint8_t* data, uint8_t length) {

/**
* Entry point for the reader task.
* TODO (2021-12-15, AL): Most of what happens in this task should be moved out
* when we move to separate motor tasks.
*/
[[noreturn]] void can_task::CanMessageReaderTask::operator()(
can::bus::CanBus* can_bus) {
Expand All @@ -76,7 +103,7 @@ void callback(void*, uint32_t identifier, uint8_t* data, uint8_t length) {
can_bus->add_filter(CanFilterType::mask, CanFilterConfig::to_fifo0, filter,
can::arbitration_id::ArbitrationId::node_id_bit_mask);

// TODO: add HEPA/UV filter
// Accept Hepa/UV
filter.node_id(can::ids::NodeId::hepa_uv);
can_bus->add_filter(CanFilterType::mask, CanFilterConfig::to_fifo1, filter,
can::arbitration_id::ArbitrationId::node_id_bit_mask);
Expand Down
55 changes: 50 additions & 5 deletions hepa-uv/core/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include "common/core/freertos_task.hpp"
#include "common/core/freertos_timer.hpp"
#include "eeprom/core/dev_data.hpp"
#include "eeprom/core/hardware_iface.hpp"
#include "eeprom/core/task.hpp"
#include "eeprom/core/update_data_rev_task.hpp"
#include "hepa-uv/core/can_task.hpp"
#include "hepa-uv/firmware/gpio_drive_hardware.hpp"
#include "hepa-uv/firmware/hepa_control_hardware.hpp"
Expand All @@ -24,31 +28,67 @@ static auto uv_task_builder =
static auto led_control_task_builder =
freertos_task::TaskStarter<512, led_control_task::LEDControlTask>{};

static auto eeprom_task_builder =
freertos_task::TaskStarter<512, eeprom::task::EEPromTask>{};

static auto eeprom_data_rev_update_builder =
freertos_task::TaskStarter<512, eeprom::data_rev_task::UpdateDataRevTask>{};

static auto i2c2_task_client =
i2c::writer::Writer<freertos_message_queue::FreeRTOSMessageQueue>();

static auto i2c2_task_builder =
freertos_task::TaskStarter<512, i2c::tasks::I2CTask>{};

template <template <typename> typename QueueImpl>
using PollerWithTimer =
i2c::tasks::I2CPollerTask<QueueImpl, freertos_timer::FreeRTOSTimer>;
static auto i2c2_poll_task_builder =
freertos_task::TaskStarter<1024, PollerWithTimer>{};

static auto i2c2_poll_client =
i2c::poller::Poller<freertos_message_queue::FreeRTOSMessageQueue>{};

/**
* Start hepa_uv tasks.
*/
void hepauv_tasks::start_tasks(
can::bus::CanBus& can_bus,
gpio_drive_hardware::GpioDrivePins& gpio_drive_pins,
hepa_control_hardware::HepaControlHardware& hepa_hardware,
led_control_hardware::LEDControlHardware& led_hardware) {
led_control_hardware::LEDControlHardware& led_hardware,
i2c::hardware::I2CBase& i2c2,
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface) {
auto& can_writer = can_task::start_writer(can_bus);
can_task::start_reader(can_bus);

// TODO: including led_hardware for testing, this should be a AssesorClient
auto& i2c2_task = i2c2_task_builder.start(5, "i2c2", i2c2);
auto& i2c2_poller_task =
i2c2_poll_task_builder.start(5, "i2c2 poller", i2c2_task_client);
i2c2_poll_client.set_queue(&i2c2_poller_task.get_queue());
i2c2_task_client.set_queue(&i2c2_task.get_queue());
auto& eeprom_task = eeprom_task_builder.start(5, "eeprom", i2c2_task_client,
eeprom_hw_iface);

auto& hepa_task = hepa_task_builder.start(5, "hepa_fan", gpio_drive_pins,
hepa_hardware, queues);
hepa_hardware, queues, queues);
auto& uv_task =
uv_task_builder.start(5, "uv_ballast", gpio_drive_pins, queues);
uv_task_builder.start(5, "uv_ballast", gpio_drive_pins, queues, queues);
auto& led_control_task =
led_control_task_builder.start(5, "push_button_leds", led_hardware);

tasks.can_writer = &can_writer;
tasks.i2c2_task = &i2c2_task;
tasks.i2c2_poller_task = &i2c2_poller_task;
tasks.eeprom_task = &eeprom_task;
tasks.hepa_task_handler = &hepa_task;
tasks.uv_task_handler = &uv_task;
tasks.led_control_task_handler = &led_control_task;
tasks.can_writer = &can_writer;

queues.set_queue(&can_writer.get_queue());
queues.i2c2_queue = &i2c2_task.get_queue();
queues.i2c2_poller_queue = &i2c2_poller_task.get_queue();
queues.eeprom_queue = &eeprom_task.get_queue();
queues.hepa_queue = &hepa_task.get_queue();
queues.uv_queue = &uv_task.get_queue();
queues.led_control_queue = &led_control_task.get_queue();
Expand All @@ -57,6 +97,11 @@ void hepauv_tasks::start_tasks(
hepauv_tasks::QueueClient::QueueClient(can::ids::NodeId this_fw)
: can::message_writer::MessageWriter{this_fw} {}

void hepauv_tasks::QueueClient::send_eeprom_queue(
const eeprom::task::TaskMessage& m) {
eeprom_queue->try_write(m);
}

void hepauv_tasks::QueueClient::send_hepa_message(
const hepa_task::TaskMessage& m) {
hepa_queue->try_write(m);
Expand Down
8 changes: 5 additions & 3 deletions hepa-uv/firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ set(HEPAUV_FW_NON_LINTABLE_SRCS
${COMMON_EXECUTABLE_DIR}/system/iwdg.c
)

set(HEPAUV_SRCS_B1
set(HEPAUV_SRCS_A1
${HEPA_UV_FW_LINTABLE_SRCS}
${HEPAUV_FW_NON_LINTABLE_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/main_rev1.cpp
)
set(HEPAUV_SRCS_B1 ${HEPAUV_SRCS_A1})
set(HEPAUV_SRCS_C1 ${HEPAUV_SRCS_B1})
set(HEPAUV_SRCS_C2 ${HEPAUV_SRCS_C1})

Expand Down Expand Up @@ -81,10 +82,11 @@ endmacro()

foreach_revision(
PROJECT_NAME hepa-uv
REVISIONS b1
SOURCES HEPAUV_SRCS_B1
REVISIONS a1 b1
SOURCES HEPAUV_SRCS_A1 HEPAUV_SRCS_B1
CALL_FOREACH_REV hepa_uv_loop)

alias_for_revision(PROJECT_NAME hepa-uv REVISION a1 REVISION_ALIAS proto)
alias_for_revision(PROJECT_NAME hepa-uv REVISION b1 REVISION_ALIAS rev1)

add_clang_tidy_target(
Expand Down
Loading

0 comments on commit acc0fc5

Please sign in to comment.