clock control library written by Michael Wei

Dependents:   IsuProject_LPC1768 Gemini_Soloist_LPC1768 OSCtoCVConverter

Files at this revision

API Documentation at this revision

Comitter:
JST2011
Date:
Wed Mar 28 10:45:42 2012 +0000
Child:
1:a6d100de3aee
Commit message:
fixed: compile error with mbed lib(at 20120328)

Changed in this revision

ClockControl.cpp Show annotated file Show diff for this revision Revisions of this file
ClockControl.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ClockControl.cpp	Wed Mar 28 10:45:42 2012 +0000
@@ -0,0 +1,37 @@
+#include "ClockControl.h"
+
+void setPLL0Frequency(unsigned char clkSrc, unsigned short cfg_m, unsigned char cfg_n)
+{
+      LPC_SC->CLKSRCSEL = clkSrc;
+      LPC_SC->PLL0CFG   = (((unsigned int)cfg_n-1) << 16) | cfg_m-1;
+      LPC_SC->PLL0CON   = 0x01;             
+      LPC_SC->PLL0FEED  = 0xAA;
+      LPC_SC->PLL0FEED  = 0x55;
+      while (!(LPC_SC->PLL0STAT & (1<<26)));
+    
+      LPC_SC->PLL0CON   = 0x03;
+      LPC_SC->PLL0FEED  = 0xAA;
+      LPC_SC->PLL0FEED  = 0x55;
+}
+
+void setPLL1Frequency(unsigned char clkSrc, unsigned short cfg_m, unsigned char cfg_n)
+{
+      LPC_SC->CLKSRCSEL = clkSrc;
+      LPC_SC->PLL1CFG   = (((unsigned int)cfg_n-1) << 16) | cfg_m-1;
+      LPC_SC->PLL1CON   = 0x01;             
+      LPC_SC->PLL1FEED  = 0xAA;
+      LPC_SC->PLL1FEED  = 0x55;
+      while (!(LPC_SC->PLL1STAT & (1<<26)));
+    
+      LPC_SC->PLL1CON   = 0x03;
+      LPC_SC->PLL1FEED  = 0xAA;
+      LPC_SC->PLL1FEED  = 0x55;
+}
+
+unsigned int setSystemFrequency(unsigned char clkDivider, unsigned char clkSrc, unsigned short cfg_m, unsigned char cfg_n)
+{
+    setPLL0Frequency(clkSrc, cfg_m, cfg_n);
+    LPC_SC->CCLKCFG = clkDivider - 1;
+    SystemCoreClockUpdate();
+    return SystemCoreClock;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ClockControl.h	Wed Mar 28 10:45:42 2012 +0000
@@ -0,0 +1,14 @@
+/* mbed PowerControl Library
+  * Copyright (c) 2010 Michael Wei
+  */ 
+  
+//shouldn't have to include, but fixes weird problems with defines
+#include "LPC1768/ARM/LPC17xx.h"
+
+#ifndef MBED_CLOCKCONTROL_H 
+#define MBED_CLOCKCONTROL_H 
+
+unsigned int setSystemFrequency(unsigned char clkDivider, unsigned char clkSrc, unsigned short cfg_m, unsigned char cfg_n);
+void setPLL0Frequency(unsigned char clkSrc, unsigned short cfg_m, unsigned char cfg_n);
+void setPLL1Frequency(unsigned char clkSrc, unsigned short cfg_m, unsigned char cfg_n);
+#endif
\ No newline at end of file