First Release Demo Application.

Dependencies:   MB85RSxx_SPI SDFileSystem mbed

Fork of SDFile_Logger by APS Lab

Files at this revision

API Documentation at this revision

Comitter:
APS_Lab
Date:
Fri Aug 25 03:06:41 2017 +0000
Parent:
2:39448ebc76ba
Commit message:
Flag Status??????

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 39448ebc76ba -r 5c6cef91faf0 main.cpp
--- a/main.cpp	Fri Aug 18 06:59:27 2017 +0000
+++ b/main.cpp	Fri Aug 25 03:06:41 2017 +0000
@@ -4,8 +4,9 @@
 #include "pinmap.h"
 
 // FRAM Address 
-#define FLAG_ADDR 0x0000
-#define SYNC_ADDR 0x0010
+#define POWR_FLAG_ADDR 0x0000
+#define SYNC_FLAG_ADDR 0x0008
+#define FILE_SYNC_ADDR 0x0010
 #define DATA_ADDR 0x0100
 
 // System Status Flag
@@ -35,7 +36,7 @@
 AnalogIn analog_value(A0); // Analog Input Port if use
 time_t seconds = time(NULL); // Time stamp if use
 
-int addr=FLAG_ADDR; // for FRAM Address Pointer
+int addr=POWR_FLAG_ADDR; // for FRAM POWR_FLAG_ADDR
 
 //Serial pc(USBTX, USBRX) 
 // Printf is output for COM port with 9600bps.
@@ -74,10 +75,10 @@
     //tmp+=fram_addr;              // Set Current FRAM Address Pointer 
     
     fram_set_addr(tmp);          // Fram Write Address Pointer Set
-    sys_set_status(SYNC_ADDR, FILE_PRE_WRITE);  // Flag Set for Pre write
+    sys_set_status(FILE_SYNC_ADDR, FILE_PRE_WRITE);  // Flag Set for Pre write
     fram.write(fram_get_addr(), buf, size);     // Save Data
     file->write(buf, size);                     // Write File
-    sys_set_status(SYNC_ADDR, FILE_POST_WRITE); // Flag Set for Post write
+    sys_set_status(FILE_SYNC_ADDR, FILE_POST_WRITE); // Flag Set for Post write
     fram_set_addr(tmp+size);     // Save Current FRAM Address Pointer
 }
     
@@ -89,10 +90,10 @@
     set_time(1498465898+32400);
     memset(buffer, 0, sizeof(buffer));
     
-    sys_set_status(FLAG_ADDR, SYNC_FAIL); // Set SYNC Flag as Fail
-    sys_set_status(FLAG_ADDR+8, SYNC_OK); // Set Acctual SYNC Flag as OK
+    sys_set_status(SYNC_FLAG_ADDR, SYNC_FAIL); // Set SYNC Flag as Fail
+    sys_set_status(SYNC_FLAG_ADDR+4, SYNC_OK); // Set Acctual SYNC Flag as OK
+    sys_set_status(FILE_SYNC_ADDR, FILE_OPEN);
     FileHandle* file = sd.open(filename, O_WRONLY | O_CREAT | O_TRUNC);
-    sys_set_status(SYNC_ADDR, FILE_OPEN);
     
     sprintf(buffer, "{\r\n\"adc log data\":[");
     
@@ -133,10 +134,10 @@
     sprintf(&buffer[0], "]}\n");
     sys_write(file, &buffer[0],2);
     
-    sys_set_status(SYNC_ADDR, FILE_CLOSE);
+    sys_set_status(FILE_SYNC_ADDR, FILE_CLOSE);
     file->close();
-    sys_set_status(SYNC_ADDR, FILE_SYNC);
-    sys_set_status(FLAG_ADDR, SYNC_OK); // Sync Flag Set as Good
+    sys_set_status(FILE_SYNC_ADDR, FILE_SYNC);
+    sys_set_status(SYNC_FLAG_ADDR, SYNC_OK); // Sync Flag Set as Good
 
 }
 
@@ -162,11 +163,11 @@
     //    fram.write(i, 0x00, 1);
     //}
     
-    sys_set_status(FLAG_ADDR+4, POWER_OK);  // Cu
+    sys_set_status(POWR_FLAG_ADDR+4, POWER_OK);  // Current Power Status
     //fram_set_powerflag(0);
     
     // Check FRAM Power Status
-    if(sys_get_status(FLAG_ADDR) == POWER_FAIL) {
+    if(sys_get_status(POWR_FLAG_ADDR) == POWER_FAIL) {
         printf("Power Down Occured!\n");
         
         // Power Down Recovery
@@ -178,7 +179,7 @@
         //fram_set_addr(0);
     }
     
-    sys_set_status(FLAG_ADDR, POWER_FAIL); //Set Flag as Power Fail
+    sys_set_status(POWR_FLAG_ADDR, POWER_FAIL); //Set Flag as Power Fail
     printf("Log Start!\n");
     while(f) {
         sprintf(fname, "d_log%03d.json", num);
@@ -197,6 +198,6 @@
         if(num > 32) f=0;
         else num++;
     }
+    sys_set_status(POWR_FLAG_ADDR, POWER_OK); //Set Flag as Power OK
     printf("Log Done!\n");
-    sys_set_status(FLAG_ADDR, POWER_OK); //Set Flag as Power OK
 }