diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2010-10-16 02:15:50 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2010-10-16 02:15:50 +0000 |
commit | e4edf83f0ac94f4705635e2af4917e2d0e7e2a7d (patch) | |
tree | 5f1ad5a848c1657bb239c361487d09335b660d22 /nuttx/arch/avr/src/at91uc3/at91uc3_clkinit.c | |
parent | e77521c50406b0a22165e14e821bdf4876ed66f0 (diff) | |
download | px4-nuttx-e4edf83f0ac94f4705635e2af4917e2d0e7e2a7d.tar.gz px4-nuttx-e4edf83f0ac94f4705635e2af4917e2d0e7e2a7d.tar.bz2 px4-nuttx-e4edf83f0ac94f4705635e2af4917e2d0e7e2a7d.zip |
Add AVR32 system timer
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3021 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/avr/src/at91uc3/at91uc3_clkinit.c')
-rw-r--r-- | nuttx/arch/avr/src/at91uc3/at91uc3_clkinit.c | 89 |
1 files changed, 79 insertions, 10 deletions
diff --git a/nuttx/arch/avr/src/at91uc3/at91uc3_clkinit.c b/nuttx/arch/avr/src/at91uc3/at91uc3_clkinit.c index 34cf9112f..5fa707600 100644 --- a/nuttx/arch/avr/src/at91uc3/at91uc3_clkinit.c +++ b/nuttx/arch/avr/src/at91uc3/at91uc3_clkinit.c @@ -73,18 +73,43 @@ **************************************************************************/ /************************************************************************** - * Public Functions + * Name: up_enableosc32 + * + * Description: + * Initialiaze the 32KHz oscillaor. This oscillaor is used by the RTC + * logic to provide the sysem timer. + * **************************************************************************/ -/************************************************************************************ - * Name: up_clkinit +static inline void up_enableosc32(void) +{ + uint32_t regval; + + /* Select the 32KHz oscillator crystal */ + + regval = getreg32(AVR32_PM_OSCCTRL32); + regval &= ~PM_OSCCTRL32_MODE_MASK; + regval |= PM_OSCCTRL32_MODE_XTAL; + putreg32(regval, AVR32_PM_OSCCTRL32); + + /* Enable the 32-kHz clock */ + + regval = getreg32(AVR32_PM_OSCCTRL32); + regval &= ~PM_OSCCTRL_STARTUP_MASK; + regval |= PM_OSCCTRL32_EN|(AVR32_OSC32STARTUP << PM_OSCCTRL_STARTUP_SHIFT); + putreg32(regval, AVR32_PM_OSCCTRL32); +} + +/************************************************************************** + * Name: up_enableosc0 * * Description: - * Initialiaze clock/PLL settings per the definitions in the board.h file. + * Initialiaze clock/PLL settings per the definitions in the board.h + * file. * - ************************************************************************************/ + **************************************************************************/ -void up_clkinitialize(void) +static inline void up_enableosc0(void) { uint32_t regval; @@ -121,16 +146,60 @@ void up_clkinitialize(void) /* Wait for CLK0 to be ready */ while ((getreg32(AVR32_PM_POSCSR) & PM_POSCSR_OSC0RDY) == 0); +} - /* Then switch the main clock to OSC0 */ +/************************************************************************** + * Name: up_mainclk + * + * Description: + * Initialiaze clock/PLL settings per the definitions in the board.h + * file. + * + **************************************************************************/ +static inline void up_mainclk(uint32_t mcsel) +{ + uint32_t regval; + regval = getreg32(AVR32_PM_MCCTRL); regval &= ~PM_MCCTRL_MCSEL_MASK; - regval |= PM_MCCTRL_MCSEL_OSC0; + regval |= mcsel; putreg32(regval, AVR32_PM_MCCTRL); +} + +/************************************************************************** + * Public Functions + **************************************************************************/ - /* Now, enable PLL0 */ -#warning "Missing Logic" +/************************************************************************** + * Name: up_clkinit + * + * Description: + * Initialiaze clock/PLL settings per the definitions in the board.h + * file. + * + **************************************************************************/ + +void up_clkinitialize(void) +{ + /* Enable the 32KHz oscillator (need by the RTC module) */ + + up_enableosc32(); + +#if defined(AVR32_CLOCK_OSC0) + /* Enable OSC0 using the settings in board.h */ + + up_enableosc0(); + + /* Then switch the main clock to OSC0 */ + + up_mainclk(PM_MCCTRL_MCSEL_OSC0); + +#elif defined(AVR32_CLOCK_PLL0) +# warning "Missing Logic" +#else +# error "No main clock" +#endif } |