]> rtime.felk.cvut.cz Git - sysless.git/commitdiff
mach HAL: removed functions lpc_pll_on and lpc_pll_off. Now, hal provides
authorPetr Smolik <petr@smoliku.cz>
Mon, 24 May 2010 21:22:46 +0000 (23:22 +0200)
committerPetr Smolik <petr@smoliku.cz>
Mon, 24 May 2010 21:22:46 +0000 (23:22 +0200)
the function system_clock_init to initialize CPU clock.

IAP improvement: don't need to switch off PLL during call a IAP function

Signed-off-by: Petr Smolik <petr@smoliku.cz>
arch/arm/mach-lpc17xx/libs/hal/hal_machperiph.c
arch/arm/mach-lpc17xx/libs/hal/hal_machperiph.h
arch/arm/mach-lpc21xx/libs/hal/hal_machperiph.c
arch/arm/mach-lpc21xx/libs/hal/hal_machperiph.h
arch/arm/mach-lpc21xx/libs/iap/iap.c
arch/arm/mach-lpc23xx/libs/hal/hal_machperiph.c
arch/arm/mach-lpc23xx/libs/hal/hal_machperiph.h
board/arm/ul_usb1/libs/bspbase/bsp0hwinit.c

index 92db8173f7a6697ed77641cc39026985ccefb374..352bb29bdb7a9749adb4a62da59f5678b1abe3ed 100644 (file)
@@ -135,14 +135,6 @@ void system_clock_init(void)
 #endif
 }
 
-void lpc_pll_off(void)
-{
-  // disable PLL
-//  PLLCON = 0;
-//  PLLFEED = 0xAA;                       // Make it happen.  These two updates
-//  PLLFEED = 0x55;                       // MUST occur in sequence.
-}
-
 void lpc_watchdog_feed()
 {
   unsigned long flags;
index e606e22772f4ecb62f7cff583051c8e5b88c1be7..9b3a74bb6eb775090cfa5525d972ec26e23d9ced 100644 (file)
@@ -6,8 +6,6 @@ extern unsigned int system_frequency;
 
 void system_clock_init(void);
 
-//void lpc_pll_on();
-void lpc_pll_off();
 void lpc_watchdog_init(int on,int timeout_ms);
 void lpc_watchdog_feed();
 
index 599fdc34c850061aee59cc1b1b0273fa4c1462a3..6316bb9e1f98cd39fab8712e0102400de2160b4c 100644 (file)
@@ -2,7 +2,9 @@
 #include <cpu_def.h>
 #include <hal_machperiph.h>
 
-void lpc_pll_on()
+unsigned int system_frequency = FOSC; /*!< System Clock Frequency (Core Clock)  */
+
+void system_clock_init(void)
 {
   // set PLL multiplier & divisor.
   // values computed from config.h
@@ -21,14 +23,17 @@ void lpc_pll_on()
   PLLCON = PLLCON_PLLE | PLLCON_PLLC;
   PLLFEED = 0xAA;                       // Make it happen.  These two updates
   PLLFEED = 0x55;                       // MUST occur in sequence.
-}
 
-void lpc_pll_off()
-{
-  // disable PLL
-  PLLCON = 0;
-  PLLFEED = 0xAA;                       // Make it happen.  These two updates
-  PLLFEED = 0x55;                       // MUST occur in sequence.
+  system_frequency=CCLK;
+
+  // setup & enable the MAM
+  MAMCR = 0;
+  MAMTIM = MAMTIM_CYCLES;
+  MAMCR = MAMCR_FULL;
+
+  // set the peripheral bus speed
+  // value computed from config.h
+  VPBDIV = VPBDIV_VALUE;                  // set the peripheral bus clock speed
 }
 
 void lpc_watchdog_feed()
index 9f8c27f2c5257a15b589aa1b12276c8228d329c8..9e790d89aa2609aeb9d354f71fab22adc796e2e8 100644 (file)
@@ -1,8 +1,10 @@
 #ifndef _HAL_MACHPERIPH_H
 #define _HAL_MACHPERIPH_H
 
-void lpc_pll_on();
-void lpc_pll_off();
+extern unsigned int system_frequency; /*!< System Clock Frequency (Core Clock)  */
+
+void system_clock_init(void);
+
 void lpc_watchdog_init(int on,int timeout_ms);
 void lpc_watchdog_feed();
 
index 4f6aa44bfbff9324bb58e93024d706db73f5d5ce..23f7bc0261a8fd3ac5392939f2e6bfcc1e869ed1 100644 (file)
@@ -2,8 +2,6 @@
 #include <cpu_def.h>
 #include <hal_machperiph.h>
 
-//#define IAP_PLL_FULL_SPEED      1
-
 #define CMD_SUCCESS 0
 #define BUSY 11
 
@@ -46,7 +44,7 @@ int lpcisp_prepare_sectors(unsigned char start, unsigned char end)
   command[0] = IAP_CMD_PREPARE;
   command[1] = start;
   command[2] = end;
-  command[3] = FOSC/1000;
+  command[3] = system_frequency/1000;
 
   iap_entry(command, result);
 
@@ -58,7 +56,7 @@ int lpcisp_erase_sectors(unsigned char start, unsigned char end)
   command[0] = IAP_CMD_ERASE;
   command[1] = start;
   command[2] = end;
-  command[3] = FOSC/1000;
+  command[3] = system_frequency/1000;
 
   iap_entry(command, result);
 
@@ -76,18 +74,12 @@ int lpcisp_erase(void *addr, int len)
   if (end<start) return 0;
 
   save_and_cli(flags);
- #ifndef IAP_PLL_FULL_SPEED
-  lpc_pll_off();
- #endif
 
   lpcisp_prepare_sectors(start,end);
   if (CMD_SUCCESS != *result) return 0;
 
   lpcisp_erase_sectors(start,end);
 
- #ifndef IAP_PLL_FULL_SPEED
-  lpc_pll_on();
- #endif
   restore_flags(flags);
 
   return (CMD_SUCCESS == *result);
@@ -102,9 +94,6 @@ int lpcisp_write(void *addr_des, const void *addr_src, int len)
   end=start;
 
   save_and_cli(flags);
- #ifndef IAP_PLL_FULL_SPEED
-  lpc_pll_off();
- #endif
 
   lpcisp_prepare_sectors(start,end);
   if (CMD_SUCCESS != *result) return 0;
@@ -113,13 +102,10 @@ int lpcisp_write(void *addr_des, const void *addr_src, int len)
   command[1] = (unsigned int)addr_des;
   command[2] = (unsigned int)addr_src;
   command[3] = len;
-  command[4] = FOSC/1000;
+  command[4] = system_frequency/1000;
 
   iap_entry(command, result);
 
- #ifndef IAP_PLL_FULL_SPEED
-  lpc_pll_on();
- #endif
   restore_flags(flags);
 
   return (CMD_SUCCESS == *result);
index 4ca6cf30ce8e9af4b597557b83ca1f0544673e65..4585b1efb43d20f0474a4f53336710c460e721b1 100644 (file)
@@ -2,7 +2,9 @@
 #include <cpu_def.h>
 #include <hal_machperiph.h>
 
-void lpc_pll_on()
+unsigned int system_frequency = FOSC; /*!< System Clock Frequency (Core Clock)  */
+
+void system_clock_init(void)
 {
   // set PLL multiplier & divisor.
   // values computed from config.h
@@ -15,8 +17,8 @@ void lpc_pll_on()
   PLLFEED = 0xAA;                       // Make it happen.  These two updates
   PLLFEED = 0x55;                       // MUST occur in sequence.
 
-  CCLKCFG = HCLK_DIV_CPU;                //only odd values have to be used
-  USBCLKCFG = HCLK_DIV_USB;              //only odd values have to be used
+  CCLKCFG = HCLK_DIV_CPU;                 //only odd values have to be used
+  USBCLKCFG = HCLK_DIV_USB;               //only odd values have to be used
 
   // wait for PLL lock
   while (!(PLLSTAT & PLLSTAT_LOCK))
@@ -26,14 +28,21 @@ void lpc_pll_on()
   PLLCON = PLLCON_PLLE | PLLCON_PLLC;
   PLLFEED = 0xAA;                       // Make it happen.  These two updates
   PLLFEED = 0x55;                       // MUST occur in sequence.
-}
 
-void lpc_pll_off()
-{
-  // disable PLL
-  PLLCON = 0;
-  PLLFEED = 0xAA;                       // Make it happen.  These two updates
-  PLLFEED = 0x55;                       // MUST occur in sequence.
+  SCS = SCS_GPIOM | SCS_OSCEN;
+  // wait for main clock to be ready to use
+  while (!(SCS & SCS_OSCSTAT))
+    continue;    
+
+  CCLKCFG = 0;                            //only 0 and odd values have to be used
+  CLKSRCSEL = 1;                          //source is XTAL
+
+  system_frequency=CCLK;
+
+  // setup & enable the MAM
+  MAMCR = 0;
+  MAMTIM = MAMTIM_CYCLES;
+  MAMCR = MAMCR_FULL;
 }
 
 void lpc_watchdog_feed()
index 9f8c27f2c5257a15b589aa1b12276c8228d329c8..9e790d89aa2609aeb9d354f71fab22adc796e2e8 100644 (file)
@@ -1,8 +1,10 @@
 #ifndef _HAL_MACHPERIPH_H
 #define _HAL_MACHPERIPH_H
 
-void lpc_pll_on();
-void lpc_pll_off();
+extern unsigned int system_frequency; /*!< System Clock Frequency (Core Clock)  */
+
+void system_clock_init(void);
+
 void lpc_watchdog_init(int on,int timeout_ms);
 void lpc_watchdog_feed();
 
index d14c1cbe0d5b1a75b03d8286597c65bf30388129..90d05800fdaabc63c83672f7e1be3d2e6b5d812e 100644 (file)
@@ -39,17 +39,7 @@ int i2c_drv_na_timer=0;
 static void sysInit(void) 
 {
 
-  lpc_pll_off();
-  lpc_pll_on();
-
-  // setup & enable the MAM
-  MAMCR = 0;
-  MAMTIM = MAMTIM_CYCLES;
-  MAMCR = MAMCR_FULL;
-
-  // set the peripheral bus speed
-  // value computed from config.h
-  VPBDIV = VPBDIV_VALUE;                // set the peripheral bus clock speed
+  system_clock_init();
 
   // setup the parallel port pin
   IO0CLR = P0IO_ZERO_BITS;                // clear the ZEROs output
@@ -83,14 +73,14 @@ void timer0_isr(void)
      #endif
      #ifdef CONFIG_OC_I2C_DRV_SYSLESS
       if (i2c_drv.flags&I2C_DRV_MS_INPR) {
-        if (i2c_drv.flags&I2C_DRV_NA)
+        if (i2c_drv.flags&I2C_DRV_NA) {
           i2c_drv_na_timer++;
           if (i2c_drv_na_timer>I2C_DRV_NA_MSTIMEOUT) {
              if (i2c_drv.stroke_fnc) 
               i2c_drv.stroke_fnc(&i2c_drv);
             i2c_drv_na_timer=0;
           }
-        else {
+        else {
           i2c_drv_na_timer=0;
         }
         i2c_drv.flags|=I2C_DRV_NA;