Skip to content

Commit 19ebe7e

Browse files
Updated ethernet stuff based on review. Also changed queue timing a bit
1 parent fb03aed commit 19ebe7e

6 files changed

Lines changed: 16 additions & 6 deletions

File tree

Core/Inc/u_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@
3333
} \
3434
} while(0)
3535

36+
/* Time and tick conversions */
37+
#define MS_TO_TICKS(ms) ((ms) * TX_TIMER_TICKS_PER_SECOND / 1000) // u_TODO - i think this truncates if ms < 10. dunno if that will be an issue
38+
#define TICKS_TO_MS(ticks) ((ticks) * 1000 / TX_TIMER_TICKS_PER_SECOND)
39+
3640

3741
#endif /* u_config.h */

Core/Inc/u_ethernet.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define ETH_UDP_PORT 2006 /* UDP port for communication */
1616
#define ETH_MESSAGE_SIZE 8 /* Maximum ethernet message size */ // u_TODO - i made this 8 bytes for consistency with CAN, but obv it can be a lot larger.
1717
#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. */
1819

1920
typedef enum {
2021
VCU = (1 << 0), // 0b00000001
@@ -26,7 +27,7 @@ typedef enum {
2627
NODE7 = (1 << 6), // 0b01000000
2728
NODE8 = (1 << 7), // 0b10000000
2829
} ethernet_node_t;
29-
#define ETH_IP(node) IP_ADDRESS(239,0,0,node) // u_TODO - you can configure ethernet IPs in CubeMX apparently. probably should look into that, not sure how that works w/ this
30+
#define ETH_IP(node) IP_ADDRESS(239,0,0,node)
3031
/* END CONFIG */
3132

3233
typedef struct {

Core/Inc/u_queues.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define __U_QUEUES_H
33

44
#include "tx_api.h"
5+
#include "u_config.h"
56
#include "u_ethernet.h"
67
#include <stdint.h>
78

@@ -11,6 +12,9 @@
1112
* Author: Blake Jackson
1213
*/
1314

15+
/* Queue Config Macros */
16+
#define QUEUE_WAIT_TIME MS_TO_TICKS(100) // Wait 100ms for queue stuff before timing out
17+
1418
typedef struct {
1519
TX_QUEUE *queue; /* Pointer to the queue */
1620
CHAR *name; /* Name of the queue */

Core/Src/u_ethernet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void _receive_message(NX_UDP_SOCKET *socket) {
4040
ethernet_message_t message = {0};
4141

4242
/* Recieve the packet */
43-
status = nx_udp_socket_receive(socket, &packet, TX_NO_WAIT);
43+
status = nx_udp_socket_receive(socket, &packet, NX_NO_WAIT);
4444
if(status == NX_SUCCESS) {
4545
/* Extract message from packet */
4646
status = nx_packet_data_extract_offset(

Core/Src/u_queues.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ uint8_t queue_send(TX_QUEUE *queue, void *message) {
5757
UINT status;
5858

5959
/* Send message to the queue. */
60-
status = tx_queue_send(queue, message, TX_NO_WAIT);
60+
status = tx_queue_send(queue, message, QUEUE_WAIT_TIME);
6161
if(status != TX_SUCCESS) {
6262
DEBUG_PRINT("ERROR: Failed to send message to queue (Status: %d, Queue: %s).", status, queue->tx_queue_name);
6363
return U_ERROR;
@@ -70,7 +70,7 @@ uint8_t queue_receive(TX_QUEUE *queue, void *message) {
7070
UINT status;
7171

7272
/* Receive message from the queue. */
73-
status = tx_queue_receive(queue, message, TX_NO_WAIT);
73+
status = tx_queue_receive(queue, message, QUEUE_WAIT_TIME);
7474
if(status != TX_SUCCESS) {
7575
DEBUG_PRINT("ERROR: Failed to receive message from queue (Status: %d, Queue: %s).", status, queue->tx_queue_name);
7676
return U_ERROR;

NetXDuo/Target/nx_stm32_phy_custom_driver.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
/* USER CODE BEGIN Includes */
1717
#include "lan8670.h"
18+
#include "u_ethernet.h"
1819
/* USER CODE END Includes */
1920

2021
/* Private typedef -----------------------------------------------------------*/
@@ -103,13 +104,13 @@ int32_t nx_eth_phy_init(void)
103104
}
104105

105106
/* Set PLCA node count and ID */
106-
ret = LAN8670_PLCA_Set_Node_Count(&lan8670, 2); // u_TODO - Actually configure this stuff based on what the network looks like
107+
ret = LAN8670_PLCA_Set_Node_Count(&lan8670, ETH_NUMBER_OF_NODES);
107108
if (ret != LAN8670_STATUS_OK)
108109
{
109110
return ETH_PHY_STATUS_ERROR;
110111
}
111112

112-
ret = LAN8670_PLCA_Set_Node_Id(&lan8670, 0); // u_TODO - Actually configure this stuff based on what the network looks like
113+
ret = LAN8670_PLCA_Set_Node_Id(&lan8670, VCU);
113114
if (ret != LAN8670_STATUS_OK)
114115
{
115116
return ETH_PHY_STATUS_ERROR;

0 commit comments

Comments
 (0)