sam3x_eth_driver.h
Go to the documentation of this file.
1 /**
2  * @file sam3x_eth_driver.h
3  * @brief SAM3X 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 _SAM3X_ETH_DRIVER_H
30 #define _SAM3X_ETH_DRIVER_H
31 
32 //Number of TX buffers
33 #ifndef SAM3X_ETH_TX_BUFFER_COUNT
34  #define SAM3X_ETH_TX_BUFFER_COUNT 2
35 #elif (SAM3X_ETH_TX_BUFFER_COUNT < 1)
36  #error SAM3X_ETH_TX_BUFFER_COUNT parameter is not valid
37 #endif
38 
39 //TX buffer size
40 #ifndef SAM3X_ETH_TX_BUFFER_SIZE
41  #define SAM3X_ETH_TX_BUFFER_SIZE 1536
42 #elif (SAM3X_ETH_TX_BUFFER_SIZE != 1536)
43  #error SAM3X_ETH_TX_BUFFER_SIZE parameter is not valid
44 #endif
45 
46 //Number of RX buffers
47 #ifndef SAM3X_ETH_RX_BUFFER_COUNT
48  #define SAM3X_ETH_RX_BUFFER_COUNT 48
49 #elif (SAM3X_ETH_RX_BUFFER_COUNT < 12)
50  #error SAM3X_ETH_RX_BUFFER_COUNT parameter is not valid
51 #endif
52 
53 //RX buffer size
54 #ifndef SAM3X_ETH_RX_BUFFER_SIZE
55  #define SAM3X_ETH_RX_BUFFER_SIZE 128
56 #elif (SAM3X_ETH_RX_BUFFER_SIZE != 128)
57  #error SAM3X_ETH_RX_BUFFER_SIZE parameter is not valid
58 #endif
59 
60 //Interrupt priority grouping
61 #ifndef SAM3X_ETH_IRQ_PRIORITY_GROUPING
62  #define SAM3X_ETH_IRQ_PRIORITY_GROUPING 3
63 #elif (SAM3X_ETH_IRQ_PRIORITY_GROUPING < 0)
64  #error SAM3X_ETH_IRQ_PRIORITY_GROUPING parameter is not valid
65 #endif
66 
67 //Ethernet interrupt group priority
68 #ifndef SAM3X_ETH_IRQ_GROUP_PRIORITY
69  #define SAM3X_ETH_IRQ_GROUP_PRIORITY 12
70 #elif (SAM3X_ETH_IRQ_GROUP_PRIORITY < 0)
71  #error SAM3X_ETH_IRQ_GROUP_PRIORITY parameter is not valid
72 #endif
73 
74 //Ethernet interrupt subpriority
75 #ifndef SAM3X_ETH_IRQ_SUB_PRIORITY
76  #define SAM3X_ETH_IRQ_SUB_PRIORITY 0
77 #elif (SAM3X_ETH_IRQ_SUB_PRIORITY < 0)
78  #error SAM3X_ETH_IRQ_SUB_PRIORITY parameter is not valid
79 #endif
80 
81 //RMII signals
82 #define EMAC_RMII_MASK (PIO_PB9A_EMDIO | PIO_PB8A_EMDC | \
83  PIO_PB7A_ERXER | PIO_PB6A_ERX1 | PIO_PB5A_ERX0 | PIO_PB4A_ERXDV | \
84  PIO_PB3A_ETX1 | PIO_PB2A_ETX0 | PIO_PB1A_ETXEN | PIO_PB0A_ETXCK)
85 
86 //TX buffer descriptor flags
87 #define EMAC_TX_USED 0x80000000
88 #define EMAC_TX_WRAP 0x40000000
89 #define EMAC_TX_ERROR 0x20000000
90 #define EMAC_TX_UNDERRUN 0x10000000
91 #define EMAC_TX_EXHAUSTED 0x08000000
92 #define EMAC_TX_NO_CRC 0x00010000
93 #define EMAC_TX_LAST 0x00008000
94 #define EMAC_TX_LENGTH 0x000007FF
95 
96 //RX buffer descriptor flags
97 #define EMAC_RX_ADDRESS 0xFFFFFFFC
98 #define EMAC_RX_WRAP 0x00000002
99 #define EMAC_RX_OWNERSHIP 0x00000001
100 #define EMAC_RX_BROADCAST 0x80000000
101 #define EMAC_RX_MULTICAST_HASH 0x40000000
102 #define EMAC_RX_UNICAST_HASH 0x20000000
103 #define EMAC_RX_EXT_ADDR 0x10000000
104 #define EMAC_RX_SAR1 0x04000000
105 #define EMAC_RX_SAR2 0x02000000
106 #define EMAC_RX_SAR3 0x01000000
107 #define EMAC_RX_SAR4 0x00800000
108 #define EMAC_RX_TYPE_ID 0x00400000
109 #define EMAC_RX_VLAN_TAG 0x00200000
110 #define EMAC_RX_PRIORITY_TAG 0x00100000
111 #define EMAC_RX_VLAN_PRIORITY 0x000E0000
112 #define EMAC_RX_CFI 0x00010000
113 #define EMAC_RX_EOF 0x00008000
114 #define EMAC_RX_SOF 0x00004000
115 #define EMAC_RX_OFFSET 0x00003000
116 #define EMAC_RX_LENGTH 0x00000FFF
117 
118 //C++ guard
119 #ifdef __cplusplus
120  extern "C" {
121 #endif
122 
123 
124 /**
125  * @brief Transmit buffer descriptor
126  **/
127 
128 typedef struct
129 {
130  uint32_t address;
131  uint32_t status;
133 
134 
135 /**
136  * @brief Receive buffer descriptor
137  **/
138 
139 typedef struct
140 {
141  uint32_t address;
142  uint32_t status;
144 
145 
146 //SAM3X Ethernet MAC driver
147 extern const NicDriver sam3xEthDriver;
148 
149 //SAM3X Ethernet MAC related functions
150 error_t sam3xEthInit(NetInterface *interface);
151 void sam3xEthInitGpio(NetInterface *interface);
152 void sam3xEthInitBufferDesc(NetInterface *interface);
153 
154 void sam3xEthTick(NetInterface *interface);
155 
156 void sam3xEthEnableIrq(NetInterface *interface);
157 void sam3xEthDisableIrq(NetInterface *interface);
158 void sam3xEthEventHandler(NetInterface *interface);
159 
161  const NetBuffer *buffer, size_t offset);
162 
164 
167 
168 void sam3xEthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data);
169 uint16_t sam3xEthReadPhyReg(uint8_t phyAddr, uint8_t regAddr);
170 
171 //C++ guard
172 #ifdef __cplusplus
173  }
174 #endif
175 
176 #endif
uint16_t sam3xEthReadPhyReg(uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
void sam3xEthTick(NetInterface *interface)
SAM3X Ethernet MAC timer handler.
void sam3xEthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
void sam3xEthEventHandler(NetInterface *interface)
SAM3X Ethernet MAC event handler.
error_t sam3xEthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
const NicDriver sam3xEthDriver
SAM3X Ethernet MAC driver.
error_t sam3xEthReceivePacket(NetInterface *interface)
Receive a packet.
error_t sam3xEthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset)
Send a packet.
NIC driver.
Definition: nic.h:161
Transmit buffer descriptor.
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:86
void sam3xEthInitGpio(NetInterface *interface)
uint16_t regAddr
Receive buffer descriptor.
error_t
Error codes.
Definition: error.h:40
error_t sam3xEthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
uint8_t data[]
Definition: dtls_misc.h:167
#define NetInterface
Definition: net.h:34
error_t sam3xEthInit(NetInterface *interface)
SAM3X Ethernet MAC initialization.
void sam3xEthEnableIrq(NetInterface *interface)
Enable interrupts.
void sam3xEthDisableIrq(NetInterface *interface)
Disable interrupts.
void sam3xEthInitBufferDesc(NetInterface *interface)
Initialize buffer descriptors.