26#ifndef CAFFEINE_HAL_HAL_ETH_H
27#define CAFFEINE_HAL_HAL_ETH_H
45#define CFN_HAL_ETH_PHY_REG_BMCR 0x00U
46#define CFN_HAL_ETH_PHY_REG_BSR 0x01U
47#define CFN_HAL_ETH_PHY_REG_ID1 0x02U
48#define CFN_HAL_ETH_PHY_REG_ID2 0x03U
49#define CFN_HAL_ETH_PHY_REG_ANAR 0x04U
50#define CFN_HAL_ETH_PHY_REG_ANLPAR 0x05U
51#define CFN_HAL_ETH_PHY_REG_ANER 0x06U
56#define CFN_HAL_ETH_PHY_BMCR_RESET CFN_HAL_BIT(15)
57#define CFN_HAL_ETH_PHY_BMCR_LOOPBACK CFN_HAL_BIT(14)
58#define CFN_HAL_ETH_PHY_BMCR_SPEED_100 CFN_HAL_BIT(13)
59#define CFN_HAL_ETH_PHY_BMCR_AUTONEG CFN_HAL_BIT(12)
60#define CFN_HAL_ETH_PHY_BMCR_POWERDOWN CFN_HAL_BIT(11)
61#define CFN_HAL_ETH_PHY_BMCR_ISOLATE CFN_HAL_BIT(10)
62#define CFN_HAL_ETH_PHY_BMCR_RESTART CFN_HAL_BIT(9)
63#define CFN_HAL_ETH_PHY_BMCR_DUPLEX CFN_HAL_BIT(8)
68#define CFN_HAL_ETH_PHY_BSR_100BASET4 CFN_HAL_BIT(15)
69#define CFN_HAL_ETH_PHY_BSR_100BASEXFD CFN_HAL_BIT(14)
70#define CFN_HAL_ETH_PHY_BSR_100BASEXHD CFN_HAL_BIT(13)
71#define CFN_HAL_ETH_PHY_BSR_10BASETFD CFN_HAL_BIT(12)
72#define CFN_HAL_ETH_PHY_BSR_10BASETHD CFN_HAL_BIT(11)
73#define CFN_HAL_ETH_PHY_BSR_AUTONEGCMP CFN_HAL_BIT(5)
74#define CFN_HAL_ETH_PHY_BSR_REMOTEFLT CFN_HAL_BIT(4)
75#define CFN_HAL_ETH_PHY_BSR_AUTONEGABL CFN_HAL_BIT(3)
76#define CFN_HAL_ETH_PHY_BSR_LINKSTAT CFN_HAL_BIT(2)
77#define CFN_HAL_ETH_PHY_BSR_JABBERDET CFN_HAL_BIT(1)
78#define CFN_HAL_ETH_PHY_BSR_EXTENDED CFN_HAL_BIT(0)
83#define CFN_HAL_ETH_PHY_ANAR_NEXT_PAGE CFN_HAL_BIT(15)
84#define CFN_HAL_ETH_PHY_ANAR_REM_FAULT CFN_HAL_BIT(13)
85#define CFN_HAL_ETH_PHY_ANAR_PAUSE CFN_HAL_BIT(10)
86#define CFN_HAL_ETH_PHY_ANAR_100T4 CFN_HAL_BIT(9)
87#define CFN_HAL_ETH_PHY_ANAR_100FD CFN_HAL_BIT(8)
88#define CFN_HAL_ETH_PHY_ANAR_100HD CFN_HAL_BIT(7)
89#define CFN_HAL_ETH_PHY_ANAR_10FD CFN_HAL_BIT(6)
90#define CFN_HAL_ETH_PHY_ANAR_10HD CFN_HAL_BIT(5)
91#define CFN_HAL_ETH_PHY_ANAR_SELECTOR 0x001FU
200 const uint8_t *frame,
204 cfn_hal_eth_t *driver, uint8_t *buffer,
size_t max_length,
size_t *received_length, uint32_t timeout);
206 cfn_hal_eth_t *driver, uint16_t phy_addr, uint16_t reg_addr, uint16_t *value, uint32_t timeout);
208 cfn_hal_eth_t *driver, uint16_t phy_addr, uint16_t reg_addr, uint16_t value, uint32_t timeout);
217 uint32_t peripheral_id,
218 struct cfn_hal_clock_s *clock,
239 if (driver == NULL || config == NULL)
304 driver->config = config;
317 if (!driver || !config || !driver->config)
321 *config = *(driver->config);
341 driver->cb = callback;
342 driver->cb_user_arg = user_arg;
488 const uint8_t *frame,
508 cfn_hal_eth_t *driver, uint8_t *buffer,
size_t max_length,
size_t *received_length, uint32_t timeout)
570 struct cfn_hal_clock_s *clock,
Core Hardware Abstraction Layer definitions and macros.
#define CFN_HAL_CHECK_AND_CALL_FUNC_VARG(expected_peripheral_type, func, driver, result,...)
Definition cfn_hal.h:134
#define CFN_HAL_CHECK_AND_CALL_FUNC(expected_peripheral_type, func, driver, result)
Definition cfn_hal.h:114
#define CFN_HAL_INLINE
Macro for inlining HAL wrapper functions. Can be overridden with attribute((always_inline)) for perfo...
Definition cfn_hal.h:61
#define CFN_HAL_BIT(x)
Definition cfn_hal.h:79
#define CFN_HAL_CREATE_DRIVER_TYPE(prefix, config_type, api_type, phy_type, cb_type)
Definition cfn_hal.h:102
Base driver Hardware Abstraction Layer declarations.
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_error_disable(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t error_mask)
Generic error disable for any driver. Deactivates exception-flow hardware triggers based on the provi...
Definition cfn_hal_base_impl.h:436
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_callback_register(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, cfn_hal_callback_t callback, void *user_arg)
Generic callback registration for any driver.
Definition cfn_hal_base_impl.h:254
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_error_enable(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t error_mask)
Generic error enable for any driver. Activates exception-flow hardware triggers based on the provided...
Definition cfn_hal_base_impl.h:411
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_event_enable(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t event_mask)
Generic event enable for any driver. Activates nominal hardware triggers based on the provided mask.
Definition cfn_hal_base_impl.h:331
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_event_get(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t *event_mask)
Generic event status getter for any driver. Retrieves the current nominal hardware triggers/flags.
Definition cfn_hal_base_impl.h:386
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_error_get(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t *error_mask)
Generic error status getter for any driver. Retrieves current exception-flow hardware flags/errors.
Definition cfn_hal_base_impl.h:461
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_config_set(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, const void *config)
Generic configuration setter for any driver.
Definition cfn_hal_base_impl.h:196
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_power_state_set(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, cfn_hal_power_state_t state)
Generic power state transition for any driver.
Definition cfn_hal_base_impl.h:279
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_deinit(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type)
Generic deinitialization for any driver. Returns the driver to the CONSTRUCTED state and releases boa...
Definition cfn_hal_base_impl.h:144
#define CFN_HAL_VMT_CHECK(api_struct_type)
Compile-time check to ensure a peripheral API struct is compatible with the base layer....
Definition cfn_hal_base.h:91
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_init(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type)
Generic initialization for any driver. Handles board-level hooks, type validation,...
Definition cfn_hal_base_impl.h:85
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_config_validate(const cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, const void *config)
Generic validation for a configuration.
Definition cfn_hal_base_impl.h:234
CFN_HAL_BASE_API cfn_hal_error_code_t cfn_hal_base_event_disable(cfn_hal_driver_t *base, cfn_hal_peripheral_type_t expected_type, uint32_t event_mask)
Generic event disable for any driver. Deactivates nominal hardware triggers based on the provided mas...
Definition cfn_hal_base_impl.h:361
#define CFN_HAL_POPULATE_DRIVER( driver_ptr, periph_type, periph_id, clock_ptr, dep_ptr, api_ptr, phy_ptr, cfg_ptr, cb_func, cb_arg)
Standardizes the population of a peripheral driver structure. This macro ensures that the base driver...
Definition cfn_hal_base_impl.h:45
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_config_set(cfn_hal_eth_t *driver, const cfn_hal_eth_config_t *config)
Sets the Ethernet configuration.
Definition cfn_hal_eth.h:292
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_receive_frame(cfn_hal_eth_t *driver, uint8_t *buffer, size_t max_length, size_t *received_length, uint32_t timeout)
Receives an Ethernet frame.
Definition cfn_hal_eth.h:507
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_error_enable(cfn_hal_eth_t *driver, uint32_t error_mask)
Enables one or more Ethernet exception errors.
Definition cfn_hal_eth.h:414
struct cfn_hal_eth_s cfn_hal_eth_t
Definition cfn_hal_eth.h:177
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_event_disable(cfn_hal_eth_t *driver, uint32_t event_mask)
Disables one or more Ethernet nominal events.
Definition cfn_hal_eth.h:384
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_start(cfn_hal_eth_t *driver)
Starts the Ethernet MAC and DMA operations.
Definition cfn_hal_eth.h:460
cfn_hal_eth_link_duplex_t
Ethernet link duplex mode.
Definition cfn_hal_eth.h:132
@ CFN_HAL_ETH_LINK_DUPLEX_HALF
Definition cfn_hal_eth.h:133
@ CFN_HAL_ETH_LINK_DUPLEX_FULL
Definition cfn_hal_eth.h:134
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_config_validate(const cfn_hal_eth_t *driver, const cfn_hal_eth_config_t *config)
Validates the Ethernet configuration.
Definition cfn_hal_eth.h:236
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_stop(cfn_hal_eth_t *driver)
Stops the Ethernet MAC and DMA operations.
Definition cfn_hal_eth.h:472
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_error_disable(cfn_hal_eth_t *driver, uint32_t error_mask)
Disables one or more Ethernet exception errors.
Definition cfn_hal_eth.h:429
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_event_get(cfn_hal_eth_t *driver, uint32_t *event_mask)
Retrieves the current Ethernet nominal event status.
Definition cfn_hal_eth.h:399
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_write_phy_reg(cfn_hal_eth_t *driver, uint16_t phy_addr, uint16_t reg_addr, uint16_t value, uint32_t timeout)
Writes a PHY register via MDIO.
Definition cfn_hal_eth.h:544
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_event_enable(cfn_hal_eth_t *driver, uint32_t event_mask)
Enables one or more Ethernet nominal events.
Definition cfn_hal_eth.h:369
cfn_hal_eth_link_speed_t
Ethernet link speed.
Definition cfn_hal_eth.h:122
@ CFN_HAL_ETH_LINK_SPEED_10M
Definition cfn_hal_eth.h:123
@ CFN_HAL_ETH_LINK_SPEED_1000M
Definition cfn_hal_eth.h:125
@ CFN_HAL_ETH_LINK_SPEED_100M
Definition cfn_hal_eth.h:124
cfn_hal_eth_error_t
Ethernet exception error flags.
Definition cfn_hal_eth.h:111
@ CFN_HAL_ETH_ERROR_GENERAL
Definition cfn_hal_eth.h:115
@ CFN_HAL_ETH_ERROR_PHY
Definition cfn_hal_eth.h:114
@ CFN_HAL_ETH_ERROR_MAC
Definition cfn_hal_eth.h:113
@ CFN_HAL_ETH_ERROR_NONE
Definition cfn_hal_eth.h:112
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_error_get(cfn_hal_eth_t *driver, uint32_t *error_mask)
Retrieves the current Ethernet exception error status.
Definition cfn_hal_eth.h:444
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_config_get(cfn_hal_eth_t *driver, cfn_hal_eth_config_t *config)
Gets the current Ethernet configuration.
Definition cfn_hal_eth.h:315
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_transmit_frame(cfn_hal_eth_t *driver, const uint8_t *frame, size_t length, uint32_t timeout)
Transmits an Ethernet frame.
Definition cfn_hal_eth.h:487
cfn_hal_error_code_t cfn_hal_eth_construct(cfn_hal_eth_t *driver, const cfn_hal_eth_config_t *config, const cfn_hal_eth_phy_t *phy, struct cfn_hal_clock_s *clock, void *dependency, cfn_hal_eth_callback_t callback, void *user_arg)
Definition cfn_hal_eth_port.c:142
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_power_state_set(cfn_hal_eth_t *driver, cfn_hal_power_state_t state)
Sets the Ethernet power state.
Definition cfn_hal_eth.h:354
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_deinit(cfn_hal_eth_t *driver)
Deinitializes the Ethernet driver.
Definition cfn_hal_eth.h:277
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_get_link_status(cfn_hal_eth_t *driver, cfn_hal_eth_link_status_t *status, uint32_t timeout)
Retrieves the current link status.
Definition cfn_hal_eth.h:559
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_read_phy_reg(cfn_hal_eth_t *driver, uint16_t phy_addr, uint16_t reg_addr, uint16_t *value, uint32_t timeout)
Reads a PHY register via MDIO.
Definition cfn_hal_eth.h:526
CFN_HAL_INLINE void cfn_hal_eth_populate(cfn_hal_eth_t *driver, uint32_t peripheral_id, struct cfn_hal_clock_s *clock, void *dependency, const cfn_hal_eth_api_t *api, const cfn_hal_eth_phy_t *phy, const cfn_hal_eth_config_t *config, cfn_hal_eth_callback_t callback, void *user_arg)
Definition cfn_hal_eth.h:216
cfn_hal_eth_event_t
Ethernet nominal event flags.
Definition cfn_hal_eth.h:99
@ CFN_HAL_ETH_EVENT_NONE
Definition cfn_hal_eth.h:100
@ CFN_HAL_ETH_EVENT_LINK_UP
Definition cfn_hal_eth.h:103
@ CFN_HAL_ETH_EVENT_RX_COMPLETE
Definition cfn_hal_eth.h:101
@ CFN_HAL_ETH_EVENT_LINK_DOWN
Definition cfn_hal_eth.h:104
@ CFN_HAL_ETH_EVENT_TX_COMPLETE
Definition cfn_hal_eth.h:102
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_init(cfn_hal_eth_t *driver)
Initializes the Ethernet driver.
Definition cfn_hal_eth.h:257
cfn_hal_error_code_t cfn_hal_eth_destruct(cfn_hal_eth_t *driver)
Definition cfn_hal_eth_port.c:158
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_callback_register(cfn_hal_eth_t *driver, const cfn_hal_eth_callback_t callback, void *user_arg)
Registers a callback for Ethernet events and errors.
Definition cfn_hal_eth.h:332
void(* cfn_hal_eth_callback_t)(cfn_hal_eth_t *driver, uint32_t event_mask, uint32_t error_mask, void *user_arg)
Ethernet callback signature.
Definition cfn_hal_eth.h:187
General Purpose Input/Output (GPIO) HAL API.
Common type definitions and enums for the HAL.
void(* cfn_hal_callback_t)(void)
Generic function pointer for HAL callbacks. Used as a standard-compliant carrier in the base layer.
Definition cfn_hal_types.h:98
enum cfn_hal_error_codes cfn_hal_error_code_t
cfn_hal_power_state_t
Definition cfn_hal_types.h:156
@ CFN_HAL_ERROR_OK
Definition cfn_hal_types.h:50
@ CFN_HAL_ERROR_BAD_PARAM
Definition cfn_hal_types.h:53
@ CFN_HAL_ERROR_BAD_CONFIG
Definition cfn_hal_types.h:60
#define CFN_HAL_PERIPHERAL_TYPE_ETH
Definition cfn_hal_types.h:140
Base API structure for all peripheral drivers. Every peripheral-specific API struct MUST have this as...
Definition cfn_hal_base.h:63
Ethernet Virtual Method Table (VMT).
Definition cfn_hal_eth.h:193
cfn_hal_error_code_t(* receive_frame)(cfn_hal_eth_t *driver, uint8_t *buffer, size_t max_length, size_t *received_length, uint32_t timeout)
Definition cfn_hal_eth.h:203
cfn_hal_error_code_t(* read_phy_reg)(cfn_hal_eth_t *driver, uint16_t phy_addr, uint16_t reg_addr, uint16_t *value, uint32_t timeout)
Definition cfn_hal_eth.h:205
cfn_hal_error_code_t(* stop)(cfn_hal_eth_t *driver)
Definition cfn_hal_eth.h:198
cfn_hal_api_base_t base
Definition cfn_hal_eth.h:194
cfn_hal_error_code_t(* write_phy_reg)(cfn_hal_eth_t *driver, uint16_t phy_addr, uint16_t reg_addr, uint16_t value, uint32_t timeout)
Definition cfn_hal_eth.h:207
cfn_hal_error_code_t(* transmit_frame)(cfn_hal_eth_t *driver, const uint8_t *frame, size_t length, uint32_t timeout)
Definition cfn_hal_eth.h:199
cfn_hal_error_code_t(* get_link_status)(cfn_hal_eth_t *driver, cfn_hal_eth_link_status_t *status, uint32_t timeout)
Definition cfn_hal_eth.h:209
cfn_hal_error_code_t(* start)(cfn_hal_eth_t *driver)
Definition cfn_hal_eth.h:197
Ethernet configuration structure.
Definition cfn_hal_eth.h:153
uint16_t phy_addr
Definition cfn_hal_eth.h:155
void * user_config
Definition cfn_hal_eth.h:156
Ethernet link status information.
Definition cfn_hal_eth.h:143
bool is_up
Definition cfn_hal_eth.h:144
cfn_hal_eth_link_duplex_t duplex
Definition cfn_hal_eth.h:146
cfn_hal_eth_link_speed_t speed
Definition cfn_hal_eth.h:145
Ethernet hardware physical mapping.
Definition cfn_hal_eth.h:163
void * instance
Definition cfn_hal_eth.h:164
cfn_hal_gpio_pin_handle_t * ref_clk
Definition cfn_hal_eth.h:165
cfn_hal_gpio_pin_handle_t * txd1
Definition cfn_hal_eth.h:173
cfn_hal_gpio_pin_handle_t * tx_en
Definition cfn_hal_eth.h:171
cfn_hal_gpio_pin_handle_t * crs_dv
Definition cfn_hal_eth.h:168
cfn_hal_gpio_pin_handle_t * mdc
Definition cfn_hal_eth.h:167
void * user_arg
Definition cfn_hal_eth.h:174
cfn_hal_gpio_pin_handle_t * rxd0
Definition cfn_hal_eth.h:169
cfn_hal_gpio_pin_handle_t * rxd1
Definition cfn_hal_eth.h:170
cfn_hal_gpio_pin_handle_t * mdio
Definition cfn_hal_eth.h:166
cfn_hal_gpio_pin_handle_t * txd0
Definition cfn_hal_eth.h:172
Lightweight handle to a specific GPIO pin. Used by other peripherals to reference physical pins.
Definition cfn_hal_gpio.h:173