sama5d3_gigabit_eth_driver.h
Go to the documentation of this file.
1 /**
2  * @file sama5d3_gigabit_eth_driver.h
3  * @brief SAMA5D3 Gigabit 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 _SAMA5D3_GIGABIT_ETH_DRIVER_H
30 #define _SAMA5D3_GIGABIT_ETH_DRIVER_H
31 
32 //Number of TX buffers
33 #ifndef SAMA5D3_GIGABIT_ETH_TX_BUFFER_COUNT
34  #define SAMA5D3_GIGABIT_ETH_TX_BUFFER_COUNT 2
35 #elif (SAMA5D3_GIGABIT_ETH_TX_BUFFER_COUNT != 2)
36  #error SAMA5D3_GIGABIT_ETH_TX_BUFFER_COUNT parameter is not valid
37 #endif
38 
39 //TX buffer size
40 #ifndef SAMA5D3_GIGABIT_ETH_TX_BUFFER_SIZE
41  #define SAMA5D3_GIGABIT_ETH_TX_BUFFER_SIZE 1536
42 #elif (SAMA5D3_GIGABIT_ETH_TX_BUFFER_SIZE != 1536)
43  #error SAMA5D3_GIGABIT_ETH_TX_BUFFER_SIZE parameter is not valid
44 #endif
45 
46 //Number of RX buffers
47 #ifndef SAMA5D3_GIGABIT_ETH_RX_BUFFER_COUNT
48  #define SAMA5D3_GIGABIT_ETH_RX_BUFFER_COUNT 96
49 #elif (SAMA5D3_GIGABIT_ETH_RX_BUFFER_COUNT < 12)
50  #error SAMA5D3_GIGABIT_ETH_RX_BUFFER_COUNT parameter is not valid
51 #endif
52 
53 //RX buffer size
54 #ifndef SAMA5D3_GIGABIT_ETH_RX_BUFFER_SIZE
55  #define SAMA5D3_GIGABIT_ETH_RX_BUFFER_SIZE 128
56 #elif (SAMA5D3_GIGABIT_ETH_RX_BUFFER_SIZE != 128)
57  #error SAMA5D3_GIGABIT_ETH_RX_BUFFER_SIZE parameter is not valid
58 #endif
59 
60 //Gigabit Ethernet interrupt priority
61 #ifndef SAMA5D3_GIGABIT_ETH_IRQ_PRIORITY
62  #define SAMA5D3_GIGABIT_ETH_IRQ_PRIORITY 0
63 #elif (SAMA5D3_GIGABIT_ETH_IRQ_PRIORITY < 0)
64  #error SAMA5D3_GIGABIT_ETH_IRQ_PRIORITY parameter is not valid
65 #endif
66 
67 //RGMII signals
68 #define GMAC_RGMII_MASK (PIO_PB18A_G125CK | \
69  PIO_PB17A_GMDIO | PIO_PB16A_GMDC | PIO_PB13A_GRXER | \
70  PIO_PB12A_GRXDV | PIO_PB11A_GRXCK | PIO_PB9A_GTXEN | \
71  PIO_PB8A_GTXCK | PIO_PB7A_GRX3 | PIO_PB6A_GRX2 | \
72  PIO_PB5A_GRX1 | PIO_PB4A_GRX0 | PIO_PB3A_GTX3 | \
73  PIO_PB2A_GTX2 | PIO_PB1A_GTX1 | PIO_PB0A_GTX0)
74 
75 //TX buffer descriptor flags
76 #define GMAC_TX_USED 0x80000000
77 #define GMAC_TX_WRAP 0x40000000
78 #define GMAC_TX_RLE_ERROR 0x20000000
79 #define GMAC_TX_UNDERRUN_ERROR 0x10000000
80 #define GMAC_TX_AHB_ERROR 0x08000000
81 #define GMAC_TX_LATE_COL_ERROR 0x04000000
82 #define GMAC_TX_CHECKSUM_ERROR 0x00700000
83 #define GMAC_TX_NO_CRC 0x00010000
84 #define GMAC_TX_LAST 0x00008000
85 #define GMAC_TX_LENGTH 0x00003FFF
86 
87 //RX buffer descriptor flags
88 #define GMAC_RX_ADDRESS 0xFFFFFFFC
89 #define GMAC_RX_WRAP 0x00000002
90 #define GMAC_RX_OWNERSHIP 0x00000001
91 #define GMAC_RX_BROADCAST 0x80000000
92 #define GMAC_RX_MULTICAST_HASH 0x40000000
93 #define GMAC_RX_UNICAST_HASH 0x20000000
94 #define GMAC_RX_SAR 0x08000000
95 #define GMAC_RX_SAR_MASK 0x06000000
96 #define GMAC_RX_TYPE_ID 0x01000000
97 #define GMAC_RX_SNAP 0x01000000
98 #define GMAC_RX_TYPE_ID_MASK 0x00C00000
99 #define GMAC_RX_CHECKSUM_VALID 0x00C00000
100 #define GMAC_RX_VLAN_TAG 0x00200000
101 #define GMAC_RX_PRIORITY_TAG 0x00100000
102 #define GMAC_RX_VLAN_PRIORITY 0x000E0000
103 #define GMAC_RX_CFI 0x00010000
104 #define GMAC_RX_EOF 0x00008000
105 #define GMAC_RX_SOF 0x00004000
106 #define GMAC_RX_LENGTH_MSB 0x00002000
107 #define GMAC_RX_BAD_FCS 0x00002000
108 #define GMAC_RX_LENGTH 0x00001FFF
109 
110 
111 #if !defined(_SAMA5D3_ETH_H)
112 
113 //C++ guard
114 #ifdef __cplusplus
115  extern "C" {
116 #endif
117 
118 /**
119  * @brief Transmit buffer descriptor
120  **/
121 
122 typedef struct
123 {
124  uint32_t address;
125  uint32_t status;
127 
128 
129 /**
130  * @brief Receive buffer descriptor
131  **/
132 
133 typedef struct
134 {
135  uint32_t address;
136  uint32_t status;
138 
139 #endif
140 
141 
142 //SAMA5D3 Gigabit Ethernet MAC driver
144 
145 //SAMA5D3 Gigabit Ethernet MAC related functions
147 void sama5d3GigabitEthInitGpio(NetInterface *interface);
149 
150 void sama5d3GigabitEthTick(NetInterface *interface);
151 
154 void sama5d3GigabitEthIrqHandler(void);
156 
158  const NetBuffer *buffer, size_t offset);
159 
161 
164 
165 void sama5d3GigabitEthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data);
166 uint16_t sama5d3GigabitEthReadPhyReg(uint8_t phyAddr, uint8_t regAddr);
167 
168 //C++ guard
169 #ifdef __cplusplus
170  }
171 #endif
172 
173 #endif
error_t sama5d3GigabitEthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset)
Send a packet.
void sama5d3GigabitEthInitBufferDesc(NetInterface *interface)
Initialize buffer descriptors.
void sama5d3GigabitEthIrqHandler(void)
SAMA5D3 Gigabit Ethernet MAC interrupt service routine.
error_t sama5d3GigabitEthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
void sama5d3GigabitEthInitGpio(NetInterface *interface)
error_t sama5d3GigabitEthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
error_t sama5d3GigabitEthInit(NetInterface *interface)
SAMA5D3 Gigabit Ethernet MAC initialization.
Receive buffer descriptor.
error_t sama5d3GigabitEthReceivePacket(NetInterface *interface)
Receive a packet.
void sama5d3GigabitEthEventHandler(NetInterface *interface)
SAMA5D3 Gigabit Ethernet MAC event handler.
void sama5d3GigabitEthEnableIrq(NetInterface *interface)
Enable interrupts.
uint16_t sama5d3GigabitEthReadPhyReg(uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
Transmit buffer descriptor.
NIC driver.
Definition: nic.h:161
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:86
void sama5d3GigabitEthDisableIrq(NetInterface *interface)
Disable interrupts.
uint16_t regAddr
Ipv6Addr address
error_t
Error codes.
Definition: error.h:40
void sama5d3GigabitEthTick(NetInterface *interface)
SAMA5D3 Gigabit Ethernet MAC timer handler.
uint8_t data[]
Definition: dtls_misc.h:167
#define NetInterface
Definition: net.h:34
const NicDriver sama5d3GigabitEthDriver
SAMA5D3 Gigabit Ethernet MAC driver.
void sama5d3GigabitEthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.