I2S speed test wip

Dependencies:   mbed

main.cpp

Committer:
jtarasidis
Date:
2020-04-25
Revision:
1:3c1ad60f5cf3
Parent:
0:b847a1ffc64f
Child:
2:8008da2bb047

File content as of revision 1:3c1ad60f5cf3:

#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);

FastOut<p21> pixel;
void pixelout(void) {
    pixel = 1;
    wait(0.1);
    pixel=0;
    wait(0.1);
}

int main() {
    setpll();
    pllfeed();
    pixelout();
    //char s[] = "I2S CCLK/4 Verification Test";
    
    //turn on i2s periph
    //LPC_SC -> PCONP |= (1 << 27);
    //set PCLK_peripheral = CCLK/2 so that serial tx CCLK/4
    //LPC_SC -> PCLKSEL1 |= (2 << 22);
    //assign clock pin and probe
    
    //LPC_I2S -> I2STXRATE |= (4 | (1 << 8));
    
    
    //monaural format; master mode
    //LPC_I2S -> I2SDAO |= (0x8);
    
    //connect i2s channel 0 tx to dma
    //LPC_I2S -> I2SDMA1 |= (0x70002);
    
    //select p5 pin for i2s tx
    //LPC_PINCON -> PINSEL0 |= (1 << 18);
    //LPC_PINCON -> PINSEL0 |= (1 << 14); 

    
    //MODDMA_Config *config = new MODDMA_Config;
    //config
    // ->channelNum    ( MODDMA::Channel_0 )
    // ->srcMemAddr    ( (uint32_t) &s )
    // ->dstMemAddr    ( LPC_I2S -> I2STXFIFO )
    // ->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);
        pixelout();
    }
}