mk6x_eth_driver.h
Go to the documentation of this file.
1 /**
2  * @file mk6x_eth_driver.h
3  * @brief Freescale Kinetis K60/K64/K65/K66 Ethernet MAC controller
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _MK6X_ETH_DRIVER_H
30 #define _MK6X_ETH_DRIVER_H
31 
32 //Number of TX buffers
33 #ifndef MK6X_ETH_TX_BUFFER_COUNT
34  #define MK6X_ETH_TX_BUFFER_COUNT 3
35 #elif (MK6X_ETH_TX_BUFFER_COUNT < 1)
36  #error MK6X_ETH_TX_BUFFER_COUNT parameter is not valid
37 #endif
38 
39 //TX buffer size
40 #ifndef MK6X_ETH_TX_BUFFER_SIZE
41  #define MK6X_ETH_TX_BUFFER_SIZE 1536
42 #elif (MK6X_ETH_TX_BUFFER_SIZE != 1536)
43  #error MK6X_ETH_TX_BUFFER_SIZE parameter is not valid
44 #endif
45 
46 //Number of RX buffers
47 #ifndef MK6X_ETH_RX_BUFFER_COUNT
48  #define MK6X_ETH_RX_BUFFER_COUNT 6
49 #elif (MK6X_ETH_RX_BUFFER_COUNT < 1)
50  #error MK6X_ETH_RX_BUFFER_COUNT parameter is not valid
51 #endif
52 
53 //RX buffer size
54 #ifndef MK6X_ETH_RX_BUFFER_SIZE
55  #define MK6X_ETH_RX_BUFFER_SIZE 1536
56 #elif (MK6X_ETH_RX_BUFFER_SIZE != 1536)
57  #error MK6X_ETH_RX_BUFFER_SIZE parameter is not valid
58 #endif
59 
60 //Interrupt priority grouping
61 #ifndef MK6X_ETH_IRQ_PRIORITY_GROUPING
62  #define MK6X_ETH_IRQ_PRIORITY_GROUPING 3
63 #elif (MK6X_ETH_IRQ_PRIORITY_GROUPING < 0)
64  #error MK6X_ETH_IRQ_PRIORITY_GROUPING parameter is not valid
65 #endif
66 
67 //Ethernet interrupt group priority
68 #ifndef MK6X_ETH_IRQ_GROUP_PRIORITY
69  #define MK6X_ETH_IRQ_GROUP_PRIORITY 12
70 #elif (MK6X_ETH_IRQ_GROUP_PRIORITY < 0)
71  #error MK6X_ETH_IRQ_GROUP_PRIORITY parameter is not valid
72 #endif
73 
74 //Ethernet interrupt subpriority
75 #ifndef MK6X_ETH_IRQ_SUB_PRIORITY
76  #define MK6X_ETH_IRQ_SUB_PRIORITY 0
77 #elif (MK6X_ETH_IRQ_SUB_PRIORITY < 0)
78  #error MK6X_ETH_IRQ_SUB_PRIORITY parameter is not valid
79 #endif
80 
81 //Legacy definitions
82 #ifndef MPU
83  #define MPU SYSMPU
84 #endif
85 
86 #ifndef MPU_CESR_VLD_MASK
87  #define MPU_CESR_VLD_MASK SYSMPU_CESR_VLD_MASK
88 #endif
89 
90 //Enhanced transmit buffer descriptor
91 #define ENET_TBD0_R 0x8000
92 #define ENET_TBD0_TO1 0x4000
93 #define ENET_TBD0_W 0x2000
94 #define ENET_TBD0_TO2 0x1000
95 #define ENET_TBD0_L 0x0800
96 #define ENET_TBD0_TC 0x0400
97 #define ENET_TBD1_DATA_LENGTH 0xFFFF
98 #define ENET_TBD2_DATA_POINTER_H 0xFFFF
99 #define ENET_TBD3_DATA_POINTER_L 0xFFFF
100 #define ENET_TBD4_INT 0x4000
101 #define ENET_TBD4_TS 0x2000
102 #define ENET_TBD4_PINS 0x1000
103 #define ENET_TBD4_IINS 0x0800
104 #define ENET_TBD5_TXE 0x8000
105 #define ENET_TBD5_UE 0x2000
106 #define ENET_TBD5_EE 0x1000
107 #define ENET_TBD5_FE 0x0800
108 #define ENET_TBD5_LCE 0x0400
109 #define ENET_TBD5_OE 0x0200
110 #define ENET_TBD5_TSE 0x0100
111 #define ENET_TBD8_BDU 0x8000
112 #define ENET_TBD10_TIMESTAMP_H 0xFFFF
113 #define ENET_TBD11_TIMESTAMP_L 0xFFFF
114 
115 //Enhanced receive buffer descriptor
116 #define ENET_RBD0_E 0x8000
117 #define ENET_RBD0_RO1 0x4000
118 #define ENET_RBD0_W 0x2000
119 #define ENET_RBD0_RO2 0x1000
120 #define ENET_RBD0_L 0x0800
121 #define ENET_RBD0_M 0x0100
122 #define ENET_RBD0_BC 0x0080
123 #define ENET_RBD0_MC 0x0040
124 #define ENET_RBD0_LG 0x0020
125 #define ENET_RBD0_NO 0x0010
126 #define ENET_RBD0_CR 0x0004
127 #define ENET_RBD0_OV 0x0002
128 #define ENET_RBD0_TR 0x0001
129 #define ENET_RBD1_DATA_LENGTH 0xFFFF
130 #define ENET_RBD2_DATA_POINTER_H 0xFFFF
131 #define ENET_RBD3_DATA_POINTER_L 0xFFFF
132 #define ENET_RBD4_ME 0x8000
133 #define ENET_RBD4_PE 0x0400
134 #define ENET_RBD4_CE 0x0200
135 #define ENET_RBD4_UC 0x0100
136 #define ENET_RBD4_INT 0x0080
137 #define ENET_RBD5_VPCP 0xE000
138 #define ENET_RBD5_ICE 0x0020
139 #define ENET_RBD5_PCR 0x0010
140 #define ENET_RBD5_VLAN 0x0004
141 #define ENET_RBD5_IPV6 0x0002
142 #define ENET_RBD5_FRAG 0x0001
143 #define ENET_RBD6_HEADER_LENGTH 0xF800
144 #define ENET_RBD6_PROTOCOL_TYPE 0x00FF
145 #define ENET_RBD7_PAYLOAD_CHECKSUM 0xFFFF
146 #define ENET_RBD8_BDU 0x8000
147 #define ENET_RBD10_TIMESTAMP_H 0xFFFF
148 #define ENET_RBD11_TIMESTAMP_L 0xFFFF
149 
150 //C++ guard
151 #ifdef __cplusplus
152  extern "C" {
153 #endif
154 
155 //Kinetis K6x Ethernet MAC driver
156 extern const NicDriver mk6xEthDriver;
157 
158 //Kinetis K6x Ethernet MAC related functions
159 error_t mk6xEthInit(NetInterface *interface);
160 void mk6xEthInitGpio(NetInterface *interface);
161 void mk6xEthInitBufferDesc(NetInterface *interface);
162 
163 void mk6xEthTick(NetInterface *interface);
164 
165 void mk6xEthEnableIrq(NetInterface *interface);
166 void mk6xEthDisableIrq(NetInterface *interface);
167 void mk6xEthEventHandler(NetInterface *interface);
168 
170  const NetBuffer *buffer, size_t offset);
171 
173 
176 
177 void mk6xEthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data);
178 uint16_t mk6xEthReadPhyReg(uint8_t phyAddr, uint8_t regAddr);
179 
180 uint32_t mk6xEthCalcCrc(const void *data, size_t length);
181 
182 //C++ guard
183 #ifdef __cplusplus
184  }
185 #endif
186 
187 #endif
error_t mk6xEthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
error_t mk6xEthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset)
Send a packet.
void mk6xEthEventHandler(NetInterface *interface)
Kinetis K6x Ethernet MAC event handler.
const NicDriver mk6xEthDriver
Kinetis K6x Ethernet MAC driver.
error_t mk6xEthReceivePacket(NetInterface *interface)
Receive a packet.
void mk6xEthDisableIrq(NetInterface *interface)
Disable interrupts.
error_t mk6xEthInit(NetInterface *interface)
Kinetis K6x Ethernet MAC initialization.
void mk6xEthInitBufferDesc(NetInterface *interface)
Initialize buffer descriptors.
NIC driver.
Definition: nic.h:161
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:86
uint16_t regAddr
uint16_t mk6xEthReadPhyReg(uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
void mk6xEthTick(NetInterface *interface)
Kinetis K6x Ethernet MAC timer handler.
error_t
Error codes.
Definition: error.h:40
void mk6xEthInitGpio(NetInterface *interface)
uint8_t data[]
Definition: dtls_misc.h:167
#define NetInterface
Definition: net.h:34
error_t mk6xEthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
void mk6xEthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
uint32_t mk6xEthCalcCrc(const void *data, size_t length)
CRC calculation.
uint8_t length
Definition: dtls_misc.h:140
void mk6xEthEnableIrq(NetInterface *interface)
Enable interrupts.