mag n gyro included

Dependencies:   mbed-rtos mbed

Fork of BAE_vr2_gingerbread2 by Seeker of Truth ,

Committer:
sakthipriya
Date:
Wed Dec 17 06:52:26 2014 +0000
Revision:
0:e9c32e1df869
Child:
1:bd715ccef1bb
i2c working with new hk(no battery gauge)

Who changed what in which revision?

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