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>
#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;
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();
#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
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()
#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();
#include <cpu_def.h>
#include <hal_machperiph.h>
-//#define IAP_PLL_FULL_SPEED 1
-
#define CMD_SUCCESS 0
#define BUSY 11
command[0] = IAP_CMD_PREPARE;
command[1] = start;
command[2] = end;
- command[3] = FOSC/1000;
+ command[3] = system_frequency/1000;
iap_entry(command, result);
command[0] = IAP_CMD_ERASE;
command[1] = start;
command[2] = end;
- command[3] = FOSC/1000;
+ command[3] = system_frequency/1000;
iap_entry(command, result);
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);
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;
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);
#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
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))
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()
#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();
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
#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;