From bac01e3a9b5960708f45f623f1006eb97abba62e Mon Sep 17 00:00:00 2001 From: AlexanderHD27 Date: Fri, 3 Jan 2025 12:48:10 +0100 Subject: [PATCH] Switched hub Freertos to multicore --- .../i2c-hub-firmware/FreeRTOSConfig.h | 5 ++- .../docs/.$NetworkStack.drawio.bkp | 8 ++-- .../i2c-hub-firmware/docs/NetworkStack.drawio | 37 +++++++++++++++---- .../src/gobotrpc/ctrl_interface/base.cpp | 4 +- .../uart_rp2040/hardware_rp2040_uart.cpp | 3 +- .../ctrl_interface/uart_rp2040/rx.cpp | 3 +- .../src/gobotrpc/include/ctrl_interface.hpp | 2 +- .../include/ctrl_interface_hardware.hpp | 6 ++- .../firmware/i2c-hub-firmware/src/main.cpp | 11 ++++-- 9 files changed, 55 insertions(+), 24 deletions(-) diff --git a/i2c-hub/firmware/i2c-hub-firmware/FreeRTOSConfig.h b/i2c-hub/firmware/i2c-hub-firmware/FreeRTOSConfig.h index 0fce63b..4373c80 100644 --- a/i2c-hub/firmware/i2c-hub-firmware/FreeRTOSConfig.h +++ b/i2c-hub/firmware/i2c-hub-firmware/FreeRTOSConfig.h @@ -104,10 +104,11 @@ #if FREE_RTOS_KERNEL_SMP // set by the RP2040 SMP port of FreeRTOS /* SMP port only */ -#define configNUMBER_OF_CORES 1 +#define configNUMBER_OF_CORES 2 #define configTICK_CORE 0 #define configRUN_MULTIPLE_PRIORITIES 1 -#define configUSE_CORE_AFFINITY 0 +#define configUSE_CORE_AFFINITY 1 +#define configUSE_PASSIVE_IDLE_HOOK 0 #endif /* RP2040 specific */ diff --git a/i2c-hub/firmware/i2c-hub-firmware/docs/.$NetworkStack.drawio.bkp b/i2c-hub/firmware/i2c-hub-firmware/docs/.$NetworkStack.drawio.bkp index 9067b56..43a95f5 100644 --- a/i2c-hub/firmware/i2c-hub-firmware/docs/.$NetworkStack.drawio.bkp +++ b/i2c-hub/firmware/i2c-hub-firmware/docs/.$NetworkStack.drawio.bkp @@ -1,6 +1,6 @@ - + @@ -810,9 +810,6 @@ - - - @@ -1099,6 +1096,9 @@ + + + diff --git a/i2c-hub/firmware/i2c-hub-firmware/docs/NetworkStack.drawio b/i2c-hub/firmware/i2c-hub-firmware/docs/NetworkStack.drawio index d2ca0c3..2b1ff49 100644 --- a/i2c-hub/firmware/i2c-hub-firmware/docs/NetworkStack.drawio +++ b/i2c-hub/firmware/i2c-hub-firmware/docs/NetworkStack.drawio @@ -1,6 +1,6 @@ - + @@ -1042,8 +1042,8 @@ - - + + @@ -1078,24 +1078,45 @@ - + - - + + - + - + + + + + + + + + + + + + + + + + + + + + + diff --git a/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/ctrl_interface/base.cpp b/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/ctrl_interface/base.cpp index fe751f8..ae69ba1 100644 --- a/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/ctrl_interface/base.cpp +++ b/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/ctrl_interface/base.cpp @@ -6,11 +6,11 @@ #include "task.h" -GobotRPC_CI::GobotRPC_CI(I_GobotRPC_CI_Hardware *hardware) { +GobotRPC_CI::GobotRPC_CI(I_GobotRPC_CI_Hardware *hardware, UBaseType_t core) { this->hardware = hardware; this->hardware->registerCB_RxData(GobotRPC_CI_rxData_cb, this); - xTaskCreate(GobotRPC_CI_heartBeatTaskFn, "Heartbeat Task", 2048, this, 2, &this->heartBeatTaskHandle); + xTaskCreateAffinitySet(GobotRPC_CI_heartBeatTaskFn, "Heartbeat Task", 2048, this, 2, core, &this->heartBeatTaskHandle); } // Rx Side diff --git a/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/ctrl_interface/uart_rp2040/hardware_rp2040_uart.cpp b/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/ctrl_interface/uart_rp2040/hardware_rp2040_uart.cpp index cad8b18..b2fcedb 100644 --- a/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/ctrl_interface/uart_rp2040/hardware_rp2040_uart.cpp +++ b/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/ctrl_interface/uart_rp2040/hardware_rp2040_uart.cpp @@ -12,8 +12,9 @@ // Initialize stuff GobotRPC_CI_Hardware_RP2040_UART * g_GobotRPC_CI_Hardware_RP2040_UART; -GobotRPC_CI_Hardware_RP2040_UART::GobotRPC_CI_Hardware_RP2040_UART(uart_inst_t *uart, uint baudrate) { +GobotRPC_CI_Hardware_RP2040_UART::GobotRPC_CI_Hardware_RP2040_UART(uart_inst_t *uart, uint baudrate, UBaseType_t core) { g_GobotRPC_CI_Hardware_RP2040_UART = this; + this->core = core; initRxTaskAndQueues(); diff --git a/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/ctrl_interface/uart_rp2040/rx.cpp b/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/ctrl_interface/uart_rp2040/rx.cpp index 2983b2c..b3e68eb 100644 --- a/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/ctrl_interface/uart_rp2040/rx.cpp +++ b/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/ctrl_interface/uart_rp2040/rx.cpp @@ -33,7 +33,8 @@ void GobotRPC_CI_Hardware_RP2040_UART::initRxTaskAndQueues() { } rxSignalSemaphore = xSemaphoreCreateBinary(); - xTaskCreate(GobotRPC_CI_Hardware_RP2040_UART_Task_RXProcessing, "UART RX Processing", 1024, this, 3, &this->rxProcessingTaskHandle); + + xTaskCreateAffinitySet(GobotRPC_CI_Hardware_RP2040_UART_Task_RXProcessing, "UART RX Processing", 1024, this, 3, core, &this->rxProcessingTaskHandle); } inputBufferRXState_t fillBuffer(inputBuffers_t * buffer, char data) { diff --git a/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/include/ctrl_interface.hpp b/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/include/ctrl_interface.hpp index b4c815a..3208f57 100644 --- a/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/include/ctrl_interface.hpp +++ b/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/include/ctrl_interface.hpp @@ -29,7 +29,7 @@ private: TaskHandle_t heartBeatTaskHandle; public: - GobotRPC_CI(I_GobotRPC_CI_Hardware *hardware); + GobotRPC_CI(I_GobotRPC_CI_Hardware *hardware, UBaseType_t core); void registerCB_TxPacket(callback_TxPacket cb, void *args); void send_RxPacket(char *data, size_t len, uint32_t addr); diff --git a/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/include/ctrl_interface_hardware.hpp b/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/include/ctrl_interface_hardware.hpp index 317d6e6..b78f64f 100644 --- a/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/include/ctrl_interface_hardware.hpp +++ b/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc/include/ctrl_interface_hardware.hpp @@ -45,7 +45,6 @@ private: inputBuffers_t inputBufferPool[NUM_INPUT_BUFFERS]; TaskHandle_t rxProcessingTaskHandle; - SemaphoreHandle_t rxSignalSemaphore; QueueHandle_t emptyInputBuffersQueue; @@ -56,12 +55,15 @@ private: SemaphoreHandle_t txMutex; + UBaseType_t core; + public: - GobotRPC_CI_Hardware_RP2040_UART(uart_inst_t *uart, uint baudrate); + GobotRPC_CI_Hardware_RP2040_UART(uart_inst_t *uart, uint baudrate, UBaseType_t core); void send(char *data, size_t len) override; void registerCB_RxData(callback_rxData cb, void *args); void initRxTaskAndQueues(); + void onRx_ISR(); void rxBufferingTaskFn(); void rxProcessingTaskFn(); diff --git a/i2c-hub/firmware/i2c-hub-firmware/src/main.cpp b/i2c-hub/firmware/i2c-hub-firmware/src/main.cpp index e8ab063..7d3dde8 100644 --- a/i2c-hub/firmware/i2c-hub-firmware/src/main.cpp +++ b/i2c-hub/firmware/i2c-hub-firmware/src/main.cpp @@ -12,6 +12,9 @@ #define LED_PIN 25 +#define UART_CORE_MASK 0b01 +#define I2C_CORE_MASK 0b10 + void vTaskMain(void * pvParameters) { while(1) { gpio_put(LED_PIN, 1); @@ -37,13 +40,15 @@ int main() { gpio_init(LED_PIN); gpio_set_dir(LED_PIN, true); - GobotRPC_CI_Hardware_RP2040_UART gobotrpc_ci_hardware(uart0, 115200); - GobotRPC_CI gobotRPC_ci(&gobotrpc_ci_hardware); + GobotRPC_CI_Hardware_RP2040_UART gobotrpc_ci_hardware(uart0, 115200, 0b01); + GobotRPC_CI gobotRPC_ci(&gobotrpc_ci_hardware, 0b01); gobotRPC_ci.registerCB_TxPacket(onTxPacket, &gobotRPC_ci); TaskHandle_t taskHandle; - xTaskCreate(vTaskMain, "Main Task", 2048, &gobotRPC_ci, 1, &taskHandle); + xTaskCreateAffinitySet(vTaskMain, "Main Task", 2048, &gobotRPC_ci, 1, UART_CORE_MASK, &taskHandle); + vTaskCoreAffinitySet(taskHandle, 0); + vTaskStartScheduler(); while(1) {}