-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.c
187 lines (150 loc) · 4.47 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//DEFINE STATEMENTS TO INCREASE SPEED
#undef LWIP_TCP
#undef LWIP_DHCP
//#undef CHECKSUM_CHECK_UDP
//#undef LWIP_CHECKSUM_ON_COPY
//#undef CHECKSUM_GEN_UDP
#include <stdio.h>
#include "xparameters.h"
#include "netif/xadapter.h"
#include "platform.h"
#include "platform_config.h"
#if defined (__arm__) || defined(__aarch64__)
#include "xil_printf.h"
#endif
#include "lwip/udp.h"
#include "xil_cache.h"
// Include our own definitions
#include "includes.h"
/* defined by each RAW mode application */
void print_app_header();
int start_application();
//int transfer_data();
void tcp_fasttmr(void);
void tcp_slowtmr(void);
/* missing declaration in lwIP */
void lwip_init();
extern volatile int TcpFastTmrFlag;
extern volatile int TcpSlowTmrFlag;
/* set up netif stuctures */
static struct netif server_netif;
struct netif *echo_netif;
// Global Variables to store results and handle data flow
int Centroid;
// Global variables for data flow
volatile u8 IndArrDone;
volatile u32 EthBytesReceived;
volatile u8 SendResults;
volatile u8 DMA_TX_Busy;
volatile u8 Error;
// Global Variables for Ethernet handling
u16_t RemotePort = 8;
struct ip_addr RemoteAddr;
struct udp_pcb send_pcb;
void
print_ip(char *msg, struct ip_addr *ip)
{
print(msg);
xil_printf("%d.%d.%d.%d\n\r", ip4_addr1(ip), ip4_addr2(ip),
ip4_addr3(ip), ip4_addr4(ip));
}
void
print_ip_settings(struct ip_addr *ip, struct ip_addr *mask, struct ip_addr *gw)
{
print_ip("Board IP: ", ip);
print_ip("Netmask : ", mask);
print_ip("Gateway : ", gw);
}
/* print_app_header: function to print a header at start time */
void print_app_header()
{
xil_printf("\n\r\n\r------lwIP UDP GetCentroid Application------\n\r");
xil_printf("UDP packets sent to port 7 will be processed\n\r");
}
int main()
{
struct ip_addr ipaddr, netmask, gw /*, Remotenetmask, Remotegw*/;
struct pbuf * psnd;
err_t udpsenderr;
int status = 0;
/* the mac address of the board. this should be unique per board */
unsigned char mac_ethernet_address[] =
{ 0x00, 0x0a, 0x35, 0x00, 0x01, 0x10 };
/* Use the same structure for the server and the echo server */
echo_netif = &server_netif;
init_platform();
/* initialize IP addresses to be used */
IP4_ADDR(&ipaddr, 10, 0, 0, 10);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP4_ADDR(&gw, 10, 0, 0, 1);
IP4_ADDR(&RemoteAddr, 10, 0, 0, 77);
//IP4_ADDR(&Remotenetmask, 255, 255, 255, 0);
//IP4_ADDR(&Remotegw, 10, 0, 0, 1);
print_app_header();
/* Initialize the lwip for UDP */
lwip_init();
/* Add network interface to the netif_list, and set it as default */
if (!xemac_add(echo_netif, &ipaddr, &netmask,
&gw, mac_ethernet_address,
PLATFORM_EMAC_BASEADDR)) {
xil_printf("Error adding N/W interface\n\r");
return -1;
}
netif_set_default(echo_netif);
/* now enable interrupts */
platform_enable_interrupts();
/* specify that the network if is up */
netif_set_up(echo_netif);
xil_printf("Zedboard IP settings: \r\n");
print_ip_settings(&ipaddr, &netmask, &gw);
xil_printf("Remote IP settings: \r\n");
//print_ip_settings(&RemoteAddr, &Remotenetmask, &Remotegw);
print_ip("Board IP: ", &RemoteAddr);
/* start the application (web server, rxtest, txtest, etc..) */
status = start_application();
if (status != 0){
xil_printf("Error in start_application() with code: %d\n\r", status);
goto ErrorOrDone;
}
/* receive and process packets */
while (Error==0) {
if (TcpFastTmrFlag) {
tcp_fasttmr();
TcpFastTmrFlag = 0;
//SendResults = 1;
//xil_printf("*");
}
if (TcpSlowTmrFlag) {
tcp_slowtmr();
TcpSlowTmrFlag = 0;
SendResults = 1;
}
//xemacif_input(echo_netif);
//transfer_data();
/* Receive packets */
xemacif_input(echo_netif);
/* Send results back from time to time */
if (SendResults == 1){
SendResults = 0;
// Read the results from the FPGA
Centroid = 0xA5;
// Send out the centroid result over UDP
psnd = pbuf_alloc(PBUF_TRANSPORT, sizeof(int), PBUF_REF);
psnd->payload = &Centroid;
udpsenderr = udp_sendto(&send_pcb, psnd, &RemoteAddr, RemotePort);
xil_printf(".");
if (udpsenderr != ERR_OK){
xil_printf("UDP Send failed with Error %d\n\r", udpsenderr);
goto ErrorOrDone;
}
pbuf_free(psnd);
}
}
// Jump point for failure
ErrorOrDone:
xil_printf("Catastrophic Error! Shutting down and exiting...\n\r");
// Disable the GetCentroid interrupts and disconnect from the GIC
//DisableIntrSystem(&Intc, GETCENTROID_INTR_ID, &GetCentroid, TX_INTR_ID);
cleanup_platform();
return 0;
}