msp432e4_eth_driver.h
Go to the documentation of this file.
1 /**
2  * @file msp432e4_eth_driver.h
3  * @brief MSP432E4 Ethernet controller
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 #ifndef _MSP432E4_ETH_DRIVER_H
32 #define _MSP432E4_ETH_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //Number of TX buffers
38 #ifndef MSP432E4_ETH_TX_BUFFER_COUNT
39  #define MSP432E4_ETH_TX_BUFFER_COUNT 3
40 #elif (MSP432E4_ETH_TX_BUFFER_COUNT < 1)
41  #error MSP432E4_ETH_TX_BUFFER_COUNT parameter is not valid
42 #endif
43 
44 //TX buffer size
45 #ifndef MSP432E4_ETH_TX_BUFFER_SIZE
46  #define MSP432E4_ETH_TX_BUFFER_SIZE 1536
47 #elif (MSP432E4_ETH_TX_BUFFER_SIZE != 1536)
48  #error MSP432E4_ETH_TX_BUFFER_SIZE parameter is not valid
49 #endif
50 
51 //Number of RX buffers
52 #ifndef MSP432E4_ETH_RX_BUFFER_COUNT
53  #define MSP432E4_ETH_RX_BUFFER_COUNT 6
54 #elif (MSP432E4_ETH_RX_BUFFER_COUNT < 1)
55  #error MSP432E4_ETH_RX_BUFFER_COUNT parameter is not valid
56 #endif
57 
58 //RX buffer size
59 #ifndef MSP432E4_ETH_RX_BUFFER_SIZE
60  #define MSP432E4_ETH_RX_BUFFER_SIZE 1536
61 #elif (MSP432E4_ETH_RX_BUFFER_SIZE != 1536)
62  #error MSP432E4_ETH_RX_BUFFER_SIZE parameter is not valid
63 #endif
64 
65 //Interrupt priority grouping
66 #ifndef MSP432E4_ETH_IRQ_PRIORITY_GROUPING
67  #define MSP432E4_ETH_IRQ_PRIORITY_GROUPING 3
68 #elif (MSP432E4_ETH_IRQ_PRIORITY_GROUPING < 0)
69  #error MSP432E4_ETH_IRQ_PRIORITY_GROUPING parameter is not valid
70 #endif
71 
72 //Ethernet interrupt priority
73 #ifndef MSP432E4_ETH_IRQ_PRIORITY
74  #define MSP432E4_ETH_IRQ_PRIORITY 192
75 #elif (MSP432E4_ETH_IRQ_PRIORITY < 0)
76  #error MSP432E4_ETH_IRQ_PRIORITY parameter is not valid
77 #endif
78 
79 //MSP432E4 Ethernet MAC registers
80 #ifndef EMAC0_CFG_R
81  #define EMAC0_CFG_R HWREG(EMAC0_BASE + EMAC_O_CFG)
82  #define EMAC0_FRAMEFLTR_R HWREG(EMAC0_BASE + EMAC_O_FRAMEFLTR)
83  #define EMAC0_HASHTBLH_R HWREG(EMAC0_BASE + EMAC_O_HASHTBLH)
84  #define EMAC0_HASHTBLL_R HWREG(EMAC0_BASE + EMAC_O_HASHTBLL)
85  #define EMAC0_MIIADDR_R HWREG(EMAC0_BASE + EMAC_O_MIIADDR)
86  #define EMAC0_MIIDATA_R HWREG(EMAC0_BASE + EMAC_O_MIIDATA)
87  #define EMAC0_FLOWCTL_R HWREG(EMAC0_BASE + EMAC_O_FLOWCTL)
88  #define EMAC0_VLANTG_R HWREG(EMAC0_BASE + EMAC_O_VLANTG)
89  #define EMAC0_STATUS_R HWREG(EMAC0_BASE + EMAC_O_STATUS)
90  #define EMAC0_RWUFF_R HWREG(EMAC0_BASE + EMAC_O_RWUFF)
91  #define EMAC0_PMTCTLSTAT_R HWREG(EMAC0_BASE + EMAC_O_PMTCTLSTAT)
92  #define EMAC0_LPICTLSTAT_R HWREG(EMAC0_BASE + EMAC_O_LPICTLSTAT)
93  #define EMAC0_LPITIMERCTL_R HWREG(EMAC0_BASE + EMAC_O_LPITIMERCTL)
94  #define EMAC0_RIS_R HWREG(EMAC0_BASE + EMAC_O_RIS)
95  #define EMAC0_IM_R HWREG(EMAC0_BASE + EMAC_O_IM)
96  #define EMAC0_ADDR0H_R HWREG(EMAC0_BASE + EMAC_O_ADDR0H)
97  #define EMAC0_ADDR0L_R HWREG(EMAC0_BASE + EMAC_O_ADDR0L)
98  #define EMAC0_ADDR1H_R HWREG(EMAC0_BASE + EMAC_O_ADDR1H)
99  #define EMAC0_ADDR1L_R HWREG(EMAC0_BASE + EMAC_O_ADDR1L)
100  #define EMAC0_ADDR2H_R HWREG(EMAC0_BASE + EMAC_O_ADDR2H)
101  #define EMAC0_ADDR2L_R HWREG(EMAC0_BASE + EMAC_O_ADDR2L)
102  #define EMAC0_ADDR3H_R HWREG(EMAC0_BASE + EMAC_O_ADDR3H)
103  #define EMAC0_ADDR3L_R HWREG(EMAC0_BASE + EMAC_O_ADDR3L)
104  #define EMAC0_WDOGTO_R HWREG(EMAC0_BASE + EMAC_O_WDOGTO)
105  #define EMAC0_MMCCTRL_R HWREG(EMAC0_BASE + EMAC_O_MMCCTRL)
106  #define EMAC0_MMCRXRIS_R HWREG(EMAC0_BASE + EMAC_O_MMCRXRIS)
107  #define EMAC0_MMCTXRIS_R HWREG(EMAC0_BASE + EMAC_O_MMCTXRIS)
108  #define EMAC0_MMCRXIM_R HWREG(EMAC0_BASE + EMAC_O_MMCRXIM)
109  #define EMAC0_MMCTXIM_R HWREG(EMAC0_BASE + EMAC_O_MMCTXIM)
110  #define EMAC0_TXCNTGB_R HWREG(EMAC0_BASE + EMAC_O_TXCNTGB)
111  #define EMAC0_TXCNTSCOL_R HWREG(EMAC0_BASE + EMAC_O_TXCNTSCOL)
112  #define EMAC0_TXCNTMCOL_R HWREG(EMAC0_BASE + EMAC_O_TXCNTMCOL)
113  #define EMAC0_TXOCTCNTG_R HWREG(EMAC0_BASE + EMAC_O_TXOCTCNTG)
114  #define EMAC0_RXCNTGB_R HWREG(EMAC0_BASE + EMAC_O_RXCNTGB)
115  #define EMAC0_RXCNTCRCERR_R HWREG(EMAC0_BASE + EMAC_O_RXCNTCRCERR)
116  #define EMAC0_RXCNTALGNERR_R HWREG(EMAC0_BASE + EMAC_O_RXCNTALGNERR)
117  #define EMAC0_RXCNTGUNI_R HWREG(EMAC0_BASE + EMAC_O_RXCNTGUNI)
118  #define EMAC0_VLNINCREP_R HWREG(EMAC0_BASE + EMAC_O_VLNINCREP)
119  #define EMAC0_VLANHASH_R HWREG(EMAC0_BASE + EMAC_O_VLANHASH)
120  #define EMAC0_TIMSTCTRL_R HWREG(EMAC0_BASE + EMAC_O_TIMSTCTRL)
121  #define EMAC0_SUBSECINC_R HWREG(EMAC0_BASE + EMAC_O_SUBSECINC)
122  #define EMAC0_TIMSEC_R HWREG(EMAC0_BASE + EMAC_O_TIMSEC)
123  #define EMAC0_TIMNANO_R HWREG(EMAC0_BASE + EMAC_O_TIMNANO)
124  #define EMAC0_TIMSECU_R HWREG(EMAC0_BASE + EMAC_O_TIMSECU)
125  #define EMAC0_TIMNANOU_R HWREG(EMAC0_BASE + EMAC_O_TIMNANOU)
126  #define EMAC0_TIMADD_R HWREG(EMAC0_BASE + EMAC_O_TIMADD)
127  #define EMAC0_TARGSEC_R HWREG(EMAC0_BASE + EMAC_O_TARGSEC)
128  #define EMAC0_TARGNANO_R HWREG(EMAC0_BASE + EMAC_O_TARGNANO)
129  #define EMAC0_HWORDSEC_R HWREG(EMAC0_BASE + EMAC_O_HWORDSEC)
130  #define EMAC0_TIMSTAT_R HWREG(EMAC0_BASE + EMAC_O_TIMSTAT)
131  #define EMAC0_PPSCTRL_R HWREG(EMAC0_BASE + EMAC_O_PPSCTRL)
132  #define EMAC0_PPS0INTVL_R HWREG(EMAC0_BASE + EMAC_O_PPS0INTVL)
133  #define EMAC0_PPS0WIDTH_R HWREG(EMAC0_BASE + EMAC_O_PPS0WIDTH)
134  #define EMAC0_DMABUSMOD_R HWREG(EMAC0_BASE + EMAC_O_DMABUSMOD)
135  #define EMAC0_TXPOLLD_R HWREG(EMAC0_BASE + EMAC_O_TXPOLLD)
136  #define EMAC0_RXPOLLD_R HWREG(EMAC0_BASE + EMAC_O_RXPOLLD)
137  #define EMAC0_RXDLADDR_R HWREG(EMAC0_BASE + EMAC_O_RXDLADDR)
138  #define EMAC0_TXDLADDR_R HWREG(EMAC0_BASE + EMAC_O_TXDLADDR)
139  #define EMAC0_DMARIS_R HWREG(EMAC0_BASE + EMAC_O_DMARIS)
140  #define EMAC0_DMAOPMODE_R HWREG(EMAC0_BASE + EMAC_O_DMAOPMODE)
141  #define EMAC0_DMAIM_R HWREG(EMAC0_BASE + EMAC_O_DMAIM)
142  #define EMAC0_MFBOC_R HWREG(EMAC0_BASE + EMAC_O_MFBOC)
143  #define EMAC0_RXINTWDT_R HWREG(EMAC0_BASE + EMAC_O_RXINTWDT)
144  #define EMAC0_HOSTXDESC_R HWREG(EMAC0_BASE + EMAC_O_HOSTXDESC)
145  #define EMAC0_HOSRXDESC_R HWREG(EMAC0_BASE + EMAC_O_HOSRXDESC)
146  #define EMAC0_HOSTXBA_R HWREG(EMAC0_BASE + EMAC_O_HOSTXBA)
147  #define EMAC0_HOSRXBA_R HWREG(EMAC0_BASE + EMAC_O_HOSRXBA)
148  #define EMAC0_PP_R HWREG(EMAC0_BASE + EMAC_O_PP)
149  #define EMAC0_PC_R HWREG(EMAC0_BASE + EMAC_O_PC)
150  #define EMAC0_CC_R HWREG(EMAC0_BASE + EMAC_O_CC)
151  #define EMAC0_EPHYRIS_R HWREG(EMAC0_BASE + EMAC_O_EPHYRIS)
152  #define EMAC0_EPHYIM_R HWREG(EMAC0_BASE + EMAC_O_EPHYIM)
153  #define EMAC0_EPHYMISC_R HWREG(EMAC0_BASE + EMAC_O_EPHYMISC)
154 #endif
155 
156 //DMABUSMOD register
157 #define EMAC_DMABUSMOD_RPBL_1 (1 << EMAC_DMABUSMOD_RPBL_S)
158 #define EMAC_DMABUSMOD_RPBL_2 (2 << EMAC_DMABUSMOD_RPBL_S)
159 #define EMAC_DMABUSMOD_RPBL_4 (4 << EMAC_DMABUSMOD_RPBL_S)
160 #define EMAC_DMABUSMOD_RPBL_8 (8 << EMAC_DMABUSMOD_RPBL_S)
161 #define EMAC_DMABUSMOD_RPBL_16 (16 << EMAC_DMABUSMOD_RPBL_S)
162 #define EMAC_DMABUSMOD_RPBL_32 (32 << EMAC_DMABUSMOD_RPBL_S)
163 
164 #define EMAC_DMABUSMOD_PR_1_1 (0 << EMAC_DMABUSMOD_PR_S)
165 #define EMAC_DMABUSMOD_PR_2_1 (1 << EMAC_DMABUSMOD_PR_S)
166 #define EMAC_DMABUSMOD_PR_3_1 (2 << EMAC_DMABUSMOD_PR_S)
167 #define EMAC_DMABUSMOD_PR_4_1 (3 << EMAC_DMABUSMOD_PR_S)
168 
169 #define EMAC_DMABUSMOD_PBL_1 (1 << EMAC_DMABUSMOD_PBL_S)
170 #define EMAC_DMABUSMOD_PBL_2 (2 << EMAC_DMABUSMOD_PBL_S)
171 #define EMAC_DMABUSMOD_PBL_4 (4 << EMAC_DMABUSMOD_PBL_S)
172 #define EMAC_DMABUSMOD_PBL_8 (8 << EMAC_DMABUSMOD_PBL_S)
173 #define EMAC_DMABUSMOD_PBL_16 (16 << EMAC_DMABUSMOD_PBL_S)
174 #define EMAC_DMABUSMOD_PBL_32 (32 << EMAC_DMABUSMOD_PBL_S)
175 
176 //Transmit DMA descriptor flags
177 #define EMAC_TDES0_OWN 0x80000000
178 #define EMAC_TDES0_IC 0x40000000
179 #define EMAC_TDES0_LS 0x20000000
180 #define EMAC_TDES0_FS 0x10000000
181 #define EMAC_TDES0_DC 0x08000000
182 #define EMAC_TDES0_DP 0x04000000
183 #define EMAC_TDES0_TTSE 0x02000000
184 #define EMAC_TDES0_CRCR 0x01000000
185 #define EMAC_TDES0_CIC 0x00C00000
186 #define EMAC_TDES0_TER 0x00200000
187 #define EMAC_TDES0_TCH 0x00100000
188 #define EMAC_TDES0_VLIC 0x000C0000
189 #define EMAC_TDES0_TTSS 0x00020000
190 #define EMAC_TDES0_IHE 0x00010000
191 #define EMAC_TDES0_ES 0x00008000
192 #define EMAC_TDES0_JT 0x00004000
193 #define EMAC_TDES0_FF 0x00002000
194 #define EMAC_TDES0_IPE 0x00001000
195 #define EMAC_TDES0_LCA 0x00000800
196 #define EMAC_TDES0_NC 0x00000400
197 #define EMAC_TDES0_LCO 0x00000200
198 #define EMAC_TDES0_EC 0x00000100
199 #define EMAC_TDES0_VF 0x00000080
200 #define EMAC_TDES0_CC 0x00000078
201 #define EMAC_TDES0_ED 0x00000004
202 #define EMAC_TDES0_UF 0x00000002
203 #define EMAC_TDES0_DB 0x00000001
204 #define EMAC_TDES1_SAIC 0xE0000000
205 #define EMAC_TDES1_TBS2 0x1FFF0000
206 #define EMAC_TDES1_TBS1 0x00001FFF
207 #define EMAC_TDES2_TBAP1 0xFFFFFFFF
208 #define EMAC_TDES3_TBAP2 0xFFFFFFFF
209 #define EMAC_TDES6_TTSL 0xFFFFFFFF
210 #define EMAC_TDES7_TTSH 0xFFFFFFFF
211 
212 //Receive DMA descriptor flags
213 #define EMAC_RDES0_OWN 0x80000000
214 #define EMAC_RDES0_AFM 0x40000000
215 #define EMAC_RDES0_FL 0x3FFF0000
216 #define EMAC_RDES0_ES 0x00008000
217 #define EMAC_RDES0_DE 0x00004000
218 #define EMAC_RDES0_SAF 0x00002000
219 #define EMAC_RDES0_LE 0x00001000
220 #define EMAC_RDES0_OE 0x00000800
221 #define EMAC_RDES0_VLAN 0x00000400
222 #define EMAC_RDES0_FS 0x00000200
223 #define EMAC_RDES0_LS 0x00000100
224 #define EMAC_RDES0_TSA_GF 0x00000080
225 #define EMAC_RDES0_LCO 0x00000040
226 #define EMAC_RDES0_FT 0x00000020
227 #define EMAC_RDES0_RWT 0x00000010
228 #define EMAC_RDES0_RE 0x00000008
229 #define EMAC_RDES0_DBE 0x00000004
230 #define EMAC_RDES0_CE 0x00000002
231 #define EMAC_RDES0_ESA 0x00000001
232 #define EMAC_RDES1_DIC 0x80000000
233 #define EMAC_RDES1_RBS2 0x1FFF0000
234 #define EMAC_RDES1_RER 0x00008000
235 #define EMAC_RDES1_RCH 0x00004000
236 #define EMAC_RDES1_RBS1 0x00001FFF
237 #define EMAC_RDES2_RBAP1 0xFFFFFFFF
238 #define EMAC_RDES3_RBAP2 0xFFFFFFFF
239 #define EMAC_RDES4_TSD 0x00004000
240 #define EMAC_RDES4_PV 0x00002000
241 #define EMAC_RDES4_PFT 0x00001000
242 #define EMAC_RDES4_PMT 0x00000F00
243 #define EMAC_RDES4_IPV6PR 0x00000080
244 #define EMAC_RDES4_IPV4PR 0x00000040
245 #define EMAC_RDES4_IPCB 0x00000020
246 #define EMAC_RDES4_IPPE 0x00000010
247 #define EMAC_RDES4_IPHE 0x00000008
248 #define EMAC_RDES4_IPPT 0x00000007
249 #define EMAC_RDES6_RTSL 0xFFFFFFFF
250 #define EMAC_RDES7_RTSH 0xFFFFFFFF
251 
252 #ifndef ti_sysbios_BIOS___VERS
253  #define msp432e4EthIrqHandler EMAC0_IRQHandler
254 #endif
255 
256 //C++ guard
257 #ifdef __cplusplus
258 extern "C" {
259 #endif
260 
261 
262 /**
263  * @brief Enhanced TX DMA descriptor
264  **/
265 
266 typedef struct
267 {
268  uint32_t tdes0;
269  uint32_t tdes1;
270  uint32_t tdes2;
271  uint32_t tdes3;
272  uint32_t tdes4;
273  uint32_t tdes5;
274  uint32_t tdes6;
275  uint32_t tdes7;
277 
278 
279 /**
280  * @brief Enhanced RX DMA descriptor
281  **/
282 
283 typedef struct
284 {
285  uint32_t rdes0;
286  uint32_t rdes1;
287  uint32_t rdes2;
288  uint32_t rdes3;
289  uint32_t rdes4;
290  uint32_t rdes5;
291  uint32_t rdes6;
292  uint32_t rdes7;
294 
295 
296 //MSP432E4 Ethernet MAC driver
297 extern const NicDriver msp432e4EthDriver;
298 
299 //MSP432E4 Ethernet MAC related functions
301 void msp432e4EthInitGpio(NetInterface *interface);
302 void msp432e4EthInitDmaDesc(NetInterface *interface);
303 
304 void msp432e4EthTick(NetInterface *interface);
305 
306 void msp432e4EthEnableIrq(NetInterface *interface);
307 void msp432e4EthDisableIrq(NetInterface *interface);
308 void msp432e4EthIrqHandler(void);
309 void msp432e4EthEventHandler(NetInterface *interface);
310 
312  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
313 
315 
318 
319 void msp432e4EthWritePhyReg(uint8_t opcode, uint8_t phyAddr,
320  uint8_t regAddr, uint16_t data);
321 
322 uint16_t msp432e4EthReadPhyReg(uint8_t opcode, uint8_t phyAddr,
323  uint8_t regAddr);
324 
325 void msp432e4EthDumpPhyReg(void);
326 
327 uint32_t msp432e4EthCalcCrc(const void *data, size_t length);
328 
329 //C++ guard
330 #ifdef __cplusplus
331 }
332 #endif
333 
334 #endif
uint8_t opcode
Definition: dns_common.h:188
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t data[]
Definition: ethernet.h:222
uint16_t msp432e4EthReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
void msp432e4EthEnableIrq(NetInterface *interface)
Enable interrupts.
void msp432e4EthWritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
#define msp432e4EthIrqHandler
error_t
Error codes.
Definition: error.h:43
#define NetInterface
Definition: net.h:36
#define NetTxAncillary
Definition: net_misc.h:36
error_t msp432e4EthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
void msp432e4EthDumpPhyReg(void)
Dump PHY registers for debugging purpose.
uint8_t length
Definition: tcp.h:368
error_t msp432e4EthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
Enhanced TX DMA descriptor.
const NicDriver msp432e4EthDriver
MSP432E4 Ethernet MAC driver.
uint16_t regAddr
error_t msp432e4EthInit(NetInterface *interface)
MSP432E4 Ethernet MAC initialization.
void msp432e4EthTick(NetInterface *interface)
MSP432E4 Ethernet MAC timer handler.
error_t msp432e4EthReceivePacket(NetInterface *interface)
Receive a packet.
Enhanced RX DMA descriptor.
Network interface controller abstraction layer.
void msp432e4EthEventHandler(NetInterface *interface)
MSP432E4 Ethernet MAC event handler.
void msp432e4EthInitGpio(NetInterface *interface)
GPIO configuration.
error_t msp432e4EthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
NIC driver.
Definition: nic.h:286
uint32_t msp432e4EthCalcCrc(const void *data, size_t length)
CRC calculation.
void msp432e4EthDisableIrq(NetInterface *interface)
Disable interrupts.
void msp432e4EthInitDmaDesc(NetInterface *interface)
Initialize DMA descriptor lists.