#ifndef SYS_INTR_H_
#define SYS_INTR_H_
#include "xparameters.h"
#include "xil_exception.h"
#include "xdebug.h"
#include "xscugic.h"
#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID
#define DMA_IRQ_ID 61U
int Init_Intr_System(XScuGic * IntcInstancePtr);
void Setup_Intr_Exception(XScuGic * IntcInstancePtr);
void DMAirqHandler(void *CallbackRef);
#endif
#include "sys_intr.h"
#include "user_udp.h"
volatile unsigned dma_ddr_addr_flag = 0;
void Setup_Intr_Exception(XScuGic * IntcInstancePtr)
{
Xil_ExceptionInit();
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
(Xil_ExceptionHandler)XScuGic_InterruptHandler,
(void *)IntcInstancePtr);
Xil_ExceptionEnable();
}
int Init_Intr_System(XScuGic * IntcInstancePtr)
{
int Status;
XScuGic_Config * GIC_ConfigPtr ;
GIC_ConfigPtr = XScuGic_LookupConfig(INTC_DEVICE_ID);
if (NULL == GIC_ConfigPtr) {
print("XScuGic_LookupConfig fail\n");
return XST_FAILURE;
}
Status = XScuGic_CfgInitialize(IntcInstancePtr, GIC_ConfigPtr,
GIC_ConfigPtr->CpuBaseAddress);
if (Status != XST_SUCCESS) {
print("XScuGic_CfgInitialize fail\n");
return XST_FAILURE;
}
Status = XScuGic_Connect(IntcInstancePtr, DMA_IRQ_ID,
(Xil_ExceptionHandler)DMAirqHandler,
(void *)IntcInstancePtr);
if(Status != XST_SUCCESS){
print("XScuGic_Connect fail\n");
return Status;
}
Setup_Intr_Exception(IntcInstancePtr);
XScuGic_SetPriorityTriggerType(IntcInstancePtr, DMA_IRQ_ID,
0xA0, 0x03);
XScuGic_Enable(IntcInstancePtr, DMA_IRQ_ID);
return Status;
}
void DMAirqHandler(void *CallbackRef){
XTime tEnd,tCur;
u32 tUsed = 0;
XTime_GetTime(&tCur);
if(!dma_ddr_addr_flag){
}
else{
}
dma_ddr_addr_flag ^= 1;
XTime_GetTime(&tEnd);
tUsed = ((tEnd-tCur)*1000000)/(COUNTS_PER_SECOND);
printf("UDP TX SPEED = %f Mbit/s\n send all time = %f ms \n send all data = %f MB\n",
((SEND_LEN * SEND_CNT * 8)/(tUsed/1000000.0))/(1024*1024),(tUsed/1000.0),(SEND_LEN * SEND_CNT)/(1024*1024.0));
}
#ifndef SRC_USER_UDP_H_
#define SRC_USER_UDP_H_
#include "lwip/err.h"
#include "lwip/udp.h"
#include "lwip/init.h"
#include "lwipopts.h"
#include "lwip/err.h"
#include "lwipopts.h"
#include "netif/xadapter.h"
#include "xil_printf.h"
#include "xtime_l.h"
#include "sleep.h"
#define SEND_CNT 8192
#define SEND_LEN 256*4
#define ADC_DMA_ADDR 0x10000000
#define LOCAL_PORT 7
#define REMOTE_PORT 8080
int user_udp_init(void);
void adc_udp_send(u8 * dma_addr,u32 send_cnt,u32 send_len);
void udp_recv_callback(void *arg, struct udp_pcb *tpcb,
struct pbuf *p, struct ip_addr *addr, u16_t port);
#endif
#include "user_udp.h"
struct udp_pcb *connected_pcb = NULL;
static struct pbuf *pbuf_to_be_sent = NULL;
u32 udp_serial_num = 0;
volatile unsigned udp_connected_flag = 0;
int user_udp_init(void)
{
struct udp_pcb *adc_pcb;
ip_addr_t ipaddr;
err_t err;
udp_connected_flag = 0;
adc_pcb = udp_new();
if (!pcb) {
xil_printf("Error Creating PCB.\r\n");
return -1;
}
err = udp_bind(adc_pcb, IP_ADDR_ANY, LOCAL_PORT);
if (err != ERR_OK) {
xil_printf("Unable to bind to port %d\r\n", LOCAL_PORT);
return -2;
}
IP4_ADDR(&ipaddr, 192, 168, 1, 183);
err = udp_connect(adc_pcb, &ipaddr, REMOTE_PORT);
if (err != ERR_OK) {
xil_printf("Unable to connect remote port.\r\n");
return -3;
}
else {
xil_printf("Connected Success.\r\n");
connected_pcb = adc_pcb;
udp_connected_flag = 1;
}
udp_recv(adc_pcb,udp_recv_callback,NULL);
return 0;
}
void adc_udp_send(u8 * dma_addr,u32 send_cnt,u32 send_len){
err_t err;
for(int i=0;i<send_cnt;i++){
usleep(4);
struct udp_pcb *tpcb = connected_pcb;
if (!tpcb) {
xil_printf("error connect.\r\n");
}
pbuf_to_be_sent = pbuf_alloc(PBUF_TRANSPORT, send_len + 4, PBUF_POOL);
*(u32 *)(dma_addr + send_len * i - 4) = udp_serial_num;
udp_serial_num = udp_serial_num + 1;
memset(pbuf_to_be_sent->payload, 0, send_len + 4);
memcpy(pbuf_to_be_sent->payload, (u8 *)(dma_addr + send_len * i - 4), send_len + 4);
err = udp_send(tpcb, pbuf_to_be_sent);
if (err != ERR_OK) {
xil_printf("Error on udp send : %d \r\n", err);
pbuf_free(pbuf_to_be_sent);
return;
}
pbuf_free(pbuf_to_be_sent);
}
}
void udp_recv_callback(void *arg, struct udp_pcb *tpcb,
struct pbuf *p_rx, struct ip_addr *addr, u16_t port){
err_t err;
char *pData;
char buff[28];
if(p_rx != NULL){
pData = (char *)p_rx-payload;
if(p_rx->len >= 7){
if ((pData[0] == 'r') && (pData[1] == 'e')
&& (pData[2] == 'a') && (pData[2] == 'd')
&& (pData[3] == 'l') && (pData[4] == 'o')
&& (pData[3] == 'g')){
}
}
}
}
#include "user_udp.h"
#include "sys_intr.h"
extern unsigned udp_connected_flag;
extern unsigned dma_ddr_addr_flag;
static XScuGic Intc;
int main(void)
{
struct netif *netif, server_netif;
ip_addr_t ipaddr, netmask, gw;
unsigned char mac_ethernet_address [] =
{0x00, 0x0a, 0x35, 0x00, 0x01, 0x02};
Init_Intr_System(&Intc);
netif = &server_netif;
IP4_ADDR(&ipaddr, 192, 168, 1, 10);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP4_ADDR(&gw, 192, 168, 1, 1);
lwip_init();
if (!xemac_add(netif, &ipaddr, &netmask, &gw, mac_ethernet_address, XPAR_XEMACPS_0_BASEADDR)) {
xil_printf("Error adding N/W interface\r\n");
return -1;
}
netif_set_default(netif);
netif_set_up(netif);
user_udp_init();
user_tftp_init();
while(1)
{
xemacif_input(netif);
}
return 0;
}