]> rtime.felk.cvut.cz Git - sysless.git/blob - arch/arm/mach-lpc23xx/libs/hal/hal_machperiph.c
4ca6cf30ce8e9af4b597557b83ca1f0544673e65
[sysless.git] / arch / arm / mach-lpc23xx / libs / hal / hal_machperiph.c
1 #include <system_def.h>
2 #include <cpu_def.h>
3 #include <hal_machperiph.h>
4
5 void lpc_pll_on()
6 {
7   // set PLL multiplier & divisor.
8   // values computed from config.h
9   PLLCFG = PLLCFG_MSEL | PLLCFG_PSEL;
10   PLLFEED = 0xAA;                       // Make it happen.  These two updates
11   PLLFEED = 0x55;                       // MUST occur in sequence.
12   
13   // enable PLL
14   PLLCON = PLLCON_PLLE;
15   PLLFEED = 0xAA;                       // Make it happen.  These two updates
16   PLLFEED = 0x55;                       // MUST occur in sequence.
17
18   CCLKCFG = HCLK_DIV_CPU;                 //only odd values have to be used
19   USBCLKCFG = HCLK_DIV_USB;               //only odd values have to be used
20
21   // wait for PLL lock
22   while (!(PLLSTAT & PLLSTAT_LOCK))
23     continue;
24
25   // enable & connect PLL
26   PLLCON = PLLCON_PLLE | PLLCON_PLLC;
27   PLLFEED = 0xAA;                       // Make it happen.  These two updates
28   PLLFEED = 0x55;                       // MUST occur in sequence.
29 }
30
31 void lpc_pll_off()
32 {
33   // disable PLL
34   PLLCON = 0;
35   PLLFEED = 0xAA;                       // Make it happen.  These two updates
36   PLLFEED = 0x55;                       // MUST occur in sequence.
37 }
38
39 void lpc_watchdog_feed()
40 {
41   unsigned long flags;
42
43   save_and_cli(flags);
44   WDFEED = 0xAA;
45   WDFEED = 0x55;
46   restore_flags(flags);
47 }
48
49 void lpc_watchdog_init(int on,int timeout_ms)
50 {
51   if (!on) return;
52   WDCLKSEL=1; //PCLK as WDT source
53   /* FIXME - only seconds are used for WDT */
54   WDTC=(PCLK/4)*(timeout_ms/1000);
55   WDMOD = 0x03;                            /* Enable watchdog timer and reset */
56 }