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