1 /*******************************************************************************
4 * Provides Functions to Initialize the UCS/FLL and clock sources
7 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the
22 * Neither the name of Texas Instruments Incorporated nor the names of
23 * its contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Created: Version 1.0 11/24/2009
39 * Updated: Version 2.0 12/15/2010
40 * Added Functions: XT2_Stop() and XT1_Stop()
42 ******************************************************************************/
47 #include "HAL_MACROS.h"
49 /*******************************************************************************
51 ******************************************************************************/
53 /* Select source for FLLREF e.g. SELECT_FLLREF(SELREF__XT1CLK) */
54 #define SELECT_FLLREF(source) st(UCSCTL3 = (UCSCTL3 & ~(SELREF_7)) | (source);)
55 /* Select source for ACLK e.g. SELECT_ACLK(SELA__XT1CLK) */
56 #define SELECT_ACLK(source) st(UCSCTL4 = (UCSCTL4 & ~(SELA_7)) | (source);)
57 /* Select source for MCLK e.g. SELECT_MCLK(SELM__XT2CLK) */
58 #define SELECT_MCLK(source) st(UCSCTL4 = (UCSCTL4 & ~(SELM_7)) | (source);)
59 /* Select source for SMCLK e.g. SELECT_SMCLK(SELS__XT2CLK) */
60 #define SELECT_SMCLK(source) st(UCSCTL4 = (UCSCTL4 & ~(SELS_7)) | (source);)
61 /* Select source for MCLK and SMCLK e.g. SELECT_MCLK_SMCLK(SELM__DCOCLK + SELS__DCOCLK) */
62 #define SELECT_MCLK_SMCLK(sources) st(UCSCTL4 = (UCSCTL4 & ~(SELM_7 + SELS_7)) | (sources);)
65 #define ACLK_DIV(x) st(UCSCTL5 = (UCSCTL5 & ~(DIVA_7)) | (DIVA__##x);)
67 #define MCLK_DIV(x) st(UCSCTL5 = (UCSCTL5 & ~(DIVM_7)) | (DIVM__##x);)
69 #define SMCLK_DIV(x) st(UCSCTL5 = (UCSCTL5 & ~(DIVS_7)) | (DIVS__##x);)
70 /* Select divider for FLLREF e.g. SELECT_FLLREFDIV(2) */
71 #define SELECT_FLLREFDIV(x) st(UCSCTL3 = (UCSCTL3 & ~(FLLREFDIV_7))|(FLLREFDIV__##x);)
73 /*******************************************************************************
75 ******************************************************************************/
76 #define UCS_STATUS_OK 0
77 #define UCS_STATUS_ERROR 1
80 /*******************************************************************************
81 * \brief Startup routine for 32kHz Crystal on LFXT1
83 * \param xtdrive Bits defining the LFXT drive mode after startup
84 ******************************************************************************/
85 extern void LFXT_Start(unsigned int xtdrive);
88 /*******************************************************************************
89 * \brief Startup routine for 32kHz Crystal on LFXT1 with timeout counter
91 * \param xtdrive Bits defining the LFXT drive mode after startup
92 * \param timeout Value for the timeout counter
93 ******************************************************************************/
94 extern unsigned int LFXT_Start_Timeout(unsigned int xtdrive, unsigned int timeout);
97 /*******************************************************************************
98 * \brief Startup routine for XT1
100 * \param xtdrive Bits defining the XT drive mode
101 ******************************************************************************/
102 extern void XT1_Start(unsigned int xtdrive);
104 /*******************************************************************************
105 * \brief Startup routine for XT1 with timeout counter
107 * \param xtdrive Bits defining the XT drive mode
108 * \param timeout Value for the timeout counter
109 ******************************************************************************/
110 extern unsigned int XT1_Start_Timeout(unsigned int xtdrive, unsigned int timeout);
112 /*******************************************************************************
113 * \brief Use XT1 in Bypasss mode
114 ******************************************************************************/
115 extern void XT1_Bypass(void);
119 /*******************************************************************************
120 * \brief Stop XT1 oscillator
121 ******************************************************************************/
122 extern void XT1_Stop(void);
125 /*******************************************************************************
126 * \brief Startup routine for XT2
128 * \param xtdrive Bits defining the XT drive mode
129 ******************************************************************************/
130 extern void XT2_Start(unsigned int xtdrive);
132 /*******************************************************************************
133 * \brief Startup routine for XT2 with timeout counter
135 * \param xtdrive Bits defining the XT drive mode
136 * \param timeout Value for the timeout counter
137 ******************************************************************************/
138 extern unsigned int XT2_Start_Timeout(unsigned int xtdrive, unsigned int timeout);
140 /*******************************************************************************
141 * \brief Use XT2 in Bypasss mode for MCLK
142 ******************************************************************************/
143 extern void XT2_Bypass(void);
145 /*******************************************************************************
146 * \brief Stop XT2 oscillator
147 ******************************************************************************/
148 extern void XT2_Stop(void);
152 /*******************************************************************************
153 * \brief Initializes FLL of the UCS and wait till settled before allowing
154 * code execution to resume. The use of this function is preferred
155 * over the use of Init_FLL().
157 * \param fsystem Required system frequency (MCLK) in kHz
158 * \param ratio Ratio between fsystem and FLLREFCLK
159 ******************************************************************************/
160 extern void Init_FLL_Settle(unsigned int fsystem, unsigned int ratio);
163 #endif /* HAL_UCS_H */