Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Ethernet PHY Media Access Controller

See Quickstart guide for GMAC driver..

Driver for the GMAC PHY (Ethernet Media Access Controller). This file contains basic functions for the GMAC PHY.

Dependencies

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.

Dependencies

This driver does not depend on other modules.

Modules

 
 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))

typedef struct gmac_dev_mem gmac_dev_mem_t

GMAC device memory management struct.

static void circ_inc ( uint16_t *  headortail,
uint32_t  size 
)
static

Increment head or tail.

Referenced by gmac_dev_read(), gmac_dev_write(), gmac_dev_write_nocopy(), and gmac_handler().

uint32_t gmac_dev_get_tx_load ( gmac_device_t p_gmac_dev,
gmac_quelist_t  queue_idx 
)

Get current load of transmit.

Parameters
p_gmac_devPointer to the GMAC device instance.
Returns
Current load of transmit.

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 
)
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.

Parameters
p_gmac_devPointer to the GMAC device instance.
p_frameAddress of the frame buffer.
ul_frame_sizeLength of the frame.
p_rcv_sizeReceived frame size.
Returns
GMAC_OK if receiving frame successfully, otherwise failed.

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.

Parameters
p_gmac_devPointer 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.

Parameters
p_gmac_devPointer to the GMAC device instance.
Returns
The number of RX buffer full.

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.

Parameters
p_gmac_devPointer to the GMAC device instance.
func_tx_cbReceive 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.

Parameters
p_gmac_devPointer to GMAC device instance.
func_wakeupPointer to wakeup callback function.
uc_thresholdNumber of free transmit descriptor before wakeup callback invoked.
Returns
GMAC_OK, GMAC_PARAM on parameter error.

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.

Parameters
p_gmac_devPointer to the GMAC device instance.
Returns
The number of TX buffer used.

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.

Parameters
p_gmac_devPointer to the GMAC device instance.
p_bufferPointer to the data buffer.
ul_sizeLength of the frame.
func_tx_cbTransmit callback function.
Returns
Length sent.

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.

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 
)
static

Initialize the allocated buffer lists for GMAC driver to transfer data.

Must be invoked after gmac_dev_init() but before RX/TX starts.

Note
If input address is not 8-byte aligned, the address is automatically adjusted and the list size is reduced by one.
Parameters
p_gmacPointer to GMAC instance.
p_gmac_devPointer to GMAC device instance.
p_dev_mmPointer to the GMAC memory management control block.
p_tx_cbPointer to allocated TX callback list.
Returns
GMAC_OK or GMAC_PARAM.

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().

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.

Parameters
p_gmacPointer to the GMAC instance.
uc_phy_addressPHY address.
uc_addressRegister address.
p_valuePointer 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 uint8_t gmac_phy_wait ( Gmac *  p_gmac,
const uint32_t  ul_retry 
)
static

Wait PHY operation to be completed.

Parameters
p_gmacHW controller address.
ul_retryThe 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.

Parameters
p_gmacPointer to the GMAC instance.
uc_phy_addressPHY Address.
uc_addressRegister Address.
ul_valueData 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().

gmac_rx_descriptor_t gs_rx_desc[GMAC_RX_BUFFERS]
static

Referenced by gmac_init_queue().

gmac_rx_descriptor_t gs_rx_desc_null
static

RX descriptors lists.

Referenced by gmac_init_queue().

gmac_dev_tx_cb_t gs_tx_callback[GMAC_TX_BUFFERS]
static

TX callback lists.

Referenced by gmac_init_queue().

gmac_tx_descriptor_t gs_tx_desc[GMAC_TX_BUFFERS]
static

Referenced by gmac_init_queue().

gmac_tx_descriptor_t gs_tx_desc_null
static

TX descriptor lists.

Referenced by gmac_init_queue().

uint8_t gs_uc_rx_buffer[GMAC_RX_BUFFERS *GMAC_RX_UNITSIZE]
static

Receive Buffer.

Referenced by gmac_init_queue().

uint8_t gs_uc_tx_buffer[GMAC_TX_BUFFERS *GMAC_TX_UNITSIZE]
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().