LWIP + RTOS with two interfaces (Serial + Ethernet). Memory allocation understanding with RTOS

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

System Information:
MCU: ATSAM4E16E
ASF version: 3.43
OS: RTOS
lwip version: 2.1.0
libwebsocket version: 4.1.2

Hi guys, I got a problem to use two network interfaces. 
- Actually I have Serial interface via GSM modem + libwebsocket. (It works alone)
- Also I have Ethernet interface and TCP/IP stack. (It also works alone)

BUT if I enable two interfaces, seems some stuck on Serial interface connection via libwebsocket.
Actually I have allocated some peace of problem, on function:

lws_header_table_attach(struct lws *wsi, int autoservice)
{

    ...

    wsi->http.ah = _lws_create_ah(pt, context->max_http_header_data);

    if (!wsi->http.ah) { /* we could not create an ah */
        _lws_header_ensure_we_are_on_waiting_list(wsi);

        goto bail;
    }

    ...
}

wsi->http.ah turns to zero. "v = (void *)realloc(ptr, size);" dynamic memory returns zero, the function of libwebsocket below, also defined macro added at the top for info:

// DEFINED: LWS_PLAT_FREERTOS
//          LWS_AMAZON_RTOS
//          LWS_HAVE_MALLOC_USABLE_SIZE

// UNDEFINED: LWS_PLAT_OPTEE

static void *
_realloc(void *ptr, size_t size, const char *reason)
{
	void *v;

	if (size) {
#if defined(LWS_PLAT_FREERTOS)
		lwsl_debug("%s: size %lu: %s (free heap %d)\n", __func__,
#if defined(LWS_AMAZON_RTOS)
			    (unsigned long)size, reason, (unsigned int)xPortGetFreeHeapSize() - (int)size);
#else
			    (unsigned long)size, reason, (unsigned int)esp_get_free_heap_size() - (int)size);
#endif
#else
		lwsl_debug("%s: size %lu: %s\n", __func__,
			   (unsigned long)size, reason);
#endif

#if defined(LWS_HAVE_MALLOC_USABLE_SIZE)
		if (ptr)
			allocated -= malloc_usable_size(ptr);
#endif

#if defined(LWS_PLAT_OPTEE)
		v = (void *)TEE_Realloc(ptr, size);
#else
		v = (void *)realloc(ptr, size);
#endif
#if defined(LWS_HAVE_MALLOC_USABLE_SIZE)
		allocated += malloc_usable_size(v);
#endif
		return v;
	}
	if (ptr) {
#if defined(LWS_HAVE_MALLOC_USABLE_SIZE)
		allocated -= malloc_usable_size(ptr);
#endif
		free(ptr);
	}

	return NULL;
}

Guys, where allocated memory using function realloc() ?? During debug this functions goes to compiler header and I can't understand where is memory allocated if also RTOS occur? 
I have attached lwip cionfig and rtos config.

Thanks in advance, will hope I'll solve this problem with you guys...

 

Attachment(s): 

Last Edited: Mon. Dec 13, 2021 - 11:58 AM