forked from espressif/esp-idf
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:
@@ -62,6 +62,7 @@ config SPIRAM_USE_CAPS_ALLOC
|
||||
bool "Make RAM allocatable using heap_caps_malloc(..., MALLOC_CAP_SPIRAM)"
|
||||
config SPIRAM_USE_MALLOC
|
||||
bool "Make RAM allocatable using malloc() as well"
|
||||
select SUPPORT_STATIC_ALLOCATION
|
||||
endchoice
|
||||
|
||||
choice SPIRAM_TYPE
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <string.h>
|
||||
#include "esp_types.h"
|
||||
#include "esp_attr.h"
|
||||
#include "esp_err.h"
|
||||
@@ -82,6 +83,12 @@ static esp_timer_handle_t s_timer_in_callback;
|
||||
static TaskHandle_t s_timer_task;
|
||||
// counting semaphore used to notify the timer task from ISR
|
||||
static SemaphoreHandle_t s_timer_semaphore;
|
||||
|
||||
#if CONFIG_SPIRAM_USE_MALLOC
|
||||
// memory for s_timer_semaphore
|
||||
static StaticQueue_t s_timer_semaphore_memory;
|
||||
#endif
|
||||
|
||||
// lock protecting s_timers, s_inactive_timers, s_timer_in_callback
|
||||
static portMUX_TYPE s_timer_lock = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
@@ -329,7 +336,12 @@ esp_err_t esp_timer_init(void)
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
#if CONFIG_SPIRAM_USE_MALLOC
|
||||
memset(&s_timer_semaphore_memory, 0, sizeof(StaticQueue_t));
|
||||
s_timer_semaphore = xSemaphoreCreateCountingStatic(TIMER_EVENT_QUEUE_SIZE, 0, &s_timer_semaphore_memory);
|
||||
#else
|
||||
s_timer_semaphore = xSemaphoreCreateCounting(TIMER_EVENT_QUEUE_SIZE, 0);
|
||||
#endif
|
||||
if (!s_timer_semaphore) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,11 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
QueueHandle_t handle; /**< FreeRTOS queue handler */
|
||||
void *storage; /**< storage for FreeRTOS queue */
|
||||
} wifi_static_queue_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize Wi-Fi Driver
|
||||
* Alloc resource for WiFi driver, such as WiFi control structure, RX/TX buffer,
|
||||
|
||||
Submodule components/esp32/lib updated: e9e4579336...8cd9fd455e
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user