vr1.1

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of CDMS_RTOS_v1_1 by Team Fox

Revision:
9:7ff6d75cc09e
Parent:
8:607ae92fa6af
Child:
12:cb3ee1ac3638
--- 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