Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
phy.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2021 IP-Logix Inc.
9 *
10 * SPDX-License-Identifier: Apache-2.0
11 */
12#ifndef ZEPHYR_INCLUDE_DRIVERS_PHY_H_
13#define ZEPHYR_INCLUDE_DRIVERS_PHY_H_
14
21#include <zephyr/types.h>
22#include <device.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
38};
39
40#define PHY_LINK_IS_FULL_DUPLEX(x) (x & (BIT(1) | BIT(3)))
41#define PHY_LINK_IS_SPEED_100M(x) (x & (BIT(2) | BIT(3)))
42
48 bool is_up;
49};
50
60typedef void (*phy_callback_t)(const struct device *dev,
61 struct phy_link_state *state,
62 void *user_data);
63
70__subsystem struct ethphy_driver_api {
72 int (*get_link)(const struct device *dev,
73 struct phy_link_state *state);
74
76 int (*cfg_link)(const struct device *dev,
77 enum phy_link_speed adv_speeds);
78
80 int (*link_cb_set)(const struct device *dev, phy_callback_t cb,
81 void *user_data);
82
84 int (*read)(const struct device *dev, uint16_t reg_addr,
85 uint32_t *data);
86
88 int (*write)(const struct device *dev, uint16_t reg_addr,
90};
107__syscall int phy_configure_link(const struct device *dev,
108 enum phy_link_speed speeds);
109
110static inline int z_impl_phy_configure_link(const struct device *dev,
111 enum phy_link_speed speeds)
112{
113 const struct ethphy_driver_api *api =
114 (const struct ethphy_driver_api *)dev->api;
115
116 return api->cfg_link(dev, speeds);
117}
118
132__syscall int phy_get_link_state(const struct device *dev,
133 struct phy_link_state *state);
134
135static inline int z_impl_phy_get_link_state(const struct device *dev,
136 struct phy_link_state *state)
137{
138 const struct ethphy_driver_api *api =
139 (const struct ethphy_driver_api *)dev->api;
140
141 return api->get_link(dev, state);
142}
143
158__syscall int phy_link_callback_set(const struct device *dev,
159 phy_callback_t callback,
160 void *user_data);
161
162static inline int z_impl_phy_link_callback_set(const struct device *dev,
163 phy_callback_t callback,
164 void *user_data)
165{
166 const struct ethphy_driver_api *api =
167 (const struct ethphy_driver_api *)dev->api;
168
169 return api->link_cb_set(dev, callback, user_data);
170}
171
184__syscall int phy_read(const struct device *dev, uint16_t reg_addr,
185 uint32_t *value);
186
187static inline int z_impl_phy_read(const struct device *dev, uint16_t reg_addr,
188 uint32_t *value)
189{
190 const struct ethphy_driver_api *api =
191 (const struct ethphy_driver_api *)dev->api;
192
193 return api->read(dev, reg_addr, value);
194}
195
208__syscall int phy_write(const struct device *dev, uint16_t reg_addr,
209 uint32_t value);
210
211static inline int z_impl_phy_write(const struct device *dev, uint16_t reg_addr,
212 uint32_t value)
213{
214 const struct ethphy_driver_api *api =
215 (const struct ethphy_driver_api *)dev->api;
216
217 return api->write(dev, reg_addr, value);
218}
219
220
221#ifdef __cplusplus
222}
223#endif
224
229#include <syscalls/phy.h>
230
231#endif /* ZEPHYR_INCLUDE_DRIVERS_PHY_H_ */
void
Definition: eswifi_shell.c:15
int phy_get_link_state(const struct device *dev, struct phy_link_state *state)
Get PHY link state.
int phy_read(const struct device *dev, uint16_t reg_addr, uint32_t *value)
Read PHY registers.
int phy_write(const struct device *dev, uint16_t reg_addr, uint32_t value)
Write PHY register.
int phy_configure_link(const struct device *dev, enum phy_link_speed speeds)
Configure PHY link.
phy_link_speed
Ethernet link speeds.
Definition: phy.h:29
void(* phy_callback_t)(const struct device *dev, struct phy_link_state *state, void *user_data)
Define the callback function signature for phy_link_callback_set() function.
Definition: phy.h:60
int phy_link_callback_set(const struct device *dev, phy_callback_t callback, void *user_data)
Set link state change callback.
@ LINK_HALF_100BASE_T
Definition: phy.h:35
@ LINK_HALF_10BASE_T
Definition: phy.h:31
@ LINK_FULL_10BASE_T
Definition: phy.h:33
@ LINK_FULL_100BASE_T
Definition: phy.h:37
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition: util_macro.h:44
state
Definition: http_parser_state.h:30
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
const void * api
Definition: device.h:373
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
static const intptr_t user_data[5]
Definition: main.c:590