void init_emacps(xemacpsif_s *xemacps, struct netif *netif) { int rdy; unsigned mac_address = (unsigned)(netif->state); unsigned link_speed = 1000; unsigned options; unsigned lock_message_printed = 0; XEmacPs *xemacpsp; XEmacPs_Config *mac_config; int Status = XST_SUCCESS; /* obtain config of this emac */ mac_config = lookup_config(mac_address); xemacpsp = &xemacps->emacps; #if 0 options = XEmacPs_GetOptions(xemacpsp); options |= XEMACPS_FLOW_CONTROL_OPTION; options |= XEMACPS_TRANSMITTER_ENABLE_OPTION; options |= XEMACPS_RECEIVER_ENABLE_OPTION; options |= XEMACPS_FCS_STRIP_OPTION; options |= XEMACPS_BROADCAST_OPTION; options |= XEMACPS_FCS_INSERT_OPTION; options |= XEMACPS_RX_CHKSUM_ENABLE_OPTION; options |= XEMACPS_TX_CHKSUM_ENABLE_OPTION; options |= XEMACPS_LENTYPE_ERR_OPTION; XEmacPs_SetOptions(xemacpsp, options); XEmacPs_ClearOptions(xemacpsp, ~options); #endif /* set mac address */ Status = XEmacPs_SetMacAddress(xemacpsp, (void*)(netif->hwaddr), 1); if (Status != XST_SUCCESS) { xil_printf("In %s:Emac Mac Address set failed...\r\n",__func__); } link_speed = Phy_Setup(xemacpsp); XEmacPs_SetOperatingSpeed(xemacpsp, link_speed); /* Setting the operating speed of the MAC needs a delay. */ { volatile int wait; for (wait=0; wait < 20000; wait++); } Status = XEmacPs_SetOptions(xemacpsp, XEMACPS_PROMISC_OPTION); if (Status != XST_SUCCESS) { xil_printf("In %s:Setting up of promiscuous mode failed...\r\n",__func__); } }
/** * This function resets the device but preserves the options set by the user. * * The descriptor list could be reinitialized with the same calls to * XEmacPs_BdRingClone() as used in main(). Doing this is a matter of * preference. * In many cases, an OS may have resources tied up in the descriptors. * Reinitializing in this case may bad for the OS since its resources may be * permamently lost. * * @param EmacPsInstancePtr is a pointer to the instance of the EmacPs * driver. * * @return XST_SUCCESS if successful, else XST_FAILURE. * * @note None. * *****************************************************************************/ static int EmacPsResetDevice(XEmacPs * EmacPsInstancePtr) { int Status = 0; u8 MacSave[6]; u32 Options; XEmacPs_Bd BdTemplate; /* * Stop device */ XEmacPs_Stop(EmacPsInstancePtr); /* * Save the device state */ XEmacPs_GetMacAddress(EmacPsInstancePtr, &MacSave, 1); Options = XEmacPs_GetOptions(EmacPsInstancePtr); /* * Stop and reset the device */ XEmacPs_Reset(EmacPsInstancePtr); /* * Restore the state */ XEmacPs_SetMacAddress(EmacPsInstancePtr, &MacSave, 1); Status |= XEmacPs_SetOptions(EmacPsInstancePtr, Options); Status |= XEmacPs_ClearOptions(EmacPsInstancePtr, ~Options); if (Status != XST_SUCCESS) { EmacPsUtilErrorTrap("Error restoring state after reset"); return XST_FAILURE; } /* * Setup callbacks */ Status = XEmacPs_SetHandler(EmacPsInstancePtr, XEMACPS_HANDLER_DMASEND, (void *) XEmacPsSendHandler, EmacPsInstancePtr); Status |= XEmacPs_SetHandler(EmacPsInstancePtr, XEMACPS_HANDLER_DMARECV, (void *) XEmacPsRecvHandler, EmacPsInstancePtr); Status |= XEmacPs_SetHandler(EmacPsInstancePtr, XEMACPS_HANDLER_ERROR, (void *) XEmacPsErrorHandler, EmacPsInstancePtr); if (Status != XST_SUCCESS) { EmacPsUtilErrorTrap("Error assigning handlers"); return XST_FAILURE; } /* * Setup RxBD space. * * We have already defined a properly aligned area of memory to store * RxBDs at the beginning of this source code file so just pass its * address into the function. No MMU is being used so the physical and * virtual addresses are the same. * * Setup a BD template for the Rx channel. This template will be copied * to every RxBD. We will not have to explicitly set these again. */ XEmacPs_BdClear(&BdTemplate); /* * Create the RxBD ring */ Status = XEmacPs_BdRingCreate(&(XEmacPs_GetRxRing (EmacPsInstancePtr)), RX_BD_LIST_START_ADDRESS, RX_BD_LIST_START_ADDRESS, XEMACPS_BD_ALIGNMENT, RXBD_CNT); if (Status != XST_SUCCESS) { EmacPsUtilErrorTrap ("Error setting up RxBD space, BdRingCreate"); return XST_FAILURE; } Status = XEmacPs_BdRingClone(& (XEmacPs_GetRxRing(EmacPsInstancePtr)), &BdTemplate, XEMACPS_RECV); if (Status != XST_SUCCESS) { EmacPsUtilErrorTrap ("Error setting up RxBD space, BdRingClone"); return XST_FAILURE; } /* * Setup TxBD space. * * Like RxBD space, we have already defined a properly aligned area of * memory to use. * * Also like the RxBD space, we create a template. Notice we don't set * the "last" attribute. The examples will be overriding this * attribute so it does no good to set it up here. */ XEmacPs_BdClear(&BdTemplate); XEmacPs_BdSetStatus(&BdTemplate, XEMACPS_TXBUF_USED_MASK); /* * Create the TxBD ring */ Status = XEmacPs_BdRingCreate(&(XEmacPs_GetTxRing (EmacPsInstancePtr)), TX_BD_LIST_START_ADDRESS, TX_BD_LIST_START_ADDRESS, XEMACPS_BD_ALIGNMENT, TXBD_CNT); if (Status != XST_SUCCESS) { EmacPsUtilErrorTrap ("Error setting up TxBD space, BdRingCreate"); return XST_FAILURE; } Status = XEmacPs_BdRingClone(& (XEmacPs_GetTxRing(EmacPsInstancePtr)), &BdTemplate, XEMACPS_SEND); if (Status != XST_SUCCESS) { EmacPsUtilErrorTrap ("Error setting up TxBD space, BdRingClone"); return XST_FAILURE; } /* * Restart the device */ XEmacPs_Start(EmacPsInstancePtr); return XST_SUCCESS; }