4.6.3 CLASSD Initialization

The following code snippet initializes the CLASSD interface with its clock source set to Audio PLL through PMC’s GCLK source.

/* Enable Audio PLL as source for CLASSD through GCLK */
PMC->PMC_PCR = PMC_PCR_PID(ID_CLASSD)
                 | PMC_PCR_GCKCSS_AUDIO_CLK 
                 | PMC_PCR_CMD 
                 | PMC_PCR_EN
                 | PMC_PCR_GCKEN;

/* Wait until GCLK is ready */
while (!(PMC->PMC_SR & PMC_SR_GCKRDY));

/* Perform software reset of CLASSD peripheral */
CLASSD->CLASSD_CR = CLASSD_CR_SWRST;

/* Configure CLASSD parameters */
CLASSD->CLASSD_MR = CLASSD_MR_LEN 
                        | CLASSD_MR_REN 
                        | CLASSD_MR_PWMTYP 
                        | CLASSD_MR_NON_OVERLAP
                        | CLASSD_MR_NOVRVAL_20NS;

CLASSD->CLASSD_INTPMR = CLASSD_INTPMR_DSPCLKFREQ_12M288
                            | CLASSD_INTPMR_FRAME_FRAME_48K
                            | CLASSD_INTPMR_ATTL(10)
                            | CLASSD_INTPMR_ATTR(10);

/* Enable DMA channel */
XDMAC0->XDMAC_GE = XDMAC_GE_EN0;

/* Wait until DMA transfer is done */
while(!(XDMAC0->XDMAC_CHID[0].XDMAC_CIS & XDMAC_CIS_BIS));

The Audio PLL clock output of 98.304 MHz is fed to the CLASSD module using the GCLK controller in PMC. The CLASSD has an internal fixed divide-by-8 prescaler, which provides the 12.288 MHz clock to the DSP engine of the CLASSD module.

The CLASSD module is configured in Non-overlap mode with PWMTYP=1 and a non-overlap delay of 20 ns. The interpolator is configured for 12.288 MHz and a sample rate of 48 kHz. The attenuation for the left and right channels is set to -10 dB.

The XDMAC channel is enabled, which starts the audio sample transfers from the buffer to the CLASSD transmit holding register, one audio sample (with both left and right channel data) at a time. The XDMAC channel block interrupt flag (BIS) will be set once the specified number of micro block length data are transferred, and the CPU will come out of the last while loop in the above code snippet.