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

RL_TCP CRASHES

Dear All
I have created 3 tasks,

this is task one it has a osPriorityBelowNormal

        for(;;)
        {
                main_TcpNet ();
        }

This is task 2 it has a osPriorityHigh

        for(;;)
        {
                /* Timer tick every 100 ms */
                timer_tick ();
                osDelay(100);
        }

this is the task 3 it has osPriorityNormal

        U8 Rem_IP[4] = {192,168,0,1};//The PC IP
        uint8_t *sendbuf;

        tcp_soc = tcp_get_socket (TCP_TYPE_CLIENT_SERVER | TCP_TYPE_KEEP_ALIVE, 0, 30, tcp_callback);

        tcp_listen (tcp_soc, 1943);


        for(;;)
        {
                osDelay(1000);

                switch (tcp_get_state (tcp_soc);)
                {
                 case TCP_STATE_FREE:
                 case TCP_STATE_CLOSED:
                 case TCP_STATE_LISTEN:
                        tcp_connect (tcp_soc, Rem_IP, 2121, 0);
                 break;

                case TCP_STATE_CONNECT:
                  if (tcp_check_send (tcp_soc) == __TRUE)
                 {
                   sendbuf = tcp_get_buf(1460);
                   //Fill buffer in here

                  tcp_send (tcp_soc, sendbuf, 1460);
                  }
                 break;

                }
        }

But when the application runs for some time it will crash and it would tell that
/* Locked Memory management function (alloc/free) re-entered. */ /* RTX multithread protection malfunctioning, not implemented */ /* or interrupt disable is not functioning correctly. */

What's wrong? do you have any idea?

Parents
  • Use a mutex to protect network functions, because they are not re-entrant.

    Protect main TCPnet stack engine:

            for(;;)
            {
                    osMutexWait (mutex_TcpNet, osWaitForever);
                    main_TcpNet ();
                    osMutexRelease (mutex_TcpNet);
            }
    

    and also your code in task 3:

                    osMutexWait (mutex_TcpNet, osWaitForever);
                    switch (tcp_get_state (tcp_soc);)
                    {
                     case TCP_STATE_FREE:
                     case TCP_STATE_CLOSED:
                     case TCP_STATE_LISTEN:
                            tcp_connect (tcp_soc, Rem_IP, 2121, 0);
                     break;
    
                    case TCP_STATE_CONNECT:
                      if (tcp_check_send (tcp_soc) == __TRUE)
                     {
                       sendbuf = tcp_get_buf(1460);
                       //Fill buffer in here
    
                      tcp_send (tcp_soc, sendbuf, 1460);
                      }
                     break;
                    }
                    osMutexRelease (mutex_TcpNet);
    

    or use BSD sockets, which are already protected.

Reply
  • Use a mutex to protect network functions, because they are not re-entrant.

    Protect main TCPnet stack engine:

            for(;;)
            {
                    osMutexWait (mutex_TcpNet, osWaitForever);
                    main_TcpNet ();
                    osMutexRelease (mutex_TcpNet);
            }
    

    and also your code in task 3:

                    osMutexWait (mutex_TcpNet, osWaitForever);
                    switch (tcp_get_state (tcp_soc);)
                    {
                     case TCP_STATE_FREE:
                     case TCP_STATE_CLOSED:
                     case TCP_STATE_LISTEN:
                            tcp_connect (tcp_soc, Rem_IP, 2121, 0);
                     break;
    
                    case TCP_STATE_CONNECT:
                      if (tcp_check_send (tcp_soc) == __TRUE)
                     {
                       sendbuf = tcp_get_buf(1460);
                       //Fill buffer in here
    
                      tcp_send (tcp_soc, sendbuf, 1460);
                      }
                     break;
                    }
                    osMutexRelease (mutex_TcpNet);
    

    or use BSD sockets, which are already protected.

Children