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:14:21 2016 +0000
Parent:
154:9aec89c8cdc7
Child:
162:48fda0b8d573
Commit message:
merged OBSRS TM and I2C_PL_working

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
Structures.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
adf.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	Mon Apr 11 16:04:55 2016 +0000
+++ b/COM_MNG_TMTC.h	Thu Apr 14 04:14:21 2016 +0000
@@ -10,11 +10,6 @@
 //added RLY_TMTC function
 //added included related files
 
-//#include "Flash.h"
-#include "cdms_rtc.h"
-
-DigitalIn tm_status_4m_slv(PIN39); //I2C interrupt to CDMS from BAE
-//DigitalIn tm_status_4m_pl(PIN61); //I2C interrupt to CDMS from PL
 
 uint8_t received = 0;
 uint16_t mid1;
@@ -196,7 +191,7 @@
 
 // CDMS TEAM CODE START
 inline Base_tm* FCTN_CDMS_RLY_TMTC(Base_tc *tc_ptr){
-    uint8_t ACKCODE = 0x00;
+    uint8_t ACKCODE = 0xB0;
     //printf("\rTC execution in progress\r\n");
     Base_tm *tm_pointer = new Long_tm;
     Base_tm *tm_ptr = tm_pointer;
@@ -205,9 +200,9 @@
     {
         case 1: //apid=01 implies it corresponds to bae
         {
-            //printf("Telecommand is for BAE\r\n");
+            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);
+            /*FCTN_I2C_WRITE((char*)tc_ptr->TC_string);
             while(1)
             {
                 wait(1); //TimeOut instead of wait
@@ -255,7 +250,7 @@
                 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
                 tm_pointer->next_TM = NULL;                 return tm_ptr;
             }
-            break;
+            break;*/
         }
         case 2:
         {
@@ -293,7 +288,7 @@
                             }                            
                             case 0x2:
                             {
-                            //printf("sub_service:Read from Flash_Memory\r\n");
+                            gPC.printf("sub_service:Read from Flash_Memory\r\n");
                             mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]);                           
                                                                                              
                                     //Data[0] = FCTN_CDMS_RD_FLASH(0);
@@ -787,22 +782,39 @@
         }
         case 3:
         {
-            //printf("Telecommand is for PL\r\n");
-            // 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);
-            //     received = 1;
-            // }
-            // if(received == 1 )
-            // {
-            //     printf("Telemetry is received from BAE\r\n");
-            //     printf("%s", tm_ptr->TM_string);
-            //     received  = 0;
-            // } // similar to BAE functions
+            #if DEBUG
+            printf("Telecommand is for PL\r\n");
+            #endif
+
+
+            if(GETservice_subtype(tc_ptr) == 0xD0 || GETservice_subtype(tc_ptr) == 0xD2 || GETservice_subtype(tc_ptr) == 0xD3)
+            {
+                PL_TM_SIZE = TM_LONG_SIZE;
+            }
+            else
+            {
+                PL_TM_SIZE = TM_LONG_SIZE;
+            }   
+                
+            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)
+            {
+                if(rcv_isr == 1)
+                {
+                    //gPC.printf("i2c_t = %d",t_pl.read_ms());  
+                        for(int i = 0;i< PL_TM_SIZE;i++)
+                        tm_pointer->TM_string[i] = PL_I2C_DATA[i];
+                        rcv_isr = 0; 
+                        break;
+                }
+            }
+            tm_pointer->next_TM = NULL;                 return tm_ptr;          
             break;
         }
         default: //invalid TC
@@ -1230,9 +1242,7 @@
                             /*execute_obsrs(current_TC, put_tm_here)*/\
                             /*read_TC(current_TC);*/\
                             execute_OBSRS_TC(current_TC);\
-                            gPC.puts("en_adf\n\r");\
                             transmit_adf;\
-                            gPC.puts("ex_adf\n\r");\
                             uint8_t tempExec = TC_STATE_SUCCESSFULLY_EXECUTED;\
                             PUTexec_status(current_TC, tempExec);\
                             /*PENDING: ABORT ON NACK CHECK, gMASTER_STATE VERIFICATION WITH SD CARD, session timeout, last executed ack l234*/\
--- a/DefinitionsAndGlobals.h	Mon Apr 11 16:04:55 2016 +0000
+++ b/DefinitionsAndGlobals.h	Thu Apr 14 04:14:21 2016 +0000
@@ -24,6 +24,11 @@
 
 // ADF INTERRUPUT
     #define ADF_IRQ PTA14
+    
+    
+//I2C - Payload to CDMS (need to change while using CDMS hardware)
+I2C master(D7,D6);
+InterruptIn PYLD_I2C_Int(PTA13);
 
 // TC LIST
     #define TCL_STATE_INCOMPLETE 0x00
--- a/Structures.h	Mon Apr 11 16:04:55 2016 +0000
+++ b/Structures.h	Thu Apr 14 04:14:21 2016 +0000
@@ -46,7 +46,7 @@
 #define GETshort_or_long_tc(x) ( ( (x->flags) & SHORT_LONG_TC_MASK ) >> 4 )
 #define GETcrc_pass(x) ( ( (x->flags) & CRC_MASK ) >> 3 )
 #define GETabort_on_nack(x) ( ( (x->TC_string[1]) & 0x08 ) >> 3 )
-#define GETapid(x) ( ( (x->TC_string[1]) & 0xA0 ) >> 6 )
+#define GETapid(x) ( ( (x->TC_string[1]) & 0xC0 ) >> 6 )
 #define GETexec_status(x) ( (x->flags) & EXEC_STATUS_MASK )
 #define GETpacket_seq_count(x) (x->TC_string[0])
 #define GETservice_type(x) ( (x->TC_string[2]) & 0xF0 )
--- a/ThreadsAndFunctions.h	Mon Apr 11 16:04:55 2016 +0000
+++ b/ThreadsAndFunctions.h	Thu Apr 14 04:14:21 2016 +0000
@@ -104,8 +104,6 @@
         }
         else if( gFLAGS & NEW_TC_RECEIVED ){
             gPC.puts("NEW TC RECEIVED\r\n");
-//            DEBUF_PRINT("NEW TC RECEIVED\r\n");
-            Thread::wait(2000);    /*To be removed in flight model*/
             gFLAGS = gFLAGS & (~NEW_TC_RECEIVED);
             gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG;
 
--- a/adf.h	Mon Apr 11 16:04:55 2016 +0000
+++ b/adf.h	Thu Apr 14 04:14:21 2016 +0000
@@ -325,7 +325,7 @@
                     ADF_off = true;\
                 }\
             }else{\ 
-                gLEDR = !gLEDR;\  
+                gLEDG = !gLEDG;\  
                 write_data;\
                 if(sent_tmfrom_SDcard)\
                 send_tm_from_SD_card_fun();\
--- a/i2c.h	Mon Apr 11 16:04:55 2016 +0000
+++ b/i2c.h	Thu Apr 14 04:14:21 2016 +0000
@@ -2,62 +2,30 @@
 #define tc_len 135
 #define tc_test_len 135
 
-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);
 const int addr = 0x20;                                            //slave address 
-char telecommand[tc_len];
-char telemetry[tm_len];
-//Timer test;
-//Timer t_read;
-bool write_ack = true;
-bool read_ack = true;
+bool write_ack = false;
+bool read_ack = false;
+const int addr_pl = 0x20<<1;  //PL address
+uint8_t rcv_isr = 0;
 
 int count = 0;
 
-void FCTN_I2C_WRITE(char *data)
+char PL_I2C_DATA[134];//Payload i2c array
+uint8_t PL_TM_SIZE;//size of data to bev read from i2c
+
+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 == 1)
     {
-//        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();
+        printf("\n\rdata not sent\n");
+        }
 }
 
-
-void FCTN_I2C_READ(char *data,int length)
+void isr_pyldtm()
 {
-    irpt_2_slv = 1;
-    //t_read.start();
-    read_ack = master.read(addr|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");
 
-    irpt_2_slv = 0;
-    //printf("\n\r %d \n",t.read_us());
-    //t.reset();
+    read_ack = master.read(addr_pl|1,PL_I2C_DATA,134);
+    gLEDR=!gLEDR;
+    rcv_isr = 1;
 }
\ No newline at end of file
--- a/main.cpp	Mon Apr 11 16:04:55 2016 +0000
+++ b/main.cpp	Thu Apr 14 04:14:21 2016 +0000
@@ -23,6 +23,8 @@
 #include "OBSRS.h"
 #include "adf.h"
 #include "COM_RCV_TC.h"
+//#include "Flash.h"
+#include "cdms_rtc.h"
 #include "COM_MNG_TMTC.h"
 #include "COM_POWER_ON_TX.h"
 #include "COM_POWER_OFF_TX.h"
@@ -36,6 +38,7 @@
     
     // ******************INITIALISATIONS START******************
     // COM RX
+    
     RX1M.baud(1200);
     gRX_HEAD_DATA_NODE = new COM_RX_DATA_NODE;
     gRX_HEAD_DATA_NODE->next_node = NULL;