i2c working

Dependencies:   mbed-rtos mbed

Fork of BAE_FRDMTESIN2 by Seeker of Truth ,

Revision:
9:221d218f4690
Parent:
8:69475d16d23d
Child:
10:ed6d3b8d1d56
--- a/main.cpp	Thu Dec 11 07:34:17 2014 +0000
+++ b/main.cpp	Mon Dec 15 05:58:04 2014 +0000
@@ -5,9 +5,12 @@
 #include "beacon.h"
 #include "ACS.h"
 #include "fault.h"
+#include "slave.h"
 
 Serial pc(USBTX, USBRX);
 
+InterruptIn interrupt(D9);
+InterruptIn master_reset(D11);
 
 
 Timer t;                                                        //To know the time of execution each thread
@@ -20,7 +23,7 @@
 Thread *ptr_t_bea;
 Thread *ptr_t_bea_telecommand;
 Thread *ptr_t_fault;
-
+Thread *ptr_t_i2c;
 
 //--------------------------------------------------------------------------------------------------------------------------------------------------
 //TASK 2 : HK
@@ -40,7 +43,7 @@
         
         FUNC_HK_MAIN();                                                             //Collecting HK data
         //thread_2.signal_set(0x4);
-        FUNC_I2C_SLAVE_MAIN(24);                                                    //Sending to CDMS via I2C
+        //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());
@@ -210,6 +213,69 @@
     }    
 }
 
+//---------------------------------------------------------------------------------------------------------------------------------------------------
+//TASK 5 : i2c data
+//---------------------------------------------------------------------------------------------------------------------------------------------------
+
+ 
+void C_FUNC_INT()
+{
+   FUNC_INT();
+   ptr_t_i2c->signal_set(0x4);
+     
+}
+
+void C_FUNC_RESET()
+{
+    FUNC_RESET();
+}
+
+
+void C_T_I2C_BAE(void const * args)
+{
+    //char data_send,data_receive;
+    while(1)
+    {
+        Thread::signal_wait(0x4);
+        T_I2C_BAE();
+        //i2c_status = temp;
+        //wait(0.5);
+        /*printf("\n entered thread\n\r");
+        if(i2c_status == 0 && reset !=1)
+        {
+            
+            FUNC_I2C_WRITE2CDMS(&data_receive);
+            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);
+            i2c_data_receive.free(i2c_data_r);                              // This has to be done from a differen thread
+            
+        }
+        else if(i2c_status ==1 && reset !=1)
+        {
+            osEvent evt = i2c_data_send.get();
+            if (evt.status == osEventMail) 
+            {
+                i2c_data *i2c_data_s = (i2c_data*)evt.value.p;
+                data_send = i2c_data_s -> data;
+                FUNC_I2C_WRITE2CDMS(&data_send);
+                printf("\nData sent to CDMS is %c\n\r",data_send);
+                i2c_data_send.free(i2c_data_s);
+                i2c_status = 0;
+                //temp = i2c_status;
+            }
+        }  
+          */ 
+    }
+}
+
+
+
+
+
+
 //------------------------------------------------------------------------------------------------------------------------------------------------
 //SCHEDULER
 //------------------------------------------------------------------------------------------------------------------------------------------------
@@ -257,12 +323,14 @@
     ptr_t_bea = new Thread(t_bea);
     ptr_t_bea_telecommand = new Thread(t_bea_telecommand);
     ptr_t_fault = new Thread(T_FAULT);
+    ptr_t_i2c = new Thread(C_T_I2C_BAE);
     //ptr_t_sc = new Thread(t_sc);
   
     interrupt_fault();
     
     ptr_t_fault -> set_priority(osPriorityRealtime);
     ptr_t_acs->set_priority(osPriorityHigh);
+    ptr_t_i2c->set_priority(osPriorityAboveNormal);
     ptr_t_hk_acq->set_priority(osPriorityNormal);
     ptr_t_acs_write2flash->set_priority(osPriorityBelowNormal);
     ptr_t_bea->set_priority(osPriorityAboveNormal);
@@ -279,11 +347,16 @@
     RtosTimer t_sc_timer(t_sc,osTimerPeriodic);
     t_sc_timer.start(10000);
     printf("\n%f\n",t1.read()); 
-        
+     
+     
+      
+    master_reset.fall(&C_FUNC_RESET);
+    interrupt.rise(&C_FUNC_INT);
+       
     while(1)
     {   
-        Thread::wait(10000);
-        ;
+        //Thread::wait(10000);
+         ir2master(); 
     }
     
 }
\ No newline at end of file