pcb test start

Dependencies:   mbed-rtos mbed

Fork of BAE_hw_test1_5 by sakthi priya amirtharaj

Committer:
greenroshks
Date:
Mon Apr 06 15:53:24 2015 +0000
Revision:
9:7936b618a879
Parent:
8:6d856d863537
pcb test start

Who changed what in which revision?

UserRevisionLine numberNew contents of line
raizel_varun 0:ebdf4f859dca 1 #include "mbed.h"
raizel_varun 0:ebdf4f859dca 2 #include "rtos.h"
raizel_varun 0:ebdf4f859dca 3 #include "HK.h"
raizel_varun 0:ebdf4f859dca 4 #include "slave.h"
raizel_varun 0:ebdf4f859dca 5 #include "beacon.h"
raizel_varun 0:ebdf4f859dca 6 #include "ACS.h"
raizel_varun 0:ebdf4f859dca 7 #include "fault.h"
raizel_varun 0:ebdf4f859dca 8 #include "slave.h"
sakthipriya 5:4199c0dfed33 9 #include "mnm.h"
greenroshks 9:7936b618a879 10 #include "pin_config.h"
raizel_varun 0:ebdf4f859dca 11
raizel_varun 0:ebdf4f859dca 12 Serial pc(USBTX, USBRX);
raizel_varun 0:ebdf4f859dca 13
greenroshks 2:edd107ea4740 14 //extern DigitalOut DRDY;
raizel_varun 0:ebdf4f859dca 15 InterruptIn interrupt(D9);
raizel_varun 0:ebdf4f859dca 16 InterruptIn master_reset(D8);
raizel_varun 0:ebdf4f859dca 17
raizel_varun 0:ebdf4f859dca 18
raizel_varun 0:ebdf4f859dca 19 Timer t; //To know the time of execution each thread
raizel_varun 0:ebdf4f859dca 20 Timer t1;
raizel_varun 0:ebdf4f859dca 21 //To know the time of entering of each thread
sakthipriya 3:20647ff68b3c 22 Timer t2;
sakthipriya 3:20647ff68b3c 23 Timer t3;
sakthipriya 3:20647ff68b3c 24 Timer t4;
raizel_varun 0:ebdf4f859dca 25
raizel_varun 0:ebdf4f859dca 26
raizel_varun 0:ebdf4f859dca 27
raizel_varun 0:ebdf4f859dca 28
raizel_varun 0:ebdf4f859dca 29
raizel_varun 0:ebdf4f859dca 30
raizel_varun 0:ebdf4f859dca 31 Thread *ptr_t_hk_acq;
raizel_varun 0:ebdf4f859dca 32 Thread *ptr_t_acs;
raizel_varun 0:ebdf4f859dca 33 //Thread *ptr_t_acs_write2flash;
raizel_varun 0:ebdf4f859dca 34 Thread *ptr_t_bea;
raizel_varun 0:ebdf4f859dca 35 //Thread *ptr_t_bea_telecommand;
raizel_varun 0:ebdf4f859dca 36 //Thread *ptr_t_fault;
raizel_varun 0:ebdf4f859dca 37 Thread *ptr_t_i2c;
raizel_varun 0:ebdf4f859dca 38 Thread *ptr_t_wdt;
raizel_varun 0:ebdf4f859dca 39
raizel_varun 0:ebdf4f859dca 40
raizel_varun 0:ebdf4f859dca 41
raizel_varun 0:ebdf4f859dca 42 I2CSlave slave(D14,D15); //configuring pins p27, p28 as I2Cslave
raizel_varun 0:ebdf4f859dca 43
raizel_varun 0:ebdf4f859dca 44
raizel_varun 0:ebdf4f859dca 45 DigitalOut data_ready(D10);
raizel_varun 0:ebdf4f859dca 46 int i2c_status=0; //read/write mode for i2c 0 : write2slave, 1 : write2master
raizel_varun 0:ebdf4f859dca 47 int reset=0;
raizel_varun 0:ebdf4f859dca 48 int temp;
raizel_varun 0:ebdf4f859dca 49
raizel_varun 0:ebdf4f859dca 50 typedef struct
raizel_varun 0:ebdf4f859dca 51 {
raizel_varun 0:ebdf4f859dca 52 char data[25]; // To avoid dynamic memory allocation
raizel_varun 0:ebdf4f859dca 53 int length;
raizel_varun 0:ebdf4f859dca 54 }i2c_data;
raizel_varun 0:ebdf4f859dca 55
raizel_varun 0:ebdf4f859dca 56
raizel_varun 0:ebdf4f859dca 57
raizel_varun 0:ebdf4f859dca 58
raizel_varun 0:ebdf4f859dca 59
raizel_varun 0:ebdf4f859dca 60
raizel_varun 0:ebdf4f859dca 61 //Mail<i2c_data,16> i2c_data_receive;
raizel_varun 0:ebdf4f859dca 62 Mail<i2c_data,16> i2c_data_send;
raizel_varun 0:ebdf4f859dca 63
raizel_varun 0:ebdf4f859dca 64 //--------------------------------------------------------------------------------------------------------------------------------------------------
raizel_varun 0:ebdf4f859dca 65 //TASK 2 : HK
raizel_varun 0:ebdf4f859dca 66 //--------------------------------------------------------------------------------------------------------------------------------------------------
raizel_varun 0:ebdf4f859dca 67
raizel_varun 0:ebdf4f859dca 68 char hk_data[25];
raizel_varun 0:ebdf4f859dca 69 extern SensorDataQuantised SensorQuantised;
raizel_varun 0:ebdf4f859dca 70 void T_HK_ACQ(void const *args)
raizel_varun 0:ebdf4f859dca 71 {
raizel_varun 0:ebdf4f859dca 72
raizel_varun 0:ebdf4f859dca 73 while(1)
raizel_varun 0:ebdf4f859dca 74 {
raizel_varun 0:ebdf4f859dca 75 Thread::signal_wait(0x2);
greenroshks 2:edd107ea4740 76 SensorQuantised.power_mode='3';
sakthipriya 3:20647ff68b3c 77 printf("\n\rTHIS IS HK %f\n\r",t1.read());
raizel_varun 0:ebdf4f859dca 78 t.start();
raizel_varun 0:ebdf4f859dca 79 FUNC_HK_FAULTS();
raizel_varun 0:ebdf4f859dca 80 FUNC_HK_POWER(SensorQuantised.power_mode); //The power mode algorithm is yet to be obtained
raizel_varun 0:ebdf4f859dca 81 FUNC_HK_MAIN(); //Collecting HK data
raizel_varun 0:ebdf4f859dca 82 //thread_2.signal_set(0x4);
raizel_varun 0:ebdf4f859dca 83 //FUNC_I2C_SLAVE_MAIN(25);
raizel_varun 0:ebdf4f859dca 84 FUNC_I2C_IR2CDMS();
raizel_varun 0:ebdf4f859dca 85 t.stop();
sakthipriya 3:20647ff68b3c 86 printf("The time to execute hk_acq is %f seconds\n\r",t.read());
raizel_varun 0:ebdf4f859dca 87 t.reset();
raizel_varun 0:ebdf4f859dca 88 }
raizel_varun 0:ebdf4f859dca 89 }
raizel_varun 0:ebdf4f859dca 90
raizel_varun 0:ebdf4f859dca 91 //---------------------------------------------------------------------------------------------------------------------------------------
raizel_varun 0:ebdf4f859dca 92 //TASK 1 : ACS
raizel_varun 0:ebdf4f859dca 93 //---------------------------------------------------------------------------------------------------------------------------------------
raizel_varun 0:ebdf4f859dca 94
raizel_varun 0:ebdf4f859dca 95 int acs_pflag = 1;
raizel_varun 0:ebdf4f859dca 96 void T_ACS(void const *args)
raizel_varun 0:ebdf4f859dca 97 {
raizel_varun 0:ebdf4f859dca 98 float *mag_field;
raizel_varun 0:ebdf4f859dca 99 float *omega;
sakthipriya 8:6d856d863537 100 float mag_field1[3];
sakthipriya 8:6d856d863537 101 float omega1[1];
sakthipriya 8:6d856d863537 102 float tauc1[3];
sakthipriya 8:6d856d863537 103 float moment[3];
sakthipriya 5:4199c0dfed33 104 float *mnm_data;
raizel_varun 0:ebdf4f859dca 105 while(1)
raizel_varun 0:ebdf4f859dca 106 {
raizel_varun 0:ebdf4f859dca 107 Thread::signal_wait(0x1);
sakthipriya 3:20647ff68b3c 108 printf("\n\rTHIS IS ACS %f\n\r",t1.read());
raizel_varun 0:ebdf4f859dca 109 t.start();
raizel_varun 0:ebdf4f859dca 110 mag_field= FUNC_ACS_MAG_EXEC(); //actual execution
greenroshks 9:7936b618a879 111 //omega = FUNC_ACS_EXEC_GYR();
greenroshks 9:7936b618a879 112 //printf("\n\r gyr 1 value %f",omega[0]);
sakthipriya 5:4199c0dfed33 113 mnm_data=EXECUTE_PNI(); //the angular velocity is stored in the first 3 values and magnetic field values in next 3
sakthipriya 5:4199c0dfed33 114 printf("\n\rmnm gyro values\n"); //printing the angular velocity and magnetic field values
sakthipriya 5:4199c0dfed33 115 for(int i=0; i<3; i++)
sakthipriya 5:4199c0dfed33 116 {
sakthipriya 5:4199c0dfed33 117 printf("%f\t",mnm_data[i]);
sakthipriya 5:4199c0dfed33 118 }
sakthipriya 5:4199c0dfed33 119 printf("\n\r mnm mag values\n");
sakthipriya 5:4199c0dfed33 120 for(int i=3; i<6; i++) {
sakthipriya 5:4199c0dfed33 121 printf("%f\t",mnm_data[i]);
sakthipriya 5:4199c0dfed33 122 }
greenroshks 9:7936b618a879 123 /*for(int i = 0 ; i<3;i++)
sakthipriya 6:1cdbda747f99 124 {
sakthipriya 8:6d856d863537 125 omega1[i] = mnm_data[i];
sakthipriya 6:1cdbda747f99 126 }
sakthipriya 6:1cdbda747f99 127 for( int i = 3;i<6;i++)
sakthipriya 6:1cdbda747f99 128 {
sakthipriya 8:6d856d863537 129 mag_field1[i-3] = mnm_data[i];
greenroshks 9:7936b618a879 130 }*/
greenroshks 9:7936b618a879 131 acs_pflag =1; //to be changed later 5/4/15
greenroshks 9:7936b618a879 132 omega1[0] = 1;
greenroshks 9:7936b618a879 133 omega1[1] = 1;
greenroshks 9:7936b618a879 134 omega1[2] = 1;
greenroshks 9:7936b618a879 135 mag_field[0] = -38;
greenroshks 9:7936b618a879 136 mag_field[1] = 1;
greenroshks 9:7936b618a879 137 mag_field[2] = 5;
raizel_varun 0:ebdf4f859dca 138 if(acs_pflag == 1)
raizel_varun 0:ebdf4f859dca 139 {
greenroshks 9:7936b618a879 140 FUNC_ACS_CNTRLALGO(mag_field,omega1,tauc1); //mag field to be in micro tesla
sakthipriya 8:6d856d863537 141 printf("\n\r control algo values ");
sakthipriya 8:6d856d863537 142 for(int i=0; i<3; i++)
sakthipriya 8:6d856d863537 143 {
sakthipriya 8:6d856d863537 144 printf("%f\t",tauc1[i]);
sakthipriya 8:6d856d863537 145 }
sakthipriya 8:6d856d863537 146 moment_calc (tauc1, mag_field1,moment);
sakthipriya 8:6d856d863537 147 printf("\n\r moment values ");
sakthipriya 8:6d856d863537 148 for(int i=0; i<3; i++)
sakthipriya 8:6d856d863537 149 {
sakthipriya 8:6d856d863537 150 printf("%f\t",moment[i]);
sakthipriya 8:6d856d863537 151 }
sakthipriya 8:6d856d863537 152
raizel_varun 0:ebdf4f859dca 153 FUNC_ACS_GENPWM(moment);
raizel_varun 0:ebdf4f859dca 154 }
raizel_varun 0:ebdf4f859dca 155
raizel_varun 0:ebdf4f859dca 156 t.reset();
raizel_varun 0:ebdf4f859dca 157 }
greenroshks 9:7936b618a879 158 }
greenroshks 9:7936b618a879 159 /*
raizel_varun 0:ebdf4f859dca 160 void T_ACS_WRITE2FLASH(void const *args)
raizel_varun 0:ebdf4f859dca 161 {
raizel_varun 0:ebdf4f859dca 162 while(1)
raizel_varun 0:ebdf4f859dca 163 {
sakthipriya 3:20647ff68b3c 164 //printf("Writing in the flash\n\r");
raizel_varun 0:ebdf4f859dca 165 osEvent evt = q_acs.get();
raizel_varun 0:ebdf4f859dca 166 if(evt.status == osEventMail)
raizel_varun 0:ebdf4f859dca 167 {
raizel_varun 0:ebdf4f859dca 168 sensor_data *ptr = (sensor_data*)evt.value.p;
raizel_varun 0:ebdf4f859dca 169 FUNC_ACS_WRITE2FLASH(ptr);
raizel_varun 0:ebdf4f859dca 170 q_acs.free(ptr);
raizel_varun 0:ebdf4f859dca 171 }
sakthipriya 3:20647ff68b3c 172 printf("Writing acs data in the flash\n\r");
raizel_varun 0:ebdf4f859dca 173 }
raizel_varun 0:ebdf4f859dca 174 }
raizel_varun 0:ebdf4f859dca 175
raizel_varun 0:ebdf4f859dca 176 */
raizel_varun 0:ebdf4f859dca 177 //---------------------------------------------------BEACON--------------------------------------------------------------------------------------------
raizel_varun 0:ebdf4f859dca 178
raizel_varun 0:ebdf4f859dca 179 int beac_flag=0; //To receive telecommand from ground.
raizel_varun 0:ebdf4f859dca 180
raizel_varun 0:ebdf4f859dca 181
raizel_varun 0:ebdf4f859dca 182 /*void T_BEA_TELECOMMAND(void const *args)
raizel_varun 0:ebdf4f859dca 183 {
raizel_varun 0:ebdf4f859dca 184 char c = pc.getc();
raizel_varun 0:ebdf4f859dca 185 if(c=='a')
raizel_varun 0:ebdf4f859dca 186 {
sakthipriya 3:20647ff68b3c 187 printf("Telecommand detected\n\r");
raizel_varun 0:ebdf4f859dca 188 beac_flag=1;
raizel_varun 0:ebdf4f859dca 189 }
raizel_varun 0:ebdf4f859dca 190 }
raizel_varun 0:ebdf4f859dca 191 */
raizel_varun 0:ebdf4f859dca 192
raizel_varun 0:ebdf4f859dca 193 void T_BEA(void const *args)
raizel_varun 0:ebdf4f859dca 194 {
raizel_varun 0:ebdf4f859dca 195
raizel_varun 0:ebdf4f859dca 196 while(1)
raizel_varun 0:ebdf4f859dca 197 {
raizel_varun 0:ebdf4f859dca 198 Thread::signal_wait(0x3);
sakthipriya 3:20647ff68b3c 199 printf("\n\rTHIS IS BEACON %f\n\r",t1.read());
raizel_varun 0:ebdf4f859dca 200 t.start();
raizel_varun 0:ebdf4f859dca 201
raizel_varun 0:ebdf4f859dca 202
raizel_varun 0:ebdf4f859dca 203
raizel_varun 0:ebdf4f859dca 204 FUNC_BEA();
raizel_varun 0:ebdf4f859dca 205
raizel_varun 0:ebdf4f859dca 206
raizel_varun 0:ebdf4f859dca 207 if(beac_flag==1)
raizel_varun 0:ebdf4f859dca 208 {
raizel_varun 0:ebdf4f859dca 209 Thread::wait(600000);
raizel_varun 0:ebdf4f859dca 210 beac_flag = 0;
raizel_varun 0:ebdf4f859dca 211 }
raizel_varun 0:ebdf4f859dca 212
sakthipriya 3:20647ff68b3c 213 printf("The time to execute beacon thread is %f seconds\n\r",t.read());
raizel_varun 0:ebdf4f859dca 214 t.reset();
raizel_varun 0:ebdf4f859dca 215 }
raizel_varun 0:ebdf4f859dca 216 }
raizel_varun 0:ebdf4f859dca 217
raizel_varun 0:ebdf4f859dca 218 //---------------------------------------------------------------------------------------------------------------------------------------------------
raizel_varun 0:ebdf4f859dca 219 //TASK 4 : FAULT MANAGEMENT
raizel_varun 0:ebdf4f859dca 220 //---------------------------------------------------------------------------------------------------------------------------------------------------
raizel_varun 0:ebdf4f859dca 221 //Dummy fault rectifier functions
raizel_varun 0:ebdf4f859dca 222
raizel_varun 0:ebdf4f859dca 223 extern SensorDataQuantised SensorQuantised;
raizel_varun 0:ebdf4f859dca 224
raizel_varun 0:ebdf4f859dca 225
raizel_varun 0:ebdf4f859dca 226 /*void T_FAULT(void const *args)
raizel_varun 0:ebdf4f859dca 227 {
raizel_varun 0:ebdf4f859dca 228 Sensor.power_mode='0';
raizel_varun 0:ebdf4f859dca 229 while(1)
raizel_varun 0:ebdf4f859dca 230 {
raizel_varun 0:ebdf4f859dca 231 Thread :: signal_wait(0x2);
raizel_varun 0:ebdf4f859dca 232 FAULTS();
raizel_varun 0:ebdf4f859dca 233 POWER(Sensor.power_mode);
raizel_varun 0:ebdf4f859dca 234 //Sensor.power_mode++; //testing ... should be removed
raizel_varun 0:ebdf4f859dca 235 }
raizel_varun 0:ebdf4f859dca 236 }
raizel_varun 0:ebdf4f859dca 237 */
raizel_varun 0:ebdf4f859dca 238 /*-------------------------------------------------------------------------------------------------------------------------------------------
raizel_varun 0:ebdf4f859dca 239 -------------------------------------------------------WATCHDOG----------------------------------------------------------------------------*/
raizel_varun 0:ebdf4f859dca 240 DigitalOut trigger(PIN63); // has to be changed
raizel_varun 0:ebdf4f859dca 241 void T_WDT(void const * args)
raizel_varun 0:ebdf4f859dca 242 {
raizel_varun 0:ebdf4f859dca 243 trigger = 1;
raizel_varun 0:ebdf4f859dca 244 while(true)
raizel_varun 0:ebdf4f859dca 245 {
raizel_varun 0:ebdf4f859dca 246 Thread::signal_wait(0x5); //signal set from scheduler or sthing. r RTOS timer nce the timing is finalized
sakthipriya 3:20647ff68b3c 247 printf("\n\rEntered WD\n\r");
raizel_varun 0:ebdf4f859dca 248 trigger = !trigger;
raizel_varun 0:ebdf4f859dca 249 }
raizel_varun 0:ebdf4f859dca 250 }
raizel_varun 0:ebdf4f859dca 251
raizel_varun 0:ebdf4f859dca 252 //---------------------------------------------------------------------------------------------------------------------------------------------------
raizel_varun 0:ebdf4f859dca 253 //TASK 5 : i2c data
raizel_varun 0:ebdf4f859dca 254 //---------------------------------------------------------------------------------------------------------------------------------------------------
raizel_varun 0:ebdf4f859dca 255
raizel_varun 0:ebdf4f859dca 256
raizel_varun 0:ebdf4f859dca 257
raizel_varun 0:ebdf4f859dca 258
raizel_varun 0:ebdf4f859dca 259
raizel_varun 0:ebdf4f859dca 260
raizel_varun 0:ebdf4f859dca 261 void FUNC_I2C_WRITE2CDMS(char *data, int length=1)
raizel_varun 0:ebdf4f859dca 262 {
raizel_varun 0:ebdf4f859dca 263 int slave_status = 1;
sakthipriya 4:b33bc4267e0d 264 //t2.stop();
sakthipriya 3:20647ff68b3c 265 if(interrupt ==1)
sakthipriya 3:20647ff68b3c 266 {
sakthipriya 3:20647ff68b3c 267
sakthipriya 3:20647ff68b3c 268 if(slave.receive() == 0)
sakthipriya 3:20647ff68b3c 269 t2.stop();
sakthipriya 4:b33bc4267e0d 270 //t4.stop();
sakthipriya 4:b33bc4267e0d 271 //printf("\n\r %d ",slave.receive());
sakthipriya 3:20647ff68b3c 272 if( slave.receive()==1)
sakthipriya 3:20647ff68b3c 273 {
sakthipriya 3:20647ff68b3c 274 t2.stop();
sakthipriya 6:1cdbda747f99 275
sakthipriya 3:20647ff68b3c 276 slave_status=slave.write(data,length);
sakthipriya 6:1cdbda747f99 277 t3.stop();
sakthipriya 3:20647ff68b3c 278
sakthipriya 3:20647ff68b3c 279 }
sakthipriya 3:20647ff68b3c 280 else if( slave.receive()==3 || slave.receive()==2)
raizel_varun 0:ebdf4f859dca 281 {
sakthipriya 3:20647ff68b3c 282 t2.stop();
sakthipriya 3:20647ff68b3c 283 //t3.start();
sakthipriya 3:20647ff68b3c 284 slave_status=slave.read(data,length);
sakthipriya 6:1cdbda747f99 285 t3.stop();
raizel_varun 0:ebdf4f859dca 286 }
sakthipriya 3:20647ff68b3c 287
raizel_varun 0:ebdf4f859dca 288
raizel_varun 0:ebdf4f859dca 289 }
sakthipriya 3:20647ff68b3c 290
sakthipriya 3:20647ff68b3c 291 printf("\n\r%d\r",t2.read_us());
sakthipriya 3:20647ff68b3c 292 t2.reset();
sakthipriya 6:1cdbda747f99 293 printf("\n\r%d\r",t3.read_us());
sakthipriya 6:1cdbda747f99 294 t3.reset();
sakthipriya 3:20647ff68b3c 295
raizel_varun 0:ebdf4f859dca 296 }
sakthipriya 3:20647ff68b3c 297
raizel_varun 0:ebdf4f859dca 298 char data_send[25],data_receive;
raizel_varun 0:ebdf4f859dca 299 void T_I2C_BAE(void const * args)
raizel_varun 0:ebdf4f859dca 300 {
raizel_varun 0:ebdf4f859dca 301 //char data_send,data_receive;
raizel_varun 0:ebdf4f859dca 302 while(1)
raizel_varun 0:ebdf4f859dca 303 {
raizel_varun 0:ebdf4f859dca 304 Thread::signal_wait(0x4);
sakthipriya 3:20647ff68b3c 305 // printf("\n\r entered thread");
sakthipriya 1:deb3c0fafa3a 306 if(i2c_status == 0 )
raizel_varun 0:ebdf4f859dca 307 {
sakthipriya 4:b33bc4267e0d 308 wait_ms(20);
raizel_varun 0:ebdf4f859dca 309 FUNC_I2C_WRITE2CDMS(&data_receive,1);
sakthipriya 3:20647ff68b3c 310
raizel_varun 0:ebdf4f859dca 311 /*i2c_data * i2c_data_r = i2c_data_receive.alloc();
raizel_varun 0:ebdf4f859dca 312 i2c_data_r->data = data_receive;
raizel_varun 0:ebdf4f859dca 313 i2c_data_r->length = 1;
raizel_varun 0:ebdf4f859dca 314 i2c_data_receive.put(i2c_data_r);*/
sakthipriya 3:20647ff68b3c 315 printf("\n\r Data received from CDMS is %c \n\r",data_receive);
raizel_varun 0:ebdf4f859dca 316 FUNC_I2C_TC_EXECUTE(data_receive); // This has to be done from a differen thread
raizel_varun 0:ebdf4f859dca 317
raizel_varun 0:ebdf4f859dca 318 }
sakthipriya 1:deb3c0fafa3a 319 else if(i2c_status ==1)
raizel_varun 0:ebdf4f859dca 320 {
raizel_varun 0:ebdf4f859dca 321 osEvent evt = i2c_data_send.get();
raizel_varun 0:ebdf4f859dca 322 if (evt.status == osEventMail)
raizel_varun 0:ebdf4f859dca 323 {
raizel_varun 0:ebdf4f859dca 324 i2c_data *i2c_data_s = (i2c_data*)evt.value.p;
raizel_varun 0:ebdf4f859dca 325 strcpy(data_send,i2c_data_s -> data);
sakthipriya 3:20647ff68b3c 326 wait_ms(29);
raizel_varun 0:ebdf4f859dca 327 FUNC_I2C_WRITE2CDMS(data_send,25);
sakthipriya 3:20647ff68b3c 328 printf("\n\rData sent to CDMS is %s\n\r",data_send);
raizel_varun 0:ebdf4f859dca 329 i2c_data_send.free(i2c_data_s);
raizel_varun 0:ebdf4f859dca 330 i2c_status = 0;
sakthipriya 3:20647ff68b3c 331
raizel_varun 0:ebdf4f859dca 332
raizel_varun 0:ebdf4f859dca 333 }
raizel_varun 0:ebdf4f859dca 334 }
raizel_varun 0:ebdf4f859dca 335
raizel_varun 0:ebdf4f859dca 336 }
raizel_varun 0:ebdf4f859dca 337 }
raizel_varun 0:ebdf4f859dca 338
raizel_varun 0:ebdf4f859dca 339
raizel_varun 0:ebdf4f859dca 340
raizel_varun 0:ebdf4f859dca 341 void FUNC_I2C_INT()
raizel_varun 0:ebdf4f859dca 342 {
sakthipriya 3:20647ff68b3c 343
sakthipriya 3:20647ff68b3c 344 t2.start();
sakthipriya 6:1cdbda747f99 345 // t3.start();
raizel_varun 0:ebdf4f859dca 346 ptr_t_i2c->signal_set(0x4);
raizel_varun 0:ebdf4f859dca 347
raizel_varun 0:ebdf4f859dca 348
raizel_varun 0:ebdf4f859dca 349 }
raizel_varun 0:ebdf4f859dca 350
raizel_varun 0:ebdf4f859dca 351 void FUNC_I2C_IR2CDMS()
raizel_varun 0:ebdf4f859dca 352 {
sakthipriya 3:20647ff68b3c 353 data_ready=0;
raizel_varun 0:ebdf4f859dca 354 //char data[25];
raizel_varun 0:ebdf4f859dca 355 //strcpy(data,"sakthi ");
raizel_varun 0:ebdf4f859dca 356 //strcat(data,"priya");
raizel_varun 0:ebdf4f859dca 357 strcpy(hk_data,SensorQuantised.Voltage);
raizel_varun 0:ebdf4f859dca 358 strcat(hk_data,SensorQuantised.Current);
raizel_varun 0:ebdf4f859dca 359 strcat(hk_data,SensorQuantised.Temperature);
raizel_varun 0:ebdf4f859dca 360 strcat(hk_data,SensorQuantised.PanelTemperature);
raizel_varun 0:ebdf4f859dca 361 strcat(hk_data,SensorQuantised.AngularSpeed);
raizel_varun 0:ebdf4f859dca 362 strcat(hk_data,SensorQuantised.Bnewvalue);
raizel_varun 0:ebdf4f859dca 363 char fdata[5] = {SensorQuantised.BatteryTemperature,SensorQuantised.faultpoll,SensorQuantised.faultir,SensorQuantised.power_mode};
raizel_varun 0:ebdf4f859dca 364
raizel_varun 0:ebdf4f859dca 365 /*strcat(hk_data,sfaultpoll);
raizel_varun 0:ebdf4f859dca 366 strcat(hk_data,sfaultir);
raizel_varun 0:ebdf4f859dca 367 strcat(hk_data,spower_mode);*/
raizel_varun 0:ebdf4f859dca 368 strcat(hk_data,fdata);
sakthipriya 3:20647ff68b3c 369 printf("\n\rhk data : %s\n\r",hk_data);
sakthipriya 3:20647ff68b3c 370
raizel_varun 0:ebdf4f859dca 371 //data = pcslave.getc();
raizel_varun 0:ebdf4f859dca 372 reset =0;
raizel_varun 0:ebdf4f859dca 373 i2c_status=1;
raizel_varun 0:ebdf4f859dca 374 i2c_data * i2c_data_s = i2c_data_send.alloc();
raizel_varun 0:ebdf4f859dca 375 strcpy(i2c_data_s->data,hk_data);
raizel_varun 0:ebdf4f859dca 376 i2c_data_s->length = 25;
raizel_varun 0:ebdf4f859dca 377 i2c_data_send.put(i2c_data_s);
raizel_varun 0:ebdf4f859dca 378 data_ready=1;
raizel_varun 0:ebdf4f859dca 379 //temp = i2c_status;
raizel_varun 0:ebdf4f859dca 380 }
sakthipriya 5:4199c0dfed33 381
raizel_varun 0:ebdf4f859dca 382
raizel_varun 0:ebdf4f859dca 383 //------------------------------------------------------------------------------------------------------------------------------------------------
raizel_varun 0:ebdf4f859dca 384 //TELECOMMAND
raizel_varun 0:ebdf4f859dca 385 //------------------------------------------------------------------------------------------------------------------------------------------------
raizel_varun 0:ebdf4f859dca 386 void FUNC_I2C_TC_EXECUTE (char command)
raizel_varun 0:ebdf4f859dca 387 { switch(command)
raizel_varun 0:ebdf4f859dca 388 { case '0' : printf("command 0 executed");
raizel_varun 0:ebdf4f859dca 389 break;
raizel_varun 0:ebdf4f859dca 390 case '1' : printf("command 1 executed");
raizel_varun 0:ebdf4f859dca 391 break;
raizel_varun 0:ebdf4f859dca 392 case '2' : printf("command 2 executed");
raizel_varun 0:ebdf4f859dca 393 break;
raizel_varun 0:ebdf4f859dca 394 case '3' : printf("command 3 executed");
raizel_varun 0:ebdf4f859dca 395 }
raizel_varun 0:ebdf4f859dca 396 }
raizel_varun 0:ebdf4f859dca 397
raizel_varun 0:ebdf4f859dca 398
raizel_varun 0:ebdf4f859dca 399 //------------------------------------------------------------------------------------------------------------------------------------------------
raizel_varun 0:ebdf4f859dca 400 //SCHEDULER
raizel_varun 0:ebdf4f859dca 401 //------------------------------------------------------------------------------------------------------------------------------------------------
raizel_varun 0:ebdf4f859dca 402 int beacon_sc = 3;
raizel_varun 0:ebdf4f859dca 403 uint16_t schedcount=1;
raizel_varun 0:ebdf4f859dca 404 void T_SC(void const *args)
raizel_varun 0:ebdf4f859dca 405 {
greenroshks 2:edd107ea4740 406 //DRDY=0;
sakthipriya 3:20647ff68b3c 407 printf("The value of i in scheduler is %d\n\r",schedcount);
raizel_varun 0:ebdf4f859dca 408 if(schedcount == 65532) //to reset the counter
raizel_varun 0:ebdf4f859dca 409 {
raizel_varun 0:ebdf4f859dca 410 schedcount = 0;
raizel_varun 0:ebdf4f859dca 411 }
raizel_varun 0:ebdf4f859dca 412
raizel_varun 0:ebdf4f859dca 413 if(schedcount%1==0)
raizel_varun 0:ebdf4f859dca 414 {
sakthipriya 3:20647ff68b3c 415 ptr_t_acs -> signal_set(0x1);
greenroshks 9:7936b618a879 416 // ptr_t_wdt -> signal_set(0x5);
raizel_varun 0:ebdf4f859dca 417 }
raizel_varun 0:ebdf4f859dca 418 if(schedcount%2==0)
raizel_varun 0:ebdf4f859dca 419 {
sakthipriya 3:20647ff68b3c 420 // ptr_t_fault -> signal_set(0x2);
greenroshks 9:7936b618a879 421 // ptr_t_hk_acq -> signal_set(0x2);
raizel_varun 0:ebdf4f859dca 422
raizel_varun 0:ebdf4f859dca 423 }
raizel_varun 0:ebdf4f859dca 424 if(schedcount%beacon_sc==0)
raizel_varun 0:ebdf4f859dca 425 {
raizel_varun 0:ebdf4f859dca 426 if(beac_flag==0)
raizel_varun 0:ebdf4f859dca 427 {
raizel_varun 0:ebdf4f859dca 428
greenroshks 9:7936b618a879 429 // ptr_t_bea -> signal_set(0x3);
raizel_varun 0:ebdf4f859dca 430 }
raizel_varun 0:ebdf4f859dca 431 }
raizel_varun 0:ebdf4f859dca 432 schedcount++;
raizel_varun 0:ebdf4f859dca 433 }
raizel_varun 0:ebdf4f859dca 434
raizel_varun 0:ebdf4f859dca 435 //---------------------------------------------------------------------------------------------------------------------------------------------
raizel_varun 0:ebdf4f859dca 436
raizel_varun 0:ebdf4f859dca 437 int main()
raizel_varun 0:ebdf4f859dca 438 {
raizel_varun 0:ebdf4f859dca 439 t1.start();
sakthipriya 7:603c2a89effc 440
greenroshks 2:edd107ea4740 441 //DRDY=0;
sakthipriya 5:4199c0dfed33 442 printf("\nahoy\n");
sakthipriya 5:4199c0dfed33 443 INIT_PNI();
sakthipriya 5:4199c0dfed33 444
raizel_varun 0:ebdf4f859dca 445 FUNC_ACS_MAG_INIT();
greenroshks 9:7936b618a879 446 //FUNC_ACS_INIT_GYR();
sakthipriya 7:603c2a89effc 447 slave.address(0x20);
raizel_varun 0:ebdf4f859dca 448
raizel_varun 0:ebdf4f859dca 449 ptr_t_hk_acq = new Thread(T_HK_ACQ);
raizel_varun 0:ebdf4f859dca 450 ptr_t_acs = new Thread(T_ACS);
raizel_varun 0:ebdf4f859dca 451 //ptr_t_acs_write2flash = new Thread(T_ACS_WRITE2FLASH);
raizel_varun 0:ebdf4f859dca 452 ptr_t_bea = new Thread(T_BEA);
raizel_varun 0:ebdf4f859dca 453 //ptr_t_bea_telecommand = new Thread(T_BEA_TELECOMMAND);
raizel_varun 0:ebdf4f859dca 454 //ptr_t_fault = new Thread(T_FAULT);
raizel_varun 0:ebdf4f859dca 455 ptr_t_i2c = new Thread(T_I2C_BAE);
raizel_varun 0:ebdf4f859dca 456 //ptr_t_sc = new Thread(T_SC);
raizel_varun 0:ebdf4f859dca 457 ptr_t_wdt = new Thread(T_WDT);
raizel_varun 0:ebdf4f859dca 458
greenroshks 9:7936b618a879 459 //interrupt_fault();
raizel_varun 0:ebdf4f859dca 460
raizel_varun 0:ebdf4f859dca 461 //ptr_t_fault -> set_priority(osPriorityRealtime);
raizel_varun 0:ebdf4f859dca 462 ptr_t_acs->set_priority(osPriorityAboveNormal);
raizel_varun 0:ebdf4f859dca 463 ptr_t_i2c->set_priority(osPriorityHigh);
raizel_varun 0:ebdf4f859dca 464 ptr_t_hk_acq->set_priority(osPriorityAboveNormal);
raizel_varun 0:ebdf4f859dca 465 //ptr_t_acs_write2flash->set_priority(osPriorityBelowNormal);
raizel_varun 0:ebdf4f859dca 466 ptr_t_bea->set_priority(osPriorityAboveNormal);
raizel_varun 0:ebdf4f859dca 467 //ptr_t_bea_telecommand->set_priority(osPriorityIdle);
raizel_varun 0:ebdf4f859dca 468 //ptr_t_sc->set_priority(osPriorityAboveNormal);
raizel_varun 0:ebdf4f859dca 469 ptr_t_wdt -> set_priority(osPriorityIdle);
raizel_varun 0:ebdf4f859dca 470
raizel_varun 0:ebdf4f859dca 471
raizel_varun 0:ebdf4f859dca 472 // ----------------------------------------------------------------------------------------------
sakthipriya 3:20647ff68b3c 473 //printf("\n\r T_FAULT priority is %d",ptr_t_fault->get_priority());
sakthipriya 3:20647ff68b3c 474 printf("\n\r T_ACS priority is %d",ptr_t_acs->get_priority());
sakthipriya 3:20647ff68b3c 475 printf("\n\r T_HK_ACQ priority is %d",ptr_t_hk_acq->get_priority());
sakthipriya 3:20647ff68b3c 476 //printf("\n\r T_ACS_WRITE2FLASH priority is %d",ptr_t_acs_write2flash->get_priority());
sakthipriya 3:20647ff68b3c 477 printf("\n\r T_BEA priority is %d",ptr_t_bea->get_priority());
raizel_varun 0:ebdf4f859dca 478 RtosTimer t_sc_timer(T_SC,osTimerPeriodic);
raizel_varun 0:ebdf4f859dca 479 t_sc_timer.start(10000);
sakthipriya 3:20647ff68b3c 480 printf("\n\r%f\n\r",t1.read());
raizel_varun 0:ebdf4f859dca 481
raizel_varun 0:ebdf4f859dca 482
raizel_varun 0:ebdf4f859dca 483
sakthipriya 1:deb3c0fafa3a 484 //master_reset.fall(&FUNC_I2C_RESET);
raizel_varun 0:ebdf4f859dca 485 interrupt.rise(&FUNC_I2C_INT);
raizel_varun 0:ebdf4f859dca 486
raizel_varun 0:ebdf4f859dca 487 while(1)
raizel_varun 0:ebdf4f859dca 488 {
raizel_varun 0:ebdf4f859dca 489 //Thread::wait(10000);
raizel_varun 0:ebdf4f859dca 490 //ir2master();
greenroshks 2:edd107ea4740 491 //DRDY = 0;
sakthipriya 3:20647ff68b3c 492 Thread::wait(5000);
raizel_varun 0:ebdf4f859dca 493 }
raizel_varun 0:ebdf4f859dca 494
raizel_varun 0:ebdf4f859dca 495 }