]> rtime.felk.cvut.cz Git - lincan.git/blob - embedded/arch/arm/mach-lpc21xx/libs/hal/hal_machperiph.c
599fdc34c850061aee59cc1b1b0273fa4c1462a3
[lincan.git] / embedded / arch / arm / mach-lpc21xx / 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
11   // enable PLL
12   PLLCON = PLLCON_PLLE;
13   PLLFEED = 0xAA;                       // Make it happen.  These two updates
14   PLLFEED = 0x55;                       // MUST occur in sequence.
15
16   // wait for PLL lock
17   while (!(PLLSTAT & PLLSTAT_LOCK))
18     continue;
19
20   // enable & connect PLL
21   PLLCON = PLLCON_PLLE | PLLCON_PLLC;
22   PLLFEED = 0xAA;                       // Make it happen.  These two updates
23   PLLFEED = 0x55;                       // MUST occur in sequence.
24 }
25
26 void lpc_pll_off()
27 {
28   // disable PLL
29   PLLCON = 0;
30   PLLFEED = 0xAA;                       // Make it happen.  These two updates
31   PLLFEED = 0x55;                       // MUST occur in sequence.
32 }
33
34 void lpc_watchdog_feed()
35 {
36   unsigned long flags;
37
38   save_and_cli(flags);
39   WDFEED = 0xAA;
40   WDFEED = 0x55;
41   restore_flags(flags);
42 }
43
44 void lpc_watchdog_init(int on,int timeout_ms)
45 {
46   if (!on) return;
47   WDTC = PCLK/(1000/timeout_ms);
48   WDMOD = 0x03;                            /* Enable watchdog timer and reset */
49 }