publishing to check changes in cdms code

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE_samp_23SEP_DMA_flag by samp Srinivasan

Revision:
206:fba4aeebf004
Parent:
187:2c7263530c57
Child:
207:28a07943dded
diff -r 5f75962ae7ea -r fba4aeebf004 CDMS_HK.h
--- a/CDMS_HK.h	Wed Jun 29 14:17:34 2016 +0000
+++ b/CDMS_HK.h	Thu Jun 30 14:00:33 2016 +0000
@@ -3,6 +3,7 @@
 #include "reset_functions.h"
 #include "DefinitionsAndGlobals.h"
 #include "COM_SND_TM_functions.h"
+#include "COM_SND_TM_functions.h"
 
 void FCTN_CDMS_HK_MAIN();
 void FCTN_CDMS_HK();
@@ -49,6 +50,18 @@
 
 void FCTN_CDMS_HK_MAIN(void const *args)
 {
+
+  uint8_t CDMS_HEALTH_DATA[128] = {0};
+  unsigned char CDMS_HK_FRAME[134] = {0};
+  char BAE_HK[128] = {0};
+  uint8_t convoluted_CDMS_HK[270];
+  uint8_t interleave_CDMS_HK[288];
+  uint8_t CDMS_HEALTH_FINAL[512] = {0};
+  uint8_t convoluted_BAE_HK[270];
+  uint8_t interleave_BAE_HK[288];
+  uint8_t BAE_HEALTH_FINAL[512] = {0};
+  unsigned char BAE_HK_FRAME[134] = {0};
+
   CDMS_HK_MAIN_STATUS = 0x01;
   CDMS_HK_MAIN_COUNTER++;
 
@@ -58,7 +71,6 @@
   VERIFY_RTC();
   HANDLE_HW_FAULTS();
   FUNC_CDMS_GPIO_STATUS(); //yet to be done
-  COLLECT_CDMS_RAM();
 
   uint8_t CDMS_quant[19];
   for(int i=0;i<16;i++)
@@ -68,40 +80,79 @@
   CDMS_quant[16]= (uint8_t)RSSI_volatge;
   CDMS_quant[17]= (uint8_t)quant_data.CDMS_temp_quant;
   
-
-  char BAE_HK[74];
-  BAE_HK_I2C = FCTN_I2C_READ(BAE_HK,74);
-  if(BAE_HK_I2C == 0)
-    hk_cdms.printf("Bae hk data received");
-  else
-  {
-    hk_cdms.printf("Bae hk data NOT received");
-    for(int i = 0;i<74;i++)
-    BAE_HK = 0;
-  }
   
-  for(int i=0;i<512;i++)
-  {
-      CDMS_HEALTH_DATA[i]=0x00;
-  }
-  
-  uint64_t time = FCTN_CDMS_RD_RTC();
+  uint64_t time = FCTN_CDMS_RD_RTC();             //Reading Time from RTC 
   time = time>>7;
   uint32_t HK_time = (uint32_t)time;
   for(int i = 0;i<4;i++)
   CDMS_HEALTH_DATA[i] = HK_time[i];
+
   // Here: Have to FIT flash data.
-  for(int i = 0;i<19;i++)
-  CDMS_HEALTH_DATA[i+24] = CDMS_quant[i];
+  for(int i = 0;i<19;i++)                         //Collecting Data from Temp sensors
+    CDMS_HEALTH_DATA[i+24] = CDMS_quant[i];
+  
+  COLLECT_CDMS_RAM();                             //Reading RAM parameters
   
+  CDMS_HEALTH_DATA[126] = GPIO_STATUS;            //Reading GPIO Pins
+  CDMS_HEALTH_DATA[127] = GPIO_STATUS >> 8;
+ 
+  FCTN_SD_MNGR();                                 //Adding FSC & TMID to TM frame
+  CDMS_HK_FRAME[0] = 0x20;
+  CDMS_HK_FRAME[1] = FSC_CURRENT[4]+1;
+  CDMS_HK_FRAME[2] = (FSC_CURRENT[4]+1) >> 8;
+  CDMS_HK_FRAME[3] = (FSC_CURRENT[4]+1) >> 16;
+  
+  for(int i = 0;i<128;i++)                         /*Adding actual CDMS Health data to TM frame*/
+    CDMS_HK_FRAME[4+i] = CDMS_HEALTH_DATA[i];
   
-  for(int i=0;i<512;i++)
-  {
-      printf("%d",CDMS_HEALTH_DATA[i]);
+  uint16_t crc = crc16_gen(CDMS_HK_FRAME,132);      /*Adding CRC to TM frame*/
+  CDMS_HK_FRAME[133] = crc;
+  CDMS_HK_FRAME[132] = crc >> 8;
+
+  Convolution CDMS_HEALTH;
+  Convolution BAE_HEALTH;
+  CDMS_HEALTH.convolutionEncode(CDMS_HK_FRAME , convoluted_CDMS_HK);
+  CDMS_HEALTH.convolutionEncode(CDMS_HK_FRAME + 67, convoluted_CDMS_HK + 135);
+  interleave(convoluted_CDMS_HK ,  interleave_CDMS_HK);
+  interleave(convoluted_CDMS_HK +135, interleave_CDMS_HK + 144);
+  for(int i=0;i<288;i++)
+    CDMS_HEALTH_FINAL[i] = interleave_CDMS_HK[i];
+
+  SD_WRITE(CDMS_HEALTH_FINAL,FSC_CURRENT[4]+1,4);
+  hk_cdms.printf("CDMS hk succesfully completed\r\n");
+
+
+/*---------------------------------- BAE HK --------------------------------------------*/
+  
+  BAE_HK_I2C = FCTN_I2C_READ(BAE_HK,134);
+  if(BAE_HK_I2C == 0){
+    TIME_LATEST_I2C_SPEED = FCTN_CDMS_RD_RTC() >> 7;
+    hk_cdms.printf("Bae hk data received");
   }
-  CDMS_HK_FSC = FCTN_SD_MNGR(0x04);
-  BAE_HK_FSC = FCTN_SD_MNGR(0x05);
-  hk_cdms.printf("CDMS executed succesfully\r\n");
+  else
+  {
+    for(int i = 0;i<128;i++)
+      BAE_HK[i] = 0;
+  }
+  for(int i = 0;i<4;i++)
+  BAE_HK[i] = HK_time[i];
+  BAE_HK_FRAME[0] = 0x28;
+  BAE_HK_FRAME[1] = FSC_CURRENT[5]+1;
+  BAE_HK_FRAME[2] = (FSC_CURRENT[5]+1) >> 8;
+  BAE_HK_FRAME[3] = (FSC_CURRENT[5]+1) >> 16;
+  for(int i = 0;i<128;i++)                         /*Adding actual CDMS Health data to TM frame*/
+    BAE_HK_FRAME[4+i] = BAE_HK[i];
+  crc = crc16_gen(BAE_HK_FRAME,132);               /*Adding CRC to TM frame*/
+  BAE_HK_FRAME[133] = crc;
+  BAE_HK_FRAME[132] = crc >> 8;
+  BAE_HEALTH.convolutionEncode(BAE_HK_FRAME , convoluted_BAE_HK);
+  BAE_HEALTH.convolutionEncode(BAE_HK_FRAME + 67, convoluted_BAE_HK + 135);
+  interleave(convoluted_BAE_HK ,  interleave_BAE_HK);
+  interleave(convoluted_BAE_HK +135, interleave_BAE_HK + 144);
+  for(int i=0;i<288;i++)
+  BAE_HEALTH_FINAL[i] = interleave_BAE_HK[i];
+  SD_WRITE(BAE_HEALTH_FINAL,FSC_CURRENT[5]+1,5);
+  hk_cdms.printf("BAE hk succesfully completed\r\n");
 }
 
 int quantiz(float start,float step,float x)
@@ -305,11 +356,11 @@
   if(BAE_STATUS != DEVICE_DISABLED)
   {
     if(BAE_STATUS = DEVICE_OC_FAULT)
-        BAE_SW_EN_DS = 1; //Power ON BAE
+        BAE_SW_EN_DS = 0; //Power ON BAE
 
     if(BAE_OC_FAULT == 0)  // If OC Fault
     {
-      BAE_SW_EN_DS = 0; //Switch OFF BAE
+      BAE_SW_EN_DS = 1; //Switch OFF BAE
       BAE_FAULTCOUNT++;
       BAE_STATUS = (BAE_FAULTCOUNT == 3)?DEVICE_DISABLED:DEVICE_OC_FAULT;
     }
@@ -326,11 +377,11 @@
   if(PL_STATUS != DEVICE_DISABLED)
   {
     if(PL_STATUS = DEVICE_OC_FAULT)
-      PL_SW_EN_DS = 1; //Power ON PL
+      PL_SW_EN_DS = 0; //Power ON PL
 
-    if(PL_BEE_SW_OC_FAULT == 1)  // if OC Fault
+    if(PL_BEE_SW_OC_FAULT == 0)  // if OC Fault
     {
-      PL_SW_EN_DS = 0;  // switching OFF PL
+      PL_SW_EN_DS = 1;  // switching OFF PL
       PL_FAULTCOUNT++;
       PL_STATUS = (PL_FAULTCOUNT == 3)?DEVICE_DISABLED:DEVICE_OC_FAULT;
     }
@@ -347,61 +398,70 @@
 { 
   /*--------------------Current FSC's---------------------*/\
   for(int i=0;i<4;i++)
-    CDMS_HEALTH_DATA[i+43] = CURRENT_FSC_HK_ARCH_BAE >> (i*8);
+    CDMS_HEALTH_DATA[i+43] = FSC_LAST[5] >> (i*8);
+  for(int i=0;i<4;i++)
+    CDMS_HEALTH_DATA[i+47] = FSC_CURRENT[5] >> (i*8);
   for(int i=0;i<4;i++)
-    CDMS_HEALTH_DATA[i+47] = CURRENT_FSC_HK_ARCH_CDMS >> (i*8);
+    CDMS_HEALTH_DATA[i+51] = FSC_LAST[4] >> (i*8);
+  for(int i=0;i<4;i++)
+    CDMS_HEALTH_DATA[i+55] = FSC_CURRENT[4] >> (i*8);
+  for(int i=0;i<4;i++)
+    CDMS_HEALTH_DATA[i+59] = FSC_LAST[3] >> (i*8);
   for(int i=0;i<4;i++)
-    CDMS_HEALTH_DATA[i+51] = CURRENT_FSC_SFF_BT >> (i*8);
+    CDMS_HEALTH_DATA[i+63] = FSC_CURRENT[3] >> (i*8);
+  for(int i=0;i<4;i++)
+    CDMS_HEALTH_DATA[i+67] = FSC_LAST[2] >> (i*8);
   for(int i=0;i<4;i++)
-    CDMS_HEALTH_DATA[i+55] = CURRENT_FSC_SFF_AT >> (i*8);
+    CDMS_HEALTH_DATA[i+71] = FSC_CURRENT[2] >> (i*8);
   for(int i=0;i<4;i++)
-    CDMS_HEALTH_DATA[i+59] = CURRENT_FSC_SCF >> (i*8);
-
+    CDMS_HEALTH_DATA[i+75] = FSC_LAST[1] >> (i*8);
+  for(int i=0;i<4;i++)
+    CDMS_HEALTH_DATA[i+79] = FSC_CURRENT[1] >> (i*8);
   /*---------------------Latest Time----------------------*/
   for(int i=0;i<4;i++)
-    CDMS_HEALTH_DATA[i+63] = TIME_LATEST_SPI_SPEED >> (i*8);
+    CDMS_HEALTH_DATA[i+83] = TIME_LATEST_SPI_SPEED >> (i*8);
   for(int i=0;i<4;i++)
-    CDMS_HEALTH_DATA[i+67] = TIME_LATEST_SD_RD >> (i*8);
+    CDMS_HEALTH_DATA[i+87] = TIME_LATEST_SD_RD >> (i*8);
   for(int i=0;i<4;i++)
-    CDMS_HEALTH_DATA[i+71] = TIME_LATEST_SD_WR >> (i*8);
+    CDMS_HEALTH_DATA[i+91] = TIME_LATEST_SD_WR >> (i*8);
   for(int i=0;i<4;i++)
-    CDMS_HEALTH_DATA[i+75] = TIME_LATEST_I2C_SPEED >> (i*8);
+    CDMS_HEALTH_DATA[i+95] = TIME_LATEST_I2C_SPEED >> (i*8);
   for(int i=0;i<4;i++)
-    CDMS_HEALTH_DATA[i+79] = TIME_LATEST_I2C_BAE >> (i*8);
+    CDMS_HEALTH_DATA[i+99] = TIME_LATEST_I2C_BAE >> (i*8);
   for(int i=0;i<4;i++)
-    CDMS_HEALTH_DATA[i+83] = TIME_LATEST_RTC >> (i*8);
+    CDMS_HEALTH_DATA[i+103] = TIME_LATEST_RTC >> (i*8);
   for(int i=0;i<2;i++)
-    CDMS_HEALTH_DATA[i+87] = COMRX_RESET_COUNTER >> (i*8);
+    CDMS_HEALTH_DATA[i+107] = COMRX_RESET_COUNTER >> (i*8);
   for(int i=0;i<2;i++)
-    CDMS_HEALTH_DATA[i+89] = PL_RCV_SC_DATA_COUNTER >> (i*8);
+    CDMS_HEALTH_DATA[i+107] = PL_RCV_SC_DATA_COUNTER >> (i*8);
   for(int i=0;i<2;i++)
-    CDMS_HEALTH_DATA[i+91] = PL_MAIN_COUNTER >> (i*8);
+    CDMS_HEALTH_DATA[i+111] = PL_MAIN_COUNTER >> (i*8);
   for(int i=0;i<2;i++)
-    CDMS_HEALTH_DATA[i+93] = CDMS_HK_MAIN_COUNTER >> (i*8);
+    CDMS_HEALTH_DATA[i+113] = CDMS_HK_MAIN_COUNTER >> (i*8);
   for(int i=0;i<2;i++)
-    CDMS_HEALTH_DATA[i+95] = CDMS_I2C_ERR_BAE_COUNTER >> (i*8);
+    CDMS_HEALTH_DATA[i+115] = CDMS_I2C_ERR_BAE_COUNTER >> (i*8);
   for(int i=0;i<2;i++)
-    CDMS_HEALTH_DATA[i+97] = CDMS_I2C_ERR_SPEED_COUNTER >> (i*8);
-  CDMS_HEALTH_DATA[100] = CDMS_HEALTH_DATA[100] | CDMS_STANDBY_PL << 7;
-  CDMS_HEALTH_DATA[100] = CDMS_HEALTH_DATA[100] | ((CDMS_INIT_STATUS << 6) & 0x40);
-  CDMS_HEALTH_DATA[100] = CDMS_HEALTH_DATA[100] | ((CDMS_HK_MAIN_STATUS << 5) & 0x20);
-  CDMS_HEALTH_DATA[100] = CDMS_HEALTH_DATA[100] | ((CDMS_HK_STATUS << 3) & 0x18);
-  CDMS_HEALTH_DATA[100] = CDMS_HEALTH_DATA[100] | ((COMRX_STATUS << 2) & 0x04);
-  CDMS_HEALTH_DATA[100] = CDMS_HEALTH_DATA[100] | ((CDMS_RTC_BL << 1) & 0x02);
-  CDMS_HEALTH_DATA[100] = CDMS_HEALTH_DATA[100] & 0xFE;
+    CDMS_HEALTH_DATA[i+117] = CDMS_I2C_ERR_SPEED_COUNTER >> (i*8);
+  CDMS_HEALTH_DATA[120] = CDMS_HEALTH_DATA[120] | CDMS_STANDBY_PL << 7;
+  CDMS_HEALTH_DATA[120] = CDMS_HEALTH_DATA[120] | ((CDMS_INIT_STATUS << 6) & 0x40);
+  CDMS_HEALTH_DATA[120] = CDMS_HEALTH_DATA[120] | ((CDMS_HK_MAIN_STATUS << 5) & 0x20);
+  CDMS_HEALTH_DATA[120] = CDMS_HEALTH_DATA[120] | ((CDMS_HK_STATUS << 3) & 0x18);
+  CDMS_HEALTH_DATA[120] = CDMS_HEALTH_DATA[120] | ((COMRX_STATUS << 2) & 0x04);
+  CDMS_HEALTH_DATA[120] = CDMS_HEALTH_DATA[120] | ((CDMS_RTC_BL << 1) & 0x02);
+  CDMS_HEALTH_DATA[120] = CDMS_HEALTH_DATA[120] & 0xFE;
   
-  CDMS_HEALTH_DATA[101] = CDMS_HEALTH_DATA[101] | PL_RCV_SC_DATA_STATUS << 7;
-  CDMS_HEALTH_DATA[101] = CDMS_HEALTH_DATA[101] | ((COM_SESSION << 6) & 0x40);
-  CDMS_HEALTH_DATA[101] = CDMS_HEALTH_DATA[101] | ((COM_RX << 5) & 0x20);
-  CDMS_HEALTH_DATA[101] = CDMS_HEALTH_DATA[101] | ((RF_SW_STATUS << 4) & 0x10);
-  CDMS_HEALTH_DATA[101] = CDMS_HEALTH_DATA[101] | ((COM_TX << 3) & 0x08);
-  CDMS_HEALTH_DATA[101] = CDMS_HEALTH_DATA[101] | ((COM_TX_STATUS << 2) & 0x04);
-  CDMS_HEALTH_DATA[101] = CDMS_HEALTH_DATA[101] | ((COM_MNG_TMTC << 1) & 0x02);
-  CDMS_HEALTH_DATA[101] = CDMS_HEALTH_DATA[101] | (CDMS_STANDBY_HK & 0x01);
+  CDMS_HEALTH_DATA[121] = CDMS_HEALTH_DATA[121] | PL_RCV_SC_DATA_STATUS << 7;
+  CDMS_HEALTH_DATA[121] = CDMS_HEALTH_DATA[121] | ((COM_SESSION << 6) & 0x40);
+  CDMS_HEALTH_DATA[121] = CDMS_HEALTH_DATA[121] | ((COM_RX << 5) & 0x20);
+  CDMS_HEALTH_DATA[121] = CDMS_HEALTH_DATA[121] | ((RF_SW_STATUS << 4) & 0x10);
+  CDMS_HEALTH_DATA[121] = CDMS_HEALTH_DATA[121] | ((COM_TX << 3) & 0x08);
+  CDMS_HEALTH_DATA[121] = CDMS_HEALTH_DATA[121] | ((COM_TX_STATUS << 2) & 0x04);
+  CDMS_HEALTH_DATA[121] = CDMS_HEALTH_DATA[121] | ((COM_MNG_TMTC << 1) & 0x02);
+  CDMS_HEALTH_DATA[121] = CDMS_HEALTH_DATA[121] | (CDMS_STANDBY_HK & 0x01);
 
-  CDMS_HEALTH_DATA[102] = CDMS_HEALTH_DATA[102] | PL_INIT_STATUS << 7;
-  CDMS_HEALTH_DATA[102] = CDMS_HEALTH_DATA[102] | ((PL_MAIN_STATUS << 6) & 0x40);
-  CDMS_HEALTH_DATA[102] = CDMS_HEALTH_DATA[102] | ((PL_LOW_POWER << 5) & 0x20);
-  CDMS_HEALTH_DATA[102] = CDMS_HEALTH_DATA[102] | ((PL_STATE << 3) & 0x18);
-  CDMS_HEALTH_DATA[102] = CDMS_HEALTH_DATA[102] | (PL_STATUS & 0x07);
+  CDMS_HEALTH_DATA[122] = CDMS_HEALTH_DATA[122] | PL_INIT_STATUS << 7;
+  CDMS_HEALTH_DATA[122] = CDMS_HEALTH_DATA[122] | ((PL_MAIN_STATUS << 6) & 0x40);
+  CDMS_HEALTH_DATA[122] = CDMS_HEALTH_DATA[122] | ((PL_LOW_POWER << 5) & 0x20);
+  CDMS_HEALTH_DATA[122] = CDMS_HEALTH_DATA[122] | ((PL_STATE << 3) & 0x18);
+  CDMS_HEALTH_DATA[122] = CDMS_HEALTH_DATA[122] | (PL_STATUS & 0x07);
 }
\ No newline at end of file