00001 00002 00003 00031 /********************************************************************* 00032 * Software License Agreement 00033 * 00034 * Copyright (C) 2002-2008 Microchip Technology Inc. All rights 00035 * reserved. 00036 * 00037 * Microchip licenses to you the right to use, modify, copy, and 00038 * distribute: 00039 * (i) the Software when embedded on a Microchip microcontroller or 00040 * digital signal controller product ("Device") which is 00041 * integrated into Licensee's product; or 00042 * (ii) ONLY the Software driver source files ENC28J60.c and 00043 * ENC28J60.h ported to a non-Microchip device used in 00044 * conjunction with a Microchip ethernet controller for the 00045 * sole purpose of interfacing with the ethernet controller. 00046 * 00047 * You should refer to the license agreement accompanying this 00048 * Software for additional information regarding your rights and 00049 * obligations. 00050 * 00051 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT 00052 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT 00053 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A 00054 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL 00055 * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR 00056 * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF 00057 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS 00058 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE 00059 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER 00060 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT 00061 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE. 00062 * 00063 * 00064 * Author Date Comment 00065 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00066 * Nilesh Rajbharti 4/27/01 Original (Rev 1.0) 00067 * Nilesh Rajbharti 11/27/01 Added SLIP 00068 * Nilesh Rajbharti 2/9/02 Cleanup 00069 * Nilesh Rajbharti 5/22/02 Rev 2.0 (See version.log for detail) 00070 * Howard Schlunder 6/28/04 Added ENC28J60 specific features 00071 * Howard Schlunder 11/29/04 Added Get/SetLEDConfig macros 00072 ********************************************************************/ 00073 #ifndef __MAC_H 00074 #define __MAC_H 00075 00076 00077 // MODIFIX: Removed support for ENC28J60 00078 #include "ETH97J60.h" 00079 00080 // MODIFIX: Added MAC address which is located in flash (bootloader). 00081 #ifdef __ETH97J60_C 00082 00083 #ifdef __DEBUG 00084 ROM BYTE cau8Mac[6] = {0x00,0x50,0xc2,0x7c,0x40,0x00}; 00085 ROM BYTE * pu8MAC = (ROM BYTE *)cau8Mac; 00086 #else 00087 ROM BYTE * pu8MAC = (ROM BYTE *)0x1FBFAul; 00088 #endif 00089 #else 00090 extern ROM BYTE * pu8MAC; 00091 #endif 00092 00093 00094 #define MAC_TX_BUFFER_SIZE (1500ul) 00095 00096 // A generic structure representing the Ethernet header starting all Ethernet 00097 // frames 00098 typedef struct __attribute__((aligned(2), packed)) 00099 { 00100 MAC_ADDR DestMACAddr; 00101 MAC_ADDR SourceMACAddr; 00102 WORD_VAL Type; 00103 } ETHER_HEADER; 00104 00105 00106 #define MAC_IP (0x00u) 00107 #define MAC_ARP (0x06u) 00108 #define MAC_UNKNOWN (0xFFu) 00109 00110 /* 00111 * Microchip Ethernet controller specific MAC items 00112 */ 00113 #if !defined(STACK_USE_HTTP2_SERVER) 00114 #define RESERVED_HTTP_MEMORY 0ul 00115 #endif 00116 00117 #if !defined(STACK_USE_SSL) 00118 #define RESERVED_SSL_MEMORY 0ul 00119 #endif 00120 00121 // MAC RAM definitions 00122 #define RAMSIZE 8192ul 00123 #define TXSTART (RAMSIZE - (1ul+1514ul+7ul) - TCP_ETH_RAM_SIZE - RESERVED_HTTP_MEMORY - RESERVED_SSL_MEMORY) 00124 #define RXSTART (0ul) // Should be an even memory address; must be 0 for errata 00125 #define RXSTOP ((TXSTART-2ul) | 0x0001ul) // Odd for errata workaround 00126 #define RXSIZE (RXSTOP-RXSTART+1ul) 00127 00128 #define BASE_TX_ADDR (TXSTART + 1ul) 00129 #define BASE_TCB_ADDR (BASE_TX_ADDR + (1514ul+7ul)) 00130 #define BASE_HTTPB_ADDR (BASE_TCB_ADDR + TCP_ETH_RAM_SIZE) 00131 #define BASE_SSLB_ADDR (BASE_HTTPB_ADDR + RESERVED_HTTP_MEMORY) 00132 00133 #if (RXSIZE < 1400) || (RXSIZE > RAMSIZE) 00134 #error Warning, Ethernet RX buffer is tiny. Reduce TCP socket count, the size of each TCP socket, or move sockets to a different RAM 00135 #endif 00136 00137 WORD MACCalcRxChecksum(WORD offset, WORD len); 00138 WORD CalcIPBufferChecksum(WORD len); 00139 00140 void MACPowerDown(void); 00141 void MACPowerUp(void); 00142 void WritePHYReg(BYTE Register, WORD Data); 00143 PHYREG ReadPHYReg(BYTE Register); 00144 void SetRXHashTableEntry(MAC_ADDR DestMACAddr); 00145 00146 // MODIFIX: Removed ENC28J60 specific function prototypes SetCLKOUT and 00147 // GetCLKOUT. 00148 00149 /****************************************************************************** 00150 * Macro: void SetLEDConfig(WORD NewConfig) 00151 * 00152 * PreCondition: SPI bus must be initialized (done in MACInit()). 00153 * 00154 * Input: NewConfig - xxx0: Pulse stretching disabled 00155 * xxx2: Pulse stretch to 40ms (default) 00156 * xxx6: Pulse stretch to 73ms 00157 * xxxA: Pulse stretch to 139ms 00158 * 00159 * xx1x: LEDB - TX 00160 * xx2x: LEDB - RX (default) 00161 * xx3x: LEDB - collisions 00162 * xx4x: LEDB - link 00163 * xx5x: LEDB - duplex 00164 * xx7x: LEDB - TX and RX 00165 * xx8x: LEDB - on 00166 * xx9x: LEDB - off 00167 * xxAx: LEDB - blink fast 00168 * xxBx: LEDB - blink slow 00169 * xxCx: LEDB - link and RX 00170 * xxDx: LEDB - link and TX and RX 00171 * xxEx: LEDB - duplex and collisions 00172 * 00173 * x1xx: LEDA - TX 00174 * x2xx: LEDA - RX 00175 * x3xx: LEDA - collisions 00176 * x4xx: LEDA - link (default) 00177 * x5xx: LEDA - duplex 00178 * x7xx: LEDA - TX and RX 00179 * x8xx: LEDA - on 00180 * x9xx: LEDA - off 00181 * xAxx: LEDA - blink fast 00182 * xBxx: LEDA - blink slow 00183 * xCxx: LEDA - link and RX 00184 * xDxx: LEDA - link and TX and RX 00185 * xExx: LEDA - duplex and collisions 00186 * 00187 * Output: None 00188 * 00189 * Side Effects: None 00190 * 00191 * Overview: Writes the value of NewConfig into the PHLCON PHY register. 00192 * The LED pins will beginning outputting the new 00193 * configuration immediately. 00194 * 00195 * Note: 00196 *****************************************************************************/ 00197 #define SetLEDConfig(NewConfig) WritePHYReg(PHLCON, NewConfig) 00198 00199 00200 /****************************************************************************** 00201 * Macro: WORD GetLEDConfig(void) 00202 * 00203 * PreCondition: SPI bus must be initialized (done in MACInit()). 00204 * 00205 * Input: None 00206 * 00207 * Output: WORD - xxx0: Pulse stretching disabled 00208 * xxx2: Pulse stretch to 40ms (default) 00209 * xxx6: Pulse stretch to 73ms 00210 * xxxA: Pulse stretch to 139ms 00211 * 00212 * xx1x: LEDB - TX 00213 * xx2x: LEDB - RX (default) 00214 * xx3x: LEDB - collisions 00215 * xx4x: LEDB - link 00216 * xx5x: LEDB - duplex 00217 * xx7x: LEDB - TX and RX 00218 * xx8x: LEDB - on 00219 * xx9x: LEDB - off 00220 * xxAx: LEDB - blink fast 00221 * xxBx: LEDB - blink slow 00222 * xxCx: LEDB - link and RX 00223 * xxDx: LEDB - link and TX and RX 00224 * xxEx: LEDB - duplex and collisions 00225 * 00226 * x1xx: LEDA - TX 00227 * x2xx: LEDA - RX 00228 * x3xx: LEDA - collisions 00229 * x4xx: LEDA - link (default) 00230 * x5xx: LEDA - duplex 00231 * x7xx: LEDA - TX and RX 00232 * x8xx: LEDA - on 00233 * x9xx: LEDA - off 00234 * xAxx: LEDA - blink fast 00235 * xBxx: LEDA - blink slow 00236 * xCxx: LEDA - link and RX 00237 * xDxx: LEDA - link and TX and RX 00238 * xExx: LEDA - duplex and collisions 00239 * 00240 * Side Effects: None 00241 * 00242 * Overview: Returns the current value of the PHLCON register. 00243 * 00244 * Note: None 00245 *****************************************************************************/ 00246 #define GetLEDConfig() ReadPHYReg(PHLCON).Val 00247 00248 00249 void MACInit(void); 00250 00251 00253 00269 BOOL MACIsLinked(void); 00270 00271 BOOL MACGetHeader(MAC_ADDR *remote, BYTE* type); 00272 void MACSetReadPtrInRx(WORD offset); 00273 WORD MACSetWritePtr(WORD address); 00274 WORD MACSetReadPtr(WORD address); 00275 BYTE MACGet(void); 00276 WORD MACGetArray(BYTE *val, WORD len); 00277 void MACDiscardRx(void); 00278 WORD MACGetFreeRxSize(void); 00279 void MACMemCopyAsync(WORD destAddr, WORD sourceAddr, WORD len); 00280 BOOL MACIsMemCopyDone(void); 00281 00282 void MACPutHeader(MAC_ADDR *remote, BYTE type, WORD dataLen); 00283 BOOL MACIsTxReady(void); 00284 void MACPut(BYTE val); 00285 void MACPutArray(BYTE *val, WORD len); 00286 void MACFlush(void); 00287 00288 // ROM function variants for PIC18 00289 #if defined(__18CXX) 00290 void MACPutROMArray(ROM BYTE *val, WORD len); 00291 #else 00292 #define MACPutROMArray(a,b) MACPutArray((BYTE*)a,b) 00293 #endif 00294 00295 00296 WORD_VAL u16MACGetCurrentReadPtrPos(void); 00297 void MACSetCurrentReadPtrPos(WORD_VAL u16Pos); 00298 00299 #endif
1.5.5