31#ifndef _APM32F4XX_ETH_DRIVER_H
32#define _APM32F4XX_ETH_DRIVER_H
38#ifndef APM32F4XX_ETH_TX_BUFFER_COUNT
39 #define APM32F4XX_ETH_TX_BUFFER_COUNT 3
40#elif (APM32F4XX_ETH_TX_BUFFER_COUNT < 1)
41 #error APM32F4XX_ETH_TX_BUFFER_COUNT parameter is not valid
45#ifndef APM32F4XX_ETH_TX_BUFFER_SIZE
46 #define APM32F4XX_ETH_TX_BUFFER_SIZE 1536
47#elif (APM32F4XX_ETH_TX_BUFFER_SIZE != 1536)
48 #error APM32F4XX_ETH_TX_BUFFER_SIZE parameter is not valid
52#ifndef APM32F4XX_ETH_RX_BUFFER_COUNT
53 #define APM32F4XX_ETH_RX_BUFFER_COUNT 6
54#elif (APM32F4XX_ETH_RX_BUFFER_COUNT < 1)
55 #error APM32F4XX_ETH_RX_BUFFER_COUNT parameter is not valid
59#ifndef APM32F4XX_ETH_RX_BUFFER_SIZE
60 #define APM32F4XX_ETH_RX_BUFFER_SIZE 1536
61#elif (APM32F4XX_ETH_RX_BUFFER_SIZE != 1536)
62 #error APM32F4XX_ETH_RX_BUFFER_SIZE parameter is not valid
66#ifndef APM32F4XX_ETH_IRQ_PRIORITY_GROUPING
67 #define APM32F4XX_ETH_IRQ_PRIORITY_GROUPING 3
68#elif (APM32F4XX_ETH_IRQ_PRIORITY_GROUPING < 0)
69 #error APM32F4XX_ETH_IRQ_PRIORITY_GROUPING parameter is not valid
73#ifndef APM32F4XX_ETH_IRQ_GROUP_PRIORITY
74 #define APM32F4XX_ETH_IRQ_GROUP_PRIORITY 12
75#elif (APM32F4XX_ETH_IRQ_GROUP_PRIORITY < 0)
76 #error APM32F4XX_ETH_IRQ_GROUP_PRIORITY parameter is not valid
80#ifndef APM32F4XX_ETH_IRQ_SUB_PRIORITY
81 #define APM32F4XX_ETH_IRQ_SUB_PRIORITY 0
82#elif (APM32F4XX_ETH_IRQ_SUB_PRIORITY < 0)
83 #error APM32F4XX_ETH_IRQ_SUB_PRIORITY parameter is not valid
87#define ETH_CFG_CST 0x02000000
88#define ETH_CFG_WDTDIS 0x00800000
89#define ETH_CFG_JDIS 0x00400000
90#define ETH_CFG_IFG 0x000E0000
91#define ETH_CFG_DISCRS 0x00010000
92#define ETH_CFG_RESERVED15 0x00008000
93#define ETH_CFG_SSEL 0x00004000
94#define ETH_CFG_DISRXO 0x00002000
95#define ETH_CFG_LBM 0x00001000
96#define ETH_CFG_DM 0x00000800
97#define ETH_CFG_IPC 0x00000400
98#define ETH_CFG_DISR 0x00000200
99#define ETH_CFG_ACS 0x00000080
100#define ETH_CFG_BL 0x00000060
101#define ETH_CFG_DC 0x00000010
102#define ETH_CFG_TXEN 0x00000008
103#define ETH_CFG_RXEN 0x00000004
106#define ETH_FRAF_RXA 0x80000000
107#define ETH_FRAF_HPF 0x00000400
108#define ETH_FRAF_SAFEN 0x00000200
109#define ETH_FRAF_SAIF 0x00000100
110#define ETH_FRAF_PCTRLF 0x000000C0
111#define ETH_FRAF_DISBF 0x00000020
112#define ETH_FRAF_PM 0x00000010
113#define ETH_FRAF_DAIF 0x00000008
114#define ETH_FRAF_HMC 0x00000004
115#define ETH_FRAF_HUC 0x00000002
116#define ETH_FRAF_PR 0x00000001
119#define ETH_ADDR_PA 0x0000F800
120#define ETH_ADDR_MR 0x000007C0
121#define ETH_ADDR_CR 0x0000003C
122#define ETH_ADDR_CR_DIV_42 0x00000000
123#define ETH_ADDR_CR_DIV_62 0x00000004
124#define ETH_ADDR_CR_DIV_16 0x00000008
125#define ETH_ADDR_CR_DIV_26 0x0000000C
126#define ETH_ADDR_CR_DIV_102 0x00000010
127#define ETH_ADDR_MW 0x00000002
128#define ETH_ADDR_MB 0x00000001
131#define ETH_DATA_MD 0x0000FFFF
134#define ETH_IMASK_TSTIM 0x00000200
135#define ETH_IMASK_PMTIM 0x00000008
138#define ETH_ADDR0H_AL1 0x80000000
139#define ETH_ADDR0H_ADDR0H 0x0000FFFF
142#define ETH_ADDR1H_ADDREN 0x80000000
143#define ETH_ADDR1H_ADDRSEL 0x40000000
144#define ETH_ADDR1H_MASKBCTRL 0x3F000000
145#define ETH_ADDR1H_ADDR1H 0x0000FFFF
148#define ETH_ADDR2H_ADDREN 0x80000000
149#define ETH_ADDR2H_ADDRSEL 0x40000000
150#define ETH_ADDR2H_MASKBCTRL 0x3F000000
151#define ETH_ADDR2H_ADDR2H 0x0000FFFF
154#define ETH_ADDR3H_ADDREN 0x80000000
155#define ETH_ADDR3H_ADDRSEL 0x40000000
156#define ETH_ADDR3H_MASKBCTRL 0x3F000000
157#define ETH_ADDR3H_ADDR3H 0x0000FFFF
160#define ETH_RXINT_RXGUNF 0x00020000
161#define ETH_RXINT_RXFAE 0x00000040
162#define ETH_RXINT_RXFCE 0x00000020
165#define ETH_TXINT_TXGF 0x00200000
166#define ETH_TXINT_TXGFMCOL 0x00008000
167#define ETH_TXINT_TXGFSCOL 0x00004000
170#define ETH_DMABMOD_MB 0x04000000
171#define ETH_DMABMOD_AAL 0x02000000
172#define ETH_DMABMOD_PBLX4 0x01000000
173#define ETH_DMABMOD_USP 0x00800000
174#define ETH_DMABMOD_RPBL 0x007E0000
175#define ETH_DMABMOD_RPBL_1 0x00020000
176#define ETH_DMABMOD_RPBL_2 0x00040000
177#define ETH_DMABMOD_RPBL_4 0x00080000
178#define ETH_DMABMOD_RPBL_8 0x00100000
179#define ETH_DMABMOD_RPBL_16 0x00200000
180#define ETH_DMABMOD_RPBL_32 0x00400000
181#define ETH_DMABMOD_FB 0x00010000
182#define ETH_DMABMOD_PR 0x0000C000
183#define ETH_DMABMOD_PR_1_1 0x00000000
184#define ETH_DMABMOD_PR_2_1 0x00004000
185#define ETH_DMABMOD_PR_3_1 0x00008000
186#define ETH_DMABMOD_PR_4_1 0x0000C000
187#define ETH_DMABMOD_PBL 0x00003F00
188#define ETH_DMABMOD_PBL_1 0x00000100
189#define ETH_DMABMOD_PBL_2 0x00000200
190#define ETH_DMABMOD_PBL_4 0x00000400
191#define ETH_DMABMOD_PBL_8 0x00000800
192#define ETH_DMABMOD_PBL_16 0x00001000
193#define ETH_DMABMOD_PBL_32 0x00002000
194#define ETH_DMABMOD_EDFEN 0x00000080
195#define ETH_DMABMOD_DSL 0x0000007C
196#define ETH_DMABMOD_DSL_0 0x00000000
197#define ETH_DMABMOD_DSL_1 0x00000004
198#define ETH_DMABMOD_DSL_2 0x00000008
199#define ETH_DMABMOD_DSL_4 0x00000010
200#define ETH_DMABMOD_DSL_8 0x00000020
201#define ETH_DMABMOD_DSL_16 0x00000040
202#define ETH_DMABMOD_DAS 0x00000002
203#define ETH_DMABMOD_SWR 0x00000001
206#define ETH_DMASTS_TSTFLG 0x20000000
207#define ETH_DMASTS_PMTFLG 0x10000000
208#define ETH_DMASTS_MMCFLG 0x08000000
209#define ETH_DMASTS_ERRB 0x03800000
210#define ETH_DMASTS_TXSTS 0x00700000
211#define ETH_DMASTS_RXSTS 0x000E0000
212#define ETH_DMASTS_NINTS 0x00010000
213#define ETH_DMASTS_AINTS 0x00008000
214#define ETH_DMASTS_ERXFLG 0x00004000
215#define ETH_DMASTS_FBERRFLG 0x00002000
216#define ETH_DMASTS_ETXFLG 0x00000400
217#define ETH_DMASTS_RXWTOFLG 0x00000200
218#define ETH_DMASTS_RXSFLG 0x00000100
219#define ETH_DMASTS_RXBU 0x00000080
220#define ETH_DMASTS_RXFLG 0x00000040
221#define ETH_DMASTS_TXUNF 0x00000020
222#define ETH_DMASTS_RXOVF 0x00000010
223#define ETH_DMASTS_TXJTO 0x00000008
224#define ETH_DMASTS_TXBU 0x00000004
225#define ETH_DMASTS_TXSFLG 0x00000002
226#define ETH_DMASTS_TXFLG 0x00000001
229#define ETH_DMAOPMOD_DISDT 0x04000000
230#define ETH_DMAOPMOD_RXSF 0x02000000
231#define ETH_DMAOPMOD_DISFRXF 0x01000000
232#define ETH_DMAOPMOD_TXSF 0x00200000
233#define ETH_DMAOPMOD_FTXF 0x00100000
234#define ETH_DMAOPMOD_TXTHCTRL 0x0001C000
235#define ETH_DMAOPMOD_STTX 0x00002000
236#define ETH_DMAOPMOD_FERRF 0x00000080
237#define ETH_DMAOPMOD_FUF 0x00000040
238#define ETH_DMAOPMOD_RXTHCTRL 0x00000018
239#define ETH_DMAOPMOD_OSECF 0x00000004
240#define ETH_DMAOPMOD_STRX 0x00000002
243#define ETH_DMAINTEN_NINTSEN 0x00010000
244#define ETH_DMAINTEN_AINTSEN 0x00008000
245#define ETH_DMAINTEN_ERXIEN 0x00004000
246#define ETH_DMAINTEN_FBERREN 0x00002000
247#define ETH_DMAINTEN_ETXIEN 0x00000400
248#define ETH_DMAINTEN_RXWTOEN 0x00000200
249#define ETH_DMAINTEN_RXSEN 0x00000100
250#define ETH_DMAINTEN_RXBUEN 0x00000080
251#define ETH_DMAINTEN_RXIEN 0x00000040
252#define ETH_DMAINTEN_TXUNFEN 0x00000020
253#define ETH_DMAINTEN_RXOVFEN 0x00000010
254#define ETH_DMAINTEN_TXJTOEN 0x00000008
255#define ETH_DMAINTEN_TXBUEN 0x00000004
256#define ETH_DMAINTEN_TXSEN 0x00000002
257#define ETH_DMAINTEN_TXIEN 0x00000001
260#define ETH_TXDES0_OWN 0x80000000
261#define ETH_TXDES0_INTC 0x40000000
262#define ETH_TXDES0_LS 0x20000000
263#define ETH_TXDES0_FS 0x10000000
264#define ETH_TXDES0_DISC 0x08000000
265#define ETH_TXDES0_DISP 0x04000000
266#define ETH_TXDES0_TXTSEN 0x02000000
267#define ETH_TXDES0_CHINS 0x00C00000
268#define ETH_TXDES0_TXENDR 0x00200000
269#define ETH_TXDES0_TXCH 0x00100000
270#define ETH_TXDES0_TXTSS 0x00020000
271#define ETH_TXDES0_IHERR 0x00010000
272#define ETH_TXDES0_ERRS 0x00008000
273#define ETH_TXDES0_JTO 0x00004000
274#define ETH_TXDES0_FF 0x00002000
275#define ETH_TXDES0_IPERR 0x00001000
276#define ETH_TXDES0_LSC 0x00000800
277#define ETH_TXDES0_NC 0x00000400
278#define ETH_TXDES0_LC 0x00000200
279#define ETH_TXDES0_EC 0x00000100
280#define ETH_TXDES0_VLANF 0x00000080
281#define ETH_TXDES0_CCNT 0x00000078
282#define ETH_TXDES0_EDEF 0x00000004
283#define ETH_TXDES0_UFERR 0x00000002
284#define ETH_TXDES0_DEF 0x00000001
285#define ETH_TXDES1_TXBS2 0x1FFF0000
286#define ETH_TXDES1_TXBS1 0x00001FFF
287#define ETH_TXDES2_TXADDR1_TXFTSL 0xFFFFFFFF
288#define ETH_TXDES3_TXADDR2_TXFTSH 0xFFFFFFFF
289#define ETH_TXDES6_TXFTSL 0xFFFFFFFF
290#define ETH_TXDES7_TXFTSH 0xFFFFFFFF
293#define ETH_RXDES0_OWN 0x80000000
294#define ETH_RXDES0_ADDRF 0x40000000
295#define ETH_RXDES0_FL 0x3FFF0000
296#define ETH_RXDES0_ERRS 0x00008000
297#define ETH_RXDES0_DESERR 0x00004000
298#define ETH_RXDES0_SADDRF 0x00002000
299#define ETH_RXDES0_LERR 0x00001000
300#define ETH_RXDES0_OFERR 0x00000800
301#define ETH_RXDES0_VLANF 0x00000400
302#define ETH_RXDES0_FDES 0x00000200
303#define ETH_RXDES0_LDES 0x00000100
304#define ETH_RXDES0_IPCERR_TSV 0x00000080
305#define ETH_RXDES0_LC 0x00000040
306#define ETH_RXDES0_FT 0x00000020
307#define ETH_RXDES0_RXWDTTO 0x00000010
308#define ETH_RXDES0_RERR 0x00000008
309#define ETH_RXDES0_DERR 0x00000004
310#define ETH_RXDES0_CERR 0x00000002
311#define ETH_RXDES0_PERR_ESA 0x00000001
312#define ETH_RXDES1_DINTC 0x80000000
313#define ETH_RXDES1_RBS2 0x1FFF0000
314#define ETH_RXDES1_RXER 0x00008000
315#define ETH_RXDES1_RXCH 0x00004000
316#define ETH_RXDES1_RBS1 0x00001FFF
317#define ETH_RXDES2_RXADDR1_RXFTSL 0xFFFFFFFF
318#define ETH_RXDES3_RXADDR2_RXFTSH 0xFFFFFFFF
319#define ETH_RXDES4_PTPV 0x00002000
320#define ETH_RXDES4_PTPFT 0x00001000
321#define ETH_RXDES4_PTPMT 0x00000F00
322#define ETH_RXDES4_IPV6P 0x00000080
323#define ETH_RXDES4_IPV4P 0x00000040
324#define ETH_RXDES4_IPCBP 0x00000020
325#define ETH_RXDES4_IPPERR 0x00000010
326#define ETH_RXDES4_IPHERR 0x00000008
327#define ETH_RXDES4_IPPT 0x00000007
328#define ETH_RXDES6_RXFTSL 0xFFFFFFFF
329#define ETH_RXDES7_RXFTSH 0xFFFFFFFF
372extern const NicDriver apm32f4xxEthDriver;
375error_t apm32f4xxEthInit(NetInterface *interface);
376void apm32f4xxEthInitGpio(NetInterface *interface);
377void apm32f4xxEthInitDmaDesc(NetInterface *interface);
379void apm32f4xxEthTick(NetInterface *interface);
381void apm32f4xxEthEnableIrq(NetInterface *interface);
382void apm32f4xxEthDisableIrq(NetInterface *interface);
383void apm32f4xxEthEventHandler(NetInterface *interface);
385error_t apm32f4xxEthSendPacket(NetInterface *interface,
386 const NetBuffer *buffer,
size_t offset, NetTxAncillary *ancillary);
388error_t apm32f4xxEthReceivePacket(NetInterface *interface);
390error_t apm32f4xxEthUpdateMacAddrFilter(NetInterface *interface);
391error_t apm32f4xxEthUpdateMacConfig(NetInterface *interface);
393void apm32f4xxEthWritePhyReg(uint8_t opcode, uint8_t phyAddr,
394 uint8_t regAddr, uint16_t data);
396uint16_t apm32f4xxEthReadPhyReg(uint8_t opcode, uint8_t phyAddr,
399uint32_t apm32f4xxEthCalcCrc(
const void *data,
size_t length);
error_t
Error codes.
Definition error.h:43
Network interface controller abstraction layer.
Enhanced RX DMA descriptor.
Definition apm32f4xx_eth_driver.h:359
Enhanced TX DMA descriptor.
Definition apm32f4xx_eth_driver.h:342
Structure describing a buffer that spans multiple chunks.
Definition net_mem.h:89
NIC driver.
Definition nic.h:283