This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

MCB2300 TCPnet application with RTX not working

Hi !
I'am compiling a TCP application based on the http demo.
My problem is that the application is not responding to ARP request, as it if was dead.
Indeed, I've put a led toggle in timer_task and tcp_task and they are alive.
I've tested many thing :
Put init_TCPnet() before os_init()
Use Round-Robin
put tcp_get_socket in the main()

Here is the code of my main.c :

#include <RTL.h>
#include <stdio.h>
#include <LPC23xx.H>

#include "ui/ui.h"
#include "led/led.h"

// Define here the priority for your task
//! Init Task must have the higher priority
#define PRIO_INIT 100
#define PRIO_TIMER_TSK 30
#define PRIO_UI_TSK     1
#define PRIO_CONTROL_LOOP 99


//! stack for the ui task
/*!
   howto declare : see os_tsk_create_user.
*/
U64 g_ui_stack[800/8];

__task void init (void) ;


int main (void) {

   /* Start with 'init' task. */
   os_sys_init(init);
   while(1);
}

__task void init (void)
{
   /* Add System initialisation code here */
   init_TcpNet ();
   LED_Init() ;
   LED_Out(0) ;
   /* Initialize Tasks */
   os_tsk_prio_self (PRIO_INIT); // Set ourself to higher priority
   os_tsk_create (ui_timer_task, PRIO_TIMER_TSK);
   os_tsk_create_user (ui_task, PRIO_UI_TSK, &g_ui_stack, sizeof(g_ui_stack));
   os_tsk_delete_self(); // delete myself and start other task execution.
}

Here is the code for my ui :

#include <RTL.h>
#include <Net_Config.h>
#include <string.h>
#include "ui.h"
#include "led/led.h"

//! Order received by GUI & target returns
typedef enum
{
        STOP = 0, //!< Stop experience
        LAST
} T_ORDER;

//! Define parameters for a task

typedef struct
{
        U32 uiEnable    ;
...
} T_TASK_PARAM ;

// Order + size fields
#define FRAME_HEADER_SIZE 8

//! Structure of the Received orders.
typedef struct
{
        T_ORDER order;
...
} T_CLIENT_FRAME ;

//! Sent Frame
typedef struct
{
   U32 uiOSClock ;
...
} T_SERVER_FRAME ;



#define NB_CONTROL_LOOP 10000


//! GUI socket
static U8 g_socket_tcp;
static T_CLIENT_FRAME g_ClientFrame ;
static T_SERVER_FRAME g_ServerFrame ;
static U8 g_BytesRead ;


U16 ui_callback (U8 soc, U8 evt, U8 *ptr, U16 par) ;
static void tcp_launch_tasks(void) ;
static void tcp_stop_tasks(void) ;
static void tcp_send_data(void) ;

#ifndef htonl
    #define htonl(a)                    \ 
        ((((a) >> 24) & 0x000000ff) |   \ 
         (((a) >>  8) & 0x0000ff00) |   \ 
         (((a) <<  8) & 0x00ff0000) |   \ 
         (((a) << 24) & 0xff000000))
#endif

#ifndef ntohl
    #define ntohl(a)    htonl((a))
#endif

#ifndef htons
    #define htons(a)                \ 
        ((((a) >> 8) & 0x00ff) |    \ 
         (((a) << 8) & 0xff00))
#endif

#ifndef ntohs
    #define ntohs(a)    htons((a))
#endif


__task void ui_task (void)
{

        unsigned int i = 0 ;
        g_BytesRead = 0 ;
        memset(&g_ClientFrame, 0, sizeof(g_ClientFrame)) ;
        memset(&g_ServerFrame, 0, sizeof(g_ServerFrame)) ;

        /* Initialize TCP server Socket and start listening */
        g_socket_tcp = tcp_get_socket (TCP_TYPE_SERVER, 0, UI_SOCKET_TIMEOUT, ui_callback);
        if (g_socket_tcp != 0)
        {
                tcp_listen (g_socket_tcp, PORT_NUM);
                while (1)
                {
                        main_TcpNet() ;
                        os_tsk_pass() ; // schedule
                        ++i ;
                        if (i > 100000)
                        {
                                LED_Toggle (1) ;
                                i = 0 ;
                        }
                }
        }
}

__task void ui_timer_task (void)
{
   /* System tick timer task */
   os_itv_set (10);
   while (1)
   {
      timer_tick () ;
      os_itv_wait (); // Wait and schedule
          LED_Toggle (0) ;
   }
}


static void ui_process_frame (void)
{

        // Toogle led
        LED_Toggle (1) ;


        // convert indianness
        g_ClientFrame.order = (T_ORDER) ntohl(g_ClientFrame.order) ;
        g_ClientFrame.size      = ntohl(g_ClientFrame.size) ;
        switch(g_ClientFrame.order)
        {
                case START :   // only convert data to be interpreted
...
                        tcp_launch_tasks() ;
                        break ;
                case STOP :
                        tcp_stop_tasks() ;
                        break ;
                case DATA :
                        tcp_send_data() ;
        }
}

U16 ui_callback (U8 soc, U8 evt, U8 *ptr, U16 par)
{
   /* This function is called by the TCP module on TCP event */
   /* Check the 'Net_Config.h' for possible events.          */

   if (soc != g_socket_tcp) {
      return (0);
   }

        switch (evt)
        {
                case TCP_EVT_DATA:
                        /* TCP data frame has arrived :
                                We frame receive portion of the frame so we shall control data received
...
                        break;
                case TCP_EVT_CONREQ:
                        /* Remote peer requested connect, accept it if socket available */
                        switch( tcp_get_state(g_socket_tcp) )
                        {
                                case TCP_STATE_CLOSED:
                                case TCP_STATE_LISTEN:
                                        return (1);
                                default :
                                        return 0 ;
                        }
                case TCP_EVT_CONNECT:
                        /* The TCP socket is connected */
                        return (1);
                case TCP_EVT_CLOSE :
                case TCP_EVT_ABORT :
                        /* Keep the socket allocated for further connection */
                        break ;
                default:
                        break ;
        }
   return (0);
}


static void tcp_launch_tasks(void)
{

}

static void tcp_stop_tasks(void)
{

}

static void tcp_send_data(void)
{
        U8 * sendbuf ;
        U32 size = FRAME_HEADER_SIZE + g_ClientFrame.size ;
        g_ClientFrame.order     = (T_ORDER) htonl(g_ClientFrame.order) ;
        g_ClientFrame.size      = htonl(g_ClientFrame.size) ;

        // check socket availability
        if (tcp_check_send(g_socket_tcp) == __TRUE)
        {
                sendbuf = tcp_get_buf(size) ;
                memcpy(sendbuf,&g_ClientFrame,size) ;
                if ( tcp_send(g_socket_tcp, sendbuf, size) == __FALSE)
                {
                        // hdle frame send error.
                }
        }
        // else abord sending... CAN add some code to place the frame in a buffer.
}

I'm getting crazy comparing with http demo without find THE Difference !!
Thanks for any help !

0