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:
Thu Dec 24 20:01:31 2015 +0000
Revision:
1:446a959e36ce
Parent:
0:7b4c00e3912f
Child:
3:07e15677a75c
updated

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 0:7b4c00e3912f 62 char telemetry[tm_len];
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 0:7b4c00e3912f 80 Thread *ptr_t_acs;
sakthipriya 0:7b4c00e3912f 81 Thread *ptr_t_eps;
sakthipriya 0:7b4c00e3912f 82 Thread *ptr_t_bcn;
sakthipriya 0:7b4c00e3912f 83 Thread *ptr_t_i2c;
sakthipriya 0:7b4c00e3912f 84
sakthipriya 0:7b4c00e3912f 85 /*********************************************************FCTN HEADERS***********************************************************************************/
sakthipriya 0:7b4c00e3912f 86
sakthipriya 0:7b4c00e3912f 87 void FCTN_ISR_I2C();
sakthipriya 0:7b4c00e3912f 88 void FCTN_TM();
sakthipriya 0:7b4c00e3912f 89
sakthipriya 0:7b4c00e3912f 90 //*******************************************ACS THREAD**************************************************//
sakthipriya 0:7b4c00e3912f 91
sakthipriya 0:7b4c00e3912f 92 void T_ACS(void const *args)
sakthipriya 0:7b4c00e3912f 93 {
sakthipriya 0:7b4c00e3912f 94 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 95 //b1[3] = {22, 22,10};
sakthipriya 0:7b4c00e3912f 96 //omega1[3] = {2.1,3.0,1.5};
sakthipriya 0:7b4c00e3912f 97 // gpo1 = 0; // att sens2 switch is disabled
sakthipriya 0:7b4c00e3912f 98 // gpo2 = 0; // att sens switch is disabled
sakthipriya 0:7b4c00e3912f 99
sakthipriya 0:7b4c00e3912f 100 while(1)
sakthipriya 0:7b4c00e3912f 101 {
sakthipriya 0:7b4c00e3912f 102
sakthipriya 0:7b4c00e3912f 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 0:7b4c00e3912f 234 }//while ends
sakthipriya 0:7b4c00e3912f 235
sakthipriya 0:7b4c00e3912f 236
sakthipriya 0:7b4c00e3912f 237 }
sakthipriya 0:7b4c00e3912f 238 //***************************************************EPS THREAD***********************************************//
sakthipriya 0:7b4c00e3912f 239
sakthipriya 0:7b4c00e3912f 240 void T_EPS(void const *args)
sakthipriya 0:7b4c00e3912f 241 {
sakthipriya 0:7b4c00e3912f 242 while(1)
sakthipriya 0:7b4c00e3912f 243 {
sakthipriya 0:7b4c00e3912f 244 Thread::signal_wait(0x2);
sakthipriya 0:7b4c00e3912f 245 pc.printf("\n\rEntered EPS %f\n",t_start.read());
sakthipriya 0:7b4c00e3912f 246 EPS_MAIN_STATUS = 's'; // Set EPS main status
sakthipriya 0:7b4c00e3912f 247 //FCTN_READ_HK();
sakthipriya 0:7b4c00e3912f 248 //FCTN_APPEND_HKDATA();
sakthipriya 0:7b4c00e3912f 249 FCTN_BATTERYGAUGE_MAIN(actual_data.Batt_gauge_actual);
sakthipriya 1:446a959e36ce 250 if (actual_data.Batt_gauge_actual[1] == 200) //data not received
sakthipriya 0:7b4c00e3912f 251 {
sakthipriya 0:7b4c00e3912f 252 actual_data.power_mode = 1;
sakthipriya 0:7b4c00e3912f 253 EPS_BATTERY_GAUGE_STATUS = 'c'; //clear EPS_BATTERY_GAUGE_STATUS
sakthipriya 0:7b4c00e3912f 254
sakthipriya 0:7b4c00e3912f 255 }
sakthipriya 0:7b4c00e3912f 256 else
sakthipriya 0:7b4c00e3912f 257 {
sakthipriya 1:446a959e36ce 258 FCTN_EPS_POWERMODE(actual_data.Batt_gauge_actual[1]); //updating power level
sakthipriya 0:7b4c00e3912f 259 EPS_BATTERY_GAUGE_STATUS = 's'; //set EPS_BATTERY_GAUGE_STATUS
sakthipriya 0:7b4c00e3912f 260 }
sakthipriya 0:7b4c00e3912f 261 /* if( Temperature data received)
sakthipriya 0:7b4c00e3912f 262 {
sakthipriya 0:7b4c00e3912f 263 FCTN_BATT_TEMP_SENSOR_MAIN();
sakthipriya 0:7b4c00e3912f 264 EPS_BATTERY_TEMP_STATUS = 's'; //set EPS_BATTERY_TEMP_STATUS
sakthipriya 0:7b4c00e3912f 265 if(EPS_BATTERY_HEAT_ENABLE = 'e')
sakthipriya 0:7b4c00e3912f 266 {
sakthipriya 0:7b4c00e3912f 267 if(actual_data.Batt_temp_actual[0] < batt_heat_low)
sakthipriya 0:7b4c00e3912f 268 {
sakthipriya 0:7b4c00e3912f 269 batt_heat = 1; //turn on battery heater
sakthipriya 0:7b4c00e3912f 270 }
sakthipriya 0:7b4c00e3912f 271 else
sakthipriya 0:7b4c00e3912f 272 {
sakthipriya 0:7b4c00e3912f 273 batt_heat = 0; //turn off battery heater
sakthipriya 0:7b4c00e3912f 274 }
sakthipriya 0:7b4c00e3912f 275
sakthipriya 0:7b4c00e3912f 276 }
sakthipriya 0:7b4c00e3912f 277 else if(EPS_BATTERY_HEAT_ENABLE = 'd)
sakthipriya 0:7b4c00e3912f 278 {
sakthipriya 0:7b4c00e3912f 279 EPS_STATUS = EPS_BATTERY_HEATER_DISABLED;
sakthipriya 0:7b4c00e3912f 280 }
sakthipriya 0:7b4c00e3912f 281
sakthipriya 0:7b4c00e3912f 282 }
sakthipriya 0:7b4c00e3912f 283 else
sakthipriya 0:7b4c00e3912f 284 {
sakthipriya 0:7b4c00e3912f 285 Set battery temp to XX
sakthipriya 0:7b4c00e3912f 286 EPS_BATTERY_TEMP_STATUS = 'c'; //clear EPS_BATTERY_TEMP_STATUS
sakthipriya 0:7b4c00e3912f 287 EPS_STATUS = EPS_ERR_BATTERY_TEMP;
sakthipriya 0:7b4c00e3912f 288 }
sakthipriya 0:7b4c00e3912f 289
sakthipriya 0:7b4c00e3912f 290 EPS_MAIN_STATUS = 'c'; // clear EPS main status */
sakthipriya 0:7b4c00e3912f 291
sakthipriya 0:7b4c00e3912f 292 }
sakthipriya 0:7b4c00e3912f 293
sakthipriya 0:7b4c00e3912f 294 }
sakthipriya 0:7b4c00e3912f 295
sakthipriya 0:7b4c00e3912f 296 //**************************************************BCN THREAD*******************************************************************//
sakthipriya 0:7b4c00e3912f 297
sakthipriya 0:7b4c00e3912f 298 void T_BCN(void const *args)
sakthipriya 0:7b4c00e3912f 299 {
sakthipriya 0:7b4c00e3912f 300 while(1)
sakthipriya 0:7b4c00e3912f 301 {
sakthipriya 0:7b4c00e3912f 302 Thread::signal_wait(0x3);
sakthipriya 0:7b4c00e3912f 303 pc.printf("\n\rEntered BCN %f\n",t_start.read());
sakthipriya 0:7b4c00e3912f 304
sakthipriya 0:7b4c00e3912f 305 P_BCN_TX_MAIN();
sakthipriya 0:7b4c00e3912f 306 }
sakthipriya 0:7b4c00e3912f 307
sakthipriya 0:7b4c00e3912f 308 }
sakthipriya 0:7b4c00e3912f 309
sakthipriya 0:7b4c00e3912f 310 //**************************************************TCTM THREAD*******************************************************************//
sakthipriya 0:7b4c00e3912f 311
sakthipriya 0:7b4c00e3912f 312 void T_TC(void const * args)
sakthipriya 0:7b4c00e3912f 313 {
sakthipriya 0:7b4c00e3912f 314 while(1)
sakthipriya 0:7b4c00e3912f 315 {
sakthipriya 0:7b4c00e3912f 316 Thread::signal_wait(0x4);
sakthipriya 0:7b4c00e3912f 317 wait_us(200); // can be between 38 to 15700
sakthipriya 0:7b4c00e3912f 318 if( slave.receive() == 0)
sakthipriya 0:7b4c00e3912f 319 slave.stop();
sakthipriya 0:7b4c00e3912f 320 else if( slave.receive() == 1) // slave writes to master
sakthipriya 0:7b4c00e3912f 321 {
sakthipriya 0:7b4c00e3912f 322 write_ack=slave.write(telemetry,tm_len);
sakthipriya 0:7b4c00e3912f 323 }
sakthipriya 0:7b4c00e3912f 324 else if( slave.receive()==3 || slave.receive()==2) // slave read
sakthipriya 0:7b4c00e3912f 325 {
sakthipriya 0:7b4c00e3912f 326 read_ack=slave.read(telecommand,tc_len);
sakthipriya 0:7b4c00e3912f 327 pc.printf("\n\rTELECOMMAND received from CDMS is %s \n",telecommand);
sakthipriya 0:7b4c00e3912f 328 pc.printf("\n\r Executing Telecommand \n");
sakthipriya 0:7b4c00e3912f 329 FCTN_TC_DECODE((uint8_t*) telecommand);
sakthipriya 0:7b4c00e3912f 330 FCTN_TM();
sakthipriya 0:7b4c00e3912f 331 }
sakthipriya 0:7b4c00e3912f 332
sakthipriya 0:7b4c00e3912f 333 }
sakthipriya 0:7b4c00e3912f 334 }
sakthipriya 0:7b4c00e3912f 335
sakthipriya 0:7b4c00e3912f 336 void FCTN_TM()
sakthipriya 0:7b4c00e3912f 337 {
sakthipriya 0:7b4c00e3912f 338 irpt_2_mstr = 0;
sakthipriya 0:7b4c00e3912f 339 pc.printf("\n\r Telemetry Generation \n");
sakthipriya 0:7b4c00e3912f 340 irpt_2_mstr = 1;
sakthipriya 0:7b4c00e3912f 341 }
sakthipriya 0:7b4c00e3912f 342
sakthipriya 0:7b4c00e3912f 343
sakthipriya 0:7b4c00e3912f 344 //******************************************************* I2C *******************************************************************//
sakthipriya 0:7b4c00e3912f 345
sakthipriya 0:7b4c00e3912f 346 void FCTN_I2C_ISR()
sakthipriya 0:7b4c00e3912f 347 {
sakthipriya 0:7b4c00e3912f 348 ptr_t_i2c->signal_set(0x4);
sakthipriya 0:7b4c00e3912f 349 }
sakthipriya 0:7b4c00e3912f 350
sakthipriya 0:7b4c00e3912f 351
sakthipriya 0:7b4c00e3912f 352 //------------------------------------------------------------------------------------------------------------------------------------------------
sakthipriya 0:7b4c00e3912f 353 //SCHEDULER
sakthipriya 0:7b4c00e3912f 354 //------------------------------------------------------------------------------------------------------------------------------------------------
sakthipriya 0:7b4c00e3912f 355 uint8_t schedcount=1;
sakthipriya 0:7b4c00e3912f 356 void T_SC(void const *args)
sakthipriya 0:7b4c00e3912f 357 {
sakthipriya 0:7b4c00e3912f 358 printf("\n\r in scheduler");
sakthipriya 0:7b4c00e3912f 359
sakthipriya 0:7b4c00e3912f 360 if(schedcount == 7) //to reset the counter
sakthipriya 0:7b4c00e3912f 361 {
sakthipriya 0:7b4c00e3912f 362 schedcount = 1;
sakthipriya 0:7b4c00e3912f 363 }
sakthipriya 0:7b4c00e3912f 364 if(schedcount%1==0)
sakthipriya 0:7b4c00e3912f 365 {
sakthipriya 1:446a959e36ce 366 //ptr_t_acs -> signal_set(0x1);
sakthipriya 0:7b4c00e3912f 367 }
sakthipriya 0:7b4c00e3912f 368
sakthipriya 0:7b4c00e3912f 369 if(schedcount%2==0)
sakthipriya 0:7b4c00e3912f 370 {
sakthipriya 1:446a959e36ce 371 ptr_t_eps -> signal_set(0x2);
sakthipriya 0:7b4c00e3912f 372
sakthipriya 0:7b4c00e3912f 373 }
sakthipriya 0:7b4c00e3912f 374 if(schedcount%3==0)
sakthipriya 0:7b4c00e3912f 375 {
sakthipriya 0:7b4c00e3912f 376 //ptr_t_bcn -> signal_set(0x3);
sakthipriya 0:7b4c00e3912f 377 }
sakthipriya 0:7b4c00e3912f 378 schedcount++;
sakthipriya 0:7b4c00e3912f 379 printf("\n\r exited scheduler");
sakthipriya 0:7b4c00e3912f 380 }
sakthipriya 0:7b4c00e3912f 381
sakthipriya 0:7b4c00e3912f 382 Timer t_flag;
sakthipriya 0:7b4c00e3912f 383 void FLAG()
sakthipriya 0:7b4c00e3912f 384 {
sakthipriya 0:7b4c00e3912f 385
sakthipriya 0:7b4c00e3912f 386 //.............acs..................//
sakthipriya 0:7b4c00e3912f 387 if(ACS_INIT_STATUS == 's')
sakthipriya 0:7b4c00e3912f 388 BAE_STATUS = BAE_STATUS | 0x00000080; //set ACS_INIT_STATUS flag
sakthipriya 0:7b4c00e3912f 389 else if(ACS_INIT_STATUS == 'c')
sakthipriya 0:7b4c00e3912f 390 BAE_STATUS &= 0xFFFFFF7F; //clear ACS_INIT_STATUS flag
sakthipriya 0:7b4c00e3912f 391
sakthipriya 0:7b4c00e3912f 392 if(ACS_DATA_ACQ_STATUS == 's')
sakthipriya 0:7b4c00e3912f 393 BAE_STATUS =BAE_STATUS | 0x00000100; //set ACS_DATA_ACQ_STATUS flag
sakthipriya 0:7b4c00e3912f 394 else if(ACS_DATA_ACQ_STATUS == 'c')
sakthipriya 0:7b4c00e3912f 395 BAE_STATUS &= 0xFFFFFEFF; //clear ACS_DATA_ACQ_STATUS flag
sakthipriya 0:7b4c00e3912f 396
sakthipriya 0:7b4c00e3912f 397 if(ACS_ATS_ENABLE == 'e')
sakthipriya 0:7b4c00e3912f 398 BAE_ENABLE |= 0x00000004;
sakthipriya 0:7b4c00e3912f 399 else if(ACS_ATS_ENABLE == 'd')
sakthipriya 0:7b4c00e3912f 400 BAE_ENABLE = BAE_ENABLE &0xFFFFFFFB | 0x00000004;
sakthipriya 0:7b4c00e3912f 401
sakthipriya 0:7b4c00e3912f 402 if(ACS_DATA_ACQ_STATUS == 'f')
sakthipriya 0:7b4c00e3912f 403 BAE_STATUS |= 0x00000200;
sakthipriya 0:7b4c00e3912f 404
sakthipriya 0:7b4c00e3912f 405 if(ACS_MAIN_STATUS == 's')
sakthipriya 0:7b4c00e3912f 406 BAE_STATUS = (BAE_STATUS | 0x00001000); //set ACS_MAIN_STATUS flag
sakthipriya 0:7b4c00e3912f 407 else if(ACS_MAIN_STATUS == 'c')
sakthipriya 0:7b4c00e3912f 408 BAE_STATUS &= 0xFFFFEFFF; //clear ACS_MAIN_STATUS flag
sakthipriya 0:7b4c00e3912f 409
sakthipriya 0:7b4c00e3912f 410 if(ACS_STATUS == '0')
sakthipriya 0:7b4c00e3912f 411 BAE_STATUS = (BAE_STATUS & 0xFFFF1FFF); // set ACS_STATUS = ACS_CONTROL_OFF
sakthipriya 0:7b4c00e3912f 412 else if(ACS_STATUS == '1')
sakthipriya 0:7b4c00e3912f 413 BAE_STATUS =(BAE_STATUS & 0xFFFF1FFF) | 0x00002000; // set ACS_STATUS = ACS_LOW_POWER
sakthipriya 0:7b4c00e3912f 414 else if(ACS_STATUS == '2')
sakthipriya 0:7b4c00e3912f 415 BAE_STATUS = (BAE_STATUS & 0xFFFF1FFF)| 0x00004000; // set ACS_STATUS = ACS_ZAXIS_MOMENT_ONLY
sakthipriya 0:7b4c00e3912f 416 else if(ACS_STATUS == '3')
sakthipriya 0:7b4c00e3912f 417 BAE_STATUS = (BAE_STATUS & 0xFFFF1FFF) | 0x00006000; // set ACS_STATUS = ACS_DATA_ACQ_FAILURE
sakthipriya 0:7b4c00e3912f 418 else if(ACS_STATUS == '4')
sakthipriya 0:7b4c00e3912f 419 BAE_STATUS = (BAE_STATUS & 0xFFFF1FFF) | 0x00008000; // set ACS_STATUS = ACS_NOMINAL_ONLY
sakthipriya 0:7b4c00e3912f 420 else if(ACS_STATUS == '5')
sakthipriya 0:7b4c00e3912f 421 BAE_STATUS =(BAE_STATUS & 0xFFFF1FFF) | 0x0000A000; // set ACS_STATUS = ACS_AUTO_CONTROL
sakthipriya 0:7b4c00e3912f 422 else if(ACS_STATUS == '6')
sakthipriya 0:7b4c00e3912f 423 BAE_STATUS =(BAE_STATUS & 0xFFFF1FFF) | 0x0000C000; // set ACS_STATUS = ACS_DETUMBLING_ONLY
sakthipriya 0:7b4c00e3912f 424 else
sakthipriya 0:7b4c00e3912f 425 BAE_STATUS =(BAE_STATUS & 0xFFFF1FFF) | 0x0000E000; // set ACS_STATUS = INVALID STATE
sakthipriya 0:7b4c00e3912f 426
sakthipriya 0:7b4c00e3912f 427 if(ACS_STATE == '0')
sakthipriya 0:7b4c00e3912f 428 BAE_ENABLE = (BAE_ENABLE & 0xFFFFFF8F); //ACS_STATE = ACS_CONTROL_OFF
sakthipriya 0:7b4c00e3912f 429 else if(ACS_STATE == '2')
sakthipriya 0:7b4c00e3912f 430 BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000020); // ACS_STATE = ACS_ZAXIS_MOMENT_ONLY
sakthipriya 0:7b4c00e3912f 431 else if(ACS_STATE == '3')
sakthipriya 0:7b4c00e3912f 432 BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000030); // set ACS_STATUS = ACS_DATA_ACQ_FAILURE
sakthipriya 0:7b4c00e3912f 433 else if(ACS_STATE == '4')
sakthipriya 0:7b4c00e3912f 434 BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000040); // ACS_STATE = ACS_NOMINAL_ONLY
sakthipriya 0:7b4c00e3912f 435 else if(ACS_STATE == '5')
sakthipriya 0:7b4c00e3912f 436 BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000050); // ACS_STATE = ACS_AUTO_CONTROL
sakthipriya 0:7b4c00e3912f 437 else if(ACS_STATE == '6')
sakthipriya 0:7b4c00e3912f 438 BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000060); //ACS_STATE = ACS_DETUMBLING_CONTROL
sakthipriya 0:7b4c00e3912f 439
sakthipriya 0:7b4c00e3912f 440 //...............eps......................//
sakthipriya 0:7b4c00e3912f 441 if(EPS_INIT_STATUS == 's')
sakthipriya 0:7b4c00e3912f 442 BAE_STATUS |= 0x00010000; //set EPS_INIT_STATUS flag
sakthipriya 0:7b4c00e3912f 443 else if(EPS_INIT_STATUS == 'c')
sakthipriya 0:7b4c00e3912f 444 BAE_STATUS &= 0xFFFEFFFF; //clear EPS_INIT_STATUS flag
sakthipriya 0:7b4c00e3912f 445 if(EPS_BATTERY_GAUGE_STATUS == 'c')
sakthipriya 0:7b4c00e3912f 446 BAE_STATUS &= 0xFFFDFFFF; //clear EPS_BATTERY_GAUGE_STATUS
sakthipriya 0:7b4c00e3912f 447 else if(EPS_BATTERY_GAUGE_STATUS == 's')
sakthipriya 0:7b4c00e3912f 448 BAE_STATUS |= 0x00020000; //set EPS_BATTERY_GAUGE_STATUS
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 1:446a959e36ce 457 // FCTN_ACS_INIT();
sakthipriya 0:7b4c00e3912f 458 FCTN_EPS_INIT();
sakthipriya 0:7b4c00e3912f 459 //P_BCN_INIT();
sakthipriya 0:7b4c00e3912f 460 FLAG();
sakthipriya 0:7b4c00e3912f 461 }
sakthipriya 0:7b4c00e3912f 462
sakthipriya 0:7b4c00e3912f 463 int main()
sakthipriya 0:7b4c00e3912f 464 {
sakthipriya 0:7b4c00e3912f 465 pc.printf("\n\r BAE Activated. Testing Version 1.1 \n");
sakthipriya 0:7b4c00e3912f 466
sakthipriya 0:7b4c00e3912f 467 /* if (BCN_FEN == 0) //dummy implementation
sakthipriya 0:7b4c00e3912f 468 {
sakthipriya 0:7b4c00e3912f 469 pc.printf("\n\r RF silence ");
sakthipriya 0:7b4c00e3912f 470 P_BCN_FEN();
sakthipriya 0:7b4c00e3912f 471 t_rfsilence.start();//Start the timer for RF_Silence
sakthipriya 0:7b4c00e3912f 472 while(t_rfsilence.read() < RF_SILENCE_TIME);
sakthipriya 0:7b4c00e3912f 473 }
sakthipriya 0:7b4c00e3912f 474 */
sakthipriya 0:7b4c00e3912f 475 ACS_STATE = '4';
sakthipriya 0:7b4c00e3912f 476 //ACS_INIT_STATUS = 'c';
sakthipriya 0:7b4c00e3912f 477 //ACS_DATA_ACQ_STATUS = 'c';
sakthipriya 0:7b4c00e3912f 478 gpo1 = 0;
sakthipriya 0:7b4c00e3912f 479 FLAG();
sakthipriya 0:7b4c00e3912f 480 FCTN_BAE_INIT();
sakthipriya 0:7b4c00e3912f 481 ACS_ATS_ENABLE = 'e';
sakthipriya 0:7b4c00e3912f 482 ACS_DATA_ACQ_ENABLE = 'e';
sakthipriya 0:7b4c00e3912f 483
sakthipriya 0:7b4c00e3912f 484 //...i2c..
sakthipriya 0:7b4c00e3912f 485 strcpy(telemetry,"This is telemetry THis is sample telemetry. ffffffffffffffffffffffffffffff end");
sakthipriya 0:7b4c00e3912f 486 slave.address(addr);
sakthipriya 0:7b4c00e3912f 487 irpt_2_mstr = 0;
sakthipriya 0:7b4c00e3912f 488
sakthipriya 0:7b4c00e3912f 489 ptr_t_i2c = new Thread(T_TC);
sakthipriya 0:7b4c00e3912f 490 ptr_t_i2c->set_priority(osPriorityHigh);
sakthipriya 0:7b4c00e3912f 491 ptr_t_acs = new Thread(T_ACS);
sakthipriya 0:7b4c00e3912f 492 ptr_t_acs->set_priority(osPriorityAboveNormal);
sakthipriya 0:7b4c00e3912f 493 ptr_t_eps = new Thread(T_EPS);
sakthipriya 0:7b4c00e3912f 494 ptr_t_eps->set_priority(osPriorityAboveNormal);
sakthipriya 0:7b4c00e3912f 495 ptr_t_bcn = new Thread(T_BCN);
sakthipriya 0:7b4c00e3912f 496 ptr_t_bcn->set_priority(osPriorityAboveNormal);
sakthipriya 0:7b4c00e3912f 497
sakthipriya 0:7b4c00e3912f 498 irpt_4m_mstr.enable_irq();
sakthipriya 0:7b4c00e3912f 499 irpt_4m_mstr.rise(&FCTN_I2C_ISR);
sakthipriya 0:7b4c00e3912f 500 RtosTimer t_sc_timer(T_SC,osTimerPeriodic); // Initiating the scheduler thread
sakthipriya 0:7b4c00e3912f 501 t_sc_timer.start(10000);
sakthipriya 0:7b4c00e3912f 502 t_start.start();
sakthipriya 0:7b4c00e3912f 503 pc.printf("\n\rStarted scheduler %f\n\r",t_start.read());
sakthipriya 0:7b4c00e3912f 504
sakthipriya 0:7b4c00e3912f 505 gpo1 = 0; // att sens2 switch is enabled
sakthipriya 0:7b4c00e3912f 506 //FCTN_BAE_INIT();
sakthipriya 0:7b4c00e3912f 507 while(1); //required to prevent main from terminating
sakthipriya 0:7b4c00e3912f 508 }