34 Commits

Author SHA1 Message Date
AlexanderHD27
db464efa36 Added Transmission Sucess 2025-01-03 20:10:15 +01:00
AlexanderHD27
aa9d00bf6e Implement I2C 2025-01-03 19:54:13 +01:00
AlexanderHD27
bac01e3a9b Switched hub Freertos to multicore 2025-01-03 12:48:10 +01:00
AlexanderHD27
1fd8737fe4 Fixed major UART Issue, I hate it 2025-01-03 12:33:51 +01:00
AlexanderHD27
cbf702c6d5 Implemented PACKET_RX,PACKET_TX and Heartbeat of GobotRPC_CtrlInterface 2025-01-03 02:24:34 +01:00
AlexanderHD27
894d5f4380 Implement First Message for Gobot Ctrl Interface 2025-01-02 23:03:23 +01:00
AlexanderHD27
78a5148a1e Finished Head Softaware 2025-01-02 19:10:59 +01:00
AlexanderHD27
0bb125fad9 Finished Firmware for Vacum 2025-01-02 03:55:45 +01:00
AlexanderHD27
ad61e7e9b7 Goto CoreXY to work 2025-01-01 19:44:15 +01:00
AlexanderHD27
c136056ed2 Got homing sequenc to work, ....again 2025-01-01 16:47:53 +01:00
AlexanderHD27
edc2dd6294 Renamed Files and added Heart beat 2024-12-30 17:17:07 +01:00
AlexanderHD27
58043ee0d5 Paritailly implement UART for RP2040 for the GobotRPC Controller Interface 2024-12-30 16:09:39 +01:00
AlexanderHD27
65df7b1912 Implemented UART_CTRL Interface (missing Hardware implementation) 2024-12-30 02:23:38 +01:00
AlexanderHD27
877040362c Build RPC Parsers 2024-12-30 00:46:36 +01:00
AlexanderHD27
ec2225aa4e Got Pico SDK + FreeRTOS to work 2024-12-29 17:30:22 +01:00
AlexanderHD27
6ef60a3f2f Merge branch 'motor-ctrl-firmware' into i2c-helpere
# Conflicts:
#	.gitmodules
#	can-interface/.gitignore
#	can-interface/.vscode/settings.json
#	can-interface/main/CMakeLists.txt
#	can-interface/main/hello_world_main.cpp
#	common-libaries/mcp2521/include/mcp2521.hpp
#	common-libaries/mcp2521/include/mcp2521_command.hpp
#	common-libaries/mcp2521/include/mcp2521_toplevel.hpp
#	common-libaries/mcp2521/interface_commands.cpp
#	common-libaries/mcp2521/interface_interrupts.cpp
#	common-libaries/mcp2521_hardware_interface/CMakeLists.txt
#	common-libaries/mcp2521_hardware_interface/esp_implementation_cmd.cpp
#	common-libaries/mcp2521_hardware_interface/esp_implementation_init.cpp
#	common-libaries/mcp2521_hardware_interface/esp_implementation_int.cpp
#	common-libaries/mcp2521_hardware_interface/include/mcp2521_hardware_esp.hpp
#	common-libaries/mcp2521_hardware_interface/include/mcp2521_hardware_handle.hpp
#	motor-control/firmware/cmake/tmc2209.cmake
2024-12-29 11:40:22 +01:00
AlexanderHD27
6f107aea76 Added Circuit 2024-12-29 11:37:43 +01:00
AlexanderHD27
801e791199 Did stuff 2024-12-28 22:47:46 +01:00
AlexanderHD27
bdec2db94d Gobot RPC Stack 2024-11-27 23:29:05 +01:00
AlexanderHD27
c1dc89eb58 Implement Multi-Bus CAN Interfaces 2024-11-23 01:25:29 +01:00
AlexanderHD27
f26cc07558 Create Spec for CAN-Protocol Stack and Doc of CAN-Interface Circuit 2024-11-12 00:20:48 +01:00
AlexanderHD27
c6fd825e39 Moved CAN Interface code to comment libary folder with symlink 2024-11-06 23:14:14 +01:00
AlexanderHD27
e7a0035041 Got MCP2521 to work 2024-11-06 22:01:28 +01:00
AlexanderHD27
4bfb1f533e Did something to YGantryMount. It works. trust me 2024-10-16 21:29:35 +02:00
AlexanderHD27
5683168a47 Implemented Command-Level Interaction with CAN Interface 2024-10-16 21:28:36 +02:00
AlexanderHD27
9c0c676be8 Added Vscode Profile file 2024-10-14 09:20:37 +02:00
AlexanderHD27
b150a905a3 Implemented Low Level Compunications 2024-10-14 09:19:00 +02:00
AlexanderHD27
7eebf619ae Created Head Pipe Mount 2024-10-07 14:46:15 +02:00
AlexanderHD27
93c40e1805 First Revision of YGantryMount 2024-10-07 14:44:11 +02:00
AlexanderHD27
91c2125458 Added Kicad Backups 2 gitignore 2024-10-03 19:53:11 +02:00
AlexanderHD27
096a6c18d6 Created ESP-IDF for can-interface 2024-10-03 19:49:21 +02:00
AlexanderHD27
48fded7981 Added files from Pico sdk to gitignore 2024-09-28 19:54:29 +02:00
AlexanderHD27
ec5e5cbf13 Create Marker for position Calibration 2024-09-14 21:09:50 +02:00
AlexanderHD27
58d31964b2 Upgrade to pico SDK 2.0.0 2024-09-13 22:15:15 +02:00
257 changed files with 47774 additions and 114 deletions

BIN
.gitmodules (Stored with Git LFS) vendored

Binary file not shown.

BIN
can-interface/.gitignore (Stored with Git LFS) vendored

Binary file not shown.

View File

@@ -14,6 +14,8 @@
"idf.pythonBinPath": "/home/alexander/.espressif/python_env/idf5.3_py3.12_env/bin/python",
"idf.toolsPath": "/home/alexander/.espressif",
"idf.flashType": "UART",
"idf.openOcdLaunchArgs": ["-c", "adapter_khz 1000"],
"idf.openOcdDebugLevel": 2,
"files.associations": {
"*.tcc": "cpp",
"cstdint": "cpp",
@@ -24,6 +26,7 @@
"regex": "cpp",
"array": "cpp",
"string": "cpp",
"span": "cpp"
"span": "cpp",
"cstring": "cpp"
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1 @@
<!DOCTYPE HTML><html lang="en-US"> <head> <meta charset="UTF-8"> <meta http-equiv="refresh" content="0; url=https://www.snapeda.com/about/import/#"> <script type="text/javascript">window.location.href="https://www.snapeda.com/about/import/#" </script> <title>Page Redirection</title> </head> <body> If you are not redirected automatically, follow this <a href="https://www.snapeda.com/about/import/#">link to the import guide</a>. </body></html>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,4 @@
(sym_lib_table
(version 7)
(lib (name "ESP32-DEVKIT-V1")(type "KiCad")(uri "${KIPRJMOD}/external/ESP32-DEVKIT-V1/ESP32-DEVKIT-V1.kicad_sym")(options "")(descr ""))
)

Binary file not shown.

BIN
can-interface/circuit/i2c-hub/i2c-hub.kicad_prl (Stored with Git LFS) Normal file

Binary file not shown.

BIN
can-interface/circuit/i2c-hub/i2c-hub.kicad_pro (Stored with Git LFS) Normal file

Binary file not shown.

View File

@@ -0,0 +1 @@
/home/alexander/Projects/gobot/common-libaries/gobot_rpc

2866
can-interface/docs/Doxyfile Normal file

File diff suppressed because it is too large Load Diff

Submodule can-interface/docs/doxygen-awesome-css added at 568f56cde6

View File

@@ -2,5 +2,6 @@ idf_component_register(SRCS "hello_world_main.cpp"
REQUIRES driver
REQUIRES mcp2521
REQUIRES mcp2521_hardware_interface
REQUIRES gobot_rpc
REQUIRES spi_flash
INCLUDE_DIRS "")

View File

@@ -23,26 +23,43 @@
#include "mcp2521.hpp"
#define SPI_PIN_CS0 GPIO_NUM_5
#define SPI_PIN_SCLK GPIO_NUM_18
#define SPI_PIN_MISO GPIO_NUM_19
#define SPI_PIN_MOSI GPIO_NUM_23
#define CAN_INT_PIN GPIO_NUM_21
#define EXTERNAL_TRIGGER GPIO_NUM_26
#define SPI_PIN_CS0 GPIO_NUM_25
#define SPI_PIN_CS1 GPIO_NUM_27
void onRX(void *arg) {
#define CAN_INT0_PIN GPIO_NUM_5
#define CAN_INT1_PIN GPIO_NUM_26
void onRX0(void *arg) {
MCP2521 *mcp2521 = (MCP2521 *)arg;
rx_info info = mcp2521->get_rx_id(MCP2521_RX_BUFFER::RXB0);
uint8_t data[8];
mcp2521->read_rx_buf(MCP2521_RX_BUFFER::RXB0, MCP2521_BUFFER_TYPE::DATA, data, info.length);
//mcp2521->read_rx_buf(MCP2521_RX_BUFFER::RXB0, MCP2521_BUFFER_TYPE::DATA, data, info.length);
printf("RX0: (%x) ", info.id);
//for (int i = 0; i < 8; i++) {
// printf("%x ", data[i]);
//}
printf("\n");
}
void onRX1(void *arg) {
MCP2521 *mcp2521 = (MCP2521 *)arg;
rx_info info = mcp2521->get_rx_id(MCP2521_RX_BUFFER::RXB0);
uint8_t data[8];
//mcp2521->read_rx_buf(MCP2521_RX_BUFFER::RXB0, MCP2521_BUFFER_TYPE::DATA, data, info.length);
printf("RX1: (%x) ", info.id);
//for (int i = 0; i < 8; i++) {
// printf("%x ", data[i]);
//}
printf("RX: (%x) ", info.id);
for (int i = 0; i < info.length; i++) {
printf("%x ", data[i]);
}
printf("\n");
}
@@ -52,46 +69,58 @@ extern "C" void app_main() {
const gpio_num_t LED_PIN = GPIO_NUM_2;
gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);
gpio_set_direction(EXTERNAL_TRIGGER, GPIO_MODE_OUTPUT);
gpio_set_level(EXTERNAL_TRIGGER, true);
vTaskDelay(100 / portTICK_PERIOD_MS);
MCP2521_HardwareHandleFactory_ESPBus mcp2521_hardware_factory(
VSPI_HOST,
SPI_PIN_MOSI,
SPI_PIN_MISO,
SPI_PIN_SCLK
);
MCP2521_HardwareHandle_ESPBus hardware_mcp2521_0 = mcp2521_hardware_factory.create(CAN_INT0_PIN, SPI_PIN_CS0);
MCP2521_HardwareHandle_ESPBus hardware_mcp2521_1 = mcp2521_hardware_factory.create(CAN_INT1_PIN, SPI_PIN_CS1);
vTaskDelay(100 / portTICK_PERIOD_MS);
MCP2521 mcp2521_0(&hardware_mcp2521_0);
MCP2521 mcp2521_1(&hardware_mcp2521_1);
spi_bus_config_t spi_bus;
uint8_t data[8] = {0x1, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
MCP2521_Hardware_Handle_ESP hardware_mcp2521(
VSPI_HOST,
&spi_bus,
SPI_PIN_MOSI,
SPI_PIN_MISO,
SPI_PIN_SCLK,
SPI_PIN_CS0,
CAN_INT_PIN
);
mcp2521_0.reset();
mcp2521_1.reset();
mcp2521_0.enable_interrupts(true, true, true, true, true, true, true, true);
mcp2521_1.enable_interrupts(true, true, true, true, true, true, true, true);
MCP2521 mcp2521(&hardware_mcp2521);
mcp2521_0.register_rx0_handler(onRX0, &mcp2521_0);
mcp2521_1.register_rx0_handler(onRX1, &mcp2521_1);
mcp2521_0.register_rx1_handler(onRX0, &mcp2521_0);
mcp2521_1.register_rx1_handler(onRX1, &mcp2521_1);
uint8_t data[4] = {0xf0, 0x42, 0x13, 0x37};
mcp2521_0.set_mode_of_operation(MCP2521_OPERATION_MODE::LOOPBACK, true);
mcp2521_1.set_mode_of_operation(MCP2521_OPERATION_MODE::LOOPBACK, true);
gpio_set_level(EXTERNAL_TRIGGER, false);
mcp2521.reset();
mcp2521.enable_interrupts(true, true, true, true, true, true, true, true);
//printf("CANSTAT0: %x\n", mcp2521_0.read_reg(MCP2521_CANSTAT));
//printf("CANSTAT1: %x\n", mcp2521_1.read_reg(MCP2521_CANSTAT));
mcp2521.register_rx0_handler(onRX, &mcp2521);
mcp2521.register_rx1_handler(onRX, &mcp2521);
mcp2521.set_mode_of_operation(MCP2521_OPERATION_MODE::LOOPBACK, true);
vTaskDelay(20 / portTICK_PERIOD_MS);
vTaskDelay(3 / portTICK_PERIOD_MS);
mcp2521_1.prepare_tx(
MCP2521_TX_BUFFER::TXB0, 0x042, data, 8, false, false);
//mcp2521_1.prepare_tx(
// MCP2521_TX_BUFFER::TXB0, 0x041, data, 4, false, false);
mcp2521.prepare_tx(
MCP2521_TX_BUFFER::TXB0, 0x042, data, 4, false, false);
mcp2521.request_to_send(MCP2521_TX_BUFFER::TXB0);
vTaskDelay(20 / portTICK_PERIOD_MS);
mcp2521_1.request_to_send(MCP2521_TX_BUFFER::TXB0);
//vTaskDelay(10 / portTICK_PERIOD_MS);
//mcp2521_1.request_to_send(MCP2521_TX_BUFFER::TXB0);
mcp2521.set_tx_id(MCP2521_TX_BUFFER::TXB0, 0x041, false);
mcp2521.request_to_send(MCP2521_TX_BUFFER::TXB0);
//vTaskDelay(20 / portTICK_PERIOD_MS);
//mcp2521_0.set_tx_id(MCP2521_TX_BUFFER::TXB0, 0x042, false);
//mcp2521_0.request_to_send(MCP2521_TX_BUFFER::TXB0);
vTaskDelay(20 / portTICK_PERIOD_MS);
@@ -100,6 +129,6 @@ extern "C" void app_main() {
gpio_set_level(LED_PIN, flag);
flag = !flag;
vTaskDelay(100 / portTICK_PERIOD_MS);
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}

2008
can-interface/sdkconfig.old Normal file

File diff suppressed because it is too large Load Diff

152
can-interface/session-setup Normal file
View File

@@ -0,0 +1,152 @@
[General]
decode_signals=2
meta_objs=0
views=1
[D0]
color=4291714048
conv_options=0
conversion_type=0
enabled=true
name=INT0
[D1]
color=4281623972
conv_options=0
conversion_type=0
enabled=true
name=CLK
[D2]
color=4281623972
conv_options=0
conversion_type=0
enabled=true
name=MOSI
[D3]
color=4281623972
conv_options=0
conversion_type=0
enabled=true
name=MISO
[D4]
color=4294277376
conv_options=0
conversion_type=0
enabled=true
name=CE0
[D5]
color=4279638298
conv_options=0
conversion_type=0
enabled=true
name=INT1
[D6]
color=4279638298
conv_options=0
conversion_type=0
enabled=true
name=CE1
[D7]
color=4285878395
conv_options=0
conversion_type=0
enabled=true
name=D7
[decode_signal0]
channel0\assigned_signal_name=CLK
channel0\initial_pin_state=2
channel0\name=CLK
channel1\assigned_signal_name=MISO
channel1\initial_pin_state=2
channel1\name=MISO
channel2\assigned_signal_name=MOSI
channel2\initial_pin_state=2
channel2\name=MOSI
channel3\assigned_signal_name=CE0
channel3\initial_pin_state=2
channel3\name=CS#
channels=4
color=4294277376
conv_options=0
conversion_type=0
decoder0\ann_class0\visible=true
decoder0\ann_class1\visible=true
decoder0\ann_class2\visible=true
decoder0\ann_class3\visible=true
decoder0\ann_class4\visible=true
decoder0\ann_class5\visible=true
decoder0\ann_class6\visible=true
decoder0\id=spi
decoder0\options=0
decoder0\row0\visible=true
decoder0\row1\visible=true
decoder0\row2\visible=true
decoder0\row3\visible=true
decoder0\row4\visible=true
decoder0\row5\visible=true
decoder0\row6\visible=true
decoder0\visible=true
decoders=1
enabled=true
name=SPI0
[decode_signal1]
channel0\assigned_signal_name=CLK
channel0\initial_pin_state=2
channel0\name=CLK
channel1\assigned_signal_name=MISO
channel1\initial_pin_state=2
channel1\name=MISO
channel2\assigned_signal_name=MOSI
channel2\initial_pin_state=2
channel2\name=MOSI
channel3\assigned_signal_name=CE1
channel3\initial_pin_state=2
channel3\name=CS#
channels=4
color=4279638298
conv_options=0
conversion_type=0
decoder0\ann_class0\visible=true
decoder0\ann_class1\visible=true
decoder0\ann_class2\visible=true
decoder0\ann_class3\visible=true
decoder0\ann_class4\visible=true
decoder0\ann_class5\visible=true
decoder0\ann_class6\visible=true
decoder0\id=spi
decoder0\options=0
decoder0\row0\visible=true
decoder0\row1\visible=true
decoder0\row2\visible=true
decoder0\row3\visible=true
decoder0\row4\visible=true
decoder0\row5\visible=true
decoder0\row6\visible=true
decoder0\visible=true
decoders=1
enabled=true
name=SPI1
[view0]
D0\trace_height=38
D1\trace_height=38
D2\trace_height=38
D3\trace_height=38
D4\trace_height=38
D5\trace_height=38
D6\trace_height=38
D7\trace_height=38
offset=22 serialization::archive 19 0 0 0 0 52315583 48568089 25582163 47181659 91047901 0 -8 1 0 6
scale=0.0021854614351496547
segment_display_mode=1
splitter_state=@ByteArray(\0\0\0\xff\0\0\0\x1\0\0\0\x2\0\0\0Z\0\0\x5\xa2\x1\0\0\0\x1\x1\0\0\0\x1\0)
v_offset=-10
zero_offset=22 serialization::archive 19 0 0 0 0 0 0 0 0 0 0 0 0 0 6

View File

@@ -0,0 +1,10 @@
idf_component_register(SRCS
"gobot_rpc_sender.cpp"
"gobot_rpc_receiver.cpp"
"gobot_rpc_statemaschine.cpp"
"gobot_rpc_numberMap.cpp"
"gobot_rpc_transiver.cpp"
REQUIRES mcp2521
REQUIRES mcp2521_hardware_interface
REQUIRES driver
INCLUDE_DIRS "include")

View File

@@ -0,0 +1,19 @@
#include "gobot_rpc.hpp"
#include "protocol_spec.hpp"
#include <string.h>
GobotRPCNumberMap::GobotRPCNumberMap() {
memset(rpc_number_map, 0xffffffff, 16);
}
GobotRPCNumberMap::~GobotRPCNumberMap() {
}
void GobotRPCNumberMap::set(RpcNum rpc_num, uint32_t id) {
rpc_number_map[(int)rpc_num] = id;
}
uint32_t GobotRPCNumberMap::get(RpcNum rpc_num) {
return rpc_number_map[(int)rpc_num];
}

View File

@@ -0,0 +1,43 @@
#include <string.h>
#include "gobot_rpc.hpp"
#include "sm.hpp"
#include "protocol_spec.hpp"
#include "freertos/FreeRTOS.h"
GobotRPCReciver::GobotRPCReciver(MCP2521 * can_interface) {
this->can_interface = can_interface;
this->state_mashine = GobotRPCStateMashine();
can_interface->register_rx0_handler(onRX0_GoboRPC, can_interface);
}
void onRX0_GoboRPC(void *arg) {
GobotRPCReciver *rpc_socket = (GobotRPCReciver *)arg;
rpc_socket->onRX();
}
void GobotRPCReciver::onRX() {
rx_info info = can_interface->get_rx_id(MCP2521_RX_BUFFER::RXB0);
uint8_t data[8];
can_interface->read_rx_buf(MCP2521_RX_BUFFER::RXB0, MCP2521_BUFFER_TYPE::DATA, data, info.length);
RPCFrame frame;
memcpy(((char *)data) + 1, (char *)frame.data, 7);
frame.header = (RPCHeader)(data[0]);
SMResult smResult;
state_mashine.submitFrame(&frame, &smResult);
if(smResult.done) {
}
}
void GobotRPCReciver::registerOnDoneFrameHandler(GobotRPCHandler_t handler, void * arg) {
onDoneFrameHandler = handler;
argOnDoneFrameHandler = arg;
}

View File

@@ -0,0 +1,74 @@
#include "sm.hpp"
#include "protocol_spec.hpp"
#include <string.h>
GobotRPCStateMashine::GobotRPCStateMashine() {
memset(requestDataBuffer, 0, REQUEST_DATA_BUFFER_SIZE*sizeof(uint8_t)*SLOTS);
memset(responseDataBuffer, 0, RESPONSE_DATA_BUFFER_SIZE*sizeof(uint8_t)*SLOTS);
memset(errorDataBuffer, 0, RESPONSE_DATA_BUFFER_SIZE*sizeof(uint8_t)*SLOTS);
memset(requestSegmentArrivedFlags, 0, sizeof(uint8_t)*SLOTS);
memset(responseSegmentArrivedFlags, 0, sizeof(uint8_t)*SLOTS);
memset(errorSegmentArrivedFlags, 0, sizeof(uint8_t)*SLOTS);
slotCounter = 0;
rpc_number_map = GobotRPCNumberMap();
}
void GobotRPCStateMashine::registerRPC(RpcNum rpc_num) {
rpc_number_map.set(rpc_num, slotCounter);
slotCounter = (slotCounter + 1) % SLOTS;
}
void GobotRPCStateMashine::submitFrame(RPCFrame * frame, SMResult * result) {
RpcNum rpcNum = (RpcNum)(frame->header.rpc_num);
result->done = false;
result->rpc_num = rpcNum;
if(rpcNum == RpcNum::INVALID)
return;
size_t slot = rpc_number_map.get(rpcNum);
if (slot == 0xffffffff)
return;
uint8_t segNum = frame->header.rpc_segement;
if(frame->header.error) {
memcpy(result->data, frame->data, 7);
errorSegmentArrivedFlags[slot] |= (1 << segNum);
result->done = true;
result->type = RPCPackageType::ERROR;
} else if(frame->header.response) {
memcpy(responseDataBuffer[slot] + segNum, frame->data, 7);
responseSegmentArrivedFlags[slot] |= (1 << segNum);
uint8_t mask = SEGMENT_MASK_RESPONSE[(int)rpcNum];
if(((responseSegmentArrivedFlags[slot] & mask) ^ mask) == 0) {
responseSegmentArrivedFlags[slot] = 0;
result->done = true;
memcpy(result->data, responseDataBuffer[slot], 7*4);
result->type = RPCPackageType::RESPONSE;
}
} else {
memcpy(requestDataBuffer[slot] + segNum, frame->data, 7);
requestSegmentArrivedFlags[slot] |= (1 << segNum);
uint8_t mask = SEGMENT_MASK_RESPONSE[(int)rpcNum];
if(((requestSegmentArrivedFlags[slot] & mask) ^ mask) == 0) {
requestSegmentArrivedFlags[slot] = 0;
result->done = true;
memcpy(result->data, requestDataBuffer[slot], 7*4);
result->type = RPCPackageType::REQUEST;
}
}
}

View File

@@ -0,0 +1,56 @@
#pragma once
#include "protocol_spec.hpp"
#include "mcp2521.hpp"
#include "sm.hpp"
#include "freertos/FreeRTOS.h"
typedef void (*GobotRPCHandler_t)(void *);
typedef void (*GobotRPCFrameHandler)(void *, RPCFrame *);
class GobotRPCReciver {
protected:
MCP2521 * can_interface;
GobotRPCStateMashine state_mashine;
GobotRPCHandler_t onDoneFrameHandler;
void * argOnDoneFrameHandler;
public:
GobotRPCReciver(MCP2521 * can_interface);
~GobotRPCReciver();
void onRX();
void registerOnDoneFrameHandler(GobotRPCHandler_t handler, void * arg);
};
void onRX0_GoboRPC(void *arg);
class GoboRPCTransiver {
private:
MCP2521 * can_interface;
GobotRPCReciver rx;
GobotRPCHandler_t onRequestHandler;
GobotRPCHandler_t onResponseHandler;
GobotRPCHandler_t onResponseErrorHandler;
void * argOnRequestHandler;
void * argOnResponseHandler;
void * argOnResponseErrorHandler;
public:
GoboRPCTransiver(MCP2521 * can_interface);
~GoboRPCTransiver();
void send(RPCFrame * frame);
void registerOnRequestHandler(GobotRPCHandler_t handler, void * arg);
void registerOnResponseHandler(GobotRPCHandler_t handler, void * arg);
void registerOnResponseErrorHandler(GobotRPCHandler_t handler, void * arg);
};

View File

@@ -0,0 +1,123 @@
#pragma once
#include <stdint.h>
enum RpcNum {
Get_Info = 0x0,
Home = 0x1,
Move_Step = 0x2,
Move_XY = 0x3,
Set_Padding = 0x4,
Release_Motors = 0x5,
Drop_Stones = 0x6,
Get_Stone_Status = 0x7,
Mov_Z_Axis = 0x8,
Set_Vacum = 0x9,
INVALID = 0xF,
};
struct RPCHeader {
unsigned char rpc_num : 4;
unsigned char response : 1;
unsigned char error : 1;
unsigned char rpc_segement : 1;
};
struct RPCFrame {
RPCHeader header;
uint8_t data[7];
};
enum RPC_Node_Type {
NODE_ALL = 0x0,
NODE_CORE_XY = 0x1,
NODE_HEAD = 0x2,
NODE_VACUM = 0x3,
};
// RPC Request and Response structures
struct RPC_RES_Get_Info {
uint32_t can_address;
RPC_Node_Type node_type;
uint32_t status;
uint32_t error;
};
enum RPC_Home_Corner {
HOME_CORNER_0 = 0b00,
HOME_CORNER_1 = 0b01,
HOME_CORNER_2 = 0b10,
HOME_CORNER_3 = 0b11,
};
struct RPC_REQ_Home {
RPC_Home_Corner corner;
};
struct RPC_RES_Home {
uint32_t x;
uint32_t y;
};
struct RPC_REQ_Move_Step {
int32_t x;
int32_t y;
};
struct RPC_RES_Move_Step {
uint32_t x;
uint32_t y;
};
struct RPC_REQ_Set_Padding {
uint32_t c_1x;
uint32_t c_1y;
uint32_t c_2x;
uint32_t c_2y;
uint8_t n_x;
uint8_t n_y;
};
struct RPC_REQ_Move_Z_Axis {
bool up;
};
struct RPC_REQ_Set_Vacum {
bool on;
};
// Segment3, Segment2, Segment1, Segment0
const uint8_t SEGMENT_MASK_REQUEST[16] = {
0b0001, // Get_Info
0b0001, // Home
0b0001, // Move_Step
0b0001, // Move_XY
0b0111, // Set_Padding
0b0001, // Release_Motors
0b0001, // Drop_Stones
0b0001, // Get_Stone_Status
0b0001, // Mov_Z_Axis
0b0001, // Set_Vacum
0b0001, //
0b0001, //
0b0001, //
0b0001, //
0b0001, //
};
const uint8_t SEGMENT_MASK_RESPONSE[16] = {
0b0001, // Get_Info
0b0001, // Home
0b0001, // Move_Step
0b0001, // Move_XY
0b0001, // Set_Padding
0b0001, // Release_Motors
0b0001, // Drop_Stones
0b0001, // Get_Stone_Status
0b0001, // Mov_Z_Axis
0b0001, // Set_Vacum
0b0001, //
0b0001, //
0b0001, //
0b0001, //
0b0001, //
};

View File

@@ -0,0 +1,58 @@
#pragma once
#include <stdint.h>
#include "protocol_spec.hpp"
#include <strings.h>
class GobotRPCNumberMap {
private:
int32_t rpc_number_map[16];
public:
GobotRPCNumberMap();
~GobotRPCNumberMap();
void set(RpcNum rpc_num, uint32_t id);
uint32_t get(RpcNum rpc_num);
};
enum RPCPackageType {
REQUEST,
RESPONSE,
ERROR
};
struct SMResult {
bool done;
uint8_t data[7*4];
RpcNum rpc_num;
RPCPackageType type;
};
class GobotRPCStateMashine {
private:
static const size_t SLOTS = 6;
static const size_t REQUEST_DATA_BUFFER_SIZE = 7*4;
static const size_t RESPONSE_DATA_BUFFER_SIZE = 7*4;
GobotRPCNumberMap rpc_number_map;
size_t slotCounter;
uint8_t requestDataBuffer[REQUEST_DATA_BUFFER_SIZE][SLOTS];
bool requestSegmentArrivedFlags [SLOTS];
uint8_t responseDataBuffer[RESPONSE_DATA_BUFFER_SIZE][SLOTS];
uint8_t responseSegmentArrivedFlags [SLOTS];
uint8_t errorDataBuffer[RESPONSE_DATA_BUFFER_SIZE][SLOTS];
uint8_t errorSegmentArrivedFlags [SLOTS];
public:
GobotRPCStateMashine();
~GobotRPCStateMashine();
void registerRPC(RpcNum rpc_num);
void submitFrame(RPCFrame * frame, SMResult * result);
};

View File

@@ -0,0 +1,102 @@
<mxfile host="Electron" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/24.7.17 Chrome/128.0.6613.36 Electron/32.0.1 Safari/537.36" version="24.7.17">
<diagram name="Page-1" id="FmQN2vLuPXQQGOlHbBG4">
<mxGraphModel dx="1434" dy="838" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1169" pageHeight="827" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="xzzxaMGRirp7Gwq30BhV-21" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.75;exitY=1;exitDx=0;exitDy=0;entryX=0.75;entryY=0;entryDx=0;entryDy=0;endArrow=diamondThin;endFill=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-1" target="xzzxaMGRirp7Gwq30BhV-18" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-1" value="«interface»&lt;br&gt;&lt;font face=&quot;Courier New&quot;&gt;&lt;b&gt;I_MCP2521_&lt;/b&gt;&lt;b&gt;HardwareHandle&lt;/b&gt;&lt;/font&gt;" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="520" y="120" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-9" value="&lt;b&gt;&lt;font face=&quot;Courier New&quot;&gt;MCP2521_HardwareHandle_ESP&lt;/font&gt;&lt;/b&gt;" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="230" y="260" width="250" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-11" value="&lt;b&gt;&lt;font face=&quot;Courier New&quot;&gt;MCP2521_&lt;/font&gt;&lt;/b&gt;&lt;b&gt;&lt;font face=&quot;Courier New&quot;&gt;HardwareHandle_ESPBus&lt;/font&gt;&lt;/b&gt;" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="230" y="200" width="250" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-12" value="" style="endArrow=none;dashed=1;html=1;rounded=0;exitX=1;exitY=1;exitDx=0;exitDy=0;strokeWidth=1;dashPattern=1 1;" parent="1" source="xzzxaMGRirp7Gwq30BhV-14" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="1060" y="320" as="sourcePoint" />
<mxPoint x="120" y="320" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-14" value="SPI - Hardware Level" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
<mxGeometry x="760" y="280" width="160" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-15" value="" style="endArrow=block;html=1;rounded=0;dashed=1;endFill=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0.25;entryY=1;entryDx=0;entryDy=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-11" target="xzzxaMGRirp7Gwq30BhV-1" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="590" y="290" as="sourcePoint" />
<mxPoint x="640" y="240" as="targetPoint" />
<Array as="points">
<mxPoint x="570" y="220" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-16" value="" style="endArrow=block;html=1;rounded=0;dashed=1;endFill=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-9" target="xzzxaMGRirp7Gwq30BhV-1" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="520" y="280" as="sourcePoint" />
<mxPoint x="580" y="250" as="targetPoint" />
<Array as="points">
<mxPoint x="620" y="280" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-17" value="MCP2521 - Device Level" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
<mxGeometry x="760" y="388" width="160" height="32" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-18" value="&lt;b&gt;&lt;font face=&quot;Courier New&quot;&gt;MCP2521_CommandInterface&lt;/font&gt;&lt;/b&gt;" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="520" y="340" width="200" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-19" value="&lt;b&gt;MCP2521&lt;/b&gt;" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="520" y="420" width="200" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-20" value="" style="endArrow=block;html=1;rounded=0;endFill=0;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-19" target="xzzxaMGRirp7Gwq30BhV-18" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="670" y="544" as="sourcePoint" />
<mxPoint x="720" y="494" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-23" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.746;entryY=0.064;entryDx=0;entryDy=0;entryPerimeter=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-22" target="xzzxaMGRirp7Gwq30BhV-11" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-24" value="creates" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="xzzxaMGRirp7Gwq30BhV-23" vertex="1" connectable="0">
<mxGeometry x="-0.3135" y="1" relative="1" as="geometry">
<mxPoint x="16" y="1" as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-22" value="&lt;b&gt;&lt;font face=&quot;Courier New&quot;&gt;MCP2521_HardwareHandleFactory_ESPBus&lt;/font&gt;&lt;/b&gt;" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="180" y="120" width="300" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-25" value="" style="endArrow=none;dashed=1;html=1;rounded=0;exitX=1;exitY=1;exitDx=0;exitDy=0;strokeWidth=1;dashPattern=1 1;" parent="1" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="920" y="480" as="sourcePoint" />
<mxPoint x="120" y="480" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-26" value="Network Stack" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
<mxGeometry x="760" y="480" width="160" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-27" value="&lt;b&gt;Socket_CANTP&lt;/b&gt;" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="520" y="500" width="200" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-28" value="&lt;b&gt;Socket_GoBotRPC&lt;/b&gt;" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="520" y="580" width="200" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-29" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.75;exitY=1;exitDx=0;exitDy=0;endArrow=diamondThin;endFill=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" target="xzzxaMGRirp7Gwq30BhV-27" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="619.76" y="460" as="sourcePoint" />
<mxPoint x="640" y="520" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-30" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.75;exitY=1;exitDx=0;exitDy=0;endArrow=diamondThin;endFill=0;" parent="1" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="619.5799999999999" y="540" as="sourcePoint" />
<mxPoint x="619.9699999999999" y="580" as="targetPoint" />
</mxGeometry>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

View File

@@ -0,0 +1,93 @@
<mxfile host="Electron" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/24.7.17 Chrome/128.0.6613.36 Electron/32.0.1 Safari/537.36" version="24.7.17">
<diagram name="Page-1" id="FmQN2vLuPXQQGOlHbBG4">
<mxGraphModel dx="1195" dy="698" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1169" pageHeight="827" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="xzzxaMGRirp7Gwq30BhV-21" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.75;exitY=1;exitDx=0;exitDy=0;entryX=0.75;entryY=0;entryDx=0;entryDy=0;endArrow=diamondThin;endFill=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-1" target="xzzxaMGRirp7Gwq30BhV-18" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-1" value="«interface»&lt;br&gt;&lt;font face=&quot;Courier New&quot;&gt;&lt;b&gt;I_MCP2521_&lt;/b&gt;&lt;b&gt;HardwareHandle&lt;/b&gt;&lt;/font&gt;" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="520" y="120" width="200" height="60" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-9" value="&lt;b&gt;&lt;font face=&quot;Courier New&quot;&gt;MCP2521_HardwareHandle_ESP&lt;/font&gt;&lt;/b&gt;" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="230" y="260" width="250" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-11" value="&lt;b&gt;&lt;font face=&quot;Courier New&quot;&gt;MCP2521_&lt;/font&gt;&lt;/b&gt;&lt;b&gt;&lt;font face=&quot;Courier New&quot;&gt;HardwareHandle_ESPBus&lt;/font&gt;&lt;/b&gt;" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="230" y="200" width="250" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-12" value="" style="endArrow=none;dashed=1;html=1;rounded=0;exitX=1;exitY=1;exitDx=0;exitDy=0;strokeWidth=1;dashPattern=1 1;" parent="1" source="xzzxaMGRirp7Gwq30BhV-14" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="1060" y="320" as="sourcePoint" />
<mxPoint x="120" y="320" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-14" value="SPI - Hardware Level" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
<mxGeometry x="760" y="280" width="160" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-15" value="" style="endArrow=block;html=1;rounded=0;dashed=1;endFill=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0.25;entryY=1;entryDx=0;entryDy=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-11" target="xzzxaMGRirp7Gwq30BhV-1" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="590" y="290" as="sourcePoint" />
<mxPoint x="640" y="240" as="targetPoint" />
<Array as="points">
<mxPoint x="570" y="220" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-16" value="" style="endArrow=block;html=1;rounded=0;dashed=1;endFill=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-9" target="xzzxaMGRirp7Gwq30BhV-1" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="520" y="280" as="sourcePoint" />
<mxPoint x="580" y="250" as="targetPoint" />
<Array as="points">
<mxPoint x="620" y="280" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-17" value="MCP2521 - Device Level" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
<mxGeometry x="760" y="388" width="160" height="32" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-18" value="&lt;b&gt;&lt;font face=&quot;Courier New&quot;&gt;MCP2521_CommandInterface&lt;/font&gt;&lt;/b&gt;" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="520" y="340" width="200" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-19" value="&lt;b&gt;MCP2521&lt;/b&gt;" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="520" y="420" width="200" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-20" value="" style="endArrow=block;html=1;rounded=0;endFill=0;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=0.5;entryY=1;entryDx=0;entryDy=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-19" target="xzzxaMGRirp7Gwq30BhV-18" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="670" y="544" as="sourcePoint" />
<mxPoint x="720" y="494" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-23" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;entryX=0.746;entryY=0.064;entryDx=0;entryDy=0;entryPerimeter=0;" parent="1" source="xzzxaMGRirp7Gwq30BhV-22" target="xzzxaMGRirp7Gwq30BhV-11" edge="1">
<mxGeometry relative="1" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-24" value="creates" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="xzzxaMGRirp7Gwq30BhV-23" vertex="1" connectable="0">
<mxGeometry x="-0.3135" y="1" relative="1" as="geometry">
<mxPoint x="16" y="1" as="offset" />
</mxGeometry>
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-22" value="&lt;b&gt;&lt;font face=&quot;Courier New&quot;&gt;MCP2521_HardwareHandleFactory_ESPBus&lt;/font&gt;&lt;/b&gt;" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="180" y="120" width="300" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-25" value="" style="endArrow=none;dashed=1;html=1;rounded=0;exitX=1;exitY=1;exitDx=0;exitDy=0;strokeWidth=1;dashPattern=1 1;" parent="1" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="920" y="480" as="sourcePoint" />
<mxPoint x="120" y="480" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-26" value="Network Stack" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
<mxGeometry x="760" y="480" width="160" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-28" value="&lt;b&gt;Socket_GoBotRPC&lt;/b&gt;" style="html=1;whiteSpace=wrap;" parent="1" vertex="1">
<mxGeometry x="520" y="500" width="200" height="40" as="geometry" />
</mxCell>
<mxCell id="xzzxaMGRirp7Gwq30BhV-29" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.75;exitY=1;exitDx=0;exitDy=0;endArrow=diamondThin;endFill=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" target="xzzxaMGRirp7Gwq30BhV-28" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="619.76" y="460" as="sourcePoint" />
<mxPoint x="620" y="500" as="targetPoint" />
</mxGeometry>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

View File

@@ -3,4 +3,5 @@
#include "mcp2521_toplevel.hpp"
#include "mcp2521_command.hpp"
#include "mcp2521_hardware_esp.hpp"
#include "mcp2521_hardware_esp_bus_factory.hpp"
#include "mcp2521_addresses.hpp"

View File

@@ -40,9 +40,9 @@ struct rx_info {
uint8_t length;
};
class MCP2521_Command_Interface {
class MCP2521_CommandInterface {
private:
MCP2521_Hardware_Handle * hardware_handle;
I_MCP2521_HardwareHandle * hardware_handle;
intHandlerFunction_t rx0_handler;
intHandlerFunction_t rx1_handler;
@@ -63,8 +63,8 @@ private:
void * message_error_handler_arg;
public:
MCP2521_Command_Interface(
MCP2521_Hardware_Handle * hardware_handle
MCP2521_CommandInterface(
I_MCP2521_HardwareHandle * hardware_handle
);
void handleInterrupt();

View File

@@ -5,7 +5,7 @@
#include "mcp2521_command.hpp"
#include "mcp2521_addresses.hpp"
class MCP2521 : public MCP2521_Command_Interface {
class MCP2521 : public MCP2521_CommandInterface {
private:
public:
void set_tx_id(MCP2521_TX_BUFFER buffer, uint16_t id, bool extended);

View File

@@ -4,12 +4,12 @@
#include "mcp2521_addresses.hpp"
void runIntHandler(void *arg) {
MCP2521_Command_Interface *command_interface = (MCP2521_Command_Interface *)arg;
MCP2521_CommandInterface *command_interface = (MCP2521_CommandInterface *)arg;
command_interface->handleInterrupt();
}
MCP2521_Command_Interface::MCP2521_Command_Interface(
MCP2521_Hardware_Handle * hardware_handle
MCP2521_CommandInterface::MCP2521_CommandInterface(
I_MCP2521_HardwareHandle * hardware_handle
) {
this->hardware_handle = hardware_handle;
this->hardware_handle->registerIntHandler(runIntHandler, (void *)this);
@@ -33,42 +33,42 @@ MCP2521_Command_Interface::MCP2521_Command_Interface(
message_error_handler_arg = NULL;
}
void MCP2521_Command_Interface::reset() {
void MCP2521_CommandInterface::reset() {
hardware_handle->execute(MCP2521_OP_RESET);
}
void MCP2521_Command_Interface::read_reg(uint8_t address, uint8_t *data, size_t length) {
void MCP2521_CommandInterface::read_reg(uint8_t address, uint8_t *data, size_t length) {
hardware_handle->read(MCP2521_OP_READ, data, length, address);
}
uint8_t MCP2521_Command_Interface::read_reg(uint8_t address) {
uint8_t MCP2521_CommandInterface::read_reg(uint8_t address) {
return hardware_handle->read(MCP2521_OP_READ, address);
}
void MCP2521_Command_Interface::read_rx_buf(MCP2521_RX_BUFFER buffer, MCP2521_BUFFER_TYPE type, uint8_t *data, size_t length) {
void MCP2521_CommandInterface::read_rx_buf(MCP2521_RX_BUFFER buffer, MCP2521_BUFFER_TYPE type, uint8_t *data, size_t length) {
uint8_t address = (buffer << 1) | (type << 2);
hardware_handle->read(MCP2521_OP_READ_RX_BUFFER | address, data, length);
}
void MCP2521_Command_Interface::write_reg(uint8_t address, uint8_t *data, size_t length) {
void MCP2521_CommandInterface::write_reg(uint8_t address, uint8_t *data, size_t length) {
hardware_handle->write(MCP2521_OP_WRITE, data, length, address);
}
void MCP2521_Command_Interface::write_reg(uint8_t address, uint8_t data) {
void MCP2521_CommandInterface::write_reg(uint8_t address, uint8_t data) {
hardware_handle->write(MCP2521_OP_WRITE, data, address);
}
void MCP2521_Command_Interface::write_tx_buf(MCP2521_TX_BUFFER buffer, MCP2521_BUFFER_TYPE type, uint8_t *data, size_t length) {
void MCP2521_CommandInterface::write_tx_buf(MCP2521_TX_BUFFER buffer, MCP2521_BUFFER_TYPE type, uint8_t *data, size_t length) {
uint8_t address = (buffer << 1) | (type);
hardware_handle->write(MCP2521_OP_LOAD_TX_BUFFER | address, data, length);
}
void MCP2521_Command_Interface::request_to_send(bool txb2, bool txb1, bool txb0) {
void MCP2521_CommandInterface::request_to_send(bool txb2, bool txb1, bool txb0) {
uint8_t data = (txb2 << 2) | (txb1 << 1) | txb0;
hardware_handle->execute(MCP2521_OP_RTS | data);
}
void MCP2521_Command_Interface::request_to_send(MCP2521_TX_BUFFER buffer) {
void MCP2521_CommandInterface::request_to_send(MCP2521_TX_BUFFER buffer) {
uint8_t mask = 0;
switch (buffer) {
@@ -86,15 +86,15 @@ void MCP2521_Command_Interface::request_to_send(MCP2521_TX_BUFFER buffer) {
hardware_handle->execute(MCP2521_OP_RTS | mask);
}
uint8_t MCP2521_Command_Interface::read_status() {
uint8_t MCP2521_CommandInterface::read_status() {
return hardware_handle->read(MCP2521_OP_READ_STATUS);
}
uint8_t MCP2521_Command_Interface::read_rx_status() {
uint8_t MCP2521_CommandInterface::read_rx_status() {
return hardware_handle->read(MCP2521_OP_RX_STATUS);
}
void MCP2521_Command_Interface::bit_modify(uint8_t address, uint8_t mask, uint8_t data) {
void MCP2521_CommandInterface::bit_modify(uint8_t address, uint8_t mask, uint8_t data) {
uint8_t data_array[3] = {address, mask, data};
hardware_handle->write(MCP2521_OP_BIT_MODIFY, data_array, 3);
}

View File

@@ -1,47 +1,47 @@
#include "mcp2521.hpp"
#include "mcp2521_addresses.hpp"
void MCP2521_Command_Interface::register_rx0_handler(intHandlerFunction_t handler, void* args) {
void MCP2521_CommandInterface::register_rx0_handler(intHandlerFunction_t handler, void* args) {
rx0_handler = handler;
rx0_handler_arg = args;
}
void MCP2521_Command_Interface::register_rx1_handler(intHandlerFunction_t handler, void* args) {
void MCP2521_CommandInterface::register_rx1_handler(intHandlerFunction_t handler, void* args) {
rx1_handler = handler;
rx1_handler_arg = args;
}
void MCP2521_Command_Interface::register_tx0_handler(intHandlerFunction_t handler, void* args) {
void MCP2521_CommandInterface::register_tx0_handler(intHandlerFunction_t handler, void* args) {
tx0_handler = handler;
tx0_handler_arg = args;
}
void MCP2521_Command_Interface::register_tx1_handler(intHandlerFunction_t handler, void* args) {
void MCP2521_CommandInterface::register_tx1_handler(intHandlerFunction_t handler, void* args) {
tx1_handler = handler;
tx1_handler_arg = args;
}
void MCP2521_Command_Interface::register_tx2_handler(intHandlerFunction_t handler, void* args) {
void MCP2521_CommandInterface::register_tx2_handler(intHandlerFunction_t handler, void* args) {
tx2_handler = handler;
tx2_handler_arg = args;
}
void MCP2521_Command_Interface::register_error_handler(intHandlerFunction_t handler, void* args) {
void MCP2521_CommandInterface::register_error_handler(intHandlerFunction_t handler, void* args) {
error_handler = handler;
error_handler_arg = args;
}
void MCP2521_Command_Interface::register_wakeup_handler(intHandlerFunction_t handler, void* args) {
void MCP2521_CommandInterface::register_wakeup_handler(intHandlerFunction_t handler, void* args) {
wakeup_handler = handler;
wakeup_handler_arg = args;
}
void MCP2521_Command_Interface::register_message_error_handler(intHandlerFunction_t handler, void* args) {
void MCP2521_CommandInterface::register_message_error_handler(intHandlerFunction_t handler, void* args) {
message_error_handler = handler;
message_error_handler_arg = args;
}
void MCP2521_Command_Interface::handleInterrupt() {
void MCP2521_CommandInterface::handleInterrupt() {
uint8_t flags = read_reg(MCP2521_CANINTF);
uint8_t clearBits = 0;

View File

@@ -1,5 +1,7 @@
idf_component_register(SRCS "esp_implementation_init.cpp"
"esp_implementation_cmd.cpp"
"esp_implementation_int.cpp"
"esp_implementation_bus.cpp"
"esp_implementation_bus_factory.cpp"
INCLUDE_DIRS "include"
REQUIRES driver)

View File

@@ -0,0 +1,58 @@
#ifdef ESP_PLATFORM
#include "freertos/FreeRTOS.h"
#include "mcp2521_hardware_esp_bus.hpp"
#include "mcp2521_hardware_esp.hpp"
MCP2521_HardwareHandle_ESPBus::MCP2521_HardwareHandle_ESPBus(
QueueHandle_t send_queue,
spi_host_device_t spi_host,
spi_bus_config_t * bus_config,
gpio_num_t cs,
gpio_num_t int_pin
) : MCP2521_HardwareHandle_ESP(spi_host, bus_config, cs, int_pin) {
this->send_queue = send_queue;
this->receive_queue = xQueueCreate(3, sizeof(spi_message_t));
}
void MCP2521_HardwareHandle_ESPBus::spi_transmit(spi_transaction_t *t) {
spi_message_t message = {
.transaction = t,
.queue = send_queue,
.spi_device_handle = spi_device_handle
};
xQueueSend(send_queue, &message, portMAX_DELAY);
xQueueReceive(receive_queue, &message, portMAX_DELAY);
}
void MCP2521_HardwareHandle_ESPBus::initPins(
gpio_num_t int_pin
) {
canInterruptSemaphore = xSemaphoreCreateBinary();
gpio_config_t io_conf;
io_conf.intr_type = GPIO_INTR_NEGEDGE;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pin_bit_mask = 1 << int_pin;
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
gpio_config(&io_conf);
gpio_isr_handler_add(int_pin, gpio_isr_can_handler, this);
char taskName[32];
sprintf(taskName, "canInterruptTask_%d", int_pin);
xTaskCreatePinnedToCore(
(TaskFunction_t)&handleInteruptTaskCallerFn,
taskName,
2048,
this,
5,
&canInterruptTaskHandle,
0
);
}
#endif

View File

@@ -0,0 +1,67 @@
#pragma once
#ifdef ESP_PLATFORM
#include "freertos/FreeRTOS.h"
#include "mcp2521_hardware_esp_bus_factory.hpp"
#include "mcp2521_hardware_esp_bus.hpp"
#include "mcp2521_hardware_esp.hpp"
void transactionTaskWrapperFn(void *pvParameters) {
MCP2521_HardwareHandleFactory_ESPBus *factory = (MCP2521_HardwareHandleFactory_ESPBus *)pvParameters;
factory->transactionTaskFn();
}
MCP2521_HardwareHandleFactory_ESPBus::MCP2521_HardwareHandleFactory_ESPBus(
spi_host_device_t spi_host,
gpio_num_t mosi,
gpio_num_t miso,
gpio_num_t sclk
) {
this->spi_host = spi_host;
this->mosi = mosi;
this->miso = miso;
this->sclk = sclk;
gpio_install_isr_service(0);
MCP2521_HardwareHandle_ESP::initSPIBus(spi_host, mosi, miso, sclk, &bus_config);
spi_queue = xQueueCreate(12, sizeof(spi_message_t));
xTaskCreatePinnedToCore(
(TaskFunction_t)&transactionTaskWrapperFn,
"transactionTask",
2048,
this,
3,
&transactionTaskHandle,
0
);
}
void MCP2521_HardwareHandleFactory_ESPBus::transactionTaskFn() {
spi_message_t message;
while(true) {
xQueueReceive(spi_queue, &message, portMAX_DELAY);
spi_device_transmit(message.spi_device_handle, message.transaction);
}
}
MCP2521_HardwareHandle_ESPBus MCP2521_HardwareHandleFactory_ESPBus::create(
gpio_num_t int_pin,
gpio_num_t cs
) {
return MCP2521_HardwareHandle_ESPBus(
spi_queue,
spi_host,
&bus_config,
cs,
int_pin
);
}
#endif

View File

@@ -5,13 +5,13 @@
const uint8_t null_buffer[32] = {0};
void MCP2521_Hardware_Handle_ESP::spi_transmit(spi_transaction_t *t) {
void MCP2521_HardwareHandle_ESP::spi_transmit(spi_transaction_t *t) {
xSemaphoreTake(spiMutex, portMAX_DELAY);
spi_device_transmit(this->spi_device_handle, t);
xSemaphoreGive(spiMutex);
}
void MCP2521_Hardware_Handle_ESP::execute(uint8_t cmd) {
void MCP2521_HardwareHandle_ESP::execute(uint8_t cmd) {
spi_transaction_ext_t t = {
.base = {
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
@@ -30,7 +30,7 @@ void MCP2521_Hardware_Handle_ESP::execute(uint8_t cmd) {
spi_transmit((spi_transaction_t*)(&t));
}
void MCP2521_Hardware_Handle_ESP::execute(uint8_t cmd, uint8_t address) {
void MCP2521_HardwareHandle_ESP::execute(uint8_t cmd, uint8_t address) {
spi_transaction_ext_t t = {
.base = {
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
@@ -49,7 +49,7 @@ void MCP2521_Hardware_Handle_ESP::execute(uint8_t cmd, uint8_t address) {
spi_transmit((spi_transaction_t*)(&t));
}
void MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t *data, size_t length, uint8_t address) {
void MCP2521_HardwareHandle_ESP::read(uint8_t cmd, uint8_t *data, size_t length, uint8_t address) {
spi_transaction_ext_t t = {
.base = {
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
@@ -68,7 +68,7 @@ void MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t *data, size_t length
spi_transmit((spi_transaction_t*)(&t));
}
void MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t *data, size_t length) {
void MCP2521_HardwareHandle_ESP::read(uint8_t cmd, uint8_t *data, size_t length) {
spi_transaction_ext_t t = {
.base = {
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
@@ -76,7 +76,7 @@ void MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t *data, size_t length
.addr = 0,
.length = 8*length,
.rxlength = 8*length,
.tx_buffer = NULL,
.tx_buffer = null_buffer,
.rx_buffer = data
},
.command_bits = 8,
@@ -87,7 +87,7 @@ void MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t *data, size_t length
spi_transmit((spi_transaction_t*)(&t));
}
uint8_t MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t address) {
uint8_t MCP2521_HardwareHandle_ESP::read(uint8_t cmd, uint8_t address) {
uint8_t result = 0;
spi_transaction_ext_t t = {
.base = {
@@ -108,7 +108,7 @@ uint8_t MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t address) {
return result;
}
uint8_t MCP2521_Hardware_Handle_ESP::read(uint8_t cmd) {
uint8_t MCP2521_HardwareHandle_ESP::read(uint8_t cmd) {
uint8_t result;
spi_transaction_ext_t t = {
.base = {
@@ -129,7 +129,7 @@ uint8_t MCP2521_Hardware_Handle_ESP::read(uint8_t cmd) {
return result;
}
void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t *data, size_t length, uint8_t address) {
void MCP2521_HardwareHandle_ESP::write(uint8_t cmd, uint8_t *data, size_t length, uint8_t address) {
uint8_t result;
spi_transaction_ext_t t = {
.base = {
@@ -149,7 +149,7 @@ void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t *data, size_t lengt
spi_transmit((spi_transaction_t*)(&t));
}
void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t *data, size_t length) {
void MCP2521_HardwareHandle_ESP::write(uint8_t cmd, uint8_t *data, size_t length) {
spi_transaction_ext_t t = {
.base = {
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
@@ -168,7 +168,7 @@ void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t *data, size_t lengt
spi_transmit((spi_transaction_t*)(&t));
}
void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t data, uint8_t address) {
void MCP2521_HardwareHandle_ESP::write(uint8_t cmd, uint8_t data, uint8_t address) {
spi_transaction_ext_t t = {
.base = {
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,
@@ -187,7 +187,7 @@ void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t data, uint8_t addre
spi_transmit((spi_transaction_t*)(&t));
}
void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t data) {
void MCP2521_HardwareHandle_ESP::write(uint8_t cmd, uint8_t data) {
spi_transaction_ext_t t = {
.base = {
.flags = SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR,

View File

@@ -8,7 +8,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
MCP2521_Hardware_Handle_ESP::MCP2521_Hardware_Handle_ESP(
MCP2521_HardwareHandle_ESP::MCP2521_HardwareHandle_ESP(
spi_host_device_t spi_host,
spi_bus_config_t *bus_config,
gpio_num_t mosi,
@@ -23,7 +23,7 @@ MCP2521_Hardware_Handle_ESP::MCP2521_Hardware_Handle_ESP(
initSPIDevice(spi_host, cs);
}
MCP2521_Hardware_Handle_ESP::MCP2521_Hardware_Handle_ESP(
MCP2521_HardwareHandle_ESP::MCP2521_HardwareHandle_ESP(
spi_host_device_t spi_host,
spi_bus_config_t *bus_config,
gpio_num_t cs,
@@ -34,11 +34,11 @@ MCP2521_Hardware_Handle_ESP::MCP2521_Hardware_Handle_ESP(
initSPIDevice(spi_host, cs);
}
MCP2521_Hardware_Handle_ESP::~MCP2521_Hardware_Handle_ESP() {
MCP2521_HardwareHandle_ESP::~MCP2521_HardwareHandle_ESP() {
}
void MCP2521_Hardware_Handle_ESP::initSPIBus(
void MCP2521_HardwareHandle_ESP::initSPIBus(
spi_host_device_t spi_host,
gpio_num_t mosi,
gpio_num_t miso,
@@ -57,7 +57,7 @@ void MCP2521_Hardware_Handle_ESP::initSPIBus(
spi_bus_initialize(spi_host, bus_config, SPI_DMA_CH_AUTO);
}
void MCP2521_Hardware_Handle_ESP::initSPIDevice(
void MCP2521_HardwareHandle_ESP::initSPIDevice(
spi_host_device_t spi_host,
gpio_num_t cs
) {
@@ -73,7 +73,7 @@ void MCP2521_Hardware_Handle_ESP::initSPIDevice(
// Learned this the hard way
.cs_ena_pretrans = 0,
.cs_ena_posttrans = 0,
.clock_speed_hz = 10000,
.clock_speed_hz = 2000,
.spics_io_num = cs,
.flags = SPI_DEVICE_NO_DUMMY,
@@ -85,7 +85,7 @@ void MCP2521_Hardware_Handle_ESP::initSPIDevice(
spiMutex = xSemaphoreCreateMutex();
}
spi_bus_config_t * MCP2521_Hardware_Handle_ESP::getSPI_bus_config() {
spi_bus_config_t * MCP2521_HardwareHandle_ESP::getSPI_bus_config() {
return this->spi_bus_config;
}

View File

@@ -6,16 +6,16 @@
#include "mcp2521_hardware_esp.hpp"
static void IRAM_ATTR gpio_isr_can_handler(void* arg) {
MCP2521_Hardware_Handle_ESP * handle = (MCP2521_Hardware_Handle_ESP *)arg;
MCP2521_HardwareHandle_ESP * handle = (MCP2521_HardwareHandle_ESP *)arg;
handle->isr_can_interrupt();
}
static void handleInteruptTaskCallerFn(void *arg) {
MCP2521_Hardware_Handle_ESP * handle = (MCP2521_Hardware_Handle_ESP *)arg;
MCP2521_HardwareHandle_ESP * handle = (MCP2521_HardwareHandle_ESP *)arg;
handle->handleIntteruptTaskFn();
}
void MCP2521_Hardware_Handle_ESP::initPins(
void MCP2521_HardwareHandle_ESP::initPins(
gpio_num_t int_pin
) {
canInterruptSemaphore = xSemaphoreCreateBinary();
@@ -31,24 +31,25 @@ void MCP2521_Hardware_Handle_ESP::initPins(
gpio_install_isr_service(0);
gpio_isr_handler_add(int_pin, gpio_isr_can_handler, this);
xTaskCreate(
xTaskCreatePinnedToCore(
(TaskFunction_t)&handleInteruptTaskCallerFn,
"canInterruptTask",
2048,
this,
5,
&canInterruptTaskHandle
&canInterruptTaskHandle,
0
);
}
void MCP2521_Hardware_Handle_ESP::handleIntteruptTaskFn() {
void MCP2521_HardwareHandle_ESP::handleIntteruptTaskFn() {
while(true) {
xSemaphoreTake(canInterruptSemaphore, portMAX_DELAY);
intHandler(intHandlerArg);
}
}
void MCP2521_Hardware_Handle_ESP::isr_can_interrupt() {
void MCP2521_HardwareHandle_ESP::isr_can_interrupt() {
BaseType_t wokenTask = pdFALSE;
xSemaphoreGiveFromISR(canInterruptSemaphore, &wokenTask);
@@ -57,7 +58,7 @@ void MCP2521_Hardware_Handle_ESP::isr_can_interrupt() {
}
}
void MCP2521_Hardware_Handle_ESP::registerIntHandler(intHandlerFunction_t handler, void * arg) {
void MCP2521_HardwareHandle_ESP::registerIntHandler(intHandlerFunction_t handler, void * arg) {
intHandlerArg = arg;
intHandler = handler;
}

View File

@@ -1,3 +1,13 @@
/**
* @file mcp2521_hardware_esp.hpp
* @author AlexanderHD27
* @brief
* @version 0.1
* @date 2024-11-16
*
* @copyright Copyright (c) 2024
*
*/
#pragma once
#include "mcp2521_hardware_handle.hpp"
@@ -8,24 +18,48 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
class MCP2521_Hardware_Handle_ESP : public MCP2521_Hardware_Handle {
char spi_tmp_buffer;
static void handleInteruptTaskCallerFn(void *arg);
static void IRAM_ATTR gpio_isr_can_handler(void* arg);
spi_bus_config_t * spi_bus_config;
spi_device_interface_config_t spi_device_config;
spi_device_handle_t spi_device_handle;
/**
* @brief Hardware handle for MCP2521 over SPI on ESP32
* This is should not be used if multiple MCP2521 are on the same SPI bus
*/
class MCP2521_HardwareHandle_ESP : public I_MCP2521_HardwareHandle {
protected:
void spi_transmit(spi_transaction_t *t);
/**
* @brief Sempahore, that is set every time the MCP2521 triggers an interrupt by the canInterruptTaskHandle
*/
SemaphoreHandle_t canInterruptSemaphore = NULL;
SemaphoreHandle_t spiMutex = NULL;
/**
* @brief Handle to task that handles the MCP2521 interrupt
* A Handle can be registered via the registerIntHandler method
*/
TaskHandle_t canInterruptTaskHandle = NULL;
void spi_transmit(spi_transaction_t *t);
spi_device_handle_t spi_device_handle;
private:
spi_bus_config_t * spi_bus_config;
char spi_tmp_buffer;
spi_device_interface_config_t spi_device_config;
/**
* @brief Sempahore, that protects the SPI bus from being accessed by multiple tasks at the same time
*
*/
SemaphoreHandle_t spiMutex = NULL;
void * intHandlerArg = NULL;
intHandlerFunction_t intHandler = NULL;
public:
MCP2521_Hardware_Handle_ESP(
MCP2521_HardwareHandle_ESP(
spi_host_device_t spi_host,
spi_bus_config_t *bus_config,
gpio_num_t mosi,
@@ -35,7 +69,7 @@ public:
gpio_num_t int_pin
);
MCP2521_Hardware_Handle_ESP(
MCP2521_HardwareHandle_ESP(
spi_host_device_t spi_host,
spi_bus_config_t *bus_config,
gpio_num_t cs,
@@ -59,12 +93,22 @@ public:
gpio_num_t int_pin
);
~MCP2521_Hardware_Handle_ESP();
~MCP2521_HardwareHandle_ESP();
spi_bus_config_t * getSPI_bus_config();
// ISR Stuff
/**
* @brief This function is called by the ISR, that is triggered by the MCP2521
* This function just set the canInterruptSemaphore, that then unblocks the canInterruptTaskHandle.
* So this function should be as short as possible, let the reset of the work be done in the canInterruptTaskHandle
*/
void isr_can_interrupt();
/**
* This is the methode run as canInterruptTaskHandle.
* It should continously aquire the canInterruptSemaphore and then call the intHandler
*/
void handleIntteruptTaskFn();
// Inherited from MCP2521_Hardware_Handle

View File

@@ -0,0 +1,46 @@
#pragma once
#include "mcp2521_hardware_esp.hpp"
#include "driver/gpio.h"
#include "driver/spi_master.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
struct spi_message_t {
spi_transaction_t *transaction;
QueueHandle_t queue;
spi_device_handle_t spi_device_handle;
};
/**
* @brief Hardware handle for MCP2521 over SPI in a multi-Bus-Setup on ESP32
* This should not be created directly, use the MCP2521_HardwareHandleFactory_ESPBus instead
*/
class MCP2521_HardwareHandle_ESPBus : public MCP2521_HardwareHandle_ESP {
using MCP2521_HardwareHandle_ESP::MCP2521_HardwareHandle_ESP;
private:
QueueHandle_t send_queue;
QueueHandle_t receive_queue;
/**
* @brief Wrapper around the spi_transmit function, that locks the spiMutex before calling spi_transmit.
* The muxtex is shared with all other MCP2521_HardwareHandle_ESPBus instances created by the same MCP2521_HardwareHandleFactory_ESPBus
* @overload
*
* @param t ESP32 SPI Transaction struct
*/
void spi_transmit(spi_transaction_t *t);
public:
MCP2521_HardwareHandle_ESPBus(
QueueHandle_t send_queue,
spi_host_device_t spi_host,
spi_bus_config_t * bus_config,
gpio_num_t cs,
gpio_num_t int_pin
);
void initPins(
gpio_num_t int_pin
);
};

View File

@@ -0,0 +1,41 @@
#pragma once
#ifdef ESP_PLATFORM
#include "mcp2521_hardware_handle.hpp"
#include "mcp2521_hardware_esp_bus.hpp"
#include "driver/gpio.h"
#include "driver/spi_master.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
class MCP2521_HardwareHandleFactory_ESPBus {
private:
spi_bus_config_t bus_config;
spi_host_device_t spi_host;
gpio_num_t mosi;
gpio_num_t miso;
gpio_num_t sclk;
QueueHandle_t spi_queue;
TaskHandle_t transactionTaskHandle;
public:
MCP2521_HardwareHandleFactory_ESPBus(
spi_host_device_t spi_host,
gpio_num_t mosi,
gpio_num_t miso,
gpio_num_t sclk
);
void transactionTaskFn();
MCP2521_HardwareHandle_ESPBus create(
gpio_num_t int_pin,
gpio_num_t cs
);
};
#endif

View File

@@ -2,23 +2,118 @@
#include <cstdint>
#include <strings.h>
/**
* @brief Handler function pointer type
*
*/
typedef void (*intHandlerFunction_t)(void *);
class MCP2521_Hardware_Handle {
/**
* @brief Hardware handle for MCP2521
* @interface
* This is an abstraction over the sepific hardware setup, eg. SPI@ESP32 or RP2040
*
*/
class I_MCP2521_HardwareHandle {
public:
/**
* @brief Registeres a function that is called when the MCP2521 triggers an interrupt
*
* @param handler This function is called when the MCP2521 triggers an interrupt
* @param arg Arguments passed to the handler-function
*/
virtual void registerIntHandler(intHandlerFunction_t handler, void * arg) = 0;
/**
* @overload
* @brief justed sends a 8bit command to the MCP2521
*
* @param cmd command to send
*/
virtual void execute(uint8_t cmd) = 0;
/**
* @overload
* @brief executes a command (8 bit) with an address (8 bit)
*
* @param cmd 8 bit command
* @param address 8 bit address
*/
virtual void execute(uint8_t cmd, uint8_t address) = 0;
/**
*
* @brief Executes a read from the MCP2521 with command, data buffer, length and address
* @overload
*
* @param cmd Command to MCP2521
* @param data Data buffer to store the read data
* @param length How many bytes to read
* @param address Address to read from
*/
virtual void read(uint8_t cmd, uint8_t *data, size_t length, uint8_t address) = 0;
/**
* @brief Executes a read from the MCP2521 with command, data buffer and length
* @overload
*
* @param cmd Command to MCP2521
* @param data Data buffer to store the read data
* @param length How many bytes to read
*/
virtual void read(uint8_t cmd, uint8_t *data, size_t length) = 0;
/**
* @brief Executes a read from the MCP2521 with command and address, returns just one byte
*
* @param cmd Command to MCP2521
* @param address Address to read from
* @return uint8_t
*/
virtual uint8_t read(uint8_t cmd, uint8_t address) = 0;
/**
* @brief Executes a read from the MCP2521 with command, returns just one byte
*
* @param cmd Command to MCP2521
* @return uint8_t
*/
virtual uint8_t read(uint8_t cmd) = 0;
/**
* @brief Writes data to the MCP2521 with command, data buffer, length and address
*
* @param cmd Command to MCP2521
* @param data Data buffer to write
* @param length Length of the data buffer
* @param address Where to write the data
*/
virtual void write(uint8_t cmd, uint8_t *data, size_t length, uint8_t address) = 0;
/**
* @brief Wirites data to the MCP2521 with command, data buffer and length
*
* @param cmd Command to MCP2521
* @param data Data buffer to write
* @param length Length of the data buffer
*/
virtual void write(uint8_t cmd, uint8_t *data, size_t length) = 0;
/**
* @brief Writes data to the MCP2521 with command, data (on byte) and address
*
* @param cmd Command to MCP2521
* @param data Data byte to write
* @param address Where to write the data
*/
virtual void write(uint8_t cmd, uint8_t data, uint8_t address) = 0;
/**
* @brief Writes to the MCP2521 with command and data (one byte)
*
* @param cmd Command to MCP2521
* @param data Data byte to write
*/
virtual void write(uint8_t cmd, uint8_t data) = 0;
};

BIN
i2c-hub/backend/Protocol.md (Stored with Git LFS) Normal file

Binary file not shown.

BIN
i2c-hub/backend/src/gobotRPC_ctrl_interface.py (Stored with Git LFS) Normal file

Binary file not shown.

View File

9
i2c-hub/backend/test.txt Normal file
View File

@@ -0,0 +1,9 @@
fe fe fe fe fc 10 10 10 20 ff 48 65 6c 6c 6f 20
6f 72 6c 64 21 0a 84 00 01 00 42 00 00 00 12
00 00 00 c0 84 01 01 01 43 00 00 00 22 00 00
3f 00 84 00 01 00 42 00 00 00 32 00 00 00 80
54 68 69 73 20 69 73 20 52 61 6e 64 6f 6d 20
65 78 74 0a 84 01 01 02 43 00 00 00 63 00 00
3f 00 84 01 01 00 42 00 00 00 73 00 00 00 bf
81 10 40 42 00 00 00 01 02 03 04 05 06 00 11
13 14 fe fe fe fe fe fe fc

Submodule i2c-hub/circuit/external/KiCad-RP-Pico added at dc6f9b9f21

Submodule i2c-hub/circuit/external/RP_Silicon_KiCad added at 8ab84dd99d

View File

@@ -0,0 +1 @@
/home/alexander/Projects/gobot/i2c-hub/circuit/i2c-hub/_autosave-i2c-hub.kicad_sch

BIN
i2c-hub/circuit/i2c-hub/_autosave-i2c-hub.kicad_sch (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
i2c-hub/circuit/i2c-hub/i2c-hub.kicad_pcb (Stored with Git LFS) Normal file

Binary file not shown.

BIN
i2c-hub/circuit/i2c-hub/i2c-hub.kicad_prl (Stored with Git LFS) Normal file

Binary file not shown.

BIN
i2c-hub/circuit/i2c-hub/i2c-hub.kicad_pro (Stored with Git LFS) Normal file

Binary file not shown.

BIN
i2c-hub/circuit/i2c-hub/i2c-hub.kicad_sch (Stored with Git LFS) Normal file

Binary file not shown.

View File

@@ -0,0 +1,4 @@
(sym_lib_table
(version 7)
(lib (name "MCU_RaspberryPi_and_Boards")(type "KiCad")(uri "/home/alexander/Projects/gobot/i2c-hub/circuit/external/KiCad-RP-Pico/RP-Pico Libraries/MCU_RaspberryPi_and_Boards.kicad_sym")(options "")(descr ""))
)

View File

@@ -0,0 +1 @@
{"hostname":"hal","username":"alexander"}

BIN
i2c-hub/firmware/i2c-hub-firmware/.gitignore (Stored with Git LFS) vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,23 @@
{
"configurations": [
{
"name": "Pico",
"includePath": [
"${workspaceFolder}/**",
"${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"
],
"defines": [],
"compilerPath": "${userHome}/.pico-sdk/toolchain/13_3_Rel1/bin/arm-none-eabi-gcc",
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "linux-gcc-arm",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}

View File

@@ -0,0 +1,15 @@
[
{
"name": "Pico",
"compilers": {
"C": "${command:raspberry-pi-pico.getCompilerPath}",
"CXX": "${command:raspberry-pi-pico.getCxxCompilerPath}"
},
"environmentVariables": {
"PATH": "${command:raspberry-pi-pico.getEnvPath};${env:PATH}"
},
"cmakeSettings": {
"Python3_EXECUTABLE": "${command:raspberry-pi-pico.getPythonPath}"
}
}
]

View File

@@ -0,0 +1,9 @@
{
"recommendations": [
"marus25.cortex-debug",
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"ms-vscode.vscode-serial-monitor",
"raspberry-pi.raspberry-pi-pico"
]
}

View File

@@ -0,0 +1,70 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Pico Debug (Cortex-Debug)",
"cwd": "${userHome}/.pico-sdk/openocd/0.12.0+dev/scripts",
"executable": "${command:raspberry-pi-pico.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"serverpath": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
"gdbPath": "${command:raspberry-pi-pico.getGDBPath}",
"device": "${command:raspberry-pi-pico.getChipUppercase}",
"configFiles": [
"interface/cmsis-dap.cfg",
"target/${command:raspberry-pi-pico.getTarget}.cfg"
],
"svdFile": "${userHome}/.pico-sdk/sdk/2.1.0/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd",
"runToEntryPoint": "main",
// Fix for no_flash binaries, where monitor reset halt doesn't do what is expected
// Also works fine for flash binaries
"overrideLaunchCommands": [
"monitor reset init",
"load \"${command:raspberry-pi-pico.launchTargetPath}\""
],
"openOCDLaunchCommands": [
"adapter speed 5000"
]
},
{
"name": "Pico Debug (Cortex-Debug with external OpenOCD)",
"cwd": "${workspaceRoot}",
"executable": "${command:raspberry-pi-pico.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"servertype": "external",
"gdbTarget": "localhost:3333",
"gdbPath": "${command:raspberry-pi-pico.getGDBPath}",
"device": "${command:raspberry-pi-pico.getChipUppercase}",
"svdFile": "${userHome}/.pico-sdk/sdk/2.1.0/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd",
"runToEntryPoint": "main",
// Fix for no_flash binaries, where monitor reset halt doesn't do what is expected
// Also works fine for flash binaries
"overrideLaunchCommands": [
"monitor reset init",
"load \"${command:raspberry-pi-pico.launchTargetPath}\""
]
},
{
"name": "Pico Debug (C++ Debugger)",
"type": "cppdbg",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${command:raspberry-pi-pico.launchTargetPath}",
"MIMode": "gdb",
"miDebuggerPath": "${command:raspberry-pi-pico.getGDBPath}",
"miDebuggerServerAddress": "localhost:3333",
"debugServerPath": "${userHome}/.pico-sdk/openocd/0.12.0+dev/openocd.exe",
"debugServerArgs": "-f interface/cmsis-dap.cfg -f target/${command:raspberry-pi-pico.getTarget}.cfg -c \"adapter speed 5000\"",
"serverStarted": "Listening on port .* for gdb connections",
"filterStderr": true,
"hardwareBreakpoints": {
"require": true,
"limit": 4
},
"preLaunchTask": "Flash",
"svdPath": "${userHome}/.pico-sdk/sdk/2.1.0/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd"
},
]
}

View File

@@ -0,0 +1,87 @@
{
"cmake.options.statusBarVisibility": "hidden",
"cmake.options.advanced": {
"build": {
"statusBarVisibility": "hidden"
},
"launch": {
"statusBarVisibility": "hidden"
},
"debug": {
"statusBarVisibility": "hidden"
}
},
"cmake.configureOnEdit": true,
"cmake.automaticReconfigure": true,
"cmake.configureOnOpen": true,
"cmake.generator": "Ninja",
"cmake.cmakePath": "${userHome}/.pico-sdk/cmake/v3.29.9/bin/cmake",
"C_Cpp.debugShortcut": false,
"terminal.integrated.env.windows": {
"PICO_SDK_PATH": "${env:USERPROFILE}/.pico-sdk/sdk/2.1.0",
"PICO_TOOLCHAIN_PATH": "${env:USERPROFILE}/.pico-sdk/toolchain/13_3_Rel1",
"Path": "${env:USERPROFILE}/.pico-sdk/toolchain/13_3_Rel1/bin;${env:USERPROFILE}/.pico-sdk/picotool/2.1.0/picotool;${env:USERPROFILE}/.pico-sdk/cmake/v3.29.9/bin;${env:USERPROFILE}/.pico-sdk/ninja/v1.12.1;${env:PATH}"
},
"terminal.integrated.env.osx": {
"PICO_SDK_PATH": "${env:HOME}/.pico-sdk/sdk/2.1.0",
"PICO_TOOLCHAIN_PATH": "${env:HOME}/.pico-sdk/toolchain/13_3_Rel1",
"PATH": "${env:HOME}/.pico-sdk/toolchain/13_3_Rel1/bin:${env:HOME}/.pico-sdk/picotool/2.1.0/picotool:${env:HOME}/.pico-sdk/cmake/v3.29.9/bin:${env:HOME}/.pico-sdk/ninja/v1.12.1:${env:PATH}"
},
"terminal.integrated.env.linux": {
"PICO_SDK_PATH": "${env:HOME}/.pico-sdk/sdk/2.1.0",
"PICO_TOOLCHAIN_PATH": "${env:HOME}/.pico-sdk/toolchain/13_3_Rel1",
"PATH": "${env:HOME}/.pico-sdk/toolchain/13_3_Rel1/bin:${env:HOME}/.pico-sdk/picotool/2.1.0/picotool:${env:HOME}/.pico-sdk/cmake/v3.29.9/bin:${env:HOME}/.pico-sdk/ninja/v1.12.1:${env:PATH}"
},
"raspberry-pi-pico.cmakeAutoConfigure": false,
"raspberry-pi-pico.useCmakeTools": true,
"raspberry-pi-pico.cmakePath": "${HOME}/.pico-sdk/cmake/v3.29.9/bin/cmake",
"raspberry-pi-pico.ninjaPath": "${HOME}/.pico-sdk/ninja/v1.12.1/ninja",
"files.associations": {
"uart.h": "c",
"freertos.h": "c",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"map": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp"
}
}

View File

@@ -0,0 +1,106 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile Project",
"type": "process",
"isBuildCommand": true,
"command": "${userHome}/.pico-sdk/ninja/v1.12.1/ninja",
"args": ["-C", "${workspaceFolder}/build"],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "shared",
"showReuseMessage": true,
"clear": true
},
"problemMatcher": "$gcc",
"windows": {
"command": "${env:USERPROFILE}/.pico-sdk/ninja/v1.12.1/ninja.exe"
}
},
{
"label": "Run Project",
"type": "process",
"command": "${env:HOME}/.pico-sdk/picotool/2.1.0/picotool/picotool",
"args": [
"load",
"${command:raspberry-pi-pico.launchTargetPath}",
"-fx"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "shared",
"showReuseMessage": true,
"clear": true
},
"problemMatcher": [],
"windows": {
"command": "${env:USERPROFILE}/.pico-sdk/picotool/2.1.0/picotool/picotool.exe"
}
},
{
"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}\" verify",
"-c", "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
},
"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; 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

@@ -0,0 +1,74 @@
# Generated Cmake Pico project file
cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Initialise pico_sdk from installed location
# (note this can come from environment, CMake cache etc)
# == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work ==
if(WIN32)
set(USERHOME $ENV{USERPROFILE})
else()
set(USERHOME $ENV{HOME})
endif()
set(sdkVersion 2.1.0)
set(toolchainVersion 13_3_Rel1)
set(picotoolVersion 2.1.0)
set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake)
if (EXISTS ${picoVscode})
include(${picoVscode})
endif()
# ====================================================================================
set(PICO_BOARD pico CACHE STRING "Board type")
# Pull in Raspberry Pi Pico SDK (must be before project)
include(pico_sdk_import.cmake)
# Adding FreeRTOS
set(FREERTOS_KERNEL_PATH ../lib/FreeRTOS-Kernel)
include(cmake/FreeRTOS_Kernel_import.cmake)
include(src/gobotrpc/cmake/CMakeLists.txt)
project(i2c-hub-firmware C CXX ASM)
# Initialise the Raspberry Pi Pico SDK
pico_sdk_init()
# Add executable. Default name is the project name, version 0.1
add_executable(i2c-hub-firmware
src/main_core0.cpp
src/main_core1.cpp
#src/freeRTOS_impl.c
)
pico_set_program_name(i2c-hub-firmware "i2c-hub-firmware")
pico_set_program_version(i2c-hub-firmware "0.1")
# Modify the below lines to enable/disable output over UART/USB
pico_enable_stdio_uart(i2c-hub-firmware 1)
pico_enable_stdio_usb(i2c-hub-firmware 0)
# Add the standard library to the build
target_link_libraries(i2c-hub-firmware
FreeRTOS-Kernel-Heap4
GobotRPC
pico_stdlib
)
# Add the standard include files to the build
target_include_directories(i2c-hub-firmware PRIVATE
${CMAKE_CURRENT_LIST_DIR}
)
# Add any user requested libraries
target_link_libraries(i2c-hub-firmware
hardware_i2c
)
pico_add_extra_outputs(i2c-hub-firmware)

View File

@@ -0,0 +1,143 @@
/*
* FreeRTOS V202111.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html
*----------------------------------------------------------*/
/* Scheduler Related */
#define configUSE_PREEMPTION 1
#define configUSE_TICKLESS_IDLE 0
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES 32
#define configMINIMAL_STACK_SIZE ( configSTACK_DEPTH_TYPE ) 256
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
/* Synchronization Related */
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_APPLICATION_TASK_TAG 0
#define configUSE_COUNTING_SEMAPHORES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configUSE_QUEUE_SETS 1
#define configUSE_TIME_SLICING 1
#define configUSE_NEWLIB_REENTRANT 0
// todo need this for lwip FreeRTOS sys_arch to compile
#define configENABLE_BACKWARD_COMPATIBILITY 1
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
/* System */
#define configSTACK_DEPTH_TYPE uint32_t
#define configMESSAGE_BUFFER_LENGTH_TYPE size_t
/* Memory allocation related definitions. */
#define configSUPPORT_STATIC_ALLOCATION 0
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configTOTAL_HEAP_SIZE (1024 * 128)
#define configAPPLICATION_ALLOCATED_HEAP (1024 * 64)
/* Hook function related definitions. */
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_MALLOC_FAILED_HOOK 0
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
/* Run time and task stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_TRACE_FACILITY 1
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
/* Co-routine related definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES 1
/* Software timer related definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH 1024
/* Interrupt nesting behaviour configuration. */
/*
#define configKERNEL_INTERRUPT_PRIORITY [dependent of processor]
#define configMAX_SYSCALL_INTERRUPT_PRIORITY [dependent on processor and application]
#define configMAX_API_CALL_INTERRUPT_PRIORITY [dependent on processor and application]
*/
#if FREE_RTOS_KERNEL_SMP // set by the RP2040 SMP port of FreeRTOS
/* SMP port only */
#define configNUMBER_OF_CORES 2
#define configTICK_CORE 0
#define configRUN_MULTIPLE_PRIORITIES 1
#define configUSE_CORE_AFFINITY 1
#define configUSE_PASSIVE_IDLE_HOOK 0
#endif
/* RP2040 specific */
#define configSUPPORT_PICO_SYNC_INTEROP 1
#define configSUPPORT_PICO_TIME_INTEROP 1
#include <assert.h>
/* Define to trap errors during development. */
#define configASSERT(x) assert(x)
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_xTaskResumeFromISR 1
#define INCLUDE_xQueueGetMutexHolder 1
/* A header file that defines trace macro can be included here. */
#endif /* FREERTOS_CONFIG_H */

View File

@@ -0,0 +1,61 @@
# This is a copy of <FREERTOS_KERNEL_PATH>/portable/ThirdParty/GCC/RP2040/FREERTOS_KERNEL_import.cmake
# This can be dropped into an external project to help locate the FreeRTOS kernel
# It should be include()ed prior to project(). Alternatively this file may
# or the CMakeLists.txt in this directory may be included or added via add_subdirectory
# respectively.
if (DEFINED ENV{FREERTOS_KERNEL_PATH} AND (NOT FREERTOS_KERNEL_PATH))
set(FREERTOS_KERNEL_PATH $ENV{FREERTOS_KERNEL_PATH})
message("Using FREERTOS_KERNEL_PATH from environment ('${FREERTOS_KERNEL_PATH}')")
endif ()
set(FREERTOS_KERNEL_RP2040_RELATIVE_PATH "portable/ThirdParty/GCC/RP2040")
# undo the above
set(FREERTOS_KERNEL_RP2040_BACK_PATH "../../../..")
if (NOT FREERTOS_KERNEL_PATH)
# check if we are inside the FreeRTOS kernel tree (i.e. this file has been included directly)
get_filename_component(_ACTUAL_PATH ${CMAKE_CURRENT_LIST_DIR} REALPATH)
get_filename_component(_POSSIBLE_PATH ${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH} REALPATH)
if (_ACTUAL_PATH STREQUAL _POSSIBLE_PATH)
get_filename_component(FREERTOS_KERNEL_PATH ${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH} REALPATH)
endif()
if (_ACTUAL_PATH STREQUAL _POSSIBLE_PATH)
get_filename_component(FREERTOS_KERNEL_PATH ${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH} REALPATH)
message("Setting FREERTOS_KERNEL_PATH to ${FREERTOS_KERNEL_PATH} based on location of FreeRTOS-Kernel-import.cmake")
elseif (PICO_SDK_PATH AND EXISTS "${PICO_SDK_PATH}/../FreeRTOS-Kernel")
set(FREERTOS_KERNEL_PATH ${PICO_SDK_PATH}/../FreeRTOS-Kernel)
message("Defaulting FREERTOS_KERNEL_PATH as sibling of PICO_SDK_PATH: ${FREERTOS_KERNEL_PATH}")
endif()
endif ()
if (NOT FREERTOS_KERNEL_PATH)
foreach(POSSIBLE_SUFFIX Source FreeRTOS-Kernel FreeRTOS/Source)
# check if FreeRTOS-Kernel exists under directory that included us
set(SEARCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
get_filename_component(_POSSIBLE_PATH ${SEARCH_ROOT}/${POSSIBLE_SUFFIX} REALPATH)
if (EXISTS ${_POSSIBLE_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}/CMakeLists.txt)
get_filename_component(FREERTOS_KERNEL_PATH ${_POSSIBLE_PATH} REALPATH)
message("Setting FREERTOS_KERNEL_PATH to '${FREERTOS_KERNEL_PATH}' found relative to enclosing project")
break()
endif()
endforeach()
endif()
if (NOT FREERTOS_KERNEL_PATH)
message(FATAL_ERROR "FreeRTOS location was not specified. Please set FREERTOS_KERNEL_PATH.")
endif()
set(FREERTOS_KERNEL_PATH "${FREERTOS_KERNEL_PATH}" CACHE PATH "Path to the FreeRTOS Kernel")
get_filename_component(FREERTOS_KERNEL_PATH "${FREERTOS_KERNEL_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
if (NOT EXISTS ${FREERTOS_KERNEL_PATH})
message(FATAL_ERROR "Directory '${FREERTOS_KERNEL_PATH}' not found")
endif()
if (NOT EXISTS ${FREERTOS_KERNEL_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}/CMakeLists.txt)
message(FATAL_ERROR "Directory '${FREERTOS_KERNEL_PATH}' does not contain an RP2040 port here: ${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}")
endif()
set(FREERTOS_KERNEL_PATH ${FREERTOS_KERNEL_PATH} CACHE PATH "Path to the FreeRTOS_KERNEL" FORCE)
add_subdirectory(${FREERTOS_KERNEL_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH} FREERTOS_KERNEL)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Submodule i2c-hub/firmware/i2c-hub-firmware/lib/FreeRTOS-Kernel added at dbf70559b2

View File

@@ -0,0 +1,84 @@
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
# This can be dropped into an external project to help locate this SDK
# It should be include()ed prior to project()
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
endif ()
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
endif ()
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
endif ()
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_TAG} AND (NOT PICO_SDK_FETCH_FROM_GIT_TAG))
set(PICO_SDK_FETCH_FROM_GIT_TAG $ENV{PICO_SDK_FETCH_FROM_GIT_TAG})
message("Using PICO_SDK_FETCH_FROM_GIT_TAG from environment ('${PICO_SDK_FETCH_FROM_GIT_TAG}')")
endif ()
if (PICO_SDK_FETCH_FROM_GIT AND NOT PICO_SDK_FETCH_FROM_GIT_TAG)
set(PICO_SDK_FETCH_FROM_GIT_TAG "master")
message("Using master as default value for PICO_SDK_FETCH_FROM_GIT_TAG")
endif()
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
set(PICO_SDK_FETCH_FROM_GIT_TAG "${PICO_SDK_FETCH_FROM_GIT_TAG}" CACHE FILEPATH "release tag for SDK")
if (NOT PICO_SDK_PATH)
if (PICO_SDK_FETCH_FROM_GIT)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
if (PICO_SDK_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
# GIT_SUBMODULES_RECURSE was added in 3.17
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
GIT_SUBMODULES_RECURSE FALSE
)
else ()
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
)
endif ()
if (NOT pico_sdk)
message("Downloading Raspberry Pi Pico SDK")
FetchContent_Populate(pico_sdk)
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
endif ()
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
else ()
message(FATAL_ERROR
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
)
endif ()
endif ()
get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
if (NOT EXISTS ${PICO_SDK_PATH})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
endif ()
set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
endif ()
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
include(${PICO_SDK_INIT_CMAKE_FILE})

View File

@@ -0,0 +1,27 @@
add_library(GobotRPC STATIC
${CMAKE_CURRENT_LIST_DIR}/../ctrl_interface/base.cpp
${CMAKE_CURRENT_LIST_DIR}/../ctrl_interface/ci_instruction.cpp
${CMAKE_CURRENT_LIST_DIR}/../ctrl_interface/uart_rp2040/hardware_rp2040_uart.cpp
${CMAKE_CURRENT_LIST_DIR}/../ctrl_interface/uart_rp2040/rx.cpp
${CMAKE_CURRENT_LIST_DIR}/../crc16.cpp
${CMAKE_CURRENT_LIST_DIR}/../protocol_base.cpp
${CMAKE_CURRENT_LIST_DIR}/../transmission_interface/rp2040_i2c_init.cpp
${CMAKE_CURRENT_LIST_DIR}/../transmission_interface/rp2040_i2c_tx.cpp
${CMAKE_CURRENT_LIST_DIR}/../transmission_interface/rp2040_i2c_rx.cpp
${CMAKE_CURRENT_LIST_DIR}/../transmission_interface/rp2040_i2c_int.cpp
${CMAKE_CURRENT_LIST_DIR}/../transmission_interface/rp2040_i2c_ci_instructions.cpp
)
target_include_directories(GobotRPC PUBLIC
${CMAKE_CURRENT_LIST_DIR}/../include
${CMAKE_CURRENT_LIST_DIR}/../include/ti
${CMAKE_CURRENT_LIST_DIR}/../../..
)
target_link_libraries(GobotRPC
FreeRTOS-Kernel-Heap4
pico_stdlib
hardware_uart
hardware_irq
hardware_i2c
)

View File

@@ -0,0 +1,37 @@
#define POLY 0x8408
/*
// 16 12 5
// this is the CCITT CRC 16 polynomial X + X + X + 1.
// This works out to be 0x1021, but the way the algorithm works
// lets us use 0x8408 (the reverse of the bit pattern). The high
// bit is always assumed to be set, thus we only use 16 bits to
// represent the 17 bit value.
*/
unsigned short crc16(char *data_p, unsigned short length)
{
unsigned char i;
unsigned int data;
unsigned int crc = 0xffff;
if (length == 0)
return (~crc);
do
{
for (i=0, data=(unsigned int)0xff & *data_p++;
i < 8;
i++, data >>= 1)
{
if ((crc & 0x0001) ^ (data & 0x0001))
crc = (crc >> 1) ^ POLY;
else crc >>= 1;
}
} while (--length);
crc = ~crc;
data = crc;
crc = (crc << 8) | (data >> 8 & 0xff);
return (crc);
}

View File

@@ -0,0 +1,70 @@
#include "ctrl_interface.hpp"
#include "pinConfig.hpp"
#include "FreeRTOSConfig.h"
#include "FreeRTOS.h"
#include "task.h"
GobotRPC_CI::GobotRPC_CI(I_GobotRPC_CI_Hardware *hardware, UBaseType_t core, QueueHandle_t ciInstructionQueue) {
this->ciInstructionQueue = ciInstructionQueue;
this->hardware = hardware;
this->hardware->registerCB_RxData(GobotRPC_CI_rxData_cb, this);
xTaskCreateAffinitySet(GobotRPC_CI_heartBeatTaskFn, "Heartbeat Task", 2048, this, 2, core, &this->heartBeatTaskHandle);
xTaskCreateAffinitySet(GobotRPC_CI_txCIInstructionTaskFn, "Tx CI Instruction Task", 2048, this, 3, core, &this->txCIInstructionTaskHandle);
}
// Rx Side
void GobotRPC_CI_rxData_cb(void * args, char *data, size_t len) {
GobotRPC_CI *gobotRPC = (GobotRPC_CI *)args;
gobotRPC->onRxData(data, len);
}
void GobotRPC_CI::onRxData(char *data, size_t len) {
GobotRPC_CI_CMD cmd = (GobotRPC_CI_CMD)data[0];
switch (cmd) {
case TX_CI_PACKET:
if(this->cb_TxPacket != NULL) {
uint32_t addr = (data[2] << 24) | (data[3] << 16) | (data[4] << 8) | data[5];
this->cb_TxPacket(this->cb_TxPacket_args, data+6, len-6, addr);
}
break;
default:
break;
}
}
void GobotRPC_CI::registerCB_TxPacket(callback_TxPacket cb, void *args) {
this->cb_TxPacket = cb;
this->cb_TxPacket_args = args;
}
void GobotRPC_CI::send_RxPacket(char *data, size_t len, uint32_t addr) {
data[0] = RX_CI_PACKET;
data[1] = len + CI_RX_PACKAGE_DATA_OFFSET;
data[2] = (addr >> 24) & 0xff;
data[3] = (addr >> 16) & 0xff;
data[4] = (addr >> 8) & 0xff;
data[5] = addr & 0xff;
this->hardware->send(data, len+6);
}
// Heartbeat Task
void GobotRPC_CI_heartBeatTaskFn(void *args) {
GobotRPC_CI *gobotRPC = (GobotRPC_CI *)args;
gobotRPC->heartBeartTaskFn();
}
void GobotRPC_CI::heartBeartTaskFn() {
char heartBeatPacket[] = {HEARTBEAT, 0x02};
while(1) {
this->hardware->send(heartBeatPacket, 2);
vTaskDelay(GOBOTRPC_HEARTBEAT_INTERVAL / portTICK_PERIOD_MS);
}
}

View File

@@ -0,0 +1,60 @@
#include "ctrl_interface.hpp"
#include "ctrl_interface_instructions.hpp"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
void GobotRPC_CI_txCIInstructionTaskFn(void *args) {
GobotRPC_CI *gobotRPC = (GobotRPC_CI *)args;
gobotRPC->txCIInstructionTask();
}
void GobotRPC_CI::txCIInstructionTask() {
while(1) {
CI_Instruction_Transport ciInstruction;
xQueueReceive(ciInstructionQueue, &ciInstruction, portMAX_DELAY);
switch (ciInstruction.type) {
case CI_INSTRUCTION_SEND_TRANMISSION_ERROR: {
uint32_t addr = ciInstruction.data[1] | (ciInstruction.data[2] << 8) | (ciInstruction.data[3] << 16) | (ciInstruction.data[4] << 24);
uint8_t rx = ciInstruction.data[0];
send_ErrorTransmission(rx, addr);
break;
}
case CI_INSTRUCTION_SEND_TRANMISSION_SUCCESS: {
uint32_t addr = ciInstruction.data[1] | (ciInstruction.data[2] << 8) | (ciInstruction.data[3] << 16) | (ciInstruction.data[4] << 24);
send_SuccessTransmission(addr);
break;
}
}
}
}
void GobotRPC_CI::send_ErrorTransmission(bool rx, uint64_t addr) {
char errorPacket[7];
errorPacket[0] = ERROR_TRANMISSION;
errorPacket[1] = 7;
errorPacket[2] = rx ? 0x01 : 0x00;
errorPacket[3] = (addr >> 24) & 0xff;
errorPacket[4] = (addr >> 16) & 0xff;
errorPacket[5] = (addr >> 8) & 0xff;
errorPacket[6] = addr & 0xff;
this->hardware->send(errorPacket, 7);
}
void GobotRPC_CI::send_SuccessTransmission(uint64_t addr) {
char successPacket[6];
successPacket[0] = SUCESS_TRANMISSION;
successPacket[1] = 6;
successPacket[2] = (addr >> 24) & 0xff;
successPacket[3] = (addr >> 16) & 0xff;
successPacket[4] = (addr >> 8) & 0xff;
successPacket[5] = addr & 0xff;
this->hardware->send(successPacket, 6);
}

View File

@@ -0,0 +1,54 @@
#include "ctrl_interface_hardware.hpp"
#include "pinConfig.hpp"
#include "pico/stdlib.h"
#include "hardware/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include <string.h>
// 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, UBaseType_t core) {
g_GobotRPC_CI_Hardware_RP2040_UART = this;
this->core = core;
initRxTaskAndQueues();
uartTxMutex = xSemaphoreCreateMutex();
this->uart = uart;
uart_init(this->uart, baudrate);
gpio_set_function(GOBOTRPC_CI_UART_RX, UART_FUNCSEL_NUM(uart, GOBOTRPC_CI_UART_RX));
gpio_set_function(GOBOTRPC_CI_UART_TX, UART_FUNCSEL_NUM(uart, GOBOTRPC_CI_UART_TX));
uart_set_hw_flow(uart, false, false);
uart_set_format(uart, 8, 1, UART_PARITY_NONE);
uart_set_baudrate(uart, baudrate);
uart_set_fifo_enabled(uart, true);
int UART_IRQ = uart == uart0 ? UART0_IRQ : UART1_IRQ;
irq_set_exclusive_handler(UART_IRQ, GobotRPC_CI_Hardware_RP2040_UART_isr);
irq_set_enabled(UART_IRQ, true);
uart_set_irq_enables(uart, true, false);
}
void GobotRPC_CI_Hardware_RP2040_UART::registerCB_RxData(callback_rxData cb, void *args) {
this->cb_rxData = cb;
this->cb_rxData_args = args;
}
// Sending data
void GobotRPC_CI_Hardware_RP2040_UART::send(char *data, size_t len) {
xSemaphoreTake(uartTxMutex, portMAX_DELAY);
uart_write_blocking(this->uart, (uint8_t *)(data), len);
uart_tx_wait_blocking(this->uart);
xSemaphoreGive(uartTxMutex);
}

View File

@@ -0,0 +1,121 @@
#include "ctrl_interface_hardware.hpp"
#include "pico/stdlib.h"
#include <string.h>
#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
// External Functions
void GobotRPC_CI_Hardware_RP2040_UART_isr() {
GobotRPC_CI_Hardware_RP2040_UART *uart = (GobotRPC_CI_Hardware_RP2040_UART *)g_GobotRPC_CI_Hardware_RP2040_UART;
uart->onRx_ISR();
};
void GobotRPC_CI_Hardware_RP2040_UART_Task_RXProcessing(void *args) {
GobotRPC_CI_Hardware_RP2040_UART *uart = (GobotRPC_CI_Hardware_RP2040_UART *)args;
uart->rxProcessingTaskFn();
}
// Init
void GobotRPC_CI_Hardware_RP2040_UART::initRxTaskAndQueues() {
emptyInputBuffersQueue = xQueueCreate(NUM_INPUT_BUFFERS, sizeof(inputBuffers_t *));
filledInputBuffersQueue = xQueueCreate(NUM_INPUT_BUFFERS, sizeof(inputBuffers_t *));
for(int i = 0; i < NUM_INPUT_BUFFERS; i++) {
inputBuffers_t * p = &inputBufferPool[i];
memset(p->data, 0xff, 256);
p->len = 0;
p->state = NEW;
p->expected_length = 0;
xQueueSend(emptyInputBuffersQueue, &p, portMAX_DELAY);
}
rxSignalSemaphore = xSemaphoreCreateBinary();
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) {
switch(buffer->state) {
case NEW:
buffer->data[0] = data;
buffer->len = 1;
buffer->state = READ_SIZE;
break;
case READ_SIZE:
buffer->data[1] = data;
buffer->expected_length = data;
buffer->len += 1;
if(buffer->len == buffer->expected_length) {
buffer->state = FULL;
} else {
buffer->state = READ_DATA;
}
break;
case READ_DATA:
buffer->data[buffer->len] = data;
buffer->len += 1;
if(buffer->len == buffer->expected_length) {
buffer->state = FULL;
} else {
buffer->state = READ_DATA;
}
break;
case FULL:
break;
}
return buffer->state;
}
// real Task Fns
void GobotRPC_CI_Hardware_RP2040_UART::onRx_ISR() {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
static inputBuffers_t * inputBuffer = NULL;
while (uart_is_readable(this->uart)) {
if(inputBuffer == NULL) {
xQueueReceiveFromISR(emptyInputBuffersQueue, &inputBuffer, &xHigherPriorityTaskWoken);
if(inputBuffer == NULL) {
return; // No more buffers -> device overload
}
inputBuffer->state = NEW;
inputBuffer->len = 0;
inputBuffer->expected_length = 0;
}
inputBufferRXState_t state = fillBuffer(inputBuffer, uart_getc(this->uart));
if (state == FULL) {
xQueueSendFromISR(filledInputBuffersQueue, &inputBuffer, &xHigherPriorityTaskWoken);
inputBuffer = NULL;
}
}
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
void GobotRPC_CI_Hardware_RP2040_UART::rxProcessingTaskFn() {
inputBuffers_t * inputBuffer = NULL;
while(1) {
xQueueReceive(filledInputBuffersQueue, &inputBuffer, portMAX_DELAY);
if(this->cb_rxData != NULL) {
this->cb_rxData(this->cb_rxData_args, inputBuffer->data, inputBuffer->len);
}
vTaskDelay(1000);
}
}

View File

@@ -0,0 +1,2 @@
#pragma once
unsigned short crc16(char *data_p, unsigned short length);

View File

@@ -0,0 +1,51 @@
#pragma once
#include "ctrl_interface_hardware.hpp"
#include <strings.h>
enum GobotRPC_CI_CMD {
TX_CI_PACKET = 0x01,
RX_CI_PACKET = 0x02,
PERFORM_SCAN_CI_PACKET = 0x03,
SCAN_RESULT_CI_PACKET = 0x04,
SUCESS_TRANMISSION = 0xfc,
ERROR_TRANMISSION = 0xfd,
HEARTBEAT = 0xff
};
#define CI_TX_PACKAGE_DATA_OFFSET 6
#define CI_TX_PACKAGE_SIZE(data_len) (data_len + CI_TX_PACKAGE_SIZE)
#define CI_RX_PACKAGE_DATA_OFFSET 6
#define CI_RX_PACKAGE_SIZE(data_len) (data_len + CI_RX_PACKAGE_DATA_OFFSET)
typedef void (*callback_TxPacket)(void * args, char *data, size_t len, uint32_t addr);
void GobotRPC_CI_rxData_cb(void * args, char *data, size_t len);
void GobotRPC_CI_heartBeatTaskFn(void *args);
void GobotRPC_CI_txCIInstructionTaskFn(void *args);
class GobotRPC_CI {
private:
I_GobotRPC_CI_Hardware *hardware;
callback_TxPacket cb_TxPacket;
void * cb_TxPacket_args;
TaskHandle_t heartBeatTaskHandle;
TaskHandle_t txCIInstructionTaskHandle;
QueueHandle_t ciInstructionQueue;
public:
GobotRPC_CI(I_GobotRPC_CI_Hardware *hardware, UBaseType_t core, QueueHandle_t ciInstructionQueue);
void registerCB_TxPacket(callback_TxPacket cb, void *args);
void send_RxPacket(char *data, size_t len, uint32_t addr);
void onRxData(char *data, size_t len);
void heartBeartTaskFn();
// CI Instruction Stuff
void txCIInstructionTask();
void send_ErrorTransmission(bool rx, uint64_t addr);
void send_SuccessTransmission(uint64_t addr);
};

Some files were not shown because too many files have changed in this diff Show More