Contiki 2.5
rtl8019.h
1 #ifndef __RTL8019_H__
2 #define __RTL8019_H__
3 
4 /*****************************************************************************
5 * Module Name: Realtek 8019AS Driver
6 *
7 * Created By: Louis Beaudoin (www.embedded-creations.com)
8 *
9 * Original Release: September 21, 2002
10 *
11 * Module Description:
12 * Provides functions to initialize the Realtek 8019AS, and send and retreive
13 * packets
14 *
15 * September 30, 2002 - Louis Beaudoin
16 * Receive functions modified to handle errors encountered when receiving a
17 * fast data stream. Functions now manually retreive data instead of
18 * using the send packet command. Interface improved by checking for
19 * overruns and data in the buffer internally.
20 * Corrected the overrun function - overrun flag was not reset after overrun
21 * Added support for the Imagecraft Compiler
22 * Added support to communicate with the NIC using general I/O ports
23 *
24 *****************************************************************************/
25 
26 /*#include "delay.h"*/
27 
28 #include "compiler.h"
29 
30 
31 /*****************************************************************************
32 * RTL8019beginPacketSend(unsigned int packetLength)
33 * Args: unsigned int - length of the Ethernet frame (see note)
34 * Created By: Louis Beaudoin
35 * Date: September 21, 2002
36 * Description: Sets up the NIC to send a packet
37 * Notes: The NIC will not send packets less than 60 bytes long (the min
38 * Ethernet frame length. The transmit length is automatically
39 * increased to 60 bytes if packetLength is < 60
40 *****************************************************************************/
41 void RTL8019beginPacketSend(unsigned int packetLength);
42 
43 
44 /*****************************************************************************
45 * RTL8019sendPacketData(unsigned char * localBuffer, unsigned int length)
46 * Args: 1. unsigned char * localBuffer - Pointer to the beginning of
47 * the buffer to load into the NIC
48 * 2. unsigned char length - number of bytes to copy to
49 * the NIC
50 * Created By: Louis Beaudoin
51 * Date: September 21, 2002
52 * Description: Loads length # of bytes from a local buffer to the transmit
53 * packet buffer
54 * Notes: RTL8019beginPacketSend() must be called before sending
55 * any data.
56 * Several calls to RTL8019retreivePacketData() may be made to
57 * copy packet data from different buffers
58 *****************************************************************************/
59 void RTL8019sendPacketData(unsigned char * localBuffer, unsigned int length);
60 
61 
62 /*****************************************************************************
63 * RTL8019endPacketSend()
64 * Created By: Louis Beaudoin
65 * Date: September 21, 2002
66 * Description: Ends a packet send operation and instructs the NIC to transmit
67 * the frame over the network
68 *****************************************************************************/
69 void RTL8019endPacketSend(void);
70 
71 
72 /*****************************************************************************
73 * initRTL8019(void);
74 *
75 * Created By: Louis Beaudoin
76 * Date: September 21, 2002
77 * Description: Sets up the RTL8019 NIC hardware interface, and initializes
78 * the buffers and configuration of the NIC
79 *****************************************************************************/
80 void initRTL8019(void);
81 
82 
83 /*****************************************************************************
84 * processRTL8019Interrupt(void);
85 *
86 * Created By: Louis Beaudoin
87 * Date: September 21, 2002
88 * Description: Reads the NIC's ISR register looking for a receive buffer
89 * overrun - which is then handled.
90 * Notes: The function does not need to be called in response to an
91 * interrupt. The function can be polled and the NIC's INT
92 * line not used. This function should be called before
93 * attempting to retreive a packet from the NIC
94 *****************************************************************************/
95 void processRTL8019Interrupt(void);
96 
97 
98 /*****************************************************************************
99 * unsigned char RTL8019ReceiveEmpty(void);
100 *
101 * Returns: non-zero (true) if buffer is empty, zero if data in buffer
102 * Created By: Louis Beaudoin
103 * Date: September 21, 2002
104 * Description: Compares the BNRY and CURR receive buffer pointers to see if
105 * there is a packet in the receive buffer
106 * ** Removed as of version 0.60.1 **
107 *****************************************************************************/
108 //unsigned char RTL8019ReceiveEmpty(void);
109 
110 
111 /*****************************************************************************
112 * unsigned int RTL8019beginPacketRetreive()
113 * Returns: unsigned int - length of the Ethernet frame (see note)
114 * Created By: Louis Beaudoin
115 * Date: September 21, 2002
116 * Description: Sets up the NIC to retreive a packet
117 * Notes: The size returned is the size of all the data in the Ethernet
118 * frame minus the Ethernet checksum. This may include unused
119 * trailer bytes appended if data is less than the minimum
120 * Ethernet frame length (60 bytes). A size of zero indicates
121 * there are no packets available.
122 * A call to RTL8019beginPacketRetreive() must be followed by a
123 * call to RTL8019endPacketRetreive() regardless if data is
124 * retreived, unless 0 is returned.
125 *****************************************************************************/
126 unsigned int RTL8019beginPacketRetreive(void);
127 
128 
129 /*****************************************************************************
130 * RTL8019retreivePacketData(unsigned char * localBuffer, unsigned int length)
131 * Args: 1. unsigned char * localBuffer - Pointer to the beginning of
132 * the buffer to store the ethernet frame.
133 * 2. unsigned char length - number of bytes to copy to
134 * localBuffer
135 * Created By: Louis Beaudoin
136 * Date: September 21, 2002
137 * Description: Loads length # of bytes from the receive packet buffer to
138 * a local buffer
139 * Notes: RTL8019beginPacketRetreive() must be called before retreiving
140 * any data.
141 * Several calls to RTL8019retreivePacketData() may be made to
142 * copy packet data to different buffers
143 *****************************************************************************/
144 void RTL8019retreivePacketData(unsigned char * localBuffer,
145  unsigned int length);
146 
147 /*****************************************************************************
148 * RTL8019endPacketRetreive()
149 * Created By: Louis Beaudoin
150 * Date: September 21, 2002
151 * Description: Ends a packet retreive operation begun by calling
152 * RTL8019beginPacketRetreive(). The NIC buffer space used by
153 * the retreived packet is freed
154 * Notes: A packet may be removed from the buffer without being read
155 * by calling RTL8019endPacketRetreive() after
156 * RTL8019beginPacketRetreive().
157 *****************************************************************************/
158 void RTL8019endPacketRetreive(void);
159 
160 
161 /*****************************************************************************
162 *
163 * AVR hardware setup
164 *
165 * External SRAM Interface:
166 * The five NIC address lines are taken from A8-A12 (uses the
167 * non-multiplexed address port so no latch is required)
168 *
169 * General I/O Interface:
170 * Two full ports are required for the address and data buses. Two pins
171 * from another port are used to control the read and write lines
172 *
173 * One output pin is required for hard resetting the NIC
174 *
175 *****************************************************************************/
176 
177 // set to 1 to use the External SRAM Interface - 0 for General I/O
178 #define MEMORY_MAPPED_NIC 1
179 
180 #if MEMORY_MAPPED_NIC /*** NIC Interface through External SRAM Interface ****/
181 
182 // NIC is mapped from address 0x8000 - 0x9F00
183 #define MEMORY_MAPPED_RTL8019_OFFSET 0x8300
184 
185 #else /************ NIC Interface through General I/O *******************/
186 
187 // RTL8019 address port
188 #define RTL8019_ADDRESS_PORT PORTC
189 #define RTL8019_ADDRESS_DDR DDRC
190 
191 // RTL8019 data port
192 #define RTL8019_DATA_PORT PORTA
193 #define RTL8019_DATA_DDR DDRA
194 #define RTL8019_DATA_PIN PINA
195 
196 // RTL8019 control port
197 #define RTL8019_CONTROL_PORT PORTD
198 #define RTL8019_CONTROL_DDR DDRD
199 #define RTL8019_CONTROL_READPIN PD7
200 #define RTL8019_CONTROL_WRITEPIN PD6
201 
202 
203 // macros to control the read and write pins
204 #define RTL8019_CLEAR_READ cbi(RTL8019_CONTROL_PORT,\
205  RTL8019_CONTROL_READPIN)
206 #define RTL8019_SET_READ sbi(RTL8019_CONTROL_PORT,\
207  RTL8019_CONTROL_READPIN)
208 #define RTL8019_CLEAR_WRITE cbi(RTL8019_CONTROL_PORT,\
209  RTL8019_CONTROL_WRITEPIN)
210 #define RTL8019_SET_WRITE sbi(RTL8019_CONTROL_PORT,\
211  RTL8019_CONTROL_WRITEPIN)
212 
213 #endif /** NIC Interface **/
214 
215 
216 
217 // RTL RESET - Port B pin 0
218 #define RTL8019_RESET_PORT PORTE
219 #define RTL8019_RESET_DDR DDRE
220 #define RTL8019_RESET_PIN PORTE0
221 
222 
223 
224 
225 
226 /*****************************************************************************
227 *
228 * Ethernet constants
229 *
230 *****************************************************************************/
231 #define ETHERNET_MIN_PACKET_LENGTH 0x3C
232 #define ETHERNET_HEADER_LENGTH 0x0E
233 
234 
235 
236 /*****************************************************************************
237 *
238 * MAC address assigned to the RTL8019
239 *
240 *****************************************************************************/
241 /*#define MYMAC_0 '0'
242 #define MYMAC_1 'F'
243 #define MYMAC_2 'F'
244 #define MYMAC_3 'I'
245 #define MYMAC_4 'C'
246 #define MYMAC_5 'E'*/
247 
248 #define MYMAC_0 0x00
249 #define MYMAC_1 0x06
250 #define MYMAC_2 0x98
251 #define MYMAC_3 0x01
252 #define MYMAC_4 0x02
253 #define MYMAC_5 0x26
254 
255 
256 
257 
258 
259 
260 
261 
262 
263 
264 
265 #endif /* __RTL8019_H__ */