![](/media/cache/group/nine_tails_kurama_by_zubair43-d4zyf5s.jpg.50x50_q85.jpg)
PWM and ALGO updated.. PWM getting generated
Dependencies: FreescaleIAP mbed-rtos mbed
Fork of TFR_BAE_vr1_1working_finally_PWM_update by
main.cpp@5:bb592f3185cc, 2015-12-31 (annotated)
- Committer:
- sakthipriya
- Date:
- Thu Dec 31 17:12:52 2015 +0000
- Revision:
- 5:bb592f3185cc
- Parent:
- 4:39a4ae8c7ecd
- Child:
- 6:036d08b62785
final version of BAE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sakthipriya | 0:7b4c00e3912f | 1 | #include "mbed.h" |
sakthipriya | 0:7b4c00e3912f | 2 | #include "rtos.h" |
sakthipriya | 0:7b4c00e3912f | 3 | #include "pin_config.h" |
sakthipriya | 0:7b4c00e3912f | 4 | #include "ACS.h" |
sakthipriya | 0:7b4c00e3912f | 5 | #include "EPS.h" |
sakthipriya | 0:7b4c00e3912f | 6 | #include "BCN.h" |
sakthipriya | 0:7b4c00e3912f | 7 | #include "TCTM.h" |
sakthipriya | 0:7b4c00e3912f | 8 | |
sakthipriya | 0:7b4c00e3912f | 9 | #define tm_len 134 |
sakthipriya | 0:7b4c00e3912f | 10 | #define tc_len 135 |
sakthipriya | 0:7b4c00e3912f | 11 | #define batt_heat_low 20 |
sakthipriya | 0:7b4c00e3912f | 12 | //***************************************************** flags *************************************************************// |
sakthipriya | 0:7b4c00e3912f | 13 | uint32_t BAE_STATUS = 0x00000000; |
sakthipriya | 0:7b4c00e3912f | 14 | uint32_t BAE_ENABLE = 0xFFFFFFFF; |
sakthipriya | 0:7b4c00e3912f | 15 | |
sakthipriya | 5:bb592f3185cc | 16 | //i2c// |
sakthipriya | 5:bb592f3185cc | 17 | char data_send_flag = 'h'; |
sakthipriya | 5:bb592f3185cc | 18 | |
sakthipriya | 0:7b4c00e3912f | 19 | //.........acs...............// |
sakthipriya | 0:7b4c00e3912f | 20 | char ACS_INIT_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 21 | char ACS_DATA_ACQ_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 22 | char ACS_ATS_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 23 | char ACS_MAIN_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 24 | char ACS_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 25 | |
sakthipriya | 0:7b4c00e3912f | 26 | char ACS_ATS_ENABLE = 'q'; |
sakthipriya | 0:7b4c00e3912f | 27 | char ACS_DATA_ACQ_ENABLE = 'q'; |
sakthipriya | 0:7b4c00e3912f | 28 | char ACS_STATE = 'q'; |
sakthipriya | 0:7b4c00e3912f | 29 | |
sakthipriya | 0:7b4c00e3912f | 30 | //.....................eps...................// |
sakthipriya | 0:7b4c00e3912f | 31 | //eps init |
sakthipriya | 0:7b4c00e3912f | 32 | char EPS_INIT_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 33 | char EPS_BATTERY_GAUGE_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 34 | //eps main |
sakthipriya | 0:7b4c00e3912f | 35 | char EPS_MAIN_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 36 | char EPS_BATTERY_TEMP_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 37 | char EPS_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 38 | |
sakthipriya | 0:7b4c00e3912f | 39 | char EPS_BATTERY_HEAT_ENABLE = 'q'; |
sakthipriya | 0:7b4c00e3912f | 40 | |
sakthipriya | 0:7b4c00e3912f | 41 | //.......................global variables..................................................................// new hk structure- everything has to changed based on this |
sakthipriya | 5:bb592f3185cc | 42 | uint8_t BAE_data[73]; |
sakthipriya | 0:7b4c00e3912f | 43 | |
sakthipriya | 0:7b4c00e3912f | 44 | |
sakthipriya | 0:7b4c00e3912f | 45 | //*************************************Global declarations************************************************// |
sakthipriya | 0:7b4c00e3912f | 46 | const int addr = 0x20; //slave address |
sakthipriya | 0:7b4c00e3912f | 47 | |
sakthipriya | 0:7b4c00e3912f | 48 | Timer t_rfsilence; |
sakthipriya | 0:7b4c00e3912f | 49 | Timer t_start; |
sakthipriya | 0:7b4c00e3912f | 50 | Serial pc(USBTX, USBRX); |
sakthipriya | 0:7b4c00e3912f | 51 | int power_flag_dummy=2; |
sakthipriya | 0:7b4c00e3912f | 52 | float data[6]; |
sakthipriya | 0:7b4c00e3912f | 53 | |
sakthipriya | 0:7b4c00e3912f | 54 | extern float moment[3]; |
sakthipriya | 0:7b4c00e3912f | 55 | extern uint8_t BCN_FEN; |
sakthipriya | 1:446a959e36ce | 56 | extern BAE_HK_actual actual_data; |
sakthipriya | 1:446a959e36ce | 57 | extern BAE_HK_quant quant_data; |
sakthipriya | 1:446a959e36ce | 58 | extern BAE_HK_min_max bae_HK_minmax; |
sakthipriya | 1:446a959e36ce | 59 | extern BAE_HK_arch arch_data; |
sakthipriya | 0:7b4c00e3912f | 60 | |
sakthipriya | 5:bb592f3185cc | 61 | int write_ack = 1; |
sakthipriya | 5:bb592f3185cc | 62 | int read_ack = 1; |
sakthipriya | 0:7b4c00e3912f | 63 | char telecommand[tc_len]; |
sakthipriya | 3:07e15677a75c | 64 | char* telemetry; |
sakthipriya | 5:bb592f3185cc | 65 | |
sakthipriya | 5:bb592f3185cc | 66 | bool pf1check = 0; |
sakthipriya | 5:bb592f3185cc | 67 | bool pf2check = 0; |
sakthipriya | 5:bb592f3185cc | 68 | bool if1check = 0; |
sakthipriya | 5:bb592f3185cc | 69 | bool if2check = 1; |
sakthipriya | 0:7b4c00e3912f | 70 | |
sakthipriya | 0:7b4c00e3912f | 71 | //*****************************************************Assigning pins******************************************************// |
sakthipriya | 0:7b4c00e3912f | 72 | DigitalOut gpo1(PTC0); // enable of att sens2 switch |
sakthipriya | 0:7b4c00e3912f | 73 | DigitalOut gpo2(PTC16); // enable of att sens switch |
sakthipriya | 0:7b4c00e3912f | 74 | InterruptIn irpt_4m_mstr(PIN38); //I2c interrupt from CDMS |
sakthipriya | 0:7b4c00e3912f | 75 | DigitalOut irpt_2_mstr(PIN4); //I2C interrupt to CDMS |
sakthipriya | 0:7b4c00e3912f | 76 | I2CSlave slave (PIN1,PIN2); |
sakthipriya | 0:7b4c00e3912f | 77 | DigitalOut batt_heat(PIN96); |
sakthipriya | 0:7b4c00e3912f | 78 | |
sakthipriya | 0:7b4c00e3912f | 79 | //gpo1 = 0; |
sakthipriya | 0:7b4c00e3912f | 80 | PwmOut PWM1(PIN93); //x //Functions used to generate PWM signal |
sakthipriya | 0:7b4c00e3912f | 81 | PwmOut PWM2(PIN94); //y |
sakthipriya | 0:7b4c00e3912f | 82 | PwmOut PWM3(PIN95); //z //PWM output comes from pins p6 |
sakthipriya | 0:7b4c00e3912f | 83 | |
sakthipriya | 5:bb592f3185cc | 84 | //........faults |
sakthipriya | 5:bb592f3185cc | 85 | //Polled Faults |
sakthipriya | 5:bb592f3185cc | 86 | DigitalIn pf1(PIN5);//Attitude Sensor 1 OC bar fault signal |
sakthipriya | 5:bb592f3185cc | 87 | DigitalIn pf2(PIN97);//Attitude Sensor 2 OC bar fault signal |
sakthipriya | 5:bb592f3185cc | 88 | DigitalIn pf3(PIN83);//Fault Bar for TRXY driver |
sakthipriya | 5:bb592f3185cc | 89 | |
sakthipriya | 5:bb592f3185cc | 90 | //Interrupt based faults |
sakthipriya | 5:bb592f3185cc | 91 | //InterruptIn ir1(PIN73);//Battery Gauge - Alert Bar Signal |
sakthipriya | 5:bb592f3185cc | 92 | InterruptIn ir2(PIN72);//TRXY Driver TR switch Fault |
sakthipriya | 5:bb592f3185cc | 93 | InterruptIn ir3(PIN89);//TRZ Driver Fault Bar |
sakthipriya | 5:bb592f3185cc | 94 | InterruptIn ir4(PIN91);//TRZ Driver TR switch Fault |
sakthipriya | 5:bb592f3185cc | 95 | InterruptIn ir5(PIN79);//CDMS - Switch Fault |
sakthipriya | 5:bb592f3185cc | 96 | InterruptIn ir6(PIN80);//Beacon- Switch OC bar |
sakthipriya | 5:bb592f3185cc | 97 | InterruptIn ir7(PIN42);//Charger IC - Fault Bar |
sakthipriya | 5:bb592f3185cc | 98 | |
sakthipriya | 5:bb592f3185cc | 99 | DigitalOut TRXY_SW(PIN71); //TR XY Switch |
sakthipriya | 5:bb592f3185cc | 100 | DigitalOut DRV_Z_SLP(PIN88); //Sleep pin of driver z |
sakthipriya | 5:bb592f3185cc | 101 | DigitalOut TRZ_SW(PIN40); //TR Z Switch |
sakthipriya | 5:bb592f3185cc | 102 | DigitalOut CDMS_RESET(PIN7); // CDMS RESET |
sakthipriya | 5:bb592f3185cc | 103 | DigitalOut BCN_SW(PIN14); //Beacon switch |
sakthipriya | 5:bb592f3185cc | 104 | DigitalOut DRV_XY_SLP(PIN82); |
sakthipriya | 5:bb592f3185cc | 105 | |
sakthipriya | 5:bb592f3185cc | 106 | |
sakthipriya | 5:bb592f3185cc | 107 | |
sakthipriya | 0:7b4c00e3912f | 108 | |
sakthipriya | 0:7b4c00e3912f | 109 | /*****************************************************************Threads USed***********************************************************************************/ |
sakthipriya | 3:07e15677a75c | 110 | |
sakthipriya | 0:7b4c00e3912f | 111 | Thread *ptr_t_i2c; |
sakthipriya | 0:7b4c00e3912f | 112 | |
sakthipriya | 0:7b4c00e3912f | 113 | /*********************************************************FCTN HEADERS***********************************************************************************/ |
sakthipriya | 0:7b4c00e3912f | 114 | |
sakthipriya | 0:7b4c00e3912f | 115 | void FCTN_ISR_I2C(); |
sakthipriya | 0:7b4c00e3912f | 116 | void FCTN_TM(); |
sakthipriya | 3:07e15677a75c | 117 | void F_ACS(); |
sakthipriya | 3:07e15677a75c | 118 | void F_EPS(); |
sakthipriya | 3:07e15677a75c | 119 | void F_BCN(); |
sakthipriya | 0:7b4c00e3912f | 120 | |
sakthipriya | 0:7b4c00e3912f | 121 | //*******************************************ACS THREAD**************************************************// |
sakthipriya | 5:bb592f3185cc | 122 | uint8_t iterP1; |
sakthipriya | 5:bb592f3185cc | 123 | uint8_t iterP2; |
sakthipriya | 5:bb592f3185cc | 124 | uint8_t iterI1; |
sakthipriya | 5:bb592f3185cc | 125 | uint8_t iterI2; |
sakthipriya | 0:7b4c00e3912f | 126 | |
sakthipriya | 5:bb592f3185cc | 127 | |
sakthipriya | 3:07e15677a75c | 128 | void F_ACS() |
sakthipriya | 0:7b4c00e3912f | 129 | { |
sakthipriya | 5:bb592f3185cc | 130 | if(pf1check == 1) |
sakthipriya | 5:bb592f3185cc | 131 | { |
sakthipriya | 5:bb592f3185cc | 132 | if(iterP1 >= 3) |
sakthipriya | 5:bb592f3185cc | 133 | { |
sakthipriya | 5:bb592f3185cc | 134 | gpo1 = 1; // turn off ats1 permanently |
sakthipriya | 5:bb592f3185cc | 135 | //FCTN_SWITCH_ATS(0); // switch on ATS2 |
sakthipriya | 5:bb592f3185cc | 136 | } |
sakthipriya | 5:bb592f3185cc | 137 | else |
sakthipriya | 5:bb592f3185cc | 138 | { |
sakthipriya | 5:bb592f3185cc | 139 | gpo1 = 0; |
sakthipriya | 5:bb592f3185cc | 140 | iterP1++; |
sakthipriya | 5:bb592f3185cc | 141 | } |
sakthipriya | 5:bb592f3185cc | 142 | } |
sakthipriya | 5:bb592f3185cc | 143 | if(pf2check == 1) |
sakthipriya | 5:bb592f3185cc | 144 | { |
sakthipriya | 5:bb592f3185cc | 145 | if(iterP1 >= 3) |
sakthipriya | 5:bb592f3185cc | 146 | { |
sakthipriya | 5:bb592f3185cc | 147 | gpo2 = 1; // turn off ats2 permanently |
sakthipriya | 5:bb592f3185cc | 148 | ACS_DATA_ACQ_ENABLE == 'd'; |
sakthipriya | 5:bb592f3185cc | 149 | ACS_STATE == '2' ; // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY |
sakthipriya | 5:bb592f3185cc | 150 | } |
sakthipriya | 5:bb592f3185cc | 151 | else |
sakthipriya | 5:bb592f3185cc | 152 | { |
sakthipriya | 5:bb592f3185cc | 153 | gpo2 = 0; |
sakthipriya | 5:bb592f3185cc | 154 | iterP2++; |
sakthipriya | 5:bb592f3185cc | 155 | } |
sakthipriya | 5:bb592f3185cc | 156 | } |
sakthipriya | 5:bb592f3185cc | 157 | if(if1check == 1) |
sakthipriya | 5:bb592f3185cc | 158 | { |
sakthipriya | 5:bb592f3185cc | 159 | if(iterI1 >= 3) |
sakthipriya | 5:bb592f3185cc | 160 | { |
sakthipriya | 5:bb592f3185cc | 161 | TRXY_SW = 0; // turn off TRXY permanently |
sakthipriya | 5:bb592f3185cc | 162 | } |
sakthipriya | 5:bb592f3185cc | 163 | else |
sakthipriya | 5:bb592f3185cc | 164 | { |
sakthipriya | 5:bb592f3185cc | 165 | TRXY_SW = 1; //switch on TRXY |
sakthipriya | 5:bb592f3185cc | 166 | iterI1++; |
sakthipriya | 5:bb592f3185cc | 167 | } |
sakthipriya | 5:bb592f3185cc | 168 | } |
sakthipriya | 5:bb592f3185cc | 169 | if(if2check == 1) |
sakthipriya | 5:bb592f3185cc | 170 | { |
sakthipriya | 5:bb592f3185cc | 171 | if(iterI2 >= 3) |
sakthipriya | 5:bb592f3185cc | 172 | { |
sakthipriya | 5:bb592f3185cc | 173 | TRZ_SW = 0; // turn off TRZ permanently |
sakthipriya | 5:bb592f3185cc | 174 | ACS_STATE == '2' ; // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY |
sakthipriya | 5:bb592f3185cc | 175 | } |
sakthipriya | 5:bb592f3185cc | 176 | else |
sakthipriya | 5:bb592f3185cc | 177 | { |
sakthipriya | 5:bb592f3185cc | 178 | TRZ_SW = 1; //switch on Z |
sakthipriya | 5:bb592f3185cc | 179 | iterI2++; |
sakthipriya | 5:bb592f3185cc | 180 | } |
sakthipriya | 5:bb592f3185cc | 181 | } |
sakthipriya | 5:bb592f3185cc | 182 | |
sakthipriya | 0:7b4c00e3912f | 183 | float b1[3]={-23.376,-37.56,14.739}, omega1[3]={-1.52,2.746,0.7629}, moment1[3]= {1.0498,-1.0535,1.3246}; |
sakthipriya | 0:7b4c00e3912f | 184 | //b1[3] = {22, 22,10}; |
sakthipriya | 0:7b4c00e3912f | 185 | //omega1[3] = {2.1,3.0,1.5}; |
sakthipriya | 0:7b4c00e3912f | 186 | // gpo1 = 0; // att sens2 switch is disabled |
sakthipriya | 0:7b4c00e3912f | 187 | // gpo2 = 0; // att sens switch is disabled |
sakthipriya | 0:7b4c00e3912f | 188 | |
sakthipriya | 3:07e15677a75c | 189 | |
sakthipriya | 0:7b4c00e3912f | 190 | |
sakthipriya | 3:07e15677a75c | 191 | //Thread::signal_wait(0x1); |
sakthipriya | 0:7b4c00e3912f | 192 | ACS_MAIN_STATUS = 's'; //set ACS_MAIN_STATUS flag |
sakthipriya | 0:7b4c00e3912f | 193 | PWM1 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 194 | PWM2 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 195 | PWM3 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 196 | pc.printf("\n\rEntered ACS %f\n",t_start.read()); |
sakthipriya | 0:7b4c00e3912f | 197 | |
sakthipriya | 0:7b4c00e3912f | 198 | if(ACS_DATA_ACQ_ENABLE == 'e')// check if ACS_DATA_ACQ_ENABLE = 1? |
sakthipriya | 0:7b4c00e3912f | 199 | { |
sakthipriya | 0:7b4c00e3912f | 200 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 201 | FCTN_ATS_DATA_ACQ(); //the angular velocity is stored in the first 3 values and magnetic field values in next 3 |
sakthipriya | 0:7b4c00e3912f | 202 | pc.printf("gyro values\n\r"); //printing the angular velocity and magnetic field values |
sakthipriya | 0:7b4c00e3912f | 203 | for(int i=0; i<3; i++) |
sakthipriya | 0:7b4c00e3912f | 204 | { |
sakthipriya | 0:7b4c00e3912f | 205 | pc.printf("%f\n\r",data[i]); |
sakthipriya | 0:7b4c00e3912f | 206 | } |
sakthipriya | 0:7b4c00e3912f | 207 | pc.printf("mag values\n\r"); |
sakthipriya | 0:7b4c00e3912f | 208 | for(int i=3; i<6; i++) |
sakthipriya | 0:7b4c00e3912f | 209 | { |
sakthipriya | 0:7b4c00e3912f | 210 | pc.printf("%f\n\r",data[i]); |
sakthipriya | 5:bb592f3185cc | 211 | } |
sakthipriya | 0:7b4c00e3912f | 212 | for(int i=0;i<3;i++) |
sakthipriya | 0:7b4c00e3912f | 213 | { |
sakthipriya | 0:7b4c00e3912f | 214 | omega1[i]= data[i]; |
sakthipriya | 0:7b4c00e3912f | 215 | b1[i] = data[i+3]; |
sakthipriya | 0:7b4c00e3912f | 216 | } |
sakthipriya | 0:7b4c00e3912f | 217 | }//if ACS_DATA_ACQ_ENABLE = 1 |
sakthipriya | 0:7b4c00e3912f | 218 | else |
sakthipriya | 0:7b4c00e3912f | 219 | { |
sakthipriya | 0:7b4c00e3912f | 220 | // Z axis actuation is the only final solution, |
sakthipriya | 0:7b4c00e3912f | 221 | } |
sakthipriya | 0:7b4c00e3912f | 222 | if(ACS_STATE == '0') // check ACS_STATE = ACS_CONTROL_OFF? |
sakthipriya | 0:7b4c00e3912f | 223 | { |
sakthipriya | 0:7b4c00e3912f | 224 | printf("\n\r acs control off\n"); |
sakthipriya | 0:7b4c00e3912f | 225 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 226 | ACS_STATUS = '0'; // set ACS_STATUS = ACS_CONTROL_OFF |
sakthipriya | 0:7b4c00e3912f | 227 | PWM1 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 228 | PWM2 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 229 | PWM3 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 230 | } |
sakthipriya | 0:7b4c00e3912f | 231 | else |
sakthipriya | 0:7b4c00e3912f | 232 | { |
sakthipriya | 1:446a959e36ce | 233 | if(actual_data.power_mode>1) |
sakthipriya | 0:7b4c00e3912f | 234 | |
sakthipriya | 0:7b4c00e3912f | 235 | { |
sakthipriya | 0:7b4c00e3912f | 236 | if(ACS_STATE == '2') // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY |
sakthipriya | 0:7b4c00e3912f | 237 | { |
sakthipriya | 0:7b4c00e3912f | 238 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 239 | printf("\n\r z axis moment only\n"); |
sakthipriya | 0:7b4c00e3912f | 240 | ACS_STATUS = '2'; // set ACS_STATUS = ACS_ZAXIS_MOMENT_ONLY |
sakthipriya | 0:7b4c00e3912f | 241 | // FCTN_ACS_CNTRLALGO(b1, omega1); |
sakthipriya | 0:7b4c00e3912f | 242 | moment[0] = 0; |
sakthipriya | 0:7b4c00e3912f | 243 | moment[1] = 0; |
sakthipriya | 0:7b4c00e3912f | 244 | moment[2] =1.3;// is a dummy value |
sakthipriya | 0:7b4c00e3912f | 245 | FCTN_ACS_GENPWM_MAIN(moment) ; |
sakthipriya | 0:7b4c00e3912f | 246 | } |
sakthipriya | 0:7b4c00e3912f | 247 | else |
sakthipriya | 0:7b4c00e3912f | 248 | { |
sakthipriya | 0:7b4c00e3912f | 249 | if(ACS_STATE == '3') // check ACS_STATE = ACS_DATA_ACQ_FAILURE |
sakthipriya | 0:7b4c00e3912f | 250 | { |
sakthipriya | 0:7b4c00e3912f | 251 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 252 | printf("\n\r acs data failure "); |
sakthipriya | 0:7b4c00e3912f | 253 | ACS_STATUS = '3'; // set ACS_STATUS = ACS_DATA_ACQ_FAILURE |
sakthipriya | 0:7b4c00e3912f | 254 | PWM1 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 255 | PWM2 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 256 | PWM3 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 257 | } |
sakthipriya | 0:7b4c00e3912f | 258 | else |
sakthipriya | 0:7b4c00e3912f | 259 | { |
sakthipriya | 0:7b4c00e3912f | 260 | if(ACS_STATE == '4') // check ACS_STATE = ACS_NOMINAL_ONLY |
sakthipriya | 0:7b4c00e3912f | 261 | { |
sakthipriya | 0:7b4c00e3912f | 262 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 263 | printf("\n\r nominal"); |
sakthipriya | 0:7b4c00e3912f | 264 | ACS_STATUS = '4'; // set ACS_STATUS = ACS_NOMINAL_ONLY |
sakthipriya | 0:7b4c00e3912f | 265 | FCTN_ACS_CNTRLALGO(b1,omega1); |
sakthipriya | 0:7b4c00e3912f | 266 | printf("\n\r moment values returned by control algo \n"); |
sakthipriya | 0:7b4c00e3912f | 267 | for(int i=0; i<3; i++) |
sakthipriya | 0:7b4c00e3912f | 268 | { |
sakthipriya | 0:7b4c00e3912f | 269 | printf("%f\t",moment[i]); |
sakthipriya | 0:7b4c00e3912f | 270 | } |
sakthipriya | 0:7b4c00e3912f | 271 | FCTN_ACS_GENPWM_MAIN(moment) ; |
sakthipriya | 0:7b4c00e3912f | 272 | } |
sakthipriya | 0:7b4c00e3912f | 273 | else |
sakthipriya | 0:7b4c00e3912f | 274 | { |
sakthipriya | 0:7b4c00e3912f | 275 | if(ACS_STATE == '5') // check ACS_STATE = ACS_AUTO_CONTROL |
sakthipriya | 0:7b4c00e3912f | 276 | { |
sakthipriya | 0:7b4c00e3912f | 277 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 278 | printf("\n\r auto control"); |
sakthipriya | 0:7b4c00e3912f | 279 | ACS_STATUS = '5'; // set ACS_STATUS = ACS_AUTO_CONTROL |
sakthipriya | 0:7b4c00e3912f | 280 | //FCTN_ACS_AUTOCTRL_LOGIC // gotta include this code |
sakthipriya | 0:7b4c00e3912f | 281 | } |
sakthipriya | 0:7b4c00e3912f | 282 | else |
sakthipriya | 0:7b4c00e3912f | 283 | { |
sakthipriya | 0:7b4c00e3912f | 284 | if(ACS_STATE == '6') // check ACS_STATE = ACS_DETUMBLING_ONLY |
sakthipriya | 0:7b4c00e3912f | 285 | { |
sakthipriya | 0:7b4c00e3912f | 286 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 287 | printf("\n\r Entered detumbling \n"); |
sakthipriya | 0:7b4c00e3912f | 288 | ACS_STATUS = '6'; // set ACS_STATUS = ACS_DETUMBLING_ONLY |
sakthipriya | 0:7b4c00e3912f | 289 | FCTN_ACS_CNTRLALGO(b1,omega1); // detumbling code has to be included |
sakthipriya | 0:7b4c00e3912f | 290 | FCTN_ACS_GENPWM_MAIN(moment) ; |
sakthipriya | 0:7b4c00e3912f | 291 | } |
sakthipriya | 0:7b4c00e3912f | 292 | else |
sakthipriya | 0:7b4c00e3912f | 293 | { |
sakthipriya | 0:7b4c00e3912f | 294 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 295 | printf("\n\r invalid state"); |
sakthipriya | 0:7b4c00e3912f | 296 | ACS_STATUS = '7' ; // set ACS_STATUS = INVALID STATE |
sakthipriya | 0:7b4c00e3912f | 297 | PWM1 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 298 | PWM2 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 299 | PWM3 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 300 | }//else of invalid |
sakthipriya | 0:7b4c00e3912f | 301 | }//else of autocontrol |
sakthipriya | 0:7b4c00e3912f | 302 | }//else of nominal |
sakthipriya | 0:7b4c00e3912f | 303 | }//else of data acg failure |
sakthipriya | 0:7b4c00e3912f | 304 | |
sakthipriya | 0:7b4c00e3912f | 305 | }//else fo z axis moment only |
sakthipriya | 0:7b4c00e3912f | 306 | }//if power >2 |
sakthipriya | 0:7b4c00e3912f | 307 | else |
sakthipriya | 0:7b4c00e3912f | 308 | { |
sakthipriya | 0:7b4c00e3912f | 309 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 310 | printf("\n\r low power"); |
sakthipriya | 0:7b4c00e3912f | 311 | ACS_STATUS = '1'; // set ACS_STATUS = ACS_LOW_POWER |
sakthipriya | 0:7b4c00e3912f | 312 | PWM1 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 313 | PWM2 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 314 | PWM3 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 315 | } |
sakthipriya | 0:7b4c00e3912f | 316 | } //else for acs control off |
sakthipriya | 0:7b4c00e3912f | 317 | |
sakthipriya | 0:7b4c00e3912f | 318 | |
sakthipriya | 0:7b4c00e3912f | 319 | |
sakthipriya | 0:7b4c00e3912f | 320 | ACS_MAIN_STATUS = 'c'; //clear ACS_MAIN_STATUS flag |
sakthipriya | 3:07e15677a75c | 321 | |
sakthipriya | 0:7b4c00e3912f | 322 | } |
sakthipriya | 0:7b4c00e3912f | 323 | //***************************************************EPS THREAD***********************************************// |
sakthipriya | 0:7b4c00e3912f | 324 | |
sakthipriya | 3:07e15677a75c | 325 | void F_EPS() |
sakthipriya | 0:7b4c00e3912f | 326 | { |
sakthipriya | 3:07e15677a75c | 327 | |
sakthipriya | 0:7b4c00e3912f | 328 | pc.printf("\n\rEntered EPS %f\n",t_start.read()); |
sakthipriya | 0:7b4c00e3912f | 329 | EPS_MAIN_STATUS = 's'; // Set EPS main status |
sakthipriya | 3:07e15677a75c | 330 | FCTN_BATT_TEMP_SENSOR_MAIN(actual_data.Batt_temp_actual); |
sakthipriya | 3:07e15677a75c | 331 | pc.printf("\n\r Battery temperature %f %f" ,actual_data.Batt_temp_actual[0], actual_data.Batt_temp_actual[1]); |
sakthipriya | 3:07e15677a75c | 332 | EPS_BATTERY_TEMP_STATUS = 's'; //set EPS_BATTERY_TEMP_STATUS |
sakthipriya | 3:07e15677a75c | 333 | if(EPS_BATTERY_HEAT_ENABLE == 'e') |
sakthipriya | 3:07e15677a75c | 334 | { |
sakthipriya | 5:bb592f3185cc | 335 | if((actual_data.Batt_temp_actual[0] < batt_heat_low) && (actual_data.Batt_temp_actual[1] < batt_heat_low)) // to confirm |
sakthipriya | 3:07e15677a75c | 336 | { |
sakthipriya | 3:07e15677a75c | 337 | batt_heat = 1; //turn on battery heater |
sakthipriya | 3:07e15677a75c | 338 | } |
sakthipriya | 3:07e15677a75c | 339 | else |
sakthipriya | 3:07e15677a75c | 340 | { |
sakthipriya | 3:07e15677a75c | 341 | batt_heat = 0; //turn off battery heater |
sakthipriya | 3:07e15677a75c | 342 | } |
sakthipriya | 3:07e15677a75c | 343 | |
sakthipriya | 3:07e15677a75c | 344 | } |
sakthipriya | 3:07e15677a75c | 345 | else if(EPS_BATTERY_HEAT_ENABLE == 'd') |
sakthipriya | 3:07e15677a75c | 346 | { |
sakthipriya | 3:07e15677a75c | 347 | EPS_STATUS = 1;//EPS_STATUS = EPS_BATTERY_HEATER_DISABLED |
sakthipriya | 3:07e15677a75c | 348 | } |
sakthipriya | 0:7b4c00e3912f | 349 | FCTN_BATTERYGAUGE_MAIN(actual_data.Batt_gauge_actual); |
sakthipriya | 1:446a959e36ce | 350 | if (actual_data.Batt_gauge_actual[1] == 200) //data not received |
sakthipriya | 0:7b4c00e3912f | 351 | { |
sakthipriya | 0:7b4c00e3912f | 352 | actual_data.power_mode = 1; |
sakthipriya | 0:7b4c00e3912f | 353 | EPS_BATTERY_GAUGE_STATUS = 'c'; //clear EPS_BATTERY_GAUGE_STATUS |
sakthipriya | 0:7b4c00e3912f | 354 | |
sakthipriya | 0:7b4c00e3912f | 355 | } |
sakthipriya | 0:7b4c00e3912f | 356 | else |
sakthipriya | 0:7b4c00e3912f | 357 | { |
sakthipriya | 1:446a959e36ce | 358 | FCTN_EPS_POWERMODE(actual_data.Batt_gauge_actual[1]); //updating power level |
sakthipriya | 0:7b4c00e3912f | 359 | EPS_BATTERY_GAUGE_STATUS = 's'; //set EPS_BATTERY_GAUGE_STATUS |
sakthipriya | 0:7b4c00e3912f | 360 | } |
sakthipriya | 3:07e15677a75c | 361 | // if( Temperature data received) |
sakthipriya | 3:07e15677a75c | 362 | //{ |
sakthipriya | 3:07e15677a75c | 363 | |
sakthipriya | 0:7b4c00e3912f | 364 | |
sakthipriya | 3:07e15677a75c | 365 | // } |
sakthipriya | 3:07e15677a75c | 366 | // else |
sakthipriya | 3:07e15677a75c | 367 | // { |
sakthipriya | 3:07e15677a75c | 368 | // Set battery temp to XX |
sakthipriya | 3:07e15677a75c | 369 | // EPS_BATTERY_TEMP_STATUS = 'c'; //clear EPS_BATTERY_TEMP_STATUS |
sakthipriya | 3:07e15677a75c | 370 | // EPS_STATUS = EPS_ERR_BATTERY_TEMP; |
sakthipriya | 3:07e15677a75c | 371 | // } |
sakthipriya | 3:07e15677a75c | 372 | FCTN_HK_MAIN(); |
sakthipriya | 5:bb592f3185cc | 373 | FCTN_APPEND_HKDATA(); |
sakthipriya | 5:bb592f3185cc | 374 | minMaxHkData(); |
sakthipriya | 0:7b4c00e3912f | 375 | |
sakthipriya | 3:07e15677a75c | 376 | EPS_MAIN_STATUS = 'c'; // clear EPS main status |
sakthipriya | 3:07e15677a75c | 377 | |
sakthipriya | 0:7b4c00e3912f | 378 | } |
sakthipriya | 0:7b4c00e3912f | 379 | |
sakthipriya | 0:7b4c00e3912f | 380 | //**************************************************BCN THREAD*******************************************************************// |
sakthipriya | 0:7b4c00e3912f | 381 | |
sakthipriya | 3:07e15677a75c | 382 | void F_BCN() |
sakthipriya | 0:7b4c00e3912f | 383 | { |
sakthipriya | 3:07e15677a75c | 384 | |
sakthipriya | 0:7b4c00e3912f | 385 | pc.printf("\n\rEntered BCN %f\n",t_start.read()); |
sakthipriya | 0:7b4c00e3912f | 386 | |
sakthipriya | 0:7b4c00e3912f | 387 | P_BCN_TX_MAIN(); |
sakthipriya | 0:7b4c00e3912f | 388 | |
sakthipriya | 0:7b4c00e3912f | 389 | } |
sakthipriya | 0:7b4c00e3912f | 390 | |
sakthipriya | 0:7b4c00e3912f | 391 | //**************************************************TCTM THREAD*******************************************************************// |
sakthipriya | 0:7b4c00e3912f | 392 | |
sakthipriya | 0:7b4c00e3912f | 393 | void T_TC(void const * args) |
sakthipriya | 0:7b4c00e3912f | 394 | { |
sakthipriya | 0:7b4c00e3912f | 395 | while(1) |
sakthipriya | 0:7b4c00e3912f | 396 | { |
sakthipriya | 0:7b4c00e3912f | 397 | Thread::signal_wait(0x4); |
sakthipriya | 0:7b4c00e3912f | 398 | wait_us(200); // can be between 38 to 15700 |
sakthipriya | 0:7b4c00e3912f | 399 | if( slave.receive() == 0) |
sakthipriya | 0:7b4c00e3912f | 400 | slave.stop(); |
sakthipriya | 0:7b4c00e3912f | 401 | else if( slave.receive() == 1) // slave writes to master |
sakthipriya | 0:7b4c00e3912f | 402 | { |
sakthipriya | 5:bb592f3185cc | 403 | if(data_send_flag == 'h') |
sakthipriya | 5:bb592f3185cc | 404 | write_ack=slave.write((char*)BAE_data,73); |
sakthipriya | 5:bb592f3185cc | 405 | else if(data_send_flag == 't') |
sakthipriya | 5:bb592f3185cc | 406 | { |
sakthipriya | 5:bb592f3185cc | 407 | write_ack=slave.write(telemetry,tm_len); |
sakthipriya | 5:bb592f3185cc | 408 | data_send_flag = 'h'; |
sakthipriya | 5:bb592f3185cc | 409 | irpt_2_mstr = 0; |
sakthipriya | 5:bb592f3185cc | 410 | } |
sakthipriya | 0:7b4c00e3912f | 411 | } |
sakthipriya | 0:7b4c00e3912f | 412 | else if( slave.receive()==3 || slave.receive()==2) // slave read |
sakthipriya | 0:7b4c00e3912f | 413 | { |
sakthipriya | 5:bb592f3185cc | 414 | read_ack=slave.read(telecommand,tc_len); |
sakthipriya | 5:bb592f3185cc | 415 | pc.printf("\n\rTELECOMMAND received from CDMS is %s \n",telecommand); |
sakthipriya | 5:bb592f3185cc | 416 | pc.printf("\n\r Executing Telecommand \n"); |
sakthipriya | 3:07e15677a75c | 417 | // FCTN_TC_DECODE((uint8_t*) telecommand); |
sakthipriya | 3:07e15677a75c | 418 | uint8_t* temp = FCTN_BAE_TM_TC((uint8_t*) telecommand); |
sakthipriya | 3:07e15677a75c | 419 | telemetry = (char*)temp; |
sakthipriya | 5:bb592f3185cc | 420 | FCTN_TM(); |
sakthipriya | 3:07e15677a75c | 421 | // for(int i = 0; i<134; i++) |
sakthipriya | 3:07e15677a75c | 422 | //pc.printf("%c", telemetry[i]); |
sakthipriya | 0:7b4c00e3912f | 423 | } |
sakthipriya | 0:7b4c00e3912f | 424 | |
sakthipriya | 0:7b4c00e3912f | 425 | } |
sakthipriya | 0:7b4c00e3912f | 426 | } |
sakthipriya | 0:7b4c00e3912f | 427 | |
sakthipriya | 0:7b4c00e3912f | 428 | void FCTN_TM() |
sakthipriya | 0:7b4c00e3912f | 429 | { |
sakthipriya | 4:39a4ae8c7ecd | 430 | //irpt_2_mstr = 0; |
sakthipriya | 5:bb592f3185cc | 431 | data_send_flag = 't'; |
sakthipriya | 0:7b4c00e3912f | 432 | pc.printf("\n\r Telemetry Generation \n"); |
sakthipriya | 0:7b4c00e3912f | 433 | irpt_2_mstr = 1; |
sakthipriya | 0:7b4c00e3912f | 434 | } |
sakthipriya | 0:7b4c00e3912f | 435 | |
sakthipriya | 0:7b4c00e3912f | 436 | |
sakthipriya | 0:7b4c00e3912f | 437 | //******************************************************* I2C *******************************************************************// |
sakthipriya | 0:7b4c00e3912f | 438 | |
sakthipriya | 0:7b4c00e3912f | 439 | void FCTN_I2C_ISR() |
sakthipriya | 0:7b4c00e3912f | 440 | { |
sakthipriya | 0:7b4c00e3912f | 441 | ptr_t_i2c->signal_set(0x4); |
sakthipriya | 0:7b4c00e3912f | 442 | } |
sakthipriya | 0:7b4c00e3912f | 443 | |
sakthipriya | 0:7b4c00e3912f | 444 | |
sakthipriya | 5:bb592f3185cc | 445 | //***********************************************************FAULTS***************************************************************// |
sakthipriya | 5:bb592f3185cc | 446 | /*void ir1clear() |
sakthipriya | 5:bb592f3185cc | 447 | { |
sakthipriya | 5:bb592f3185cc | 448 | actual_data.faultIr_status |= 0x01; // alert |
sakthipriya | 5:bb592f3185cc | 449 | |
sakthipriya | 5:bb592f3185cc | 450 | }*/ |
sakthipriya | 5:bb592f3185cc | 451 | |
sakthipriya | 5:bb592f3185cc | 452 | |
sakthipriya | 5:bb592f3185cc | 453 | |
sakthipriya | 5:bb592f3185cc | 454 | void ir2clear() |
sakthipriya | 5:bb592f3185cc | 455 | { |
sakthipriya | 5:bb592f3185cc | 456 | actual_data.faultIr_status |= 0x02; |
sakthipriya | 5:bb592f3185cc | 457 | TRXY_SW = 0; // Switch off TR XY |
sakthipriya | 5:bb592f3185cc | 458 | if1check = 1; |
sakthipriya | 5:bb592f3185cc | 459 | } |
sakthipriya | 5:bb592f3185cc | 460 | |
sakthipriya | 5:bb592f3185cc | 461 | void ir3clear() |
sakthipriya | 5:bb592f3185cc | 462 | { |
sakthipriya | 5:bb592f3185cc | 463 | actual_data.faultIr_status |= 0x04; |
sakthipriya | 5:bb592f3185cc | 464 | DRV_Z_SLP = 0; |
sakthipriya | 5:bb592f3185cc | 465 | wait_us(1); |
sakthipriya | 5:bb592f3185cc | 466 | DRV_Z_SLP = 1; |
sakthipriya | 5:bb592f3185cc | 467 | |
sakthipriya | 5:bb592f3185cc | 468 | } |
sakthipriya | 5:bb592f3185cc | 469 | |
sakthipriya | 5:bb592f3185cc | 470 | void ir4clear() |
sakthipriya | 5:bb592f3185cc | 471 | { |
sakthipriya | 5:bb592f3185cc | 472 | if2check = 1; |
sakthipriya | 5:bb592f3185cc | 473 | actual_data.faultIr_status |= 0x08; |
sakthipriya | 5:bb592f3185cc | 474 | TRZ_SW = 0; |
sakthipriya | 5:bb592f3185cc | 475 | } |
sakthipriya | 5:bb592f3185cc | 476 | |
sakthipriya | 5:bb592f3185cc | 477 | void ir5clear() |
sakthipriya | 5:bb592f3185cc | 478 | { |
sakthipriya | 5:bb592f3185cc | 479 | actual_data.faultIr_status |= 0x10; |
sakthipriya | 5:bb592f3185cc | 480 | CDMS_RESET = 0; |
sakthipriya | 5:bb592f3185cc | 481 | wait_us(1); |
sakthipriya | 5:bb592f3185cc | 482 | CDMS_RESET = 1; |
sakthipriya | 5:bb592f3185cc | 483 | } |
sakthipriya | 5:bb592f3185cc | 484 | |
sakthipriya | 5:bb592f3185cc | 485 | void ir6clear() |
sakthipriya | 5:bb592f3185cc | 486 | { |
sakthipriya | 5:bb592f3185cc | 487 | actual_data.faultIr_status |= 0x20; |
sakthipriya | 5:bb592f3185cc | 488 | BCN_SW = 0; |
sakthipriya | 5:bb592f3185cc | 489 | wait_us(1); |
sakthipriya | 5:bb592f3185cc | 490 | BCN_SW = 1; |
sakthipriya | 5:bb592f3185cc | 491 | } |
sakthipriya | 5:bb592f3185cc | 492 | |
sakthipriya | 5:bb592f3185cc | 493 | void ir7clear() |
sakthipriya | 5:bb592f3185cc | 494 | { |
sakthipriya | 5:bb592f3185cc | 495 | actual_data.faultIr_status |= 0x40; |
sakthipriya | 5:bb592f3185cc | 496 | } |
sakthipriya | 5:bb592f3185cc | 497 | uint8_t iter2=0,iter4 = 0; |
sakthipriya | 5:bb592f3185cc | 498 | |
sakthipriya | 5:bb592f3185cc | 499 | |
sakthipriya | 5:bb592f3185cc | 500 | |
sakthipriya | 5:bb592f3185cc | 501 | void pollfault() |
sakthipriya | 5:bb592f3185cc | 502 | { |
sakthipriya | 5:bb592f3185cc | 503 | |
sakthipriya | 5:bb592f3185cc | 504 | |
sakthipriya | 5:bb592f3185cc | 505 | |
sakthipriya | 5:bb592f3185cc | 506 | if (pf1==0) // OC_ATS1 |
sakthipriya | 5:bb592f3185cc | 507 | { |
sakthipriya | 5:bb592f3185cc | 508 | pf1check=1; |
sakthipriya | 5:bb592f3185cc | 509 | actual_data.faultPoll_status |=0x01 ; |
sakthipriya | 5:bb592f3185cc | 510 | gpo1 = 1; // turn off ats1 // to be turned on next cycle in ACS |
sakthipriya | 5:bb592f3185cc | 511 | } |
sakthipriya | 5:bb592f3185cc | 512 | else actual_data.faultPoll_status &= 0xFE; |
sakthipriya | 5:bb592f3185cc | 513 | |
sakthipriya | 5:bb592f3185cc | 514 | if (pf2==0) |
sakthipriya | 5:bb592f3185cc | 515 | { |
sakthipriya | 5:bb592f3185cc | 516 | pf2check=1; |
sakthipriya | 5:bb592f3185cc | 517 | actual_data.faultPoll_status |=0x02 ; |
sakthipriya | 5:bb592f3185cc | 518 | gpo2 = 1; // turn off ats2 // turn on in ACS |
sakthipriya | 5:bb592f3185cc | 519 | } |
sakthipriya | 5:bb592f3185cc | 520 | else actual_data.faultPoll_status &= 0xFD; |
sakthipriya | 5:bb592f3185cc | 521 | |
sakthipriya | 5:bb592f3185cc | 522 | if (pf3==0) |
sakthipriya | 5:bb592f3185cc | 523 | { actual_data.faultPoll_status |=0x04 ; |
sakthipriya | 5:bb592f3185cc | 524 | DRV_XY_SLP = 0; |
sakthipriya | 5:bb592f3185cc | 525 | wait_us(1); |
sakthipriya | 5:bb592f3185cc | 526 | DRV_XY_SLP = 1; |
sakthipriya | 5:bb592f3185cc | 527 | } |
sakthipriya | 5:bb592f3185cc | 528 | else actual_data.faultPoll_status &= 0xFB; |
sakthipriya | 5:bb592f3185cc | 529 | |
sakthipriya | 5:bb592f3185cc | 530 | |
sakthipriya | 5:bb592f3185cc | 531 | |
sakthipriya | 5:bb592f3185cc | 532 | |
sakthipriya | 5:bb592f3185cc | 533 | /*if (ir1==1) |
sakthipriya | 5:bb592f3185cc | 534 | { |
sakthipriya | 5:bb592f3185cc | 535 | actual_data.faultIr_status &=0xFE; |
sakthipriya | 5:bb592f3185cc | 536 | }*/ |
sakthipriya | 5:bb592f3185cc | 537 | if (ir2==1) |
sakthipriya | 5:bb592f3185cc | 538 | { |
sakthipriya | 5:bb592f3185cc | 539 | actual_data.faultIr_status &=0xFD; |
sakthipriya | 5:bb592f3185cc | 540 | } |
sakthipriya | 5:bb592f3185cc | 541 | if (ir3==1) |
sakthipriya | 5:bb592f3185cc | 542 | { |
sakthipriya | 5:bb592f3185cc | 543 | actual_data.faultIr_status &=0xFB; |
sakthipriya | 5:bb592f3185cc | 544 | } |
sakthipriya | 5:bb592f3185cc | 545 | if (ir4==1) |
sakthipriya | 5:bb592f3185cc | 546 | { |
sakthipriya | 5:bb592f3185cc | 547 | actual_data.faultIr_status &=0xF7; |
sakthipriya | 5:bb592f3185cc | 548 | } |
sakthipriya | 5:bb592f3185cc | 549 | if (ir5==1) |
sakthipriya | 5:bb592f3185cc | 550 | { |
sakthipriya | 5:bb592f3185cc | 551 | actual_data.faultIr_status &=0xEF; |
sakthipriya | 5:bb592f3185cc | 552 | } |
sakthipriya | 5:bb592f3185cc | 553 | if (ir6==1) |
sakthipriya | 5:bb592f3185cc | 554 | { |
sakthipriya | 5:bb592f3185cc | 555 | actual_data.faultIr_status &=0xDF; |
sakthipriya | 5:bb592f3185cc | 556 | }if (ir7==1) |
sakthipriya | 5:bb592f3185cc | 557 | { |
sakthipriya | 5:bb592f3185cc | 558 | actual_data.faultIr_status &=0xBF; |
sakthipriya | 5:bb592f3185cc | 559 | } |
sakthipriya | 5:bb592f3185cc | 560 | |
sakthipriya | 5:bb592f3185cc | 561 | } |
sakthipriya | 5:bb592f3185cc | 562 | |
sakthipriya | 5:bb592f3185cc | 563 | |
sakthipriya | 0:7b4c00e3912f | 564 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
sakthipriya | 0:7b4c00e3912f | 565 | //SCHEDULER |
sakthipriya | 0:7b4c00e3912f | 566 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
sakthipriya | 0:7b4c00e3912f | 567 | uint8_t schedcount=1; |
sakthipriya | 0:7b4c00e3912f | 568 | void T_SC(void const *args) |
sakthipriya | 0:7b4c00e3912f | 569 | { |
sakthipriya | 0:7b4c00e3912f | 570 | printf("\n\r in scheduler"); |
sakthipriya | 0:7b4c00e3912f | 571 | |
sakthipriya | 0:7b4c00e3912f | 572 | if(schedcount == 7) //to reset the counter |
sakthipriya | 0:7b4c00e3912f | 573 | { |
sakthipriya | 0:7b4c00e3912f | 574 | schedcount = 1; |
sakthipriya | 0:7b4c00e3912f | 575 | } |
sakthipriya | 0:7b4c00e3912f | 576 | if(schedcount%1==0) |
sakthipriya | 0:7b4c00e3912f | 577 | { |
sakthipriya | 3:07e15677a75c | 578 | F_ACS(); |
sakthipriya | 0:7b4c00e3912f | 579 | } |
sakthipriya | 0:7b4c00e3912f | 580 | |
sakthipriya | 0:7b4c00e3912f | 581 | if(schedcount%2==0) |
sakthipriya | 0:7b4c00e3912f | 582 | { |
sakthipriya | 3:07e15677a75c | 583 | F_EPS(); |
sakthipriya | 0:7b4c00e3912f | 584 | } |
sakthipriya | 0:7b4c00e3912f | 585 | if(schedcount%3==0) |
sakthipriya | 0:7b4c00e3912f | 586 | { |
sakthipriya | 3:07e15677a75c | 587 | // F_BCN(); |
sakthipriya | 0:7b4c00e3912f | 588 | } |
sakthipriya | 0:7b4c00e3912f | 589 | schedcount++; |
sakthipriya | 0:7b4c00e3912f | 590 | printf("\n\r exited scheduler"); |
sakthipriya | 0:7b4c00e3912f | 591 | } |
sakthipriya | 0:7b4c00e3912f | 592 | |
sakthipriya | 0:7b4c00e3912f | 593 | Timer t_flag; |
sakthipriya | 0:7b4c00e3912f | 594 | void FLAG() |
sakthipriya | 0:7b4c00e3912f | 595 | { |
sakthipriya | 0:7b4c00e3912f | 596 | |
sakthipriya | 0:7b4c00e3912f | 597 | //.............acs..................// |
sakthipriya | 0:7b4c00e3912f | 598 | if(ACS_INIT_STATUS == 's') |
sakthipriya | 0:7b4c00e3912f | 599 | BAE_STATUS = BAE_STATUS | 0x00000080; //set ACS_INIT_STATUS flag |
sakthipriya | 0:7b4c00e3912f | 600 | else if(ACS_INIT_STATUS == 'c') |
sakthipriya | 0:7b4c00e3912f | 601 | BAE_STATUS &= 0xFFFFFF7F; //clear ACS_INIT_STATUS flag |
sakthipriya | 0:7b4c00e3912f | 602 | |
sakthipriya | 0:7b4c00e3912f | 603 | if(ACS_DATA_ACQ_STATUS == 's') |
sakthipriya | 0:7b4c00e3912f | 604 | BAE_STATUS =BAE_STATUS | 0x00000100; //set ACS_DATA_ACQ_STATUS flag |
sakthipriya | 0:7b4c00e3912f | 605 | else if(ACS_DATA_ACQ_STATUS == 'c') |
sakthipriya | 0:7b4c00e3912f | 606 | BAE_STATUS &= 0xFFFFFEFF; //clear ACS_DATA_ACQ_STATUS flag |
sakthipriya | 0:7b4c00e3912f | 607 | |
sakthipriya | 0:7b4c00e3912f | 608 | if(ACS_ATS_ENABLE == 'e') |
sakthipriya | 0:7b4c00e3912f | 609 | BAE_ENABLE |= 0x00000004; |
sakthipriya | 0:7b4c00e3912f | 610 | else if(ACS_ATS_ENABLE == 'd') |
sakthipriya | 0:7b4c00e3912f | 611 | BAE_ENABLE = BAE_ENABLE &0xFFFFFFFB | 0x00000004; |
sakthipriya | 0:7b4c00e3912f | 612 | |
sakthipriya | 0:7b4c00e3912f | 613 | if(ACS_DATA_ACQ_STATUS == 'f') |
sakthipriya | 0:7b4c00e3912f | 614 | BAE_STATUS |= 0x00000200; |
sakthipriya | 0:7b4c00e3912f | 615 | |
sakthipriya | 0:7b4c00e3912f | 616 | if(ACS_MAIN_STATUS == 's') |
sakthipriya | 0:7b4c00e3912f | 617 | BAE_STATUS = (BAE_STATUS | 0x00001000); //set ACS_MAIN_STATUS flag |
sakthipriya | 0:7b4c00e3912f | 618 | else if(ACS_MAIN_STATUS == 'c') |
sakthipriya | 0:7b4c00e3912f | 619 | BAE_STATUS &= 0xFFFFEFFF; //clear ACS_MAIN_STATUS flag |
sakthipriya | 0:7b4c00e3912f | 620 | |
sakthipriya | 0:7b4c00e3912f | 621 | if(ACS_STATUS == '0') |
sakthipriya | 0:7b4c00e3912f | 622 | BAE_STATUS = (BAE_STATUS & 0xFFFF1FFF); // set ACS_STATUS = ACS_CONTROL_OFF |
sakthipriya | 0:7b4c00e3912f | 623 | else if(ACS_STATUS == '1') |
sakthipriya | 0:7b4c00e3912f | 624 | BAE_STATUS =(BAE_STATUS & 0xFFFF1FFF) | 0x00002000; // set ACS_STATUS = ACS_LOW_POWER |
sakthipriya | 0:7b4c00e3912f | 625 | else if(ACS_STATUS == '2') |
sakthipriya | 0:7b4c00e3912f | 626 | BAE_STATUS = (BAE_STATUS & 0xFFFF1FFF)| 0x00004000; // set ACS_STATUS = ACS_ZAXIS_MOMENT_ONLY |
sakthipriya | 0:7b4c00e3912f | 627 | else if(ACS_STATUS == '3') |
sakthipriya | 0:7b4c00e3912f | 628 | BAE_STATUS = (BAE_STATUS & 0xFFFF1FFF) | 0x00006000; // set ACS_STATUS = ACS_DATA_ACQ_FAILURE |
sakthipriya | 0:7b4c00e3912f | 629 | else if(ACS_STATUS == '4') |
sakthipriya | 0:7b4c00e3912f | 630 | BAE_STATUS = (BAE_STATUS & 0xFFFF1FFF) | 0x00008000; // set ACS_STATUS = ACS_NOMINAL_ONLY |
sakthipriya | 0:7b4c00e3912f | 631 | else if(ACS_STATUS == '5') |
sakthipriya | 0:7b4c00e3912f | 632 | BAE_STATUS =(BAE_STATUS & 0xFFFF1FFF) | 0x0000A000; // set ACS_STATUS = ACS_AUTO_CONTROL |
sakthipriya | 0:7b4c00e3912f | 633 | else if(ACS_STATUS == '6') |
sakthipriya | 0:7b4c00e3912f | 634 | BAE_STATUS =(BAE_STATUS & 0xFFFF1FFF) | 0x0000C000; // set ACS_STATUS = ACS_DETUMBLING_ONLY |
sakthipriya | 0:7b4c00e3912f | 635 | else |
sakthipriya | 0:7b4c00e3912f | 636 | BAE_STATUS =(BAE_STATUS & 0xFFFF1FFF) | 0x0000E000; // set ACS_STATUS = INVALID STATE |
sakthipriya | 0:7b4c00e3912f | 637 | |
sakthipriya | 0:7b4c00e3912f | 638 | if(ACS_STATE == '0') |
sakthipriya | 0:7b4c00e3912f | 639 | BAE_ENABLE = (BAE_ENABLE & 0xFFFFFF8F); //ACS_STATE = ACS_CONTROL_OFF |
sakthipriya | 0:7b4c00e3912f | 640 | else if(ACS_STATE == '2') |
sakthipriya | 0:7b4c00e3912f | 641 | BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000020); // ACS_STATE = ACS_ZAXIS_MOMENT_ONLY |
sakthipriya | 0:7b4c00e3912f | 642 | else if(ACS_STATE == '3') |
sakthipriya | 0:7b4c00e3912f | 643 | BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000030); // set ACS_STATUS = ACS_DATA_ACQ_FAILURE |
sakthipriya | 0:7b4c00e3912f | 644 | else if(ACS_STATE == '4') |
sakthipriya | 0:7b4c00e3912f | 645 | BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000040); // ACS_STATE = ACS_NOMINAL_ONLY |
sakthipriya | 0:7b4c00e3912f | 646 | else if(ACS_STATE == '5') |
sakthipriya | 0:7b4c00e3912f | 647 | BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000050); // ACS_STATE = ACS_AUTO_CONTROL |
sakthipriya | 0:7b4c00e3912f | 648 | else if(ACS_STATE == '6') |
sakthipriya | 0:7b4c00e3912f | 649 | BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000060); //ACS_STATE = ACS_DETUMBLING_CONTROL |
sakthipriya | 0:7b4c00e3912f | 650 | |
sakthipriya | 0:7b4c00e3912f | 651 | //...............eps......................// |
sakthipriya | 5:bb592f3185cc | 652 | |
sakthipriya | 5:bb592f3185cc | 653 | |
sakthipriya | 5:bb592f3185cc | 654 | if (EPS_INIT_STATUS=='s') // Set EPS_INIT_STATUS |
sakthipriya | 5:bb592f3185cc | 655 | BAE_STATUS |= 0x00010000; |
sakthipriya | 5:bb592f3185cc | 656 | else if(EPS_INIT_STATUS=='c') // Clear |
sakthipriya | 5:bb592f3185cc | 657 | BAE_STATUS &= 0xFFFEFFFF; |
sakthipriya | 5:bb592f3185cc | 658 | |
sakthipriya | 5:bb592f3185cc | 659 | |
sakthipriya | 5:bb592f3185cc | 660 | if (EPS_MAIN_STATUS=='s') // Set EPS_MAIIN_STATUS |
sakthipriya | 5:bb592f3185cc | 661 | BAE_STATUS |= 0x00040000; |
sakthipriya | 5:bb592f3185cc | 662 | else if(EPS_MAIN_STATUS=='c') // Clear |
sakthipriya | 5:bb592f3185cc | 663 | BAE_STATUS &= 0xFFFBFFFF; |
sakthipriya | 5:bb592f3185cc | 664 | |
sakthipriya | 5:bb592f3185cc | 665 | |
sakthipriya | 5:bb592f3185cc | 666 | if (EPS_BATTERY_GAUGE_STATUS=='s') // Set EPS_BATTERY_GAUGE_STATUS |
sakthipriya | 5:bb592f3185cc | 667 | BAE_STATUS |= 0x00020000; |
sakthipriya | 5:bb592f3185cc | 668 | else if(EPS_BATTERY_GAUGE_STATUS=='c') // Clear |
sakthipriya | 5:bb592f3185cc | 669 | BAE_STATUS &= 0xFFFDFFFF; |
sakthipriya | 5:bb592f3185cc | 670 | |
sakthipriya | 5:bb592f3185cc | 671 | |
sakthipriya | 5:bb592f3185cc | 672 | if (EPS_BATTERY_TEMP_STATUS=='s') // Set EPS_BATTERY_TEMP_STATUS |
sakthipriya | 5:bb592f3185cc | 673 | BAE_STATUS |= 0x00080000; |
sakthipriya | 5:bb592f3185cc | 674 | else if(EPS_BATTERY_TEMP_STATUS=='c') // Clear |
sakthipriya | 5:bb592f3185cc | 675 | BAE_STATUS &= 0xFFF7FFFF; |
sakthipriya | 5:bb592f3185cc | 676 | |
sakthipriya | 5:bb592f3185cc | 677 | if (EPS_STATUS==0) |
sakthipriya | 5:bb592f3185cc | 678 | BAE_STATUS = (BAE_STATUS & 0xFF8FFFFF); // Set EPS_ERR_BATTERY_TEMP |
sakthipriya | 5:bb592f3185cc | 679 | else if (EPS_STATUS==1) |
sakthipriya | 5:bb592f3185cc | 680 | BAE_STATUS = (BAE_STATUS & 0xFF8FFFFF)|0x00010000; // Set EPS_BATTERY_HEATER_DISABLED |
sakthipriya | 5:bb592f3185cc | 681 | else if (EPS_STATUS==2) |
sakthipriya | 5:bb592f3185cc | 682 | BAE_STATUS = (BAE_STATUS & 0xFF8FFFFF)|0x00020000; // Set EPS_ERR_HEATER_SWITCH_OFF |
sakthipriya | 5:bb592f3185cc | 683 | else if (EPS_STATUS==3) |
sakthipriya | 5:bb592f3185cc | 684 | BAE_STATUS = (BAE_STATUS & 0xFF8FFFFF)|0x00030000; // Set EPS_ERR_HEATER_SWITCH_ON |
sakthipriya | 5:bb592f3185cc | 685 | else if (EPS_STATUS==4) |
sakthipriya | 5:bb592f3185cc | 686 | BAE_STATUS = (BAE_STATUS & 0xFF8FFFFF)|0x00040000; // Set EPS_BATTERY_HEATER_OFF |
sakthipriya | 5:bb592f3185cc | 687 | else if (EPS_STATUS==5) |
sakthipriya | 5:bb592f3185cc | 688 | BAE_STATUS = (BAE_STATUS & 0xFF8FFFFF)|0x00050000; // Set EPS_BATTERY_HEATER_ON |
sakthipriya | 5:bb592f3185cc | 689 | |
sakthipriya | 5:bb592f3185cc | 690 | |
sakthipriya | 5:bb592f3185cc | 691 | if(EPS_BATTERY_HEAT_ENABLE == 'e') |
sakthipriya | 5:bb592f3185cc | 692 | BAE_ENABLE |= 0x00000080; |
sakthipriya | 5:bb592f3185cc | 693 | else if(EPS_BATTERY_HEAT_ENABLE == 'd') |
sakthipriya | 5:bb592f3185cc | 694 | BAE_ENABLE = BAE_ENABLE &0xFFFFFF7; |
sakthipriya | 3:07e15677a75c | 695 | |
sakthipriya | 0:7b4c00e3912f | 696 | |
sakthipriya | 0:7b4c00e3912f | 697 | |
sakthipriya | 0:7b4c00e3912f | 698 | pc.printf("\n\r BAE status %x BAE ENABLE %x ",BAE_STATUS,BAE_ENABLE); |
sakthipriya | 0:7b4c00e3912f | 699 | } |
sakthipriya | 0:7b4c00e3912f | 700 | |
sakthipriya | 0:7b4c00e3912f | 701 | void FCTN_BAE_INIT() |
sakthipriya | 0:7b4c00e3912f | 702 | { |
sakthipriya | 0:7b4c00e3912f | 703 | printf("\n\r Initialising BAE "); |
sakthipriya | 3:07e15677a75c | 704 | //..........intial status....// |
sakthipriya | 3:07e15677a75c | 705 | ACS_STATE = '4'; |
sakthipriya | 3:07e15677a75c | 706 | ACS_ATS_ENABLE = 'e'; |
sakthipriya | 3:07e15677a75c | 707 | ACS_DATA_ACQ_ENABLE = 'e'; |
sakthipriya | 3:07e15677a75c | 708 | EPS_BATTERY_HEAT_ENABLE = 'e'; |
sakthipriya | 3:07e15677a75c | 709 | //............................// |
sakthipriya | 3:07e15677a75c | 710 | FCTN_ACS_INIT(); |
sakthipriya | 0:7b4c00e3912f | 711 | FCTN_EPS_INIT(); |
sakthipriya | 0:7b4c00e3912f | 712 | //P_BCN_INIT(); |
sakthipriya | 3:07e15677a75c | 713 | |
sakthipriya | 3:07e15677a75c | 714 | |
sakthipriya | 0:7b4c00e3912f | 715 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 716 | } |
sakthipriya | 0:7b4c00e3912f | 717 | |
sakthipriya | 0:7b4c00e3912f | 718 | int main() |
sakthipriya | 0:7b4c00e3912f | 719 | { |
sakthipriya | 0:7b4c00e3912f | 720 | pc.printf("\n\r BAE Activated. Testing Version 1.1 \n"); |
sakthipriya | 0:7b4c00e3912f | 721 | |
sakthipriya | 0:7b4c00e3912f | 722 | /* if (BCN_FEN == 0) //dummy implementation |
sakthipriya | 0:7b4c00e3912f | 723 | { |
sakthipriya | 0:7b4c00e3912f | 724 | pc.printf("\n\r RF silence "); |
sakthipriya | 0:7b4c00e3912f | 725 | P_BCN_FEN(); |
sakthipriya | 0:7b4c00e3912f | 726 | t_rfsilence.start();//Start the timer for RF_Silence |
sakthipriya | 0:7b4c00e3912f | 727 | while(t_rfsilence.read() < RF_SILENCE_TIME); |
sakthipriya | 0:7b4c00e3912f | 728 | } |
sakthipriya | 0:7b4c00e3912f | 729 | */ |
sakthipriya | 3:07e15677a75c | 730 | |
sakthipriya | 0:7b4c00e3912f | 731 | //ACS_INIT_STATUS = 'c'; |
sakthipriya | 0:7b4c00e3912f | 732 | //ACS_DATA_ACQ_STATUS = 'c'; |
sakthipriya | 0:7b4c00e3912f | 733 | gpo1 = 0; |
sakthipriya | 0:7b4c00e3912f | 734 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 735 | FCTN_BAE_INIT(); |
sakthipriya | 3:07e15677a75c | 736 | |
sakthipriya | 0:7b4c00e3912f | 737 | |
sakthipriya | 0:7b4c00e3912f | 738 | //...i2c.. |
sakthipriya | 3:07e15677a75c | 739 | //strcpy(telemetry,"This is telemetry THis is sample telemetry. ffffffffffffffffffffffffffffff end"); |
sakthipriya | 0:7b4c00e3912f | 740 | slave.address(addr); |
sakthipriya | 0:7b4c00e3912f | 741 | irpt_2_mstr = 0; |
sakthipriya | 0:7b4c00e3912f | 742 | |
sakthipriya | 0:7b4c00e3912f | 743 | ptr_t_i2c = new Thread(T_TC); |
sakthipriya | 0:7b4c00e3912f | 744 | ptr_t_i2c->set_priority(osPriorityHigh); |
sakthipriya | 5:bb592f3185cc | 745 | |
sakthipriya | 0:7b4c00e3912f | 746 | irpt_4m_mstr.enable_irq(); |
sakthipriya | 0:7b4c00e3912f | 747 | irpt_4m_mstr.rise(&FCTN_I2C_ISR); |
sakthipriya | 5:bb592f3185cc | 748 | // ir1.fall(&ir1clear); //Battery Gauge - Alert Bar Signal |
sakthipriya | 5:bb592f3185cc | 749 | ir2.fall(&ir2clear); //TRXY Driver TR switch Fault |
sakthipriya | 5:bb592f3185cc | 750 | ir3.fall(&ir3clear); //TRZ Driver Fault Bar |
sakthipriya | 5:bb592f3185cc | 751 | ir4.fall(&ir4clear); //TRZ Driver TR switch Fault |
sakthipriya | 5:bb592f3185cc | 752 | ir5.fall(&ir5clear); //CDMS - Switch Fault |
sakthipriya | 5:bb592f3185cc | 753 | ir6.fall(&ir6clear); //Beacon- Switch OC bar |
sakthipriya | 5:bb592f3185cc | 754 | ir7.fall(&ir7clear); //Charger IC - Fault Bar |
sakthipriya | 0:7b4c00e3912f | 755 | RtosTimer t_sc_timer(T_SC,osTimerPeriodic); // Initiating the scheduler thread |
sakthipriya | 0:7b4c00e3912f | 756 | t_sc_timer.start(10000); |
sakthipriya | 0:7b4c00e3912f | 757 | t_start.start(); |
sakthipriya | 0:7b4c00e3912f | 758 | pc.printf("\n\rStarted scheduler %f\n\r",t_start.read()); |
sakthipriya | 0:7b4c00e3912f | 759 | |
sakthipriya | 0:7b4c00e3912f | 760 | gpo1 = 0; // att sens2 switch is enabled |
sakthipriya | 0:7b4c00e3912f | 761 | //FCTN_BAE_INIT(); |
sakthipriya | 0:7b4c00e3912f | 762 | while(1); //required to prevent main from terminating |
sakthipriya | 3:07e15677a75c | 763 | } |
sakthipriya | 3:07e15677a75c | 764 |