mcf5225x_eth_driver.h
Go to the documentation of this file.
1 /**
2  * @file mcf5225x_eth_driver.h
3  * @brief Coldfire V2 MCF5225x 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 _MCF5225X_ETH_DRIVER_H
30 #define _MCF5225X_ETH_DRIVER_H
31 
32 //Number of TX buffers
33 #ifndef MCF5225X_ETH_TX_BUFFER_COUNT
34  #define MCF5225X_ETH_TX_BUFFER_COUNT 2
35 #elif (MCF5225X_ETH_TX_BUFFER_COUNT < 1)
36  #error MCF5225X_ETH_TX_BUFFER_COUNT parameter is not valid
37 #endif
38 
39 //TX buffer size
40 #ifndef MCF5225X_ETH_TX_BUFFER_SIZE
41  #define MCF5225X_ETH_TX_BUFFER_SIZE 1536
42 #elif (MCF5225X_ETH_TX_BUFFER_SIZE != 1536)
43  #error MCF5225X_ETH_TX_BUFFER_SIZE parameter is not valid
44 #endif
45 
46 //Number of RX buffers
47 #ifndef MCF5225X_ETH_RX_BUFFER_COUNT
48  #define MCF5225X_ETH_RX_BUFFER_COUNT 4
49 #elif (MCF5225X_ETH_RX_BUFFER_COUNT < 1)
50  #error MCF5225X_ETH_RX_BUFFER_COUNT parameter is not valid
51 #endif
52 
53 //RX buffer size
54 #ifndef MCF5225X_ETH_RX_BUFFER_SIZE
55  #define MCF5225X_ETH_RX_BUFFER_SIZE 1536
56 #elif (MCF5225X_ETH_RX_BUFFER_SIZE != 1536)
57  #error MCF5225X_ETH_RX_BUFFER_SIZE parameter is not valid
58 #endif
59 
60 //Ethernet interrupt level
61 #ifndef MCF5225X_ETH_IRQ_LEVEL
62  #define MCF5225X_ETH_IRQ_LEVEL 4
63 #elif (MCF5225X_ETH_IRQ_LEVEL < 0)
64  #error MCF5225X_ETH_IRQ_LEVEL parameter is not valid
65 #endif
66 
67 //Ethernet interrupt priority
68 #ifndef MCF5225X_ETH_IRQ_PRIORITY
69  #define MCF5225X_ETH_IRQ_PRIORITY 1
70 #elif (MCF5225X_ETH_IRQ_PRIORITY < 0)
71  #error MCF5225X_ETH_IRQ_PRIORITY parameter is not valid
72 #endif
73 
74 //Align to 16-byte boundary
75 #define FEC_ALIGN16(p) ((void *) ((((uint32_t) (p)) + 15) & 0xFFFFFFF0))
76 
77 //Transmit buffer descriptor
78 #define FEC_TX_BD_R 0x8000
79 #define FEC_TX_BD_TO1 0x4000
80 #define FEC_TX_BD_W 0x2000
81 #define FEC_TX_BD_TO2 0x1000
82 #define FEC_TX_BD_L 0x0800
83 #define FEC_TX_BD_TC 0x0400
84 #define FEC_TX_BD_ABC 0x0200
85 
86 //Receive buffer descriptor
87 #define FEC_RX_BD_E 0x8000
88 #define FEC_RX_BD_RO1 0x4000
89 #define FEC_RX_BD_W 0x2000
90 #define FEC_RX_BD_RO2 0x1000
91 #define FEC_RX_BD_L 0x0800
92 #define FEC_RX_BD_M 0x0100
93 #define FEC_RX_BD_BC 0x0080
94 #define FEC_RX_BD_MC 0x0040
95 #define FEC_RX_BD_LG 0x0020
96 #define FEC_RX_BD_NO 0x0010
97 #define FEC_RX_BD_CR 0x0004
98 #define FEC_RX_BD_OV 0x0002
99 #define FEC_RX_BD_TR 0x0001
100 
101 //C++ guard
102 #ifdef __cplusplus
103  extern "C" {
104 #endif
105 
106 
107 /**
108  * @brief Transmit buffer descriptor
109  **/
110 
111 typedef struct
112 {
113  uint16_t status;
114  uint16_t length;
115  uint32_t address;
117 
118 
119 /**
120  * @brief Receive buffer descriptor
121  **/
122 
123 typedef struct
124 {
125  uint16_t status;
126  uint16_t length;
127  uint32_t address;
129 
130 
131 //MCF5225x Ethernet MAC driver
132 extern const NicDriver mcf5225xEthDriver;
133 
134 //MCF5225x Ethernet MAC related functions
136 void mcf5225xEthInitGpio(NetInterface *interface);
137 void mcf5225xEthInitBufferDesc(NetInterface *interface);
138 
139 void mcf5225xEthTick(NetInterface *interface);
140 
141 void mcf5225xEthEnableIrq(NetInterface *interface);
142 void mcf5225xEthDisableIrq(NetInterface *interface);
143 void mcf5225xEthEventHandler(NetInterface *interface);
144 
146  const NetBuffer *buffer, size_t offset);
147 
149 
152 
153 void mcf5225xEthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data);
154 uint16_t mcf5225xEthReadPhyReg(uint8_t phyAddr, uint8_t regAddr);
155 
156 uint32_t mcf5225xEthCalcCrc(const void *data, size_t length);
157 
158 //C++ guard
159 #ifdef __cplusplus
160  }
161 #endif
162 
163 #endif
void mcf5225xEthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
error_t mcf5225xEthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
void mcf5225xEthDisableIrq(NetInterface *interface)
Disable interrupts.
Transmit buffer descriptor.
error_t mcf5225xEthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset)
Send a packet.
error_t mcf5225xEthInit(NetInterface *interface)
MCF5225x Ethernet MAC initialization.
Receive buffer descriptor.
void mcf5225xEthInitBufferDesc(NetInterface *interface)
Initialize buffer descriptors.
uint16_t mcf5225xEthReadPhyReg(uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
NIC driver.
Definition: nic.h:161
error_t mcf5225xEthReceivePacket(NetInterface *interface)
Receive a packet.
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:86
uint16_t regAddr
error_t
Error codes.
Definition: error.h:40
void mcf5225xEthTick(NetInterface *interface)
MCF5225x Ethernet MAC timer handler.
const NicDriver mcf5225xEthDriver
MCF5225x Ethernet MAC driver.
uint8_t data[]
Definition: dtls_misc.h:167
#define NetInterface
Definition: net.h:34
void mcf5225xEthInitGpio(NetInterface *interface)
uint32_t mcf5225xEthCalcCrc(const void *data, size_t length)
CRC calculation.
uint8_t length
Definition: dtls_misc.h:140
error_t mcf5225xEthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
void mcf5225xEthEventHandler(NetInterface *interface)
MCF5225x Ethernet MAC event handler.
void mcf5225xEthEnableIrq(NetInterface *interface)
Enable interrupts.