
Repository for CDMS code
Dependencies: SimpleDMA mbed-rtos mbed eeprom
Fork of COM_MNG_TMTC_SIMPLE by
Revision 9:e9eaada136c6, committed 2015-12-31
- Comitter:
- ee12b079
- Date:
- Thu Dec 31 10:19:12 2015 +0000
- Parent:
- 7:fcd26c28411d
- Child:
- 10:414fde3ef107
- Commit message:
- changed adf.h and COM_SND_TM.h files
Changed in this revision
COM_SND_TM.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 |
--- a/COM_SND_TM.h Thu Dec 31 10:06:45 2015 +0000 +++ b/COM_SND_TM.h Thu Dec 31 10:19:12 2015 +0000 @@ -1,21 +1,21 @@ void adf_not_SDcard(); #define S_FRAME_SIZE 48 -#define ISR 30 +#define ISR 40 #define TM_FRAME_SIZE 134 //in bytes #define T_FRAME_SIZE 159 #define EOS_SIZE 120 -#define MAX_ADF_LEN 65535 - +#define MAX_ADF_LEN 65535 + const unsigned char S_frame[] = {0x46,0x9D,0xFB,0xF0,0xD2,0xBA,0x89,0xE4,0x46,0x9D,0xFB,0xF0,0xD2,0xBA,0x89,0xE4,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; const unsigned char EoS[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x1A,0x77,0xEF,0xC3,0x4A,0xEA,0x27,0x91,0x1A,0x77,0xEF,0xC3,0x4A,0xEA,0x27,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x1A,0x77,0xEF,0xC3,0x4A,0xEA,0x27,0x91,0x1A,0x77,0xEF,0xC3,0x4A,0xEA,0x27,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; const unsigned char FCCH80[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; const unsigned char SCH40[] = {0x0a,0x3f,0x46,0xb4,0x00}; - + class SND_TM{ - - Base_tm * head_ptr; - + + Base_tm * head_ptr; + // transmit data variables unsigned char Tframe_c; //_c represents counter, counts Tframe written in a segment unsigned char EOS_c; //count no of bytes of eos have been weitten in the rolling buffer @@ -30,15 +30,17 @@ bool SCH40_f; bool FCCH80_f; bool data_f; + bool repeat_data_f; bool transmit_data_f; bool eos_f; bool junk_f; - - + bool segment_r; //flag checking if more sessions are required + + // type 1 frame - + Base_tm *T0F_pointer ; - + int diff_prev; void differential_encode(unsigned char* ptr, int length){ for(int i=0; i<length;i++){ @@ -48,18 +50,20 @@ diff_prev = int(s & 0x01); ptr[i] = t; } - } - + } + int type0_no; //number of type zero frames - int type1_no; + int type1_no; int total_frames; //number of type one packe (TMP) int SEGMENT_NO; //number of type one packe (TMP) + int TOTAL_SEGMENT_NO; + int LAST_SEGMENT_SIZE; void inline data_number(){ int type1_frame_no; Base_tm*head = head_ptr; type0_no = 0; type1_no = 0; - while(head != NULL){ + while(head->next_TM != NULL){ switch( GETshort_or_long_tm(head->fields) ){ case 0: type0_no++; @@ -68,13 +72,23 @@ type1_no++; break; } + head=head->next_TM; } type1_frame_no = ( type1_no % 10 == 0 )? (type1_no / 10) : ( (type1_no / 10) + 1); total_frames = type0_no + type1_frame_no ; - SEGMENT_NO = (total_frames*2 % (ISR) == 0) ? ( total_frames*2/(ISR) ) : (total_frames*2/(ISR) + 1); //subtracting 1 since the last SCH40_f is not detected + TOTAL_SEGMENT_NO = (total_frames*2 % (ISR) == 0) ? ( total_frames*2/(ISR) ) : (total_frames*2/(ISR) + 1); //subtracting 1 since the last SCH40_f is not detected + SEGMENT_NO = TOTAL_SEGMENT_NO; + if(SEGMENT_NO > MAX_SEGMENT) + { + SEGMENT_NO = MAX_SEGMENT; + segment_r = 1; + } + else segment_r = 0; + TOTAL_SEGMENT_NO -= SEGMENT_NO; + LAST_SEGMENT_SIZE = total_frames*2%ISR; } - + #define next_type_structure(ptr){\ unsigned char temp = GETshort_or_long_tm(ptr->fields);\ if((temp == 0) && (ptr->next_TM != NULL) ){\ @@ -85,7 +99,6 @@ while(temp == 1 && ptr->next_TM != NULL);\ if(temp == 1){\ ptr = NULL;\ - break;\ }\ }\ else if((temp == 1) && (ptr->next_TM != NULL)){\ @@ -95,19 +108,18 @@ }\ while(temp == 0 && ptr->next_TM != NULL);\ if(temp == 0){\ - ptr NULL;\ - break;\ + ptr = NULL;\ }\ }\ else{\ - ptr NULL;\ + ptr = NULL;\ }\ } - + /* brief: take input type 0 or 1 and return the address of the first node in the list that have that type parameter: type 0 or 1 - return: pointer of the first node having same type + return: pointer of the first node having same type */ // Base_tm* first_type_structure(int type){ // Base_tm* temp_ptr = head_ptr; @@ -116,21 +128,21 @@ // temp_ptr = temp_ptr->next_TM; // if(temp_ptr == NULL){ // return NULL ; -// } -// } +// } +// } // } // else if(type == 1){ // while(GETshort_or_long_tm(temp_ptr->fields) == 0){ // temp_ptr = temp_ptr->next_TM; // if(temp_ptr == NULL){ -// return NULL; -// } -// } -// } +// return NULL; +// } +// } +// } // return temp_ptr; // } - - + + #define first_type_structure( type,return_ptr) {\ Base_tm* temp_ptr = head_ptr;\ if(type == 0){\ @@ -151,14 +163,14 @@ }\ return_ptr = temp_ptr;\ } - - - + + + Base_tm *T1F_pointer ; int T1F_counter; unsigned char TMframe_type1[TM_FRAME_SIZE]; bool type1_frame_flag; //should be true for every new list - + #define type1_frame(ptr){\ int i=4;\ if(type1_frame_flag){\ @@ -180,9 +192,10 @@ TMframe_type1[i] = TMframe_type1[i-13];\ }\ }\ + ptr=TMframe_type1;\ } - - + + // unsigned char * type1_frame(){ // int i=4; // if(type1_frame_flag){ @@ -204,15 +217,15 @@ // //end header // if(T1F_pointer == NULL && i>12){ // for( ; i < 134 ; i++){ //repeating ;ast packet to fill up the extra space -// TMframe_type1[i] = TMframe_type1[i-13]; +// TMframe_type1[i] = TMframe_type1[i-13]; // } // } // return TMframe_type1; // } - + bool type0_frame_flag; - - + + #define type0_frame(ptr){\ if(type0_frame_flag){\ first_type_structure(0,T0F_pointer);\ @@ -223,28 +236,28 @@ }\ ptr = T0F_pointer->TM_string;\ } - - + + // unsigned char* type0_frame(){ // if(type0_frame_flag){ -// T0F_pointer = first_type_structure(0); +// T0F_pointer = first_type_structure(0); // type0_frame_flag = false; -// } +// } // else { // T0F_pointer = next_type_structure(T0F_pointer); // } // return T0F_pointer->TM_string; // } - - unsigned char convoluted_frame[270]; + + unsigned char convoluted_frame[270]; Convolution ConvObj2; void convolution (unsigned char * ptr){ ConvObj2.convolutionEncode(ptr, convoluted_frame); ConvObj2.convolutionEncode(ptr + 67, convoluted_frame + 135); } - - - unsigned char interleave_data[2][144]; + + + unsigned char interleave_data[2][144]; unsigned char DS_index; bool DS_state; int DS_counter; @@ -278,17 +291,49 @@ // }\ // DS_index = (DS_state==true)?1:0;\ // } - + +#define make_DataStream {\ + unsigned char* ptr;\ + if(make_DataStream_f == true){\ + DS_state = true;\ + DS_counter = 0;\ + DS_f = false;\ + make_DataStream_f = false;\ + }\ + if(DS_state){\ + if(DS_counter < total_frames-type0_no){\ + type1_frame(ptr); \ + DS_f = true;\ + }\ + else if(DS_counter < total_frames ){\ + type0_frame(ptr);\ + DS_f = true;\ + }\ + DS_counter++;\ + }\ + DS_state = !DS_state;\ + if (DS_f){\ + DS_f = false;\ + convolution(ptr);\ + interleave(convoluted_frame,interleave_data[0]);\ + interleave(convoluted_frame+ 135,interleave_data[1]);}\ + DS_index = (DS_state==true)?1:0;\ + } + + +// public: - + bool reset_adf; SND_TM(){ - MAX_SEGMENT = (MAX_ADF_LEN-T_FRAME_SIZE)/( S_FRAME_SIZE + ISR*T_FRAME_SIZE); //(max length - eos size)/(sframe length + tFrameLength*ISR) + MAX_SEGMENTMAX_SEGMENT = (MAX_ADF_LEN-EOS_SIZE)/( S_FRAME_SIZE + ISR*T_FRAME_SIZE); + //MAX_SEGMENT = 1; + //(max length - eos size)/(sframe length + tFrameLength*ISR) // cout<<int(MAX_SEGMENT)<<endl; } - + - + void head_pointer(Base_tm* ptr){ head_ptr = ptr ; type1_frame_flag = true; @@ -297,11 +342,11 @@ transmit_data_f = true; diff_prev = 0; data_number(); -// make_DataStream; - gPC.putc('z'); + // make_DataStream; +// gPC.putc('z'); } - - + + void inline transmit_data(unsigned char * transmit , bool * last_buffer){ if(transmit_data_f){ RB_c = 0; @@ -312,7 +357,7 @@ EOS_c = 0; segment_c = 0; data_c = 0; - + Sframe = true; SCH40_f = false; data_f = false; @@ -321,13 +366,14 @@ reset_adf = false; *last_buffer = false; } - + for(RB_c = 0 ; RB_c<112 ; RB_c++){ - - if(junk_f){ - transmit[RB_c] = 0xaa; + + if(junk_f || *last_buffer){ + transmit[RB_c] = 0x00; + continue; } - + if(Sframe){ transmit[RB_c] = S_frame[Sframe_c++]; if(Sframe_c == 48){ @@ -338,22 +384,32 @@ } continue; } -// +// if(SCH40_f){ - transmit[RB_c] = SCH40[SCH40_c++]; + transmit[RB_c] = SCH40[SCH40_c++]; if(SCH40_c == 5 ){ SCH40_c = 0; - SCH40_f = false; - data_f = true; + SCH40_f = false; + + + if(Tframe_c >= LAST_SEGMENT_SIZE && segment_r == 0) + { + repeat_data_f = true; + DS_index = !DS_index; + } + else + { + data_f = true; + make_DataStream; + } // printf("exit SCH40 frame\n"); } continue; } -// +// if(data_f){ transmit[RB_c] = interleave_data[DS_index][data_c++]; if(data_c == 144){ -// make_DataStream; data_c = 0; FCCH80_f = true; data_f = false; @@ -361,7 +417,17 @@ } continue; } - + if(repeat_data_f){ + transmit[RB_c] = interleave_data[DS_index][data_c++]; + if(data_c == 144){ + data_c = 0; + FCCH80_f = true; + repeat_data_f = false; +// printf("exit Data\n"); + } + continue; + } + if(FCCH80_f){ transmit[RB_c] = FCCH80[FCCH80_c++]; if(FCCH80_c == 10){ @@ -369,11 +435,11 @@ FCCH80_f = false; // printf("exit FCCH80\n"); if(++Tframe_c != ISR) - SCH40_f = true; + SCH40_f = true; else{ Tframe_c = 0; segment_c++; - if(segment_c == SEGMENT_NO||segment_c == MAX_SEGMENT) + if(segment_c == SEGMENT_NO) {eos_f = true;} else{ Sframe = true; @@ -381,35 +447,50 @@ } } continue; - } - - if(eos_f){ + } + + if(eos_f){ transmit[RB_c] = EoS[EOS_c++]; if(EOS_c == EOS_SIZE){ EOS_c = 0; eos_f = false; // printf("exit EOS\n"); - if(segment_c == MAX_SEGMENT){ - segment_c = 0; - SEGMENT_NO = SEGMENT_NO - MAX_SEGMENT; - reset_adf = true; - Sframe = true; - }else{ - *last_buffer = true; - } +// if(segment_c == MAX_SEGMENT){ +// segment_c = 0; +// SEGMENT_NO = SEGMENT_NO - MAX_SEGMENT; +// reset_adf = true;//what does this do?? +// Sframe = true; +// }else{ +// *last_buffer = true; +// } + if(segment_c == SEGMENT_NO && segment_r == 0){ + *last_buffer = true; + } + else if(segment_c == SEGMENT_NO && segment_r != 0){ + segment_c = 0; + SEGMENT_NO = TOTAL_SEGMENT_NO; + if(SEGMENT_NO > MAX_SEGMENT) + { + SEGMENT_NO = MAX_SEGMENT; + segment_r = 1; + } + else segment_r = 0; + TOTAL_SEGMENT_NO -= SEGMENT_NO; + reset_adf = true;//what does this do?? + Sframe = true; + } junk_f = true; } continue; - } + } } - differential_encode(transmit,112); if(reset_adf == true){ diff_prev = 0; junk_f = false; } - + } - + }; SND_TM snd_tm; \ No newline at end of file
--- a/adf.h Thu Dec 31 10:06:45 2015 +0000 +++ b/adf.h Thu Dec 31 10:19:12 2015 +0000 @@ -1,17 +1,18 @@ //without reset feature , with state checks. InterruptIn IRQ(ADF_IRQ); Ticker ticker; - + bool sent_tmfrom_SDcard; bool loop_on; bool ADF_off; bool buffer_state; +bool finish_write_data; uint8_t signal = 0x00; unsigned char bbram_buffer[66]={0x19,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0xF4,0xC2,0x10,0xC0,0x00,0x30,0x31,0x07,0x00,0x01,0x00,0x7F,0x00,0x0B,0x37,0x00,0x00,0x40,0x0C,0x00,0x05,0x00,0x00,0x18,0x12,0x34,0x56,0x10,0x10,0xC4,0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00}; - + //int initialise_card(); //int disk_initialize(); - + #define bbram_write {\ SPI_mutex.lock();\ gCS_ADF=0;\ @@ -30,7 +31,7 @@ //bool assrt_phy_off( int, int, int); //bool assrt_phy_on( int,int,int); //bool assrt_phy_tx(int,int,int); - + #define START_ADDRESS 0x020; #define MISO_PIN PTE3 /**************Defining Counter Limits**************/ @@ -45,7 +46,7 @@ #define CMD_PHY_OFF 0xB0 #define CMD_PHY_TX 0xB5 #define CMD_CONFIG_DEV 0xBB - + #define check_status {\ unsigned char stat=0;\ gCS_ADF=0;\ @@ -54,7 +55,7 @@ gCS_ADF=1;\ status = stat;\ } - + // all three arguments are int #define assrt_phy_off(return_this) {\ int cmd_err_cnt = 0;\ @@ -91,8 +92,8 @@ }\ }\ } - - + + //#define assrt_phy_on(cmd_err_cnt, spi_err_cnt, state_err_cnt, return_this){\ // status=check_status();\ // if((status&0x1F)==0x12){\ @@ -124,10 +125,10 @@ // }\ // }\ //} - - - - + + + + #define initial_adf_check {\ spi.write(CMD_PHY_OFF);\ int tempReturn = 0;\ @@ -154,7 +155,7 @@ bcn_flag=1;\ }\ } - + unsigned char status =0; unsigned int cmd_err_cnt=0; unsigned int state_err_cnt=0; @@ -162,7 +163,7 @@ unsigned int hw_reset_err_cnt=0; bool bcn_flag=0; bool bbram_flag=0; - + //bool assrt_phy_off(int cmd_err_cnt,int spi_err_cnt,int state_err_cnt){ // status=check_status(); // if(status==0xB1){ @@ -192,7 +193,7 @@ // return assrt_phy_off(cmd_err_cnt+1,spi_err_cnt,state_err_cnt); // } //} - + //bool assrt_phy_on(int cmd_err_cnt,int spi_err_cnt,int state_err_cnt){ // status=check_status(); // if((status&0x1F)==0x12){ @@ -224,8 +225,8 @@ // } // } //} - - + + // bool assrt_phy_tx(int cmd_err_cnt,int spi_err_cnt,int state_err_cnt){ // status=check_status(); // if((status & 0x1F) == 0x14){ @@ -257,7 +258,7 @@ // } // } //} - + bool hardware_reset(int bcn_call){ for(int i= 0; i < 20 ; i++){ gCS_ADF=0; @@ -282,7 +283,7 @@ } return 1; } - + //bool hardware_reset(int bcn_call){ // if (bcn_call>20){//Worst Case 20seconds will be lost ! // return 1; @@ -313,10 +314,10 @@ // return 0; // //} - - - - + + + + //void initial_adf_check(){ // spi.write(CMD_PHY_OFF); //0xB0 // while(hw_reset_err_cnt<2){ @@ -337,10 +338,10 @@ // bcn_flag=1; // } //} - + //for reseting the transmission call assert function after b5 and b1. after b1 assert_phi_on and after b5 assert_phi_tx. //---------------------------------------------------------------------------- - + # define initiate {\ SPI_mutex.lock();\ gCS_ADF=0;\ @@ -377,10 +378,17 @@ spi.write(0x39);\ spi.write(0x10);\ gCS_ADF=1;\ + gCS_ADF=0;\ + spi.write(0xBB);\ + gCS_ADF=1;\ + gCS_ADF=0;\ + spi.write(0xFF);\ + spi.write(0xFF);\ + gCS_ADF=1;\ SPI_mutex.unlock();\ } - - + + #define write_data {\ SPI_mutex.lock();\ gCS_ADF=0;\ @@ -407,29 +415,20 @@ SPI_mutex.unlock();\ buffer_state = !buffer_state;\ if(last_buffer){\ - ADF_off = true;\ + finish_write_data = true;\ gPC.puts("adf_off\r\n");\ }\ } - + void check(){ if(IRQ){ gCOM_MNG_TMTC_THREAD->signal_set(signal); } } - + #define send_data {\ - SPI_mutex.lock();\ - gCS_ADF=0;\ - spi.write(0xBB);\ - gCS_ADF=1;\ - gCS_ADF=0;\ - spi.write(0xFF);\ - spi.write(0xFF);\ - gCS_ADF=1;\ - SPI_mutex.unlock();\ if(sent_tmfrom_SDcard){\ send_tm_from_SD_card();\ }else{\ @@ -515,7 +514,7 @@ gPC.puts("sending from sd card\r\n"); adf_SND_SDCard; } - + //Timeout ADF_non_responsive_timeout; //bool ADF_non_responsive_flag = false; // @@ -523,34 +522,48 @@ // ADF_non_responsive_flag = true; // gCOM_MNG_TMTC_THREAD->signal_set(signal); //} - -void adf_not_SDcard(){ + +void configure_adf(){ + finish_write_data = false; buffer_state = true; last_buffer = false; loop_on = true; ADF_off = false; + /*initial adf check*/ + initial_adf_check; + gPC.puts("initial adf check\r\n"); + initiate; +// gPC.puts("initiate done\r\n"); + gPC.puts("adf configured\r\n"); +} + +void adf_not_SDcard(){ sent_tmfrom_SDcard = false; - + configure_adf(); signal = COM_MNG_TMTC_SIGNAL_ADF_NSD; - initial_adf_check; - initiate; send_data; // gPC.puts("Inside adf transmission\r\n"); // ADF_non_responsive_timeout.attach(&ADF_non_responsive_fun, 10); - + while(loop_on){ gCOM_MNG_TMTC_THREAD->signal_wait(COM_MNG_TMTC_SIGNAL_ADF_NSD); // if( ADF_non_responsive_flag == false ){ - if(ADF_off){ - SPI_mutex.lock(); - ticker.detach(); - // wait_ms(35); - gCS_ADF=0; - spi.write(0xB1); - gCS_ADF=1; - SPI_mutex.unlock(); - loop_on = false; + if(finish_write_data){ + if(ADF_off){ + SPI_mutex.lock(); + ticker.detach(); + // wait_ms(35); + gCS_ADF=0; + spi.write(0xB1); + gCS_ADF=1; + SPI_mutex.unlock(); + loop_on = false; + gPC.puts("Transmission done\r\n"); + } + else{ + ADF_off = true; + } }else{ write_data; snd_tm.transmit_data(buffer_112,&last_buffer); @@ -561,5 +574,4 @@ // break; // } } -} - \ No newline at end of file +} \ No newline at end of file