]> rtime.felk.cvut.cz Git - lincan.git/blob - embedded/arch/arm/mach-lpc21xx/libs/hal/hal_machperiph.c
Update of system-less architecture and board support code to actual uLAN.sf.net version.
[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 unsigned int system_frequency = FOSC; /*!< System Clock Frequency (Core Clock)  */
6
7 void system_clock_init(void)
8 {
9   // set PLL multiplier & divisor.
10   // values computed from config.h
11   PLLCFG = PLLCFG_MSEL | PLLCFG_PSEL;
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   // wait for PLL lock
19   while (!(PLLSTAT & PLLSTAT_LOCK))
20     continue;
21
22   // enable & connect PLL
23   PLLCON = PLLCON_PLLE | PLLCON_PLLC;
24   PLLFEED = 0xAA;                       // Make it happen.  These two updates
25   PLLFEED = 0x55;                       // MUST occur in sequence.
26
27   system_frequency=CCLK;
28
29   // setup & enable the MAM
30   MAMCR = 0;
31   MAMTIM = MAMTIM_CYCLES;
32   MAMCR = MAMCR_FULL;
33
34   // set the peripheral bus speed
35   // value computed from config.h
36   VPBDIV = VPBDIV_VALUE;                  // set the peripheral bus clock speed
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   WDTC = PCLK/(1000/timeout_ms);
53   WDMOD = 0x03;                            /* Enable watchdog timer and reset */
54 }