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