DSP Configuration
The purpose of this document is to introduce DSP CFG module. MCU will load DSP-related parameters from DSP CFG image, then send them to DSP. DSP CFG image is generated from DSPConfig Tool, and users should download DSP CFG image by MPPG Tool as MPPG Tool Download:
API Usage
The purpose of this chapter is to give an overview of DSP CFG API.
The source code is in
sdk\src\sample\common\app_dsp_cfg.c
.
Initialization
Users should call app_dsp_cfg_init()
to initialize when the system does initialization, it will load DSP CFG image to get the header, EQ parameters, extensible parameters, and gain table.
void app_dsp_cfg_init(bool is_normal_apt)
{
app_dsp_cfg_load_header();
app_dsp_cfg_eq_param_load();
app_dsp_cfg_extensible_param_load();
app_dsp_cfg_gain_table_load(is_normal_apt);
}
Header Load
app_dsp_cfg_load_header()
will get DSP CFG image header. The structures T_APP_DSP_PARAM_R_ONLY
parameters offset is fixed, users should not modify it.
Layout of DSP CFG image header is shown on Header Layout:
static void app_dsp_cfg_load_header(void)
{
app_dsp_cfg_data = calloc(1, sizeof(T_APP_DSP_CFG_DATA));
if (app_dsp_cfg_data != NULL)
{
fmc_flash_nor_read(flash_cur_bank_img_payload_addr_get(FLASH_IMG_DSPCONFIG),
&app_dsp_cfg_data->dsp_cfg_header, sizeof(T_APP_DSP_PARAM_R_ONLY));
}
}
typedef struct t_app_dsp_param_r_only
{
uint16_t sync_word;
uint16_t reserved1;
uint32_t tool_version_info;
uint16_t user_version;
uint16_t reserved2;
uint32_t algo_block_offset;
uint32_t eq_cmd_block_offset;
uint32_t gain_table_block_offset;
uint32_t vad_param_block_offset;
uint32_t eq_extend_info_offset;
uint32_t hw_eq_block_offset;
uint32_t extensible_param_offset;
uint8_t reserved[4];
uint32_t pacakge_features; //need check it in patch
T_VOICE_PROC_ENB voice_stream_feature_bit;
T_AUDIO_PROC_ENB audio_stream_feature_bit;
} T_APP_DSP_PARAM_R_ONLY;
EQ Parameters Load
By the header, users can find the EQ parameters location in flash. app_dsp_cfg_eq_param_load()
will load EQ parameters to the RAM.
Layout of EQ parameters is shown on EQ parameters Layout:
static bool app_dsp_cfg_eq_param_load(void)
{
uint32_t data_offset;
int32_t ret = 0;
T_APP_DSP_EQ_PARAM_HEADER *header = NULL;
T_APP_DSP_EQ_SPK_HEADER *spk_header = NULL;
T_APP_DSP_EQ_MIC_HEADER *mic_header = NULL;
T_APP_DSP_EQ_SPK_HEADER *voice_eq_header = NULL;
uint32_t eq_spk_application_num;
uint32_t eq_mic_application_num;
uint8_t mode;
app_dsp_cfg_data->eq_param.header = calloc(1, sizeof(T_APP_DSP_EQ_PARAM_HEADER));
header = app_dsp_cfg_data->eq_param.header;
if (header == NULL)
{
ret = 1;
goto fail_alloc_eq_param_head;
}
data_offset = app_dsp_cfg_data->dsp_cfg_header.eq_cmd_block_offset;
fmc_flash_nor_read(flash_cur_bank_img_payload_addr_get(FLASH_IMG_DSPCONFIG) + data_offset,
header, sizeof(T_APP_DSP_EQ_PARAM_HEADER) - 16);
......
fmc_flash_nor_read(flash_cur_bank_img_payload_addr_get(FLASH_IMG_DSPCONFIG) + data_offset,
spk_header, header->eq_spk_application_num * sizeof(T_APP_DSP_EQ_SPK_HEADER));
......
fmc_flash_nor_read(flash_cur_bank_img_payload_addr_get(FLASH_IMG_DSPCONFIG) + data_offset,
mic_header, header->eq_mic_application_num * sizeof(T_APP_DSP_EQ_MIC_HEADER));
......
fmc_flash_nor_read(flash_cur_bank_img_payload_addr_get(FLASH_IMG_DSPCONFIG) + data_offset,
header->sub_header, header->eq_num * sizeof(T_APP_DSP_EQ_SUB_PARAM_HEADER));
......
}
Extensible Parameters Load
By the header, users can find the extensible parameters location in flash. app_dsp_cfg_extensible_param_load()
will load extensible parameters to the RAM.
Layout of extensible parameters is shown on Extensible Parameters Layout:
static bool app_dsp_cfg_extensible_param_load(void)
{
uint32_t data_offset;
uint16_t index = 0;
int32_t ret = 0;
T_APP_DSP_EXTENSIBLE_PARAM *header = NULL;
header = (T_APP_DSP_EXTENSIBLE_PARAM *)(&app_dsp_cfg_data->dsp_extensible_param);
header->sync_word = 0;
if (app_dsp_cfg_data->dsp_cfg_header.extensible_param_offset == 0)
{
//for DSP configuration bin compatibility
ret = 1;
goto extensible_invalid_address;
}
data_offset = app_dsp_cfg_data->dsp_cfg_header.extensible_param_offset;
fmc_flash_nor_read((flash_cur_bank_img_payload_addr_get(FLASH_IMG_DSPCONFIG) +
data_offset),
(uint8_t *)header,
sizeof(header->sync_word) + sizeof(header->extensible_len));
......
fmc_flash_nor_read((flash_cur_bank_img_payload_addr_get(FLASH_IMG_DSPCONFIG) +
data_offset),
header->raw_data, header->extensible_len);
......
}
Gain Table Load
By the header, users can find the gain table location in flash. app_dsp_cfg_gain_table_load()
will load gain table to the RAM.
Layout of gain table is shown on Gain Table Layout:
static void app_dsp_cfg_gain_table_load(void)
{
T_APP_DSP_GAIN_TABLE_BLOCK *block;
int32_t ret = 0;
block = calloc(1, sizeof(T_APP_DSP_GAIN_TABLE_BLOCK));
if (block == NULL)
{
ret = 1;
goto fail_calloc;
}
app_dsp_cfg_load_param_r_data(block,
app_dsp_cfg_data->dsp_cfg_header.gain_table_block_offset,
sizeof(T_APP_DSP_GAIN_TABLE_BLOCK));
......
}