MSP430 DriverLib for MSP430i2xx Devices  2.91.13.01
cs.h
1 //*****************************************************************************
2 //
3 // cs.h - Driver for the CS Module.
4 //
5 //*****************************************************************************
6 
7 #ifndef __MSP430WARE_CS_H__
8 #define __MSP430WARE_CS_H__
9 
10 #include "inc/hw_memmap.h"
11 
12 #ifdef __MSP430_HAS_CS__
13 
14 //*****************************************************************************
15 //
16 // If building with a C++ compiler, make all of the definitions in this header
17 // have a C binding.
18 //
19 //*****************************************************************************
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 //*****************************************************************************
26 //
27 // The following are values that can be passed to the mode parameter for
28 // functions: CS_setupDCO().
29 //
30 //*****************************************************************************
31 #define CS_INTERNAL_RESISTOR 0x00
32 #define CS_EXTERNAL_RESISTOR DCOR
33 #define CS_BYPASS_MODE DCOBYP
34 
35 //*****************************************************************************
36 //
37 // The following are values that can be passed to the clockSource parameter for
38 // functions: CS_initClockSignal().
39 //
40 //*****************************************************************************
41 #define CS_MCLK 0x01
42 #define CS_SMCLK 0x02
43 
44 //*****************************************************************************
45 //
46 // The following are values that can be passed to the clockSourceDivider
47 // parameter for functions: CS_initClockSignal().
48 //
49 //*****************************************************************************
50 #define CS_CLOCK_DIVIDER_1 DIVM_0
51 #define CS_CLOCK_DIVIDER_2 DIVM_1
52 #define CS_CLOCK_DIVIDER_4 DIVM_2
53 #define CS_CLOCK_DIVIDER_8 DIVM_3
54 #define CS_CLOCK_DIVIDER_16 DIVM_4
55 
56 //*****************************************************************************
57 //
58 // The following are values that can be passed to the mask parameter for
59 // functions: CS_getFaultFlagStatus() as well as returned by the
60 // CS_getFaultFlagStatus() function.
61 //
62 //*****************************************************************************
63 #define CS_DCO_FAULT_FLAG DCOF
64 
65 //*****************************************************************************
66 //
67 // Prototypes for the APIs.
68 //
69 //*****************************************************************************
70 
71 //*****************************************************************************
72 //
73 //! \brief Sets up the DCO using the selected mode
74 //!
75 //! Sets up the DCO using the selected mode. If the bypass mode is selected
76 //! than an external digital clock is required on the CLKIN pin to drive all
77 //! clocks on the device. ACLK frequency is not programmable and is fixed to
78 //! the bypass clock frequency divided by 512. For external resistor mode a
79 //! 20kOhm resistor is recommended at the ROSC pin. External resistor mode
80 //! offers higer clock accuracy in terms of absolute tolerance and temperature
81 //! drift compared to the internal resistor mode. Please check your device
82 //! datasheet for details and ratings for the differnt modes.
83 //!
84 //! \param mode Mode to put the DCO into
85 //! Valid values are:
86 //! - \b CS_INTERNAL_RESISTOR - DCO operation with internal resistor
87 //! - \b CS_EXTERNAL_RESISTOR - DCO operation with external resistor
88 //! - \b CS_BYPASS_MODE - Bypass mode, provide external clock signal
89 //!
90 //! \return None
91 //
92 //*****************************************************************************
93 extern void CS_setupDCO(uint8_t mode);
94 
95 //*****************************************************************************
96 //
97 //! \brief Initializes a clock singal with a divider
98 //!
99 //! Sets up a clock signal with a divider. If the DCO is in bypass mode the
100 //! frequency will be CLKIN / divider. If the DCO is not in bypass mode the
101 //! frequency will 16.384MHz / divider.
102 //!
103 //! \param clockSource Clock signal to initialize
104 //! Valid values are:
105 //! - \b CS_MCLK
106 //! - \b CS_SMCLK
107 //! \param clockSourceDivider Divider setting for the selected clock signal
108 //! Valid values are:
109 //! - \b CS_CLOCK_DIVIDER_1
110 //! - \b CS_CLOCK_DIVIDER_2
111 //! - \b CS_CLOCK_DIVIDER_4
112 //! - \b CS_CLOCK_DIVIDER_8
113 //! - \b CS_CLOCK_DIVIDER_16
114 //!
115 //! \return None
116 //
117 //*****************************************************************************
118 extern void CS_initClockSignal(uint8_t clockSource,
119  uint8_t clockSourceDivider);
120 
121 //*****************************************************************************
122 //
123 //! \brief Get the current ACLK frequency in Hz
124 //!
125 //! This API returns the current ACLK frequency in Hz. It does not work when
126 //! the device is setup in DCO bypass mode. Also, CS_setupDCO() should be
127 //! called before this API so that the DCO has been calibrated and this
128 //! calculation is accurate.
129 //!
130 //!
131 //! \return Current ACLK frequency in Hz, 0 when in bypass mode
132 //
133 //*****************************************************************************
134 extern uint32_t CS_getACLK(void);
135 
136 //*****************************************************************************
137 //
138 //! \brief Get the current SMCLK frequency in Hz
139 //!
140 //! This API returns the current SMCLK frequency in Hz. It does not work when
141 //! the device is setup in DCO bypass mode. Also, CS_setupDCO() should be
142 //! called before this API so that the DCO has been calibrated and this
143 //! calculation is accurate.
144 //!
145 //!
146 //! \return Current SMCLK frequency in Hz, 0 when in bypass mode
147 //
148 //*****************************************************************************
149 extern uint32_t CS_getSMCLK(void);
150 
151 //*****************************************************************************
152 //
153 //! \brief Get the current MCLK frequency in Hz
154 //!
155 //! This API returns the current MCLK frequency in Hz. It does not work when
156 //! the device is setup in DCO bypass mode. Also, CS_setupDCO() should be
157 //! called before this API so that the DCO has been calibrated and this
158 //! calculation is accurate.
159 //!
160 //!
161 //! \return Current MCLK frequency in Hz, 0 when in bypass mode
162 //
163 //*****************************************************************************
164 extern uint32_t CS_getMCLK(void);
165 
166 //*****************************************************************************
167 //
168 //! \brief Get the DCO fault flag status
169 //!
170 //! Reads and returns DCO fault flag. The DCO fault flag is set when the DCO is
171 //! operating in external resistor mode and the DCO detects an abnormality. An
172 //! abnormality could be if the ROSC pin is left open or shorted to ground, or
173 //! if the resistance connected at the ROSC pin is far away from the
174 //! recommended value. If the fault persists the DCO automatically switches to
175 //! the internal resistor mode as a fail-safe mechanism.
176 //!
177 //! \param mask Mask of fault flags to check
178 //! Mask value is the logical OR of any of the following:
179 //! - \b CS_DCO_FAULT_FLAG
180 //!
181 //! \return Logical OR of any of the following:
182 //! - \b CS_DCO_FAULT_FLAG
183 //! \n indicating if the masked fault flags are set
184 //
185 //*****************************************************************************
186 extern uint8_t CS_getFaultFlagStatus(uint8_t mask);
187 
188 //*****************************************************************************
189 //
190 // Mark the end of the C bindings section for C++ compilers.
191 //
192 //*****************************************************************************
193 #ifdef __cplusplus
194 }
195 #endif
196 
197 #endif
198 #endif // __MSP430WARE_CS_H__
uint32_t CS_getACLK(void)
Get the current ACLK frequency in Hz.
Definition: cs.c:54
uint8_t CS_getFaultFlagStatus(uint8_t mask)
Get the DCO fault flag status.
Definition: cs.c:69
void CS_setupDCO(uint8_t mode)
Sets up the DCO using the selected mode.
Definition: cs.c:28
void CS_initClockSignal(uint8_t clockSource, uint8_t clockSourceDivider)
Initializes a clock singal with a divider.
Definition: cs.c:42
uint32_t CS_getMCLK(void)
Get the current MCLK frequency in Hz.
Definition: cs.c:64
uint32_t CS_getSMCLK(void)
Get the current SMCLK frequency in Hz.
Definition: cs.c:58

Copyright 2020, Texas Instruments Incorporated