Repository for CDMS code

Dependencies:   SimpleDMA mbed-rtos mbed eeprom

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Files at this revision

API Documentation at this revision

Comitter:
ee12b079
Date:
Thu Apr 14 04:34:58 2016 +0000
Parent:
161:a63672bf4423
Child:
164:be3b4b760d0c
Commit message:
Merged bae_i2c

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
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	Thu Apr 14 04:14:21 2016 +0000
+++ b/COM_MNG_TMTC.h	Thu Apr 14 04:34:58 2016 +0000
@@ -202,14 +202,22 @@
         {
             gPC.printf("Telecommand is for BAE\r\n");
             //printf("Sending TC to BAE...\r\n"); //interrupt to be sent to the bae
-            /*FCTN_I2C_WRITE((char*)tc_ptr->TC_string);
+
+            if(GETshort_or_long_tc(tc_ptr) == LONG_TC_CODE)
+                FCTN_I2C_WRITE((char*)tc_ptr->TC_string,TC_LONG_SIZE);
+            else 
+            {
+                FCTN_I2C_WRITE((char*)tc_ptr->TC_string,TC_SHORT_SIZE);
+            }
+            
             while(1)
             {
                 wait(1); //TimeOut instead of wait
-                if(tm_status_4m_slv == 1)
+                if(BAE_I2C_GPIO == 1)
                 {
+                    
                     //printf("receiving...\r\n");
-                    FCTN_I2C_READ((char*)tm_pointer->TM_string,134);
+                    FCTN_I2C_READ((char*)tm_pointer->TM_string,TM_LONG_SIZE);
                     //printf("%s", tm_pointer->TM_string);
                     received+=1;
                     tm_pointer = tm_pointer->next_TM;
@@ -222,25 +230,13 @@
             }
             if(received >= 1 )
             {
-                //printf("Telemetry is received from BAE\r\n");
-                Base_tm *tm_print = tm_ptr;
-                for(uint8_t i=0;i<received;i++)
-                {  
-                    //printf("%s", tm_print->TM_string);
-                    tm_print = tm_print->next_TM; //for check
-                }
-                received  = 0;
-                tm_pointer->next_TM = NULL;                 return tm_ptr;
-            }
-            else
-            {
                 //printf("Telemetry is not received from BAE\r\n");
                 //tm_pointer = new Short_tm;
                 tm_pointer->TM_string[0] = 0xB0;
                 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);
-                tm_pointer->TM_string[2] = 0x01;
-                tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided
-                tm_pointer->TM_string[4] = 0x01;
+                tm_pointer->TM_string[2] = 0x00;
+                tm_pointer->TM_string[3] = 0x00; //ackcode to be decided
+                tm_pointer->TM_string[4] = 0x00;
                 for(uint8_t i=0;i<6;i++)
                 {
                     tm_pointer->TM_string[i+5] = 0;
@@ -250,7 +246,7 @@
                 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
                 tm_pointer->next_TM = NULL;                 return tm_ptr;
             }
-            break;*/
+            break;
         }
         case 2:
         {
--- a/DefinitionsAndGlobals.h	Thu Apr 14 04:14:21 2016 +0000
+++ b/DefinitionsAndGlobals.h	Thu Apr 14 04:34:58 2016 +0000
@@ -26,10 +26,14 @@
     #define ADF_IRQ PTA14
     
     
-//I2C - Payload to CDMS (need to change while using CDMS hardware)
-I2C master(D7,D6);
+//I2C - Payload to CDMS (need to change while using CDMS hardware);
+I2C master(PIN32,PIN31);
 InterruptIn PYLD_I2C_Int(PTA13);
 
+//I2C - CDMS to BAE
+DigitalIn BAE_I2C_GPIO(PIN39);
+DigitalOut CDMS_I2C_GPIO(PIN67);
+
 // TC LIST
     #define TCL_STATE_INCOMPLETE 0x00
     #define TCL_STATE_ABORTED 0x03
--- a/i2c.h	Thu Apr 14 04:14:21 2016 +0000
+++ b/i2c.h	Thu Apr 14 04:34:58 2016 +0000
@@ -6,6 +6,7 @@
 bool write_ack = false;
 bool read_ack = false;
 const int addr_pl = 0x20<<1;  //PL address
+const int addr_bae = 0x20; ///bae address
 uint8_t rcv_isr = 0;
 
 int count = 0;
@@ -22,6 +23,47 @@
         }
 }
 
+void FCTN_I2C_READ(char *data,int length)
+{   
+    CDMS_I2C_GPIO = 1;
+    //t_read.start();
+    read_ack = master.read(addr_bae|1,data,length);
+    //t_read.stop();
+  
+    if(read_ack == 0)
+        printf("\n\rData received from BAE %s \n",data);
+ if (read_ack == 1)
+    {
+        printf("\n \r data not received \n");
+    }
+//if(read_ack == 1)
+//pc.printf("\n \r data not received \n");
+
+    CDMS_I2C_GPIO = 0;
+    //printf("\n\r %d \n",t.read_us());
+    //t.reset();
+}
+
+void FCTN_I2C_WRITE(char *data,uint8_t tc_len2)
+{
+    CDMS_I2C_GPIO = 1;
+    //t.start();
+    write_ack = master.write(addr_bae|0x00,data,tc_len2);
+    //t.stop();
+    //if(write_ack == 0)
+        //gPC.printf("\n\r data not sent \n");
+       
+if (write_ack == 1)
+    {
+//        led2 = 1;
+        gPC.printf("\n\r data not sent \n");
+//        led2 = 0;    
+    }
+    CDMS_I2C_GPIO = 0;
+    //gPC.printf("\n\r %d \n",t.read_us());
+    //t.reset();
+}
+
 void isr_pyldtm()
 {
 
--- a/main.cpp	Thu Apr 14 04:14:21 2016 +0000
+++ b/main.cpp	Thu Apr 14 04:34:58 2016 +0000
@@ -4,6 +4,7 @@
 #include "mbed.h"
 
 #define DEBUG 1
+#define power_tx 0
 
 #include "SimpleDMA.h"
 #include "dmaSPIslave.h"
@@ -34,6 +35,9 @@
 //void set_sig(){gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL);}
 int main()
 {
+    
+    
+    CDMS_I2C_GPIO = 0;  
     //gLEDR = 1;
     
     // ******************INITIALISATIONS START******************
@@ -69,13 +73,13 @@
     
     // COM_MNG_TMTC THREAD
     gCOM_MNG_TMTC_THREAD = new Thread(COM_MNG_TMTC_FUN);
-    gCOM_MNG_TMTC_THREAD->set_priority(osPriorityAboveNormal);
+    gCOM_MNG_TMTC_THREAD->set_priority(osPriorityHigh);
     #if DEBUG
     gPC.puts("allocating threads\r\n");
     #endif
     gSCIENCE_THREAD = new Thread(SCIENCE_FUN);
    // gPC.puts("step one complete\r\n");
-    gSCIENCE_THREAD->set_priority(osPriorityBelowNormal);
+    gSCIENCE_THREAD->set_priority(osPriorityAboveNormal);
     #if DEBUG
     gPC.puts("competed allocating threads\r\n");
     #endif