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