RTOS SDK / ESPCONN: allocating in RX callback?

esp03madness
Posts: 8
Joined: Tue Nov 24, 2015 11:42 am

RTOS SDK / ESPCONN: allocating in RX callback?

Postby esp03madness » Tue Jan 12, 2016 2:20 pm

I am trying to decide how to ferry data that arrives in the "espconn network receive callback" to a processing thread. The callback has the following prototype:

Code: Select all

static void
network_resoved_cb (void* arg, char* data, usigned short len)


I assume (please correct me if this is wrong) that "data" will be freed when the callback returns. Therefore, I need to move "data" to a safe place where it can wait for delayed processing.

I am thinking of doing something like this:

Code: Select all

receive_callback(data, len):
  //using heap_4.c
  saved_data = pvPortMalloc(len)
  copy data -> saved_data
  xQueueSendToBack(saved_data)
 
processing_thread:
  saved_data = xQueueReceive()
  //do something with saved_data
  vPortFree(saved_data)


Is this a bad idea? Use of heap_4.c is supposed to limit heap fragmentation, but I thought it would be better to ask first.

Who is online

Users browsing this forum: No registered users and 16 guests