sam9263_eth_driver.h
Go to the documentation of this file.
1 /**
2  * @file sam9263_eth_driver.h
3  * @brief AT91SAM9263 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 _SAM9263_ETH_DRIVER_H
30 #define _SAM9263_ETH_DRIVER_H
31 
32 //Number of TX buffers
33 #ifndef SAM9263_ETH_TX_BUFFER_COUNT
34  #define SAM9263_ETH_TX_BUFFER_COUNT 3
35 #elif (SAM9263_ETH_TX_BUFFER_COUNT < 1)
36  #error SAM9263_ETH_TX_BUFFER_COUNT parameter is not valid
37 #endif
38 
39 //TX buffer size
40 #ifndef SAM9263_ETH_TX_BUFFER_SIZE
41  #define SAM9263_ETH_TX_BUFFER_SIZE 1536
42 #elif (SAM9263_ETH_TX_BUFFER_SIZE != 1536)
43  #error SAM9263_ETH_TX_BUFFER_SIZE parameter is not valid
44 #endif
45 
46 //Number of RX buffers
47 #ifndef SAM9263_ETH_RX_BUFFER_COUNT
48  #define SAM9263_ETH_RX_BUFFER_COUNT 72
49 #elif (SAM9263_ETH_RX_BUFFER_COUNT < 12)
50  #error SAM9263_ETH_RX_BUFFER_COUNT parameter is not valid
51 #endif
52 
53 //RX buffer size
54 #ifndef SAM9263_ETH_RX_BUFFER_SIZE
55  #define SAM9263_ETH_RX_BUFFER_SIZE 128
56 #elif (SAM9263_ETH_RX_BUFFER_SIZE != 128)
57  #error SAM9263_ETH_RX_BUFFER_SIZE parameter is not valid
58 #endif
59 
60 //EMAC controller base address
61 #define AT91C_BASE_EMAC AT91C_BASE_MACB
62 
63 //RMII signals
64 #define AT91C_EMAC_RMII_MASK_C AT91C_PC25_ERXDV
65 
66 #define AT91C_EMAC_RMII_MASK_E (AT91C_PE30_EMDIO | \
67  AT91C_PE29_EMDC | AT91C_PE28_ETXEN | AT91C_PE27_ERXER | AT91C_PE26_ERX1 | \
68  AT91C_PE25_ERX0 | AT91C_PE24_ETX1 | AT91C_PE23_ETX0 | AT91C_PE21_ETXCK)
69 
70 //PHY maintenance register (EMAC_MAN)
71 #define AT91C_EMAC_SOF_01 (1 << 30)
72 #define AT91C_EMAC_RW_01 (1 << 28)
73 #define AT91C_EMAC_RW_10 (2 << 28)
74 #define AT91C_EMAC_CODE_10 (2 << 16)
75 
76 //TX buffer descriptor flags
77 #define AT91C_EMAC_TX_USED 0x80000000
78 #define AT91C_EMAC_TX_WRAP 0x40000000
79 #define AT91C_EMAC_TX_ERROR 0x20000000
80 #define AT91C_EMAC_TX_UNDERRUN 0x10000000
81 #define AT91C_EMAC_TX_EXHAUSTED 0x08000000
82 #define AT91C_EMAC_TX_NO_CRC 0x00010000
83 #define AT91C_EMAC_TX_LAST 0x00008000
84 #define AT91C_EMAC_TX_LENGTH 0x000007FF
85 
86 //RX buffer descriptor flags
87 #define AT91C_EMAC_RX_ADDRESS 0xFFFFFFFC
88 #define AT91C_EMAC_RX_WRAP 0x00000002
89 #define AT91C_EMAC_RX_OWNERSHIP 0x00000001
90 #define AT91C_EMAC_RX_BROADCAST 0x80000000
91 #define AT91C_EMAC_RX_MULTICAST_HASH 0x40000000
92 #define AT91C_EMAC_RX_UNICAST_HASH 0x20000000
93 #define AT91C_EMAC_RX_EXT_ADDR 0x10000000
94 #define AT91C_EMAC_RX_SAR1 0x04000000
95 #define AT91C_EMAC_RX_SAR2 0x02000000
96 #define AT91C_EMAC_RX_SAR3 0x01000000
97 #define AT91C_EMAC_RX_SAR4 0x00800000
98 #define AT91C_EMAC_RX_TYPE_ID 0x00400000
99 #define AT91C_EMAC_RX_VLAN_TAG 0x00200000
100 #define AT91C_EMAC_RX_PRIORITY_TAG 0x00100000
101 #define AT91C_EMAC_RX_VLAN_PRIORITY 0x000E0000
102 #define AT91C_EMAC_RX_CFI 0x00010000
103 #define AT91C_EMAC_RX_EOF 0x00008000
104 #define AT91C_EMAC_RX_SOF 0x00004000
105 #define AT91C_EMAC_RX_OFFSET 0x00003000
106 #define AT91C_EMAC_RX_LENGTH 0x00000FFF
107 
108 //C++ guard
109 #ifdef __cplusplus
110  extern "C" {
111 #endif
112 
113 
114 /**
115  * @brief Transmit buffer descriptor
116  **/
117 
118 typedef struct
119 {
120  uint32_t address;
121  uint32_t status;
123 
124 
125 /**
126  * @brief Receive buffer descriptor
127  **/
128 
129 typedef struct
130 {
131  uint32_t address;
132  uint32_t status;
134 
135 
136 //SAM9263 Ethernet MAC driver
137 extern const NicDriver sam9263EthDriver;
138 
139 //SAM9263 Ethernet MAC related functions
141 void sam9263EthInitGpio(NetInterface *interface);
142 void sam9263EthInitBufferDesc(NetInterface *interface);
143 
144 void sam9263EthTick(NetInterface *interface);
145 
146 void sam9263EthEnableIrq(NetInterface *interface);
147 void sam9263EthDisableIrq(NetInterface *interface);
148 void sam9263EthIrqHandler(void);
149 void sam9263EthEventHandler(NetInterface *interface);
150 
152  const NetBuffer *buffer, size_t offset);
153 
155 
158 
159 void sam9263EthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data);
160 uint16_t sam9263EthReadPhyReg(uint8_t phyAddr, uint8_t regAddr);
161 
162 //Wrapper for the interrupt service routine
163 void emacIrqWrapper(void);
164 
165 //C++ guard
166 #ifdef __cplusplus
167  }
168 #endif
169 
170 #endif
error_t sam9263EthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset)
Send a packet.
void sam9263EthInitBufferDesc(NetInterface *interface)
Initialize buffer descriptors.
const NicDriver sam9263EthDriver
SAM9263 Ethernet MAC driver.
void sam9263EthIrqHandler(void)
SAM9263 Ethernet MAC interrupt service routine.
uint16_t sam9263EthReadPhyReg(uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
NIC driver.
Definition: nic.h:161
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:86
error_t sam9263EthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
error_t sam9263EthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
uint16_t regAddr
void sam9263EthEventHandler(NetInterface *interface)
SAM9263 Ethernet MAC event handler.
error_t
Error codes.
Definition: error.h:40
void sam9263EthDisableIrq(NetInterface *interface)
Disable interrupts.
uint8_t data[]
Definition: dtls_misc.h:167
#define NetInterface
Definition: net.h:34
void sam9263EthInitGpio(NetInterface *interface)
void emacIrqWrapper(void)
Transmit buffer descriptor.
void sam9263EthTick(NetInterface *interface)
SAM9263 Ethernet MAC timer handler.
error_t sam9263EthReceivePacket(NetInterface *interface)
Receive a packet.
void sam9263EthEnableIrq(NetInterface *interface)
Enable interrupts.
void sam9263EthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
error_t sam9263EthInit(NetInterface *interface)
SAM9263 Ethernet MAC initialization.
Receive buffer descriptor.