rza2_eth2_driver.h
Go to the documentation of this file.
1 /**
2  * @file rza2_eth2_driver.h
3  * @brief RZ/A2 Ethernet MAC driver (ETHERC1 instance)
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 _RZA2_ETH2_DRIVER_H
32 #define _RZA2_ETH2_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //Number of TX buffers
38 #ifndef RZA2_ETH2_TX_BUFFER_COUNT
39  #define RZA2_ETH2_TX_BUFFER_COUNT 8
40 #elif (RZA2_ETH2_TX_BUFFER_COUNT < 1)
41  #error RZA2_ETH2_TX_BUFFER_COUNT parameter is not valid
42 #endif
43 
44 //TX buffer size
45 #ifndef RZA2_ETH2_TX_BUFFER_SIZE
46  #define RZA2_ETH2_TX_BUFFER_SIZE 1536
47 #elif (RZA2_ETH2_TX_BUFFER_SIZE != 1536)
48  #error RZA2_ETH2_TX_BUFFER_SIZE parameter is not valid
49 #endif
50 
51 //Number of RX buffers
52 #ifndef RZA2_ETH2_RX_BUFFER_COUNT
53  #define RZA2_ETH2_RX_BUFFER_COUNT 8
54 #elif (RZA2_ETH2_RX_BUFFER_COUNT < 1)
55  #error RZA2_ETH2_RX_BUFFER_COUNT parameter is not valid
56 #endif
57 
58 //RX buffer size
59 #ifndef RZA2_ETH2_RX_BUFFER_SIZE
60  #define RZA2_ETH2_RX_BUFFER_SIZE 1536
61 #elif (RZA2_ETH2_RX_BUFFER_SIZE != 1536)
62  #error RZA2_ETH2_RX_BUFFER_SIZE parameter is not valid
63 #endif
64 
65 //Ethernet interrupt priority
66 #ifndef RZA2_ETH2_IRQ_PRIORITY
67  #define RZA2_ETH2_IRQ_PRIORITY 25
68 #elif (RZA2_ETH2_IRQ_PRIORITY < 0)
69  #error RZA2_ETH2_IRQ_PRIORITY parameter is not valid
70 #endif
71 
72 //Name of the section where to place DMA buffers
73 #ifndef RZA2_ETH2_RAM_SECTION
74  #define RZA2_ETH2_RAM_SECTION ".BSS_DMAC_SAMPLE_INTERNAL_RAM"
75 #endif
76 
77 //Get physical address
78 #ifndef RZA2_ETH2_GET_PHYSICAL_ADDR
79  #define RZA2_ETH2_GET_PHYSICAL_ADDR(addr) ((uint32_t) (addr) - 0x02000000U)
80 #endif
81 
82 //EDMR register
83 #define EDMAC_EDMR_DL_16 0x00000000
84 #define EDMAC_EDMR_DL_32 0x00000010
85 #define EDMAC_EDMR_DL_64 0x00000020
86 
87 //FDR register
88 #define EDMAC_FDR_TFD_2048 0x00000700
89 #define EDMAC_FDR_RFD_4096 0x0000000F
90 
91 //Transmit DMA descriptor flags
92 #define EDMAC_TD0_TACT 0x80000000
93 #define EDMAC_TD0_TDLE 0x40000000
94 #define EDMAC_TD0_TFP_SOF 0x20000000
95 #define EDMAC_TD0_TFP_EOF 0x10000000
96 #define EDMAC_TD0_TFE 0x08000000
97 #define EDMAC_TD0_TWBI 0x04000000
98 #define EDMAC_TD0_TFS_MASK 0x0000010F
99 #define EDMAC_TD0_TFS_TABT 0x00000100
100 #define EDMAC_TD0_TFS_CND 0x00000008
101 #define EDMAC_TD0_TFS_DLC 0x00000004
102 #define EDMAC_TD0_TFS_CD 0x00000002
103 #define EDMAC_TD0_TFS_TRO 0x00000001
104 #define EDMAC_TD1_TBL 0xFFFF0000
105 #define EDMAC_TD2_TBA 0xFFFFFFFF
106 
107 //Receive DMA descriptor flags
108 #define EDMAC_RD0_RACT 0x80000000
109 #define EDMAC_RD0_RDLE 0x40000000
110 #define EDMAC_RD0_RFP_SOF 0x20000000
111 #define EDMAC_RD0_RFP_EOF 0x10000000
112 #define EDMAC_RD0_RFE 0x08000000
113 #define EDMAC_RD0_RFS_MASK 0x0000039F
114 #define EDMAC_RD0_RFS_RFOF 0x00000200
115 #define EDMAC_RD0_RFS_RABT 0x00000100
116 #define EDMAC_RD0_RFS_RMAF 0x00000080
117 #define EDMAC_RD0_RFS_RRF 0x00000010
118 #define EDMAC_RD0_RFS_RTLF 0x00000008
119 #define EDMAC_RD0_RFS_RTSF 0x00000004
120 #define EDMAC_RD0_RFS_PRE 0x00000002
121 #define EDMAC_RD0_RFS_CERF 0x00000001
122 #define EDMAC_RD1_RBL 0xFFFF0000
123 #define EDMAC_RD1_RFL 0x0000FFFF
124 #define EDMAC_RD2_RBA 0xFFFFFFFF
125 
126 //C++ guard
127 #ifdef __cplusplus
128 extern "C" {
129 #endif
130 
131 
132 /**
133  * @brief Transmit DMA descriptor
134  **/
135 
136 typedef struct
137 {
138  uint32_t td0;
139  uint32_t td1;
140  uint32_t td2;
141  uint32_t padding;
143 
144 
145 /**
146  * @brief Receive DMA descriptor
147  **/
148 
149 typedef struct
150 {
151  uint32_t rd0;
152  uint32_t rd1;
153  uint32_t rd2;
154  uint32_t padding;
156 
157 
158 //RZ/A2 Ethernet MAC driver (ETHERC1 instance)
159 extern const NicDriver rza2Eth2Driver;
160 
161 //RZ/A2 Ethernet MAC related functions
162 error_t rza2Eth2Init(NetInterface *interface);
163 void rza2Eth2InitGpio(NetInterface *interface);
164 void rza2Eth2InitDmaDesc(NetInterface *interface);
165 
166 void rza2Eth2Tick(NetInterface *interface);
167 
168 void rza2Eth2EnableIrq(NetInterface *interface);
169 void rza2Eth2DisableIrq(NetInterface *interface);
170 void rza2Eth2IrqHandler(uint32_t intSense);
171 void rza2Eth2EventHandler(NetInterface *interface);
172 
174  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
175 
177 
180 
181 void rza2Eth2WritePhyReg(uint8_t opcode, uint8_t phyAddr,
182  uint8_t regAddr, uint16_t data);
183 
184 uint16_t rza2Eth2ReadPhyReg(uint8_t opcode, uint8_t phyAddr,
185  uint8_t regAddr);
186 
187 void rza2Eth2WriteSmi(uint32_t data, uint_t length);
188 uint32_t rza2Eth2ReadSmi(uint_t length);
189 
190 //C++ guard
191 #ifdef __cplusplus
192 }
193 #endif
194 
195 #endif
void rza2Eth2WritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
void rza2Eth2InitDmaDesc(NetInterface *interface)
Initialize DMA descriptor lists.
uint8_t opcode
Definition: dns_common.h:188
uint16_t rza2Eth2ReadPhyReg(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
void rza2Eth2EnableIrq(NetInterface *interface)
Enable interrupts.
uint8_t data[]
Definition: ethernet.h:222
error_t rza2Eth2UpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
uint32_t rza2Eth2ReadSmi(uint_t length)
SMI read operation.
void rza2Eth2EventHandler(NetInterface *interface)
RZ/A2 Ethernet MAC event handler.
void rza2Eth2InitGpio(NetInterface *interface)
GPIO configuration.
error_t
Error codes.
Definition: error.h:43
error_t rza2Eth2SendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
void rza2Eth2Tick(NetInterface *interface)
RZ/A2 Ethernet MAC timer handler.
#define NetInterface
Definition: net.h:36
void rza2Eth2WriteSmi(uint32_t data, uint_t length)
SMI write operation.
error_t rza2Eth2Init(NetInterface *interface)
RZ/A2 Ethernet MAC initialization.
#define NetTxAncillary
Definition: net_misc.h:36
uint8_t length
Definition: tcp.h:368
Transmit DMA descriptor.
uint16_t regAddr
void rza2Eth2DisableIrq(NetInterface *interface)
Disable interrupts.
Network interface controller abstraction layer.
Receive DMA descriptor.
error_t rza2Eth2ReceivePacket(NetInterface *interface)
Receive a packet.
unsigned int uint_t
Definition: compiler_port.h:50
error_t rza2Eth2UpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
NIC driver.
Definition: nic.h:286
const NicDriver rza2Eth2Driver
RZ/A2 Ethernet MAC driver (ETHERC1 instance)
void rza2Eth2IrqHandler(uint32_t intSense)
RZ/A2 Ethernet MAC interrupt service routine.