3.11. sample_dsp 使用说明
首先adsp 目录adsp 代码。
相关
文档:本 示例 仅 演示 DSP 的 使用 流程,不 含 DSP 侧 固件 二次开发。如需 进行 DSP 固件 二次开发(需 授权),参见 HIFI5 用户 指南 、SSF 开发指南 与 HIFI5 接口文档 。
3.11.1. 功能概述
该
3.11.1.1. 软件架构说明
sample_dsp 在

3.11.1.2. 代码位置及目录结构
DSP 侧(部分):即我们提到的 adsp 的目录,未授权则没有开放。
adsp:
├── sample
│ ├── main.c # main 函数
│ └── Makefile # 编译脚本
......
├── bsp_project/no-archive/algo/ # 算子示例源文件目录
│ ├── hifi5_fft_cplx_32x32
│ │ ├── fft_cplx_32x32.c
│ │ ├── input.c
│ │ ├── readme.txt
│ │ ├── ref_output.c
│ │ └── twiddle32_1024.c
│ └── horizon_sample
│ └── horizon_algo_sample.c
......
ARM 侧: /app/platform_samples/sample_dsp/
├── Makefile
├── sample_config.json # IPC 初始化依赖的 json 文件
└── sample_dsp.cpp # main 函数, sample 示例
3.11.1.3. 工具位置及目录结构
/app/platform_samples/sample_dsp/: 该sample_dsp。
.
├── Makefile
├── sample_config.json
├── sample_dsp
├── sample_dsp.cpp
└── sample_dsp.o
另/usr/hobot/lib/firmware/。
.
├── adsp # 语音唤醒的固件
├── adsp-sample # 复数算法固件
├── bkfir__32x32_taps256_n80.out # 滤波器相关固件
└── libmm # video 相关固件
这个
3.11.1.4. 背景知识
DSP(数字
3.11.1.5. API 流程说明

API 流程图
| 函数 |
描述 |
|---|---|
| hb_dsp_init | 用于 |
| hb_dsp_mem_alloc | 为 DSP 操作 |
| hb_ipcfhal_getchan_byjson | 用于 |
| hb_ipcfhal_init | 初始化 IPC 通道。 |
| hb_dsp_start | 启动 DSP 处理。 |
| hb_ipcfhal_send | ARM 侧 |
| hb_ipcfhal_recv | ARM 侧 |
| hb_ipcfhal_deinit | 用于 |
| hb_dsp_stop | 停止 DSP 处理。 |
| hb_dsp_mem_free | 释放 |
| hb_dsp_deinit | 进行 DSP 环境 |
3.11.2. 编译部署
3.11.2.1. 编译
前提条件:需要adsp/toolchain/ 目录
编译
DSP 侧: 进入 DSP 侧
的 目录: 首先 source 环境变量,然后 参考 每 一步 最后 的 数字 的 选择 进行 选择,最后 再 进行 编译。
source env_hf5.sh
please input adsp version: 0: debug or 1: release: 0
adsp target version is debug
Need test cases or not : 0: no or 1: yes: 0
adsp without test cases
Enable stress cases or not : 0: no or 1: yes: 0
Enable algo sample or not : 0: no or 1: yes: 1
make -j4
ARM 侧: 支持
整编 或者 单独 编译 app 目录 的 时候 编译 到 sample_dsp
./bd.sh
./bd.sh app
3.11.2.2. 工具部署及配置
同样
DSP 侧:输出
产物 在 adsp/output/adsp-sample 没有 申请 adsp 的 伙伴 不用 担心,我们 释放 的 镜像 包含 了 固件,以供 体验 使用 流程。 ARM 侧:输出
文件 在 out/deploy/app/platform_samples/sample_dsp/ 这部分 是 示例 的 以及 编译 产物 的 位置,编译 完成 后 可 参考 程序运行 方法 执行。
3.11.3. 运行
3.11.3.1. 程序运行方法
前提:
检查/usr/hobot/lib/firmware 路径/usr/hobot/lib/firmware/ 有
3.11.3.2. 程序参数选项说明
Usage: ./sample_dsp
-p --dsp_path Specifying firmware paths ( 用于指定 dsp firmware 路径。[ 必选项 ])
-t --algo_type Specifying algo type ( 用于指定算法类型。默认 type 是 1)
-n --dsp_name Specifying dsp name ( 用于指定加载的 firmware 名称。默认值是 adsp)
-h --help print usage ( 用于打印使用帮助 )
例如./sample_dsp -p /usr/hobot/lib/firmware/ -n adsp-sample
( 如果./sample_dsp -p /usr/hobot/lib/firmware/ -n adsp-sample-release )
这里
| 参数 | 描述 |
|---|---|
| -p | 用于 |
| -t | 可 |
| -n | 是 firmware 的 |
| -h | 用于 |
3.11.3.3. 配置文件说明
sample_config.json 是
{
"log_level": 0,
"config_num": 2,
"config_num_max":256,
"config_0": {
"name": "cpu2dsp_ins2ch0",
"instance": 2,
"channel": 0,
"pkg_size_max": 4096,
"fifo_size": 64000,
"fifo_type": 0,
"ipcf_dev_path":"/dev/ipcdrv",
"ipcf_dev_name":"ipcdrv"
},
"config_1": {
"name": "cpu2dsp_ins2ch1",
"instance": 2,
"channel": 1,
"pkg_size_max": 4096,
"fifo_size": 64000,
"fifo_type": 0,
"ipcf_dev_path":"/dev/ipcdrv",
"ipcf_dev_name":"ipcdrv"
}
}
以下
| 字 |
子字段 | 值 | 描述 |
|---|---|---|---|
| log_level | 0 | 定义 |
|
| config_num | 2 | 指定 |
|
| config_num_max | 256 | 配置 |
|
| config_0 | name | cpu2dsp_ins2ch0 | 通道 |
| instance | 2 | IPC 通道 |
|
| channel | 0 | 通道 |
|
| pkg_size_max | 4096 | 最大 |
|
| fifo_size | 64000 | FIFO(先进先出 |
|
| fifo_type | 0 | FIFO 的 |
|
| ipcf_dev_path | /dev/ipcdrv | IPC 设备 |
|
| ipcf_dev_name | ipcdrv | IPC 设备 |
3.11.3.4. 运行效果
使用 /usr/hobot/lib/firmware/adsp-sample 固件 :
使用/app/platform_samples/sample_dsp 目录./sample_dsp -p /usr/hobot/lib/firmware/ -n adsp-sample,会
(release 版本
root@buildroot:/app/platform_samples/sample_dsp# ./sample_dsp -p /usr/hobot/lib/firmware/ -n adsp-sample
[INFO][hb_ipcf_hal.cpp:272] [channel] cpu2dsp_ins2ch0 [id] 0 init success.
[INFO][hb_ipcf_hal.cpp:325] [channel] cpu2dsp_ins2ch0 [id] 0 config success.
[INFO][hb_ipcf_hal.cpp:272] [channel] cpu2dsp_ins2ch1 [id] 1 init success.
[INFO][hb_ipcf_hal.cpp:325] [channel] cpu2dsp_ins2ch1 [id] 1 config success.
[DSP0-I][]DSP_FREQ = 811000000, xos_get_clock_freq = 811000000, TICK_CYCLES = 811000
[DSP0-I][]--------WELCOME ADSP0 START---------
The example algorithm hifi-fft-cplx takes 19741 cycles
Test Passed.
The example algorithm hifi-fft-cplx takes 7490 cycles
Test Passed.
The example algorithm hifi-fft-cplx takes 8858 cycles
Test Passed.
The example algorithm hifi-fft-cplx takes 9033 cycles
Test Passed.
The example algorithm hifi-fft-cplx takes 8668 cycles
Test Passed.
The example algorithm hifi-fft-cplx takes 8805 cycles
Test Passed.
......
The example algorithm hifi-fft-cplx takes 7789 cycles
Test Passed.
The example algorithm hifi-fft-cplx takes 7670 cycles
Test Passed.
[INFO][hb_ipcf_hal.cpp:500] [channel] cpu2dsp_ins2ch0 [id] 0 deinit success.
The example algorithm hifi-fft-cplx takes 7286 cycles
Test Passed.
[INFO][hb_ipcf_hal.cpp:500] [channel] cpu2dsp_ins2ch1 [id] 1 deinit success.
root@buildroot:/app/platform_samples/sample_dsp#
如果[DSP-I] 开头dmesg 打印 Kernel Log 才能
3.11.4. 常见问题
Q: 报错
提示 IPC 通信 失败,出现 如下 打印:
root@buildroot:/app/platform_samples/sample_dsp# ./sample_dsp -p /usr/hobot/lib/firmware/
[ 613.038429] hobot-dsp dsp0: Not attached to any iommu, using physical address!
[INFO][hb_ipcf_hal.cpp:244] [channel] cpu2dsp_ins2ch0 [id] 0 init success.
[INFO][hb_ipcf_hal.cpp:297] [channel] cpu2dsp_ins2ch0 [id] 0 config success.
[DSP0-I][]DSP_FREQ = 811000000, xos_get_clock_freq = 811000000, TICK_CYCLES = 811000
[DSP0-I][]--------WELCOME ADSP0 START---------
[DSP0-I][]platform_init
[DSP0-I][]main
SSF version: V0.1
build: Dec 23 2024 18:24:01
-------- Start SSF Main --------
[ 616.094545] remoteproc remoteproc0: wait for boot timeout
[ 616.100035] ipc-drv: ipc_shm_acquire_buf() [763]: No free buffer found in channel 0
[ 616.107726] ipc-drv: hb_ipc_acquire_buf() [226]: buf acquire failed
[ 616.114001] ipc-shm-hal: hal_ipc_shm_write(): [Ins 2 channel 0] sample_dsp(1034) can't obtain buf size 72 from channel cnt 1.
[ERROR][][/Data16T/sw_ae/wangfuhua/sdk-x5-20241227/app/samples/platform_samples/sample_dsp/sample_dsp.cpp:123] ipcfhal send error
[ERROR][][/Data16T/sw_ae/wangfuhua/sdk-x5-20241227/app/samples/platform_samples/sample_dsp/sample_dsp.cpp:212] dsp call fail:-14
root@buildroot:/app/platform_samples/sample_dsp#
A: 出现
Q: 使用
./sample_dsp -p /usr/hobot/lib/firmware/ -n adsp-sample执行的 时候 出现 如下 报错,怎么 排查?
root@buildroot:/app/platform_samples/sample_dsp# ./sample_dsp -p /usr/hobot/lib/firmware/ -n adsp-sample
[INFO][hb_ipcf_hal.cpp:272] [channel] cpu2dsp_ins2ch0 [id] 0 init success.
[INFO][hb_ipcf_hal.cpp:325] [channel] cpu2dsp_ins2ch[ 4874.846815] remoteproc remoteproc0: hobot_remoteproc_shutdown_hifi5 dsp state is not running
0 [id] 0 config success.
[INFO][hb_ipcf_hal.cpp:272] [channel] [ 4874.848494] hobot-dsp dsp0: dsp_char_ioctl: dsp0 cmd -1071627262 execute error, ret =-22
cpu2dsp_ins2ch1 [id] 1 init success.
[INFO][hb_ipcf_hal.cpp:325] [channel] cpu2dsp_ins2ch1 [id] 1 config success.
[ERROR][][/Data16T/jenkins_slave/workspace/X5_SDK_Publish/platform_source_code/app/samples/platform_samples/sample_dsp/sample_dsp.cpp:290] hb_dsp_start failed, ret -7
[INFO][hb_ipcf_hal.cpp:500] [channel] cpu2dsp_ins2ch0 [id] 0 deinit success.
[INFO][hb_ipcf_hal.cpp:500] [channel] cpu2dsp_ins2ch1 [id] 1 deinit success.
root@buildroot:/app/platform_samples/sample_dsp#
A: 检查 /userdata/log/usr/message , 看报/usr/hobot/lib/firmware/adsp-sample is not exist 这样