Strange WICED resets

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
MaFa_974161
Level 5
Level 5
100 sign-ins 50 replies posted 50 questions asked

Hello.

I write simple code to configure WICED as P2P GC.

In p2p_result_callback I start a task that connects to a server and initiates a cycle where it expects a TCP packet from server and responds with another TCP packet.

After two or three packets the WICED resets itself and I not understand what is the problem.

Can someone help me ?

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

Hello:

  I have add the while circle into my tcpclient app test.  it is running well ..

attach my file here.

I think this HIGHEST_PRIORITY is suspicous .  suggest:

#define WICED_APPLICATION_PRIORITY     (7)

    if ( wiced_rtos_create_thread ( &tcpConnectThread, WICED_RTOS_HIGHEST_PRIORITY, "TCP_SEND", (wiced_thread_function_t)&tcpConnect, 1024, NULL ) != WICED_SUCCESS )

*   WICED thread priority table

*

* +----------+-----------------+

* | Priority |      Thread     |

* |----------|-----------------|

* |     0    |      Wiced      |   Highest priority

* |     1    |     Network     |

* |     2    |                 |

* |     3    | Network worker  |

* |     4    |                 |

* |     5    | Default Library |

* |          | Default worker  |

* |     6    |                 |

* |     7    |   Application   |

* |     8    |                 |

* |     9    |      Idle       |   Lowest priority

* +----------+-----------------+

*/

#define WICED_RTOS_HIGHEST_PRIORITY        (0)

#define WICED_NETWORK_WORKER_PRIORITY      (3)

#define WICED_DEFAULT_WORKER_PRIORITY      (5)

#define WICED_DEFAULT_LIBRARY_PRIORITY     (5)

#define WICED_APPLICATION_PRIORITY         (7)

View solution in original post

0 Likes
4 Replies
MaFa_974161
Level 5
Level 5
100 sign-ins 50 replies posted 50 questions asked

OK,

I have another thread that sends 1KByte UDP packet every 25ms.

If I stop this thread the problem disappears.

How solve it ?

I have also to send 1kByte UDPO packets ...

Have I to use semaphores ??

0 Likes

if it is suitable you can send me all your code , I can have a try also.

0 Likes

#include "wiced.h"

#include "p2p_structures.h"

#include "../libraries/utilities/connection_manager/connection_manager.h"

#include "../WICED/platform/include/platform_peripheral.h"

#include "wiced_platform.h"

#define TCP_CONNECTION_NUMBER_OF_RETRIES    3       /* Numero di tentativi di connessione al Server TCP */

#define TCP_CLIENT_CONNECT_TIMEOUT          500     /* Tempo di attesa della conferma di connessione al Server */

#define UDP_TARGET_PORT                     50001

#define TCP_TARGET_PORT                     50002

static wiced_thread_t udpSendThread;

static wiced_thread_t tcpConnectThread;

static void p2p_result_callback(connection_p2p_result_t result);

static void udpSend(uint args);

static void tcpConnect(uint args);

void application_start(void)

{

    /* Initializes the WICED system */

    wiced_init ( );

    /* Lauch CONNECTION_P2P_GC */

    if ( connection_launch ( CONNECTION_P2P_GC ) != WICED_SUCCESS )

    {

        WPRINT_APP_INFO( ("connection_launch failed\n") );

        return;

    }

    /* Register connection callback */

    connection_register_p2p_result_callback ( p2p_result_callback );

}

static void p2p_result_callback(connection_p2p_result_t result)

{

    if ( result == CONNECTION_P2P_CONNECTED )

    {

        WPRINT_APP_INFO( ("p2p_result_callback(CONNECTION_P2P_CONNECTED)\n") );

        /* Crete UDP_SEND thread */

        if ( wiced_rtos_create_thread ( &udpSendThread, WICED_NETWORK_WORKER_PRIORITY, "UDP_SEND", (wiced_thread_function_t)&udpSend, 1024, NULL ) != WICED_SUCCESS )

        {

            WPRINT_APP_INFO( ("wiced_rtos_create_thread UDP_SEND failed\n") );

            return;

        }

        /* Create TCP_SEND thread */

        if ( wiced_rtos_create_thread ( &tcpConnectThread, WICED_RTOS_HIGHEST_PRIORITY, "TCP_SEND", (wiced_thread_function_t)&tcpConnect, 1024, NULL ) != WICED_SUCCESS )

        {

            WPRINT_APP_INFO( ("wiced_rtos_create_thread UDP_SEND failed\n") );

            return;

        }

    }

}

static void tcpConnect(uint args)

{

    wiced_tcp_socket_t          tcp_socket;

    wiced_packet_t*             request_packet;

    wiced_packet_t*             answer_packet;

    wiced_result_t              result;

    wiced_ip_address_t          gateway;

    uint16_t                    request_data_length;

    uint16_t                    available_data_length;

    int                         connection_retries;

    char*                       request_data;

    char*                       answer_data;

   

    UNUSED_PARAMETER ( args );

    WPRINT_APP_INFO( ("start of tcpConnect thread\n") );

    /* Get gateway */

    if ( wiced_ip_get_gateway_address ( WICED_P2P_INTERFACE, &gateway ) != WICED_SUCCESS )

    {

        WPRINT_APP_INFO( ("wiced_ip_get_gateway_address failed\n") );

        return;

    }

    /* Create TCP socket */

    if ( wiced_tcp_create_socket ( &tcp_socket, WICED_P2P_INTERFACE ) != WICED_SUCCESS )

    {

        WPRINT_APP_INFO( ("wiced_tcp_create_socket failed\n") );

        return;

    }

    /* Bind to the socket */

    if ( wiced_tcp_bind ( &tcp_socket, TCP_TARGET_PORT ) != WICED_SUCCESS )

    {

        WPRINT_APP_INFO( ("wiced_tcp_bind failed\n") );

        return;

    }

    connection_retries = 0;

    do

    {

        result = wiced_tcp_connect ( &tcp_socket, &gateway, TCP_TARGET_PORT, TCP_CLIENT_CONNECT_TIMEOUT );

        connection_retries++;

    }

    while ( ( result != WICED_SUCCESS ) );//&& ( connection_retries < TCP_CONNECTION_NUMBER_OF_RETRIES ) );

//    if( result != WICED_SUCCESS)

//    {

//        WPRINT_APP_INFO( ("Unable to connect to the server! Halt.\n") );

//        return;

//    }

    /* Ciclo */

    while(WICED_TRUE)

    {

        /* Receive Server's Request */

        if ( wiced_tcp_receive ( &tcp_socket, &request_packet, WICED_NEVER_TIMEOUT ) != WICED_SUCCESS )

        {

            WPRINT_APP_INFO ( ("wiced_tcp_receive failed\n") );

            /* Delete packet, since the receive failed */

            wiced_packet_delete ( request_packet );

            /* Close the connection */

            wiced_tcp_disconnect ( &tcp_socket );

            return;

        }

        /* Get the contents of the received packet */

        if ( wiced_packet_get_data ( request_packet, 0, (uint8_t**)&request_data, &request_data_length, &available_data_length ) != WICED_SUCCESS )

        {

            WPRINT_APP_INFO( ("wiced_packet_get_data failed\n") );

            /* Delete packet, since the receive failed */

            wiced_packet_delete ( request_packet );

            /* Close the connection */

            wiced_tcp_disconnect ( &tcp_socket );

            return;

        }

        /* Verify len */

        if ( request_data_length != available_data_length )

        {

            WPRINT_APP_INFO( ("Fragmented packets not supported\n") );

            /* Delete packet, since the receive failed */

            wiced_packet_delete ( request_packet );

            /* Close the connection */

            wiced_tcp_disconnect ( &tcp_socket );

            return;

        }

        #define ANSWER_LEN 8 /* Numero di byte del pacchetto di risposta FPGA su TCP, TODO: calcolare in base al protocollo */

        /* Create the TCP packet. Memory for the tx_data is automatically allocated */

        if ( wiced_packet_create_tcp ( &tcp_socket, ANSWER_LEN, &answer_packet, (uint8_t**)&answer_data, &available_data_length ) != WICED_SUCCESS )

        {

            WPRINT_APP_INFO( ("wiced_packet_create_tcp failed\n") );

            return;

        }

        /* Verify len */

        if ( available_data_length < ANSWER_LEN )

        {

            WPRINT_APP_INFO( ("available_data_length < ANSWER_LEN\n") );

            /* Delete packet, since the send failed */

            wiced_packet_delete ( answer_packet );

            /* Close the connection */

            wiced_tcp_disconnect ( &tcp_socket );

            return;

        }

        /* Set the end of the data portion */

        if ( wiced_packet_set_data_end ( answer_packet, (uint8_t*)answer_data + ANSWER_LEN ) != WICED_SUCCESS )

        {

            WPRINT_APP_INFO( ("wiced_packet_set_data_end failed\n") );

            return;

        }

        /* Delete the REQUEST */

        if ( wiced_packet_delete ( request_packet ) != WICED_SUCCESS)

        {

            WPRINT_APP_INFO( ("wiced_packet_delete failed\n") );

            return;

        }

        /* Send the TCP packet */

        if ( wiced_tcp_send_packet ( &tcp_socket, answer_packet ) != WICED_SUCCESS )

        {

            WPRINT_APP_INFO( ("wiced_tcp_send_packet failed\n") );

            /* Delete packet, since the send failed */

            wiced_packet_delete ( answer_packet );

            /* Close the connection */

            wiced_tcp_disconnect ( &tcp_socket );

            return;

        }

    }

}

static void udpSend(uint args)

{

    wiced_udp_socket_t  udp_socket;

    wiced_ip_address_t  gateway;

    wiced_packet_t*     packet;

    uint16_t            available_data_length;

    UNUSED_PARAMETER ( args );

    WPRINT_APP_INFO( ("start of udpSend thread\n") );

    /* Get gateway */

    if ( wiced_ip_get_gateway_address ( WICED_P2P_INTERFACE, &gateway ) != WICED_SUCCESS )

    {

        WPRINT_APP_INFO( ("wiced_ip_get_gateway_address failed\n") );

        return;

    }

    /* Create UDP socket */

    if ( wiced_udp_create_socket ( &udp_socket, UDP_TARGET_PORT, WICED_P2P_INTERFACE ) != WICED_SUCCESS )

    {

        WPRINT_APP_INFO( ("wiced_udp_create_socket failed\n") );

        return;

    }

    /* Send UDP */

    while(WICED_TRUE)

    {

        /* Create the UDP packet */

        if ( wiced_packet_create_udp ( &udp_socket, 1024, &packet, (uint8_t**) &udp_data, &available_data_length ) != WICED_SUCCESS )

        {

            WPRINT_APP_INFO( ("wiced_packet_create_udp failed\n") );

            return;

        }

        /* Set the end of the data portion */

        wiced_packet_set_data_end ( packet, (uint8_t*) udp_data + 1024 );

        /* Send the UDP packet */

        if ( wiced_udp_send ( &udp_socket, &gateway, UDP_TARGET_PORT, packet ) != WICED_SUCCESS )

        {

            WPRINT_APP_INFO( ("wiced_udp_send failed\n") );

            wiced_packet_delete( packet ); /* Delete packet, since the send failed */

            return;

        }

        /* Delay */

        wiced_rtos_delay_milliseconds ( 25 );

    }

    /*

     * NOTE : It is not necessary to delete the packet created above, the packet

     *        will be automatically deleted *AFTER* it has been successfully sent

     */

}

0 Likes
lock attach
Attachments are accessible only for community members.

Hello:

  I have add the while circle into my tcpclient app test.  it is running well ..

attach my file here.

I think this HIGHEST_PRIORITY is suspicous .  suggest:

#define WICED_APPLICATION_PRIORITY     (7)

    if ( wiced_rtos_create_thread ( &tcpConnectThread, WICED_RTOS_HIGHEST_PRIORITY, "TCP_SEND", (wiced_thread_function_t)&tcpConnect, 1024, NULL ) != WICED_SUCCESS )

*   WICED thread priority table

*

* +----------+-----------------+

* | Priority |      Thread     |

* |----------|-----------------|

* |     0    |      Wiced      |   Highest priority

* |     1    |     Network     |

* |     2    |                 |

* |     3    | Network worker  |

* |     4    |                 |

* |     5    | Default Library |

* |          | Default worker  |

* |     6    |                 |

* |     7    |   Application   |

* |     8    |                 |

* |     9    |      Idle       |   Lowest priority

* +----------+-----------------+

*/

#define WICED_RTOS_HIGHEST_PRIORITY        (0)

#define WICED_NETWORK_WORKER_PRIORITY      (3)

#define WICED_DEFAULT_WORKER_PRIORITY      (5)

#define WICED_DEFAULT_LIBRARY_PRIORITY     (5)

#define WICED_APPLICATION_PRIORITY         (7)

0 Likes