gd32h7xx_eth1_driver.h
Go to the documentation of this file.
1 /**
2  * @file gd32h7xx_eth1_driver.h
3  * @brief GigaDevice GD32H7 Ethernet MAC driver (ENET0 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_ETH1_DRIVER_H
32 #define _GD32H7XX_ETH1_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //Number of TX buffers
38 #ifndef GD32H7XX_ETH1_TX_BUFFER_COUNT
39  #define GD32H7XX_ETH1_TX_BUFFER_COUNT 8
40 #elif (GD32H7XX_ETH1_TX_BUFFER_COUNT < 1)
41  #error GD32H7XX_ETH1_TX_BUFFER_COUNT parameter is not valid
42 #endif
43 
44 //TX buffer size
45 #ifndef GD32H7XX_ETH1_TX_BUFFER_SIZE
46  #define GD32H7XX_ETH1_TX_BUFFER_SIZE 1536
47 #elif (GD32H7XX_ETH1_TX_BUFFER_SIZE != 1536)
48  #error GD32H7XX_ETH1_TX_BUFFER_SIZE parameter is not valid
49 #endif
50 
51 //Number of RX buffers
52 #ifndef GD32H7XX_ETH1_RX_BUFFER_COUNT
53  #define GD32H7XX_ETH1_RX_BUFFER_COUNT 8
54 #elif (GD32H7XX_ETH1_RX_BUFFER_COUNT < 1)
55  #error GD32H7XX_ETH1_RX_BUFFER_COUNT parameter is not valid
56 #endif
57 
58 //RX buffer size
59 #ifndef GD32H7XX_ETH1_RX_BUFFER_SIZE
60  #define GD32H7XX_ETH1_RX_BUFFER_SIZE 1536
61 #elif (GD32H7XX_ETH1_RX_BUFFER_SIZE != 1536)
62  #error GD32H7XX_ETH1_RX_BUFFER_SIZE parameter is not valid
63 #endif
64 
65 //Interrupt priority grouping
66 #ifndef GD32H7XX_ETH1_IRQ_PRIORITY_GROUPING
67  #define GD32H7XX_ETH1_IRQ_PRIORITY_GROUPING 3
68 #elif (GD32H7XX_ETH1_IRQ_PRIORITY_GROUPING < 0)
69  #error GD32H7XX_ETH1_IRQ_PRIORITY_GROUPING parameter is not valid
70 #endif
71 
72 //Ethernet interrupt group priority
73 #ifndef GD32H7XX_ETH1_IRQ_GROUP_PRIORITY
74  #define GD32H7XX_ETH1_IRQ_GROUP_PRIORITY 12
75 #elif (GD32H7XX_ETH1_IRQ_GROUP_PRIORITY < 0)
76  #error GD32H7XX_ETH1_IRQ_GROUP_PRIORITY parameter is not valid
77 #endif
78 
79 //Ethernet interrupt subpriority
80 #ifndef GD32H7XX_ETH1_IRQ_SUB_PRIORITY
81  #define GD32H7XX_ETH1_IRQ_SUB_PRIORITY 0
82 #elif (GD32H7XX_ETH1_IRQ_SUB_PRIORITY < 0)
83  #error GD32H7XX_ETH1_IRQ_SUB_PRIORITY parameter is not valid
84 #endif
85 
86 //Name of the section where to place DMA buffers
87 #ifndef STM32H7XX_ETH1_RAM_SECTION
88  #define STM32H7XX_ETH1_RAM_SECTION ".ram_no_cache"
89 #endif
90 //C++ guard
91 #ifdef __cplusplus
92 extern "C" {
93 #endif
94 
95 
96 /**
97  * @brief Enhanced TX DMA descriptor
98  **/
99 
100 typedef struct
101 {
102  uint32_t tdes0;
103  uint32_t tdes1;
104  uint32_t tdes2;
105  uint32_t tdes3;
106  uint32_t tdes4;
107  uint32_t tdes5;
108  uint32_t tdes6;
109  uint32_t tdes7;
111 
112 
113 /**
114  * @brief Enhanced RX DMA descriptor
115  **/
116 
117 typedef struct
118 {
119  uint32_t rdes0;
120  uint32_t rdes1;
121  uint32_t rdes2;
122  uint32_t rdes3;
123  uint32_t rdes4;
124  uint32_t rdes5;
125  uint32_t rdes6;
126  uint32_t rdes7;
128 
129 
130 //GD32H7 Ethernet MAC driver
131 extern const NicDriver gd32h7xxEth1Driver;
132 
133 //GD32H7 Ethernet MAC related functions
135 void gd32h7xxEth1InitGpio(NetInterface *interface);
136 void gd32h7xxEth1InitDmaDesc(NetInterface *interface);
137 
138 void gd32h7xxEth1Tick(NetInterface *interface);
139 
140 void gd32h7xxEth1EnableIrq(NetInterface *interface);
141 void gd32h7xxEth1DisableIrq(NetInterface *interface);
142 void gd32h7xxEth1EventHandler(NetInterface *interface);
143 
145  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
146 
148 
151 
152 void gd32h7xxEth1WritePhyReg(uint8_t opcode, uint8_t phyAddr,
153  uint8_t regAddr, uint16_t data);
154 
155 uint16_t gd32h7xxEth1ReadPhyReg(uint8_t opcode, uint8_t phyAddr,
156  uint8_t regAddr);
157 
158 uint32_t gd32h7xxEth1CalcCrc(const void *data, size_t length);
159 
160 //C++ guard
161 #ifdef __cplusplus
162 }
163 #endif
164 
165 #endif
uint8_t opcode
Definition: dns_common.h:188
error_t gd32h7xxEth1UpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
Enhanced RX DMA descriptor.
uint8_t data[]
Definition: ethernet.h:222
error_t gd32h7xxEth1UpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
void gd32h7xxEth1DisableIrq(NetInterface *interface)
Disable interrupts.
void gd32h7xxEth1WritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
Enhanced TX DMA descriptor.
error_t gd32h7xxEth1SendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
error_t gd32h7xxEth1Init(NetInterface *interface)
GD32H7 Ethernet MAC initialization.
error_t
Error codes.
Definition: error.h:43
const NicDriver gd32h7xxEth1Driver
GD32H7 Ethernet MAC driver (ENET0 instance)
#define NetInterface
Definition: net.h:36
#define NetTxAncillary
Definition: net_misc.h:36
uint32_t gd32h7xxEth1CalcCrc(const void *data, size_t length)
CRC calculation.
uint8_t length
Definition: tcp.h:375
void gd32h7xxEth1InitDmaDesc(NetInterface *interface)
Initialize DMA descriptor lists.
uint16_t regAddr
void gd32h7xxEth1EnableIrq(NetInterface *interface)
Enable interrupts.
Network interface controller abstraction layer.
void gd32h7xxEth1Tick(NetInterface *interface)
GD32H7 Ethernet MAC timer handler.
void gd32h7xxEth1InitGpio(NetInterface *interface)
GPIO configuration.
void gd32h7xxEth1EventHandler(NetInterface *interface)
GD32H7 Ethernet MAC event handler.
uint16_t gd32h7xxEth1ReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
NIC driver.
Definition: nic.h:286
error_t gd32h7xxEth1ReceivePacket(NetInterface *interface)
Receive a packet.