BF 609 Ethernet sample application availability?

We want to evaluate ethernet connectivity on BF 609 using standard TCP/IP socket api's. We want to transmit and receive data from Host PC to the BF 609 and process the same on BF 609.

But could not find a sample application to do the same?

Do we need to use lwIP stack compulsorily for the same? Does the lwIP stack have a hard dependency on uC OS?

Can we have standard TCP /IP socket API based communication without using lwIP or uC OS.

Please educate me on the available options and examples for this.

Thanks....

  • 0
    •  Analog Employees 
    on Mar 15, 2013 3:40 PM

    Hi,

    We do have a port of the LwIP stack available as an Add-In for CrossCore Embedded Studio, but this does require an RTOS.

    You may be aware that the LwIP stack we provide is simply a port of the open-source LwIP stack available from Savannah.org. You could take the stack from Savannah and port it to the BF60x yourself, without the need for an OS, if you want the stack.

    Regarding other ethernet examples, we only have the Ethernet loopback test of the Power On Self Test to refer you to. This does not use the LwIP stack, or an RTOs, so may be of interest to you if you want to perform TCP/IP at a bare metal level. This is located at "...\BF609_Evaluation_Board\Blackfin\Examples\Power_On_Self_Test\src\ether_loopback" in the Board Support Package, which can be downloaded from the link below.

    http://www.analog.com/swexamples

    Regards,

    Craig.

  • Hi Craig,

    Thanks for the inputs.

    As pointed out by you I decided to evaluate the lwIP stack using the uC OS RTOS.

    Taking the "fileserver" as reference, I created a new project with following Add-ins selected:

    1. Analog Devices lwIP TCP/Ip stack.

    2. Ethernet Driver

    3. Pin Multiplexing

    4. Startup Code/LDF

    The PIN multiplexing and Startup Code/LDF setting are made exactly as "fileserver" example.

    In case of "Analog Devices lwIP TCP/Ip stack" configuration, I have changed from DHCP to Static IP and configured the IP address and Subnet to "192.168.0.1 and 255.255.255.0" and my Host PC's static IP and Subnet is set at "192.168.0.2 and 255.255.255.0" respectively. The EZKIT and Host is connected directly to each other over using a ethernet cable.

    My BF-609 program is pasted below. The BF-609 is expected to act as TCP/IP server and then received some image data from Host PC in packets of 1K.

    **********************************************************************************************************************************

    /*****************************************************************************
    * Ethernet_Core0.c
    *****************************************************************************/
    #include <os.h>
    #include <adi_types.h>
    #include <ccblkfn.h>
    #include "adi_initialize.h"
    #include "Ethernet_Core0.h"
    #include <lwip\sockets.h>

    #define APPLICATION_TASK_STACK_SIZE (1024)
    #define APPLICATION_TASK_PRIO  (9)

    #define MAX_PENDING   (5)
    #define MAX_IMAGE_WIDTH  (640)
    #define MAX_IMAGE_HEIGHT (360)
    #define IMG_CHANNELS  (1)

    #define NO_OF_BYTES_TO_READ_AT_SINGLECALL (1*1024)

    static OS_TCB  ApplicationTaskTCB;
    static CPU_STK ApplicationTaskStack[APPLICATION_TASK_STACK_SIZE];

    static unsigned char ImageData[MAX_IMAGE_WIDTH*MAX_IMAGE_HEIGHT*IMG_CHANNELS];


    struct sockaddr_in g_ServerSocket;
    int g_Socket_fd;
    int g_AcceptSocket;

    char *g_ServerIP = "192.168.0.1";
    int g_ServerPortNo = 5001;

    /* boot semaphore */
    extern OS_SEM  g_semLWIPBootComplete;

    /* function prototypes */
    void    ApplicationTask(void *p_arg);
    int32_t adi_OS_Init(void);
    int32_t adi_initComponents(void);
    void * read_frame(void);
    int mainloop(void);

    int main(void)
    {
    int32_t result;
    OS_ERR  osErr;

    /* adi_OS_Init() API is explicitly placed for the examples.
      * LWIP examples use uCos libraries instead of uCos product
      * which is source based. When uCos product is added to your
      * network application this call will be automatically added
      * by the uCos component framework, i.e adi_OS_Init()
      * is called from adi_init_Components().
      */
    result = adi_OS_Init();

    if (result != 0)
    {
      printf("Failed to initialize operating system \n");
      while(1){ ; }
    }

    /* Initialize any managed drivers and/or services.This routine
      * will call init routines for the add-in components.For lwip
      * adi_lwip_Init() gets called from adi_initComponents() which
      * initializes the lwip subsystem.
      *
      * Once RTOS is started with OSStart() lwipboot task starts the
      * lwip subsystem.
      */
    result = adi_initComponents();

    if (result != 0)
    {
      printf("Failed to initialize system components \n");
      while(1){ ; }
    }

    /* create Application task */
    OSTaskCreate (
      &ApplicationTaskTCB,                /* Pointer to TCB */
      "Application_Task",                 /* The Task Name */
      ApplicationTask,                    /* Function Pointer */
      (void*) NULL,                       /* Function Argument */
      APPLICATION_TASK_PRIO,              /* Application Task Priority */
      ApplicationTaskStack,               /* Stack base Address */
      APPLICATION_TASK_STACK_SIZE - 1,    /* Stack Limit */
      APPLICATION_TASK_STACK_SIZE,        /* Stack Size */
      NULL,                               /* Message Queue Size */
      1,                                  /* Time Quota */
      NULL,                               /* External Pointer */
      OS_OPT_TASK_STK_CHK |               /* Allow Stack Check */
      OS_OPT_TASK_STK_CLR,                /* Clear the stack */
      &osErr                              /* Pointer to error variable */
      );

        if(osErr != OS_ERR_NONE)
        {
         printf("Error creating application task /n");
         while(1){ ; }
        }

    /* start the OS.This allows the start of lwip system boot task and
      * other application tasks
      */
    OSStart(&osErr);

    if(osErr != OS_ERR_NONE)
    {
      printf("failed to start OS\n");
      while(1){ ; }
    }

    return 0;
    }

    void ApplicationTask(void *p_arg)
    {
        OS_ERR osErr;
        int retval =0;

        printf("SHAILESH:Waiting for LWIP for finish booting....\n");
        /* Wait for lwip to finish booting */
        OSSemPend(&g_semLWIPBootComplete,0,OS_OPT_PEND_BLOCKING,NULL,&osErr);

        if (osErr != OS_ERR_NONE)
        {
            printf("failed to wait on lwip boot semaphore \n");
            return;
        }
        printf("SHAILESH:Creating socket....\n");

        g_Socket_fd = socket(AF_INET, SOCK_STREAM, 0);
        if (g_Socket_fd < 0)
        {
            printf("SHAILESH:Server socket creation failed\n");
            return;
        }

        memset(&g_ServerSocket, 0, sizeof(struct sockaddr_in));
        g_ServerSocket.sin_family = AF_INET;
        g_ServerSocket.sin_addr.s_addr = inet_addr(g_ServerIP);
        g_ServerSocket.sin_port = htons(g_ServerPortNo);

        retval = bind(g_Socket_fd, (struct sockaddr *)&g_ServerSocket, sizeof(g_ServerSocket));
        if(retval < 0)
        {
            printf("SHAILESH:Server Bind Error\n");
            return;
        }

        printf("SHAILESH:Waiting for TCP client to connect..\n");

        if(listen(g_Socket_fd, MAX_PENDING) < 0)
        {
            printf("SHAILESH:Listening Error\n");
            return;
        }

        if((g_AcceptSocket = accept(g_Socket_fd, NULL, NULL) == 0))
        {
            printf("SHAILESH:Failed to accept connection from client\n");
            return;
        }

        printf("SHAILESH:Socket connection accepted!!\n");

        mainloop();

        /* Suspend the lwip task */
        OSTaskSuspend(NULL, &osErr);

        if (osErr != OS_ERR_NONE)
        {
           printf("suspend failed\n");
        }
        return;

    }

    int mainloop(void)
    {
    unsigned char *ImageDataPointer;
    unsigned int frame_cnt = 1;

    while(1) {

      ImageDataPointer = (unsigned char *)read_frame();

      if(NULL == ImageDataPointer)
      {
       printf("Error receiving Image data NULL\n");
       return -1;
      }
      printf("SHAILESH: Received Frame No: %d\n", frame_cnt);
      frame_cnt++;

    }
    return -1;

    }

    void * read_frame(void)
    {
    int s32NoOfBytes = 0;
    unsigned int u32BufferSize;
    int s32ReceivedData;
    static unsigned char *ptr_u8BufferData = NULL;

    /* Buffer size to read from socket */
    u32BufferSize = NO_OF_BYTES_TO_READ_AT_SINGLECALL;

    s32ReceivedData = 0;
    ptr_u8BufferData = &ImageData[0];

    do {

      if((s32NoOfBytes = recv(g_Socket_fd, ptr_u8BufferData, (u32BufferSize - s32ReceivedData), MSG_WAITALL
    )) < 0)
      {
        printf("Failed to receive data bytes from client\n");
        break;
      }

      ptr_u8BufferData += s32NoOfBytes;
      s32ReceivedData += s32NoOfBytes;

    } while((s32ReceivedData < u32BufferSize - 1) && (s32NoOfBytes > 0));

    printf("Received %d bytes\n", s32ReceivedData);

    return ImageData;
    }

    ***************************************************************************************************************************************

    Following is the console output for the above program:

    ####################### LOG OUTPUT ON CONSOLE ##############################

    Loading application: "E:\Analog Devices\CrossCore Embedded Studio\Ethernet_Core0\Debug\Ethernet_Core0.dxe"

    Configuring switches for the ethernet operation

    SHAILESH:Waiting for LWIP for finish booting....

    Waiting for the link to be established

    Link established

    IP ADDRESS: 192.168.0.1

    SHAILESH:Creating socket....

    SHAILESH:Waiting for TCP client to connect..

    SHAILESH:Socket connection accepted!!

    Assertion "netconn_accept: invalid recvmbox" failed at line 354 in C:\Hudson\workspace\lwIP 1.0.1\scripts\temp\SSL_temp_Sources_Checkout\sources\Blackfin\lib\lwip\src\api\api_lib.c

    #################################################################################

    Following error is observed when the client connects to the servers and the server is trying to receive the data.

    The "recv()" is not able to return with the requested number of bytes and instead generating the error :

    Assertion "netconn_accept: invalid recvmbox" failed at line 354 in C:\Hudson\workspace\lwIP 1.0.1\scripts\temp\SSL_temp_Sources_Checkout\sources\Blackfin\lib\lwip\src\api\api_lib.c

    I have tried changing the no of bytes for which the recv call blocks from 32 bytes to 64K bytes, but the same error is generated.

    Can you help me in resolving the error ? I am unable to understand the reason for such a error.

    Do let me know if you require any more inputs in this regard.

    Thanks and Regards,

    Shailesh


  • 0
    •  Analog Employees 
    on Mar 19, 2013 9:30 AM

    Hi,

    Please use the 'Use advanced editor' option to reply, and provide a complete example project, as we will need to take a look at your project configuration.

    You should ensure that your heap/stack are configured as per the examples, as LwIP requires a lot of memory allocated in SDRAM.

    Regards,

    Craig.

  • Hi Craig,

    As requested have attached the entire project for your reference.

    Kindly go through the same, and help in resolving the issue.

    Do let me know if you need any more information.

    Thanks,

    Shailesh

  • Hi Craig,

    Any update on the above issue, are you able to identify the cause for the error?

    Shailesh