CLEON  Version 1
Cloud-Offloaded GPS Receiver
sys_mmc.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 // File system variables
14 extern FATFS Fatfs;
15 extern FIL fileObject;
16 
17 // Flags
19 
20 /*----------------------------------------------------------------------------*/
28 void SYS_MMC_Init(void)
29 {
31 
32  // Check if MicroSD is inserted
35 
36 #if SYS_MMC_LED_INDICATION_FOR_ERROR == _ENABLE_
38 #endif
39 
40  // Initializing file system
41  FS_Init();
42 
43  // Mount FatFs moudle
44  FS_Mount(0, &Fatfs);
45 
46  // Create directory named 'CLEON'
47  FS_MakeDir("CLEON");
48 
49  // Change directory to 'CLEON'
50  FS_ChangeDir("/CLEON");
51 
52  }else{
53 #if SYS_MMC_LED_INDICATION_FOR_ERROR == _ENABLE_
55 #endif
56  }
57 }
58 
59 /*----------------------------------------------------------------------------*/
67 void SYS_MMC_InitIO(void)
68 {
72 
75 
79 
82 
85 
89 }
90 
91 /*----------------------------------------------------------------------------*/
99 void SYS_MMC_FastMode(void)
100 {
101  UCB1CTL1 |= UCSWRST; // Put state machine in reset
102  UCB1BR0 = 2; // f_UCxCLK = 12MHz/2 = 6MHz
103  UCB1BR1 = 0;
104  UCB1CTL1 &= ~UCSWRST; // Release USCI state machine
105 }
106 
107 /*----------------------------------------------------------------------------*/
116 void SYS_MMC_ReadFrame(unsigned char* ptrucBuffer, unsigned int uiSize)
117 {
118  unsigned int uiGIE = __get_SR_register() & GIE; //Store current GIE state
119 
120  __disable_interrupt(); //Make this operation atomic
121 
122  UCB1IFG &= ~UCRXIFG; //Ensure RXIFG is clear
123 
124  //Clock the actual data transfer and receive the bytes
125  while (uiSize--){
126  while (!(UCB1IFG & UCTXIFG)) ; //Wait while not ready for TX
127  UCB1TXBUF = 0xff; //Write dummy byte
128  while (!(UCB1IFG & UCRXIFG)) ; //Wait for RX buffer (full)
129  *ptrucBuffer++ = UCB1RXBUF;
130  }
131 
132  __bis_SR_register(uiGIE); //Restore original GIE state
133 }
134 
135 /*----------------------------------------------------------------------------*/
144 void SYS_MMC_SendFrame(unsigned char* ptrucBuffer, unsigned int uiSize)
145 {
146  unsigned int uiGIE = __get_SR_register() & GIE; //Store current GIE state
147 
148  __disable_interrupt(); //Make this operation atomic
149 
150  //Clock the actual data transfer and send the bytes. Note that we
151  //intentionally not read out the receive buffer during frame transmission
152  //in order to optimize transfer speed, however we need to take care of the
153  //resulting overrun condition.
154  while (uiSize--){
155  while (!(UCB1IFG & UCTXIFG)) ; //Wait while not ready for TX
156  UCB1TXBUF = *ptrucBuffer++; //Write byte
157  }
158  while (UCB1STAT & UCBUSY) ; //Wait for all TX/RX to finish
159 
160  UCB1RXBUF; //Dummy read to empty RX buffer
161  //and clear any overrun conditions
162 
163  __bis_SR_register(uiGIE); //Restore original GIE state
164 }
165 
166 /*----------------------------------------------------------------------------*/
175 {
177 }
178 
179 /*----------------------------------------------------------------------------*/
188 {
190 }