June 30

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

Committer:
chaithanyarss
Date:
Sat Jul 02 13:36:18 2016 +0000
Revision:
191:d14b1c783736
Parent:
190:28a07943dded
;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chaithanyarss 189:fba4aeebf004 1 int pl_next_index=-1;
chaithanyarss 189:fba4aeebf004 2 uint8_t pl_main_flag=0;
chaithanyarss 189:fba4aeebf004 3 uint8_t PL_PREV_STATE=0x00;
chaithanyarss 189:fba4aeebf004 4 uint8_t POWER_LEVEL = 3; //Would be present in HK data extracted
chaithanyarss 190:28a07943dded 5 uint32_t pl_block[192]={0};
chaithanyarss 189:fba4aeebf004 6 uint32_t pl_time;
chaithanyarss 189:fba4aeebf004 7 uint32_t TIME_LATEST_PL=0;
chaithanyarss 189:fba4aeebf004 8 uint8_t i;
chaithanyarss 189:fba4aeebf004 9 uint8_t PL_BEE_SW_STATUS=0;
chaithanyarss 189:fba4aeebf004 10
chaithanyarss 189:fba4aeebf004 11 //Serial pc(USBTX,USBRX);
chaithanyarss 189:fba4aeebf004 12
chaithanyarss 189:fba4aeebf004 13 #define PL_MAIN_STATUS 0x01
chaithanyarss 189:fba4aeebf004 14 #define PL_LOW_POWER 0x02
chaithanyarss 189:fba4aeebf004 15 #define STATE_OFF 0x00
chaithanyarss 189:fba4aeebf004 16 #define STATE_STANDBY 0x04
chaithanyarss 189:fba4aeebf004 17 #define STATE_HIBERNATE 0x08
chaithanyarss 189:fba4aeebf004 18 #define STATE_SCIENCE 0x0C //also used as mask for PL_STATE
chaithanyarss 189:fba4aeebf004 19 #define PL_OFF 0x00
chaithanyarss 189:fba4aeebf004 20 #define PL_STANDBY 0x10
chaithanyarss 189:fba4aeebf004 21 #define PL_HIBERNATE 0x20
chaithanyarss 189:fba4aeebf004 22 #define PL_SCIENCE 0x30
chaithanyarss 189:fba4aeebf004 23 #define PL_SUCCESS_I2C 0x40
chaithanyarss 189:fba4aeebf004 24 #define PL_ERR_I2C 0x50
chaithanyarss 189:fba4aeebf004 25 #define PL_INVALID_STATE 0x60
chaithanyarss 189:fba4aeebf004 26 #define PL_DISABLED 0x70 //also used as mask for PL_STATUS
chaithanyarss 189:fba4aeebf004 27 #define EXECUTED 0x00000001
chaithanyarss 189:fba4aeebf004 28 #define RETRY 0x00000002
chaithanyarss 189:fba4aeebf004 29 #define UNEXECUTED 0x00000003 //also used as mask for EXEC_STATUS
chaithanyarss 189:fba4aeebf004 30
chaithanyarss 189:fba4aeebf004 31
chaithanyarss 189:fba4aeebf004 32 DigitalOut PYLD_DFF(PIN73);
chaithanyarss 189:fba4aeebf004 33 DigitalOut PYLD_DFF_CLK(PIN65);
chaithanyarss 189:fba4aeebf004 34 DigitalOut PYLD_EPS_DFF_PWR(PIN64);
chaithanyarss 189:fba4aeebf004 35 DigitalOut PYLD_EPS_DFF_PWR_CLK(PIN40);
chaithanyarss 189:fba4aeebf004 36 Base_tm* FCTN_CDMS_RLY_TMTC(Base_tc *tc_ptr);
chaithanyarss 189:fba4aeebf004 37
chaithanyarss 189:fba4aeebf004 38 // waiting 1us for setup time,hold time and propagation delay
chaithanyarss 189:fba4aeebf004 39 #define SET_PL_BEE_OFF {\
chaithanyarss 189:fba4aeebf004 40 PYLD_DFF_CLK = 0;\
chaithanyarss 189:fba4aeebf004 41 PYLD_DFF = 0;\
chaithanyarss 189:fba4aeebf004 42 wait_us(1);\
chaithanyarss 189:fba4aeebf004 43 PYLD_DFF_CLK = 1;\
chaithanyarss 189:fba4aeebf004 44 wait_us(1);\
chaithanyarss 189:fba4aeebf004 45 PYLD_DFF_CLK = 0;\
chaithanyarss 189:fba4aeebf004 46 wait_us(1);\
chaithanyarss 189:fba4aeebf004 47 }
chaithanyarss 189:fba4aeebf004 48 #define SET_PL_BEE_ON {\
chaithanyarss 189:fba4aeebf004 49 PYLD_DFF_CLK = 0;\
chaithanyarss 189:fba4aeebf004 50 PYLD_DFF = 1;\
chaithanyarss 189:fba4aeebf004 51 wait_us(1);\
chaithanyarss 189:fba4aeebf004 52 PYLD_DFF_CLK = 1;\
chaithanyarss 189:fba4aeebf004 53 wait_us(1);\
chaithanyarss 189:fba4aeebf004 54 PYLD_DFF_CLK = 0;\
chaithanyarss 189:fba4aeebf004 55 wait_us(1);\
chaithanyarss 189:fba4aeebf004 56 }
chaithanyarss 189:fba4aeebf004 57
chaithanyarss 189:fba4aeebf004 58 //TC_string[0] should not be 0x00
chaithanyarss 189:fba4aeebf004 59
chaithanyarss 189:fba4aeebf004 60 #define SET_PL_BEE_STANDBY(tm_ptr_standby) {\
chaithanyarss 189:fba4aeebf004 61 Base_tc *pl_tc_standby = new Short_tc;\
chaithanyarss 189:fba4aeebf004 62 pl_tc_standby->next_TC = NULL;\
chaithanyarss 189:fba4aeebf004 63 PUTshort_or_long(pl_tc_standby,0);\
chaithanyarss 189:fba4aeebf004 64 PUTcrc_pass(pl_tc_standby,0x1);\
chaithanyarss 189:fba4aeebf004 65 PUTexec_status(pl_tc_standby,0);\
chaithanyarss 189:fba4aeebf004 66 pl_tc_standby->TC_string[0] = 0x01;\
chaithanyarss 189:fba4aeebf004 67 pl_tc_standby->TC_string[1] = 0xE1;\
chaithanyarss 189:fba4aeebf004 68 pl_tc_standby->TC_string[2] = 0x81;\
chaithanyarss 189:fba4aeebf004 69 pl_tc_standby->TC_string[3] = 0x02;\
chaithanyarss 189:fba4aeebf004 70 pl_tc_standby->TC_string[4] = 0;\
chaithanyarss 189:fba4aeebf004 71 pl_tc_standby->TC_string[5] = 0;\
chaithanyarss 189:fba4aeebf004 72 pl_tc_standby->TC_string[6] = 0;\
chaithanyarss 189:fba4aeebf004 73 pl_tc_standby->TC_string[7] = 0;\
chaithanyarss 189:fba4aeebf004 74 pl_tc_standby->TC_string[8] = 0;\
chaithanyarss 189:fba4aeebf004 75 uint16_t crc16 = crc16_gen(pl_tc_standby->TC_string, 9);\
chaithanyarss 189:fba4aeebf004 76 pl_tc_standby->TC_string[9] = (uint8_t)(crc16 & 0xFF00)>>8;\
chaithanyarss 189:fba4aeebf004 77 pl_tc_standby->TC_string[10] = (uint8_t)(crc16 & 0x00FF);\
chaithanyarss 189:fba4aeebf004 78 tm_ptr_standby = FCTN_CDMS_RLY_TMTC(pl_tc_standby);\
chaithanyarss 189:fba4aeebf004 79 VERIFY_TM(tm_ptr_standby);\
chaithanyarss 189:fba4aeebf004 80 }
chaithanyarss 189:fba4aeebf004 81
chaithanyarss 189:fba4aeebf004 82 //TC_string[0] should not be 0x00
chaithanyarss 189:fba4aeebf004 83
chaithanyarss 189:fba4aeebf004 84 #define SET_PL_BEE_HIBERNATE(tm_ptr_hibernate) {\
chaithanyarss 189:fba4aeebf004 85 Base_tc *pl_tc_hibernate = new Short_tc;\
chaithanyarss 189:fba4aeebf004 86 pl_tc_hibernate->next_TC = NULL;\
chaithanyarss 189:fba4aeebf004 87 PUTshort_or_long(pl_tc_hibernate,0);\
chaithanyarss 189:fba4aeebf004 88 PUTcrc_pass(pl_tc_hibernate,0x1);\
chaithanyarss 189:fba4aeebf004 89 PUTexec_status(pl_tc_hibernate,0);\
chaithanyarss 189:fba4aeebf004 90 pl_tc_hibernate->TC_string[0] = 0x01;\
chaithanyarss 189:fba4aeebf004 91 pl_tc_hibernate->TC_string[1] = 0xE1;\
chaithanyarss 189:fba4aeebf004 92 pl_tc_hibernate->TC_string[2] = 0x81;\
chaithanyarss 189:fba4aeebf004 93 pl_tc_hibernate->TC_string[3] = 0x03;\
chaithanyarss 189:fba4aeebf004 94 pl_tc_hibernate->TC_string[4] = 0;\
chaithanyarss 189:fba4aeebf004 95 pl_tc_hibernate->TC_string[5] = 0;\
chaithanyarss 189:fba4aeebf004 96 pl_tc_hibernate->TC_string[6] = 0;\
chaithanyarss 189:fba4aeebf004 97 pl_tc_hibernate->TC_string[7] = 0;\
chaithanyarss 189:fba4aeebf004 98 pl_tc_hibernate->TC_string[8] = 0;\
chaithanyarss 189:fba4aeebf004 99 uint16_t crc16 = crc16_gen(pl_tc_hibernate->TC_string, 9);\
chaithanyarss 189:fba4aeebf004 100 pl_tc_hibernate->TC_string[9] = (uint8_t)(crc16 & 0xFF00)>>8;\
chaithanyarss 189:fba4aeebf004 101 pl_tc_hibernate->TC_string[10] = (uint8_t)(crc16 & 0x00FF);\
chaithanyarss 189:fba4aeebf004 102 tm_ptr_hibernate = FCTN_CDMS_RLY_TMTC(pl_tc_hibernate);\
chaithanyarss 189:fba4aeebf004 103 VERIFY_TM(tm_ptr_hibernate);\
chaithanyarss 189:fba4aeebf004 104 }
chaithanyarss 189:fba4aeebf004 105
chaithanyarss 189:fba4aeebf004 106 //TC_string[0] should not be 0x00
chaithanyarss 189:fba4aeebf004 107 /*
chaithanyarss 189:fba4aeebf004 108 PUTshort_or_long(pl_tc_science,0);\
chaithanyarss 189:fba4aeebf004 109 PUTcrc_pass(pl_tc_science,0x1);\
chaithanyarss 189:fba4aeebf004 110 PUTexec_status(pl_tc_science,0);\*/
chaithanyarss 189:fba4aeebf004 111
chaithanyarss 189:fba4aeebf004 112 #define SET_PL_BEE_SCIENCE(tm_ptr_science) {\
chaithanyarss 189:fba4aeebf004 113 Base_tc *pl_tc_science = new Short_tc;\
chaithanyarss 189:fba4aeebf004 114 pl_tc_science->next_TC = NULL;\
chaithanyarss 189:fba4aeebf004 115 pl_tc_science->TC_string[0] = 0x01;\
chaithanyarss 189:fba4aeebf004 116 pl_tc_science->TC_string[1] = 0xE1;\
chaithanyarss 189:fba4aeebf004 117 pl_tc_science->TC_string[2] = 0x81;\
chaithanyarss 189:fba4aeebf004 118 pl_tc_science->TC_string[3] = 0x04;\
chaithanyarss 189:fba4aeebf004 119 pl_tc_science->TC_string[4] = 0;\
chaithanyarss 189:fba4aeebf004 120 pl_tc_science->TC_string[5] = 0;\
chaithanyarss 189:fba4aeebf004 121 pl_tc_science->TC_string[6] = 0;\
chaithanyarss 189:fba4aeebf004 122 pl_tc_science->TC_string[7] = 0;\
chaithanyarss 189:fba4aeebf004 123 pl_tc_science->TC_string[8] = 0;\
chaithanyarss 189:fba4aeebf004 124 uint16_t crc16 = crc16_gen(pl_tc_science->TC_string, 9);\
chaithanyarss 189:fba4aeebf004 125 pl_tc_science->TC_string[9] = (uint8_t)(crc16 & 0xFF00)>>8;\
chaithanyarss 189:fba4aeebf004 126 pl_tc_science->TC_string[10] = (uint8_t)(crc16 & 0x00FF);\
chaithanyarss 189:fba4aeebf004 127 tm_ptr_science = FCTN_CDMS_RLY_TMTC(pl_tc_science);\
chaithanyarss 189:fba4aeebf004 128 VERIFY_TM(tm_ptr_science);\
chaithanyarss 189:fba4aeebf004 129 }
chaithanyarss 189:fba4aeebf004 130 void print_processed_block(uint8_t index)
chaithanyarss 189:fba4aeebf004 131 {
chaithanyarss 189:fba4aeebf004 132 gPC.printf("\n\n\rBlock after processing:");
chaithanyarss 189:fba4aeebf004 133 gPC.printf("\n\rTime of block:");
chaithanyarss 189:fba4aeebf004 134 gPC.printf("\n\rYear :%d",((((pl_block[index]&0xFFFFFFF0)>>4) & 0x0C000000)>>26)+2016);
chaithanyarss 189:fba4aeebf004 135 gPC.printf("\tMonth :%d",((((pl_block[index]&0xFFFFFFF0)>>4) & 0x03C00000)>>22));
chaithanyarss 189:fba4aeebf004 136 gPC.printf("\tDay :%d",((((pl_block[index]&0xFFFFFFF0)>>4) & 0x003E0000)>>17));
chaithanyarss 189:fba4aeebf004 137 gPC.printf("\n\rHours :%d",((((pl_block[index]&0xFFFFFFF0)>>4) & 0x0001F000)>>12));
chaithanyarss 189:fba4aeebf004 138 gPC.printf("\tMin :%d",((((pl_block[index]&0xFFFFFFF0)>>4) & 0x00000FC0)>>6));
chaithanyarss 189:fba4aeebf004 139 gPC.printf("\tSec :%d",(((pl_block[index]&0xFFFFFFF0)>>4) & 0x0000003F));
chaithanyarss 189:fba4aeebf004 140 gPC.printf("\n\rSID :%d",(pl_block[index] & 0x0000000C)>>2);
chaithanyarss 189:fba4aeebf004 141 gPC.printf("\tExecution Status :%d",pl_block[index] & UNEXECUTED);
chaithanyarss 189:fba4aeebf004 142 }
chaithanyarss 189:fba4aeebf004 143 void print_exit(uint8_t* temp)
chaithanyarss 189:fba4aeebf004 144 {
chaithanyarss 189:fba4aeebf004 145 uint8_t temp2[3];
chaithanyarss 189:fba4aeebf004 146 temp2[0] = (pl_main_flag&STATE_SCIENCE)>>2;
chaithanyarss 189:fba4aeebf004 147 temp2[1] = (pl_main_flag&PL_DISABLED)>>4;
chaithanyarss 189:fba4aeebf004 148 temp2[2] = (PL_PREV_STATE & STATE_SCIENCE)>>2;
chaithanyarss 189:fba4aeebf004 149 gPC.printf("\n\rAt exit");
chaithanyarss 189:fba4aeebf004 150 char state[][17] = {"STATE_OFF","STATE_STANDBY","STATE_HIBERNATE","STATE_SCIENCE"};
chaithanyarss 189:fba4aeebf004 151 char status[][17] = {"PL_OFF","PL_STANDBY","PL_HIBERNATE","PL_SCIENCE","PL_SUCCESS_I2C","PL_ERR_I2C","PL_INVALID_STATE","PL_DISABLED"};
chaithanyarss 189:fba4aeebf004 152 gPC.printf("\n\rPL_state:%s -> %s",state[(uint8_t)temp[0]],state[(uint8_t)temp2[0]]);
chaithanyarss 189:fba4aeebf004 153 gPC.printf("\n\rPL_status:%s -> %s",status[(uint8_t)temp[1]],status[(uint8_t)temp2[1]]);
chaithanyarss 189:fba4aeebf004 154 gPC.printf("\n\rPL_PREV_state:%s -> %s",state[(uint8_t)temp[2]],state[(uint8_t)temp2[2]]);
chaithanyarss 189:fba4aeebf004 155 }
chaithanyarss 189:fba4aeebf004 156 void VERIFY_TM(Base_tm *tm_ptr)
chaithanyarss 189:fba4aeebf004 157 {
chaithanyarss 189:fba4aeebf004 158 uint8_t temp = tm_ptr->TM_string[2]; //Obatining ACK_CODE
chaithanyarss 189:fba4aeebf004 159 if(GETshort_or_long_tm(tm_ptr)==1) //short TM
chaithanyarss 189:fba4aeebf004 160 {
chaithanyarss 189:fba4aeebf004 161 gPC.printf("\n\rSHORT TM received");
chaithanyarss 189:fba4aeebf004 162 uint16_t crc16 = crc16_gen(tm_ptr->TM_string, 11);
chaithanyarss 189:fba4aeebf004 163 if(tm_ptr->TM_string[12]==((uint8_t)(crc16 & 0x00FF)) && tm_ptr->TM_string[11]==((uint8_t)((crc16 & 0xFF00)>>8)))
chaithanyarss 189:fba4aeebf004 164 {
chaithanyarss 189:fba4aeebf004 165 if(temp!=0x00 && temp!=0x01 && temp!=0x02 && temp!=0x03 && temp!=0x84 && temp!=0x85)
chaithanyarss 189:fba4aeebf004 166 {
chaithanyarss 189:fba4aeebf004 167 gPC.printf("\n\rTime_Latest_PL Updated");
chaithanyarss 189:fba4aeebf004 168 TIME_LATEST_PL = pl_time; //update latest time when I2C communication was successful
chaithanyarss 189:fba4aeebf004 169 }
chaithanyarss 189:fba4aeebf004 170 if(temp==0xA0 || temp==0xC0)
chaithanyarss 189:fba4aeebf004 171 {
chaithanyarss 189:fba4aeebf004 172 gPC.printf("\n\rACK_CODE Success");
chaithanyarss 189:fba4aeebf004 173 if(temp==0xA0)
chaithanyarss 189:fba4aeebf004 174 gPC.printf("\n\rACK_CODE = 0x%02X",temp);
chaithanyarss 189:fba4aeebf004 175 else
chaithanyarss 189:fba4aeebf004 176 gPC.printf("\n\rACK_CODE = 0x%02X",temp);
chaithanyarss 189:fba4aeebf004 177 pl_main_flag = pl_main_flag & (~PL_DISABLED);
chaithanyarss 189:fba4aeebf004 178 pl_main_flag |= PL_SUCCESS_I2C;
chaithanyarss 189:fba4aeebf004 179 pl_block[pl_next_index-1] &= (~UNEXECUTED); //changing exec_status
chaithanyarss 189:fba4aeebf004 180 pl_block[pl_next_index-1] |= EXECUTED;
chaithanyarss 189:fba4aeebf004 181 }
chaithanyarss 189:fba4aeebf004 182 else
chaithanyarss 189:fba4aeebf004 183 {
chaithanyarss 189:fba4aeebf004 184 gPC.printf("\n\rACK_CODE failure (0x%02X)",temp);
chaithanyarss 189:fba4aeebf004 185 //gPC.printf("\n\rACK_CODE = 0x%02X",temp);
chaithanyarss 189:fba4aeebf004 186 pl_main_flag = pl_main_flag & (~PL_DISABLED);
chaithanyarss 189:fba4aeebf004 187 pl_main_flag |= PL_ERR_I2C;
chaithanyarss 189:fba4aeebf004 188 pl_block[pl_next_index-1] &= (~UNEXECUTED); //changing exec_status
chaithanyarss 189:fba4aeebf004 189 pl_block[pl_next_index-1] |= RETRY;
chaithanyarss 189:fba4aeebf004 190 }
chaithanyarss 189:fba4aeebf004 191 }
chaithanyarss 189:fba4aeebf004 192 else
chaithanyarss 189:fba4aeebf004 193 {
chaithanyarss 189:fba4aeebf004 194 gPC.printf("\n\rShort_TM CRC failed");
chaithanyarss 189:fba4aeebf004 195 pl_main_flag = pl_main_flag & (~PL_DISABLED);
chaithanyarss 189:fba4aeebf004 196 pl_main_flag |= PL_ERR_I2C;
chaithanyarss 189:fba4aeebf004 197 pl_block[pl_next_index-1] &= (~UNEXECUTED); //changing exec_status
chaithanyarss 189:fba4aeebf004 198 pl_block[pl_next_index-1] |= RETRY;
chaithanyarss 189:fba4aeebf004 199 }
chaithanyarss 189:fba4aeebf004 200 }
chaithanyarss 189:fba4aeebf004 201 else if(GETshort_or_long_tm(tm_ptr)==0) //LONG TM
chaithanyarss 189:fba4aeebf004 202 {
chaithanyarss 189:fba4aeebf004 203 gPC.printf("\n\rLONG TM received");
chaithanyarss 189:fba4aeebf004 204 uint16_t crc16 = crc16_gen(tm_ptr->TM_string,132);
chaithanyarss 189:fba4aeebf004 205 if(tm_ptr->TM_string[133]==((uint8_t)(crc16 & 0x00FF)) && tm_ptr->TM_string[132]==((uint8_t)((crc16 & 0xFF00)>>8)))
chaithanyarss 189:fba4aeebf004 206 {
chaithanyarss 189:fba4aeebf004 207 if(temp!=0x00 && temp!=0x01 && temp!=0x02 && temp!=0x03 && temp!=0x84 && temp!=0x85)
chaithanyarss 189:fba4aeebf004 208 {
chaithanyarss 189:fba4aeebf004 209 gPC.printf("\n\rTime_Latest_PL Updated");
chaithanyarss 189:fba4aeebf004 210 TIME_LATEST_PL = pl_time; //update latest time when I2C communication was successful
chaithanyarss 189:fba4aeebf004 211 }
chaithanyarss 189:fba4aeebf004 212 if(temp==0xA0 || temp==0xC0)
chaithanyarss 189:fba4aeebf004 213 {
chaithanyarss 189:fba4aeebf004 214 gPC.printf("\n\rACK_CODE Success");
chaithanyarss 189:fba4aeebf004 215 if(temp==0xA0)
chaithanyarss 189:fba4aeebf004 216 gPC.printf("\n\rACK_CODE = 0x%02X",temp);
chaithanyarss 189:fba4aeebf004 217 else
chaithanyarss 189:fba4aeebf004 218 gPC.printf("\n\rACK_CODE = 0x%02X",temp);
chaithanyarss 189:fba4aeebf004 219 pl_main_flag = pl_main_flag & (~PL_DISABLED);
chaithanyarss 189:fba4aeebf004 220 pl_main_flag |= PL_SUCCESS_I2C;
chaithanyarss 189:fba4aeebf004 221 pl_block[pl_next_index-1] &= (~UNEXECUTED); //changing exec_status
chaithanyarss 189:fba4aeebf004 222 pl_block[pl_next_index-1] |= EXECUTED;
chaithanyarss 189:fba4aeebf004 223 }
chaithanyarss 189:fba4aeebf004 224 else
chaithanyarss 189:fba4aeebf004 225 {
chaithanyarss 189:fba4aeebf004 226 gPC.printf("\n\rACK_CODE failure (0x%02X)",temp);
chaithanyarss 189:fba4aeebf004 227 pl_main_flag = pl_main_flag & (~PL_DISABLED);
chaithanyarss 189:fba4aeebf004 228 pl_main_flag |= PL_ERR_I2C;
chaithanyarss 189:fba4aeebf004 229 pl_block[pl_next_index-1] &= (~UNEXECUTED); //changing exec_status
chaithanyarss 189:fba4aeebf004 230 pl_block[pl_next_index-1] |= RETRY;
chaithanyarss 189:fba4aeebf004 231 }
chaithanyarss 189:fba4aeebf004 232 }
chaithanyarss 189:fba4aeebf004 233 else
chaithanyarss 189:fba4aeebf004 234 {
chaithanyarss 189:fba4aeebf004 235 gPC.printf("\n\rLong_TM CRC failed");
chaithanyarss 189:fba4aeebf004 236 pl_main_flag = pl_main_flag & (~PL_DISABLED);
chaithanyarss 189:fba4aeebf004 237 pl_main_flag |= PL_ERR_I2C;
chaithanyarss 189:fba4aeebf004 238 pl_block[pl_next_index-1] &= (~UNEXECUTED); //changing exec_status
chaithanyarss 189:fba4aeebf004 239 pl_block[pl_next_index-1] |= RETRY;
chaithanyarss 189:fba4aeebf004 240 }
chaithanyarss 189:fba4aeebf004 241 }
chaithanyarss 189:fba4aeebf004 242 }
chaithanyarss 189:fba4aeebf004 243 void test1(uint8_t t)
chaithanyarss 189:fba4aeebf004 244 {
chaithanyarss 189:fba4aeebf004 245 //Output should be PL_STATUS = PL_DISABLED
chaithanyarss 189:fba4aeebf004 246 if(t!=0)
chaithanyarss 189:fba4aeebf004 247 {
chaithanyarss 189:fba4aeebf004 248 gPC.printf("\n\rTesting OC protection");
chaithanyarss 189:fba4aeebf004 249 PL_BEE_SW_STATUS = 2; //OC protection
chaithanyarss 189:fba4aeebf004 250 }
chaithanyarss 189:fba4aeebf004 251 }
chaithanyarss 189:fba4aeebf004 252 void test2(uint8_t t)
chaithanyarss 189:fba4aeebf004 253 {
chaithanyarss 189:fba4aeebf004 254 //output should be same as test1()
chaithanyarss 189:fba4aeebf004 255 if(t!=0)
chaithanyarss 189:fba4aeebf004 256 {
chaithanyarss 189:fba4aeebf004 257 gPC.printf("\n\rTesting Deviced Disabled case");
chaithanyarss 189:fba4aeebf004 258 PL_BEE_SW_STATUS = 3; //Device DISABLED
chaithanyarss 189:fba4aeebf004 259 }
chaithanyarss 189:fba4aeebf004 260 }
chaithanyarss 189:fba4aeebf004 261 void test3(uint8_t t)
chaithanyarss 189:fba4aeebf004 262 {
chaithanyarss 189:fba4aeebf004 263 if(t!=0)
chaithanyarss 189:fba4aeebf004 264 {
chaithanyarss 189:fba4aeebf004 265 gPC.printf("\n\rTesting RTC failed case");
chaithanyarss 189:fba4aeebf004 266 pl_time = 0; //RTC failed
chaithanyarss 189:fba4aeebf004 267 }
chaithanyarss 189:fba4aeebf004 268 }
chaithanyarss 189:fba4aeebf004 269 /*void test4(uint8_t t)
chaithanyarss 189:fba4aeebf004 270 {
chaithanyarss 189:fba4aeebf004 271 if(t!=0)
chaithanyarss 189:fba4aeebf004 272 {
chaithanyarss 189:fba4aeebf004 273 gPC.printf("\n\rTesting No future blocks available");
chaithanyarss 189:fba4aeebf004 274 schedule1[0] = {0,0,0,0,0,0,0,0};
chaithanyarss 189:fba4aeebf004 275 }
chaithanyarss 189:fba4aeebf004 276 }*/
chaithanyarss 189:fba4aeebf004 277 void FCTN_CDMS_PL_MAIN(void const *args)
chaithanyarss 189:fba4aeebf004 278 {
chaithanyarss 189:fba4aeebf004 279 uint8_t temp[3];
chaithanyarss 189:fba4aeebf004 280 pl_main_flag|=PL_MAIN_STATUS; //Setting PL_MAIN_STATUS
chaithanyarss 189:fba4aeebf004 281 PL_MAIN_COUNTER++;
chaithanyarss 189:fba4aeebf004 282 pl_main_flag&=~(PL_LOW_POWER); //Clearing PL_LOW_POWER
chaithanyarss 189:fba4aeebf004 283 temp[0] = (pl_main_flag&STATE_SCIENCE)>>2;
chaithanyarss 189:fba4aeebf004 284 temp[1] = (pl_main_flag&PL_DISABLED)>>4;
chaithanyarss 189:fba4aeebf004 285 temp[2] = (PL_PREV_STATE & STATE_SCIENCE)>>2;
chaithanyarss 189:fba4aeebf004 286 //test2(1);
chaithanyarss 189:fba4aeebf004 287
chaithanyarss 189:fba4aeebf004 288 if(PL_BEE_SW_STATUS==2 || PL_BEE_SW_STATUS==3)
chaithanyarss 189:fba4aeebf004 289 {
chaithanyarss 189:fba4aeebf004 290 gPC.printf("\n\rDevice Disabled or OC Fault");
chaithanyarss 189:fba4aeebf004 291 pl_main_flag = pl_main_flag & (~PL_DISABLED);
chaithanyarss 189:fba4aeebf004 292 pl_main_flag |= PL_DISABLED; //setting PL_STATUS as PL_DISABLED
chaithanyarss 189:fba4aeebf004 293 pl_main_flag = pl_main_flag & (~PL_MAIN_STATUS); //Clearing pl_main status
chaithanyarss 189:fba4aeebf004 294 print_exit(temp);
chaithanyarss 189:fba4aeebf004 295 return;
chaithanyarss 189:fba4aeebf004 296 }
chaithanyarss 189:fba4aeebf004 297 PL_PREV_STATE = (pl_main_flag & STATE_SCIENCE); //saving current pl_state
chaithanyarss 189:fba4aeebf004 298 uint64_t temp_time;
chaithanyarss 189:fba4aeebf004 299 temp_time=FCTN_CDMS_RD_RTC();
chaithanyarss 189:fba4aeebf004 300 pl_time = (uint32_t)((temp_time>>7) & 0x000000000FFFFFFF);
chaithanyarss 189:fba4aeebf004 301
chaithanyarss 189:fba4aeebf004 302 //call test3() here
chaithanyarss 189:fba4aeebf004 303 //test3(1);
chaithanyarss 189:fba4aeebf004 304
chaithanyarss 189:fba4aeebf004 305 //gPC.printf("\n\rprev_state :%d",(PL_PREV_STATE)>>4);
chaithanyarss 189:fba4aeebf004 306 gPC.printf("\n\n\rtTime_RTC:");
chaithanyarss 189:fba4aeebf004 307 gPC.printf("\n\rYear :%d\t",((pl_time & 0x0C000000)>>26)+2016);
chaithanyarss 189:fba4aeebf004 308 gPC.printf("Month :%d\t",((pl_time & 0x03C00000)>>22));
chaithanyarss 189:fba4aeebf004 309 gPC.printf("Day :%d",((pl_time & 0x003E0000)>>17));
chaithanyarss 189:fba4aeebf004 310 gPC.printf("\n\rHours :%d",((pl_time & 0x0001F000)>>12));
chaithanyarss 189:fba4aeebf004 311 gPC.printf("\tMin :%d",((pl_time & 0x00000FC0)>>6));
chaithanyarss 189:fba4aeebf004 312 gPC.printf("\t\tSec :%d",(pl_time & 0x0000003F));
chaithanyarss 189:fba4aeebf004 313 if(pl_time!=0) //RTC read successful
chaithanyarss 189:fba4aeebf004 314 {
chaithanyarss 189:fba4aeebf004 315 // run the loop until end of schedule is reached or month and day are both zeros or future block is found
chaithanyarss 189:fba4aeebf004 316 gPC.printf("\n\rRTC read success");
chaithanyarss 189:fba4aeebf004 317 for(i=0;(i<192)&&(((uint16_t)((pl_block[i] & 0x3FE00000)>>21))!=0);i++)
chaithanyarss 189:fba4aeebf004 318 {
chaithanyarss 189:fba4aeebf004 319 if(((pl_block[i]>>4) & 0x0FFFFFFF)>pl_time) //Checking for future blocks
chaithanyarss 189:fba4aeebf004 320 {
chaithanyarss 189:fba4aeebf004 321 pl_next_index=i;
chaithanyarss 189:fba4aeebf004 322 gPC.printf("\n\rFuture block found at index = %d",pl_next_index);
chaithanyarss 189:fba4aeebf004 323 break;
chaithanyarss 189:fba4aeebf004 324 }
chaithanyarss 189:fba4aeebf004 325 }
chaithanyarss 189:fba4aeebf004 326 }
chaithanyarss 189:fba4aeebf004 327 if((pl_next_index==-1) || pl_time==0) //RTC read failed or Future block not found
chaithanyarss 189:fba4aeebf004 328 {
chaithanyarss 189:fba4aeebf004 329 if(PL_PREV_STATE==STATE_SCIENCE)
chaithanyarss 189:fba4aeebf004 330 {
chaithanyarss 189:fba4aeebf004 331 pl_main_flag = pl_main_flag & (~STATE_SCIENCE);
chaithanyarss 189:fba4aeebf004 332 pl_main_flag |= STATE_HIBERNATE;
chaithanyarss 189:fba4aeebf004 333 }
chaithanyarss 189:fba4aeebf004 334 else
chaithanyarss 189:fba4aeebf004 335 {
chaithanyarss 189:fba4aeebf004 336 pl_main_flag = pl_main_flag & (~STATE_SCIENCE);
chaithanyarss 189:fba4aeebf004 337 pl_main_flag |= PL_PREV_STATE;
chaithanyarss 189:fba4aeebf004 338 }
chaithanyarss 189:fba4aeebf004 339 if(pl_time==0)
chaithanyarss 189:fba4aeebf004 340 {
chaithanyarss 189:fba4aeebf004 341 gPC.printf("\n\rRTC read failed");
chaithanyarss 189:fba4aeebf004 342 }
chaithanyarss 189:fba4aeebf004 343 if(pl_next_index==-1)
chaithanyarss 189:fba4aeebf004 344 {
chaithanyarss 189:fba4aeebf004 345 gPC.printf("\n\rFuture block not found");
chaithanyarss 189:fba4aeebf004 346 gPC.printf("\n\rpl_next_index = %d",pl_next_index);
chaithanyarss 189:fba4aeebf004 347 }
chaithanyarss 189:fba4aeebf004 348 gPC.printf("\n\rNew pl_state = %d",(pl_main_flag&(~STATE_SCIENCE))>>2);
chaithanyarss 189:fba4aeebf004 349 }
chaithanyarss 189:fba4aeebf004 350
chaithanyarss 189:fba4aeebf004 351 //Processing the PL schedule
chaithanyarss 189:fba4aeebf004 352 if(((pl_block[pl_next_index-1] & UNEXECUTED)==3)||((pl_block[pl_next_index-1] & UNEXECUTED)==2))
chaithanyarss 189:fba4aeebf004 353 {
chaithanyarss 189:fba4aeebf004 354 if(((pl_block[pl_next_index-1] & UNEXECUTED)==3))
chaithanyarss 189:fba4aeebf004 355 gPC.printf("\n\rElapsed blocked not executed");
chaithanyarss 189:fba4aeebf004 356 else
chaithanyarss 189:fba4aeebf004 357 gPC.printf("\n\rElapsed block marked for retry");
chaithanyarss 189:fba4aeebf004 358
chaithanyarss 189:fba4aeebf004 359 gPC.printf("\n\r Retrieving pl_state from schedule");
chaithanyarss 189:fba4aeebf004 360 if((pl_block[pl_next_index-1] & 0x0000000C)==0)
chaithanyarss 189:fba4aeebf004 361 {
chaithanyarss 189:fba4aeebf004 362 pl_main_flag = pl_main_flag & (~STATE_SCIENCE);
chaithanyarss 189:fba4aeebf004 363 pl_main_flag |= STATE_OFF;
chaithanyarss 189:fba4aeebf004 364 }
chaithanyarss 189:fba4aeebf004 365 if((pl_block[pl_next_index-1] & 0x0000000C)==4)
chaithanyarss 189:fba4aeebf004 366 {
chaithanyarss 189:fba4aeebf004 367 pl_main_flag = pl_main_flag & (~STATE_SCIENCE);
chaithanyarss 189:fba4aeebf004 368 pl_main_flag |= STATE_STANDBY;
chaithanyarss 189:fba4aeebf004 369 }
chaithanyarss 189:fba4aeebf004 370 if((pl_block[pl_next_index-1] & 0x0000000C)==8)
chaithanyarss 189:fba4aeebf004 371 {
chaithanyarss 189:fba4aeebf004 372 pl_main_flag = pl_main_flag & (~STATE_SCIENCE);
chaithanyarss 189:fba4aeebf004 373 pl_main_flag |= STATE_HIBERNATE;
chaithanyarss 189:fba4aeebf004 374 }
chaithanyarss 189:fba4aeebf004 375 if((pl_block[pl_next_index-1] & 0x0000000C)==12)
chaithanyarss 189:fba4aeebf004 376 {
chaithanyarss 189:fba4aeebf004 377 pl_main_flag = pl_main_flag & (~STATE_SCIENCE);
chaithanyarss 189:fba4aeebf004 378 pl_main_flag |= STATE_SCIENCE;
chaithanyarss 189:fba4aeebf004 379 }
chaithanyarss 189:fba4aeebf004 380 }
chaithanyarss 189:fba4aeebf004 381 else if((pl_block[pl_next_index-1] & UNEXECUTED)==1)
chaithanyarss 189:fba4aeebf004 382 {
chaithanyarss 189:fba4aeebf004 383 gPC.printf("\n\rElapsed block is executed");
chaithanyarss 189:fba4aeebf004 384 pl_main_flag = pl_main_flag & (~PL_MAIN_STATUS); //Clearing pl_main status
chaithanyarss 189:fba4aeebf004 385 print_exit(temp);
chaithanyarss 189:fba4aeebf004 386 return;
chaithanyarss 189:fba4aeebf004 387 }
chaithanyarss 189:fba4aeebf004 388 else if((pl_block[pl_next_index-1] & UNEXECUTED)==0)
chaithanyarss 189:fba4aeebf004 389 {
chaithanyarss 189:fba4aeebf004 390 gPC.printf("\n\rEmpty Schedule Block");
chaithanyarss 189:fba4aeebf004 391 pl_main_flag = pl_main_flag & (~PL_MAIN_STATUS); //Clearing pl_main status
chaithanyarss 189:fba4aeebf004 392 print_exit(temp);
chaithanyarss 189:fba4aeebf004 393 return;
chaithanyarss 189:fba4aeebf004 394 }
chaithanyarss 189:fba4aeebf004 395 switch(pl_main_flag & STATE_SCIENCE) //Checking PL_STATE
chaithanyarss 189:fba4aeebf004 396 {
chaithanyarss 189:fba4aeebf004 397 case STATE_OFF:
chaithanyarss 189:fba4aeebf004 398 {
chaithanyarss 189:fba4aeebf004 399 gPC.printf("\n\rEntered PL_OFF case");
chaithanyarss 189:fba4aeebf004 400 if(PL_BEE_SW_STATUS!=0)
chaithanyarss 189:fba4aeebf004 401 {
chaithanyarss 189:fba4aeebf004 402 gPC.printf("\n\rCommanding PL_BEE to go to Standby State");
chaithanyarss 189:fba4aeebf004 403 Base_tm *tm_ptr_standby;
chaithanyarss 189:fba4aeebf004 404 SET_PL_BEE_STANDBY(tm_ptr_standby); //No ack needed now
chaithanyarss 189:fba4aeebf004 405 gPC.printf("\n\rPowering OFF PL_BEE");
chaithanyarss 189:fba4aeebf004 406 SET_PL_BEE_OFF;
chaithanyarss 189:fba4aeebf004 407 PL_BEE_SW_STATUS=0;
chaithanyarss 189:fba4aeebf004 408 }
chaithanyarss 189:fba4aeebf004 409 pl_main_flag = pl_main_flag & (~PL_DISABLED);
chaithanyarss 189:fba4aeebf004 410 pl_main_flag |= PL_OFF;
chaithanyarss 189:fba4aeebf004 411 pl_block[pl_next_index-1] &= (~UNEXECUTED); //changing exec_status
chaithanyarss 189:fba4aeebf004 412 pl_block[pl_next_index-1] |= EXECUTED;
chaithanyarss 189:fba4aeebf004 413 pl_main_flag = pl_main_flag & (~PL_MAIN_STATUS); //Clearing PL_MAIN_STATUS
chaithanyarss 189:fba4aeebf004 414 print_processed_block(pl_next_index-1);
chaithanyarss 189:fba4aeebf004 415 print_exit(temp);
chaithanyarss 189:fba4aeebf004 416 return;
chaithanyarss 189:fba4aeebf004 417 }
chaithanyarss 189:fba4aeebf004 418 case STATE_STANDBY:
chaithanyarss 189:fba4aeebf004 419 {
chaithanyarss 189:fba4aeebf004 420 gPC.printf("\n\rEntered PL_STANDBY case");
chaithanyarss 189:fba4aeebf004 421 if(PL_BEE_SW_STATUS==0)
chaithanyarss 189:fba4aeebf004 422 {
chaithanyarss 189:fba4aeebf004 423 gPC.printf("\n\rPowering on PL_BEE");
chaithanyarss 189:fba4aeebf004 424 SET_PL_BEE_ON;
chaithanyarss 189:fba4aeebf004 425 PL_BEE_SW_STATUS=1;
chaithanyarss 189:fba4aeebf004 426 }
chaithanyarss 189:fba4aeebf004 427 gPC.printf("\n\rCommanding PL_BEE to go to Standby State");
chaithanyarss 189:fba4aeebf004 428 Base_tm *tm_ptr_standby;
chaithanyarss 189:fba4aeebf004 429 SET_PL_BEE_STANDBY(tm_ptr_standby);
chaithanyarss 189:fba4aeebf004 430 if((pl_main_flag & PL_DISABLED)==PL_SUCCESS_I2C)
chaithanyarss 189:fba4aeebf004 431 {
chaithanyarss 189:fba4aeebf004 432 pl_main_flag = pl_main_flag & (~PL_DISABLED);
chaithanyarss 189:fba4aeebf004 433 pl_main_flag |= PL_STANDBY;
chaithanyarss 189:fba4aeebf004 434 }
chaithanyarss 189:fba4aeebf004 435 pl_main_flag = pl_main_flag & (~PL_MAIN_STATUS); //Clearing PL_MAIN_STATUS
chaithanyarss 189:fba4aeebf004 436 print_processed_block(pl_next_index-1);
chaithanyarss 189:fba4aeebf004 437 print_exit(temp);
chaithanyarss 189:fba4aeebf004 438 return;
chaithanyarss 189:fba4aeebf004 439 //////DELETE THE TM AND TC LATER
chaithanyarss 189:fba4aeebf004 440 }
chaithanyarss 189:fba4aeebf004 441 case STATE_HIBERNATE:
chaithanyarss 189:fba4aeebf004 442 {
chaithanyarss 189:fba4aeebf004 443 gPC.printf("\n\rEntered PL_HIBERNATE case");
chaithanyarss 189:fba4aeebf004 444 if(POWER_LEVEL==2 || POWER_LEVEL==3 || POWER_LEVEL==0)
chaithanyarss 189:fba4aeebf004 445 {
chaithanyarss 189:fba4aeebf004 446 if(PL_BEE_SW_STATUS==0)
chaithanyarss 189:fba4aeebf004 447 {
chaithanyarss 189:fba4aeebf004 448 gPC.printf("Powering on PL_BEE\r\n");
chaithanyarss 189:fba4aeebf004 449 SET_PL_BEE_ON;
chaithanyarss 189:fba4aeebf004 450 PL_BEE_SW_STATUS=1;
chaithanyarss 189:fba4aeebf004 451 }
chaithanyarss 189:fba4aeebf004 452 gPC.printf("\n\rCommanding PL_BEE to go to Hibernate State");
chaithanyarss 189:fba4aeebf004 453 Base_tm *tm_ptr_hibernate;
chaithanyarss 189:fba4aeebf004 454 SET_PL_BEE_HIBERNATE(tm_ptr_hibernate);
chaithanyarss 189:fba4aeebf004 455 if((pl_main_flag & PL_DISABLED)==PL_SUCCESS_I2C)
chaithanyarss 189:fba4aeebf004 456 {
chaithanyarss 189:fba4aeebf004 457 pl_main_flag = pl_main_flag & (~PL_DISABLED);
chaithanyarss 189:fba4aeebf004 458 pl_main_flag |= PL_HIBERNATE;
chaithanyarss 189:fba4aeebf004 459 }
chaithanyarss 189:fba4aeebf004 460 }
chaithanyarss 189:fba4aeebf004 461 else
chaithanyarss 189:fba4aeebf004 462 {
chaithanyarss 189:fba4aeebf004 463 pl_main_flag |= PL_LOW_POWER;
chaithanyarss 189:fba4aeebf004 464 if(PL_BEE_SW_STATUS==0)
chaithanyarss 189:fba4aeebf004 465 {
chaithanyarss 189:fba4aeebf004 466 gPC.printf("\n\rPowering on PL_BEE");
chaithanyarss 189:fba4aeebf004 467 SET_PL_BEE_ON;
chaithanyarss 189:fba4aeebf004 468 PL_BEE_SW_STATUS=1;
chaithanyarss 189:fba4aeebf004 469 }
chaithanyarss 189:fba4aeebf004 470 gPC.printf("\n\rCommanding PL_BEE to go to Standby State");
chaithanyarss 189:fba4aeebf004 471 Base_tm *tm_ptr_standby;
chaithanyarss 189:fba4aeebf004 472 SET_PL_BEE_STANDBY(tm_ptr_standby);
chaithanyarss 189:fba4aeebf004 473 if((pl_main_flag & PL_DISABLED)==PL_SUCCESS_I2C)
chaithanyarss 189:fba4aeebf004 474 {
chaithanyarss 189:fba4aeebf004 475 pl_main_flag = pl_main_flag & (~PL_DISABLED);
chaithanyarss 189:fba4aeebf004 476 pl_main_flag |= PL_STANDBY;
chaithanyarss 189:fba4aeebf004 477 }
chaithanyarss 189:fba4aeebf004 478 pl_main_flag = pl_main_flag & (~PL_MAIN_STATUS); //Clearing PL_MAIN_STATUS
chaithanyarss 189:fba4aeebf004 479 print_processed_block(pl_next_index-1);
chaithanyarss 189:fba4aeebf004 480 print_exit(temp);
chaithanyarss 189:fba4aeebf004 481 return;
chaithanyarss 189:fba4aeebf004 482 //////DELETE THE TM AND TC LATER
chaithanyarss 189:fba4aeebf004 483 }
chaithanyarss 189:fba4aeebf004 484 pl_main_flag = pl_main_flag & (~PL_MAIN_STATUS); //Clearing PL_MAIN_STATUS
chaithanyarss 189:fba4aeebf004 485 print_processed_block(pl_next_index-1);
chaithanyarss 189:fba4aeebf004 486 print_exit(temp);
chaithanyarss 189:fba4aeebf004 487 return;
chaithanyarss 189:fba4aeebf004 488 //////DELETE THE TM LATER
chaithanyarss 189:fba4aeebf004 489 }
chaithanyarss 189:fba4aeebf004 490 case STATE_SCIENCE:
chaithanyarss 189:fba4aeebf004 491 {
chaithanyarss 189:fba4aeebf004 492 gPC.printf("\n\rEntered PL_SCIENCE case");
chaithanyarss 189:fba4aeebf004 493 if(POWER_LEVEL==3 || POWER_LEVEL==0) //POWER_LEVEL = 0 = NA
chaithanyarss 189:fba4aeebf004 494 {
chaithanyarss 189:fba4aeebf004 495 gPC.printf("\n\rPOWER_LEVEL = 3 or NA");
chaithanyarss 189:fba4aeebf004 496 if(PL_BEE_SW_STATUS==0)
chaithanyarss 189:fba4aeebf004 497 {
chaithanyarss 189:fba4aeebf004 498 gPC.printf("\n\rPowering on PL_BEE");
chaithanyarss 189:fba4aeebf004 499 SET_PL_BEE_ON;
chaithanyarss 189:fba4aeebf004 500 PL_BEE_SW_STATUS=1;
chaithanyarss 189:fba4aeebf004 501 }
chaithanyarss 189:fba4aeebf004 502 gPC.printf("\n\rCommanding PL_BEE to go to Science State");
chaithanyarss 189:fba4aeebf004 503 Base_tm *tm_ptr_science;
chaithanyarss 189:fba4aeebf004 504 SET_PL_BEE_SCIENCE(tm_ptr_science);
chaithanyarss 189:fba4aeebf004 505 if((pl_main_flag & PL_DISABLED)==PL_SUCCESS_I2C)
chaithanyarss 189:fba4aeebf004 506 {
chaithanyarss 189:fba4aeebf004 507 pl_main_flag = pl_main_flag & (~PL_DISABLED);
chaithanyarss 189:fba4aeebf004 508 pl_main_flag |= PL_SCIENCE;
chaithanyarss 189:fba4aeebf004 509 }
chaithanyarss 189:fba4aeebf004 510 pl_main_flag = pl_main_flag & (~PL_MAIN_STATUS); //Clearing PL_MAIN_STATUS
chaithanyarss 189:fba4aeebf004 511 print_processed_block(pl_next_index-1);
chaithanyarss 189:fba4aeebf004 512 print_exit(temp);
chaithanyarss 189:fba4aeebf004 513 return;
chaithanyarss 189:fba4aeebf004 514 }
chaithanyarss 189:fba4aeebf004 515 else
chaithanyarss 189:fba4aeebf004 516 {
chaithanyarss 189:fba4aeebf004 517 gPC.printf("\n\rPower level = 2,3 or NA");
chaithanyarss 189:fba4aeebf004 518 pl_main_flag |= PL_LOW_POWER;
chaithanyarss 189:fba4aeebf004 519 if(POWER_LEVEL==2 || POWER_LEVEL==3 || POWER_LEVEL==0)
chaithanyarss 189:fba4aeebf004 520 {
chaithanyarss 189:fba4aeebf004 521 if(PL_BEE_SW_STATUS==0)
chaithanyarss 189:fba4aeebf004 522 {
chaithanyarss 189:fba4aeebf004 523 gPC.printf("\n\rPowering on PL_BEE");
chaithanyarss 189:fba4aeebf004 524 SET_PL_BEE_ON;
chaithanyarss 189:fba4aeebf004 525 PL_BEE_SW_STATUS=1;
chaithanyarss 189:fba4aeebf004 526 }
chaithanyarss 189:fba4aeebf004 527 gPC.printf("\n\rCommanding PL_BEE to go to Hibernate State");
chaithanyarss 189:fba4aeebf004 528 Base_tm *tm_ptr_hibernate;
chaithanyarss 189:fba4aeebf004 529 SET_PL_BEE_HIBERNATE(tm_ptr_hibernate);
chaithanyarss 189:fba4aeebf004 530 if((pl_main_flag & PL_DISABLED)==PL_SUCCESS_I2C)
chaithanyarss 189:fba4aeebf004 531 {
chaithanyarss 189:fba4aeebf004 532 pl_main_flag = pl_main_flag & (~PL_DISABLED);
chaithanyarss 189:fba4aeebf004 533 pl_main_flag |= PL_HIBERNATE;
chaithanyarss 189:fba4aeebf004 534 }
chaithanyarss 189:fba4aeebf004 535 }
chaithanyarss 189:fba4aeebf004 536 else
chaithanyarss 189:fba4aeebf004 537 {
chaithanyarss 189:fba4aeebf004 538 pl_main_flag |= PL_LOW_POWER;
chaithanyarss 189:fba4aeebf004 539 if(PL_BEE_SW_STATUS==0)
chaithanyarss 189:fba4aeebf004 540 {
chaithanyarss 189:fba4aeebf004 541 gPC.printf("\n\rPowering on PL_BEE");
chaithanyarss 189:fba4aeebf004 542 SET_PL_BEE_ON;
chaithanyarss 189:fba4aeebf004 543 PL_BEE_SW_STATUS=1;
chaithanyarss 189:fba4aeebf004 544 }
chaithanyarss 189:fba4aeebf004 545 gPC.printf("\n\rCommanding PL_BEE to go to Standby State");
chaithanyarss 189:fba4aeebf004 546 Base_tm *tm_ptr_standby;
chaithanyarss 189:fba4aeebf004 547 SET_PL_BEE_STANDBY(tm_ptr_standby);
chaithanyarss 189:fba4aeebf004 548 if((pl_main_flag & PL_DISABLED)==PL_SUCCESS_I2C)
chaithanyarss 189:fba4aeebf004 549 {
chaithanyarss 189:fba4aeebf004 550 pl_main_flag = pl_main_flag & (~PL_DISABLED);
chaithanyarss 189:fba4aeebf004 551 pl_main_flag |= PL_STANDBY;
chaithanyarss 189:fba4aeebf004 552 }
chaithanyarss 189:fba4aeebf004 553 pl_main_flag = pl_main_flag & (~PL_MAIN_STATUS); //Clearing PL_MAIN_STATUS
chaithanyarss 189:fba4aeebf004 554 print_processed_block(pl_next_index-1);
chaithanyarss 189:fba4aeebf004 555 print_exit(temp);
chaithanyarss 189:fba4aeebf004 556 return;
chaithanyarss 189:fba4aeebf004 557 //////DELETE THE TM AND TC LATER
chaithanyarss 189:fba4aeebf004 558 }
chaithanyarss 189:fba4aeebf004 559 pl_main_flag = pl_main_flag & (~PL_MAIN_STATUS); //Clearing PL_MAIN_STATUS
chaithanyarss 189:fba4aeebf004 560 print_processed_block(pl_next_index-1);
chaithanyarss 189:fba4aeebf004 561 print_exit(temp);
chaithanyarss 189:fba4aeebf004 562 return;
chaithanyarss 189:fba4aeebf004 563 //////DELETE THE TM LATER
chaithanyarss 189:fba4aeebf004 564 }
chaithanyarss 189:fba4aeebf004 565 }
chaithanyarss 189:fba4aeebf004 566 default:
chaithanyarss 189:fba4aeebf004 567 {
chaithanyarss 189:fba4aeebf004 568 gPC.printf("\n\rInvalid PL_STATE in block at index = %d",pl_next_index-1);
chaithanyarss 189:fba4aeebf004 569 pl_main_flag = pl_main_flag & (~PL_DISABLED);
chaithanyarss 189:fba4aeebf004 570 pl_main_flag |= PL_INVALID_STATE;
chaithanyarss 189:fba4aeebf004 571 pl_block[pl_next_index-1] &= (~UNEXECUTED); //changing exec_status
chaithanyarss 189:fba4aeebf004 572 pl_block[pl_next_index-1] |= EXECUTED;
chaithanyarss 189:fba4aeebf004 573 pl_main_flag = pl_main_flag & (~PL_MAIN_STATUS); //Clearing PL_MAIN_STATUS
chaithanyarss 189:fba4aeebf004 574 print_processed_block(pl_next_index-1);
chaithanyarss 189:fba4aeebf004 575 print_exit(temp);
chaithanyarss 189:fba4aeebf004 576 return;
chaithanyarss 189:fba4aeebf004 577 }
chaithanyarss 189:fba4aeebf004 578 }
chaithanyarss 189:fba4aeebf004 579 }