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