Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
utility/Enc28J60Network.h@1:01c2344f98a3, 2014-11-20 (annotated)
- Committer:
- hudakz
- Date:
- Thu Nov 20 21:26:54 2014 +0000
- Revision:
- 1:01c2344f98a3
- Parent:
- uitility/Enc28J60Network.h@0:5350a66d5279
rev. 01
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| hudakz | 0:5350a66d5279 | 1 | /* |
| hudakz | 0:5350a66d5279 | 2 | Enc28J60Network.h |
| hudakz | 0:5350a66d5279 | 3 | UIPEthernet network driver for Microchip ENC28J60 Ethernet Interface. |
| hudakz | 0:5350a66d5279 | 4 | |
| hudakz | 0:5350a66d5279 | 5 | Copyright (c) 2013 Norbert Truchsess <norbert.truchsess@t-online.de> |
| hudakz | 0:5350a66d5279 | 6 | All rights reserved. |
| hudakz | 0:5350a66d5279 | 7 | |
| hudakz | 0:5350a66d5279 | 8 | inspired by enc28j60.c file from the AVRlib library by Pascal Stang. |
| hudakz | 0:5350a66d5279 | 9 | For AVRlib See http://www.procyonengineering.com/ |
| hudakz | 0:5350a66d5279 | 10 | |
| hudakz | 0:5350a66d5279 | 11 | Modified (ported to mbed) by Zoltan Hudak <hudakz@inbox.com> |
| hudakz | 0:5350a66d5279 | 12 | |
| hudakz | 0:5350a66d5279 | 13 | This program is free software: you can redistribute it and/or modify |
| hudakz | 0:5350a66d5279 | 14 | it under the terms of the GNU General Public License as published by |
| hudakz | 0:5350a66d5279 | 15 | the Free Software Foundation, either version 3 of the License, or |
| hudakz | 0:5350a66d5279 | 16 | (at your option) any later version. |
| hudakz | 0:5350a66d5279 | 17 | |
| hudakz | 0:5350a66d5279 | 18 | This program is distributed in the hope that it will be useful, |
| hudakz | 0:5350a66d5279 | 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| hudakz | 0:5350a66d5279 | 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| hudakz | 0:5350a66d5279 | 21 | GNU General Public License for more details. |
| hudakz | 0:5350a66d5279 | 22 | |
| hudakz | 0:5350a66d5279 | 23 | You should have received a copy of the GNU General Public License |
| hudakz | 0:5350a66d5279 | 24 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| hudakz | 0:5350a66d5279 | 25 | */ |
| hudakz | 0:5350a66d5279 | 26 | #ifndef ENC28J60NETWORK_H_ |
| hudakz | 0:5350a66d5279 | 27 | #define ENC28J60NETWORK_H_ |
| hudakz | 0:5350a66d5279 | 28 | |
| hudakz | 0:5350a66d5279 | 29 | #include "mbed.h" |
| hudakz | 0:5350a66d5279 | 30 | #include "mempool.h" |
| hudakz | 0:5350a66d5279 | 31 | |
| hudakz | 0:5350a66d5279 | 32 | #define UIP_RECEIVEBUFFERHANDLE 0xff |
| hudakz | 0:5350a66d5279 | 33 | |
| hudakz | 0:5350a66d5279 | 34 | //#define ENC28J60DEBUG |
| hudakz | 0:5350a66d5279 | 35 | |
| hudakz | 0:5350a66d5279 | 36 | /* |
| hudakz | 0:5350a66d5279 | 37 | * Received from ip-header, arp etc... |
| hudakz | 0:5350a66d5279 | 38 | * when tcp/udp -> tcp/udp-callback -> assign new packet to connection |
| hudakz | 0:5350a66d5279 | 39 | */ |
| hudakz | 0:5350a66d5279 | 40 | class Enc28J60Network : |
| hudakz | 0:5350a66d5279 | 41 | public MemoryPool |
| hudakz | 0:5350a66d5279 | 42 | { |
| hudakz | 0:5350a66d5279 | 43 | private: |
| hudakz | 0:5350a66d5279 | 44 | SPI _spi; |
| hudakz | 0:5350a66d5279 | 45 | DigitalOut _cs; |
| hudakz | 0:5350a66d5279 | 46 | uint16_t nextPacketPtr; |
| hudakz | 0:5350a66d5279 | 47 | uint8_t bank; |
| hudakz | 0:5350a66d5279 | 48 | |
| hudakz | 0:5350a66d5279 | 49 | struct memblock receivePkt; |
| hudakz | 0:5350a66d5279 | 50 | |
| hudakz | 0:5350a66d5279 | 51 | uint8_t readOp(uint8_t op, uint8_t address); |
| hudakz | 0:5350a66d5279 | 52 | void writeOp(uint8_t op, uint8_t address, uint8_t data); |
| hudakz | 0:5350a66d5279 | 53 | uint16_t setReadPtr(memhandle handle, memaddress position, uint16_t len); |
| hudakz | 0:5350a66d5279 | 54 | void setERXRDPT(void); |
| hudakz | 0:5350a66d5279 | 55 | void readBuffer(uint16_t len, uint8_t* data); |
| hudakz | 0:5350a66d5279 | 56 | void writeBuffer(uint16_t len, uint8_t* data); |
| hudakz | 0:5350a66d5279 | 57 | uint8_t readByte(uint16_t addr); |
| hudakz | 0:5350a66d5279 | 58 | void writeByte(uint16_t addr, uint8_t data); |
| hudakz | 0:5350a66d5279 | 59 | void setBank(uint8_t address); |
| hudakz | 0:5350a66d5279 | 60 | uint8_t readReg(uint8_t address); |
| hudakz | 0:5350a66d5279 | 61 | void writeReg(uint8_t address, uint8_t data); |
| hudakz | 0:5350a66d5279 | 62 | void writeRegPair(uint8_t address, uint16_t data); |
| hudakz | 0:5350a66d5279 | 63 | void phyWrite(uint8_t address, uint16_t data); |
| hudakz | 0:5350a66d5279 | 64 | void clkout(uint8_t clk); |
| hudakz | 0:5350a66d5279 | 65 | uint8_t getRev(void); |
| hudakz | 0:5350a66d5279 | 66 | protected: |
| hudakz | 0:5350a66d5279 | 67 | void memblock_mv_cb(memaddress dest, memaddress src, memaddress size); |
| hudakz | 0:5350a66d5279 | 68 | public: |
| hudakz | 0:5350a66d5279 | 69 | Enc28J60Network(PinName mosi, PinName miso, PinName sclk, PinName cs); |
| hudakz | 0:5350a66d5279 | 70 | void init(uint8_t* macaddr); |
| hudakz | 0:5350a66d5279 | 71 | memhandle receivePacket(void); |
| hudakz | 0:5350a66d5279 | 72 | void freePacket(void); |
| hudakz | 0:5350a66d5279 | 73 | memaddress blockSize(memhandle handle); |
| hudakz | 0:5350a66d5279 | 74 | void sendPacket(memhandle handle); |
| hudakz | 0:5350a66d5279 | 75 | uint16_t readPacket(memhandle handle, memaddress position, uint8_t* buffer, uint16_t len); |
| hudakz | 0:5350a66d5279 | 76 | uint16_t writePacket(memhandle handle, memaddress position, uint8_t* buffer, uint16_t len); |
| hudakz | 0:5350a66d5279 | 77 | void copyPacket(memhandle dest, memaddress dest_pos, memhandle src, memaddress src_pos, uint16_t len); |
| hudakz | 0:5350a66d5279 | 78 | uint16_t chksum(uint16_t sum, memhandle handle, memaddress pos, uint16_t len); |
| hudakz | 0:5350a66d5279 | 79 | }; |
| hudakz | 0:5350a66d5279 | 80 | #endif /* ENC28J60NETWORK_H_ */ |
| hudakz | 0:5350a66d5279 | 81 |