FINAL ACS TO BE USED FOR TESTING. COMMISSIONING, ACS MAIN, DATA ACQ ALL DONE.

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of ACS_FULL_Flowchart_BAE by Team Fox

Committer:
sakthipriya
Date:
Sat Mar 12 12:54:14 2016 +0000
Revision:
8:82250e41da81
Parent:
7:a46a1dee4497
Child:
9:194afacf7449
modifying tctm

Who changed what in which revision?

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