I2C BAE standalone hardware testing
Dependencies: FreescaleIAP mbed-rtos mbed
Fork of ACS_Flowchart_BAE_1 by
main.cpp@17:8a8024c45dc0, 2016-06-24 (annotated)
- Committer:
- prasanthbj05
- Date:
- Fri Jun 24 08:08:52 2016 +0000
- Revision:
- 17:8a8024c45dc0
- Parent:
- 16:cc77770d787f
- Child:
- 18:95f0cc565ee3
I2C working with printfs;
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 |
prasanthbj05 | 17:8a8024c45dc0 | 12 | #define PRINT 1 |
sakthipriya | 9:194afacf7449 | 13 | |
sakthipriya | 0:7b4c00e3912f | 14 | //***************************************************** flags *************************************************************// |
sakthipriya | 0:7b4c00e3912f | 15 | uint32_t BAE_STATUS = 0x00000000; |
sakthipriya | 0:7b4c00e3912f | 16 | uint32_t BAE_ENABLE = 0xFFFFFFFF; |
sakthipriya | 0:7b4c00e3912f | 17 | |
sakthipriya | 5:bb592f3185cc | 18 | //i2c// |
sakthipriya | 5:bb592f3185cc | 19 | char data_send_flag = 'h'; |
sakthipriya | 5:bb592f3185cc | 20 | |
sakthipriya | 0:7b4c00e3912f | 21 | //.........acs...............// |
sakthipriya | 9:194afacf7449 | 22 | /* char ACS_INIT_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 23 | char ACS_DATA_ACQ_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 24 | char ACS_ATS_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 25 | char ACS_MAIN_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 26 | char ACS_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 27 | |
sakthipriya | 0:7b4c00e3912f | 28 | char ACS_ATS_ENABLE = 'q'; |
sakthipriya | 0:7b4c00e3912f | 29 | char ACS_DATA_ACQ_ENABLE = 'q'; |
sakthipriya | 9:194afacf7449 | 30 | char ACS_STATE = 'q';*/ |
sakthipriya | 9:194afacf7449 | 31 | |
sakthipriya | 9:194afacf7449 | 32 | uint8_t ACS_INIT_STATUS = 0; |
sakthipriya | 9:194afacf7449 | 33 | uint8_t ACS_DATA_ACQ_STATUS = 0; |
Bragadeesh153 | 16:cc77770d787f | 34 | uint8_t ACS_ATS_STATUS = 0x60; |
sakthipriya | 9:194afacf7449 | 35 | uint8_t ACS_MAIN_STATUS = 0; |
sakthipriya | 9:194afacf7449 | 36 | uint8_t ACS_STATUS = 0; |
sakthipriya | 9:194afacf7449 | 37 | |
sakthipriya | 9:194afacf7449 | 38 | uint8_t ACS_ATS_ENABLE = 1; |
sakthipriya | 9:194afacf7449 | 39 | uint8_t ACS_DATA_ACQ_ENABLE = 1; |
sakthipriya | 9:194afacf7449 | 40 | uint8_t ACS_STATE = 4; |
sakthipriya | 0:7b4c00e3912f | 41 | |
sakthipriya | 0:7b4c00e3912f | 42 | //.....................eps...................// |
sakthipriya | 0:7b4c00e3912f | 43 | //eps init |
sakthipriya | 9:194afacf7449 | 44 | /*char EPS_INIT_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 45 | char EPS_BATTERY_GAUGE_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 46 | //eps main |
sakthipriya | 0:7b4c00e3912f | 47 | char EPS_MAIN_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 48 | char EPS_BATTERY_TEMP_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 49 | char EPS_STATUS = 'q'; |
sakthipriya | 0:7b4c00e3912f | 50 | |
sakthipriya | 0:7b4c00e3912f | 51 | char EPS_BATTERY_HEAT_ENABLE = 'q'; |
sakthipriya | 9:194afacf7449 | 52 | */ |
sakthipriya | 9:194afacf7449 | 53 | |
sakthipriya | 9:194afacf7449 | 54 | uint8_t EPS_INIT_STATUS = 0; |
sakthipriya | 9:194afacf7449 | 55 | uint8_t EPS_BATTERY_GAUGE_STATUS = 0; |
sakthipriya | 9:194afacf7449 | 56 | //eps main |
sakthipriya | 9:194afacf7449 | 57 | uint8_t EPS_MAIN_STATUS = 0; |
sakthipriya | 9:194afacf7449 | 58 | uint8_t EPS_BATTERY_TEMP_STATUS = 0; |
sakthipriya | 9:194afacf7449 | 59 | uint8_t EPS_STATUS = 7; //invalid status |
sakthipriya | 9:194afacf7449 | 60 | |
sakthipriya | 9:194afacf7449 | 61 | uint8_t EPS_BATTERY_HEAT_ENABLE = 0; |
sakthipriya | 0:7b4c00e3912f | 62 | |
sakthipriya | 0:7b4c00e3912f | 63 | //.......................global variables..................................................................// new hk structure- everything has to changed based on this |
sakthipriya | 6:036d08b62785 | 64 | uint8_t BAE_data[74]; |
sakthipriya | 6:036d08b62785 | 65 | char BAE_chardata[74]; |
sakthipriya | 0:7b4c00e3912f | 66 | |
sakthipriya | 0:7b4c00e3912f | 67 | |
sakthipriya | 0:7b4c00e3912f | 68 | //*************************************Global declarations************************************************// |
sakthipriya | 0:7b4c00e3912f | 69 | const int addr = 0x20; //slave address |
sakthipriya | 0:7b4c00e3912f | 70 | |
sakthipriya | 0:7b4c00e3912f | 71 | Timer t_rfsilence; |
sakthipriya | 0:7b4c00e3912f | 72 | Timer t_start; |
sakthipriya | 7:a46a1dee4497 | 73 | Timer t_tc; |
sakthipriya | 7:a46a1dee4497 | 74 | Timer t_tm; |
prasanthbj05 | 17:8a8024c45dc0 | 75 | Timer synch; |
sakthipriya | 0:7b4c00e3912f | 76 | Serial pc(USBTX, USBRX); |
sakthipriya | 0:7b4c00e3912f | 77 | int power_flag_dummy=2; |
sakthipriya | 0:7b4c00e3912f | 78 | float data[6]; |
sakthipriya | 0:7b4c00e3912f | 79 | |
sakthipriya | 0:7b4c00e3912f | 80 | extern float moment[3]; |
sakthipriya | 0:7b4c00e3912f | 81 | extern uint8_t BCN_FEN; |
sakthipriya | 1:446a959e36ce | 82 | extern BAE_HK_actual actual_data; |
sakthipriya | 1:446a959e36ce | 83 | extern BAE_HK_quant quant_data; |
sakthipriya | 1:446a959e36ce | 84 | extern BAE_HK_min_max bae_HK_minmax; |
sakthipriya | 1:446a959e36ce | 85 | extern BAE_HK_arch arch_data; |
sakthipriya | 0:7b4c00e3912f | 86 | |
sakthipriya | 5:bb592f3185cc | 87 | int write_ack = 1; |
sakthipriya | 5:bb592f3185cc | 88 | int read_ack = 1; |
prasanthbj05 | 17:8a8024c45dc0 | 89 | uint8_t telecommand[11]; |
Bragadeesh153 | 13:fb7facaf308b | 90 | extern uint8_t telemetry[135]; |
sakthipriya | 5:bb592f3185cc | 91 | |
sakthipriya | 5:bb592f3185cc | 92 | bool pf1check = 0; |
sakthipriya | 5:bb592f3185cc | 93 | bool pf2check = 0; |
sakthipriya | 5:bb592f3185cc | 94 | bool if1check = 0; |
lakshya | 14:a9588f443f1a | 95 | bool if2check = 0; |
sakthipriya | 0:7b4c00e3912f | 96 | |
sakthipriya | 0:7b4c00e3912f | 97 | //*****************************************************Assigning pins******************************************************// |
sakthipriya | 9:194afacf7449 | 98 | DigitalOut ATS1_SW_ENABLE(PTC0); // enable of att sens2 switch |
sakthipriya | 9:194afacf7449 | 99 | DigitalOut ATS2_SW_ENABLE(PTC16); // enable of att sens switch |
Bragadeesh153 | 16:cc77770d787f | 100 | |
sakthipriya | 0:7b4c00e3912f | 101 | InterruptIn irpt_4m_mstr(PIN38); //I2c interrupt from CDMS |
sakthipriya | 0:7b4c00e3912f | 102 | DigitalOut irpt_2_mstr(PIN4); //I2C interrupt to CDMS |
lakshya | 14:a9588f443f1a | 103 | I2CSlave slave (PIN1,PIN2);///pin1 pin2 |
sakthipriya | 0:7b4c00e3912f | 104 | DigitalOut batt_heat(PIN96); |
sakthipriya | 0:7b4c00e3912f | 105 | |
sakthipriya | 9:194afacf7449 | 106 | //ATS1_SW_ENABLE = 0; |
sakthipriya | 0:7b4c00e3912f | 107 | PwmOut PWM1(PIN93); //x //Functions used to generate PWM signal |
sakthipriya | 0:7b4c00e3912f | 108 | PwmOut PWM2(PIN94); //y |
sakthipriya | 0:7b4c00e3912f | 109 | PwmOut PWM3(PIN95); //z //PWM output comes from pins p6 |
sakthipriya | 0:7b4c00e3912f | 110 | |
sakthipriya | 5:bb592f3185cc | 111 | //........faults |
sakthipriya | 5:bb592f3185cc | 112 | //Polled Faults |
sakthipriya | 5:bb592f3185cc | 113 | DigitalIn pf1(PIN5);//Attitude Sensor 1 OC bar fault signal |
sakthipriya | 5:bb592f3185cc | 114 | DigitalIn pf2(PIN97);//Attitude Sensor 2 OC bar fault signal |
sakthipriya | 5:bb592f3185cc | 115 | DigitalIn pf3(PIN83);//Fault Bar for TRXY driver |
sakthipriya | 5:bb592f3185cc | 116 | |
sakthipriya | 5:bb592f3185cc | 117 | //Interrupt based faults |
lakshya | 14:a9588f443f1a | 118 | //InterruptIn ir1(PIN73);//Battery Gauge - Alert Bar Signal |
sakthipriya | 5:bb592f3185cc | 119 | InterruptIn ir2(PIN72);//TRXY Driver TR switch Fault |
sakthipriya | 5:bb592f3185cc | 120 | InterruptIn ir3(PIN89);//TRZ Driver Fault Bar |
sakthipriya | 5:bb592f3185cc | 121 | InterruptIn ir4(PIN91);//TRZ Driver TR switch Fault |
sakthipriya | 5:bb592f3185cc | 122 | InterruptIn ir5(PIN79);//CDMS - Switch Fault |
sakthipriya | 5:bb592f3185cc | 123 | InterruptIn ir6(PIN80);//Beacon- Switch OC bar |
sakthipriya | 5:bb592f3185cc | 124 | InterruptIn ir7(PIN42);//Charger IC - Fault Bar |
sakthipriya | 5:bb592f3185cc | 125 | |
lakshya | 14:a9588f443f1a | 126 | |
Bragadeesh153 | 13:fb7facaf308b | 127 | //DigitalOut TRXY_SW_EN(PIN71); //TR XY Switch |
Bragadeesh153 | 13:fb7facaf308b | 128 | //DigitalOut DRV_Z_SLP(PIN88); //Sleep pin of driver z |
Bragadeesh153 | 13:fb7facaf308b | 129 | //DigitalOut TRZ_SW(PIN40); //TR Z Switch |
Bragadeesh153 | 13:fb7facaf308b | 130 | //DigitalOut CDMS_RESET(PIN7); // CDMS RESET |
Bragadeesh153 | 13:fb7facaf308b | 131 | //DigitalOut BCN_SW(PIN14); //Beacon switch |
Bragadeesh153 | 13:fb7facaf308b | 132 | //DigitalOut DRV_XY_SLP(PIN82); |
Bragadeesh153 | 13:fb7facaf308b | 133 | |
Bragadeesh153 | 13:fb7facaf308b | 134 | |
Bragadeesh153 | 13:fb7facaf308b | 135 | DigitalOut TRXY_SW(PIN71); //TR XY Switch |
Bragadeesh153 | 13:fb7facaf308b | 136 | DigitalOut DRV_Z_EN(PIN88); //Sleep pin of driver z |
sakthipriya | 5:bb592f3185cc | 137 | DigitalOut TRZ_SW(PIN40); //TR Z Switch |
prasanthbj05 | 17:8a8024c45dc0 | 138 | DigitalOut CDMS_RESET(PIN7,1); // CDMS RESET |
sakthipriya | 5:bb592f3185cc | 139 | DigitalOut BCN_SW(PIN14); //Beacon switch |
Bragadeesh153 | 13:fb7facaf308b | 140 | DigitalOut DRV_XY_EN(PIN82); |
sakthipriya | 0:7b4c00e3912f | 141 | |
sakthipriya | 0:7b4c00e3912f | 142 | /*****************************************************************Threads USed***********************************************************************************/ |
sakthipriya | 3:07e15677a75c | 143 | |
sakthipriya | 0:7b4c00e3912f | 144 | Thread *ptr_t_i2c; |
sakthipriya | 0:7b4c00e3912f | 145 | |
sakthipriya | 0:7b4c00e3912f | 146 | /*********************************************************FCTN HEADERS***********************************************************************************/ |
sakthipriya | 0:7b4c00e3912f | 147 | |
sakthipriya | 0:7b4c00e3912f | 148 | void FCTN_ISR_I2C(); |
sakthipriya | 0:7b4c00e3912f | 149 | void FCTN_TM(); |
sakthipriya | 3:07e15677a75c | 150 | void F_ACS(); |
sakthipriya | 3:07e15677a75c | 151 | void F_EPS(); |
sakthipriya | 3:07e15677a75c | 152 | void F_BCN(); |
sakthipriya | 0:7b4c00e3912f | 153 | |
sakthipriya | 0:7b4c00e3912f | 154 | //*******************************************ACS THREAD**************************************************// |
sakthipriya | 5:bb592f3185cc | 155 | uint8_t iterP1; |
sakthipriya | 5:bb592f3185cc | 156 | uint8_t iterP2; |
sakthipriya | 5:bb592f3185cc | 157 | uint8_t iterI1; |
sakthipriya | 5:bb592f3185cc | 158 | uint8_t iterI2; |
sakthipriya | 0:7b4c00e3912f | 159 | |
sakthipriya | 5:bb592f3185cc | 160 | |
sakthipriya | 3:07e15677a75c | 161 | void F_ACS() |
sakthipriya | 0:7b4c00e3912f | 162 | { |
sakthipriya | 8:82250e41da81 | 163 | |
sakthipriya | 9:194afacf7449 | 164 | |
sakthipriya | 8:82250e41da81 | 165 | //...................// |
sakthipriya | 8:82250e41da81 | 166 | |
sakthipriya | 5:bb592f3185cc | 167 | if(pf1check == 1) |
sakthipriya | 5:bb592f3185cc | 168 | { |
sakthipriya | 5:bb592f3185cc | 169 | if(iterP1 >= 3) |
sakthipriya | 5:bb592f3185cc | 170 | { |
sakthipriya | 9:194afacf7449 | 171 | ATS1_SW_ENABLE = 1; // turn off ats1 permanently |
sakthipriya | 5:bb592f3185cc | 172 | //FCTN_SWITCH_ATS(0); // switch on ATS2 |
sakthipriya | 5:bb592f3185cc | 173 | } |
sakthipriya | 5:bb592f3185cc | 174 | else |
sakthipriya | 5:bb592f3185cc | 175 | { |
sakthipriya | 9:194afacf7449 | 176 | ATS1_SW_ENABLE = 0; |
sakthipriya | 5:bb592f3185cc | 177 | iterP1++; |
sakthipriya | 5:bb592f3185cc | 178 | } |
sakthipriya | 9:194afacf7449 | 179 | pf1check = 0; |
sakthipriya | 5:bb592f3185cc | 180 | } |
sakthipriya | 5:bb592f3185cc | 181 | if(pf2check == 1) |
sakthipriya | 5:bb592f3185cc | 182 | { |
sakthipriya | 5:bb592f3185cc | 183 | if(iterP1 >= 3) |
sakthipriya | 5:bb592f3185cc | 184 | { |
sakthipriya | 9:194afacf7449 | 185 | ATS2_SW_ENABLE = 1; // turn off ats2 permanently |
Bragadeesh153 | 13:fb7facaf308b | 186 | ACS_DATA_ACQ_ENABLE = 0; |
Bragadeesh153 | 13:fb7facaf308b | 187 | ACS_STATE = 2 ; // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY |
sakthipriya | 5:bb592f3185cc | 188 | } |
sakthipriya | 5:bb592f3185cc | 189 | else |
sakthipriya | 5:bb592f3185cc | 190 | { |
sakthipriya | 9:194afacf7449 | 191 | ATS2_SW_ENABLE = 0; |
sakthipriya | 5:bb592f3185cc | 192 | iterP2++; |
sakthipriya | 5:bb592f3185cc | 193 | } |
sakthipriya | 9:194afacf7449 | 194 | pf2check = 0; |
sakthipriya | 5:bb592f3185cc | 195 | } |
sakthipriya | 5:bb592f3185cc | 196 | if(if1check == 1) |
sakthipriya | 5:bb592f3185cc | 197 | { |
sakthipriya | 5:bb592f3185cc | 198 | if(iterI1 >= 3) |
sakthipriya | 5:bb592f3185cc | 199 | { |
Bragadeesh153 | 13:fb7facaf308b | 200 | TRXY_SW = 0; // turn off TRXY permanently |
sakthipriya | 5:bb592f3185cc | 201 | } |
sakthipriya | 5:bb592f3185cc | 202 | else |
sakthipriya | 5:bb592f3185cc | 203 | { |
Bragadeesh153 | 13:fb7facaf308b | 204 | TRXY_SW = 1; //switch on TRXY |
sakthipriya | 5:bb592f3185cc | 205 | iterI1++; |
sakthipriya | 5:bb592f3185cc | 206 | } |
sakthipriya | 5:bb592f3185cc | 207 | } |
sakthipriya | 5:bb592f3185cc | 208 | if(if2check == 1) |
sakthipriya | 5:bb592f3185cc | 209 | { |
sakthipriya | 5:bb592f3185cc | 210 | if(iterI2 >= 3) |
sakthipriya | 5:bb592f3185cc | 211 | { |
sakthipriya | 5:bb592f3185cc | 212 | TRZ_SW = 0; // turn off TRZ permanently |
Bragadeesh153 | 13:fb7facaf308b | 213 | ACS_STATE = 2 ; // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY |
sakthipriya | 5:bb592f3185cc | 214 | } |
sakthipriya | 5:bb592f3185cc | 215 | else |
sakthipriya | 5:bb592f3185cc | 216 | { |
sakthipriya | 5:bb592f3185cc | 217 | TRZ_SW = 1; //switch on Z |
sakthipriya | 5:bb592f3185cc | 218 | iterI2++; |
sakthipriya | 5:bb592f3185cc | 219 | } |
sakthipriya | 5:bb592f3185cc | 220 | } |
sakthipriya | 5:bb592f3185cc | 221 | |
sakthipriya | 6:036d08b62785 | 222 | //float b1[3]={-23.376,-37.56,14.739}, omega1[3]={-1.52,2.746,0.7629}, moment1[3]= {1.0498,-1.0535,1.3246}; |
sakthipriya | 0:7b4c00e3912f | 223 | //b1[3] = {22, 22,10}; |
sakthipriya | 0:7b4c00e3912f | 224 | //omega1[3] = {2.1,3.0,1.5}; |
sakthipriya | 9:194afacf7449 | 225 | // ATS1_SW_ENABLE = 0; // att sens2 switch is disabled |
sakthipriya | 9:194afacf7449 | 226 | // ATS2_SW_ENABLE = 0; // att sens switch is disabled |
sakthipriya | 0:7b4c00e3912f | 227 | |
sakthipriya | 3:07e15677a75c | 228 | |
sakthipriya | 0:7b4c00e3912f | 229 | |
sakthipriya | 3:07e15677a75c | 230 | //Thread::signal_wait(0x1); |
sakthipriya | 9:194afacf7449 | 231 | ACS_MAIN_STATUS = 1; //set ACS_MAIN_STATUS flag |
sakthipriya | 0:7b4c00e3912f | 232 | PWM1 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 233 | PWM2 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 234 | PWM3 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 235 | pc.printf("\n\rEntered ACS %f\n",t_start.read()); |
sakthipriya | 0:7b4c00e3912f | 236 | |
sakthipriya | 9:194afacf7449 | 237 | if(ACS_DATA_ACQ_ENABLE == 1)// check if ACS_DATA_ACQ_ENABLE = 1? |
sakthipriya | 0:7b4c00e3912f | 238 | { |
Bragadeesh153 | 13:fb7facaf308b | 239 | //FLAG(); |
sakthipriya | 0:7b4c00e3912f | 240 | FCTN_ATS_DATA_ACQ(); //the angular velocity is stored in the first 3 values and magnetic field values in next 3 |
sakthipriya | 0:7b4c00e3912f | 241 | pc.printf("gyro values\n\r"); //printing the angular velocity and magnetic field values |
sakthipriya | 0:7b4c00e3912f | 242 | for(int i=0; i<3; i++) |
sakthipriya | 0:7b4c00e3912f | 243 | { |
lakshya | 15:e09aaaccf134 | 244 | printf("%f\n\r",actual_data.AngularSpeed_actual[i]); |
sakthipriya | 0:7b4c00e3912f | 245 | } |
sakthipriya | 0:7b4c00e3912f | 246 | pc.printf("mag values\n\r"); |
sakthipriya | 6:036d08b62785 | 247 | for(int i=0; i<3; i++) |
sakthipriya | 0:7b4c00e3912f | 248 | { |
sakthipriya | 6:036d08b62785 | 249 | pc.printf("%f\n\r",actual_data.Bvalue_actual[i]); |
sakthipriya | 5:bb592f3185cc | 250 | } |
sakthipriya | 6:036d08b62785 | 251 | // for(int i=0;i<3;i++) |
sakthipriya | 6:036d08b62785 | 252 | // { |
sakthipriya | 6:036d08b62785 | 253 | // omega1[i]= data[i]; |
sakthipriya | 6:036d08b62785 | 254 | // b1[i] = data[i+3]; |
sakthipriya | 6:036d08b62785 | 255 | // } |
sakthipriya | 0:7b4c00e3912f | 256 | }//if ACS_DATA_ACQ_ENABLE = 1 |
sakthipriya | 0:7b4c00e3912f | 257 | else |
sakthipriya | 0:7b4c00e3912f | 258 | { |
sakthipriya | 0:7b4c00e3912f | 259 | // Z axis actuation is the only final solution, |
sakthipriya | 0:7b4c00e3912f | 260 | } |
sakthipriya | 9:194afacf7449 | 261 | if(ACS_STATE == 0) // check ACS_STATE = ACS_CONTROL_OFF? |
sakthipriya | 0:7b4c00e3912f | 262 | { |
sakthipriya | 0:7b4c00e3912f | 263 | printf("\n\r acs control off\n"); |
sakthipriya | 0:7b4c00e3912f | 264 | FLAG(); |
sakthipriya | 9:194afacf7449 | 265 | ACS_STATUS = 0; // set ACS_STATUS = ACS_CONTROL_OFF |
sakthipriya | 0:7b4c00e3912f | 266 | PWM1 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 267 | PWM2 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 268 | PWM3 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 269 | } |
sakthipriya | 0:7b4c00e3912f | 270 | else |
sakthipriya | 0:7b4c00e3912f | 271 | { |
sakthipriya | 1:446a959e36ce | 272 | if(actual_data.power_mode>1) |
sakthipriya | 0:7b4c00e3912f | 273 | |
sakthipriya | 0:7b4c00e3912f | 274 | { |
sakthipriya | 9:194afacf7449 | 275 | if(ACS_STATE == 2) // check ACS_STATE = ACS_ZAXIS_MOMENT_ONLY |
sakthipriya | 0:7b4c00e3912f | 276 | { |
sakthipriya | 0:7b4c00e3912f | 277 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 278 | printf("\n\r z axis moment only\n"); |
sakthipriya | 9:194afacf7449 | 279 | ACS_STATUS = 2; // set ACS_STATUS = ACS_ZAXIS_MOMENT_ONLY |
sakthipriya | 0:7b4c00e3912f | 280 | // FCTN_ACS_CNTRLALGO(b1, omega1); |
sakthipriya | 0:7b4c00e3912f | 281 | moment[0] = 0; |
sakthipriya | 0:7b4c00e3912f | 282 | moment[1] = 0; |
sakthipriya | 0:7b4c00e3912f | 283 | moment[2] =1.3;// is a dummy value |
sakthipriya | 0:7b4c00e3912f | 284 | FCTN_ACS_GENPWM_MAIN(moment) ; |
sakthipriya | 0:7b4c00e3912f | 285 | } |
sakthipriya | 0:7b4c00e3912f | 286 | else |
sakthipriya | 0:7b4c00e3912f | 287 | { |
sakthipriya | 9:194afacf7449 | 288 | if(ACS_STATE == 3) // check ACS_STATE = ACS_DATA_ACQ_FAILURE |
sakthipriya | 0:7b4c00e3912f | 289 | { |
sakthipriya | 0:7b4c00e3912f | 290 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 291 | printf("\n\r acs data failure "); |
sakthipriya | 9:194afacf7449 | 292 | ACS_STATUS = 3; // set ACS_STATUS = ACS_DATA_ACQ_FAILURE |
sakthipriya | 0:7b4c00e3912f | 293 | PWM1 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 294 | PWM2 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 295 | PWM3 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 296 | } |
sakthipriya | 0:7b4c00e3912f | 297 | else |
sakthipriya | 0:7b4c00e3912f | 298 | { |
sakthipriya | 9:194afacf7449 | 299 | if(ACS_STATE == 4) // check ACS_STATE = ACS_NOMINAL_ONLY |
sakthipriya | 0:7b4c00e3912f | 300 | { |
sakthipriya | 0:7b4c00e3912f | 301 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 302 | printf("\n\r nominal"); |
sakthipriya | 9:194afacf7449 | 303 | ACS_STATUS = 4; // set ACS_STATUS = ACS_NOMINAL_ONLY |
sakthipriya | 6:036d08b62785 | 304 | FCTN_ACS_CNTRLALGO(actual_data.Bvalue_actual,actual_data.AngularSpeed_actual); |
sakthipriya | 0:7b4c00e3912f | 305 | printf("\n\r moment values returned by control algo \n"); |
sakthipriya | 0:7b4c00e3912f | 306 | for(int i=0; i<3; i++) |
sakthipriya | 0:7b4c00e3912f | 307 | { |
sakthipriya | 0:7b4c00e3912f | 308 | printf("%f\t",moment[i]); |
sakthipriya | 0:7b4c00e3912f | 309 | } |
sakthipriya | 0:7b4c00e3912f | 310 | FCTN_ACS_GENPWM_MAIN(moment) ; |
sakthipriya | 0:7b4c00e3912f | 311 | } |
sakthipriya | 0:7b4c00e3912f | 312 | else |
sakthipriya | 0:7b4c00e3912f | 313 | { |
sakthipriya | 9:194afacf7449 | 314 | if(ACS_STATE == 5) // check ACS_STATE = ACS_AUTO_CONTROL |
sakthipriya | 0:7b4c00e3912f | 315 | { |
sakthipriya | 0:7b4c00e3912f | 316 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 317 | printf("\n\r auto control"); |
sakthipriya | 9:194afacf7449 | 318 | ACS_STATUS = 5; // set ACS_STATUS = ACS_AUTO_CONTROL |
sakthipriya | 0:7b4c00e3912f | 319 | //FCTN_ACS_AUTOCTRL_LOGIC // gotta include this code |
sakthipriya | 0:7b4c00e3912f | 320 | } |
sakthipriya | 0:7b4c00e3912f | 321 | else |
sakthipriya | 0:7b4c00e3912f | 322 | { |
sakthipriya | 9:194afacf7449 | 323 | if(ACS_STATE == 6) // check ACS_STATE = ACS_DETUMBLING_ONLY |
sakthipriya | 0:7b4c00e3912f | 324 | { |
sakthipriya | 0:7b4c00e3912f | 325 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 326 | printf("\n\r Entered detumbling \n"); |
sakthipriya | 9:194afacf7449 | 327 | ACS_STATUS = 6; // set ACS_STATUS = ACS_DETUMBLING_ONLY |
sakthipriya | 6:036d08b62785 | 328 | FCTN_ACS_CNTRLALGO(actual_data.Bvalue_actual,actual_data.AngularSpeed_actual); // detumbling code has to be included |
sakthipriya | 0:7b4c00e3912f | 329 | FCTN_ACS_GENPWM_MAIN(moment) ; |
sakthipriya | 0:7b4c00e3912f | 330 | } |
sakthipriya | 0:7b4c00e3912f | 331 | else |
sakthipriya | 0:7b4c00e3912f | 332 | { |
sakthipriya | 0:7b4c00e3912f | 333 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 334 | printf("\n\r invalid state"); |
sakthipriya | 9:194afacf7449 | 335 | ACS_STATUS = 7 ; // set ACS_STATUS = INVALID STATE |
sakthipriya | 0:7b4c00e3912f | 336 | PWM1 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 337 | PWM2 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 338 | PWM3 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 339 | }//else of invalid |
sakthipriya | 0:7b4c00e3912f | 340 | }//else of autocontrol |
sakthipriya | 0:7b4c00e3912f | 341 | }//else of nominal |
sakthipriya | 0:7b4c00e3912f | 342 | }//else of data acg failure |
sakthipriya | 0:7b4c00e3912f | 343 | |
sakthipriya | 0:7b4c00e3912f | 344 | }//else fo z axis moment only |
sakthipriya | 0:7b4c00e3912f | 345 | }//if power >2 |
sakthipriya | 0:7b4c00e3912f | 346 | else |
sakthipriya | 0:7b4c00e3912f | 347 | { |
sakthipriya | 0:7b4c00e3912f | 348 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 349 | printf("\n\r low power"); |
sakthipriya | 9:194afacf7449 | 350 | ACS_STATUS = 1; // set ACS_STATUS = ACS_LOW_POWER |
sakthipriya | 0:7b4c00e3912f | 351 | PWM1 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 352 | PWM2 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 353 | PWM3 = 0; //clear pwm pins |
sakthipriya | 0:7b4c00e3912f | 354 | } |
sakthipriya | 0:7b4c00e3912f | 355 | } //else for acs control off |
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*******************************************************************// |
prasanthbj05 | 17:8a8024c45dc0 | 429 | /*void I2C_busreset(void) |
prasanthbj05 | 17:8a8024c45dc0 | 430 | { |
prasanthbj05 | 17:8a8024c45dc0 | 431 | uint8_t count=0; |
prasanthbj05 | 17:8a8024c45dc0 | 432 | if((PORTE->PCR[1] & PORT_PCR_MUX(6)) && (PORTE->PCR[0] & PORT_PCR_MUX(6))) |
prasanthbj05 | 17:8a8024c45dc0 | 433 | { |
prasanthbj05 | 17:8a8024c45dc0 | 434 | printf("\n\rResetting\n\r"); |
prasanthbj05 | 17:8a8024c45dc0 | 435 | I2C1->C1 &= 0x7f; // Disable I2C1 bus |
prasanthbj05 | 17:8a8024c45dc0 | 436 | PORTE->PCR[1] = PORT_PCR_MUX(1); // PTE1 Alt1 (pin) |
prasanthbj05 | 17:8a8024c45dc0 | 437 | PORTE->PCR[0] = PORT_PCR_MUX(1); // PTE0 Alt1 (pin) |
prasanthbj05 | 17:8a8024c45dc0 | 438 | while(((PTE->PDIR & 0x3) != 3) && (count<10)) // When PTE0 / PTE1 are not 1 : I2C1 bus lock-up |
prasanthbj05 | 17:8a8024c45dc0 | 439 | { |
prasanthbj05 | 17:8a8024c45dc0 | 440 | PTE->PDDR |= 0x3; // Set PTE1 and PTE0 as a GPIO output so we can bit bang it |
prasanthbj05 | 17:8a8024c45dc0 | 441 | PTE->PDOR |= 0x2; // Set PTE1 (SCL) pin high; |
prasanthbj05 | 17:8a8024c45dc0 | 442 | wait_ms(1); |
prasanthbj05 | 17:8a8024c45dc0 | 443 | PTE->PDOR |= 0x1; // Set PTE0 (SDA) pin high; |
prasanthbj05 | 17:8a8024c45dc0 | 444 | wait_ms(1); |
prasanthbj05 | 17:8a8024c45dc0 | 445 | count++; |
prasanthbj05 | 17:8a8024c45dc0 | 446 | wait(1); |
prasanthbj05 | 17:8a8024c45dc0 | 447 | } |
prasanthbj05 | 17:8a8024c45dc0 | 448 | // Reinstate I2C1 bus pins |
prasanthbj05 | 17:8a8024c45dc0 | 449 | PORTE->PCR[1] = PORT_PCR_MUX(6); // PTE1 Alt6 (SCL) |
prasanthbj05 | 17:8a8024c45dc0 | 450 | PORTE->PCR[0] = PORT_PCR_MUX(6); // PTE0 Alt6 (SDA) |
prasanthbj05 | 17:8a8024c45dc0 | 451 | I2C1->C1 |= 0x80; // Enable I2C1 bus |
prasanthbj05 | 17:8a8024c45dc0 | 452 | printf("Count: %d\n\r",count); |
prasanthbj05 | 17:8a8024c45dc0 | 453 | //wait(1); |
prasanthbj05 | 17:8a8024c45dc0 | 454 | } |
prasanthbj05 | 17:8a8024c45dc0 | 455 | |
prasanthbj05 | 17:8a8024c45dc0 | 456 | }*/ |
prasanthbj05 | 17:8a8024c45dc0 | 457 | #define PORT_PCR_MUX_MASK2 0x00000700u |
prasanthbj05 | 17:8a8024c45dc0 | 458 | void debug() |
prasanthbj05 | 17:8a8024c45dc0 | 459 | { |
prasanthbj05 | 17:8a8024c45dc0 | 460 | // uint32_t temp=0x0AF30000; |
prasanthbj05 | 17:8a8024c45dc0 | 461 | //printf("\n\rTemp = %08X",temp); |
prasanthbj05 | 17:8a8024c45dc0 | 462 | //pc.printf("\n\rPORTE->PCR[0] = 0x%08X",PORTE->PCR[0]); |
prasanthbj05 | 17:8a8024c45dc0 | 463 | //pc.printf("\n\rPORTE->PCR[1] = 0x%08X",PORTE->PCR[1]); |
prasanthbj05 | 17:8a8024c45dc0 | 464 | pc.printf("\n\rPTE->DIR = 0x%08X",PTE->PDIR); |
prasanthbj05 | 17:8a8024c45dc0 | 465 | } |
prasanthbj05 | 17:8a8024c45dc0 | 466 | void debug1() |
prasanthbj05 | 17:8a8024c45dc0 | 467 | { |
prasanthbj05 | 17:8a8024c45dc0 | 468 | printf("\n\r Before disabling"); |
prasanthbj05 | 17:8a8024c45dc0 | 469 | debug(); |
prasanthbj05 | 17:8a8024c45dc0 | 470 | //wait_ms(50); |
prasanthbj05 | 17:8a8024c45dc0 | 471 | I2C1->C1 &= 0x7f; |
prasanthbj05 | 17:8a8024c45dc0 | 472 | printf("\n\r After muxing "); |
prasanthbj05 | 17:8a8024c45dc0 | 473 | PORTE->PCR[1] = PORT_PCR_MUX(1); // PTE24 Alt1 (pin) |
prasanthbj05 | 17:8a8024c45dc0 | 474 | PORTE->PCR[0] = PORT_PCR_MUX(1); // PTE25 Alt1 (pin) |
prasanthbj05 | 17:8a8024c45dc0 | 475 | PTE->PDDR |= 0x3; // Set PTE1 and PTE0 as a GPIO output so we can bit bang it |
prasanthbj05 | 17:8a8024c45dc0 | 476 | PTE->PDOR |= 0x2; // Set PTE1 (SCL) pin high; |
prasanthbj05 | 17:8a8024c45dc0 | 477 | wait_ms(1); |
prasanthbj05 | 17:8a8024c45dc0 | 478 | PTE->PDOR |= 0x1; // Set PTE0 (SDA) pin high; |
prasanthbj05 | 17:8a8024c45dc0 | 479 | wait_ms(1); |
prasanthbj05 | 17:8a8024c45dc0 | 480 | debug(); |
prasanthbj05 | 17:8a8024c45dc0 | 481 | PORTE->PCR[1] &= (~(PORT_PCR_MUX_MASK2)); |
prasanthbj05 | 17:8a8024c45dc0 | 482 | PORTE->PCR[0] &= (~(PORT_PCR_MUX_MASK2)); |
prasanthbj05 | 17:8a8024c45dc0 | 483 | PORTE->PCR[1] |= PORT_PCR_MUX(6); // PTE24 Alt6 (pin) |
prasanthbj05 | 17:8a8024c45dc0 | 484 | PORTE->PCR[0] |= PORT_PCR_MUX(6); // PTE25 Alt6 (pin) |
prasanthbj05 | 17:8a8024c45dc0 | 485 | PORTE->PCR[1] |= 0x00000004; |
prasanthbj05 | 17:8a8024c45dc0 | 486 | PORTE->PCR[0] |= 0x00000004; |
prasanthbj05 | 17:8a8024c45dc0 | 487 | I2C1->C1 |= 0x80; // Enable I2C1 bus |
prasanthbj05 | 17:8a8024c45dc0 | 488 | printf("\n\r After enabling I2C"); |
prasanthbj05 | 17:8a8024c45dc0 | 489 | debug(); |
prasanthbj05 | 17:8a8024c45dc0 | 490 | } |
prasanthbj05 | 17:8a8024c45dc0 | 491 | void debug2() |
prasanthbj05 | 17:8a8024c45dc0 | 492 | { |
prasanthbj05 | 17:8a8024c45dc0 | 493 | printf("\n\rI2C1->A1 = 0x%02X",I2C1->A1); |
prasanthbj05 | 17:8a8024c45dc0 | 494 | printf("\n\rI2C1->F = 0x%02X",I2C1->F); |
prasanthbj05 | 17:8a8024c45dc0 | 495 | printf("\n\rI2C1->C1 = 0x%02X",I2C1->C1); |
prasanthbj05 | 17:8a8024c45dc0 | 496 | printf("\n\rI2C1->S = 0x%02X",I2C1->S); |
prasanthbj05 | 17:8a8024c45dc0 | 497 | printf("\n\rI2C1->D = 0x%02X",I2C1->D); |
prasanthbj05 | 17:8a8024c45dc0 | 498 | printf("\n\rI2C1->C2 = 0x%02X",I2C1->C2); |
prasanthbj05 | 17:8a8024c45dc0 | 499 | printf("\n\rI2C1->FLT = 0x%02X",I2C1->FLT); |
prasanthbj05 | 17:8a8024c45dc0 | 500 | printf("\n\rI2C1->RA = 0x%02X",I2C1->RA); |
prasanthbj05 | 17:8a8024c45dc0 | 501 | printf("\n\rI2C1->SMB = 0x%02X",I2C1->SMB); |
prasanthbj05 | 17:8a8024c45dc0 | 502 | printf("\n\rI2C1->A2 = 0x%02X",I2C1->A2); |
prasanthbj05 | 17:8a8024c45dc0 | 503 | printf("\n\rI2C1->SLTH = 0x%02X",I2C1->SLTH); |
prasanthbj05 | 17:8a8024c45dc0 | 504 | printf("\n\rI2C1->SLTL = 0x%02X\n",I2C1->SLTL); |
prasanthbj05 | 17:8a8024c45dc0 | 505 | } |
sakthipriya | 0:7b4c00e3912f | 506 | |
prasanthbj05 | 17:8a8024c45dc0 | 507 | void debug3() |
prasanthbj05 | 17:8a8024c45dc0 | 508 | { |
prasanthbj05 | 17:8a8024c45dc0 | 509 | //pc.printf("\n\r Resetting I2C"); |
prasanthbj05 | 17:8a8024c45dc0 | 510 | //debug2(); |
prasanthbj05 | 17:8a8024c45dc0 | 511 | //printf("\n\r SIM->SCGC4 = 0x%08X",SIM->SCGC4); |
prasanthbj05 | 17:8a8024c45dc0 | 512 | PORTE->PCR[1] &= 0xfffffffb; |
prasanthbj05 | 17:8a8024c45dc0 | 513 | PORTE->PCR[0] &= 0xfffffffb; |
prasanthbj05 | 17:8a8024c45dc0 | 514 | I2C1->C1 &= 0x7f; |
prasanthbj05 | 17:8a8024c45dc0 | 515 | //wait_ms(2); |
prasanthbj05 | 17:8a8024c45dc0 | 516 | SIM->SCGC4 &= 0xffffff7f; |
prasanthbj05 | 17:8a8024c45dc0 | 517 | //printf("\n\r SIM->SCGC4 = 0x%08X",SIM->SCGC4); |
prasanthbj05 | 17:8a8024c45dc0 | 518 | //wait_ms(10); |
prasanthbj05 | 17:8a8024c45dc0 | 519 | SIM->SCGC4 |= 0x00000080; |
prasanthbj05 | 17:8a8024c45dc0 | 520 | //printf("\n\r SIM->SCGC4 = 0x%08X",SIM->SCGC4); |
prasanthbj05 | 17:8a8024c45dc0 | 521 | //wait_ms(10); |
prasanthbj05 | 17:8a8024c45dc0 | 522 | I2C1->C1 |= 0x80; |
prasanthbj05 | 17:8a8024c45dc0 | 523 | PORTE->PCR[1] |= 0x00000004; |
prasanthbj05 | 17:8a8024c45dc0 | 524 | PORTE->PCR[0] |= 0x00000004; |
prasanthbj05 | 17:8a8024c45dc0 | 525 | //wait_ms(10); |
prasanthbj05 | 17:8a8024c45dc0 | 526 | wait_ms(2); |
prasanthbj05 | 17:8a8024c45dc0 | 527 | //printf("\n\r After enabling clock"); |
prasanthbj05 | 17:8a8024c45dc0 | 528 | //debug2(); |
prasanthbj05 | 17:8a8024c45dc0 | 529 | //printf("\n"); |
prasanthbj05 | 17:8a8024c45dc0 | 530 | } |
prasanthbj05 | 17:8a8024c45dc0 | 531 | void I2C_busreset() |
prasanthbj05 | 17:8a8024c45dc0 | 532 | { |
prasanthbj05 | 17:8a8024c45dc0 | 533 | //Thread::wait(1); |
prasanthbj05 | 17:8a8024c45dc0 | 534 | PORTE->PCR[1] &= 0xfffffffb; |
prasanthbj05 | 17:8a8024c45dc0 | 535 | //Thread::wait(1); |
prasanthbj05 | 17:8a8024c45dc0 | 536 | PORTE->PCR[0] &= 0xfffffffb; |
prasanthbj05 | 17:8a8024c45dc0 | 537 | //Thread::wait(1); |
prasanthbj05 | 17:8a8024c45dc0 | 538 | I2C1->C1 &= 0x7f; |
prasanthbj05 | 17:8a8024c45dc0 | 539 | //Thread::wait(1); |
prasanthbj05 | 17:8a8024c45dc0 | 540 | SIM->SCGC4 &= 0xffffff7f; |
prasanthbj05 | 17:8a8024c45dc0 | 541 | //Thread::wait(1); |
prasanthbj05 | 17:8a8024c45dc0 | 542 | SIM->SCGC4 |= 0x00000080; |
prasanthbj05 | 17:8a8024c45dc0 | 543 | //Thread::wait(1); |
prasanthbj05 | 17:8a8024c45dc0 | 544 | I2C1->C1 |= 0x80; |
prasanthbj05 | 17:8a8024c45dc0 | 545 | //Thread::wait(1); |
prasanthbj05 | 17:8a8024c45dc0 | 546 | PORTE->PCR[1] |= 0x00000004; |
prasanthbj05 | 17:8a8024c45dc0 | 547 | //Thread::wait(1); |
prasanthbj05 | 17:8a8024c45dc0 | 548 | PORTE->PCR[0] |= 0x00000004; |
prasanthbj05 | 17:8a8024c45dc0 | 549 | Thread::wait(1); |
prasanthbj05 | 17:8a8024c45dc0 | 550 | } |
prasanthbj05 | 17:8a8024c45dc0 | 551 | uint32_t pdirtc1,pdirtc2,pdirtm1,pdirtm2,pdirss1,pdirss2; |
sakthipriya | 0:7b4c00e3912f | 552 | void T_TC(void const * args) |
sakthipriya | 0:7b4c00e3912f | 553 | { |
sakthipriya | 0:7b4c00e3912f | 554 | while(1) |
prasanthbj05 | 17:8a8024c45dc0 | 555 | { |
prasanthbj05 | 17:8a8024c45dc0 | 556 | //pc.printf("\n\n\rWaiting"); |
sakthipriya | 0:7b4c00e3912f | 557 | Thread::signal_wait(0x4); |
prasanthbj05 | 17:8a8024c45dc0 | 558 | wait_us(300); // can be between 38 to 15700 |
sakthipriya | 0:7b4c00e3912f | 559 | if( slave.receive() == 0) |
prasanthbj05 | 17:8a8024c45dc0 | 560 | { |
prasanthbj05 | 17:8a8024c45dc0 | 561 | //synch.stop(); |
prasanthbj05 | 17:8a8024c45dc0 | 562 | //pdirss1=PTE->PDIR; |
prasanthbj05 | 17:8a8024c45dc0 | 563 | irpt_2_mstr = 0; |
prasanthbj05 | 17:8a8024c45dc0 | 564 | data_send_flag = 'h'; |
prasanthbj05 | 17:8a8024c45dc0 | 565 | #if PRINT |
prasanthbj05 | 17:8a8024c45dc0 | 566 | pc.printf("\n\rSlave stop"); |
prasanthbj05 | 17:8a8024c45dc0 | 567 | pc.printf("\n\rPTE->DIR = 0x%08X",pdirss1); |
prasanthbj05 | 17:8a8024c45dc0 | 568 | #endif |
prasanthbj05 | 17:8a8024c45dc0 | 569 | slave.stop(); |
prasanthbj05 | 17:8a8024c45dc0 | 570 | I2C_busreset(); |
prasanthbj05 | 17:8a8024c45dc0 | 571 | pdirss2=PTE->PDIR; |
prasanthbj05 | 17:8a8024c45dc0 | 572 | #if PRINT |
prasanthbj05 | 17:8a8024c45dc0 | 573 | pc.printf("\n\rPTE->DIR = 0x%08X",pdirss2); |
prasanthbj05 | 17:8a8024c45dc0 | 574 | #endif |
prasanthbj05 | 17:8a8024c45dc0 | 575 | //pc.printf("\n\rPTE->DIR = 0x%08X",pdir2); |
prasanthbj05 | 17:8a8024c45dc0 | 576 | } |
prasanthbj05 | 17:8a8024c45dc0 | 577 | else if( slave.receive() == 1) // slave writes to master |
sakthipriya | 0:7b4c00e3912f | 578 | { |
sakthipriya | 5:bb592f3185cc | 579 | if(data_send_flag == 'h') |
sakthipriya | 6:036d08b62785 | 580 | { |
sakthipriya | 6:036d08b62785 | 581 | //FCTN_APPEND_HKDATA(); |
sakthipriya | 6:036d08b62785 | 582 | // pc.printf("\n\r here"); |
prasanthbj05 | 17:8a8024c45dc0 | 583 | write_ack=slave.write(BAE_chardata,74); |
prasanthbj05 | 17:8a8024c45dc0 | 584 | irpt_2_mstr = 0; |
Bragadeesh153 | 13:fb7facaf308b | 585 | if(write_ack==0) |
prasanthbj05 | 17:8a8024c45dc0 | 586 | { |
prasanthbj05 | 17:8a8024c45dc0 | 587 | irpt_2_mstr = 0; |
prasanthbj05 | 17:8a8024c45dc0 | 588 | pc.printf("\n\rgot interrupt\n"); |
prasanthbj05 | 17:8a8024c45dc0 | 589 | } |
sakthipriya | 6:036d08b62785 | 590 | } |
sakthipriya | 5:bb592f3185cc | 591 | else if(data_send_flag == 't') |
sakthipriya | 5:bb592f3185cc | 592 | { |
prasanthbj05 | 17:8a8024c45dc0 | 593 | uint8_t i2c_count =0; |
prasanthbj05 | 17:8a8024c45dc0 | 594 | write_ack=slave.write((char*)telemetry,135); |
prasanthbj05 | 17:8a8024c45dc0 | 595 | Thread::wait(1); |
prasanthbj05 | 17:8a8024c45dc0 | 596 | pdirtm1=PTE->PDIR; |
prasanthbj05 | 17:8a8024c45dc0 | 597 | irpt_2_mstr = 0; |
prasanthbj05 | 17:8a8024c45dc0 | 598 | //data_send_flag = 'h'; |
prasanthbj05 | 17:8a8024c45dc0 | 599 | if(write_ack==0) |
prasanthbj05 | 17:8a8024c45dc0 | 600 | { |
prasanthbj05 | 17:8a8024c45dc0 | 601 | while(((pdirtm1 & 0x00000003)!=3)&& i2c_count<10) |
prasanthbj05 | 17:8a8024c45dc0 | 602 | { |
prasanthbj05 | 17:8a8024c45dc0 | 603 | Thread::wait(1); |
prasanthbj05 | 17:8a8024c45dc0 | 604 | pdirtm1=PTE->PDIR; |
prasanthbj05 | 17:8a8024c45dc0 | 605 | i2c_count++; |
prasanthbj05 | 17:8a8024c45dc0 | 606 | } |
prasanthbj05 | 17:8a8024c45dc0 | 607 | if(((pdirtm1 & 0x00000003)==3)) |
prasanthbj05 | 17:8a8024c45dc0 | 608 | { |
prasanthbj05 | 17:8a8024c45dc0 | 609 | pc.printf("\n\rWrite TM success"); |
prasanthbj05 | 17:8a8024c45dc0 | 610 | //pc.printf("\n\rPTE->DIR = 0x%08X",PTE->PDIR); |
prasanthbj05 | 17:8a8024c45dc0 | 611 | } |
prasanthbj05 | 17:8a8024c45dc0 | 612 | else |
prasanthbj05 | 17:8a8024c45dc0 | 613 | { |
prasanthbj05 | 17:8a8024c45dc0 | 614 | //Resetting should be done here |
prasanthbj05 | 17:8a8024c45dc0 | 615 | |
prasanthbj05 | 17:8a8024c45dc0 | 616 | #if PRINT |
prasanthbj05 | 17:8a8024c45dc0 | 617 | pc.printf("\n\rWrite TM error"); |
prasanthbj05 | 17:8a8024c45dc0 | 618 | pc.printf("\n\rPTE->DIR = 0x%08X",pdirtm1); |
prasanthbj05 | 17:8a8024c45dc0 | 619 | #endif |
prasanthbj05 | 17:8a8024c45dc0 | 620 | I2C_busreset(); |
prasanthbj05 | 17:8a8024c45dc0 | 621 | pdirtm2=PTE->PDIR; |
prasanthbj05 | 17:8a8024c45dc0 | 622 | #if PRINT |
prasanthbj05 | 17:8a8024c45dc0 | 623 | pc.printf("\n\rPTE->DIR = 0x%08X",pdirtm2); |
prasanthbj05 | 17:8a8024c45dc0 | 624 | #endif |
prasanthbj05 | 17:8a8024c45dc0 | 625 | } |
prasanthbj05 | 17:8a8024c45dc0 | 626 | //pc.printf("\n\rTM count:%d",i2c_count); |
prasanthbj05 | 17:8a8024c45dc0 | 627 | } |
prasanthbj05 | 17:8a8024c45dc0 | 628 | else |
prasanthbj05 | 17:8a8024c45dc0 | 629 | { |
prasanthbj05 | 17:8a8024c45dc0 | 630 | //Thread::wait(30); |
prasanthbj05 | 17:8a8024c45dc0 | 631 | #if PRINT |
prasanthbj05 | 17:8a8024c45dc0 | 632 | pc.printf("\nTM ack failed"); |
prasanthbj05 | 17:8a8024c45dc0 | 633 | pc.printf("\n\rPTE->DIR = 0x%08X",pdirtm1); |
prasanthbj05 | 17:8a8024c45dc0 | 634 | #endif |
prasanthbj05 | 17:8a8024c45dc0 | 635 | I2C_busreset(); |
prasanthbj05 | 17:8a8024c45dc0 | 636 | pdirtm2=PTE->PDIR; |
prasanthbj05 | 17:8a8024c45dc0 | 637 | #if PRINT |
prasanthbj05 | 17:8a8024c45dc0 | 638 | pc.printf("\n\rPTE->DIR = 0x%08X",pdirtm2); |
prasanthbj05 | 17:8a8024c45dc0 | 639 | #endif |
prasanthbj05 | 17:8a8024c45dc0 | 640 | //Thread::wait(10); |
prasanthbj05 | 17:8a8024c45dc0 | 641 | //pc.printf("\n\rPTE->DIR = 0x%08X",PTE->PDIR); |
prasanthbj05 | 17:8a8024c45dc0 | 642 | //debug3(); |
prasanthbj05 | 17:8a8024c45dc0 | 643 | //wait_ms(10); |
prasanthbj05 | 17:8a8024c45dc0 | 644 | //pc.printf("\n\rPTE->DIR = 0x%08X",PTE->PDIR); |
prasanthbj05 | 17:8a8024c45dc0 | 645 | } |
prasanthbj05 | 17:8a8024c45dc0 | 646 | i2c_count=0; |
prasanthbj05 | 17:8a8024c45dc0 | 647 | } |
prasanthbj05 | 17:8a8024c45dc0 | 648 | else if(data_send_flag == 'i') |
prasanthbj05 | 17:8a8024c45dc0 | 649 | { |
prasanthbj05 | 17:8a8024c45dc0 | 650 | //to be filled |
prasanthbj05 | 17:8a8024c45dc0 | 651 | data_send_flag = 'h'; |
prasanthbj05 | 17:8a8024c45dc0 | 652 | } |
sakthipriya | 0:7b4c00e3912f | 653 | } |
sakthipriya | 0:7b4c00e3912f | 654 | else if( slave.receive()==3 || slave.receive()==2) // slave read |
sakthipriya | 0:7b4c00e3912f | 655 | { |
prasanthbj05 | 17:8a8024c45dc0 | 656 | uint8_t i2c_count = 0; |
prasanthbj05 | 17:8a8024c45dc0 | 657 | synch.stop(); |
prasanthbj05 | 17:8a8024c45dc0 | 658 | read_ack=slave.read((char *)telecommand,11); |
prasanthbj05 | 17:8a8024c45dc0 | 659 | Thread::wait(1); |
prasanthbj05 | 17:8a8024c45dc0 | 660 | pdirtc1=PTE->PDIR; |
prasanthbj05 | 17:8a8024c45dc0 | 661 | irpt_2_mstr = 1; |
prasanthbj05 | 17:8a8024c45dc0 | 662 | data_send_flag = 't'; |
prasanthbj05 | 17:8a8024c45dc0 | 663 | if(read_ack==0) |
prasanthbj05 | 17:8a8024c45dc0 | 664 | { |
prasanthbj05 | 17:8a8024c45dc0 | 665 | while(((pdirtc1 & 0x00000003)!=3)&& i2c_count<10) |
prasanthbj05 | 17:8a8024c45dc0 | 666 | { |
prasanthbj05 | 17:8a8024c45dc0 | 667 | Thread::wait(1); |
prasanthbj05 | 17:8a8024c45dc0 | 668 | pdirtc1=PTE->PDIR; |
prasanthbj05 | 17:8a8024c45dc0 | 669 | i2c_count++; |
prasanthbj05 | 17:8a8024c45dc0 | 670 | } |
prasanthbj05 | 17:8a8024c45dc0 | 671 | if(((pdirtc1 & 0x00000003)==3)) |
prasanthbj05 | 17:8a8024c45dc0 | 672 | { |
prasanthbj05 | 17:8a8024c45dc0 | 673 | pc.printf("\n\n\rRead TC success"); |
prasanthbj05 | 17:8a8024c45dc0 | 674 | |
prasanthbj05 | 17:8a8024c45dc0 | 675 | // FCTN_TC_DECODE((uint8_t*) telecommand); |
prasanthbj05 | 17:8a8024c45dc0 | 676 | //FCTN_BAE_TM_TC((uint8_t*) telecommand); |
prasanthbj05 | 17:8a8024c45dc0 | 677 | //telemetry = (char*)temp; |
prasanthbj05 | 17:8a8024c45dc0 | 678 | //FCTN_TM(); |
prasanthbj05 | 17:8a8024c45dc0 | 679 | |
prasanthbj05 | 17:8a8024c45dc0 | 680 | //uint8_t read_ack2 = (uint8_t)(PTE->PDIR & 0x00000003); |
prasanthbj05 | 17:8a8024c45dc0 | 681 | //printf("\n\rread_ack2 = %d",read_ack2); |
prasanthbj05 | 17:8a8024c45dc0 | 682 | //if((read_ack ==0)&&(read_ack2==3)) |
prasanthbj05 | 17:8a8024c45dc0 | 683 | //if(read_ack==0 && ((PTE->PDIR & 0x00000003)==3)) |
prasanthbj05 | 17:8a8024c45dc0 | 684 | //debug2(); |
prasanthbj05 | 17:8a8024c45dc0 | 685 | //pc.printf("\n\rPTE->DIR = 0x%08X",PTE->PDIR); |
prasanthbj05 | 17:8a8024c45dc0 | 686 | //wait_us(10); |
prasanthbj05 | 17:8a8024c45dc0 | 687 | //read_ack2 = (uint8_t)(PTE->PDIR & 0x00000003); |
prasanthbj05 | 17:8a8024c45dc0 | 688 | //tempt.stop(); |
prasanthbj05 | 17:8a8024c45dc0 | 689 | //data_send_flag = 't'; //uncomment later |
prasanthbj05 | 17:8a8024c45dc0 | 690 | } |
prasanthbj05 | 17:8a8024c45dc0 | 691 | else |
prasanthbj05 | 17:8a8024c45dc0 | 692 | { |
prasanthbj05 | 17:8a8024c45dc0 | 693 | #if PRINT |
prasanthbj05 | 17:8a8024c45dc0 | 694 | pc.printf("\n\n\rRead TC error"); |
prasanthbj05 | 17:8a8024c45dc0 | 695 | pc.printf("\n\rPTE->DIR = 0x%08X",pdirtc1); |
prasanthbj05 | 17:8a8024c45dc0 | 696 | #endif |
prasanthbj05 | 17:8a8024c45dc0 | 697 | I2C_busreset(); |
prasanthbj05 | 17:8a8024c45dc0 | 698 | pdirtc2=PTE->PDIR; |
prasanthbj05 | 17:8a8024c45dc0 | 699 | #if PRINT |
prasanthbj05 | 17:8a8024c45dc0 | 700 | pc.printf("\n\rPTE->DIR = 0x%08X",pdirtc2); |
prasanthbj05 | 17:8a8024c45dc0 | 701 | #endif |
prasanthbj05 | 17:8a8024c45dc0 | 702 | //pc.printf("\n\rPTE->DIR = 0x%08X",PTE->PDIR); |
prasanthbj05 | 17:8a8024c45dc0 | 703 | //debug3(); |
prasanthbj05 | 17:8a8024c45dc0 | 704 | //printf("\n\rread_ack2 = %d and time = %d",read_ack2,tempt.read_us()); |
prasanthbj05 | 17:8a8024c45dc0 | 705 | //data_send_flag = 'i'; |
prasanthbj05 | 17:8a8024c45dc0 | 706 | } |
prasanthbj05 | 17:8a8024c45dc0 | 707 | //pc.printf("\n\rTC count:%d",i2c_count); |
prasanthbj05 | 17:8a8024c45dc0 | 708 | } |
prasanthbj05 | 17:8a8024c45dc0 | 709 | else |
prasanthbj05 | 17:8a8024c45dc0 | 710 | { |
prasanthbj05 | 17:8a8024c45dc0 | 711 | #if PRINT |
prasanthbj05 | 17:8a8024c45dc0 | 712 | pc.printf("\n\n\rTC ack failed"); |
prasanthbj05 | 17:8a8024c45dc0 | 713 | pc.printf("\n\rPTE->DIR = 0x%08X",pdirtc1); |
prasanthbj05 | 17:8a8024c45dc0 | 714 | #endif |
prasanthbj05 | 17:8a8024c45dc0 | 715 | I2C_busreset(); |
prasanthbj05 | 17:8a8024c45dc0 | 716 | pdirtc2=PTE->PDIR; |
prasanthbj05 | 17:8a8024c45dc0 | 717 | #if PRINT |
prasanthbj05 | 17:8a8024c45dc0 | 718 | pc.printf("\n\rPTE->DIR = 0x%08X",pdirtc2); |
prasanthbj05 | 17:8a8024c45dc0 | 719 | #endif |
prasanthbj05 | 17:8a8024c45dc0 | 720 | //pc.printf("\n\rPTE->DIR = 0x%08X",PTE->PDIR); |
prasanthbj05 | 17:8a8024c45dc0 | 721 | } |
prasanthbj05 | 17:8a8024c45dc0 | 722 | i2c_count = 0; |
prasanthbj05 | 17:8a8024c45dc0 | 723 | //printf("\n\rSize of data : %d",sizeof(telecommand)); |
prasanthbj05 | 17:8a8024c45dc0 | 724 | //printf("\n\rGiven Size : %d\n",11); |
prasanthbj05 | 17:8a8024c45dc0 | 725 | //printf("\n\rREAD_ACK : %d",read_ack); |
prasanthbj05 | 17:8a8024c45dc0 | 726 | //t_tc.start(); |
prasanthbj05 | 17:8a8024c45dc0 | 727 | //pc.printf("\n\rTELECOMMAND received from CDMS is %s \n",telecommand); |
prasanthbj05 | 17:8a8024c45dc0 | 728 | //pc.printf("\n\r Executing Telecommand \n"); |
prasanthbj05 | 17:8a8024c45dc0 | 729 | |
prasanthbj05 | 17:8a8024c45dc0 | 730 | //t_tc.stop(); |
prasanthbj05 | 17:8a8024c45dc0 | 731 | //printf("\n\r time taken %d",t_tc.read_us()); |
prasanthbj05 | 17:8a8024c45dc0 | 732 | //t_tc.reset(); |
sakthipriya | 3:07e15677a75c | 733 | // for(int i = 0; i<134; i++) |
sakthipriya | 3:07e15677a75c | 734 | //pc.printf("%c", telemetry[i]); |
prasanthbj05 | 17:8a8024c45dc0 | 735 | } |
prasanthbj05 | 17:8a8024c45dc0 | 736 | //pc.printf("Time after slave.read() = %d",synch.read_us()); |
prasanthbj05 | 17:8a8024c45dc0 | 737 | //synch.reset(); |
prasanthbj05 | 17:8a8024c45dc0 | 738 | } |
sakthipriya | 0:7b4c00e3912f | 739 | } |
sakthipriya | 0:7b4c00e3912f | 740 | void FCTN_TM() |
sakthipriya | 0:7b4c00e3912f | 741 | { |
sakthipriya | 4:39a4ae8c7ecd | 742 | //irpt_2_mstr = 0; |
sakthipriya | 5:bb592f3185cc | 743 | data_send_flag = 't'; |
sakthipriya | 0:7b4c00e3912f | 744 | pc.printf("\n\r Telemetry Generation \n"); |
sakthipriya | 0:7b4c00e3912f | 745 | irpt_2_mstr = 1; |
sakthipriya | 0:7b4c00e3912f | 746 | } |
sakthipriya | 0:7b4c00e3912f | 747 | |
sakthipriya | 0:7b4c00e3912f | 748 | |
sakthipriya | 0:7b4c00e3912f | 749 | //******************************************************* I2C *******************************************************************// |
sakthipriya | 0:7b4c00e3912f | 750 | |
sakthipriya | 0:7b4c00e3912f | 751 | void FCTN_I2C_ISR() |
sakthipriya | 0:7b4c00e3912f | 752 | { |
prasanthbj05 | 17:8a8024c45dc0 | 753 | //synch.start(); |
sakthipriya | 0:7b4c00e3912f | 754 | ptr_t_i2c->signal_set(0x4); |
sakthipriya | 0:7b4c00e3912f | 755 | } |
sakthipriya | 0:7b4c00e3912f | 756 | |
sakthipriya | 0:7b4c00e3912f | 757 | |
sakthipriya | 5:bb592f3185cc | 758 | //***********************************************************FAULTS***************************************************************// |
sakthipriya | 5:bb592f3185cc | 759 | /*void ir1clear() |
sakthipriya | 5:bb592f3185cc | 760 | { |
sakthipriya | 5:bb592f3185cc | 761 | actual_data.faultIr_status |= 0x01; // alert |
sakthipriya | 5:bb592f3185cc | 762 | |
sakthipriya | 5:bb592f3185cc | 763 | }*/ |
sakthipriya | 5:bb592f3185cc | 764 | |
sakthipriya | 5:bb592f3185cc | 765 | |
sakthipriya | 5:bb592f3185cc | 766 | |
sakthipriya | 5:bb592f3185cc | 767 | void ir2clear() |
sakthipriya | 5:bb592f3185cc | 768 | { |
sakthipriya | 5:bb592f3185cc | 769 | actual_data.faultIr_status |= 0x02; |
Bragadeesh153 | 13:fb7facaf308b | 770 | TRXY_SW = 0; // Switch off TR XY |
sakthipriya | 5:bb592f3185cc | 771 | if1check = 1; |
sakthipriya | 5:bb592f3185cc | 772 | } |
sakthipriya | 5:bb592f3185cc | 773 | |
sakthipriya | 5:bb592f3185cc | 774 | void ir3clear() |
sakthipriya | 5:bb592f3185cc | 775 | { |
sakthipriya | 5:bb592f3185cc | 776 | actual_data.faultIr_status |= 0x04; |
Bragadeesh153 | 13:fb7facaf308b | 777 | DRV_Z_EN = 0; |
sakthipriya | 5:bb592f3185cc | 778 | wait_us(1); |
Bragadeesh153 | 13:fb7facaf308b | 779 | DRV_Z_EN = 1; |
sakthipriya | 5:bb592f3185cc | 780 | |
sakthipriya | 5:bb592f3185cc | 781 | } |
sakthipriya | 5:bb592f3185cc | 782 | |
sakthipriya | 5:bb592f3185cc | 783 | void ir4clear() |
sakthipriya | 5:bb592f3185cc | 784 | { |
sakthipriya | 5:bb592f3185cc | 785 | if2check = 1; |
sakthipriya | 5:bb592f3185cc | 786 | actual_data.faultIr_status |= 0x08; |
sakthipriya | 5:bb592f3185cc | 787 | TRZ_SW = 0; |
sakthipriya | 5:bb592f3185cc | 788 | } |
sakthipriya | 5:bb592f3185cc | 789 | |
sakthipriya | 5:bb592f3185cc | 790 | void ir5clear() |
sakthipriya | 5:bb592f3185cc | 791 | { |
sakthipriya | 5:bb592f3185cc | 792 | actual_data.faultIr_status |= 0x10; |
sakthipriya | 5:bb592f3185cc | 793 | CDMS_RESET = 0; |
sakthipriya | 5:bb592f3185cc | 794 | wait_us(1); |
sakthipriya | 5:bb592f3185cc | 795 | CDMS_RESET = 1; |
sakthipriya | 5:bb592f3185cc | 796 | } |
sakthipriya | 5:bb592f3185cc | 797 | |
sakthipriya | 5:bb592f3185cc | 798 | void ir6clear() |
sakthipriya | 5:bb592f3185cc | 799 | { |
sakthipriya | 5:bb592f3185cc | 800 | actual_data.faultIr_status |= 0x20; |
sakthipriya | 5:bb592f3185cc | 801 | BCN_SW = 0; |
sakthipriya | 5:bb592f3185cc | 802 | wait_us(1); |
sakthipriya | 5:bb592f3185cc | 803 | BCN_SW = 1; |
sakthipriya | 5:bb592f3185cc | 804 | } |
sakthipriya | 5:bb592f3185cc | 805 | |
sakthipriya | 5:bb592f3185cc | 806 | void ir7clear() |
sakthipriya | 5:bb592f3185cc | 807 | { |
sakthipriya | 5:bb592f3185cc | 808 | actual_data.faultIr_status |= 0x40; |
sakthipriya | 5:bb592f3185cc | 809 | } |
sakthipriya | 5:bb592f3185cc | 810 | uint8_t iter2=0,iter4 = 0; |
sakthipriya | 5:bb592f3185cc | 811 | |
sakthipriya | 5:bb592f3185cc | 812 | |
sakthipriya | 5:bb592f3185cc | 813 | |
sakthipriya | 5:bb592f3185cc | 814 | void pollfault() |
sakthipriya | 5:bb592f3185cc | 815 | { |
sakthipriya | 5:bb592f3185cc | 816 | |
sakthipriya | 5:bb592f3185cc | 817 | |
sakthipriya | 5:bb592f3185cc | 818 | |
sakthipriya | 5:bb592f3185cc | 819 | if (pf1==0) // OC_ATS1 |
sakthipriya | 5:bb592f3185cc | 820 | { |
sakthipriya | 5:bb592f3185cc | 821 | pf1check=1; |
sakthipriya | 5:bb592f3185cc | 822 | actual_data.faultPoll_status |=0x01 ; |
sakthipriya | 9:194afacf7449 | 823 | ATS1_SW_ENABLE = 1; // turn off ats1 // to be turned on next cycle in ACS |
sakthipriya | 5:bb592f3185cc | 824 | } |
sakthipriya | 5:bb592f3185cc | 825 | else actual_data.faultPoll_status &= 0xFE; |
sakthipriya | 5:bb592f3185cc | 826 | |
sakthipriya | 5:bb592f3185cc | 827 | if (pf2==0) |
sakthipriya | 5:bb592f3185cc | 828 | { |
sakthipriya | 5:bb592f3185cc | 829 | pf2check=1; |
sakthipriya | 5:bb592f3185cc | 830 | actual_data.faultPoll_status |=0x02 ; |
sakthipriya | 9:194afacf7449 | 831 | ATS2_SW_ENABLE = 1; // turn off ats2 // turn on in ACS |
sakthipriya | 5:bb592f3185cc | 832 | } |
sakthipriya | 5:bb592f3185cc | 833 | else actual_data.faultPoll_status &= 0xFD; |
sakthipriya | 5:bb592f3185cc | 834 | |
sakthipriya | 5:bb592f3185cc | 835 | if (pf3==0) |
sakthipriya | 5:bb592f3185cc | 836 | { actual_data.faultPoll_status |=0x04 ; |
Bragadeesh153 | 13:fb7facaf308b | 837 | DRV_XY_EN = 0; |
sakthipriya | 5:bb592f3185cc | 838 | wait_us(1); |
Bragadeesh153 | 13:fb7facaf308b | 839 | DRV_XY_EN = 1; |
sakthipriya | 5:bb592f3185cc | 840 | } |
sakthipriya | 5:bb592f3185cc | 841 | else actual_data.faultPoll_status &= 0xFB; |
sakthipriya | 5:bb592f3185cc | 842 | |
sakthipriya | 5:bb592f3185cc | 843 | |
sakthipriya | 5:bb592f3185cc | 844 | |
sakthipriya | 5:bb592f3185cc | 845 | |
sakthipriya | 5:bb592f3185cc | 846 | /*if (ir1==1) |
sakthipriya | 5:bb592f3185cc | 847 | { |
sakthipriya | 5:bb592f3185cc | 848 | actual_data.faultIr_status &=0xFE; |
sakthipriya | 5:bb592f3185cc | 849 | }*/ |
lakshya | 14:a9588f443f1a | 850 | |
sakthipriya | 5:bb592f3185cc | 851 | if (ir2==1) |
sakthipriya | 5:bb592f3185cc | 852 | { |
sakthipriya | 5:bb592f3185cc | 853 | actual_data.faultIr_status &=0xFD; |
sakthipriya | 5:bb592f3185cc | 854 | } |
sakthipriya | 5:bb592f3185cc | 855 | if (ir3==1) |
sakthipriya | 5:bb592f3185cc | 856 | { |
sakthipriya | 5:bb592f3185cc | 857 | actual_data.faultIr_status &=0xFB; |
sakthipriya | 5:bb592f3185cc | 858 | } |
sakthipriya | 5:bb592f3185cc | 859 | if (ir4==1) |
sakthipriya | 5:bb592f3185cc | 860 | { |
sakthipriya | 5:bb592f3185cc | 861 | actual_data.faultIr_status &=0xF7; |
sakthipriya | 5:bb592f3185cc | 862 | } |
sakthipriya | 5:bb592f3185cc | 863 | if (ir5==1) |
sakthipriya | 5:bb592f3185cc | 864 | { |
sakthipriya | 5:bb592f3185cc | 865 | actual_data.faultIr_status &=0xEF; |
sakthipriya | 5:bb592f3185cc | 866 | } |
sakthipriya | 5:bb592f3185cc | 867 | if (ir6==1) |
sakthipriya | 5:bb592f3185cc | 868 | { |
sakthipriya | 5:bb592f3185cc | 869 | actual_data.faultIr_status &=0xDF; |
sakthipriya | 5:bb592f3185cc | 870 | }if (ir7==1) |
sakthipriya | 5:bb592f3185cc | 871 | { |
sakthipriya | 5:bb592f3185cc | 872 | actual_data.faultIr_status &=0xBF; |
sakthipriya | 5:bb592f3185cc | 873 | } |
lakshya | 14:a9588f443f1a | 874 | |
sakthipriya | 5:bb592f3185cc | 875 | |
sakthipriya | 5:bb592f3185cc | 876 | } |
sakthipriya | 5:bb592f3185cc | 877 | |
sakthipriya | 5:bb592f3185cc | 878 | |
sakthipriya | 0:7b4c00e3912f | 879 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
sakthipriya | 0:7b4c00e3912f | 880 | //SCHEDULER |
sakthipriya | 0:7b4c00e3912f | 881 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
sakthipriya | 0:7b4c00e3912f | 882 | uint8_t schedcount=1; |
sakthipriya | 0:7b4c00e3912f | 883 | void T_SC(void const *args) |
sakthipriya | 0:7b4c00e3912f | 884 | { |
prasanthbj05 | 17:8a8024c45dc0 | 885 | //printf("\n\r in scheduler"); |
sakthipriya | 0:7b4c00e3912f | 886 | |
sakthipriya | 0:7b4c00e3912f | 887 | if(schedcount == 7) //to reset the counter |
sakthipriya | 0:7b4c00e3912f | 888 | { |
sakthipriya | 0:7b4c00e3912f | 889 | schedcount = 1; |
sakthipriya | 0:7b4c00e3912f | 890 | } |
sakthipriya | 0:7b4c00e3912f | 891 | if(schedcount%1==0) |
prasanthbj05 | 17:8a8024c45dc0 | 892 | { //pc.printf("\nSTATE IS !!!!!! = %x !!\n",ACS_STATE); |
prasanthbj05 | 17:8a8024c45dc0 | 893 | //pc.printf("\niterp1 !!!!!! = %x !!\n",iterP1); |
prasanthbj05 | 17:8a8024c45dc0 | 894 | //pc.printf("\niteri2 IS !!!!!! = %x !!\n",iterI2); |
prasanthbj05 | 17:8a8024c45dc0 | 895 | //F_ACS(); |
sakthipriya | 0:7b4c00e3912f | 896 | } |
sakthipriya | 0:7b4c00e3912f | 897 | |
sakthipriya | 0:7b4c00e3912f | 898 | if(schedcount%2==0) |
sakthipriya | 0:7b4c00e3912f | 899 | { |
prasanthbj05 | 17:8a8024c45dc0 | 900 | //F_EPS(); |
sakthipriya | 0:7b4c00e3912f | 901 | } |
lakshya | 14:a9588f443f1a | 902 | if(schedcount%1==0) |
sakthipriya | 0:7b4c00e3912f | 903 | { |
prasanthbj05 | 17:8a8024c45dc0 | 904 | //F_BCN(); |
sakthipriya | 0:7b4c00e3912f | 905 | } |
sakthipriya | 0:7b4c00e3912f | 906 | schedcount++; |
prasanthbj05 | 17:8a8024c45dc0 | 907 | //printf("\n\r BAE is alive\n"); |
sakthipriya | 0:7b4c00e3912f | 908 | } |
sakthipriya | 0:7b4c00e3912f | 909 | |
sakthipriya | 0:7b4c00e3912f | 910 | Timer t_flag; |
sakthipriya | 0:7b4c00e3912f | 911 | void FLAG() |
sakthipriya | 0:7b4c00e3912f | 912 | { |
sakthipriya | 0:7b4c00e3912f | 913 | |
sakthipriya | 0:7b4c00e3912f | 914 | //.............acs..................// |
sakthipriya | 9:194afacf7449 | 915 | if(ACS_INIT_STATUS == 1) |
sakthipriya | 0:7b4c00e3912f | 916 | BAE_STATUS = BAE_STATUS | 0x00000080; //set ACS_INIT_STATUS flag |
sakthipriya | 9:194afacf7449 | 917 | else if(ACS_INIT_STATUS == 0) |
sakthipriya | 0:7b4c00e3912f | 918 | BAE_STATUS &= 0xFFFFFF7F; //clear ACS_INIT_STATUS flag |
sakthipriya | 0:7b4c00e3912f | 919 | |
sakthipriya | 9:194afacf7449 | 920 | if(ACS_DATA_ACQ_STATUS == 1) |
sakthipriya | 0:7b4c00e3912f | 921 | BAE_STATUS =BAE_STATUS | 0x00000100; //set ACS_DATA_ACQ_STATUS flag |
sakthipriya | 9:194afacf7449 | 922 | else if(ACS_DATA_ACQ_STATUS == 0) |
sakthipriya | 0:7b4c00e3912f | 923 | BAE_STATUS &= 0xFFFFFEFF; //clear ACS_DATA_ACQ_STATUS flag |
sakthipriya | 0:7b4c00e3912f | 924 | |
sakthipriya | 9:194afacf7449 | 925 | if(ACS_ATS_ENABLE == 1) |
sakthipriya | 0:7b4c00e3912f | 926 | BAE_ENABLE |= 0x00000004; |
sakthipriya | 9:194afacf7449 | 927 | else if(ACS_ATS_ENABLE == 0) |
sakthipriya | 0:7b4c00e3912f | 928 | BAE_ENABLE = BAE_ENABLE &0xFFFFFFFB | 0x00000004; |
sakthipriya | 0:7b4c00e3912f | 929 | |
sakthipriya | 0:7b4c00e3912f | 930 | if(ACS_DATA_ACQ_STATUS == 'f') |
sakthipriya | 0:7b4c00e3912f | 931 | BAE_STATUS |= 0x00000200; |
sakthipriya | 0:7b4c00e3912f | 932 | |
sakthipriya | 9:194afacf7449 | 933 | if(ACS_MAIN_STATUS == 1) |
sakthipriya | 0:7b4c00e3912f | 934 | BAE_STATUS = (BAE_STATUS | 0x00001000); //set ACS_MAIN_STATUS flag |
sakthipriya | 9:194afacf7449 | 935 | else if(ACS_MAIN_STATUS == 0) |
sakthipriya | 0:7b4c00e3912f | 936 | BAE_STATUS &= 0xFFFFEFFF; //clear ACS_MAIN_STATUS flag |
sakthipriya | 0:7b4c00e3912f | 937 | |
sakthipriya | 0:7b4c00e3912f | 938 | if(ACS_STATUS == '0') |
sakthipriya | 0:7b4c00e3912f | 939 | BAE_STATUS = (BAE_STATUS & 0xFFFF1FFF); // set ACS_STATUS = ACS_CONTROL_OFF |
sakthipriya | 0:7b4c00e3912f | 940 | else if(ACS_STATUS == '1') |
sakthipriya | 0:7b4c00e3912f | 941 | BAE_STATUS =(BAE_STATUS & 0xFFFF1FFF) | 0x00002000; // set ACS_STATUS = ACS_LOW_POWER |
sakthipriya | 0:7b4c00e3912f | 942 | else if(ACS_STATUS == '2') |
sakthipriya | 0:7b4c00e3912f | 943 | BAE_STATUS = (BAE_STATUS & 0xFFFF1FFF)| 0x00004000; // set ACS_STATUS = ACS_ZAXIS_MOMENT_ONLY |
sakthipriya | 0:7b4c00e3912f | 944 | else if(ACS_STATUS == '3') |
sakthipriya | 0:7b4c00e3912f | 945 | BAE_STATUS = (BAE_STATUS & 0xFFFF1FFF) | 0x00006000; // set ACS_STATUS = ACS_DATA_ACQ_FAILURE |
sakthipriya | 0:7b4c00e3912f | 946 | else if(ACS_STATUS == '4') |
sakthipriya | 0:7b4c00e3912f | 947 | BAE_STATUS = (BAE_STATUS & 0xFFFF1FFF) | 0x00008000; // set ACS_STATUS = ACS_NOMINAL_ONLY |
sakthipriya | 0:7b4c00e3912f | 948 | else if(ACS_STATUS == '5') |
sakthipriya | 0:7b4c00e3912f | 949 | BAE_STATUS =(BAE_STATUS & 0xFFFF1FFF) | 0x0000A000; // set ACS_STATUS = ACS_AUTO_CONTROL |
sakthipriya | 0:7b4c00e3912f | 950 | else if(ACS_STATUS == '6') |
sakthipriya | 0:7b4c00e3912f | 951 | BAE_STATUS =(BAE_STATUS & 0xFFFF1FFF) | 0x0000C000; // set ACS_STATUS = ACS_DETUMBLING_ONLY |
sakthipriya | 0:7b4c00e3912f | 952 | else |
sakthipriya | 0:7b4c00e3912f | 953 | BAE_STATUS =(BAE_STATUS & 0xFFFF1FFF) | 0x0000E000; // set ACS_STATUS = INVALID STATE |
sakthipriya | 0:7b4c00e3912f | 954 | |
sakthipriya | 0:7b4c00e3912f | 955 | if(ACS_STATE == '0') |
sakthipriya | 0:7b4c00e3912f | 956 | BAE_ENABLE = (BAE_ENABLE & 0xFFFFFF8F); //ACS_STATE = ACS_CONTROL_OFF |
sakthipriya | 0:7b4c00e3912f | 957 | else if(ACS_STATE == '2') |
sakthipriya | 0:7b4c00e3912f | 958 | BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000020); // ACS_STATE = ACS_ZAXIS_MOMENT_ONLY |
sakthipriya | 0:7b4c00e3912f | 959 | else if(ACS_STATE == '3') |
sakthipriya | 0:7b4c00e3912f | 960 | BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000030); // set ACS_STATUS = ACS_DATA_ACQ_FAILURE |
sakthipriya | 0:7b4c00e3912f | 961 | else if(ACS_STATE == '4') |
sakthipriya | 0:7b4c00e3912f | 962 | BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000040); // ACS_STATE = ACS_NOMINAL_ONLY |
sakthipriya | 0:7b4c00e3912f | 963 | else if(ACS_STATE == '5') |
sakthipriya | 0:7b4c00e3912f | 964 | BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000050); // ACS_STATE = ACS_AUTO_CONTROL |
sakthipriya | 0:7b4c00e3912f | 965 | else if(ACS_STATE == '6') |
sakthipriya | 0:7b4c00e3912f | 966 | BAE_ENABLE = ((BAE_ENABLE & 0xFFFFFF8F)| 0x00000060); //ACS_STATE = ACS_DETUMBLING_CONTROL |
sakthipriya | 0:7b4c00e3912f | 967 | |
sakthipriya | 0:7b4c00e3912f | 968 | //...............eps......................// |
sakthipriya | 5:bb592f3185cc | 969 | |
sakthipriya | 5:bb592f3185cc | 970 | |
sakthipriya | 9:194afacf7449 | 971 | if (EPS_INIT_STATUS==1) // Set EPS_INIT_STATUS |
sakthipriya | 5:bb592f3185cc | 972 | BAE_STATUS |= 0x00010000; |
sakthipriya | 9:194afacf7449 | 973 | else if(EPS_INIT_STATUS==0) // Clear |
sakthipriya | 5:bb592f3185cc | 974 | BAE_STATUS &= 0xFFFEFFFF; |
sakthipriya | 5:bb592f3185cc | 975 | |
sakthipriya | 5:bb592f3185cc | 976 | |
sakthipriya | 9:194afacf7449 | 977 | if (EPS_MAIN_STATUS==1) // Set EPS_MAIIN_STATUS |
sakthipriya | 5:bb592f3185cc | 978 | BAE_STATUS |= 0x00040000; |
sakthipriya | 9:194afacf7449 | 979 | else if(EPS_MAIN_STATUS==0) // Clear |
sakthipriya | 5:bb592f3185cc | 980 | BAE_STATUS &= 0xFFFBFFFF; |
sakthipriya | 5:bb592f3185cc | 981 | |
sakthipriya | 5:bb592f3185cc | 982 | |
sakthipriya | 9:194afacf7449 | 983 | if (EPS_BATTERY_GAUGE_STATUS==1) // Set EPS_BATTERY_GAUGE_STATUS |
sakthipriya | 5:bb592f3185cc | 984 | BAE_STATUS |= 0x00020000; |
sakthipriya | 9:194afacf7449 | 985 | else if(EPS_BATTERY_GAUGE_STATUS==0) // Clear |
sakthipriya | 5:bb592f3185cc | 986 | BAE_STATUS &= 0xFFFDFFFF; |
sakthipriya | 5:bb592f3185cc | 987 | |
sakthipriya | 5:bb592f3185cc | 988 | |
sakthipriya | 9:194afacf7449 | 989 | if (EPS_BATTERY_TEMP_STATUS==1) // Set EPS_BATTERY_TEMP_STATUS |
sakthipriya | 5:bb592f3185cc | 990 | BAE_STATUS |= 0x00080000; |
sakthipriya | 9:194afacf7449 | 991 | else if(EPS_BATTERY_TEMP_STATUS==0) // Clear |
sakthipriya | 5:bb592f3185cc | 992 | BAE_STATUS &= 0xFFF7FFFF; |
sakthipriya | 5:bb592f3185cc | 993 | |
sakthipriya | 5:bb592f3185cc | 994 | if (EPS_STATUS==0) |
sakthipriya | 5:bb592f3185cc | 995 | BAE_STATUS = (BAE_STATUS & 0xFF8FFFFF); // Set EPS_ERR_BATTERY_TEMP |
sakthipriya | 5:bb592f3185cc | 996 | else if (EPS_STATUS==1) |
sakthipriya | 5:bb592f3185cc | 997 | BAE_STATUS = (BAE_STATUS & 0xFF8FFFFF)|0x00010000; // Set EPS_BATTERY_HEATER_DISABLED |
sakthipriya | 5:bb592f3185cc | 998 | else if (EPS_STATUS==2) |
sakthipriya | 5:bb592f3185cc | 999 | BAE_STATUS = (BAE_STATUS & 0xFF8FFFFF)|0x00020000; // Set EPS_ERR_HEATER_SWITCH_OFF |
sakthipriya | 5:bb592f3185cc | 1000 | else if (EPS_STATUS==3) |
sakthipriya | 5:bb592f3185cc | 1001 | BAE_STATUS = (BAE_STATUS & 0xFF8FFFFF)|0x00030000; // Set EPS_ERR_HEATER_SWITCH_ON |
sakthipriya | 5:bb592f3185cc | 1002 | else if (EPS_STATUS==4) |
sakthipriya | 5:bb592f3185cc | 1003 | BAE_STATUS = (BAE_STATUS & 0xFF8FFFFF)|0x00040000; // Set EPS_BATTERY_HEATER_OFF |
sakthipriya | 5:bb592f3185cc | 1004 | else if (EPS_STATUS==5) |
sakthipriya | 5:bb592f3185cc | 1005 | BAE_STATUS = (BAE_STATUS & 0xFF8FFFFF)|0x00050000; // Set EPS_BATTERY_HEATER_ON |
sakthipriya | 5:bb592f3185cc | 1006 | |
sakthipriya | 5:bb592f3185cc | 1007 | |
sakthipriya | 9:194afacf7449 | 1008 | if(EPS_BATTERY_HEAT_ENABLE == 1) |
sakthipriya | 5:bb592f3185cc | 1009 | BAE_ENABLE |= 0x00000080; |
sakthipriya | 9:194afacf7449 | 1010 | else if(EPS_BATTERY_HEAT_ENABLE == 0) |
sakthipriya | 5:bb592f3185cc | 1011 | BAE_ENABLE = BAE_ENABLE &0xFFFFFF7; |
sakthipriya | 3:07e15677a75c | 1012 | |
sakthipriya | 0:7b4c00e3912f | 1013 | |
sakthipriya | 0:7b4c00e3912f | 1014 | |
sakthipriya | 0:7b4c00e3912f | 1015 | pc.printf("\n\r BAE status %x BAE ENABLE %x ",BAE_STATUS,BAE_ENABLE); |
sakthipriya | 0:7b4c00e3912f | 1016 | } |
sakthipriya | 0:7b4c00e3912f | 1017 | |
sakthipriya | 0:7b4c00e3912f | 1018 | void FCTN_BAE_INIT() |
sakthipriya | 0:7b4c00e3912f | 1019 | { |
sakthipriya | 0:7b4c00e3912f | 1020 | printf("\n\r Initialising BAE "); |
sakthipriya | 3:07e15677a75c | 1021 | //..........intial status....// |
Bragadeesh153 | 13:fb7facaf308b | 1022 | ACS_STATE = 4; |
sakthipriya | 9:194afacf7449 | 1023 | ACS_ATS_ENABLE = 1; |
sakthipriya | 9:194afacf7449 | 1024 | ACS_DATA_ACQ_ENABLE = 1; |
Bragadeesh153 | 16:cc77770d787f | 1025 | |
Bragadeesh153 | 16:cc77770d787f | 1026 | |
sakthipriya | 9:194afacf7449 | 1027 | EPS_BATTERY_HEAT_ENABLE = 1; |
Bragadeesh153 | 13:fb7facaf308b | 1028 | actual_data.power_mode=3; |
sakthipriya | 9:194afacf7449 | 1029 | //............intializing pins................// |
Bragadeesh153 | 16:cc77770d787f | 1030 | |
Bragadeesh153 | 16:cc77770d787f | 1031 | ATS2_SW_ENABLE = 1; |
Bragadeesh153 | 16:cc77770d787f | 1032 | ATS1_SW_ENABLE = 1; |
Bragadeesh153 | 16:cc77770d787f | 1033 | wait_ms(5); |
sakthipriya | 9:194afacf7449 | 1034 | ATS1_SW_ENABLE = 0; |
Bragadeesh153 | 16:cc77770d787f | 1035 | |
Bragadeesh153 | 16:cc77770d787f | 1036 | ACS_ATS_STATUS = 0x60; //Set Sensor 1 working , Sensor2 working and powered off by default |
Bragadeesh153 | 13:fb7facaf308b | 1037 | |
Bragadeesh153 | 13:fb7facaf308b | 1038 | DRV_XY_EN = 1; |
Bragadeesh153 | 13:fb7facaf308b | 1039 | DRV_Z_EN = 1; |
Bragadeesh153 | 13:fb7facaf308b | 1040 | TRZ_SW = 1; |
Bragadeesh153 | 13:fb7facaf308b | 1041 | TRXY_SW = 1; |
sakthipriya | 9:194afacf7449 | 1042 | |
sakthipriya | 3:07e15677a75c | 1043 | //............................// |
prasanthbj05 | 17:8a8024c45dc0 | 1044 | //FCTN_ACS_INIT(); |
prasanthbj05 | 17:8a8024c45dc0 | 1045 | //FCTN_EPS_INIT(); |
lakshya | 14:a9588f443f1a | 1046 | //FCTN_BCN_INIT(); |
sakthipriya | 3:07e15677a75c | 1047 | |
sakthipriya | 3:07e15677a75c | 1048 | |
sakthipriya | 0:7b4c00e3912f | 1049 | FLAG(); |
sakthipriya | 0:7b4c00e3912f | 1050 | } |
sakthipriya | 0:7b4c00e3912f | 1051 | |
sakthipriya | 0:7b4c00e3912f | 1052 | int main() |
sakthipriya | 0:7b4c00e3912f | 1053 | { |
prasanthbj05 | 17:8a8024c45dc0 | 1054 | pc.baud(9600); |
sakthipriya | 0:7b4c00e3912f | 1055 | pc.printf("\n\r BAE Activated. Testing Version 1.1 \n"); |
prasanthbj05 | 17:8a8024c45dc0 | 1056 | //CDMS_RESET = 1; |
lakshya | 14:a9588f443f1a | 1057 | /*if (BCN_FEN == 0) //dummy implementation |
sakthipriya | 0:7b4c00e3912f | 1058 | { |
sakthipriya | 0:7b4c00e3912f | 1059 | pc.printf("\n\r RF silence "); |
Bragadeesh153 | 12:af1d7e18b868 | 1060 | FCTN_BCN_FEN(); |
sakthipriya | 0:7b4c00e3912f | 1061 | t_rfsilence.start();//Start the timer for RF_Silence |
sakthipriya | 0:7b4c00e3912f | 1062 | while(t_rfsilence.read() < RF_SILENCE_TIME); |
sakthipriya | 0:7b4c00e3912f | 1063 | } |
sakthipriya | 0:7b4c00e3912f | 1064 | */ |
sakthipriya | 3:07e15677a75c | 1065 | |
sakthipriya | 9:194afacf7449 | 1066 | //ACS_INIT_STATUS = 0; |
sakthipriya | 9:194afacf7449 | 1067 | //ACS_DATA_ACQ_STATUS = 0; |
Bragadeesh153 | 13:fb7facaf308b | 1068 | |
Bragadeesh153 | 13:fb7facaf308b | 1069 | |
sakthipriya | 9:194afacf7449 | 1070 | |
Bragadeesh153 | 13:fb7facaf308b | 1071 | //FLAG(); |
sakthipriya | 0:7b4c00e3912f | 1072 | FCTN_BAE_INIT(); |
prasanthbj05 | 17:8a8024c45dc0 | 1073 | //pc.printf("\n\rPORTE->PCR[0] = 0x%08X",PORTE->PCR[0]); |
prasanthbj05 | 17:8a8024c45dc0 | 1074 | //pc.printf("\n\rPORTE->PCR[1] = 0x%08X",PORTE->PCR[1]); |
sakthipriya | 3:07e15677a75c | 1075 | |
sakthipriya | 0:7b4c00e3912f | 1076 | |
sakthipriya | 0:7b4c00e3912f | 1077 | //...i2c.. |
sakthipriya | 3:07e15677a75c | 1078 | //strcpy(telemetry,"This is telemetry THis is sample telemetry. ffffffffffffffffffffffffffffff end"); |
sakthipriya | 0:7b4c00e3912f | 1079 | slave.address(addr); |
sakthipriya | 0:7b4c00e3912f | 1080 | irpt_2_mstr = 0; |
sakthipriya | 0:7b4c00e3912f | 1081 | |
sakthipriya | 0:7b4c00e3912f | 1082 | ptr_t_i2c = new Thread(T_TC); |
sakthipriya | 0:7b4c00e3912f | 1083 | ptr_t_i2c->set_priority(osPriorityHigh); |
sakthipriya | 5:bb592f3185cc | 1084 | |
sakthipriya | 0:7b4c00e3912f | 1085 | irpt_4m_mstr.enable_irq(); |
sakthipriya | 0:7b4c00e3912f | 1086 | irpt_4m_mstr.rise(&FCTN_I2C_ISR); |
sakthipriya | 5:bb592f3185cc | 1087 | // ir1.fall(&ir1clear); //Battery Gauge - Alert Bar Signal |
lakshya | 14:a9588f443f1a | 1088 | /* ir2.fall(&ir2clear); //TRXY Driver TR switch Fault |
lakshya | 14:a9588f443f1a | 1089 | ir3.fall(&ir3clear); //TRZ Driver Fault Bar |
lakshya | 14:a9588f443f1a | 1090 | ir4.fall(&ir4clear); //TRZ Driver TR switch Fault |
lakshya | 14:a9588f443f1a | 1091 | ir5.fall(&ir5clear); //CDMS - Switch Fault |
lakshya | 14:a9588f443f1a | 1092 | ir6.fall(&ir6clear); //Beacon- Switch OC bar |
lakshya | 14:a9588f443f1a | 1093 | ir7.fall(&ir7clear); //Charger IC - Fault Bar |
lakshya | 14:a9588f443f1a | 1094 | |
lakshya | 14:a9588f443f1a | 1095 | */ |
sakthipriya | 0:7b4c00e3912f | 1096 | RtosTimer t_sc_timer(T_SC,osTimerPeriodic); // Initiating the scheduler thread |
sakthipriya | 0:7b4c00e3912f | 1097 | t_sc_timer.start(10000); |
sakthipriya | 0:7b4c00e3912f | 1098 | t_start.start(); |
sakthipriya | 0:7b4c00e3912f | 1099 | pc.printf("\n\rStarted scheduler %f\n\r",t_start.read()); |
prasanthbj05 | 17:8a8024c45dc0 | 1100 | printf("\n\rPTE->DIR = 0x%08X",PTE->PDIR); |
prasanthbj05 | 17:8a8024c45dc0 | 1101 | //printf("\n\rInitial values\n"); |
prasanthbj05 | 17:8a8024c45dc0 | 1102 | //debug(); |
prasanthbj05 | 17:8a8024c45dc0 | 1103 | //debug2(); |
sakthipriya | 0:7b4c00e3912f | 1104 | //FCTN_BAE_INIT(); |
sakthipriya | 0:7b4c00e3912f | 1105 | while(1); //required to prevent main from terminating |
sakthipriya | 3:07e15677a75c | 1106 | } |
sakthipriya | 3:07e15677a75c | 1107 |