Guest User

Untitled

a guest
Jun 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. /**
  2. * clock_t.h - clock peripheral configuration template
  3. *
  4. * Author: kimballr
  5. * Date: 02/08/2012
  6. * Version: 0.01
  7. *
  8. */
  9.  
  10. #ifndef CLOCK_T_H_
  11. #define CLOCK_T_H_
  12.  
  13. #include <msp430.h>
  14.  
  15. #define CLOCK_T_VERSION 0x0001 // 00.01
  16.  
  17. /**
  18. * BasicClock traits no clock out
  19. */
  20. typedef struct {
  21. static const bool hasBasicClockPlus = true;
  22. static const bool hasCSClock = true;
  23.  
  24. static void OutputSMCLK() { }
  25. } BCSClockTraits, LaunchpadClockTraits;
  26.  
  27. /**
  28. * BasicClock traits clock out on P1.4
  29. */
  30. typedef struct {
  31. static const bool hasBasicClockPlus = true;
  32. static const bool hasCSClock = true;
  33.  
  34. static void OutputSMCLK() {
  35. P1DIR |= BIT4; P1SEL |= BIT4;
  36. }
  37. } BCSDebugClockTraits, LaunchpadDebugClockTraits;
  38.  
  39. /**
  40. * BasicClock traits clock out on P1.4
  41. */
  42. typedef struct {
  43. static const bool hasBasicClockPlus = false;
  44. static const bool hasCSClock = true;
  45. static void OutputSMCLK() {
  46. P1DIR |= BIT4; P1SEL |= BIT4;
  47. }
  48. } UCSDebugClockTraits;
  49.  
  50. /**
  51. * CS traits clock out on J.0 - clock on the msp430fr5739
  52. *
  53. * The clock system module supports low system cost and low power consumption. Using three internal
  54. * clock signals, the user can select the best balance of performance and low power consumption. The
  55. * clock module can be configured to operate without any external components, with one or two external
  56. * crystals, or with resonators, under full software control
  57. */
  58. typedef struct {
  59. static const bool hasBasicClockPlus = false;
  60. static const bool hasCSClock = true;
  61.  
  62. static void OutputSMCLK() {
  63. #ifdef __MSP430_HAS_CS__
  64. PJSEL0 |= BIT0;
  65. PJSEL1 &= ~BIT0;
  66. PJDIR |= BIT0;
  67. #endif
  68. }
  69. } FraunchpadDebugClockTraits;
  70.  
  71. /**
  72. * CLK_t - master clock template
  73. */
  74. template <
  75. uint32_t MCLK = 1024000UL,
  76. typename ClockTraits = LaunchpadDebugClockTraits,
  77. uint32_t SMCLK = MCLK,
  78. uint32_t ACLK = 12000UL
  79. >
  80. struct CLK_t {
  81. static const uint32_t MCLK_FREQ = MCLK;
  82.  
  83. /**
  84. * init() - initialize the clock for the given MCLK_FREQ
  85. */
  86. static void init() {
  87. ClockTraits::OutputSMCLK();
  88. // default clock usually around 1.024MHz
  89. // do nothing to initialize, just use the default clock
  90. }
  91.  
  92. static void OutputSMCLK() { ClockTraits::OutputSMCLK(); }
  93. };
  94.  
  95. typedef CLK_t<> DefaultBCSMCLK;
  96. typedef CLK_t<1024000UL,FraunchpadDebugClockTraits> DefaultCSMCLK;
  97.  
  98. /**
  99. * 16MHz BCS calibrated clock
  100. */
  101. template<>
  102. struct CLK_t<16000000UL> {
  103. static void init() {
  104. DefaultBCSMCLK::OutputSMCLK();
  105.  
  106. DCOCTL = 0;
  107. BCSCTL1 = CALBC1_16MHZ;
  108. DCOCTL = CALDCO_16MHZ;
  109.  
  110. { volatile uint16_t n; for(n=0; n < 0xffff; n++); }
  111. }
  112. };
  113.  
  114. /**
  115. * 12MHz BCS calibrated clock
  116. */
  117. template<>
  118. struct CLK_t<12000000UL> {
  119. static void init() {
  120. DefaultBCSMCLK::OutputSMCLK();
  121.  
  122. DCOCTL = 0;
  123. BCSCTL1 = CALBC1_12MHZ;
  124. DCOCTL = CALDCO_12MHZ;
  125.  
  126. { volatile uint16_t n; for(n=0; n < 0xffff; n++); }
  127. }
  128. };
  129.  
  130. /**
  131. * 8MHz BCS calibrated clock
  132. */
  133. template<>
  134. struct CLK_t<8000000UL> {
  135. static void init() {
  136. DefaultBCSMCLK::OutputSMCLK();
  137.  
  138. DCOCTL = 0;
  139. BCSCTL1 = CALBC1_8MHZ;
  140. DCOCTL = CALDCO_8MHZ;
  141.  
  142. { volatile uint16_t n; for(n=0; n < 0xffff; n++); }
  143. }
  144. };
  145.  
  146. /**
  147. * 1MHz BCS calibrated clock
  148. */
  149. template<>
  150. struct CLK_t<1000000UL> {
  151. static void init() {
  152. DefaultBCSMCLK::OutputSMCLK();
  153.  
  154. DCOCTL = 0;
  155. BCSCTL1 = CALBC1_1MHZ;
  156. DCOCTL = CALDCO_1MHZ;
  157. }
  158. };
  159.  
  160. /**
  161. * 8MHz CS+ calibrated clock found on FRAM chip
  162. */
  163. template<>
  164. struct CLK_t<8000000UL, FraunchpadDebugClockTraits> {
  165. static void init() {
  166. #ifdef __MSP430_HAS_CS__
  167. FraunchpadDebugClockTraits::OutputSMCLK();
  168. // Use 8MHz DCO factory calibration
  169.  
  170. CSCTL0_H = 0xA5;// CS_KEY
  171. CSCTL1 |= DCOFSEL0 | DCOFSEL1;// Set max. DCO setting
  172. CSCTL2 = SELA_3 | SELS_3 | SELM_3;// set ACLK = MCLK = DCO
  173. CSCTL3 = DIVA_0 | DIVS_0 | DIVM_0;// set all dividers
  174. CSCTL0_H = 0x01;// Lock Register
  175.  
  176. { volatile uint16_t n; for(n=0; n < 0xffff; n++); }
  177. #endif
  178. }
  179. };
  180.  
  181. /**
  182. * 24MHz CS+ calibrated clock found on FRAM chip
  183. */
  184. template<>
  185. struct CLK_t<24000000UL, FraunchpadDebugClockTraits> {
  186. static void init() {
  187. #ifdef __MSP430_HAS_CS__
  188. FraunchpadDebugClockTraits::OutputSMCLK();
  189.  
  190. CSCTL0_H = 0xA5; // CS_KEY
  191. CSCTL1 |= DCORSEL | DCOFSEL0 | DCOFSEL1;// Set max. DCO setting
  192. CSCTL2 = SELA_3 + SELS_3 + SELM_3;// set ACLK = MCLK = DCO
  193. CSCTL3 = DIVA_0 + DIVS_0 + DIVM_0;// set all dividers
  194. CSCTL0_H = 0x01;// Lock Register
  195. { volatile uint16_t n; for (n = 0; n < 0xffff; n++); }
  196. #endif
  197. }
  198. };
  199.  
  200. #endif /* CLOCK_T_H_ */
Add Comment
Please, Sign In to add comment