From 3e29876d98973f03ee19911b688076cd81463d70 Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Tue, 19 Jan 2010 19:57:38 +0100 Subject: rcc: Add a few functions to set prescalers. Thanks Thomas Otto for the patch! --- lib/rcc.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'lib/rcc.c') diff --git a/lib/rcc.c b/lib/rcc.c index 58ab8b5..2392084 100644 --- a/lib/rcc.c +++ b/lib/rcc.c @@ -3,6 +3,8 @@ * * Copyright (C) 2009 Federico Ruiz-Ugalde * Copyright (C) 2009 Uwe Hermann + * Copyright (C) 2010 Thomas Otto + * * * 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 @@ -279,3 +281,45 @@ void rcc_set_pllxtpre(u32 pllxtpre) reg32 &= ~(1 << 17); RCC_CFGR = (reg32 | (pllxtpre << 17)); } + +void rcc_set_adcpre(u32 adcpre) +{ + u32 reg32; + + reg32 = RCC_CFGR; + reg32 &= ((1 << 14) | (1 << 15)); + RCC_CFGR = (reg32 | (adcpre << 14)); +} + +void rcc_set_ppre2(u32 ppre2) +{ + u32 reg32; + + reg32 = RCC_CFGR; + reg32 &= ((1 << 11) | (1 << 12) | (1 << 13)); + RCC_CFGR = (reg32 | (ppre2 << 11)); +} + +void rcc_set_ppre1(u32 ppre1) +{ + u32 reg32; + + reg32 = RCC_CFGR; + reg32 &= ((1 << 8) | (1 << 9) | (1 << 10)); + RCC_CFGR = (reg32 | (ppre1 << 8)); +} + +void rcc_set_hpre(u32 hpre) +{ + u32 reg32; + + reg32 = RCC_CFGR; + reg32 &= ((1 << 4) | (1 << 5) | (1 << 6) | (1 << 7)); + RCC_CFGR = (reg32 | (hpre << 4)); +} + +u32 rcc_system_clock_source(void) +{ + /* Return the clock source which is used as system clock. */ + return ((RCC_CFGR & 0x000c) >> 2); +} -- cgit v1.2.3