I2C BAE standalone hardware testing

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of ACS_Flowchart_BAE_1 by Team Fox

Committer:
sakthipriya
Date:
Fri Jan 22 19:51:50 2016 +0000
Revision:
6:036d08b62785
Parent:
5:bb592f3185cc
Child:
7:a46a1dee4497
i2c prob again

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