skeleton code for WES237B lab2

Dependencies:   mbed

Fork of ClockControl by Michael Wei

main.cpp

Committer:
mbed36372
Date:
2014-04-18
Revision:
2:53ed37115187
Parent:
1:5dd5b87217e5

File content as of revision 2:53ed37115187:

#include "mbed.h"

//Need to include these two libraries
#include "ClockControl/ClockControl.h"
#include "GetTickCount/GetTickCount.h"

Serial pc(USBTX, USBRX); // tx, rx    
//Timer t;

// A sample function
void foo(int n) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                int num =  rand()%1024;
            }
        }
    }
}

int main() {    
    while(1) {   
        // Input M and N
        unsigned short newM=12, newN=1;
        
        // Default value is M=12, N=1, frequency is 96MHz
        pc.printf("Value of M? (default = 12):\r\n");
        pc.scanf("%hu", &newM);
    
        pc.printf("Value of N? (default = 1):\r\n");
        pc.scanf("%hu", &newN);
        
        pc.printf("M = %hu, N = %hu\r\n", newM, newN);
    
        // Set system clock according to M, N.
        setSystemFrequency(0x3, 0x1, newM, newN);    
            
        // Reconfigure the serial
        pc.baud(9600);
        
        // The foo() function takes a certain number of cpu cycles
        // When the cpu clock rate changed, the actual time passed changed
        // "GetTickCount" could acquire the real time passed.
        GetTickCount_Start();
        pc.printf("Begin func\r\n");
        foo(200);
        pc.printf("The actual time passed is %d\r\n", GetTickCount());
        
        // Clean system state
        wait(1);
        NVIC_SystemReset();
    }
}