CLEON
Version 1
Cloud-Offloaded GPS Receiver
Main Page
Related Pages
Data Structures
Files
File List
Globals
hal_gpio.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
extern
char
sFilename
[50];
17
18
// Flags
19
extern
bool
bFLAG_CLEONSampleIntervalConuter
;
20
extern
bool
bFLAG_MicroSDInserted
;
21
extern
bool
bFLAG_USBConnected
;
22
extern
bool
bFLAG_ISLoggingRequested
;
23
extern
bool
bFLAG_IsTimeSynced
;;
24
25
// Second and millisecond time tick
26
extern
milliseoncd_time_tick_u
uniMillisecondTimeTick
;
27
extern
seoncd_time_tick_u
uniSecondTimeTick
;
28
29
// User parameters
30
extern
unsigned
long
ulSampleCount
;
31
extern
unsigned
long
ulSampleGap
;
32
extern
unsigned
long
ulChunkCount
;
33
extern
unsigned
long
ulChunkGap
;
34
35
// Counting number of seconds
36
extern
unsigned
char
ucRTCNumberOfSecondCounter
;
37
38
// Counting number of samples stored in a file
39
extern
unsigned
long
ulNumberOfCLEONSamplesInAFileCount
;
40
41
// Measuring time taken by each step of CLEON data logging
42
extern
time_measurement_s
stTimeMeasurement
[
NUMBER_OF_TIME_MEASUREMENT_TEST
];
43
44
45
/*----------------------------------------------------------------------------*/
53
void
HAL_GPIO_Init
(
void
)
54
{
55
// User swtich
56
USER_SW_PORT
(
DIR
) &= ~
BV
(
USER_SW_PIN
);
57
USER_SW_PORT
(IES) |=
BV
(
USER_SW_PIN
);
58
USER_SW_PORT
(IE) |=
BV
(
USER_SW_PIN
);
59
60
// LEDs
61
LED1_PORT
(OUT) |=
BV
(
LED1_PIN
);
62
LED1_PORT
(
DIR
) |=
BV
(
LED1_PIN
);
63
LED2_PORT
(OUT) |=
BV
(
LED2_PIN
);
64
LED2_PORT
(
DIR
) |=
BV
(
LED2_PIN
);
65
LED3_PORT
(OUT) |=
BV
(
LED3_PIN
);
66
LED3_PORT
(
DIR
) |=
BV
(
LED3_PIN
);
67
LED4_PORT
(OUT) |=
BV
(
LED4_PIN
);
68
LED4_PORT
(
DIR
) |=
BV
(
LED4_PIN
);
69
LED5_PORT
(OUT) |=
BV
(
LED5_PIN
);
70
LED5_PORT
(
DIR
) |=
BV
(
LED5_PIN
);
71
LED6_PORT
(OUT) |=
BV
(
LED6_PIN
);
72
LED6_PORT
(
DIR
) |=
BV
(
LED6_PIN
);
73
}
74
75
//------------------------------------------------------------------------------
76
// PORT1 Interrupt Service Routine
77
//------------------------------------------------------------------------------
78
#pragma vector=PORT1_VECTOR
79
__interrupt
void
PORT1_VECTOR_ISR
(
void
)
80
{
81
switch
(__even_in_range(P1IV,16))
82
{
83
case
0:
break
;
84
case
2:
85
if
(
bFLAG_IsTimeSynced
==
_SET_
){
86
if
(
bFLAG_ISLoggingRequested
==
_CLEAR_
){
87
// This flag is set only when time has been synchronized
88
bFLAG_ISLoggingRequested
=
_SET_
;
89
#if TIME_MEASUREMENT == _ENABLE_
90
// Logging current system time tick
91
if
(
ulNumberOfCLEONSamplesInAFileCount
<
NUMBER_OF_TIME_MEASUREMENT_TEST
){
92
stTimeMeasurement[
ulNumberOfCLEONSamplesInAFileCount
].
ullTimeAtUserButtonPressed
= uniSecondTimeTick.
ullSecondTimeTick
+ uniMillisecondTimeTick.
ullMillisecondTimeTick
;
93
}
94
#endif
95
if
(
ulSampleCount
== 1){
96
bFLAG_CLEONSampleIntervalConuter
=
_SET_
;
97
__low_power_mode_off_on_exit();
98
}
99
}
100
}
101
break
;
102
case
4:
break
;
103
case
6:
104
if
(
SYS_MMC_IsMicroSDInserted
() ==
_TRUE_
){
105
// Mount FatFs moudle
106
FS_Mount
(0, &Fatfs);
107
// Create directory
108
FS_MakeDir
(
"CLEON"
);
109
// Change directory
110
FS_ChangeDir
(
"/CLEON"
);
111
112
if
(
ulSampleCount
== 1){
113
// Initailize filename
114
memset(
sFilename
, 0,
sizeof
(
sFilename
));
115
// File name will start with CLEON's current system time
116
#if (APP_LOG_TEMP_AND_HUM_SENSORS == _ENABLE_) || (APP_LOG_LIGHT_SENSORS == _ENABLE_)
117
sprintf(
sFilename
,
"%lld_s16368_if4092000_m2_i2_s8.bin"
, uniSecondTimeTick.
ullSecondTimeTick
+ uniMillisecondTimeTick.
ullMillisecondTimeTick
);
118
#else
119
sprintf(
sFilename
,
"%lld_s16368_if4092000_m2_i2_s0.bin"
, uniSecondTimeTick.
ullSecondTimeTick
+ uniMillisecondTimeTick.
ullMillisecondTimeTick
);
120
#endif
121
// The created file will remain openned until the number of samples defined in 'APP_LOG_SAMPLES_IN_A_FILE' are captured
122
FS_Open
(&fileObject,
sFilename
,
FA_WRITE
|
FA_CREATE_ALWAYS
);
123
}
124
// Micro SD is inserted
125
bFLAG_MicroSDInserted
=
_SET_
;
126
// Turn LED1 off if Micro SD is inserted
127
MICRO_SD_ERROR_LED_OFF
();
128
// Change interrupt edge to low-to-high
129
MICROSD_STATUS_PORT
(IES) &= ~
BV
(
MICROSD_STATUS_PIN
);
130
}
else
{
131
// Micro SD is missing
132
bFLAG_MicroSDInserted
=
_CLEAR_
;
133
// Disable logging
134
bFLAG_ISLoggingRequested
=
_CLEAR_
;
135
// Set number of seconds counter to zero
136
ucRTCNumberOfSecondCounter
= 0;
137
// Move pointer to the end of file to append
138
FS_Lseek
(&fileObject,
FS_GetSizeOfFile
(&fileObject));
139
// Flush cached information of a writing file
140
FS_Sync
(&fileObject);
141
// Close file
142
FS_Close
(&fileObject);
143
// Unmount file system
144
FS_Mount
(0, NULL);
145
// Set counter value to zero to start over the logging process
146
ulNumberOfCLEONSamplesInAFileCount
= 0;
147
// Turn LED1 on if Micro SD is not inserted
148
MICRO_SD_ERROR_LED_ON
();
149
// Change interrupt edge to high-to-low
150
MICROSD_STATUS_PORT
(IES) |=
BV
(
MICROSD_STATUS_PIN
);
151
}
152
break
;
153
case
8:
154
if
(
SYS_USB_IsUSBConnected
() ==
_TRUE_
){
155
// USB is connected
156
bFLAG_USBConnected
=
_SET_
;
157
// Change interrupt edge to low-to-high
158
USB_STATUS_PORT
(IES) |=
BV
(
USB_STATUS_PIN
);
159
// Exit low power mode
160
__low_power_mode_off_on_exit();
161
}
else
{
162
// USB is disconnected
163
bFLAG_USBConnected
=
_CLEAR_
;
164
// Change interrupt edge to high-to-low
165
USB_STATUS_PORT
(IES) &= ~
BV
(
USB_STATUS_PIN
);
166
}
167
break
;
168
case
10:
break
;
169
case
12:
break
;
170
case
14:
break
;
171
case
16:
break
;
172
default
:
break
;
173
}
174
}
hal
hal_gpio.c
Generated on Tue May 28 2013 15:17:19 for CLEON by
1.8.2