libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
phy_ksz80x1.c
Go to the documentation of this file.
1/** @defgroup ethernet_phy_ksz8051mll_file PHY KSZ8051MLL
2 *
3 * @ingroup ETH
4 *
5 * @brief <b>Ethernet PHY STM32Fxx7 Drivers</b>
6 *
7 * @version 1.0.0
8 * @author @htmlonly &copy; @endhtmlonly 2013 Frantisek Burian <BuFran@seznam.cz>
9 *
10 * @date 1 September 2013
11 *
12 * LGPL License Terms @ref lgpl_license
13 */
14
15/*
16 * This file is part of the libopencm3 project.
17 *
18 * Copyright (C) 2013 Frantisek Burian <BuFran@seznam.cz>
19 *
20 * This library is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU Lesser General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
24 *
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public License
31 * along with this library. If not, see <http://www.gnu.org/licenses/>.
32 */
33
37
38
39/**@{*/
40
41/*---------------------------------------------------------------------------*/
42/** @brief Get the current link status
43 *
44 * Retrieve the link speed and duplex status of the link.
45 *
46 * @param[in] phy uint8_t phy ID of the PHY
47 * @returns ::phy_status Link status
48 */
49enum phy_status phy_link_status(uint8_t phy)
50{
51 return eth_smi_read(phy, KSZ80X1_CR1) & 0x07;
52}
53
54/*---------------------------------------------------------------------------*/
55/** @brief Force autonegotiation
56 *
57 * Force the autonegotiation and set link speed and duplex mode of the link
58 *
59 * @param[in] phy uint8_t phy ID of the PHY
60 * @param[in] mode enum phy_status Desired link status
61 */
62void phy_autoneg_force(uint8_t phy, enum phy_status mode)
63{
64 uint16_t bst = 0;
65
66 if ((mode == LINK_FD_10M) || (mode == LINK_FD_100M) ||
67 (mode == LINK_FD_1000M) || (mode == LINK_FD_10000M)) {
68 bst |= PHY_REG_BCR_FD;
69 }
70
71 if ((mode == LINK_FD_100M) || (mode == LINK_HD_100M)) {
72 bst |= PHY_REG_BCR_100M;
73 }
74
77}
78
79/*---------------------------------------------------------------------------*/
80/** @brief Enable the autonegotiation
81 *
82 * Enable the autonegotiation of the link speed and duplex mode
83 *
84 * @param[in] phy uint8_t phy ID of the PHY
85 */
86void phy_autoneg_enable(uint8_t phy)
87{
89}
90
91/*---------------------------------------------------------------------------*/
92
93/**@}*/
uint16_t eth_smi_read(uint8_t phy, uint8_t reg)
Read the 16-bit register from the PHY.
void eth_smi_bit_set(uint8_t phy, uint8_t reg, uint16_t setbits)
Set bits in the register.
void eth_smi_bit_op(uint8_t phy, uint8_t reg, uint16_t bits, uint16_t mask)
Process the bit-operation on PHY register.
#define PHY_REG_BCR
Definition: phy.h:44
#define PHY_REG_BCR_100M
Definition: phy.h:64
#define PHY_REG_BCR_AN
Definition: phy.h:63
phy_status
Definition: phy.h:82
#define PHY_REG_BCR_ANRST
Definition: phy.h:60
#define PHY_REG_BCR_FD
Definition: phy.h:59
@ LINK_FD_10M
Definition: phy.h:88
@ LINK_HD_100M
Definition: phy.h:85
@ LINK_FD_1000M
Definition: phy.h:90
@ LINK_FD_10000M
Definition: phy.h:91
@ LINK_FD_100M
Definition: phy.h:89
void phy_autoneg_force(uint8_t phy, enum phy_status mode)
Force autonegotiation.
Definition: phy_ksz80x1.c:62
void phy_autoneg_enable(uint8_t phy)
Enable the autonegotiation.
Definition: phy_ksz80x1.c:86
enum phy_status phy_link_status(uint8_t phy)
Get the current link status.
Definition: phy_ksz80x1.c:49
#define KSZ80X1_CR1
Definition: phy_ksz80x1.h:90