source: firmware/FSC/src/w5100_spi_interface.h@ 13190

Last change on this file since 13190 was 11667, checked in by neise, 13 years ago
File size: 8.9 KB
Line 
1#ifndef __W5100_SPI_INTERFACE_H
2#define __W5100_SPI_INTERFACE_H
3//-----------------------------------------------------------------------------
4
5#include "typedefs.h"
6#include "application.h"
7#include "num_conversion.h"
8
9extern volatile BOOL sock0_connection_established;
10
11
12#define ETH_READ_BUFFER_SIZE 4
13#define ETH_WRITE_BUFFER_SIZE 32
14extern volatile U08 eth_read_buffer[ETH_READ_BUFFER_SIZE];
15extern volatile U08 eth_write_buffer[ETH_WRITE_BUFFER_SIZE];
16extern U08 eth_write_index;
17//-----------------------------------------------------------------------------
18// Port Definitions
19// Pin Definitions
20// W5100 is SPI device 0
21// -- so there is no need to define special pins.
22// -- refer to the device by using the global buffers:
23// volatile U08 spi_read_buffer[SPI_READ_BUFFER_SIZE];
24// volatile U08 spi_write_buffer[SPI_WRITE_BUFFER_SIZE];
25//
26// and the spi function:
27// void spi_transfer(U08 bytes, U08 device)
28//
29// when only sending one byte, you can do:
30// U08 returnvalue;
31// CLR_BIT(SPI_DEVICE_SS_PRT[0], SPI_DEVICE_SS[0]); // Set CS low
32// returnvalue = spi_transfer_byte(0xFF);
33// SET_BIT(SPI_DEVICE_SS_PRT[0], SPI_DEVICE_SS[0]); // Set CS high
34//
35// W5100 supports SPI modes 0 and 3 --> cpol/cpha= 0/0 or 1/1
36
37// we only use socket 0 in this application. So only a few of W5100 adresses are mentioned here
38// W5100 MEM Addresses
39// Common registers:
40#define CM_MR 0x0000 // mode register
41#define CM_GAR0 0x0001 // Gateway adress
42#define CM_GAR1 0x0002 // Gateway adress
43#define CM_GAR2 0x0003 // Gateway adress
44#define CM_GAR3 0x0004 // Gateway adress
45#define CM_SUBR0 0x0005 // Subnetmask adress
46#define CM_SUBR1 0x0006 // Subnetmask adress
47#define CM_SUBR2 0x0007 // Subnetmask adress
48#define CM_SUBR3 0x0008 // Subnetmask adress
49#define CM_SHAR0 0x0009 // Source Hardware adress: MAC
50#define CM_SHAR1 0x000A // Source Hardware adress: MAC
51#define CM_SHAR2 0x000B // Source Hardware adress: MAC
52#define CM_SHAR3 0x000C // Source Hardware adress: MAC
53#define CM_SHAR4 0x000D // Source Hardware adress: MAC
54#define CM_SHAR5 0x000E // Source Hardware adress: MAC
55#define CM_SIPR0 0x000F // Source IP adress
56#define CM_SIPR1 0x0010 // Source IP adress
57#define CM_SIPR2 0x0011 // Source IP adress
58#define CM_SIPR3 0x0012 // Source IP adress
59#define CM_IR 0x0015 // Interrupt
60#define CM_IMR 0x0016 // Source IP adress
61#define CM_RTR0 0x0017 // retry time register
62#define CM_RTR1 0x0018 // retry time register
63#define CM_RCR 0x0019 // Retry count
64#define CM_RMSR 0x001A // RX mem size -- full mem size for sock0 --> value=0x03
65#define CM_TMSR 0x001B // TX mem size -- full mem size for sock0 --> value=0x03
66
67// Socket 0 registers
68#define S0_MR 0x0400 // Socket 0 mode -- for TCP value = 0x01 (set bit 5 for no delay ACK)
69#define S0_CR 0x0401 // socket 0 command -- for commands see below
70#define S0_IR 0x0402 // socket 0 interrupt -- see bit description below
71#define S0_SR 0x0403 // socket 0 status -- see below
72#define S0_PORT0 0x0404 // socket 0 Port MSB -- FSC might get port number 0x1F5C = 8028, since we have only one FSC in cam
73#define S0_PORT1 0x0405 // socket 0 Port LSB -- 0xF5C1= 62913 is okay as well ...
74#define S0_MSSR0 0x0412 // max segment size --
75#define S0_MSSR1 0x0413 // max segment size -- reset value is 0xFFFF; is set to other party value, if in TCP passive mode
76#define S0_TX_FSR0 0x0420 // socket 0 TX free size
77#define S0_TX_FSR1 0x0421 // socket 0 TX free size
78#define S0_TX_RD0 0x0422 // socket 0 TX read pointer -- read only:
79#define S0_TX_RD1 0x0423 // socket 0 TX read pointer
80#define S0_TX_WR0 0x0424 // socket 0 TX write pointer
81#define S0_TX_WR1 0x0425 // socket 0 TX write pointer
82#define S0_RX_RSR0 0x0426 // socket 0 RX received size
83#define S0_RX_RSR1 0x0427 // socket 0 RX received size
84#define S0_RX_RD0 0x0428 // socket 0 RX read pointer
85#define S0_RX_RD1 0x0429 // socket 0 RX read pointer
86
87
88
89// some register values:
90#define MR_TCP 0
91#define MR_NOACKDELAY 5
92
93#define CR_OPEN 0x01
94#define CR_LISTEN 0x02
95#define CR_CONECT 0x04
96#define CR_DISCON 0x08
97#define CR_CLOSE 0x10
98#define CR_SEND 0x20
99#define CR_RECV 0x40
100#define CR_SEND_MAC 0x21
101#define CR_SEND_KEEP 0x22
102
103#define IR_SEND_OK 4
104#define IR_TIMEOUT 3
105#define IR_RECV 2
106#define IR_DISCON 1
107#define IR_CON 0
108
109#define SR_SOCK_CLOSED 0x00
110#define SR_SOCK_INIT 0x13
111#define SR_SOCK_LISTEN 0x14
112#define SR_SOCK_ESTABLISHED 0x17
113#define SR_SOCK_CLOSE_WAIT 0x1C
114#define SR_SOCK_UDP 0x22
115#define SR_SOCK_IPRAW 0x32
116#define SR_SOCK_MACRAW 0x42
117#define SR_SOCK_PPPOE 0x5F
118//changing
119#define SR_SOCK_SYNSENT 0x15
120#define SR_SOCK_SYNRECV 0x16
121#define SR_SOCK_FIN_WAIT 0x18
122#define SR_SOCK_CLOSING 0x1A
123#define SR_SOCK_TIME_WAIT 0x1B
124#define SR_SOCK_LAST_ACK 0x1D
125#define SR_SOCK_ARP0 0x11
126#define SR_SOCK_ARP1 0x21
127#define SR_SOCK_ARP2 0x31
128
129// low level functions
130void w5100_write( U16 addr, U08 data);
131U08 w5100_read( U16 addr);
132
133//------------------------------------------------------------------------------
134// Description of w5100_init() function:
135//------------------------------------------------------------------------------
136//------------------------------------------------------------------------------
137// BASIC SETTINGS:
138//------------------------------------------------------------------------------
139// leave common MR in default state: 0x00
140// leave IMR in default state: 0x00 no interrupt will occur, since #INT line is not routed
141// leave RTR in default state: 0x07D0 --> 200ms
142// leave RCR in default state: 0x08, after 8 re-transmissionsm, the TIMEOUT bit in Sn_IR is set '1'
143//------------------------------------------------------------------------------
144// NETWORK SETTING:
145// set GAR to FSC_GATEWAY_ADDRESS
146//#define FSC_GATEWAY_ADDRESS0 192 // 192.33.96.1
147//#define FSC_GATEWAY_ADDRESS1 33
148//#define FSC_GATEWAY_ADDRESS2 96
149//#define FSC_GATEWAY_ADDRESS3 1
150
151#define FSC_GATEWAY_ADDRESS0 10
152#define FSC_GATEWAY_ADDRESS1 0
153#define FSC_GATEWAY_ADDRESS2 0
154#define FSC_GATEWAY_ADDRESS3 0
155
156
157//#define FSC_GATEWAY_ADDRESS0 192 // 192.168.0.1
158//#define FSC_GATEWAY_ADDRESS1 168
159//#define FSC_GATEWAY_ADDRESS2 0
160//#define FSC_GATEWAY_ADDRESS3 1
161
162
163// set SHAR to FSC_MAC_ADDRESS
164#define FSC_MAC_ADDRESS0 0xFA //FA:C7:0F:AD:22:01
165#define FSC_MAC_ADDRESS1 0xC7
166#define FSC_MAC_ADDRESS2 0x0F
167#define FSC_MAC_ADDRESS3 0xAD
168#define FSC_MAC_ADDRESS4 0x22
169#define FSC_MAC_ADDRESS5 0x01
170
171// set SUBR to FSC_SUBNET_MASK
172#define FSC_SUBNET_MASK0 255 //255.255.255.0
173#define FSC_SUBNET_MASK1 255
174#define FSC_SUBNET_MASK2 255
175#define FSC_SUBNET_MASK3 0
176// set SIPR to FSC_IP_ADDRESS
177
178//#define FSC_IP_ADDRESS0 192 // 192.33.99.247
179//#define FSC_IP_ADDRESS1 33
180//#define FSC_IP_ADDRESS2 99
181//#define FSC_IP_ADDRESS3 247
182
183#define FSC_IP_ADDRESS0 10
184#define FSC_IP_ADDRESS1 0
185#define FSC_IP_ADDRESS2 128
186#define FSC_IP_ADDRESS3 127
187
188
189//#define FSC_IP_ADDRESS0 192 // 192.168.0.2
190//#define FSC_IP_ADDRESS1 168
191//#define FSC_IP_ADDRESS2 0
192//#define FSC_IP_ADDRESS3 2
193
194
195//------------------------------------------------------------------------------
196// MEM SETTINGS:
197// we plan the possible use of 2 Sockets:
198// Socket 0 for command input and requested data output
199// Socket 1 as a Webserver
200//
201// set RMSR=0x0A --> 4k memory for Socket 0 and 1
202#define RX_MEM_BASE 0x6000
203#define S0_RX_BASE 0x6000 // since it is the first socket its base adress is just the RX MEM SPACE BASE
204#define S0_RX_MASK 0x0FFF // this is 4k - 1
205#define S1_RX_BASE 0x7000 // 2nd socket start, right after first socket
206#define S1_RX_MASK 0x0FFF // again: 4k - 1
207// set TMSR=0x0A --> 4k mem for each socket
208#define TX_MEM_BASE 0x4000
209#define S0_TX_BASE 0x4000 // since it is the first socket its base adress is just the RX MEM SPACE BASE
210#define S0_TX_MASK 0x0FFF // this is 4k - 1
211#define S1_TX_BASE 0x5000 // 2nd socket start, right after first socket
212#define S1_TX_MASK 0x0FFF // again: 4k - 1
213//------------------------------------------------------------------------------
214U08 w5100_init();
215
216
217// -- returns: TRUE if socket status is == SR_SOCK_ESTABLISHED
218BOOL w5100_is_established();
219// request socket status info:
220U08 w5100_sock_status();
221
222
223U16 w5100_get_received_size();
224U16 w5100_get_start_address();
225//-----------------------------------------------------------------------------
226#endif //__W5100_SPI_INTERFACE_H
227
228U16 get_S0_TX_FSR();
229U16 get_S0_TX_RD();
230U16 get_S0_TX_WR();
231U16 get_S0_RX_RSR();
232U16 get_S0_RX_RD();
233U08 w5100_get_RX(U08 NumBytes, BOOL send_ACK);
234void w5100_TX(U08 NumBytes, U08 *str);
235U16 w5100_set_TX(U08* string, U16 NumBytes);
236
237extern bool w5100_needs_init;
238extern bool w5100_ready;
239
240
241
242U08 w5100_caretaker();
243void w5100_reset() ;
244
245
246void eth_write_str( U08* str );
247void eth_writeln_str( U08* str );
248void eth_write_lf(void);
Note: See TracBrowser for help on using the repository browser.