summaryrefslogtreecommitdiff
path: root/openpicc/application/clock_switch.c
blob: 16c1bf1b01a3a234a031af9ab6a5fb9fc16f92f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/***************************************************************
 *
 * OpenPICC - clock switch driver
 * 
 * Copyright 2008 Henryk Plötz <henryk@ploetzli.ch>
 *
 ***************************************************************

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; version 2.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

*/

#include <FreeRTOS.h>
#include <openpicc.h>

#include "clock_switch.h"

static int initialized = 0;

void clock_switch(enum clock_source clock)
{
	if(!OPENPICC->features.clock_switching) return;
	if(!initialized)
		AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, OPENPICC->CLOCK_SWITCH);
	
	switch(clock) {
	case CLOCK_SELECT_PLL:
		AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPICC->CLOCK_SWITCH);
		break;
	case CLOCK_SELECT_CARRIER:
		AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPICC->CLOCK_SWITCH);
		break;
	}
}

void clock_switch_init(void)
{
	if(!OPENPICC->features.clock_switching) return;
	AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, OPENPICC->CLOCK_SWITCH);
	clock_switch(OPENPICC->default_clock);
	initialized = 1;
}
personal git repositories of Harald Welte. Your mileage may vary