while loop removed ( master cant send)

Dependencies:   mbed-rtos mbed

Fork of slave_working_obama by sakthi priya amirtharaj

Files at this revision

API Documentation at this revision

Comitter:
greenroshks
Date:
Mon Jan 26 11:12:57 2015 +0000
Parent:
12:f6b6954b65d6
Commit message:
without timeouts and timers

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r f6b6954b65d6 -r fe24dd810078 main.cpp
--- a/main.cpp	Sat Jan 24 11:50:04 2015 +0000
+++ b/main.cpp	Mon Jan 26 11:12:57 2015 +0000
@@ -12,7 +12,8 @@
 int i2c_status=0;                                 //read/write mode for i2c 0 : write2slave, 1 : write2master
 int reset=0;
 int temp;
-
+Timer t;
+Timer t2;
 
 typedef struct
 {
@@ -35,18 +36,28 @@
        int slave_status = 1;
  //  printf("\nData is %c\n\r",*data);  
          
-    slave.address(0x20);
-        
+    
+    //wait_ms(10);   
     if(interrupt ==1)
     {        
           //wait(2);
           //printf("\nin int loop\n");
+            //t.stop();
+            //t2.start();
             receive_status = slave.receive();
+            //t2.stop();
+            //printf("\n%d\n",receive_status);
+            t.stop();
             //printf("\n status %d \n",receive_status);
             if( receive_status==1)
             {
                // printf("\nslave receive b4: \n");
+                //t.stop();
+                //t2.start();
+                
                 slave_status=slave.write(data,length);
+                
+                t2.stop();
                // printf("\nData sent to CDMS is %c\n\r",*data);
               // printf("\n\r write"); 
                 //printf("\nslave receive after: %d \n",slave.receive());
@@ -56,6 +67,8 @@
             
             else if( receive_status==3 ||  receive_status==2)
             {
+                //t.stop();
+                //printf("\nh\n");
                 slave_status=slave.read(data,length);
                 
             }
@@ -64,8 +77,11 @@
            //  printf("\n\r %d %d %d %d %d \n",*data_reg,*status_reg,*c1_reg,*c2_reg,*freq_reg);
             
     }
-            printf("\ndone\n\r");
-
+            printf("\n%f\r",t.read());
+            t.reset();
+            printf("\n%d\r",t2.read_us());
+            t2.reset();
+            //printf("\n%f\r",t.read());
 }
 
 void T_I2C_BAE(void const * args)
@@ -77,7 +93,7 @@
         //i2c_status = temp;
         //wait(0.5);
         printf("\n entered thread\n\r");
-        if(i2c_status == 0 && reset !=1)
+        if(i2c_status == 0 )                                    //receiving data from cdms
         {
             
             FUNC_I2C_WRITE2CDMS(&data_receive);
@@ -89,7 +105,7 @@
             i2c_data_receive.free(i2c_data_r);                              // This has to be done from a differen thread
             
         }
-        else if(i2c_status ==1 && reset !=1)
+        else if(i2c_status ==1 )                                //sending data to cdms
         {
             osEvent evt = i2c_data_send.get();
             if (evt.status == osEventMail) 
@@ -111,15 +127,13 @@
         
 void FUNC_INT()
 {
-   reset = 0;
+   //reset = 0;
+   t.start();
    ptr_t_i2c->signal_set(0x1);
      
 }
 
-void FUNC_RESET()
-{
-    reset = 1;
-}
+
 
 void ir2master()
 {
@@ -145,7 +159,7 @@
 {   
     
     printf("\n slave started\n\r");
-    
+    slave.address(0x20);
     ptr_t_i2c = new Thread(T_I2C_BAE);
     
     interrupt.rise(&FUNC_INT);