四、解读VisualDSP++案例之21489 AD1939 C Block-Based Talkthru 48 or 96 kHz

记录一下,方便以后翻阅~

ADSP学习之路远比STM32痛苦,不仅是可参考资料少(主要学习官方原版手册以及安装完VisualDSP软件后里面提供的案例库),近几年国内也有专做以ADI公司芯片为主的开发版的公司(记得是ADSP开源社区),不过不买他们的开发板就不提供服务,相比较正点原子来说“小气”很多,所以一点一点积累知识吧~

在说下VisualDSP这款软件,这是ADI公司针对ADI公司DSP器件开发的软件开发平台,支持ADI公司BF60x之外的所有系列DSP处理器,包括Blackfin系列和 ADSP-21XX系列定点处理器、SHARC系列和TigerSHARC系列的浮点处理器的各种型号处理器。

VisualDSP功能太少,连go to definition这种功能都没有,且现在ADI公司主推CCES这款软件,VisualDSP的功能未来也不会有太大的更新了。所以做好心理准备,有条件的可以直接转CCES,没条件的先学VisualDSP,后期转CCES个人认为也是很快的,可类比学LabVIEW的工程师转学NXG。

今天分享VisualDSP软件自带的案例21489 AD1939 C Block-Based Talkthru 48 or 96 kHz

先看下Readme部分内容
This project contains a talkthrough example using the onboard AD1939 to acquire and output an audio stream. The digital audio data is available for processing in the file SPORT1_isr.c. The block size is 256 samples per audio channel.
The AD1939 can be set up for 48/96/192 Khz Sampling rate. The ADC is connected to SPORT 0A. DAC1 is connected to SPORT 1A, DAC2 to SPORT 1A, DAC3 to SPORT1A, and DAC4 (Headphone output) to SPORT1A. All channels of the codec are accessed in TDM mode. See initSRU.c for the details of which DAI pins are used to access the codec.
大致意思就是这个案例用板子上的AD1939音频芯片采集声音并发出声音,数字音频数据通过 SPORT1_isr.c.文件进行处理,块采样为256一次。这个AD1939芯片只能设置 48/96/192 Khz采样率,ADC与SPORT 0A相连,DAC1,2,3,4与SPORT 1A相连,采用TDM模式访问,这些引脚配置会在initSRU.c文件里详细描述。

Source Files contained in this directory:
21489 AD1939 C Block-Based Talkthru 48 or 96 kHz.dpj VisualDSP project file
ad1939.h Macro Definitions for AD1939 registers
ADDS_21489_EzKit.h Includes and external declarations used for all files
blockProcess_audio.c Process the audio data in the current block
init1939viaSPI.c ADSP-21489 source - AD1939 SPI Control Port Subroutines
init_PLL_SDRAM.c Configures core for 400 MHz and enables SDRAM memory
initSRU.c Set up the DAI pins and SRU to connect to the AD1939
main.c Main section to call setup routines
initSPORT01_TDM_mode.c Initialize the SPORT DMA to communicate with the AD1939
**SPORT1_isr.c ** Process SPORT 1 interrupts
Dependencies contained in VisualDSP++ default include path:
def21489.h Header file with generic definitions for ADSP-21489
SRU.h Header file with SRU definitions and Macros
上述是这个案例包括的文件,main.c文件是主函数,其他都是子函数或头文件。需要注意的是def21489.h和SRU.h不在案例的文件夹里,这两个头文件地址为VisualDSP软件的安装地址,写程序时直接include就行,软件会自动去VisualDSP软件的安装地址里找的。所以,你看到的Porject如下图所示(看仔细了,没有def21489.h和SRU.h):
四、解读VisualDSP++案例之21489 AD1939 C Block-Based Talkthru 48 or 96 kHz_第1张图片
接下来看下main函数里都有些什么,上代码

/
// (c) Copyright 2009 - Analog Devices, Inc.                                               //
// NAME:      main.c (sample-based Talkthrough)                                            //
// DATE:      02/06/10                                                                     //
// PURPOSE:   Function main() for AD1939/ADSP-21489 Talkthrough framework.                 //
// USAGE:     This file contains the main routine calls functions to set up the talkthrough//
//            routine.                                                                     //
// Author(s): VS., Analog Devices, Inc                                                     //
/
#include "ADDS_21489_EzKit.h"
void main()
{
       
 initPLL_SDRAM();  // Initialize the PLL and SDRAM controller,时钟配置,位于init_PLL_SDRAM.c文件里
 InitDAI();        // Initialize DAI because the SPORT and SPI signals need to be routed,DAI配置,位于initSRU.c文件里
 Init1939viaSPI(); // This function will configure the AD1939 codec on the 21489 EZ-KIT,SPI配置,比较好理解
 InitSPORT();      // Turn on SPORT0 TX and SPORT1 RX for Multichannel Operation,SPORT配置,这是ADI特有的端口
 interrupt(SIG_SP1,TalkThroughISR); // Unmask SPORT1 RX ISR Interrupt ,当SIG_SP1中断发生,运行TalkThroughISR中断函数,比较好理解
 // Be in infinite loop and do nothing until done.
 while(1)
 {
     
  if(inputReady)
    handleCodecData(buffer_cntr);    // 这个函数就是从ADC采集音频信号,然后不做处理,在传到DAC去
 }
}

上述代码的注释已经简单说了一下各函数的作用,接下来再细说下InitDAI这个函数, InitSPORT函数也很重要,不过我目前只会用,不太会讲解。

上InitDAI代码

void InitDAI()
{
     
    clearDAIpins();   // 这个函数就是把ADSP21489芯片上20个DAI引脚拉低,并设为输入模式
//-----------------------------------------------------------------------------
//  Connect the AD1939 ADCs: The AD1939 drives a BCLK output to DAI pin 7, a frame sync to DAI pin 8 and TDM rx data to DAI pins 5
//  Connect the TDM ADC stream to SPORT1, using data input A
//  All four lines are always inputs to the SHARC so tie the pin buffer inputs and pin buffer enable inputs all low.
    SRU(DAI_PB07_O, SPORT1_CLK_I);   // DAIP17 (RSCLK1) to SPORT1 CLK (CLK)
    SRU(DAI_PB07_O, SPORT0_CLK_I);   // DAIP7 (RSCLK1) to SPORT0 CLK (CLK)
    SRU(DAI_PB08_O, SPORT1_FS_I);    // DAIP8 (RFS1) to SPORT1 FS (FS)
    SRU(DAI_PB08_O, SPORT0_FS_I);    // DAIP8 (RFS1) to SPORT0 FS (FS)
    SRU(DAI_PB05_O, SPORT1_DA_I);    // DAIP5 (DR1PRI) to SPORT1 DA (RX)
//-----------------------------------------------------------------------------
//  Connect the AD1939 DACs in TDM mode to SPORT0: The clock and frame sync inputs are provided by the ADCs
//  All DAC connections are always outputs from the SHARC so tie the pin buffer enable inputs all high.
//  Connect the TDM DAC stream to SPORT0 A via DAI pin 12
    SRU(HIGH, PBEN12_I);
    SRU(SPORT0_DA_O, DAI_PB12_I);    // DAIP 13 (DT1PRI)to SPORT0 DA (TX)
//--------------------------------------------------------------------------
// Route SPI signals to AD1939 Control Port.
    SRU(SPI_MOSI_O, DPI_PB01_I);     //Connect MOSI to DPI PB1.
    SRU(DPI_PB02_O, SPI_MISO_I);     //Connect DPI PB2 to MISO.
    SRU(SPI_CLK_O,  DPI_PB03_I);     //Connect SPI CLK to DPI PB3.
    SRU(SPI_FLG0_O, DPI_PB04_I);     //Connect SPI FLAG0 to DPI PB4.    
//---------------------------------------------------------------------------
// Tie pin buffer enable from SPI peipheral to determine whether they are inputs or outputs
    SRU(SPI_MOSI_PBEN_O, DPI_PBEN01_I);
    SRU(SPI_MISO_PBEN_O, DPI_PBEN02_I);
    SRU(SPI_CLK_PBEN_O, DPI_PBEN03_I);
    SRU(SPI_FLG0_PBEN_O, DPI_PBEN04_I);     
//-----------------------------------------------------------------------------
}

要理解上面的函数,先看下官方给的AD1939与SHARC ADSP-21489的连接示意图:

/*-----------------------------------------------------------------------------
   *** 21489 EZ-Board TDM MODE AD1939 Single Codec ADC/DAC ROUTING OVERVIEW ***
   (AD1939 AUX TDM mode implementation uses 4 DAI pins and 2 internal SPORTs)
                          ..............................................
 AD1939                   :SHARC ADSP-21489    
                          :
   ADC  12.288 MHz DAI_P07:  o-DAI_PB07_O--------------*-----o-SPORT0_CLK_I
   BCLK >---------------->#--o-                  +---- | ----o-SPORT0_FS_I
   OUT                    :  o-PBEN07_I=LOW      |     |  +--o-SPORT0_DA_O
                          :                      |     |  |
   ADC   48/96 kHz DAI_P08:  o-DAI_PB08_O--------*     |  |
   FS   >---------------->#--o-                  |     |  |
   OUT                    :  o-PBEN08_I=LOW      |     |  |
                          :                      |     |  | 
   ADC1            DAI_P05:  o-DAI_PB05_O-----+  |     |  |
   DATA >---------------->#--o-               |  |     |  |
   OUT                    :  o PBEN05_I=LOW   |  |     |  |
                          :                   |  |     |  |
   ADC2                   :  o-DAI_PB06_O     |  |     |  |
   DATA >                >#--o-               |  |     |  |
   OUT                    :  o PBEN06_I=LOW   |  |     |  |
                          :                   |  |     |  |    
   DAC1                   :  o-               |  |     |  |
   BCLK <                <#--o-DAI_PB13_I     |  |     |  | 
   IN                     :  o-PBEN13_I=HIGH  |  |     |  |
                          :                   |  |     |  |
   DAC1                   :  o-               |  |     +---->o-SPORT1_CLK_I
   FS   <                <#--o-DAI_PB14_I     |  +---------->o-SPORT1_FS_I
   IN                     :  o PBEN14_I=HIGH  +------------->o-SPORT1_DA_I
                          :                               |  o-SPORT1_DB_I
   DAC1            DAI_P12:  o                            |   
   DATA <----------------<#--o-DAI_PB12_I<----------------+   
   IN                     :  o PBEN12_I=HIGH               
                          :                                
   DAC2                   :  o-                            
   DATA <                <#--o-DAI_PB11_I<---
   IN                     :  o PBEN11_I=HIGH         
                          :                                  o-SPORT2_CLK_I
   DAC3                   :  o-                              o-SPORT2_FS_I
   DATA <                <#--o-DAI_PB10_I<---                o-SPORT2_DA_O
   IN                     :  o PBEN10_I=HIGH                 o-SPORT2_DB_O
                          :                                
   DAC4                   :  o-                            
   DATA <                <#--o-DAI_PB09_I<---
   IN                     :  o PBEN09_I=HIGH
                          :
                          ..............................................
-----------------------------------------------------------------------------*/

直白点,就是:
AD1939引脚—>SHARC ADSP-21489引脚 ---->该引脚配置的功能
ADC BCLK OUT—>DAI_PB07_O---->SPORT0_CLK_I,且PBEN07_I设LOW;
ADC BCLK OUT—>DAI_PB07_O---->SPORT1_CLK_I,且PBEN07_I设LOW;
ADC FS OUT—> DAI_PB08_O—>SPORT0_FS_I,且PBEN08_I设LOW;
ADC FS OUT—> DAI_PB08_O—>SPORT1_FS_I,且PBEN08_I设LOW;
ADC1 DATA OUT—>DAI_PB05_O—>SPORT1_DA_I,且PBEN05_I设LOW;
DAC1 DATA IN—>DAI_PB12_I—>SPORT0_DA_O,且PBEN12_I=HIGH。
这样一看,是不是InitDAI函数的一半都理解了?最后8行代码是SPI的配置和使能,就不说了。

最后,简单说下SPORT:
SPORT(串行端口)是ADI特有的,有两根数据线,一根时钟线和一根帧同步线组成,具体还是要看ADI相关的官方手册,慢慢学习。

备注:
软件开发相关技术交流可留言或私信(LabVIEW,Matlab,STM32,ADSP均可)

你可能感兴趣的:(ADSP学习心得及问题记录,ADSP,VisualDSP++,ADI,21489,SHARC)