See Quickstart guide for GMAC driver..
Driver for the GMAC PHY (Ethernet Media Access Controller). This file contains basic functions for the GMAC PHY.
This driver does not depend on other modules.
Driver for the GMAC (Ethernet Media Access Controller). This file contains basic functions for the GMAC, with support for all modes, settings and clock speeds.
This driver does not depend on other modules.
Modules | |
Related Project(s) | |
In this section you can find all the projects related to the Ethernet PHY Media Access Controller. | |
Quick Start Guide(s) | |
In this section you can find a list of all Quick Start guides related to the Ethernet PHY Media Access Controller. | |
Data Structures | |
struct | gmac_dev_mem |
GMAC device memory management struct. More... | |
Macros | |
#define | CIRC_CLEAR(head, tail) (head = tail = 0) |
Clear circular buffer. More... | |
#define | CIRC_CNT(head, tail, size) (((head) - (tail)) % (size)) |
Return count in buffer. More... | |
#define | CIRC_EMPTY(head, tail) (head == tail) |
Circular buffer is empty ? More... | |
#define | CIRC_SPACE(head, tail, size) CIRC_CNT((tail),((head)+1),(size)) |
Typedefs | |
typedef struct gmac_dev_mem | gmac_dev_mem_t |
GMAC device memory management struct. More... | |
Functions | |
static void | circ_inc (uint16_t *headortail, uint32_t size) |
Increment head or tail. More... | |
uint8_t * | gmac_dev_get_tx_buffer (gmac_device_t *p_gmac_dev, gmac_quelist_t queue_idx) |
uint32_t | gmac_dev_get_tx_load (gmac_device_t *p_gmac_dev, gmac_quelist_t queue_idx) |
Get current load of transmit. More... | |
void | gmac_dev_init (Gmac *p_gmac, gmac_device_t *p_gmac_dev, gmac_options_t *p_opt) |
Initialize the GMAC driver. More... | |
uint32_t | gmac_dev_read (gmac_device_t *p_gmac_dev, gmac_quelist_t queue_idx, uint8_t *p_frame, uint32_t ul_frame_size, uint32_t *p_rcv_size) |
Frames can be read from the GMAC in multiple sections. More... | |
void | gmac_dev_reset (gmac_device_t *p_gmac_dev, gmac_quelist_t queue_idx) |
Reset TX & RX queue & statistics. More... | |
uint32_t | gmac_dev_rx_buf_used (gmac_device_t *p_gmac_dev, gmac_quelist_t queue_idx) |
Return the number of RX buffer full. More... | |
void | gmac_dev_set_rx_callback (gmac_device_t *p_gmac_dev, gmac_quelist_t queue_idx, gmac_dev_tx_cb_t func_rx_cb) |
Register/Clear RX callback. More... | |
uint8_t | gmac_dev_set_tx_wakeup_callback (gmac_device_t *p_gmac_dev, gmac_quelist_t queue_idx, gmac_dev_wakeup_cb_t func_wakeup_cb, uint8_t uc_threshold) |
Register/Clear TX wakeup callback. More... | |
uint32_t | gmac_dev_tx_buf_used (gmac_device_t *p_gmac_dev, gmac_quelist_t queue_idx) |
Return the number of TX buffer waiting for transfer. More... | |
uint32_t | gmac_dev_write (gmac_device_t *p_gmac_dev, gmac_quelist_t queue_idx, void *p_buffer, uint32_t ul_size, gmac_dev_tx_cb_t func_tx_cb) |
Send ulLength bytes from pcFrom. More... | |
uint32_t | gmac_dev_write_nocopy (gmac_device_t *p_gmac_dev, gmac_quelist_t queue_idx, uint32_t ul_size, gmac_dev_tx_cb_t func_tx_cb) |
void | gmac_handler (gmac_device_t *p_gmac_dev, gmac_quelist_t queue_idx) |
GMAC Interrupt handler. More... | |
static uint8_t | gmac_init_mem (gmac_device_t *p_gmac_dev, gmac_quelist_t queue_idx, gmac_dev_mem_t *p_dev_mm, gmac_dev_tx_cb_t *p_tx_cb) |
Initialize the allocated buffer lists for GMAC driver to transfer data. More... | |
static void | gmac_init_queue (Gmac *p_gmac, gmac_device_t *p_gmac_dev) |
uint8_t | gmac_phy_read (Gmac *p_gmac, uint8_t uc_phy_address, uint8_t uc_address, uint32_t *p_value) |
Read the PHY register. More... | |
static uint8_t | gmac_phy_wait (Gmac *p_gmac, const uint32_t ul_retry) |
Wait PHY operation to be completed. More... | |
uint8_t | gmac_phy_write (Gmac *p_gmac, uint8_t uc_phy_address, uint8_t uc_address, uint32_t ul_value) |
Write the PHY register. More... | |
static void | gmac_reset_rx_mem (gmac_device_t *p_dev, gmac_quelist_t queue_idx) |
Disable receiver, reset registers and descriptor list. More... | |
static void | gmac_reset_tx_mem (gmac_device_t *p_dev, gmac_quelist_t queue_idx) |
Disable transfer, reset registers and descriptor lists. More... | |
Variables | |
static gmac_rx_descriptor_t | gs_rx_desc [GMAC_RX_BUFFERS] |
static gmac_rx_descriptor_t | gs_rx_desc_null |
RX descriptors lists. More... | |
static gmac_dev_tx_cb_t | gs_tx_callback [GMAC_TX_BUFFERS] |
TX callback lists. More... | |
static gmac_tx_descriptor_t | gs_tx_desc [GMAC_TX_BUFFERS] |
static gmac_tx_descriptor_t | gs_tx_desc_null |
TX descriptor lists. More... | |
static uint8_t | gs_uc_rx_buffer [GMAC_RX_BUFFERS *GMAC_RX_UNITSIZE] |
Receive Buffer. More... | |
static uint8_t | gs_uc_tx_buffer [GMAC_TX_BUFFERS *GMAC_TX_UNITSIZE] |
Send Buffer. More... | |
#define CIRC_CLEAR | ( | head, | |
tail | |||
) | (head = tail = 0) |
Clear circular buffer.
Referenced by gmac_reset_tx_mem().
#define CIRC_CNT | ( | head, | |
tail, | |||
size | |||
) | (((head) - (tail)) % (size)) |
Return count in buffer.
Referenced by gmac_dev_get_tx_load(), and gmac_handler().
#define CIRC_EMPTY | ( | head, | |
tail | |||
) | (head == tail) |
Circular buffer is empty ?
Referenced by gmac_handler().
#define CIRC_SPACE | ( | head, | |
tail, | |||
size | |||
) | CIRC_CNT((tail),((head)+1),(size)) |
Referenced by gmac_dev_get_tx_buffer(), gmac_dev_write(), and gmac_handler().
typedef struct gmac_dev_mem gmac_dev_mem_t |
GMAC device memory management struct.
|
static |
Increment head or tail.
Referenced by gmac_dev_read(), gmac_dev_write(), gmac_dev_write_nocopy(), and gmac_handler().
uint8_t* gmac_dev_get_tx_buffer | ( | gmac_device_t * | p_gmac_dev, |
gmac_quelist_t | queue_idx | ||
) |
uint32_t gmac_dev_get_tx_load | ( | gmac_device_t * | p_gmac_dev, |
gmac_quelist_t | queue_idx | ||
) |
Get current load of transmit.
p_gmac_dev | Pointer to the GMAC device instance. |
References CIRC_CNT, gmac_device::gmac_queue_list, gmac_queue::us_tx_head, gmac_queue::us_tx_list_size, and gmac_queue::us_tx_tail.
void gmac_dev_init | ( | Gmac * | p_gmac, |
gmac_device_t * | p_gmac_dev, | ||
gmac_options_t * | p_opt | ||
) |
Initialize the GMAC driver.
p_gmac | Pointer to the GMAC instance. |
p_gmac_dev | Pointer to the GMAC device instance. |
p_opt | GMAC configure options. |
References gmac_clear_rx_status(), gmac_clear_statistics(), gmac_clear_tx_status(), gmac_disable_broadcast(), gmac_disable_interrupt(), gmac_enable_copy_all(), gmac_get_config(), gmac_init_queue(), gmac_network_control(), gmac_set_address(), gmac_set_config(), gmac_options::uc_copy_all_frame, gmac_options::uc_mac_addr, gmac_options::uc_no_boardcast, vQueueAddToRegistry, vSemaphoreCreateBinary, and xSemaphoreTake.
uint32_t gmac_dev_read | ( | gmac_device_t * | p_gmac_dev, |
gmac_quelist_t | queue_idx, | ||
uint8_t * | p_frame, | ||
uint32_t | ul_frame_size, | ||
uint32_t * | p_rcv_size | ||
) |
Frames can be read from the GMAC in multiple sections.
Read ul_frame_size bytes from the GMAC receive buffers to pcTo. p_rcv_size is the size of the entire frame. Generally gmac_read will be repeatedly called until the sum of all the ul_frame_size equals the value of p_rcv_size.
p_gmac_dev | Pointer to the GMAC device instance. |
p_frame | Address of the frame buffer. |
ul_frame_size | Length of the frame. |
p_rcv_size | Received frame size. |
References gmac_rx_descriptor::addr, circ_inc(), GMAC_OK, GMAC_PARAM, gmac_device::gmac_queue_list, GMAC_RX_ERROR, GMAC_RX_NO_DATA, GMAC_RX_UNITSIZE, GMAC_RXD_ADDR_MASK, GMAC_RXD_EOF, GMAC_RXD_LEN_MASK, GMAC_RXD_OWNERSHIP, GMAC_RXD_SOF, GMAC_SIZE_TOO_SMALL, NULL, gmac_queue::p_rx_dscr, gmac_rx_descriptor::status, gmac_queue::us_rx_idx, gmac_queue::us_rx_list_size, gmac_rx_descriptor::gmac_rx_addr::val, and gmac_rx_descriptor::gmac_rx_status::val.
void gmac_dev_reset | ( | gmac_device_t * | p_gmac_dev, |
gmac_quelist_t | queue_idx | ||
) |
Reset TX & RX queue & statistics.
p_gmac_dev | Pointer to GMAC device instance. |
References gmac_network_control(), gmac_reset_rx_mem(), gmac_reset_tx_mem(), and gmac_device::p_hw.
uint32_t gmac_dev_rx_buf_used | ( | gmac_device_t * | p_gmac_dev, |
gmac_quelist_t | queue_idx | ||
) |
Return the number of RX buffer full.
p_gmac_dev | Pointer to the GMAC device instance. |
References gmac_rx_descriptor::addr, gmac_device::gmac_queue_list, GMAC_RXD_OWNERSHIP, gmac_queue::p_rx_dscr, gmac_queue::us_rx_list_size, and gmac_rx_descriptor::gmac_rx_addr::val.
void gmac_dev_set_rx_callback | ( | gmac_device_t * | p_gmac_dev, |
gmac_quelist_t | queue_idx, | ||
gmac_dev_tx_cb_t | func_rx_cb | ||
) |
Register/Clear RX callback.
Callback will be invoked after the next received frame.
When gmac_dev_read() returns GMAC_RX_NULL, the application task calls gmac_dev_set_rx_callback() to register func_rx_cb() callback and enters suspend state. The callback is in charge to resume the task once a new frame has been received. The next time gmac_dev_read() is called, it will be successful.
This function is usually invoked from the RX callback itself with NULL callback, to unregister. Once the callback has resumed the application task, there is no need to invoke the callback again.
p_gmac_dev | Pointer to the GMAC device instance. |
func_tx_cb | Receive callback function. |
References gmac_queue::func_rx_cb, gmac_disable_interrupt(), gmac_disable_priority_interrupt(), gmac_enable_interrupt(), gmac_enable_priority_interrupt(), GMAC_QUE_0, gmac_device::gmac_queue_list, NULL, and gmac_device::p_hw.
uint8_t gmac_dev_set_tx_wakeup_callback | ( | gmac_device_t * | p_gmac_dev, |
gmac_quelist_t | queue_idx, | ||
gmac_dev_wakeup_cb_t | func_wakeup_cb, | ||
uint8_t | uc_threshold | ||
) |
Register/Clear TX wakeup callback.
When gmac_dev_write() returns GMAC_TX_BUSY (all transmit descriptor busy), the application task calls gmac_dev_set_tx_wakeup_callback() to register func_wakeup() callback and enters suspend state. The callback is in charge to resume the task once several transmit descriptors have been released. The next time gmac_dev_write() will be called, it shall be successful.
This function is usually invoked with NULL callback from the TX wakeup callback itself, to unregister. Once the callback has resumed the application task, there is no need to invoke the callback again.
p_gmac_dev | Pointer to GMAC device instance. |
func_wakeup | Pointer to wakeup callback function. |
uc_threshold | Number of free transmit descriptor before wakeup callback invoked. |
References gmac_queue::func_wakeup_cb, GMAC_OK, GMAC_PARAM, gmac_device::gmac_queue_list, NULL, and gmac_queue::uc_wakeup_threshold.
uint32_t gmac_dev_tx_buf_used | ( | gmac_device_t * | p_gmac_dev, |
gmac_quelist_t | queue_idx | ||
) |
Return the number of TX buffer waiting for transfer.
p_gmac_dev | Pointer to the GMAC device instance. |
References gmac_device::gmac_queue_list, GMAC_TXD_USED, gmac_queue::p_tx_dscr, gmac_tx_descriptor::status, gmac_queue::us_tx_list_size, and gmac_tx_descriptor::gmac_tx_status::val.
uint32_t gmac_dev_write | ( | gmac_device_t * | p_gmac_dev, |
gmac_quelist_t | queue_idx, | ||
void * | p_buffer, | ||
uint32_t | ul_size, | ||
gmac_dev_tx_cb_t | func_tx_cb | ||
) |
Send ulLength bytes from pcFrom.
This copies the buffer to one of the GMAC Tx buffers, and then indicates to the GMAC that the buffer is ready. If lEndOfFrame is true then the data being copied is the end of the frame and the frame can be transmitted.
p_gmac_dev | Pointer to the GMAC device instance. |
p_buffer | Pointer to the data buffer. |
ul_size | Length of the frame. |
func_tx_cb | Transmit callback function. |
References gmac_tx_descriptor::addr, circ_inc(), CIRC_SPACE, gmac_queue::func_tx_cb_list, GMAC_OK, GMAC_PARAM, gmac_device::gmac_queue_list, gmac_start_transmission(), GMAC_TX_BUSY, GMAC_TX_UNITSIZE, GMAC_TXD_LAST, GMAC_TXD_LEN_MASK, GMAC_TXD_USED, GMAC_TXD_WRAP, gmac_device::p_hw, gmac_queue::p_tx_dscr, gmac_tx_descriptor::status, gmac_queue::us_tx_head, gmac_queue::us_tx_list_size, gmac_queue::us_tx_tail, and gmac_tx_descriptor::gmac_tx_status::val.
uint32_t gmac_dev_write_nocopy | ( | gmac_device_t * | p_gmac_dev, |
gmac_quelist_t | queue_idx, | ||
uint32_t | ul_size, | ||
gmac_dev_tx_cb_t | func_tx_cb | ||
) |
References circ_inc(), gmac_queue::func_tx_cb_list, GMAC_OK, GMAC_PARAM, gmac_device::gmac_queue_list, gmac_start_transmission(), GMAC_TX_UNITSIZE, GMAC_TXD_LAST, GMAC_TXD_LEN_MASK, GMAC_TXD_WRAP, gmac_device::p_hw, gmac_queue::p_tx_dscr, gmac_tx_descriptor::status, gmac_queue::us_tx_head, gmac_queue::us_tx_list_size, and gmac_tx_descriptor::gmac_tx_status::val.
void gmac_handler | ( | gmac_device_t * | p_gmac_dev, |
gmac_quelist_t | queue_idx | ||
) |
GMAC Interrupt handler.
p_gmac_dev | Pointer to GMAC device instance. |
References CIRC_CNT, CIRC_EMPTY, circ_inc(), CIRC_SPACE, gmac_queue::func_rx_cb, gmac_queue::func_tx_cb_list, gmac_queue::func_wakeup_cb, gmac_clear_rx_status(), gmac_clear_tx_status(), gmac_enable_transmit(), gmac_get_interrupt_mask(), gmac_get_interrupt_status(), gmac_get_priority_interrupt_status(), gmac_get_rx_status(), gmac_get_tx_status(), GMAC_QUE_0, gmac_device::gmac_queue_list, gmac_reset_tx_mem(), GMAC_TXD_USED, gmac_device::p_hw, gmac_queue::p_tx_dscr, pdFALSE, gmac_tx_descriptor::status, gmac_queue::uc_wakeup_threshold, gmac_queue::us_tx_head, gmac_queue::us_tx_list_size, gmac_queue::us_tx_tail, gmac_tx_descriptor::gmac_tx_status::val, and xSemaphoreGiveFromISR.
|
static |
Initialize the allocated buffer lists for GMAC driver to transfer data.
Must be invoked after gmac_dev_init() but before RX/TX starts.
p_gmac | Pointer to GMAC instance. |
p_gmac_dev | Pointer to GMAC device instance. |
p_dev_mm | Pointer to the GMAC memory management control block. |
p_tx_cb | Pointer to allocated TX callback list. |
References gmac_queue::func_tx_cb_list, GMAC_OK, GMAC_PARAM, gmac_device::gmac_queue_list, gmac_reset_rx_mem(), gmac_reset_tx_mem(), NULL, gmac_queue::p_rx_buffer, gmac_dev_mem::p_rx_buffer, gmac_queue::p_rx_dscr, gmac_dev_mem::p_rx_dscr, gmac_queue::p_tx_buffer, gmac_dev_mem::p_tx_buffer, gmac_queue::p_tx_dscr, gmac_dev_mem::p_tx_dscr, gmac_queue::us_rx_list_size, gmac_dev_mem::us_rx_size, gmac_queue::us_tx_list_size, and gmac_dev_mem::us_tx_size.
Referenced by gmac_init_queue().
|
static |
References gmac_rx_descriptor::addr, gmac_tx_descriptor::addr, gmac_enable_interrupt(), gmac_enable_receive(), gmac_enable_statistics_write(), gmac_enable_transmit(), gmac_get_interrupt_status(), gmac_get_priority_interrupt_status(), gmac_init_mem(), GMAC_QUE_0, GMAC_RXD_ADDR_MASK, GMAC_RXD_WRAP, gmac_set_rx_priority_queue(), gmac_set_tx_priority_queue(), GMAC_TXD_USED, GMAC_TXD_WRAP, gs_rx_desc, gs_rx_desc_null, gs_tx_callback, gs_tx_desc, gs_tx_desc_null, gs_uc_rx_buffer, gs_uc_tx_buffer, gmac_dev_mem::p_rx_buffer, gmac_dev_mem::p_rx_dscr, gmac_dev_mem::p_tx_buffer, gmac_dev_mem::p_tx_dscr, gmac_rx_descriptor::status, gmac_tx_descriptor::status, gmac_dev_mem::us_rx_size, gmac_dev_mem::us_tx_size, gmac_rx_descriptor::gmac_rx_addr::val, gmac_rx_descriptor::gmac_rx_status::val, and gmac_tx_descriptor::gmac_tx_status::val.
Referenced by gmac_dev_init().
uint8_t gmac_phy_read | ( | Gmac * | p_gmac, |
uint8_t | uc_phy_address, | ||
uint8_t | uc_address, | ||
uint32_t * | p_value | ||
) |
Read the PHY register.
p_gmac | Pointer to the GMAC instance. |
uc_phy_address | PHY address. |
uc_address | Register address. |
p_value | Pointer to a 32-bit location to store read data. |
GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
References gmac_get_phy_data(), gmac_maintain_phy(), GMAC_OK, gmac_phy_wait(), and GMAC_TIMEOUT.
Referenced by ethernet_phy_auto_negotiate(), ethernet_phy_find_valid(), ethernet_phy_reset(), and ethernet_phy_set_link().
|
static |
Wait PHY operation to be completed.
p_gmac | HW controller address. |
ul_retry | The retry times. |
Return GMAC_OK if the operation is completed successfully.
References gmac_is_phy_idle(), GMAC_OK, and GMAC_TIMEOUT.
Referenced by gmac_phy_read(), and gmac_phy_write().
uint8_t gmac_phy_write | ( | Gmac * | p_gmac, |
uint8_t | uc_phy_address, | ||
uint8_t | uc_address, | ||
uint32_t | ul_value | ||
) |
Write the PHY register.
p_gmac | Pointer to the GMAC instance. |
uc_phy_address | PHY Address. |
uc_address | Register Address. |
ul_value | Data to write, actually 16-bit data. |
GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
References gmac_maintain_phy(), GMAC_OK, gmac_phy_wait(), and GMAC_TIMEOUT.
Referenced by ethernet_phy_auto_negotiate(), and ethernet_phy_reset().
|
static |
Disable receiver, reset registers and descriptor list.
p_dev | Pointer to GMAC Driver instance. |
References gmac_rx_descriptor::addr, gmac_enable_receive(), GMAC_QUE_0, gmac_device::gmac_queue_list, GMAC_RX_UNITSIZE, GMAC_RXD_ADDR_MASK, GMAC_RXD_WRAP, gmac_set_rx_priority_queue(), gmac_set_rx_queue(), gmac_device::p_hw, gmac_queue::p_rx_buffer, gmac_queue::p_rx_dscr, gmac_rx_descriptor::status, gmac_queue::us_rx_idx, gmac_queue::us_rx_list_size, gmac_rx_descriptor::gmac_rx_addr::val, and gmac_rx_descriptor::gmac_rx_status::val.
Referenced by gmac_dev_reset(), and gmac_init_mem().
|
static |
Disable transfer, reset registers and descriptor lists.
p_dev | Pointer to GMAC driver instance. |
References gmac_tx_descriptor::addr, CIRC_CLEAR, gmac_enable_transmit(), GMAC_QUE_0, gmac_device::gmac_queue_list, gmac_set_tx_priority_queue(), gmac_set_tx_queue(), GMAC_TX_UNITSIZE, GMAC_TXD_USED, GMAC_TXD_WRAP, gmac_device::p_hw, gmac_queue::p_tx_buffer, gmac_queue::p_tx_dscr, gmac_tx_descriptor::status, gmac_queue::us_tx_head, gmac_queue::us_tx_list_size, gmac_queue::us_tx_tail, and gmac_tx_descriptor::gmac_tx_status::val.
Referenced by gmac_dev_reset(), gmac_handler(), and gmac_init_mem().
|
static |
Referenced by gmac_init_queue().
|
static |
RX descriptors lists.
Referenced by gmac_init_queue().
|
static |
TX callback lists.
Referenced by gmac_init_queue().
|
static |
Referenced by gmac_init_queue().
|
static |
TX descriptor lists.
Referenced by gmac_init_queue().
|
static |
Receive Buffer.
Referenced by gmac_init_queue().
|
static |
Send Buffer.
Section 3.6 of AMBA 2.0 spec states that burst should not cross the 1K Boundaries. Receive buffer manager write operations are burst of 2 words => 3 lsb bits of the address shall be set to 0.
Referenced by gmac_init_queue().