新手入门 
 
	- 积分
 - 7
 
        - 金钱
 - 7 
 
       - 注册时间
 - 2021-12-27
 
      - 在线时间
 - 2 小时
 
 
 
 | 
 
 
 楼主 |
发表于 2021-12-27 17:19:09
|
显示全部楼层
 
 
 
 
麻烦您能帮忙看下具体是哪里的问题吗,感谢大佬! 
main.c 
 
- #include "dma_intr.h"
 
 - #include "timer_intr.h"
 
 - #include "sys_intr.h"
 
  
- #include "lwip/err.h"
 
 - #include "lwip/tcp.h"
 
 - #include "lwipopts.h"
 
 - #include "netif/xadapter.h"
 
 - #include "lwipopts.h"
 
 - #include "tcp_transmission.h"
 
  
- static  XScuGic Intc; //GIC
 
 - static  XScuTimer Timer;//timer
 
 - XAxiDma AxiDma;
 
 - u32         *RxBufferPtr[2];  /* ping pong buffers*/
 
  
- volatile u32 RX_success;
 
 - volatile u32 TX_success;
 
  
- volatile u32 RX_ready=1;
 
 - volatile u32 TX_ready=1;
 
  
- #define TIMER_LOAD_VALUE    XPAR_CPU_CORTEXA9_0_CPU_CLK_FREQ_HZ / 8 //0.25S
 
  
- int init_intr_sys(void)
 
 - {
 
 -         DMA_Intr_Init(&AxiDma,0);//initial interrupt system
 
 -         Timer_init(&Timer,TIMER_LOAD_VALUE,0);
 
 -         Init_Intr_System(&Intc); // initial DMA interrupt system
 
 -         Setup_Intr_Exception(&Intc);
 
 -         DMA_Setup_Intr_System(&Intc,&AxiDma,0,RX_INTR_ID);//setup dma interrpt system
 
 -         Timer_Setup_Intr_System(&Intc,&Timer,TIMER_IRPT_INTR);
 
 -         DMA_Intr_Enable(&Intc,&AxiDma);
 
  
- }
 
  
- int main(void)
 
 - {
 
 -         int Status;
 
 -         struct netif *netif, server_netif;
 
 -         struct ip_addr ipaddr, netmask, gw;
 
 -         err_t err;
 
  
-         /* the mac address of the board. this should be unique per board */
 
 -         unsigned char mac_ethernet_address[] = { 0x00, 0x0a, 0x35, 0x00, 0x01, 0x02 };
 
  
-         /* Initialize the ping pong buffers for the data received from axidma */
 
 -         RxBufferPtr[0] = (u32 *)RX_BUFFER0_BASE;
 
 -         RxBufferPtr[1] = (u32 *)RX_BUFFER1_BASE;
 
  
-         init_intr_sys();
 
 -         TcpTmrFlag = 0;
 
  
-         netif = &server_netif;
 
  
-         IP4_ADDR(&ipaddr,  192, 168,   1,  10);
 
 -         IP4_ADDR(&netmask, 255, 255, 255,  0);
 
 -         IP4_ADDR(&gw,      192, 168,   1,  10);
 
  
-         /*lwip library init*/
 
 -         lwip_init();
 
 -         /* Add network interface to the netif_list, and set it as default */
 
 -         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);
 
  
-         /* specify that the network if is up */
 
 -         netif_set_up(netif);
 
  
-         /* initialize tcp pcb */
 
 -         tcp_send_init();
 
  
-         Timer_start(&Timer);
 
  
 
-         while (1)
 
 -         {
 
 -                 /* call tcp timer every 250ms */
 
 -                 if(TcpTmrFlag)
 
 -                 {
 
 -                         if(request_pcb->state == CLOSED || (request_pcb->state == SYN_SENT && request_pcb->nrtx == TCP_SYNMAXRTX))
 
 -                         {
 
 -                                 request_pcb = tcp_new();
 
 -                                 if (!request_pcb) {
 
 -                                         xil_printf("txperf: Error creating PCB. Out of Memory\r\n");
 
 -                                         return -1;
 
 -                                 }
 
  
-                                 //ip_set_option(request_pcb, SOF_REUSEADDR);
 
  
-                                 err = tcp_connect(request_pcb, &ipaddress, port, tcp_connected_callback);
 
 -                                 if (err != ERR_OK) {
 
 -                                         xil_printf("txperf: tcp_connect returned error: %d\r\n", err);
 
 -                                         return err;
 
 -                                 }
 
 -                         }
 
 -                         tcp_tmr();
 
 -                         TcpTmrFlag = 0;
 
 -                 }
 
 -                 /*receive input packet from emac*/
 
 -                 xemacif_input(netif); //将MAC队列里的packets传输到你的LwIP/IP stack里
 
 -                 /* if connected to the server, start receive data from PL through axidma, then transmit the data to the PC software by TCP*/
 
 -                 if(tcp_client_connected)
 
 -                         send_received_data();
 
 -         }
 
 -         return 0;
 
  
- }
 
 
  复制代码 
 
dma_intr.h 
 
- #include "dma_intr.h"
 
  
-  int DMA_CheckData(int Length, u8 StartValue)
 
 - {
 
 -         u32 *RxPacket;
 
 -         int Index = 0;
 
 -         u32 Value;
 
  
-         RxPacket = (u32 *) RX_BUFFER_BASE;
 
 -         Value = StartValue;
 
  
-         /* Invalidate the DestBuffer before receiving the data, in case the
 
 -          * Data Cache is enabled
 
 -          */
 
 - #ifndef __aarch64__
 
 -         Xil_DCacheInvalidateRange((u32)RxPacket, Length* sizeof(u32));
 
 - #endif
 
  
-         for(Index = 0; Index < Length; Index++) {
 
 -                 if (RxPacket[Index] != Value) {
 
 -                         /*xil_printf("Data error %d: %x/%x\r\n",
 
 -                             Index, RxPacket[Index], Value);*/
 
  
-                         return XST_FAILURE;
 
 -                 }
 
 -                 Value = (Value + 1) & 0xFF;
 
 -         }
 
  
-         return XST_SUCCESS;
 
 - }
 
  
- void DMA_DisableIntrSystem(XScuGic * IntcInstancePtr,
 
 -                                         u16 TxIntrId, u16 RxIntrId)
 
 - {
 
 - #ifdef XPAR_INTC_0_DEVICE_ID
 
 -         /* Disconnect the interrupts for the DMA TX and RX channels */
 
 -         //XIntc_Disconnect(IntcInstancePtr, TxIntrId);
 
 -         XIntc_Disconnect(IntcInstancePtr, RxIntrId);
 
 - #else
 
 -         //XScuGic_Disconnect(IntcInstancePtr, TxIntrId);
 
 -         XScuGic_Disconnect(IntcInstancePtr, RxIntrId);
 
 - #endif
 
 - }
 
  
- static void DMA_TxIntrHandler(void *Callback)
 
 - {
 
  
-         u32 IrqStatus;
 
 -         int TimeOut;
 
 -         XAxiDma *AxiDmaInst = (XAxiDma *)Callback;
 
  
-         /* Read pending interrupts */
 
 -         IrqStatus = XAxiDma_IntrGetIrq(AxiDmaInst, XAXIDMA_DMA_TO_DEVICE);
 
  
-         /* Acknowledge pending interrupts */
 
  
 
-         XAxiDma_IntrAckIrq(AxiDmaInst, IrqStatus, XAXIDMA_DMA_TO_DEVICE);
 
  
-         /*
 
 -          * If no interrupt is asserted, we do not do anything
 
 -          */
 
 -         if (!(IrqStatus & XAXIDMA_IRQ_ALL_MASK)) {
 
  
-                 return;
 
 -         }
 
  
-         /*
 
 -          * If error interrupt is asserted, raise error flag, reset the
 
 -          * hardware to recover from the error, and return with no further
 
 -          * processing.
 
 -          */
 
 -         if ((IrqStatus & XAXIDMA_IRQ_ERROR_MASK)) {
 
 -                 xil_printf("rx error! \r\n");
 
 -                 /*
 
 -                  * Reset should never fail for transmit channel
 
 -                  */
 
 -                 XAxiDma_Reset(AxiDmaInst);
 
  
-                 TimeOut = RESET_TIMEOUT_COUNTER;
 
  
-                 while (TimeOut) {
 
 -                         if (XAxiDma_ResetIsDone(AxiDmaInst)) {
 
 -                                 break;
 
 -                         }
 
  
-                         TimeOut -= 1;
 
 -                 }
 
  
-                 return;
 
 -         }
 
  
-         /*
 
 -          * If Completion interrupt is asserted, then set the TxDone flag
 
 -          */
 
 -         if ((IrqStatus & XAXIDMA_IRQ_IOC_MASK)) {
 
  
-                 TxDone = 1;
 
 -         }
 
 - }
 
  
 
- static void DMA_RxIntrHandler(void *Callback)
 
 - {
 
 -         u32 IrqStatus;
 
 -         int TimeOut;
 
 -         XAxiDma *AxiDmaInst = (XAxiDma *)Callback;
 
  
-         /* Read pending interrupts */
 
 -         IrqStatus = XAxiDma_IntrGetIrq(AxiDmaInst, XAXIDMA_DEVICE_TO_DMA);
 
  
-         /* Acknowledge pending interrupts */
 
 -         XAxiDma_IntrAckIrq(AxiDmaInst, IrqStatus, XAXIDMA_DEVICE_TO_DMA);
 
  
-         /*
 
 -          * If no interrupt is asserted, we do not do anything
 
 -          */
 
 -         if (!(IrqStatus & XAXIDMA_IRQ_ALL_MASK)) {
 
 -                 return;
 
 -         }
 
  
-         /*
 
 -          * If error interrupt is asserted, raise error flag, reset the
 
 -          * hardware to recover from the error, and return with no further
 
 -          * processing.
 
 -          */
 
 -         if ((IrqStatus & XAXIDMA_IRQ_ERROR_MASK)) {
 
 -                 xil_printf("rx error! \r\n");
 
 -                 return;
 
 -         }
 
  
-         /*
 
 -          * If completion interrupt is asserted, then set RxDone flag
 
 -          */
 
 -         if ((IrqStatus & XAXIDMA_IRQ_IOC_MASK)) {
 
 -                 if(packet_trans_done)
 
 -                         xil_printf("last transmission has not finished!\r\n");
 
 -                 else
 
 -                         /*set the axidma done flag*/
 
 -                     packet_trans_done = 1;
 
 -         }
 
 - }
 
  
- int DMA_Setup_Intr_System(XScuGic * IntcInstancePtr,XAxiDma * AxiDmaPtr, u16 TxIntrId, u16 RxIntrId)
 
 - {
 
 -         int Status;
 
 -         //XScuGic_SetPriorityTriggerType(IntcInstancePtr, TxIntrId, 0xA0, 0x3);
 
  
-         XScuGic_SetPriorityTriggerType(IntcInstancePtr, RxIntrId, 0xA0, 0x3);
 
 -         /*
 
 -          * Connect the device driver handler that will be called when an
 
 -          * interrupt for the device occurs, the handler defined above performs
 
 -          * the specific interrupt processing for the device.
 
 -          */
 
 -         /*
 
 -         Status = XScuGic_Connect(IntcInstancePtr, TxIntrId,
 
 -                                 (Xil_InterruptHandler)DMA_TxIntrHandler,
 
 -                                 AxiDmaPtr);
 
 -         if (Status != XST_SUCCESS) {
 
 -                 return Status;
 
 -         }
 
 - */
 
 -         Status = XScuGic_Connect(IntcInstancePtr, RxIntrId,
 
 -                                 (Xil_InterruptHandler)DMA_RxIntrHandler,
 
 -                                 AxiDmaPtr);
 
 -         if (Status != XST_SUCCESS) {
 
 -                 return Status;
 
 -         }
 
  
-         //XScuGic_Enable(IntcInstancePtr, TxIntrId);
 
 -         XScuGic_Enable(IntcInstancePtr, RxIntrId);
 
 -         return XST_SUCCESS;
 
 - }
 
  
 
 
- int DMA_Intr_Enable(XScuGic * IntcInstancePtr,XAxiDma *DMAPtr)
 
 - {
 
  
-         /* Disable all interrupts before setup */
 
 - /*
 
 -         XAxiDma_IntrDisable(DMAPtr, XAXIDMA_IRQ_ALL_MASK,
 
 -                                                 XAXIDMA_DMA_TO_DEVICE);
 
 - */
 
 -         XAxiDma_IntrDisable(DMAPtr, XAXIDMA_IRQ_ALL_MASK,
 
 -                                 XAXIDMA_DEVICE_TO_DMA);
 
  
-         /* Enable all interrupts */
 
 - /*
 
 -         XAxiDma_IntrEnable(DMAPtr, XAXIDMA_IRQ_ALL_MASK,
 
 -                                                         XAXIDMA_DMA_TO_DEVICE);
 
 - */
 
 -         XAxiDma_IntrEnable(DMAPtr, XAXIDMA_IRQ_ALL_MASK,
 
 -                                                         XAXIDMA_DEVICE_TO_DMA);
 
 -         return XST_SUCCESS;
 
  
- }
 
  
 
- int DMA_Intr_Init(XAxiDma *DMAPtr,u32 DeviceId)
 
 - {
 
 -         int Status;
 
 -         XAxiDma_Config *Config=NULL;
 
  
-         Config = XAxiDma_LookupConfig(DeviceId);
 
 -         if (!Config) {
 
 -                 xil_printf("No config found for %d\r\n", DeviceId);
 
 -                 return XST_FAILURE;
 
 -         }
 
  
-         /* Initialize DMA engine */
 
 -         Status = XAxiDma_CfgInitialize(DMAPtr, Config);
 
  
-         if (Status != XST_SUCCESS) {
 
 -                 xil_printf("Initialization failed %d\r\n", Status);
 
 -                 return XST_FAILURE;
 
 -         }
 
  
-         if(XAxiDma_HasSg(DMAPtr)){
 
 -                 xil_printf("Device configured as SG mode \r\n");
 
 -                 return XST_FAILURE;
 
 -         }
 
 -         return XST_SUCCESS;
 
  
- }
 
 
  复制代码 |   
 
 
 
 |