BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
cs.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 
80 #ifndef BSP430_PERIPH_CS_H
81 #define BSP430_PERIPH_CS_H
82 
83 #include <bsp430/clock.h>
84 #include <bsp430/periph.h>
85 
103 #define BSP430_CS_IS_FR58XX (BSP430_PERIPH_CS_IS_CSA - 0)
104 
113 #define BSP430_CS_IS_FR57XX (defined(__MSP430_HAS_CS__) && (! ((BSP430_PERIPH_CS_IS_CSA - 0) || (BSP430_PERIPH_CS_IS_CS4 - 0))))
114 
125 #define BSP430_MODULE_CS ((BSP430_CS_IS_FR57XX - 0) || (BSP430_CS_IS_FR58XX - 0))
126 
127 #if defined(BSP430_DOXYGEN) || (BSP430_MODULE_CS - 0)
128 
130 /* Simplify conditionally-defined macros to avoid reference to
131  * non-existent values and inconsistencies between CS and CS_A. */
132 #if (BSP430_CS_IS_FR58XX - 0)
133 #define BSP430_CS_XT2DRIVE_ HFXTDRIVE
134 #define BSP430_CS_XT2OFF_ HFXTOFF
135 #define BSP430_CS_XT1DRIVE_ LFXTDRIVE
136 #define BSP430_CS_XTS_ 0
137 #define BSP430_CS_XT1BYPASS_ LFXTBYPASS
138 #define BSP430_CS_XT1OFF_ LFXTOFF
139 #define BSP430_CS_XT2OFFG_ HFXTOFFG
140 #define BSP430_CS_XT1OFFG_ LFXTOFFG
141 #else /* CS or CS_A */
142 #define BSP430_CS_XT2DRIVE_ XT2DRIVE
143 #define BSP430_CS_XT2OFF_ XT2OFF
144 #define BSP430_CS_XT1DRIVE_ XT1DRIVE
145 #define BSP430_CS_XTS_ XTS
146 #define BSP430_CS_XT1BYPASS_ XT1BYPASS
147 #define BSP430_CS_XT1OFF_ XT1OFF
148 #if defined(XT2OFFG)
149 #define BSP430_CS_XT2OFFG_ XT2OFFG
150 #else /* XT2OFFG */
151 #define BSP430_CS_XT2OFFG_ 0
152 #endif /* XT2OFFG */
153 #define BSP430_CS_XT1OFFG_ XT1OFFG
154 #endif /* CS or CS_A */
155 
157 #if defined(BSP430_DOXYGEN) || (BSP430_CS_IS_FR58XX - 0)
158 /* CS_A has a significantly different set of capabilities */
159 
168 #ifndef BSP430_CS_NOMINAL_MODCLK_HZ
169 #define BSP430_CS_NOMINAL_MODCLK_HZ 5000000UL
170 #endif /* BSP430_CS_NOMINAL_MODCLK_HZ */
171 
173 /* Provide definition for clock system */
174 #define BSP430_NOMINAL_MODCLK_HZ BSP430_CS_NOMINAL_MODCLK_HZ
175 
181 #define BSP430_CS_NOMINAL_LFMODCLK_HZ (BSP430_CS_NOMINAL_MODCLK_HZ / 128)
182 #endif /* BSP430_CS_IS_FR58XX */
183 
190 #define BSP430_CS_LFXT1_IS_FAULTED_NI() (CSCTL5 & BSP430_CS_XT1OFFG_)
191 
199 #define BSP430_CS_XT2_IS_FAULTED_NI() (CSCTL5 & BSP430_CS_XT2OFFG_)
200 
216 #if defined(BSP430_DOXYGEN) || ! defined(BSP430_CLOCK_LFXT1_IS_FAULTED_NI)
217 #define BSP430_CLOCK_LFXT1_IS_FAULTED_NI() ((CSCTL4 & BSP430_CS_XT1OFF_) || BSP430_CS_LFXT1_IS_FAULTED_NI())
218 #endif /* BSP430_CLOCK_LFXT1_IS_FAULTED_NI */
219 
235 #if defined(BSP430_DOXYGEN) || ! defined(BSP430_CLOCK_XT2_IS_FAULTED_NI)
236 #define BSP430_CLOCK_XT2_IS_FAULTED_NI() ((CSCTL4 & BSP430_CS_XT2OFF_) || BSP430_CS_XT2_IS_FAULTED_NI())
237 #endif /* BSP430_CLOCK_XT2_IS_FAULTED_NI */
238 
243 #define BSP430_CS_CLEAR_FAULTS_NI() do { \
244  CSCTL5 &= ~(BSP430_CS_XT2OFFG_ | BSP430_CS_XT1OFFG_); \
245  } while (0)
246 
253 #if defined(BSP430_DOXYGEN) || ! defined(BSP430_CLOCK_CLEAR_FAULTS_NI)
254 #define BSP430_CLOCK_CLEAR_FAULTS_NI() do { \
255  CSCTL0_H = 0xA5; \
256  BSP430_CS_CLEAR_FAULTS_NI(); \
257  CSCTL0_H = !0xA5; \
258  BSP430_CLOCK_OSC_CLEAR_FAULT_NI(); \
259  } while (0)
260 #endif /* BSP430_CLOCK_CLEAR_FAULTS_NI */
261 
293 #if defined(BSP430_DOXYGEN)
294 #define BSP430_CS_FRAM_NWAITS_FOR_FREQ(freq_) include <bsp430/platform.h>
295 #endif /* BSP430_PMM_COREV_FOR_MCLK */
296 
298 #define BSP430_CLOCK_NOMINAL_VLOCLK_HZ 10000U
299 
301 #define BSP430_CLOCK_PUC_MCLK_HZ 1048576UL
302 
303 #endif /* BSP430_MODULE_CS */
304 
305 #endif /* BSP430_PERIPH_CS_H */
Clock-related functions implemented on all MSP430 MCUs.
Generic peripheral support for MSP430 MCUs.