SmartOS之------Enc28j60(以太网)


作用


 以太网芯片Enc28j60便宜好用,基于SPI。

 

代码


 

 1 #include "Sys.h"

 2 #include "Enc28j60.h"

 3 

 4 #include "conf.h"

 5 #include "ip_arp_udp_tcp.h"

 6 #include "net.h"

 7 

 8 #define PSTR(s) s

 9 

10 static char MAC[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };

11 //static char IP[] = { 192, 168, 0, 94 };

12 static char Url[] = "http://192.168.0.1/";

13 

14 static u16 Port = 1200; // listen port for udp

15 #define BUFFER_SIZE 1500//400 64---1518

16 static byte buf[BUFFER_SIZE + 1]; //»º³åÇø

17 //static char password[] = "888"; // must not be longer than 9 char

18 

19 void TestEnc28j60()

20 {

21     debug_printf("\r\n\r\n");

22     debug_printf("TestEnc28j60 Start......\r\n");

23 

24     Spi spi(SPI_1, 9000000, true);

25     Enc28j60 enc(&spi, PE3, PE1);

26     enc.Init(MAC);

27     

28     byte rev = enc.GetRevision();

29     debug_printf("Revision: 0x%08x\r\n", rev);

30 

31     enc.PhyWrite(PHLCON, 0x476);

32     enc.ClockOut(2); // change clkout from 6.25MHz to 12.5MHz

33 

34     //init the ethernet/ip layer:

35     while (1)

36     {

37         // get the next new packet:

38         ushort plen = enc.PacketReceive(buf, BUFFER_SIZE);

39         //USART_DMASendData(USART1,buf,plen);

40 

41         /*plen will be unequal to zero if there is a valid packet (without crc error) */

42         if (plen == 0) continue;

43 

44     }

45 

46     debug_printf("\r\nTestEnc28j60 Finish!\r\n");

47 }

 

讲解


 

无。

End!

    ------来自新生命团队!

 

欢迎大家一起交流 ,分享程序员励志故事。   幸福的程序员 QQ群:幸福的程序员 嵌入式交流群中国嵌入式物联网群

你可能感兴趣的:(OS)