1 /***********************************************************************//**
\r
2 * @file lpc17xx_emac.h
\r
3 * @brief Contains all macro definitions and function prototypes
\r
4 * support for Ethernet MAC firmware library on LPC17xx
\r
6 * @date 21. May. 2010
\r
7 * @author NXP MCU SW Application Team
\r
8 **************************************************************************
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * products. This software is supplied "AS IS" without any warranties.
\r
12 * NXP Semiconductors assumes no responsibility or liability for the
\r
13 * use of the software, conveys no license or title under any patent,
\r
14 * copyright, or mask work right to the product. NXP Semiconductors
\r
15 * reserves the right to make changes in the software without
\r
16 * notification. NXP Semiconductors also make no representation or
\r
17 * warranty that such application will be suitable for the specified
\r
18 * use without further testing or modification.
\r
19 **************************************************************************/
\r
21 /* Peripheral group ----------------------------------------------------------- */
\r
22 /** @defgroup EMAC EMAC
\r
23 * @ingroup LPC1700CMSIS_FwLib_Drivers
\r
27 #ifndef LPC18XX_EMAC_H_
\r
28 #define LPC18XX_EMAC_H_
\r
30 /* Includes ------------------------------------------------------------------- */
\r
31 #include "LPC18xx.h"
\r
40 #include "lpc_types.h"
\r
44 /* Interface Selection */
\r
45 #define MII 0 // =0 RMII - =1 MII
\r
47 /* End of Configuration */
\r
49 /* Descriptors Fields bits */
\r
50 #define OWN_BIT (1U<<31) /* Own bit in RDES0 & TDES0 */
\r
51 #define RX_END_RING (1<<15) /* Receive End of Ring bit in RDES1 */
\r
52 #define RX_NXTDESC_FLAG (1<<14) /* Second Address Chained bit in RDES1 */
\r
53 #define TX_LAST_SEGM (1<<29) /* Last Segment bit in TDES0 */
\r
54 #define RX_LAST_SEGM (1<<9)
\r
55 #define TX_FIRST_SEGM (1<<28) /* First Segment bit in TDES0 */
\r
56 #define RX_FIRST_SEGM (1<<8) /* First Segment bit in TDES0 */
\r
57 #define TX_END_RING (1<<21) /* Transmit End of Ring bit in TDES0 */
\r
58 #define TX_NXTDESC_FLAG (1<<20) /* Second Address Chained bit in TDES0 */
\r
60 /* EMAC Memory Buffer configuration for 16K Ethernet RAM */
\r
61 #define EMAC_ETH_MAX_FLEN ipETHERNET_FRAME_SIZE_TO_USE
\r
63 /* NOTE: EMAC_NUM_RX_FRAG is not used by the example FreeRTOS drivers - use
\r
64 configNUM_RX_ETHERNET_DMA_DESCRIPTORS. */
\r
65 #define EMAC_NUM_RX_FRAG 6 /**< Num.of RX Fragments */
\r
67 /* NOTE: EMAC_NUM_TX_FRAG is not used by the example FreeRTOS drivers - use
\r
68 configNUM_TX_ETHERNET_DMA_DESCRIPTORS. */
\r
69 #define EMAC_NUM_TX_FRAG 2 /**< Num.of TX Fragments */
\r
71 /* EMAC Control and Status bits */
\r
72 #define MAC_RX_ENABLE (1<<2) /* Receiver Enable in MAC_CONFIG reg */
\r
73 #define MAC_TX_ENABLE (1<<3) /* Transmitter Enable in MAC_CONFIG reg */
\r
74 #define MAC_PADCRC_STRIP (1<<7) /* Automatic Pad-CRC Stripping in MAC_CONFIG reg */
\r
75 #define MAC_DUPMODE (1<<11) /* Duplex Mode in MAC_CONFIG reg */
\r
76 #define MAC_100MPS (1<<14) /* Speed is 100Mbps in MAC_CONFIG reg */
\r
77 #define MAC_PROMISCUOUS (1U<<0) /* Promiscuous Mode bit in MAC_FRAME_FILTER reg */
\r
78 #define MAC_DIS_BROAD (1U<<5) /* Disable Broadcast Frames bit in MAC_FRAME_FILTER reg */
\r
79 #define MAC_RECEIVEALL (1U<<31) /* Receive All bit in MAC_FRAME_FILTER reg */
\r
80 #define DMA_SOFT_RESET 0x01 /* Software Reset bit in DMA_BUS_MODE reg */
\r
81 #define DMA_SS_RECEIVE (1<<1) /* Start/Stop Receive bit in DMA_OP_MODE reg */
\r
82 #define DMA_SS_TRANSMIT (1<<13) /* Start/Stop Transmission bit in DMA_OP_MODE reg */
\r
83 #define DMA_INT_TRANSMIT (1<<0) /* Transmit Interrupt Enable bit in DMA_INT_EN reg */
\r
84 #define DMA_INT_OVERFLOW (1<<4) /* Overflow Interrupt Enable bit in DMA_INT_EN reg */
\r
85 #define DMA_INT_UNDERFLW (1<<5) /* Underflow Interrupt Enable bit in DMA_INT_EN reg */
\r
86 #define DMA_INT_RECEIVE (1<<6) /* Receive Interrupt Enable bit in DMA_INT_EN reg */
\r
87 #define DMA_INT_ABN_SUM (1<<15) /* Abnormal Interrupt Summary Enable bit in DMA_INT_EN reg */
\r
88 #define DMA_INT_NOR_SUM (1<<16) /* Normal Interrupt Summary Enable bit in DMA_INT_EN reg */
\r
90 /* MII Management Command Register */
\r
91 #define GMII_READ (0<<1) /* GMII Read PHY */
\r
92 #define GMII_WRITE (1<<1) /* GMII Write PHY */
\r
93 #define GMII_BUSY 0x00000001 /* GMII is Busy / Start Read/Write */
\r
94 #define MII_WR_TOUT 0x00050000 /* MII Write timeout count */
\r
95 #define MII_RD_TOUT 0x00050000 /* MII Read timeout count */
\r
97 /* MII Management Address Register */
\r
98 #define MADR_PHY_ADR 0x00001F00 /* PHY Address Mask */
\r
100 /* LAN8720 PHY Registers */
\r
101 #define PHY_REG_BMCR 0x00 /* Basic Mode Control Register */
\r
102 #define PHY_REG_BMSR 0x01 /* Basic Mode Status Register */
\r
103 #define PHY_REG_IDR1 0x02 /* PHY Identifier 1 */
\r
104 #define PHY_REG_IDR2 0x03 /* PHY Identifier 2 */
\r
105 #define PHY_REG_ANAR 0x04 /* Auto-Negotiation Advertisement */
\r
106 #define PHY_REG_ANLPAR 0x05 /* Auto-Neg. Link Partner Abitily */
\r
107 #define PHY_REG_ANER 0x06 /* Auto-Neg. Expansion Register */
\r
108 #define PHY_REG_ANNPTR 0x07 /* Auto-Neg. Next Page TX */
\r
110 /* LAN8720 PHY Speed identify */
\r
111 #define PHY_REG_SPCON 0x1f /* Speed indication Register */
\r
112 #define PHY_REG_HCDSPEED_MASK 0x1c /* Speed indication Register mask*/
\r
113 #define PHY_REG_HCDSPEED_10MB_HALFD 0x04 /* Speed is 10Mbps HALF-duplex */
\r
114 #define PHY_REG_HCDSPEED_10MB_FULLD 0x14 /* Speed is 10Mbps FULL-duplex */
\r
115 #define PHY_REG_HCDSPEED_100MB_HALFD 0x08 /* Speed is 100Mbps HALF-duplex */
\r
116 #define PHY_REG_HCDSPEED_100MB_FULLD 0x18 /* Speed is 100Mbps FULL-duplex */
\r
119 /* PHY Extended Registers */
\r
120 #define PHY_REG_STS 0x10 /* Status Register */
\r
121 #define PHY_REG_MICR 0x11 /* MII Interrupt Control Register */
\r
122 #define PHY_REG_MISR 0x12 /* MII Interrupt Status Register */
\r
123 #define PHY_REG_FCSCR 0x14 /* False Carrier Sense Counter */
\r
124 #define PHY_REG_RECR 0x15 /* Receive Error Counter */
\r
125 #define PHY_REG_PCSR 0x16 /* PCS Sublayer Config. and Status */
\r
126 #define PHY_REG_RBR 0x17 /* RMII and Bypass Register */
\r
127 #define PHY_REG_LEDCR 0x18 /* LED Direct Control Register */
\r
128 #define PHY_REG_PHYCR 0x19 /* PHY Control Register */
\r
129 #define PHY_REG_10BTSCR 0x1A /* 10Base-T Status/Control Register */
\r
130 #define PHY_REG_CDCTRL1 0x1B /* CD Test Control and BIST Extens. */
\r
131 #define PHY_REG_EDCR 0x1D /* Energy Detect Control Register */
\r
133 /* PHY Control and Status bits */
\r
134 #define PHY_FULLD_100M 0x2100 /* Full Duplex 100Mbit */
\r
135 #define PHY_HALFD_100M 0x2000 /* Half Duplex 100Mbit */
\r
136 #define PHY_FULLD_10M 0x0100 /* Full Duplex 10Mbit */
\r
137 #define PHY_HALFD_10M 0x0000 /* Half Duplex 10MBit */
\r
138 #define PHY_AUTO_NEG 0x1000 /* Select Auto Negotiation */
\r
139 #define PHY_AUTO_NEG_DONE 0x0020 /* AutoNegotiation Complete in BMSR PHY reg */
\r
140 #define PHY_BMCR_RESET 0x8000 /* Reset bit at BMCR PHY reg */
\r
141 #define LINK_VALID_STS 0x0001 /* Link Valid Status at REG_STS PHY reg */
\r
142 #define FULL_DUP_STS 0x0004 /* Full Duplex Status at REG_STS PHY reg */
\r
143 #define SPEED_10M_STS 0x0002 /* 10Mbps Status at REG_STS PHY reg */
\r
145 #define DP83848C_DEF_ADR 0x01 /* Default PHY device address */
\r
146 #define DP83848C_ID 0x20005C90 /* PHY Identifier (without Rev. info */
\r
147 #define LAN8720_ID 0x0007C0F1 /* PHY Identifier for SMSC PHY */
\r
150 #define ETHERNET_RST 22 /* Reset Output for EMAC at RGU */
\r
151 #define RMII_SELECT 0x04 /* Select RMII in EMACCFG */
\r
155 * @brief EMAC configuration structure definition
\r
158 uint32_t Mode; /**< Supported EMAC PHY device speed, should be one of the following:
\r
160 - EMAC_MODE_10M_FULL
\r
161 - EMAC_MODE_10M_HALF
\r
162 - EMAC_MODE_100M_FULL
\r
163 - EMAC_MODE_100M_HALF
\r
165 uint8_t *pbEMAC_Addr; /**< Pointer to EMAC Station address that contains 6-bytes
\r
166 of MAC address, it must be sorted in order (bEMAC_Addr[0]..[5])
\r
170 /* Descriptor and status formats ---------------------------------------------- */
\r
172 * @brief RX Descriptor structure type definition
\r
175 uint32_t Status; /**< Receive Status Descriptor */
\r
176 uint32_t Ctrl; /**< Receive Control Descriptor */
\r
177 uint32_t Packet; /**< Receive Packet Descriptor */
\r
178 uint32_t NextDescripter;/**< Receive Next Descriptor Address */
\r
182 * @brief RX Status structure type definition
\r
185 uint32_t Info; /**< Receive Information Status */
\r
186 uint32_t HashCRC; /**< Receive Hash CRC Status */
\r
190 * @brief TX Descriptor structure type definition
\r
193 uint32_t Status; /**< Transmit Status Descriptor */
\r
194 uint32_t Ctrl; /**< Transmit Control Descriptor */
\r
195 uint32_t Packet; /**< Transmit Packet Descriptor */
\r
196 uint32_t NextDescripter; /**< Transmit Next Descriptor Address */
\r
200 * @brief TX Status structure type definition
\r
203 uint32_t Info; /**< Transmit Information Status */
\r
208 * @brief TX Data Buffer structure definition
\r
211 uint32_t ulDataLen; /**< Data length */
\r
212 uint32_t *pbDataBuf; /**< A word-align data pointer to data buffer */
\r
213 } EMAC_PACKETBUF_Type;
\r
218 portBASE_TYPE EMAC_Init(EMAC_CFG_Type *EMAC_ConfigStruct);
\r
219 int32_t EMAC_UpdatePHYStatus(void);
\r
220 uint32_t EMAC_GetReceiveDataSize(void);
\r
221 void EMAC_StartTransmitNextBuffer( uint32_t ulLength );
\r
222 void EMAC_SetNextPacketToSend( uint8_t * pucBuffer );
\r
223 void EMAC_NextPacketToRead( xNetworkBufferDescriptor_t *pxNetworkBuffer );
\r
224 void EMAC_UpdateRxConsumeIndex(void);
\r
225 portBASE_TYPE EMAC_CheckReceiveIndex(void);
\r
226 portBASE_TYPE EMAC_CheckTransmitIndex(void);
\r
232 #endif /* LPC18XX_EMAC_H_ */
\r
238 /* --------------------------------- End Of File ------------------------------ */
\r