skeleton code for WES237B lab2

Dependencies:   mbed

Fork of ClockControl by Michael Wei

Committer:
mbed36372
Date:
Fri Apr 18 01:26:02 2014 +0000
Revision:
2:53ed37115187
Parent:
1:5dd5b87217e5
change getTickCount in folder;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
no2chem 0:b5d3bd64d2dc 1 #include "mbed.h"
no2chem 0:b5d3bd64d2dc 2
mbed36372 1:5dd5b87217e5 3 //Need to include these two libraries
mbed36372 1:5dd5b87217e5 4 #include "ClockControl/ClockControl.h"
mbed36372 1:5dd5b87217e5 5 #include "GetTickCount/GetTickCount.h"
mbed36372 1:5dd5b87217e5 6
mbed36372 1:5dd5b87217e5 7 Serial pc(USBTX, USBRX); // tx, rx
mbed36372 1:5dd5b87217e5 8 //Timer t;
no2chem 0:b5d3bd64d2dc 9
mbed36372 1:5dd5b87217e5 10 // A sample function
mbed36372 1:5dd5b87217e5 11 void foo(int n) {
mbed36372 1:5dd5b87217e5 12 for (int i = 0; i < n; i++) {
mbed36372 1:5dd5b87217e5 13 for (int j = 0; j < n; j++) {
mbed36372 1:5dd5b87217e5 14 for (int k = 0; k < n; k++) {
mbed36372 1:5dd5b87217e5 15 int num = rand()%1024;
mbed36372 1:5dd5b87217e5 16 }
mbed36372 1:5dd5b87217e5 17 }
no2chem 0:b5d3bd64d2dc 18 }
no2chem 0:b5d3bd64d2dc 19 }
mbed36372 1:5dd5b87217e5 20
mbed36372 1:5dd5b87217e5 21 int main() {
mbed36372 1:5dd5b87217e5 22 while(1) {
mbed36372 1:5dd5b87217e5 23 // Input M and N
mbed36372 1:5dd5b87217e5 24 unsigned short newM=12, newN=1;
mbed36372 1:5dd5b87217e5 25
mbed36372 1:5dd5b87217e5 26 // Default value is M=12, N=1, frequency is 96MHz
mbed36372 1:5dd5b87217e5 27 pc.printf("Value of M? (default = 12):\r\n");
mbed36372 1:5dd5b87217e5 28 pc.scanf("%hu", &newM);
mbed36372 1:5dd5b87217e5 29
mbed36372 1:5dd5b87217e5 30 pc.printf("Value of N? (default = 1):\r\n");
mbed36372 1:5dd5b87217e5 31 pc.scanf("%hu", &newN);
mbed36372 1:5dd5b87217e5 32
mbed36372 1:5dd5b87217e5 33 pc.printf("M = %hu, N = %hu\r\n", newM, newN);
mbed36372 1:5dd5b87217e5 34
mbed36372 1:5dd5b87217e5 35 // Set system clock according to M, N.
mbed36372 1:5dd5b87217e5 36 setSystemFrequency(0x3, 0x1, newM, newN);
mbed36372 1:5dd5b87217e5 37
mbed36372 1:5dd5b87217e5 38 // Reconfigure the serial
mbed36372 1:5dd5b87217e5 39 pc.baud(9600);
mbed36372 1:5dd5b87217e5 40
mbed36372 1:5dd5b87217e5 41 // The foo() function takes a certain number of cpu cycles
mbed36372 1:5dd5b87217e5 42 // When the cpu clock rate changed, the actual time passed changed
mbed36372 1:5dd5b87217e5 43 // "GetTickCount" could acquire the real time passed.
mbed36372 1:5dd5b87217e5 44 GetTickCount_Start();
mbed36372 1:5dd5b87217e5 45 pc.printf("Begin func\r\n");
mbed36372 1:5dd5b87217e5 46 foo(200);
mbed36372 1:5dd5b87217e5 47 pc.printf("The actual time passed is %d\r\n", GetTickCount());
mbed36372 1:5dd5b87217e5 48
mbed36372 1:5dd5b87217e5 49 // Clean system state
mbed36372 1:5dd5b87217e5 50 wait(1);
mbed36372 1:5dd5b87217e5 51 NVIC_SystemReset();
mbed36372 1:5dd5b87217e5 52 }
mbed36372 1:5dd5b87217e5 53 }