![]() |
no-OS
|
#include <stdbool.h>#include <stdint.h>#include "no_os_spi.h"#include "no_os_util.h"#include "oa_tc6.h"Classes | |
| struct | adin1140_desc |
| ADIN1140 device descriptor. More... | |
| struct | adin1140_mac_cfg |
| MAC CONFIG0 user-configurable bitfields. TXFCSVE is always cleared so the MAC appends the FCS itself; SYNC, PROTE, SEQE are managed internally and not exposed here. More... | |
| struct | adin1140_plca_diag |
| PLCA diagnostic latches read from the DIAG register. All bits are sticky (W1C) on the device; pass clear=true to adin1140_plca_get_diag to acknowledge after reading. More... | |
| struct | adin1140_plca_cfg |
| PLCA (Physical Layer Collision Avoidance) configuration. More... | |
| struct | adin1140_init_param |
| Initialization parameter for the device descriptor. More... | |
| struct | adin1140_eth_buff |
| Buffer structure used for frame RX and TX transactions. More... | |
| struct | adin1140_stats |
| MAC hardware statistics counters (free-running accumulators read from the device counter registers). More... | |
Functions | |
| int | adin1140_reg_write (struct adin1140_desc *desc, uint32_t addr, uint32_t data) |
| Write a register's value. | |
| int | adin1140_reg_read (struct adin1140_desc *desc, uint32_t addr, uint32_t *data) |
| Read a register's value. | |
| int | adin1140_reg_update (struct adin1140_desc *desc, uint32_t addr, uint32_t mask, uint32_t data) |
| Update a register's value based on a mask. | |
| int | adin1140_mdio_read_c22 (struct adin1140_desc *desc, uint16_t reg, uint16_t *data) |
| Read a PHY register using clause 22 via MMS. | |
| int | adin1140_mdio_write_c22 (struct adin1140_desc *desc, uint16_t reg, uint16_t data) |
| Write a PHY register using clause 22 via MMS. | |
| int | adin1140_mdio_read_c45 (struct adin1140_desc *desc, uint32_t devnum, uint16_t reg, uint16_t *data) |
| Read a PHY register using clause 45 via MMS. | |
| int | adin1140_mdio_write_c45 (struct adin1140_desc *desc, uint32_t devnum, uint16_t reg, uint16_t data) |
| Write a PHY register using clause 45 via MMS. | |
| int | adin1140_set_mac_addr (struct adin1140_desc *desc, uint8_t mac_address[ADIN1140_ETH_ALEN]) |
| Add a unicast MAC address filter in the first available slot. Slots 0, 1 and 2 are reserved (multicast, broadcast and the device's own address), so the address is placed in the first free slot starting from ADIN1140_MAC_FILT_UNICAST_SLOT + 1. | |
| int | adin1140_broadcast_filter (struct adin1140_desc *desc, bool enabled) |
| Enable/disable the broadcast filter. | |
| int | adin1140_multicast_filter (struct adin1140_desc *desc, bool enabled) |
| Enable/disable the all-multicast filter. Matches any frame with the multicast bit set in the destination MAC. | |
| int | adin1140_set_promisc (struct adin1140_desc *desc, bool promisc) |
| Set/clear promiscuous mode via CONFIG2 FWD_UNK2HOST. | |
| int | adin1140_mac_set_cfg (struct adin1140_desc *desc, const struct adin1140_mac_cfg *cfg) |
| Apply the MAC CONFIG0 bitfields exposed via struct adin1140_mac_cfg. TXFCSVE is always cleared so the MAC appends the FCS itself. SYNC is preserved (read-modify-write). | |
| int | adin1140_mac_get_cfg (struct adin1140_desc *desc, struct adin1140_mac_cfg *cfg) |
| Read back the MAC CONFIG0 bitfields into struct adin1140_mac_cfg. | |
| int | adin1140_sw_reset (struct adin1140_desc *desc) |
| Trigger a MAC-PHY soft reset via OA-TC6 SWRESET, then re-assert the CONFIG0.SYNC bit so the device is ready to handle traffic. | |
| int | adin1140_write_fifo (struct adin1140_desc *desc, struct adin1140_eth_buff *eth_buff) |
| Write a frame to the TX FIFO via OA TC6. | |
| int | adin1140_read_fifo (struct adin1140_desc *desc, struct adin1140_eth_buff *eth_buff) |
| Read a frame from the RX FIFO via OA TC6. | |
| int | adin1140_plca_set_cfg (struct adin1140_desc *desc, const struct adin1140_plca_cfg *cfg) |
| Set the PLCA configuration. | |
| int | adin1140_plca_get_cfg (struct adin1140_desc *desc, struct adin1140_plca_cfg *cfg) |
| Get the current PLCA configuration. | |
| int | adin1140_plca_get_status (struct adin1140_desc *desc, bool *active) |
| Get the PLCA status (whether PLCA is active). | |
| int | adin1140_plca_reset (struct adin1140_desc *desc) |
| Reset the PLCA logic by setting CTRL0.PLCARST. The bit is self-clearing once the PLCA state machines and counters have been returned to their reset state. Other CTRL0 bits (notably PLCAEN) are preserved. | |
| int | adin1140_plca_get_diag (struct adin1140_desc *desc, struct adin1140_plca_diag *diag, bool clear) |
| Read the PLCA DIAG register and decode the three latched diagnostic indicators. Bits are RO/W1C on the device; if clear is true, write back any bits that were read as 1 to acknowledge them. | |
| int | adin1140_register_callback (struct adin1140_desc *desc, void(*callback)(struct adin1140_desc *, uint32_t, void *), void *arg) |
| Register a callback for OA TC6 events (e.g. link state change). | |
| int | adin1140_poll (struct adin1140_desc *desc) |
| int | adin1140_link_state (struct adin1140_desc *desc, uint32_t *state) |
| Get the link state. | |
| int | adin1140_get_stats (struct adin1140_desc *desc, struct adin1140_stats *stats) |
| Read the MAC hardware statistics counters. | |
| int | adin1140_init (struct adin1140_desc **desc, struct adin1140_init_param *param) |
| Initialize the ADIN1140 device. | |
| int | adin1140_remove (struct adin1140_desc *desc) |
| Free the ADIN1140 device descriptor. | |
| #define ADIN1140_CONFIG0_CPS_64 NO_OS_GENMASK(2, 1) |
| #define ADIN1140_CONFIG0_CPS_MASK NO_OS_GENMASK(2, 0) |
| #define ADIN1140_CONFIG0_CSARFE NO_OS_BIT(13) |
| #define ADIN1140_CONFIG0_FTSE NO_OS_BIT(7) |
| #define ADIN1140_CONFIG0_FTSS NO_OS_BIT(6) |
| #define ADIN1140_CONFIG0_REG OA_MMS_REG(0x0, 0x0004) |
| #define ADIN1140_CONFIG0_RXCTE NO_OS_BIT(8) |
| #define ADIN1140_CONFIG0_SYNC NO_OS_BIT(15) |
| #define ADIN1140_CONFIG0_TXCTE NO_OS_BIT(9) |
| #define ADIN1140_CONFIG0_TXCTHRESH_MASK NO_OS_GENMASK(11, 10) |
| #define ADIN1140_CONFIG0_TXFCSVE NO_OS_BIT(14) |
| #define ADIN1140_CONFIG0_ZARFE NO_OS_BIT(12) |
| #define ADIN1140_CONFIG2_FWD_UNK2HOST NO_OS_BIT(2) |
| #define ADIN1140_CONFIG2_REG OA_MMS_REG(0x0, 0x0006) |
| #define ADIN1140_ETH_ALEN 6 |
| #define ADIN1140_ETH_HDR_LEN 14 |
| #define ADIN1140_IMASK1_P1_RX_RDY_MASK NO_OS_BIT(4) |
| #define ADIN1140_IMASK1_REG OA_MMS_REG(0x0, 0x000D) |
| #define ADIN1140_MAC_ADDR_APPLY2PORT1 NO_OS_BIT(30) |
| #define ADIN1140_MAC_ADDR_FILT_LWR_REG | ( | x | ) |
| #define ADIN1140_MAC_ADDR_FILT_UPR_REG | ( | x | ) |
| #define ADIN1140_MAC_ADDR_MASK_LWR_REG | ( | x | ) |
| #define ADIN1140_MAC_ADDR_MASK_SLOTS 2 |
| #define ADIN1140_MAC_ADDR_MASK_UPR_REG | ( | x | ) |
| #define ADIN1140_MAC_ADDR_TO_HOST NO_OS_BIT(16) |
| #define ADIN1140_MAC_FILT_BROADCAST_SLOT 1 |
| #define ADIN1140_MAC_FILT_MAX_SLOT 16 |
| #define ADIN1140_MAC_FILT_MULTICAST_SLOT 0 |
| #define ADIN1140_MAC_FILT_UNICAST_SLOT 2 |
| #define ADIN1140_MAC_P1_LOOP_REG OA_MMS_REG(0x1, 0xC4) |
| #define ADIN1140_MACPHY_ID_REG OA_MMS_REG(0x0, 0x0001) |
| #define ADIN1140_PHY_C45_PCS_MMS 2 |
| #define ADIN1140_PHY_C45_PMA_PMD_MMS 3 |
| #define ADIN1140_PHY_C45_VS_PLCA_MMS 4 |
| #define ADIN1140_PHY_ID 0x0283BE00 |
| #define ADIN1140_PLCA_BURST_BTMR_MASK NO_OS_GENMASK(7, 0) |
| #define ADIN1140_PLCA_BURST_MAXBC_MASK NO_OS_GENMASK(15, 8) |
| #define ADIN1140_PLCA_BURST_REG OA_MMS_REG(0x4, 0xCA05) |
| #define ADIN1140_PLCA_CTRL0_EN NO_OS_BIT(15) |
| #define ADIN1140_PLCA_CTRL0_REG OA_MMS_REG(0x4, 0xCA01) |
| #define ADIN1140_PLCA_CTRL0_RST NO_OS_BIT(14) |
| #define ADIN1140_PLCA_CTRL1_ID_MASK NO_OS_GENMASK(7, 0) |
| #define ADIN1140_PLCA_CTRL1_NCNT_MASK NO_OS_GENMASK(15, 8) |
| #define ADIN1140_PLCA_CTRL1_REG OA_MMS_REG(0x4, 0xCA02) |
| #define ADIN1140_PLCA_DIAG_BCNBFTO NO_OS_BIT(0) |
| #define ADIN1140_PLCA_DIAG_REG OA_MMS_REG(0x4, 0xCA06) |
| #define ADIN1140_PLCA_DIAG_RXINTO NO_OS_BIT(2) |
| #define ADIN1140_PLCA_DIAG_UNEXPB NO_OS_BIT(1) |
| #define ADIN1140_PLCA_IDVER_REG OA_MMS_REG(0x4, 0xCA00) |
| #define ADIN1140_PLCA_STATUS_PST NO_OS_BIT(15) |
| #define ADIN1140_PLCA_STATUS_REG OA_MMS_REG(0x4, 0xCA03) |
| #define ADIN1140_PLCA_TOTMR_MASK NO_OS_GENMASK(7, 0) |
| #define ADIN1140_PLCA_TOTMR_REG OA_MMS_REG(0x4, 0xCA04) |
| #define ADIN1140_RX_ALGN_ERR_CNT_REG OA_MMS_REG(0x1, 0xA6) |
| #define ADIN1140_RX_BCAST_CNT_REG OA_MMS_REG(0x1, 0xA2) |
| #define ADIN1140_RX_CRC_ERR_CNT_REG OA_MMS_REG(0x1, 0xA5) |
| #define ADIN1140_RX_FRAME_CNT_REG OA_MMS_REG(0x1, 0xA1) |
| #define ADIN1140_RX_MCAST_CNT_REG OA_MMS_REG(0x1, 0xA3) |
| #define ADIN1140_RX_UCAST_CNT_REG OA_MMS_REG(0x1, 0xA4) |
| #define ADIN1140_STATUS0_REG OA_MMS_REG(0x0, 0x0008) |
| #define ADIN1140_STATUS0_RESETC NO_OS_BIT(6) |
| #define ADIN1140_STATUS1_LINK_STATE NO_OS_BIT(0) |
| #define ADIN1140_STATUS1_REG OA_MMS_REG(0x0, 0x0009) |
| #define ADIN1140_TX_BCAST_CNT_REG OA_MMS_REG(0x1, 0xB2) |
| #define ADIN1140_TX_FRAME_CNT_REG OA_MMS_REG(0x1, 0xB1) |
| #define ADIN1140_TX_MCAST_CNT_REG OA_MMS_REG(0x1, 0xB3) |
| #define ADIN1140_TX_UCAST_CNT_REG OA_MMS_REG(0x1, 0xB4) |
| int adin1140_broadcast_filter | ( | struct adin1140_desc * | desc, |
| bool | enabled ) |
Enable/disable the broadcast filter.
| desc | - the device descriptor. |
| enabled | - true to enable, false to disable. |
| int adin1140_get_stats | ( | struct adin1140_desc * | desc, |
| struct adin1140_stats * | stats ) |
Read the MAC hardware statistics counters.
| desc | - the device descriptor. |
| stats | - storage for the counter snapshot. |
| int adin1140_init | ( | struct adin1140_desc ** | desc, |
| struct adin1140_init_param * | param ) |
Initialize the ADIN1140 device.
| desc | - pointer to the device descriptor to be initialized. |
| param | - the device's initialization parameters. |
| int adin1140_link_state | ( | struct adin1140_desc * | desc, |
| uint32_t * | state ) |
Get the link state.
| desc | - the device descriptor. |
| state | - pointer to store the link state (1 = up, 0 = down). |
| int adin1140_mac_get_cfg | ( | struct adin1140_desc * | desc, |
| struct adin1140_mac_cfg * | cfg ) |
Read back the MAC CONFIG0 bitfields into struct adin1140_mac_cfg.
| desc | - the device descriptor. |
| cfg | - pointer to store the configuration values. |
| int adin1140_mac_set_cfg | ( | struct adin1140_desc * | desc, |
| const struct adin1140_mac_cfg * | cfg ) |
Apply the MAC CONFIG0 bitfields exposed via struct adin1140_mac_cfg. TXFCSVE is always cleared so the MAC appends the FCS itself. SYNC is preserved (read-modify-write).
| desc | - the device descriptor. |
| cfg | - configuration values to apply. |
| int adin1140_mdio_read_c22 | ( | struct adin1140_desc * | desc, |
| uint16_t | reg, | ||
| uint16_t * | data ) |
Read a PHY register using clause 22 via MMS.
| desc | - the device descriptor. |
| reg | - register address (0..31). |
| data | - pointer to store the register value. |
| int adin1140_mdio_read_c45 | ( | struct adin1140_desc * | desc, |
| uint32_t | devnum, | ||
| uint16_t | reg, | ||
| uint16_t * | data ) |
Read a PHY register using clause 45 via MMS.
| desc | - the device descriptor. |
| devnum | - MMD device number (1=PMA/PMD, 3=PCS, 31=VEND2). |
| reg | - register address within the MMD. |
| data | - pointer to store the register value. |
| int adin1140_mdio_write_c22 | ( | struct adin1140_desc * | desc, |
| uint16_t | reg, | ||
| uint16_t | data ) |
Write a PHY register using clause 22 via MMS.
| desc | - the device descriptor. |
| reg | - register address (0..31). |
| data | - value to write. |
| int adin1140_mdio_write_c45 | ( | struct adin1140_desc * | desc, |
| uint32_t | devnum, | ||
| uint16_t | reg, | ||
| uint16_t | data ) |
Write a PHY register using clause 45 via MMS.
| desc | - the device descriptor. |
| devnum | - MMD device number (1=PMA/PMD, 3=PCS, 31=VEND2). |
| reg | - register address within the MMD. |
| data | - value to write. |
| int adin1140_multicast_filter | ( | struct adin1140_desc * | desc, |
| bool | enabled ) |
Enable/disable the all-multicast filter. Matches any frame with the multicast bit set in the destination MAC.
| desc | - the device descriptor. |
| enabled | - true to enable, false to disable. |
| int adin1140_plca_get_cfg | ( | struct adin1140_desc * | desc, |
| struct adin1140_plca_cfg * | cfg ) |
Get the current PLCA configuration.
| desc | - the device descriptor. |
| cfg | - pointer to store the PLCA configuration. |
| int adin1140_plca_get_diag | ( | struct adin1140_desc * | desc, |
| struct adin1140_plca_diag * | diag, | ||
| bool | clear ) |
Read the PLCA DIAG register and decode the three latched diagnostic indicators. Bits are RO/W1C on the device; if clear is true, write back any bits that were read as 1 to acknowledge them.
| desc | - the device descriptor. |
| diag | - pointer to store the decoded diagnostic values. |
| clear | - true to W1C-clear the latches that were observed set. |
| int adin1140_plca_get_status | ( | struct adin1140_desc * | desc, |
| bool * | active ) |
Get the PLCA status (whether PLCA is active).
| desc | - the device descriptor. |
| active | - pointer to store the status (true if PLCA is active). |
| int adin1140_plca_reset | ( | struct adin1140_desc * | desc | ) |
Reset the PLCA logic by setting CTRL0.PLCARST. The bit is self-clearing once the PLCA state machines and counters have been returned to their reset state. Other CTRL0 bits (notably PLCAEN) are preserved.
| desc | - the device descriptor. |
| int adin1140_plca_set_cfg | ( | struct adin1140_desc * | desc, |
| const struct adin1140_plca_cfg * | cfg ) |
Set the PLCA configuration.
| desc | - the device descriptor. |
| cfg | - PLCA configuration to apply. |
| int adin1140_poll | ( | struct adin1140_desc * | desc | ) |
| int adin1140_read_fifo | ( | struct adin1140_desc * | desc, |
| struct adin1140_eth_buff * | eth_buff ) |
Read a frame from the RX FIFO via OA TC6.
| desc | - the device descriptor. |
| eth_buff | - buffer to receive the frame. |
| int adin1140_reg_read | ( | struct adin1140_desc * | desc, |
| uint32_t | addr, | ||
| uint32_t * | data ) |
Read a register's value.
| desc | - the device descriptor. |
| addr | - MMS-encoded register address. |
| data | - pointer to store the register value. |
| int adin1140_reg_update | ( | struct adin1140_desc * | desc, |
| uint32_t | addr, | ||
| uint32_t | mask, | ||
| uint32_t | data ) |
Update a register's value based on a mask.
| desc | - the device descriptor. |
| addr | - MMS-encoded register address. |
| mask | - the bits that may be modified. |
| data | - new value for the masked bits. |
| int adin1140_reg_write | ( | struct adin1140_desc * | desc, |
| uint32_t | addr, | ||
| uint32_t | data ) |
Write a register's value.
| desc | - the device descriptor. |
| addr | - MMS-encoded register address. |
| data | - register value to write. |
| int adin1140_register_callback | ( | struct adin1140_desc * | desc, |
| void(* | callback )(struct adin1140_desc *, uint32_t, void *), | ||
| void * | arg ) |
Register a callback for OA TC6 events (e.g. link state change).
| desc | - the device descriptor. |
| callback | - function called with the device descriptor, the event and the user argument. NULL disables the callback. |
| arg | - user argument passed to the callback. |
| int adin1140_remove | ( | struct adin1140_desc * | desc | ) |
Free the ADIN1140 device descriptor.
| desc | - the device descriptor to be removed. |
| int adin1140_set_mac_addr | ( | struct adin1140_desc * | desc, |
| uint8_t | mac_address[ADIN1140_ETH_ALEN] ) |
Add a unicast MAC address filter in the first available slot. Slots 0, 1 and 2 are reserved (multicast, broadcast and the device's own address), so the address is placed in the first free slot starting from ADIN1140_MAC_FILT_UNICAST_SLOT + 1.
| desc | - the device descriptor. |
| mac_address | - the MAC address to filter on. |
| int adin1140_set_promisc | ( | struct adin1140_desc * | desc, |
| bool | promisc ) |
Set/clear promiscuous mode via CONFIG2 FWD_UNK2HOST.
| desc | - the device descriptor. |
| promisc | - true to enable promiscuous mode, false to disable. |
| int adin1140_sw_reset | ( | struct adin1140_desc * | desc | ) |
Trigger a MAC-PHY soft reset via OA-TC6 SWRESET, then re-assert the CONFIG0.SYNC bit so the device is ready to handle traffic.
| desc | - the device descriptor. |
| int adin1140_write_fifo | ( | struct adin1140_desc * | desc, |
| struct adin1140_eth_buff * | eth_buff ) |
Write a frame to the TX FIFO via OA TC6.
| desc | - the device descriptor. |
| eth_buff | - the frame to be transmitted. |