
see http://mbed.org/users/no2chem/notebook/mbed-clock-control--benchmarks/
main.cpp@0:b5d3bd64d2dc, 2010-01-24 (annotated)
- Committer:
- no2chem
- Date:
- Sun Jan 24 15:46:26 2010 +0000
- Revision:
- 0:b5d3bd64d2dc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
no2chem | 0:b5d3bd64d2dc | 1 | #include "mbed.h" |
no2chem | 0:b5d3bd64d2dc | 2 | #include "ClockControl/ClockControl.h" |
no2chem | 0:b5d3bd64d2dc | 3 | #include "CoreMark/core_portme.h" |
no2chem | 0:b5d3bd64d2dc | 4 | |
no2chem | 0:b5d3bd64d2dc | 5 | int main() { |
no2chem | 0:b5d3bd64d2dc | 6 | while(1) { |
no2chem | 0:b5d3bd64d2dc | 7 | |
no2chem | 0:b5d3bd64d2dc | 8 | |
no2chem | 0:b5d3bd64d2dc | 9 | printf("mbed Clock Control test\r\n"); |
no2chem | 0:b5d3bd64d2dc | 10 | printf("(c) 2010 Michael Wei\r\n"); |
no2chem | 0:b5d3bd64d2dc | 11 | |
no2chem | 0:b5d3bd64d2dc | 12 | unsigned short newM = 12; |
no2chem | 0:b5d3bd64d2dc | 13 | unsigned short newN = 1; |
no2chem | 0:b5d3bd64d2dc | 14 | |
no2chem | 0:b5d3bd64d2dc | 15 | printf("Value of M? (default = 12):\r\n"); |
no2chem | 0:b5d3bd64d2dc | 16 | scanf("%d", &newM); |
no2chem | 0:b5d3bd64d2dc | 17 | |
no2chem | 0:b5d3bd64d2dc | 18 | printf("Value of N? (default = 1):\r\n"); |
no2chem | 0:b5d3bd64d2dc | 19 | scanf("%d", &newN); |
no2chem | 0:b5d3bd64d2dc | 20 | |
no2chem | 0:b5d3bd64d2dc | 21 | setSystemFrequency(0x3, 0x1, newM, newN); |
no2chem | 0:b5d3bd64d2dc | 22 | |
no2chem | 0:b5d3bd64d2dc | 23 | Serial pc(USBTX, USBRX); // tx, rx |
no2chem | 0:b5d3bd64d2dc | 24 | |
no2chem | 0:b5d3bd64d2dc | 25 | //This code by Simon Ford: http://mbed.org/forum/mbed/topic/229/?page=1#comment-1225 |
no2chem | 0:b5d3bd64d2dc | 26 | |
no2chem | 0:b5d3bd64d2dc | 27 | int Fin = 12000000; // 12MHz XTAL |
no2chem | 0:b5d3bd64d2dc | 28 | pc.printf("PLL Registers:\r\n"); |
no2chem | 0:b5d3bd64d2dc | 29 | pc.printf(" - PLL0CFG = 0x%08X\r\n", LPC_SC->PLL0CFG); |
no2chem | 0:b5d3bd64d2dc | 30 | pc.printf(" - CLKCFG = 0x%08X\r\n", LPC_SC->CCLKCFG); |
no2chem | 0:b5d3bd64d2dc | 31 | |
no2chem | 0:b5d3bd64d2dc | 32 | int M = (LPC_SC->PLL0CFG & 0xFFFF) + 1; |
no2chem | 0:b5d3bd64d2dc | 33 | int N = (LPC_SC->PLL0CFG >> 16) + 1; |
no2chem | 0:b5d3bd64d2dc | 34 | int CCLKDIV = LPC_SC->CCLKCFG + 1; |
no2chem | 0:b5d3bd64d2dc | 35 | |
no2chem | 0:b5d3bd64d2dc | 36 | pc.printf("Clock Variables:\r\n"); |
no2chem | 0:b5d3bd64d2dc | 37 | pc.printf(" - Fin = %d\r\n", Fin); |
no2chem | 0:b5d3bd64d2dc | 38 | pc.printf(" - M = %d\r\n", M); |
no2chem | 0:b5d3bd64d2dc | 39 | pc.printf(" - N = %d\r\n", N); |
no2chem | 0:b5d3bd64d2dc | 40 | pc.printf(" - CCLKDIV = %d\r\n", CCLKDIV); |
no2chem | 0:b5d3bd64d2dc | 41 | |
no2chem | 0:b5d3bd64d2dc | 42 | int Fcco = (2 * M * 12000000) / N; |
no2chem | 0:b5d3bd64d2dc | 43 | int CCLK = Fcco / CCLKDIV; |
no2chem | 0:b5d3bd64d2dc | 44 | |
no2chem | 0:b5d3bd64d2dc | 45 | pc.printf("Clock Results:\r\n"); |
no2chem | 0:b5d3bd64d2dc | 46 | pc.printf(" - Fcco = %d\r\n", Fcco); |
no2chem | 0:b5d3bd64d2dc | 47 | |
no2chem | 0:b5d3bd64d2dc | 48 | printf(" - CCLK = %d\r\n", CCLK); |
no2chem | 0:b5d3bd64d2dc | 49 | |
no2chem | 0:b5d3bd64d2dc | 50 | printf("Run CoreMark? (Y/N)\n"); |
no2chem | 0:b5d3bd64d2dc | 51 | char buf[8]; |
no2chem | 0:b5d3bd64d2dc | 52 | scanf("%s", buf); |
no2chem | 0:b5d3bd64d2dc | 53 | if (buf[0] == 'y' || buf[0] == 'Y') |
no2chem | 0:b5d3bd64d2dc | 54 | { |
no2chem | 0:b5d3bd64d2dc | 55 | mainCoreMark(); |
no2chem | 0:b5d3bd64d2dc | 56 | } |
no2chem | 0:b5d3bd64d2dc | 57 | |
no2chem | 0:b5d3bd64d2dc | 58 | wait(1); |
no2chem | 0:b5d3bd64d2dc | 59 | NVIC_SystemReset(); |
no2chem | 0:b5d3bd64d2dc | 60 | } |
no2chem | 0:b5d3bd64d2dc | 61 | } |