(四)基带数据的以太网发送
对各个频点回波数据做数字下变频得到I、Q支路存储到RAM中后,需要通过以太网口将数据发送到PC机上。此功能通过FPGA的MicroBlaze完成 首先添加如图1所示的资源到PLB总线上,时钟为80MHz。MicroBlaze通过EMC从外部RAM中读取数据,然后通过BCM5221将数据从以太网中饭发出去。 要通过以太网发送数据,首先要熟悉它的帧格式如图2所示。在以太网帧中需要用户拼接的有6Bytes的目的地址、6Bytes的源地址,2Bytes的长度和0-1500Bytes的数据。其余的由协议本身根据需要自动生成,用户不需要关注。 拼接以太网帧的C语言如下: static int EmacLiteSendFrame(XEmacLite *InstancePtr, u8 *SendFramePtr,u32 PayloadSize) { u8 *FramePtr; Xuint16 Index; Xuint16 j; Xuint8 *FramePtr_in; FramePtr = (u8 *)TxFrame; FramePtr_in=SendFramePtr; /* * Fill in the valid Destination MAC address if * the Loopback is not enabled. */ *FramePtr++ = RemoteAddress[0]; *FramePtr++ = RemoteAddress[1]; *FramePtr++ = RemoteAddress[2]; *FramePtr++ = RemoteAddress[3]; *FramePtr++ = RemoteAddress[4]; *FramePtr++ = RemoteAddress[5]; /* * Fill in the source MAC address. */ *FramePtr++ = LocalAddress[0]; *FramePtr++ = LocalAddress[1]; *FramePtr++ = LocalAddress[2]; *FramePtr++ = LocalAddress[3]; *FramePtr++ = LocalAddress[4]; *FramePtr++ = LocalAddress[5]; /* * Set up the type/length field - be sure its in network order. */ *((u16 *)FramePtr) = PayloadSize; FramePtr++; FramePtr++; /* * Now fill in the data field with known values so we can verify them * on receive. */ *FramePtr++ = 0x55; *FramePtr++ = 0xbb; j=PayloadSize-2; for (Index = 0; Index < j; Index++) { *FramePtr++ = *FramePtr_in++; } /* * Now send the frame. */ return XEmacLite_Send(InstancePtr, (u8 *)TxFrame, PayloadSize + XEL_HEADER_SIZE); 发送之前首先要寻找物理芯片(本设计为BCM5221)地址: u32 EmacLitePhyDetect(XEmacLite *InstancePtr) //detect the valid PHY device { u16 PhyData; u32 PhyAddr; for (PhyAddr = 31; PhyAddr >= 0; PhyAddr--) { XEmacLite_PhyRead(InstancePtr, PhyAddr, PHY_REG1_OFFSET, &PhyData); if (PhyData != 0xFFFF) { if ((PhyData & PHY_REG1_DETECT_MASK) == PHY_REG1_DETECT_MASK) { return PhyAddr; /* Found a valid PHY device */ } } } 找到物理地址后,配置物理芯片的寄存器来完成对以太网工作模式的配置。本设计以太网设计配置为双工模式,10M网速。 EmacLite_Config = XEmacLite_LookupConfig(EMAC_DEVICE_ID); Status = XEmacLite_CfgInitialize(&EmacLite,EmacLite_Config,EmacLite_Config->BaseAddress); PhyAddress = EmacLitePhyDetect(&EmacLite); XEmacLite_PhyWrite(&EmacLite, PhyAddress, 0,0x0100); //配置PHY register0 XEmacLite_PhyWrite(&EmacLite, PhyAddress, 1,0x1008); //配置PHY register1,10BASE-TX full-duplex 完成以上操作后,通过验证,FPGA能完成数据的以太网发送。
|