samv71_eth_driver.h
Go to the documentation of this file.
1 /**
2  * @file samv71_eth_driver.h
3  * @brief SAMV71 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 _SAMV71_ETH_DRIVER_H
30 #define _SAMV71_ETH_DRIVER_H
31 
32 //Number of TX buffers
33 #ifndef SAMV71_ETH_TX_BUFFER_COUNT
34  #define SAMV71_ETH_TX_BUFFER_COUNT 4
35 #elif (SAMV71_ETH_TX_BUFFER_COUNT < 1)
36  #error SAMV71_ETH_TX_BUFFER_COUNT parameter is not valid
37 #endif
38 
39 //TX buffer size
40 #ifndef SAMV71_ETH_TX_BUFFER_SIZE
41  #define SAMV71_ETH_TX_BUFFER_SIZE 1536
42 #elif (SAMV71_ETH_TX_BUFFER_SIZE != 1536)
43  #error SAMV71_ETH_TX_BUFFER_SIZE parameter is not valid
44 #endif
45 
46 //Number of RX buffers
47 #ifndef SAMV71_ETH_RX_BUFFER_COUNT
48  #define SAMV71_ETH_RX_BUFFER_COUNT 96
49 #elif (SAMV71_ETH_RX_BUFFER_COUNT < 12)
50  #error SAMV71_ETH_RX_BUFFER_COUNT parameter is not valid
51 #endif
52 
53 //RX buffer size
54 #ifndef SAMV71_ETH_RX_BUFFER_SIZE
55  #define SAMV71_ETH_RX_BUFFER_SIZE 128
56 #elif (SAMV71_ETH_RX_BUFFER_SIZE != 128)
57  #error SAMV71_ETH_RX_BUFFER_SIZE parameter is not valid
58 #endif
59 
60 //Number of dummy buffers
61 #ifndef SAMV71_ETH_DUMMY_BUFFER_COUNT
62  #define SAMV71_ETH_DUMMY_BUFFER_COUNT 2
63 #elif (SAMV71_ETH_DUMMY_BUFFER_COUNT < 1)
64  #error SAMV71_ETH_DUMMY_BUFFER_COUNT parameter is not valid
65 #endif
66 
67 //Dummy buffer size
68 #ifndef SAMV71_ETH_DUMMY_BUFFER_SIZE
69  #define SAMV71_ETH_DUMMY_BUFFER_SIZE 128
70 #elif (SAMV71_ETH_DUMMY_BUFFER_SIZE != 128)
71  #error SAMV71_ETH_DUMMY_BUFFER_SIZE parameter is not valid
72 #endif
73 
74 //Interrupt priority grouping
75 #ifndef SAMV71_ETH_IRQ_PRIORITY_GROUPING
76  #define SAMV71_ETH_IRQ_PRIORITY_GROUPING 4
77 #elif (SAMV71_ETH_IRQ_PRIORITY_GROUPING < 0)
78  #error SAMV71_ETH_IRQ_PRIORITY_GROUPING parameter is not valid
79 #endif
80 
81 //Ethernet interrupt group priority
82 #ifndef SAMV71_ETH_IRQ_GROUP_PRIORITY
83  #define SAMV71_ETH_IRQ_GROUP_PRIORITY 6
84 #elif (SAMV71_ETH_IRQ_GROUP_PRIORITY < 0)
85  #error SAMV71_ETH_IRQ_GROUP_PRIORITY parameter is not valid
86 #endif
87 
88 //Ethernet interrupt subpriority
89 #ifndef SAMV71_ETH_IRQ_SUB_PRIORITY
90  #define SAMV71_ETH_IRQ_SUB_PRIORITY 0
91 #elif (SAMV71_ETH_IRQ_SUB_PRIORITY < 0)
92  #error SAMV71_ETH_IRQ_SUB_PRIORITY parameter is not valid
93 #endif
94 
95 //RMII signals
96 #define GMAC_RMII_MASK (PIO_PD9A_GMDIO | PIO_PD8A_GMDC | \
97  PIO_PD7A_GRXER | PIO_PD6A_GRX1 | PIO_PD5A_GRX0 | PIO_PD4A_GRXDV | \
98  PIO_PD3A_GTX1 | PIO_PD2A_GTX0 | PIO_PD1A_GTXEN | PIO_PD0A_GTXCK)
99 
100 //TX buffer descriptor flags
101 #define GMAC_TX_USED 0x80000000
102 #define GMAC_TX_WRAP 0x40000000
103 #define GMAC_TX_RLE_ERROR 0x20000000
104 #define GMAC_TX_UNDERRUN_ERROR 0x10000000
105 #define GMAC_TX_AHB_ERROR 0x08000000
106 #define GMAC_TX_LATE_COL_ERROR 0x04000000
107 #define GMAC_TX_CHECKSUM_ERROR 0x00700000
108 #define GMAC_TX_NO_CRC 0x00010000
109 #define GMAC_TX_LAST 0x00008000
110 #define GMAC_TX_LENGTH 0x00003FFF
111 
112 //RX buffer descriptor flags
113 #define GMAC_RX_ADDRESS 0xFFFFFFFC
114 #define GMAC_RX_WRAP 0x00000002
115 #define GMAC_RX_OWNERSHIP 0x00000001
116 #define GMAC_RX_BROADCAST 0x80000000
117 #define GMAC_RX_MULTICAST_HASH 0x40000000
118 #define GMAC_RX_UNICAST_HASH 0x20000000
119 #define GMAC_RX_SAR 0x08000000
120 #define GMAC_RX_SAR_MASK 0x06000000
121 #define GMAC_RX_TYPE_ID 0x01000000
122 #define GMAC_RX_SNAP 0x01000000
123 #define GMAC_RX_TYPE_ID_MASK 0x00C00000
124 #define GMAC_RX_CHECKSUM_VALID 0x00C00000
125 #define GMAC_RX_VLAN_TAG 0x00200000
126 #define GMAC_RX_PRIORITY_TAG 0x00100000
127 #define GMAC_RX_VLAN_PRIORITY 0x000E0000
128 #define GMAC_RX_CFI 0x00010000
129 #define GMAC_RX_EOF 0x00008000
130 #define GMAC_RX_SOF 0x00004000
131 #define GMAC_RX_LENGTH_MSB 0x00002000
132 #define GMAC_RX_BAD_FCS 0x00002000
133 #define GMAC_RX_LENGTH 0x00001FFF
134 
135 //C++ guard
136 #ifdef __cplusplus
137  extern "C" {
138 #endif
139 
140 
141 /**
142  * @brief Transmit buffer descriptor
143  **/
144 
145 typedef struct
146 {
147  uint32_t address;
148  uint32_t status;
150 
151 
152 /**
153  * @brief Receive buffer descriptor
154  **/
155 
156 typedef struct
157 {
158  uint32_t address;
159  uint32_t status;
161 
162 
163 //SAMV71 Ethernet MAC driver
164 extern const NicDriver samv71EthDriver;
165 
166 //SAMV71 Ethernet MAC related functions
168 void samv71EthInitGpio(NetInterface *interface);
169 void samv71EthInitBufferDesc(NetInterface *interface);
170 
171 void samv71EthTick(NetInterface *interface);
172 
173 void samv71EthEnableIrq(NetInterface *interface);
174 void samv71EthDisableIrq(NetInterface *interface);
175 void samv71EthEventHandler(NetInterface *interface);
176 
178  const NetBuffer *buffer, size_t offset);
179 
181 
184 
185 void samv71EthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data);
186 uint16_t samv71EthReadPhyReg(uint8_t phyAddr, uint8_t regAddr);
187 
188 //C++ guard
189 #ifdef __cplusplus
190  }
191 #endif
192 
193 #endif
const NicDriver samv71EthDriver
SAMV71 Ethernet MAC driver.
Transmit buffer descriptor.
error_t samv71EthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset)
Send a packet.
Receive buffer descriptor.
error_t samv71EthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
void samv71EthDisableIrq(NetInterface *interface)
Disable interrupts.
error_t samv71EthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
void samv71EthEnableIrq(NetInterface *interface)
Enable interrupts.
void samv71EthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
uint16_t samv71EthReadPhyReg(uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
void samv71EthTick(NetInterface *interface)
SAMV71 Ethernet MAC timer handler.
error_t samv71EthReceivePacket(NetInterface *interface)
Receive a packet.
NIC driver.
Definition: nic.h:161
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:86
error_t samv71EthInit(NetInterface *interface)
SAMV71 Ethernet MAC initialization.
uint16_t regAddr
error_t
Error codes.
Definition: error.h:40
void samv71EthEventHandler(NetInterface *interface)
SAMV71 Ethernet MAC event handler.
uint8_t data[]
Definition: dtls_misc.h:167
#define NetInterface
Definition: net.h:34
void samv71EthInitBufferDesc(NetInterface *interface)
Initialize buffer descriptors.
void samv71EthInitGpio(NetInterface *interface)