esp32_eth_driver.h
Go to the documentation of this file.
1 /**
2  * @file esp32_eth_driver.h
3  * @brief ESP32 Ethernet MAC controller
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _ESP32_ETH_DRIVER_H
30 #define _ESP32_ETH_DRIVER_H
31 
32 //Dependencies
33 #include "core/nic.h"
34 
35 //Number of TX buffers
36 #ifndef ESP32_ETH_TX_BUFFER_COUNT
37  #define ESP32_ETH_TX_BUFFER_COUNT 3
38 #elif (ESP32_ETH_TX_BUFFER_COUNT < 1)
39  #error ESP32_ETH_TX_BUFFER_COUNT parameter is not valid
40 #endif
41 
42 //TX buffer size
43 #ifndef ESP32_ETH_TX_BUFFER_SIZE
44  #define ESP32_ETH_TX_BUFFER_SIZE 1536
45 #elif (ESP32_ETH_TX_BUFFER_SIZE != 1536)
46  #error ESP32_ETH_TX_BUFFER_SIZE parameter is not valid
47 #endif
48 
49 //Number of RX buffers
50 #ifndef ESP32_ETH_RX_BUFFER_COUNT
51  #define ESP32_ETH_RX_BUFFER_COUNT 6
52 #elif (ESP32_ETH_RX_BUFFER_COUNT < 1)
53  #error ESP32_ETH_RX_BUFFER_COUNT parameter is not valid
54 #endif
55 
56 //RX buffer size
57 #ifndef ESP32_ETH_RX_BUFFER_SIZE
58  #define ESP32_ETH_RX_BUFFER_SIZE 1536
59 #elif (ESP32_ETH_RX_BUFFER_SIZE != 1536)
60  #error ESP32_ETH_RX_BUFFER_SIZE parameter is not valid
61 #endif
62 
63 //Interrupt priority grouping
64 #ifndef ESP32_ETH_IRQ_PRIORITY_GROUPING
65  #define ESP32_ETH_IRQ_PRIORITY_GROUPING 3
66 #elif (ESP32_ETH_IRQ_PRIORITY_GROUPING < 0)
67  #error ESP32_ETH_IRQ_PRIORITY_GROUPING parameter is not valid
68 #endif
69 
70 //Ethernet interrupt group priority
71 #ifndef ESP32_ETH_IRQ_GROUP_PRIORITY
72  #define ESP32_ETH_IRQ_GROUP_PRIORITY 12
73 #elif (ESP32_ETH_IRQ_GROUP_PRIORITY < 0)
74  #error ESP32_ETH_IRQ_GROUP_PRIORITY parameter is not valid
75 #endif
76 
77 //Ethernet interrupt subpriority
78 #ifndef ESP32_ETH_IRQ_SUB_PRIORITY
79  #define ESP32_ETH_IRQ_SUB_PRIORITY 0
80 #elif (ESP32_ETH_IRQ_SUB_PRIORITY < 0)
81  #error ESP32_ETH_IRQ_SUB_PRIORITY parameter is not valid
82 #endif
83 
84 //Transmit DMA descriptor flags
85 #define EMAC_TDES0_OWN 0x80000000
86 #define EMAC_TDES0_IC 0x40000000
87 #define EMAC_TDES0_LS 0x20000000
88 #define EMAC_TDES0_FS 0x10000000
89 #define EMAC_TDES0_DC 0x08000000
90 #define EMAC_TDES0_DP 0x04000000
91 #define EMAC_TDES0_TTSE 0x02000000
92 #define EMAC_TDES0_CIC 0x00C00000
93 #define EMAC_TDES0_TER 0x00200000
94 #define EMAC_TDES0_TCH 0x00100000
95 #define EMAC_TDES0_TTSS 0x00020000
96 #define EMAC_TDES0_IHE 0x00010000
97 #define EMAC_TDES0_ES 0x00008000
98 #define EMAC_TDES0_JT 0x00004000
99 #define EMAC_TDES0_FF 0x00002000
100 #define EMAC_TDES0_IPE 0x00001000
101 #define EMAC_TDES0_LCA 0x00000800
102 #define EMAC_TDES0_NC 0x00000400
103 #define EMAC_TDES0_LCO 0x00000200
104 #define EMAC_TDES0_EC 0x00000100
105 #define EMAC_TDES0_VF 0x00000080
106 #define EMAC_TDES0_CC 0x00000078
107 #define EMAC_TDES0_ED 0x00000004
108 #define EMAC_TDES0_UF 0x00000002
109 #define EMAC_TDES0_DB 0x00000001
110 #define EMAC_TDES1_TBS2 0x1FFF0000
111 #define EMAC_TDES1_TBS1 0x00001FFF
112 #define EMAC_TDES2_TBAP1 0xFFFFFFFF
113 #define EMAC_TDES3_TBAP2 0xFFFFFFFF
114 #define EMAC_TDES6_TTSL 0xFFFFFFFF
115 #define EMAC_TDES7_TTSH 0xFFFFFFFF
116 
117 //Receive DMA descriptor flags
118 #define EMAC_RDES0_OWN 0x80000000
119 #define EMAC_RDES0_AFM 0x40000000
120 #define EMAC_RDES0_FL 0x3FFF0000
121 #define EMAC_RDES0_ES 0x00008000
122 #define EMAC_RDES0_DE 0x00004000
123 #define EMAC_RDES0_SAF 0x00002000
124 #define EMAC_RDES0_LE 0x00001000
125 #define EMAC_RDES0_OE 0x00000800
126 #define EMAC_RDES0_VLAN 0x00000400
127 #define EMAC_RDES0_FS 0x00000200
128 #define EMAC_RDES0_LS 0x00000100
129 #define EMAC_RDES0_IPHCE 0x00000080
130 #define EMAC_RDES0_LCO 0x00000040
131 #define EMAC_RDES0_FT 0x00000020
132 #define EMAC_RDES0_RWT 0x00000010
133 #define EMAC_RDES0_RE 0x00000008
134 #define EMAC_RDES0_DBE 0x00000004
135 #define EMAC_RDES0_CE 0x00000002
136 #define EMAC_RDES0_PCE 0x00000001
137 #define EMAC_RDES1_DIC 0x80000000
138 #define EMAC_RDES1_RBS2 0x1FFF0000
139 #define EMAC_RDES1_RER 0x00008000
140 #define EMAC_RDES1_RCH 0x00004000
141 #define EMAC_RDES1_RBS1 0x00001FFF
142 #define EMAC_RDES2_RBAP1 0xFFFFFFFF
143 #define EMAC_RDES3_RBAP2 0xFFFFFFFF
144 #define EMAC_RDES4_PV 0x00002000
145 #define EMAC_RDES4_PFT 0x00001000
146 #define EMAC_RDES4_PMT 0x00000F00
147 #define EMAC_RDES4_IPV6PR 0x00000080
148 #define EMAC_RDES4_IPV4PR 0x00000040
149 #define EMAC_RDES4_IPCB 0x00000020
150 #define EMAC_RDES4_IPPE 0x00000010
151 #define EMAC_RDES4_IPHE 0x00000008
152 #define EMAC_RDES4_IPPT 0x00000007
153 #define EMAC_RDES6_RTSL 0xFFFFFFFF
154 #define EMAC_RDES7_RTSH 0xFFFFFFFF
155 
156 //C++ guard
157 #ifdef __cplusplus
158  extern "C" {
159 #endif
160 
161 
162 /**
163  * @brief Enhanced TX DMA descriptor
164  **/
165 
166 typedef struct
167 {
168  uint32_t tdes0;
169  uint32_t tdes1;
170  uint32_t tdes2;
171  uint32_t tdes3;
172  uint32_t tdes4;
173  uint32_t tdes5;
174  uint32_t tdes6;
175  uint32_t tdes7;
177 
178 
179 /**
180  * @brief Enhanced RX DMA descriptor
181  **/
182 
183 typedef struct
184 {
185  uint32_t rdes0;
186  uint32_t rdes1;
187  uint32_t rdes2;
188  uint32_t rdes3;
189  uint32_t rdes4;
190  uint32_t rdes5;
191  uint32_t rdes6;
192  uint32_t rdes7;
194 
195 
196 //ESP32 Ethernet MAC driver
197 extern const NicDriver esp32EthDriver;
198 
199 //ESP32 Ethernet MAC related functions
200 error_t esp32EthInit(NetInterface *interface);
201 void esp32EthInitGpio(NetInterface *interface);
202 void esp32EthInitDmaDesc(NetInterface *interface);
203 
204 void esp32EthTick(NetInterface *interface);
205 
206 void esp32EthEnableIrq(NetInterface *interface);
207 void esp32EthDisableIrq(NetInterface *interface);
208 void esp32EthIrqHandler(void *arg);
209 void esp32EthEventHandler(NetInterface *interface);
210 
212  const NetBuffer *buffer, size_t offset);
213 
215 
218 
219 void esp32EthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data);
220 uint16_t esp32EthReadPhyReg(uint8_t phyAddr, uint8_t regAddr);
221 
222 //C++ guard
223 #ifdef __cplusplus
224  }
225 #endif
226 
227 #endif
Enhanced TX DMA descriptor.
error_t esp32EthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
void esp32EthEnableIrq(NetInterface *interface)
Enable interrupts.
void esp32EthInitGpio(NetInterface *interface)
error_t esp32EthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset)
Send a packet.
void esp32EthInitDmaDesc(NetInterface *interface)
Initialize DMA descriptor lists.
const NicDriver esp32EthDriver
ESP32 Ethernet MAC driver.
NIC driver.
Definition: nic.h:161
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:86
void esp32EthEventHandler(NetInterface *interface)
ESP32 Ethernet MAC event handler.
void esp32EthTick(NetInterface *interface)
ESP32 Ethernet MAC timer handler.
void esp32EthDisableIrq(NetInterface *interface)
Disable interrupts.
error_t esp32EthInit(NetInterface *interface)
ESP32 Ethernet MAC initialization.
error_t esp32EthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
uint16_t regAddr
error_t
Error codes.
Definition: error.h:40
uint16_t esp32EthReadPhyReg(uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
uint8_t data[]
Definition: dtls_misc.h:167
#define NetInterface
Definition: net.h:34
error_t esp32EthReceivePacket(NetInterface *interface)
Receive a packet.
Enhanced RX DMA descriptor.
Network interface controller abstraction layer.
void esp32EthIrqHandler(void *arg)
ESP32 Ethernet MAC interrupt service routine.
void esp32EthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.