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:
Wed Dec 30 04:57:46 2015 +0000
Revision:
4:39a4ae8c7ecd
Parent:
3:07e15677a75c
Child:
5:bb592f3185cc
for Pradeep's use

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 bae_data_len 150
sakthipriya 0:7b4c00e3912f 12 #define batt_heat_low 20
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 0:7b4c00e3912f 17 //.........acs...............//
sakthipriya 0:7b4c00e3912f 18 char ACS_INIT_STATUS = 'q';
sakthipriya 0:7b4c00e3912f 19 char ACS_DATA_ACQ_STATUS = 'q';
sakthipriya 0:7b4c00e3912f 20 char ACS_ATS_STATUS = 'q';
sakthipriya 0:7b4c00e3912f 21 char ACS_MAIN_STATUS = 'q';
sakthipriya 0:7b4c00e3912f 22 char ACS_STATUS = 'q';
sakthipriya 0:7b4c00e3912f 23
sakthipriya 0:7b4c00e3912f 24 char ACS_ATS_ENABLE = 'q';
sakthipriya 0:7b4c00e3912f 25 char ACS_DATA_ACQ_ENABLE = 'q';
sakthipriya 0:7b4c00e3912f 26 char ACS_STATE = 'q';
sakthipriya 0:7b4c00e3912f 27
sakthipriya 0:7b4c00e3912f 28 //.....................eps...................//
sakthipriya 0:7b4c00e3912f 29 //eps init
sakthipriya 0:7b4c00e3912f 30 char EPS_INIT_STATUS = 'q';
sakthipriya 0:7b4c00e3912f 31 char EPS_BATTERY_GAUGE_STATUS = 'q';
sakthipriya 0:7b4c00e3912f 32 //eps main
sakthipriya 0:7b4c00e3912f 33 char EPS_MAIN_STATUS = 'q';
sakthipriya 0:7b4c00e3912f 34 char EPS_BATTERY_TEMP_STATUS = 'q';
sakthipriya 0:7b4c00e3912f 35 char EPS_STATUS = 'q';
sakthipriya 0:7b4c00e3912f 36
sakthipriya 0:7b4c00e3912f 37 char EPS_BATTERY_HEAT_ENABLE = 'q';
sakthipriya 0:7b4c00e3912f 38
sakthipriya 0:7b4c00e3912f 39 //.......................global variables..................................................................// new hk structure- everything has to changed based on this
sakthipriya 0:7b4c00e3912f 40 char BAE_data[bae_data_len];
sakthipriya 0:7b4c00e3912f 41
sakthipriya 0:7b4c00e3912f 42
sakthipriya 0:7b4c00e3912f 43 //*************************************Global declarations************************************************//
sakthipriya 0:7b4c00e3912f 44 const int addr = 0x20; //slave address
sakthipriya 0:7b4c00e3912f 45
sakthipriya 0:7b4c00e3912f 46 Timer t_rfsilence;
sakthipriya 0:7b4c00e3912f 47 Timer t_start;
sakthipriya 0:7b4c00e3912f 48 Serial pc(USBTX, USBRX);
sakthipriya 0:7b4c00e3912f 49 int power_flag_dummy=2;
sakthipriya 0:7b4c00e3912f 50 float data[6];
sakthipriya 0:7b4c00e3912f 51
sakthipriya 0:7b4c00e3912f 52 extern float moment[3];
sakthipriya 0:7b4c00e3912f 53 extern uint8_t BCN_FEN;
sakthipriya 1:446a959e36ce 54 extern BAE_HK_actual actual_data;
sakthipriya 1:446a959e36ce 55 extern BAE_HK_quant quant_data;
sakthipriya 1:446a959e36ce 56 extern BAE_HK_min_max bae_HK_minmax;
sakthipriya 1:446a959e36ce 57 extern BAE_HK_arch arch_data;
sakthipriya 0:7b4c00e3912f 58
sakthipriya 0:7b4c00e3912f 59 bool write_ack = 1;
sakthipriya 0:7b4c00e3912f 60 bool read_ack = 1;
sakthipriya 0:7b4c00e3912f 61 char telecommand[tc_len];
sakthipriya 3:07e15677a75c 62 char* telemetry;
sakthipriya 0:7b4c00e3912f 63 char data_send_flag = 'h';
sakthipriya 0:7b4c00e3912f 64
sakthipriya 0:7b4c00e3912f 65 //*****************************************************Assigning pins******************************************************//
sakthipriya 0:7b4c00e3912f 66 DigitalOut gpo1(PTC0); // enable of att sens2 switch
sakthipriya 0:7b4c00e3912f 67 DigitalOut gpo2(PTC16); // enable of att sens switch
sakthipriya 0:7b4c00e3912f 68 InterruptIn irpt_4m_mstr(PIN38); //I2c interrupt from CDMS
sakthipriya 0:7b4c00e3912f 69 DigitalOut irpt_2_mstr(PIN4); //I2C interrupt to CDMS
sakthipriya 0:7b4c00e3912f 70 I2CSlave slave (PIN1,PIN2);
sakthipriya 0:7b4c00e3912f 71 DigitalOut batt_heat(PIN96);
sakthipriya 0:7b4c00e3912f 72
sakthipriya 0:7b4c00e3912f 73 //gpo1 = 0;
sakthipriya 0:7b4c00e3912f 74 PwmOut PWM1(PIN93); //x //Functions used to generate PWM signal
sakthipriya 0:7b4c00e3912f 75 PwmOut PWM2(PIN94); //y
sakthipriya 0:7b4c00e3912f 76 PwmOut PWM3(PIN95); //z //PWM output comes from pins p6
sakthipriya 0:7b4c00e3912f 77
sakthipriya 0:7b4c00e3912f 78
sakthipriya 0:7b4c00e3912f 79 /*****************************************************************Threads USed***********************************************************************************/
sakthipriya 3:07e15677a75c 80
sakthipriya 0:7b4c00e3912f 81 Thread *ptr_t_i2c;
sakthipriya 0:7b4c00e3912f 82
sakthipriya 0:7b4c00e3912f 83 /*********************************************************FCTN HEADERS***********************************************************************************/
sakthipriya 0:7b4c00e3912f 84
sakthipriya 0:7b4c00e3912f 85 void FCTN_ISR_I2C();
sakthipriya 0:7b4c00e3912f 86 void FCTN_TM();
sakthipriya 3:07e15677a75c 87 void F_ACS();
sakthipriya 3:07e15677a75c 88 void F_EPS();
sakthipriya 3:07e15677a75c 89 void F_BCN();
sakthipriya 0:7b4c00e3912f 90
sakthipriya 0:7b4c00e3912f 91 //*******************************************ACS THREAD**************************************************//
sakthipriya 0:7b4c00e3912f 92
sakthipriya 3:07e15677a75c 93 void F_ACS()
sakthipriya 0:7b4c00e3912f 94 {
sakthipriya 0:7b4c00e3912f 95 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 96 //b1[3] = {22, 22,10};
sakthipriya 0:7b4c00e3912f 97 //omega1[3] = {2.1,3.0,1.5};
sakthipriya 0:7b4c00e3912f 98 // gpo1 = 0; // att sens2 switch is disabled
sakthipriya 0:7b4c00e3912f 99 // gpo2 = 0; // att sens switch is disabled
sakthipriya 0:7b4c00e3912f 100
sakthipriya 3:07e15677a75c 101
sakthipriya 0:7b4c00e3912f 102
sakthipriya 3:07e15677a75c 103 //Thread::signal_wait(0x1);
sakthipriya 0:7b4c00e3912f 104 ACS_MAIN_STATUS = 's'; //set ACS_MAIN_STATUS flag
sakthipriya 0:7b4c00e3912f 105 PWM1 = 0; //clear pwm pins
sakthipriya 0:7b4c00e3912f 106 PWM2 = 0; //clear pwm pins
sakthipriya 0:7b4c00e3912f 107 PWM3 = 0; //clear pwm pins
sakthipriya 0:7b4c00e3912f 108 pc.printf("\n\rEntered ACS %f\n",t_start.read());
sakthipriya 0:7b4c00e3912f 109
sakthipriya 0:7b4c00e3912f 110 if(ACS_DATA_ACQ_ENABLE == 'e')// check if ACS_DATA_ACQ_ENABLE = 1?
sakthipriya 0:7b4c00e3912f 111 {
sakthipriya 0:7b4c00e3912f 112 FLAG();
sakthipriya 0:7b4c00e3912f 113 FCTN_ATS_DATA_ACQ(); //the angular velocity is stored in the first 3 values and magnetic field values in next 3
sakthipriya 0:7b4c00e3912f 114 pc.printf("gyro values\n\r"); //printing the angular velocity and magnetic field values
sakthipriya 0:7b4c00e3912f 115 for(int i=0; i<3; i++)
sakthipriya 0:7b4c00e3912f 116 {
sakthipriya 0:7b4c00e3912f 117 pc.printf("%f\n\r",data[i]);
sakthipriya 0:7b4c00e3912f 118 }
sakthipriya 0:7b4c00e3912f 119 pc.printf("mag values\n\r");
sakthipriya 0:7b4c00e3912f 120 for(int i=3; i<6; i++)
sakthipriya 0:7b4c00e3912f 121 {
sakthipriya 0:7b4c00e3912f 122 pc.printf("%f\n\r",data[i]);
sakthipriya 0:7b4c00e3912f 123
sakthipriya 0:7b4c00e3912f 124 for(int i=0;i<3;i++)
sakthipriya 0:7b4c00e3912f 125 {
sakthipriya 0:7b4c00e3912f 126 omega1[i]= data[i];
sakthipriya 0:7b4c00e3912f 127 b1[i] = data[i+3];
sakthipriya 0:7b4c00e3912f 128 }
sakthipriya 0:7b4c00e3912f 129 }
sakthipriya 0:7b4c00e3912f 130 }//if ACS_DATA_ACQ_ENABLE = 1
sakthipriya 0:7b4c00e3912f 131 else
sakthipriya 0:7b4c00e3912f 132 {
sakthipriya 0:7b4c00e3912f 133 // Z axis actuation is the only final solution,
sakthipriya 0:7b4c00e3912f 134 }
sakthipriya 0:7b4c00e3912f 135 if(ACS_STATE == '0') // check ACS_STATE = ACS_CONTROL_OFF?
sakthipriya 0:7b4c00e3912f 136 {
sakthipriya 0:7b4c00e3912f 137 printf("\n\r acs control off\n");
sakthipriya 0:7b4c00e3912f 138 FLAG();
sakthipriya 0:7b4c00e3912f 139 ACS_STATUS = '0'; // set ACS_STATUS = ACS_CONTROL_OFF
sakthipriya 0:7b4c00e3912f 140 PWM1 = 0; //clear pwm pins
sakthipriya 0:7b4c00e3912f 141 PWM2 = 0; //clear pwm pins
sakthipriya 0:7b4c00e3912f 142 PWM3 = 0; //clear pwm pins
sakthipriya 0:7b4c00e3912f 143 }
sakthipriya 0:7b4c00e3912f 144 else
sakthipriya 0:7b4c00e3912f 145 {
sakthipriya 1:446a959e36ce 146 if(actual_data.power_mode>1)
sakthipriya 0:7b4c00e3912f 147
sakthipriya 0:7b4c00e3912f 148 {
sakthipriya 0:7b4c00e3912f 149 if(ACS_STATE == '2') // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY
sakthipriya 0:7b4c00e3912f 150 {
sakthipriya 0:7b4c00e3912f 151 FLAG();
sakthipriya 0:7b4c00e3912f 152 printf("\n\r z axis moment only\n");
sakthipriya 0:7b4c00e3912f 153 ACS_STATUS = '2'; // set ACS_STATUS = ACS_ZAXIS_MOMENT_ONLY
sakthipriya 0:7b4c00e3912f 154 // FCTN_ACS_CNTRLALGO(b1, omega1);
sakthipriya 0:7b4c00e3912f 155 moment[0] = 0;
sakthipriya 0:7b4c00e3912f 156 moment[1] = 0;
sakthipriya 0:7b4c00e3912f 157 moment[2] =1.3;// is a dummy value
sakthipriya 0:7b4c00e3912f 158 FCTN_ACS_GENPWM_MAIN(moment) ;
sakthipriya 0:7b4c00e3912f 159 }
sakthipriya 0:7b4c00e3912f 160 else
sakthipriya 0:7b4c00e3912f 161 {
sakthipriya 0:7b4c00e3912f 162 if(ACS_STATE == '3') // check ACS_STATE = ACS_DATA_ACQ_FAILURE
sakthipriya 0:7b4c00e3912f 163 {
sakthipriya 0:7b4c00e3912f 164 FLAG();
sakthipriya 0:7b4c00e3912f 165 printf("\n\r acs data failure ");
sakthipriya 0:7b4c00e3912f 166 ACS_STATUS = '3'; // set ACS_STATUS = ACS_DATA_ACQ_FAILURE
sakthipriya 0:7b4c00e3912f 167 PWM1 = 0; //clear pwm pins
sakthipriya 0:7b4c00e3912f 168 PWM2 = 0; //clear pwm pins
sakthipriya 0:7b4c00e3912f 169 PWM3 = 0; //clear pwm pins
sakthipriya 0:7b4c00e3912f 170 }
sakthipriya 0:7b4c00e3912f 171 else
sakthipriya 0:7b4c00e3912f 172 {
sakthipriya 0:7b4c00e3912f 173 if(ACS_STATE == '4') // check ACS_STATE = ACS_NOMINAL_ONLY
sakthipriya 0:7b4c00e3912f 174 {
sakthipriya 0:7b4c00e3912f 175 FLAG();
sakthipriya 0:7b4c00e3912f 176 printf("\n\r nominal");
sakthipriya 0:7b4c00e3912f 177 ACS_STATUS = '4'; // set ACS_STATUS = ACS_NOMINAL_ONLY
sakthipriya 0:7b4c00e3912f 178 FCTN_ACS_CNTRLALGO(b1,omega1);
sakthipriya 0:7b4c00e3912f 179 printf("\n\r moment values returned by control algo \n");
sakthipriya 0:7b4c00e3912f 180 for(int i=0; i<3; i++)
sakthipriya 0:7b4c00e3912f 181 {
sakthipriya 0:7b4c00e3912f 182 printf("%f\t",moment[i]);
sakthipriya 0:7b4c00e3912f 183 }
sakthipriya 0:7b4c00e3912f 184 FCTN_ACS_GENPWM_MAIN(moment) ;
sakthipriya 0:7b4c00e3912f 185 }
sakthipriya 0:7b4c00e3912f 186 else
sakthipriya 0:7b4c00e3912f 187 {
sakthipriya 0:7b4c00e3912f 188 if(ACS_STATE == '5') // check ACS_STATE = ACS_AUTO_CONTROL
sakthipriya 0:7b4c00e3912f 189 {
sakthipriya 0:7b4c00e3912f 190 FLAG();
sakthipriya 0:7b4c00e3912f 191 printf("\n\r auto control");
sakthipriya 0:7b4c00e3912f 192 ACS_STATUS = '5'; // set ACS_STATUS = ACS_AUTO_CONTROL
sakthipriya 0:7b4c00e3912f 193 //FCTN_ACS_AUTOCTRL_LOGIC // gotta include this code
sakthipriya 0:7b4c00e3912f 194 }
sakthipriya 0:7b4c00e3912f 195 else
sakthipriya 0:7b4c00e3912f 196 {
sakthipriya 0:7b4c00e3912f 197 if(ACS_STATE == '6') // check ACS_STATE = ACS_DETUMBLING_ONLY
sakthipriya 0:7b4c00e3912f 198 {
sakthipriya 0:7b4c00e3912f 199 FLAG();
sakthipriya 0:7b4c00e3912f 200 printf("\n\r Entered detumbling \n");
sakthipriya 0:7b4c00e3912f 201 ACS_STATUS = '6'; // set ACS_STATUS = ACS_DETUMBLING_ONLY
sakthipriya 0:7b4c00e3912f 202 FCTN_ACS_CNTRLALGO(b1,omega1); // detumbling code has to be included
sakthipriya 0:7b4c00e3912f 203 FCTN_ACS_GENPWM_MAIN(moment) ;
sakthipriya 0:7b4c00e3912f 204 }
sakthipriya 0:7b4c00e3912f 205 else
sakthipriya 0:7b4c00e3912f 206 {
sakthipriya 0:7b4c00e3912f 207 FLAG();
sakthipriya 0:7b4c00e3912f 208 printf("\n\r invalid state");
sakthipriya 0:7b4c00e3912f 209 ACS_STATUS = '7' ; // set ACS_STATUS = INVALID STATE
sakthipriya 0:7b4c00e3912f 210 PWM1 = 0; //clear pwm pins
sakthipriya 0:7b4c00e3912f 211 PWM2 = 0; //clear pwm pins
sakthipriya 0:7b4c00e3912f 212 PWM3 = 0; //clear pwm pins
sakthipriya 0:7b4c00e3912f 213 }//else of invalid
sakthipriya 0:7b4c00e3912f 214 }//else of autocontrol
sakthipriya 0:7b4c00e3912f 215 }//else of nominal
sakthipriya 0:7b4c00e3912f 216 }//else of data acg failure
sakthipriya 0:7b4c00e3912f 217
sakthipriya 0:7b4c00e3912f 218 }//else fo z axis moment only
sakthipriya 0:7b4c00e3912f 219 }//if power >2
sakthipriya 0:7b4c00e3912f 220 else
sakthipriya 0:7b4c00e3912f 221 {
sakthipriya 0:7b4c00e3912f 222 FLAG();
sakthipriya 0:7b4c00e3912f 223 printf("\n\r low power");
sakthipriya 0:7b4c00e3912f 224 ACS_STATUS = '1'; // set ACS_STATUS = ACS_LOW_POWER
sakthipriya 0:7b4c00e3912f 225 PWM1 = 0; //clear pwm pins
sakthipriya 0:7b4c00e3912f 226 PWM2 = 0; //clear pwm pins
sakthipriya 0:7b4c00e3912f 227 PWM3 = 0; //clear pwm pins
sakthipriya 0:7b4c00e3912f 228 }
sakthipriya 0:7b4c00e3912f 229 } //else for acs control off
sakthipriya 0:7b4c00e3912f 230
sakthipriya 0:7b4c00e3912f 231
sakthipriya 0:7b4c00e3912f 232
sakthipriya 0:7b4c00e3912f 233 ACS_MAIN_STATUS = 'c'; //clear ACS_MAIN_STATUS flag
sakthipriya 3:07e15677a75c 234
sakthipriya 0:7b4c00e3912f 235 }
sakthipriya 0:7b4c00e3912f 236 //***************************************************EPS THREAD***********************************************//
sakthipriya 0:7b4c00e3912f 237
sakthipriya 3:07e15677a75c 238 void F_EPS()
sakthipriya 0:7b4c00e3912f 239 {
sakthipriya 3:07e15677a75c 240
sakthipriya 0:7b4c00e3912f 241 pc.printf("\n\rEntered EPS %f\n",t_start.read());
sakthipriya 0:7b4c00e3912f 242 EPS_MAIN_STATUS = 's'; // Set EPS main status
sakthipriya 3:07e15677a75c 243 FCTN_BATT_TEMP_SENSOR_MAIN(actual_data.Batt_temp_actual);
sakthipriya 3:07e15677a75c 244 pc.printf("\n\r Battery temperature %f %f" ,actual_data.Batt_temp_actual[0], actual_data.Batt_temp_actual[1]);
sakthipriya 3:07e15677a75c 245 EPS_BATTERY_TEMP_STATUS = 's'; //set EPS_BATTERY_TEMP_STATUS
sakthipriya 3:07e15677a75c 246 if(EPS_BATTERY_HEAT_ENABLE == 'e')
sakthipriya 3:07e15677a75c 247 {
sakthipriya 3:07e15677a75c 248 if((actual_data.Batt_temp_actual[0] < batt_heat_low) & (actual_data.Batt_temp_actual[1] < batt_heat_low)) // to confirm
sakthipriya 3:07e15677a75c 249 {
sakthipriya 3:07e15677a75c 250 batt_heat = 1; //turn on battery heater
sakthipriya 3:07e15677a75c 251 }
sakthipriya 3:07e15677a75c 252 else
sakthipriya 3:07e15677a75c 253 {
sakthipriya 3:07e15677a75c 254 batt_heat = 0; //turn off battery heater
sakthipriya 3:07e15677a75c 255 }
sakthipriya 3:07e15677a75c 256
sakthipriya 3:07e15677a75c 257 }
sakthipriya 3:07e15677a75c 258 else if(EPS_BATTERY_HEAT_ENABLE == 'd')
sakthipriya 3:07e15677a75c 259 {
sakthipriya 3:07e15677a75c 260 EPS_STATUS = 1;//EPS_STATUS = EPS_BATTERY_HEATER_DISABLED
sakthipriya 3:07e15677a75c 261 }
sakthipriya 0:7b4c00e3912f 262 FCTN_BATTERYGAUGE_MAIN(actual_data.Batt_gauge_actual);
sakthipriya 1:446a959e36ce 263 if (actual_data.Batt_gauge_actual[1] == 200) //data not received
sakthipriya 0:7b4c00e3912f 264 {
sakthipriya 0:7b4c00e3912f 265 actual_data.power_mode = 1;
sakthipriya 0:7b4c00e3912f 266 EPS_BATTERY_GAUGE_STATUS = 'c'; //clear EPS_BATTERY_GAUGE_STATUS
sakthipriya 0:7b4c00e3912f 267
sakthipriya 0:7b4c00e3912f 268 }
sakthipriya 0:7b4c00e3912f 269 else
sakthipriya 0:7b4c00e3912f 270 {
sakthipriya 1:446a959e36ce 271 FCTN_EPS_POWERMODE(actual_data.Batt_gauge_actual[1]); //updating power level
sakthipriya 0:7b4c00e3912f 272 EPS_BATTERY_GAUGE_STATUS = 's'; //set EPS_BATTERY_GAUGE_STATUS
sakthipriya 0:7b4c00e3912f 273 }
sakthipriya 3:07e15677a75c 274 // if( Temperature data received)
sakthipriya 3:07e15677a75c 275 //{
sakthipriya 3:07e15677a75c 276
sakthipriya 0:7b4c00e3912f 277
sakthipriya 3:07e15677a75c 278 // }
sakthipriya 3:07e15677a75c 279 // else
sakthipriya 3:07e15677a75c 280 // {
sakthipriya 3:07e15677a75c 281 // Set battery temp to XX
sakthipriya 3:07e15677a75c 282 // EPS_BATTERY_TEMP_STATUS = 'c'; //clear EPS_BATTERY_TEMP_STATUS
sakthipriya 3:07e15677a75c 283 // EPS_STATUS = EPS_ERR_BATTERY_TEMP;
sakthipriya 3:07e15677a75c 284 // }
sakthipriya 3:07e15677a75c 285 FCTN_HK_MAIN();
sakthipriya 3:07e15677a75c 286 //FCTN_APPEND_HKDATA();
sakthipriya 3:07e15677a75c 287 //minMaxHkData();
sakthipriya 0:7b4c00e3912f 288
sakthipriya 3:07e15677a75c 289 EPS_MAIN_STATUS = 'c'; // clear EPS main status
sakthipriya 3:07e15677a75c 290
sakthipriya 0:7b4c00e3912f 291 }
sakthipriya 0:7b4c00e3912f 292
sakthipriya 0:7b4c00e3912f 293 //**************************************************BCN THREAD*******************************************************************//
sakthipriya 0:7b4c00e3912f 294
sakthipriya 3:07e15677a75c 295 void F_BCN()
sakthipriya 0:7b4c00e3912f 296 {
sakthipriya 3:07e15677a75c 297
sakthipriya 0:7b4c00e3912f 298 pc.printf("\n\rEntered BCN %f\n",t_start.read());
sakthipriya 0:7b4c00e3912f 299
sakthipriya 0:7b4c00e3912f 300 P_BCN_TX_MAIN();
sakthipriya 0:7b4c00e3912f 301
sakthipriya 0:7b4c00e3912f 302 }
sakthipriya 0:7b4c00e3912f 303
sakthipriya 0:7b4c00e3912f 304 //**************************************************TCTM THREAD*******************************************************************//
sakthipriya 0:7b4c00e3912f 305
sakthipriya 0:7b4c00e3912f 306 void T_TC(void const * args)
sakthipriya 0:7b4c00e3912f 307 {
sakthipriya 0:7b4c00e3912f 308 while(1)
sakthipriya 0:7b4c00e3912f 309 {
sakthipriya 0:7b4c00e3912f 310 Thread::signal_wait(0x4);
sakthipriya 0:7b4c00e3912f 311 wait_us(200); // can be between 38 to 15700
sakthipriya 0:7b4c00e3912f 312 if( slave.receive() == 0)
sakthipriya 0:7b4c00e3912f 313 slave.stop();
sakthipriya 0:7b4c00e3912f 314 else if( slave.receive() == 1) // slave writes to master
sakthipriya 0:7b4c00e3912f 315 {
sakthipriya 3:07e15677a75c 316 write_ack=slave.write((char*)telemetry,tm_len);
sakthipriya 4:39a4ae8c7ecd 317 irpt_2_mstr = 0;
sakthipriya 0:7b4c00e3912f 318 }
sakthipriya 0:7b4c00e3912f 319 else if( slave.receive()==3 || slave.receive()==2) // slave read
sakthipriya 0:7b4c00e3912f 320 {
sakthipriya 0:7b4c00e3912f 321 read_ack=slave.read(telecommand,tc_len);
sakthipriya 0:7b4c00e3912f 322 pc.printf("\n\rTELECOMMAND received from CDMS is %s \n",telecommand);
sakthipriya 0:7b4c00e3912f 323 pc.printf("\n\r Executing Telecommand \n");
sakthipriya 3:07e15677a75c 324 // FCTN_TC_DECODE((uint8_t*) telecommand);
sakthipriya 3:07e15677a75c 325 uint8_t* temp = FCTN_BAE_TM_TC((uint8_t*) telecommand);
sakthipriya 3:07e15677a75c 326 telemetry = (char*)temp;
sakthipriya 0:7b4c00e3912f 327 FCTN_TM();
sakthipriya 3:07e15677a75c 328 // for(int i = 0; i<134; i++)
sakthipriya 3:07e15677a75c 329 //pc.printf("%c", telemetry[i]);
sakthipriya 0:7b4c00e3912f 330 }
sakthipriya 0:7b4c00e3912f 331
sakthipriya 0:7b4c00e3912f 332 }
sakthipriya 0:7b4c00e3912f 333 }
sakthipriya 0:7b4c00e3912f 334
sakthipriya 0:7b4c00e3912f 335 void FCTN_TM()
sakthipriya 0:7b4c00e3912f 336 {
sakthipriya 4:39a4ae8c7ecd 337 //irpt_2_mstr = 0;
sakthipriya 0:7b4c00e3912f 338 pc.printf("\n\r Telemetry Generation \n");
sakthipriya 0:7b4c00e3912f 339 irpt_2_mstr = 1;
sakthipriya 0:7b4c00e3912f 340 }
sakthipriya 0:7b4c00e3912f 341
sakthipriya 0:7b4c00e3912f 342
sakthipriya 0:7b4c00e3912f 343 //******************************************************* I2C *******************************************************************//
sakthipriya 0:7b4c00e3912f 344
sakthipriya 0:7b4c00e3912f 345 void FCTN_I2C_ISR()
sakthipriya 0:7b4c00e3912f 346 {
sakthipriya 0:7b4c00e3912f 347 ptr_t_i2c->signal_set(0x4);
sakthipriya 0:7b4c00e3912f 348 }
sakthipriya 0:7b4c00e3912f 349
sakthipriya 0:7b4c00e3912f 350
sakthipriya 0:7b4c00e3912f 351 //------------------------------------------------------------------------------------------------------------------------------------------------
sakthipriya 0:7b4c00e3912f 352 //SCHEDULER
sakthipriya 0:7b4c00e3912f 353 //------------------------------------------------------------------------------------------------------------------------------------------------
sakthipriya 0:7b4c00e3912f 354 uint8_t schedcount=1;
sakthipriya 0:7b4c00e3912f 355 void T_SC(void const *args)
sakthipriya 0:7b4c00e3912f 356 {
sakthipriya 0:7b4c00e3912f 357 printf("\n\r in scheduler");
sakthipriya 0:7b4c00e3912f 358
sakthipriya 0:7b4c00e3912f 359 if(schedcount == 7) //to reset the counter
sakthipriya 0:7b4c00e3912f 360 {
sakthipriya 0:7b4c00e3912f 361 schedcount = 1;
sakthipriya 0:7b4c00e3912f 362 }
sakthipriya 0:7b4c00e3912f 363 if(schedcount%1==0)
sakthipriya 0:7b4c00e3912f 364 {
sakthipriya 3:07e15677a75c 365 F_ACS();
sakthipriya 0:7b4c00e3912f 366 }
sakthipriya 0:7b4c00e3912f 367
sakthipriya 0:7b4c00e3912f 368 if(schedcount%2==0)
sakthipriya 0:7b4c00e3912f 369 {
sakthipriya 3:07e15677a75c 370 F_EPS();
sakthipriya 0:7b4c00e3912f 371 }
sakthipriya 0:7b4c00e3912f 372 if(schedcount%3==0)
sakthipriya 0:7b4c00e3912f 373 {
sakthipriya 3:07e15677a75c 374 // F_BCN();
sakthipriya 0:7b4c00e3912f 375 }
sakthipriya 0:7b4c00e3912f 376 schedcount++;
sakthipriya 0:7b4c00e3912f 377 printf("\n\r exited scheduler");
sakthipriya 0:7b4c00e3912f 378 }
sakthipriya 0:7b4c00e3912f 379
sakthipriya 0:7b4c00e3912f 380 Timer t_flag;
sakthipriya 0:7b4c00e3912f 381 void FLAG()
sakthipriya 0:7b4c00e3912f 382 {
sakthipriya 0:7b4c00e3912f 383
sakthipriya 0:7b4c00e3912f 384 //.............acs..................//
sakthipriya 0:7b4c00e3912f 385 if(ACS_INIT_STATUS == 's')
sakthipriya 0:7b4c00e3912f 386 BAE_STATUS = BAE_STATUS | 0x00000080; //set ACS_INIT_STATUS flag
sakthipriya 0:7b4c00e3912f 387 else if(ACS_INIT_STATUS == 'c')
sakthipriya 0:7b4c00e3912f 388 BAE_STATUS &= 0xFFFFFF7F; //clear ACS_INIT_STATUS flag
sakthipriya 0:7b4c00e3912f 389
sakthipriya 0:7b4c00e3912f 390 if(ACS_DATA_ACQ_STATUS == 's')
sakthipriya 0:7b4c00e3912f 391 BAE_STATUS =BAE_STATUS | 0x00000100; //set ACS_DATA_ACQ_STATUS flag
sakthipriya 0:7b4c00e3912f 392 else if(ACS_DATA_ACQ_STATUS == 'c')
sakthipriya 0:7b4c00e3912f 393 BAE_STATUS &= 0xFFFFFEFF; //clear ACS_DATA_ACQ_STATUS flag
sakthipriya 0:7b4c00e3912f 394
sakthipriya 0:7b4c00e3912f 395 if(ACS_ATS_ENABLE == 'e')
sakthipriya 0:7b4c00e3912f 396 BAE_ENABLE |= 0x00000004;
sakthipriya 0:7b4c00e3912f 397 else if(ACS_ATS_ENABLE == 'd')
sakthipriya 0:7b4c00e3912f 398 BAE_ENABLE = BAE_ENABLE &0xFFFFFFFB | 0x00000004;
sakthipriya 0:7b4c00e3912f 399
sakthipriya 0:7b4c00e3912f 400 if(ACS_DATA_ACQ_STATUS == 'f')
sakthipriya 0:7b4c00e3912f 401 BAE_STATUS |= 0x00000200;
sakthipriya 0:7b4c00e3912f 402
sakthipriya 0:7b4c00e3912f 403 if(ACS_MAIN_STATUS == 's')
sakthipriya 0:7b4c00e3912f 404 BAE_STATUS = (BAE_STATUS | 0x00001000); //set ACS_MAIN_STATUS flag
sakthipriya 0:7b4c00e3912f 405 else if(ACS_MAIN_STATUS == 'c')
sakthipriya 0:7b4c00e3912f 406 BAE_STATUS &= 0xFFFFEFFF; //clear ACS_MAIN_STATUS flag
sakthipriya 0:7b4c00e3912f 407
sakthipriya 0:7b4c00e3912f 408 if(ACS_STATUS == '0')
sakthipriya 0:7b4c00e3912f 409 BAE_STATUS = (BAE_STATUS & 0xFFFF1FFF); // set ACS_STATUS = ACS_CONTROL_OFF
sakthipriya 0:7b4c00e3912f 410 else if(ACS_STATUS == '1')
sakthipriya 0:7b4c00e3912f 411 BAE_STATUS =(BAE_STATUS & 0xFFFF1FFF) | 0x00002000; // set ACS_STATUS = ACS_LOW_POWER
sakthipriya 0:7b4c00e3912f 412 else if(ACS_STATUS == '2')
sakthipriya 0:7b4c00e3912f 413 BAE_STATUS = (BAE_STATUS & 0xFFFF1FFF)| 0x00004000; // set ACS_STATUS = ACS_ZAXIS_MOMENT_ONLY
sakthipriya 0:7b4c00e3912f 414 else if(ACS_STATUS == '3')
sakthipriya 0:7b4c00e3912f 415 BAE_STATUS = (BAE_STATUS & 0xFFFF1FFF) | 0x00006000; // set ACS_STATUS = ACS_DATA_ACQ_FAILURE
sakthipriya 0:7b4c00e3912f 416 else if(ACS_STATUS == '4')
sakthipriya 0:7b4c00e3912f 417 BAE_STATUS = (BAE_STATUS & 0xFFFF1FFF) | 0x00008000; // set ACS_STATUS = ACS_NOMINAL_ONLY
sakthipriya 0:7b4c00e3912f 418 else if(ACS_STATUS == '5')
sakthipriya 0:7b4c00e3912f 419 BAE_STATUS =(BAE_STATUS & 0xFFFF1FFF) | 0x0000A000; // set ACS_STATUS = ACS_AUTO_CONTROL
sakthipriya 0:7b4c00e3912f 420 else if(ACS_STATUS == '6')
sakthipriya 0:7b4c00e3912f 421 BAE_STATUS =(BAE_STATUS & 0xFFFF1FFF) | 0x0000C000; // set ACS_STATUS = ACS_DETUMBLING_ONLY
sakthipriya 0:7b4c00e3912f 422 else
sakthipriya 0:7b4c00e3912f 423 BAE_STATUS =(BAE_STATUS & 0xFFFF1FFF) | 0x0000E000; // set ACS_STATUS = INVALID STATE
sakthipriya 0:7b4c00e3912f 424
sakthipriya 0:7b4c00e3912f 425 if(ACS_STATE == '0')
sakthipriya 0:7b4c00e3912f 426 BAE_ENABLE = (BAE_ENABLE & 0xFFFFFF8F); //ACS_STATE = ACS_CONTROL_OFF
sakthipriya 0:7b4c00e3912f 427 else if(ACS_STATE == '2')
sakthipriya 0:7b4c00e3912f 428 BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000020); // ACS_STATE = ACS_ZAXIS_MOMENT_ONLY
sakthipriya 0:7b4c00e3912f 429 else if(ACS_STATE == '3')
sakthipriya 0:7b4c00e3912f 430 BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000030); // set ACS_STATUS = ACS_DATA_ACQ_FAILURE
sakthipriya 0:7b4c00e3912f 431 else if(ACS_STATE == '4')
sakthipriya 0:7b4c00e3912f 432 BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000040); // ACS_STATE = ACS_NOMINAL_ONLY
sakthipriya 0:7b4c00e3912f 433 else if(ACS_STATE == '5')
sakthipriya 0:7b4c00e3912f 434 BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000050); // ACS_STATE = ACS_AUTO_CONTROL
sakthipriya 0:7b4c00e3912f 435 else if(ACS_STATE == '6')
sakthipriya 0:7b4c00e3912f 436 BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000060); //ACS_STATE = ACS_DETUMBLING_CONTROL
sakthipriya 0:7b4c00e3912f 437
sakthipriya 0:7b4c00e3912f 438 //...............eps......................//
sakthipriya 0:7b4c00e3912f 439 if(EPS_INIT_STATUS == 's')
sakthipriya 0:7b4c00e3912f 440 BAE_STATUS |= 0x00010000; //set EPS_INIT_STATUS flag
sakthipriya 0:7b4c00e3912f 441 else if(EPS_INIT_STATUS == 'c')
sakthipriya 0:7b4c00e3912f 442 BAE_STATUS &= 0xFFFEFFFF; //clear EPS_INIT_STATUS flag
sakthipriya 0:7b4c00e3912f 443 if(EPS_BATTERY_GAUGE_STATUS == 'c')
sakthipriya 0:7b4c00e3912f 444 BAE_STATUS &= 0xFFFDFFFF; //clear EPS_BATTERY_GAUGE_STATUS
sakthipriya 0:7b4c00e3912f 445 else if(EPS_BATTERY_GAUGE_STATUS == 's')
sakthipriya 0:7b4c00e3912f 446 BAE_STATUS |= 0x00020000; //set EPS_BATTERY_GAUGE_STATUS
sakthipriya 3:07e15677a75c 447
sakthipriya 3:07e15677a75c 448
sakthipriya 0:7b4c00e3912f 449
sakthipriya 0:7b4c00e3912f 450
sakthipriya 0:7b4c00e3912f 451 pc.printf("\n\r BAE status %x BAE ENABLE %x ",BAE_STATUS,BAE_ENABLE);
sakthipriya 0:7b4c00e3912f 452 }
sakthipriya 0:7b4c00e3912f 453
sakthipriya 0:7b4c00e3912f 454 void FCTN_BAE_INIT()
sakthipriya 0:7b4c00e3912f 455 {
sakthipriya 0:7b4c00e3912f 456 printf("\n\r Initialising BAE ");
sakthipriya 3:07e15677a75c 457 //..........intial status....//
sakthipriya 3:07e15677a75c 458 ACS_STATE = '4';
sakthipriya 3:07e15677a75c 459 ACS_ATS_ENABLE = 'e';
sakthipriya 3:07e15677a75c 460 ACS_DATA_ACQ_ENABLE = 'e';
sakthipriya 3:07e15677a75c 461 EPS_BATTERY_HEAT_ENABLE = 'e';
sakthipriya 3:07e15677a75c 462 //............................//
sakthipriya 3:07e15677a75c 463 FCTN_ACS_INIT();
sakthipriya 0:7b4c00e3912f 464 FCTN_EPS_INIT();
sakthipriya 0:7b4c00e3912f 465 //P_BCN_INIT();
sakthipriya 3:07e15677a75c 466
sakthipriya 3:07e15677a75c 467
sakthipriya 0:7b4c00e3912f 468 FLAG();
sakthipriya 0:7b4c00e3912f 469 }
sakthipriya 0:7b4c00e3912f 470
sakthipriya 0:7b4c00e3912f 471 int main()
sakthipriya 0:7b4c00e3912f 472 {
sakthipriya 0:7b4c00e3912f 473 pc.printf("\n\r BAE Activated. Testing Version 1.1 \n");
sakthipriya 0:7b4c00e3912f 474
sakthipriya 0:7b4c00e3912f 475 /* if (BCN_FEN == 0) //dummy implementation
sakthipriya 0:7b4c00e3912f 476 {
sakthipriya 0:7b4c00e3912f 477 pc.printf("\n\r RF silence ");
sakthipriya 0:7b4c00e3912f 478 P_BCN_FEN();
sakthipriya 0:7b4c00e3912f 479 t_rfsilence.start();//Start the timer for RF_Silence
sakthipriya 0:7b4c00e3912f 480 while(t_rfsilence.read() < RF_SILENCE_TIME);
sakthipriya 0:7b4c00e3912f 481 }
sakthipriya 0:7b4c00e3912f 482 */
sakthipriya 3:07e15677a75c 483
sakthipriya 0:7b4c00e3912f 484 //ACS_INIT_STATUS = 'c';
sakthipriya 0:7b4c00e3912f 485 //ACS_DATA_ACQ_STATUS = 'c';
sakthipriya 0:7b4c00e3912f 486 gpo1 = 0;
sakthipriya 0:7b4c00e3912f 487 FLAG();
sakthipriya 0:7b4c00e3912f 488 FCTN_BAE_INIT();
sakthipriya 3:07e15677a75c 489
sakthipriya 0:7b4c00e3912f 490
sakthipriya 0:7b4c00e3912f 491 //...i2c..
sakthipriya 3:07e15677a75c 492 //strcpy(telemetry,"This is telemetry THis is sample telemetry. ffffffffffffffffffffffffffffff end");
sakthipriya 0:7b4c00e3912f 493 slave.address(addr);
sakthipriya 0:7b4c00e3912f 494 irpt_2_mstr = 0;
sakthipriya 0:7b4c00e3912f 495
sakthipriya 0:7b4c00e3912f 496 ptr_t_i2c = new Thread(T_TC);
sakthipriya 0:7b4c00e3912f 497 ptr_t_i2c->set_priority(osPriorityHigh);
sakthipriya 0:7b4c00e3912f 498
sakthipriya 0:7b4c00e3912f 499 irpt_4m_mstr.enable_irq();
sakthipriya 0:7b4c00e3912f 500 irpt_4m_mstr.rise(&FCTN_I2C_ISR);
sakthipriya 0:7b4c00e3912f 501 RtosTimer t_sc_timer(T_SC,osTimerPeriodic); // Initiating the scheduler thread
sakthipriya 0:7b4c00e3912f 502 t_sc_timer.start(10000);
sakthipriya 0:7b4c00e3912f 503 t_start.start();
sakthipriya 0:7b4c00e3912f 504 pc.printf("\n\rStarted scheduler %f\n\r",t_start.read());
sakthipriya 0:7b4c00e3912f 505
sakthipriya 0:7b4c00e3912f 506 gpo1 = 0; // att sens2 switch is enabled
sakthipriya 0:7b4c00e3912f 507 //FCTN_BAE_INIT();
sakthipriya 0:7b4c00e3912f 508 while(1); //required to prevent main from terminating
sakthipriya 3:07e15677a75c 509 }
sakthipriya 3:07e15677a75c 510