hahalvl1

Dependencies:   mbed-rtos mbed

Fork of BAE_b4hw_test by sakthi priya amirtharaj

Revision:
3:20647ff68b3c
Parent:
2:edd107ea4740
Child:
4:b33bc4267e0d
--- a/main.cpp	Fri Dec 26 06:12:09 2014 +0000
+++ b/main.cpp	Sat Jan 31 14:11:53 2015 +0000
@@ -17,7 +17,9 @@
 Timer t;                                                        //To know the time of execution each thread
 Timer t1;
                                                        //To know the time of entering  of each thread
-
+Timer t2;
+Timer t3;
+Timer t4;
 
 
 
@@ -70,7 +72,7 @@
     {
         Thread::signal_wait(0x2);
         SensorQuantised.power_mode='3';
-        printf("\nTHIS IS HK    %f\n",t1.read());
+        printf("\n\rTHIS IS HK    %f\n\r",t1.read());
         t.start();
         FUNC_HK_FAULTS();
         FUNC_HK_POWER(SensorQuantised.power_mode);                                                   //The power mode algorithm is yet to be obtained
@@ -79,7 +81,7 @@
         //FUNC_I2C_SLAVE_MAIN(25);    
         FUNC_I2C_IR2CDMS();
         t.stop();
-        printf("The time to execute hk_acq is %f seconds\n",t.read());
+        printf("The time to execute hk_acq is %f seconds\n\r",t.read());
         t.reset();
     }
 }
@@ -97,11 +99,11 @@
     while(1)
     {
         Thread::signal_wait(0x1);
-        printf("\nTHIS IS ACS   %f\n",t1.read());
+        printf("\n\rTHIS IS ACS   %f\n\r",t1.read());
         t.start();
         mag_field= FUNC_ACS_MAG_EXEC();                              //actual execution
         omega = FUNC_ACS_EXEC_GYR();
-        printf("\n gyr 1 value %f",omega[0]);
+        printf("\n\r gyr 1 value %f",omega[0]);
         
         
         if(acs_pflag == 1)
@@ -118,7 +120,7 @@
 {
     while(1)
     {
-        //printf("Writing in the flash\n");
+        //printf("Writing in the flash\n\r");
         osEvent evt = q_acs.get();
         if(evt.status == osEventMail)
         {
@@ -126,7 +128,7 @@
             FUNC_ACS_WRITE2FLASH(ptr);
             q_acs.free(ptr);
         }
-        printf("Writing acs data in the flash\n");
+        printf("Writing acs data in the flash\n\r");
     }
 }
 
@@ -141,7 +143,7 @@
     char c = pc.getc();
     if(c=='a')
     {
-        printf("Telecommand detected\n");
+        printf("Telecommand detected\n\r");
         beac_flag=1;
     }
 }
@@ -153,7 +155,7 @@
     while(1)
     {
         Thread::signal_wait(0x3);
-        printf("\nTHIS IS BEACON    %f\n",t1.read());
+        printf("\n\rTHIS IS BEACON    %f\n\r",t1.read());
         t.start();
         
         
@@ -167,7 +169,7 @@
             beac_flag = 0;
         }
         
-        printf("The time to execute beacon thread is %f seconds\n",t.read());
+        printf("The time to execute beacon thread is %f seconds\n\r",t.read());
         t.reset();
     }
 }
@@ -177,38 +179,6 @@
 //---------------------------------------------------------------------------------------------------------------------------------------------------
 //Dummy fault rectifier functions
 
-/*Mail<int,16> faults;
-
-void FUNC_FAULT_FUNCT1()
-{
-    printf("\nFault 1 detected... \n");
-}
-
-void FUNC_FAULT_FUNCT2()
-{
-    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);
-        }
-    }
-}*/
-
 extern SensorDataQuantised SensorQuantised;
 
 
@@ -233,7 +203,7 @@
     while(true)
     {
         Thread::signal_wait(0x5);                               //signal set from scheduler or sthing. r RTOS timer nce the timing is finalized
-        printf("\nEntered WD\n");
+        printf("\n\rEntered WD\n\r");
         trigger = !trigger;
     }
 }
@@ -250,26 +220,41 @@
 void FUNC_I2C_WRITE2CDMS(char *data, int length=1)
 {
        int slave_status = 1;
-   
-    while(slave_status && interrupt == 1)
-    {                 
-            slave.address(0x20);
-            if(slave.receive()==1)
+//t2.stop();
+       if(interrupt ==1)
+       {
+
+           if(slave.receive() == 0)
+           t2.stop();
+//t4.stop();     
+//  printf("\n\r %d ",slave.receive());  
+           if( slave.receive()==1)
+           {
+               t2.stop();
+               //t3.start();
+               slave_status=slave.write(data,length);
+               //t3.stop();
+            
+            }
+            else if( slave.receive()==3 ||  slave.receive()==2)
             {
-                slave_status=slave.write(data,length);
-               
+                t2.stop();
+                //t3.start();
+                slave_status=slave.read(data,length);
+                //t3.stop();
                 
             }
-            else if(slave.receive()==3 || slave.receive()==2)
-            {
-                slave_status=slave.read(data,length);
-            }
+         
             
     }
-            
-            printf("\ndone\n\r");
-
+           
+            printf("\n\r%d\r",t2.read_us());
+            t2.reset();
+             //printf("\n\r%d\r",t3.read_us());
+            //t3.reset();
+     
 }
+   
 char data_send[25],data_receive;
 void T_I2C_BAE(void const * args)
 {
@@ -277,20 +262,17 @@
     while(1)
     {
         Thread::signal_wait(0x4);
-        //T_I2C_BAE();
-        //i2c_status = temp;
-        //wait(0.5);
-        printf("\n entered thread   %d\n\r",i2c_status);
+       // printf("\n\r entered thread");
         if(i2c_status == 0 )
         {
-            
+            wait_ms(30);
             FUNC_I2C_WRITE2CDMS(&data_receive,1);
-            printf("\n received\n");
+               
             /*i2c_data * i2c_data_r = i2c_data_receive.alloc();
             i2c_data_r->data = data_receive;
             i2c_data_r->length = 1;
             i2c_data_receive.put(i2c_data_r);*/
-            printf("\n Data received from CDMS is %c \n\r",data_receive);
+            printf("\n\r Data received from CDMS is %c \n\r",data_receive);
             FUNC_I2C_TC_EXECUTE(data_receive);                             // This has to be done from a differen thread
             
         }
@@ -301,11 +283,12 @@
             {
                 i2c_data *i2c_data_s = (i2c_data*)evt.value.p;
                 strcpy(data_send,i2c_data_s -> data);
+                wait_ms(29);
                 FUNC_I2C_WRITE2CDMS(data_send,25);
-                printf("\nData sent to CDMS is %s\n\r",data_send);
+                printf("\n\rData sent to CDMS is %s\n\r",data_send);
                 i2c_data_send.free(i2c_data_s);
                 i2c_status = 0;
-                //temp = i2c_status;
+                
                 
             }
         }  
@@ -317,19 +300,16 @@
 
 void FUNC_I2C_INT()
 {
-   reset = 0;
+   
+   t2.start();
    ptr_t_i2c->signal_set(0x4);
    
      
 }
 
-
-
-
-
 void FUNC_I2C_IR2CDMS()
 {
-        
+        data_ready=0; 
         //char data[25];
         //strcpy(data,"sakthi ");
         //strcat(data,"priya");
@@ -345,8 +325,8 @@
         strcat(hk_data,sfaultir);
         strcat(hk_data,spower_mode);*/
         strcat(hk_data,fdata);
-        printf("\nhk data : %s\n",hk_data);
-        data_ready=0;
+        printf("\n\rhk data : %s\n\r",hk_data);
+       
         //data = pcslave.getc();
         reset =0;
         i2c_status=1;
@@ -383,7 +363,7 @@
 void T_SC(void const *args)
 {
     //DRDY=0;
-    printf("The value of i in scheduler is %d\n",schedcount);
+    printf("The value of i in scheduler is %d\n\r",schedcount);
     if(schedcount == 65532)                         //to reset the counter
     {
         schedcount = 0;
@@ -391,12 +371,12 @@
     
     if(schedcount%1==0)
     {
-        ptr_t_acs -> signal_set(0x1);
-        ptr_t_wdt -> signal_set(0x5);
+     ptr_t_acs -> signal_set(0x1);
+       ptr_t_wdt -> signal_set(0x5);
     }
     if(schedcount%2==0)
     {
-        //ptr_t_fault -> signal_set(0x2);
+       // ptr_t_fault -> signal_set(0x2);
         ptr_t_hk_acq -> signal_set(0x2);
         
     }
@@ -405,7 +385,7 @@
         if(beac_flag==0)
         {
             
-            //ptr_t_bea -> signal_set(0x3);
+            ptr_t_bea -> signal_set(0x3);
         }
     }
     schedcount++;
@@ -416,6 +396,7 @@
 int main()
 {
     t1.start();
+     slave.address(0x20);
     //DRDY=0;
      FUNC_ACS_MAG_INIT();
      FUNC_ACS_INIT_GYR();
@@ -444,14 +425,14 @@
     
   
    // ----------------------------------------------------------------------------------------------
-    //printf("\n T_FAULT priority is %d",ptr_t_fault->get_priority()); 
-    printf("\n T_ACS priority is %d",ptr_t_acs->get_priority());
-    printf("\n T_HK_ACQ priority is %d",ptr_t_hk_acq->get_priority());
-    //printf("\n T_ACS_WRITE2FLASH priority is %d",ptr_t_acs_write2flash->get_priority());
-    printf("\n T_BEA priority is %d",ptr_t_bea->get_priority());  
+    //printf("\n\r T_FAULT priority is %d",ptr_t_fault->get_priority()); 
+    printf("\n\r T_ACS priority is %d",ptr_t_acs->get_priority());
+    printf("\n\r T_HK_ACQ priority is %d",ptr_t_hk_acq->get_priority());
+    //printf("\n\r T_ACS_WRITE2FLASH priority is %d",ptr_t_acs_write2flash->get_priority());
+    printf("\n\r T_BEA priority is %d",ptr_t_bea->get_priority());  
     RtosTimer t_sc_timer(T_SC,osTimerPeriodic);
     t_sc_timer.start(10000);
-    printf("\n%f\n",t1.read()); 
+    printf("\n\r%f\n\r",t1.read()); 
      
      
       
@@ -463,7 +444,7 @@
         //Thread::wait(10000);
          //ir2master(); 
          //DRDY = 0;
-         Thread::wait(5000);
+        Thread::wait(5000);
     }
     
 }