werwere

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of COM_MNG_TMTC_SIMPLE_pl123 by Siva ram

Files at this revision

API Documentation at this revision

Comitter:
ee12b079
Date:
Sat Feb 27 07:12:04 2016 +0000
Parent:
128:a232a4352664
Child:
131:8745e6041ebc
Child:
132:d4a4461214ad
Commit message:
Integrating i2c with PL

Changed in this revision

COM_MNG_TMTC.h Show annotated file Show diff for this revision Revisions of this file
DefinitionsAndGlobals.h Show annotated file Show diff for this revision Revisions of this file
ThreadsAndFunctions.h Show annotated file Show diff for this revision Revisions of this file
i2c.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/COM_MNG_TMTC.h	Fri Feb 26 13:29:33 2016 +0000
+++ b/COM_MNG_TMTC.h	Sat Feb 27 07:12:04 2016 +0000
@@ -12,7 +12,7 @@
 
 //#include "Flash.h"
 #include "cdms_rtc.h"
-
+Timer t_pl;
 //defined in definations and globals, need to mapped with the final ones.
 //DigitalIn tm_status_4m_slv(PIN39); //I2C interrupt to CDMS from BAE
 //DigitalIn tm_status_4m_pl(PIN61); //I2C interrupt to CDMS from PL 
@@ -991,15 +991,47 @@
         {
             
             
-            
-            //printf("Telecommand is for PL\r\n");
+            uint8_t PL_TM_SIZE;
+            #if DEBUG
+            printf("Telecommand is for PL\r\n");
+            #endif
             // printf("Informing PL about TC using I2C\r\n"); //interrupt to be sent to the bae
-            // FCTN_I2C_WRITE((char*)tc_ptr->TC_string);
-            // printf("sent the Telecommand to BAE\r\n"); //packet along with crc will be sent when bae is ready
-            // wait(1); //wait time is to be optimised
-            // if(tm_status_4m_slv == 1)
-            // {
-            //     FCTN_I2C_READ((char*)tm_ptr->TM_string);
+            if(GETshort_or_long_tc(tc_ptr) == LONG_TC_CODE)
+                FCTN_I2C_WRITE_PL((char*)tc_ptr->TC_string,TC_LONG_SIZE);
+            else 
+                FCTN_I2C_WRITE_PL((char*)tc_ptr->TC_string,TC_SHORT_SIZE);
+            
+            
+            
+            while(1)
+            {
+                gLEDG = !gLEDG;
+                t_pl.start();
+                if(PYLD_I2C_Int == 1)
+                {
+                    t_pl.stop();
+                    gPC.printf("i2c_t = %d",t_pl.read_ms());
+                    if(GETservice_subtype(tc_ptr) == 0xD0 || GETservice_subtype(tc_ptr) == 0xD2 || GETservice_subtype(tc_ptr) == 0xD3) //check which all require short TM
+                    {   
+                        FCTN_I2C_READ_PL((char*)tm_pointer->TM_string,TM_LONG_SIZE);
+                        break;
+                        }
+                    else 
+                    {
+                        FCTN_I2C_READ_PL((char*)tm_pointer->TM_string,TM_SHORT_SIZE);
+                        break;
+                        }
+                    }
+                
+                
+                }
+            
+            
+                // for(int i;i<2000;i++){if(PYLD_I2C_Int=1)i=2001;}//timeout to be defined
+                 
+                 
+                 //PL should reset the i2c pin
+                 
             //     received = 1;
             // }
             // if(received == 1 )
--- a/DefinitionsAndGlobals.h	Fri Feb 26 13:29:33 2016 +0000
+++ b/DefinitionsAndGlobals.h	Sat Feb 27 07:12:04 2016 +0000
@@ -26,7 +26,7 @@
     #define ADF_IRQ PTA14
     
 //I2C - Payload to CDMS (need to change while using CDMS hardware)
-I2C master (D7,D6);
+I2C master(D7,D6);
 InterruptIn PYLD_I2C_Int(PTA13);
 
 // TC LIST
@@ -179,6 +179,4 @@
 CDMS_HK_min_max min_max_data;
 bool firstCount=true;
 
-//I2C thread
-Thread* ptr_t_pyldtm = NULL;
 
--- a/ThreadsAndFunctions.h	Fri Feb 26 13:29:33 2016 +0000
+++ b/ThreadsAndFunctions.h	Sat Feb 27 07:12:04 2016 +0000
@@ -301,24 +301,4 @@
         #endif
         gPAY_SPI.bulkRead_start();
     }
-}
-
-//I2C from CDMS to PL
-const int addr1 = (0x20<<1|0);
-
-bool f = 1;
-
-void isr_pyldtm()
-{
-    ptr_t_pyldtm->signal_set(0x4);
-}
-
-char rdata[134];
-void pyldtm(void const *args)
-{   
-  while(1)
-  {
-    Thread::signal_wait(0x4);
-    f=  master.read(addr1,rdata,134);
-  }
 }
\ No newline at end of file
--- a/i2c.h	Fri Feb 26 13:29:33 2016 +0000
+++ b/i2c.h	Sat Feb 27 07:12:04 2016 +0000
@@ -4,13 +4,11 @@
 
 InterruptIn irpt_4m_slv(D3);                                      //I2c interrupt from CDMS
 DigitalOut irpt_2_slv(D4);                                        //I2C interrupt to CDMS
-//I2C master(PIN32,PIN31);
-I2C master(PTC9,PTC8);
-//DigitalOut led1(PIN46);
-//DigitalOut led2(PIN95);
+//I2C master(PTC9,PTC8);
 const int addr = 0x20;                                            //slave address 
-char telecommand[tc_len];
-char telemetry[tm_len];
+const int addr_pl = 0x20<<1;                                            //PL slave address
+//char telecommand[tc_len];
+//char telemetry[tm_len];
 //Timer test;
 //Timer t_read;
 bool write_ack = true;
@@ -18,29 +16,44 @@
 
 int count = 0;
 
-void FCTN_I2C_WRITE(char *data)
+void FCTN_I2C_WRITE_PL(char *data2,uint8_t tc_len2)
 {
-    irpt_2_slv = 1;
-    //t.start();
-    write_ack = master.write(addr|0x00,data,tc_len);
-    //t.stop();
-    //if(write_ack == 0)
-        //gPC.printf("\n\r data not sent \n");
-       
-if (write_ack == 1)
+    write_ack = master.write(addr_pl|0x00,data2,tc_len2);//address to be defined in payload
+    if(write_ack == 0)
+    {
+        #if DEBUG
+        gPC.printf("\n\r data not sent \n");
+        #endif
+        }
+    else
     {
-//        led2 = 1;
-        //gPC.printf("\n\r data not sent \n");
-//        led2 = 0;    
-    }
-    irpt_2_slv = 0;
-    //gPC.printf("\n\r %d \n",t.read_us());
+        #if DEBUG
+        gPC.printf("\n\r data sent \n");
+        #endif
+        }
+}
+void FCTN_I2C_READ_PL(char *data,int length)
+{   
+    //t_read.start();
+    read_ack = master.read(addr_pl|1,data,length);
+    //t_read.stop();
+  
+    //if(read_ack == 0)
+      //  printf("\n\rData received from BAE %s \n",data);
+ //if (read_ack == 1)
+//    {
+//        gLEDR = 1;
+//        printf("\n \r data not received \n");
+//        gLEDR = 0;
+//    }
+//if(read_ack == 1)
+//pc.printf("\n \r data not received \n");
+    //printf("\n\r %d \n",t.read_us());
     //t.reset();
 }
 
-
-void FCTN_I2C_READ(char *data,int length)
-{
+void FCTN_I2C_READ(char *data,int length, int addr)
+{   
     irpt_2_slv = 1;
     //t_read.start();
     read_ack = master.read(addr|1,data,length);
@@ -60,4 +73,24 @@
     irpt_2_slv = 0;
     //printf("\n\r %d \n",t.read_us());
     //t.reset();
+}
+
+void FCTN_I2C_WRITE(char *data)
+{
+    irpt_2_slv = 1;
+    //t.start();
+    write_ack = master.write(addr|0x00,data,tc_len);
+    //t.stop();
+    //if(write_ack == 0)
+        //gPC.printf("\n\r data not sent \n");
+       
+if (write_ack == 0)
+    {
+//        led2 = 1;
+        //gPC.printf("\n\r data not sent \n");
+//        led2 = 0;    
+    }
+    irpt_2_slv = 0;
+    //gPC.printf("\n\r %d \n",t.read_us());
+    //t.reset();
 }
\ No newline at end of file
--- a/main.cpp	Fri Feb 26 13:29:33 2016 +0000
+++ b/main.cpp	Sat Feb 27 07:12:04 2016 +0000
@@ -2,7 +2,7 @@
 
 #include "mbed.h"
 
-#define DEBUG 0
+#define DEBUG 1
 
 #include "SimpleDMA.h"
 #include "dmaSPIslave.h"
@@ -13,7 +13,7 @@
 #include "pinconfig.h"
 #include "DefinitionsAndGlobals.h"
 #include "crc.h"
-//#include "i2c.h"
+#include "i2c.h"
 #include "COM_SND_TM_functions.h"
 #include "COM_SND_TM.h"
 #include "cdms_sd.h"
@@ -42,8 +42,8 @@
 //    gRX_CURRENT_PTR = gRX_CURRENT_DATA_NODE->values;
     RX1M.attach(&rx_read, Serial::RxIrq);
     
-    //I2C to Payload
-    PYLD_I2C_Int.rise(&isr_pyldtm);
+    //I2C to Payload    (depends on pl interrupt design)
+    //PYLD_I2C_Int.rise(&isr_pyldtm);
     
     
     // DEBUG
@@ -76,11 +76,6 @@
    // gPC.puts("step one complete\r\n");
     gSCIENCE_THREAD->set_priority(osPriorityBelowNormal);
     
-    //thread for I2C
-    ptr_t_pyldtm = new Thread(pyldtm);
-    gSCIENCE_THREAD->set_priority(osPriorityLow);//need to check the priorities
-    
-    
     #if DEBUG
     gPC.puts("competed allocating threads\r\n");
     #endif