]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/include/phyHandling.h
Sync FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP with the version in GitHub at (23665258ca...
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-TCP / portable / NetworkInterface / include / phyHandling.h
1 /*\r
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
7  * \r
8  */\r
9 \r
10 #ifndef PHYHANDLING_H\r
11 \r
12 #define PHYHANDLING_H\r
13 \r
14 #ifdef __cplusplus\r
15 extern "C" {\r
16 #endif\r
17 \r
18 \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
22 #endif\r
23 \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
28 \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
33 \r
34 typedef struct xPhyProperties\r
35 {\r
36         uint8_t ucSpeed;\r
37         uint8_t ucMDI_X;                /* MDI-X : Medium Dependent Interface - Crossover */\r
38         uint8_t ucDuplex;\r
39         uint8_t ucSpare;\r
40 } PhyProperties_t;\r
41 \r
42 typedef struct xEthernetPhy\r
43 {\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
56 } EthernetPhy_t;\r
57 \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
60 \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
65 \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
70 \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
75 \r
76 /* ID's of supported PHY's : */\r
77 #define PHY_ID_LAN8742A         0x0007c130\r
78 #define PHY_ID_LAN8720          0x0007c0f0\r
79 \r
80 #define PHY_ID_KSZ8041          0x000010A1\r
81 #define PHY_ID_KSZ8051          0x000010A1\r
82 #define PHY_ID_KSZ8081          0x000010A1\r
83 \r
84 #define PHY_ID_KSZ8863          0x00221430\r
85 #define PHY_ID_KSZ8081MNXIA 0x00221560\r
86 \r
87 #define PHY_ID_DP83848I         0x20005C90\r
88 \r
89 \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
92 \r
93 /* Discover all PHY's connected by polling 32 indexes ( zero-based ) */\r
94 BaseType_t xPhyDiscover( EthernetPhy_t *pxPhyObject );\r
95 \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
98 \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
101 \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
104 \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
109 \r
110 /* Get the bitmask of a given 'EthernetPhy_t'. */\r
111 #define xPhyGetMask( pxPhyObject ) \\r
112         ( ( ( ( uint32_t ) 1u ) << ( pxPhyObject )->xPortCount ) - 1u )\r
113 \r
114 #ifdef __cplusplus\r
115 } /* extern "C" */\r
116 #endif\r
117 \r
118 #endif\r