Webserver+3d print

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers nic.h Source File

nic.h

Go to the documentation of this file.
00001 /**
00002  * @file nic.h
00003  * @brief Network interface controller abstraction layer
00004  *
00005  * @section License
00006  *
00007  * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
00008  *
00009  * This file is part of CycloneTCP Open.
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation; either version 2
00014  * of the License, or (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software Foundation,
00023  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024  *
00025  * @author Oryx Embedded SARL (www.oryx-embedded.com)
00026  * @version 1.7.6
00027  **/
00028 
00029 #ifndef _NIC_H
00030 #define _NIC_H
00031 
00032 //Dependencies
00033 #include "core/net.h"
00034 
00035 //Tick interval to handle NIC periodic operations
00036 #ifndef NIC_TICK_INTERVAL
00037    #define NIC_TICK_INTERVAL 1000
00038 #elif (NIC_TICK_INTERVAL < 10)
00039    #error NIC_TICK_INTERVAL parameter is not valid
00040 #endif
00041 
00042 //Maximum duration a write operation may block
00043 #ifndef NIC_MAX_BLOCKING_TIME
00044    #define NIC_MAX_BLOCKING_TIME INFINITE_DELAY
00045 #elif (NIC_MAX_BLOCKING_TIME < 0)
00046    #error NIC_MAX_BLOCKING_TIME parameter is not valid
00047 #endif
00048 
00049 //Size of the NIC driver context
00050 #ifndef NIC_CONTEXT_SIZE
00051    #define NIC_CONTEXT_SIZE 16
00052 #elif (NIC_CONTEXT_SIZE < 1)
00053    #error NIC_CONTEXT_SIZE parameter is not valid
00054 #endif
00055 
00056 
00057 /**
00058  * @brief NIC types
00059  **/
00060 
00061 typedef enum
00062 {
00063    NIC_TYPE_ETHERNET = 0, ///<Ethernet interface
00064    NIC_TYPE_PPP      = 1, ///<PPP interface
00065    NIC_TYPE_6LOWPAN  = 2  ///<6LoWPAN interface
00066 } NicType;
00067 
00068 
00069 /**
00070  * @brief Link state
00071  **/
00072 
00073 typedef enum
00074 {
00075    NIC_LINK_STATE_DOWN = 0,
00076    NIC_LINK_STATE_UP   = 1,
00077    NIC_LINK_STATE_AUTO = 2
00078 } NicLinkState;
00079 
00080 
00081 /**
00082  * @brief Link speed
00083  **/
00084 
00085 typedef enum
00086 {
00087    NIC_LINK_SPEED_UNKNOWN = 0,
00088    NIC_LINK_SPEED_10MBPS  = 10000000,
00089    NIC_LINK_SPEED_100MBPS = 100000000,
00090    NIC_LINK_SPEED_1GBPS   = 1000000000
00091 } NicLinkSpeed;
00092 
00093 
00094 /**
00095  * @brief Duplex mode
00096  **/
00097 
00098 typedef enum
00099 {
00100    NIC_UNKNOWN_DUPLEX_MODE = 0,
00101    NIC_HALF_DUPLEX_MODE    = 1,
00102    NIC_FULL_DUPLEX_MODE    = 2
00103 } NicDuplexMode;
00104 
00105 
00106 //NIC abstraction layer
00107 typedef error_t (*NicInit)(NetInterface *interface);
00108 typedef void (*NicTick)(NetInterface *interface);
00109 typedef void (*NicEnableIrq)(NetInterface *interface);
00110 typedef void (*NicDisableIrq)(NetInterface *interface);
00111 typedef void (*NicEventHandler)(NetInterface *interface);
00112 typedef error_t (*NicSendPacket)(NetInterface *interface, const NetBuffer *buffer, size_t offset);
00113 typedef error_t (*NicSetMulticastFilter)(NetInterface *interface);
00114 typedef error_t (*NicUpdateMacConfig)(NetInterface *interface);
00115 typedef void (*NicWritePhyReg)(uint8_t phyAddr, uint8_t regAddr, uint16_t data);
00116 typedef uint16_t (*NicReadPhyReg)(uint8_t phyAddr, uint8_t regAddr);
00117 
00118 //PHY abstraction layer
00119 typedef error_t (*PhyInit)(NetInterface *interface);
00120 typedef void (*PhyTick)(NetInterface *interface);
00121 typedef void (*PhyEnableIrq)(NetInterface *interface);
00122 typedef void (*PhyDisableIrq)(NetInterface *interface);
00123 typedef void (*PhyEventHandler)(NetInterface *interface);
00124 
00125 //SPI abstraction layer
00126 typedef error_t (*SpiInit)(void);
00127 typedef error_t (*SpiSetMode)(uint_t mode);
00128 typedef error_t (*SpiSetBitrate)(uint_t bitrate);
00129 typedef void (*SpiAssertCs)(void);
00130 typedef void (*SpiDeassertCs)(void);
00131 typedef uint8_t (*SpiTransfer)(uint8_t data);
00132 
00133 //UART abstraction layer
00134 typedef error_t (*UartInit)(void);
00135 typedef void (*UartEnableIrq)(void);
00136 typedef void (*UartDisableIrq)(void);
00137 typedef void (*UartStartTx)(void);
00138 
00139 //External interrupt line abstraction layer
00140 typedef error_t (*ExtIntInit)(void);
00141 typedef void (*ExtIntEnableIrq)(void);
00142 typedef void (*ExtIntDisableIrq)(void);
00143 
00144 
00145 /**
00146  * @brief NIC driver
00147  **/
00148 
00149 typedef struct
00150 {
00151    NicType type;
00152    size_t mtu;
00153    NicInit init;
00154    NicTick tick;
00155    NicEnableIrq enableIrq;
00156    NicDisableIrq disableIrq;
00157    NicEventHandler eventHandler;
00158    NicSendPacket sendPacket;
00159    NicSetMulticastFilter setMulticastFilter;
00160    NicUpdateMacConfig updateMacConfig;
00161    NicWritePhyReg writePhyReg;
00162    NicReadPhyReg readPhyReg;
00163    bool_t autoPadding;
00164    bool_t autoCrcCalc;
00165    bool_t autoCrcVerif;
00166    bool_t autoCrcStrip;
00167    //bool_t autoIpv4ChecksumCalc;
00168    //bool_t autoIpv4ChecksumVerif;
00169    //bool_t autoIpv6ChecksumCalc;
00170    //bool_t autoIpv6ChecksumVerif;
00171    //bool_t autoIcmpChecksumCalc;
00172    //bool_t autoIcmpChecksumVerif;
00173    //bool_t autoTcpChecksumCalc;
00174    //bool_t autoTcpChecksumVerif;
00175    //bool_t autoUdpChecksumCalc;
00176    //bool_t autoUdpChecksumVerif;
00177 } NicDriver;
00178 
00179 
00180 /**
00181  * @brief PHY driver
00182  **/
00183 
00184 typedef struct
00185 {
00186    PhyInit init;
00187    PhyTick tick;
00188    PhyEnableIrq enableIrq;
00189    PhyDisableIrq disableIrq;
00190    PhyEventHandler eventHandler;
00191 } PhyDriver;
00192 
00193 
00194 /**
00195  * @brief SPI driver
00196  **/
00197 
00198 typedef struct
00199 {
00200    SpiInit init;
00201    SpiSetMode setMode;
00202    SpiSetBitrate setBitrate;
00203    SpiAssertCs assertCs;
00204    SpiDeassertCs deassertCs;
00205    SpiTransfer transfer;
00206 } SpiDriver;
00207 
00208 
00209 /**
00210  * @brief UART driver
00211  **/
00212 
00213 typedef struct
00214 {
00215    UartInit init;
00216    UartEnableIrq enableIrq;
00217    UartDisableIrq disableIrq;
00218    UartStartTx startTx;
00219 } UartDriver;
00220 
00221 
00222 /**
00223  * @brief External interrupt line driver
00224  **/
00225 
00226 typedef struct
00227 {
00228    ExtIntInit init;
00229    ExtIntEnableIrq enableIrq;
00230    ExtIntDisableIrq disableIrq;
00231 } ExtIntDriver;
00232 
00233 
00234 //Tick counter to handle periodic operations
00235 extern systime_t nicTickCounter;
00236 
00237 //NIC abstraction layer
00238 void nicTick(NetInterface *interface);
00239 
00240 error_t nicSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset);
00241 error_t nicSetMulticastFilter(NetInterface *interface);
00242 
00243 void nicProcessPacket(NetInterface *interface, void *packet, size_t length);
00244 void nicNotifyLinkChange(NetInterface *interface);
00245 
00246 #endif
00247