BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ucs.h
Go to the documentation of this file.
1 /* Copyright 2012-2014, Peter A. Bigot
2  *
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the software nor the names of its contributors may be
16  * used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
88 #ifndef BSP430_PERIPH_UCS_H
89 #define BSP430_PERIPH_UCS_H
90 
91 #include <bsp430/clock.h>
92 #include <bsp430/periph.h>
93 
100 #define BSP430_MODULE_UCS (defined(__MSP430_HAS_UCS__) \
101  || defined(__MSP430_HAS_UCS_RF__))
102 
103 #if defined(BSP430_DOXYGEN) || (BSP430_MODULE_UCS - 0)
104 
125 #ifndef configBSP430_UCS_TRIM_DCOCLKDIV
126 #define configBSP430_UCS_TRIM_DCOCLKDIV 1
127 #endif /* configBSP430_UCS_TRIM_DCOCLKDIV */
128 
129 #if (configBSP430_UCS_TRIM_DCOCLKDIV - 0) && ! (configBSP430_TIMER_CCACLK - 0)
130 #warning configBSP430_UCS_TRIM_DCOCLKDIV requested without configBSP430_TIMER_CCACLK
131 #endif /* configBSP430_UCS_TRIM_DCOCLKDIV */
132 
142 #if defined(BSP430_DOXYGEN)
143 #define BSP430_UCS_TRIM_DCOCLKDIV include <bsp430/platform.h>
144 #endif /* BSP430_DOXYGEN */
145 
146 #if defined(BSP430_DOXYGEN) || (configBSP430_UCS_TRIM_DCOCLKDIV - 0)
147 
179 #endif /* configBSP430_UCS_TRIM_DCOCLKDIV */
180 
190 #ifndef BSP430_UCS_FLL_SELREF
191 #define BSP430_UCS_FLL_SELREF SELREF__XT1CLK
192 #endif /* BSP430_UCS_FLL_SELREF */
193 
195 /* Simplify conditionally-defined macros to avoid reference to
196  * non-existent values. */
197 #if defined(XT2OFFG)
198 #define BSP430_UCS_XT2OFF_ XT2OFF
199 #define BSP430_UCS_XT2OFFG_ XT2OFFG
200 #else /* XT2OFFG */
201 #define BSP430_UCS_XT2OFF_ 0
202 #define BSP430_UCS_XT2OFFG_ 0
203 #endif /* XT2OFFG */
204 #if defined(XT1HFOFFG)
205 #define BSP430_UCS_XT1HFOFFG_ XT1HFOFFG
206 #else /* XT1HFOFFG */
207 #define BSP430_UCS_XT1HFOFFG_ 0
208 #endif /* XT1HFOFFG */
209 
212 #define BSP430_UCS_DCO_IS_FAULTED_NI() (UCSCTL7 & DCOFFG)
213 
220 #define BSP430_UCS_LFXT1_IS_FAULTED_NI() (UCSCTL7 & XT1LFOFFG)
221 
229 #define BSP430_UCS_XT2_IS_FAULTED_NI() (UCSCTL7 & BSP430_UCS_XT2OFFG_)
230 
246 #if defined(BSP430_DOXYGEN) || ! defined(BSP430_CLOCK_LFXT1_IS_FAULTED_NI)
247 #define BSP430_CLOCK_LFXT1_IS_FAULTED_NI() ((UCSCTL6 & XT1OFF) || BSP430_UCS_LFXT1_IS_FAULTED_NI())
248 #endif /* BSP430_CLOCK_LFXT1_IS_FAULTED_NI */
249 
265 #if defined(BSP430_DOXYGEN) || ! defined(BSP430_CLOCK_XT2_IS_FAULTED_NI)
266 #define BSP430_CLOCK_XT2_IS_FAULTED_NI() ((UCSCTL6 & BSP430_UCS_XT2OFF_) || BSP430_UCS_XT2_IS_FAULTED_NI())
267 #endif /* BSP430_CLOCK_XT2_IS_FAULTED_NI */
268 
270 #define BSP430_UCS_CLEAR_FAULTS_NI() do { \
271  UCSCTL7 &= ~(BSP430_UCS_XT2OFFG_ | BSP430_UCS_XT1HFOFFG_ | XT1LFOFFG | DCOFFG); \
272  } while (0)
273 
280 #if defined(BSP430_DOXYGEN) || ! defined(BSP430_CLOCK_CLEAR_FAULTS_NI)
281 #define BSP430_CLOCK_CLEAR_FAULTS_NI() do { \
282  BSP430_UCS_CLEAR_FAULTS_NI(); \
283  BSP430_CLOCK_OSC_CLEAR_FAULT_NI(); \
284  } while (0)
285 #endif /* BSP430_CLOCK_CLEAR_FAULTS_NI */
286 
287 #ifndef BSP430_CLOCK_LFXT1_XCAP
288 
289 #define BSP430_CLOCK_LFXT1_XCAP XCAP_1
290 #endif /* BSP430_CLOCK_LFXT1_XCAP */
291 
292 #if defined(BSP430_DOXYGEN) || defined(BSP430_PERIPH_XT2)
293 
294 #undef BSP430_CLOCK_XT2_IS_FAULTED_NI
295 
303 #define BSP430_CLOCK_XT2_IS_FAULTED_NI() (UCSCTL7 & XT2OFFG)
304 
305 #endif /* BSP430_PERIPH_XT2 */
306 
308 #define BSP430_CLOCK_NOMINAL_VLOCLK_HZ 10000U
309 
311 #define BSP430_CLOCK_PUC_MCLK_HZ 1048576UL
312 
316 #define BSP430_UCS_NOMINAL_REFOCLK_HZ 32768U
317 
324 #ifndef BSP430_UCS_NOMINAL_MODCLK_HZ
325 #define BSP430_UCS_NOMINAL_MODCLK_HZ 5000000UL
326 #endif /* BSP430_UCS_NOMINAL_MODCLK_HZ */
327 
329 /* Provide definition for clock system */
330 #define BSP430_NOMINAL_MODCLK_HZ BSP430_UCS_NOMINAL_MODCLK_HZ
331 
333 #endif /* BSP430_MODULE_UCS */
334 
335 #endif /* BSP430_PERIPH_UCS_H */
336 
Clock-related functions implemented on all MSP430 MCUs.
int iBSP430ucsTrimDCOCLKDIV_ni()
Generic peripheral support for MSP430 MCUs.