Skip to content

Commit 5a41029

Browse files
committed
2 parents 8f6f6b3 + 3147da8 commit 5a41029

10 files changed

Lines changed: 1435 additions & 6 deletions

File tree

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 DEBUG_PRINTLN() (defined in another file). */
12+
13+
// clang-format on
14+
#endif /* u_nx_debug.h */

NetX/inc/u_nx_ethernet.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 "nx_api.h"
12+
13+
/* CONFIG */
14+
#define ETH_UDP_PORT 2006 /* UDP port for communication */
15+
#define ETH_MESSAGE_SIZE 8 /* Maximum ethernet message size in bytes. */
16+
#define ETH_MAX_PACKETS 10 /* Maximum number of packets we wanna handle simultaneously */
17+
#define ETH_NUMBER_OF_NODES 8 /* Number of nodes in the network. */
18+
19+
typedef enum {
20+
VCU = (1 << 0), // 0b00000001
21+
COMPUTE = (1 << 1), // 0b00000010
22+
TPU = (1 << 2), // 0b00000100
23+
MSB1 = (1 << 3), // 0b00001000
24+
MSB2 = (1 << 4), // 0b00010000
25+
MSB3 = (1 << 5), // 0b00100000
26+
MSB4 = (1 << 6), // 0b01000000
27+
NODE8 = (1 << 7), // 0b10000000
28+
} ethernet_node_t;
29+
#define ETH_IP(node) IP_ADDRESS(239, 0, 0, node)
30+
/* END CONFIG */
31+
32+
typedef struct {
33+
uint8_t sender_id;
34+
uint8_t recipient_id;
35+
uint8_t message_id;
36+
uint8_t data_length;
37+
uint8_t data[ETH_MESSAGE_SIZE];
38+
} ethernet_message_t;
39+
40+
/* Function Pointers (for initialization). */
41+
typedef void (*DriverFunction)(NX_IP_DRIVER *); /* User-supplied network driver used to send and receive IP packets. */
42+
typedef void (*OnRecieve)(ethernet_message_t message); /* User-supplied function that will be called whenever an ethernet message is recieved. */
43+
44+
/**
45+
* @brief Initializes the NetX ethernet system in a repo.
46+
* @param node_id The ID (ethernet_node_t) of this node.
47+
* @param driver User-supplied network driver function. Should be set to nx_stm32_eth_driver (from "nx_stm32_eth_driver.h") for STM32 projects.
48+
* @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.
49+
* @return Status.
50+
*/
51+
uint8_t ethernet_init(ethernet_node_t node_id, DriverFunction driver, OnRecieve on_recieve);
52+
53+
/**
54+
* @brief Creates an ethernet message. Can be send with ethernet_send_message(), or added to a queue.
55+
* @param recipient_id The ID of the recipient node.
56+
* @param message_id The ID of the message.
57+
* @param data Pointer to the data to include in the message.
58+
* @param data_length Length of the data in bytes.
59+
* @return The created ethernet message.
60+
*/
61+
ethernet_message_t ethernet_create_message(uint8_t message_id, ethernet_node_t recipient_id, uint8_t *data, uint8_t data_length);
62+
63+
/**
64+
* @brief Sends an ethernet message.
65+
* @param message The message to send.
66+
* @return Status.
67+
*/
68+
uint8_t ethernet_send_message(ethernet_message_t *message);
69+
70+
// clang-format on
71+
#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 DEBUG_PRINTLN(), 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)