Latest FM Code with EEPROM

Dependencies:   FreescaleIAP SimpleDMA eeprom mbed-rtos mbed

Fork of CDMS_QM_03MAR2017_Flash_with_obsrs by Team Fox

Revision:
356:4484bf39526f
Parent:
355:a5e72222ff26
--- a/main.cpp	Tue Mar 28 08:50:07 2017 +0000
+++ b/main.cpp	Sat Feb 24 10:28:56 2018 +0000
@@ -1,7 +1,7 @@
 // TESTING PUSH PULL IN MAIN CPP
 
 #include "mbed.h"
-//#include "eeprom.h"
+#include "eeprom.h"
 
 #define DEBUG 1
 
@@ -15,8 +15,7 @@
 #include "DefinitionsAndGlobals.h"
 #include "crc.h"
 #include "i2c.h"
-//#include "EEPROM.h"
-#include "Flash.h"
+#include "EEPROM.h"
 #include "COM_SND_TM_functions.h"
 #include "cdms_rtc.h"
 #include "COM_SND_TM.h"
@@ -47,7 +46,7 @@
     RF_SW_CNTRL_BCN = 0;
     PYLD_DFF = 1;
     
-    for(int i= 0; i< 10 ; i++)
+    for(int i= 0; i< 10 ; i++)                      //probably remove as PMS must turn on PYLD for FM
     {PYLD_DFF_CLK = !PYLD_DFF_CLK;
     wait_us(10);} 
     
@@ -61,16 +60,21 @@
     gRX_COUNT = 0;
     RX1M.attach(&rx_read, Serial::RxIrq);
     
-   gPC.baud(1200);//changed for bypassing COM
+    gPC.baud(1200);//changed for bypassing COM
    
     
     //Base_tm *tm_ptr = NULL;
     //SET_BCN_STANDBY(tm_ptr);
-    //gPC.puts("set Bcn off\r\n");
+    gPC.puts("set Bcn off\r\n");
     
     // COMMON SPI
     spi.format(8,0);
     spi.frequency(500000);
+   
+
+    if ((BAE_STATUS & 0x03) == 0x03)
+    {SW_OFF_BAE();}
+    uint8_t sd_stat_temp = SD_STATUS & 0x03;                        //Joel
     SD_CARD_fromuC_ENA3 = 0; 
     SD_CARD_fromISO_ENA4 = 0;
     SD_SW_EN_DS = 0; 
@@ -78,23 +82,41 @@
     SD_CARD_fromuC_ENA3 = 1; 
     SD_CARD_fromISO_ENA4 = 1;
     SD_SW_EN_DS = 1;
-    
+        
     wait(1);
     // SD CARD
     cs_sd = 1;
     gCS_RTC = 1;
     gCS_ADF = 1;
     
-  //  CDMS_RTC_DISABLE = 1;
+  
     
-    FCTN_CDMS_INIT_RTC();/* rtc initialization*/
+    CDMS_RTC_DISABLE = 1;
+    if((CDMS_RTC_DISABLE & 0x01) == 0)
+    {
+      EN_RTC = 0;
+    }
+    if((RTC_INIT_STATUS & 0x01) != 1)                  //Joel
+     {
+        FCTN_CDMS_INIT_RTC();/* rtc initialization*/
+     }
     FCTN_CDMS_SD_INIT();/* sd card initialization*/
-   // INIT_EEPROM(); // added by samp
+    INIT_EEPROM();
+    if(sd_stat_temp ==  DEVICE_DISABLED)
+    {
+        SD_STATUS = sd_stat_temp;
+        SD_SW_EN_DS = 0;
+    }
+    else if(sd_stat_temp == DEVICE_OC_FAULT)
+    {
+        SD_STATUS = sd_stat_temp;
+    }
 
-    CDMS_RESET_COUNTER++;
-    FCTN_CDMS_WR_FLASH(17,CDMS_RESET_COUNTER);
+    CDMS_RESET_COUNTER+=1;
+    WRITE_TO_EEPROM(7,CDMS_RESET_COUNTER);
+    gPC.printf("\n\r%d\n",CDMS_RESET_COUNTER);
     TIME_LATEST_CDSMS_RESET = FCTN_CDMS_RD_RTC() >> 7;
-    FCTN_CDMS_WR_FLASH(8,TIME_LATEST_CDSMS_RESET);
+    WRITE_TO_EEPROM(8,TIME_LATEST_CDSMS_RESET);
     
    // gPC.printf("%d \n", READ_FROM_EERPOM(8));
     uint8_t test[512];
@@ -102,8 +124,9 @@
     for(int i =0; i<512; i++)
         test[i] = 0;
     disk_write(test,80000);
-   
-    //SD_MNG_SECT = SD_LIB_BLK_CURRENT;
+
+    SD_MNG_SECT = SD_LIB_BLK_CURRENT;
+
     FCTN_SD_MNGR();
 
     #if DEBUG