CLEON
Version 1
Cloud-Offloaded GPS Receiver
Main Page
Related Pages
Data Structures
Files
File List
Globals
app_usb.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
// RTC time
14
extern
rtc_time_u
uniRTCTime
;
15
16
// Second and millisecond time tick
17
extern
milliseoncd_time_tick_u
uniMillisecondTimeTick
;
18
extern
seoncd_time_tick_u
uniSecondTimeTick
;
19
20
// USB reception frame
21
extern
usb_frame_u
uniUSBRecvFrame
;
22
23
// Counting number of samples stored in a file
24
extern
unsigned
long
ulNumberOfCLEONSamplesInAFileCount
;
25
26
// Flags
27
extern
bool
bFLAG_USBConnected
;
28
extern
bool
bFLAG_USBFrameReceived
;
29
extern
bool
bFLAG_IsTimeSynced
;
30
extern
bool
bFLAG_RTCTimeTickOfSecond
;
31
32
// File system variables
33
extern
FIL
fileObject
;
34
extern
UINT
bw
;
35
extern
char
sFilename
[50];
36
37
// User parameters
38
extern
unsigned
long
ulSampleCount
;
39
extern
unsigned
long
ulSampleGap
;
40
extern
unsigned
long
ulChunkCount
;
41
extern
unsigned
long
ulChunkGap
;
42
43
/*----------------------------------------------------------------------------*/
53
void
APP_USB_ProcessingRcvdFrame
()
54
{
56
// Check if USB frame has been received
57
if
(
bFLAG_USBFrameReceived
==
_SET_
){
58
bFLAG_USBFrameReceived
=
_CLEAR_
;
59
61
// Identify command contained in the USB frame
62
switch
(uniUSBRecvFrame.
stUSBFrame
.
ucCommand
){
63
65
case
USB_FRAME_COMMAND_CONNECT
:
66
// Transmit ACK
67
SYS_USB_SendACK
(uniUSBRecvFrame.
stUSBFrame
.
ucCommand
);
68
break
;
69
71
case
USB_FRAME_COMMAND_UPDATE_RTC_TIME
:
72
// Transmit ACK
73
SYS_USB_SendACK
(uniUSBRecvFrame.
stUSBFrame
.
ucCommand
);
74
HAL_SetRTCYear
((uniUSBRecvFrame.
ucSingleByte
[4] << 8) + uniUSBRecvFrame.
ucSingleByte
[5]);
75
HAL_SetRTCMon
(uniUSBRecvFrame.
ucSingleByte
[6]);
76
HAL_SetRTCDay
(uniUSBRecvFrame.
ucSingleByte
[7]);
77
HAL_SetRTCHour
(uniUSBRecvFrame.
ucSingleByte
[8]);
78
HAL_SetRTCMin
(uniUSBRecvFrame.
ucSingleByte
[9]);
79
HAL_SetRTCSec
(uniUSBRecvFrame.
ucSingleByte
[10]);
80
break
;
81
83
case
USB_FRAME_COMMAND_UPDATE_TIME_TICK
:
84
// Transmit ACK
85
SYS_USB_SendACK
(uniUSBRecvFrame.
stUSBFrame
.
ucCommand
);
86
uniSecondTimeTick.
ucSingleByte
[7] = uniUSBRecvFrame.
ucSingleByte
[11];
87
uniSecondTimeTick.
ucSingleByte
[6] = uniUSBRecvFrame.
ucSingleByte
[10];
88
uniSecondTimeTick.
ucSingleByte
[5] = uniUSBRecvFrame.
ucSingleByte
[9];
89
uniSecondTimeTick.
ucSingleByte
[4] = uniUSBRecvFrame.
ucSingleByte
[8];
90
uniSecondTimeTick.
ucSingleByte
[3] = uniUSBRecvFrame.
ucSingleByte
[7];
91
uniSecondTimeTick.
ucSingleByte
[2] = uniUSBRecvFrame.
ucSingleByte
[6];
92
uniSecondTimeTick.
ucSingleByte
[1] = uniUSBRecvFrame.
ucSingleByte
[5];
93
uniSecondTimeTick.
ucSingleByte
[0] = uniUSBRecvFrame.
ucSingleByte
[4];
94
95
// Wait until millisecond part becomes zero
96
while
(uniMillisecondTimeTick.
ullMillisecondTimeTick
!= 0);
97
// Read RTC time and save it to 'uniRTCTime'
98
HAL_RTC_ReadRTCTime
();
99
// Store 'uniRTCTime (8 bytes)' to the first entry of internal FLASH bank 3 (0x038000)
100
// This information will later be used to restore system time
101
HAL_FLASH_Write
(
sizeof
(uniRTCTime), (
unsigned
char
*)&uniRTCTime, (
unsigned
char
*)
MSP430_INTERNAL_FLASH_BANK3_ADDRESS
);
102
// Store 'uniSecondTimeTick (8bytes)' next to 'uniRTCTime' stored to internal FLASH bank 3 (0x038008)
103
// This information will later be used to restore system time
104
HAL_FLASH_Write
(
sizeof
(uniSecondTimeTick), (
unsigned
char
*)&uniSecondTimeTick, (
unsigned
char
*)(
MSP430_INTERNAL_FLASH_BANK3_ADDRESS
+
sizeof
(uniRTCTime)));
105
106
if
(
SYS_MMC_IsMicroSDInserted
() ==
_TRUE_
){
107
if
(
ulNumberOfCLEONSamplesInAFileCount
== 0){
108
if
(
ulSampleCount
== 1){
109
// Initailize filename
110
memset(
sFilename
, 0,
sizeof
(
sFilename
));
111
// File name will start with CLEON's current system time
112
#if (APP_LOG_TEMP_AND_HUM_SENSORS == _ENABLE_) || (APP_LOG_LIGHT_SENSORS == _ENABLE_)
113
sprintf(
sFilename
,
"%lld_s16368_if4092000_m2_i2_s8.bin"
, uniSecondTimeTick.
ullSecondTimeTick
+ uniMillisecondTimeTick.
ullMillisecondTimeTick
);
114
#else
115
sprintf(
sFilename
,
"%lld_s16368_if4092000_m2_i2_s0.bin"
, uniSecondTimeTick.
ullSecondTimeTick
+ uniMillisecondTimeTick.
ullMillisecondTimeTick
);
116
#endif
117
// The created file will remain openned until the number of samples defined in 'APP_LOG_SAMPLES_IN_A_FILE' are captured
118
FS_Open
(&fileObject,
sFilename
,
FA_WRITE
|
FA_CREATE_ALWAYS
);
119
}
120
}
121
}
122
123
// Now that time is synchronized, set flag
124
bFLAG_IsTimeSynced
=
_SET_
;
125
126
// Turn LED3 off
127
TIME_SYNC_ERROR_LED_OFF
();
128
break
;
129
131
case
USB_FRAME_COMMAND_UPDATE_SAMPLE_COUNT
:
132
// Transmit ACK
133
SYS_USB_SendACK
(uniUSBRecvFrame.
stUSBFrame
.
ucCommand
);
134
ulSampleCount
= ((
unsigned
long)uniUSBRecvFrame.
stUSBFrame
.
ucData
[3] << 24)
135
+ ((
unsigned
long)uniUSBRecvFrame.
stUSBFrame
.
ucData
[2] << 16)
136
+ ((
unsigned
long)uniUSBRecvFrame.
stUSBFrame
.
ucData
[1] << 8)
137
+ ((
unsigned
long)uniUSBRecvFrame.
stUSBFrame
.
ucData
[0]);
138
break
;
139
141
case
USB_FRAME_COMMAND_UPDATE_SAMPLE_GAP
:
142
// Transmit ACK
143
SYS_USB_SendACK
(uniUSBRecvFrame.
stUSBFrame
.
ucCommand
);
144
ulSampleGap
= ((
unsigned
long)uniUSBRecvFrame.
stUSBFrame
.
ucData
[3] << 24)
145
+ ((
unsigned
long)uniUSBRecvFrame.
stUSBFrame
.
ucData
[2] << 16)
146
+ ((
unsigned
long)uniUSBRecvFrame.
stUSBFrame
.
ucData
[1] << 8)
147
+ ((
unsigned
long)uniUSBRecvFrame.
stUSBFrame
.
ucData
[0]);
148
break
;
149
151
case
USB_FRAME_COMMAND_UPDATE_CHUNK_COUNT
:
152
// Transmit ACK
153
SYS_USB_SendACK
(uniUSBRecvFrame.
stUSBFrame
.
ucCommand
);
154
ulChunkCount
= ((
unsigned
long)uniUSBRecvFrame.
stUSBFrame
.
ucData
[3] << 24)
155
+ ((
unsigned
long)uniUSBRecvFrame.
stUSBFrame
.
ucData
[2] << 16)
156
+ ((
unsigned
long)uniUSBRecvFrame.
stUSBFrame
.
ucData
[1] << 8)
157
+ ((
unsigned
long)uniUSBRecvFrame.
stUSBFrame
.
ucData
[0]);
158
break
;
159
161
case
USB_FRAME_COMMAND_UPDATE_CHUNK_GAP
:
162
// Transmit ACK
163
SYS_USB_SendACK
(uniUSBRecvFrame.
stUSBFrame
.
ucCommand
);
164
ulChunkGap
= ((
unsigned
long)uniUSBRecvFrame.
stUSBFrame
.
ucData
[3] << 24)
165
+ ((
unsigned
long)uniUSBRecvFrame.
stUSBFrame
.
ucData
[2] << 16)
166
+ ((
unsigned
long)uniUSBRecvFrame.
stUSBFrame
.
ucData
[1] << 8)
167
+ ((
unsigned
long)uniUSBRecvFrame.
stUSBFrame
.
ucData
[0]);
168
break
;
169
171
default
:
break
;
172
}
173
}
174
}
175
176
177
178
179
180
181
182
183
184
app
app_usb.c
Generated on Tue May 28 2013 15:17:19 for CLEON by
1.8.2