lkdsnf;

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of COM_MNG_TMTC_SIMPLE_PL_Working by Siva ram

Files at this revision

API Documentation at this revision

Comitter:
ee12b079
Date:
Mon Jan 25 13:10:43 2016 +0000
Parent:
95:42d6747900cb
Child:
97:717c7908c822
Commit message:
Com thread worked in parallel with science thread, both types of TCs worked

Changed in this revision

COM_MNG_TMTC.h Show annotated file Show diff for this revision Revisions of this file
Compression.h Show annotated file Show diff for this revision Revisions of this file
OBSRS.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
cdms_rtc.h Show annotated file Show diff for this revision Revisions of this file
cdms_sd.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 Jan 25 06:22:29 2016 +0000
+++ b/COM_MNG_TMTC.h	Mon Jan 25 13:10:43 2016 +0000
@@ -1465,7 +1465,9 @@
                             /*execute_obsrs(current_TC, put_tm_here)*/\
                             /*read_TC(current_TC);*/\
                             execute_OBSRS_TC(current_TC);\
+                            gPC.puts("en_adf");\
                             transmit_adf;\
+                            gPC.puts("ex_adf");\
                             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/Compression.h	Mon Jan 25 06:22:29 2016 +0000
+++ b/Compression.h	Mon Jan 25 13:10:43 2016 +0000
@@ -273,7 +273,7 @@
                     space = adjust(1,0,pointer,8);
                     space = adjust(4,3,pointer,space);
                     FSC_science = FCTN_SD_MNGR(3);
-                    gPC.printf("SID = 3, FSC = %02X\r\n", FSC_science);
+                    //gPC.printf("SID = 3, FSC = %02X\r\n", FSC_science);
                     frames[id][1] = (FSC_science>>24)&0xff;
                     frames[id][2] = (FSC_science>>16)&0xff;
                     frames[id][3] = (FSC_science>>8)&0xff;
@@ -287,7 +287,7 @@
                     space = adjust(1,0,pointer,8);
                     space = adjust(4,2,pointer,space);
                     FSC_science = FCTN_SD_MNGR(2);
-                    gPC.printf("SID = 2, FSC = %02X\r\n", FSC_science);
+                    //gPC.printf("SID = 2, FSC = %02X\r\n", FSC_science);
                     frames[id][1] = (FSC_science>>16)&0xff;
                     frames[id][2] = (FSC_science>>8)&0xff;
                     frames[id][3] = FSC_science&0xff;
@@ -551,7 +551,7 @@
                 space = adjust(1,0,pointer,8);
                 space = adjust(4,1,pointer,space);
                 FSC_science = FCTN_SD_MNGR(1);
-                gPC.printf("SID = 1, FSC = %02X\r\n", FSC_science);
+                //gPC.printf("SID = 1, FSC = %02X\r\n", FSC_science);
                 frames[id][1] = (FSC_science>>16)&0xff;
                 frames[id][2] = (FSC_science>>8)&0xff;
                 frames[id][3] = (FSC_science)&0xff;
@@ -569,4 +569,5 @@
                 frames[id][4] = (length-1) - j;
             }
     }
+    gPC.puts("end srp");
 }//srp fucntion end bracket
\ No newline at end of file
--- a/OBSRS.h	Mon Jan 25 06:22:29 2016 +0000
+++ b/OBSRS.h	Mon Jan 25 13:10:43 2016 +0000
@@ -526,8 +526,9 @@
             list_of_FSC[i] = tcp->TC_string[4+i];
         }
     }
-    gPC.printf("sid = %u \r\n",SID);
-    gPC.printf("FSC = %u\r\n",FSC);
+    //gPC.printf("sid = %u \r\n",SID);
+    //gPC.printf("FSC = %u\r\n",FSC);
+    gPC.puts("exit_sdcard");
 //    SID = 0x0;
 //    FSC = 10;
 //    no_of_frames = 2;
--- a/ThreadsAndFunctions.h	Mon Jan 25 06:22:29 2016 +0000
+++ b/ThreadsAndFunctions.h	Mon Jan 25 13:10:43 2016 +0000
@@ -70,8 +70,8 @@
 
 void COM_MNG_TMTC_FUN(void const *args){
     if( !(gFLAGS & COM_SESSION_FLAG) ){
-        gLEDR = 1;
-        gLEDG = 1;
+        //gLEDR = 1;
+        //gLEDG = 1;
     }
     while(true){
         Thread::signal_wait( COM_MNG_TMTC_SIGNAL_UART_INT );
@@ -85,25 +85,25 @@
                 PUT_RAW_BYTE;
                 // PENDING : MEASURE RSSI
                 if( gFLAGS & COM_SESSION_FLAG ){
-                    gLEDR = 0;
-                    gLEDG = 0;
+                    //gLEDR = 0;
+                    //gLEDG = 0;
                 }
             }
             else if( gFLAGS & COM_RX_FLAG ){
-                gLEDR = 0;
-                gLEDG = 1;
+                //gLEDR = 0;
+                //gLEDG = 1;
                 PUT_RAW_BYTE;
             }
             else{
-                gLEDR = 1;
-                gLEDG = 0;
+                //gLEDR = 1;
+                //gLEDG = 0;
                 gFLAGS = gFLAGS | COM_RX_FLAG;
                 PUT_RAW_BYTE;
             }
         }
         else if( gFLAGS & NEW_TC_RECEIVED ){
             /*gPC.puts("NEW TC RECEIVED\r\n");*/
-            Thread::wait(10000);    /*To be removed in flight model*/
+            Thread::wait(2000);    /*To be removed in flight model*/
             gFLAGS = gFLAGS & (~NEW_TC_RECEIVED);
             gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG;
 
@@ -270,37 +270,40 @@
 }
 
 
-//uint8_t payload_data[6723];
+uint8_t payload_data[6723];
  
-//void SCIENCE_FUN(void const *args){
-//    uint8_t *ptr;
-//    gPC.puts("haha\r\n");
-//    ptr = &(payload_data[3]);
-//    gPC.puts("haha2\r\n");
-//    int counter = 0;
-//    gPC.puts("haha3\r\n");
-//    payload_data[2] = 0;//for mode
-//    for(int i = 0; i<60 ;i++){      //for mode 0.....callibra
-//        for(int j= 0; j<48; j++){   //2 byte values
-//            ptr[counter++] = 0;     ptr[counter++] = 65;
-//        }
-//        for(int j=96; j <100 ; j++){
-//            ptr[counter++] = 0;     ptr[counter++] = 0;     ptr[counter++] = 0;     ptr[counter++] = 65;    
-//        }
-//        ptr = ptr+112;
-//        counter = 0;
-//    }
-//    srp(payload_data);
-//    
-//     gPC.puts("data given to payload");
-//    while(true){
-//        gSCIENCE_THREAD->wait(osWaitForever);
-//    }
-//    while(true){
+void SCIENCE_FUN(void const *args){
+    uint8_t *ptr;
+    gPC.puts("haha\r\n");
+    ptr = &(payload_data[3]);
+    gPC.puts("haha2\r\n");
+    int counter = 0;
+    gPC.puts("haha3\r\n");
+    payload_data[2] = 0;//for mode
+    for(int i = 0; i<60 ;i++){      //for mode 0.....callibra
+        for(int j= 0; j<48; j++){   //2 byte values
+            ptr[counter++] = 0;     ptr[counter++] = 65;
+        }
+        for(int j=96; j <100 ; j++){
+            ptr[counter++] = 0;     ptr[counter++] = 0;     ptr[counter++] = 0;     ptr[counter++] = 65;    
+        }
+        ptr = ptr+112;
+        counter = 0;
+    }
+     //srp(payload_data);
+    
+     //gPC.puts("data given to payload");
+     gLEDR = 1;
+     gSCIENCE_THREAD->wait(2000); gSCIENCE_THREAD->terminate();
+     
+    /*while(true){
+        gSCIENCE_THREAD->wait(osWaitForever);
+    }*/
+    //while(true){
 //        gSCIENCE_THREAD->signal_wait(SCIENCE_SIGNAL);
 //        srp(payload_data);
 //    }
-//}
+}
 
 
 
--- a/adf.h	Mon Jan 25 06:22:29 2016 +0000
+++ b/adf.h	Mon Jan 25 13:10:43 2016 +0000
@@ -292,7 +292,7 @@
     /*gPC.puts("initial adf check\r\n");*/\
     initiate;\
     /*gPC.puts("adf configured\r\n");*/\
-    gLEDR = !gLEDR;\
+    /*gLEDR = !gLEDR;*/\
 }
  
 #define transmit_adf {\
@@ -313,11 +313,13 @@
                     SPI_mutex.unlock();\
                     loop_on = false;\
                     gPC.puts("Transmission done\r\n");\
+                    gLEDR = 1;\
                 }\
                 else{\
                     ADF_off = true;\
                 }\
-            }else{\   
+            }else{\ 
+                gLEDR = !gLEDR;\  
                 write_data;\
                 if(sent_tmfrom_SDcard)\
                 send_tm_from_SD_card_fun();\
--- a/cdms_rtc.h	Mon Jan 25 06:22:29 2016 +0000
+++ b/cdms_rtc.h	Mon Jan 25 13:10:43 2016 +0000
@@ -74,7 +74,7 @@
     spi.write(0x87); 
     spi.write(0x01); //set year to 00(2000)
     gCS_RTC=1;
-    printf("\n\r rtc initalised \n");
+//    printf("\n\r rtc initalised \n");
     SPI_mutex.unlock();
 }
  
@@ -82,7 +82,7 @@
 {    
     SPI_mutex.lock();
     uint8_t response;
-    printf("\n\r Entered rtc\n");
+    //printf("\n\r Entered rtc\n");
     gCS_RTC=1;
     gCS_RTC=0;
     spi.write(0x00); //reading milliseconds register
@@ -132,9 +132,9 @@
     gCS_RTC=1;
     //sprintf(Time_stamp,"%02d%02d%02d%02d%02d%02d%02d%02d",year, month, date, day, hours, minutes, seconds, milliseconds );
     uint8_t Time_stamp[8] = {year, month, date, day, hours, minutes, seconds, centiseconds};
-    for(int i= 0; i<8;i++)
-        printf("%d\t",Time_stamp[i]);
-    printf("read\r\n");
+    for(int i= 0; i<8;i++);
+        //printf("%d\t",Time_stamp[i]);
+    //printf("read\r\n");
     uint64_t time;
     time = 0;
     time = time|(((uint64_t)(centiseconds&0x7F)));
@@ -146,7 +146,7 @@
     time = time|(((uint64_t)(year&0x03))<<33);
     time = (time&0x00000007FFFFFFFF);
     //printf("\n\r%x%x", (int)(time >> 32), (int)(time));
-    printf("\n\r0x%016llx\n\r", time);
+    //printf("\n\r0x%016llx\n\r", time);
    return time;
    SPI_mutex.unlock();
 }
\ No newline at end of file
--- a/cdms_sd.h	Mon Jan 25 06:22:29 2016 +0000
+++ b/cdms_sd.h	Mon Jan 25 13:10:43 2016 +0000
@@ -269,11 +269,11 @@
 // send CMD8 to determine whther it is ver 2.x
     int r = cmd8();
     if (r == R1_IDLE_STATE) {
-        printf("\rEntering v2\r\n");
+//        printf("\rEntering v2\r\n");
         return initialise_card_v2();
 
     } else if (r == (R1_IDLE_STATE | R1_ILLEGAL_COMMAND)) {
-        printf("\rEntering v1\r\n");
+//        printf("\rEntering v1\r\n");
         return initialise_card_v1();
 
     } else {
@@ -287,7 +287,7 @@
     for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) {
         cmd(55, 0);
         if (cmd(41, 0) == 0) {
-            printf("\rv1 initialization successfull\r\n");
+            gPC.puts("\rv1 initialization successfull\r\n");
             cdv = 512;
             debug_if(SD_DBG, "\n\rInit: SEDCARD_V1\n\r");
 
@@ -307,7 +307,7 @@
         cmd58();
         cmd(55, 0);
         if (cmd(41, 0x40000000) == 0) {
-            printf("\rv2 initialization successfull\r\n");
+//            printf("\rv2 initialization successfull\r\n");
             cmd58();
             debug_if(SD_DBG, "\n\rInit: SDCARD_V2\n\r");
             cdv = 1;
@@ -513,7 +513,7 @@
         debug("\rSet 512-byte block timed out\r\n");
         return 1;
     } else {
-        printf("\rDisk initialization successfull\r\n");
+//        printf("\rDisk initialization successfull\r\n");
     }
 
     spi.frequency(1000000); // Set to 1MHz for data transfer
--- a/i2c.h	Mon Jan 25 06:22:29 2016 +0000
+++ b/i2c.h	Mon Jan 25 13:10:43 2016 +0000
@@ -4,13 +4,13 @@
 
 DigitalOut irpt_2_slv(PIN67);                                        //I2C interrupt to CDMS
 I2C master(PIN32,PIN31);
-DigitalOut led1(PIN46);
-DigitalOut led2(PIN95);
+//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;
+//Timer test;
+//Timer t_read;
 bool write_ack = true;
 bool read_ack = true;
 
@@ -27,9 +27,9 @@
        
 if (write_ack == 1)
     {
-        led2 = 1;
+//        led2 = 1;
         //gPC.printf("\n\r data not sent \n");
-        led2 = 0;    
+//        led2 = 0;    
     }
     irpt_2_slv = 0;
     //gPC.printf("\n\r %d \n",t.read_us());
@@ -40,17 +40,17 @@
 void FCTN_I2C_READ(char *data)
 {
     irpt_2_slv = 1; 
-    t_read.start();
+//    t_read.start();
     read_ack = master.read(addr|1,data,tm_len);
-    t_read.stop();
+ //   t_read.stop();
    
     //if(read_ack == 0)
       //  gPC.printf("\n\rData received from BAE %s \n",data);
  if (read_ack == 1)
     {
-        led2 = 1;
+//        led2 = 1;
         //gPC.printf("\n \r data not received \n");
-        led2 = 0;
+//        led2 = 0;
     }
 //if(read_ack == 1)
 //gPC.printf("\n \r data not received \n");
--- a/main.cpp	Mon Jan 25 06:22:29 2016 +0000
+++ b/main.cpp	Mon Jan 25 13:10:43 2016 +0000
@@ -18,11 +18,13 @@
 #include "COM_MNG_TMTC.h"
 #include "COM_POWER_ON_TX.h"
 #include "COM_POWER_OFF_TX.h"
-//#include "Compression.h"
+#include "Compression.h"
 #include "ThreadsAndFunctions.h"
 
 int main()
 {
+    gLEDR = 1;
+    
     // ******************INITIALISATIONS START******************
     // COM RX
     RX1M.baud(1200);
@@ -62,16 +64,30 @@
     gCOM_MNG_TMTC_THREAD = new Thread(COM_MNG_TMTC_FUN);
     gCOM_MNG_TMTC_THREAD->set_priority(osPriorityAboveNormal);
     gPC.puts("allocating threads\r\n");
-    //gSCIENCE_THREAD = new Thread(SCIENCE_FUN);
+    gSCIENCE_THREAD = new Thread(SCIENCE_FUN);
    // gPC.puts("step one complete\r\n");
-    //gSCIENCE_THREAD->set_priority(osPriorityAboveNormal);
+    gSCIENCE_THREAD->set_priority(osPriorityBelowNormal);
     gPC.puts("competed allocating threads\r\n");
     // *******************INITIALISATIONS END********************
     
     /*Calculating Stack used*/
     
-    int theAcount = 0;
+    int state;
+    /*while (true) { 
+    Thread::wait(500); 
+    state = gSCIENCE_THREAD->get_state(); 
+    //gPC.printf("Thread state %d\r\n", state); 
+    if(state == Thread::Inactive) 
+    {delete gSCIENCE_THREAD;
+    break;}
+    }*/
+    
+    
+    
     while(true){
-        Thread::wait(osWaitForever);
+        Thread::wait(500);
+        //state = gCOM_MNG_TMTC_THREAD->get_state() + '0';
+         gLEDG = !gLEDG;
+        //gPC.putc(state); 
     }
 }
\ No newline at end of file