diff --git a/NetX/inc/u_nx_ethernet.h b/NetX/inc/u_nx_ethernet.h index b304a7fa..484e8b2c 100644 --- a/NetX/inc/u_nx_ethernet.h +++ b/NetX/inc/u_nx_ethernet.h @@ -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. @@ -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, @@ -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). */ diff --git a/NetX/src/u_nx_ethernet.c b/NetX/src/u_nx_ethernet.c index 7650337c..450ca303 100644 --- a/NetX/src/u_nx_ethernet.c +++ b/NetX/src/u_nx_ethernet.c @@ -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" @@ -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 @@ -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 ); @@ -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 @@ -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 @@ -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, @@ -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 \ No newline at end of file diff --git a/general/include/lan8670.h b/general/include/lan8670.h index 8f587f94..a02da558 100644 --- a/general/include/lan8670.h +++ b/general/include/lan8670.h @@ -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 \ No newline at end of file diff --git a/general/src/lan8670.c b/general/src/lan8670.c index cb77bfde..28c9bf32 100644 --- a/general/src/lan8670.c +++ b/general/src/lan8670.c @@ -10,6 +10,7 @@ #include // Used for debug() #include // Used for debug() +#include "u_tx_debug.h" /* SMI Registers */ #define REG_BASIC_CONTROL 0x00 // Basic Control Register. (Datasheet pgs. 63-64) @@ -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) { @@ -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.) diff --git a/ner_environment/build_system/build_system.py b/ner_environment/build_system/build_system.py index 7ef48e8a..23c569a3 100644 --- a/ner_environment/build_system/build_system.py +++ b/ner_environment/build_system/build_system.py @@ -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]") diff --git a/openocd.cfg b/openocd.cfg index 12a8374b..c906825d 100644 --- a/openocd.cfg +++ b/openocd.cfg @@ -1,4 +1,4 @@ -$_TARGETNAME configure -event gdb-detach { +$_CHIPNAME.cpu configure -event gdb-detach { reset run shutdown }