working version
Dependencies: mbed mbed-rtos SimpleDMA FreescaleIAP eeprom
Fork of CDMS_CODE_FM_28JAN2017 by
Diff: COM_MNG_TMTC.h
- Revision:
- 357:f3d48d62e00e
- Parent:
- 356:197c93dc2012
--- a/COM_MNG_TMTC.h Sat Feb 10 09:06:26 2018 +0000 +++ b/COM_MNG_TMTC.h Sun Apr 03 15:35:53 2022 +0000 @@ -104,7 +104,26 @@ }\ } +void mcpy(uint32_t *a2,uint8_t *a1,int n){ + + *a2=0; + for (int i=0;i<n;i++){ + *(a2) += *(a1+i); + if(i<n-1){ + *(a2)=(*(a2))<<8; + //printf("%d\n",*(a2)); + } + } + +} +/*void rmcpy(uint8_t *a1,uint32_t *a2,int n){ + + for (int i=0;i<n;i++){ + *(a1+i) = (*(a2))>>((n*8)-(8*(i+1))); + } + +}*/ void after_cooling_pa(){ gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT); @@ -432,7 +451,7 @@ { //gPC.printf("sub_service:Read LONG_RAM_Memory\r\n"); mid=((uint16_t)(tc_ptr->TC_string[3]<<4))+((uint16_t)(tc_ptr->TC_string[4])); - if(mid!=0x0000 && mid!=0x0001) + if(mid < 0x0000 && mid > 0x000A) { Base_tm *tm_ptr_short = new Short_tm; ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr)); @@ -448,6 +467,24 @@ FCTN_CDMS_RD_L_RAM(tm_ptr); if(mid == 0x0001) FCTN_CDMS_MAX_MIN(tm_ptr); + if(mid == 0x0002) + FCTN_CDMS_SCP_M0a(tm_ptr); + if(mid == 0x0003) + FCTN_CDMS_SCP_M0b(tm_ptr); + if(mid == 0x0004) + FCTN_CDMS_SCP_M1a(tm_ptr); + if(mid == 0x0005) + FCTN_CDMS_SCP_M1b(tm_ptr); + if(mid == 0x0006) + FCTN_CDMS_SCP_SFP_SUM(tm_ptr); + if(mid == 0x0007) + FCTN_CDMS_SFP_M0a(tm_ptr); + if(mid == 0x0008) + FCTN_CDMS_SFP_M0b(tm_ptr); + if(mid == 0x0009) + FCTN_CDMS_SFP_M1a(tm_ptr); + if(mid == 0x000A) + FCTN_CDMS_SFP_M1b(tm_ptr); crc16 = crc16_gen(tm_ptr->TM_string,132); tm_ptr->TM_string[132] = (uint8_t)((crc16&0xFF00)>>8); @@ -457,18 +494,18 @@ } case 0x5: // change the cases appropriately { - //gPC.printf("WRITE ON SHORT_FLASH_MEMORY\r\n"); + gPC.printf("WRITE ON SHORT_EEPROM_MEMORY\r\n"); mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]); //32 bits at a time Base_tm *tm_ptr_short = new Short_tm; - if(mid == 0x0101 || mid==0x0102 || mid == 0x0103 || mid == 0x0100) //allowable MID values? + if(mid == 0x0101 || mid==0x0102 || mid == 0x0103 || mid == 0x0100 || mid == 0x0104) //allowable MID values? { ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr)); return tm_ptr_short; } - //FCTN_CDMS_WR_S_FLASH(mid,(uint32_t)(tc_ptr->TC_string[5]<<24)+(uint32_t)(tc_ptr->TC_string[6]<<16)+(uint32_t)(tc_ptr->TC_string[7]<<8)+(uint32_t)(tc_ptr->TC_string[8])); + FCTN_CDMS_WR_S_EEPROM(mid,(uint32_t)(tc_ptr->TC_string[5]<<24)+(uint32_t)(tc_ptr->TC_string[6]<<16)+(uint32_t)(tc_ptr->TC_string[7]<<8)+(uint32_t)(tc_ptr->TC_string[8])); ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr)); @@ -480,18 +517,16 @@ if(mid == 0x0002) { for(uint8_t z=0;z<24;z++) - scp_threshold_m0[z] = tc_ptr->TC_string[z+5]; - for(uint8_t z=24;z<32;z++) - scp_threshold_m0[z+8] = tc_ptr->TC_string[z+5]; + mcpy(scp_threshold_m0+z,tc_ptr->TC_string+4*z+5,4); + for(uint8_t z=24;z<32;z++) + mcpy(scp_threshold_m0+z+8,tc_ptr->TC_string+4*z+5,4); for(uint8_t z=0;z<24;z++) flasharray_thres[z] = scp_threshold_m0[z]; for(uint8_t z=24;z<32;z++) flasharray_thres[z] = scp_threshold_m0[z+8]; + + THRES_WRITE_TO_EEPROM(mid,flasharray_thres,1); - // FCTN_CDMS_WR_S_FLASH(mid,flasharray_thres); - erase_sector(strt_add_thres); - program_flash(strt_add_thres, (char*)flasharray_thres,32); - Base_tm *tm_ptr_short = new Short_tm; ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr)); return tm_ptr_short; @@ -499,13 +534,11 @@ else if(mid == 0x0003) { for(uint8_t z=0;z<12;z++) - scp_threshold_m0[z+40] = tc_ptr->TC_string[z+5]; + mcpy(scp_threshold_m0+z+40,tc_ptr->TC_string+4*z+5,4); for(uint8_t z=0;z<12;z++) flasharray_thres[z] = scp_threshold_m0[z+40]; - - // FCTN_CDMS_WR_S_FLASH(mid,flasharray_thres); - erase_sector(strt_add_thres+SECTOR_SIZE); - program_flash(strt_add_thres+SECTOR_SIZE, (char*)flasharray_thres,32); + + THRES_WRITE_TO_EEPROM(mid,flasharray_thres,2); Base_tm *tm_ptr_short = new Short_tm; ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr)); @@ -514,13 +547,11 @@ else if(mid == 0x0004) { for(uint8_t z=0;z<32;z++) - scp_threshold_m1[z] = tc_ptr->TC_string[z+5]; + mcpy(scp_threshold_m1+z,tc_ptr->TC_string+4*z+5,4); for(uint8_t z=0;z<32;z++) flasharray_thres[z] = scp_threshold_m1[z]; - - // THRES_WRITE_TO_EEPROM(mid,flasharray_thres); - erase_sector(strt_add_thres+(2*SECTOR_SIZE)); - program_flash(strt_add_thres+(2*SECTOR_SIZE), (char*)flasharray_thres,32); + + THRES_WRITE_TO_EEPROM(mid,flasharray_thres,1); Base_tm *tm_ptr_short = new Short_tm; ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr)); @@ -529,13 +560,11 @@ else if(mid == 0x0005) { for(uint8_t z=0;z<20;z++) - scp_threshold_m1[z+32] = tc_ptr->TC_string[z+5]; + mcpy(scp_threshold_m1+z+32,tc_ptr->TC_string+4*z+5,4); for(uint8_t z=0;z<20;z++) flasharray_thres[z] = scp_threshold_m1[z+32]; - // THRES_WRITE_TO_EEPROM(mid,flasharray_thres); - erase_sector(strt_add_thres+(3*SECTOR_SIZE)); - program_flash(strt_add_thres+(3*SECTOR_SIZE), (char*)flasharray_thres,32); + THRES_WRITE_TO_EEPROM(mid,flasharray_thres,3); Base_tm *tm_ptr_short = new Short_tm; ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr)); @@ -543,15 +572,16 @@ } else if(mid == 0x0006) { - scp_threshold_m0_1[7] = tc_ptr->TC_string[5]; - scp_threshold_m0_1[5] = tc_ptr->TC_string[6]; - scp_threshold_m0_1[8] = tc_ptr->TC_string[7]; - scp_threshold_m0_1[6] = tc_ptr->TC_string[8]; + mcpy(scp_threshold_m0_1+7,tc_ptr->TC_string+4*0+5,4); + mcpy(scp_threshold_m0_1+5,tc_ptr->TC_string+4*1+5,4); + mcpy(scp_threshold_m0_1+8,tc_ptr->TC_string+4*2+5,4); + mcpy(scp_threshold_m0_1+6,tc_ptr->TC_string+4*3+5,4); for(uint8_t z=0;z<5;z++) - scp_threshold_m0_1[z] = tc_ptr->TC_string[z+9]; - scp_sfp_threshold_m0_2[0] = tc_ptr->TC_string[14]; - scp_sfp_threshold_m0_2[1] = tc_ptr->TC_string[15]; - scp_sfp_threshold_m0_2[2] = tc_ptr->TC_string[16]; + mcpy(scp_threshold_m0_1+z,tc_ptr->TC_string+4*(z+4)+5,4); + mcpy(scp_sfp_threshold_m0_2+0,tc_ptr->TC_string+4*9+5,4); + mcpy(scp_sfp_threshold_m0_2+1,tc_ptr->TC_string+4*10+5,4); + mcpy(scp_sfp_threshold_m0_2+2,tc_ptr->TC_string+4*11+5,4); + flasharray_thres[0] = scp_threshold_m0_1[7]; flasharray_thres[1] = scp_threshold_m0_1[5]; flasharray_thres[2] = scp_threshold_m0_1[8]; @@ -561,11 +591,8 @@ flasharray_thres[9] = scp_sfp_threshold_m0_2[0]; flasharray_thres[10] = scp_sfp_threshold_m0_2[1]; flasharray_thres[11] = scp_sfp_threshold_m0_2[2]; - - // THRES_WRITE_TO_EEPROM(mid,flasharray_thres); - - erase_sector(strt_add_thres+(4*SECTOR_SIZE)); - program_flash(strt_add_thres+(4*SECTOR_SIZE), (char*)flasharray_thres,32); + + THRES_WRITE_TO_EEPROM(mid,flasharray_thres,2); Base_tm *tm_ptr_short = new Short_tm; ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr)); @@ -574,17 +601,15 @@ else if(mid == 0x0007) { for(uint8_t z=0;z<24;z++) - sfp_threshold_m0[z] = tc_ptr->TC_string[z+5]; + mcpy(sfp_threshold_m0+z,tc_ptr->TC_string+4*z+5,4); for(uint8_t z=24;z<32;z++) - sfp_threshold_m0[z+8] = tc_ptr->TC_string[z+5]; + mcpy(sfp_threshold_m0+z+8,tc_ptr->TC_string+4*z+5,4); for(uint8_t z=0;z<24;z++) flasharray_thres[z] = sfp_threshold_m0[z]; for(uint8_t z=24;z<32;z++) flasharray_thres[z] = sfp_threshold_m0[z+8]; - - // THRES_WRITE_TO_EEPROM(mid,flasharray_thres); - erase_sector(strt_add_thres+(5*SECTOR_SIZE)); - program_flash(strt_add_thres+(5*SECTOR_SIZE), (char*)flasharray_thres,32); + + THRES_WRITE_TO_EEPROM(mid,flasharray_thres,1); Base_tm *tm_ptr_short = new Short_tm; ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr)); @@ -593,13 +618,12 @@ else if(mid == 0x0008) { for(uint8_t z=0;z<12;z++) - sfp_threshold_m0[z+40] = tc_ptr->TC_string[z+5]; + mcpy(sfp_threshold_m0+z+40,tc_ptr->TC_string+4*z+5,4); for(uint8_t z=0;z<12;z++) flasharray_thres[z] = sfp_threshold_m0[z+40]; - - // THRES_WRITE_TO_EEPROM(mid,flasharray_thres); - erase_sector(strt_add_thres+(6*SECTOR_SIZE)); - program_flash(strt_add_thres+(6*SECTOR_SIZE), (char*)flasharray_thres,32); + + THRES_WRITE_TO_EEPROM(mid,flasharray_thres,2); + Base_tm *tm_ptr_short = new Short_tm; ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr)); return tm_ptr_short; @@ -607,15 +631,12 @@ else if(mid == 0x0009) { for(uint8_t z=0;z<32;z++) - sfp_threshold_m1[z] = tc_ptr->TC_string[z+5]; + mcpy(sfp_threshold_m1+z,tc_ptr->TC_string+4*z+5,4); for(uint8_t z=0;z<32;z++) flasharray_thres[z] = sfp_threshold_m1[z]; - - // THRES_WRITE_TO_EEPROM(mid,flasharray_thres); - - erase_sector(strt_add_thres+(7*SECTOR_SIZE)); - program_flash(strt_add_thres+(7*SECTOR_SIZE), (char*)flasharray_thres,32); - + + THRES_WRITE_TO_EEPROM(mid,flasharray_thres,1); + Base_tm *tm_ptr_short = new Short_tm; ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr)); return tm_ptr_short; @@ -623,14 +644,12 @@ else if(mid == 0x000A) { for(uint8_t z=0;z<20;z++) - sfp_threshold_m1[z+32] = tc_ptr->TC_string[z+5]; + mcpy(sfp_threshold_m1+z+32,tc_ptr->TC_string+4*z+5,4); for(uint8_t z=0;z<20;z++) flasharray_thres[z] = sfp_threshold_m1[z+32]; -// THRES_WRITE_TO_EEPROM(mid,flasharray_thres); - erase_sector(strt_add_thres+(8*SECTOR_SIZE)); - program_flash(strt_add_thres+(8*SECTOR_SIZE), (char*)flasharray_thres,32); - + THRES_WRITE_TO_EEPROM(mid,flasharray_thres,3); + Base_tm *tm_ptr_short = new Short_tm; ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr)); return tm_ptr_short; @@ -913,6 +932,35 @@ ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr)); return tm_ptr_short; } + else if(GETpid(tc_ptr)==0x3A) + { + //REQUEST FOR SYS_RESET + sys_pwr_rst.output(); + sys_pwr_rst = 1; + + //PREPARE FOR SYS_RESET + SYS_RESET(); + + while(1){ + wait_ms(10000); + RESET_WATCHDOG(); //uncomment in the FM SBC with watchdog enabled + uint64_t cur_rtc_tc = FCTN_CDMS_RD_RTC(); + uint32_t T_check1_tc = ((((cur_rtc_tc - TIME_LATEST_CDMS_EPS_RST) >> 7)& 0x00000FC0)>>6); + gPC.printf("\r%d\n",T_check1_tc ); + //gPC.printf("\r%d\n",TIME_LATEST_CDMS_EPS_RST); + gPC.printf("\r%d\n",cur_rtc_tc); + if(T_check1_tc >= 5*T_OFF_RST) + { + break; + } + } + BACK_NORMAL(); + + Base_tm *tm_ptr_short = new Short_tm; + ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + + } else if(GETpid(tc_ptr)==0x3b) { //gPC.printf("TC_RST_BAE\r\n"); // call PWR_SWCH_ON function @@ -926,13 +974,14 @@ else if(GETpid(tc_ptr)==0x40) { //gPC.printf("RESET_HK_COUNTER\r\n"); // call PWR_SWCH_ON function - if(tc_ptr->TC_string[4] == 0x00 || tc_ptr->TC_string[4] == 0x01) EN_PL = tc_ptr->TC_string[4]; if(tc_ptr->TC_string[5] == 0x00 || tc_ptr->TC_string[5] == 0x01) //was else if changed to if to match the flowcharts - J EN_CDMS_HK = tc_ptr->TC_string[5]; if(tc_ptr->TC_string[6] == 0x00 || tc_ptr->TC_string[6] == 0x01) EN_RCV_SC = tc_ptr->TC_string[6]; + if(tc_ptr->TC_string[7] == 0x00 || tc_ptr->TC_string[7] == 0x01) + EN_P_MGMT = tc_ptr->TC_string[7]; Base_tm *tm_ptr_short = new Short_tm; ACK_L234(tm_ptr_short,0xA0,GETpacket_seq_count(tc_ptr)); @@ -1044,7 +1093,8 @@ pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[5+j]))<<8); pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[6+j]))); j+=4; - } + } + //WRITE_PMS_TO_EEPROM(0x0001, pl_block); //Uncomment and test after ensuring PMS TCs work without the EEPROM part in it return tm_ptr; } else if(GETservice_subtype(tc_ptr)==0x2) @@ -1060,6 +1110,7 @@ pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[5+j]))<<8); pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[6+j]))); } + //WRITE_PMS_TO_EEPROM(0x0002, pl_block + (32)); //Uncomment and test after ensuring PMS TCs work without the EEPROM part in it return tm_ptr; } else if(GETservice_subtype(tc_ptr)==0x3) @@ -1075,6 +1126,7 @@ pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[5+j]))<<8); pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[6+j]))); } + //WRITE_PMS_TO_EEPROM(0x0003, pl_block + (64)); //Uncomment and test after ensuring PMS TCs work without the EEPROM part in it return tm_ptr; } else if(GETservice_subtype(tc_ptr)==0x4) @@ -1090,6 +1142,7 @@ pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[5+j]))<<8); pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[6+j]))); } + //WRITE_PMS_TO_EEPROM(0x0004, pl_block + (96)); //Uncomment and test after ensuring PMS TCs work without the EEPROM part in it return tm_ptr; } else if(GETservice_subtype(tc_ptr)==0x5) @@ -1105,6 +1158,7 @@ pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[5+j]))<<8); pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[6+j]))); } + //WRITE_PMS_TO_EEPROM(0x0005, pl_block + (128)); //Uncomment and test after ensuring PMS TCs work without the EEPROM part in it return tm_ptr; } else if(GETservice_subtype(tc_ptr)==0x6) @@ -1120,6 +1174,7 @@ pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[5+j]))<<8); pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[6+j]))); } + //WRITE_PMS_TO_EEPROM(0x0006, pl_block + (160)); //Uncomment and test after ensuring PMS TCs work without the EEPROM part in it return tm_ptr; } else if(GETservice_subtype(tc_ptr)==0xF)