Example #1
0
/*---------------------------------------------------------------------------*/
int main(void)
{
    uint16_t plen;    
    
    init_serial();
    init_mac(mymac);      
    init_udp_or_www_server(mymac,myip);             

    enc28j60Init(mymac);        
    enc28j60PhyWrite(PHLCON,0x476);
    enc28j60EnableBroadcast();

    xprintf(PSTR("Hello World!\r\n"));

    /* main loop */
    while(1)
    {            
        /* poll hardware ethernet buffer */
        plen = enc28j60PacketReceive(BUFFER_SIZE,buf);

        /* any new message? */
        if(plen > 0)
        {
            checkBootloaderCondition(buf);
        }

    }
    return 0;
}
Example #2
0
/**
  * @brief  task who manage ethernet communication
  * @param  None
  * @retval None
  */
void ethernet_task(void *pdata)
{
#if 1
	pdata=pdata;

	// initialize enc28j60
	ES_enc28j60Init(&mymac[0]);

	/* Magjack leds configuration, see enc28j60 datasheet, page 11 */
	// LEDB=yellow LEDA=green
	//
	// 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
	// enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
	enc28j60PhyWrite(PHLCON,0x476);
	init_udp_or_www_server(&mymac[0],&myip[0]);

	//ES_init_ip_arp_udp_tcp(mymac,myip,80);

	if( ES_enc28j60Revision() <= 0 )
	{
	  // Failed to access ENC28J60
	  while(1);    // Just loop here
	}
	// Get IP Address details
	#if 0
	if( allocateIPAddress(buf, BUFFER_SIZE, mymac, 80, myip, mynetmask, gwip, dhcpsvrip, dnsip ) > 0 ) {
	  // Display the results:
	} else {
		// Failed to get IP address"
		while(1);
	}
	#endif
#endif
	for(;;)
	{
#if 1
		ethernet_process();
#endif
	}

}
Example #3
0
int main(void)
{
  uint16_t dat_p;
        
  ADC_init();
  _delay_ms ( 100 );
  //DDRB |= (1<<PB0);

  initTimer();



  //initialize the hardware driver for the enc28j60
  enc28j60Init(mymac);
  enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
  _delay_loop_1(0); // 60us
  enc28j60PhyWrite(PHLCON,0x476);
        
  //init the ethernet/ip layer:
  init_udp_or_www_server(mymac,myip);
  www_server_port(MYWWWPORT);

  while(1)
  {
    // read packet, handle ping and wait for a tcp packet:
    dat_p=packetloop_arp_icmp_tcp(buf,enc28j60PacketReceive(BUFFER_SIZE, buf));

    // dat_p will be unequal to zero if there is a valid  http get
    if(dat_p==0)
    {
	// no http request
	continue;
    }
    // tcp port 80 begin
    if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0)
    {
      // head, post and other methods:
      dat_p=http200ok();
      dat_p=fill_tcp_data_p(buf,dat_p,PSTR("<h1>200 OK</h1>"));
      www_server_reply(buf,dat_p);
      continue;
    }
    // just one web page in the "root directory" of the web server
    if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0)
    {
      //dat_p=print_webpage(buf);
      dat_p=printIndex(buf);
      www_server_reply(buf,dat_p);
    }
    else if (strncmp("/now.htm", (char *)&(buf[dat_p+4]),8) == 0 )
    {
      dat_p = printNowHTML ( buf );
      www_server_reply( buf, dat_p );
    }
    else if (strncmp("/min0.htm", (char *)&(buf[dat_p+4]),9) == 0 )
    {
      dat_p = printMinHTML ( buf, 0 );
      www_server_reply( buf, dat_p );
    }
    else if (strncmp("/min1.htm", (char *)&(buf[dat_p+4]),9) == 0 )
    {
      dat_p = printMinHTML ( buf, 1 );
      www_server_reply( buf, dat_p );
    }
    else if (strncmp("/wlcm.htm", (char *)&(buf[dat_p+4]),9) == 0 )
    {
      dat_p = printWelcomeHTML ( buf );
      www_server_reply( buf, dat_p );
    }
    else
    {
      dat_p=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n<h1>401 Unauthorized</h1>"));
      www_server_reply(buf,dat_p);
    }
  }
  return (0);
}
Example #4
0
/*
 * Main entry point
 */
int main(void) {

    //=====init green led
    LEDInit();
    LEDSet(1);

    //=====setup eth interface
    uint16_t plen = 0,  dat_p = 0;
    //initialize enc28j60
    enc28j60Init(mymac);



    _delay_ms(100);

    // Magjack leds configuration, see enc28j60 datasheet, page 11 
    // LEDB=yellow LEDA=green
    // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
    // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
    enc28j60PhyWrite(PHLCON,0x476);


    _delay_ms(100);

    //init the ethernet/ip layer:
    init_udp_or_www_server(mymac,myip);
    www_server_port(MYWWWPORT);
    register_ping_rec_callback(PingCallback);


    while(1){

        // handle ping and wait for a tcp packet:
        dat_p = packetloop_arp_icmp_tcp(buf, enc28j60PacketReceive(BUFFER_SIZE, buf));

        // dat_p will be unequal to zero if there is a valid http get
        if(dat_p==0){
            // do nothing
            continue;
        }
        // tcp port 80 begin
        if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0){
            dat_p = fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
            dat_p = fill_tcp_data_p(buf, dat_p, PSTR("<h1>200 OK</h1>"));
            goto SENDTCP;
        }
        if (strncmp("/ ",(char *) & (buf[ dat_p + 4] ), 2) == 0 ){
            nAccessCount++;
            dat_p = fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
            // webcontent
            char szWebText[130] = {0};
            sprintf(szWebText,
                    "<b>ATmega8 Webserver / ENC28J60</b><br><br>Server stats:<br>Acc:%d Png:%d<br><br>(C) Radu Motisan 2012, www.pocketmagic.net<br/>Tomasz Jokiel",
                    nAccessCount, nPingCount);
            dat_p = fill_tcp_data(buf, dat_p, szWebText);
            //
            goto SENDTCP;
        }
        // all other URLs:
        dat_p = fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n<h1>401 Unauthorized</h1>"));
        SENDTCP:
        www_server_reply(buf, dat_p); // send web page data


    }

    return (0);
} 
int main(void){
        uint16_t dat_p;
        // Set the clock speed to "no pre-scaler" (8MHz with internal osc or 
        // full external speed)
        // set the clock prescaler. First write CLKPCE to enable setting 
        // of clock the next four instructions.
        // Note that the CKDIV8 Fuse determines the initial
        // value of the CKKPS bits.
#if 0		
        CLKPR=(1<<CLKPCE);
        CLKPR=0; // 8 MHZ
#endif		
        _delay_loop_1(0); // 60us
        
        /*initialize enc28j60*/
        enc28j60Init(mymac);
        enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
        _delay_loop_1(0); // 60us
        
        // Magjack leds configuration, see enc28j60 datasheet, page 11 
        // LEDB=yellow LEDA=green
        //
        // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
        // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
        enc28j60PhyWrite(PHLCON,0x476);

        //init the ethernet/ip layer:
        init_udp_or_www_server(mymac,myip);
        www_server_port(MYWWWPORT);

        while(1){
                // handle ping and wait for a tcp packet:
                dat_p=packetloop_arp_icmp_tcp(buf,enc28j60PacketReceive(BUFFER_SIZE, buf));

                // dat_p will be unequal to zero if there is a valid http get 
                if(dat_p==0){
                        // do nothing
                        continue;
                }
                // tcp port 80 begin
                if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0){
                        // head, post and other methods:
                        //
                        // for possible status codes see:
                        // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
                        dat_p=http200ok();
                        dat_p=fill_tcp_data_p(buf,dat_p,PSTR("<h1>200 OK</h1>"));
                        goto SENDTCP;
                }
                if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0){
                        dat_p=http200ok();
                        dat_p=fill_tcp_data_p(buf,dat_p,PSTR("<p>OK, works great!</p>\n"));
                        goto SENDTCP;
                }
                // all other URLs:
                dat_p=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n<h1>401 Unauthorized</h1>"));
SENDTCP:
                www_server_reply(buf,dat_p); // send web page data
        }
        return (0);
}