Aidan Walton / Mbed 2 deprecated ClockControl

Dependencies:   mbed

Fork of ClockControl by Michael Wei

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "ClockControl/ClockControl.h"
00003 #include "CoreMark/core_portme.h"
00004 
00005 int main() {
00006     while(1) {   
00007     
00008 
00009     printf("mbed Clock Control test\r\n");
00010     printf("(c) 2010 Michael Wei\r\n");
00011     
00012     unsigned short newM = 12;
00013     unsigned short newN = 1;
00014     unsigned char newUSBdiv = 6;
00015     
00016     printf("Value of M? (default = 12):\r\n");
00017     scanf("%d", &newM);
00018     
00019     printf("Value of N? (default = 1):\r\n");
00020     scanf("%d", &newN);
00021     
00022     printf("Value of USB divider? (default = 6):\r\n");
00023     scanf("%d", &newUSBdiv);
00024     
00025     setSystemFrequency(newUSBdiv, 0x3, 0x1, newM, newN);
00026     
00027     Serial pc(USBTX, USBRX); // tx, rx
00028     
00029     //This code by Simon Ford: http://mbed.org/forum/mbed/topic/229/?page=1#comment-1225
00030     
00031     int Fin = 12000000; // 12MHz XTAL
00032     pc.printf("PLL Registers:\r\n");
00033     pc.printf(" - PLL0CFG = 0x%08X\r\n", LPC_SC->PLL0CFG);
00034     pc.printf(" - CLKCFG  = 0x%08X\r\n", LPC_SC->CCLKCFG);
00035     
00036     int M = (LPC_SC->PLL0CFG & 0xFFFF) + 1;
00037     int N = (LPC_SC->PLL0CFG >> 16) + 1;
00038     int CCLKDIV = LPC_SC->CCLKCFG + 1;
00039     int USBCLKDIV = LPC_SC->USBCLKCFG + 1;
00040 
00041     pc.printf("Clock Variables:\r\n");
00042     pc.printf(" - Fin = %d\r\n", Fin);
00043     pc.printf(" - M   = %d\r\n", M);
00044     pc.printf(" - N   = %d\r\n", N);
00045     pc.printf(" - CCLKDIV = %d\r\n", CCLKDIV);
00046     pc.printf(" - USBCLKDIV = %d\r\n", USBCLKDIV);
00047 
00048     int Fcco = (2 * M * 12000000) / N;
00049     int CCLK = Fcco / CCLKDIV;
00050 
00051     pc.printf("Clock Results:\r\n");    
00052     pc.printf(" - Fcco = %d\r\n", Fcco);
00053     
00054     printf(" - CCLK = %d\r\n", CCLK);
00055     
00056     printf("Run CoreMark? (Y/N)\n");
00057     char buf[8];
00058     scanf("%s", buf);
00059     if (buf[0] == 'y' || buf[0] == 'Y')
00060     {
00061         mainCoreMark();
00062     }
00063     
00064     wait(1);
00065     NVIC_SystemReset();
00066     }
00067 }