feat(openthread): Add support to allocate message pool from PSRAM
This commit is contained in:
@@ -11,7 +11,6 @@
|
||||
#include "esp_log.h"
|
||||
#include "esp_openthread_alarm.h"
|
||||
#include "esp_openthread_common_macro.h"
|
||||
#include "esp_openthread_flash.h"
|
||||
#include "esp_openthread_lock.h"
|
||||
#include "esp_openthread_radio.h"
|
||||
#include "esp_openthread_spi_slave.h"
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "esp_openthread_flash.h"
|
||||
#include "esp_partition.h"
|
||||
#include "openthread/instance.h"
|
||||
#include "openthread/platform/flash.h"
|
||||
#include "openthread/platform/settings.h"
|
||||
|
||||
#define ESP_OT_FLASH_PAGE_NUM 2
|
||||
#define ESP_OT_FLASH_PAGE_SIZE 4096
|
||||
|
||||
static const esp_partition_t *s_ot_partition = NULL;
|
||||
|
||||
void esp_openthread_flash_set_partition(const esp_partition_t *partition)
|
||||
{
|
||||
s_ot_partition = partition;
|
||||
}
|
||||
|
||||
void otPlatFlashInit(otInstance *instance)
|
||||
{
|
||||
assert(s_ot_partition != NULL);
|
||||
assert(s_ot_partition->size >= otPlatFlashGetSwapSize(instance));
|
||||
}
|
||||
|
||||
uint32_t otPlatFlashGetSwapSize(otInstance *instance)
|
||||
{
|
||||
return ESP_OT_FLASH_PAGE_SIZE;
|
||||
}
|
||||
|
||||
void otPlatFlashErase(otInstance *instance, uint8_t index)
|
||||
{
|
||||
uint32_t address = ESP_OT_FLASH_PAGE_SIZE * (index != 0);
|
||||
uint32_t size = ESP_OT_FLASH_PAGE_SIZE;
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
err = esp_partition_erase_range(s_ot_partition, address, size);
|
||||
|
||||
assert(err == ESP_OK);
|
||||
}
|
||||
|
||||
void otPlatFlashRead(otInstance *instance, uint8_t index, uint32_t offset, void *data, uint32_t size)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
offset += ESP_OT_FLASH_PAGE_SIZE * (index != 0);
|
||||
|
||||
err = esp_partition_read(s_ot_partition, offset, data, size);
|
||||
|
||||
assert(err == ESP_OK);
|
||||
}
|
||||
|
||||
void otPlatFlashWrite(otInstance *instance, uint8_t index, uint32_t offset, const void *data, uint32_t size)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
offset += ESP_OT_FLASH_PAGE_SIZE * (index != 0);
|
||||
|
||||
err = esp_partition_write(s_ot_partition, offset, data, size);
|
||||
|
||||
assert(err == ESP_OK);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include "esp_openthread_common_macro.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "openthread/instance.h"
|
||||
#include "openthread/platform/messagepool.h"
|
||||
|
||||
int s_buffer_pool_head = -1;
|
||||
otMessageBuffer **s_buffer_pool_pointer = NULL;
|
||||
|
||||
void otPlatMessagePoolInit(otInstance *aInstance, uint16_t aMinNumFreeBuffers, size_t aBufferSize)
|
||||
{
|
||||
otMessageBuffer *buffer_pool = (otMessageBuffer *)heap_caps_calloc(aMinNumFreeBuffers, aBufferSize, MALLOC_CAP_SPIRAM);
|
||||
s_buffer_pool_pointer = (otMessageBuffer **)heap_caps_calloc(aMinNumFreeBuffers, sizeof(otMessageBuffer **), MALLOC_CAP_SPIRAM);
|
||||
if (buffer_pool == NULL || s_buffer_pool_pointer == NULL) {
|
||||
ESP_LOGE(OT_PLAT_LOG_TAG, "Failed to create message buffer pool");
|
||||
assert(false);
|
||||
}
|
||||
for (uint16_t i = 0; i < aMinNumFreeBuffers; i++) {
|
||||
s_buffer_pool_pointer[i] = buffer_pool + i * aBufferSize / sizeof(otMessageBuffer);
|
||||
}
|
||||
s_buffer_pool_head = aMinNumFreeBuffers - 1;
|
||||
ESP_LOGI(OT_PLAT_LOG_TAG, "Create message buffer pool successfully, size %d", aMinNumFreeBuffers*aBufferSize);
|
||||
}
|
||||
|
||||
otMessageBuffer *otPlatMessagePoolNew(otInstance *aInstance)
|
||||
{
|
||||
otMessageBuffer *ret = NULL;
|
||||
if (s_buffer_pool_head >= 0) {
|
||||
ret = s_buffer_pool_pointer[s_buffer_pool_head];
|
||||
s_buffer_pool_head--;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void otPlatMessagePoolFree(otInstance *aInstance, otMessageBuffer *aBuffer)
|
||||
{
|
||||
s_buffer_pool_head++;
|
||||
s_buffer_pool_pointer[s_buffer_pool_head] = aBuffer;
|
||||
}
|
||||
|
||||
uint16_t otPlatMessagePoolNumFreeBuffers(otInstance *aInstance)
|
||||
{
|
||||
return s_buffer_pool_head + 1;
|
||||
}
|
||||
Reference in New Issue
Block a user