Skip to content

Commit 33cff99

Browse files
Update ETH driver validation for RMII interface (#10)
1 parent b99c0e1 commit 33cff99

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

Source/DV_ETH.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,36 @@ static int32_t ETH_RunTransfer (const uint8_t *out, uint8_t *in, uint32_t len, u
111111
return ARM_DRIVER_ERROR;
112112
}
113113

114+
// Initialize MAC driver wrapper for RMII interface
115+
static int32_t mac_initialize (ARM_ETH_MAC_SignalEvent_t cb_event) {
116+
ARM_DRIVER_ETH_MAC *drv_mac = &CREATE_SYMBOL(Driver_ETH_MAC, DRV_ETH);
117+
118+
phy_power = 1U;
119+
return drv_mac->Initialize(cb_event);
120+
}
121+
122+
// Uninitialize MAC driver wrapper for RMII interface
123+
static int32_t mac_uninitialize (void) {
124+
ARM_DRIVER_ETH_MAC *drv_mac = &CREATE_SYMBOL(Driver_ETH_MAC, DRV_ETH);
125+
126+
phy_power = 0U;
127+
return drv_mac->Uninitialize();
128+
}
129+
114130
// MAC driver power control wrapper for RMII interface
115131
static int32_t mac_power_control (ARM_POWER_STATE state) {
116132
ARM_DRIVER_ETH_MAC *drv_mac = &CREATE_SYMBOL(Driver_ETH_MAC, DRV_ETH);
117133
ARM_DRIVER_ETH_PHY *drv_phy = &CREATE_SYMBOL(Driver_ETH_PHY, DRV_ETH);
118134
int32_t retv;
119135

120136
retv = drv_mac->PowerControl(state);
121-
if ((state == ARM_POWER_FULL) && (retv == ARM_DRIVER_ERROR) && (phy_power == 0U)) {
137+
if ((state == ARM_POWER_FULL) && (retv == ARM_DRIVER_ERROR) && (phy_power == 1U)) {
122138
/* RMII solution when the PHY is a 50 MHz reference clock source */
123139
/* MAC never exits soft reset when PHY is powered down (no 50 MHz) */
124140
/* So turn on the power for the PHY here to prevent deadlock */
125141
drv_phy->Initialize(drv_mac->PHY_Read, drv_mac->PHY_Write);
126142
if (drv_phy->PowerControl(ARM_POWER_FULL) == ARM_DRIVER_OK) {
127-
phy_power = 1U;
143+
phy_power = 2U;
128144
osDelay (10);
129145
retv = drv_mac->PowerControl(state);
130146
if (retv == ARM_DRIVER_OK) {
@@ -142,8 +158,8 @@ static int32_t phy_power_control (ARM_POWER_STATE state) {
142158
int32_t retv;
143159

144160
retv = drv_phy->PowerControl(state);
145-
if ((state == ARM_POWER_OFF) && (retv == ARM_DRIVER_OK)) {
146-
phy_power = 0U;
161+
if ((state == ARM_POWER_OFF) && (retv == ARM_DRIVER_OK) && (phy_power == 2U)) {
162+
phy_power = 1U;
147163
}
148164
return (retv);
149165
}
@@ -160,11 +176,13 @@ void ETH_DV_Initialize (void) {
160176
memcpy(&s_mac, eth_mac, sizeof(s_mac));
161177
memcpy(&s_phy, eth_phy, sizeof(s_phy));
162178
/* Use wrapper functions in RMII interface mode */
179+
s_mac.Initialize = &mac_initialize;
180+
s_mac.Uninitialize = &mac_uninitialize;
163181
s_mac.PowerControl = &mac_power_control;
164182
s_phy.PowerControl = &phy_power_control;
165183
eth_mac = &s_mac;
166184
eth_phy = &s_phy;
167-
phy_power = 1U;
185+
phy_power = 0U;
168186
mac_lockup = 0U;
169187
}
170188
cb_event = (capab.event_rx_frame) ? ETH_DrvEvent : NULL;

0 commit comments

Comments
 (0)