1
2
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
34
35
36
37
42
43
44
45
46
47
48
49
50
51
55
56
57
58
59
64
65
71
72
77
78
82
83
88
89
100
101
106
110
111
118
127
128
137
138
142
...
#include "nx_stm32_phy_driver.h"
#include "nx_stm32_eth_config.h"
static int32_t lan8742_io_init(void);
static int32_t lan8742_io_deinit (void);
static int32_t lan8742_io_write_reg(uint32_t DevAddr, uint32_t RegAddr, uint32_t RegVal);
static int32_t lan8742_io_read_reg(uint32_t DevAddr, uint32_t RegAddr, uint32_t *pRegVal);
static int32_t lan8742_io_get_tick(void);
static lan8742_IOCtx_t LAN8742_IOCtx = { lan8742_io_init,
lan8742_io_deinit,
lan8742_io_write_reg,
lan8742_io_read_reg,
lan8742_io_get_tick
...};
static lan8742_Object_t LAN8742;
/* ... */
int32_t nx_eth_phy_init(void)
{
int32_t ret = ETH_PHY_STATUS_ERROR;
LAN8742_RegisterBusIO(&LAN8742, &LAN8742_IOCtx);
if (LAN8742_Init(&LAN8742) == LAN8742_STATUS_OK)
{
ret = ETH_PHY_STATUS_OK;
}if (LAN8742_Init(&LAN8742) == LAN8742_STATUS_OK) { ... }
return ret;
}{ ... }
/* ... */
int32_t nx_eth_phy_get_link_state(void)
{
int32_t linkstate = LAN8742_GetLinkState(&LAN8742);
return linkstate;
}{ ... }
/* ... */
nx_eth_phy_handle_t nx_eth_phy_get_handle(void)
{
return (nx_eth_phy_handle_t)&LAN8742;
}{ ... }
/* ... */
int32_t lan8742_io_init(void)
{
/* ... */
HAL_ETH_SetMDIOClockRange(ð_handle);
return ETH_PHY_STATUS_OK;
}{ ... }
/* ... */
int32_t lan8742_io_deinit (void)
{
return ETH_PHY_STATUS_OK;
}{ ... }
/* ... */
int32_t lan8742_io_read_reg(uint32_t DevAddr, uint32_t RegAddr, uint32_t *pRegVal)
{
if(HAL_ETH_ReadPHYRegister(ð_handle, DevAddr, RegAddr, pRegVal) != HAL_OK)
{
return ETH_PHY_STATUS_ERROR;
}if (HAL_ETH_ReadPHYRegister(ð_handle, DevAddr, RegAddr, pRegVal) != HAL_OK) { ... }
return ETH_PHY_STATUS_OK;
}{ ... }
int32_t lan8742_io_write_reg(uint32_t DevAddr, uint32_t RegAddr, uint32_t RegVal)
{
if(HAL_ETH_WritePHYRegister(ð_handle, DevAddr, RegAddr, RegVal) != HAL_OK)
{
return ETH_PHY_STATUS_ERROR;
}if (HAL_ETH_WritePHYRegister(ð_handle, DevAddr, RegAddr, RegVal) != HAL_OK) { ... }
return ETH_PHY_STATUS_OK;
}{ ... }
/* ... */
int32_t lan8742_io_get_tick(void)
{
return HAL_GetTick();
}{ ... }