1 |
584 |
jeremybenn |
//*******************************************************************************
|
2 |
|
|
// Provides Functions to Initialize the UCS/FLL and clock sources
|
3 |
|
|
// File: hal_ucs.c
|
4 |
|
|
//
|
5 |
|
|
// Texas Instruments
|
6 |
|
|
//
|
7 |
|
|
// Version 1.2
|
8 |
|
|
// 11/24/09
|
9 |
|
|
//
|
10 |
|
|
// V1.0 Initial Version
|
11 |
|
|
// V1.1 Added timeout function
|
12 |
|
|
// V1.1 Added parameter for XTDrive
|
13 |
|
|
//*******************************************************************************
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
#ifndef __hal_UCS
|
17 |
|
|
#define __hal_UCS
|
18 |
|
|
|
19 |
|
|
#include <stdint.h>
|
20 |
|
|
#include "hal_macros.h"
|
21 |
|
|
|
22 |
|
|
/*************************************************************************
|
23 |
|
|
* MACROS
|
24 |
|
|
**************************************************************************/
|
25 |
|
|
|
26 |
|
|
/* Select source for FLLREF e.g. SELECT_FLLREF(SELREF__XT1CLK) */
|
27 |
|
|
#define SELECT_FLLREF(source) st(UCSCTL3 = (UCSCTL3 & ~(SELREF_7)) | (source);)
|
28 |
|
|
/* Select source for ACLK e.g. SELECT_ACLK(SELA__XT1CLK) */
|
29 |
|
|
#define SELECT_ACLK(source) st(UCSCTL4 = (UCSCTL4 & ~(SELA_7)) | (source);)
|
30 |
|
|
/* Select source for MCLK e.g. SELECT_MCLK(SELM__XT2CLK) */
|
31 |
|
|
#define SELECT_MCLK(source) st(UCSCTL4 = (UCSCTL4 & ~(SELM_7)) | (source);)
|
32 |
|
|
/* Select source for SMCLK e.g. SELECT_SMCLK(SELS__XT2CLK) */
|
33 |
|
|
#define SELECT_SMCLK(source) st(UCSCTL4 = (UCSCTL4 & ~(SELS_7)) | (source);)
|
34 |
|
|
/* Select source for MCLK and SMCLK e.g. SELECT_MCLK_SMCLK(SELM__DCOCLK + SELS__DCOCLK) */
|
35 |
|
|
#define SELECT_MCLK_SMCLK(sources) st(UCSCTL4 = (UCSCTL4 & ~(SELM_7 + SELS_7)) | (sources);)
|
36 |
|
|
|
37 |
|
|
/* set ACLK/x */
|
38 |
|
|
#define ACLK_DIV(x) st(UCSCTL5 = (UCSCTL5 & ~(DIVA_7)) | (DIVA__##x);)
|
39 |
|
|
/* set MCLK/x */
|
40 |
|
|
#define MCLK_DIV(x) st(UCSCTL5 = (UCSCTL5 & ~(DIVM_7)) | (DIVM__##x);)
|
41 |
|
|
/* set SMCLK/x */
|
42 |
|
|
#define SMCLK_DIV(x) st(UCSCTL5 = (UCSCTL5 & ~(DIVS_7)) | (DIVS__##x);)
|
43 |
|
|
/* Select divider for FLLREF e.g. SELECT_FLLREFDIV(2) */
|
44 |
|
|
#define SELECT_FLLREFDIV(x) st(UCSCTL3 = (UCSCTL3 & ~(FLLREFDIV_7))|(FLLREFDIV__##x);)
|
45 |
|
|
|
46 |
|
|
//************************************************************************
|
47 |
|
|
// Defines
|
48 |
|
|
//************************************************************************
|
49 |
|
|
|
50 |
|
|
#define UCS_STATUS_OK 0
|
51 |
|
|
#define UCS_STATUS_ERROR 1
|
52 |
|
|
|
53 |
|
|
//====================================================================
|
54 |
|
|
/**
|
55 |
|
|
* Startup routine for 32kHz Cristal on LFXT1
|
56 |
|
|
*
|
57 |
|
|
* \param xtdrive: Bits defining the LFXT drive mode after startup
|
58 |
|
|
*
|
59 |
|
|
*/
|
60 |
|
|
extern void LFXT_Start(uint16_t xtdrive);
|
61 |
|
|
|
62 |
|
|
//====================================================================
|
63 |
|
|
/**
|
64 |
|
|
* Startup routine for 32kHz Cristal on LFXT1 with timeout counter
|
65 |
|
|
*
|
66 |
|
|
* \param xtdrive: Bits defining the LFXT drive mode after startup
|
67 |
|
|
* \param timeout: value for the timeout counter
|
68 |
|
|
*
|
69 |
|
|
*/
|
70 |
|
|
extern uint16_t LFXT_Start_Timeout(uint16_t xtdrive, uint16_t timeout);
|
71 |
|
|
|
72 |
|
|
//====================================================================
|
73 |
|
|
/**
|
74 |
|
|
* Startup routine for XT1
|
75 |
|
|
*
|
76 |
|
|
* \param xtdrive: Bits defining the XT drive mode
|
77 |
|
|
*
|
78 |
|
|
*/
|
79 |
|
|
extern void XT1_Start(uint16_t xtdrive);
|
80 |
|
|
|
81 |
|
|
//====================================================================
|
82 |
|
|
/**
|
83 |
|
|
* Startup routine for XT1 with timeout counter
|
84 |
|
|
*
|
85 |
|
|
* \param xtdrive: Bits defining the XT drive mode
|
86 |
|
|
* \param timeout: value for the timeout counter
|
87 |
|
|
*
|
88 |
|
|
*/
|
89 |
|
|
extern uint16_t XT1_Start_Timeout(uint16_t xtdrive, uint16_t timeout);
|
90 |
|
|
|
91 |
|
|
//====================================================================
|
92 |
|
|
/**
|
93 |
|
|
* Use XT1 in Bypasss mode
|
94 |
|
|
*
|
95 |
|
|
*/
|
96 |
|
|
extern void XT1_Bypass(void);
|
97 |
|
|
|
98 |
|
|
//====================================================================
|
99 |
|
|
/**
|
100 |
|
|
* Startup routine for XT2
|
101 |
|
|
*
|
102 |
|
|
* \param xtdrive: Bits defining the XT drive mode
|
103 |
|
|
*
|
104 |
|
|
*/
|
105 |
|
|
extern void XT2_Start(uint16_t xtdrive);
|
106 |
|
|
|
107 |
|
|
//====================================================================
|
108 |
|
|
/**
|
109 |
|
|
* Startup routine for XT2 with timeout counter
|
110 |
|
|
*
|
111 |
|
|
* \param xtdrive: Bits defining the XT drive mode
|
112 |
|
|
* \param timeout: value for the timeout counter
|
113 |
|
|
*
|
114 |
|
|
*/
|
115 |
|
|
extern uint16_t XT2_Start_Timeout(uint16_t xtdrive, uint16_t timeout);
|
116 |
|
|
|
117 |
|
|
//====================================================================
|
118 |
|
|
/**
|
119 |
|
|
* Use XT2 in Bypasss mode for MCLK
|
120 |
|
|
*
|
121 |
|
|
*/
|
122 |
|
|
extern void XT2_Bypass(void);
|
123 |
|
|
|
124 |
|
|
//====================================================================
|
125 |
|
|
/**
|
126 |
|
|
* Initializes FLL of the UCS and wait till settled
|
127 |
|
|
*
|
128 |
|
|
* \param fsystem required system frequency (MCLK) in kHz
|
129 |
|
|
* \param ratio ratio between fsystem and FLLREFCLK
|
130 |
|
|
*/
|
131 |
|
|
extern void Init_FLL_Settle(uint16_t fsystem, uint16_t ratio);
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
//====================================================================
|
135 |
|
|
/**
|
136 |
|
|
* Initializes FLL of the UCS
|
137 |
|
|
*
|
138 |
|
|
* \param fsystem required system frequency (MCLK) in kHz
|
139 |
|
|
* \param ratio ratio between fsystem and FLLREFCLK
|
140 |
|
|
*/
|
141 |
|
|
static void Init_FLL(uint16_t fsystem, uint16_t ratio);
|
142 |
|
|
|
143 |
|
|
#endif /* __hal_UCS */
|