Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions NetX/inc/u_nx_ethernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
#define ETH_NUMBER_OF_NODES 8 /* Number of nodes in the network. */

typedef enum {
VCU = (1 << 0), // 0b00000001
COMPUTE = (1 << 1), // 0b00000010
TPU = (1 << 2), // 0b00000100
TPU = (1 << 0), // 0b00000001
VCU = (1 << 1), // 0b00000010
COMPUTE = (1 << 2), // 0b00000100
MSB1 = (1 << 3), // 0b00001000
MSB2 = (1 << 4), // 0b00010000
MSB3 = (1 << 5), // 0b00100000
MSB4 = (1 << 6), // 0b01000000
NODE8 = (1 << 7), // 0b10000000
} ethernet_node_t;
#define ETH_IP(node) IP_ADDRESS(239, 0, 0, node)
#define ETH_IP(node) IP_ADDRESS(224, 0, 0, node)

/* These node ids are ONLY relavent to PLCA configuration.
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.
Expand All @@ -38,9 +38,9 @@ typedef enum {
LAN8670_PLCA_Set_Node_Id(&lan8670, PLCA_VCU) // replace 'PLCA_VCU' with whatever board it is
*/
typedef enum {
PLCA_VCU, // 0. This is the PLCA coordinator node.
PLCA_TPU, // 0. This is the PLCA coordinator node.
PLCA_VCU,
PLCA_COMPUTE,
PLCA_TPU,
PLCA_MSB1,
PLCA_MSB2,
PLCA_MSB3,
Expand All @@ -55,7 +55,7 @@ typedef struct {
uint8_t recipient_id;
uint8_t message_id;
uint8_t data_length;
uint8_t data[ETH_MESSAGE_SIZE];
uint8_t data[10]; // change back
} ethernet_message_t;

/* Function Pointers (for initialization). */
Expand Down
36 changes: 32 additions & 4 deletions NetX/src/u_nx_ethernet.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// clang-format off
#include "u_nx_ethernet.h"
#include "nx_stm32_eth_driver.h"
#include "u_nx_debug.h"
#include "u_tx_debug.h"
#include "nx_api.h"
Expand All @@ -8,7 +9,7 @@

/* PRIVATE MACROS */
#define _PACKET_POOL_SIZE \
((sizeof(ethernet_message_t) + sizeof(NX_PACKET)) * ETH_MAX_PACKETS)
((sizeof(ethernet_message_t) + sizeof(NX_PACKET)) * ETH_MAX_PACKETS * 100)
#define _IP_THREAD_STACK_SIZE 2048
#define _ARP_CACHE_SIZE 1024
#define _IP_THREAD_PRIORITY 1
Expand Down Expand Up @@ -109,7 +110,7 @@ uint8_t ethernet_init(ethernet_node_t node_id, DriverFunction driver, OnRecieve
status = nx_packet_pool_create(
&device.packet_pool, // Pointer to the packet pool instance
"Ethernet Packet Pool", // Name
sizeof(ethernet_message_t), // Payload size (i.e. the size of each packet)
sizeof(ethernet_message_t) + 128, // Payload size (i.e. the size of each packet)
device.packet_pool_memory, // Pointer to the pool's memory area
_PACKET_POOL_SIZE // Size of the pool's memory area
);
Expand Down Expand Up @@ -263,6 +264,18 @@ uint8_t ethernet_send_message(ethernet_message_t *message) {
return U_ERROR;
}

PRINTLN_INFO("got to this part of ethernet_send_message()");

/* Make sure interface is up. */
ULONG actual_status = 0;
status = nx_ip_interface_status_check(&device.ip, 0, NX_IP_LINK_ENABLED, &actual_status, 1000);
if(status != NX_SUCCESS) {
PRINTLN_ERROR("Failed to call nx_ip_interface_status_check() (Status: %d/%s).", status, nx_status_toString(status));
return U_ERROR;
} else {
PRINTLN_INFO("Succeeded calling nx_ip_interface_status_check() (Status: %d/%s).", status, nx_status_toString(status));
}

/* Allocate a packet */
status = nx_packet_allocate(
&device.packet_pool, // Packet pool
Expand All @@ -275,6 +288,8 @@ uint8_t ethernet_send_message(ethernet_message_t *message) {
return U_ERROR;
}

PRINTLN_INFO("got to nx_packet_allocate() part of send message");

/* Append message data to packet */
status = nx_packet_data_append(
packet, // Packet
Expand All @@ -289,6 +304,16 @@ uint8_t ethernet_send_message(ethernet_message_t *message) {
return U_ERROR;
}

PRINTLN_INFO("got to nx_packet_data_append() part of send message");

ULONG length = 0;
status = nx_packet_length_get(packet, &length);
if(status != NX_SUCCESS) {
PRINTLN_ERROR("Failed to call nx_packet_length_get() (Status: %d/%n).", status, nx_status_toString(status));
} else {
PRINTLN_INFO("Packet has length of %d!", length);
}

/* Send message */
status = nx_udp_socket_send(
&device.socket,
Expand All @@ -297,12 +322,15 @@ uint8_t ethernet_send_message(ethernet_message_t *message) {
ETH_UDP_PORT
);
if(status != NX_SUCCESS) {
PRINTLN_ERROR("Failed to send packet (Status: %d/%s, Message ID: %d).", status, nx_status_toString(status), message->message_id);
PRINTLN_ERROR("Failed to send packet (Status: %d/%s, Message ID: %d, Recipient ID: %d, IP Address: %d, IP components: 224.0.0.%d).", status, nx_status_toString(status), message->message_id, message->recipient_id, ETH_IP(message->recipient_id), ETH_IP(message->recipient_id));
nx_packet_release(packet);
return U_ERROR;
}

PRINTLN_INFO("Sent ethernet message (Recipient ID: %d, Message ID: %d).", message->recipient_id, message->message_id);
PRINTLN_INFO("got to nx_udp_socket_send() part of send message");

PRINTLN_INFO("Sent ethernet message (Recipient ID: %d, Message ID: %d, Message Contents: %d).", message->recipient_id, message->message_id, message->data);
PRINTLN_INFO("TX complete count: %lu", tx_complete_count);
return U_SUCCESS;
}
// clang-format on
28 changes: 28 additions & 0 deletions general/include/lan8670.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,32 @@ int32_t LAN8670_Get_Link_State(lan8670_t *lan, uint8_t *state);
* @return Status.
*/
int32_t LAN8670_RegisterBusIO(lan8670_t *lan, lan8670_IOCtx_t *ioctx);

/**
* @brief Reads the PLCA status.
*
* @param lan Pointer to the lan8670_t instance.
* @param status Buffer for the returned status value. false=The PLCA reconciliation sublayer is not regularly receiving or transmitting the BEACON, true=The PLCA reconciliation sublayer is regularly receiving or transmitting the BEACON
* @return Status (an error code, not related to the *status bool).
*/
int32_t LAN8670_PLCA_Get_Status(lan8670_t *lan, bool *status);

/**
* @brief Reads the PLCA TOTMR (Transmit Opportunity Timer) setting. Should be 32 bit-times by default.
*
* @param lan Pointer to the lan8670_t instance.
* @param buffer Buffer for the register value. The value has a unit of bit-times.
* @return Status.
*/
int32_t LAN8670_PLCA_ReadTOTMR(lan8670_t *lan, bool *buffer);

/**
* @brief Writes the PLCA TOTMR (Transmit Opportunity Timer) setting.
*
* @param lan Pointer to the lan8670_t instance.
* @param data Setting to write to the register. Should be an integer with a unit of bit-times.
* @return Status.
*/
int32_t LAN8670_PLCA_WriteTOTMR(lan8670_t *lan, uint8_t data);

// clang-format on
46 changes: 44 additions & 2 deletions general/src/lan8670.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <stdio.h> // Used for debug()
#include <stdarg.h> // Used for debug()
#include "u_tx_debug.h"

/* SMI Registers */
#define REG_BASIC_CONTROL 0x00 // Basic Control Register. (Datasheet pgs. 63-64)
Expand Down Expand Up @@ -317,9 +318,8 @@ static int mmd_write_register(lan8670_t *lan, uint16_t mmd_addr, uint16_t regist
* @param value Pointer to store the read value.
* @return Status.
*/
static int __attribute__((unused)) mmd_read_register_field(lan8670_t *lan, uint16_t mmd_addr, uint16_t register_offset, int start, int end, uint16_t *value)
static int mmd_read_register_field(lan8670_t *lan, uint16_t mmd_addr, uint16_t register_offset, int start, int end, uint16_t *value)
{
// NOTE: Remove the __attribute__((unused)) if this function gets used.

/* Validate bit range */
if (start > end) {
Expand Down Expand Up @@ -503,6 +503,48 @@ int32_t LAN8670_PLCA_Set_Node_Id(lan8670_t *lan, uint8_t id)
return mmd_write_register_field(lan, MMD_MISC, MISC_PLCA_CTRL1, 0, 7, id);
}

/* false=The PLCA reconciliation sublayer is not regularly receiving or transmitting the BEACON, true=The PLCA reconciliation sublayer is regularly receiving or transmitting the BEACON. */
int32_t LAN8670_PLCA_Get_Status(lan8670_t *lan, bool *status) {
uint16_t reading = 0;
int error = mmd_read_register_field(lan, MMD_MISC, MISC_PLCA_STS, 15, 15, &reading);
if(error != LAN8670_STATUS_OK) {
PRINTLN_ERROR("Failed to call mmd_read_register_field() (Status: %d).", error);
return error;
}

if(reading == 1) {
*status = true;
} else {
*status = false;
}

return LAN8670_STATUS_OK;
}

/* Reads the value of the TOMTR register. Should be 32 bit-times by default. */
int32_t LAN8670_PLCA_ReadTOTMR(lan8670_t *lan, bool *buffer) {
uint16_t reading = 0;
int status = mmd_read_register_field(lan, MMD_MISC, MISC_PLCA_TOTMR, 0, 7, &reading);
if(status != LAN8670_STATUS_OK) {
PRINTLN_ERROR("Failed to call mmd_read_register_field() (Status: %d).", status);
return status;
}

*buffer = (uint8_t)reading;
return LAN8670_STATUS_OK;
}

/* Writes the value of the TOMTOR register. */
int32_t LAN8670_PLCA_WriteTOTMR(lan8670_t *lan, uint8_t data) {
int status = mmd_write_register_field(lan, MMD_MISC, MISC_PLCA_TOTMR, 0, 7, (uint16_t)data);
if(status != LAN8670_STATUS_OK) {
PRINTLN_ERROR("Failed to call mmd_write_register_field() (Status: %d).", status);
return status;
}

return LAN8670_STATUS_OK;
}

int32_t LAN8670_Get_Link_State(lan8670_t *lan, uint8_t *state)
{
// Read bit 2 of the Basic Status register. (Note: For the LAN8670, this will always be 1.)
Expand Down
2 changes: 1 addition & 1 deletion ner_environment/build_system/build_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def build(profile: str = typer.Option(None, "--profile", "-p", callback=unsuppor
run_command_docker('cmake --build build --target clean ; find . -type d -name "build" -exec rm -rf {} +')
print("[#cccccc](ner build):[/#cccccc] [green]Ran build-cleaning command.[/green]")
else:
run_command_docker("mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=cmake/gcc-arm-none-eabi.cmake .. && cmake --build .", stream_output=True)
run_command_docker("mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=cmake/gcc-arm-none-eabi.cmake .. && cmake --build .", stream_output=True)
run_command_docker('chmod 777 -R ./build/*')
else: # Repo uses Make, so execute Make commands.
print("[#cccccc](ner build):[/#cccccc] [blue]Makefile-based project detected.[/blue]")
Expand Down
2 changes: 1 addition & 1 deletion openocd.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$_TARGETNAME configure -event gdb-detach {
$_CHIPNAME.cpu configure -event gdb-detach {
reset run
shutdown
}
Expand Down