green rosh / Mbed 2 deprecated RTOS_BAE_IITMSAT

Dependencies:   mbed-rtos mbed

Revision:
2:1792c9cda669
Parent:
1:5a364ac20fa4
Child:
3:307c56629df0
--- a/main.cpp	Thu Jun 26 05:16:58 2014 +0000
+++ b/main.cpp	Fri Jul 04 11:30:40 2014 +0000
@@ -1,6 +1,7 @@
-#include "mbed.h"
+
 #include "rtos.h"
-//#include "reset.cpp"
+#include "HK.h"
+#include "slave.h"
 
 Serial pc(USBTX,USBRX);
 Timer t;
@@ -9,6 +10,7 @@
 Thread *t_hk_acq;
 Thread *t_acs_write2flash;
 Thread *t_hk_write2cdms;
+Thread *t_fault;
 
 
 
@@ -119,19 +121,20 @@
 
 void T_ACS_MAIN(void const * args)
 {
+    FUNC_ACS_SENSORINIT();                                                                      //Initializing sensors
     while(1)
     {
         
         float m;
-        Thread::signal_wait(0x1);  // waiting for signal from main every ten seconds
+        Thread::signal_wait(0x1);                                                           // waiting for signal from scheduler every ten seconds
         printf("\nACS   :%fn",t.read());
-        printf("\nACS thread spriority is %d\n",t_acs->get_priority());
-        printf("\nBeacon thread priority  :%d\n",t_bea->get_priority());
-        printf("\nACS_WRITE2FLASH thread priority is %d\n",t_acs_write2flash->get_priority());
-        printf("\nHK_ACQ thread priority is %d\n",t_hk_acq->get_priority());
-        printf("\nHK_WRITE2CDMS thread priority is %d\n",t_hk_write2cdms->get_priority());
+        printf("\nACS thread state is %d\n",t_acs->get_state());
+        printf("\nBeacon thread state  :%d\n",t_bea->get_state());
+        printf("\nACS_WRITE2FLASH thread state is %d\n",t_acs_write2flash->get_state());
+        printf("\nHK_ACQ thread state is %d\n",t_hk_acq->get_state());
+        printf("\nHK_WRITE2CDMS thread state is %d\n",t_hk_write2cdms->get_state());
         
-        sens_data * s = q_sensor.alloc(); // please delete the  memory after it is used.
+        sens_data * s = q_sensor.alloc(); 
         
         FUNC_ACS_READDATA(s);
         q_sensor.put(s);
@@ -150,11 +153,11 @@
             osEvent evt=q_sensor.get();
             if(evt.status==osEventMail)
             {
-             printf("\nACS thread status is %d\n",t_acs->get_state());
-            printf("\nBeacon thread status  :%d\n",t_bea->get_state());
-            printf("\nACS_WRITE2FLASH thread status is %d\n",t_acs_write2flash->get_state());
-            printf("\nHK_ACQ thread status is %d\n",t_hk_acq->get_state());
-            printf("\nHK_WRITE2CDMS thread status is %d\n",t_hk_write2cdms->get_state());   
+                printf("\nACS thread status is %d\n",t_acs->get_state());
+                printf("\nBeacon thread status  :%d\n",t_bea->get_state());
+                printf("\nACS_WRITE2FLASH thread status is %d\n",t_acs_write2flash->get_state());
+                printf("\nHK_ACQ thread status is %d\n",t_hk_acq->get_state());
+                printf("\nHK_WRITE2CDMS thread status is %d\n",t_hk_write2cdms->get_state());   
                 sens_data *s1 =(sens_data *)evt.value.p;// please see
                 FUNC_ACS_WRITE2FLASH(s1);
                 
@@ -169,43 +172,19 @@
 
 //Functions for the thread T_HK_ACQ begins here
 //----------------------------------------------------------------------------------------------------------------------------------------------------
-void FUNC_HK_ACQ_STORE()
-{
-    /*
-        Code to be obtained from pranoy and bharath
-    */
-    
-    pc.printf("\nAcivating Mux\n");
-    pc.printf("\nActivating ADC\n");
-    pc.printf("\nWriting HK data to flash memory\n");
-}
+extern void FUNC_HK_MAIN();                                  // declared in HK.h
 
 //Functions of the thread T_HK_SEND2CDMS starts here.
 //----------------------------------------------------------------------------------------------------------------------------------------------------
 
+extern void FUNC_I2C_SLAVE_MAIN();
 
-void FUNC_HK_READFLASH()
-{
-    /*
-       Code to be given by Chaitanya and Vasanthi
-                                                    */
-    
-    pc.printf("\nReading HK data from flash memeory\n");
-}
-
-void FUNC_HK_SEND2CDMS()
-{
-     /*
-       Code to be given by Chaitanya and Vasanthi
-                                                    */
-    
-    pc.printf("\nSending HK data to CDMS\n");
-}
 //----------------------------------------------------------------------------------------------------------------------------------------------------
 // Defintion of thread for sending data to CDMS
 //----------------------------------------------------------------------------------------------------------------------------------------------------
 void T_HK_SEND2CDMS(void const * args)
 {
+   
     while(1)
     {
         Thread::signal_wait(0x1);                                       // Waiting for signal from T_HK_ACQ
@@ -214,8 +193,7 @@
         printf("\nACS_WRITE2FLASH thread status is %d\n",t_acs_write2flash->get_state());
         printf("\nHK_ACQ thread status is %d\n",t_hk_acq->get_state());
         printf("\nHK_WRITE2CDMS thread status is %d\n",t_hk_write2cdms->get_state());
-        FUNC_HK_READFLASH();
-        FUNC_HK_SEND2CDMS();
+        FUNC_I2C_SLAVE_MAIN();
     }
 }
 
@@ -230,15 +208,15 @@
     while(1)
     {
     
-        Thread::signal_wait(0x1);                                   //Waiting for the signal from main every 20 seconds
+        Thread::signal_wait(0x1);                                   //Waiting for the signal from sceduler every 20 seconds
         printf("\n\nHK  :%f\n",t.read());
-        /*printf("\nACS thread status is %d\n",t_acs->get_state());
+        printf("\nACS thread status is %d\n",t_acs->get_state());
         printf("\nBeacon thread status  :%d\n",t_bea->get_state());
         printf("\nACS_WRITE2FLASH thread status is %d\n",t_acs_write2flash->get_state());
         printf("\nHK_ACQ thread status is %d\n",t_hk_acq->get_state());
-        printf("\nHK_WRITE2CDMS thread status is %d\n",t_hk_write2cdms->get_state());*/
+        printf("\nHK_WRITE2CDMS thread status is %d\n",t_hk_write2cdms->get_state());
         
-        FUNC_HK_ACQ_STORE();
+        FUNC_HK_MAIN();
         t_hk_write2cdms->signal_set(0x1);
         //Thread::wait(19925);
     }
@@ -246,17 +224,17 @@
 }
 
 /*--------------------------------------------------------------------------------------------------------------------------------------------------
- TASK 4 : BEACON
+ TASK 3 : BEACON
 -----------------------------------------------------------------------------------------------------------------------------------------------------*/
 
 
-void FUNC_BEA_READBAEFLASH()
+void FUNC_BEA_READBAERAM()
 {
     /*
       Code to be given by Nathaniel
                                         */
     
-    pc.printf("\nReading HK data from BAE flash\n");
+    pc.printf("\nReading HK data from BAE RAM\n");
 }
 
 void FUNC_BEA_WRITE2SPI()
@@ -271,10 +249,11 @@
 
 void T_BEA(void const * args)
 {
+    extern SensorData Sensor;                                                           //Defined in HK.h
     while(1)
     {
     
-        Thread::signal_wait(0x1);                                       //waiting for signal from main every 30 seconds.
+        Thread::signal_wait(0x1);                                       //waiting for signal from scheduler every 30 seconds.
         pc.printf("\nBEACON     :%f\n",t.read());
         printf("\nACS thread status is %d\n",t_acs->get_state());
         printf("\nBeacon thread status  :%d\n",t_bea->get_state());
@@ -285,7 +264,7 @@
         if(flag==0)
         {
                
-            FUNC_BEA_READBAEFLASH();
+            FUNC_BEA_READBAERAM();
             FUNC_BEA_WRITE2SPI();
            // Thread::wait(30000);
         }
@@ -315,20 +294,66 @@
 }
     
 
+//---------------------------------------------------------------------------------------------------------------------------------------------------
+//TASK 4 : FAULT MANAGEMENT
+//---------------------------------------------------------------------------------------------------------------------------------------------------
+//Dummy fault rectifier functions
+
+Mail<int,16> faults;
+
+void FUNC_FAULT_FUNCT1()
+{
+    pc.printf("\nFault 1 detected... \n");
+}
+
+void FUNC_FAULT_FUNCT2()
+{
+    pc.printf("\nFault 2 detected...\n");
+}
+
+void T_FAULT(void const *args)
+{
+    while(1)
+    {
+        osEvent evt = faults.get();
+        if(evt.status==osEventMail)
+        {
+            int *fault_id= (int *)evt.value.p;
+            switch(*fault_id)
+            {
+                case 1: FUNC_FAULT_FUNCT1();
+                        break;
+                case 2: FUNC_FAULT_FUNCT2();
+                        break;
+            }
+            faults.free(fault_id);
+        }
+    }
+}
+
+//----------------------------------------------------------------------------------------------------------------------------------------------
+//Scheduler
+//----------------------------------------------------------------------------------------------------------------------------------------------
 int schedcount=1;   
 void scheduler(void const * args)
 {
+    if(schedcount == 7)
+    {
+        int * fault_id = faults.alloc();
+        *fault_id = 1;
+        faults.put(fault_id);
+    }
     t_acs->signal_set(0x1);
     
     if(schedcount%2==0)
        {
-            pc.printf("\nHK signal at %f",t.read());
+            //pc.printf("\nHK signal at %f",t.read());
             t_hk_acq->signal_set(0x1);
             
        } 
     if(schedcount%3==0)
         {
-            pc.printf("\nBeacon signal at %f",t.read());
+            //pc.printf("\nBeacon signal at %f",t.read());
             t_bea->signal_set(0x1);
             
         }
@@ -342,23 +367,24 @@
 int main()
 {
         t.start();
-       // int i =0;
+       
         t_acs = new Thread(T_ACS_MAIN);
         t_bea = new Thread(T_BEA);
         t_hk_acq = new Thread(T_HK_ACQ);
         t_acs_write2flash = new Thread(T_ACS_WRITE2FLASH);
         Thread key(keypress);
-       // Thread scd(scheduler);
-          t_hk_write2cdms = new Thread(T_HK_SEND2CDMS);           
+        t_fault = new Thread(T_FAULT); 
+        t_hk_write2cdms = new Thread(T_HK_SEND2CDMS);           
   
-        t_acs->set_priority(osPriorityLow);
+        t_fault->set_priority(osPriorityRealtime);
+        t_acs->set_priority(osPriorityHigh);
         t_bea->set_priority(osPriorityAboveNormal);
         t_hk_acq->set_priority(osPriorityNormal);
         t_acs_write2flash->set_priority(osPriorityBelowNormal);
-        //t_hk_write2cdms->set_priority(osPriorityLow);
+        
         key.set_priority(osPriorityIdle);
         
-        
+                
         /*RtosTimer t_hk_timer(T_HK_ACQ,osTimerPeriodic);
         RtosTimer t_bea_timer(T_BEA,osTimerPeriodic);
         RtosTimer t_acs_timer(T_ACS_MAIN,osTimerPeriodic);
@@ -371,6 +397,9 @@
         schedule.start(10000);
         t_hk_write2cdms->set_priority(osPriorityLow);
         pc.printf("\n T_HK_SEND2CDMS priority is %d",t_hk_write2cdms->get_priority());
+        pc.printf("\n T_ACS priority is %d",t_acs->get_priority());
+        pc.printf("\n T_FAULTS priority is %d",t_fault->get_priority());
+        
         while(1)
         {
             /*if(i%10==0)
@@ -385,8 +414,7 @@
             
             i++;*/
             Thread::wait(1000);
-            pc.printf("\n T_ACS_ACQ priority is %d",t_acs->get_priority());
-
-            pc.printf("\n%f\n",t.read());
+           
+           // pc.printf("\n%f\n",t.read());
         }
 }
\ No newline at end of file