Skip to content

Commit 3517ac8

Browse files
authored
Merge branch 'main' into feature/p3t1755-driver
2 parents c468a5c + a893274 commit 3517ac8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+19597
-10831
lines changed

.github/workflows/build_calypso.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/workflows/format-check.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ jobs:
77
name: Check format of C
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v4
11-
with:
12-
submodules: recursive
10+
- uses: actions/checkout@v6
1311
- name: Run clang-format style check for C/C++ sources
1412
uses: Northeastern-Electric-Racing/clang-format-action@main
1513
with:

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "dev/OpenOCD"]
2+
path = dev/OpenOCD
3+
url = https://github.com/STMicroelectronics/OpenOCD

NetX/inc/u_nx_debug.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef _U_NX_DEBUG_H
2+
#define _U_NX_DEBUG_H
3+
4+
// clang-format off
5+
6+
#include "nx_api.h"
7+
8+
/* This file contains NetX-specific debug helpers. */
9+
10+
/* API */
11+
const char *nx_status_toString(UINT status); /* Converts a NetX status macro to a printable string. Meant to be used with PRINTLN_...() macros (defined in another file). */
12+
13+
// clang-format on
14+
#endif /* u_nx_debug.h */

NetX/inc/u_nx_ethernet.h

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#ifndef _U_NX_ETHERNET_H
2+
#define _U_NX_ETHERNET_H
3+
4+
// clang-format off
5+
6+
/*
7+
* NOTE: This file can only be used in projects that include NetXDuo.
8+
*/
9+
10+
#include <stdint.h>
11+
#include <stdbool.h>
12+
#include "nx_api.h"
13+
14+
/* CONFIG */
15+
#define ETH_UDP_PORT 2006 /* UDP port for communication */
16+
#define ETH_MESSAGE_SIZE 8 /* Maximum ethernet message size in bytes. */
17+
#define ETH_MAX_PACKETS 10 /* Maximum number of packets we wanna handle simultaneously */
18+
#define ETH_NUMBER_OF_NODES 8 /* Number of nodes in the network. */
19+
20+
typedef enum {
21+
VCU = (1 << 0), // 0b00000001
22+
COMPUTE = (1 << 1), // 0b00000010
23+
TPU = (1 << 2), // 0b00000100
24+
MSB1 = (1 << 3), // 0b00001000
25+
MSB2 = (1 << 4), // 0b00010000
26+
MSB3 = (1 << 5), // 0b00100000
27+
MSB4 = (1 << 6), // 0b01000000
28+
NODE8 = (1 << 7), // 0b10000000
29+
} ethernet_node_t;
30+
#define ETH_IP(node) IP_ADDRESS(239, 0, 0, node)
31+
32+
/* These node ids are ONLY relavent to PLCA configuration.
33+
They are meant to be used when configuring a PHY. The IDs must be sequential, and the "0" id always indicates the network's coordinator node.
34+
They have no impact on application-level IP addresses or message processing.
35+
36+
For example, if you're using the LAN8670 PHY driver, you'd probably use these enum values like this:
37+
LAN8670_PLCA_Set_Node_Count(&lan8670, PLCA_NUM_NODES);
38+
LAN8670_PLCA_Set_Node_Id(&lan8670, PLCA_VCU) // replace 'PLCA_VCU' with whatever board it is
39+
*/
40+
typedef enum {
41+
PLCA_VCU, // 0. This is the PLCA coordinator node.
42+
PLCA_COMPUTE,
43+
PLCA_TPU,
44+
PLCA_MSB1,
45+
PLCA_MSB2,
46+
PLCA_MSB3,
47+
PLCA_MSB4,
48+
PLCA_NODE8,
49+
PLCA_NUM_NODES
50+
} plca_node_id_t;
51+
/* END CONFIG */
52+
53+
typedef struct {
54+
uint8_t sender_id;
55+
uint8_t recipient_id;
56+
uint8_t message_id;
57+
uint8_t data_length;
58+
uint8_t data[ETH_MESSAGE_SIZE];
59+
} ethernet_message_t;
60+
61+
/* Function Pointers (for initialization). */
62+
typedef void (*DriverFunction)(NX_IP_DRIVER *); /* User-supplied network driver used to send and receive IP packets. */
63+
typedef void (*OnRecieve)(ethernet_message_t message); /* User-supplied function that will be called whenever an ethernet message is recieved. */
64+
65+
/**
66+
* @brief Initializes the NetX ethernet system in a repo.
67+
* @param node_id The ID (ethernet_node_t) of this node.
68+
* @param driver User-supplied network driver function. Should be set to nx_stm32_eth_driver (from "nx_stm32_eth_driver.h") for STM32 projects.
69+
* @param on_recieve User-supplied function to be called whenever an ethernet message is recieved. The function's only parameter is an ethernet_message_t instance containing the recieved message.
70+
* @return Status.
71+
*/
72+
uint8_t ethernet_init(ethernet_node_t node_id, DriverFunction driver, OnRecieve on_recieve);
73+
74+
/**
75+
* @brief Creates an ethernet message. Can be send with ethernet_send_message(), or added to a queue.
76+
* @param recipient_id The ID of the recipient node.
77+
* @param message_id The ID of the message.
78+
* @param data Pointer to the data to include in the message.
79+
* @param data_length Length of the data in bytes.
80+
* @return The created ethernet message.
81+
*/
82+
ethernet_message_t ethernet_create_message(uint8_t message_id, ethernet_node_t recipient_id, uint8_t *data, uint8_t data_length);
83+
84+
/**
85+
* @brief Sends an ethernet message.
86+
* @param message The message to send.
87+
* @return Status.
88+
*/
89+
uint8_t ethernet_send_message(ethernet_message_t *message);
90+
91+
// clang-format on
92+
#endif /* u_nx_ethernet.h */

NetX/src/u_nx_debug.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include "u_nx_debug.h"
2+
3+
// clang-format off
4+
5+
/* Converts a NetX status macro to a printable string. */
6+
/* This function is intended to be used with PRINTLN_...() macros, and shouldn't really ever be used outside of debugging purposes. */
7+
/* (these macros are defined in nx_api.h) */
8+
const char* nx_status_toString(UINT status) {
9+
switch(status) {
10+
case NX_SUCCESS: return "NX_SUCCESS";
11+
case NX_NO_PACKET: return "NX_NO_PACKET";
12+
case NX_UNDERFLOW: return "NX_UNDERFLOW";
13+
case NX_OVERFLOW: return "NX_OVERFLOW";
14+
case NX_NO_MAPPING: return "NX_NO_MAPPING";
15+
case NX_DELETED: return "NX_DELETED";
16+
case NX_POOL_ERROR: return "NX_POOL_ERROR";
17+
case NX_PTR_ERROR: return "NX_PTR_ERROR";
18+
case NX_WAIT_ERROR: return "NX_WAIT_ERROR";
19+
case NX_SIZE_ERROR: return "NX_SIZE_ERROR";
20+
case NX_OPTION_ERROR: return "NX_OPTION_ERROR";
21+
case NX_DELETE_ERROR: return "NX_DELETE_ERROR";
22+
case NX_CALLER_ERROR: return "NX_CALLER_ERROR";
23+
case NX_INVALID_PACKET: return "NX_INVALID_PACKET";
24+
case NX_INVALID_SOCKET: return "NX_INVALID_SOCKET";
25+
case NX_NOT_ENABLED: return "NX_NOT_ENABLED";
26+
case NX_ALREADY_ENABLED: return "NX_ALREADY_ENABLED";
27+
case NX_ENTRY_NOT_FOUND: return "NX_ENTRY_NOT_FOUND";
28+
case NX_NO_MORE_ENTRIES: return "NX_NO_MORE_ENTRIES";
29+
case NX_ARP_TIMER_ERROR: return "NX_ARP_TIMER_ERROR";
30+
case NX_RESERVED_CODE0: return "NX_RESERVED_CODE0";
31+
case NX_WAIT_ABORTED: return "NX_WAIT_ABORTED";
32+
case NX_IP_INTERNAL_ERROR: return "NX_IP_INTERNAL_ERROR";
33+
case NX_IP_ADDRESS_ERROR: return "NX_IP_ADDRESS_ERROR";
34+
case NX_ALREADY_BOUND: return "NX_ALREADY_BOUND";
35+
case NX_PORT_UNAVAILABLE: return "NX_PORT_UNAVAILABLE";
36+
case NX_NOT_BOUND: return "NX_NOT_BOUND";
37+
case NX_RESERVED_CODE1: return "NX_RESERVED_CODE1";
38+
case NX_SOCKET_UNBOUND: return "NX_SOCKET_UNBOUND";
39+
case NX_NOT_CREATED: return "NX_NOT_CREATED";
40+
case NX_SOCKETS_BOUND: return "NX_SOCKETS_BOUND";
41+
case NX_NO_RESPONSE: return "NX_NO_RESPONSE";
42+
case NX_POOL_DELETED: return "NX_POOL_DELETED";
43+
case NX_ALREADY_RELEASED: return "NX_ALREADY_RELEASED";
44+
case NX_RESERVED_CODE2: return "NX_RESERVED_CODE2";
45+
case NX_MAX_LISTEN: return "NX_MAX_LISTEN";
46+
case NX_DUPLICATE_LISTEN: return "NX_DUPLICATE_LISTEN";
47+
case NX_NOT_CLOSED: return "NX_NOT_CLOSED";
48+
case NX_NOT_LISTEN_STATE: return "NX_NOT_LISTEN_STATE";
49+
case NX_IN_PROGRESS: return "NX_IN_PROGRESS";
50+
case NX_NOT_CONNECTED: return "NX_NOT_CONNECTED";
51+
case NX_WINDOW_OVERFLOW: return "NX_WINDOW_OVERFLOW";
52+
case NX_ALREADY_SUSPENDED: return "NX_ALREADY_SUSPENDED";
53+
case NX_DISCONNECT_FAILED: return "NX_DISCONNECT_FAILED";
54+
case NX_STILL_BOUND: return "NX_STILL_BOUND";
55+
case NX_NOT_SUCCESSFUL: return "NX_NOT_SUCCESSFUL";
56+
case NX_UNHANDLED_COMMAND: return "NX_UNHANDLED_COMMAND";
57+
case NX_NO_FREE_PORTS: return "NX_NO_FREE_PORTS";
58+
case NX_INVALID_PORT: return "NX_INVALID_PORT";
59+
case NX_INVALID_RELISTEN: return "NX_INVALID_RELISTEN";
60+
case NX_CONNECTION_PENDING: return "NX_CONNECTION_PENDING";
61+
case NX_TX_QUEUE_DEPTH: return "NX_TX_QUEUE_DEPTH";
62+
case NX_NOT_IMPLEMENTED: return "NX_NOT_IMPLEMENTED";
63+
case NX_NOT_SUPPORTED: return "NX_NOT_SUPPORTED";
64+
case NX_INVALID_INTERFACE: return "NX_INVALID_INTERFACE";
65+
case NX_INVALID_PARAMETERS: return "NX_INVALID_PARAMETERS";
66+
case NX_NOT_FOUND: return "NX_NOT_FOUND";
67+
case NX_CANNOT_START: return "NX_CANNOT_START";
68+
case NX_NO_INTERFACE_ADDRESS: return "NX_NO_INTERFACE_ADDRESS";
69+
case NX_INVALID_MTU_DATA: return "NX_INVALID_MTU_DATA";
70+
case NX_DUPLICATED_ENTRY: return "NX_DUPLICATED_ENTRY";
71+
case NX_PACKET_OFFSET_ERROR: return "NX_PACKET_OFFSET_ERROR";
72+
case NX_OPTION_HEADER_ERROR: return "NX_OPTION_HEADER_ERROR";
73+
case NX_CONTINUE: return "NX_CONTINUE";
74+
case NX_TCPIP_OFFLOAD_ERROR: return "NX_TCPIP_OFFLOAD_ERROR";
75+
default: return "UNKNOWN_STATUS";
76+
}
77+
}
78+
79+
// clang-format on

0 commit comments

Comments
 (0)