mk6x_eth_driver.h
Go to the documentation of this file.
1 /**
2  * @file mk6x_eth_driver.h
3  * @brief NXP Kinetis K60/K64/K65/K66 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 _MK6X_ETH_DRIVER_H
32 #define _MK6X_ETH_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //Number of TX buffers
38 #ifndef MK6X_ETH_TX_BUFFER_COUNT
39  #define MK6X_ETH_TX_BUFFER_COUNT 3
40 #elif (MK6X_ETH_TX_BUFFER_COUNT < 1)
41  #error MK6X_ETH_TX_BUFFER_COUNT parameter is not valid
42 #endif
43 
44 //TX buffer size
45 #ifndef MK6X_ETH_TX_BUFFER_SIZE
46  #define MK6X_ETH_TX_BUFFER_SIZE 1536
47 #elif (MK6X_ETH_TX_BUFFER_SIZE != 1536)
48  #error MK6X_ETH_TX_BUFFER_SIZE parameter is not valid
49 #endif
50 
51 //Number of RX buffers
52 #ifndef MK6X_ETH_RX_BUFFER_COUNT
53  #define MK6X_ETH_RX_BUFFER_COUNT 6
54 #elif (MK6X_ETH_RX_BUFFER_COUNT < 1)
55  #error MK6X_ETH_RX_BUFFER_COUNT parameter is not valid
56 #endif
57 
58 //RX buffer size
59 #ifndef MK6X_ETH_RX_BUFFER_SIZE
60  #define MK6X_ETH_RX_BUFFER_SIZE 1536
61 #elif (MK6X_ETH_RX_BUFFER_SIZE != 1536)
62  #error MK6X_ETH_RX_BUFFER_SIZE parameter is not valid
63 #endif
64 
65 //Interrupt priority grouping
66 #ifndef MK6X_ETH_IRQ_PRIORITY_GROUPING
67  #define MK6X_ETH_IRQ_PRIORITY_GROUPING 3
68 #elif (MK6X_ETH_IRQ_PRIORITY_GROUPING < 0)
69  #error MK6X_ETH_IRQ_PRIORITY_GROUPING parameter is not valid
70 #endif
71 
72 //Ethernet interrupt group priority
73 #ifndef MK6X_ETH_IRQ_GROUP_PRIORITY
74  #define MK6X_ETH_IRQ_GROUP_PRIORITY 12
75 #elif (MK6X_ETH_IRQ_GROUP_PRIORITY < 0)
76  #error MK6X_ETH_IRQ_GROUP_PRIORITY parameter is not valid
77 #endif
78 
79 //Ethernet interrupt subpriority
80 #ifndef MK6X_ETH_IRQ_SUB_PRIORITY
81  #define MK6X_ETH_IRQ_SUB_PRIORITY 0
82 #elif (MK6X_ETH_IRQ_SUB_PRIORITY < 0)
83  #error MK6X_ETH_IRQ_SUB_PRIORITY parameter is not valid
84 #endif
85 
86 //Legacy definitions
87 #ifndef MPU
88  #define MPU SYSMPU
89 #endif
90 
91 #ifndef MPU_CESR_VLD_MASK
92  #define MPU_CESR_VLD_MASK SYSMPU_CESR_VLD_MASK
93 #endif
94 
95 //Enhanced transmit buffer descriptor
96 #define ENET_TBD0_R 0x8000
97 #define ENET_TBD0_TO1 0x4000
98 #define ENET_TBD0_W 0x2000
99 #define ENET_TBD0_TO2 0x1000
100 #define ENET_TBD0_L 0x0800
101 #define ENET_TBD0_TC 0x0400
102 #define ENET_TBD1_DATA_LENGTH 0xFFFF
103 #define ENET_TBD2_DATA_POINTER_H 0xFFFF
104 #define ENET_TBD3_DATA_POINTER_L 0xFFFF
105 #define ENET_TBD4_INT 0x4000
106 #define ENET_TBD4_TS 0x2000
107 #define ENET_TBD4_PINS 0x1000
108 #define ENET_TBD4_IINS 0x0800
109 #define ENET_TBD5_TXE 0x8000
110 #define ENET_TBD5_UE 0x2000
111 #define ENET_TBD5_EE 0x1000
112 #define ENET_TBD5_FE 0x0800
113 #define ENET_TBD5_LCE 0x0400
114 #define ENET_TBD5_OE 0x0200
115 #define ENET_TBD5_TSE 0x0100
116 #define ENET_TBD8_BDU 0x8000
117 #define ENET_TBD10_TIMESTAMP_H 0xFFFF
118 #define ENET_TBD11_TIMESTAMP_L 0xFFFF
119 
120 //Enhanced receive buffer descriptor
121 #define ENET_RBD0_E 0x8000
122 #define ENET_RBD0_RO1 0x4000
123 #define ENET_RBD0_W 0x2000
124 #define ENET_RBD0_RO2 0x1000
125 #define ENET_RBD0_L 0x0800
126 #define ENET_RBD0_M 0x0100
127 #define ENET_RBD0_BC 0x0080
128 #define ENET_RBD0_MC 0x0040
129 #define ENET_RBD0_LG 0x0020
130 #define ENET_RBD0_NO 0x0010
131 #define ENET_RBD0_CR 0x0004
132 #define ENET_RBD0_OV 0x0002
133 #define ENET_RBD0_TR 0x0001
134 #define ENET_RBD1_DATA_LENGTH 0xFFFF
135 #define ENET_RBD2_DATA_POINTER_H 0xFFFF
136 #define ENET_RBD3_DATA_POINTER_L 0xFFFF
137 #define ENET_RBD4_ME 0x8000
138 #define ENET_RBD4_PE 0x0400
139 #define ENET_RBD4_CE 0x0200
140 #define ENET_RBD4_UC 0x0100
141 #define ENET_RBD4_INT 0x0080
142 #define ENET_RBD5_VPCP 0xE000
143 #define ENET_RBD5_ICE 0x0020
144 #define ENET_RBD5_PCR 0x0010
145 #define ENET_RBD5_VLAN 0x0004
146 #define ENET_RBD5_IPV6 0x0002
147 #define ENET_RBD5_FRAG 0x0001
148 #define ENET_RBD6_HEADER_LENGTH 0xF800
149 #define ENET_RBD6_PROTOCOL_TYPE 0x00FF
150 #define ENET_RBD7_PAYLOAD_CHECKSUM 0xFFFF
151 #define ENET_RBD8_BDU 0x8000
152 #define ENET_RBD10_TIMESTAMP_H 0xFFFF
153 #define ENET_RBD11_TIMESTAMP_L 0xFFFF
154 
155 //C++ guard
156 #ifdef __cplusplus
157 extern "C" {
158 #endif
159 
160 //Kinetis K6x Ethernet MAC driver
161 extern const NicDriver mk6xEthDriver;
162 
163 //Kinetis K6x Ethernet MAC related functions
164 error_t mk6xEthInit(NetInterface *interface);
165 void mk6xEthInitGpio(NetInterface *interface);
166 void mk6xEthInitBufferDesc(NetInterface *interface);
167 
168 void mk6xEthTick(NetInterface *interface);
169 
170 void mk6xEthEnableIrq(NetInterface *interface);
171 void mk6xEthDisableIrq(NetInterface *interface);
172 void mk6xEthEventHandler(NetInterface *interface);
173 
175  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
176 
178 
181 
182 void mk6xEthWritePhyReg(uint8_t opcode, uint8_t phyAddr,
183  uint8_t regAddr, uint16_t data);
184 
185 uint16_t mk6xEthReadPhyReg(uint8_t opcode, uint8_t phyAddr,
186  uint8_t regAddr);
187 
188 uint32_t mk6xEthCalcCrc(const void *data, size_t length);
189 
190 //C++ guard
191 #ifdef __cplusplus
192 }
193 #endif
194 
195 #endif
uint8_t opcode
Definition: dns_common.h:191
void mk6xEthEventHandler(NetInterface *interface)
Kinetis K6x Ethernet MAC event handler.
error_t mk6xEthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
const NicDriver mk6xEthDriver
Kinetis K6x Ethernet MAC driver.
error_t mk6xEthReceivePacket(NetInterface *interface)
Receive a packet.
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t data[]
Definition: ethernet.h:224
uint16_t mk6xEthReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
error_t mk6xEthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
error_t
Error codes.
Definition: error.h:43
error_t mk6xEthInit(NetInterface *interface)
Kinetis K6x Ethernet MAC initialization.
void mk6xEthTick(NetInterface *interface)
Kinetis K6x Ethernet MAC timer handler.
#define NetInterface
Definition: net.h:36
#define NetTxAncillary
Definition: net_misc.h:36
error_t mk6xEthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
uint8_t length
Definition: tcp.h:375
void mk6xEthWritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
uint16_t regAddr
void mk6xEthEnableIrq(NetInterface *interface)
Enable interrupts.
Network interface controller abstraction layer.
void mk6xEthInitBufferDesc(NetInterface *interface)
Initialize buffer descriptors.
NIC driver.
Definition: nic.h:286
void mk6xEthDisableIrq(NetInterface *interface)
Disable interrupts.
uint32_t mk6xEthCalcCrc(const void *data, size_t length)
CRC calculation.
void mk6xEthInitGpio(NetInterface *interface)
GPIO configuration.