I2S speed test wip

Dependencies:   mbed

main.cpp

Committer:
jtarasidis
Date:
2020-04-13
Revision:
0:b847a1ffc64f
Child:
1:3c1ad60f5cf3

File content as of revision 0:b847a1ffc64f:

#include "mbed.h"
//#include "SDFileSystem"
//#include "FastIO.h"
#include "MODDMA.h"


void pllfeed() {
    __disable_irq();
    LPC_SC->PLL0FEED=0x000000aa;
    LPC_SC->PLL0FEED=0x00000055;
    __enable_irq();    
}
void setpll() {
    // the MBED crystal oscillator is 12 MHz
    // main oscillator frequency 300 MHz: M = (300 x N) / (2 x 12)
    int n=2;
    int m=25;
    // processor clock 100 MHz = 300 MHz / D
    int d=3;
    // disconnect
    LPC_SC->PLL0CON=0x00000001; pllfeed();
    // disable
    LPC_SC->PLL0CON=0x00000000; pllfeed();
    // set new PLL values
    LPC_SC->PLL0CFG=((n-1)<<16)|(m-1); pllfeed();
    // enable
    LPC_SC->PLL0CON=0x00000001; pllfeed();
    // set cpu clock divider
    LPC_SC->CCLKCFG=d-1;
    // wait for lock
    while (LPC_SC->PLL0STAT&0x04000000==0);
    // connect
    LPC_SC->PLL0CON=0x00000003; pllfeed();
}


DigitalOut led1(LED1);
DigitalOut led2(LED2);

MODDMA dma;

void TC0_callback(void) {
    led1 = 1;
}

Serial test(p13, p14);

int main() {
    setpll();
    pllfeed();
    
    char s[] = "I2S CCLK/4 Verification Test";
    
    //turn on i2s periph
    LPC_SC -> PCONP |= (1 << 27);
    
    //set PCLK_peripheral = CCLK/2; such that bitstream is CCLK/4
    LPC_SC -> PCLKSEL1 |= (2 << 22);
    
    //monaural format; master mode
    LPC_I2S -> I2SDAO |= (0x8);
    
    //connect i2s channel 0 tx to dma
    LPC_I2S -> I2SDMA1 |= (0x80002);
    
    //select p5 pin for i2s tx
    LPC_PINCON -> PINSEL0 |= (1 << 18);

    
    MODDMA_Config *config = new MODDMA_Config;
    config
     ->channelNum    ( MODDMA::Channel_0 )
     ->srcMemAddr    ( (uint32_t) &s )
     ->dstMemAddr    ( 0 )
     ->transferSize  ( sizeof(s) )
     ->transferType  ( MODDMA::m2p )
     ->transferWidth ( 8 )
     ->srcConn       ( 0 )
     ->dstConn       ( MODDMA::I2S_Channel_0 )
     ->dmaLLI        ( 0 )
     ->attach_tc     ( &TC0_callback )
    ;
    
    dma.Setup(config);
    dma.Enable(config);
    while(1) {
        printf("%d ;", LPC_I2S -> I2SSTATE);
        wait(0.5);
    }
}