CLEON  Version 1
Cloud-Offloaded GPS Receiver
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
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
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
43 
44 
45 /*----------------------------------------------------------------------------*/
53 void HAL_GPIO_Init(void)
54 {
55  // User swtich
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:
87  // This flag is set only when time has been synchronized
89 #if TIME_MEASUREMENT == _ENABLE_
90  // Logging current system time tick
92  stTimeMeasurement[ulNumberOfCLEONSamplesInAFileCount].ullTimeAtUserButtonPressed = uniSecondTimeTick.ullSecondTimeTick + uniMillisecondTimeTick.ullMillisecondTimeTick;
93  }
94 #endif
95  if(ulSampleCount == 1){
97  __low_power_mode_off_on_exit();
98  }
99  }
100  }
101  break;
102  case 4: break;
103  case 6:
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
126  // Turn LED1 off if Micro SD is inserted
128  // Change interrupt edge to low-to-high
130  }else{
131  // Micro SD is missing
133  // Disable logging
135  // Set number of seconds counter to zero
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
147  // Turn LED1 on if Micro SD is not inserted
149  // Change interrupt edge to high-to-low
151  }
152  break;
153  case 8:
155  // USB is connected
157  // Change interrupt edge to low-to-high
159  // Exit low power mode
160  __low_power_mode_off_on_exit();
161  }else{
162  // USB is disconnected
164  // Change interrupt edge to high-to-low
166  }
167  break;
168  case 10: break;
169  case 12: break;
170  case 14: break;
171  case 16: break;
172  default: break;
173  }
174 }