rtl8019.h

00001 #ifndef __RTL8019_H__
00002 #define __RTL8019_H__
00003 
00004 /*****************************************************************************
00005 *  Module Name:       Realtek 8019AS Driver
00006 *  
00007 *  Created By:        Louis Beaudoin (www.embedded-creations.com)
00008 *
00009 *  Original Release:  September 21, 2002 
00010 *
00011 *  Module Description:  
00012 *  Provides functions to initialize the Realtek 8019AS, and send and retreive
00013 *  packets
00014 *
00015 *  September 30, 2002 - Louis Beaudoin
00016 *    Receive functions modified to handle errors encountered when receiving a
00017 *      fast data stream.  Functions now manually retreive data instead of
00018 *      using the send packet command.  Interface improved by checking for
00019 *      overruns and data in the buffer internally.
00020 *    Corrected the overrun function - overrun flag was not reset after overrun
00021 *    Added support for the Imagecraft Compiler
00022 *    Added support to communicate with the NIC using general I/O ports
00023 *
00024 *****************************************************************************/
00025 
00026 /*#include "delay.h"*/
00027 
00028 #include "compiler.h"
00029 
00030 
00031 /*****************************************************************************
00032 *  RTL8019beginPacketSend(unsigned int packetLength)
00033 *  Args:        unsigned int - length of the Ethernet frame (see note)
00034 *  Created By:  Louis Beaudoin
00035 *  Date:        September 21, 2002
00036 *  Description: Sets up the NIC to send a packet
00037 *  Notes:       The NIC will not send packets less than 60 bytes long (the min
00038 *                 Ethernet frame length.  The transmit length is automatically
00039 *                 increased to 60 bytes if packetLength is < 60
00040 *****************************************************************************/
00041 void RTL8019beginPacketSend(unsigned int packetLength);
00042 
00043 
00044 /*****************************************************************************
00045 *  RTL8019sendPacketData(unsigned char * localBuffer, unsigned int length)
00046 *  Args:        1. unsigned char * localBuffer - Pointer to the beginning of
00047 *                    the buffer to load into the NIC
00048 *               2. unsigned char length - number of bytes to copy to
00049 *                    the NIC
00050 *  Created By:  Louis Beaudoin
00051 *  Date:        September 21, 2002
00052 *  Description: Loads length # of bytes from a local buffer to the transmit
00053 *                 packet buffer
00054 *  Notes:       RTL8019beginPacketSend() must be called before sending
00055 *                 any data.
00056 *               Several calls to RTL8019retreivePacketData() may be made to 
00057 *                 copy packet data from different buffers
00058 *****************************************************************************/
00059 void RTL8019sendPacketData(unsigned char * localBuffer, unsigned int length);
00060 
00061 
00062 /*****************************************************************************
00063 *  RTL8019endPacketSend()
00064 *  Created By:  Louis Beaudoin
00065 *  Date:        September 21, 2002
00066 *  Description: Ends a packet send operation and instructs the NIC to transmit
00067 *                 the frame over the network
00068 *****************************************************************************/
00069 void RTL8019endPacketSend(void);
00070 
00071 
00072 /*****************************************************************************
00073 *  initRTL8019(void);
00074 *
00075 *  Created By:  Louis Beaudoin
00076 *  Date:        September 21, 2002
00077 *  Description: Sets up the RTL8019 NIC hardware interface, and initializes
00078 *                 the buffers and configuration of the NIC
00079 *****************************************************************************/
00080 void initRTL8019(void);
00081 
00082 
00083 /*****************************************************************************
00084 *  processRTL8019Interrupt(void);
00085 *
00086 *  Created By:  Louis Beaudoin
00087 *  Date:        September 21, 2002
00088 *  Description: Reads the NIC's ISR register looking for a receive buffer
00089 *                 overrun - which is then handled.
00090 *  Notes:       The function does not need to be called in response to an
00091 *                 interrupt.  The function can be polled and the NIC's INT
00092 *                 line not used.  This function should be called before
00093 *                 attempting to retreive a packet from the NIC
00094 *****************************************************************************/
00095 void processRTL8019Interrupt(void);
00096 
00097 
00098 /*****************************************************************************
00099 *  unsigned char RTL8019ReceiveEmpty(void);
00100 *
00101 *  Returns:     non-zero (true) if buffer is empty, zero if data in buffer
00102 *  Created By:  Louis Beaudoin
00103 *  Date:        September 21, 2002
00104 *  Description: Compares the BNRY and CURR receive buffer pointers to see if
00105 *                 there is a packet in the receive buffer
00106 *  ** Removed as of version 0.60.1 **
00107 *****************************************************************************/
00108 //unsigned char RTL8019ReceiveEmpty(void);
00109 
00110 
00111 /*****************************************************************************
00112 *  unsigned int RTL8019beginPacketRetreive()
00113 *  Returns:     unsigned int - length of the Ethernet frame (see note)
00114 *  Created By:  Louis Beaudoin
00115 *  Date:        September 21, 2002
00116 *  Description: Sets up the NIC to retreive a packet
00117 *  Notes:       The size returned is the size of all the data in the Ethernet
00118 *                 frame minus the Ethernet checksum.  This may include unused
00119 *                 trailer bytes appended if data is less than the minimum
00120 *                 Ethernet frame length (60 bytes).  A size of zero indicates
00121 *                 there are no packets available.
00122 *               A call to RTL8019beginPacketRetreive() must be followed by a
00123 *                 call to RTL8019endPacketRetreive() regardless if data is
00124 *                 retreived, unless 0 is returned.
00125 *****************************************************************************/
00126 unsigned int RTL8019beginPacketRetreive(void);
00127 
00128 
00129 /*****************************************************************************
00130 *  RTL8019retreivePacketData(unsigned char * localBuffer, unsigned int length)
00131 *  Args:        1. unsigned char * localBuffer - Pointer to the beginning of
00132 *                    the buffer to store the ethernet frame.
00133 *               2. unsigned char length - number of bytes to copy to
00134 *                    localBuffer
00135 *  Created By:  Louis Beaudoin
00136 *  Date:        September 21, 2002
00137 *  Description: Loads length # of bytes from the receive packet buffer to
00138 *                 a local buffer
00139 *  Notes:       RTL8019beginPacketRetreive() must be called before retreiving
00140 *                 any data.
00141 *               Several calls to RTL8019retreivePacketData() may be made to 
00142 *                 copy packet data to different buffers
00143 *****************************************************************************/
00144 void RTL8019retreivePacketData(unsigned char * localBuffer,
00145                                unsigned int length);
00146 
00147 /*****************************************************************************
00148 *  RTL8019endPacketRetreive()
00149 *  Created By:  Louis Beaudoin
00150 *  Date:        September 21, 2002
00151 *  Description: Ends a packet retreive operation begun by calling
00152 *                 RTL8019beginPacketRetreive().  The NIC buffer space used by
00153 *                 the retreived packet is freed
00154 *  Notes:       A packet may be removed from the buffer without being read
00155 *                 by calling RTL8019endPacketRetreive() after
00156 *                 RTL8019beginPacketRetreive().
00157 *****************************************************************************/
00158 void RTL8019endPacketRetreive(void);
00159 
00160 
00161 /*****************************************************************************
00162 *
00163 *  AVR hardware setup
00164 *
00165 *    External SRAM Interface:
00166 *      The five NIC address lines are taken from A8-A12 (uses the
00167 *      non-multiplexed address port so no latch is required)
00168 *
00169 *    General I/O Interface:
00170 *      Two full ports are required for the address and data buses.  Two pins
00171 *        from another port are used to control the read and write lines
00172 *
00173 *    One output pin is required for hard resetting the NIC
00174 *
00175 *****************************************************************************/
00176 
00177 // set to 1 to use the External SRAM Interface - 0 for General I/O
00178 #define MEMORY_MAPPED_NIC 1
00179 
00180 #if MEMORY_MAPPED_NIC /*** NIC Interface through External SRAM Interface ****/
00181 
00182 // NIC is mapped from address 0x8000 - 0x9F00
00183 #define MEMORY_MAPPED_RTL8019_OFFSET 0x8300
00184 
00185 #else /************ NIC Interface through General I/O *******************/
00186 
00187 // RTL8019 address port
00188 #define RTL8019_ADDRESS_PORT        PORTC
00189 #define RTL8019_ADDRESS_DDR         DDRC
00190 
00191 // RTL8019 data port
00192 #define RTL8019_DATA_PORT           PORTA
00193 #define RTL8019_DATA_DDR            DDRA
00194 #define RTL8019_DATA_PIN            PINA
00195 
00196 // RTL8019 control port
00197 #define RTL8019_CONTROL_PORT        PORTD
00198 #define RTL8019_CONTROL_DDR         DDRD
00199 #define RTL8019_CONTROL_READPIN     PD7
00200 #define RTL8019_CONTROL_WRITEPIN    PD6
00201 
00202 
00203 // macros to control the read and write pins
00204 #define RTL8019_CLEAR_READ   cbi(RTL8019_CONTROL_PORT,\
00205                                  RTL8019_CONTROL_READPIN)
00206 #define RTL8019_SET_READ     sbi(RTL8019_CONTROL_PORT,\
00207                                  RTL8019_CONTROL_READPIN) 
00208 #define RTL8019_CLEAR_WRITE  cbi(RTL8019_CONTROL_PORT,\
00209                                  RTL8019_CONTROL_WRITEPIN)
00210 #define RTL8019_SET_WRITE    sbi(RTL8019_CONTROL_PORT,\
00211                                  RTL8019_CONTROL_WRITEPIN)
00212 
00213 #endif /** NIC Interface **/
00214 
00215 
00216 
00217 // RTL RESET - Port B pin 0
00218 #define RTL8019_RESET_PORT      PORTE
00219 #define RTL8019_RESET_DDR       DDRE
00220 #define RTL8019_RESET_PIN       PORTE0
00221 
00222 
00223 
00224 
00225 
00226 /*****************************************************************************
00227 *
00228 *  Ethernet constants
00229 *
00230 *****************************************************************************/
00231 #define ETHERNET_MIN_PACKET_LENGTH      0x3C
00232 #define ETHERNET_HEADER_LENGTH          0x0E
00233 
00234 
00235 
00236 /*****************************************************************************
00237 *
00238 * MAC address assigned to the RTL8019
00239 *
00240 *****************************************************************************/
00241 /*#define MYMAC_0 '0'
00242 #define MYMAC_1 'F'
00243 #define MYMAC_2 'F'
00244 #define MYMAC_3 'I'
00245 #define MYMAC_4 'C'
00246 #define MYMAC_5 'E'*/
00247 
00248 #define MYMAC_0 0x00
00249 #define MYMAC_1 0x06
00250 #define MYMAC_2 0x98
00251 #define MYMAC_3 0x01
00252 #define MYMAC_4 0x02
00253 #define MYMAC_5 0x26
00254 
00255 
00256 
00257 
00258 
00259 
00260 
00261 
00262 
00263 
00264 
00265 #endif /* __RTL8019_H__ */

Generated on Mon Apr 11 14:23:36 2011 for Contiki 2.5 by  doxygen 1.6.1