CDMS code for testing sbc

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

Files at this revision

API Documentation at this revision

Comitter:
ee12b079
Date:
Thu Jul 21 13:18:02 2016 +0000
Parent:
268:ded5306a1fd1
Child:
270:5be8e2449dc3
Child:
275:a2f1d544ab8b
Commit message:
Testing OBSRS TM and adf and srp

Changed in this revision

CDMS_HK.h Show annotated file Show diff for this revision Revisions of this file
COM_POWER_ON_TX.h Show annotated file Show diff for this revision Revisions of this file
COM_SND_TM.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
DefinitionsAndGlobals.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
adf.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/CDMS_HK.h	Wed Jul 20 09:58:59 2016 +0000
+++ b/CDMS_HK.h	Thu Jul 21 13:18:02 2016 +0000
@@ -104,12 +104,12 @@
         gPC.puts("sd write failure");
         break;
         }
-    gPC.printf("Completed CDMS HK\t");
+    /*gPC.printf("Completed CDMS HK\t")*/;
 
     /*---------------------------------- BAE HK --------------------------------------------*/
 
     BAE_HK_I2C = FCTN_I2C_READ(BAE_HK,134);
-    gPC.printf("Entering BAE HK\t");
+    /*gPC.printf("Entering BAE HK\t")*/;
     if(BAE_HK_I2C == 0) {
         crc = crc16_gen((unsigned char *)BAE_HK,132);
         if(crc == ((uint16_t)BAE_HK[132] << 8) | (uint16_t)BAE_HK[133]){
@@ -143,11 +143,11 @@
         }
         
     } else {
-        gPC.printf("BAE HK data not recieved through I2C\t");
+        /*gPC.printf("BAE HK data not recieved through I2C\t")*/;
         for(int i = 0; i<134; i++)
             BAE_HK[i] = 0;
     }
-    gPC.printf("Completed BAE HK\n");
+    /*gPC.printf("Completed BAE HK\n")*/;
 
     /*----------------------------------Beacon message--------------------------------------*/
     unsigned char SC_HK_LBM_0[135];
@@ -161,10 +161,10 @@
     bool y;
     y = FCTN_I2C_WRITE((char *)SC_HK_LBM_0,135);
     if(y == 0)
-        gPC.printf("long Bcn sent\n\r");
+        /*gPC.printf("long Bcn sent\n\r")*/;
         else
         gPC.printf("long Bcn not sent\r\n");
-    gPC.printf("\rCompleted Beacon\n");
+    gPC.printf("\rCompleted HK\n");
     gMutex.unlock();
     }
 }
--- a/COM_POWER_ON_TX.h	Wed Jul 20 09:58:59 2016 +0000
+++ b/COM_POWER_ON_TX.h	Thu Jul 21 13:18:02 2016 +0000
@@ -127,6 +127,7 @@
                 SET_BCN_STANDBY(tm_ptr);
                 gPC.puts("set Bcn off\r\n");
                 uint8_t bcn_main_status = (tm_ptr->TM_string[2] & 0xEF);
+                gPC.printf("bcn_main_status = 0x%02X\r\n",bcn_main_status);
                 if(( bcn_main_status == 0xC0 )||( bcn_main_status ==0xA0 )){
                     /*ACK RECCEIVED*/
                     if( bcn_main_status == 0xA0 ){
--- a/COM_SND_TM.h	Wed Jul 20 09:58:59 2016 +0000
+++ b/COM_SND_TM.h	Thu Jul 21 13:18:02 2016 +0000
@@ -1,35 +1,5 @@
-//void adf_not_SDcard();
- 
-//~ #include"SDcard.h"
-/*#define T_frames 30
-unsigned char buffer_112_counter,sent_tm = 0;
-int disk_read(uint8_t *, uint64_t),j;
-bool new_session = true;
-bool last_buffer = false;
-bool first_block = true;
-bool last_block =false;
-bool repeat_T_frame = false;
-unsigned int counter_in_block=0,diff_prev=0;
-unsigned char  EOS_counter = 0;
-unsigned char enable_T_frame = false;
-uint64_t  start_block_num ;           // Read from TC
-uint64_t  end_block_num ;            // Read from TC
-uint64_t  Number_of_blocks_to_read ;
-uint64_t  block_counter = 0;
-unsigned char buffer_512[512], buffer_112[112],counter_in_S_frame=0,counter_in_SCH=0;
-unsigned char make_EOS_flag = true;
-bool reset = false; */
- 
- 
- 
- 
- 
- 
- 
 bool sent_tmfrom_SDcard;
- 
- 
- 
+bool restart_adf_flag=false;
 #define S_FRAME_SIZE 48
 #define ISR 40
 #define TM_FRAME_SIZE 134           //in bytes
@@ -50,8 +20,6 @@
     }\
 }
  
-//void send_tm_from_SD_card(){} 
- 
 class SND_TM{
  
     Base_tm * head_ptr;
@@ -274,8 +242,6 @@
  
 //
     public:
- 
-        bool reset_adf;
         SND_TM(){
             MAX_SEGMENT = (MAX_ADF_LEN-EOS_SIZE)/( S_FRAME_SIZE + ISR*T_FRAME_SIZE);
                             //(max length - eos size)/(sframe length + tFrameLength*ISR)
@@ -324,7 +290,7 @@
                 data_f = false;
                 FCCH80_f = false;
                 transmit_data_f = false;
-                reset_adf = false;
+                restart_adf_flag = false;
                 *last_buffer = false;
             }
  
@@ -429,7 +395,7 @@
                                 }
                                 if(SEGMENT_NO == 1) segment_r = 0; else segment_r = 1; 
                                 TOTAL_SEGMENT_NO -= SEGMENT_NO;
-                                reset_adf = true;//what does this do??
+                                restart_adf_flag = true;//what does this do??
                                 Sframe = true;
                                 junk_f = true;
                            }
@@ -439,7 +405,7 @@
                 }
             }
             differential_encode(transmit,112);
-            if(reset_adf == true){
+            if(restart_adf_flag == true){
                 diff_prev = 0;
                 junk_f = false;
             }
--- a/Compression.h	Wed Jul 20 09:58:59 2016 +0000
+++ b/Compression.h	Thu Jul 21 13:18:02 2016 +0000
@@ -427,7 +427,8 @@
                 if(id == 1){    //below threshold
                     space = adjust(1,0,pointer,8);
                     space = adjust(4,3,pointer,space);
-                    FSC_science = FSC_CURRENT[3];                               ///to be used as this, but FSC_CURRENT[] is 32 bit                    
+                    FSC_science = FSC_CURRENT[3];                               ///to be used as this, but FSC_CURRENT[] is 32 bit 
+                    gPC.printf("3 = 0x%X",FSC_science);                   
                     frames[id][1] = (FSC_science>>24)&0xff;
                     frames[id][2] = (FSC_science>>16)&0xff;
                     frames[id][3] = (FSC_science>>8)&0xff;
@@ -438,6 +439,7 @@
                     space = adjust(1,0,pointer,8);
                     space = adjust(4,2,pointer,space);                    
                     FSC_science = FSC_CURRENT[2];                                               ///to be used as this
+                    gPC.printf("2 = 0x%X",FSC_science);
                     frames[id][1] = (FSC_science>>16)&0xff;
                     frames[id][2] = (FSC_science>>8)&0xff;
                     frames[id][3] = FSC_science&0xff;
@@ -1121,6 +1123,7 @@
             space = adjust(1,0,pointer,8);
             space = adjust(4,1,pointer,space);
             FSC_science = FSC_CURRENT[1];
+            gPC.printf("1 = 0x%X",FSC_science);
             frames[id][1] = (FSC_science>>16)&0xff;
             frames[id][2] = (FSC_science>>8)&0xff;
             frames[id][3] = (FSC_science)&0xff;
--- a/DefinitionsAndGlobals.h	Wed Jul 20 09:58:59 2016 +0000
+++ b/DefinitionsAndGlobals.h	Thu Jul 21 13:18:02 2016 +0000
@@ -1,6 +1,5 @@
 // **************DEFINITIONS*********************
 
-#define bypass_adf 0
 #define dma 0
 
 // COM_RX
@@ -292,7 +291,7 @@
 
 DigitalIn SD_OC_FAULT (PIN90);
 DigitalOut SD_SW_EN_DS (PIN97);
-DigitalOut BAE_SW_EN_DS (PIN47);
+DigitalOut BAE_SW_EN_DS (PIN47,1);
 DigitalOut TRXY_EN (PIN84);
 DigitalOut TRZ_EN (PIN88);
 DigitalOut V_A_EN (PIN99);
--- a/OBSRS.h	Wed Jul 20 09:58:59 2016 +0000
+++ b/OBSRS.h	Thu Jul 21 13:18:02 2016 +0000
@@ -256,7 +256,7 @@
         if(counter_EoS == 120){\
             counter_EoS = 0;\
             /*gPC.printf("EoS sent");*/\
-            restart_adf();\
+            restart_adf_flag = true;\
             enable_new_segment = true;\
             /*cout<<"new session"<<ENDL;*/\
             /*cout<<"new segment"<<ENDL;*/\
@@ -358,7 +358,9 @@
 void send_tm_from_SD_card_fun(){
 /*    gPC.printf("\n\rsend tm sd called\r\n");*/
     for(counter_buffer_112=0;counter_buffer_112<112;counter_buffer_112++){
-        if(enable_new_segment){                     // starting new segment
+        if(restart_adf_flag)
+            buffer_112[counter_buffer_112] = 0;
+        else if(enable_new_segment){                     // starting new segment
             send_S_frame;
             T_frames_sent=0;
         }
@@ -543,7 +545,6 @@
 //                delete ack_and_callsign;
 //                ack_and_callsign = temp;
             }
-            
         }
         else if(last_buffer){
             /*gPC.printf("last buffer2");*/
--- a/adf.h	Wed Jul 20 09:58:59 2016 +0000
+++ b/adf.h	Thu Jul 21 13:18:02 2016 +0000
@@ -85,7 +85,7 @@
 buffer_state = true;\
 loop_on = true;\
 ADF_off = false;\
-sent_tmfrom_SDcard = false;\
+/*sent_tmfrom_SDcard = false;*/\
 Adf_data_counter=0;\
 status =0;\
 cmd_err_cnt=0;\
@@ -161,32 +161,37 @@
     gCS_ADF=1;\
     status = stat;\
 }
+/***********************/
+/**********Restart ADF**************/
+
+/**************************/
 
 /*CMD_VAR*/
 bool cmd_bit=true;
 bool cmd_err_flag=false;
 unsigned char command = 0x00;
-#define CMD(command) {\
-    cmd_err_cnt=0;\
-    cmd_err_flag=false;\
-    while(cmd_err_cnt<3) {\
-        check_status;\
-        cmd_bit=status&0x20;\
-        if(cmd_bit) {\
-            gCS_ADF=0;\
-            spi.write(command);\
-            gCS_ADF=1;\
-            break;\
-        } else {\
-            wait_us(5);\
-            cmd_err_cnt++;\
-        }\
-    }\
-    if(cmd_err_cnt==3) {\
-        cmd_err_flag=true;\
-    }\
+void CMD(uint8_t command) {
+    cmd_err_cnt=0;
+    cmd_err_flag=false;
+    while(cmd_err_cnt<3) {
+        check_status;
+        cmd_bit=status&0x20;
+        if(cmd_bit) {
+            gCS_ADF=0;
+            spi.write(command);
+            gCS_ADF=1;
+            break;
+        } else {
+            wait_us(5);
+            cmd_err_cnt++;
+        }
+    }
+    if(cmd_err_cnt==3) {
+        cmd_err_flag=true;
+    }
 }
-// all three arguments are int\
+
+// all three arguments are int
 #define assrt_phy_off {\
     int state_err_cnt = 0;\
     CMD(CMD_PHY_OFF);\
@@ -323,6 +328,11 @@
 
 #define write_data {\
     counter++;\
+    if(counter==584){\
+        finish_write_data=true;\
+        restart_adf_flag=true;\
+        counter=0;\
+        }\
     gCS_ADF=0;\
         spi.write(0x0B);\
         spi.write(0x36);\
@@ -336,9 +346,6 @@
             spi.write(0x18);\
             spi.write(0x20);\
             for(unsigned char i=0; i<112;i++){\
-                if(bypass_adf)\
-                    gPC.putc(buffer_112[i]);\
-                else\
                     spi.write(buffer_112[i]);\
                     /*gPC.printf("0x%X,",spi.write(buffer_112[i]));*/\
             }\
@@ -347,9 +354,6 @@
             spi.write(0x18);\
             spi.write(0x90);\
             for(unsigned char i=0; i<112;i++){\
-                if(bypass_adf)\
-                    gPC.putc(buffer_112[i]);\
-                else\
                     spi.write(buffer_112[i]);\
                 /*gPC.printf("0x%X,",spi.write(buffer_112[i]));*/\
             }\
@@ -389,10 +393,10 @@
 #define check {\
     check_status;\
     /*gPC.printf("I 0x%X\r\n",(int)status);*/\
-    if(IRQ || bypass_adf){\
+    if(IRQ){\
         /*gPC.printf("det\r\n");*/\
         if(!ADF_off) {\
-            if(finish_write_data) {\
+            if(finish_write_data || restart_adf_flag) {\
                 write_data;\
                 ADF_off=true;\
             } else {\
@@ -408,15 +412,25 @@
             gCS_ADF=1;\
             gPC.puts("transmission done\r\n");\
             loop_on=false;\
+            if(restart_adf_flag)\
+            {\
+                restart_adf_flag=false;\
+                ADF_off=false;\
+                send_data;\
+                loop_on=true;\
+                CMD(CMD_PHY_TX);\
+                wait_us(2000);\
+                }\
+            /*Stop_the_Timer*/\
         }\
     }\
-    else{\
-        if(T.read_us()>98000){\
-                data_irq_err=true;\
-                CMD(CMD_PHY_ON);\
-                gPC.printf("Data_error_detected");\
-                }\        
-        }\
+    /*else{*/\
+        /*if(T.read_us()>98000){*/\
+                /*data_irq_err=true;*/\
+                /*CMD(CMD_PHY_ON);*/\
+                /*gPC.printf("Data_error_detected");*/\
+                /*}*/\        
+        /*}*/\
 }
 
 #define send_data {\
@@ -557,6 +571,8 @@
 }
  
 #define transmit_adf {\
+    restart_adf_flag=false;\
+    bool tx_err=false;\
     configure_adf;\
     send_data;\
     CMD(CMD_PHY_TX);\
@@ -564,10 +580,9 @@
     while(loop_on){\
         wait_us(20);\
         check;\
-        if(data_irq_err){\
+        if(data_irq_err||tx_err){\
         break;\
         }\
     }\
     /*gPC.puts("after while loop\r\n");*/\
 }
-
--- a/main.cpp	Wed Jul 20 09:58:59 2016 +0000
+++ b/main.cpp	Thu Jul 21 13:18:02 2016 +0000
@@ -91,8 +91,8 @@
     
     master.frequency(400000);
     
-    /*HK_counter = new RtosTimer(hk_isr, osTimerPeriodic,(void * )NULL);
-    HK_counter->start(10000);*/
+    HK_counter = new RtosTimer(hk_isr, osTimerPeriodic,(void * )NULL);
+    //HK_counter->start(10000);
     
     sys_reset_cdms_timer = new RtosTimer(sys_pwr_reset, osTimerPeriodic, (void * )NULL);
     sys_reset_cdms_timer->start(cdms_reset_timeout);