tc2xx_eth_driver.h
Go to the documentation of this file.
1 /**
2  * @file tc2xx_eth_driver.h
3  * @brief Infineon AURIX TriCore TC2xx Ethernet MAC driver
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.0
29  **/
30 
31 #ifndef _TC2XX_ETH_DRIVER_H
32 #define _TC2XX_ETH_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //Number of TX buffers
38 #ifndef TC2XX_ETH_TX_BUFFER_COUNT
39  #define TC2XX_ETH_TX_BUFFER_COUNT 3
40 #elif (TC2XX_ETH_TX_BUFFER_COUNT < 1)
41  #error TC2XX_ETH_TX_BUFFER_COUNT parameter is not valid
42 #endif
43 
44 //TX buffer size
45 #ifndef TC2XX_ETH_TX_BUFFER_SIZE
46  #define TC2XX_ETH_TX_BUFFER_SIZE 1536
47 #elif (TC2XX_ETH_TX_BUFFER_SIZE != 1536)
48  #error TC2XX_ETH_TX_BUFFER_SIZE parameter is not valid
49 #endif
50 
51 //Number of RX buffers
52 #ifndef TC2XX_ETH_RX_BUFFER_COUNT
53  #define TC2XX_ETH_RX_BUFFER_COUNT 6
54 #elif (TC2XX_ETH_RX_BUFFER_COUNT < 1)
55  #error TC2XX_ETH_RX_BUFFER_COUNT parameter is not valid
56 #endif
57 
58 //RX buffer size
59 #ifndef TC2XX_ETH_RX_BUFFER_SIZE
60  #define TC2XX_ETH_RX_BUFFER_SIZE 1536
61 #elif (TC2XX_ETH_RX_BUFFER_SIZE != 1536)
62  #error TC2XX_ETH_RX_BUFFER_SIZE parameter is not valid
63 #endif
64 
65 //Ethernet interrupt priority
66 #ifndef TC2XX_ETH_IRQ_PRIORITY
67  #define TC2XX_ETH_IRQ_PRIORITY 10
68 #elif (TC2XX_ETH_IRQ_PRIORITY < 0)
69  #error TC2XX_ETH_IRQ_PRIORITY parameter is not valid
70 #endif
71 
72 //ETH_STATUS register
73 #define ETH_STATUS_GLPII 0x40000000
74 #define ETH_STATUS_TTI 0x20000000
75 #define ETH_STATUS_GPI 0x10000000
76 #define ETH_STATUS_GMI 0x08000000
77 #define ETH_STATUS_GLI 0x04000000
78 #define ETH_STATUS_EB 0x03800000
79 #define ETH_STATUS_TS 0x00700000
80 #define ETH_STATUS_RS 0x000E0000
81 #define ETH_STATUS_NIS 0x00010000
82 #define ETH_STATUS_AIS 0x00008000
83 #define ETH_STATUS_ERI 0x00004000
84 #define ETH_STATUS_FBI 0x00002000
85 #define ETH_STATUS_ETI 0x00000400
86 #define ETH_STATUS_RWT 0x00000200
87 #define ETH_STATUS_RPS 0x00000100
88 #define ETH_STATUS_RU 0x00000080
89 #define ETH_STATUS_RI 0x00000040
90 #define ETH_STATUS_UNF 0x00000020
91 #define ETH_STATUS_OVF 0x00000010
92 #define ETH_STATUS_TJT 0x00000008
93 #define ETH_STATUS_TU 0x00000004
94 #define ETH_STATUS_TPS 0x00000002
95 #define ETH_STATUS_TI 0x00000001
96 
97 //ETH_INTERRUPT_ENABLE register
98 #define ETH_INTERRUPT_ENABLE_NIE 0x00010000
99 #define ETH_INTERRUPT_ENABLE_AIE 0x00008000
100 #define ETH_INTERRUPT_ENABLE_ERE 0x00004000
101 #define ETH_INTERRUPT_ENABLE_FBE 0x00002000
102 #define ETH_INTERRUPT_ENABLE_ETE 0x00000400
103 #define ETH_INTERRUPT_ENABLE_RWE 0x00000200
104 #define ETH_INTERRUPT_ENABLE_RSE 0x00000100
105 #define ETH_INTERRUPT_ENABLE_RUE 0x00000080
106 #define ETH_INTERRUPT_ENABLE_RIE 0x00000040
107 #define ETH_INTERRUPT_ENABLE_UNE 0x00000020
108 #define ETH_INTERRUPT_ENABLE_OVE 0x00000010
109 #define ETH_INTERRUPT_ENABLE_TJE 0x00000008
110 #define ETH_INTERRUPT_ENABLE_TUE 0x00000004
111 #define ETH_INTERRUPT_ENABLE_TSE 0x00000002
112 #define ETH_INTERRUPT_ENABLE_TIE 0x00000001
113 
114 //Transmit DMA descriptor flags
115 #define ETH_TDES0_OWN 0x80000000
116 #define ETH_TDES0_IC 0x40000000
117 #define ETH_TDES0_LS 0x20000000
118 #define ETH_TDES0_FS 0x10000000
119 #define ETH_TDES0_DC 0x08000000
120 #define ETH_TDES0_DP 0x04000000
121 #define ETH_TDES0_TTSE 0x02000000
122 #define ETH_TDES0_CIC 0x00C00000
123 #define ETH_TDES0_TER 0x00200000
124 #define ETH_TDES0_TCH 0x00100000
125 #define ETH_TDES0_TTSS 0x00020000
126 #define ETH_TDES0_IHE 0x00010000
127 #define ETH_TDES0_ES 0x00008000
128 #define ETH_TDES0_JT 0x00004000
129 #define ETH_TDES0_FF 0x00002000
130 #define ETH_TDES0_IPE 0x00001000
131 #define ETH_TDES0_LCA 0x00000800
132 #define ETH_TDES0_NC 0x00000400
133 #define ETH_TDES0_LCO 0x00000200
134 #define ETH_TDES0_EC 0x00000100
135 #define ETH_TDES0_VF 0x00000080
136 #define ETH_TDES0_CC 0x00000078
137 #define ETH_TDES0_ED 0x00000004
138 #define ETH_TDES0_UF 0x00000002
139 #define ETH_TDES0_DB 0x00000001
140 #define ETH_TDES1_TBS2 0x1FFF0000
141 #define ETH_TDES1_TBS1 0x00001FFF
142 #define ETH_TDES2_B1AP 0xFFFFFFFF
143 #define ETH_TDES3_B2AP 0xFFFFFFFF
144 #define ETH_TDES6_TTSL 0xFFFFFFFF
145 #define ETH_TDES7_TTSH 0xFFFFFFFF
146 
147 //Receive DMA descriptor flags
148 #define ETH_RDES0_OWN 0x80000000
149 #define ETH_RDES0_AFM 0x40000000
150 #define ETH_RDES0_FL 0x3FFF0000
151 #define ETH_RDES0_ES 0x00008000
152 #define ETH_RDES0_DE 0x00004000
153 #define ETH_RDES0_SAF 0x00002000
154 #define ETH_RDES0_LE 0x00001000
155 #define ETH_RDES0_OE 0x00000800
156 #define ETH_RDES0_VLAN 0x00000400
157 #define ETH_RDES0_FS 0x00000200
158 #define ETH_RDES0_LS 0x00000100
159 #define ETH_RDES0_TS 0x00000080
160 #define ETH_RDES0_LCO 0x00000040
161 #define ETH_RDES0_FT 0x00000020
162 #define ETH_RDES0_RWT 0x00000010
163 #define ETH_RDES0_RE 0x00000008
164 #define ETH_RDES0_DBE 0x00000004
165 #define ETH_RDES0_CE 0x00000002
166 #define ETH_RDES0_ESA 0x00000001
167 #define ETH_RDES1_DIC 0x80000000
168 #define ETH_RDES1_RBS2 0x1FFF0000
169 #define ETH_RDES1_RER 0x00008000
170 #define ETH_RDES1_RCH 0x00004000
171 #define ETH_RDES1_RBS1 0x00001FFF
172 #define ETH_RDES2_B1AP 0xFFFFFFFF
173 #define ETH_RDES3_B2AP 0xFFFFFFFF
174 #define ETH_RDES4_PV 0x00002000
175 #define ETH_RDES4_PFT 0x00001000
176 #define ETH_RDES4_MT 0x00000F00
177 #define ETH_RDES4_IP6R 0x00000080
178 #define ETH_RDES4_IP4R 0x00000040
179 #define ETH_RDES4_IPCB 0x00000020
180 #define ETH_RDES4_IPE 0x00000010
181 #define ETH_RDES4_IPHE 0x00000008
182 #define ETH_RDES4_IPT 0x00000007
183 #define ETH_RDES6_RTSL 0xFFFFFFFF
184 #define ETH_RDES7_RTSH 0xFFFFFFFF
185 
186 //Get CPU core identifier
187 #define ETH_CPU_ID() (_mfcr(CPU_CORE_ID) & IFX_CPU_CORE_ID_CORE_ID_MSK)
188 
189 //Convert a local DSPR address to a global DSPR address
190 #define ETH_GLOBAL_DSPR_ADDR(address) \
191  ((((uint32_t) (address) & 0xF0000000) == 0xD0000000) ? \
192  ((((uint32_t) (address) & 0x000FFFFF) | 0x70000000) - (ETH_CPU_ID() * 0x10000000)) : \
193  (uint32_t) (address))
194 
195 //C++ guard
196 #ifdef __cplusplus
197 extern "C" {
198 #endif
199 
200 
201 /**
202  * @brief Transmit DMA descriptor
203  **/
204 
205 typedef struct
206 {
207  uint32_t tdes0;
208  uint32_t tdes1;
209  uint32_t tdes2;
210  uint32_t tdes3;
211  uint32_t tdes4;
212  uint32_t tdes5;
213  uint32_t tdes6;
214  uint32_t tdes7;
216 
217 
218 /**
219  * @brief Receive DMA descriptor
220  **/
221 
222 typedef struct
223 {
224  uint32_t rdes0;
225  uint32_t rdes1;
226  uint32_t rdes2;
227  uint32_t rdes3;
228  uint32_t rdes4;
229  uint32_t rdes5;
230  uint32_t rdes6;
231  uint32_t rdes7;
233 
234 
235 //TC2xx Ethernet MAC driver
236 extern const NicDriver tc2xxEthDriver;
237 
238 //TC2xx Ethernet MAC related functions
239 error_t tc2xxEthInit(NetInterface *interface);
240 void tc2xxEthInitGpio(NetInterface *interface);
241 void tc2xxEthInitDmaDesc(NetInterface *interface);
242 
243 void tc2xxEthTick(NetInterface *interface);
244 
245 void tc2xxEthEnableIrq(NetInterface *interface);
246 void tc2xxEthDisableIrq(NetInterface *interface);
247 void tc2xxEthIrqHandler(int_t arg);
248 void tc2xxEthEventHandler(NetInterface *interface);
249 
251  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
252 
254 
257 
258 void tc2xxEthWritePhyReg(uint8_t opcode, uint8_t phyAddr,
259  uint8_t regAddr, uint16_t data);
260 
261 uint16_t tc2xxEthReadPhyReg(uint8_t opcode, uint8_t phyAddr,
262  uint8_t regAddr);
263 
264 uint32_t tc2xxEthCalcCrc(const void *data, size_t length);
265 
266 //C++ guard
267 #ifdef __cplusplus
268 }
269 #endif
270 
271 #endif
signed int int_t
Definition: compiler_port.h:49
uint8_t opcode
Definition: dns_common.h:188
error_t
Error codes.
Definition: error.h:43
uint8_t data[]
Definition: ethernet.h:222
uint16_t regAddr
#define NetInterface
Definition: net.h:36
#define NetTxAncillary
Definition: net_misc.h:36
Network interface controller abstraction layer.
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
NIC driver.
Definition: nic.h:283
Receive DMA descriptor.
Transmit DMA descriptor.
void tc2xxEthWritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
error_t tc2xxEthReceivePacket(NetInterface *interface)
Receive a packet.
void tc2xxEthDisableIrq(NetInterface *interface)
Disable interrupts.
error_t tc2xxEthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
void tc2xxEthEventHandler(NetInterface *interface)
TC2xx Ethernet MAC event handler.
error_t tc2xxEthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
error_t tc2xxEthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
uint16_t tc2xxEthReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
void tc2xxEthTick(NetInterface *interface)
TC2xx Ethernet MAC timer handler.
error_t tc2xxEthInit(NetInterface *interface)
TC2xx Ethernet MAC initialization.
void tc2xxEthEnableIrq(NetInterface *interface)
Enable interrupts.
void tc2xxEthIrqHandler(int_t arg)
TC2xx Ethernet MAC interrupt service routine.
void tc2xxEthInitDmaDesc(NetInterface *interface)
Initialize DMA descriptor lists.
const NicDriver tc2xxEthDriver
TC2xx Ethernet MAC driver.
uint32_t tc2xxEthCalcCrc(const void *data, size_t length)
CRC calculation.
void tc2xxEthInitGpio(NetInterface *interface)
GPIO configuration.
uint8_t length
Definition: tcp.h:368