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