CLEON  Version 1
Cloud-Offloaded GPS Receiver
hal_ucs.c
Go to the documentation of this file.
1 
7 #include "cleon_conf.h"
8 #include "app_define.h"
9 #include "sys_define.h"
10 #include "hal_define.h"
11 #include "fs_define.h"
12 
13 /*----------------------------------------------------------------------------*/
22 {
23  unsigned int uiXT1Timeout = 50000;
24  unsigned int uiXT2Timeout = 50000;
25 
26  while (BAKCTL & LOCKBAK) BAKCTL &= ~LOCKBAK;
27 
28  // XT1 (32768Hz)
29  UCSCTL6 |= XT1DRIVE1 + XT1DRIVE0;
30 
31  UCSCTL6 &= ~XT1OFF; // Set XT1 On
32  UCSCTL6 &= ~(XCAP1 + XCAP0); // Internal load cap
33 
34  __delay_cycles(50000); // Delay until XT2 is stabilized
35 
36  do // Loop until XT1 stabilizes
37  {
38  UCSCTL7 &= ~XT1LFOFFG; // Clear XT2,XT1,DCO fault flags
39  SFRIFG1 &= ~OFIFG; // Clear fault flags
40  }while ((UCSCTL7 & XT1LFOFFG) && --uiXT1Timeout); // Check XT2 fault flag
41 
42  // XT2 (12000000Hz)
43  XT2_PORT(SEL) |= BV(XT2OUT_PIN); // Set P7.2/XT2IN and P7.3/XT2OUT for XT pins
44  XT2_PORT(SEL) |= BV(XT2IN_PIN);
45 
46  UCSCTL6 |= XT2DRIVE0; // Drive strength set to range of 8MHz to 16MHz
47  UCSCTL6 &= ~XT2OFF; // Set XT2 On
48 
49  __delay_cycles(50000); // Delay until XT2 is stabilized
50 
51  do // Loop until XT2 stabilizes
52  {
53  UCSCTL7 &= ~XT2OFFG; // Clear XT2,XT1,DCO fault flags
54  SFRIFG1 &= ~OFIFG; // Clear fault flags
55  }while ((UCSCTL7 & XT2OFFG) && --uiXT2Timeout); // Check XT2 fault flag
56 
57  // Clock selection
58  UCSCTL4 |= SELA_0 + SELS_5 + SELM_5; // Select SMCLK, ACLK source and DCO source
59 }