Postby www220 » Sun Feb 26, 2017 8:18 am
LAN8720连接方式
MDIO->GPIO14
MDC->GPIO32
RST->GPIO18
其他管脚按照默认的GPIO连接
RXD0,RXD1,CRS_DV,TXD0,TXD1,TXEN,EXT_CLK
#define PHY_RESET_CONTROL_REG (0x0)
#define SOFTWARE_RESET BIT(15)
#define SOFTWARE_AUTO_NEGTIATION BIT(12)
#define BASIC_MODE_STATUS_REG (0x1)
#define AUTO_NEGOTIATION_COMPLETE BIT(5)
#define LINK_STATUS BIT(2)
#define AUTO_NEG_ADVERTISEMENT_REG (0x4)
#define ASM_DIR BIT(11)
#define PAUSE BIT(10)
#define PHY_LINK_PARTNER_ABILITY_REG (0x5)
#define PARTNER_ASM_DIR BIT(11)
#define PARTNER_PAUSE BIT(10)
#define PHY_STATUS_REG (0x1f)
#define AUTO_NEGTIATION_STATUS BIT(12)
#define DUPLEX_STATUS BIT(4)
#define SPEED_STATUS BIT(2)
void phy_tlk110_check_phy_init(void)
{
while((esp_eth_smi_read(BASIC_MODE_STATUS_REG) & AUTO_NEGOTIATION_COMPLETE ) != AUTO_NEGOTIATION_COMPLETE)
{};
while((esp_eth_smi_read(PHY_STATUS_REG) & AUTO_NEGTIATION_STATUS ) != AUTO_NEGTIATION_STATUS)
{};
}
eth_speed_mode_t phy_tlk110_get_speed_mode(void)
{
if((esp_eth_smi_read(PHY_STATUS_REG) & SPEED_STATUS ) != SPEED_STATUS) {
return ETH_SPEED_MODE_100M;
} else {
return ETH_SPEED_MODE_10M;
}
}
eth_duplex_mode_t phy_tlk110_get_duplex_mode(void)
{
if((esp_eth_smi_read(PHY_STATUS_REG) & DUPLEX_STATUS ) == DUPLEX_STATUS) {
return ETH_MDOE_FULLDUPLEX;
} else {
return ETH_MODE_HALFDUPLEX;
}
}
bool phy_tlk110_check_phy_link_status(void)
{
if((esp_eth_smi_read(BASIC_MODE_STATUS_REG) & LINK_STATUS) == LINK_STATUS ) {
return true;
} else {
return false;
}
}
bool phy_tlk110_get_partner_pause_enable(void)
{
if((esp_eth_smi_read(PHY_LINK_PARTNER_ABILITY_REG) & PARTNER_PAUSE) == PARTNER_PAUSE) {
return true;
} else {
return false;
}
}
void phy_enable_flow_ctrl(void)
{
uint32_t data = 0;
data = esp_eth_smi_read(AUTO_NEG_ADVERTISEMENT_REG);
esp_eth_smi_write(AUTO_NEG_ADVERTISEMENT_REG,data|ASM_DIR|PAUSE);
}
void phy_tlk110_power_enable(bool enable)
{
}
void phy_tlk110_init(void)
{
gpio_set_level(GPIO_NUM_18, 0);
vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(GPIO_NUM_18, 1);
esp_eth_smi_write(PHY_RESET_CONTROL_REG, SOFTWARE_RESET);
vTaskDelay(1000 / portTICK_PERIOD_MS);
esp_eth_smi_write(PHY_RESET_CONTROL_REG, SOFTWARE_AUTO_NEGTIATION);
vTaskDelay(100 / portTICK_PERIOD_MS);
//if config.flow_ctrl_enable == true ,enable this
phy_enable_flow_ctrl();
}
void eth_gpio_config_rmii(void)
{
//txd0 to gpio19 ,can not change
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO19_U, FUNC_GPIO19_EMAC_TXD0);
//tx_en to gpio21 ,can not change
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO21_U, FUNC_GPIO21_EMAC_TX_EN);
//txd1 to gpio22 , can not change
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO22_U, FUNC_GPIO22_EMAC_TXD1);
//rxd0 to gpio25 , can not change
gpio_set_direction(25, GPIO_MODE_INPUT);
//rxd1 to gpio26 ,can not change
gpio_set_direction(26, GPIO_MODE_INPUT);
//rmii clk ,can not change
gpio_set_direction(0, GPIO_MODE_INPUT);
if(RTC_GPIO_IS_VALID_GPIO(GPIO_NUM_32)) rtc_gpio_deinit(GPIO_NUM_32);
if(RTC_GPIO_IS_VALID_GPIO(GPIO_NUM_14)) rtc_gpio_deinit(GPIO_NUM_14);
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[GPIO_NUM_32], PIN_FUNC_GPIO);
gpio_set_pull_mode(GPIO_NUM_32, GPIO_PULLUP_ONLY);
gpio_set_direction(GPIO_NUM_32, GPIO_MODE_OUTPUT);
gpio_matrix_out(GPIO_NUM_32, EMAC_MDC_O_IDX, 0, 0);
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[GPIO_NUM_14], PIN_FUNC_GPIO);
gpio_set_pull_mode(GPIO_NUM_14, GPIO_PULLUP_ONLY);
gpio_set_direction(GPIO_NUM_14, GPIO_MODE_INPUT_OUTPUT);
gpio_matrix_in(GPIO_NUM_14, EMAC_MDI_I_IDX, 0);
gpio_matrix_out(GPIO_NUM_14, EMAC_MDO_O_IDX, 0, 0);
if(RTC_GPIO_IS_VALID_GPIO(GPIO_NUM_18)) rtc_gpio_deinit(GPIO_NUM_18);
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[GPIO_NUM_18], PIN_FUNC_GPIO);
gpio_set_pull_mode(GPIO_NUM_18, GPIO_PULLUP_ONLY);
gpio_set_level(GPIO_NUM_18, 1);
gpio_set_direction(GPIO_NUM_18, GPIO_MODE_OUTPUT);
gpio_matrix_out(GPIO_NUM_18, SIG_GPIO_OUT_IDX, 0, 0);
}