sw_test_workin

Dependencies:   mbed-rtos mbed

Fork of BAE_icecream_1_0 by sakthi priya amirtharaj

Committer:
sakthipriya
Date:
Sat Jan 31 14:11:53 2015 +0000
Revision:
3:20647ff68b3c
Parent:
2:edd107ea4740
Child:
4:b33bc4267e0d
i2c while removed and works - to be characterised

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