/** * * This function sends a frame of given size. This function assumes interrupt * mode and sends the frame. * * @param XEmacInstancePtr is a pointer to the XEmacLite instance to be * worked on. * @param PayloadSize is the size of the frame to create. The size only * reflects the payload size, it does not include the Ethernet * header size (14 bytes) nor the Ethernet CRC size (4 bytes). * @param DestAddress if the address of the remote hardware the frame is * to be sent to. * * @return XST_SUCCESS if successful, a driver-specific return code if not. * * @note None. * ******************************************************************************/ static int EmacLiteSendFrame(XEmacLite *XEmacInstancePtr, u32 PayloadSize) { u8 *FramePtr; int Index; int Status; /* * Set the Complete flag to false. */ TransmitComplete = FALSE; /* * Assemble the frame with a destination address and the source address. */ FramePtr = (u8 *)TxFrame; *FramePtr++ = LocalAddress[0]; *FramePtr++ = LocalAddress[1]; *FramePtr++ = LocalAddress[2]; *FramePtr++ = LocalAddress[3]; *FramePtr++ = LocalAddress[4]; *FramePtr++ = LocalAddress[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) = Xil_Htons(PayloadSize); FramePtr++; FramePtr++; /* * Now fill in the data field with known values so we can verify them * on receive. */ for (Index = 0; Index < PayloadSize; Index++) { *FramePtr++ = (u8)Index; } /* * Now send the frame. */ Status = XEmacLite_Send(XEmacInstancePtr, (u8 *)TxFrame, PayloadSize + XEL_HEADER_SIZE); return Status; }
/** * * This function sends a frame of given size. * * @param XEmacInstancePtr is a pointer to the XEmacLite instance. * @param PayloadSize is the size of the frame to create. The size only * reflects the payload size, it does not include the Ethernet * header size (14 bytes) nor the Ethernet CRC size (4 bytes). * * @return XST_SUCCESS if successful, else a driver-specific return code. * * @note None. * ******************************************************************************/ int EmacLiteSendFrame(XEmacLite *InstancePtr, u32 PayloadSize) { u8 *FramePtr; int Index; FramePtr = (u8 *)TxFrame; /* * Set up the destination address as the local address for * Phy Loopback. */ /* * 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) = Xil_Htons(PayloadSize); FramePtr++; FramePtr++; /* * Now fill in the data field with known values so we can verify them * on receive. */ for (Index = 0; Index < PayloadSize; Index++) { *FramePtr++ = (u8)Index; } /* * Now send the frame. */ return XEmacLite_Send(InstancePtr, (u8 *)TxFrame, PayloadSize + XEL_HEADER_SIZE); }
int transmit_packet(XEmacLite *instancep, void *packet, unsigned len) { XStatus result = 0; /* there is space for a buffer, so transfer */ result = XEmacLite_Send(instancep, packet, len); if (result != XST_SUCCESS) { return -1; } return 0; }
// // This routine is called to send data to the hardware. static void s3esk_eth_send(struct eth_drv_sc *sc, struct eth_drv_sg *sg_list, int sg_len, int total_len, unsigned long key) { struct s3esk_eth_info *qi = (struct s3esk_eth_info *)sc->driver_private; volatile char *bp; int i; #ifdef CYGPKG_NET cyg_uint32 int_state; HAL_DISABLE_INTERRUPTS(int_state); // FIXME: closer to Send #endif //can be send max 1500 bytes // Set up buffer qi->txlength = total_len; bp = qi->txbuf; qi->sended = 0; for (i = 0; i < sg_len; i++) { memcpy((void *)bp, (void *)sg_list[i].buf, sg_list[i].len); bp += sg_list[i].len; } cyg_uint32 len = qi->txlength - qi->sended; if(len > CYGNUM_DEVS_ETH_POWERPC_S3ESK_BUFSIZE) len = CYGNUM_DEVS_ETH_POWERPC_S3ESK_BUFSIZE; //XEmacLite_SetMacAddress(&qi->dev, qi->enaddr); if (XEmacLite_Send(&qi->dev, qi->txbuf + qi->sended, len) != XST_SUCCESS) { deferred = 1; } else { qi->sended += len; if(qi->sended >= qi->txlength) deferred = 0; else deferred = 1; } // sg_list can be freed! (maybe deferred) (sc->funs->eth_drv->tx_done)(sc, key, 0); #ifdef CYGPKG_NET HAL_RESTORE_INTERRUPTS(int_state); #endif }
// // This function is called when a frame has been sent // static void s3esk_eth_TxEvent(void *_cb) { struct eth_drv_sc *sc = (struct eth_drv_sc *)_cb; struct s3esk_eth_info *qi = (struct s3esk_eth_info *)sc->driver_private; if (deferred) { cyg_uint32 len = qi->txlength - qi->sended; if(len > CYGNUM_DEVS_ETH_POWERPC_S3ESK_BUFSIZE) len = CYGNUM_DEVS_ETH_POWERPC_S3ESK_BUFSIZE; //XEmacLite_SetMacAddress(&qi->dev, qi->enaddr); if (XEmacLite_Send(&qi->dev, qi->txbuf + qi->sended, len) != XST_SUCCESS) { deferred = 1; } else { qi->sended += len; if(qi->sended >= qi->txlength) deferred = 0; else deferred = 1; } } }
// // This function is called when a frame has been sent // static void emaclite_TxEvent(void *_cb) { struct eth_drv_sc *sc = (struct eth_drv_sc *)_cb; struct emaclite_info *qi = (struct emaclite_info *)sc->driver_private; if (deferred) { cyg_uint32 len = qi->txlength - qi->sended; if(len > MTU) len = MTU; //XEmacLite_SetMacAddress(&qi->dev, qi->enaddr); if (XEmacLite_Send(&qi->dev, qi->txbuf + qi->sended, len) != XST_SUCCESS) { deferred = 1; } else { qi->sended += len; if(qi->sended >= qi->txlength) deferred = 0; else deferred = 1; } } }
static err_t prvLowLevelOutput( struct netif *pxNetIf, struct pbuf *p ) { /* This is taken from lwIP example code and therefore does not conform to the FreeRTOS coding standard. */ struct pbuf *q; static unsigned char ucBuffer[ 1520 ] __attribute__((aligned(32))); unsigned char *pucBuffer = ucBuffer; unsigned char *pucChar; struct eth_hdr *pxHeader; u16_t usTotalLength = p->tot_len - ETH_PAD_SIZE; err_t xReturn = ERR_OK; long x; ( void ) pxNetIf; #if defined(LWIP_DEBUG) && LWIP_NETIF_TX_SINGLE_PBUF LWIP_ASSERT("p->next == NULL && p->len == p->tot_len", p->next == NULL && p->len == p->tot_len); #endif /* Initiate transfer. */ if( p->len == p->tot_len ) { /* No pbuf chain, don't have to copy -> faster. */ pucBuffer = &( ( unsigned char * ) p->payload )[ ETH_PAD_SIZE ]; } else { /* pbuf chain, copy into contiguous ucBuffer. */ if( p->tot_len >= sizeof( ucBuffer ) ) { LINK_STATS_INC( link.lenerr ); LINK_STATS_INC( link.drop ); snmp_inc_ifoutdiscards( pxNetIf ); xReturn = ERR_BUF; } else { pucChar = ucBuffer; for( q = p; q != NULL; q = q->next ) { /* Send the data from the pbuf to the interface, one pbuf at a time. The size of the data in each pbuf is kept in the ->len variable. */ /* send data from(q->payload, q->len); */ LWIP_DEBUGF( NETIF_DEBUG, ( "NETIF: send pucChar %p q->payload %p q->len %i q->next %p\n", pucChar, q->payload, ( int ) q->len, ( void* ) q->next ) ); if( q == p ) { memcpy( pucChar, &( ( char * ) q->payload )[ ETH_PAD_SIZE ], q->len - ETH_PAD_SIZE ); pucChar += q->len - ETH_PAD_SIZE; } else { memcpy( pucChar, q->payload, q->len ); pucChar += q->len; } } } } if( xReturn == ERR_OK ) { for( x = 0; x < netifMAX_TX_ATTEMPTS; x++ ) { xReturn = XEmacLite_Send( &xEMACInstance, pucBuffer, ( int ) usTotalLength ); if( xReturn == XST_SUCCESS ) { break; } else { vTaskDelay( netifTX_BUFFER_FREE_WAIT ); } } if( xReturn != XST_SUCCESS ) { LINK_STATS_INC( link.memerr ); LINK_STATS_INC( link.drop ); snmp_inc_ifoutdiscards( pxNetIf ); xReturn = ERR_BUF; } else { LINK_STATS_INC( link.xmit ); snmp_add_ifoutoctets( pxNetIf, usTotalLength ); pxHeader = ( struct eth_hdr * )p->payload; if( ( pxHeader->dest.addr[ 0 ] & 1 ) != 0 ) { /* broadcast or multicast packet*/ snmp_inc_ifoutnucastpkts( pxNetIf ); } else { /* unicast packet */ snmp_inc_ifoutucastpkts( pxNetIf ); } } } return xReturn; }
/** * * This function processes the received packet and generates the corresponding * reply packets. * * @param InstancePtr is a pointer to the instance of the EmacLite. * * @return None. * * @note This function assumes MAC does not strip padding or CRC. * ******************************************************************************/ static void ProcessRecvFrame(XEmacLite *InstancePtr) { u16 *RxFramePtr; u16 *TxFramePtr; u16 *TempPtr; u16 CheckSum; u32 NextTxBuffBaseAddr; int Index; int PacketType = 0; TxFramePtr = (u16 *)TxFrame; RxFramePtr = (u16 *)RxFrame; /* * Determine the next expected Tx buffer address. */ NextTxBuffBaseAddr = XEmacLite_NextTransmitAddr(InstancePtr); /* * Check the packet type. */ Index = MAC_ADDR_LEN; TempPtr = (u16 *)LocalMacAddr; while (Index--) { if (Xil_Ntohs((*(RxFramePtr + Index)) == BROADCAST_ADDR) && (PacketType != MAC_MATCHED_PACKET)) { PacketType = BROADCAST_PACKET; } else if (Xil_Ntohs((*(RxFramePtr + Index)) == *(TempPtr + Index)) && (PacketType != BROADCAST_PACKET)) { PacketType = MAC_MATCHED_PACKET; } else { PacketType = 0; break; } } /* * Process broadcast packet. */ if (PacketType == BROADCAST_PACKET) { /* * Check for an ARP Packet if so generate a reply. */ if (Xil_Ntohs(*(RxFramePtr + ETHER_PROTO_TYPE_LOC)) == XEL_ETHER_PROTO_TYPE_ARP) { /* * IP address of the local machine. */ TempPtr = (u16 *)LocalIpAddr; /* * Check destination IP address of the packet with * local IP address. */ if ( ((*(RxFramePtr + ARP_REQ_DEST_IP_LOC_1)) == *TempPtr++) && ((*(RxFramePtr + ARP_REQ_DEST_IP_LOC_2)) == *TempPtr++)) { /* * Check ARP packet type(request/reply). */ if (Xil_Ntohs(*(RxFramePtr + ARP_REQ_STATUS_LOC)) == ARP_REQUEST) { /* * Add destination MAC address * to the reply packet (i.e) source * address of the received packet. */ Index = SRC_MAC_ADDR_LOC; while (Index < (SRC_MAC_ADDR_LOC + MAC_ADDR_LEN)) { *TxFramePtr++ = *(RxFramePtr + Index); Index++; } /* * Add source (local) MAC address * to the reply packet. */ Index = 0; TempPtr = (u16 *)LocalMacAddr; while (Index < MAC_ADDR_LEN) { *TxFramePtr++ = *TempPtr++; Index++; } /* * Add Ethernet proto type H/W * type(10/3MBps),H/W address length and * protocol address len (i.e)same as in * the received packet */ Index = ETHER_PROTO_TYPE_LOC; while (Index < (ETHER_PROTO_TYPE_LOC + ETHER_PROTO_TYPE_LEN + ARP_HW_TYPE_LEN + ARP_HW_ADD_LEN + ARP_PROTO_ADD_LEN)) { *TxFramePtr++ = *(RxFramePtr + Index); Index++; } /* * Add ARP reply status to the reply * packet. */ *TxFramePtr++ = Xil_Htons(ARP_REPLY); /* * Add local MAC Address * to the reply packet. */ TempPtr = (u16 *)LocalMacAddr; Index = 0; while (Index < MAC_ADDR_LEN) { *TxFramePtr++ = *TempPtr++; Index++; } /* * Add local IP Address * to the reply packet. */ TempPtr = (u16 *)LocalIpAddr; Index = 0; while (Index < IP_ADDR_LEN) { *TxFramePtr++ = *TempPtr++ ; Index++; } /* * Add Destination MAC Address * to the reply packet from the received * packet. */ Index = SRC_MAC_ADDR_LOC; while (Index < (SRC_MAC_ADDR_LOC + MAC_ADDR_LEN)) { *TxFramePtr++ = *(RxFramePtr + Index); Index++; } /* * Add Destination IP Address * to the reply packet. */ Index = ARP_REQ_SRC_IP_LOC; while (Index < (ARP_REQ_SRC_IP_LOC + IP_ADDR_LEN)) { *TxFramePtr++ = *(RxFramePtr + Index); Index++; } /* * Fill zeros as per protocol. */ Index = 0; while (Index < ARP_ZEROS_LEN) { *TxFramePtr++ = 0x0000; Index++; } /* * Transmit the Reply Packet. */ XEmacLite_Send(InstancePtr, (u8 *)&TxFrame, ARP_PACKET_SIZE); } } } } /* * Process packets whose MAC address is matched. */ if (PacketType == MAC_MATCHED_PACKET) { /* * Check ICMP packet. */ if (Xil_Ntohs(*(RxFramePtr + ETHER_PROTO_TYPE_LOC)) == XEL_ETHER_PROTO_TYPE_IP) { /* * Check the IP header checksum. */ CheckSum = CheckSumCalculation(RxFramePtr, IP_HDR_START_LOC, IP_HDR_LEN); /* * Check the Data field checksum. */ if (CheckSum == CORRECT_CKSUM_VALUE) { CheckSum = CheckSumCalculation(RxFramePtr, ICMP_DATA_START_LOC, ICMP_DATA_FIELD_LEN); if (CheckSum == CORRECT_CKSUM_VALUE) { /* * Add destination address * to the reply packet (i.e)source * address of the received packet. */ Index = SRC_MAC_ADDR_LOC; while (Index < (SRC_MAC_ADDR_LOC + MAC_ADDR_LEN)) { *TxFramePtr++ = *(RxFramePtr + Index); Index++; } /* * Add local MAC address * to the reply packet. */ Index = 0; TempPtr = (u16 *)LocalMacAddr; while (Index < MAC_ADDR_LEN) { *TxFramePtr++ = *TempPtr++; Index++; } /* * Add protocol type * header length and, packet * length(60 Bytes) to the reply packet. */ Index = ETHER_PROTO_TYPE_LOC; while (Index < (ETHER_PROTO_TYPE_LOC + ETHER_PROTO_TYPE_LEN + IP_VERSION_LEN + IP_PACKET_LEN)) { *TxFramePtr++ = *(RxFramePtr + Index); Index++; } /* * Identification field a random number * which is set to IDENT_FIELD_VALUE. */ *TxFramePtr++ = IDENT_FIELD_VALUE; /* * Add fragment type, time to live and * ICM field. It is same as in the * received packet. */ Index = IP_FRAG_FIELD_LOC; while (Index < (IP_FRAG_FIELD_LOC + IP_TTL_ICM_LEN + IP_FRAG_FIELD_LEN)) { *TxFramePtr++ = *(RxFramePtr + Index); Index++; } /* * Checksum first set to 0 and * added in this field later. */ *TxFramePtr++ = 0x0000; /* * Add Source IP address */ Index = 0; TempPtr = (u16 *)LocalIpAddr; while (Index < IP_ADDR_LEN) { *TxFramePtr++ = *TempPtr++; Index++; } /* * Add Destination IP address. */ Index = ICMP_REQ_SRC_IP_LOC; while (Index < (ICMP_REQ_SRC_IP_LOC + IP_ADDR_LEN)) { *TxFramePtr++ = *(RxFramePtr + Index); Index++; } /* * Calculate checksum, and * add it in the appropriate field. */ CheckSum = CheckSumCalculation( (u16 *)TxFrame, IP_HDR_START_LOC, IP_HDR_LEN); CheckSum = ~CheckSum; *(TxFramePtr - IP_CSUM_LOC_BACK) = Xil_Htons(CheckSum); /* * Echo reply status & checksum. */ Index = ICMP_ECHO_FIELD_LOC; while (Index < (ICMP_ECHO_FIELD_LOC + ICMP_ECHO_FIELD_LEN)) { *TxFramePtr++ = 0x0000; Index++; } /* * Add data to buffer which was * received from the packet. */ Index = ICMP_DATA_LOC; while (Index < (ICMP_DATA_LOC + ICMP_DATA_LEN)) { *TxFramePtr++ = (*(RxFramePtr + Index)); Index++; } /* * Generate checksum for the data and * add it in the appropriate field. */ CheckSum = CheckSumCalculation( (u16 *)TxFrame, ICMP_DATA_START_LOC, ICMP_DATA_FIELD_LEN); CheckSum = ~CheckSum; *(TxFramePtr - ICMP_DATA_CSUM_LOC_BACK) = Xil_Htons(CheckSum); /* * Transmit the frame. */ XEmacLite_Send(InstancePtr, (u8 *)&TxFrame, ICMP_PACKET_SIZE); /* * Increment the number of * Ping replies sent. */ NumOfPingReplies++; } } } } }
/** * * This function will send a Echo request packet. * * @param InstancePtr is a pointer to the instance of the EmacLite. * * @return None. * * @note None. * ******************************************************************************/ static void SendEchoReqFrame(XEmacLite *InstancePtr) { u16 *TempPtr; u16 *TxFramePtr; u16 *RxFramePtr; u16 CheckSum; u32 NextTxBuffBaseAddr; int Index; TxFramePtr = (u16 *)TxFrame; RxFramePtr = (u16 *)RxFrame; /* * Determine the next expected transmit buffer base address. */ NextTxBuffBaseAddr = XEmacLite_NextTransmitAddr(InstancePtr); /* * Add Destination MAC Address. */ Index = MAC_ADDR_LEN; while (Index--) { *(TxFramePtr + Index) = *(DestMacAddr + Index); } /* * Add Source MAC Address. */ Index = MAC_ADDR_LEN; TempPtr = (u16 *)LocalMacAddr; while (Index--) { *(TxFramePtr + (Index + SRC_MAC_ADDR_LOC )) = *(TempPtr + Index); } /* * Add IP header information. */ Index = IP_START_LOC; while (Index--) { *(TxFramePtr + (Index + ETHER_PROTO_TYPE_LOC )) = Xil_Htons(*(IpHeaderInfo + Index)); } /* * Add Source IP address. */ Index = IP_ADDR_LEN; TempPtr = (u16 *)LocalIpAddress; while (Index--) { *(TxFramePtr + (Index + IP_REQ_SRC_IP_LOC )) = *(TempPtr + Index); } /* * Add Destination IP address. */ Index = IP_ADDR_LEN; TempPtr = (u16 *)DestIpAddress; while (Index--) { *(TxFramePtr + (Index + IP_REQ_DEST_IP_LOC )) = *(TempPtr + Index); } /* * Checksum is calculated for IP field and added in the frame. */ CheckSum = CheckSumCalculation((u16 *)TxFrame, IP_START_LOC, IP_HEADER_LEN); CheckSum = ~CheckSum; *(TxFramePtr + IP_CHECKSUM_LOC) = Xil_Htons(CheckSum); /* * Add echo field information. */ *(TxFramePtr + ICMP_ECHO_FIELD_LOC) = Xil_Htons(XEL_ETHER_PROTO_TYPE_IP); /* * Checksum value is initialized to zeros. */ *(TxFramePtr + ICMP_DATA_LEN) = 0x0000; /* * Add identifier and sequence number to the frame. */ *(TxFramePtr + ICMP_IDEN_FIELD_LOC) = (IDEN_NUM); *(TxFramePtr + (ICMP_IDEN_FIELD_LOC + 1)) = Xil_Htons((u16)(++SeqNum)); /* * Add known data to the frame. */ Index = ICMP_KNOWN_DATA_LEN; while (Index--) { *(TxFramePtr + (Index + ICMP_KNOWN_DATA_LOC)) = Xil_Htons(*(IcmpData + Index)); } /* * Checksum is calculated for Data Field and added in the frame. */ CheckSum = CheckSumCalculation((u16 *)TxFrame, ICMP_DATA_START_LOC, ICMP_DATA_FIELD_LEN ); CheckSum = ~CheckSum; *(TxFramePtr + ICMP_DATA_CHECKSUM_LOC) = Xil_Htons(CheckSum); /* * Transmit the Frame. */ XEmacLite_Send(InstancePtr, (u8 *)&TxFrame, ICMP_PKT_SIZE); }
/** * * This function will send a ARP request packet. * * @param InstancePtr is a pointer to the instance of the EmacLite. * * @return None. * * @note None. * ******************************************************************************/ static void SendArpReqFrame(XEmacLite *InstancePtr) { u16 *TempPtr; u16 *TxFramePtr; u32 NextTxBuffBaseAddr; int Index; TxFramePtr = (u16 *)TxFrame; /* * Determine the next expected transmit buffer base address. */ NextTxBuffBaseAddr = XEmacLite_NextTransmitAddr(InstancePtr); /* * Add broadcast address. */ Index = MAC_ADDR_LEN; while (Index--) { *TxFramePtr++ = BROADCAST_ADDR; } /* * Add local MAC address. */ Index = 0; TempPtr = (u16 *)LocalMacAddr; while (Index < MAC_ADDR_LEN) { *TxFramePtr++ = *(TempPtr + Index); Index++; } /* * Add * - Ethernet proto type. * - Hardware Type * - Protocol IP Type * - IP version (IPv6/IPv4) * - ARP Request */ *TxFramePtr++ = Xil_Htons(XEL_ETHER_PROTO_TYPE_ARP); *TxFramePtr++ = Xil_Htons(HW_TYPE); *TxFramePtr++ = Xil_Htons(XEL_ETHER_PROTO_TYPE_IP); *TxFramePtr++ = Xil_Htons(IP_VERSION); *TxFramePtr++ = Xil_Htons(ARP_REQUEST); /* * Add local MAC address. */ Index = 0; TempPtr = (u16 *)LocalMacAddr; while (Index < MAC_ADDR_LEN) { *TxFramePtr++ = *(TempPtr + Index); Index++; } /* * Add local IP address. */ Index = 0; TempPtr = (u16 *)LocalIpAddress; while (Index < IP_ADDR_LEN) { *TxFramePtr++ = *(TempPtr + Index); Index++; } /* * Fills 6 bytes of information with zeros as per protocol. */ Index = 0; while (Index < 3) { *TxFramePtr++ = 0x0000; Index++; } /* * Add Destination IP address. */ Index = 0; TempPtr = (u16 *)DestIpAddress; while (Index < IP_ADDR_LEN) { *TxFramePtr++ = *(TempPtr + Index); Index++; } /* * Transmit the Frame. */ XEmacLite_Send(InstancePtr, (u8 *)&TxFrame, ARP_REQ_PKT_SIZE); }
/** * * This function sends a frame of given size. This function assumes interrupt * mode and sends the frame. * * @param EmacLiteInstPtr is a pointer to the EmacLite instance. * @param PayloadSize is the size of the frame to create. The size only * reflects the payload size, it does not include the Ethernet * header size (14 bytes) nor the Ethernet CRC size (4 bytes). * * @return XST_SUCCESS if successful, else XST_FAILURE. * * @note None. * ******************************************************************************/ static int EmacLiteSendFrame(XEmacLite *EmacLiteInstPtr, u32 PayloadSize) { int Status; u8 *FramePtr; u32 Index; /* * Set the Complete flag to false. */ TransmitComplete = FALSE; /* * Assemble the frame with a destination address and the source address. */ FramePtr = (u8 *)TxFrame; /* * Set up the destination address as the local address for * Phy Loopback and Internal loopback. */ if (XEmacLite_IsMdioConfigured(EmacLiteInstPtr) || XEmacLite_IsLoopbackConfigured(EmacLiteInstPtr)) { *FramePtr++ = LocalAddress[0]; *FramePtr++ = LocalAddress[1]; *FramePtr++ = LocalAddress[2]; *FramePtr++ = LocalAddress[3]; *FramePtr++ = LocalAddress[4]; *FramePtr++ = LocalAddress[5]; } else { /* * 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) = Xil_Htons(PayloadSize); FramePtr++; FramePtr++; /* * Now fill in the data field with known values so we can verify them. */ for (Index = 0; Index < PayloadSize; Index++) { *FramePtr++ = (u8)Index; } /* * Now send the frame. */ Status = XEmacLite_Send(EmacLiteInstPtr, (u8 *)TxFrame, PayloadSize + XEL_HEADER_SIZE); if (Status != XST_SUCCESS) { return XST_FAILURE; } return XST_SUCCESS; }
/** * * This function sends a frame of given size. This function assumes interrupt * mode and sends the frame. * * @param EmacLiteInstPtr is a pointer to the EmacLite instance. * @param PayloadSize is the size of the frame to create. The size only * reflects the payload size, it does not include the Ethernet header * size (14 bytes) nor the Ethernet CRC size (4 bytes). * @param DestAddress if the address of the remote hardware the frame is to be * sent to. * * @return XST_SUCCESS if successful, else XST_FAILURE. * * @note None. * ******************************************************************************/ static XStatus EmacLiteSendFrame(XEmacLite *EmacLiteInstPtr, Xuint32 PayloadSize, Xuint8 *DestAddress) { XStatus Status; Xuint8 *FramePtr; Xuint8 *AddrPtr = DestAddress; Xuint32 Index; /* * Set the Complete flag to false */ TransmitComplete = XFALSE; /* * Assemble the frame with a destination address and the source address. */ FramePtr = (Xuint8 *)TxFrame; *FramePtr++ = *AddrPtr++; *FramePtr++ = *AddrPtr++; *FramePtr++ = *AddrPtr++; *FramePtr++ = *AddrPtr++; *FramePtr++ = *AddrPtr++; *FramePtr++ = *AddrPtr++; /* * 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. */ *((Xuint16 *)FramePtr) = PayloadSize; *FramePtr++; *FramePtr++; /* * Now fill in the data field with known values so we can verify them. */ for (Index = 0; Index < PayloadSize; Index++) { *FramePtr++ = (Xuint8)Index; } /* * Now send the frame. */ Status = XEmacLite_Send(EmacLiteInstPtr, (Xuint8 *)TxFrame, PayloadSize + XEL_HEADER_SIZE); if (Status != XST_SUCCESS) { return XST_FAILURE; } return XST_SUCCESS; }
/** * * This function sends a frame of given size. This function assumes interrupt * mode and sends the frame. * * @param EmacLiteInstPtr is a pointer to the EmacLite instance. * @param PayloadSize is the size of the frame to create. The size only * reflects the payload size, it does not include the Ethernet * header size (14 bytes) nor the Ethernet CRC size (4 bytes). * * @return XST_SUCCESS if successful, else XST_FAILURE. * * @note None. * ******************************************************************************/ int EmacLiteSendFrame(u8 *Payload, u32 PayloadSize, MACAddr_t *DstMACAddr, short Type) { int Status; int i; u8 *FramePtr; //u32 Index; /* * Set the Complete flag to false. */ //TransmitComplete = FALSE; /* * Assemble the frame with a destination address and the source address. */ FramePtr = (u8 *)TxFrame; /* * Fill in the valid Destination MAC address if * the Loopback is not enabled. */ *FramePtr++ = DstMACAddr->byte1; *FramePtr++ = DstMACAddr->byte2; *FramePtr++ = DstMACAddr->byte3; *FramePtr++ = DstMACAddr->byte4; *FramePtr++ = DstMACAddr->byte5; *FramePtr++ = DstMACAddr->byte6; /* * 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) = Xil_Htons(Type); FramePtr++; FramePtr++; for (i = 0; i < PayloadSize; i++) { *FramePtr++ = Payload[i]; } /* * Now send the frame. */ Status = XEmacLite_Send(ð_handle, (u8 *)TxFrame, PayloadSize + XEL_HEADER_SIZE); if (Status != XST_SUCCESS) { return XST_FAILURE; } return XST_SUCCESS; }