cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Visitor
Visitor
4,496 Views
Registered: ‎03-24-2009

Emac Lite driver for UIP -TCP/IP Stack.

the UIP/TCP-IP  stack has following main function for  which  I need EMACLite Driver. If any body can get me the proper frunctionality using Emaclite driver. I have been able to get ping response using this IP Stack but it does not forward the application packets data.

I am implementing it on Microblaze. I can use Spartan , Virtex4 and Virtex5 chips.

the working driver in xapp807 is also given, whose functionality i want to map in my driver.

 

=================================================================================================

 

int main(void)
{
    Xuint16 x, first_array, second_array;

    int I=0;
    int J=0;

    unsigned char *Buffer[UIP_BUFSIZE+2];

    first_array = UIP_LLH_LEN + 40;
    second_array = uip_len - UIP_LLH_LEN-40;


    u32 Register1,Register2,Register3,Register4,Register5;
    int Status;
    XEmacLite *EmacLiteInstancePtr = &EmacLiteInstance;
    u32 TxLength;
    RecvFrameLength = 0;
    XEmacLite_Config *ConfigPtr;

//    unsigned char *Frame = uip_buf;
//    unsigned char *Frame_app = uip_appdata;
    /*
     * Initialize the EmacLite device.
     */
    ConfigPtr = XEmacLite_LookupConfig(EMAC_DEVICE_ID);
    if (ConfigPtr == NULL) {
        return XST_FAILURE;
    }
    Status = XEmacLite_CfgInitialize(EmacLiteInstancePtr,
                    ConfigPtr,
                    ConfigPtr->BaseAddress);
    if (Status != XST_SUCCESS) {
        return XST_FAILURE;
    }



    /*
     * Set the MAC address.
     */
    XEmacLite_SetMacAddress(EmacLiteInstancePtr, LocalAddress);
    print("-- Set Mac Address --\r\n");

    /*
     * Empty any existing receive frames.
     */
    XEmacLite_FlushReceive(EmacLiteInstancePtr);
    print("-- Flush Receive Buffer--\r\n");

    /*
     * Check if there is a TX buffer available, if there isn't it is an
     * error.
     */
    if (XEmacLite_TxBufferAvailable(EmacLiteInstancePtr) != TRUE) {
        return XST_FAILURE;
    }

   
   
//    unsigned char *Frame;
//    Frame = uip_buf;
   

  u8_t i,j, arptimer;
//  LCD_Init();
//  LCD_Write("   Welcome to   ", "    XAPP807     ");

  /* Initialize the device driver. */
 // tapdev_init();

  /* Initialize the uIP TCP/IP stack. */
  uip_init();
 // print("--  uip_init() --\r\n");

  /* Initialize the HTTP server. */
  httpd_init();
  //print("-- httpd_init --\r\n");

  arptimer = 0;
 
 
while(1)
 {
     /* Let the tapdev network device driver read an entire IP packet
    into the uip_buf. If it must wait for more than 0.5 seconds, it
    will return with the return value 0. If so, we know that it is
      time to call upon the uip_periodic(). Otherwise, the tapdev has
      received an IP packet that is to be processed by uIP. */
          uip_len = XEmacLite_Recv(EmacLiteInstancePtr, (u8 *)uip_buf);
  //  uip_len = XEmacLite_RecvFrame(0x81000000, uip_buf);
    if(uip_len == 0)
             {
          for(i = 0; i < UIP_CONNS; i++)
                        {
                            uip_periodic(i);
    /*  If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
                         if(uip_len > 0)
                              {
                                         uip_arp_out();
                                 //    tapdev_send();
                                 SendFrame(EmacLiteInstancePtr);
                              }
                        }

                    #if UIP_UDP
                        for(j = 0; j < UIP_UDP_CONNS; j++)
                        {
                            uip_udp_periodic(i);
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
                            if(uip_len > 0)
                                {
                                  uip_arp_out();
                                //tapdev_send();
                                  SendFrame(EmacLiteInstancePtr);
                                }
                        }
                    #endif /* UIP_UDP */
                       
                    /* Call the ARP timer function every 10 seconds. */
                    if(++arptimer == 20)
                        {   
                            uip_arp_timer();
                            arptimer = 0;
                    }
     
     }
            else
                    {
                        if(BUF->type == htons(UIP_ETHTYPE_IP))
                            {
                                uip_arp_ipin();
                                uip_input();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
                                if(uip_len > 0)
                                    {
                                      uip_arp_out();
                                    //tapdev_send();
                                        SendFrame(EmacLiteInstancePtr);
                                    }   
                            }
                            else if(BUF->type == htons(UIP_ETHTYPE_ARP))
                                {
                                    uip_arp_arpin();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */   
                                        if(uip_len > 0)
                                            {   
                                             //tapdev_send();
                                             //SendFrame(EmacLiteInstancePtr);
                                            }
                                }
                    }
   
  }
  return 0;
}

 

========================================= Help needed in this driver working to transmit properly =======================

static int SendFrame(XEmacLite *InstancePtr)

{
    unsigned char *Buffer[UIP_BUFSIZE+2];
unsigned char *Frame = uip_buf;
unsigned char *Frame_app = uip_appdata;

Xuint16 x, first_array, second_array;

int I=0;
int J=0;

first_array = UIP_LLH_LEN + 40;
second_array = uip_len - UIP_LLH_LEN-40;




//    memcpy(&Buffer[0],Frame,first_array);
//
//    second_array = uip_len - UIP_LLH_LEN-40;
//
//    memcpy(&Buffer[55],uip_appdata,second_array);

//        for (I=0; I < first_array; I++)
//
//            {
//                *Buffer[I] =uip_buf[I];
//            }
//
//        for (J=0; J < 1448; J++)
//
//            {
//                *Buffer[54 + J] = uip_appdata[J];
//            }

 if(uip_len > first_array)
    {
            //XEmacLite_Send(InstancePtr, Frame, first_array);
            //XEmacLite_SendFrame(0x81000000, (u8 *)uip_buf, first_array);
            //XEmacLite_SendFrame(0x81000000,(u8 *)Buffer, second_array+first_array);
            //XEmacLite_Send(InstancePtr, (u8 *)uip_appdata, second_array);
            //XEmacLite_SendFrame(0x81000000,(u8 *)Buffer, second_array);


            
     }
  else
        {
            //XEmacLite_SendFrame(0x81000000, (u8 *)uip_buf, uip_len);
        //XEmacLite_Send(InstancePtr, Frame, uip_len);
        }
return 0;

}

 ================================================================================================

 

 

void tapdev_send()
{
  u16_t x, first_array, second_array;
  lock_tx_fifo();
  stw(FIFOPORT, ((Xuint32) (uip_buf[0])));
  // changed to below to adapt to where data is pointed in this software.
  first_array = UIP_LLH_LEN + 40;
  second_array = uip_len - UIP_LLH_LEN-40;
  if(uip_len > first_array)
    {
         for(x = 0; x < first_array; ++x)
        {
         stw(FIFOPORT, ((Xuint32) (uip_buf[x])));
        }
         for(x=0; x < second_array; ++x)
        {
         stw(FIFOPORT, ((Xuint32) (uip_appdata[x])));
        }
    }
    else
    {
    for(x = 0; x < uip_len; ++x)
        {
            stw(FIFOPORT, ((Xuint32) (uip_buf[x]) ));
        }
    }
  stw(FIFOPORT, 0x00000100);
  stw(FIFOPORT, 0x00000100);
  unlock_tx_fifo();
}



int tapdev_read(){
  Xuint32 input;
  u16_t x, time_out=0;
  do
    {
    if(time_out>65530)
        {
            return 0;
        }
             x=0;
             time_out++;
    do
        {
            input      = lwz(FIFOPORT);
            uip_buf[x] = (u8_t)(input & RX_DATA_FILTER);
      if (!(input & RX_EMPTY_FILTER))
      {
        x++;
      }
    }
    while (((input & RX_VALID_FILTER) || (input & RX_EMPTY_FILTER && x!=0)) && (!(input & RX_FULL_FILTER)));
    if ((input & RX_FULL_FILTER))
        {
            reset_rx_fifo();
        }
  } while ((input & RX_FULL_FILTER) || (x==0));
  return (x-1);
 }

====================================================================================================

 

I have to get the functionality of the above driver code from the Emaclite driver.

the code given above is for emac in Ultracontroller.

 

 

0 Kudos
1 Reply
Highlighted
Visitor
Visitor
4,461 Views
Registered: ‎03-24-2009

I am using following IP stack.

 

http://www.sics.se/~adam/uip/index.php/Main_Page

 

this is being used in Ultracontroller II in XAPP807. I want to work it on Microblaze.

0 Kudos