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