⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adam.h

📁 altera epxa1的例子程序
💻 H
字号:
#ifndef _ADAM_
#define _ADAM_

#ifndef BASETYPES
#define BASETYPES
typedef unsigned long ULONG;
typedef ULONG *PULONG;
typedef unsigned short USHORT;
typedef USHORT *PUSHORT;
typedef unsigned char UCHAR;
typedef UCHAR *PUCHAR;
typedef char *PSZ;
#endif  /* !BASETYPES */

// ADAM is mapped onto PLD0 space
#define ADAM_BASE               EXC_PLD_BLOCK0_BASE
#define PLD_AHB_CLK_FREQUENCY   (32768000)

//#define DEBUG_IO        0       // enable putch() -> debug_io port
#define SERIAL          1       // enable putch() -> serial port
#define PRINTF          1       // enable printf()s
//#define SOFT_UART       1       // enable soft uart


#define write_csr(addr, data)   *(volatile ULONG *)(addr) = (ULONG)data
#define read_csr(addr)          *(volatile ULONG *)(addr)


#define MAC_MAC_CTL             (ADAM_BASE + 0x0000)
#define MAC_ARC_CTL             (ADAM_BASE + 0x0004)
#define MAC_TX_CTL              (ADAM_BASE + 0x0008)
#define MAC_TX_STAT             (ADAM_BASE + 0x000c)
#define MAC_RX_CTL              (ADAM_BASE + 0x0010)
#define MAC_RX_STAT             (ADAM_BASE + 0x0014)
#define MAC_MD_DATA             (ADAM_BASE + 0x0018)
#define MAC_MD_CA               (ADAM_BASE + 0x001c)
#define MAC_ARC_ENA             (ADAM_BASE + 0x0028)
#define MAC_PROM_CTL            (ADAM_BASE + 0x002c)
#define MAC_PROM_DATA           (ADAM_BASE + 0x0030)
#define MAC_MISS_CNT            (ADAM_BASE + 0x003c)

#define DMA_CTL                 (ADAM_BASE + 0x0100)
#define DMA_TX_FRMPTR           (ADAM_BASE + 0x0104)
#define DMA_TX_THRESH           (ADAM_BASE + 0x0308)
#define DMA_TX_TPOLLCTR         (ADAM_BASE + 0x030c)
#define DMA_BLFRMPTR            (ADAM_BASE + 0x0110)
#define DMA_RX_FRAGSIZE         (ADAM_BASE + 0x0114)
#define DMA_INT_EN              (ADAM_BASE + 0x0118)
#define DMA_FDA_BASE            (ADAM_BASE + 0x011c)
#define DMA_FDA_LIMIT           (ADAM_BASE + 0x0120)
#define DMA_INT_SRC             (ADAM_BASE + 0x0124)

#define MAC_ARC_ADDR            (ADAM_BASE + 0x0160)
#define MAC_ARC_DATA            (ADAM_BASE + 0x0364)

#define MAC_PAUSE_CNT           (ADAM_BASE + 0x0040)
#define MAC_REMPAUSE_CNT        (ADAM_BASE + 0x0044)
#define MAC_TX_CTLFRM_STATUS    (ADAM_BASE + 0x0348)

#define RMON_COUNT_DATA         (ADAM_BASE + 0x0080)
#define RMON_COUNT_ACCESS       (ADAM_BASE + 0x0084)
#define RMON_TX_INT_ENA         (ADAM_BASE + 0x0088)
#define RMON_RX_INT_ENA         (ADAM_BASE + 0x008C)

#define RMON_CMD_NONE           0x00000000
#define RMON_CMD_WRITE          0x00000100
#define RMON_CMD_READ           0x00000200
#define RMON_CMD_READCLR        0x00000300
#define RMON_CMD_BANKSWAP       0x00000400
#define RMON_CMD_CLRINT         0x00000500
#define RMON_CMD_CLRTX          0x00000600
#define RMON_CMD_CLRRX          0x00000700

#define RMON_STATUS_BANK        0x00000800
#define RMON_STATUS_BANKBSY     0x00001000
#define RMON_STATUS_INT         0x00002000
#define RMON_STATUS_CLRBSY      0x00004000






#define TX_DESC         EXC_SPSRAM_BLOCK1_BASE
#define NUM_TX_DESC     0x200
#define NUM_TX_BUFFS    6               //minimum = 2, must be even number ...
#define TX_BUFFER       (EXC_SDRAM_BLOCK1_BASE)

#define RX_BL_DESC      (TX_BUFFER + (0x200000))
#define NUM_RX_DESC     0x4
#define NUM_RX_BUFFS    0x3fe           //minimum = 2, must be even number ... max = 3fe ???
#define RX_BUFFER_LEN   0x600
#define RX_BUFFER       (TX_BUFFER +(0x2000000))

#define RX_FDA_DESC     (TX_DESC + (0x10000))
#define RX_FDA_LIMIT    0x8000          // approx # of rx buffs
//================================


#define PROMISCUOUS 0x01
#define MULTICAST   0x02
#define BROADCAST   0x04
#define UNICAST     0x10

typedef struct
{
    ULONG debug;
    int   nummacs;
    UCHAR macaddr[0x80];
    UCHAR arcmode;
    ULONG fullduplex;

// some descriptor stuff
    ULONG tx_desc;
    ULONG tx_desc_done;
    ULONG rx_bl_desc;
    ULONG rx_fda_desc;

    ULONG tx_desc_base;
    ULONG tx_num_descs;
    ULONG tx_num_buffs;

    ULONG rx_bl_desc_base;
    ULONG rx_buffer_base;
    ULONG rx_buffer_length;
    ULONG rx_num_descs;
    ULONG rx_num_buffs;

    ULONG rx_fda_desc_base;
    ULONG rx_fda_limit;
} type_eth_descriptors;

typedef int (*rx_callback_proc)(void *rbuf, int rlen, void *context);

int eth_config(type_eth_descriptors *eth);
int eth_init(type_eth_descriptors *eth);
int eth_transmit(type_eth_descriptors *eth, void *tbuf, int tlen, int wait);
int eth_pause(type_eth_descriptors *eth, USHORT slots);
int eth_transmit_status(type_eth_descriptors *eth);
int eth_receive(type_eth_descriptors *eth, rx_callback_proc rx_callback, void *context);
int eth_mdread(int addr, int reg);
int eth_mdwrite(int addr, int reg, int wdata);
int eth_rmon_getstats(int banksel, ULONG *sdata, int clear, int view);


#endif // _ADAM_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -