Webserver+3d print

Dependents:   Nucleo

Committer:
Sergunb
Date:
Sat Feb 04 18:15:49 2017 +0000
Revision:
0:8918a71cdbe9
nothing else

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sergunb 0:8918a71cdbe9 1 /**
Sergunb 0:8918a71cdbe9 2 * @file sam9263_eth.h
Sergunb 0:8918a71cdbe9 3 * @brief AT91SAM9263 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 _SAM9263_ETH_H
Sergunb 0:8918a71cdbe9 30 #define _SAM9263_ETH_H
Sergunb 0:8918a71cdbe9 31
Sergunb 0:8918a71cdbe9 32 //Number of TX buffers
Sergunb 0:8918a71cdbe9 33 #ifndef SAM9263_ETH_TX_BUFFER_COUNT
Sergunb 0:8918a71cdbe9 34 #define SAM9263_ETH_TX_BUFFER_COUNT 3
Sergunb 0:8918a71cdbe9 35 #elif (SAM9263_ETH_TX_BUFFER_COUNT < 1)
Sergunb 0:8918a71cdbe9 36 #error SAM9263_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 SAM9263_ETH_TX_BUFFER_SIZE
Sergunb 0:8918a71cdbe9 41 #define SAM9263_ETH_TX_BUFFER_SIZE 1536
Sergunb 0:8918a71cdbe9 42 #elif (SAM9263_ETH_TX_BUFFER_SIZE != 1536)
Sergunb 0:8918a71cdbe9 43 #error SAM9263_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 SAM9263_ETH_RX_BUFFER_COUNT
Sergunb 0:8918a71cdbe9 48 #define SAM9263_ETH_RX_BUFFER_COUNT 72
Sergunb 0:8918a71cdbe9 49 #elif (SAM9263_ETH_RX_BUFFER_COUNT < 12)
Sergunb 0:8918a71cdbe9 50 #error SAM9263_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 SAM9263_ETH_RX_BUFFER_SIZE
Sergunb 0:8918a71cdbe9 55 #define SAM9263_ETH_RX_BUFFER_SIZE 128
Sergunb 0:8918a71cdbe9 56 #elif (SAM9263_ETH_RX_BUFFER_SIZE != 128)
Sergunb 0:8918a71cdbe9 57 #error SAM9263_ETH_RX_BUFFER_SIZE parameter is not valid
Sergunb 0:8918a71cdbe9 58 #endif
Sergunb 0:8918a71cdbe9 59
Sergunb 0:8918a71cdbe9 60 //EMAC controller base address
Sergunb 0:8918a71cdbe9 61 #define AT91C_BASE_EMAC AT91C_BASE_MACB
Sergunb 0:8918a71cdbe9 62
Sergunb 0:8918a71cdbe9 63 //RMII signals
Sergunb 0:8918a71cdbe9 64 #define AT91C_EMAC_RMII_MASK_C AT91C_PC25_ERXDV
Sergunb 0:8918a71cdbe9 65
Sergunb 0:8918a71cdbe9 66 #define AT91C_EMAC_RMII_MASK_E (AT91C_PE30_EMDIO | \
Sergunb 0:8918a71cdbe9 67 AT91C_PE29_EMDC | AT91C_PE28_ETXEN | AT91C_PE27_ERXER | AT91C_PE26_ERX1 | \
Sergunb 0:8918a71cdbe9 68 AT91C_PE25_ERX0 | AT91C_PE24_ETX1 | AT91C_PE23_ETX0 | AT91C_PE21_ETXCK)
Sergunb 0:8918a71cdbe9 69
Sergunb 0:8918a71cdbe9 70 //PHY maintenance register (EMAC_MAN)
Sergunb 0:8918a71cdbe9 71 #define AT91C_EMAC_SOF_01 (1 << 30)
Sergunb 0:8918a71cdbe9 72 #define AT91C_EMAC_RW_01 (1 << 28)
Sergunb 0:8918a71cdbe9 73 #define AT91C_EMAC_RW_10 (2 << 28)
Sergunb 0:8918a71cdbe9 74 #define AT91C_EMAC_CODE_10 (2 << 16)
Sergunb 0:8918a71cdbe9 75
Sergunb 0:8918a71cdbe9 76 //TX buffer descriptor flags
Sergunb 0:8918a71cdbe9 77 #define AT91C_EMAC_TX_USED 0x80000000
Sergunb 0:8918a71cdbe9 78 #define AT91C_EMAC_TX_WRAP 0x40000000
Sergunb 0:8918a71cdbe9 79 #define AT91C_EMAC_TX_ERROR 0x20000000
Sergunb 0:8918a71cdbe9 80 #define AT91C_EMAC_TX_UNDERRUN 0x10000000
Sergunb 0:8918a71cdbe9 81 #define AT91C_EMAC_TX_EXHAUSTED 0x08000000
Sergunb 0:8918a71cdbe9 82 #define AT91C_EMAC_TX_NO_CRC 0x00010000
Sergunb 0:8918a71cdbe9 83 #define AT91C_EMAC_TX_LAST 0x00008000
Sergunb 0:8918a71cdbe9 84 #define AT91C_EMAC_TX_LENGTH 0x000007FF
Sergunb 0:8918a71cdbe9 85
Sergunb 0:8918a71cdbe9 86 //RX buffer descriptor flags
Sergunb 0:8918a71cdbe9 87 #define AT91C_EMAC_RX_ADDRESS 0xFFFFFFFC
Sergunb 0:8918a71cdbe9 88 #define AT91C_EMAC_RX_WRAP 0x00000002
Sergunb 0:8918a71cdbe9 89 #define AT91C_EMAC_RX_OWNERSHIP 0x00000001
Sergunb 0:8918a71cdbe9 90 #define AT91C_EMAC_RX_BROADCAST 0x80000000
Sergunb 0:8918a71cdbe9 91 #define AT91C_EMAC_RX_MULTICAST_HASH 0x40000000
Sergunb 0:8918a71cdbe9 92 #define AT91C_EMAC_RX_UNICAST_HASH 0x20000000
Sergunb 0:8918a71cdbe9 93 #define AT91C_EMAC_RX_EXT_ADDR 0x10000000
Sergunb 0:8918a71cdbe9 94 #define AT91C_EMAC_RX_SAR1 0x04000000
Sergunb 0:8918a71cdbe9 95 #define AT91C_EMAC_RX_SAR2 0x02000000
Sergunb 0:8918a71cdbe9 96 #define AT91C_EMAC_RX_SAR3 0x01000000
Sergunb 0:8918a71cdbe9 97 #define AT91C_EMAC_RX_SAR4 0x00800000
Sergunb 0:8918a71cdbe9 98 #define AT91C_EMAC_RX_TYPE_ID 0x00400000
Sergunb 0:8918a71cdbe9 99 #define AT91C_EMAC_RX_VLAN_TAG 0x00200000
Sergunb 0:8918a71cdbe9 100 #define AT91C_EMAC_RX_PRIORITY_TAG 0x00100000
Sergunb 0:8918a71cdbe9 101 #define AT91C_EMAC_RX_VLAN_PRIORITY 0x000E0000
Sergunb 0:8918a71cdbe9 102 #define AT91C_EMAC_RX_CFI 0x00010000
Sergunb 0:8918a71cdbe9 103 #define AT91C_EMAC_RX_EOF 0x00008000
Sergunb 0:8918a71cdbe9 104 #define AT91C_EMAC_RX_SOF 0x00004000
Sergunb 0:8918a71cdbe9 105 #define AT91C_EMAC_RX_OFFSET 0x00003000
Sergunb 0:8918a71cdbe9 106 #define AT91C_EMAC_RX_LENGTH 0x00000FFF
Sergunb 0:8918a71cdbe9 107
Sergunb 0:8918a71cdbe9 108
Sergunb 0:8918a71cdbe9 109 /**
Sergunb 0:8918a71cdbe9 110 * @brief Transmit buffer descriptor
Sergunb 0:8918a71cdbe9 111 **/
Sergunb 0:8918a71cdbe9 112
Sergunb 0:8918a71cdbe9 113 typedef struct
Sergunb 0:8918a71cdbe9 114 {
Sergunb 0:8918a71cdbe9 115 uint32_t address;
Sergunb 0:8918a71cdbe9 116 uint32_t status;
Sergunb 0:8918a71cdbe9 117 } Sam9263TxBufferDesc;
Sergunb 0:8918a71cdbe9 118
Sergunb 0:8918a71cdbe9 119
Sergunb 0:8918a71cdbe9 120 /**
Sergunb 0:8918a71cdbe9 121 * @brief Receive buffer descriptor
Sergunb 0:8918a71cdbe9 122 **/
Sergunb 0:8918a71cdbe9 123
Sergunb 0:8918a71cdbe9 124 typedef struct
Sergunb 0:8918a71cdbe9 125 {
Sergunb 0:8918a71cdbe9 126 uint32_t address;
Sergunb 0:8918a71cdbe9 127 uint32_t status;
Sergunb 0:8918a71cdbe9 128 } Sam9263RxBufferDesc;
Sergunb 0:8918a71cdbe9 129
Sergunb 0:8918a71cdbe9 130
Sergunb 0:8918a71cdbe9 131 //SAM9263 Ethernet MAC driver
Sergunb 0:8918a71cdbe9 132 extern const NicDriver sam9263EthDriver;
Sergunb 0:8918a71cdbe9 133
Sergunb 0:8918a71cdbe9 134 //SAM9263 Ethernet MAC related functions
Sergunb 0:8918a71cdbe9 135 error_t sam9263EthInit(NetInterface *interface);
Sergunb 0:8918a71cdbe9 136 void sam9263EthInitGpio(NetInterface *interface);
Sergunb 0:8918a71cdbe9 137 void sam9263EthInitBufferDesc(NetInterface *interface);
Sergunb 0:8918a71cdbe9 138
Sergunb 0:8918a71cdbe9 139 void sam9263EthTick(NetInterface *interface);
Sergunb 0:8918a71cdbe9 140
Sergunb 0:8918a71cdbe9 141 void sam9263EthEnableIrq(NetInterface *interface);
Sergunb 0:8918a71cdbe9 142 void sam9263EthDisableIrq(NetInterface *interface);
Sergunb 0:8918a71cdbe9 143 void sam9263EthIrqHandler(void);
Sergunb 0:8918a71cdbe9 144 void sam9263EthEventHandler(NetInterface *interface);
Sergunb 0:8918a71cdbe9 145
Sergunb 0:8918a71cdbe9 146 error_t sam9263EthSendPacket(NetInterface *interface,
Sergunb 0:8918a71cdbe9 147 const NetBuffer *buffer, size_t offset);
Sergunb 0:8918a71cdbe9 148
Sergunb 0:8918a71cdbe9 149 error_t sam9263EthReceivePacket(NetInterface *interface);
Sergunb 0:8918a71cdbe9 150
Sergunb 0:8918a71cdbe9 151 error_t sam9263EthSetMulticastFilter(NetInterface *interface);
Sergunb 0:8918a71cdbe9 152 error_t sam9263EthUpdateMacConfig(NetInterface *interface);
Sergunb 0:8918a71cdbe9 153
Sergunb 0:8918a71cdbe9 154 void sam9263EthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data);
Sergunb 0:8918a71cdbe9 155 uint16_t sam9263EthReadPhyReg(uint8_t phyAddr, uint8_t regAddr);
Sergunb 0:8918a71cdbe9 156
Sergunb 0:8918a71cdbe9 157 //Wrapper for the interrupt service routine
Sergunb 0:8918a71cdbe9 158 void emacIrqWrapper(void);
Sergunb 0:8918a71cdbe9 159
Sergunb 0:8918a71cdbe9 160 #endif
Sergunb 0:8918a71cdbe9 161