Implemented RX on Node

This commit is contained in:
AlexanderHD27
2025-01-06 03:28:10 +01:00
parent caf7586b5b
commit 1e317adedd
29 changed files with 1646 additions and 2298 deletions

View File

@@ -7,8 +7,8 @@
"${userHome}/.pico-sdk/sdk/2.1.0/**"
],
"forcedInclude": [
"${userHome}/.pico-sdk/sdk/2.1.0/src/common/pico_base_headers/include/pico.h",
"${workspaceFolder}/build/generated/pico_base/pico/config_autogen.h"
"${workspaceFolder}/build/generated/pico_base/pico/config_autogen.h",
"${userHome}/.pico-sdk/sdk/2.1.0/src/common/pico_base_headers/include/pico.h"
],
"defines": [],
"compilerPath": "${userHome}/.pico-sdk/toolchain/13_3_Rel1/bin/arm-none-eabi-gcc",
@@ -19,4 +19,4 @@
}
],
"version": 4
}
}

View File

@@ -9,8 +9,12 @@
"args": ["-C", "${workspaceFolder}/build"],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"panel": "dedicated"
"focus": true,
"panel": "dedicated",
"showReuseMessage": true,
"clear": true
},
"problemMatcher": "$gcc",
"windows": {
@@ -27,8 +31,12 @@
"-fx"
],
"presentation": {
"echo": true,
"reveal": "always",
"panel": "dedicated"
"focus": true,
"panel": "shared",
"showReuseMessage": true,
"clear": true
},
"problemMatcher": [],
"windows": {
@@ -39,16 +47,51 @@
"label": "Flash",
"type": "process",
"command": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
"args": [
"-s",
"${userHome}/.pico-sdk/openocd/0.12.0+dev/scripts",
"-f", "interface/cmsis-dap.cfg",
"-f", "target/${command:raspberry-pi-pico.getTarget}.cfg",
"-c", "adapter speed 5000; program \"${command:raspberry-pi-pico.launchTargetPath}\" reset exit",
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "shared",
"showReuseMessage": true,
"clear": true
},
"dependsOn": ["Compile Project"],
"problemMatcher": [],
"windows": {
"command": "${env:USERPROFILE}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
}
},
{
"label": "Reset",
"type": "process",
"command": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
"args": [
"-s",
"${userHome}/.pico-sdk/openocd/0.12.0+dev/scripts",
"-f",
"interface/cmsis-dap.cfg",
"-f",
"target/${command:raspberry-pi-pico.getTarget}.cfg",
"-c",
"adapter speed 5000; program \"${command:raspberry-pi-pico.launchTargetPath}\" verify reset exit"
"-f", "target/${command:raspberry-pi-pico.getTarget}.cfg",
"-c", "adapter speed 5000; init; reset halt;",
"-c", "rp2040.core1 arp_reset assert 0",
"-c", "rp2040.core0 arp_reset assert 0",
"-c", "exit"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "shared",
"showReuseMessage": true,
"clear": true
},
"problemMatcher": [],
"windows": {
"command": "${env:USERPROFILE}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",

View File

@@ -34,6 +34,9 @@ project(vacum-control-firmware C CXX ASM)
set(FREERTOS_KERNEL_PATH ${CMAKE_CURRENT_LIST_DIR}/lib/FreeRTOS-Kernel)
include(cmake/FreeRTOS_Kernel_import.cmake)
# Adding GobotRPC Node Library
include(lib/gobotrpc/cmake/gobotRPC_Node.cmake)
# Initialise the Raspberry Pi Pico SDK
pico_sdk_init()
@@ -54,6 +57,7 @@ pico_enable_stdio_usb(vacum-control-firmware 0)
# Add the standard library to the build
target_link_libraries(vacum-control-firmware
pico_stdlib
GobotRPC_Node_RP2040_I2C
FreeRTOS-Kernel-Heap4
)

View File

@@ -72,8 +72,8 @@
/* Memory allocation related definitions. */
#define configSUPPORT_STATIC_ALLOCATION 0
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configTOTAL_HEAP_SIZE (1024 * 64)
#define configAPPLICATION_ALLOCATED_HEAP (1024 * 32)
#define configTOTAL_HEAP_SIZE (1024 * 128)
#define configAPPLICATION_ALLOCATED_HEAP (1024 * 64)
/* Hook function related definitions. */
#define configCHECK_FOR_STACK_OVERFLOW 0
@@ -104,11 +104,11 @@
#if FREE_RTOS_KERNEL_SMP // set by the RP2040 SMP port of FreeRTOS
/* SMP port only */
#define configUSE_PASSIVE_IDLE_HOOK 0
#define configNUMBER_OF_CORES 1
#define configNUMBER_OF_CORES 2
#define configTICK_CORE 0
#define configRUN_MULTIPLE_PRIORITIES 1
//#define configUSE_CORE_AFFINITY 1
#define configUSE_CORE_AFFINITY 1
#define configUSE_PASSIVE_IDLE_HOOK 0
#endif
/* RP2040 specific */

View File

@@ -1,10 +1,13 @@
#pragma once
#define CORE_MASK_GOBOTRPC 0b10
#define CORE_MASK_VACUM 0b01
#define LED1_PIN 16
#define LED2_PIN 25
#define RELAY_PIN 15
#define GORPC_INT_PIN 3
#define GORPC_INT_PIN 2
#define GORPC_SDA_PIN 4
#define GORPC_SCL_PIN 5

View File

@@ -1,5 +1,5 @@
#pragma once
#include "pinConfig.hpp"
#include "pinConfigNode.hpp"
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
@@ -9,6 +9,7 @@ void vButtonTaskFn(void *pvParameters);
class VacumControl {
private:
uint coreMask;
bool state = false;
xSemaphoreHandle vacumMutex;
xSemaphoreHandle interruptionSemaphore;
@@ -16,7 +17,7 @@ private:
xTaskHandle interruptionTask;
xTaskHandle buttonTask;
public:
VacumControl();
VacumControl(uint coreMask);
void initVacumPins();
void setState(bool on);

View File

@@ -0,0 +1 @@
/home/alexander/Projects/gobot/i2c-hub/firmware/i2c-hub-firmware/src/gobotrpc

View File

@@ -1,5 +1,5 @@
#include "vacum.hpp"
#include "pinConfig.hpp"
#include "pinConfigNode.hpp"
#include "FreeRTOS.h"
#include "task.h"
@@ -17,13 +17,14 @@ void vButtonTaskFn(void *pvParameters) {
vacumControl->buttonTaskFn();
}
VacumControl::VacumControl() {
VacumControl::VacumControl(uint coreMask) {
this->coreMask = coreMask;
initVacumPins();
state = false;
vacumMutex = xSemaphoreCreateMutex();
interruptionSemaphore = xSemaphoreCreateBinary();
xTaskCreate(vInterruptionTaskFn, "Interruption Task", 1024, this, 3, &interruptionTask);
xTaskCreate(vButtonTaskFn, "Button Task", 1024, this, 2, &buttonTask);
xTaskCreateAffinitySet(vInterruptionTaskFn, "Interruption Task", 1024, this, 3, coreMask, &interruptionTask);
xTaskCreateAffinitySet(vButtonTaskFn, "Button Task", 1024, this, 2, coreMask, &buttonTask);
}
void VacumControl::initVacumPins() {

View File

@@ -1,4 +1,5 @@
#include <stdio.h>
#include <string.h>
#include "pico/stdlib.h"
#include "vacum.hpp"
@@ -6,22 +7,88 @@
#include "FreeRTOSConfig.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
void vTaskFunction(void *pvParameters) {
while (true) {
printf("Button: %d\n", gpio_get(BUTTON_PIN));
vTaskDelay(pdMS_TO_TICKS(1000));
#include "hardware/i2c.h"
#include "pinConfigNode.hpp"
#include "node_interface_hardware.hpp"
#include "node_interface.hpp"
#include "protocol.hpp"
struct AppData {
xQueueHandle txQueue;
xQueueHandle rxQueue;
VacumControl * vacumControl;
GobotRPC_NI * gobotrpc_ni;
};
AppData g_appData;
void onRxPackage(void * args, char *data, uint16_t len, GobotRPCTypes type, GobotRPCNumber number) {
AppData * appData = (AppData *) args;
char txBuffer[32];
switch (number) {
case GobotRPCNumber::VACUM: {
GobotRPCPackage_Req_Vacum * pkg = (GobotRPCPackage_Req_Vacum *) data;
appData->vacumControl->setState(pkg->enable);
g_appData.gobotrpc_ni->sendPackage(txBuffer, 0, GobotRPCTypes::RESPONSE, GobotRPCNumber::VACUM);
break;
}
default: {
break;
}
}
}
void core1_main(void *pvParameters) {
AppData * appData = (AppData *) pvParameters;
GobotRPC_NI_Hardware_RP2040_I2C gobotrpc_ni_hardware(
appData->txQueue, appData->rxQueue, CORE_MASK_VACUM,
i2c0, 0x21, GORPC_SDA_PIN, GORPC_SCL_PIN, GORPC_INT_PIN
);
while (true) {
gpio_put(LED2_PIN, 0);
vTaskDelay(500 / portTICK_PERIOD_MS);
gpio_put(LED2_PIN, 1);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
TaskHandle_t xCore0TaskHandle = NULL;
TaskHandle_t xCore1TaskHandle = NULL;
int main() {
stdio_init_all();
printf("Hello, world!\n");
VacumControl vacumControl;
gpio_init(LED1_PIN);
gpio_set_dir(LED1_PIN, GPIO_OUT);
gpio_put(LED1_PIN, 1);
gpio_init(LED2_PIN);
gpio_set_dir(LED2_PIN, GPIO_OUT);
gpio_put(LED2_PIN, 1);
g_appData.txQueue = xQueueCreate(16, sizeof(GobotRPC_NI_Package_Transport));
g_appData.rxQueue = xQueueCreate(16, sizeof(GobotRPC_NI_Package_Transport));
VacumControl vacumControl = VacumControl(CORE_MASK_VACUM);
vacumControl.setState(false);
xTaskCreate(vTaskFunction, "Main Task", 1024, NULL, tskIDLE_PRIORITY, NULL);
g_appData.vacumControl = &vacumControl;
GobotRPC_NI gobotrpc_ni(CORE_MASK_VACUM, g_appData.txQueue, g_appData.rxQueue);
gobotrpc_ni.registerOnPackageRxCallback(onRxPackage, &g_appData);
g_appData.gobotrpc_ni = &gobotrpc_ni;
xTaskCreateAffinitySet(
core1_main, "Core 1 Main", 2048, &g_appData, 1, CORE_MASK_VACUM, &xCore1TaskHandle
);
vTaskStartScheduler();
while (true) {