I2C BAE standalone hardware testing

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of ACS_Flowchart_BAE_1 by Team Fox

Committer:
lakshya
Date:
Tue Apr 19 21:27:07 2016 +0000
Revision:
15:e09aaaccf134
Parent:
14:a9588f443f1a
Child:
16:cc77770d787f
checking

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