|
caffeine-hal 0.6.6
A Header-Defined Interface c library, it provides the hal layer for the Caffeine framework
|
Ethernet / MAC HAL API. More...
Go to the source code of this file.
Data Structures | |
| struct | cfn_hal_eth_link_status_t |
| Ethernet link status information. More... | |
| struct | cfn_hal_eth_config_t |
| Ethernet configuration structure. More... | |
| struct | cfn_hal_eth_phy_t |
| Ethernet hardware physical mapping. More... | |
| struct | cfn_hal_eth_api_s |
| Ethernet Virtual Method Table (VMT). More... | |
Typedefs | |
| typedef struct cfn_hal_eth_s | cfn_hal_eth_t |
| typedef struct cfn_hal_eth_api_s | cfn_hal_eth_api_t |
| typedef 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. | |
Enumerations | |
| enum | cfn_hal_eth_event_t { CFN_HAL_ETH_EVENT_NONE = 0 , CFN_HAL_ETH_EVENT_RX_COMPLETE = CFN_HAL_BIT(0) , CFN_HAL_ETH_EVENT_TX_COMPLETE = CFN_HAL_BIT(1) , CFN_HAL_ETH_EVENT_LINK_UP = CFN_HAL_BIT(2) , CFN_HAL_ETH_EVENT_LINK_DOWN = CFN_HAL_BIT(3) } |
| Ethernet nominal event flags. More... | |
| enum | cfn_hal_eth_error_t { CFN_HAL_ETH_ERROR_NONE = 0 , CFN_HAL_ETH_ERROR_MAC = CFN_HAL_BIT(0) , CFN_HAL_ETH_ERROR_PHY = CFN_HAL_BIT(1) , CFN_HAL_ETH_ERROR_GENERAL = CFN_HAL_BIT(2) } |
| Ethernet exception error flags. More... | |
| enum | cfn_hal_eth_link_speed_t { CFN_HAL_ETH_LINK_SPEED_10M , CFN_HAL_ETH_LINK_SPEED_100M , CFN_HAL_ETH_LINK_SPEED_1000M } |
| Ethernet link speed. More... | |
| enum | cfn_hal_eth_link_duplex_t { CFN_HAL_ETH_LINK_DUPLEX_HALF , CFN_HAL_ETH_LINK_DUPLEX_FULL } |
| Ethernet link duplex mode. More... | |
Ethernet / MAC HAL API.
Copyright (c) 2026 Hisham Moussa Daou https://www.whileone.me
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| #define CFN_HAL_ETH_PHY_ANAR_100FD CFN_HAL_BIT(8) |
100Base-TX full duplex ability
| #define CFN_HAL_ETH_PHY_ANAR_100HD CFN_HAL_BIT(7) |
100Base-TX half duplex ability
| #define CFN_HAL_ETH_PHY_ANAR_100T4 CFN_HAL_BIT(9) |
100Base-T4 ability
| #define CFN_HAL_ETH_PHY_ANAR_10FD CFN_HAL_BIT(6) |
10Base-T full duplex ability
| #define CFN_HAL_ETH_PHY_ANAR_10HD CFN_HAL_BIT(5) |
10Base-T half duplex ability
| #define CFN_HAL_ETH_PHY_ANAR_NEXT_PAGE CFN_HAL_BIT(15) |
ANAR (Auto-Negotiation Advertisement Register) bit definitions.
Next page ability
| #define CFN_HAL_ETH_PHY_ANAR_PAUSE CFN_HAL_BIT(10) |
Pause support
| #define CFN_HAL_ETH_PHY_ANAR_REM_FAULT CFN_HAL_BIT(13) |
Remote fault
| #define CFN_HAL_ETH_PHY_ANAR_SELECTOR 0x001FU |
Protocol selector field
| #define CFN_HAL_ETH_PHY_BMCR_AUTONEG CFN_HAL_BIT(12) |
Enable auto-negotiation
| #define CFN_HAL_ETH_PHY_BMCR_DUPLEX CFN_HAL_BIT(8) |
Full duplex (0 = half)
| #define CFN_HAL_ETH_PHY_BMCR_ISOLATE CFN_HAL_BIT(10) |
Isolate PHY from MII
| #define CFN_HAL_ETH_PHY_BMCR_LOOPBACK CFN_HAL_BIT(14) |
Enable loopback
| #define CFN_HAL_ETH_PHY_BMCR_POWERDOWN CFN_HAL_BIT(11) |
PHY power down
| #define CFN_HAL_ETH_PHY_BMCR_RESET CFN_HAL_BIT(15) |
BMCR (Basic Mode Control Register) bit definitions.
PHY reset
| #define CFN_HAL_ETH_PHY_BMCR_RESTART CFN_HAL_BIT(9) |
Restart auto-negotiation
| #define CFN_HAL_ETH_PHY_BMCR_SPEED_100 CFN_HAL_BIT(13) |
Select 100Mbps (0 = 10Mbps)
| #define CFN_HAL_ETH_PHY_BSR_100BASET4 CFN_HAL_BIT(15) |
BSR (Basic Mode Status Register) bit definitions.
100Base-T4 support
| #define CFN_HAL_ETH_PHY_BSR_100BASEXFD CFN_HAL_BIT(14) |
100Base-X Full Duplex support
| #define CFN_HAL_ETH_PHY_BSR_100BASEXHD CFN_HAL_BIT(13) |
100Base-X Half Duplex support
| #define CFN_HAL_ETH_PHY_BSR_10BASETFD CFN_HAL_BIT(12) |
10Base-T Full Duplex support
| #define CFN_HAL_ETH_PHY_BSR_10BASETHD CFN_HAL_BIT(11) |
10Base-T Half Duplex support
| #define CFN_HAL_ETH_PHY_BSR_AUTONEGABL CFN_HAL_BIT(3) |
Auto-negotiation ability
| #define CFN_HAL_ETH_PHY_BSR_AUTONEGCMP CFN_HAL_BIT(5) |
Auto-negotiation complete
| #define CFN_HAL_ETH_PHY_BSR_EXTENDED CFN_HAL_BIT(0) |
Extended capability support
| #define CFN_HAL_ETH_PHY_BSR_JABBERDET CFN_HAL_BIT(1) |
Jabber condition detected
| #define CFN_HAL_ETH_PHY_BSR_LINKSTAT CFN_HAL_BIT(2) |
Link status (1 = up)
| #define CFN_HAL_ETH_PHY_BSR_REMOTEFLT CFN_HAL_BIT(4) |
Remote fault detected
| #define CFN_HAL_ETH_PHY_REG_ANAR 0x04U |
Auto-Negotiation Advertisement Register
| #define CFN_HAL_ETH_PHY_REG_ANER 0x06U |
Auto-Negotiation Expansion Register
| #define CFN_HAL_ETH_PHY_REG_ANLPAR 0x05U |
Auto-Negotiation Link Partner Ability Register
| #define CFN_HAL_ETH_PHY_REG_BMCR 0x00U |
Standard IEEE 802.3 PHY Registers.
Basic Mode Control Register
| #define CFN_HAL_ETH_PHY_REG_BSR 0x01U |
Basic Mode Status Register
| #define CFN_HAL_ETH_PHY_REG_ID1 0x02U |
PHY Identifier 1 Register
| #define CFN_HAL_ETH_PHY_REG_ID2 0x03U |
PHY Identifier 2 Register
| typedef struct cfn_hal_eth_api_s cfn_hal_eth_api_t |
| typedef 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.
| driver | Pointer to the Ethernet driver instance. |
| event_mask | Mask of triggered nominal events. |
| error_mask | Mask of triggered exception errors. |
| user_arg | User-defined argument passed during registration. |
| typedef struct cfn_hal_eth_s cfn_hal_eth_t |
| enum cfn_hal_eth_error_t |
| enum cfn_hal_eth_event_t |
| CFN_HAL_CREATE_DRIVER_TYPE | ( | eth | , |
| cfn_hal_eth_config_t | , | ||
| cfn_hal_eth_api_t | , | ||
| cfn_hal_eth_phy_t | , | ||
| cfn_hal_eth_callback_t | |||
| ) |
| 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.
| driver | Pointer to the Ethernet driver instance. |
| callback | The callback function to register. |
| user_arg | User-defined argument passed to the callback. |
| 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.
| driver | Pointer to the Ethernet driver instance. |
| config | [out] Pointer to store the configuration. |
| 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.
| driver | Pointer to the Ethernet driver instance. |
| config | Pointer to the configuration structure. |
| 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.
| driver | Pointer to the ETH driver instance. |
| config | Pointer to the configuration structure. |
| 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 | ||
| ) |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_deinit | ( | cfn_hal_eth_t * | driver | ) |
Deinitializes the Ethernet driver.
| driver | Pointer to the Ethernet driver instance. |
| cfn_hal_error_code_t cfn_hal_eth_destruct | ( | cfn_hal_eth_t * | driver | ) |
| 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.
| driver | Pointer to the Ethernet driver instance. |
| error_mask | Mask of errors to disable. |
| 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.
| driver | Pointer to the Ethernet driver instance. |
| error_mask | Mask of errors to enable. |
| 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.
| driver | Pointer to the Ethernet driver instance. |
| error_mask | [out] Pointer to store the error mask. |
| 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.
| driver | Pointer to the Ethernet driver instance. |
| event_mask | Mask of events to disable. |
| 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.
| driver | Pointer to the Ethernet driver instance. |
| event_mask | Mask of events to enable. |
| 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.
| driver | Pointer to the Ethernet driver instance. |
| event_mask | [out] Pointer to store the event mask. |
| 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.
| driver | Pointer to the Ethernet driver instance. |
| status | [out] Pointer to the link status structure. |
| timeout | Maximum time to wait for completion in milliseconds. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_init | ( | cfn_hal_eth_t * | driver | ) |
Initializes the Ethernet driver.
| driver | Pointer to the Ethernet driver instance. |
| 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 | ||
| ) |
| 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.
| driver | Pointer to the Ethernet driver instance. |
| state | Target power state. |
| 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.
| driver | Pointer to the Ethernet driver instance. |
| phy_addr | Address of the target PHY. |
| reg_addr | Address of the target register. |
| value | [out] Pointer to store the read value. |
| timeout | Maximum time to wait for completion in milliseconds. |
| 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.
| driver | Pointer to the Ethernet driver instance. |
| buffer | Pointer to the buffer where the frame will be stored. |
| max_length | Maximum capacity of the buffer. |
| received_length | [out] Actual number of bytes received. |
| timeout | Maximum time to wait for completion in milliseconds. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_start | ( | cfn_hal_eth_t * | driver | ) |
Starts the Ethernet MAC and DMA operations.
| driver | Pointer to the Ethernet driver instance. |
| CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_eth_stop | ( | cfn_hal_eth_t * | driver | ) |
Stops the Ethernet MAC and DMA operations.
| driver | Pointer to the Ethernet driver instance. |
| 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.
| driver | Pointer to the Ethernet driver instance. |
| frame | Pointer to the raw frame data. |
| length | Length of the frame in bytes. |
| timeout | Maximum time to wait for completion in milliseconds. |
| 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.
| driver | Pointer to the Ethernet driver instance. |
| phy_addr | Address of the target PHY. |
| reg_addr | Address of the target register. |
| value | Value to write. |
| timeout | Maximum time to wait for completion in milliseconds. |
| CFN_HAL_VMT_CHECK | ( | struct cfn_hal_eth_api_s | ) |