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