iLLD_TC27xD  1.0
IfxEth_Phy_Pef7071.c
Go to the documentation of this file.
1 /**
2  * \file IfxEth_Phy_Pef7071.c
3  * \brief ETH PHY_PEF7071 details
4  *
5  * \version iLLD_1_0_0_11_0
6  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
7  *
8  *
9  * IMPORTANT NOTICE
10  *
11  *
12  * Infineon Technologies AG (Infineon) is supplying this file for use
13  * exclusively with Infineon's microcontroller products. This file can be freely
14  * distributed within development tools that are supporting such microcontroller
15  * products.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
18  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
20  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
21  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
22  *
23  */
24 
25 /******************************************************************************/
26 /*----------------------------------Includes----------------------------------*/
27 /******************************************************************************/
28 
29 #include "IfxEth_Phy_Pef7071.h"
30 
31 /******************************************************************************/
32 /*----------------------------------Macros------------------------------------*/
33 /******************************************************************************/
34 
35 #define IFXETH_PHY_PEF7071_MDIO_CTRL 0x00
36 
37 #define IFXETH_PHY_PEF7071_MDIO_STAT 0x01
38 
39 #define IFXETH_PHY_PEF7071_MDIO_PHYID1 0x02
40 
41 #define IFXETH_PHY_PEF7071_MDIO_PHYID2 0x03
42 
43 #define IFXETH_PHY_PEF7071_MDIO_AN_ADV 0x04
44 
45 #define IFXETH_PHY_PEF7071_MDIO_AN_LPA 0x05
46 
47 #define IFXETH_PHY_PEF7071_MDIO_AN_EXP 0x06
48 
49 #define IFXETH_PHY_PEF7071_MDIO_AN_NPTX 0x07
50 
51 #define IFXETH_PHY_PEF7071_MDIO_AN_NPRX 0x08
52 
53 #define IFXETH_PHY_PEF7071_MDIO_GCTRL 0x09
54 
55 #define IFXETH_PHY_PEF7071_MDIO_GSTAT 0x0A
56 
57 #define IFXETH_PHY_PEF7071_MDIO_RES11 0x0B
58 
59 #define IFXETH_PHY_PEF7071_MDIO_RES12 0x0C
60 
61 #define IFXETH_PHY_PEF7071_MDIO_MMDCTRL 0x0D
62 
63 #define IFXETH_PHY_PEF7071_MDIO_MMDDATA 0x0E
64 
65 #define IFXETH_PHY_PEF7071_MDIO_XSTAT 0x0F
66 
67 #define IFXETH_PHY_PEF7071_MDIO_PHYPERF 0x10
68 
69 #define IFXETH_PHY_PEF7071_MDIO_PHYSTAT1 0x11
70 
71 #define IFXETH_PHY_PEF7071_MDIO_PHYSTAT2 0x12
72 
73 #define IFXETH_PHY_PEF7071_MDIO_PHYCTL1 0x13
74 
75 #define IFXETH_PHY_PEF7071_MDIO_PHYCTL2 0x14
76 
77 #define IFXETH_PHY_PEF7071_MDIO_ERRCNT 0x15
78 
79 #define IFXETH_PHY_PEF7071_MDIO_EECTRL 0x16
80 
81 #define IFXETH_PHY_PEF7071_MDIO_MIICTRL 0x17
82 
83 #define IFXETH_PHY_PEF7071_MDIO_MIISTAT 0x18
84 
85 #define IFXETH_PHY_PEF7071_MDIO_IMASK 0x19
86 
87 #define IFXETH_PHY_PEF7071_MDIO_ISTAT 0x1A
88 
89 #define IFXETH_PHY_PEF7071_MDIO_LED 0x1B
90 
91 #define IFXETH_PHY_PEF7071_MDIO_TPGCTRL 0x1C
92 
93 #define IFXETH_PHY_PEF7071_MDIO_TPGDATA 0x1D
94 
95 #define IFXETH_PHY_PEF7071_MDIO_FWV 0x1E
96 
97 #define IFXETH_PHY_PEF7071_MDIO_RES1F 0x1F
98 
99 #define IFXETH_PHY_PEF7071_WAIT_GMII_READY() while (ETH_GMII_ADDRESS.B.GB) {}
100 
101 /******************************************************************************/
102 /*-----------------------Exported Variables/Constants-------------------------*/
103 /******************************************************************************/
104 
106 
107 /******************************************************************************/
108 /*-------------------------Function Implementations---------------------------*/
109 /******************************************************************************/
110 
112 {
114 
115  /* // read once all PHY registers
116  * int i;
117  * for(i = 0; i < 31; i++)
118  * {
119  * uint32 value;
120  * read_mdio_reg(0, i, &value);
121  * } */
122 
123  // reset PHY
125  uint32 value;
126 
127  do
128  {
130  } while (value & 0x8000); // wait for reset to finish
131 
132  // setup PHY
133  IfxEth_Phy_Pef7071_write_mdio_reg(0, IFXETH_PHY_PEF7071_MDIO_MIICTRL, 0xF702); // skew adaptation is needed, RMII mode (10/100MBit)
134  IfxEth_Phy_Pef7071_write_mdio_reg(0, IFXETH_PHY_PEF7071_MDIO_GCTRL, 0x0000); // advertise no 1000BASE-T (full/half duplex)
135  IfxEth_Phy_Pef7071_write_mdio_reg(0, IFXETH_PHY_PEF7071_MDIO_AN_ADV, 0x0101); // advertise 100BASE-TX full duplex only
136  IfxEth_Phy_Pef7071_write_mdio_reg(0, IFXETH_PHY_PEF7071_MDIO_CTRL, 0x1200); // enable auto-negotiation, restart auto-negotiation
137 
138  // we set our loop mode (RJ45) in side the PHY (PHYCTL1 register) if we will have a loop
139  // if (CONFIG_ETH._loop)
140  // write_mdio_reg (0, 0x13, (0x4 << 13) | 0x1);
141 
142  // done
144 
145  return 1;
146 }
147 
148 
150 {
151  boolean linkEstablished = FALSE;
152 
154  {
155  uint32 value;
157  linkEstablished = ((value & (1 << 2)) != 0) ? TRUE : FALSE;
158  }
159 
160  return linkEstablished;
161 }
162 
163 
164 void IfxEth_Phy_Pef7071_read_mdio_reg(uint32 layeraddr, uint32 regaddr, uint32 *pdata)
165 {
166  // 5bit Physical Layer Adddress, 5bit GMII Regnr, 4bit csrclock divider, Read, Busy
167  ETH_GMII_ADDRESS.U = (layeraddr << 11) | (regaddr << 6) | (0 << 2) | (0 << 1) | (1 << 0);
168 
170 
171  // get data
172  *pdata = ETH_GMII_DATA.U;
173 }
174 
175 
177 {
178  // put data
179  ETH_GMII_DATA.U = data;
180 
181  // 5bit Physical Layer Adddress, 5bit GMII Regnr, 4bit csrclock divider, Write, Busy
182  ETH_GMII_ADDRESS.U = (layeraddr << 11) | (regaddr << 6) | (0 << 2) | (1 << 1) | (1 << 0);
183 
185 }