DHCP not working on NE64!  Please Help!

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DHCP not working on NE64!  Please Help!

667 Views
chinniwhites
Contributor II

I just bought an NE64 dev board and am currently in the process of trying to get to accept a dhcp address.  I hacked apart the connecterapp and NE64_Vend_OpenTcp to try to make my own project.  Please let me know what i am doing wrong here.  Here is what i got so far:

 

 /**************************************************************************                     
 *       
 *       Copyright (C) 2003 Freescale Semiconductor, Inc.
 *           and 2000-2002 Viola Systems Ltd.
 *       All Rights Reserved
 *    
 * File Name      : Main.c
 * Project Name   : Connector_App.mcp
 * Description    : This file contains main() for the Connector_App demo
 *                    code for the MC9S12NE64.
 *                  It does initializations and calls functions in the
 *                    Connector_App.c application code. The Connector_App.c
 *                    file contains code for IO communication and UDP
 *                    protocol functions on the MC9S12NE64.
 *
 * *** NOTE: This project is for demonstration purposes only. It excludes
 *             portions of the complete OpenTCP Stack for other protocols,
 *             such as http, bootp, dns, etc. The complete version of this
 *             stack is also included in the MC9S12NE64 Resource CD.
 *                
 * *** NOTE: All header files have been removed from the Connector_App.mcp
 *             project due to the 32-file limit of CodeWarrior Special 
 *             Edition. However, all the header files are included in your
 *             working folder and can be viewed by highlighting it's name
 *             in a source file, right clicking, and choosing "Find and
 *             Open File..." You may also just type the name of the file
 *       in any source file and do this.
 *
 * Version : 1.1
 * Date    : 07/21/04
 *
 ***************************************************************************/

#include "Connector_App.h"

#include "ne64api.h"
#include "ne64config.h"
#include "ne64debug.h"
#include "ne64driver.h"
#include "mBuf.h"

#include "debug.h"
#include "datatypes.h"
#include "timers.h"
#include "system.h"
#include "ethernet.h"
#include "arp.h"
#include "dhcpc.h"
#include "icmp.h"
#include "ip.h"
#include "udp.h"
#include "tcp_ip.h" 

#include "address.h"

#include "MC9S12NE64.h"
/* Including used modules for compiling procedure */

/* Network Interface definition. Must be somewhere so why not here? :-)*/
struct netif localmachine;

extern void RTI_Init (void);
extern void RTI_Enable (void);
//extern void porth_isr_handler (void);

extern tU08 gotlink;
extern UINT8 dhcpc_state;
void Wait_for_UpdTcp(void);

#if USE_SWLED
tU16 LEDcounter=0;
#endif


//============================================================
tU08 OldSwitchValue=255;
tU16 Pot=0;
tU16 OldPot=1050;
tU08 OldB1=255;
tU08 OldB2=255;
//============================================================
//Initialize ATD
//============================================================
void ATD_init(void)
{
    ATDCTL2 =  ATDCTL2_ADPU_MASK | ATDCTL2_AFFC_MASK;
    ATDCTL3_S1C = 8;    // 8 ch seq.
    ATDCTL3_FIFO = 0;    // no FIFO
    ATDCTL3_FRZ = 3;     // Freeze immediately in BDM 
    ATDCTL4 =  ATDCTL4_PRS2_MASK |ATDCTL4_PRS1_MASK | ATDCTL4_PRS0_MASK;
    ATDCTL4 = ATDCTL4 & ~ATDCTL4_SRES8_MASK; //10 bit
    ATDCTL5 = ATDCTL5_SCAN_MASK;
}


//============================================================
// Initialize Port for LEDs, Switch, and Buttons
//============================================================
void demoinit(void)
 {
     //LEDS
    DDRG_DDRG0 = 1;
    DDRG_DDRG1 = 1;
   PTG_PTG0 = 1; //turn off  
   PTG_PTG1 = 1; //turn off  

    //SWITCH (RUN/LOAD)   0:input
    DDRG_DDRG4 = 0;

    //BUTTON2
    DDRH_DDRH4 = 0;
    PIEH_PIEH4 = 1;      //PIEH4 Interrupt Enable
 }


//============================================================
/* main */
//============================================================
void main(void)
{
  //INT16 len;
  long timeout;
  char Got_dhcp=TRUE;

  /* System clock initialization */
  CLKSEL=0;
  CLKSEL_PLLSEL = 0;                   /* Select clock source from XTAL */
  PLLCTL_PLLON = 0;                    /* Disable the PLL */
  SYNR = 0;                           /* Set the multiplier register */
  REFDV = 0;                          /* Set the divider register */
  PLLCTL = 192;
  PLLCTL_PLLON = 1;                    /* Enable the PLL */
  while(!CRGFLG_LOCK);                 /* Wait */
  CLKSEL_PLLSEL = 1;                   /* Select clock source from PLL */

  INTCR_IRQEN = 0;                     /* Disable the IRQ interrupt. IRQ interrupt is enabled after CPU reset by default. */
 
 
 /* initialize processor-dependant stuff (I/O ports, timers...).
  * Most important things to do in this function as far as the TCP/IP
  * stack concerns:
  *  - initializing some timer so it executes decrement_timers
  *  on every 10ms (TODO: Throw out this dependency from several files
  * so that frequency can be adjusted more freely!!!)
  *  - not mess too much with ports allocated for Ethernet controller
  */
  _INIT_DEBUG();
 
  ATD_init();
  demoinit();
  RTI_Init();

  /* Ethernet (MAC) address */
  localmachine.localHW[0] = hard_addr[0];
  localmachine.localHW[1] = hard_addr[1];
  localmachine.localHW[2] = hard_addr[2];
  localmachine.localHW[3] = hard_addr[3];
  localmachine.localHW[4] = hard_addr[4];
  localmachine.localHW[5] = hard_addr[5];

 
 /* Init system services  */   
 timer_pool_init();
  
    /* Initialize all buffer descriptors */
 mBufInit ();
     
  /* Initialize all network layers */
  EtherInit();
 
  //Enable RTI
 RTI_Enable ();
 
  //Initialize required network protocols  
  (void)arp_init();
  (void)udp_init();
  (void)tcp_init();
 
  while (!gotlink){
  }
 
  /* if using DHCP, following network variables should be initialized to zero
   * during startup (or to previously-assigned parameters if they are stored
   * somewhere - in FLASH maybe...)
   */
  /* Note: If enabled, this function initializes the DHCP protocol */
  localmachine.localip = 0;
 localmachine.defgw = 0;
  localmachine.netmask = 0;    
 
  (void)dhcpc_init();
 timeout = 1600000; // This timeout is Application,and frequency dependent
 
  while (dhcpc_state != DHCP_STATE_BOUND){
    dhcpc_run();
    Wait_for_UpdTcp();     //wait for it
    timeout--;
 
    if (timeout == 0)
     {
       Got_dhcp = FALSE;
       break;
     }
  }
 
 if(Got_dhcp==FALSE){
   /* Set our network information. This is for static configuration.*
    * if using BOOTP or DHCP this will be a bit different.          */
    /* IP address */
    localmachine.localip = *((UINT32 *)ip_address);      
    /* Default gateway */
    localmachine.defgw   = *((UINT32 *)ip_gateway);
    /* Subnet mask */
    localmachine.netmask = *((UINT32 *)ip_netmask);
 }
 
 /* main loop */
 DEBUGOUT(">>>>>>>>>Entering to MAIN LOOP>>>>>>>>>\n\r");
 for (;:smileywink:{
    #if USE_SWLED
          UseSWLedRun();
    #endif
   
   if (gotlink) {
     /* Try to receive Ethernet Frame */     
      Wait_for_UpdTcp();
    /* Application main loops */
     /* manage arp cache tables */
     arp_manage(); 
     
     if(Got_dhcp==TRUE){
        dhcpc_run ();
        PTG_PTG1 = 0; //turn on LED2
     }
     else{
       PTG_PTG0 = 0; //turn on LED1 
      }
    }
 
  /* Application main loops */
  /* TCP/IP stack Periodic tasks here... */
    //udp_demo_run();
  }
}

//---------------end of main----------------------------------------
//---------------start of function declarations

void Wait_for_UpdTcp(void){
INT16 Pack_len;

 if( NETWORK_CHECK_IF_RECEIVED() == TRUE ) 
  {
    switch( received_frame.protocol)
   {
     case PROTOCOL_ARP:
      process_arp (&received_frame);
       break;
     case PROTOCOL_IP:
      Pack_len = process_ip_in(&received_frame);
     if(Pack_len < 0)
         break;
        switch (received_ip_packet.protocol)
      {
       case IP_ICMP:
        process_icmp_in (&received_ip_packet, Pack_len);
        break;
       case IP_UDP:
              process_udp_in (&received_ip_packet,Pack_len);          
              break;
      case IP_TCP:
        process_tcp_in (&received_ip_packet, Pack_len);    
        break;
       default:
       break;
      }
        break;
     default:
      break;
   }
    /* discard received frame */      
    NETWORK_RECEIVE_END();
   }
}

Labels (1)
0 Kudos
1 Reply

259 Views
chinniwhites
Contributor II

I hooked up wireshark and noticed the NE64 sends out a discover message but nothing else.  I used wireshark to see how the computer handles dhcp, and it sends about five different DHCP related messages.  So my question is why am i not getting past the DHCP Discover message?

0 Kudos