mk7x_eth_driver.h
Go to the documentation of this file.
1 /**
2  * @file mk7x_eth_driver.h
3  * @brief NXP Kinetis K70 Ethernet MAC driver
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.4
29  **/
30 
31 #ifndef _MK7X_ETH_DRIVER_H
32 #define _MK7X_ETH_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //Number of TX buffers
38 #ifndef MK7X_ETH_TX_BUFFER_COUNT
39  #define MK7X_ETH_TX_BUFFER_COUNT 3
40 #elif (MK7X_ETH_TX_BUFFER_COUNT < 1)
41  #error MK7X_ETH_TX_BUFFER_COUNT parameter is not valid
42 #endif
43 
44 //TX buffer size
45 #ifndef MK7X_ETH_TX_BUFFER_SIZE
46  #define MK7X_ETH_TX_BUFFER_SIZE 1536
47 #elif (MK7X_ETH_TX_BUFFER_SIZE != 1536)
48  #error MK7X_ETH_TX_BUFFER_SIZE parameter is not valid
49 #endif
50 
51 //Number of RX buffers
52 #ifndef MK7X_ETH_RX_BUFFER_COUNT
53  #define MK7X_ETH_RX_BUFFER_COUNT 6
54 #elif (MK7X_ETH_RX_BUFFER_COUNT < 1)
55  #error MK7X_ETH_RX_BUFFER_COUNT parameter is not valid
56 #endif
57 
58 //RX buffer size
59 #ifndef MK7X_ETH_RX_BUFFER_SIZE
60  #define MK7X_ETH_RX_BUFFER_SIZE 1536
61 #elif (MK7X_ETH_RX_BUFFER_SIZE != 1536)
62  #error MK7X_ETH_RX_BUFFER_SIZE parameter is not valid
63 #endif
64 
65 //Interrupt priority grouping
66 #ifndef MK7X_ETH_IRQ_PRIORITY_GROUPING
67  #define MK7X_ETH_IRQ_PRIORITY_GROUPING 3
68 #elif (MK7X_ETH_IRQ_PRIORITY_GROUPING < 0)
69  #error MK7X_ETH_IRQ_PRIORITY_GROUPING parameter is not valid
70 #endif
71 
72 //Ethernet interrupt group priority
73 #ifndef MK7X_ETH_IRQ_GROUP_PRIORITY
74  #define MK7X_ETH_IRQ_GROUP_PRIORITY 12
75 #elif (MK7X_ETH_IRQ_GROUP_PRIORITY < 0)
76  #error MK7X_ETH_IRQ_GROUP_PRIORITY parameter is not valid
77 #endif
78 
79 //Ethernet interrupt subpriority
80 #ifndef MK7X_ETH_IRQ_SUB_PRIORITY
81  #define MK7X_ETH_IRQ_SUB_PRIORITY 0
82 #elif (MK7X_ETH_IRQ_SUB_PRIORITY < 0)
83  #error MK7X_ETH_IRQ_SUB_PRIORITY parameter is not valid
84 #endif
85 
86 //Enhanced transmit buffer descriptor
87 #define ENET_TBD0_R 0x80000000
88 #define ENET_TBD0_TO1 0x40000000
89 #define ENET_TBD0_W 0x20000000
90 #define ENET_TBD0_TO2 0x10000000
91 #define ENET_TBD0_L 0x08000000
92 #define ENET_TBD0_TC 0x04000000
93 #define ENET_TBD0_DATA_LENGTH 0x0000FFFF
94 #define ENET_TBD1_DATA_POINTER 0xFFFFFFFF
95 #define ENET_TBD2_INT 0x40000000
96 #define ENET_TBD2_TS 0x20000000
97 #define ENET_TBD2_PINS 0x10000000
98 #define ENET_TBD2_IINS 0x08000000
99 #define ENET_TBD2_TXE 0x00008000
100 #define ENET_TBD2_UE 0x00002000
101 #define ENET_TBD2_EE 0x00001000
102 #define ENET_TBD2_FE 0x00000800
103 #define ENET_TBD2_LCE 0x00000400
104 #define ENET_TBD2_OE 0x00000200
105 #define ENET_TBD2_TSE 0x00000100
106 #define ENET_TBD4_BDU 0x80000000
107 #define ENET_TBD5_TIMESTAMP 0xFFFFFFFF
108 
109 //Enhanced receive buffer descriptor
110 #define ENET_RBD0_E 0x80000000
111 #define ENET_RBD0_RO1 0x40000000
112 #define ENET_RBD0_W 0x20000000
113 #define ENET_RBD0_RO2 0x10000000
114 #define ENET_RBD0_L 0x08000000
115 #define ENET_RBD0_M 0x01000000
116 #define ENET_RBD0_BC 0x00800000
117 #define ENET_RBD0_MC 0x00400000
118 #define ENET_RBD0_LG 0x00200000
119 #define ENET_RBD0_NO 0x00100000
120 #define ENET_RBD0_CR 0x00040000
121 #define ENET_RBD0_OV 0x00020000
122 #define ENET_RBD0_TR 0x00010000
123 #define ENET_RBD0_DATA_LENGTH 0x0000FFFF
124 #define ENET_RBD1_DATA_POINTER 0xFFFFFFFF
125 #define ENET_RBD2_ME 0x80000000
126 #define ENET_RBD2_PE 0x04000000
127 #define ENET_RBD2_CE 0x02000000
128 #define ENET_RBD2_UC 0x01000000
129 #define ENET_RBD2_INT 0x00800000
130 #define ENET_RBD2_VPCP 0x0000E000
131 #define ENET_RBD2_ICE 0x00000020
132 #define ENET_RBD2_PCR 0x00000010
133 #define ENET_RBD2_VLAN 0x00000004
134 #define ENET_RBD2_IPV6 0x00000002
135 #define ENET_RBD2_FRAG 0x00000001
136 #define ENET_RBD3_HEADER_LENGTH 0xF8000000
137 #define ENET_RBD3_PROTOCOL_TYPE 0x00FF0000
138 #define ENET_RBD3_PAYLOAD_CHECKSUM 0x0000FFFF
139 #define ENET_RBD4_BDU 0x80000000
140 #define ENET_RBD5_TIMESTAMP 0xFFFFFFFF
141 
142 //C++ guard
143 #ifdef __cplusplus
144 extern "C" {
145 #endif
146 
147 //Kinetis K7x Ethernet MAC driver
148 extern const NicDriver mk7xEthDriver;
149 
150 //Kinetis K7x Ethernet MAC related functions
151 error_t mk7xEthInit(NetInterface *interface);
152 void mk7xEthInitGpio(NetInterface *interface);
153 void mk7xEthInitBufferDesc(NetInterface *interface);
154 
155 void mk7xEthTick(NetInterface *interface);
156 
157 void mk7xEthEnableIrq(NetInterface *interface);
158 void mk7xEthDisableIrq(NetInterface *interface);
159 void mk7xEthEventHandler(NetInterface *interface);
160 
162  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
163 
165 
168 
169 void mk7xEthWritePhyReg(uint8_t opcode, uint8_t phyAddr,
170  uint8_t regAddr, uint16_t data);
171 
172 uint16_t mk7xEthReadPhyReg(uint8_t opcode, uint8_t phyAddr,
173  uint8_t regAddr);
174 
175 uint32_t mk7xEthCalcCrc(const void *data, size_t length);
176 
177 //C++ guard
178 #ifdef __cplusplus
179 }
180 #endif
181 
182 #endif
uint8_t opcode
Definition: dns_common.h:191
void mk7xEthWritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
void mk7xEthDisableIrq(NetInterface *interface)
Disable interrupts.
void mk7xEthInitBufferDesc(NetInterface *interface)
Initialize buffer descriptors.
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
error_t mk7xEthReceivePacket(NetInterface *interface)
Receive a packet.
uint8_t data[]
Definition: ethernet.h:224
uint32_t mk7xEthCalcCrc(const void *data, size_t length)
CRC calculation.
void mk7xEthInitGpio(NetInterface *interface)
GPIO configuration.
error_t mk7xEthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
error_t
Error codes.
Definition: error.h:43
void mk7xEthTick(NetInterface *interface)
Kinetis K7x Ethernet MAC timer handler.
#define NetInterface
Definition: net.h:36
#define NetTxAncillary
Definition: net_misc.h:36
uint8_t length
Definition: tcp.h:375
error_t mk7xEthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
uint16_t regAddr
uint16_t mk7xEthReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
void mk7xEthEnableIrq(NetInterface *interface)
Enable interrupts.
Network interface controller abstraction layer.
error_t mk7xEthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
error_t mk7xEthInit(NetInterface *interface)
Kinetis K7x Ethernet MAC initialization.
const NicDriver mk7xEthDriver
Kinetis K7x Ethernet MAC driver.
NIC driver.
Definition: nic.h:286
void mk7xEthEventHandler(NetInterface *interface)
Kinetis K7x Ethernet MAC event handler.