esp32/bt/driver: support static allocation of FreeRTOS queues used by ISR routine

Support static allocation of FreeRTOS queues used by ISR routine in WiFi/BT/esp_timer/driver etc
This commit is contained in:
Liu Zhi Fu
2018-03-30 11:39:42 +08:00
parent cc2d1fda96
commit ed46976f41
7 changed files with 336 additions and 2 deletions

View File

@@ -12,9 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string.h>
#include "esp_attr.h"
#include "esp_heap_caps.h"
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "esp_wifi.h"
#include "esp_wifi_internal.h"
/*
If CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST is enabled. Prefer to allocate a chunk of memory in SPIRAM firstly.
@@ -54,3 +59,58 @@ IRAM_ATTR void *wifi_calloc( size_t n, size_t size )
return calloc(n, size);
#endif
}
wifi_static_queue_t* wifi_create_queue( int queue_len, int item_size)
{
wifi_static_queue_t *queue = NULL;
queue = (wifi_static_queue_t*)heap_caps_malloc(sizeof(wifi_static_queue_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
if (!queue) {
return NULL;
}
#if CONFIG_SPIRAM_USE_MALLOC
queue->storage = heap_caps_calloc(1, sizeof(StaticQueue_t) + (queue_len*item_size), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
if (!queue->storage) {
goto _error;
}
queue->handle = xQueueCreateStatic( queue_len, item_size, ((uint8_t*)(queue->storage)) + sizeof(StaticQueue_t), (StaticQueue_t*)(queue->storage));
if (!queue->handle) {
goto _error;
}
return queue;
_error:
if (queue) {
if (queue->storage) {
free(queue->storage);
}
free(queue);
}
return NULL;
#else
queue->handle = xQueueCreate( queue_len, item_size);
return queue;
#endif
}
void wifi_delete_queue(wifi_static_queue_t *queue)
{
if (queue) {
vQueueDelete(queue->handle);
#if CONFIG_SPIRAM_USE_MALLOC
if (queue->storage) {
free(queue->storage);
}
#endif
free(queue);
}
}