2 * FreeRTOS+TCP V2.0.11
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://aws.amazon.com/freertos
\r
23 * http://www.FreeRTOS.org
\r
27 * Handling of Ethernet PHY's
\r
28 * PHY's communicate with an EMAC either through
\r
29 * a Media-Independent Interface (MII), or a Reduced Media-Independent Interface (RMII).
\r
30 * The EMAC can poll for PHY ports on 32 different addresses. Each of the PHY ports
\r
31 * shall be treated independently.
\r
35 #ifndef PHYHANDLING_H
\r
37 #define PHYHANDLING_H
\r
44 #ifndef ipconfigPHY_MAX_PORTS
\r
45 /* There can be at most 32 PHY ports, but in most cases there are 4 or less. */
\r
46 #define ipconfigPHY_MAX_PORTS 4
\r
49 /* A generic user-provided function that reads from the PHY-port at 'xAddress'( 0-based ). A 16-bit value shall be stored in
\r
50 '*pusValue'. xRegister is the register number ( 0 .. 31 ). In fact all PHY registers are 16-bit.
\r
51 Return non-zero in case the action failed. */
\r
52 typedef BaseType_t ( *xApplicationPhyReadHook_t )( BaseType_t xAddress, BaseType_t xRegister, uint32_t *pulValue );
\r
54 /* A generic user-provided function that writes 'usValue' to the
\r
55 PHY-port at 'xAddress' ( 0-based ). xRegister is the register number ( 0 .. 31 ).
\r
56 Return non-zero in case the action failed. */
\r
57 typedef BaseType_t ( *xApplicationPhyWriteHook_t )( BaseType_t xAddress, BaseType_t xRegister, uint32_t ulValue );
\r
59 typedef struct xPhyProperties
\r
62 uint8_t ucMDI_X; /* MDI-X : Medium Dependent Interface - Crossover */
\r
67 typedef struct xEthernetPhy
\r
69 xApplicationPhyReadHook_t fnPhyRead;
\r
70 xApplicationPhyWriteHook_t fnPhyWrite;
\r
71 uint32_t ulPhyIDs[ ipconfigPHY_MAX_PORTS ];
\r
72 uint8_t ucPhyIndexes[ ipconfigPHY_MAX_PORTS ];
\r
73 TimeOut_t xLinkStatusTimer;
\r
74 TickType_t xLinkStatusRemaining;
\r
75 BaseType_t xPortCount;
\r
76 uint32_t ulBCRValue;
\r
77 uint32_t ulACRValue;
\r
78 uint32_t ulLinkStatusMask;
\r
79 PhyProperties_t xPhyPreferences;
\r
80 PhyProperties_t xPhyProperties;
\r
83 /* Some defines used internally here to indicate preferences about speed, MDIX
\r
84 (wired direct or crossed), and duplex (half or full). */
\r
86 /* Values for PhyProperties_t::ucSpeed : */
\r
87 #define PHY_SPEED_10 1
\r
88 #define PHY_SPEED_100 2
\r
89 #define PHY_SPEED_AUTO 3
\r
91 /* Values for PhyProperties_t::ucMDI_X : */
\r
92 #define PHY_MDIX_DIRECT 1
\r
93 #define PHY_MDIX_CROSSED 2
\r
94 #define PHY_MDIX_AUTO 3
\r
96 /* Values for PhyProperties_t::ucDuplex : */
\r
97 #define PHY_DUPLEX_HALF 1
\r
98 #define PHY_DUPLEX_FULL 2
\r
99 #define PHY_DUPLEX_AUTO 3
\r
101 /* ID's of supported PHY's : */
\r
102 #define PHY_ID_LAN8742A 0x0007c130
\r
103 #define PHY_ID_LAN8720 0x0007c0f0
\r
105 #define PHY_ID_KSZ8041 0x000010A1
\r
106 #define PHY_ID_KSZ8051 0x000010A1
\r
107 #define PHY_ID_KSZ8081 0x000010A1
\r
109 #define PHY_ID_KSZ8863 0x00221430
\r
110 #define PHY_ID_KSZ8081MNXIA 0x00221560
\r
112 #define PHY_ID_DP83848I 0x20005C90
\r
115 /* Initialise the struct and assign a PHY-read and -write function. */
\r
116 void vPhyInitialise( EthernetPhy_t *pxPhyObject, xApplicationPhyReadHook_t fnPhyRead, xApplicationPhyWriteHook_t fnPhyWrite );
\r
118 /* Discover all PHY's connected by polling 32 indexes ( zero-based ) */
\r
119 BaseType_t xPhyDiscover( EthernetPhy_t *pxPhyObject );
\r
121 /* Send a reset commando to the connected PHY ports and send configuration. */
\r
122 BaseType_t xPhyConfigure( EthernetPhy_t *pxPhyObject, const PhyProperties_t *pxPhyProperties );
\r
124 /* Give a commando to start auto negotiation on a set of PHY port's. */
\r
125 BaseType_t xPhyStartAutoNegotiation( EthernetPhy_t *pxPhyObject, uint32_t ulPhyMask );
\r
127 /* Do not use auto negotiation but use predefined values from 'pxPhyObject->xPhyPreferences'. */
\r
128 BaseType_t xPhyFixedValue( EthernetPhy_t *pxPhyObject, uint32_t ulPhyMask );
\r
130 /* Check the current Link Status.
\r
131 'xHadReception' : make this true if a packet has been received since the
\r
132 last call to this function. */
\r
133 BaseType_t xPhyCheckLinkStatus( EthernetPhy_t *pxPhyObject, BaseType_t xHadReception );
\r
135 static __inline uint32_t xPhyGetMask( EthernetPhy_t *pxPhyObject )
\r
137 return ( ( ( uint32_t ) 1u ) << pxPhyObject-> xPortCount ) - 1;
\r