1 /** 2 * Copyright (C) 2016 CSI Project. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef _CSI_ETH_PHY_H_ 18 #define _CSI_ETH_PHY_H_ 19 20 #include "drv/eth.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 typedef void *eth_phy_handle_t; 27 28 #define CSI_ETH_PHY_API_VERSION CSI_ETH_VERSION_MAJOR_MINOR(2,1) /* API version */ 29 30 31 #define _CSI_Driver_ETH_PHY_(n) Driver_ETH_PHY##n 32 #define CSI_Driver_ETH_PHY_(n) _CSI_Driver_ETH_PHY_(n) 33 34 35 /****** Ethernet PHY Mode *****/ 36 #define CSI_ETH_PHY_SPEED_Pos 0 37 #define CSI_ETH_PHY_SPEED_Msk (3UL << CSI_ETH_PHY_SPEED_Pos) 38 #define CSI_ETH_PHY_SPEED_10M (CSI_ETH_SPEED_10M << CSI_ETH_PHY_SPEED_Pos) ///< 10 Mbps link speed 39 #define CSI_ETH_PHY_SPEED_100M (CSI_ETH_SPEED_100M << CSI_ETH_PHY_SPEED_Pos) ///< 100 Mbps link speed 40 #define CSI_ETH_PHY_SPEED_1G (CSI_ETH_SPEED_1G << CSI_ETH_PHY_SPEED_Pos) ///< 1 Gpbs link speed 41 #define CSI_ETH_PHY_DUPLEX_Pos 2 42 #define CSI_ETH_PHY_DUPLEX_Msk (1UL << CSI_ETH_PHY_DUPLEX_Pos) 43 #define CSI_ETH_PHY_DUPLEX_HALF (CSI_ETH_DUPLEX_HALF << CSI_ETH_PHY_DUPLEX_Pos) ///< Half duplex link 44 #define CSI_ETH_PHY_DUPLEX_FULL (CSI_ETH_DUPLEX_FULL << CSI_ETH_PHY_DUPLEX_Pos) ///< Full duplex link 45 #define CSI_ETH_PHY_AUTO_NEGOTIATE (1UL << 3) ///< Auto Negotiation mode 46 #define CSI_ETH_PHY_LOOPBACK (1UL << 4) ///< Loop-back test mode 47 #define CSI_ETH_PHY_ISOLATE (1UL << 5) ///< Isolate PHY from MII/RMII interface 48 49 typedef int32_t (*csi_eth_phy_read_t)(uint8_t phy_addr, uint8_t reg_addr, uint16_t *data); ///< Read Ethernet PHY Register. 50 typedef int32_t (*csi_eth_phy_write_t)(uint8_t phy_addr, uint8_t reg_addr, uint16_t data); ///< Write Ethernet PHY Register. 51 52 typedef struct { 53 csi_eth_phy_read_t phy_read; 54 csi_eth_phy_write_t phy_write; 55 eth_link_info_t link_info; 56 } eth_phy_priv_t; 57 58 // Function documentation 59 /** 60 \brief Get driver version. 61 \param[in] handle ethernet phy handle 62 \return driver version 63 */ 64 csi_drv_version_t csi_eth_phy_get_version(eth_phy_handle_t handle); 65 66 /** 67 \brief Initialize Ethernet PHY Device. 68 \param[in] fn_read 69 \param[in] fn_write 70 \return ethernet phy handle 71 */ 72 eth_phy_handle_t csi_eth_phy_initialize(csi_eth_phy_read_t fn_read, csi_eth_phy_write_t fn_write); 73 74 /** 75 \brief De-initialize Ethernet PHY Device. 76 \param[in] handle ethernet phy handle 77 \return error code 78 */ 79 int32_t csi_eth_phy_uninitialize(eth_phy_handle_t handle); 80 81 /** 82 \brief Control Ethernet PHY Device Power. 83 \param[in] handle ethernet phy handle 84 \param[in] state Power state 85 \return error code 86 */ 87 int32_t csi_eth_phy_power_control(eth_phy_handle_t handle, eth_power_state_t state); 88 89 /** 90 \brief Set Ethernet Media Interface. 91 \param[in] handle ethernet phy handle 92 \param[in] interface Media Interface type 93 \return error code 94 */ 95 int32_t csi_eth_phy_set_interface(eth_phy_handle_t handle, uint32_t interface); 96 97 /** 98 \brief Set Ethernet PHY Device Operation mode. 99 \param[in] handle ethernet phy handle 100 \param[in] mode Operation Mode 101 \return error code 102 */ 103 int32_t csi_eth_phy_set_mode(eth_phy_handle_t handle, uint32_t mode); 104 105 /** 106 \brief Get Ethernet PHY Device Link state. 107 \param[in] handle ethernet phy handle 108 \return current link status \ref eth_link_state_t 109 */ 110 eth_link_state_t csi_eth_phy_get_linkstate(eth_phy_handle_t handle); 111 112 /** 113 \brief Get Ethernet PHY Device Link information. 114 \param[in] handle ethernet phy handle 115 \return current link parameters \ref eth_link_info_t 116 */ 117 eth_link_info_t csi_eth_phy_get_linkinfo(eth_phy_handle_t handle); 118 119 #ifdef __cplusplus 120 } 121 #endif 122 123 #endif 124 125