PICSimLab - Programmable IC Simulator Laboratory 0.9.2
PICSimLab - API
Loading...
Searching...
No Matches
eth_w5500.h
1/* ########################################################################
2
3 PICSimLab - Programmable IC Simulator Laboratory
4
5 ########################################################################
6
7 Copyright (c) : 2010-2024 Luis Claudio GambĂ´a Lopes <lcgamboa@yahoo.com>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 For e-mail suggestions : lcgamboa@yahoo.com
24 ######################################################################## */
25
26#ifndef ETH_W5500
27#define ETH_W5500
28
29#include "bitbang_spi.h"
30
31// BSB
32#define B_COMMON 0x00 // 00000 Selects Common Register.
33#define B_SCK0RG 0x01 // 00001 Selects Socket 0 Register
34#define B_SCK0TX 0x02 // 00010 Selects Socket 0 TX Buffer
35#define B_SCK0RX 0x03 // 00011 Selects Socket 0 RX Buffer
36// #define B_RESERV 0x04 //00100 Reserved
37#define B_SCK1RG 0x05 // 00101 Selects Socket 1 Register
38#define B_SCK1TX 0x06 // 00110 Selects Socket 1 TX Buffer
39#define B_SCK1RX 0x07 // 00111 Selects Socket 1 RX Buffer
40// #define B_RESERV 0x08 //01000 Reserved
41#define B_SCK2RG 0x09 // 01001 Selects Socket 2 Register
42#define B_SCK2TX 0x0A // 01010 Selects Socket 2 TX Buffer
43#define B_SCK2RX 0x0B // 01011 Selects Socket 2 RX Buffer
44// #define B_RESERV 0x0C //01100 Reserved
45#define B_SCK3RG 0x0D // 01101 Selects Socket 3 Register
46#define B_SCK3TX 0x0E // 01110 Selects Socket 3 TX Buffer
47#define B_SCK3RX 0x0F // 01111 Selects Socket 3 RX Buffer
48// #define B_RESERV 0x10 //10000 Reserved
49#define B_SCK4RG 0x11 // 10001 Selects Socket 4 Register
50#define B_SCK4TX 0x12 // 10010 Selects Socket 4 TX Buffer
51#define B_SCK4RX 0x13 // 10011 Selects Socket 4 RX Buffer
52// #define B_RESERV 0x14 //10100 Reserved
53#define B_SCK5RG 0x15 // 10101 Selects Socket 5 Register
54#define B_SCK5TX 0x16 // 10110 Selects Socket 5 TX Buffer
55#define B_SCK5RX 0x17 // 10111 Selects Socket 5 RX Buffer
56// #define B_RESERV 0x18 //11000 Reserved
57#define B_SCK6RG 0x19 // 11001 Selects Socket 6 Register
58#define B_SCK6TX 0x1A // 11010 Selects Socket 6 TX Buffer
59#define B_SCK6RX 0x1B // 11011 Selects Socket 6 RX Buffer
60#define B_RESERV 0x1C // 11100 Reserved
61#define B_SCK7RG 0x1D // 11101 Selects Socket 7 Register
62#define B_SCK7TX 0x1E // 11110 Selects Socket 7 TX Buffer
63#define B_SCK7RX 0x1F // 11111 Selects Socket 7 RX Buffer
64
65// Common Register
66#define CR_MR 0x0000 //(MR) Mode
67#define CR_GAR0 0x0001 //(GAR0) Gateway Address
68#define CR_GAR1 0x0002 //(GAR1)
69#define CR_GAR2 0x0003 //(GAR2)
70#define CR_GAR3 0x0004 //(GAR3)
71#define CR_SUBR0 0x0005 //(SUBR0) Subnet Mask Address
72#define CR_SUBR1 0x0006 //(SUBR1)
73#define CR_SUBR2 0x0007 //(SUBR2)
74#define CR_SUBR3 0x0008 //(SUBR3)
75#define CR_SHAR0 0x0009 //(SHAR0) Source Hardware Address
76#define CR_SHAR1 0x000A //(SHAR1)
77#define CR_SHAR2 0x000B //(SHAR2)
78#define CR_SHAR3 0x000C //(SHAR3)
79#define CR_SHAR4 0x000D //(SHAR4)
80#define CR_SHAR5 0x000E //(SHAR5)
81#define CR_SIPR0 0x000F //(SIPR0) Source IP Address
82#define CR_SIPR1 0x0010 //(SIPR1)
83#define CR_SIPR2 0x0011 //(SIPR2)
84#define CR_SIPR3 0x0012 //(SIPR3)
85#define CR_INTLEVEL0 0x0013 //(INTLEVEL0) Interrupt Low Level Timer
86#define CR_INTLEVEL1 0x0014 //(INTLEVEL1)
87#define CR_IR 0x0015 //(IR) Interrupt
88#define CR_IMR 0x0016 //(IMR) Interrupt Mask
89#define CR_SIR 0x0017 //(SIR) Socket Interrupt
90#define CR_SIMR 0x0018 //(SIMR) Socket Interrupt Mask
91#define CR_RTR0 0x0019 //(RTR0) Retry Time
92#define CR_RTR1 0x001A //(RTR1)
93#define CR_RCR 0x001B //(RCR) Retry Count
94#define CR_PTIMER 0x001C //(PTIMER) PPP LCP Request Timer
95#define CR_PMAGIC 0x001D //(PMAGIC) PPP LCP Magic number
96#define CR_PHAR0 0x001E //(PHAR0) PPP Destination MAC Address
97#define CR_PHAR1 0x001F //(PHAR1)
98#define CR_PHAR2 0x0020 //(PHAR2)
99#define CR_PHAR3 0x0021 //(PHAR3)
100#define CR_PHAR4 0x0022 //(PHAR4)
101#define CR_PHAR5 0x0023 //(PHAR5)
102#define CR_PSID0 0x0024 //(PSID0) PPP Session Identification
103#define CR_PSID1 0x0025 //(PSID1)
104#define CR_PMRU0 0x0026 //(PMRU0) PPP Maximum Segment Size
105#define CR_PMRU1 0x0027 //(PMRU1)
106#define CR_UIPR0 0x0028 //(UIPR0) Unreachable IP address
107#define CR_UIPR1 0x0029 //(UIPR1)
108#define CR_UIPR2 0x002A //(UIPR2)
109#define CR_UIPR3 0x002B //(UIPR3)
110#define CR_UPORTR0 0x002C //(UPORTR0) Unreachable Port
111#define CR_UPORTR1 0x002D //(UPORTR1)
112#define CR_PHYCFGR 0x002E //(PHYCFGR) PHY Configuration
113// 0x002F ~ Reserved
114// 0x0038 ~
115#define CR_VERSIONR 0x0039 //(VERSIONR) Chip version
116
117// Socket Register Block
118#define Sn_MR 0x0000 //(Sn_MR) Socket n Mode
119#define Sn_CR 0x0001 //(Sn_CR) Socket n Command (Sn_CR)
120#define Sn_IR 0x0002 //(Sn_IR) Socket n Interrupt
121#define Sn_SR 0x0003 //(Sn_SR) Socket n Status
122#define Sn_PORT0 0x0004 //(Sn_PORT0) Socket n Source Port
123#define Sn_PORT1 0x0005 //(Sn_PORT1)
124#define Sn_DHAR0 0x0006 //(Sn_DHAR0) Socket n Destination Hardware Address
125#define Sn_DHAR1 0x0007 //(Sn_DHAR1)
126#define Sn_DHAR2 0x0008 //(Sn_DHAR2)
127#define Sn_DHAR3 0x0009 //(Sn_DHAR3)
128#define Sn_DHAR4 0x000A //(Sn_DHAR4)
129#define Sn_DHAR5 0x000B //(Sn_DHAR5)
130#define Sn_DIPR0 0x000C //(Sn_DIPR0) Socket n Destination IP Address
131#define Sn_DIPR1 0x000D //(Sn_DIPR1)
132#define Sn_DIPR2 0x000E //(Sn_DIPR2)
133#define Sn_DIPR3 0x000F //(Sn_DIPR3)
134#define Sn_DPORT0 0x0010 //(Sn_DPORT0) Socket n Destination Port
135#define Sn_DPORT1 0x0011 //(Sn_DPORT1)
136#define Sn_MSSR0 0x0012 //(Sn_MSSR0) Socket n Maximum Segment Size
137#define Sn_MSSR1 0x0013 //(Sn_MSSR1)
138// 0x0014 Reserved
139#define Sn_TOS 0x0015 //(Sn_TOS) Socket n IP TOS
140#define Sn_TTL 0x0016 //(Sn_TTL) Socket n IP TTL
141// 0x0017 ~ Reserved
142// 0x001D
143#define Sn_RXBUF_SIZE 0x001E //(Sn_RXBUF_SIZE) Socket n Receive Buffer Size
144#define Sn_TXBUF_SIZE 0x001F //(Sn_TXBUF_SIZE) Socket n Transmit Buffer Size
145#define Sn_TX_FSR0 0x0020 //(Sn_TX_FSR0) Socket n TX Free Size
146#define Sn_TX_FSR1 0x0021 //(Sn_TX_FSR1)
147#define Sn_TX_RD0 0x0022 //(Sn_TX_RD0) Socket n TX Read Pointer
148#define Sn_TX_RD1 0x0023 //(Sn_TX_RD1)
149#define Sn_TX_WR0 0x0024 //(Sn_TX_WR0) Socket n TX WritePointer
150#define Sn_TX_WR1 0x0025 //(Sn_TX_WR1)
151#define Sn_RX_RSR0 0x0026 //(Sn_RX_RSR0) Socket n RX Received Size
152#define Sn_RX_RSR1 0x0027 //(Sn_RX_RSR1)
153#define Sn_RX_RD0 0x0028 //(Sn_RX_RD0) Socket n RX Read Pointer
154#define Sn_RX_RD1 0x0029 //(Sn_RX_RD1)
155#define Sn_RX_WR0 0x002A //(Sn_RX_WR0) Socket n RX Write Pointer
156#define Sn_RX_WR1 0x002B //(Sn_RX_WR1)
157#define Sn_IMR 0x002C //(Sn_IMR) Socket n Interrupt Mask
158#define Sn_FRAG0 0x002D //(Sn_FRAG0) Socket n Fragment Offset in IP header
159#define Sn_FRAG1 0x002E //(Sn_FRAG1)
160#define Sn_KPALVTR 0x002F //(Sn_KPALVTR) Keep alive timer
161// 0x0030 ~ Reserved
162// 0xFFFF
163
164#define Sn_MR_CLOSE 0x00
165#define Sn_MR_TCP 0x01
166#define Sn_MR_UDP 0x02
167#define S0_MR_MACRAW 0x04
168
169#define OPEN 0x01
170#define LISTEN 0x02
171#define CONNECT 0x04
172#define DISCON 0x08
173#define CLOSE 0x10
174#define SEND 0x20
175#define SEND_MAC 0x21
176#define SEND_KEEP 0x22
177#define RECV 0x40
178
179#define SOCK_CLOSED 0x00
180#define SOCK_INIT 0x13
181#define SOCK_LISTEN 0x14
182#define SOCK_SYNSENT 0x15
183#define SOCK_ESTABLISHED 0x17
184#define SOCK_CLOSE_WAIT 0x1C
185#define SOCK_UDP 0x22
186#define SOCK_MACRAW 0x42
187
188#define ER_BIND 1
189#define ER_SEND 2
190#define ER_RECV 3
191#define ER_LIST 4
192#define ER_REUSE 5
193#define ER_CONN 6
194#define ER_SHUT 7
195
196typedef struct {
197 unsigned char link;
198 unsigned char active;
199 bitbang_spi_t bb_spi;
200 unsigned short addr;
201 unsigned char control;
202 unsigned char Common[0x40];
203 unsigned char Socket[8][0x30];
204 int sockfd[8];
205 int listenfd[8];
206 unsigned short listenfd_port[8];
207 unsigned char listenfd_map[8];
208 unsigned char RX_Mem[0x4000];
209 unsigned char TX_Mem[0x4000];
210 unsigned short RX_ptr[8];
211 unsigned short TX_ptr[8];
212 unsigned short RX_size[8];
213 unsigned short TX_size[8];
214 unsigned short RX_mask[8];
215 unsigned short TX_mask[8];
216 unsigned char status[8];
217 unsigned short bindp[8];
219
220void eth_w5500_rst(eth_w5500_t* eth);
221void eth_w5500_init(eth_w5500_t* eth, unsigned char linkon = 1);
222void eth_w5500_process(eth_w5500_t* eth);
223void eth_w5500_end(eth_w5500_t* eth);
224void eth_w5500_set_link(eth_w5500_t* eth, unsigned char on);
225unsigned char eth_w5500_get_leds(eth_w5500_t* eth);
226
227unsigned short eth_w5500_io(eth_w5500_t* eth, unsigned char mosi, unsigned char sclk, unsigned char scs,
228 unsigned char rst);
229
230#endif // ETH_W5500
Definition bitbang_spi.h:35
Definition eth_w5500.h:196