AnsweredAssumed Answered

Ping Pong Buffer Synchronisation in SPORTs

Question asked by tonsud on Oct 26, 2015
Latest reply on Oct 28, 2015 by Harshit.Gaharwar

I am using the Sharc ADSP21489 in my application. I need to handle several signals: 16 Input channels at 48 Khz (TDM), 16 Output channels at 48kHz (TDM), Digital Input (2 channels (Stereo)) and Digital Output (2 channels (Stereo)) at 192kHz. I am using Sport2 for Dig In, Sport3 for Dig Out. Sport0 for TDMIn and Sport1 for TDM Out.

 

The whole system looks like:

DigIn -> SRC1 -> SPORT2 ->DSP

DSP->SPORT3->DigOut

 

TDMIn->SPORT0->DSP

DSP->SPORT1->TDMOut

 

PCG_A is used to generate 192kHz from an external Oscillator (49.152MHz / 256)

PCG_A is routed to SRC1 (Out), SPORT2 and SPORT3

 

The system uses Ping-Pong buffers to receive/send data. (receive block_0Rx and simultaneously send block_0Tx, then Rx/Tx block1, 0,1, …) I am testing a bypass program that sends two decoded TDM channels (192kHz) from the TDM stream (4 slots, as the stream is at 48 kHz and 16 slots per frame) to the digital Output. When I run the program I see that the  right channel is coherent but the left channel is wrong, it seems that it is sending the data from the previous block. Indeed, if I change the test tone to 12000Hz, the signal looks correct (One cycle of the signal fills perfectly in the 16 samples Ping/pong buffer, so buffer sync error (sending the buffers in the wrong order) is hidden 192kHz/16 = 12kHz). I need to find out the best way to achieve proper sync for the Ping Pong Buffers in my application. Please advise.

 

I have seen a similar problem in the I2STalkthrough example code for the Ez-board. Stopping/staring the example results in sending the wrong buffer (Ping pong becomes pong ping and the game starts to sound bad). Please advise on this too. I have checked the "stop I/O DMA" but the problem still occurs when debugging. How can I work around this?

 

This is the code:

 

Main()

{

      adi_initComponents();

      initPLL();

      initSerialRoutingUnitTDM2();

      InitSPDIF();

      InitPCGTDM();

      InitSRC1();

      InitSPORTTDM2();

      InitSPI();

 

      /* Install and enable a handler for the SPORT2 Receiver interrupt.*/

      adi_int_InstallHandler(ADI_CID_P6I, TalkThroughISR, 0, true);//TDM in (Sport0)

      adi_int_InstallHandler(ADI_CID_P7I, SPDIFInISR, 0, true);//Digital in (Sport2)

 

 

 

      while(1);

}

 

void SPDIFInISR(uint32_t iid, void *handlerarg) {

      static int testCounter = 0;

 

      for (int i=0;i<((sizeof(Rx2BlockSPDIF[0])/2));i++)

      {

            myTestBuffer4[testCounter % sizeof(myTestBuffer4)] = conv_float_by(((int) *(&Rx2BlockSPDIF[frameCounter][i*2+0])) >> 8, -23);//L

            myTestBuffer5[testCounter % sizeof(myTestBuffer5)] = conv_float_by(((int) *(&Rx2BlockSPDIF[frameCounter][i*2+1])) >> 8, -23);//R

            testCounter++;

      }

}

 
 

 

 

void TalkThroughISR(uint32_t iid, void *handlerarg) {

blockReady = 1;

 

 

      //Frame Swapping. Application works on currentFrame, SPORT Receives/transmits previousFrame

      temp = currentFrame;

      currentFrame= previousFrame;

      previousFrame = temp;

 

 

 

      //DiginL to 192kHz Out1

      Tx1BlockTDM[currentFrame][0*16+0]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][0])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][0*16+4]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][2])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][0*16+8]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][4])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][0*16+12]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][6])) >> 8, -23),31))>>8;

 

      Tx1BlockTDM[currentFrame][1*16+0]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][8])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][1*16+4]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][10])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][1*16+8]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][12])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][1*16+12]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][14])) >> 8, -23),31))>>8;

 

      Tx1BlockTDM[currentFrame][2*16+0]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][16])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][2*16+4]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][18])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][2*16+8]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][20])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][2*16+12]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][22])) >> 8, -23),31))>>8;

 

      Tx1BlockTDM[currentFrame][3*16+0]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][24])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][3*16+4]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][26])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][3*16+8]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][28])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][3*16+12]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][30])) >> 8, -23),31))>>8;

 

      //DiginR to 192kHz Out2

      Tx1BlockTDM[currentFrame][0*16+2]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][1])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][0*16+6]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][3])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][0*16+10]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][5])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][0*16+14]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][7])) >> 8, -23),31))>>8;

 

      Tx1BlockTDM[currentFrame][1*16+2]     = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][9])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][1*16+6]     = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][11])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][1*16+10]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][13])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][1*16+14]     = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][15])) >> 8, -23),31))>>8;

 

      Tx1BlockTDM[currentFrame][2*16+2]     = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][17])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][2*16+6]     = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][19])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][2*16+10]    = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][21])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][2*16+14]     = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][23])) >> 8, -23),31))>>8;

 

      Tx1BlockTDM[currentFrame][3*16+2]   = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][25])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][3*16+6]   = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][27])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][3*16+10]  = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][29])) >> 8, -23),31))>>8;

      Tx1BlockTDM[currentFrame][3*16+14]   = (conv_trunc_by( conv_float_by((( int) *(&Rx2BlockSPDIF[currentFrame][31])) >> 8, -23),31))>>8;

 

      /*Digital Out L*/

      Tx3BlockSPDIF[currentFrame][0] =  (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][0*16+0])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][2] =  (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][0*16+4])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][4] =  (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][0*16+8])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][6] =  (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][0*16+12])) >> 8, -23),31))>>8;

 

      Tx3BlockSPDIF[currentFrame][8] =  (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][1*16+0])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][10] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][1*16+4])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][12] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][1*16+8])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][14] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][1*16+12])) >> 8, -23),31))>>8;

 

      Tx3BlockSPDIF[currentFrame][16] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][2*16+0])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][18] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][2*16+4])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][20] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][2*16+8])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][22] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][2*16+12])) >> 8, -23),31))>>8;

 

      Tx3BlockSPDIF[currentFrame][24] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][3*16+0])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][26] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][3*16+4])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][28] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][3*16+8])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][30] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][3*16+12])) >> 8, -23),31))>>8;

 

      /*Digital Out R*/

      Tx3BlockSPDIF[currentFrame][1] =  (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][0*16+2])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][3] =  (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][0*16+6])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][5] =  (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][0*16+10])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][7] =  (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][0*16+14])) >> 8, -23),31))>>8;

 

      Tx3BlockSPDIF[currentFrame][9] =  (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][1*16+2])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][11] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][1*16+6])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][13] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][1*16+10])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][15] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][1*16+14])) >> 8, -23),31))>>8;

 

      Tx3BlockSPDIF[currentFrame][17] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][2*16+2])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][19] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][2*16+6])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][21] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][2*16+10])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][23] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][2*16+14])) >> 8, -23),31))>>8;

 

      Tx3BlockSPDIF[currentFrame][25] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][3*16+2])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][27] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][3*16+6])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][29] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][3*16+10])) >> 8, -23),31))>>8;

      Tx3BlockSPDIF[currentFrame][31] = (conv_trunc_by( conv_float_by((( int) *(&Rx0BlockTDM[currentFrame][3*16+14])) >> 8, -23),31))>>8;

 

 

      if (previousFrame == 0)

      {

            *pCPSP1A = ((unsigned int) TCB_Tx1BlockTDM_A1 + 7) & 0x7FFFF;

      }

      else

      {

            *pCPSP1A = ((unsigned int) TCB_Tx1BlockTDM_A0 + 7) & 0x7FFFF;

      }

      return;

}

 

void initSerialRoutingUnitTDM2() {

      clearDAIpins();

      /*---------------------------------------------------------*/

      /*Dig_Input -> SRC1 -> SPORT2 -> DSP */

      /*TDM_Input ->  ->  -> SPORT0 -> DSP */

 

      /*DSP -> SPORT1  ->  -> -> TDM_Output*/

      /*DSP -> SPORT3 -> SDRC2 -> Dig_output*/

      /*---------------------------------------------------------*/

 

      /* SRC1 (InputClock:Dig_Input|| OutputClock:PCGA(192kHz)) */

      /*PCGA:  49.152 MHz to 192kHz (divider 256). 192kHz -> (re-sampled DigIn, DigOut(before resampling))(SRC1(O), SPORT0, SPORT3, (SRC2 is not used))* /

      /*PCGB: 49.152 MHz to 16*48kHz (divider 64). 192kHz->[SPORT2, Dig_Output]*/

      /*PCGC: 49.152 MHz to 48/96/192kHz(user selectable)->[SPORT2, Dig_Output]*/

 

      SRU(HIGH, PBEN01_I);

      SRU(HIGH, PBEN19_I);

      SRU(HIGH, PBEN13_I);

 

 

      /*DAI_1 to Dig_Input*/

      SRU(DAI_PB02_O, DIR_I);

 

      /**********************Digital In**********************/

 

      /*Dig_Input -> SRC1*/

      SRU(DIR_DAT_O, SRC1_DAT_IP_I);

      SRU(DIR_FS_O, SRC1_FS_IP_I);

      SRU(DIR_CLK_O, SRC1_CLK_IP_I);

 

      /*SRC1 -> SPORT2*/

      SRU(SRC1_DAT_OP_O, SPORT2_DA_I);

 

      /**********************Digital Out*********************/

      SRU(SPORT3_DA_O, DIT_DAT_I);

 

      /**********************TDM In**************************/

      /*TDM_IN->SPORT2->DSP*/

      SRU(DAI_PB07_O, SPORT0_DA_I);

 

      /**********************TDM Out*************************/

      /*DSP->SPORT1->TDM_OUT*/

      SRU(SPORT1_DA_O, DAI_PB13_I);

 

      /*TDM Loopback test*/

      //SRU(DAI_PB13_O, SPORT0_DA_I);

      //SRU(DAI_PB13_O, SPORT0_DA_I);

 

      /*Clocks*/

      /*External 49.152 MHz connected to DAI_PB03_I*/

      /*49.152 MHz to PCGA, PCGB and PCGC*/

      SRU(DAI_PB03_O, PCG_EXTA_I);

      SRU(DAI_PB03_O, PCG_EXTB_I);

      SRU(DAI_PB03_O, PCG_EXTC_I);

      SRU(DAI_PB03_O, PCG_EXTD_I);

 

      /*PCGA(48kHz) to SRC1*/

      SRU(PCG_FSA_O, SRC1_FS_OP_I);

      SRU(PCG_CLKA_O, SRC1_CLK_OP_I);

 

      /*PCGA(48kHz) to SPORT0*/

      SRU(PCG_FSA_O, SPORT0_FS_I);

      SRU(PCG_CLKA_O, SPORT0_CLK_I);

 

      /*PCGA(48kHz) to SPORT2*/

      SRU(PCG_FSA_O, SPORT2_FS_I);

      SRU(PCG_CLKA_O, SPORT2_CLK_I);

 

      /*PCGC(selectable 48, 96, 192 kHz) to SPORT3*/

      SRU(PCG_FSA_O, SPORT3_FS_I);

      SRU(PCG_CLKA_O, SPORT3_CLK_I);

 

      /*PCGA(48kHz) to SRC2(I)*/

      SRU(PCG_FSA_O, SRC2_FS_IP_I);

      SRU(PCG_CLKA_O, SRC2_CLK_IP_I);

 

      /*PCGC(48kHz-98kHz-192kHz) to SRC2(O)*/

      SRU(PCG_FSC_O, SRC2_FS_OP_I);

      SRU(PCG_CLKC_O, SRC2_CLK_OP_I);

 

      /*SPDIF Tx Clock*/

      SRU(PCG_FSA_O, DIT_FS_I);

      SRU(PCG_CLKA_O, DIT_CLK_I);

      SRU(DAI_PB03_O, DIT_HFCLK_I);

 

      /*PCGB(16*48kHz) to SPORT1*/

      SRU(PCG_CLKB_O, SPORT1_CLK_I);

      SRU(SPORT1_FS_O, DAI_PB19_I);

 

      /*PCGB(16*48kHz) to SPORT0*/

      SRU(PCG_CLKB_O, SPORT0_CLK_I);

 

      SRU(PCG_CLKB_O, DAI_PB01_I);

 

      /*SPDIF TX*/

      SRU(HIGH, PBEN06_I);

      SRU(DIT_O, DAI_PB06_I);

 

 

      //SPI Configuration

      /*SPI pins for communication with main processor*/

      SRU2(LOW, DPI_PBEN01_I);

      SRU2(DPI_PB01_O, SPI_MOSI_I);

 

      SRU2(HIGH, DPI_PBEN02_I);

      SRU2(SPI_MISO_O, DPI_PB02_I);

 

      SRU2(LOW, DPI_PBEN03_I);

      SRU2(DPI_PB03_O, SPI_CLK_I);

 

      SRU2(LOW, DPI_PBEN04_I);

      SRU2(DPI_PB04_O, SPI_DS_I);

      return;

}

 

void InitPCGTDM(void)

{

      *pPCG_CTLA1 = CLKASOURCE|FSASOURCE|4; // CLKADIV = 4

      *pPCG_CTLA0 =  ENCLKA|ENFSA|256|((256/2) <<20) ; // FS DIVISOR = 256

 

      /*48*16 kHz*/

      *pPCG_CTLB1 = CLKBSOURCE|FSASOURCE|2; // CLKADIV = 2 (input 49.152 MHz, output (16*48000*32 = 24.576 MHz))

      *pPCG_CTLB0 =  ENCLKB; // FS DIVISOR = 256

 

 

      *pPCG_CTLD1 = CLKDSOURCE|FSDSOURCE|4; // CLKADIV = 4

      *pPCG_CTLD0 =  ENCLKD|ENFSD|256|((256/2) <<20) ; // FS DIVISOR = 256

}

 

 

 

 

 

 

 

 

section("seg_dmda") unsigned int Rx2BlockSPDIF[2][NWINDOW*2*4];//*4 for 192kHz

section("seg_dmda") unsigned int Tx3BlockSPDIF[2][NWINDOW*2*4];

 

section("seg_dmda") unsigned int Rx0BlockTDM[2][NWINDOW*16];

section("seg_dmda") unsigned int Tx1BlockTDM[2][NWINDOW*16];

 

int   TCB_Rx0Block_A0[8]  = {0, 0, 0, 0, 0, sizeof(Rx0Block[0]), 1, (int) Rx0Block[0]};     /* SPORT0 receive TCB */

int   TCB_Rx0Block_A1[8]  = {0, 0, 0, 0, 0, sizeof(Rx0Block[1]), 1, (int) Rx0Block[1]};     /* SPORT0 receive TCB */

int   TCB_Tx1Block_A0[8]  = {0, 0, 0, 0, 0, sizeof(Tx1Block[0]), 1, (int) Tx1Block[0]};     /* SPORT1 TX TCB */

int   TCB_Tx1Block_A1[8]  = {0, 0, 0, 0, 0, sizeof(Tx1Block[1]), 1, (int) Tx1Block[1]};     /* SPORT1 TX TCB */

 

 

int   TCB_Rx0BlockTDM_A0[8]  = {0, 0, 0, 0, 0, sizeof(Rx0BlockTDM[0]), 1, (int) Rx0BlockTDM[0]};     /* SPORT0 receive TCB */

int   TCB_Rx0BlockTDM_A1[8]  = {0, 0, 0, 0, 0, sizeof(Rx0BlockTDM[1]), 1, (int) Rx0BlockTDM[1]};     /* SPORT0 receive TCB */

int   TCB_Tx1BlockTDM_A0[8]  = {0, 0, 0, 0, 0, sizeof(Tx1BlockTDM[0]), 1, (int) Tx1BlockTDM[0]};     /* SPORT1 TX TCB */

int   TCB_Tx1BlockTDM_A1[8]  = {0, 0, 0, 0, 0, sizeof(Tx1BlockTDM[1]), 1, (int) Tx1BlockTDM[1]};     /* SPORT1 TX TCB */

 

int   TCB_Rx2BlockSPDIF_A0[8]  = {0, 0, 0, 0, 0, sizeof(Rx2BlockSPDIF[0]), 1, (int) Rx2BlockSPDIF[0]}; /* SPORT0 receive TCB */

int   TCB_Rx2BlockSPDIF_A1[8]  = {0, 0, 0, 0, 0, sizeof(Rx2BlockSPDIF[1]), 1, (int) Rx2BlockSPDIF[1]}; /* SPORT0 receive TCB */

int   TCB_Tx3BlockSPDIF_A0[8]  = {0, 0, 0, 0, 0, sizeof(Tx3BlockSPDIF[0]), 1, (int) Tx3BlockSPDIF[0]}; /* SPORT1 TX TCB */

int   TCB_Tx3BlockSPDIF_A1[8]  = {0, 0, 0, 0, 0, sizeof(Tx3BlockSPDIF[1]), 1, (int) Tx3BlockSPDIF[1]}; /* SPORT1 TX TCB */

 

void InitSPORTTDM2(void)

{

      /***************TDM BUS DMA******************/

      // Set up "ping-pong" chained DMAs

      //Proceed from Block A0 to Block A1

      TCB_Tx1BlockTDM_A0[4] = ((unsigned int) TCB_Tx1BlockTDM_A1 + 7) & 0x7FFFF;// | (1<<19);

      TCB_Tx1BlockTDM_A0[7] = (unsigned int) Tx1BlockTDM[0] - OFFSET;

    //Proceed from Block A1 to Block A0

      TCB_Tx1BlockTDM_A1[4] = ((unsigned int) TCB_Tx1BlockTDM_A0 + 7) & 0x7FFFF;// | (1<<19);

      TCB_Tx1BlockTDM_A1[7] = (unsigned int) Tx1BlockTDM[1] - OFFSET;

 

      //Proceed from Block A0 to Block A1

      TCB_Rx0BlockTDM_A0[4] = (((unsigned int) TCB_Rx0BlockTDM_A1 + 7) & 0x7FFFF) | (1<<19);

      TCB_Rx0BlockTDM_A0[7] = (unsigned int) Rx0BlockTDM[0] - OFFSET;

      //Proceed from Block A1 to Block A0

      TCB_Rx0BlockTDM_A1[4] = (((unsigned int) TCB_Rx0BlockTDM_A0 + 7) & 0x7FFFF) | (1<<19);

      TCB_Rx0BlockTDM_A1[7] = (unsigned int) Rx0BlockTDM[1] - OFFSET;

 

 

      /***************SPDIF DMA******************/

      TCB_Tx3BlockSPDIF_A0[4] = ((unsigned int) TCB_Tx3BlockSPDIF_A1 + 7) & 0x7FFFF;// | (1<<19);

      TCB_Tx3BlockSPDIF_A0[7] = (unsigned int) Tx3BlockSPDIF[0] - OFFSET;

    //Proceed from Block A1 to Block A0

      TCB_Tx3BlockSPDIF_A1[4] = ((unsigned int) TCB_Tx3BlockSPDIF_A0 + 7) & 0x7FFFF;// | (1<<19);

      TCB_Tx3BlockSPDIF_A1[7] = (unsigned int) Tx3BlockSPDIF[1] - OFFSET;

 

      //Proceed from Block A0 to Block A1

      TCB_Rx2BlockSPDIF_A0[4] = (((unsigned int) TCB_Rx2BlockSPDIF_A1 + 7) & 0x7FFFF) | (1<<19);

      TCB_Rx2BlockSPDIF_A0[7] = (unsigned int) Rx2BlockSPDIF[0] - OFFSET;

      //Proceed from Block A1 to Block A0

      TCB_Rx2BlockSPDIF_A1[4] = (((unsigned int) TCB_Rx2BlockSPDIF_A0 + 7) & 0x7FFFF) | (1<<19);

      TCB_Rx2BlockSPDIF_A1[7] = (unsigned int) Rx2BlockSPDIF[1] - OFFSET;

 

    //============================================================

    // Make sure that the multichannel mode registers are cleared

    //============================================================

      *pSPCTL0 = 0;

      *pSPCTL1 = 0;

      *pSPCTL2 = 0;

      *pSPCTL3 = 0;

      *pSPCTL4 = 0;

 

      *pSPMCTL0 = 0;

      *pSPMCTL1 = 0;

      *pSPMCTL2 = 0;

      *pSPMCTL3 = 0;

      *pSPMCTL4 = 0;

 

      *pCPSP0A = 0;

      *pCPSP1A = 0;

 

      *pSP0CS0 = 0xffff;// Activate 16 channels

      *pSP1CS0 = 0xffff;// Activate 16 channels

 

    *pDIV0 = 0;

    *pDIV1 = 0;

 

    *pDIV0 = 511 << 16;

    *pDIV1 = 511 << 16;

 

      *pCPSP1A = ((unsigned int) TCB_Tx1BlockTDM_A0  + 7) & 0x7FFFF;

      *pCPSP0A = ((unsigned int) TCB_Rx0BlockTDM_A0  + 7) & 0x7FFFF;

 

    //============================================================

    // Configure SPORTs 1 as transmiters to DACs 1-4

    //============================================================

    *pSPCTL1 = SPTRAN | SLEN32 | SDEN_A | SCHEN_A | IMFS | BHD | DIFS | CKRE;

 

    //============================================================

    // Configure SPORT 0 as a receiver

    //============================================================

    *pSPCTL0 = SLEN32 | SDEN_A | SCHEN_A | IMFS | BHD | DIFS | CKRE;

 

 

      while(*pSPMCTL1 & DMACHS1A);

 

      *pSPMCTL0 = MFD0 | NCH15 | MCEA ;

      *pSPMCTL1 = MFD0 | NCH15 | MCEA ;

 

 

      /*SPDIF SPORTS INIT (RX on SPORT2 TX on SPORT3)*/

    *pDIV2 = 0;

    *pDIV3 = 0;

 

      *pCPSP2A = ((unsigned int) TCB_Rx2BlockSPDIF_A0  + 7) & 0x7FFFF;

      *pCPSP3A = ((unsigned int) TCB_Tx3BlockSPDIF_A0  + 7) & 0x7FFFF;

 

    //============================================================

    // Configure SPORT 2 as a receiver

    *pSPCTL2 = OPMODE | L_FIRST | SLEN32 | SPEN_A | SDEN_A | SCHEN_A;

 

      //*pSPCTL1 = ( LAFS | OPMODE | SLEN32 | SPEN_A | SCHEN_A | SDEN_A |L_FIRST  );

    //*pSPCTL2 = OPMODE | L_FIRST | SLEN32 | SPEN_A ;

 

    //============================================================

    // Configure SPORT 3 as transmiters to DACs 1-4

    *pSPCTL3 = SPTRAN | OPMODE | L_FIRST | SLEN24 | SPEN_A | SDEN_A | SCHEN_A;// | LAFS;

    //*pSPCTL4 = SPTRAN | OPMODE | L_FIRST | SLEN24 | SPEN_A | SPEN_B|SDEN_A|SCHEN_A|SDEN_B|SCHEN_B;

}

Outcomes