SAMV71 Xplained Ultra Software Package 1.3

gmac.h

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2012, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
00028  */
00029 
00030 /** \file */
00031 
00032 /** \addtogroup gmac_module
00033  * @{
00034  * Provides the interface to configure and use the GMAC peripheral.
00035  *
00036  * \section gmac_usage Usage
00037  * - Configure Gmac::GMAC_NCFG with GMAC_Configure(), some of related controls
00038  *   are also available, such as:
00039  *   - GMAC_SetSpeed(): Setup GMAC working clock.
00040  *   - GMAC_FullDuplexEnable(): Working in full duplex or not.
00041  *   - GMAC_CpyAllEnable(): Copying all valid frames (\ref GMAC_NCFG_CAF).
00042  *   - ...
00043  * - Setup Gmac::GMAC_NCR with GMAC_NetworkControl(), more related controls
00044  *   can modify with:
00045  *   - GMAC_ReceiveEnable(): Enable/Disable Rx.
00046  *   - GMAC_TransmitEnable(): Enable/Disable Tx.
00047  *   - GMAC_BroadcastDisable(): Enable/Disable broadcast receiving.
00048  *   - ...
00049  * - Manage GMAC interrupts with GMAC_EnableIt(), GMAC_DisableIt(),
00050  *   GMAC_GetItMask() and GMAC_GetItStatus().
00051  * - Manage GMAC Tx/Rx status with GMAC_GetTxStatus(), GMAC_GetRxStatus()
00052  *   GMAC_ClearTxStatus() and GMAC_ClearRxStatus().
00053  * - Manage GMAC Queue with GMAC_SetTxQueue(), GMAC_GetTxQueue(),
00054  *   GMAC_SetRxQueue() and GMAC_GetRxQueue(), the queue descriptor can define
00055  *   by \ref sGmacRxDescriptor and \ref sGmacTxDescriptor.
00056  * - Manage PHY through GMAC is performed by
00057  *   - GMAC_ManagementEnable(): Enable/Disable PHY management.
00058  *   - GMAC_PHYMaintain(): Execute PHY management commands.
00059  *   - GMAC_PHYData(): Return PHY management data.
00060  *   - GMAC_IsIdle(): Check if PHY is idle.
00061  * - Setup GMAC parameters with following functions:
00062  *   - GMAC_SetHash(): Set Hash value.
00063  *   - GMAC_SetAddress(): Set MAC address.
00064  * - Enable/Disable GMAC transceiver clock via GMAC_TransceiverClockEnable()
00065  * - Switch GMAC MII/RMII mode through GMAC_RMIIEnable()
00066  *
00067  * For more accurate information, please look at the GMAC section of the
00068  * Datasheet.
00069  *
00070  * \sa \ref gmacd_module
00071  *
00072  * Related files:\n
00073  * gmac.c\n
00074  * gmac.h.\n
00075  *
00076  *   \defgroup gmac_defines GMAC Defines
00077  *   \defgroup gmac_structs GMAC Data Structs
00078  *   \defgroup gmac_functions GMAC Functions
00079  */
00080 /**@}*/
00081 
00082 #ifndef _GMAC_H
00083 #define _GMAC_H
00084 
00085 /*----------------------------------------------------------------------------
00086  *        Headers
00087  *----------------------------------------------------------------------------*/
00088 #include "chip.h"
00089 
00090 #include <stdint.h>
00091 
00092 #ifdef __cplusplus
00093  extern "C" {
00094 #endif
00095 
00096 /*----------------------------------------------------------------------------
00097  *        Defines
00098  *----------------------------------------------------------------------------*/
00099 /** \addtogroup gmac_defines
00100         @{*/
00101 
00102 #define NUM_GMAC_QUEUES 3
00103 /// Board GMAC base address
00104 
00105 #define GMAC_DUPLEX_HALF 0
00106 #define GMAC_DUPLEX_FULL 1
00107 
00108 //
00109 #define GMAC_SPEED_10M      0
00110 #define GMAC_SPEED_100M     1
00111 #define GMAC_SPEED_1000M    2
00112    
00113 /*------------------------------------------------------------------------------
00114                             Definitions
00115 ------------------------------------------------------------------------------
00116 */
00117 /// The buffer addresses written into the descriptors must be aligned so the
00118 /// last few bits are zero.  These bits have special meaning for the GMAC
00119 /// peripheral and cannot be used as part of the address.
00120 #define GMAC_ADDRESS_MASK   ((unsigned int)0xFFFFFFFC)
00121 #define GMAC_LENGTH_FRAME   ((unsigned int)0x3FFF)    /// Length of frame mask
00122 
00123 // receive buffer descriptor bits
00124 #define GMAC_RX_OWNERSHIP_BIT   (1u <<  0)
00125 #define GMAC_RX_WRAP_BIT        (1u <<  1)
00126 #define GMAC_RX_SOF_BIT         (1u << 14)
00127 #define GMAC_RX_EOF_BIT         (1u << 15)
00128 
00129 // Transmit buffer descriptor bits
00130 #define GMAC_TX_LAST_BUFFER_BIT (1u << 15)
00131 #define GMAC_TX_WRAP_BIT        (1u << 30)
00132 #define GMAC_TX_USED_BIT        (1u << 31)
00133 #define GMAC_TX_RLE_BIT         (1u << 29) /// Retry Limit Exceeded
00134 #define GMAC_TX_UND_BIT         (1u << 28) /// Tx Buffer Under-run
00135 #define GMAC_TX_ERR_BIT         (1u << 27) /// Exhausted in mid-frame
00136 #define GMAC_TX_ERR_BITS  \
00137     (GMAC_TX_RLE_BIT | GMAC_TX_UND_BIT | GMAC_TX_ERR_BIT)
00138 
00139 // Interrupt bits
00140 #define GMAC_INT_RX_BITS  \
00141     (GMAC_IER_RCOMP | GMAC_IER_RXUBR | GMAC_IER_ROVR)
00142 #define GMAC_INT_TX_ERR_BITS  \
00143     (GMAC_IER_TUR | GMAC_IER_RLEX | GMAC_IER_TFC | GMAC_IER_HRESP)
00144 #define GMAC_INT_TX_BITS  \
00145     (GMAC_INT_TX_ERR_BITS | GMAC_IER_TCOMP)
00146 /*----------------------------------------------------------------------------
00147  *        Types
00148  *----------------------------------------------------------------------------*/
00149 /** \addtogroup gmac_structs
00150         @{*/
00151    
00152 /* This is the list of GMAC queue */
00153 typedef enum  {
00154     GMAC_QUE_0 = 0,
00155     GMAC_QUE_1 = 1,
00156     GMAC_QUE_2 = 2
00157 }gmacQueList_t;
00158 
00159 /** Receive buffer descriptor struct */
00160 typedef struct _GmacRxDescriptor {
00161     union _GmacRxAddr {
00162         uint32_t val;
00163         struct _GmacRxAddrBM {
00164             uint32_t bOwnership:1,  /**< User clear, GMAC set this to one once
00165                                          it has successfully written a frame to
00166                                          memory */
00167                      bWrap:1,       /**< Marks last descriptor in receive buffer */
00168                      addrDW:30;     /**< Address in number of DW */
00169         } bm;
00170     } addr;                    /**< Address, Wrap & Ownership */
00171     union _GmacRxStatus {
00172         uint32_t val;
00173         struct _GmacRxStatusBM {
00174             uint32_t len:12,                /** Length of frame including FCS */
00175                      offset:2,              /** Receive buffer offset,
00176                                                 bits 13:12 of frame length for jumbo
00177                                                 frame */
00178                      bSof:1,                /** Start of frame */
00179                      bEof:1,                /** End of frame */
00180                      bCFI:1,                /** Concatenation Format Indicator */
00181                      vlanPriority:3,        /** VLAN priority (if VLAN detected) */
00182                      bPriorityDetected:1,   /** Priority tag detected */
00183                      bVlanDetected:1,       /**< VLAN tag detected */
00184                      bTypeIDMatch:1,        /**< Type ID match */
00185                      bAddr4Match:1,         /**< Address register 4 match */
00186                      bAddr3Match:1,         /**< Address register 3 match */
00187                      bAddr2Match:1,         /**< Address register 2 match */
00188                      bAddr1Match:1,         /**< Address register 1 match */
00189                      reserved:1,
00190                      bExtAddrMatch:1,       /**< External address match */
00191                      bUniHashMatch:1,       /**< Unicast hash match */
00192                      bMultiHashMatch:1,     /**< Multicast hash match */
00193                      bBroadcastDetected:1;  /**< Global all ones broadcast
00194                                                  address detected */
00195         } bm;
00196     } status;
00197 } sGmacRxDescriptor ;    /* GCC */
00198 
00199 /** Transmit buffer descriptor struct */
00200 typedef struct _GmacTxDescriptor {
00201     uint32_t addr;
00202     union _GmacTxStatus {
00203         uint32_t val;
00204         struct _GmacTxStatusBM {
00205             uint32_t len:11,        /**< Length of buffer */
00206                      reserved:4,
00207                      bLastBuffer:1, /**< Last buffer (in the current frame) */
00208                      bNoCRC:1,      /**< No CRC */
00209                      reserved1:10,
00210                      bExhausted:1,  /**< Buffer exhausted in mid frame */
00211                      bUnderrun:1,   /**< Transmit under run */
00212                      bError:1,      /**< Retry limit exceeded, error detected */
00213                      bWrap:1,       /**< Marks last descriptor in TD list */
00214                      bUsed:1;       /**< User clear, GMAC sets this once a frame
00215                                          has been successfully transmitted */
00216         } bm;
00217     } status;
00218 } sGmacTxDescriptor;     /* GCC */
00219 
00220 /**     @}*/
00221 
00222 //-----------------------------------------------------------------------------
00223 //         PHY Exported functions
00224 //-----------------------------------------------------------------------------
00225 extern uint8_t GMAC_IsIdle(Gmac *pGmac);
00226 extern void GMAC_PHYMaintain(Gmac      *pGmac,
00227                              uint8_t   bPhyAddr,
00228                              uint8_t   bRegAddr,
00229                              uint8_t   bRW,
00230                              uint16_t  wData);
00231 extern uint16_t GMAC_PHYData(Gmac *pGmac);
00232 extern void GMAC_ClearStatistics(Gmac *pGmac);
00233 extern void GMAC_IncreaseStatistics(Gmac *pGmac);
00234 extern void GMAC_StatisticsWriteEnable(Gmac *pGmac, uint8_t bEnaDis);
00235 extern uint8_t GMAC_SetMdcClock(Gmac *pGmac, uint32_t mck );
00236 extern void GMAC_EnableMdio(Gmac *pGmac );
00237 extern void GMAC_DisableMdio(Gmac *pGmac );
00238 extern void GMAC_EnableMII(Gmac *pGmac );
00239 extern void GMAC_EnableRMII(Gmac *pGmac );
00240 extern void GMAC_EnableGMII( Gmac *pGmac );
00241 extern void GMAC_SetLinkSpeed(Gmac *pGmac, uint8_t speed, uint8_t fullduplex);
00242 extern void GMAC_EnableIt(Gmac *pGmac, uint32_t dwSources, gmacQueList_t queueIdx);
00243 extern void GMAC_EnableAllQueueIt(Gmac *pGmac, uint32_t dwSources);
00244 extern void GMAC_DisableIt(Gmac *pGmac, uint32_t dwSources, gmacQueList_t queueIdx);
00245 extern void GMAC_DisableAllQueueIt(Gmac *pGmac, uint32_t dwSources);
00246 extern uint32_t GMAC_GetItStatus(Gmac *pGmac, gmacQueList_t queueIdx);
00247 extern uint32_t GMAC_GetItMask(Gmac *pGmac, gmacQueList_t queueIdx);
00248 extern uint32_t GMAC_GetTxStatus(Gmac *pGmac);
00249 extern void GMAC_ClearTxStatus(Gmac *pGmac, uint32_t dwStatus);
00250 extern uint32_t GMAC_GetRxStatus(Gmac *pGmac);
00251 extern void GMAC_ClearRxStatus(Gmac *pGmac, uint32_t dwStatus);
00252 extern void GMAC_ReceiveEnable(Gmac* pGmac, uint8_t bEnaDis);
00253 extern void GMAC_TransmitEnable(Gmac *pGmac, uint8_t bEnaDis);
00254 extern uint32_t GMAC_SetLocalLoopBack(Gmac *pGmac);
00255 extern void GMAC_SetRxQueue(Gmac *pGmac, uint32_t dwAddr, gmacQueList_t queueIdx);
00256 extern uint32_t GMAC_GetRxQueue(Gmac *pGmac, gmacQueList_t queueIdx);
00257 extern void GMAC_SetTxQueue(Gmac *pGmac, uint32_t dwAddr, gmacQueList_t queueIdx);
00258 extern uint32_t GMAC_GetTxQueue(Gmac *pGmac, gmacQueList_t queueIdx);
00259 extern void GMAC_NetworkControl(Gmac *pGmac, uint32_t bmNCR);
00260 extern uint32_t GMAC_GetNetworkControl(Gmac *pGmac);
00261 extern void GMAC_SetAddress(Gmac *pGmac, uint8_t bIndex, uint8_t *pMacAddr);
00262 extern void GMAC_SetAddress32(Gmac *pGmac, uint8_t bIndex, uint32_t dwMacT, uint32_t dwMacB);
00263 extern void GMAC_SetAddress64(Gmac *pGmac, uint8_t bIndex, uint64_t ddwMac);
00264 extern void GMAC_Configure(Gmac *pGmac, uint32_t dwCfg);
00265 extern void GMAC_SetDMAConfig(Gmac *pGmac, uint32_t dwDmaCfg, gmacQueList_t queueIdx);
00266 extern uint32_t GMAC_GetDMAConfig(Gmac *pGmac, gmacQueList_t queueIdx);
00267 extern uint32_t GMAC_GetConfigure(Gmac *pGmac);
00268 extern void GMAC_TransmissionStart(Gmac *pGmac);
00269 extern void GMAC_TransmissionHalt(Gmac *pGmac);
00270 extern void GMAC_EnableRGMII(Gmac *pGmac, uint32_t duplex, uint32_t speed);
00271 
00272 void GMAC_ClearScreener1Reg (Gmac* pGmac, gmacQueList_t queueIdx);
00273 
00274 void GMAC_WriteScreener1Reg(Gmac* pGmac, gmacQueList_t queueIdx, uint32_t regVal);
00275 
00276 void GMAC_ClearScreener2Reg (Gmac* pGmac, gmacQueList_t queueIdx);
00277 
00278 void GMAC_WriteScreener2Reg (Gmac* pGmac, gmacQueList_t queueIdx, uint32_t regVal);
00279 
00280 void GMAC_WriteEthTypeReg (Gmac* pGmac, gmacQueList_t queueIdx,  uint16_t etherType);
00281 
00282 void GMAC_WriteCompareReg(Gmac* pGmac, gmacQueList_t queueIdx, uint32_t c0Reg, uint16_t c1Reg);
00283 
00284 void GMAC_EnableCbsQueA(Gmac *pGmac);
00285 
00286 void GMAC_DisableCbsQueA(Gmac *pGmac);
00287 
00288 void GMAC_EnableCbsQueB(Gmac *pGmac);
00289 
00290 void GMAC_DisableCbsQueB(Gmac *pGmac);
00291 
00292 void GMAC_ConfigIdleSlopeA(Gmac *pGmac, uint32_t idleSlopeA);
00293 
00294 void GMAC_ConfigIdleSlopeB(Gmac *pGmac, uint32_t idleSlopeB);
00295 
00296 void GMAC_SetTsuTmrIncReg( Gmac *pGmac, uint32_t nanoSec);
00297 
00298 uint16_t GMAC_GetPtpEvtMsgRxdMsbSec( Gmac *pGmac );
00299 
00300 uint32_t GMAC_GetPtpEvtMsgRxdLsbSec( Gmac *pGmac );
00301 
00302 uint32_t GMAC_GetPtpEvtMsgRxdNanoSec( Gmac *pGmac );
00303 
00304 void GMAC_SetTsuCompare(Gmac *pGmac, uint32_t seconds47, uint32_t seconds31, uint32_t nanosec );
00305 
00306 void GMAC_SetTsuCompareNanoSec(Gmac *pGmac, uint32_t nanosec);
00307 
00308 void GMAC_SetTsuCompareSec31(Gmac *pGmac, uint32_t seconds31);
00309 
00310 void GMAC_SetTsuCompareSec47(Gmac *pGmac, uint16_t seconds47);
00311 
00312 uint32_t GMAC_GetRxEvtFrameSec(Gmac *pGmac);
00313 
00314 uint32_t GMAC_GetRxEvtFrameNsec(Gmac *pGmac);
00315 
00316 uint32_t GMAC_GetRxPeerEvtFrameSec(Gmac *pGmac);
00317 
00318 uint32_t GMAC_GetRxPeerEvtFrameNsec(Gmac *pGmac);
00319 
00320 uint32_t GMAC_GetTxEvtFrameSec(Gmac *pGmac);
00321 
00322 uint32_t GMAC_GetTxEvtFrameNsec(Gmac *pGmac);
00323 
00324 uint32_t GMAC_GetTxPeerEvtFrameSec(Gmac *pGmac);
00325 
00326 uint32_t GMAC_GetTxPeerEvtFrameNsec(Gmac *pGmac);
00327 
00328 #ifdef __cplusplus
00329 }
00330 #endif
00331 
00332 #endif // #ifndef GMAC_H
00333 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines