mbed OS5

Fork of UIPEthernet by Zoltan Hudak

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Enc28J60Network.h Source File

Enc28J60Network.h

00001 /*
00002  Enc28J60Network.h
00003  UIPEthernet network driver for Microchip ENC28J60 Ethernet Interface.
00004 
00005  Copyright (c) 2013 Norbert Truchsess <norbert.truchsess@t-online.de>
00006  All rights reserved.
00007 
00008  based on enc28j60.c file from the AVRlib library by Pascal Stang.
00009  For AVRlib See http://www.procyonengineering.com/
00010 
00011  Modified (ported to mbed) by Zoltan Hudak <hudakz@inbox.com>
00012 
00013  This program is free software: you can redistribute it and/or modify
00014  it under the terms of the GNU General Public License as published by
00015  the Free Software Foundation, either version 3 of the License, or
00016  (at your option) any later version.
00017 
00018  This program is distributed in the hope that it will be useful,
00019  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  GNU General Public License for more details.
00022 
00023  You should have received a copy of the GNU General Public License
00024  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  */
00026 #ifndef ENC28J60NETWORK_H
00027 #define ENC28J60NETWORK_H
00028 
00029 #include "mbed.h"
00030 #include "mempool.h"
00031 
00032 #define UIP_RECEIVEBUFFERHANDLE 0xff
00033 
00034 //#define ENC28J60DEBUG
00035 
00036 /*
00037  * Empfangen von ip-header, arp etc...
00038  * wenn tcp/udp -> tcp/udp-callback -> assign new packet to connection
00039  */
00040 class Enc28J60Network :
00041     public myMemoryPool
00042 {
00043 private:
00044     SPI                     _spi;
00045     DigitalOut              _cs;
00046     static uint16_t         nextPacketPtr;
00047     static uint8_t          bank;
00048 
00049     static struct memblock  receivePkt;
00050 
00051     uint8_t                 readOp(uint8_t op, uint8_t address);
00052     void                    writeOp(uint8_t op, uint8_t address, uint8_t data);
00053     uint16_t                setReadPtr(memhandle handle, memaddress position, uint16_t len);
00054     void                    setERXRDPT(void);
00055     void                    readBuffer(uint16_t len, uint8_t* data);
00056     void                    writeBuffer(uint16_t len, uint8_t* data);
00057     uint8_t                 readByte(uint16_t addr);
00058     void                    writeByte(uint16_t addr, uint8_t data);
00059     void                    setBank(uint8_t address);
00060     uint8_t                 readReg(uint8_t address);
00061     void                    writeReg(uint8_t address, uint8_t data);
00062     void                    writeRegPair(uint8_t address, uint16_t data);
00063     void                    phyWrite(uint8_t address, uint16_t data);
00064     uint16_t                phyRead(uint8_t address);
00065     void                    clkout(uint8_t clk);
00066 
00067     friend void             enc28J60_mempool_block_move_callback(memaddress, memaddress, memaddress);
00068 public:
00069     Enc28J60Network(PinName mosi, PinName miso, PinName sclk, PinName cs);
00070     uint8_t     getrev(void);
00071     void        powerOn(void);
00072     void        powerOff(void);
00073     bool        linkStatus(void);
00074 
00075     void        init(uint8_t* macaddr);
00076     memhandle   receivePacket(void);
00077     void        freePacket(void);
00078     memaddress  blockSize(memhandle handle);
00079     void        sendPacket(memhandle handle);
00080     uint16_t    readPacket(memhandle handle, memaddress position, uint8_t* buffer, uint16_t len);
00081     uint16_t    writePacket(memhandle handle, memaddress position, uint8_t* buffer, uint16_t len);
00082     void        copyPacket(memhandle dest, memaddress dest_pos, memhandle src, memaddress src_pos, uint16_t len);
00083     uint16_t    chksum(uint16_t sum, memhandle handle, memaddress pos, uint16_t len);
00084 };
00085 #endif /* Enc28J60NetworkClass_H_ */