Fork for fixes
utility/Enc28j60Eth.h@22:a0b1d0e6d237, 2020-09-26 (annotated)
- Committer:
- ivo_n
- Date:
- Sat Sep 26 08:31:41 2020 +0000
- Revision:
- 22:a0b1d0e6d237
- Parent:
- 19:58e840279555
Everything seems to work
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 9:a156d3de5647 | 1 | /* |
hudakz | 9:a156d3de5647 | 2 | Enc28J60Network.h |
hudakz | 9:a156d3de5647 | 3 | UIPEthernet network driver for Microchip ENC28J60 Ethernet Interface. |
hudakz | 9:a156d3de5647 | 4 | |
hudakz | 9:a156d3de5647 | 5 | Copyright (c) 2013 Norbert Truchsess <norbert.truchsess@t-online.de> |
hudakz | 9:a156d3de5647 | 6 | All rights reserved. |
hudakz | 9:a156d3de5647 | 7 | |
hudakz | 9:a156d3de5647 | 8 | based on enc28j60.c file from the AVRlib library by Pascal Stang. |
hudakz | 9:a156d3de5647 | 9 | For AVRlib See http://www.procyonengineering.com/ |
hudakz | 9:a156d3de5647 | 10 | |
hudakz | 9:a156d3de5647 | 11 | Modified (ported to mbed) by Zoltan Hudak <hudakz@inbox.com> |
hudakz | 9:a156d3de5647 | 12 | |
hudakz | 9:a156d3de5647 | 13 | This program is free software: you can redistribute it and/or modify |
hudakz | 9:a156d3de5647 | 14 | it under the terms of the GNU General Public License as published by |
hudakz | 9:a156d3de5647 | 15 | the Free Software Foundation, either version 3 of the License, or |
hudakz | 9:a156d3de5647 | 16 | (at your option) any later version. |
hudakz | 9:a156d3de5647 | 17 | |
hudakz | 9:a156d3de5647 | 18 | This program is distributed in the hope that it will be useful, |
hudakz | 9:a156d3de5647 | 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
hudakz | 9:a156d3de5647 | 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
hudakz | 9:a156d3de5647 | 21 | GNU General Public License for more details. |
hudakz | 9:a156d3de5647 | 22 | |
hudakz | 9:a156d3de5647 | 23 | You should have received a copy of the GNU General Public License |
hudakz | 9:a156d3de5647 | 24 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
hudakz | 9:a156d3de5647 | 25 | */ |
hudakz | 9:a156d3de5647 | 26 | #ifndef ENC28J60PHY_H |
hudakz | 9:a156d3de5647 | 27 | #define ENC28J60PHY_H |
hudakz | 9:a156d3de5647 | 28 | |
hudakz | 9:a156d3de5647 | 29 | #include "mbed.h" |
hudakz | 9:a156d3de5647 | 30 | #include "MemPool.h" |
hudakz | 9:a156d3de5647 | 31 | |
hudakz | 9:a156d3de5647 | 32 | #define UIP_RECEIVEBUFFERHANDLE 0xff |
hudakz | 9:a156d3de5647 | 33 | |
ivo_n | 19:58e840279555 | 34 | #define ENC28J60DEBUG |
hudakz | 9:a156d3de5647 | 35 | |
hudakz | 11:647d53d146f1 | 36 | class Enc28j60Eth : public MemPool |
hudakz | 9:a156d3de5647 | 37 | { |
hudakz | 9:a156d3de5647 | 38 | private: |
hudakz | 9:a156d3de5647 | 39 | SPI _spi; |
hudakz | 9:a156d3de5647 | 40 | DigitalOut _cs; |
hudakz | 9:a156d3de5647 | 41 | static uint16_t nextPacketPtr; |
hudakz | 9:a156d3de5647 | 42 | static uint8_t bank; |
hudakz | 9:a156d3de5647 | 43 | |
hudakz | 9:a156d3de5647 | 44 | static struct memblock receivePkt; |
hudakz | 9:a156d3de5647 | 45 | |
hudakz | 9:a156d3de5647 | 46 | uint16_t setReadPtr(memhandle handle, memaddress position, uint16_t len); |
hudakz | 9:a156d3de5647 | 47 | void setERXRDPT(); |
hudakz | 9:a156d3de5647 | 48 | void readBuffer(uint16_t len, uint8_t* data); |
hudakz | 9:a156d3de5647 | 49 | void writeBuffer(uint16_t len, uint8_t* data); |
hudakz | 9:a156d3de5647 | 50 | void setBank(uint8_t address); |
hudakz | 9:a156d3de5647 | 51 | uint8_t readReg(uint8_t address); |
hudakz | 9:a156d3de5647 | 52 | void writeReg(uint8_t address, uint8_t data); |
hudakz | 9:a156d3de5647 | 53 | void phyWrite(uint8_t address, uint16_t data); |
hudakz | 9:a156d3de5647 | 54 | uint16_t phyRead(uint8_t address); |
hudakz | 9:a156d3de5647 | 55 | void clkout(uint8_t clk); |
hudakz | 9:a156d3de5647 | 56 | |
hudakz | 9:a156d3de5647 | 57 | friend void enc28j60_mempool_block_move_callback(memaddress, memaddress, memaddress); |
hudakz | 9:a156d3de5647 | 58 | public: |
hudakz | 11:647d53d146f1 | 59 | Enc28j60Eth(PinName mosi, PinName miso, PinName sclk, PinName cs); |
hudakz | 9:a156d3de5647 | 60 | uint8_t getrev(); |
hudakz | 9:a156d3de5647 | 61 | void powerOn(); |
hudakz | 9:a156d3de5647 | 62 | void powerOff(); |
hudakz | 9:a156d3de5647 | 63 | bool linkStatus(); |
hudakz | 9:a156d3de5647 | 64 | |
hudakz | 9:a156d3de5647 | 65 | void init(uint8_t* macaddr); |
hudakz | 9:a156d3de5647 | 66 | memhandle receivePacket(); |
hudakz | 9:a156d3de5647 | 67 | void freePacket(); |
hudakz | 14:7648334eb41b | 68 | size_t blockSize(memhandle handle); |
hudakz | 9:a156d3de5647 | 69 | void sendPacket(memhandle handle); |
hudakz | 9:a156d3de5647 | 70 | uint16_t readPacket(memhandle handle, memaddress position, uint8_t* buffer, uint16_t len); |
hudakz | 9:a156d3de5647 | 71 | uint16_t writePacket(memhandle handle, memaddress position, uint8_t* buffer, uint16_t len); |
hudakz | 9:a156d3de5647 | 72 | void copyPacket(memhandle dest, memaddress dest_pos, memhandle src, memaddress src_pos, uint16_t len); |
hudakz | 9:a156d3de5647 | 73 | uint16_t chksum(uint16_t sum, memhandle handle, memaddress pos, uint16_t len); |
hudakz | 9:a156d3de5647 | 74 | |
hudakz | 9:a156d3de5647 | 75 | uint8_t readOp(uint8_t op, uint8_t address); |
hudakz | 9:a156d3de5647 | 76 | uint8_t readByte(uint16_t addr); |
hudakz | 9:a156d3de5647 | 77 | void writeOp(uint8_t op, uint8_t address, uint8_t data); |
hudakz | 9:a156d3de5647 | 78 | void writeRegPair(uint8_t address, uint16_t data); |
hudakz | 9:a156d3de5647 | 79 | void writeByte(uint16_t addr, uint8_t data); |
hudakz | 9:a156d3de5647 | 80 | }; |
hudakz | 9:a156d3de5647 | 81 | |
hudakz | 9:a156d3de5647 | 82 | #endif |