@ -28,6 +28,8 @@
# include "programStrings.h"
// include configuration
# include "nic.h"
# include "net.h"
# include "enc28j60conf.h"
# include "enc28j60.h"
@ -88,10 +90,12 @@ void nicSetMacAddress(uint8_t* macaddr)
enc28j60Write ( MAADR0 , * macaddr + + ) ;
}
# ifdef NET_DEBUG || NIC_DEBUG
void nicRegDump ( void )
{
enc28j60RegDump ( ) ;
}
# endif
void nicHardReset ( void )
{
@ -333,33 +337,33 @@ void enc28j60Init(void)
delay ( 1 ) ;
# ifdef DEBUG_ENC_INIT
SPrintln _P( PSTR ( " SPI Enabled " ) ) ;
SPrintln ( " SPI Enabled " ) ;
# endif
// Reboot the ENC28J60
enc28j60Reboot ( ) ;
# ifdef DEBUG_ENC_INIT
SPrintln _P( PSTR ( " PHY reboot done " ) ) ;
SPrintln ( " PHY reboot done " ) ;
# endif
# ifdef ENC28J60_LAMPS_MODE
SPrintln _P( PSTR ( " Custom lamps " ) ) ;
SPrintln ( " Custom lamps " ) ;
enc28j60PhyWrite ( PHLCON , ENC28J60_LAMPS_MODE ) ;
# else
// Errata #9 correction
if ( enc28j60Read ( MACON3 ) & MACON3_FULDPX )
{
SPrintln _P( PSTR ( " Full duplex lamps " ) ) ;
SPrintln ( " Full duplex lamps " ) ;
enc28j60PhyWrite ( PHLCON , PHLCON_DEFAULT ) ;
} else {
SPrintln _P( PSTR ( " Half duplex lamps " ) ) ;
SPrintln ( " Half duplex lamps " ) ;
enc28j60PhyWrite ( PHLCON , PHLCON_DEFAULT_HD ) ;
}
# endif
# ifdef DEBUG_ENC_INIT
SPrintln _P( PSTR ( " Lamps set " ) ) ;
SPrintln ( " Lamps set " ) ;
# endif
// do bank 0 stuff
// initialize receive buffer
@ -443,7 +447,7 @@ void enc28j60Init(void)
enc28j60WriteOp ( ENC28J60_BIT_FIELD_SET , ECON1 , ECON1_RXEN ) ;
# ifdef DEBUG_ENC_INIT
SPrintln _P( PSTR ( " Banks robbed " ) ) ;
SPrintln ( " Banks robbed " ) ;
# endif
/*
enc28j60PhyWrite ( PHLCON , 0x0AA2 ) ;
@ -540,11 +544,19 @@ void enc28j60PacketSend(uint16_t len, uint8_t* packet)
// send the contents of the transmit buffer onto the network
enc28j60WriteOp ( ENC28J60_BIT_FIELD_SET , ECON1 , ECON1_TXRTS ) ;
// From errata Rev B.4
// if( (enc28j60Read(EIR) & EIR_TXERIF) ){
// enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_TXRTS);
// }
}
# ifndef enc28j60ReadNextPtr
# define enc28j60ReadNextPtr(ptr) do { ptr = enc28j60ReadOp(ENC28J60_READ_BUF_MEM, 0); \
ptr | = enc28j60ReadOp ( ENC28J60_READ_BUF_MEM , 0 ) < < 8 ; \
} while ( 0 )
# endif
uint16_t enc28j60PacketReceive ( uint16_t maxlen , uint8_t * packet )
{
uint16_t rxstat ;
@ -564,16 +576,13 @@ uint16_t enc28j60PacketReceive(uint16_t maxlen, uint8_t* packet)
enc28j60Write ( ERDPTH , ( NextPacketPtr ) > > 8 ) ;
// read the next packet pointer
NextPacketPtr = enc28j60ReadOp ( ENC28J60_READ_BUF_MEM , 0 ) ;
NextPacketPtr | = enc28j60ReadOp ( ENC28J60_READ_BUF_MEM , 0 ) < < 8 ;
enc28j60ReadNextPtr ( NextPacketPtr ) ;
// read the packet length
len = enc28j60ReadOp ( ENC28J60_READ_BUF_MEM , 0 ) ;
len | = enc28j60ReadOp ( ENC28J60_READ_BUF_MEM , 0 ) < < 8 ;
enc28j60ReadNextPtr ( len ) ;
// read the receive status
rxstat = enc28j60ReadOp ( ENC28J60_READ_BUF_MEM , 0 ) ;
rxstat | = enc28j60ReadOp ( ENC28J60_READ_BUF_MEM , 0 ) < < 8 ;
enc28j60ReadNextPtr ( rxstat ) ;
// limit retrieve length
// (we reduce the MAC-reported length by 4 to remove the CRC)
@ -619,95 +628,98 @@ void enc28j60ReceiveOverflowRecover(void)
// recovery completed
}
# ifdef NET_DEBUG || NIC_DEBUG
# define SPrint_D(str) SPrint(str); delayMicroseconds(100);
void enc28j60RegDump ( void )
{
// unsigned char macaddr[6];
// result = ax88796Read(TR);
// SPrint _P(PSTR ("Media State: ") );
// SPrint ("Media State: ");
// if(!(result & AUTOD))
// SPrint _P(PSTR ("Autonegotiation\r\n") );
// SPrint ("Autonegotiation\r\n");
// else if(result & RST_B)
// SPrint _P(PSTR ("PHY in Reset \r\n") );
// SPrint ("PHY in Reset \r\n");
// else if(!(result & RST_10B))
// SPrint _P(PSTR ("10BASE-T \r\n") );
// SPrint ("10BASE-T \r\n");
// else if(!(result & RST_TXB))
// SPrint_P(PSTR("100BASE-T \r\n"));
SPrint_P ( PSTR ( " RevID: " ) ) ; delay ( 5 ) ;
Serial . println ( enc28j60Read ( EREVID ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " Cntrl: ECON1 ECON2 ESTAT EIR EIE \r \n " ) ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( ECON1 ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( ECON2 ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( ESTAT ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( EIR ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( EIE ) , HEX ) ; delay ( 5 ) ;
Serial . println ( ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " MAC : MACON1 MACON2 MACON3 MACON4 MAC-Address \r \n " ) ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( MACON1 ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( MACON2 ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( MACON3 ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( MACON4 ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( MAADR5 ) , HEX ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( MAADR4 ) , HEX ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( MAADR3 ) , HEX ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( MAADR2 ) , HEX ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( MAADR1 ) , HEX ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( MAADR0 ) , HEX ) ; delay ( 5 ) ;
Serial . println ( ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " Rx : ERXST ERXND ERXWRPT ERXRDPT ERXFCON EPKTCNT MAMXFL \r \n " ) ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( ERXSTH ) , HEX ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( ERXSTL ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( ERXNDH ) , HEX ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( ERXNDL ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( ERXWRPTH ) , HEX ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( ERXWRPTL ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( ERXRDPTH ) , HEX ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( ERXRDPTL ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( ERXFCON ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( EPKTCNT ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( MAMXFLH ) , HEX ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( MAMXFLL ) , HEX ) ; delay ( 5 ) ;
Serial . println ( ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " Tx : ETXST ETXND MACLCON1 MACLCON2 MAPHSUP \r \n " ) ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( ETXSTH ) , HEX ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( ETXSTL ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( ETXNDH ) , HEX ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( ETXNDL ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( MACLCON1 ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( MACLCON2 ) , HEX ) ; delay ( 5 ) ;
SPrint_P ( PSTR ( " " ) ) ; delay ( 5 ) ;
Serial . print ( enc28j60Read ( MAPHSUP ) , HEX ) ; delay ( 5 ) ;
Serial . println ( ) ; delay ( 5 ) ;
//delay_ms(25); delay(5);
delay ( 25 ) ;
}
// SPrint("100BASE-T \r\n");
SPrint_D ( " RevID: " ) ;
Serial . println ( enc28j60Read ( EREVID ) , HEX ) ;
SPrint_D ( " Cntrl: ECON1 ECON2 ESTAT EIR EIE \r \n " ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( ECON1 ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( ECON2 ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( ESTAT ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( EIR ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( EIE ) , HEX ) ;
Serial . println ( ) ;
SPrint_D ( " MAC : MACON1 MACON2 MACON3 MACON4 MAC-Address \r \n " ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( MACON1 ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( MACON2 ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( MACON3 ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( MACON4 ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( MAADR5 ) , HEX ) ;
Serial . print ( enc28j60Read ( MAADR4 ) , HEX ) ;
Serial . print ( enc28j60Read ( MAADR3 ) , HEX ) ;
Serial . print ( enc28j60Read ( MAADR2 ) , HEX ) ;
Serial . print ( enc28j60Read ( MAADR1 ) , HEX ) ;
Serial . print ( enc28j60Read ( MAADR0 ) , HEX ) ;
Serial . println ( ) ;
SPrint_D ( " Rx : ERXST ERXND ERXWRPT ERXRDPT ERXFCON EPKTCNT MAMXFL \r \n " ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( ERXSTH ) , HEX ) ;
Serial . print ( enc28j60Read ( ERXSTL ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( ERXNDH ) , HEX ) ;
Serial . print ( enc28j60Read ( ERXNDL ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( ERXWRPTH ) , HEX ) ;
Serial . print ( enc28j60Read ( ERXWRPTL ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( ERXRDPTH ) , HEX ) ;
Serial . print ( enc28j60Read ( ERXRDPTL ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( ERXFCON ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( EPKTCNT ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( MAMXFLH ) , HEX ) ;
Serial . print ( enc28j60Read ( MAMXFLL ) , HEX ) ;
Serial . println ( ) ;
SPrint_D ( " Tx : ETXST ETXND MACLCON1 MACLCON2 MAPHSUP \r \n " ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( ETXSTH ) , HEX ) ;
Serial . print ( enc28j60Read ( ETXSTL ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( ETXNDH ) , HEX ) ;
Serial . print ( enc28j60Read ( ETXNDL ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( MACLCON1 ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( MACLCON2 ) , HEX ) ;
SPrint_D ( " " ) ;
Serial . print ( enc28j60Read ( MAPHSUP ) , HEX ) ;
Serial . println ( ) ;
SPrint_D ( " PHLCON: 00 " ) ;
Serial . println ( ( long int ) ( enc28j60PhyRead ( PHLCON ) ) , BIN ) ;
delay ( 1 ) ;
}
# endif