sc594_eth2_driver.h
Go to the documentation of this file.
1 /**
2  * @file sc594_eth2_driver.h
3  * @brief ADSP-SC594 Ethernet MAC driver (EMAC1 instance)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 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.6.0
29  **/
30 
31 #ifndef _SC594_ETH2_DRIVER_H
32 #define _SC594_ETH2_DRIVER_H
33 
34 //Dependencies
35 #include "core/nic.h"
36 
37 //Number of TX buffers
38 #ifndef SC594_ETH2_TX_BUFFER_COUNT
39  #define SC594_ETH2_TX_BUFFER_COUNT 8
40 #elif (SC594_ETH2_TX_BUFFER_COUNT < 1)
41  #error SC594_ETH2_TX_BUFFER_COUNT parameter is not valid
42 #endif
43 
44 //TX buffer size
45 #ifndef SC594_ETH2_TX_BUFFER_SIZE
46  #define SC594_ETH2_TX_BUFFER_SIZE 1536
47 #elif (SC594_ETH2_TX_BUFFER_SIZE != 1536)
48  #error SC594_ETH2_TX_BUFFER_SIZE parameter is not valid
49 #endif
50 
51 //Number of RX buffers
52 #ifndef SC594_ETH2_RX_BUFFER_COUNT
53  #define SC594_ETH2_RX_BUFFER_COUNT 8
54 #elif (SC594_ETH2_RX_BUFFER_COUNT < 1)
55  #error SC594_ETH2_RX_BUFFER_COUNT parameter is not valid
56 #endif
57 
58 //RX buffer size
59 #ifndef SC594_ETH2_RX_BUFFER_SIZE
60  #define SC594_ETH2_RX_BUFFER_SIZE 1536
61 #elif (SC594_ETH2_RX_BUFFER_SIZE != 1536)
62  #error SC594_ETH2_RX_BUFFER_SIZE parameter is not valid
63 #endif
64 
65 //Ethernet interrupt priority
66 #ifndef SC594_ETH2_IRQ_PRIORITY
67  #define SC594_ETH2_IRQ_PRIORITY 0
68 #elif (SC594_ETH2_IRQ_PRIORITY < 0)
69  #error SC594_ETH2_IRQ_PRIORITY parameter is not valid
70 #endif
71 
72 //Name of the section where to place DMA buffers
73 #ifndef SC594_ETH2_RAM_SECTION
74  #define SC594_ETH2_RAM_SECTION ".l2_uncached_data"
75 #endif
76 
77 //EMAC1 peripheral ID
78 #define EMAC1_SPU_PID 106
79 
80 //EMAC_SMI_ADDR register
81 #define ENUM_EMAC_SMI_ADDR_CR_DIV42 (0 << BITP_EMAC_SMI_ADDR_CR)
82 #define ENUM_EMAC_SMI_ADDR_CR_DIV62 (1 << BITP_EMAC_SMI_ADDR_CR)
83 #define ENUM_EMAC_SMI_ADDR_CR_DIV16 (2 << BITP_EMAC_SMI_ADDR_CR)
84 #define ENUM_EMAC_SMI_ADDR_CR_DIV26 (3 << BITP_EMAC_SMI_ADDR_CR)
85 
86 //EMAC_DMA_BUSMODE register
87 #define ENUM_EMAC_DMA_BUSMODE_RPBL_1 (1 << BITP_EMAC_DMA0_BUSMODE_RPBL)
88 #define ENUM_EMAC_DMA_BUSMODE_RPBL_2 (2 << BITP_EMAC_DMA0_BUSMODE_RPBL)
89 #define ENUM_EMAC_DMA_BUSMODE_RPBL_4 (4 << BITP_EMAC_DMA0_BUSMODE_RPBL)
90 #define ENUM_EMAC_DMA_BUSMODE_RPBL_8 (8 << BITP_EMAC_DMA0_BUSMODE_RPBL)
91 #define ENUM_EMAC_DMA_BUSMODE_RPBL_16 (16 << BITP_EMAC_DMA0_BUSMODE_RPBL)
92 #define ENUM_EMAC_DMA_BUSMODE_RPBL_32 (32 << BITP_EMAC_DMA0_BUSMODE_RPBL)
93 
94 #define ENUM_EMAC_DMA_BUSMODE_PBL_1 (1 << BITP_EMAC_DMA0_BUSMODE_PBL)
95 #define ENUM_EMAC_DMA_BUSMODE_PBL_2 (2 << BITP_EMAC_DMA0_BUSMODE_PBL)
96 #define ENUM_EMAC_DMA_BUSMODE_PBL_4 (4 << BITP_EMAC_DMA0_BUSMODE_PBL)
97 #define ENUM_EMAC_DMA_BUSMODE_PBL_8 (8 << BITP_EMAC_DMA0_BUSMODE_PBL)
98 #define ENUM_EMAC_DMA_BUSMODE_PBL_16 (16 << BITP_EMAC_DMA0_BUSMODE_PBL)
99 #define ENUM_EMAC_DMA_BUSMODE_PBL_32 (32 << BITP_EMAC_DMA0_BUSMODE_PBL)
100 
101 //Transmit DMA descriptor flags
102 #define EMAC_TDES0_OWN 0x80000000
103 #define EMAC_TDES0_IC 0x40000000
104 #define EMAC_TDES0_LS 0x20000000
105 #define EMAC_TDES0_FS 0x10000000
106 #define EMAC_TDES0_DC 0x08000000
107 #define EMAC_TDES0_DP 0x04000000
108 #define EMAC_TDES0_TTSE 0x02000000
109 #define EMAC_TDES0_CRCR 0x01000000
110 #define EMAC_TDES0_CIC 0x00C00000
111 #define EMAC_TDES0_TER 0x00200000
112 #define EMAC_TDES0_TCH 0x00100000
113 #define EMAC_TDES0_VLIC 0x000C0000
114 #define EMAC_TDES0_TTSS 0x00020000
115 #define EMAC_TDES0_IHE 0x00010000
116 #define EMAC_TDES0_ES 0x00008000
117 #define EMAC_TDES0_JT 0x00004000
118 #define EMAC_TDES0_FF 0x00002000
119 #define EMAC_TDES0_IPE 0x00001000
120 #define EMAC_TDES0_LCA 0x00000800
121 #define EMAC_TDES0_NC 0x00000400
122 #define EMAC_TDES0_LCO 0x00000200
123 #define EMAC_TDES0_EC 0x00000100
124 #define EMAC_TDES0_VF 0x00000080
125 #define EMAC_TDES0_CC 0x00000078
126 #define EMAC_TDES0_ED 0x00000004
127 #define EMAC_TDES0_UF 0x00000002
128 #define EMAC_TDES0_DB 0x00000001
129 #define EMAC_TDES1_SAIC 0xE0000000
130 #define EMAC_TDES1_TBS2 0x1FFF0000
131 #define EMAC_TDES1_TBS1 0x00001FFF
132 #define EMAC_TDES2_TBAP1 0xFFFFFFFF
133 #define EMAC_TDES3_TBAP2 0xFFFFFFFF
134 
135 //Receive DMA descriptor flags
136 #define EMAC_RDES0_OWN 0x80000000
137 #define EMAC_RDES0_AFM 0x40000000
138 #define EMAC_RDES0_FL 0x3FFF0000
139 #define EMAC_RDES0_ES 0x00008000
140 #define EMAC_RDES0_DE 0x00004000
141 #define EMAC_RDES0_SAF 0x00002000
142 #define EMAC_RDES0_LE 0x00001000
143 #define EMAC_RDES0_OE 0x00000800
144 #define EMAC_RDES0_VLAN 0x00000400
145 #define EMAC_RDES0_FS 0x00000200
146 #define EMAC_RDES0_LS 0x00000100
147 #define EMAC_RDES0_TSV 0x00000080
148 #define EMAC_RDES0_LCO 0x00000040
149 #define EMAC_RDES0_FT 0x00000020
150 #define EMAC_RDES0_RWT 0x00000010
151 #define EMAC_RDES0_RE 0x00000008
152 #define EMAC_RDES0_DBE 0x00000004
153 #define EMAC_RDES0_CE 0x00000002
154 #define EMAC_RDES0_ESA 0x00000001
155 #define EMAC_RDES1_DIC 0x80000000
156 #define EMAC_RDES1_RBS2 0x1FFF0000
157 #define EMAC_RDES1_RER 0x00008000
158 #define EMAC_RDES1_RCH 0x00004000
159 #define EMAC_RDES1_RBS1 0x00001FFF
160 #define EMAC_RDES2_RBAP1 0xFFFFFFFF
161 #define EMAC_RDES3_RBAP2 0xFFFFFFFF
162 
163 //C++ guard
164 #ifdef __cplusplus
165 extern "C" {
166 #endif
167 
168 
169 /**
170  * @brief Enhanced TX DMA descriptor
171  **/
172 
173 typedef struct
174 {
175  uint32_t tdes0;
176  uint32_t tdes1;
177  uint32_t tdes2;
178  uint32_t tdes3;
180 
181 
182 /**
183  * @brief Enhanced RX DMA descriptor
184  **/
185 
186 typedef struct
187 {
188  uint32_t rdes0;
189  uint32_t rdes1;
190  uint32_t rdes2;
191  uint32_t rdes3;
193 
194 
195 //ADSP-SC594 Ethernet MAC driver (EMAC1 instance)
196 extern const NicDriver sc594Eth2Driver;
197 
198 //ADSP-SC594 Ethernet MAC related functions
200 void sc594Eth2InitGpio(NetInterface *interface);
201 void sc594Eth2ResetPhy(NetInterface *interface);
202 void sc594Eth2InitDmaDesc(NetInterface *interface);
203 
204 void sc594Eth2Tick(NetInterface *interface);
205 
206 void sc594Eth2EnableIrq(NetInterface *interface);
207 void sc594Eth2DisableIrq(NetInterface *interface);
208 void sc594Eth2IrqHandler(uint32_t id, void *param);
209 void sc594Eth2EventHandler(NetInterface *interface);
210 
212  const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary);
213 
215 
218 
219 void sc594Eth2WritePhyReg(uint8_t opcode, uint8_t phyAddr,
220  uint8_t regAddr, uint16_t data);
221 
222 uint16_t sc594Eth2ReadPhyReg(uint8_t opcode, uint8_t phyAddr,
223  uint8_t regAddr);
224 
225 uint32_t sc594Eth2CalcCrc(const void *data, size_t length);
226 
227 //C++ guard
228 #ifdef __cplusplus
229 }
230 #endif
231 
232 #endif
error_t sc594Eth2Init(NetInterface *interface)
ADSP-SC594 Ethernet MAC initialization.
error_t sc594Eth2ReceivePacket(NetInterface *interface)
Receive a packet.
uint8_t opcode
Definition: dns_common.h:191
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t data[]
Definition: ethernet.h:224
error_t sc594Eth2UpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
void sc594Eth2EventHandler(NetInterface *interface)
ADSP-SC594 Ethernet MAC event handler.
Enhanced RX DMA descriptor.
uint16_t sc594Eth2ReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
const NicDriver sc594Eth2Driver
ADSP-SC594 Ethernet MAC driver (EMAC1 instance)
void sc594Eth2InitGpio(NetInterface *interface)
GPIO configuration.
error_t
Error codes.
Definition: error.h:43
void sc594Eth2IrqHandler(uint32_t id, void *param)
ADSP-SC594 Ethernet MAC interrupt service routine.
Enhanced TX DMA descriptor.
void sc594Eth2ResetPhy(NetInterface *interface)
Reset PHY transceiver.
#define NetInterface
Definition: net.h:40
error_t sc594Eth2UpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
#define NetTxAncillary
Definition: net_misc.h:36
uint8_t length
Definition: tcp.h:375
void sc594Eth2WritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
void sc594Eth2EnableIrq(NetInterface *interface)
Enable interrupts.
uint16_t regAddr
void sc594Eth2InitDmaDesc(NetInterface *interface)
Initialize DMA descriptor lists.
Network interface controller abstraction layer.
void sc594Eth2DisableIrq(NetInterface *interface)
Disable interrupts.
uint32_t sc594Eth2CalcCrc(const void *data, size_t length)
CRC calculation.
NIC driver.
Definition: nic.h:286
void sc594Eth2Tick(NetInterface *interface)
ADSP-SC594 Ethernet MAC timer handler.
error_t sc594Eth2SendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.