2022-12-19 07:29:52 -05:00
|
|
|
/*
|
2023-06-25 23:09:16 -04:00
|
|
|
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
2022-12-19 07:29:52 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2023-06-13 07:18:57 -04:00
|
|
|
#include "esp_check.h"
|
|
|
|
#include "esp_log.h"
|
2022-12-19 07:29:52 -05:00
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "esp_private/btbb.h"
|
|
|
|
|
|
|
|
#define BTBB_ENABLE_VERSION_PRINT 1
|
|
|
|
|
|
|
|
static _lock_t s_btbb_access_lock;
|
|
|
|
/* Reference count of enabling BT BB */
|
|
|
|
static uint8_t s_btbb_access_ref = 0;
|
|
|
|
|
2023-06-13 07:18:57 -04:00
|
|
|
|
2023-06-25 02:17:56 -04:00
|
|
|
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
2023-06-13 07:18:57 -04:00
|
|
|
#include "esp_private/sleep_retention.h"
|
|
|
|
#include "btbb_retention_reg.h"
|
|
|
|
static const char* TAG = "btbb_init";
|
|
|
|
|
|
|
|
#if SOC_PM_RETENTION_HAS_CLOCK_BUG
|
|
|
|
#define BTBB_LINK_OWNER ENTRY(3)
|
|
|
|
#else
|
|
|
|
#define BTBB_LINK_OWNER ENTRY(0) | ENTRY(2)
|
|
|
|
#endif // SOC_PM_RETENTION_HAS_CLOCK_BUG
|
|
|
|
|
|
|
|
static esp_err_t btbb_sleep_retention_init(void)
|
|
|
|
{
|
|
|
|
const static sleep_retention_entries_config_t btbb_regs_retention[] = {
|
|
|
|
[0] = { .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_MODEM_BT_BB_LINK(0x00), BB_PART_0_ADDR, BB_PART_0_ADDR, BB_PART_0_SIZE, 0, 0), .owner = BTBB_LINK_OWNER },
|
|
|
|
[1] = { .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_MODEM_BT_BB_LINK(0x01), BB_PART_1_ADDR, BB_PART_1_ADDR, BB_PART_1_SIZE, 0, 0), .owner = BTBB_LINK_OWNER },
|
2023-06-25 02:17:56 -04:00
|
|
|
[2] = { .config = REGDMA_LINK_CONTINUOUS_INIT(REGDMA_MODEM_BT_BB_LINK(0x02), BB_PART_2_ADDR, BB_PART_2_ADDR, BB_PART_2_SIZE, 0, 0), .owner = BTBB_LINK_OWNER },
|
2023-06-13 07:18:57 -04:00
|
|
|
};
|
2024-01-31 03:52:27 -05:00
|
|
|
esp_err_t err = sleep_retention_entries_create(btbb_regs_retention, ARRAY_SIZE(btbb_regs_retention), REGDMA_LINK_PRI_BT_MAC_BB, SLEEP_RETENTION_MODULE_BT_BB);
|
2023-06-13 07:18:57 -04:00
|
|
|
ESP_RETURN_ON_ERROR(err, TAG, "failed to allocate memory for btbb retention");
|
|
|
|
ESP_LOGI(TAG, "btbb sleep retention initialization");
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void btbb_sleep_retention_deinit(void)
|
|
|
|
{
|
2023-06-19 02:29:06 -04:00
|
|
|
sleep_retention_entries_destroy(SLEEP_RETENTION_MODULE_BT_BB);
|
2023-06-13 07:18:57 -04:00
|
|
|
}
|
2023-06-25 02:17:56 -04:00
|
|
|
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
2023-06-13 07:18:57 -04:00
|
|
|
|
|
|
|
|
2022-12-19 07:29:52 -05:00
|
|
|
void esp_btbb_enable(void)
|
|
|
|
{
|
|
|
|
_lock_acquire(&s_btbb_access_lock);
|
|
|
|
if (s_btbb_access_ref == 0) {
|
|
|
|
bt_bb_v2_init_cmplx(BTBB_ENABLE_VERSION_PRINT);
|
2023-06-25 02:17:56 -04:00
|
|
|
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
2023-06-13 07:18:57 -04:00
|
|
|
btbb_sleep_retention_init();
|
2023-06-25 02:17:56 -04:00
|
|
|
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
2022-12-19 07:29:52 -05:00
|
|
|
}
|
|
|
|
s_btbb_access_ref++;
|
|
|
|
_lock_release(&s_btbb_access_lock);
|
|
|
|
}
|
2023-03-17 04:18:27 -04:00
|
|
|
|
|
|
|
void esp_btbb_disable(void)
|
|
|
|
{
|
|
|
|
_lock_acquire(&s_btbb_access_lock);
|
2023-06-13 07:18:57 -04:00
|
|
|
if (s_btbb_access_ref && (--s_btbb_access_ref == 0)) {
|
2023-06-25 02:17:56 -04:00
|
|
|
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
2023-06-13 07:18:57 -04:00
|
|
|
btbb_sleep_retention_deinit();
|
2023-06-25 02:17:56 -04:00
|
|
|
#endif // SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
2023-03-17 04:18:27 -04:00
|
|
|
}
|
|
|
|
_lock_release(&s_btbb_access_lock);
|
|
|
|
}
|