2025-09-30 11:56:06 +08:00
<!DOCTYPE html> < html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "zh-cn" lang = "zh-cn" data-whc_version = "26.0" >
< head > < meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" / > < meta name = "viewport" content = "width=device-width, initial-scale=1.0" / > < meta http-equiv = "X-UA-Compatible" content = "IE=edge" / > < meta name = "description" content = "测试环境 硬件 测试板:带有第三方 codec 芯片的测试板 PC: 用于和测试板交互 串口线:连接测试板的调试串口 软件 PC 端串口终端软件 alsa-lib 和 alsa-utils 第三方软件包 第三方 codec 驱动 创建声卡的 machine 驱动 创建声卡 machine 驱动 声卡的驱动分为三部分: platform 驱动、codec 驱动、machine ..." / > < meta name = "DC.rights.owner" content = "(C) 版权 2025" / > < meta name = "copyright" content = "(C) 版权 2025" / > < meta name = "generator" content = "DITA-OT" / > < meta name = "DC.type" content = "concept" / > < meta name = "DC.contributor" content = "yan.wang" / > < meta name = "DC.date.modified" content = "2024-12-02" / > < meta name = "DC.format" content = "HTML5" / > < meta name = "DC.identifier" content = "i2s_test_guide" / > < meta name = "DC.language" content = "zh-CN" / > < title > 测试指南< / title > <!-- Build number 2023110923. --> < meta name = "wh-path2root" content = "../../../" / > < meta name = "wh-toc-id" content = "" / > < meta name = "wh-source-relpath" content = "topics/sdk/i2s/i2s_test_guide.dita" / > < meta name = "wh-out-relpath" content = "topics/sdk/i2s/i2s_test_guide.html" / >
< link rel = "stylesheet" type = "text/css" href = "../../../webhelp/app/commons.css?buildId=2023110923" / >
< link rel = "stylesheet" type = "text/css" href = "../../../webhelp/app/topic.css?buildId=2023110923" / >
< script src = "../../../webhelp/app/options/properties.js?buildId=20250121171154" > < / script >
< script src = "../../../webhelp/app/localization/strings.js?buildId=2023110923" > < / script >
< script src = "../../../webhelp/app/search/index/keywords.js?buildId=20250121171154" > < / script >
< script defer = "defer" src = "../../../webhelp/app/commons.js?buildId=2023110923" > < / script >
< script defer = "defer" src = "../../../webhelp/app/topic.js?buildId=2023110923" > < / script >
< link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/aic-styles-web.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/notes.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/aic-common.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/aic-images.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/footnote.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/aic-web-watermark.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/topic-body-list.css?buildId=2023110923" / > < / head >
< body id = "i2s_test_guide" class = "wh_topic_page frmBody" >
< a href = "#wh_topic_body" class = "sr-only sr-only-focusable" >
跳转到主要内容
< / a >
< header class = "navbar navbar-default wh_header" >
< div class = "container-fluid" >
< div class = "wh_header_flex_container navbar-nav navbar-expand-md navbar-dark" >
< div class = "wh_logo_and_publication_title_container" >
< div class = "wh_logo_and_publication_title" >
< a href = "http://www.artinchip.com" class = " wh_logo d-none d-sm-block " > < img src = "../../../company-logo-white.png" alt = "RTOS SDK 使用指南SDK 指南文件" / > < / a >
< div class = " wh_publication_title " > < a href = "../../../index.html" > < span class = "booktitle" > < span class = "ph mainbooktitle" > RTOS SDK 使用指南< / span > < span class = "ph booktitlealt" > SDK 指南文件< / span > < / span > < / a > < / div >
< / div >
< / div >
< div class = "wh_top_menu_and_indexterms_link collapse navbar-collapse" id = "wh_top_menu_and_indexterms_link" >
< / div >
< / div >
< / div >
< / header >
< div class = " wh_search_input navbar-form wh_topic_page_search search " role = "form" >
< form id = "searchForm" method = "get" role = "search" action = "../../../search.html" > < div > < input type = "search" placeholder = "搜索 " class = "wh_search_textfield" id = "textToSearch" name = "searchQuery" aria-label = "搜索查询" required = "required" / > < button type = "submit" class = "wh_search_button" aria-label = "搜索" > < span class = "search_input_text" > 搜索< / span > < / button > < / div > < / form >
< / div >
< div class = "container-fluid" id = "wh_topic_container" >
< div class = "row" >
< nav class = "wh_tools d-print-none navbar-expand-md" aria-label = "Tools" >
< div data-tooltip-position = "bottom" class = " wh_breadcrumb " > < / div >
< div class = "wh_right_tools" >
< button class = "wh_hide_highlight" aria-label = "切换搜索突出显示" title = "切换搜索突出显示" > < / button >
< button class = "webhelp_expand_collapse_sections" data-next-state = "collapsed" aria-label = "折叠截面" title = "折叠截面" > < / button >
< div class = " wh_print_link print d-none d-md-inline-block " > < button onClick = "window.print()" title = "打印此页" aria-label = "打印此页" > < / button > < / div >
< / div >
< / nav >
< / div >
< div class = "wh_content_area" >
< div class = "row" >
< div class = "col-lg-10 col-md-10 col-sm-10 col-xs-12" id = "wh_topic_body" >
< button id = "wh_close_topic_toc_button" class = "close-toc-button d-none" aria-label = "Toggle topic table of content" aria-controls = "wh_topic_toc" aria-expanded = "true" >
< span class = "close-toc-icon-container" >
< span class = "close-toc-icon" > < / span >
< / span >
< / button >
< div class = " wh_topic_content body " > < main role = "main" > < article class = "- topic/topic concept/concept topic concept" role = "article" aria-labelledby = "ariaid-title1" > < span class = "edit-link" style = "font-size:12px; opacity:0.6; text-align:right; vertical-align:middle" > < a target = "_blank" href = "http://172.16.35.88/tasks/jdssno1uvvbf2mltu9kb9v3if05d5gopuakboe8hlud18rma/edit/F:/aicdita/aicdita-cn/topics/sdk/i2s/i2s_test_guide.dita" > Edit online< / a > < / span > < h1 class = "- topic/title title topictitle1" id = "ariaid-title1" > 测试指南< / h1 > < div class = "date inPage" > 2 Dec 2024< / div > < div style = "color: gray;" >
Read time: 3 minute(s)
< / div > < div class = "- topic/body concept/conbody body conbody" > < section class = "- topic/section section" id = "i2s_test_guide__section_dy2_jvl_4dc" data-ofbid = "i2s_test_guide__section_dy2_jvl_4dc" > < h2 class = "- topic/title title sectiontitle" > 测试环境< / h2 >
< div class = "- topic/p p" data-ofbid = "d97978e27__20250121171535" >
< ul class = "- topic/ul ul" id = "i2s_test_guide__ul_nhq_xf3_d1c" data-ofbid = "i2s_test_guide__ul_nhq_xf3_d1c" > < li class = "- topic/li li" data-ofbid = "d97978e30__20250121171535" > 硬件< ul class = "- topic/ul ul" id = "i2s_test_guide__ul_pcc_xf3_d1c" data-ofbid = "i2s_test_guide__ul_pcc_xf3_d1c" > < li class = "- topic/li li" data-ofbid = "d97978e33__20250121171535" >
< p class = "- topic/p p" data-ofbid = "d97978e35__20250121171535" > 测试板:带有第三方 codec 芯片的测试板< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d97978e38__20250121171535" >
< p class = "- topic/p p" data-ofbid = "d97978e40__20250121171535" > PC: 用于和测试板交互< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d97978e43__20250121171535" >
< p class = "- topic/p p" data-ofbid = "d97978e45__20250121171535" > 串口线:连接测试板的调试串口< / p >
< / li > < / ul > < / li > < li class = "- topic/li li" data-ofbid = "d97978e48__20250121171535" > 软件< ul class = "- topic/ul ul" id = "i2s_test_guide__ul_qcc_xf3_d1c" data-ofbid = "i2s_test_guide__ul_qcc_xf3_d1c" > < li class = "- topic/li li" data-ofbid = "d97978e51__20250121171535" >
< p class = "- topic/p p" data-ofbid = "d97978e53__20250121171535" > PC 端串口终端软件< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d97978e56__20250121171535" >
< p class = "- topic/p p" data-ofbid = "d97978e58__20250121171535" > alsa-lib 和 alsa-utils 第三方软件包< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d97978e61__20250121171535" >
< p class = "- topic/p p" data-ofbid = "d97978e63__20250121171535" > 第三方 codec 驱动< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d97978e66__20250121171535" >
< p class = "- topic/p p" data-ofbid = "d97978e68__20250121171535" > 创建声卡的 machine 驱动< / p >
< / li > < / ul > < / li > < / ul >
< / div >
< / section > < section class = "- topic/section section" id = "i2s_test_guide__section_rcc_xf3_d1c" data-ofbid = "i2s_test_guide__section_rcc_xf3_d1c" > < h2 class = "- topic/title title sectiontitle" > 创建声卡 < / h2 >
< div class = "- topic/p p" data-ofbid = "d97978e78__20250121171535" >
< ol class = "- topic/ol ol" id = "i2s_test_guide__ol_n5k_cg3_d1c" data-ofbid = "i2s_test_guide__ol_n5k_cg3_d1c" > < li class = "- topic/li li" data-ofbid = "d97978e81__20250121171535" > machine 驱动< p class = "- topic/p p" data-ofbid = "d97978e83__20250121171535" > 声卡的驱动分为三部分: platform 驱动、codec 驱动、machine 驱动。对于本章节来说, platform 驱动即 S 驱动。codec 驱动一般会由 codec 厂家提供,内核中也提供了大量的 codec 驱动源码,可以选择相应的 codec 芯片进行测试,本章节会选用 allwinner 的 ac102 芯片。所以在测试前需要做的就是编写声卡的 machine 驱动, machine 驱动实现 platform 驱动和 codec 驱动的耦合,创建声卡,同时确定 dai 和 codec_dai 的连接方式以及支持的格式、采样深度等信息。< / p > < div class = "- topic/p p" data-ofbid = "d97978e85__20250121171535" > 创建声卡的一个非常重要的结构体是 link, 该结构体用来指定 platform 和 codec 的耦合关系,主要的成员变量如下:< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "i2s_test_guide__codeblock_tyd_dg3_d1c" data-ofbid = "i2s_test_guide__codeblock_tyd_dg3_d1c" > < strong class = "hl-keyword" > struct< / strong > snd_soc_dai_link {
< em class = "hl-comment" > /* config - must be set by machine driver */< / em >
< strong class = "hl-keyword" > const< / strong > < strong class = "hl-keyword" > char< / strong > *name;
< strong class = "hl-keyword" > const< / strong > < strong class = "hl-keyword" > char< / strong > *stream_name;
< strong class = "hl-keyword" > struct< / strong > snd_soc_dai_link_component *cpus;
< strong class = "hl-keyword" > unsigned< / strong > < strong class = "hl-keyword" > int< / strong > num_cpus;
< strong class = "hl-keyword" > struct< / strong > snd_soc_dai_link_component *codecs;
< strong class = "hl-keyword" > unsigned< / strong > < strong class = "hl-keyword" > int< / strong > num_codecs;
< strong class = "hl-keyword" > struct< / strong > snd_soc_dai_link_component *platforms;
< strong class = "hl-keyword" > unsigned< / strong > < strong class = "hl-keyword" > int< / strong > num_platforms;
< em class = "hl-comment" > /* format to set on init */< / em >
< strong class = "hl-keyword" > unsigned< / strong > < strong class = "hl-keyword" > int< / strong > dai_fmt;
< em class = "hl-comment" > /* machine stream operations */< / em >
< strong class = "hl-keyword" > const< / strong > < strong class = "hl-keyword" > struct< / strong > snd_soc_ops *ops;
...
};< / pre > < / div > < div class = "- topic/p p" data-ofbid = "d97978e89__20250121171535" > dai_link 中成员变量的一些定义规则(规则定义可参考 link 结构体定义或函数 soc_dai_link_sanity_check): < ol class = "- topic/ol ol" type = "a" id = "i2s_test_guide__ol_tcc_xf3_d1c" data-ofbid = "i2s_test_guide__ol_tcc_xf3_d1c" > < li class = "- topic/li li" data-ofbid = "d97978e92__20250121171535" >
< p class = "- topic/p p" data-ofbid = "d97978e94__20250121171535" > codecs 必须定义, codecs-> name 和 codecs-> of_node 必须定义其一, 不可以都定义, 也不可以都不定义。codecs-> dai_name 必须定义< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d97978e97__20250121171535" >
< p class = "- topic/p p" data-ofbid = "d97978e99__20250121171535" > cpus 可不定义。但定义时, cpus-> name 和 cpus-> of_node 二者定义其一, 不可以都定义。cpus-> dai_name 可定义, 也可不定义。cpus-> name 和 cpus-> of_node 未定义时,将会通过 cpus-> dai_name 进行匹配。cpus-> dai_name 未定义时,将会通过 cpus-> name 或 cpus-> of_node 进行匹配。< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d97978e102__20250121171535" >
< p class = "- topic/p p" data-ofbid = "d97978e104__20250121171535" > platforms 可不定义。但定义时 platforms-> name 和 platforms-> of_node 二者定义其一, 不可以都定义。platforms-> dai_name 在 ALSA 框架中并未使用。< / p >
< p class = "- topic/p p" data-ofbid = "d97978e107__20250121171535" > ALSA 框架中提供了一些宏,用来定义上述的一些成员变量,比较常用的是通过宏 DEFS 进行定义。现在内核中比较通用的做法是通过 DEFS 将成员变量定义为空,在声卡的 probe 函数中通过读取 DTS 定义 cpus/codecs/platforms 的 node 变量。这样做的优点是修改 codec 外部配置或连接方式时,只需编译 DTS 即可,不需要重新编译内核。< / p >
< p class = "- topic/p p" data-ofbid = "d97978e110__20250121171535" > dai_fmt 变量定义 S 和 codec 之间的音频数据传输方式。< / p >
< p class = "- topic/p p" data-ofbid = "d97978e113__20250121171535" > ops 定义 machine 驱动所支持的操作函数集。< / p >
< p class = "- topic/p p" data-ofbid = "d97978e116__20250121171535" > 将定义的 link 结构体变量赋值给 struct
snd_soc_card 结构体的 link 成员变量,然后调用 card 即可完成声卡的注册,具体可参考内核中提供的一些 machine 驱动。< / p >
< / li > < / ol > < / div > < / li > < li class = "- topic/li li" data-ofbid = "d97978e119__20250121171535" > 声卡 DTS
配置< div class = "- topic/p p" data-ofbid = "d97978e121__20250121171535" > 需要在 DTS 中配置声卡的结点,才能正确调用声卡的 machine 驱动。DTS 中声卡的结点配置如下(以 allwinner 的 ac102 为例说明): < pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "i2s_test_guide__codeblock_ijz_fg3_d1c" data-ofbid = "i2s_test_guide__codeblock_ijz_fg3_d1c" > soundCard {
compatible = < span class = "hl-string" > "artinchip,aic-ac102"< / span > ;
aic,codec-chip = < & ac102> ;
aic,i2s-controller = < & i2s1> ;
status = < span class = "hl-string" > "okay"< / span > ;
};< / pre > < / div > < div class = "- topic/p p" data-ofbid = "d97978e125__20250121171535" > machine 驱动通过读取 aic,codec-chip 和 aic,i2s-controller 属性获取相应的 s 和 codec 结点。SOC 一般是通过 C 接口对 codec 芯片进行控制,所以需要在 C 控制器下挂接 codec 芯片< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "i2s_test_guide__codeblock_q5d_gg3_d1c" data-ofbid = "i2s_test_guide__codeblock_q5d_gg3_d1c" > & i2c3 {
pinctrl-names = < span class = "hl-string" > "default"< / span > ;
pinctrl-< span class = "hl-number" > 0< / span > = < & i2c3_pins_b> ;
status = < span class = "hl-string" > "okay"< / span > ;
ac102: ac102@< span class = "hl-number" > 33< / span > {
compatible = < span class = "hl-string" > "allwinner,ac102"< / span > ;
reg = < < span class = "hl-number" > 0x33< / span > > ;
};
};< / pre > < / div > < / li > < / ol >
< / div >
< / section > < section class = "- topic/section section" id = "i2s_test_guide__section_ucc_xf3_d1c" data-ofbid = "i2s_test_guide__section_ucc_xf3_d1c" > < h2 class = "- topic/title title sectiontitle" > 音频测试< / h2 >
< div class = "- topic/p p" data-ofbid = "d97978e136__20250121171535" >
< ol class = "- topic/ol ol" id = "i2s_test_guide__ol_bl2_jg3_d1c" data-ofbid = "i2s_test_guide__ol_bl2_jg3_d1c" > < li class = "- topic/li li" data-ofbid = "d97978e139__20250121171535" > 测试音频播放< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "i2s_test_guide__codeblock_fmk_2jj_g1c" data-ofbid = "i2s_test_guide__codeblock_fmk_2jj_g1c" > aplay test.wav
< / pre > < pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "i2s_test_guide__codeblock_el3_fjj_g1c" data-ofbid = "i2s_test_guide__codeblock_el3_fjj_g1c" > test_wavplay /sdcard/wav/test.wav < em class = "hl-comment" > //播放 SD 卡音频文件< / em > < / pre > < / li > < li class = "- topic/li li" data-ofbid = "d97978e145__20250121171535" > 测试音频录音< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "i2s_test_guide__codeblock_lf1_gjj_g1c" data-ofbid = "i2s_test_guide__codeblock_lf1_gjj_g1c" > arecord -d < span class = "hl-number" > 10< / span > -f dat -t wav test.wav
< / pre > < ul class = "- topic/ul ul" id = "i2s_test_guide__ul_mn5_kg3_d1c" data-ofbid = "i2s_test_guide__ul_mn5_kg3_d1c" > < li class = "- topic/li li" data-ofbid = "d97978e150__20250121171535" >
< p class = "- topic/p p" data-ofbid = "d97978e152__20250121171535" > -d: 指定录音时长, 单位为秒< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d97978e155__20250121171535" >
< p class = "- topic/p p" data-ofbid = "d97978e157__20250121171535" > -f: 指定录制的格式, dat 表示 16bit 小端数据, 48K 采样率,立体声< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d97978e160__20250121171535" >
< p class = "- topic/p p" data-ofbid = "d97978e162__20250121171535" > -t: 指定生成的文件格式, 为 wav 文件< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d97978e165__20250121171535" >
< p class = "- topic/p p" data-ofbid = "d97978e167__20250121171535" > test.wav: 生成的 wav 文件名< / p >
< / li > < / ul > < / li > < / ol >
< / div >
< / section > < / div > < / article > < / main > < / div >
< / div >
< nav role = "navigation" id = "wh_topic_toc" aria-label = "On this page" class = "col-lg-2 d-none d-lg-block navbar d-print-none" >
< div id = "wh_topic_toc_content" >
< div class = " wh_topic_toc " > < div class = "wh_topic_label" > 在本页上< / div > < ul > < li class = "section-item" > < div class = "section-title" > < a href = "#i2s_test_guide__section_dy2_jvl_4dc" data-tocid = "i2s_test_guide__section_dy2_jvl_4dc" > 测试环境< / a > < / div > < / li > < li class = "section-item" > < div class = "section-title" > < a href = "#i2s_test_guide__section_rcc_xf3_d1c" data-tocid = "i2s_test_guide__section_rcc_xf3_d1c" > 创建声卡 < / a > < / div > < / li > < li class = "section-item" > < div class = "section-title" > < a href = "#i2s_test_guide__section_ucc_xf3_d1c" data-tocid = "i2s_test_guide__section_ucc_xf3_d1c" > 音频测试< / a > < / div > < / li > < / ul > < / div >
< / div >
< / nav >
< / div >
< / div >
< / div >
< footer class = "navbar navbar-default wh_footer" >
< div class = " footer-container mx-auto " >
< title > footer def< / title >
< style > < ! - -
.p1 {
font-family: FangZhengShuSong, Times, serif;
}
.p2 {
font-family: Arial, Helvetica, sans-serif;
}
.p3 {
font-family: "Lucida Console", "Courier New", monospace;
}
-->< / style >
< div class = "webhelp.fragment.footer" >
< p class = "p1" > Copyright © 2019-2024 广东匠芯创科技有限公司. All rights reserved.< / p >
< / div > < div >
< div class = "generation_time" >
Update Time: 2025-01-21
< / div >
< / div >
< / div >
< / footer >
< div id = "go2top" class = "d-print-none" >
< span class = "oxy-icon oxy-icon-up" > < / span >
< / div >
< div id = "modal_img_large" class = "modal" >
< span class = "close oxy-icon oxy-icon-remove" > < / span >
< div id = "modal_img_container" > < / div >
< div id = "caption" > < / div >
< / div >
< script src = "${pd}/publishing/publishing-styles-AIC-template/js/custom.js" defer = "defer" > < / script >
< / body >
2025-01-23 16:37:00 +08:00
< / html >