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-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.4
29  **/
30 
31 #ifndef _MCF5225X_ETH_DRIVER_H
32 #define _MCF5225X_ETH_DRIVER_H
33 
34 //Number of TX buffers
35 #ifndef MCF5225X_ETH_TX_BUFFER_COUNT
36  #define MCF5225X_ETH_TX_BUFFER_COUNT 2
37 #elif (MCF5225X_ETH_TX_BUFFER_COUNT < 1)
38  #error MCF5225X_ETH_TX_BUFFER_COUNT parameter is not valid
39 #endif
40 
41 //TX buffer size
42 #ifndef MCF5225X_ETH_TX_BUFFER_SIZE
43  #define MCF5225X_ETH_TX_BUFFER_SIZE 1536
44 #elif (MCF5225X_ETH_TX_BUFFER_SIZE != 1536)
45  #error MCF5225X_ETH_TX_BUFFER_SIZE parameter is not valid
46 #endif
47 
48 //Number of RX buffers
49 #ifndef MCF5225X_ETH_RX_BUFFER_COUNT
50  #define MCF5225X_ETH_RX_BUFFER_COUNT 4
51 #elif (MCF5225X_ETH_RX_BUFFER_COUNT < 1)
52  #error MCF5225X_ETH_RX_BUFFER_COUNT parameter is not valid
53 #endif
54 
55 //RX buffer size
56 #ifndef MCF5225X_ETH_RX_BUFFER_SIZE
57  #define MCF5225X_ETH_RX_BUFFER_SIZE 1536
58 #elif (MCF5225X_ETH_RX_BUFFER_SIZE != 1536)
59  #error MCF5225X_ETH_RX_BUFFER_SIZE parameter is not valid
60 #endif
61 
62 //Ethernet interrupt level
63 #ifndef MCF5225X_ETH_IRQ_LEVEL
64  #define MCF5225X_ETH_IRQ_LEVEL 4
65 #elif (MCF5225X_ETH_IRQ_LEVEL < 0)
66  #error MCF5225X_ETH_IRQ_LEVEL parameter is not valid
67 #endif
68 
69 //Ethernet interrupt priority
70 #ifndef MCF5225X_ETH_IRQ_PRIORITY
71  #define MCF5225X_ETH_IRQ_PRIORITY 1
72 #elif (MCF5225X_ETH_IRQ_PRIORITY < 0)
73  #error MCF5225X_ETH_IRQ_PRIORITY parameter is not valid
74 #endif
75 
76 //Align to 16-byte boundary
77 #define FEC_ALIGN16(p) ((void *) ((((uint32_t) (p)) + 15) & 0xFFFFFFF0))
78 
79 //Transmit buffer descriptor
80 #define FEC_TX_BD_R 0x8000
81 #define FEC_TX_BD_TO1 0x4000
82 #define FEC_TX_BD_W 0x2000
83 #define FEC_TX_BD_TO2 0x1000
84 #define FEC_TX_BD_L 0x0800
85 #define FEC_TX_BD_TC 0x0400
86 #define FEC_TX_BD_ABC 0x0200
87 
88 //Receive buffer descriptor
89 #define FEC_RX_BD_E 0x8000
90 #define FEC_RX_BD_RO1 0x4000
91 #define FEC_RX_BD_W 0x2000
92 #define FEC_RX_BD_RO2 0x1000
93 #define FEC_RX_BD_L 0x0800
94 #define FEC_RX_BD_M 0x0100
95 #define FEC_RX_BD_BC 0x0080
96 #define FEC_RX_BD_MC 0x0040
97 #define FEC_RX_BD_LG 0x0020
98 #define FEC_RX_BD_NO 0x0010
99 #define FEC_RX_BD_CR 0x0004
100 #define FEC_RX_BD_OV 0x0002
101 #define FEC_RX_BD_TR 0x0001
102 
103 //C++ guard
104 #ifdef __cplusplus
105 extern "C" {
106 #endif
107 
108 
109 /**
110  * @brief Transmit buffer descriptor
111  **/
112 
113 typedef struct
114 {
115  uint16_t status;
116  uint16_t length;
117  uint32_t address;
119 
120 
121 /**
122  * @brief Receive buffer descriptor
123  **/
124 
125 typedef struct
126 {
127  uint16_t status;
128  uint16_t length;
129  uint32_t address;
131 
132 
133 //MCF5225x Ethernet MAC driver
134 extern const NicDriver mcf5225xEthDriver;
135 
136 //MCF5225x Ethernet MAC related functions
138 void mcf5225xEthInitGpio(NetInterface *interface);
139 void mcf5225xEthInitBufferDesc(NetInterface *interface);
140 
141 void mcf5225xEthTick(NetInterface *interface);
142 
143 void mcf5225xEthEnableIrq(NetInterface *interface);
144 void mcf5225xEthDisableIrq(NetInterface *interface);
145 void mcf5225xEthEventHandler(NetInterface *interface);
146 
148  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
149 
151 
154 
155 void mcf5225xEthWritePhyReg(uint8_t opcode, uint8_t phyAddr,
156  uint8_t regAddr, uint16_t data);
157 
158 uint16_t mcf5225xEthReadPhyReg(uint8_t opcode, uint8_t phyAddr,
159  uint8_t regAddr);
160 
161 uint32_t mcf5225xEthCalcCrc(const void *data, size_t length);
162 
163 //C++ guard
164 #ifdef __cplusplus
165 }
166 #endif
167 
168 #endif
void mcf5225xEthInitGpio(NetInterface *interface)
GPIO configuration.
uint8_t opcode
Definition: dns_common.h:188
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:222
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:368
Receive buffer descriptor.
void mcf5225xEthEnableIrq(NetInterface *interface)
Enable interrupts.
uint16_t regAddr
Transmit buffer descriptor.
void mcf5225xEthInitBufferDesc(NetInterface *interface)
Initialize buffer descriptors.
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