phyHandling.h 5.0 KB

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