DSP Configuration

The purpose of this document is to introduce DSP configuration module. MCU will load DSP-related parameters from DSP configuration image, then send them to DSP. DSP configuration image is generated from DSPConfig Tool, and users should download DSP configuration image by MPPG Tool as MPPG Tool Download:

../../../_images/mppgtool_download.png

MPPG Tool Download

API Usage

The purpose of this chapter is to give an overview of DSP configuration APIs. The source code is in sdk\src\sample\common\app_dsp_cfg.c.

Initialization

Users should call app_dsp_cfg_init() when the system does initialization, which will load DSP configuration image to get the header, EQ parameters, extensible parameters, and gain table.

Header Load

app_dsp_cfg_load_header() will get DSP configuration image header. The offset of parameters in structure T_APP_DSP_PARAM_R_ONLY is fixed and shall not be modified by users.

Layout of DSP configuration image header is shown on Header Layout:

../../../_images/header_layout.png

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

The image header provides information of 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:

../../../_images/eq_parameters_layout.png

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

The image header provides information of 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:

../../../_images/extensible_parameters_layout.png

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

The image header provides information of 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:

../../../_images/gain_table_layout.png

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));
        ......
}