]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D4x_EK_IAR/AtmelFiles/libchip_sama5d4x/include/gmac.h
Core kernel files:
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D4x_EK_IAR / AtmelFiles / libchip_sama5d4x / include / gmac.h
1 /* ----------------------------------------------------------------------------\r
2  *         SAM Software Package License \r
3  * ----------------------------------------------------------------------------\r
4  * Copyright (c) 2012, Atmel Corporation\r
5  *\r
6  * All rights reserved.\r
7  *\r
8  * Redistribution and use in source and binary forms, with or without\r
9  * modification, are permitted provided that the following conditions are met:\r
10  *\r
11  * - Redistributions of source code must retain the above copyright notice,\r
12  * this list of conditions and the disclaimer below.\r
13  *\r
14  * Atmel's name may not be used to endorse or promote products derived from\r
15  * this software without specific prior written permission.\r
16  *\r
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR\r
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE\r
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,\r
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
27  * ----------------------------------------------------------------------------\r
28  */\r
29 \r
30 /** \file */\r
31 \r
32 /** \addtogroup gmac_module\r
33  * @{\r
34  * Provides the interface to configure and use the GMAC peripheral.\r
35  *\r
36  * \section gmac_usage Usage\r
37  * - Configure Gmac::GMAC_NCFG with GMAC_Configure(), some of related controls\r
38  *   are also available, such as:\r
39  *   - GMAC_SetSpeed(): Setup GMAC working clock.\r
40  *   - GMAC_FullDuplexEnable(): Working in full duplex or not.\r
41  *   - GMAC_CpyAllEnable(): Copying all valid frames (\ref GMAC_NCFG_CAF).\r
42  *   - ...\r
43  * - Setup Gmac::GMAC_NCR with GMAC_NetworkControl(), more related controls\r
44  *   can modify with:\r
45  *   - GMAC_ReceiveEnable(): Enable/Disable Rx.\r
46  *   - GMAC_TransmitEnable(): Enable/Disable Tx.\r
47  *   - GMAC_BroadcastDisable(): Enable/Disable broadcast receiving.\r
48  *   - ...\r
49  * - Manage GMAC interrupts with GMAC_EnableIt(), GMAC_DisableIt(),\r
50  *   GMAC_GetItMask() and GMAC_GetItStatus().\r
51  * - Manage GMAC Tx/Rx status with GMAC_GetTxStatus(), GMAC_GetRxStatus()\r
52  *   GMAC_ClearTxStatus() and GMAC_ClearRxStatus().\r
53  * - Manage GMAC Queue with GMAC_SetTxQueue(), GMAC_GetTxQueue(),\r
54  *   GMAC_SetRxQueue() and GMAC_GetRxQueue(), the queue descriptor can define\r
55  *   by \ref sGmacRxDescriptor and \ref sGmacTxDescriptor.\r
56  * - Manage PHY through GMAC is performed by\r
57  *   - GMAC_ManagementEnable(): Enable/Disable PHY management.\r
58  *   - GMAC_PHYMaintain(): Execute PHY management commands.\r
59  *   - GMAC_PHYData(): Return PHY management data.\r
60  *   - GMAC_IsIdle(): Check if PHY is idle.\r
61  * - Setup GMAC parameters with following functions:\r
62  *   - GMAC_SetHash(): Set Hash value.\r
63  *   - GMAC_SetAddress(): Set MAC address.\r
64  * - Enable/Disable GMAC transceiver clock via GMAC_TransceiverClockEnable()\r
65  * - Switch GMAC MII/RMII mode through GMAC_RMIIEnable()\r
66  *\r
67  * For more accurate information, please look at the GMAC section of the\r
68  * Datasheet.\r
69  *\r
70  * \sa \ref gmacd_module\r
71  *\r
72  * Related files:\n\r
73  * gmac.c\n\r
74  * gmac.h.\n\r
75  *\r
76  *   \defgroup gmac_defines GMAC Defines\r
77  *   \defgroup gmac_structs GMAC Data Structs\r
78  *   \defgroup gmac_functions GMAC Functions\r
79  */\r
80 /**@}*/\r
81 \r
82 #ifndef _GMAC_H\r
83 #define _GMAC_H\r
84 \r
85 /*----------------------------------------------------------------------------\r
86  *        Headers\r
87  *----------------------------------------------------------------------------*/\r
88 #include "chip.h"\r
89 \r
90 #include <stdint.h>\r
91 \r
92 #ifdef __cplusplus\r
93  extern "C" {\r
94 #endif\r
95 \r
96 /*----------------------------------------------------------------------------\r
97  *        Defines\r
98  *----------------------------------------------------------------------------*/\r
99 /** \addtogroup gmac_defines\r
100         @{*/\r
101 \r
102 /// Board GMAC base address\r
103 \r
104 /// Number of buffer for RX, be carreful: MUST be 2^n\r
105 #define GRX_BUFFERS  16\r
106 /// Number of buffer for TX, be carreful: MUST be 2^n\r
107 #define GTX_BUFFERS   8\r
108 \r
109 /// Buffer Size\r
110 #define GMAC_RX_UNITSIZE            128     /// Fixed size for RX buffer\r
111 #define GMAC_TX_UNITSIZE            1518    /// Size for ETH frame length\r
112 \r
113 // The MAC can support frame lengths up to 1536 bytes.\r
114 #define GMAC_FRAME_LENTGH_MAX       1536\r
115 \r
116 //\r
117 #define GMAC_DUPLEX_HALF 0\r
118 #define GMAC_DUPLEX_FULL 1\r
119 \r
120 //\r
121 #define GMAC_SPEED_10M      0\r
122 #define GMAC_SPEED_100M     1\r
123 #define GMAC_SPEED_1000M    2\r
124 /*----------------------------------------------------------------------------\r
125  *        Types\r
126  *----------------------------------------------------------------------------*/\r
127 /** \addtogroup gmac_structs\r
128         @{*/\r
129 /** Receive buffer descriptor struct */\r
130 typedef struct _GmacRxDescriptor {\r
131     union _GmacRxAddr {\r
132         uint32_t val;\r
133         struct _GmacRxAddrBM {\r
134             uint32_t bOwnership:1,  /**< User clear, GMAC set this to one once\r
135                                          it has successfully written a frame to\r
136                                          memory */\r
137                      bWrap:1,       /**< Marks last descriptor in receive buffer */\r
138                      addrDW:30;     /**< Address in number of DW */\r
139         } bm;\r
140     } addr;                    /**< Address, Wrap & Ownership */\r
141     union _GmacRxStatus {\r
142         uint32_t val;\r
143         struct _GmacRxStatusBM {\r
144             uint32_t len:12,                /** Length of frame including FCS */\r
145                      offset:2,              /** Receive buffer offset,\r
146                                                 bits 13:12 of frame length for jumbo\r
147                                                 frame */\r
148                      bSof:1,                /** Start of frame */\r
149                      bEof:1,                /** End of frame */\r
150                      bCFI:1,                /** Concatenation Format Indicator */\r
151                      vlanPriority:3,        /** VLAN priority (if VLAN detected) */\r
152                      bPriorityDetected:1,   /** Priority tag detected */\r
153                      bVlanDetected:1,       /**< VLAN tag detected */\r
154                      bTypeIDMatch:1,        /**< Type ID match */\r
155                      bAddr4Match:1,         /**< Address register 4 match */\r
156                      bAddr3Match:1,         /**< Address register 3 match */\r
157                      bAddr2Match:1,         /**< Address register 2 match */\r
158                      bAddr1Match:1,         /**< Address register 1 match */\r
159                      reserved:1,\r
160                      bExtAddrMatch:1,       /**< External address match */\r
161                      bUniHashMatch:1,       /**< Unicast hash match */\r
162                      bMultiHashMatch:1,     /**< Multicast hash match */\r
163                      bBroadcastDetected:1;  /**< Global all ones broadcast\r
164                                                  address detected */\r
165         } bm;\r
166     } status;\r
167 } sGmacRxDescriptor;    /* GCC */\r
168 \r
169 /** Transmit buffer descriptor struct */\r
170 typedef struct _GmacTxDescriptor {\r
171     uint32_t addr;\r
172     union _GmacTxStatus {\r
173         uint32_t val;\r
174         struct _GmacTxStatusBM {\r
175             uint32_t len:11,        /**< Length of buffer */\r
176                      reserved:4,\r
177                      bLastBuffer:1, /**< Last buffer (in the current frame) */\r
178                      bNoCRC:1,      /**< No CRC */\r
179                      reserved1:10,\r
180                      bExhausted:1,  /**< Buffer exhausted in mid frame */\r
181                      bUnderrun:1,   /**< Transmit underrun */\r
182                      bError:1,      /**< Retry limit exceeded, error detected */\r
183                      bWrap:1,       /**< Marks last descriptor in TD list */\r
184                      bUsed:1;       /**< User clear, GMAC sets this once a frame\r
185                                          has been successfully transmitted */\r
186         } bm;\r
187     } status;\r
188 } sGmacTxDescriptor;     /* GCC */\r
189 \r
190 /**     @}*/\r
191 \r
192 //-----------------------------------------------------------------------------\r
193 //         PHY Exported functions\r
194 //-----------------------------------------------------------------------------\r
195 extern uint8_t GMAC_IsIdle(Gmac *pGmac);\r
196 extern void GMAC_PHYMaintain(Gmac      *pGmac,\r
197                              uint8_t   bPhyAddr,\r
198                              uint8_t   bRegAddr,\r
199                              uint8_t   bRW,\r
200                              uint16_t  wData);\r
201 extern uint16_t GMAC_PHYData(Gmac *pGmac);\r
202 extern void GMAC_ClearStatistics(Gmac *pGmac);\r
203 extern void GMAC_IncreaseStatistics(Gmac *pGmac);\r
204 extern void GMAC_StatisticsWriteEnable(Gmac *pGmac, uint8_t bEnaDis);\r
205 extern uint8_t GMAC_SetMdcClock(Gmac *pGmac, uint32_t mck );\r
206 extern void GMAC_EnableMdio(Gmac *pGmac );\r
207 extern void GMAC_DisableMdio(Gmac *pGmac );\r
208 extern void GMAC_EnableMII(Gmac *pGmac );\r
209 extern void GMAC_EnableRMII(Gmac *pGmac );\r
210 extern void GMAC_EnableGMII( Gmac *pGmac );\r
211 extern void GMAC_SetLinkSpeed(Gmac *pGmac, uint8_t speed, uint8_t fullduplex);\r
212 extern void GMAC_EnableIt(Gmac *pGmac, uint32_t dwSources);\r
213 extern void GMAC_DisableIt(Gmac *pGmac, uint32_t dwSources);\r
214 extern uint32_t GMAC_GetItStatus(Gmac *pGmac);\r
215 extern uint32_t GMAC_GetItMask(Gmac *pGmac);\r
216 extern uint32_t GMAC_GetTxStatus(Gmac *pGmac);\r
217 extern void GMAC_ClearTxStatus(Gmac *pGmac, uint32_t dwStatus);\r
218 extern uint32_t GMAC_GetRxStatus(Gmac *pGmac);\r
219 extern void GMAC_ClearRxStatus(Gmac *pGmac, uint32_t dwStatus);\r
220 extern void GMAC_ReceiveEnable(Gmac* pGmac, uint8_t bEnaDis);\r
221 extern void GMAC_TransmitEnable(Gmac *pGmac, uint8_t bEnaDis);\r
222 extern void GMAC_SetRxQueue(Gmac *pGmac, uint32_t dwAddr);\r
223 extern uint32_t GMAC_SetLocalLoopBack(Gmac *pGmac);\r
224 extern uint32_t GMAC_GetRxQueue(Gmac *pGmac);\r
225 extern void GMAC_SetTxQueue(Gmac *pGmac, uint32_t dwAddr);\r
226 extern uint32_t GMAC_GetTxQueue(Gmac *pGmac);\r
227 extern void GMAC_NetworkControl(Gmac *pGmac, uint32_t bmNCR);\r
228 extern uint32_t GMAC_GetNetworkControl(Gmac *pGmac);\r
229 extern void GMAC_SetAddress(Gmac *pGmac, uint8_t bIndex, uint8_t *pMacAddr);\r
230 extern void GMAC_SetAddress32(Gmac *pGmac, uint8_t bIndex, uint32_t dwMacT, uint32_t dwMacB);\r
231 extern void GMAC_SetAddress64(Gmac *pGmac, uint8_t bIndex, uint64_t ddwMac);\r
232 extern void GMAC_Configure(Gmac *pGmac, uint32_t dwCfg);\r
233 extern uint32_t GMAC_GetConfigure(Gmac *pGmac);\r
234 extern void GMAC_TransmissionStart(Gmac *pGmac);\r
235 extern void GMAC_TransmissionHalt(Gmac *pGmac);\r
236 extern void GMAC_EnableRGMII(Gmac *pGmac, uint32_t duplex, uint32_t speed);\r
237 #endif // #ifndef GMAC_H\r
238 \r