記錄一下,方便以后翻閱~
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):

接下來看下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均可)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/258528.html
標籤:其他
