for frequency correction testing

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

Revision:
217:c63cdba0550f
Parent:
215:570251b23c7b
diff -r 93505a6f8db7 -r c63cdba0550f Flash.h
--- a/Flash.h	Sun Jul 03 11:35:55 2016 +0000
+++ b/Flash.h	Sun Jul 03 15:25:24 2016 +0000
@@ -1,91 +1,67 @@
 #include "FreescaleIAP.h"
 
-int strt_add = flash_size() - (4*SECTOR_SIZE);  
-uint32_t flasharray[256+(3*1024)];
+int strt_add = flash_size() - SECTOR_SIZE;    // Using the last sector of flash memory
 char *nativeflash = (char*)strt_add;
 
-/*Initiation of Flash*/
+void FCTN_CDMS_WR_FLASH(uint16_t ,uint32_t );
+uint32_t* FCTN_CDMS_RD_FLASH();
+uint32_t flasharray[5];
+
+uint32_t INITIAL_FLASH_VALUES[5] = {0};
+ 
 void FLASH_INIT()
 {
-    uint32_t read[8]; 
-    for(int i=0;i<8;i++)
+    uint32_t read[5]; 
+    for(int i=0;i<5;i++)
         {  
-            read[i] = FCTN_CDMS_RD_FLASH(i);
-            //printf("\n\r val is read after starting %x  ",read[i]);
+            read[i] = nativeflash[i];
         }
             
     if(read[0] == -1)
-        for(int j=0;j<8;j++)
+        for(int j=0;j<5;j++)
             {   
-                FCTN_CDMS_WR_FLASH(j,ARR_INITIAL_VAL[j]); 
+                FCTN_CDMS_WR_FLASH(j,INITIAL_FLASH_VALUES[j]); 
             } 
     else
        {
-        for(int j=0;j<8;j++)
-            {   
-                read[j] = FCTN_CDMS_RD_FLASH(j);
-            }
-        ACS_ATS_STATUS  = read[0]>>24;
-        ACS_TR_XY_SW_STATUS = ((uint8_t)(read[0]>>22))&0x03;
-        ACS_TR_Z_SW_STATUS = (read[0]>>20)&0x03;
-        ACS_DETUMBLING_ALGO_TYPE = (read[0]>>19)&0x01;
-        ACS_STATE = (read[0]>>16)&0x07;
-        BCN_TX_SW_STATUS = ((uint8_t)(read[0]>>14))&0x03;
-        BCN_SPND_TX = ((uint8_t)(read[0]>>13))&0x01;
-        BCN_FEN = ((uint8_t)(read[0]>>12))&0x01;
-        BCN_LONG_MSG_TYPE = ((uint8_t)(read[0]>>11))&0x01;
-        EPS_BTRY_HTR_AUTO = ((uint8_t)(read[0]>>10))&0x03;//EPS_BATTERY_HEATER_ENABLE
-        //now two spares in telemetry[5]
-        
-        //updating the reset counter
-        BAE_RESET_COUNTER = ((uint8_t)(read[0]))+1;
-        read[0]=(read[0]&0xffffff00) | (uint32_t)BAE_RESET_COUNTER;
-        FCTN_CDMS_WR_FLASH(0,read[0]);
-        
+        for(int j=0;j<5;j++)
+                read[j] = nativeflash[j];
                 
-        EPS_SOC_LEVEL_12 = (uint8_t)(read[1]>>24); 
-        EPS_SOC_LEVEL_23 = (uint8_t)(read[1]>>16);
-        ACS_MAG_TIME_DELAY = (uint8_t)(read[1]>>8);
-        ACS_DEMAG_TIME_DELAY = (uint8_t)read[1];
-                
-        EPS_BAT_TEMP_LOW = (uint8_t)(read[2]>>24);
-        EPS_BAT_TEMP_HIGH = (uint8_t)(read[2]>>16);
-        EPS_BAT_TEMP_DEFAULT = (uint8_t)(read[2]>>8);
-                                                                    
-        ACS_MM_X_COMSN = (uint16_t)(read[3]>>16);                                                                
-        ACS_MM_Y_COMSN = (uint16_t)read[3];
-                                                                    
-        ACS_MG_X_COMSN = (uint16_t)(read[4]>>16);
-        ACS_MG_Y_COMSN = (uint16_t)read[4];
-                                                                
-        ACS_MM_Z_COMSN = (uint16_t)(read[5]>>16);
-        ACS_MG_Z_COMSN = (uint16_t)read[5];
-                                                                    
-        ACS_Z_FIXED_MOMENT = (uint16_t)(read[6]>>16);//assignvalues 
-            
+            EPS_V_A_EN_STATUS       = read[0]&0x00000001;
+            BAE_SW_STATUS           = read[0]&0x00000006;
+            CDMS_SD_SW_STATUS       = read[0]&0x00000018;
+            PL_BEE_SW_STATUS        = read[0]&0x00000060;
+            PL_EPS_LATCH_SW_EN      = read[0]&0x00000080;
+            RTC_INIT_STATUS         = read[0]&0x00000300;
+            CDMS_RTC_DISABLE        = read[0]&0x00000400;
+            CDMS_RESET_COUNTER      = read[0]&0xFFFF0000;
+            TIME_LATEST_CDSMS_RESET = read[1]&0xFFFFFFFF;
+            COM_TC_BYTES_LIMIT      = read[2]&0x0000FFFF;
+            COM_RX_CURRENT_MAX      = read[2]&0x00FF0000;
+            COM_RX_DISABLE_TIMEOUT  = read[2]&0xFF000000;
+            COM_PA_TMP_HIGH         = read[3]&0x000000FF;
+            COM_PA_RECOVERY_TIMEOUT = read[3]&0x0000FF00;
+            COM_SESSION_TIMEOUT     = read[3]&0x00FF0000;
+            COM_RSSI_MIN            = read[3]&0xFF000000;
+            SD_LIB_BLK_CURRENT_NMBR = read[4]&0x0000FFFF;
         }
-    
 }
 
-
-/*Writing to the Flash*/
-void FCTN_CDMS_WR_FLASH(uint16_t j,uint32_t block)
+void FCTN_CDMS_WR_FLASH(uint16_t j,uint32_t data)      // Function to write into flash
 {
-    for(int64_t i=0;i<(256+(3*1024));i++)
+    for(int64_t i=0;i<5;i++)
     {
         flasharray[i]=nativeflash[i];
     }
-    flasharray[j]=block;
+    flasharray[j]=data;
     erase_sector(strt_add);
-    program_flash(strt_add, (char*)&flasharray,4*(256+(1024*3)));
+    program_flash(strt_add, (char*)flasharray,32);
 }
 
-/*Reading from Flash*/
-uint32_t FCTN_CDMS_RD_FLASH(uint16_t j)
+uint32_t* FCTN_CDMS_RD_FLASH()                 // Function to read from flash
 {
-    for(int64_t i=0;i<(256+(3*1024));i++)
-    {
+    for(int64_t i=0;i<5;i++)
         flasharray[i]=nativeflash[i];
-    }
-    return flasharray[j];
+        
+    return flasharray;
 }
\ No newline at end of file