Robobo
emac.h File Reference

EMAC (Ethernet MAC) driver for SAM. More...

#include "../chip.h"

Go to the source code of this file.

Classes

struct  emac_rx_descriptor
 
union  emac_rx_descriptor::emac_rx_addr
 
struct  emac_rx_descriptor::emac_rx_addr::emac_rx_addr_bm
 
union  emac_rx_descriptor::emac_rx_status
 
struct  emac_rx_descriptor::emac_rx_status::emac_rx_status_bm
 
union  emac_rx_addr
 
struct  emac_rx_addr::emac_rx_addr_bm
 
union  emac_rx_status
 
struct  emac_rx_status::emac_rx_status_bm
 
struct  emac_tx_descriptor
 
union  emac_tx_descriptor::emac_tx_status
 
struct  emac_tx_descriptor::emac_tx_status::emac_tx_status_bm
 
union  emac_tx_status
 
struct  emac_tx_status::emac_tx_status_bm
 
struct  emac_options
 Input parameters when initializing the emac module mode. More...
 
struct  emac_device
 

Macros

#define EMAC_RXD_ADDR_MASK   0xFFFFFFFC
 
#define EMAC_RXD_WRAP   (1ul << 1)
 
#define EMAC_RXD_OWNERSHIP   (1ul << 0)
 
#define EMAC_RXD_BROADCAST   (1ul << 31)
 
#define EMAC_RXD_MULTIHASH   (1ul << 30)
 
#define EMAC_RXD_UNIHASH   (1ul << 29)
 
#define EMAC_RXD_EXTADDR   (1ul << 28)
 
#define EMAC_RXD_ADDR1   (1ul << 26)
 
#define EMAC_RXD_ADDR2   (1ul << 25)
 
#define EMAC_RXD_ADDR3   (1ul << 24)
 
#define EMAC_RXD_ADDR4   (1ul << 23)
 
#define EMAC_RXD_TYPE   (1ul << 22)
 
#define EMAC_RXD_VLAN   (1ul << 21)
 
#define EMAC_RXD_PRIORITY   (1ul << 20)
 
#define EMAC_RXD_PRIORITY_MASK   (3ul << 17)
 
#define EMAC_RXD_CFI   (1ul << 16)
 
#define EMAC_RXD_EOF   (1ul << 15)
 
#define EMAC_RXD_SOF   (1ul << 14)
 
#define EMAC_RXD_OFFSET_MASK
 
#define EMAC_RXD_LEN_MASK   (0xFFF)
 
#define EMAC_RXD_LENJUMBO_MASK   (0x3FFF)
 
#define EMAC_TXD_USED   (1ul << 31)
 
#define EMAC_TXD_WRAP   (1ul << 30)
 
#define EMAC_TXD_ERROR   (1ul << 29)
 
#define EMAC_TXD_UNDERRUN   (1ul << 28)
 
#define EMAC_TXD_EXHAUSTED   (1ul << 27)
 
#define EMAC_TXD_NOCRC   (1ul << 16)
 
#define EMAC_TXD_LAST   (1ul << 15)
 
#define EMAC_TXD_LEN_MASK   (0x7FF)
 
#define EMAC_FRAME_LENTGH_MAX   1536
 
#define EMAC_RX_UNITSIZE   128
 
#define EMAC_TX_UNITSIZE   1518
 
#define EMAC_CLOCK_SPEED_160MHZ   (160*1000*1000)
 
#define EMAC_CLOCK_SPEED_80MHZ   (80*1000*1000)
 
#define EMAC_CLOCK_SPEED_40MHZ   (40*1000*1000)
 
#define EMAC_CLOCK_SPEED_20MHZ   (20*1000*1000)
 
#define EMAC_MAN_CODE_VALUE   (10)
 
#define EMAC_MAN_SOF_VALUE   (1)
 
#define EMAC_MAN_RW_TYPE   (2)
 
#define EMAC_MAN_READ_ONLY   (1)
 
#define EMAC_ADDR_LENGTH   (6)
 

Typedefs

typedef struct emac_options emac_options_t
 Input parameters when initializing the emac module mode.
 
typedef void(* emac_dev_tx_cb_t) (uint32_t ul_status)
 
typedef void(* emac_dev_wakeup_cb_t) (void)
 
typedef struct emac_device emac_device_t
 

Enumerations

enum  emac_status_t {
  EMAC_OK = 0, EMAC_TIMEOUT = 1, EMAC_TX_BUSY, EMAC_RX_NULL,
  EMAC_SIZE_TOO_SMALL, EMAC_PARAM, EMAC_INVALID = 0xFF
}
 Return codes for EMAC APIs. More...
 

Functions

struct emac_rx_descriptor __attribute__ ((packed, aligned(8))) emac_rx_descriptor_t
 
uint8_t emac_phy_read (Emac *p_emac, uint8_t uc_phy_address, uint8_t uc_address, uint32_t *p_value)
 
uint8_t emac_phy_write (Emac *p_emac, uint8_t uc_phy_address, uint8_t uc_address, uint32_t ul_value)
 
void emac_dev_init (Emac *p_emac, emac_device_t *p_emac_dev, emac_options_t *p_opt)
 
uint32_t emac_dev_read (emac_device_t *p_emac_dev, uint8_t *p_frame, uint32_t ul_frame_size, uint32_t *p_rcv_size)
 
uint32_t emac_dev_write (emac_device_t *p_emac_dev, void *p_buffer, uint32_t ul_size, emac_dev_tx_cb_t func_tx_cb)
 
uint32_t emac_dev_get_tx_load (emac_device_t *p_emac_dev)
 
void emac_dev_set_rx_callback (emac_device_t *p_emac_dev, emac_dev_tx_cb_t func_rx_cb)
 
uint8_t emac_dev_set_tx_wakeup_callback (emac_device_t *p_emac_dev, emac_dev_wakeup_cb_t func_wakeup, uint8_t uc_threshold)
 
void emac_dev_reset (emac_device_t *p_emac_dev)
 
void emac_handler (emac_device_t *p_emac_dev)
 

Variables

union emac_rx_addr addr
 
union emac_rx_status status
 

Detailed Description

EMAC (Ethernet MAC) driver for SAM.

Copyright (c) 2011-2012 Atmel Corporation. All rights reserved.

Macro Definition Documentation

#define EMAC_ADDR_LENGTH   (6)

EMAC address length

#define EMAC_CLOCK_SPEED_160MHZ   (160*1000*1000)

EMAC clock speed

#define EMAC_FRAME_LENTGH_MAX   1536

The MAC can support frame lengths up to 1536 bytes

#define EMAC_MAN_CODE_VALUE   (10)

EMAC maintain code default value

#define EMAC_MAN_READ_ONLY   (1)

EMAC maintain read only

#define EMAC_MAN_RW_TYPE   (2)

EMAC maintain read/write

#define EMAC_MAN_SOF_VALUE   (1)

EMAC maintain start of frame default value

#define EMAC_RX_UNITSIZE   128

Fixed size for RX buffer

#define EMAC_RXD_ADDR1   (1ul << 26)

Address 1 match

#define EMAC_RXD_ADDR2   (1ul << 25)

Address 2 match

#define EMAC_RXD_ADDR3   (1ul << 24)

Address 3 match

#define EMAC_RXD_ADDR4   (1ul << 23)

Address 4 match

#define EMAC_RXD_ADDR_MASK   0xFFFFFFFC

The buffer addresses written into the descriptors must be aligned, so the last few bits are zero. These bits have special meaning for the EMAC peripheral and cannot be used as part of the address.

#define EMAC_RXD_BROADCAST   (1ul << 31)

Broadcast detected

#define EMAC_RXD_CFI   (1ul << 16)

Concatenation Format Indicator only if bit 21 is set

#define EMAC_RXD_EOF   (1ul << 15)

End of frame

#define EMAC_RXD_EXTADDR   (1ul << 28)

External address match

#define EMAC_RXD_LEN_MASK   (0xFFF)

Length of frame including FCS (if selected)

#define EMAC_RXD_LENJUMBO_MASK   (0x3FFF)

Jumbo frame length

#define EMAC_RXD_MULTIHASH   (1ul << 30)

Multicast hash match

#define EMAC_RXD_OFFSET_MASK

Receive buffer offset

#define EMAC_RXD_OWNERSHIP   (1ul << 0)

Ownership bit

#define EMAC_RXD_PRIORITY   (1ul << 20)

Priority tag detected

#define EMAC_RXD_PRIORITY_MASK   (3ul << 17)

VLAN priority

#define EMAC_RXD_SOF   (1ul << 14)

Start of frame

#define EMAC_RXD_TYPE   (1ul << 22)

Type ID match

#define EMAC_RXD_UNIHASH   (1ul << 29)

Unicast hash match

#define EMAC_RXD_VLAN   (1ul << 21)

VLAN tag detected

#define EMAC_RXD_WRAP   (1ul << 1)

Wrap bit

#define EMAC_TX_UNITSIZE   1518

Size for ETH frame length

#define EMAC_TXD_ERROR   (1ul << 29)

Retry limit exceeded, error

#define EMAC_TXD_EXHAUSTED   (1ul << 27)

Buffer exhausted

#define EMAC_TXD_LAST   (1ul << 15)

Last buffer in frame

#define EMAC_TXD_LEN_MASK   (0x7FF)

Length of buffer

#define EMAC_TXD_NOCRC   (1ul << 16)

No CRC

#define EMAC_TXD_UNDERRUN   (1ul << 28)

Transmit underrun

#define EMAC_TXD_USED   (1ul << 31)

Frame is transmitted

#define EMAC_TXD_WRAP   (1ul << 30)

Last descriptor

Typedef Documentation

typedef void(* emac_dev_tx_cb_t) (uint32_t ul_status)

RX callback

typedef void(* emac_dev_wakeup_cb_t) (void)

Wakeup callback

typedef struct emac_device emac_device_t

EMAC driver structure.

Enumeration Type Documentation

Return codes for EMAC APIs.

Enumerator
EMAC_TIMEOUT 

Operation OK

EMAC_TX_BUSY 

EMAC operation timeout

EMAC_RX_NULL 

TX in progress

EMAC_SIZE_TOO_SMALL 

No data received

EMAC_PARAM 

Buffer size not enough

EMAC_INVALID 

Parameter error, TX packet invalid or RX size too small

Function Documentation

struct emac_tx_descriptor __attribute__ ( (packed, aligned(8))  )

Receive buffer descriptor struct

Transmit buffer descriptor struct

Variable Documentation

uint32_t addr

Address, Wrap & Ownership