Exemplo n.º 1
0
/**
 * Reset and initialize the ENC28J60 and starts packet transmission/reception.
 *
 * \param[in] mac A pointer to a 6-byte buffer containing the MAC address.
 * \returns \c true on success, \c false on failure.
 */
bool enc28j60_init(const uint8_t* mac)
{
#if 0
	/* init i/o */
	enc28j60_io_init();
#endif
	/* reset device */
	enc28j60_reset();

	/* configure rx/tx buffers */
	enc28j60_write(ERXSTL, RX_START & 0xff);
	enc28j60_write(ERXSTH, RX_START >> 8);
	enc28j60_write(ERXNDL, RX_END & 0xff);
	enc28j60_write(ERXNDH, RX_END >> 8);

	enc28j60_write(ERXWRPTL, RX_START & 0xff);
	enc28j60_write(ERXWRPTH, RX_START >> 8);
	enc28j60_write(ERXRDPTL, RX_START & 0xff);
	enc28j60_write(ERXRDPTH, RX_START >> 8);

	/* configure frame filters */
	enc28j60_write(ERXFCON, (1 << ERXFCON_UCEN)  | /* accept unicast packets */
	                    (1 << ERXFCON_CRCEN) | /* accept packets with valid CRC only */
	                    (0 << ERXFCON_PMEN)  | /* no pattern matching */
	                    (0 << ERXFCON_MPEN)  | /* ignore magic packets */
	                    (0 << ERXFCON_HTEN)  | /* disable hash table filter */
	                    (0 << ERXFCON_MCEN)  | /* ignore multicast packets */
	                    (1 << ERXFCON_BCEN)  | /* accept broadcast packets */
	                    (0 << ERXFCON_ANDOR)   /* packets must meet at least one criteria */
	          );

	/* configure MAC */
	enc28j60_clear_bits(MACON2, (1 << MACON2_MARST));
	enc28j60_write(MACON1, (0 << MACON1_LOOPBK) |
#if ENC28J60_FULL_DUPLEX 
	                   (1 << MACON1_TXPAUS) |
	                   (1 << MACON1_RXPAUS) |
#else
	                   (0 << MACON1_TXPAUS) |
	                   (0 << MACON1_RXPAUS) |
#endif
	                   (0 << MACON1_PASSALL) |
	                   (1 << MACON1_MARXEN)
	          );
	enc28j60_write(MACON3, (1 << MACON3_PADCFG2) |
	                   (1 << MACON3_PADCFG1) |
	                   (1 << MACON3_PADCFG0) |
	                   (1 << MACON3_TXCRCEN) |
	                   (0 << MACON3_PHDRLEN) |
	                   (0 << MACON3_HFRMEN) |
	                   (1 << MACON3_FRMLNEN) |
#if ENC28J60_FULL_DUPLEX 
	                   (1 << MACON3_FULDPX)
#else
	                   (0 << MACON3_FULDPX)
#endif
	          );
	enc28j60_write(MAMXFLL, 0xee);
	enc28j60_write(MAMXFLH, 0x05);
#if ENC28J60_FULL_DUPLEX 
	enc28j60_write(MABBIPG, 0x15);
#else
	enc28j60_write(MABBIPG, 0x12);
#endif
	enc28j60_write(MAIPGL, 0x12);
#if !ENC28J60_FULL_DUPLEX 
	enc28j60_write(MAIPGH, 0x0c);
#endif
	enc28j60_write(MAADR0, mac[5]);
	enc28j60_write(MAADR1, mac[4]);
	enc28j60_write(MAADR2, mac[3]);
	enc28j60_write(MAADR3, mac[2]);
	enc28j60_write(MAADR4, mac[1]);
	enc28j60_write(MAADR5, mac[0]);

	if(enc28j60_read(MAADR5)== mac[0]){
		ENC28J60_INIT_DEBUG(("MAADR5 = 0x%x\n", enc28j60_read(MAADR5)));
		ENC28J60_INIT_DEBUG(("MAADR4 = 0x%x\n", enc28j60_read(MAADR4)));
		ENC28J60_INIT_DEBUG(("MAADR3 = 0x%x\n", enc28j60_read(MAADR3)));
		ENC28J60_INIT_DEBUG(("MAADR2 = 0x%x\n", enc28j60_read(MAADR2)));
		ENC28J60_INIT_DEBUG(("MAADR1 = 0x%x\n", enc28j60_read(MAADR1)));
		ENC28J60_INIT_DEBUG(("MAADR0 = 0x%x\n", enc28j60_read(MAADR0)));
	}

	/*
	 * configure PHY
	 */

	/* leda -- green led, ledb -- orange led */
#if 0
	enc28j60_write_phy(PHLCON, (1 << PHLCON_LACFG3) |
	                       (1 << PHLCON_LACFG2) |
	                       (0 << PHLCON_LACFG1) |
	                       (1 << PHLCON_LACFG0) |
	                       (0 << PHLCON_LBCFG3) |
	                       (1 << PHLCON_LBCFG2) |
	                       (0 << PHLCON_LBCFG1) |
	                       (1 << PHLCON_LBCFG0) |
	                       (0 << PHLCON_LFRQ1) |
	                       (0 << PHLCON_LFRQ0) |
	                       (1 << PHLCON_STRCH)
	              );
#else
	enc28j60_write_phy(PHLCON, (0 << PHLCON_LACFG3) |
	                       (1 << PHLCON_LACFG2) |
	                       (0 << PHLCON_LACFG1) |
	                       (0 << PHLCON_LACFG0) |
	                       (0 << PHLCON_LBCFG3) |
	                       (1 << PHLCON_LBCFG2) |
	                       (1 << PHLCON_LBCFG1) |
	                       (1 << PHLCON_LBCFG0) |
	                       (0 << PHLCON_LFRQ1) |
	                       (0 << PHLCON_LFRQ0) |
	                       (1 << PHLCON_STRCH)
	              );

#endif
	enc28j60_write_phy(PHCON1, (0 << PHCON1_PRST) |
	                       (0 << PHCON1_PLOOPBK) |
	                       (0 << PHCON1_PPWRSV) |
#if ENC28J60_FULL_DUPLEX 
	                       (1 << PHCON1_PDPXMD)
#else
	                       (0 << PHCON1_PDPXMD)
#endif
	              );
	enc28j60_write_phy(PHCON2, (0 << PHCON2_FRCLNK) |
	                       (0 << PHCON2_TXDIS) |
	                       (0 << PHCON2_JABBER) |
	                       (1 << PHCON2_HDLDIS)
	              );

	/* start receiving packets */
	enc28j60_set_bits(ECON2, (1 << ECON2_AUTOINC));
#if 0
	enc28j60_set_bits(ECON1, (1 << ECON1_RXEN));

	ENC28J60_INIT_DEBUG(("line:%d, EIE = 0x%x\n", __LINE__, enc28j60_read(EIE)));

	/* enable interrupt, David  */
	enc28j60_set_bits(EIE, (1 << EIE_INTIE) | (1<<EIE_PKTIE) | (1<<EIE_TXIE));

	ENC28J60_INIT_DEBUG(("line:%d, EIE = 0x%x\n", __LINE__, enc28j60_read(EIE)));
#endif	
	return true;
}
Exemplo n.º 2
0
int main(void)
{
 static unsigned char buffer[BUFFER_SIZE];
 unsigned short i;

 unsigned char timeout = 3;

 RTCTime local_time;

 SystemInit();

// IODIR0 |= (P0_15|P0_16|P0_17); // some outputs for debugging and measures
//P0_16 ReadSector() in mmc_spi.c
//P0_17 enc28j60 write packet
//P0_15 general purpose, BE AWARE !

// uart1Init(B38400, UART_8N1, UART_FIFO_8); // setup the UART
 uart1Init(B115200, UART_8N1, UART_FIFO_8); // setup the UART
 rprintf_devopen( uart1_sendchar ); /* init rprintf */

 VICIntEnClear = 0xFFFFFFFF;
 VICIntSelect = 0x00000000;

 RTCInit();
/* current date 05.08.2007 20:45:00*/
 local_time.RTC_Sec = 0;
 local_time.RTC_Min = 45;
 local_time.RTC_Hour = 20;
 local_time.RTC_Mday = 5;
 local_time.RTC_Wday = 3; // My monday has 0
 local_time.RTC_Yday = 1;
 local_time.RTC_Mon = 8;
 local_time.RTC_Year = 2007;
 RTCSetTime( local_time );		/* Set local time */
// RTCStart();

 init_timer();

 enableIRQ();

 printf("Holgi's ARM7 LPC213x MultiFAT Speed Test\n\r");

 MMC_IO_Init();
 enc28j60_io_init(); // You don't need this ! It's for my board only.

 while (GetDriveInformation() != F_OK && timeout--)
  {
   printf ("MMC/SD-Card not found !\n\r");
   HaltCPU();
  }

 ShowDOSConfig(); // show selected DOS details from dosdefs.h

/*
// test time measurement
 StartTimer();
 timer_value = SetDelay10ms(1000); // delay 10 seconds
 while(CheckDelay10ms(timer_value)==0);
 StopTimer(); // stop measure and show results
// result is 2MB in 10s -> 200kB/s
// end test time measurement
*/

 printf("\nTest directory functions\n");
 Chdir("dir1");
 Remove("dir4");
 Chdir("/"); // Back to root
 Remove("dir1");

 Mkdir("dir1");
 Chdir("dir1");
 Mkdir("dir2");
 Mkdir("dir3");
 Rename("dir3","dir4");
 Remove("dir2");

 // You should have now:
 // dir1/dir4

 Chdir("/"); // Back to root

 printf("\nDeleting files\n");
 Remove("01.bin"); //Remove last data
 Remove("02.bin");
 Remove("04.bin");
 Remove("08.bin");
 Remove("16.bin");
 Remove("32.bin");
 Remove("64.bin");
 Remove("77.bin");
 Remove("128.bin");
 Remove("MAX.bin");

 //Fill the test buffer
 for(i=0; i<BUFFER_SIZE; i++) buffer[i]=(unsigned char)(i);

 printf("\nStart writing files\n");
 WriteTestFile("01.bin",buffer,1);
 WriteTestFile("02.bin",buffer,2);
 WriteTestFile("04.bin",buffer,4);
 WriteTestFile("08.bin",buffer,8);
 WriteTestFile("16.bin",buffer,16);
 WriteTestFile("32.bin",buffer,32);
 WriteTestFile("64.bin",buffer,64);
 WriteTestFile("77.bin",buffer,77);
 WriteTestFile("128.bin",buffer,128);
 WriteTestFile("MAX.bin",buffer,BUFFER_SIZE);

 printf("\nStart reading files\n");
 ReadTestFile("01.bin",buffer,1);
 ReadTestFile("02.bin",buffer,2);
 ReadTestFile("04.bin",buffer,4);
 ReadTestFile("08.bin",buffer,8);
 ReadTestFile("16.bin",buffer,16);
 ReadTestFile("32.bin",buffer,32);
 ReadTestFile("64.bin",buffer,64);
 ReadTestFile("77.bin",buffer,77);
 ReadTestFile("128.bin",buffer,128);
 ReadTestFile("MAX.bin",buffer,BUFFER_SIZE);

 printf("\nVerifying files\n");
 VerifyTestFile("32.bin",buffer,32);
 VerifyTestFile("64.bin",buffer,64);
 VerifyTestFile("77.bin",buffer,77);
 VerifyTestFile("128.bin",buffer,128);
 VerifyTestFile("MAX.bin",buffer,BUFFER_SIZE);

 printf("Test done.\n");

// test if RTC is running
     local_time=RTCGetTime();
     printf("%02u:%02u:%02u %02u.%02u.%04u\n\r",local_time.RTC_Hour,local_time.RTC_Min,local_time.RTC_Sec
                                          ,local_time.RTC_Mday,local_time.RTC_Mon,local_time.RTC_Year );
 while(1)
  {
/*
   if(CheckDelay10ms(timer_value))
    {
     timer_value = SetDelay10ms(1000); // delay 10 seconds

// test if RTC is running
     local_time=RTCGetTime();
     printf("%02u:%02u:%02u %02u.%02u.%04u\n\r",local_time.RTC_Hour,local_time.RTC_Min,local_time.RTC_Sec
                                          ,local_time.RTC_Mday,local_time.RTC_Mon,local_time.RTC_Year );
    }
*/
  }

 return(0);
}