CDMS_CODE_samp_23SEP_DMA_flag

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE_samp_23SEP_DMA by iitm sat

Revision:
257:7d404e9dc9e2
Parent:
52:0bd68655c651
Child:
259:066a7abd2a5f
--- a/Flash.h	Tue Jul 12 11:10:48 2016 +0000
+++ b/Flash.h	Tue Jul 12 17:07:17 2016 +0000
@@ -1,28 +1,83 @@
 #include "FreescaleIAP.h"
 
-int strt_add = flash_size() - (4*SECTOR_SIZE);  
-uint32_t flasharray[256+(3*1024)];
-char *nativeflash = (char*)strt_add;
+int strt_add = flash_size() - (2*SECTOR_SIZE);
+uint32_t flasharray[32];    //256+(3*1024)
+uint32_t INITIAL_FLASH[32];
+/*corrected*/
+int *nativeflash = (int*)strt_add;
+
+void FLASH_INI()
+{
+    uint32_t read[32]; 
+    for(int i=0;i<32;i++)
+        {  
+            read[i] = nativeflash[i];
+        }
+            
+    if(read[0] == -1)
+        for(int j=0;j<32;j++)
+            {   
+                FCTN_CDMS_WR_FLASH(j,INITIAL_FLASH[j]); 
+            } 
+    else
+       {
+        for(int j=0;j<32;j++)
+            {   
+                read[j] = nativeflash[j];
+            }
+            EPS_V_A_EN_STATUS = read[0] >> 31;
+            BAE_SW_STATUS   = (read[0] << 1) >> 30; 
+            CDMS_SD_SW_STATUS = (read[0] << 3) >> 30;
+            PL_BEE_SW_STATUS = (read[0] << 5) >> 30;
+            PL_EPS_LATCH_SW_EN = (read[0] << 7) >> 31;
+            RTC_INIT_STATUS = (read[0] << 8) >> 30;
+            CDMS_RTC_DISABLE = (read[0] << 10) >> 31;
+            CDMS_RESET_COUNTER = read[0];
+            TIME_LATEST_CDSMS_RESET = read[1];
+            COM_TC_BYTES_LIMIT = read[2] >> 16;
+            COM_RX_CURRENT_MAX = (read[2] << 16) >> 24;
+            COM_RX_DISABLE_TIMEOUT = read[2];
+            COM_PA_TMP_HIGH = read[3] >> 24;
+            COM_PA_RECOVERY_TIMEOUT = (read[3] << 8) >> 24;
+            COM_SESSION_TIMEOUT = (read[3] << 16) << 24;
+            COM_RSSI_MIN = read[3];
+            SD_LIB_BLK_CURRENT = read[4] >> 16;
+        }
+    
+}
 
 /*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 datablock)  //j-position to write address  ; fdata - flash data to be written
 {
-    for(int64_t i=0;i<(256+(3*1024));i++)
+    for(int i=0;i<5;i++)
     {
         flasharray[i]=nativeflash[i];
     }
-    flasharray[j]=block;
+    flasharray[j]=datablock;
     erase_sector(strt_add);
-    program_flash(strt_add, (char*)&flasharray,4*(256+(1024*3)));
+    program_flash(strt_add, (char*)flasharray,32);
 }
 /*End*/
 
-/*Reading from Flash*/
-uint32_t FCTN_CDMS_RD_FLASH(uint16_t j)
+/*===================================================MMS Functions=================================================*/
+
+void WRITE_TO_FLASH(uint8_t *);
+
+void WRITE_TO_FLASH(uint8_t *flash)
 {
-    for(int64_t i=0;i<(256+(3*1024));i++)
-    {
-        flasharray[i]=nativeflash[i];
-    }
-    return flasharray[j];
+    uint32_t FLASH[5];
+    FLASH[0] = ((uint32_t)flash[0] << 24) | ((uint32_t)flash[1] << 16) | ((uint32_t)flash[2] << 8) | ((uint32_t)flash[3]); 
+    FLASH[1] = ((uint32_t)flash[4] << 24) | ((uint32_t)flash[5] << 16) | ((uint32_t)flash[6] << 8) | ((uint32_t)flash[7]);
+    FLASH[2] = ((uint32_t)flash[8] << 24) | ((uint32_t)flash[9] << 16) | ((uint32_t)flash[10] << 8) | ((uint32_t)flash[11]);
+    FLASH[3] = ((uint32_t)flash[12] << 24) | ((uint32_t)flash[13] << 16) | ((uint32_t)flash[14] << 8) | ((uint32_t)flash[15]);
+    FLASH[4] = ((uint32_t)flash[16] << 24) | ((uint32_t)flash[17] << 16) | ((uint32_t)flash[18] << 8) | ((uint32_t)flash[19]);
+    erase_sector(strt_add);
+    program_flash(strt_add, (char*)FLASH,160);
+}
+
+void FCTN_CDMS_WR_S_FLASH(uint16_t , uint32_t);
+
+void FCTN_CDMS_WR_S_FLASH(uint16_t mid, uint32_t datavalue)
+{
+    
 }
\ No newline at end of file