![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
cdms i2c working - but not working after hk data is sent
Fork of pcb_test_vr1_1_2 by
main.cpp@3:0931a8800543, 2015-05-13 (annotated)
- Committer:
- sakthipriya
- Date:
- Wed May 13 06:19:25 2015 +0000
- Revision:
- 3:0931a8800543
- Parent:
- 2:3d9ca9554adf
- Child:
- 4:65a2d0b97d01
end of integration v.1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sakthipriya | 0:e91ee0e99213 | 1 | #include "mbed.h" |
sakthipriya | 0:e91ee0e99213 | 2 | #include "rtos.h" |
sakthipriya | 0:e91ee0e99213 | 3 | #include "HK.h" |
sakthipriya | 0:e91ee0e99213 | 4 | #include "slave.h" |
sakthipriya | 0:e91ee0e99213 | 5 | #include "beacon.h" |
sakthipriya | 0:e91ee0e99213 | 6 | #include "ACS.h" |
sakthipriya | 0:e91ee0e99213 | 7 | #include "fault.h" |
sakthipriya | 0:e91ee0e99213 | 8 | #include "slave.h" |
sakthipriya | 0:e91ee0e99213 | 9 | #include "mnm.h" |
sakthipriya | 0:e91ee0e99213 | 10 | |
sakthipriya | 0:e91ee0e99213 | 11 | Serial pc(USBTX, USBRX); |
sakthipriya | 0:e91ee0e99213 | 12 | |
raizel_varun | 2:3d9ca9554adf | 13 | InterruptIn interrupt(PIN97); //I2c interrupt from CDMS |
raizel_varun | 2:3d9ca9554adf | 14 | DigitalOut data_ready(PIN90); //Sends interrupt to CDMS |
sakthipriya | 3:0931a8800543 | 15 | //InterruptIn interrupt(D9); //I2c interrupt from CDMS |
sakthipriya | 3:0931a8800543 | 16 | //DigitalOut data_ready(D10); |
sakthipriya | 0:e91ee0e99213 | 17 | |
sakthipriya | 0:e91ee0e99213 | 18 | Timer t; //To know the time of execution each thread |
sakthipriya | 0:e91ee0e99213 | 19 | Timer t1; //To know the time of entering of each thread |
sakthipriya | 0:e91ee0e99213 | 20 | Timer t2; //To check the time sync in i2c communication |
sakthipriya | 0:e91ee0e99213 | 21 | Timer t3; //To know the time taken by i2c read/write function |
sakthipriya | 3:0931a8800543 | 22 | Timer i1; |
sakthipriya | 3:0931a8800543 | 23 | Timer i2; |
sakthipriya | 0:e91ee0e99213 | 24 | /*****************************************************************Threads USed***********************************************************************************/ |
sakthipriya | 0:e91ee0e99213 | 25 | Thread *ptr_t_hk_acq; |
sakthipriya | 0:e91ee0e99213 | 26 | Thread *ptr_t_acs; |
sakthipriya | 0:e91ee0e99213 | 27 | Thread *ptr_t_bea; |
sakthipriya | 0:e91ee0e99213 | 28 | Thread *ptr_t_i2c; |
sakthipriya | 0:e91ee0e99213 | 29 | Thread *ptr_t_wdt; |
sakthipriya | 0:e91ee0e99213 | 30 | |
sakthipriya | 0:e91ee0e99213 | 31 | /****************************************************************configuring I2c*********************************************************************************/ |
sakthipriya | 3:0931a8800543 | 32 | I2CSlave slave(PIN1,PIN2); //configuring pins p27, p28 as I2Cslave |
sakthipriya | 3:0931a8800543 | 33 | //I2CSlave slave (D14,D15); |
sakthipriya | 0:e91ee0e99213 | 34 | int i2c_status=0; //read or write mode for i2c 0: write2slave 1: write2master |
sakthipriya | 0:e91ee0e99213 | 35 | typedef struct //structure of i2c data |
sakthipriya | 0:e91ee0e99213 | 36 | { |
sakthipriya | 0:e91ee0e99213 | 37 | char data[25]; |
sakthipriya | 0:e91ee0e99213 | 38 | int length; |
sakthipriya | 0:e91ee0e99213 | 39 | }i2c_data; |
sakthipriya | 0:e91ee0e99213 | 40 | |
sakthipriya | 0:e91ee0e99213 | 41 | |
sakthipriya | 0:e91ee0e99213 | 42 | //Mail<i2c_data,16> i2c_data_receive; |
sakthipriya | 0:e91ee0e99213 | 43 | Mail<i2c_data,16> i2c_data_send; |
sakthipriya | 0:e91ee0e99213 | 44 | |
sakthipriya | 0:e91ee0e99213 | 45 | //-------------------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 46 | //TASK 2 : HK |
sakthipriya | 0:e91ee0e99213 | 47 | //-------------------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 48 | |
sakthipriya | 0:e91ee0e99213 | 49 | char hk_data[25]; |
sakthipriya | 0:e91ee0e99213 | 50 | extern SensorDataQuantised SensorQuantised; |
sakthipriya | 0:e91ee0e99213 | 51 | void T_HK_ACQ(void const *args) |
sakthipriya | 0:e91ee0e99213 | 52 | { |
sakthipriya | 0:e91ee0e99213 | 53 | |
sakthipriya | 0:e91ee0e99213 | 54 | while(1) |
sakthipriya | 0:e91ee0e99213 | 55 | { |
sakthipriya | 0:e91ee0e99213 | 56 | Thread::signal_wait(0x2); |
sakthipriya | 0:e91ee0e99213 | 57 | SensorQuantised.power_mode='3'; //default power mode(dummy) |
sakthipriya | 0:e91ee0e99213 | 58 | printf("\n\rTHIS IS HK %f\n\r",t1.read()); |
sakthipriya | 0:e91ee0e99213 | 59 | t.start(); |
sakthipriya | 0:e91ee0e99213 | 60 | FUNC_HK_FAULTS(); // !Actual fault management is not implemented |
sakthipriya | 0:e91ee0e99213 | 61 | FUNC_HK_POWER(SensorQuantised.power_mode); // !The power mode algorithm is yet to be obtained |
sakthipriya | 0:e91ee0e99213 | 62 | FUNC_HK_MAIN(); //Collecting HK data |
sakthipriya | 0:e91ee0e99213 | 63 | FUNC_I2C_IR2CDMS(); //sending HK data to CDMS |
sakthipriya | 0:e91ee0e99213 | 64 | t.stop(); |
sakthipriya | 0:e91ee0e99213 | 65 | printf("The time to execute hk_acq is %f seconds\n\r",t.read()); |
sakthipriya | 0:e91ee0e99213 | 66 | t.reset(); |
sakthipriya | 0:e91ee0e99213 | 67 | } |
sakthipriya | 0:e91ee0e99213 | 68 | } |
sakthipriya | 0:e91ee0e99213 | 69 | |
sakthipriya | 0:e91ee0e99213 | 70 | //--------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 71 | //TASK 1 : ACS |
sakthipriya | 0:e91ee0e99213 | 72 | //--------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 73 | |
sakthipriya | 0:e91ee0e99213 | 74 | int acs_pflag = 1; |
sakthipriya | 0:e91ee0e99213 | 75 | void T_ACS(void const *args) |
sakthipriya | 0:e91ee0e99213 | 76 | { |
sakthipriya | 0:e91ee0e99213 | 77 | float mag_field[3]; |
sakthipriya | 0:e91ee0e99213 | 78 | float omega[3]; |
sakthipriya | 0:e91ee0e99213 | 79 | float *mnm_data; |
sakthipriya | 0:e91ee0e99213 | 80 | float mag_field1[3]; |
sakthipriya | 0:e91ee0e99213 | 81 | float omega1[3]; |
sakthipriya | 0:e91ee0e99213 | 82 | float tauc1[3]; |
sakthipriya | 0:e91ee0e99213 | 83 | float moment[3]; |
sakthipriya | 0:e91ee0e99213 | 84 | while(1) |
sakthipriya | 0:e91ee0e99213 | 85 | { |
sakthipriya | 0:e91ee0e99213 | 86 | Thread::signal_wait(0x1); |
sakthipriya | 0:e91ee0e99213 | 87 | printf("\n\rEntered ACS %f\n",t1.read()); |
sakthipriya | 0:e91ee0e99213 | 88 | t.start(); |
sakthipriya | 0:e91ee0e99213 | 89 | FUNC_ACS_MAG_EXEC(mag_field); |
sakthipriya | 3:0931a8800543 | 90 | //printf("\n\r check"); |
sakthipriya | 0:e91ee0e99213 | 91 | for(int i=0; i<3; i++) |
sakthipriya | 0:e91ee0e99213 | 92 | { |
sakthipriya | 0:e91ee0e99213 | 93 | printf("%f\t",mag_field[i]); |
sakthipriya | 0:e91ee0e99213 | 94 | } |
sakthipriya | 0:e91ee0e99213 | 95 | FUNC_ACS_EXEC_GYR(omega); |
sakthipriya | 0:e91ee0e99213 | 96 | acs_pflag =1; //to be removed later |
sakthipriya | 0:e91ee0e99213 | 97 | omega[0] = 1.0; |
sakthipriya | 0:e91ee0e99213 | 98 | omega[1] = 1.0; |
sakthipriya | 0:e91ee0e99213 | 99 | omega[2] = 1.0; |
sakthipriya | 0:e91ee0e99213 | 100 | |
sakthipriya | 0:e91ee0e99213 | 101 | |
sakthipriya | 0:e91ee0e99213 | 102 | |
sakthipriya | 0:e91ee0e99213 | 103 | /* mnm_data=EXECUTE_PNI(); //the angular velocity is stored in the first 3 values and magnetic field values in next 3 |
sakthipriya | 0:e91ee0e99213 | 104 | printf("\n\rmnm gyro values\n"); //printing the angular velocity and magnetic field values |
sakthipriya | 0:e91ee0e99213 | 105 | for(int i=0; i<3; i++) |
sakthipriya | 0:e91ee0e99213 | 106 | { |
sakthipriya | 0:e91ee0e99213 | 107 | printf("%f\t",mnm_data[i]); |
sakthipriya | 0:e91ee0e99213 | 108 | } |
sakthipriya | 0:e91ee0e99213 | 109 | printf("\n\r mnm mag values\n"); |
sakthipriya | 0:e91ee0e99213 | 110 | for(int i=3; i<6; i++) |
sakthipriya | 0:e91ee0e99213 | 111 | { |
sakthipriya | 0:e91ee0e99213 | 112 | printf("%f\t",mnm_data[i]); |
sakthipriya | 0:e91ee0e99213 | 113 | } |
sakthipriya | 0:e91ee0e99213 | 114 | for(int i = 0 ; i<3;i++) |
sakthipriya | 0:e91ee0e99213 | 115 | { |
sakthipriya | 0:e91ee0e99213 | 116 | omega1[i] = mnm_data[i]; |
sakthipriya | 0:e91ee0e99213 | 117 | } |
sakthipriya | 0:e91ee0e99213 | 118 | for( int i = 3;i<6;i++) |
sakthipriya | 0:e91ee0e99213 | 119 | { |
sakthipriya | 0:e91ee0e99213 | 120 | mag_field1[i-3] = mnm_data[i]; |
sakthipriya | 0:e91ee0e99213 | 121 | } |
sakthipriya | 0:e91ee0e99213 | 122 | */ |
sakthipriya | 0:e91ee0e99213 | 123 | if(acs_pflag == 1) |
sakthipriya | 0:e91ee0e99213 | 124 | { |
sakthipriya | 0:e91ee0e99213 | 125 | |
sakthipriya | 0:e91ee0e99213 | 126 | FUNC_ACS_CNTRLALGO(mag_field,omega,tauc1); |
sakthipriya | 0:e91ee0e99213 | 127 | printf("\n\r control algo values "); |
sakthipriya | 0:e91ee0e99213 | 128 | for(int i=0; i<3; i++) |
sakthipriya | 0:e91ee0e99213 | 129 | { |
sakthipriya | 0:e91ee0e99213 | 130 | printf("%f\t",tauc1[i]); |
sakthipriya | 0:e91ee0e99213 | 131 | } |
sakthipriya | 0:e91ee0e99213 | 132 | moment_calc (tauc1, mag_field,moment); |
sakthipriya | 0:e91ee0e99213 | 133 | printf("\n\r moment values "); |
sakthipriya | 0:e91ee0e99213 | 134 | for(int i=0; i<3; i++) |
sakthipriya | 0:e91ee0e99213 | 135 | { |
sakthipriya | 0:e91ee0e99213 | 136 | printf("%f\t",moment[i]); |
sakthipriya | 0:e91ee0e99213 | 137 | } |
sakthipriya | 0:e91ee0e99213 | 138 | FUNC_ACS_GENPWM(moment); |
sakthipriya | 0:e91ee0e99213 | 139 | } |
sakthipriya | 0:e91ee0e99213 | 140 | t.reset(); |
sakthipriya | 0:e91ee0e99213 | 141 | } |
sakthipriya | 0:e91ee0e99213 | 142 | } |
sakthipriya | 0:e91ee0e99213 | 143 | |
sakthipriya | 0:e91ee0e99213 | 144 | //---------------------------------------------------BEACON-------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 145 | |
sakthipriya | 0:e91ee0e99213 | 146 | int beac_flag=0; //To receive telecommand from ground. |
sakthipriya | 0:e91ee0e99213 | 147 | |
sakthipriya | 0:e91ee0e99213 | 148 | |
sakthipriya | 0:e91ee0e99213 | 149 | /*void T_BEA_TELECOMMAND(void const *args) |
sakthipriya | 0:e91ee0e99213 | 150 | { |
sakthipriya | 0:e91ee0e99213 | 151 | char c = pc.getc(); |
sakthipriya | 0:e91ee0e99213 | 152 | if(c=='a') |
sakthipriya | 0:e91ee0e99213 | 153 | { |
sakthipriya | 0:e91ee0e99213 | 154 | printf("Telecommand detected\n\r"); |
sakthipriya | 0:e91ee0e99213 | 155 | beac_flag=1; |
sakthipriya | 0:e91ee0e99213 | 156 | } |
sakthipriya | 0:e91ee0e99213 | 157 | } |
sakthipriya | 0:e91ee0e99213 | 158 | */ |
sakthipriya | 0:e91ee0e99213 | 159 | |
sakthipriya | 0:e91ee0e99213 | 160 | void T_BEA(void const *args) |
sakthipriya | 0:e91ee0e99213 | 161 | { |
sakthipriya | 0:e91ee0e99213 | 162 | |
sakthipriya | 0:e91ee0e99213 | 163 | while(1) |
sakthipriya | 0:e91ee0e99213 | 164 | { |
sakthipriya | 0:e91ee0e99213 | 165 | Thread::signal_wait(0x3); |
sakthipriya | 0:e91ee0e99213 | 166 | printf("\n\rTHIS IS BEACON %f\n\r",t1.read()); |
sakthipriya | 0:e91ee0e99213 | 167 | t.start(); |
sakthipriya | 0:e91ee0e99213 | 168 | FUNC_BEA(); |
sakthipriya | 0:e91ee0e99213 | 169 | if(beac_flag==1) |
sakthipriya | 0:e91ee0e99213 | 170 | { |
sakthipriya | 0:e91ee0e99213 | 171 | Thread::wait(600000); |
sakthipriya | 0:e91ee0e99213 | 172 | beac_flag = 0; |
sakthipriya | 0:e91ee0e99213 | 173 | } |
sakthipriya | 0:e91ee0e99213 | 174 | printf("The time to execute beacon thread is %f seconds\n\r",t.read()); |
sakthipriya | 0:e91ee0e99213 | 175 | t.reset(); |
sakthipriya | 0:e91ee0e99213 | 176 | } |
sakthipriya | 0:e91ee0e99213 | 177 | } |
sakthipriya | 0:e91ee0e99213 | 178 | |
sakthipriya | 0:e91ee0e99213 | 179 | |
sakthipriya | 0:e91ee0e99213 | 180 | |
sakthipriya | 0:e91ee0e99213 | 181 | extern SensorDataQuantised SensorQuantised; |
sakthipriya | 0:e91ee0e99213 | 182 | |
sakthipriya | 0:e91ee0e99213 | 183 | /*------------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 184 | -------------------------------------------------------WATCHDOG----------------------------------------------------------------------------*/ |
sakthipriya | 0:e91ee0e99213 | 185 | DigitalOut trigger(PIN63); // has to be changed |
sakthipriya | 0:e91ee0e99213 | 186 | void T_WDT(void const * args) |
sakthipriya | 0:e91ee0e99213 | 187 | { |
sakthipriya | 0:e91ee0e99213 | 188 | trigger = 1; |
sakthipriya | 0:e91ee0e99213 | 189 | while(true) |
sakthipriya | 0:e91ee0e99213 | 190 | { |
sakthipriya | 0:e91ee0e99213 | 191 | Thread::signal_wait(0x5); //signal set from scheduler or sthing. r RTOS timer nce the timing is finalized |
sakthipriya | 0:e91ee0e99213 | 192 | printf("\n\rEntered WD\n\r"); |
sakthipriya | 0:e91ee0e99213 | 193 | trigger = !trigger; |
sakthipriya | 0:e91ee0e99213 | 194 | } |
sakthipriya | 0:e91ee0e99213 | 195 | } |
sakthipriya | 0:e91ee0e99213 | 196 | |
sakthipriya | 0:e91ee0e99213 | 197 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 198 | //TASK 5 : i2c data |
sakthipriya | 0:e91ee0e99213 | 199 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 200 | |
sakthipriya | 0:e91ee0e99213 | 201 | void FUNC_I2C_WRITE2CDMS(char *data, int length=1) |
sakthipriya | 0:e91ee0e99213 | 202 | { |
sakthipriya | 0:e91ee0e99213 | 203 | int slave_status = 1; |
sakthipriya | 3:0931a8800543 | 204 | int inter_test = interrupt; |
sakthipriya | 3:0931a8800543 | 205 | int slr = slave.receive(); |
sakthipriya | 3:0931a8800543 | 206 | wait_ms(20); |
sakthipriya | 3:0931a8800543 | 207 | //printf("\n\r time is %d\n",t2.read_us()); |
sakthipriya | 3:0931a8800543 | 208 | //if(interrupt ==1) |
sakthipriya | 3:0931a8800543 | 209 | //{ |
sakthipriya | 3:0931a8800543 | 210 | //printf("\n\r slave status %d",slave.receive()); |
sakthipriya | 3:0931a8800543 | 211 | //t2.stop(); |
sakthipriya | 0:e91ee0e99213 | 212 | if(slave.receive() == 0) |
sakthipriya | 0:e91ee0e99213 | 213 | t2.stop(); |
sakthipriya | 0:e91ee0e99213 | 214 | if( slave.receive()==1) |
sakthipriya | 0:e91ee0e99213 | 215 | { |
sakthipriya | 0:e91ee0e99213 | 216 | t2.stop(); |
sakthipriya | 0:e91ee0e99213 | 217 | t3.start(); |
sakthipriya | 0:e91ee0e99213 | 218 | slave_status=slave.write(data,length); |
sakthipriya | 0:e91ee0e99213 | 219 | t3.stop(); |
sakthipriya | 0:e91ee0e99213 | 220 | } |
sakthipriya | 0:e91ee0e99213 | 221 | else if( slave.receive()==3 || slave.receive()==2) |
sakthipriya | 0:e91ee0e99213 | 222 | { |
sakthipriya | 0:e91ee0e99213 | 223 | t2.stop(); |
sakthipriya | 0:e91ee0e99213 | 224 | t3.start(); |
sakthipriya | 0:e91ee0e99213 | 225 | slave_status=slave.read(data,length); |
sakthipriya | 0:e91ee0e99213 | 226 | t3.stop(); |
sakthipriya | 0:e91ee0e99213 | 227 | } |
sakthipriya | 3:0931a8800543 | 228 | //} |
sakthipriya | 3:0931a8800543 | 229 | // printf("\n\r time taken to receive intrpt 4m cdms %d",i1.read_us()); |
sakthipriya | 3:0931a8800543 | 230 | //i1.reset(); |
sakthipriya | 3:0931a8800543 | 231 | printf("\n\r slave status %d %d %d",slave.receive(),t2.read_us(),t3.read_us()); |
sakthipriya | 3:0931a8800543 | 232 | // printf("\n\r time taken from interrupt to reach i2c fn %d",t2.read_us()); |
sakthipriya | 3:0931a8800543 | 233 | t2.stop(); |
sakthipriya | 0:e91ee0e99213 | 234 | t2.reset(); |
sakthipriya | 3:0931a8800543 | 235 | //printf("\n\r time to execute i2c function %d",t3.read_us()); |
sakthipriya | 0:e91ee0e99213 | 236 | t3.reset(); |
sakthipriya | 0:e91ee0e99213 | 237 | } |
sakthipriya | 0:e91ee0e99213 | 238 | |
sakthipriya | 0:e91ee0e99213 | 239 | char data_send[25],data_receive; |
sakthipriya | 0:e91ee0e99213 | 240 | void T_I2C_BAE(void const * args) |
sakthipriya | 0:e91ee0e99213 | 241 | { |
sakthipriya | 0:e91ee0e99213 | 242 | while(1) |
sakthipriya | 0:e91ee0e99213 | 243 | { |
sakthipriya | 0:e91ee0e99213 | 244 | Thread::signal_wait(0x4); |
sakthipriya | 3:0931a8800543 | 245 | int something = interrupt; |
sakthipriya | 3:0931a8800543 | 246 | // printf("\n\r interrupt %d",interrupt); |
sakthipriya | 0:e91ee0e99213 | 247 | if(i2c_status == 0 ) |
sakthipriya | 3:0931a8800543 | 248 | |
sakthipriya | 0:e91ee0e99213 | 249 | { |
sakthipriya | 3:0931a8800543 | 250 | // wait_ms(23); |
sakthipriya | 0:e91ee0e99213 | 251 | FUNC_I2C_WRITE2CDMS(&data_receive,1); |
sakthipriya | 0:e91ee0e99213 | 252 | /*i2c_data * i2c_data_r = i2c_data_receive.alloc(); |
sakthipriya | 0:e91ee0e99213 | 253 | i2c_data_r->data = data_receive; |
sakthipriya | 0:e91ee0e99213 | 254 | i2c_data_r->length = 1; |
sakthipriya | 0:e91ee0e99213 | 255 | i2c_data_receive.put(i2c_data_r);*/ |
sakthipriya | 0:e91ee0e99213 | 256 | printf("\n\r Data received from CDMS is %c \n\r",data_receive); |
sakthipriya | 0:e91ee0e99213 | 257 | FUNC_I2C_TC_EXECUTE(data_receive); // This has to be done from a differen thread |
sakthipriya | 0:e91ee0e99213 | 258 | |
sakthipriya | 0:e91ee0e99213 | 259 | } |
sakthipriya | 0:e91ee0e99213 | 260 | else if(i2c_status ==1) |
sakthipriya | 0:e91ee0e99213 | 261 | { |
sakthipriya | 0:e91ee0e99213 | 262 | osEvent evt = i2c_data_send.get(); |
sakthipriya | 0:e91ee0e99213 | 263 | if (evt.status == osEventMail) |
sakthipriya | 0:e91ee0e99213 | 264 | { |
sakthipriya | 0:e91ee0e99213 | 265 | i2c_data *i2c_data_s = (i2c_data*)evt.value.p; |
sakthipriya | 0:e91ee0e99213 | 266 | strcpy(data_send,i2c_data_s -> data); |
sakthipriya | 3:0931a8800543 | 267 | // wait_ms(13); |
sakthipriya | 3:0931a8800543 | 268 | |
sakthipriya | 0:e91ee0e99213 | 269 | FUNC_I2C_WRITE2CDMS(data_send,25); |
sakthipriya | 0:e91ee0e99213 | 270 | printf("\n\rData sent to CDMS is %s\n\r",data_send); |
sakthipriya | 0:e91ee0e99213 | 271 | |
sakthipriya | 0:e91ee0e99213 | 272 | i2c_data_send.free(i2c_data_s); |
sakthipriya | 0:e91ee0e99213 | 273 | i2c_status = 0; |
sakthipriya | 0:e91ee0e99213 | 274 | } |
sakthipriya | 0:e91ee0e99213 | 275 | } |
sakthipriya | 0:e91ee0e99213 | 276 | |
sakthipriya | 0:e91ee0e99213 | 277 | } |
sakthipriya | 0:e91ee0e99213 | 278 | } |
sakthipriya | 0:e91ee0e99213 | 279 | |
sakthipriya | 0:e91ee0e99213 | 280 | |
sakthipriya | 0:e91ee0e99213 | 281 | |
sakthipriya | 0:e91ee0e99213 | 282 | void FUNC_I2C_INT() |
sakthipriya | 0:e91ee0e99213 | 283 | { |
sakthipriya | 3:0931a8800543 | 284 | //i1.stop(); |
sakthipriya | 0:e91ee0e99213 | 285 | |
sakthipriya | 0:e91ee0e99213 | 286 | // t3.start(); |
sakthipriya | 0:e91ee0e99213 | 287 | ptr_t_i2c->signal_set(0x4); |
sakthipriya | 3:0931a8800543 | 288 | //printf("\n ceckh\n"); |
sakthipriya | 3:0931a8800543 | 289 | t2.start(); |
sakthipriya | 3:0931a8800543 | 290 | // printf("\n\r time taken from interrupt to reach i2c fn %d",t2.read_us()); |
sakthipriya | 0:e91ee0e99213 | 291 | } |
sakthipriya | 0:e91ee0e99213 | 292 | |
sakthipriya | 0:e91ee0e99213 | 293 | void FUNC_I2C_IR2CDMS() |
sakthipriya | 0:e91ee0e99213 | 294 | { |
sakthipriya | 0:e91ee0e99213 | 295 | data_ready=0; |
sakthipriya | 0:e91ee0e99213 | 296 | //char data[25]; |
sakthipriya | 0:e91ee0e99213 | 297 | strcpy(hk_data,"hk_Data"); |
sakthipriya | 0:e91ee0e99213 | 298 | strcat(hk_data,SensorQuantised.Voltage); |
sakthipriya | 0:e91ee0e99213 | 299 | strcat(hk_data,SensorQuantised.Current); |
sakthipriya | 0:e91ee0e99213 | 300 | strcat(hk_data,SensorQuantised.Temperature); |
sakthipriya | 0:e91ee0e99213 | 301 | strcat(hk_data,SensorQuantised.PanelTemperature); |
sakthipriya | 0:e91ee0e99213 | 302 | strcat(hk_data,SensorQuantised.AngularSpeed); |
sakthipriya | 0:e91ee0e99213 | 303 | strcat(hk_data,SensorQuantised.Bnewvalue); |
sakthipriya | 0:e91ee0e99213 | 304 | char fdata[5] = {SensorQuantised.BatteryTemperature,SensorQuantised.faultpoll,SensorQuantised.faultir,SensorQuantised.power_mode}; |
sakthipriya | 0:e91ee0e99213 | 305 | |
sakthipriya | 0:e91ee0e99213 | 306 | /*strcat(hk_data,sfaultpoll); |
sakthipriya | 0:e91ee0e99213 | 307 | strcat(hk_data,sfaultir); |
sakthipriya | 0:e91ee0e99213 | 308 | strcat(hk_data,spower_mode);*/ |
sakthipriya | 0:e91ee0e99213 | 309 | strcat(hk_data,fdata); |
sakthipriya | 0:e91ee0e99213 | 310 | printf("\n\r hk data being sent %s ",hk_data); |
sakthipriya | 0:e91ee0e99213 | 311 | //for(int i=0;i<100000000000;i++) |
sakthipriya | 0:e91ee0e99213 | 312 | //; |
sakthipriya | 0:e91ee0e99213 | 313 | |
sakthipriya | 0:e91ee0e99213 | 314 | /*for(int d=0;d<23;d++) //was written just to check hk data |
sakthipriya | 0:e91ee0e99213 | 315 | { |
sakthipriya | 0:e91ee0e99213 | 316 | if(hk_data[d]>10) |
sakthipriya | 0:e91ee0e99213 | 317 | printf("\n\rhk data : %d\n\r",hk_data[d]); |
sakthipriya | 0:e91ee0e99213 | 318 | } */ |
sakthipriya | 0:e91ee0e99213 | 319 | |
sakthipriya | 0:e91ee0e99213 | 320 | //data = pcslave.getc(); |
sakthipriya | 0:e91ee0e99213 | 321 | |
sakthipriya | 0:e91ee0e99213 | 322 | i2c_status=1; |
sakthipriya | 0:e91ee0e99213 | 323 | i2c_data * i2c_data_s = i2c_data_send.alloc(); |
sakthipriya | 0:e91ee0e99213 | 324 | strcpy(i2c_data_s->data,hk_data); |
sakthipriya | 0:e91ee0e99213 | 325 | i2c_data_s->length = 25; |
sakthipriya | 0:e91ee0e99213 | 326 | i2c_data_send.put(i2c_data_s); |
sakthipriya | 0:e91ee0e99213 | 327 | data_ready=1; |
sakthipriya | 3:0931a8800543 | 328 | // i1.start(); |
sakthipriya | 0:e91ee0e99213 | 329 | //temp = i2c_status; |
sakthipriya | 0:e91ee0e99213 | 330 | } |
sakthipriya | 0:e91ee0e99213 | 331 | |
sakthipriya | 0:e91ee0e99213 | 332 | |
sakthipriya | 0:e91ee0e99213 | 333 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
sakthipriya | 0:e91ee0e99213 | 334 | //TELECOMMAND |
sakthipriya | 0:e91ee0e99213 | 335 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
sakthipriya | 0:e91ee0e99213 | 336 | void FUNC_I2C_TC_EXECUTE (char command) |
sakthipriya | 0:e91ee0e99213 | 337 | { switch(command) |
sakthipriya | 0:e91ee0e99213 | 338 | { case '0' : printf("command 0 executed"); |
sakthipriya | 0:e91ee0e99213 | 339 | break; |
sakthipriya | 0:e91ee0e99213 | 340 | case '1' : printf("command 1 executed"); |
sakthipriya | 0:e91ee0e99213 | 341 | break; |
sakthipriya | 0:e91ee0e99213 | 342 | case '2' : printf("command 2 executed"); |
sakthipriya | 0:e91ee0e99213 | 343 | break; |
sakthipriya | 0:e91ee0e99213 | 344 | case '3' : printf("command 3 executed"); |
sakthipriya | 0:e91ee0e99213 | 345 | } |
sakthipriya | 0:e91ee0e99213 | 346 | } |
sakthipriya | 0:e91ee0e99213 | 347 | |
sakthipriya | 0:e91ee0e99213 | 348 | |
sakthipriya | 0:e91ee0e99213 | 349 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
sakthipriya | 0:e91ee0e99213 | 350 | //SCHEDULER |
sakthipriya | 0:e91ee0e99213 | 351 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
sakthipriya | 0:e91ee0e99213 | 352 | int beacon_sc = 3; |
sakthipriya | 0:e91ee0e99213 | 353 | uint16_t schedcount=1; |
sakthipriya | 0:e91ee0e99213 | 354 | void T_SC(void const *args) |
sakthipriya | 0:e91ee0e99213 | 355 | { |
sakthipriya | 0:e91ee0e99213 | 356 | //DRDY=0; |
sakthipriya | 0:e91ee0e99213 | 357 | printf("The value of i in scheduler is %d\n\r",schedcount); |
sakthipriya | 0:e91ee0e99213 | 358 | if(schedcount == 65532) //to reset the counter |
sakthipriya | 0:e91ee0e99213 | 359 | { |
sakthipriya | 0:e91ee0e99213 | 360 | schedcount = 0; |
sakthipriya | 0:e91ee0e99213 | 361 | } |
sakthipriya | 0:e91ee0e99213 | 362 | |
sakthipriya | 0:e91ee0e99213 | 363 | if(schedcount%1==0) |
sakthipriya | 0:e91ee0e99213 | 364 | { |
sakthipriya | 3:0931a8800543 | 365 | //ptr_t_acs -> signal_set(0x1); |
sakthipriya | 0:e91ee0e99213 | 366 | //ptr_t_wdt -> signal_set(0x5); |
sakthipriya | 0:e91ee0e99213 | 367 | } |
sakthipriya | 0:e91ee0e99213 | 368 | if(schedcount%2==0) |
sakthipriya | 0:e91ee0e99213 | 369 | { |
sakthipriya | 0:e91ee0e99213 | 370 | // ptr_t_fault -> signal_set(0x2); |
raizel_varun | 2:3d9ca9554adf | 371 | ptr_t_hk_acq -> signal_set(0x2); |
sakthipriya | 0:e91ee0e99213 | 372 | |
sakthipriya | 0:e91ee0e99213 | 373 | } |
sakthipriya | 0:e91ee0e99213 | 374 | if(schedcount%beacon_sc==0) |
sakthipriya | 0:e91ee0e99213 | 375 | { |
sakthipriya | 0:e91ee0e99213 | 376 | if(beac_flag==0) |
sakthipriya | 0:e91ee0e99213 | 377 | { |
sakthipriya | 0:e91ee0e99213 | 378 | |
sakthipriya | 0:e91ee0e99213 | 379 | //ptr_t_bea -> signal_set(0x3); |
sakthipriya | 0:e91ee0e99213 | 380 | } |
sakthipriya | 0:e91ee0e99213 | 381 | } |
sakthipriya | 0:e91ee0e99213 | 382 | schedcount++; |
sakthipriya | 0:e91ee0e99213 | 383 | } |
sakthipriya | 0:e91ee0e99213 | 384 | |
sakthipriya | 0:e91ee0e99213 | 385 | //--------------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 386 | |
sakthipriya | 0:e91ee0e99213 | 387 | int main() |
sakthipriya | 0:e91ee0e99213 | 388 | { |
sakthipriya | 0:e91ee0e99213 | 389 | t1.start(); |
sakthipriya | 0:e91ee0e99213 | 390 | printf("\n\rIITMSAT BAE Activated \n"); |
sakthipriya | 3:0931a8800543 | 391 | //INIT_PNI(); // Initializing mnm blue |
sakthipriya | 3:0931a8800543 | 392 | //FUNC_ACS_MAG_INIT(); // Initializing magnetometer |
sakthipriya | 0:e91ee0e99213 | 393 | //FUNC_ACS_INIT_GYR(); // Initializing Gyroscope |
sakthipriya | 0:e91ee0e99213 | 394 | slave.address(0x20); // setting slave address for BAE for I2C communication |
sakthipriya | 3:0931a8800543 | 395 | //init_beacon(); |
sakthipriya | 0:e91ee0e99213 | 396 | ptr_t_hk_acq = new Thread(T_HK_ACQ); |
sakthipriya | 0:e91ee0e99213 | 397 | ptr_t_acs = new Thread(T_ACS); |
sakthipriya | 0:e91ee0e99213 | 398 | ptr_t_bea = new Thread(T_BEA); |
sakthipriya | 0:e91ee0e99213 | 399 | ptr_t_i2c = new Thread(T_I2C_BAE); |
sakthipriya | 0:e91ee0e99213 | 400 | //ptr_t_sc = new Thread(T_SC); |
sakthipriya | 0:e91ee0e99213 | 401 | ptr_t_wdt = new Thread(T_WDT); |
sakthipriya | 0:e91ee0e99213 | 402 | |
sakthipriya | 0:e91ee0e99213 | 403 | interrupt_fault(); // Dummy function called when a fault interrupt is detected |
sakthipriya | 0:e91ee0e99213 | 404 | |
sakthipriya | 0:e91ee0e99213 | 405 | ptr_t_acs->set_priority(osPriorityAboveNormal); |
sakthipriya | 0:e91ee0e99213 | 406 | ptr_t_i2c->set_priority(osPriorityHigh); |
sakthipriya | 0:e91ee0e99213 | 407 | ptr_t_hk_acq->set_priority(osPriorityAboveNormal); |
sakthipriya | 0:e91ee0e99213 | 408 | ptr_t_bea->set_priority(osPriorityAboveNormal); |
sakthipriya | 0:e91ee0e99213 | 409 | //ptr_t_sc->set_priority(osPriorityAboveNormal); |
sakthipriya | 0:e91ee0e99213 | 410 | ptr_t_wdt -> set_priority(osPriorityIdle); |
sakthipriya | 0:e91ee0e99213 | 411 | |
sakthipriya | 0:e91ee0e99213 | 412 | |
sakthipriya | 0:e91ee0e99213 | 413 | // ---------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 414 | printf("\n\r T_ACS priority is %d",ptr_t_acs->get_priority()); |
sakthipriya | 0:e91ee0e99213 | 415 | printf("\n\r T_HK_ACQ priority is %d",ptr_t_hk_acq->get_priority()); |
sakthipriya | 0:e91ee0e99213 | 416 | printf("\n\r T_BEA priority is %d",ptr_t_bea->get_priority()); |
sakthipriya | 0:e91ee0e99213 | 417 | RtosTimer t_sc_timer(T_SC,osTimerPeriodic); |
sakthipriya | 0:e91ee0e99213 | 418 | t_sc_timer.start(10000); |
sakthipriya | 0:e91ee0e99213 | 419 | printf("\n\r%f\n\r",t1.read()); |
sakthipriya | 0:e91ee0e99213 | 420 | |
raizel_varun | 2:3d9ca9554adf | 421 | interrupt.rise(&FUNC_I2C_INT); //interrupt received from CDMS |
sakthipriya | 0:e91ee0e99213 | 422 | while(1) //required to prevent main from terminating |
sakthipriya | 0:e91ee0e99213 | 423 | { |
sakthipriya | 0:e91ee0e99213 | 424 | Thread::wait(5000); |
sakthipriya | 0:e91ee0e99213 | 425 | } |
sakthipriya | 0:e91ee0e99213 | 426 | |
sakthipriya | 0:e91ee0e99213 | 427 | } |