Beispiel #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;
}
Beispiel #2
0
// Initial_tid can be a random number for every board. E.g the last digit
// of the mac address. It is not so important that the number is random.
// It is more important that it is unique and no other board on the same
// Lan has the same number. This is because there might be a power outage
// and all boards reboot afterwards at the same time. At that moment they
// must all have different TIDs otherwise there will be an IP address mess-up.
//
// The function returns 1 once we have a valid IP. 
// At this point you must not call the function again.
uint8_t packetloop_dhcp_initial_ip_assignment(uint8_t *buf,uint16_t plen,uint8_t initial_tid){
        static uint16_t init=0x5fff; // about 2 sec delay
        uint8_t cmd;
        // do nothing if the link is down
        if (!enc28j60linkup()) return(0);
        // first time that this function is called:
        if (plen==0){
                if (init==2){
                        init=1;
                        dhcp_6sec_cnt=0;
                        dhcp_tid=initial_tid;
                        // Reception of broadcast packets is turned off by default, but
                        // the DHCP offer message that the DHCP server sends will be
                        // a broadcast packet. Enable here and disable later.
                        enc28j60EnableBroadcast();
                        send_dhcp_discover(buf,dhcp_tid);
                        return(0);
                }
                if (dhcp_yiaddr[0]==0 && dhcp_6sec_cnt > 5){
                        // still no IP after 30 sec
                        dhcp_tid++;
                        dhcp_6sec_cnt=0;
                        // Reception of broadcast packets is turned off by default, but
                        // the DHCP offer message that the DHCP server sends will be
                        // a broadcast packet. Enable here and disable later.
                        enc28j60EnableBroadcast();
                        send_dhcp_discover(buf,dhcp_tid);
                        return(0);
                }
                // We have a little delay (about 2sec) at startup. Sometimes
                // the power fluctuates or the programmer causes
                // the board to reset and then immediately reset again.
                // We wait with the sending of a send_dhcp_discover just in case
                // we did already so at the last reset which was possibly less
                // than a second ago.
                if (init>2){
                        init--;
                }
                return(0);
        }
        // plen > 0
        if (is_dhcp_msg_for_me(buf,plen,dhcp_tid)){
                // It's really a borderline case that we the the dhcp_is_renew_tid
                // function call for. It could only happen if the board is power cyceled 
                // during operation.
                if (dhcp_is_renew_tid(buf,plen)==1) return(0); // should have been initial tid, just return
                cmd=dhcp_get_message_type(buf,plen);
                if (cmd==2){ // DHCPOFFER =2
                        init=1; // no more init needed
                        dhcp_get_yiaddr(buf,plen);
                        dhcp_option_parser(buf,plen);
                        // answer offer with a request:
                        send_dhcp_request(buf,dhcp_tid);
                }
                if (cmd==5){ // DHCPACK =5
                        // success, DHCPACK, we have the IP
                        init=1; // no more init needed
                        enc28j60DisableBroadcast();
                        return(1);
                }
        }
        return(0);
}
Beispiel #3
0
void EtherShield::ES_enc28j60EnableBroadcast( void ) {
	enc28j60EnableBroadcast();
}