/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : hal_eth.h * @brief : Hardware Abstraction Layer Ethernet interface header file ****************************************************************************** */ /* USER CODE END Header */ #ifndef HAL_ETH_H #define HAL_ETH_H #include "hal.h" /** * @brief Ethernet instance definitions */ typedef enum { HAL_ETH_INSTANCE_1 = 0, /*!< Ethernet instance 1 */ HAL_ETH_INSTANCE_MAX } hal_eth_instance_t; /** * @brief Ethernet mode definitions */ typedef enum { HAL_ETH_MODE_HALFDUPLEX = 0, /*!< Half duplex mode */ HAL_ETH_MODE_FULLDUPLEX, /*!< Full duplex mode */ HAL_ETH_MODE_MAX } hal_eth_mode_t; /** * @brief Ethernet speed definitions */ typedef enum { HAL_ETH_SPEED_10MBPS = 0, /*!< 10 Mbps speed */ HAL_ETH_SPEED_100MBPS, /*!< 100 Mbps speed */ HAL_ETH_SPEED_MAX } hal_eth_speed_t; /** * @brief Ethernet PHY address definitions */ typedef uint8_t hal_eth_phy_addr_t; /** * @brief Ethernet MAC address structure */ typedef struct { uint8_t byte[6]; /*!< MAC address bytes */ } hal_eth_mac_addr_t; /** * @brief Ethernet configuration structure */ typedef struct { uint8_t enable; /*!< Ethernet enable flag */ hal_eth_instance_t instance; /*!< Ethernet instance */ hal_eth_mode_t mode; /*!< Ethernet mode */ hal_eth_speed_t speed; /*!< Ethernet speed */ hal_eth_phy_addr_t phy_addr; /*!< PHY address */ hal_eth_mac_addr_t mac_addr; /*!< MAC address */ uint8_t auto_negotiation; /*!< Auto negotiation enable flag */ uint8_t interrupt_enable; /*!< Interrupt enable flag */ } hal_eth_config_t; /** * @brief Ethernet status structure */ typedef struct { uint8_t link_up; /*!< Link up status */ uint8_t duplex; /*!< Duplex mode (0: half, 1: full) */ uint32_t speed; /*!< Speed in Mbps */ uint32_t rx_packets; /*!< Received packets count */ uint32_t tx_packets; /*!< Transmitted packets count */ uint32_t rx_errors; /*!< Receive errors count */ uint32_t tx_errors; /*!< Transmit errors count */ } hal_eth_status_t; /** * @brief Initialize Ethernet module * @param config: Pointer to Ethernet configuration structure * @retval HAL status code */ hal_ret_t hal_eth_init(const hal_eth_config_t* config); /** * @brief Deinitialize Ethernet module * @param instance: Ethernet instance * @retval HAL status code */ hal_ret_t hal_eth_deinit(hal_eth_instance_t instance); /** * @brief Get Ethernet status * @param instance: Ethernet instance * @param status: Pointer to Ethernet status structure * @retval HAL status code */ hal_ret_t hal_eth_get_status(hal_eth_instance_t instance, hal_eth_status_t* status); /** * @brief Set Ethernet MAC address * @param instance: Ethernet instance * @param mac_addr: Pointer to MAC address structure * @retval HAL status code */ hal_ret_t hal_eth_set_mac_addr(hal_eth_instance_t instance, const hal_eth_mac_addr_t* mac_addr); /** * @brief Get Ethernet MAC address * @param instance: Ethernet instance * @param mac_addr: Pointer to MAC address structure * @retval HAL status code */ hal_ret_t hal_eth_get_mac_addr(hal_eth_instance_t instance, hal_eth_mac_addr_t* mac_addr); /** * @brief Check Ethernet link status * @param instance: Ethernet instance * @param link_up: Pointer to store link up status * @retval HAL status code */ hal_ret_t hal_eth_check_link(hal_eth_instance_t instance, uint8_t* link_up); /** * @brief Reset Ethernet PHY * @param instance: Ethernet instance * @param phy_addr: PHY address * @retval HAL status code */ hal_ret_t hal_eth_reset_phy(hal_eth_instance_t instance, hal_eth_phy_addr_t phy_addr); /** * @brief Read PHY register * @param instance: Ethernet instance * @param phy_addr: PHY address * @param reg_addr: Register address * @param value: Pointer to store register value * @retval HAL status code */ hal_ret_t hal_eth_read_phy_reg(hal_eth_instance_t instance, hal_eth_phy_addr_t phy_addr, uint16_t reg_addr, uint16_t* value); /** * @brief Write PHY register * @param instance: Ethernet instance * @param phy_addr: PHY address * @param reg_addr: Register address * @param value: Register value * @retval HAL status code */ hal_ret_t hal_eth_write_phy_reg(hal_eth_instance_t instance, hal_eth_phy_addr_t phy_addr, uint16_t reg_addr, uint16_t value); /** * @brief Get default Ethernet configuration * @return Pointer to default Ethernet configuration */ const hal_eth_config_t* hal_eth_get_default_config(void); #endif /* HAL_ETH_H */