vr1.1

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of CDMS_RTOS_v1_1 by Team Fox

Files at this revision

API Documentation at this revision

Comitter:
pradeepvk2208
Date:
Sat Jul 04 09:44:31 2015 +0000
Parent:
8:607ae92fa6af
Child:
10:2c8b9ebc79e9
Commit message:
PL added

Changed in this revision

Flags.h Show annotated file Show diff for this revision Revisions of this file
HK_MAIN.cpp Show annotated file Show diff for this revision Revisions of this file
HK_MAIN.h Show annotated file Show diff for this revision Revisions of this file
PL.cpp Show annotated file Show diff for this revision Revisions of this file
PL.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Flags.h	Sat Jul 04 08:56:34 2015 +0000
+++ b/Flags.h	Sat Jul 04 09:44:31 2015 +0000
@@ -2,5 +2,16 @@
 #define HK_INIT_STATUS 0X01
 #define HK_MAIN_STATUS 0X02
 #define HK_BAE_DISBLED 0X04
-#define HK_BAE_ERR-I2C 0X08
+#define HK_BAE_ERR_I2C 0X08
+/*End*/
+
+/*PL*/
+#define PL_MAIN_STATUS 0x00
+#define PL_LOW_POWER 0x01
+#define PL_OFF 0x02
+#define PL_ERR_I2C 0x04
+#define PL_STANDBY 0x08
+#define PL_HIBERNATE 0x10
+#define PL_SCIENCE 0x20
+#define PL_INVALID_STATE 0x40
 /*End*/
\ No newline at end of file
--- a/HK_MAIN.cpp	Sat Jul 04 08:56:34 2015 +0000
+++ b/HK_MAIN.cpp	Sat Jul 04 09:44:31 2015 +0000
@@ -8,7 +8,7 @@
 void FCTN_HK_MAIN()
 {
     hk_main.printf("\rin FCTN_CDMS_HK_MAIN()\r\n");
-    FCTN_MASTER_I2C('h' , i2c_data ); //BAE hk data is collected
+    FCTN_MASTER_I2C('h' , hk_i2c_data ); //BAE hk data is collected
     FCTN_CDMS_RD_RTC(rtc_data);  //RTC data is read to the rtc_data.
     for(int i=(hk_count%(HK_ITER+1))*(HK_DATA+8);i<(hk_count%(HK_ITER+1))*(HK_DATA+8)+8;i++)
     {
@@ -16,7 +16,7 @@
     }
     for(int i=(hk_count%(HK_ITER+1))*(HK_DATA+8)+8;i<(hk_count%(HK_ITER+1))*(HK_DATA+8)+8+HK_DATA;i++)
     {
-        hk_data[i] = i2c_data[i-(hk_count%(HK_ITER+1))*(HK_DATA+8)+8];
+        hk_data[i] = hk_i2c_data[i-(hk_count%(HK_ITER+1))*(HK_DATA+8)+8];
     }
     hk_count++;
     if(hk_count%HK_ITER==0)
--- a/HK_MAIN.h	Sat Jul 04 08:56:34 2015 +0000
+++ b/HK_MAIN.h	Sat Jul 04 09:44:31 2015 +0000
@@ -10,7 +10,7 @@
 /*End*/
 
 /*Declaring global variables*/
-char i2c_data[25];
+char hk_i2c_data[25];
 int hk_count = 0;
 uint8_t hk_data[512];
 uint8_t rtc_data[8];
--- a/PL.cpp	Sat Jul 04 08:56:34 2015 +0000
+++ b/PL.cpp	Sat Jul 04 09:44:31 2015 +0000
@@ -1,29 +1,305 @@
 #include "mbed.h"
 #include "PL.h"
 #include "all_funcs.h"
+#include "Flags.h"
 
 Serial sr(USBTX,USBRX);
 
-SPISlave pl_spi(PTE18, PTE19, PTE17, PTE16 ); // mosi, miso, sclk, ssel --> using SPI1
-//SPISlave pl_spi(PTD6, PTD7, PTD5, PTD4   ); // mosi, miso, sclk, ssel --> using SPI1
-int payloadBins = 4;
-
 void FCTN_PL_RCV_SC_DATA()
 {
-        sr.printf("in FCTN_PL_RCV_SC_DATA\r\n");
-        uint8_t scienceRawPacket[payloadBins];
-        for(int i=0; i<payloadBins;i++)
+    sr.printf("in FCTN_PL_RCV_SC_DATA\r\n");
+    uint8_t scienceRawPacket[payloadBins];
+    for(int i=0; i<payloadBins; i++) 
+    {
+        while(!pl_spi.receive()); // blocking statement --> waiting for data from Payload
+        uint8_t v = pl_spi.read();   // Read byte from master
+        scienceRawPacket[i] = v;
+    }
+    // serial feedback
+    sr.printf("Packet recieved\r\r\n");
+    for(int i=0; i<payloadBins; i++) 
+    {
+        sr.printf("%0x\t",scienceRawPacket[i]);
+        scienceRawPacket[i] = 0;
+    }
+    sr.printf("\r\r\n");
+}
+
+void FCTN_PL_MAIN()
+{
+    pl_main_flags|=PL_MAIN_STATUS;
+    pl_main_flags&=~(PL_LOW_POWER);
+    pl_prev_state=pl_state;
+    if(pl_schedule==1) 
+    {
+        pl_state=pl_schedule_TC;
+    } 
+    else 
+    {
+        if(pl_state==PL_SCIENCE) 
+        {
+            pl_state= PL_HIBERNATE;
+        } 
+        else 
+        {
+            pl_state=pl_prev_state;
+        }
+    }
+
+    switch(pl_state) 
+    {
+        case PL_OFF: 
         {
-            while(!pl_spi.receive()); // blocking statement --> waiting for data from Payload
-            uint8_t v = pl_spi.read();   // Read byte from master
-            scienceRawPacket[i] = v;
+            if(pl_prev_state!=PL_OFF) 
+            {
+                sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
+            }
+            sr.printf("Power off SPEED\r\n");
+            pl_status=PL_OFF;
+            sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
+            pl_main_flags&=~(PL_MAIN_STATUS);
+        }
+        case PL_STANDBY: 
+        {
+            if(power_level<0) 
+            {
+                pl_main_flags|=PL_LOW_POWER;
+                if(pl_prev_state!=PL_OFF) 
+                {
+                    sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
+                }
+                sr.printf("Power off SPEED\r\n");
+                pl_status=PL_OFF;
+                sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
+                pl_main_flags&=~(PL_MAIN_STATUS);
+            } 
+            else 
+            {
+                if(pl_prev_state!=PL_OFF) 
+                {
+                    sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
+                    sr.printf("Power OFF SPEED PMTs\r\n");
+                    if(I2C_acknowledgement==1) 
+                    {
+                        pl_status=PL_STANDBY;
+                    } 
+                    else 
+                    {
+                        pl_status=PL_ERR_I2C;
+                    }
+                    sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
+                    pl_main_flags&=~(PL_MAIN_STATUS);
+                } 
+                else 
+                {
+                    sr.printf("Power on SPPED DL\r\n");
+                    sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
+                    if(I2C_acknowledgement==1) 
+                    {
+                        pl_status=PL_STANDBY;
+                    } 
+                    else 
+                    {
+                        pl_status=PL_ERR_I2C;
+                    }
+                    sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
+                    pl_main_flags&=~(PL_MAIN_STATUS);
+                }
+            }
         }
-        // serial feedback
-        sr.printf("Packet recieved\r\r\n");
-        for(int i=0;i<payloadBins;i++)
+        case PL_HIBERNATE: 
+        {
+            if(power_level<1) 
+            {
+                pl_main_flags|=PL_LOW_POWER;
+                if(power_level<0) 
+                {
+                    pl_main_flags|=PL_LOW_POWER;
+                    if(pl_prev_state!=PL_OFF) 
+                    {
+                        sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
+                    }
+                    sr.printf("Power off SPEED\r\n");
+                    pl_status=PL_OFF;
+                    sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
+                    pl_main_flags&=~(PL_MAIN_STATUS);
+                } 
+                else 
+                {
+                    if(pl_prev_state!=PL_OFF) 
+                    {
+                        sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
+                        sr.printf("Power OFF SPEED PMTs\r\n");
+                        if(I2C_acknowledgement==1) 
+                        {
+                            pl_status=PL_STANDBY;
+                        } 
+                        else 
+                        {
+                            pl_status=PL_ERR_I2C;
+                        }
+                        sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
+                        pl_main_flags&=~(PL_MAIN_STATUS);
+                    } 
+                    else 
+                    {
+                        sr.printf("Power on SPPED DL\r\n");
+                        sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
+                        if(I2C_acknowledgement==1) {
+                            pl_status=PL_STANDBY;
+                        } 
+                        else 
+                        {
+                            pl_status=PL_ERR_I2C;
+                        }
+                        sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
+                        pl_main_flags&=~(PL_MAIN_STATUS);
+                    }
+                }
+            }
+            if(power_level>1) 
+            {
+                if(pl_prev_state==PL_OFF) 
+                {
+                    sr.printf("Power on SPEED DL\r\n");
+                }
+                sr.printf("Power on Speed PMT with reduced Voltage\r\n");
+                sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
+                if(I2C_acknowledgement==1) 
+                {
+                    pl_status=PL_HIBERNATE;
+                } 
+                else 
+                {
+                    pl_status=PL_ERR_I2C;
+                }
+                sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
+                pl_main_flags&=~(PL_MAIN_STATUS);
+            }
+        }
+
+        case PL_SCIENCE: 
         {
-            sr.printf("%0x\t",scienceRawPacket[i]);
-            scienceRawPacket[i] = 0;
+
+            if(power_level<2) 
+            {
+                if(power_level<1) 
+                {
+                    pl_main_flags|=PL_LOW_POWER;
+                    if(power_level<0) 
+                    {
+                        pl_main_flags|=PL_LOW_POWER;
+                        if(pl_prev_state!=PL_OFF) 
+                        {
+                            sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
+                        }
+                        sr.printf("Power off SPEED\r\n");
+                        pl_status=PL_OFF;
+                        sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
+                        pl_main_flags&=~(PL_MAIN_STATUS);
+                    } 
+                    else 
+                    {
+                        if(pl_prev_state!=PL_OFF) 
+                        {
+                            sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
+                            sr.printf("Power OFF SPEED PMTs\r\n");
+                            if(I2C_acknowledgement==1) 
+                            {
+                                pl_status=PL_STANDBY;
+                            } 
+                            else 
+                            {
+                                pl_status=PL_ERR_I2C;
+                            }
+                            sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
+                            pl_main_flags&=~(PL_MAIN_STATUS);
+                        } 
+                        else 
+                        {
+                            sr.printf("Power on SPPED DL\r\n");
+                            sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
+                            if(I2C_acknowledgement==1) 
+                            {
+                                pl_status=PL_STANDBY;
+                            } 
+                            else 
+                            {
+                                pl_status=PL_ERR_I2C;
+                            }
+                            sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
+                            pl_main_flags&=~(PL_MAIN_STATUS);
+                        }
+                    }
+                }
+                if(power_level>1) 
+                {
+                    if(pl_prev_state==PL_OFF) 
+                    {
+                        sr.printf("Power on SPEED DL\r\n");
+                    }
+                    sr.printf("Power on Speed PMT with reduced Voltage\r\n");
+                    sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
+                    if(I2C_acknowledgement==1) 
+                    {
+                        pl_status=PL_HIBERNATE;
+                    } 
+                    else 
+                    {
+                        pl_status=PL_ERR_I2C;
+                    }
+                    sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
+                    pl_main_flags&=~(PL_MAIN_STATUS);
+                }
+            }
+            if(power_level>2) 
+            {
+                if(pl_prev_state==PL_SCIENCE) 
+                {
+                    pl_status=PL_SCIENCE;
+                    pl_main_flags&=~(PL_MAIN_STATUS);
+                } 
+                else if(pl_prev_state==PL_HIBERNATE) 
+                {
+                    sr.printf("Power on SPEED PMT with high voltage \r\n");
+                    sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
+                    if(I2C_acknowledgement==1) 
+                    {
+                        sr.printf("Enable SRP_INTERVAL_COUNTER\r\n");
+                        pl_status=PL_SCIENCE;
+                        pl_main_flags&=~(PL_MAIN_STATUS);
+                    } 
+                    else 
+                    {
+                        pl_status=PL_ERR_I2C;
+                        sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
+                        pl_main_flags&=~(PL_MAIN_STATUS);
+                    }
+                } 
+                else
+
+                {
+                    if(pl_prev_state==PL_OFF) 
+                    {
+                        sr.printf("Power on SPEED DL\r\n");
+                    }
+                    sr.printf("Power on Speed PMT with reduced Voltage\r\n");
+                    sr.printf("Command SPEED DL to go to Standby State (I2C) \r\n");
+                    if(I2C_acknowledgement==1) 
+                    {
+                        pl_status=PL_HIBERNATE;
+                    } 
+                    else 
+                    {
+                        pl_status=PL_ERR_I2C;
+                    }
+                    sr.printf("Disable SRP_INTERVAL_COUNTER\r\n");
+                    pl_main_flags&=~(PL_MAIN_STATUS);
+                }
+            }
+
+
         }
-        sr.printf("\r\r\n");
+
+    }
 }
\ No newline at end of file
--- a/PL.h	Sat Jul 04 08:56:34 2015 +0000
+++ b/PL.h	Sat Jul 04 09:44:31 2015 +0000
@@ -0,0 +1,11 @@
+uint8_t pl_main_flags;
+uint8_t pl_state;
+uint8_t pl_prev_state;
+uint8_t pl_schedule_TC;
+uint8_t pl_status;
+bool pl_schedule;
+int8_t power_level;
+bool I2C_acknowledgement;
+
+SPISlave pl_spi(PTE18, PTE19, PTE17, PTE16 ); // mosi, miso, sclk, ssel --> using SPI1
+int payloadBins = 4;
\ No newline at end of file
--- a/main.cpp	Sat Jul 04 08:56:34 2015 +0000
+++ b/main.cpp	Sat Jul 04 09:44:31 2015 +0000
@@ -46,11 +46,11 @@
     sc_timer++;
     if(sc_timer%18==0)
     {
-        FCTN_CDMS_HK_MAIN;
+        FCTN_CDMS_HK_MAIN();
     }
     if(sc_timer%9==0)
     {
-        FCTN_PL_MAIN;
+        FCTN_PL_MAIN();
     }
 }
 /*End*/