Reply
New Contributor
Digilog
Posts: 2
Registered: ‎07-04-2008

CP2200 Ethernet problem

I am doing a project using the CP2200 AB4 development board with the C8051FX20 development board.
I have enabled HTTP,DCHP, Netfinder and TCP/UDP options in the TCP stack library and am successfully sending and receiving TCP packets.
My problem is that after a certain time of not sending any packets the TCP socket stops monitoring the network and I am unable to test for this condition to reopen a socket.
If I test the socket->tcp_state or socket->socket_state they say that the socket is open but I am unable to communicate to the socket.
I have tried a large number of variations of my code but the result is the same.
My PC application opens a TCP socket connection, transmits a packet, waits for a reply and then closes the socket.

On the CP2200 end the code receives the packet and transmits the reply thus:
SCHAR callback_app_server_process_packet(PSOCKET_INFO socket_ptr)
{
// Handle Incoming Netfinder Packets
if(socket_ptr->socket_no == netfinder_socketno){
netfinder_process_packet();
}

if(data_buff[1] == 0xA2)
{

socket_ptr->send_ptr = socket_ptr->recv_ptr;
socket_ptr->send_len = socket_ptr->recv_len;
return (NEED_TO_SEND);
}

return (0);
}

After the socket is closed it is reopened thus:
SCHAR callback_app_server_idle(PSOCKET_INFO *psocket_ptr)
{

// Put your code here.
if (socket_ptr->socket_state == TCP_CLOSED)
TCP();


// If the link goes invalid, exit mn_server().
if(link_lost)
return (NEED_TO_EXIT);

psocket_ptr = psocket_ptr; // This statment prevents compiler warning.
return (0);
}

I have also found that the void callback_socket_closed(SCHAR socket_no) function appears to be called twice every time the socket is closed.

Can anyone please give me any ideas as to why the opened socket seems to become inactive after a certain time of being idle?

Also is there any information on the variables inside the typedef struct socket_info_s structure?

Thanks.
Esteemed Contributor
Tsuneo
Posts: 6,303
Registered: ‎02-15-2004

Re: CP2200 Ethernet problem

To send packets (segments), use callback_app_server_idle(), instead of callback_app_server_process_packet()

callback_app_server_process_packet() is used to receive packets.
Anyway, you have to check the socket_no before processing the packet.


I posted a brief summary about how to use the callbacks in this topic.
How to deal with?
posted June 20, 2007 10:59 AM

You'll see an example to handle closing/re-opening sockets in this topic.
tcp server: How to listen the port


I have enabled HTTP,DCHP, Netfinder and TCP/UDP options

So many options.
Did you increase the num_sockets in mn_userconst.h, as many as the number of the required sockets?

mn_userconst.h

// Sets the number of sockets that can be used. The value must be between
// 1 and 127. Each socket uses about 46 bytes of RAM.

#define num_sockets 3



is there any information on the variables inside the typedef struct socket_info_s structure?

You'll find it in CMX Micronet Coldfire MCF522xx demo, netlib folder, socket.h and tcp.h
It's common to the CMX stacks, even for other MCU implementation.
Sign up on the CMX download site to get it.
http://www.cmx.com/download.htm

Tsuneo

[This message has been edited by Tsuneo (edited July 04, 2008).]
New Contributor
Digilog
Posts: 2
Registered: ‎07-04-2008

Re: CP2200 Ethernet problem

Excellent!!
It all works without a problem now.

Thank you Tsuneo for your fantastic reply to my problem.
After rewriting my code along your guidelines I do not get any more TCP connection problems.

Thanks.