⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xemacps_control.c

📁 自学ZedBoard:使用IP通过ARM PS访问FPGA(源代码)
💻 C
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************//** * Set the Type ID match for this driver/device.  The register is a 32-bit * value. The device must be stopped before calling this function. * * @param InstancePtr is a pointer to the instance to be worked on. * @param Id_Check is type ID to be configured. * @param Index is a index to which Type ID (1-4). * * @return * - XST_SUCCESS if the MAC address was set successfully * - XST_DEVICE_IS_STARTED if the device has not yet been stopped * *****************************************************************************/int XEmacPs_SetTypeIdCheck(XEmacPs *InstancePtr, u32 Id_Check, u8 Index){	Xil_AssertNonvoid(InstancePtr != NULL);	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);	Xil_AssertNonvoid((Index <= XEMACPS_MAX_TYPE_ID) && (Index > 0));	/* Be sure device has been stopped */	if (InstancePtr->IsStarted == XIL_COMPONENT_IS_STARTED) {		return (XST_DEVICE_IS_STARTED);	}	/* Index ranges 1 to 4, for offset calculation is 0 to 3. */	Index--;	/* Set the ID bits in MATCHx register */	XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,			   (XEMACPS_MATCH1_OFFSET + (Index * 4)), Id_Check);	return (XST_SUCCESS);}/*****************************************************************************//** * Set options for the driver/device. The driver should be stopped with * XEmacPs_Stop() before changing options. * * @param InstancePtr is a pointer to the instance to be worked on. * @param Options are the options to set. Multiple options can be set by OR'ing *        XTE_*_OPTIONS constants together. Options not specified are not *        affected. * * @return * - XST_SUCCESS if the options were set successfully * - XST_DEVICE_IS_STARTED if the device has not yet been stopped * * @note * See xemacps.h for a description of the available options. * *****************************************************************************/int XEmacPs_SetOptions(XEmacPs *InstancePtr, u32 Options){	u32 Reg;		/* Generic register contents */	u32 RegNetCfg;		/* Reflects original contents of NET_CONFIG */	u32 RegNewNetCfg;	/* Reflects new contents of NET_CONFIG */	Xil_AssertNonvoid(InstancePtr != NULL);	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);	/* Be sure device has been stopped */	if (InstancePtr->IsStarted == XIL_COMPONENT_IS_STARTED) {		return (XST_DEVICE_IS_STARTED);	}	/* Many of these options will change the NET_CONFIG registers.	 * To reduce the amount of IO to the device, group these options here	 * and change them all at once.	 */	/* Grab current register contents */	RegNetCfg = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,				      XEMACPS_NWCFG_OFFSET);	RegNewNetCfg = RegNetCfg;	/*	 * It is configured to max 1536.	 */	if (Options & XEMACPS_FRAME1536_OPTION) {		RegNewNetCfg |= (XEMACPS_NWCFG_1536RXEN_MASK);	}	/* Turn on VLAN packet only, only VLAN tagged will be accepted */	if (Options & XEMACPS_VLAN_OPTION) {		RegNewNetCfg |= XEMACPS_NWCFG_NVLANDISC_MASK;	}	/* Turn on FCS stripping on receive packets */	if (Options & XEMACPS_FCS_STRIP_OPTION) {		RegNewNetCfg |= XEMACPS_NWCFG_FCSREM_MASK;	}	/* Turn on length/type field checking on receive packets */	if (Options & XEMACPS_LENTYPE_ERR_OPTION) {		RegNewNetCfg |= XEMACPS_NWCFG_LENGTHERRDSCRD_MASK;	}	/* Turn on flow control */	if (Options & XEMACPS_FLOW_CONTROL_OPTION) {		RegNewNetCfg |= XEMACPS_NWCFG_PAUSEEN_MASK;	}	/* Turn on promiscuous frame filtering (all frames are received) */	if (Options & XEMACPS_PROMISC_OPTION) {		RegNewNetCfg |= XEMACPS_NWCFG_COPYALLEN_MASK;	}	/* Allow broadcast address reception */	if (Options & XEMACPS_BROADCAST_OPTION) {		RegNewNetCfg &= ~XEMACPS_NWCFG_BCASTDI_MASK;	}	/* Allow multicast address filtering */	if (Options & XEMACPS_MULTICAST_OPTION) {		RegNewNetCfg |= XEMACPS_NWCFG_MCASTHASHEN_MASK;	}	/* enable RX checksum offload */	if (Options & XEMACPS_RX_CHKSUM_ENABLE_OPTION) {		RegNewNetCfg |= XEMACPS_NWCFG_RXCHKSUMEN_MASK;	}	/* Officially change the NET_CONFIG registers if it needs to be	 * modified.	 */	if (RegNetCfg != RegNewNetCfg) {		XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,				   XEMACPS_NWCFG_OFFSET, RegNewNetCfg);	}	/* Enable TX checksum offload */	if (Options & XEMACPS_TX_CHKSUM_ENABLE_OPTION) {		Reg = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,					XEMACPS_DMACR_OFFSET);		Reg |= XEMACPS_DMACR_TCPCKSUM_MASK;		XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,					 XEMACPS_DMACR_OFFSET, Reg);	}	/* Enable transmitter */	if (Options & XEMACPS_TRANSMITTER_ENABLE_OPTION) {		Reg = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,					XEMACPS_NWCTRL_OFFSET);		Reg |= XEMACPS_NWCTRL_TXEN_MASK;		XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,				   XEMACPS_NWCTRL_OFFSET, Reg);	}	/* Enable receiver */	if (Options & XEMACPS_RECEIVER_ENABLE_OPTION) {		Reg = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,					XEMACPS_NWCTRL_OFFSET);		Reg |= XEMACPS_NWCTRL_RXEN_MASK;		XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,				   XEMACPS_NWCTRL_OFFSET, Reg);	}	/* The remaining options not handled here are managed elsewhere in the	 * driver. No register modifications are needed at this time. Reflecting	 * the option in InstancePtr->Options is good enough for now.	 */	/* Set options word to its new value */	InstancePtr->Options |= Options;	return (XST_SUCCESS);}/*****************************************************************************//** * Clear options for the driver/device * * @param InstancePtr is a pointer to the instance to be worked on. * @param Options are the options to clear. Multiple options can be cleared by *        OR'ing XEMACPS_*_OPTIONS constants together. Options not specified *        are not affected. * * @return * - XST_SUCCESS if the options were set successfully * - XST_DEVICE_IS_STARTED if the device has not yet been stopped * * @note * See xemacps.h for a description of the available options. * *****************************************************************************/int XEmacPs_ClearOptions(XEmacPs *InstancePtr, u32 Options){	u32 Reg;		/* Generic */	u32 RegNetCfg;		/* Reflects original contents of NET_CONFIG */	u32 RegNewNetCfg;	/* Reflects new contents of NET_CONFIG */	Xil_AssertNonvoid(InstancePtr != NULL);	Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);	/* Be sure device has been stopped */	if (InstancePtr->IsStarted == XIL_COMPONENT_IS_STARTED) {		return (XST_DEVICE_IS_STARTED);	}	/* Many of these options will change the NET_CONFIG registers.	 * To reduce the amount of IO to the device, group these options here	 * and change them all at once.	 */	/* Grab current register contents */	RegNetCfg = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,				      XEMACPS_NWCFG_OFFSET);	RegNewNetCfg = RegNetCfg;	/* There is only RX configuration!?	 * It is configured in two different length, upto 1536 and 10240 bytes	 */	if (Options & XEMACPS_FRAME1536_OPTION) {		RegNewNetCfg &= ~XEMACPS_NWCFG_1536RXEN_MASK;	}	/* Turn off VLAN packet only */	if (Options & XEMACPS_VLAN_OPTION) {		RegNewNetCfg &= ~XEMACPS_NWCFG_NVLANDISC_MASK;	}	/* Turn off FCS stripping on receive packets */	if (Options & XEMACPS_FCS_STRIP_OPTION) {		RegNewNetCfg &= ~XEMACPS_NWCFG_FCSREM_MASK;	}	/* Turn off length/type field checking on receive packets */	if (Options & XEMACPS_LENTYPE_ERR_OPTION) {		RegNewNetCfg &= ~XEMACPS_NWCFG_LENGTHERRDSCRD_MASK;	}	/* Turn off flow control */	if (Options & XEMACPS_FLOW_CONTROL_OPTION) {		RegNewNetCfg &= ~XEMACPS_NWCFG_PAUSEEN_MASK;	}	/* Turn off promiscuous frame filtering (all frames are received) */	if (Options & XEMACPS_PROMISC_OPTION) {		RegNewNetCfg &= ~XEMACPS_NWCFG_COPYALLEN_MASK;	}	/* Disallow broadcast address filtering => broadcast reception */	if (Options & XEMACPS_BROADCAST_OPTION) {		RegNewNetCfg |= XEMACPS_NWCFG_BCASTDI_MASK;	}	/* Disallow multicast address filtering */	if (Options & XEMACPS_MULTICAST_OPTION) {		RegNewNetCfg &= ~XEMACPS_NWCFG_MCASTHASHEN_MASK;	}	/* Disable RX checksum offload */	if (Options & XEMACPS_RX_CHKSUM_ENABLE_OPTION) {		RegNewNetCfg &= ~XEMACPS_NWCFG_RXCHKSUMEN_MASK;	}	/* Officially change the NET_CONFIG registers if it needs to be	 * modified.	 */	if (RegNetCfg != RegNewNetCfg) {		XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,				   XEMACPS_NWCFG_OFFSET, RegNewNetCfg);	}	/* Disable TX checksum offload */	if (Options & XEMACPS_TX_CHKSUM_ENABLE_OPTION) {		Reg = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,					XEMACPS_DMACR_OFFSET);		Reg &= ~XEMACPS_DMACR_TCPCKSUM_MASK;		XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,					 XEMACPS_DMACR_OFFSET, Reg);	}	/* Disable transmitter */	if (Options & XEMACPS_TRANSMITTER_ENABLE_OPTION) {		Reg = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,					XEMACPS_NWCTRL_OFFSET);		Reg &= ~XEMACPS_NWCTRL_TXEN_MASK;		XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,				   XEMACPS_NWCTRL_OFFSET, Reg);	}	/* Disable receiver */	if (Options & XEMACPS_RECEIVER_ENABLE_OPTION) {		Reg = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,					XEMACPS_NWCTRL_OFFSET);		Reg &= ~XEMACPS_NWCTRL_RXEN_MASK;		XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,				   XEMACPS_NWCTRL_OFFSET, Reg);	}	/* The remaining options not handled here are managed elsewhere in the	 * driver. No register modifications are needed at this time. Reflecting	 * option in InstancePtr->Options is good enough for now.	 */	/* Set options word to its new value */	InstancePtr->Options &= ~Options;	return (XST_SUCCESS);}/*****************************************************************************//** * Get current option settings * * @param InstancePtr is a pointer to the instance to be worked on. * * @return * A bitmask of XTE_*_OPTION constants. Any bit set to 1 is to be interpreted * as a set opion. * * @note * See xemacps.h for a description of the available options. * *****************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -