Updated BAE RTOS

Dependencies:   mbed-rtos mbed

Fork of all_combined_week6 by Harshit Gupta

Revision:
7:b3f876f605d9
Parent:
6:82153349cc9b
--- a/main.cpp	Tue Jul 15 10:04:38 2014 +0000
+++ b/main.cpp	Fri Sep 19 05:12:40 2014 +0000
@@ -4,13 +4,13 @@
 #include "slave.h"
 #include "beacon.h"
 #include "ACS.h"
-//watda?
+
 Serial pc(USBTX, USBRX);
 
 
 
-Timer t;
-Timer t1;
+Timer t;                                                        //To know the time of entering each thread
+Timer t1;                                                       //To know the time of execution of each thread
 
 Thread *ptr_t_hk_acq;
 Thread *ptr_t_acs;
@@ -20,53 +20,15 @@
 Thread *ptr_t_fault;
 
 
-//----------------------------------------------HOUSE-KEEPING(HK)------------------------------------------------------------------------------------------
-//void func_hk_mux()
-//{
-//    pc.printf("Something related to mux\n");
-//}
-//
-//void func_hk_adc()
-//{
-//    pc.printf("Converting analog to digital\n");
-//}
-//
-//void func_hk_write2flash()
-//{
-//    pc.printf("Writing the house keeping data to flash\n");
-//}
-//
-//void func_hk_readram()
-//{
-//    pc.printf("Reading hk data from ram\n");
-//}
+//--------------------------------------------------------------------------------------------------------------------------------------------------
+//TASK 2 : HK
+//--------------------------------------------------------------------------------------------------------------------------------------------------
 
-//void func_hk_send2cdms()
-//{
-//    pc.printf("Send the data to sd card\n");
-//}
 
-void t_hk_send2cdms(void const *args)
-{
-    while(1)
-    {
-        t.start();
-        Thread::signal_wait(0x4);
-        printf("\nEntered t_hk_send2cdms\n");
-        /*printf("The state of hk_acq thread is %d\n",ptr_t_hk_acq->get_state());
-        printf("The state of acs_main thread is %d\n",ptr_t_acs->get_state());
-        printf("The state of acs_write2flash thread is %d\n",ptr_t_acs_write2flash->get_state());
-        printf("The state of beacon thread is %d\n",ptr_t_bea->get_state());*/
-             
-        //FUNC_I2C_SLAVE_MAIN(24);
-        printf("The time to execute send2cdms is %f\n",t.read());
-        t.reset();
-    }
-}
 
 void t_hk_acq(void const *args)
 {
-    Thread thread_2(t_hk_send2cdms);
+    
     while(1)
     {
         Thread::signal_wait(0x2);
@@ -74,13 +36,10 @@
         printf("\nTHIS IS HK    %f\n",t1.read());
         t.start();
         
-        FUNC_HK_MAIN();
+        FUNC_HK_MAIN();                                                             //Collecting HK data
         //thread_2.signal_set(0x4);
-        FUNC_I2C_SLAVE_MAIN(24);
-        /*printf("The state of hk_acq thread is %d\n",ptr_t_hk_acq->get_state());
-        printf("The state of acs_main thread is %d\n",ptr_t_acs->get_state());
-        printf("The state of acs_write2flash thread is %d\n",ptr_t_acs_write2flash->get_state());
-        printf("The state of beacon thread is %d\n",ptr_t_bea->get_state());*/
+        FUNC_I2C_SLAVE_MAIN(24);                                                    //Sending to CDMS via I2C
+        
         t.stop();
         printf("The time to execute hk_acq is %f seconds\n",t.read());
         t.reset();
@@ -88,7 +47,8 @@
 }
 
 //---------------------------------------------------------------------------------------------------------------------------------------
-
+//TASK 1 : ACS
+//---------------------------------------------------------------------------------------------------------------------------------------
 typedef struct {
     float mag_field;
     float omega;
@@ -108,10 +68,7 @@
     pc.printf("Executing control algo\n");
 }
 
-/*void func_acs_pwmgen()
-{
-    pc.printf("Generating PWM signal\n");
-}*/
+
 
 void func_acs_write2flash(sensor_data *ptr2)
 {
@@ -130,14 +87,9 @@
         func_acs_readdata(ptr);
         q_acs.put(ptr);
         func_acs_ctrlalgo();
-        FUNC_ACS_GENPWM();
+        FUNC_ACS_GENPWM();                                      //Generating PWM signal.
         
-        /*printf("The state of hk_acq thread is %d\n",ptr_t_hk_acq->get_state());
-        printf("The state of acs_main thread is %d\n",ptr_t_acs->get_state());
-        printf("The state of acs_write2flash thread is %d\n",ptr_t_acs_write2flash->get_state());
-        printf("The state of beacon thread is %d\n",ptr_t_bea->get_state());
-        printf("The time to execute t_acs is %f seconds\n",t.read());*/
-            //   Thread::wait(10000);
+       
         t.reset();
     }
 }
@@ -154,26 +106,16 @@
             func_acs_write2flash(ptr);
             q_acs.free(ptr);
         }
-        printf("Writing acsd data in the flash\n");
+        printf("Writing acs data in the flash\n");
     }
 }
 
+
 //---------------------------------------------------BEACON--------------------------------------------------------------------------------------------
 
-int beac_flag=0;
+int beac_flag=0;                                                            //To receive telecommand from ground.
 
-/*void func_bea_readbaeflash()
-{
-        pc.printf("Reading data from beacon flash\n");
-        wait(0.01);
-}
 
-void func_bea_spiwrite()
-{
-    pc.printf("Writing through SPI\n");
-    wait(0.01);
-}
-*/
 void t_bea_telecommand(void const *args)
 {
     char c = pc.getc();
@@ -192,18 +134,13 @@
         Thread::signal_wait(0x3);
         printf("\nTHIS IS BEACON    %f\n",t1.read());
         t.start();
-        /*printf("The state of hk_acq thread is %d\n",ptr_t_hk_acq->get_state());
-        printf("The state of acs_main thread is %d\n",ptr_t_acs->get_state());
-        printf("The state of acs_write2flash thread is %d\n",ptr_t_acs_write2flash->get_state());
-        printf("The state of beacon thread is %d\n",ptr_t_bea->get_state());*/
-        if(beac_flag==0)
-        {
-            //func_bea_readbaeflash();
-            //func_bea_spiwrite();
-            beacon_func();
-            //Thread::wait(30000);
-        }
-        else
+        
+        
+            
+        FUNC_BEA();
+            
+        
+        if(beac_flag==1)
         {
             Thread::wait(600000);
             beac_flag = 0;
@@ -274,7 +211,11 @@
     }
     if(schedcount%3==0)
     {
-        ptr_t_bea -> signal_set(0x3);
+        if(beac_flag==0)
+        {
+            
+            ptr_t_bea -> signal_set(0x3);
+        }
     }
     schedcount++;
 }
@@ -301,15 +242,8 @@
     ptr_t_bea_telecommand->set_priority(osPriorityIdle);
     //ptr_t_sc->set_priority(osPriorityAboveNormal);
     
-    /*RtosTimer for individual thread-------------------------------------------------------------------------------------------
-    RtosTimer t_hk_acq_timer(t_hk_acq, osTimerPeriodic);
-    RtosTimer t_acs_timer(t_acs, osTimerPeriodic);    
-    RtosTimer t_bea_timer(t_bea, osTimerPeriodic);
-    
-    t_hk_acq_timer.start(20000);
-    t_acs_timer.start(10000);
-    t_bea_timer.start(30000);
-    ----------------------------------------------------------------------------------------------*/    
+  
+   // ----------------------------------------------------------------------------------------------
     pc.printf("\n T_FAULT priority is %d",ptr_t_fault->get_priority()); 
     pc.printf("\n T_ACS priority is %d",ptr_t_acs->get_priority());
     pc.printf("\n T_HK_ACQ priority is %d",ptr_t_hk_acq->get_priority());