Webserver+3d print
cyclone_tcp/drivers/sam4e_eth.h@0:8918a71cdbe9, 2017-02-04 (annotated)
- Committer:
- Sergunb
- Date:
- Sat Feb 04 18:15:49 2017 +0000
- Revision:
- 0:8918a71cdbe9
nothing else
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sergunb | 0:8918a71cdbe9 | 1 | /** |
Sergunb | 0:8918a71cdbe9 | 2 | * @file sam4e_eth.h |
Sergunb | 0:8918a71cdbe9 | 3 | * @brief SAM4E Ethernet MAC controller |
Sergunb | 0:8918a71cdbe9 | 4 | * |
Sergunb | 0:8918a71cdbe9 | 5 | * @section License |
Sergunb | 0:8918a71cdbe9 | 6 | * |
Sergunb | 0:8918a71cdbe9 | 7 | * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. |
Sergunb | 0:8918a71cdbe9 | 8 | * |
Sergunb | 0:8918a71cdbe9 | 9 | * This file is part of CycloneTCP Open. |
Sergunb | 0:8918a71cdbe9 | 10 | * |
Sergunb | 0:8918a71cdbe9 | 11 | * This program is free software; you can redistribute it and/or |
Sergunb | 0:8918a71cdbe9 | 12 | * modify it under the terms of the GNU General Public License |
Sergunb | 0:8918a71cdbe9 | 13 | * as published by the Free Software Foundation; either version 2 |
Sergunb | 0:8918a71cdbe9 | 14 | * of the License, or (at your option) any later version. |
Sergunb | 0:8918a71cdbe9 | 15 | * |
Sergunb | 0:8918a71cdbe9 | 16 | * This program is distributed in the hope that it will be useful, |
Sergunb | 0:8918a71cdbe9 | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Sergunb | 0:8918a71cdbe9 | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Sergunb | 0:8918a71cdbe9 | 19 | * GNU General Public License for more details. |
Sergunb | 0:8918a71cdbe9 | 20 | * |
Sergunb | 0:8918a71cdbe9 | 21 | * You should have received a copy of the GNU General Public License |
Sergunb | 0:8918a71cdbe9 | 22 | * along with this program; if not, write to the Free Software Foundation, |
Sergunb | 0:8918a71cdbe9 | 23 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
Sergunb | 0:8918a71cdbe9 | 24 | * |
Sergunb | 0:8918a71cdbe9 | 25 | * @author Oryx Embedded SARL (www.oryx-embedded.com) |
Sergunb | 0:8918a71cdbe9 | 26 | * @version 1.7.6 |
Sergunb | 0:8918a71cdbe9 | 27 | **/ |
Sergunb | 0:8918a71cdbe9 | 28 | |
Sergunb | 0:8918a71cdbe9 | 29 | #ifndef _SAM4E_ETH_H |
Sergunb | 0:8918a71cdbe9 | 30 | #define _SAM4E_ETH_H |
Sergunb | 0:8918a71cdbe9 | 31 | |
Sergunb | 0:8918a71cdbe9 | 32 | //Number of TX buffers |
Sergunb | 0:8918a71cdbe9 | 33 | #ifndef SAM4E_ETH_TX_BUFFER_COUNT |
Sergunb | 0:8918a71cdbe9 | 34 | #define SAM4E_ETH_TX_BUFFER_COUNT 2 |
Sergunb | 0:8918a71cdbe9 | 35 | #elif (SAM4E_ETH_TX_BUFFER_COUNT < 1) |
Sergunb | 0:8918a71cdbe9 | 36 | #error SAM4E_ETH_TX_BUFFER_COUNT parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 37 | #endif |
Sergunb | 0:8918a71cdbe9 | 38 | |
Sergunb | 0:8918a71cdbe9 | 39 | //TX buffer size |
Sergunb | 0:8918a71cdbe9 | 40 | #ifndef SAM4E_ETH_TX_BUFFER_SIZE |
Sergunb | 0:8918a71cdbe9 | 41 | #define SAM4E_ETH_TX_BUFFER_SIZE 1536 |
Sergunb | 0:8918a71cdbe9 | 42 | #elif (SAM4E_ETH_TX_BUFFER_SIZE != 1536) |
Sergunb | 0:8918a71cdbe9 | 43 | #error SAM4E_ETH_TX_BUFFER_SIZE parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 44 | #endif |
Sergunb | 0:8918a71cdbe9 | 45 | |
Sergunb | 0:8918a71cdbe9 | 46 | //Number of RX buffers |
Sergunb | 0:8918a71cdbe9 | 47 | #ifndef SAM4E_ETH_RX_BUFFER_COUNT |
Sergunb | 0:8918a71cdbe9 | 48 | #define SAM4E_ETH_RX_BUFFER_COUNT 48 |
Sergunb | 0:8918a71cdbe9 | 49 | #elif (SAM4E_ETH_RX_BUFFER_COUNT < 12) |
Sergunb | 0:8918a71cdbe9 | 50 | #error SAM4E_ETH_RX_BUFFER_COUNT parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 51 | #endif |
Sergunb | 0:8918a71cdbe9 | 52 | |
Sergunb | 0:8918a71cdbe9 | 53 | //RX buffer size |
Sergunb | 0:8918a71cdbe9 | 54 | #ifndef SAM4E_ETH_RX_BUFFER_SIZE |
Sergunb | 0:8918a71cdbe9 | 55 | #define SAM4E_ETH_RX_BUFFER_SIZE 128 |
Sergunb | 0:8918a71cdbe9 | 56 | #elif (SAM4E_ETH_RX_BUFFER_SIZE != 128) |
Sergunb | 0:8918a71cdbe9 | 57 | #error SAM4E_ETH_RX_BUFFER_SIZE parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 58 | #endif |
Sergunb | 0:8918a71cdbe9 | 59 | |
Sergunb | 0:8918a71cdbe9 | 60 | //Interrupt priority grouping |
Sergunb | 0:8918a71cdbe9 | 61 | #ifndef SAM4E_ETH_IRQ_PRIORITY_GROUPING |
Sergunb | 0:8918a71cdbe9 | 62 | #define SAM4E_ETH_IRQ_PRIORITY_GROUPING 3 |
Sergunb | 0:8918a71cdbe9 | 63 | #elif (SAM4E_ETH_IRQ_PRIORITY_GROUPING < 0) |
Sergunb | 0:8918a71cdbe9 | 64 | #error SAM4E_ETH_IRQ_PRIORITY_GROUPING parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 65 | #endif |
Sergunb | 0:8918a71cdbe9 | 66 | |
Sergunb | 0:8918a71cdbe9 | 67 | //Ethernet interrupt group priority |
Sergunb | 0:8918a71cdbe9 | 68 | #ifndef SAM4E_ETH_IRQ_GROUP_PRIORITY |
Sergunb | 0:8918a71cdbe9 | 69 | #define SAM4E_ETH_IRQ_GROUP_PRIORITY 12 |
Sergunb | 0:8918a71cdbe9 | 70 | #elif (SAM4E_ETH_IRQ_GROUP_PRIORITY < 0) |
Sergunb | 0:8918a71cdbe9 | 71 | #error SAM4E_ETH_IRQ_GROUP_PRIORITY parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 72 | #endif |
Sergunb | 0:8918a71cdbe9 | 73 | |
Sergunb | 0:8918a71cdbe9 | 74 | //Ethernet interrupt subpriority |
Sergunb | 0:8918a71cdbe9 | 75 | #ifndef SAM4E_ETH_IRQ_SUB_PRIORITY |
Sergunb | 0:8918a71cdbe9 | 76 | #define SAM4E_ETH_IRQ_SUB_PRIORITY 0 |
Sergunb | 0:8918a71cdbe9 | 77 | #elif (SAM4E_ETH_IRQ_SUB_PRIORITY < 0) |
Sergunb | 0:8918a71cdbe9 | 78 | #error SAM4E_ETH_IRQ_SUB_PRIORITY parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 79 | #endif |
Sergunb | 0:8918a71cdbe9 | 80 | |
Sergunb | 0:8918a71cdbe9 | 81 | //Legacy definitions |
Sergunb | 0:8918a71cdbe9 | 82 | #ifndef PIO_PD6A_GRX1 |
Sergunb | 0:8918a71cdbe9 | 83 | #define PIO_PD6A_GRX1 PIO_PD6A_GRX0 |
Sergunb | 0:8918a71cdbe9 | 84 | #endif |
Sergunb | 0:8918a71cdbe9 | 85 | |
Sergunb | 0:8918a71cdbe9 | 86 | //MII signals |
Sergunb | 0:8918a71cdbe9 | 87 | #define GMAC_MII_MASK (PIO_PD16A_GTX3 | \ |
Sergunb | 0:8918a71cdbe9 | 88 | PIO_PD15A_GTX2 | PIO_PD14A_GRXCK | PIO_PD13A_GCOL | PIO_PD12A_GRX3 | \ |
Sergunb | 0:8918a71cdbe9 | 89 | PIO_PD11A_GRX2 | PIO_PD10A_GCRS | PIO_PD9A_GMDIO | PIO_PD8A_GMDC | \ |
Sergunb | 0:8918a71cdbe9 | 90 | PIO_PD7A_GRXER | PIO_PD6A_GRX1 | PIO_PD5A_GRX0 | PIO_PD4A_GRXDV | \ |
Sergunb | 0:8918a71cdbe9 | 91 | PIO_PD3A_GTX1 | PIO_PD2A_GTX0 | PIO_PD1A_GTXEN | PIO_PD0A_GTXCK) |
Sergunb | 0:8918a71cdbe9 | 92 | |
Sergunb | 0:8918a71cdbe9 | 93 | //TX buffer descriptor flags |
Sergunb | 0:8918a71cdbe9 | 94 | #define GMAC_TX_USED 0x80000000 |
Sergunb | 0:8918a71cdbe9 | 95 | #define GMAC_TX_WRAP 0x40000000 |
Sergunb | 0:8918a71cdbe9 | 96 | #define GMAC_TX_RLE_ERROR 0x20000000 |
Sergunb | 0:8918a71cdbe9 | 97 | #define GMAC_TX_UNDERRUN_ERROR 0x10000000 |
Sergunb | 0:8918a71cdbe9 | 98 | #define GMAC_TX_AHB_ERROR 0x08000000 |
Sergunb | 0:8918a71cdbe9 | 99 | #define GMAC_TX_LATE_COL_ERROR 0x04000000 |
Sergunb | 0:8918a71cdbe9 | 100 | #define GMAC_TX_CHECKSUM_ERROR 0x00700000 |
Sergunb | 0:8918a71cdbe9 | 101 | #define GMAC_TX_NO_CRC 0x00010000 |
Sergunb | 0:8918a71cdbe9 | 102 | #define GMAC_TX_LAST 0x00008000 |
Sergunb | 0:8918a71cdbe9 | 103 | #define GMAC_TX_LENGTH 0x00003FFF |
Sergunb | 0:8918a71cdbe9 | 104 | |
Sergunb | 0:8918a71cdbe9 | 105 | //RX buffer descriptor flags |
Sergunb | 0:8918a71cdbe9 | 106 | #define GMAC_RX_ADDRESS 0xFFFFFFFC |
Sergunb | 0:8918a71cdbe9 | 107 | #define GMAC_RX_WRAP 0x00000002 |
Sergunb | 0:8918a71cdbe9 | 108 | #define GMAC_RX_OWNERSHIP 0x00000001 |
Sergunb | 0:8918a71cdbe9 | 109 | #define GMAC_RX_BROADCAST 0x80000000 |
Sergunb | 0:8918a71cdbe9 | 110 | #define GMAC_RX_MULTICAST_HASH 0x40000000 |
Sergunb | 0:8918a71cdbe9 | 111 | #define GMAC_RX_UNICAST_HASH 0x20000000 |
Sergunb | 0:8918a71cdbe9 | 112 | #define GMAC_RX_SAR 0x08000000 |
Sergunb | 0:8918a71cdbe9 | 113 | #define GMAC_RX_SAR_MASK 0x06000000 |
Sergunb | 0:8918a71cdbe9 | 114 | #define GMAC_RX_TYPE_ID 0x01000000 |
Sergunb | 0:8918a71cdbe9 | 115 | #define GMAC_RX_SNAP 0x01000000 |
Sergunb | 0:8918a71cdbe9 | 116 | #define GMAC_RX_TYPE_ID_MASK 0x00C00000 |
Sergunb | 0:8918a71cdbe9 | 117 | #define GMAC_RX_CHECKSUM_VALID 0x00C00000 |
Sergunb | 0:8918a71cdbe9 | 118 | #define GMAC_RX_VLAN_TAG 0x00200000 |
Sergunb | 0:8918a71cdbe9 | 119 | #define GMAC_RX_PRIORITY_TAG 0x00100000 |
Sergunb | 0:8918a71cdbe9 | 120 | #define GMAC_RX_VLAN_PRIORITY 0x000E0000 |
Sergunb | 0:8918a71cdbe9 | 121 | #define GMAC_RX_CFI 0x00010000 |
Sergunb | 0:8918a71cdbe9 | 122 | #define GMAC_RX_EOF 0x00008000 |
Sergunb | 0:8918a71cdbe9 | 123 | #define GMAC_RX_SOF 0x00004000 |
Sergunb | 0:8918a71cdbe9 | 124 | #define GMAC_RX_LENGTH_MSB 0x00002000 |
Sergunb | 0:8918a71cdbe9 | 125 | #define GMAC_RX_BAD_FCS 0x00002000 |
Sergunb | 0:8918a71cdbe9 | 126 | #define GMAC_RX_LENGTH 0x00001FFF |
Sergunb | 0:8918a71cdbe9 | 127 | |
Sergunb | 0:8918a71cdbe9 | 128 | |
Sergunb | 0:8918a71cdbe9 | 129 | /** |
Sergunb | 0:8918a71cdbe9 | 130 | * @brief Transmit buffer descriptor |
Sergunb | 0:8918a71cdbe9 | 131 | **/ |
Sergunb | 0:8918a71cdbe9 | 132 | |
Sergunb | 0:8918a71cdbe9 | 133 | typedef struct |
Sergunb | 0:8918a71cdbe9 | 134 | { |
Sergunb | 0:8918a71cdbe9 | 135 | uint32_t address; |
Sergunb | 0:8918a71cdbe9 | 136 | uint32_t status; |
Sergunb | 0:8918a71cdbe9 | 137 | } Sam4eTxBufferDesc; |
Sergunb | 0:8918a71cdbe9 | 138 | |
Sergunb | 0:8918a71cdbe9 | 139 | |
Sergunb | 0:8918a71cdbe9 | 140 | /** |
Sergunb | 0:8918a71cdbe9 | 141 | * @brief Receive buffer descriptor |
Sergunb | 0:8918a71cdbe9 | 142 | **/ |
Sergunb | 0:8918a71cdbe9 | 143 | |
Sergunb | 0:8918a71cdbe9 | 144 | typedef struct |
Sergunb | 0:8918a71cdbe9 | 145 | { |
Sergunb | 0:8918a71cdbe9 | 146 | uint32_t address; |
Sergunb | 0:8918a71cdbe9 | 147 | uint32_t status; |
Sergunb | 0:8918a71cdbe9 | 148 | } Sam4eRxBufferDesc; |
Sergunb | 0:8918a71cdbe9 | 149 | |
Sergunb | 0:8918a71cdbe9 | 150 | |
Sergunb | 0:8918a71cdbe9 | 151 | //SAM4E Ethernet MAC driver |
Sergunb | 0:8918a71cdbe9 | 152 | extern const NicDriver sam4eEthDriver; |
Sergunb | 0:8918a71cdbe9 | 153 | |
Sergunb | 0:8918a71cdbe9 | 154 | //SAM4E Ethernet MAC related functions |
Sergunb | 0:8918a71cdbe9 | 155 | error_t sam4eEthInit(NetInterface *interface); |
Sergunb | 0:8918a71cdbe9 | 156 | void sam4eEthInitGpio(NetInterface *interface); |
Sergunb | 0:8918a71cdbe9 | 157 | void sam4eEthInitBufferDesc(NetInterface *interface); |
Sergunb | 0:8918a71cdbe9 | 158 | |
Sergunb | 0:8918a71cdbe9 | 159 | void sam4eEthTick(NetInterface *interface); |
Sergunb | 0:8918a71cdbe9 | 160 | |
Sergunb | 0:8918a71cdbe9 | 161 | void sam4eEthEnableIrq(NetInterface *interface); |
Sergunb | 0:8918a71cdbe9 | 162 | void sam4eEthDisableIrq(NetInterface *interface); |
Sergunb | 0:8918a71cdbe9 | 163 | void sam4eEthEventHandler(NetInterface *interface); |
Sergunb | 0:8918a71cdbe9 | 164 | |
Sergunb | 0:8918a71cdbe9 | 165 | error_t sam4eEthSendPacket(NetInterface *interface, |
Sergunb | 0:8918a71cdbe9 | 166 | const NetBuffer *buffer, size_t offset); |
Sergunb | 0:8918a71cdbe9 | 167 | |
Sergunb | 0:8918a71cdbe9 | 168 | error_t sam4eEthReceivePacket(NetInterface *interface); |
Sergunb | 0:8918a71cdbe9 | 169 | |
Sergunb | 0:8918a71cdbe9 | 170 | error_t sam4eEthSetMulticastFilter(NetInterface *interface); |
Sergunb | 0:8918a71cdbe9 | 171 | error_t sam4eEthUpdateMacConfig(NetInterface *interface); |
Sergunb | 0:8918a71cdbe9 | 172 | |
Sergunb | 0:8918a71cdbe9 | 173 | void sam4eEthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data); |
Sergunb | 0:8918a71cdbe9 | 174 | uint16_t sam4eEthReadPhyReg(uint8_t phyAddr, uint8_t regAddr); |
Sergunb | 0:8918a71cdbe9 | 175 | |
Sergunb | 0:8918a71cdbe9 | 176 | #endif |
Sergunb | 0:8918a71cdbe9 | 177 |