gd32h7xx_eth2_driver.h
Go to the documentation of this file.
1 /**
2  * @file gd32h7xx_eth2_driver.h
3  * @brief GigaDevice GD32H7 Ethernet MAC driver (ENET1 instance)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 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.5.0
29  **/
30 
31 #ifndef _GD32H7XX_ETH2_DRIVER_H
32 #define _GD32H7XX_ETH2_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //Number of TX buffers
38 #ifndef GD32H7XX_ETH2_TX_BUFFER_COUNT
39  #define GD32H7XX_ETH2_TX_BUFFER_COUNT 8
40 #elif (GD32H7XX_ETH2_TX_BUFFER_COUNT < 1)
41  #error GD32H7XX_ETH2_TX_BUFFER_COUNT parameter is not valid
42 #endif
43 
44 //TX buffer size
45 #ifndef GD32H7XX_ETH2_TX_BUFFER_SIZE
46  #define GD32H7XX_ETH2_TX_BUFFER_SIZE 1536
47 #elif (GD32H7XX_ETH2_TX_BUFFER_SIZE != 1536)
48  #error GD32H7XX_ETH2_TX_BUFFER_SIZE parameter is not valid
49 #endif
50 
51 //Number of RX buffers
52 #ifndef GD32H7XX_ETH2_RX_BUFFER_COUNT
53  #define GD32H7XX_ETH2_RX_BUFFER_COUNT 8
54 #elif (GD32H7XX_ETH2_RX_BUFFER_COUNT < 1)
55  #error GD32H7XX_ETH2_RX_BUFFER_COUNT parameter is not valid
56 #endif
57 
58 //RX buffer size
59 #ifndef GD32H7XX_ETH2_RX_BUFFER_SIZE
60  #define GD32H7XX_ETH2_RX_BUFFER_SIZE 1536
61 #elif (GD32H7XX_ETH2_RX_BUFFER_SIZE != 1536)
62  #error GD32H7XX_ETH2_RX_BUFFER_SIZE parameter is not valid
63 #endif
64 
65 //Interrupt priority grouping
66 #ifndef GD32H7XX_ETH2_IRQ_PRIORITY_GROUPING
67  #define GD32H7XX_ETH2_IRQ_PRIORITY_GROUPING 3
68 #elif (GD32H7XX_ETH2_IRQ_PRIORITY_GROUPING < 0)
69  #error GD32H7XX_ETH2_IRQ_PRIORITY_GROUPING parameter is not valid
70 #endif
71 
72 //Ethernet interrupt group priority
73 #ifndef GD32H7XX_ETH2_IRQ_GROUP_PRIORITY
74  #define GD32H7XX_ETH2_IRQ_GROUP_PRIORITY 12
75 #elif (GD32H7XX_ETH2_IRQ_GROUP_PRIORITY < 0)
76  #error GD32H7XX_ETH2_IRQ_GROUP_PRIORITY parameter is not valid
77 #endif
78 
79 //Ethernet interrupt subpriority
80 #ifndef GD32H7XX_ETH2_IRQ_SUB_PRIORITY
81  #define GD32H7XX_ETH2_IRQ_SUB_PRIORITY 0
82 #elif (GD32H7XX_ETH2_IRQ_SUB_PRIORITY < 0)
83  #error GD32H7XX_ETH2_IRQ_SUB_PRIORITY parameter is not valid
84 #endif
85 
86 //Name of the section where to place DMA buffers
87 #ifndef STM32H7XX_ETH2_RAM_SECTION
88  #define STM32H7XX_ETH2_RAM_SECTION ".ram_no_cache"
89 #endif
90 
91 //C++ guard
92 #ifdef __cplusplus
93 extern "C" {
94 #endif
95 
96 
97 /**
98  * @brief Enhanced TX DMA descriptor
99  **/
100 
101 typedef struct
102 {
103  uint32_t tdes0;
104  uint32_t tdes1;
105  uint32_t tdes2;
106  uint32_t tdes3;
107  uint32_t tdes4;
108  uint32_t tdes5;
109  uint32_t tdes6;
110  uint32_t tdes7;
112 
113 
114 /**
115  * @brief Enhanced RX DMA descriptor
116  **/
117 
118 typedef struct
119 {
120  uint32_t rdes0;
121  uint32_t rdes1;
122  uint32_t rdes2;
123  uint32_t rdes3;
124  uint32_t rdes4;
125  uint32_t rdes5;
126  uint32_t rdes6;
127  uint32_t rdes7;
129 
130 
131 //GD32H7 Ethernet MAC driver
132 extern const NicDriver gd32h7xxEth2Driver;
133 
134 //GD32H7 Ethernet MAC related functions
136 void gd32h7xxEth2InitGpio(NetInterface *interface);
137 void gd32h7xxEth2InitDmaDesc(NetInterface *interface);
138 
139 void gd32h7xxEth2Tick(NetInterface *interface);
140 
141 void gd32h7xxEth2EnableIrq(NetInterface *interface);
142 void gd32h7xxEth2DisableIrq(NetInterface *interface);
143 void gd32h7xxEth2EventHandler(NetInterface *interface);
144 
146  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
147 
149 
152 
153 void gd32h7xxEth2WritePhyReg(uint8_t opcode, uint8_t phyAddr,
154  uint8_t regAddr, uint16_t data);
155 
156 uint16_t gd32h7xxEth2ReadPhyReg(uint8_t opcode, uint8_t phyAddr,
157  uint8_t regAddr);
158 
159 uint32_t gd32h7xxEth2CalcCrc(const void *data, size_t length);
160 
161 //C++ guard
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 #endif
Enhanced RX DMA descriptor.
uint8_t opcode
Definition: dns_common.h:188
error_t gd32h7xxEth2Init(NetInterface *interface)
GD32H7 Ethernet MAC initialization.
uint32_t gd32h7xxEth2CalcCrc(const void *data, size_t length)
CRC calculation.
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t data[]
Definition: ethernet.h:222
void gd32h7xxEth2EventHandler(NetInterface *interface)
GD32H7 Ethernet MAC event handler.
Enhanced TX DMA descriptor.
error_t gd32h7xxEth2UpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
void gd32h7xxEth2DisableIrq(NetInterface *interface)
Disable interrupts.
error_t gd32h7xxEth2ReceivePacket(NetInterface *interface)
Receive a packet.
error_t gd32h7xxEth2UpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
error_t
Error codes.
Definition: error.h:43
void gd32h7xxEth2InitDmaDesc(NetInterface *interface)
Initialize DMA descriptor lists.
void gd32h7xxEth2Tick(NetInterface *interface)
GD32H7 Ethernet MAC timer handler.
#define NetInterface
Definition: net.h:36
#define NetTxAncillary
Definition: net_misc.h:36
uint8_t length
Definition: tcp.h:375
const NicDriver gd32h7xxEth2Driver
GD32H7 Ethernet MAC driver (ENET1 instance)
uint16_t regAddr
void gd32h7xxEth2InitGpio(NetInterface *interface)
GPIO configuration.
Network interface controller abstraction layer.
error_t gd32h7xxEth2SendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
void gd32h7xxEth2EnableIrq(NetInterface *interface)
Enable interrupts.
NIC driver.
Definition: nic.h:286
uint16_t gd32h7xxEth2ReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
void gd32h7xxEth2WritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.