/* ================================================================== >>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<< ------------------------------------------------------------------ Copyright (c) 2019-2024 by Lattice Semiconductor Corporation ALL RIGHTS RESERVED ------------------------------------------------------------------ IMPORTANT: THIS FILE IS USED BY OR GENERATED BY the LATTICE PROPELâ„¢ DEVELOPMENT SUITE, WHICH INCLUDES PROPEL BUILDER AND PROPEL SDK. Lattice grants permission to use this code pursuant to the terms of the Lattice Propel License Agreement. DISCLAIMER: LATTICE MAKES NO WARRANTIES ON THIS FILE OR ITS CONTENTS, WHETHER EXPRESSED, IMPLIED, STATUTORY, OR IN ANY PROVISION OF THE LATTICE PROPEL LICENSE AGREEMENT OR COMMUNICATION WITH LICENSEE, AND LATTICE SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. LATTICE DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED HEREIN WILL MEET LICENSEE 'S REQUIREMENTS, OR THAT LICENSEE' S OPERATION OF ANY DEVICE, SOFTWARE OR SYSTEM USING THIS FILE OR ITS CONTENTS WILL BE UNINTERRUPTED OR ERROR FREE, OR THAT DEFECTS HEREIN WILL BE CORRECTED. LICENSEE ASSUMES RESPONSIBILITY FOR SELECTION OF MATERIALS TO ACHIEVE ITS INTENDED RESULTS, AND FOR THE PROPER INSTALLATION, USE, AND RESULTS OBTAINED THEREFROM. LICENSEE ASSUMES THE ENTIRE RISK OF THE FILE AND ITS CONTENTS PROVING DEFECTIVE OR FAILING TO PERFORM PROPERLY AND IN SUCH EVENT, LICENSEE SHALL ASSUME THE ENTIRE COST AND RISK OF ANY REPAIR, SERVICE, CORRECTION, OR ANY OTHER LIABILITIES OR DAMAGES CAUSED BY OR ASSOCIATED WITH THE SOFTWARE.IN NO EVENT SHALL LATTICE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS FILE OR ITS CONTENTS, EVEN IF LATTICE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. LATTICE 'S SOLE LIABILITY, AND LICENSEE' S SOLE REMEDY, IS SET FORTH ABOVE. LATTICE DOES NOT WARRANT OR REPRESENT THAT THIS FILE, ITS CONTENTS OR USE THEREOF DOES NOT INFRINGE ON THIRD PARTIES' INTELLECTUAL PROPERTY RIGHTS, INCLUDING ANY PATENT. IT IS THE USER' S RESPONSIBILITY TO VERIFY THE USER SOFTWARE DESIGN FOR CONSISTENCY AND FUNCTIONALITY THROUGH THE USE OF FORMAL SOFTWARE VALIDATION METHODS. ------------------------------------------------------------------ ================================================================== */ #include "ethernet.h" #include /** * @brief This function configures the TSEMAC to receive all address frames, sets the MAC address, * enables operation at speeds of 10/100/1000 Mbps, and activates both the transmit (TX) and receive (RX) MAC. * @param : handle : handle for the tsemac. * @return : status for initialization */ unsigned char ethernet_init(tsemac_handle_t *handle) { if(handle == NULL) return FAILURE; tsemac_reg_type_t *tsemac = (tsemac_reg_type_t *) (handle->adr); ethernet_disable_tx_rx_mac(handle); tsemac->max_packet_size = MAX_PACKET_SIZE; //configure maximum packet size register tsemac->ipg = IPG_TIME; tsemac->tx_rx_ctrl |= handle->tx_rx_ctrl_var; //configure Rx MAC to receive multicast and broadcast frame receive ethernet_set_speed(handle); ethernet_set_mac_address(handle); ethernet_enable_tx_rx_mac(handle); return SUCCESS; } /** * @brief This function is used to transmit the frame by copying src_packet buffer into dest_packet * and same packet is transmit to tsemac. * @param : handle : handle for the tsemac. * src_packet : buffer containing the packet to transmit to tsemac. * dest_packet :src_packet to copy in dest_packet for user. * @return : void */ void ethernet_packet_handle(tsemac_handle_t *handle,unsigned int *src_packet,unsigned int *dest_packet) { int count; for(count=0; countframe_length; count++) { dest_packet[count] = src_packet[count]; } } /** * @brief This function is used to set the mac address for tsemac. * @param: handle : handle for the tsemac. * @return: return the status of setting the MAC address. */ unsigned char ethernet_set_mac_address(tsemac_handle_t *handle) { if(handle == NULL) return FAILURE; tsemac_reg_type_t *tsemac = (tsemac_reg_type_t *) (handle->adr); tsemac->mac_addr0 = handle->mac_upper; //storing the MAC address for first 4 byte in register MAC address0 tsemac->mac_addr1 = handle->mac_lower; //storing the MAC address for last 2 byte in register MAC address1 return SUCCESS; } /** * @brief This function is used to read the mac address for tsemac. * @param: handle : handle for the tsemac. * @retrun: return the status of MAC address read. */ unsigned char ethernet_get_mac_address(tsemac_handle_t *handle) { if(handle == NULL) return FAILURE; tsemac_reg_type_t *tsemac = (tsemac_reg_type_t *) (handle->adr); handle->mac_upper = tsemac->mac_addr0; //read first 4 byte of MAC address from address word 0 register handle->mac_lower = tsemac->mac_addr1; //read last 2 byte of MAC address from address word 1 register return SUCCESS; } /** * @brief This function is used to set for multicast address for tsemac. * @param: handle : handle for the tsemac. * @retrun: return the status of setting the multicast address. */ unsigned char ethernet_set_multicast_address(tsemac_handle_t *handle) { if(handle == NULL) return FAILURE; tsemac_reg_type_t *tsemac = (tsemac_reg_type_t *) (handle->adr); tsemac->multi_cast0 = handle->multicast_upper; //storing the first 4 byte of the 64 bit hash in mutlicast table word 0 register tsemac->multi_cast1 = handle->multicast_lower; //storing the last 4 byte of the 64 bit hash in mutlicast table word 1 register return SUCCESS; } /** * @brief This function is used to get for multicast address. * @param: handle : handle for the tsemac. * @retrun: return the status of multicast address read. */ unsigned char ethernet_get_multicast_address(tsemac_handle_t *handle) { if(handle == NULL) return FAILURE; tsemac_reg_type_t *tsemac = (tsemac_reg_type_t *) (handle->adr); handle->multicast_upper = tsemac->multi_cast0; //read first 4 byte of the 64 bit hash from multicast table word 0 register handle->multicast_lower = tsemac->multi_cast1; //read last 4 byte of the 64 bit hash from multicast table word 1 register return SUCCESS; } /** * @brief This function is used to set the speed for tsemac at 10/100/1000 Mbps. * @param : handle : handle for the tsemac. * @return : return the success or failure status based on condition. */ unsigned char ethernet_set_speed(tsemac_handle_t *handle) { if(handle == NULL) return FAILURE; tsemac_reg_type_t *tsemac = (tsemac_reg_type_t *) (handle->adr); if(handle->speed_mode == one_g_mode) { tsemac->tx_rx_ctrl &= (~(1 << SET_FULL_DUPLEX_MODE)); //set full duplex mode tsemac->mode_reg |= (1 << SPEED_1G); //set into 1G mode } else if(handle->speed_mode == fast_half_duplex_mode) { tsemac->tx_rx_ctrl |= (1 << SET_HALF_DUPLEX_MODE); //set half duplex mode tsemac->mode_reg &= (~(1 << SPEED_10_OR_100_MBPS)); //set into 10 or 100 mbps } else { tsemac->tx_rx_ctrl &= (~(1 << SET_FULL_DUPLEX_MODE)); //set full duplex mode tsemac->mode_reg &= (~(1 << SPEED_10_OR_100_MBPS)); //set into 10 or 100 mbps } return SUCCESS; } /** * @brief This function is used to start the tx and rx mac. * @param : handle : handle for the tsemac. * @return : return the success or failure status based on condition. */ unsigned char ethernet_enable_tx_rx_mac(tsemac_handle_t *handle) { if(handle == NULL) return FAILURE; tsemac_reg_type_t *tsemac = (tsemac_reg_type_t *) (handle->adr); tsemac->mode_reg |= (TX_EN | RX_EN); return SUCCESS; } /** * @brief This function is used to stop the tx and rx mac. * @param : handle : handle for the tsemac. * @return : return the success or failure status based on condition. */ unsigned char ethernet_disable_tx_rx_mac(tsemac_handle_t *handle) { if(handle == NULL) return FAILURE; tsemac_reg_type_t *tsemac = (tsemac_reg_type_t *) (handle->adr); tsemac->mode_reg &= ~(TX_EN | RX_EN); return SUCCESS; } /** * @brief This function is used to read the Transmit and receive status register. * @param: handle : handle for the tsemac. * @return : return status register value after reading. */ unsigned int ethernet_tx_rx_status_reg_read(tsemac_handle_t *handle) { tsemac_reg_type_t *tsemac = (tsemac_reg_type_t *) (handle->adr); return tsemac->tx_rx_status; } /** * @brief This function is used to read the mode register. * @param: handle : handle for the tsemac. * @return : return mode register value after reading. */ unsigned int ethernet_mode_reg_read(tsemac_handle_t *handle) { tsemac_reg_type_t *tsemac = (tsemac_reg_type_t *) (handle->adr); return tsemac->mode_reg; } /** * @brief This function is used to set the particular bit in Transmit and Receive control register. * @param: handle : handle for the tsemac. * @return : return the success or failure status based on condition. */ unsigned char ethernet_tx_rx_control_reg_set(tsemac_handle_t *handle,unsigned char bit_pos) { if(handle == NULL) return FAILURE; tsemac_reg_type_t *tsemac = (tsemac_reg_type_t *) (handle->adr); tsemac->tx_rx_ctrl |= 1 << bit_pos; return SUCCESS; }