2 * Handling of Ethernet PHY's
\r
3 * PHY's communicate with an EMAC either through
\r
4 * a Media-Independent Interface (MII), or a Reduced Media-Independent Interface (RMII).
\r
5 * The EMAC can poll for PHY ports on 32 different addresses. Each of the PHY ports
\r
6 * shall be treated independently.
\r
10 #ifndef PHYHANDLING_H
\r
12 #define PHYHANDLING_H
\r
19 #ifndef ipconfigPHY_MAX_PORTS
\r
20 /* There can be at most 32 PHY ports, but in most cases there are 4 or less. */
\r
21 #define ipconfigPHY_MAX_PORTS 4
\r
24 /* A generic user-provided function that reads from the PHY-port at 'xAddress'( 0-based ). A 16-bit value shall be stored in
\r
25 '*pulValue'. xRegister is the register number ( 0 .. 31 ). In fact all PHY registers are 16-bit.
\r
26 Return non-zero in case the action failed. */
\r
27 typedef BaseType_t ( *xApplicationPhyReadHook_t )( BaseType_t xAddress, BaseType_t xRegister, uint32_t *pulValue );
\r
29 /* A generic user-provided function that writes 'ulValue' to the
\r
30 PHY-port at 'xAddress' ( 0-based ). xRegister is the register number ( 0 .. 31 ).
\r
31 Return non-zero in case the action failed. */
\r
32 typedef BaseType_t ( *xApplicationPhyWriteHook_t )( BaseType_t xAddress, BaseType_t xRegister, uint32_t ulValue );
\r
34 typedef struct xPhyProperties
\r
37 uint8_t ucMDI_X; /* MDI-X : Medium Dependent Interface - Crossover */
\r
42 typedef struct xEthernetPhy
\r
44 xApplicationPhyReadHook_t fnPhyRead;
\r
45 xApplicationPhyWriteHook_t fnPhyWrite;
\r
46 uint32_t ulPhyIDs[ ipconfigPHY_MAX_PORTS ];
\r
47 uint8_t ucPhyIndexes[ ipconfigPHY_MAX_PORTS ];
\r
48 TimeOut_t xLinkStatusTimer;
\r
49 TickType_t xLinkStatusRemaining;
\r
50 BaseType_t xPortCount;
\r
51 uint32_t ulBCRValue;
\r
52 uint32_t ulACRValue;
\r
53 uint32_t ulLinkStatusMask;
\r
54 PhyProperties_t xPhyPreferences;
\r
55 PhyProperties_t xPhyProperties;
\r
58 /* Some defines used internally here to indicate preferences about speed, MDIX
\r
59 (wired direct or crossed), and duplex (half or full). */
\r
61 /* Values for PhyProperties_t::ucSpeed : */
\r
62 #define PHY_SPEED_10 1
\r
63 #define PHY_SPEED_100 2
\r
64 #define PHY_SPEED_AUTO 3
\r
66 /* Values for PhyProperties_t::ucMDI_X : */
\r
67 #define PHY_MDIX_DIRECT 1
\r
68 #define PHY_MDIX_CROSSED 2
\r
69 #define PHY_MDIX_AUTO 3
\r
71 /* Values for PhyProperties_t::ucDuplex : */
\r
72 #define PHY_DUPLEX_HALF 1
\r
73 #define PHY_DUPLEX_FULL 2
\r
74 #define PHY_DUPLEX_AUTO 3
\r
76 /* ID's of supported PHY's : */
\r
77 #define PHY_ID_LAN8742A 0x0007c130
\r
78 #define PHY_ID_LAN8720 0x0007c0f0
\r
80 #define PHY_ID_KSZ8041 0x000010A1
\r
81 #define PHY_ID_KSZ8051 0x000010A1
\r
82 #define PHY_ID_KSZ8081 0x000010A1
\r
84 #define PHY_ID_KSZ8863 0x00221430
\r
85 #define PHY_ID_KSZ8081MNXIA 0x00221560
\r
87 #define PHY_ID_DP83848I 0x20005C90
\r
90 /* Initialise the struct and assign a PHY-read and -write function. */
\r
91 void vPhyInitialise( EthernetPhy_t *pxPhyObject, xApplicationPhyReadHook_t fnPhyRead, xApplicationPhyWriteHook_t fnPhyWrite );
\r
93 /* Discover all PHY's connected by polling 32 indexes ( zero-based ) */
\r
94 BaseType_t xPhyDiscover( EthernetPhy_t *pxPhyObject );
\r
96 /* Send a reset command to the connected PHY ports and send configuration. */
\r
97 BaseType_t xPhyConfigure( EthernetPhy_t *pxPhyObject, const PhyProperties_t *pxPhyProperties );
\r
99 /* Give a command to start auto negotiation on a set of PHY port's. */
\r
100 BaseType_t xPhyStartAutoNegotiation( EthernetPhy_t *pxPhyObject, uint32_t ulPhyMask );
\r
102 /* Do not use auto negotiation but use predefined values from 'pxPhyObject->xPhyPreferences'. */
\r
103 BaseType_t xPhyFixedValue( EthernetPhy_t *pxPhyObject, uint32_t ulPhyMask );
\r
105 /* Check the current Link Status.
\r
106 'xHadReception' : make this true if a packet has been received since the
\r
107 last call to this function. */
\r
108 BaseType_t xPhyCheckLinkStatus( EthernetPhy_t *pxPhyObject, BaseType_t xHadReception );
\r
110 /* Get the bitmask of a given 'EthernetPhy_t'. */
\r
111 #define xPhyGetMask( pxPhyObject ) \
\r
112 ( ( ( ( uint32_t ) 1u ) << ( pxPhyObject )->xPortCount ) - 1u )
\r