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