Skip to content

Commit

Permalink
remove unused tasks
Browse files Browse the repository at this point in the history
remove copy/paste fragments
fix simulator and tests
remove i2c/spi/eeprom related files
  • Loading branch information
vegano1 committed Jan 12, 2024
1 parent 6dc6d3c commit 34ff65d
Show file tree
Hide file tree
Showing 22 changed files with 36 additions and 834 deletions.
9 changes: 1 addition & 8 deletions common/firmware/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,4 @@ __attribute__((section( ".ccmram" )))
#endif
bool gpio_is_set(void* port, uint16_t pin, uint8_t active_setting) {
return HAL_GPIO_ReadPin(port, pin) == active_setting;
}

#ifdef ENABLE_CCMRAM
__attribute__((section( ".ccmram" )))
#endif
uint8_t gpio_read(void* port, uint16_t pin) {
return HAL_GPIO_ReadPin(port, pin);
}
}
10 changes: 1 addition & 9 deletions common/firmware/gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,4 @@ __attribute__((section( ".ccmram" )))
auto gpio::is_set(const gpio::PinConfig& pc)
-> bool {
return gpio_is_set(pc.port, pc.pin, pc.active_setting);
}

#ifdef ENABLE_CCMRAM
__attribute__((section( ".ccmram" )))
#endif
auto gpio::read_pin(const gpio::PinConfig& pc)
-> uint8_t {
return gpio_read(pc.port, pc.pin);
}
}
2 changes: 1 addition & 1 deletion hepa-uv/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function(target_hepauv_core TARGET)
function(target_hepa_uv_core TARGET)
target_sources(${TARGET} PUBLIC
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/can_tasks.cpp
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/tasks.cpp)
Expand Down
20 changes: 1 addition & 19 deletions hepa-uv/core/can_tasks.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <span>

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

using namespace can::dispatch;
Expand All @@ -10,10 +9,6 @@ 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 gripper_info_handler =
gripper_info::GripperInfoMessageHandler{main_queues, main_queues};

/** Handler of system messages. */
static auto system_message_handler =
can::message_handlers::system::SystemMessageHandler{
Expand All @@ -27,18 +22,6 @@ 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 gripper_info_dispatch_target =
can_task::GripperInfoDispatchTarget{gripper_info_handler};

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

auto static reader_message_buffer =
freertos_message_buffer::FreeRTOSMessageBuffer<1024>{};
Expand Down
114 changes: 2 additions & 112 deletions hepa-uv/core/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

#include "common/core/freertos_task.hpp"
#include "common/core/freertos_timer.hpp"
#include "eeprom/core/dev_data.hpp"
#include "hepa-uv/core/can_task.hpp"
#include "hepa-uv/firmware/eeprom_keys.hpp"
#include "hepa-uv/firmware/gpio_drive_hardware.hpp"
#include "spi/core/tasks/spi_task.hpp"
#include "spi/core/writer.hpp"

#pragma GCC diagnostic push
// NOLINTNEXTLINE(clang-diagnostic-unknown-warning-option)
Expand All @@ -18,124 +13,19 @@
static auto tasks = hepauv_tasks::AllTask{};
static auto queues = hepauv_tasks::QueueClient{can::ids::NodeId::hepa_uv};

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

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

static auto i2c2_task_builder =
freertos_task::TaskStarter<512, i2c::tasks::I2CTask>{};
static auto i2c3_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 i2c3_poll_task_builder =
freertos_task::TaskStarter<1024, PollerWithTimer>{};

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

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

// PushButtonBlink Test Task
static auto pushbutton_task_builder =
freertos_task::TaskStarter<512, pushbutton_task::PushButtonTask>{};

static auto gpio_drive_pins = gpio_drive_hardware::GpioDrivePins {
.push_button_led = gpio::PinConfig {
.port = LED_DRIVE_PORT,
.pin = LED_DRIVE_PIN,
.active_setting = GPIO_PIN_SET
},
.push_button = gpio::PinConfig {
.port = HEPA_NO_MCU_PORT,
.pin = HEPA_NO_MCU_PIN,
.active_setting = GPIO_PIN_SET
},
.reed_switch = gpio::PinConfig {
.port = REED_SW_MCU_PORT,
.pin = REED_SW_MCU_PIN,
.active_setting = GPIO_PIN_SET
},
.door_open = gpio::PinConfig {
.port = DOOR_OPEN_MCU_PORT,
.pin = DOOR_OPEN_MCU_PIN,
.active_setting = GPIO_PIN_SET
}
};


/**
* Start gripper tasks.
* Start hepa_uv tasks.
*/
void hepauv_tasks::start_tasks(
can::bus::CanBus& can_bus,
i2c::hardware::I2CBase& i2c2, i2c::hardware::I2CBase& i2c3,
eeprom::hardware_iface::EEPromHardwareIface& eeprom_hw_iface) {
void hepauv_tasks::start_tasks(can::bus::CanBus& can_bus) {
auto& can_writer = can_task::start_writer(can_bus);
can_task::start_reader(can_bus);
tasks.can_writer = &can_writer;
queues.set_queue(&can_writer.get_queue());

auto& i2c2_task = i2c2_task_builder.start(5, "i2c2", i2c2);
i2c2_task_client.set_queue(&i2c2_task.get_queue());
auto& i2c3_task = i2c3_task_builder.start(5, "i2c3", i2c3);
i2c3_task_client.set_queue(&i2c3_task.get_queue());

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());
auto& i2c3_poller_task =
i2c3_poll_task_builder.start(5, "i2c3 poller", i2c3_task_client);
i2c3_poll_client.set_queue(&i2c3_poller_task.get_queue());

auto& eeprom_task = eeprom_task_builder.start(5, "eeprom", i2c3_task_client,
eeprom_hw_iface);
#if PCBA_PRIMARY_REVISION != 'b'
auto& eeprom_data_rev_update_task = eeprom_data_rev_update_builder.start(
5, "data_rev_update", queues, tail_accessor, table_updater);
#endif

tasks.i2c2_task = &i2c2_task;
tasks.i2c3_task = &i2c3_task;
tasks.i2c2_poller_task = &i2c2_poller_task;
tasks.i2c3_poller_task = &i2c3_poller_task;
tasks.eeprom_task = &eeprom_task;
#if PCBA_PRIMARY_REVISION != 'b'
tasks.update_data_rev_task = &eeprom_data_rev_update_task;
#endif

queues.i2c2_queue = &i2c2_task.get_queue();
queues.i2c3_queue = &i2c3_task.get_queue();
queues.i2c2_poller_queue = &i2c2_poller_task.get_queue();
queues.i2c3_poller_queue = &i2c3_poller_task.get_queue();
queues.eeprom_queue = &eeprom_task.get_queue();

// PushButtonBlink Test Task
auto& pushbutton_task =
pushbutton_task_builder.start(5, "pushbutton", gpio_drive_pins);
tasks.pushbutton_task = &pushbutton_task;
}

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);
}

/**
* Access to the tasks singleton
* @return
Expand Down
3 changes: 1 addition & 2 deletions hepa-uv/firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ set(REVISIONS hepa-rev1)
# Add source files that should be checked by clang-tidy here
set(HEPAUV_FW_LINTABLE_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/freertos_idle_timer_task.cpp
${CMAKE_CURRENT_SOURCE_DIR}/eeprom_keys.cpp
${COMMON_EXECUTABLE_DIR}/system/iwdg.cpp
${CAN_FW_DIR}/hal_can_bus.cpp
${CAN_FW_DIR}/utils.c
Expand Down Expand Up @@ -64,7 +63,7 @@ macro(hepauv_loop)
STM32G4xx_FreeRTOS_${_driver_suffix}
PROPERTIES FREERTOS_HEAP_IMPLEMENTATION "heap_5")

target_hepauv_core(${REVISION_TARGET})
target_hepa_uv_core(${REVISION_TARGET})
target_ot_motor_control(${REVISION_TARGET})

target_i2c_firmware(${REVISION_TARGET})
Expand Down
34 changes: 0 additions & 34 deletions hepa-uv/firmware/eeprom_keys.cpp

This file was deleted.

35 changes: 1 addition & 34 deletions hepa-uv/firmware/main_rev1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
#include "common/firmware/gpio.hpp"
#include "common/firmware/iwdg.hpp"
#include "common/firmware/utility_gpio.h"
#include "hepa-uv/core/interfaces.hpp"
#include "hepa-uv/core/tasks.hpp"
#include "hepa-uv/firmware/utility_gpio.h"
#include "i2c/firmware/i2c_comms.hpp"
#include "sensors/firmware/sensor_hardware.hpp"

static auto iWatchdog = iwdg::IndependentWatchDog{};

Expand Down Expand Up @@ -56,46 +53,16 @@ static constexpr auto can_bit_timings =
can::bit_timings::BitTimings<170 * can::bit_timings::MHZ, 100,
500 * can::bit_timings::KHZ, 800>{};

/**
* I2C handles
*/
static auto i2c_comms2 = i2c::hardware::I2C();
static auto i2c_comms3 = i2c::hardware::I2C();
static auto i2c_handles = I2CHandlerStruct{};

static constexpr auto eeprom_chip =
eeprom::hardware_iface::EEPromChipType::ST_M24128_BF;

class EEPromHardwareInterface
: public eeprom::hardware_iface::EEPromHardwareIface {
public:
EEPromHardwareInterface()
: eeprom::hardware_iface::EEPromHardwareIface(eeprom_chip) {}
void set_write_protect(bool enable) final {
if (enable) {
disable_eeprom_write();
} else {
enable_eeprom_write();
}
}
};
static auto eeprom_hw_iface = EEPromHardwareInterface();

auto main() -> int {
HardwareInit();
RCC_Peripheral_Clock_Select();
utility_gpio_init();

app_update_clear_flags();

i2c_setup(&i2c_handles);
i2c_comms2.set_handle(i2c_handles.i2c2);
i2c_comms3.set_handle(i2c_handles.i2c3);

canbus.start(can_bit_timings);

hepauv_tasks::start_tasks(
canbus, i2c_comms2, i2c_comms3, eeprom_hw_iface);
hepauv_tasks::start_tasks(canbus);

iWatchdog.start(6);

Expand Down
28 changes: 13 additions & 15 deletions hepa-uv/simulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,38 @@ list(APPEND FREERTOS_SOURCES "${FreeRTOS_SOURCE_DIR}/FreeRTOS/Source/portable/Th


# Create the freertos lib
add_library(freertos-gripper STATIC ${FREERTOS_SOURCES})
add_library(freertos-hepa-uv STATIC ${FREERTOS_SOURCES})

set(GRIPPER_SIMULATOR_SRC
set(HEPA_UV_SIMULATOR_SRC
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/interfaces.cpp
${CMAKE_CURRENT_SOURCE_DIR}/freertos_idle_timer_task.cpp
${CMAKE_CURRENT_SOURCE_DIR}/eeprom_keys.cpp
)

add_executable(
gripper-simulator
${GRIPPER_SIMULATOR_SRC}
hepa-uv-simulator
${HEPA_UV_SIMULATOR_SRC}
)

add_revision(TARGET gripper-simulator REVISION a1)
add_revision(TARGET hepa-uv-simulator REVISION a1)


if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux" AND DEFINED ENV{USE_SOCKETCAN})
target_compile_definitions(gripper-simulator PUBLIC USE_SOCKETCAN)
target_compile_definitions(hepa-uv-simulator PUBLIC USE_SOCKETCAN)
endif ()

target_compile_definitions(gripper-simulator PUBLIC ENABLE_LOGGING)
target_compile_definitions(hepa-uv-simulator PUBLIC ENABLE_LOGGING)

target_can_simlib(gripper-simulator)
target_can_simlib(hepa-uv-simulator)

target_gripper_core(gripper-simulator)
target_hepa_uv_core(hepa-uv-simulator)

target_ot_motor_control(gripper-simulator)
target_ot_motor_control(hepa-uv-simulator)

target_i2c_simlib(gripper-simulator)
target_i2c_simlib(hepa-uv-simulator)

target_link_libraries(gripper-simulator PRIVATE can-core common-simulation freertos-gripper pthread Boost::boost Boost::program_options state_manager)
target_link_libraries(hepa-uv-simulator PRIVATE can-core common-simulation freertos-hepa-uv pthread Boost::boost Boost::program_options state_manager)

set_target_properties(gripper-simulator
set_target_properties(hepa-uv-simulator
PROPERTIES CXX_STANDARD 20
CXX_STANDARD_REQUIRED TRUE
C_STANDARD 11
Expand Down
Loading

0 comments on commit 34ff65d

Please sign in to comment.