openpcd/firmware/src/picc/pll.c @ master
1 | 32985a29 | laforge | /* PLL routines for OpenPICC
|
---|---|---|---|
2 | * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
|
||
3 | *
|
||
4 | * This program is free software; you can redistribute it and/or modify
|
||
5 | * it under the terms of the GNU General Public License as published by
|
||
6 | * the Free Software Foundation; either version 2 of the License, or
|
||
7 | * (at your option) any later version.
|
||
8 | *
|
||
9 | * This program is distributed in the hope that it will be useful,
|
||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
12 | * GNU General Public License for more details.
|
||
13 | *
|
||
14 | * You should have received a copy of the GNU General Public License
|
||
15 | * along with this program; if not, write to the Free Software
|
||
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
17 | *
|
||
18 | */
|
||
19 | |||
20 | 82a994e1 | (no author) | |
21 | #include <sys/types.h>
|
||
22 | #include <lib_AT91SAM7.h>
|
||
23 | 9b752b40 | (no author) | #include <os/pio_irq.h>
|
24 | #include <os/dbgu.h>
|
||
25 | 514b0f72 | laforge | #include <os/led.h>
|
26 | 82a994e1 | (no author) | #include "../openpcd.h"
|
27 | |||
28 | void pll_inhibit(int inhibit) |
||
29 | {
|
||
30 | if (inhibit) |
||
31 | AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPICC_PIO_PLL_INHIBIT); |
||
32 | else
|
||
33 | AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPICC_PIO_PLL_INHIBIT); |
||
34 | }
|
||
35 | |||
36 | int pll_is_locked(void) |
||
37 | {
|
||
38 | return AT91F_PIO_IsInputSet(AT91C_BASE_PIOA, OPENPICC_PIO_PLL_LOCK); |
||
39 | }
|
||
40 | |||
41 | 373c172a | Harald Welte | static void pll_lock_change_cb(uint32_t pio) |
42 | 9b752b40 | (no author) | {
|
43 | DEBUGPCRF("PLL LOCK: %d", pll_is_locked()); |
||
44 | #if 1
|
||
45 | if (pll_is_locked()) |
||
46 | 28eb4a57 | laforge | led_switch(2, 1); |
47 | 9b752b40 | (no author) | else
|
48 | 28eb4a57 | laforge | led_switch(2, 0); |
49 | 9b752b40 | (no author) | #endif
|
50 | }
|
||
51 | |||
52 | 82a994e1 | (no author) | void pll_init(void) |
53 | {
|
||
54 | AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, OPENPICC_PIO_PLL_INHIBIT); |
||
55 | AT91F_PIO_CfgInput(AT91C_BASE_PIOA, OPENPICC_PIO_PLL_LOCK); |
||
56 | pll_inhibit(0); |
||
57 | 9b752b40 | (no author) | |
58 | pio_irq_register(OPENPICC_PIO_PLL_LOCK, &pll_lock_change_cb); |
||
59 | pio_irq_enable(OPENPICC_PIO_PLL_LOCK); |
||
60 | 82a994e1 | (no author) | }
|