Contiki 2.5
pll_drv.h
Go to the documentation of this file.
1 /* This file has been prepared for Doxygen automatic documentation generation.*/
2 /*! \file *********************************************************************
3  *
4  * \brief
5  * This file contains the low level macros and definition for the USB PLL.
6  *
7  * \par Application note:
8  * AVR280: USB Host CDC Demonstration
9  *
10  * \par Documentation
11  * For comprehensive code documentation, supported compilers, compiler
12  * settings and supported devices see readme.html
13  *
14  * \author
15  * Atmel Corporation: http://www.atmel.com \n
16  * Support email: avr@atmel.com
17  *
18  * $Name: $
19  * $Revision: 1.1 $
20  * $RCSfile: pll_drv.h,v $
21  * $Date: 2008/10/14 20:16:36 $ \n
22  * $Id: pll_drv.h,v 1.1 2008/10/14 20:16:36 c_oflynn Exp $
23  ******************************************************************************/
24 /* Copyright (c) 2008 ATMEL Corporation
25  All rights reserved.
26 
27  Redistribution and use in source and binary forms, with or without
28  modification, are permitted provided that the following conditions are met:
29 
30  * Redistributions of source code must retain the above copyright
31  notice, this list of conditions and the following disclaimer.
32  * Redistributions in binary form must reproduce the above copyright
33  notice, this list of conditions and the following disclaimer in
34  the documentation and/or other materials provided with the
35  distribution.
36  * Neither the name of the copyright holders nor the names of
37  contributors may be used to endorse or promote products derived
38  from this software without specific prior written permission.
39 
40  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
41  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
44  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
46  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
47  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
48  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
50  POSSIBILITY OF SUCH DAMAGE.
51 */
52 
53 #ifndef PLL_DRV_H
54 #define PLL_DRV_H
55 
56 //_____ I N C L U D E S ____________________________________________________
57 
58 /**
59  @addtogroup usb
60  @{
61 */
62 //_____ M A C R O S ________________________________________________________
63 
64  //! @defgroup PLL_macros PLL Macros
65  //! These functions allow to control the PLL
66  //! @{
67 #define PLLx24 ( (0<<PLLP2) | (0<<PLLP1) | (0<<PLLP0) )
68 #define PLLx12 ( (0<<PLLP2) | (0<<PLLP1) | (1<<PLLP0) )
69 #define PLLx08 ( (0<<PLLP2) | (1<<PLLP1) | (0<<PLLP0) )
70 #define PLLx06 ( (0<<PLLP2) | (1<<PLLP1) | (1<<PLLP0) )
71 #define PLLx04 ( (1<<PLLP2) | (0<<PLLP1) | (0<<PLLP0) )
72 #define PLLx03 ( (1<<PLLP2) | (0<<PLLP1) | (1<<PLLP0) )
73 #define PLLx04_8 ( (1<<PLLP2) | (1<<PLLP1) | (0<<PLLP0) )
74 #define PLLx02 ( (1<<PLLP2) | (1<<PLLP1) | (1<<PLLP0) )
75 
76 
77  //! @brief Start the PLL at only 48 MHz, regarding CPU frequency
78  //! Start the USB PLL with clockfactor
79  //! clockfactor can be PLLx24, PLLx12, PLLx08
80  //! PLLx06, PLLx04, PLLx03
81 #define Start_pll(clockfactor) \
82  (PLLCSR = ( clockfactor | (1<<PLLE) ))
83 
84  //! return 1 when PLL locked
85 #define Is_pll_ready() (PLLCSR & (1<<PLOCK) )
86 
87  //! Test PLL lock bit and wait until lock is set
88 #define Wait_pll_ready() while (!(PLLCSR & (1<<PLOCK)))
89 
90  //! Stop the PLL
91 #define Stop_pll() (PLLCSR &= (~(1<<PLLE)) )
92 
93  // Start the PLL in autofactor mode
94  // regarding FOSC define
95 #if (FOSC==2000)
96  //! Start the PLL in autofactor mode
97  //! regarding FOSC define
98  #define Pll_start_auto() Start_pll(PLLx24)
99 #elif (FOSC==4000)
100  #define Pll_start_auto() Start_pll(PLLx12)
101 #elif (FOSC==6000)
102  #define Pll_start_auto() Start_pll(PLLx08)
103 #elif (FOSC==8000)
104  //! Start the PLL in autofactor mode
105  //! regarding FOSC define
106  #define Pll_start_auto() Start_pll(PLLx06)
107 #elif (FOSC==12000)
108  #define Pll_start_auto() Start_pll(PLLx04)
109 #elif (FOSC==16000)
110  #define Pll_start_auto() Start_pll(PLLx03)
111 #elif (FOSC==20000)
112  #define Pll_start_auto() Start_pll(PLLx04_8)
113 #elif (FOSC==24000)
114  #define Pll_start_auto() Start_pll(PLLx02)
115 #else
116  #error "FOSC should be defined in config.h"
117 #endif
118 
119  //! @}
120 
121 //! @}
122 #endif // PLL_DRV_H
123 
124