Rtos code for BAE microcontroller, IITMSAT

Dependencies:   mbed-rtos mbed

Committer:
greenroshks
Date:
Fri Jul 04 11:30:40 2014 +0000
Revision:
2:1792c9cda669
Parent:
1:5a364ac20fa4
Child:
3:307c56629df0
Updated BAE RTOS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
greenroshks 2:1792c9cda669 1
greenroshks 0:f1f148215d00 2 #include "rtos.h"
greenroshks 2:1792c9cda669 3 #include "HK.h"
greenroshks 2:1792c9cda669 4 #include "slave.h"
greenroshks 0:f1f148215d00 5
greenroshks 0:f1f148215d00 6 Serial pc(USBTX,USBRX);
greenroshks 0:f1f148215d00 7 Timer t;
greenroshks 0:f1f148215d00 8 Thread *t_acs;
greenroshks 0:f1f148215d00 9 Thread *t_bea;
greenroshks 0:f1f148215d00 10 Thread *t_hk_acq;
greenroshks 0:f1f148215d00 11 Thread *t_acs_write2flash;
greenroshks 0:f1f148215d00 12 Thread *t_hk_write2cdms;
greenroshks 2:1792c9cda669 13 Thread *t_fault;
greenroshks 0:f1f148215d00 14
greenroshks 1:5a364ac20fa4 15
greenroshks 1:5a364ac20fa4 16
greenroshks 0:f1f148215d00 17 int flag = 0; //for detecting keypress from computer
greenroshks 0:f1f148215d00 18
greenroshks 0:f1f148215d00 19
greenroshks 0:f1f148215d00 20 /*----------------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 0:f1f148215d00 21 TASK 1:ACS
greenroshks 0:f1f148215d00 22 ----------------------------------------------------------------------------------------------------------------------------------------------------*/
greenroshks 0:f1f148215d00 23 typedef struct
greenroshks 0:f1f148215d00 24 {
greenroshks 0:f1f148215d00 25 int B;
greenroshks 0:f1f148215d00 26 int omega;
greenroshks 0:f1f148215d00 27 }sens_data;
greenroshks 0:f1f148215d00 28
greenroshks 1:5a364ac20fa4 29 void FUNC_ACS_READDATA(sens_data * s);
greenroshks 1:5a364ac20fa4 30
greenroshks 0:f1f148215d00 31 Mail <sens_data,16> q_sensor;
greenroshks 1:5a364ac20fa4 32 /*----------------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 1:5a364ac20fa4 33 Definitions of functions for thread T_ACS_MAIN begin here
greenroshks 1:5a364ac20fa4 34 -----------------------------------------------------------------------------------------------------------------------------------------------------*/
greenroshks 1:5a364ac20fa4 35 //This function is called only once after the microcontroller is reset.
greenroshks 1:5a364ac20fa4 36 void FUNC_ACS_SENSORINIT()
greenroshks 1:5a364ac20fa4 37 {
greenroshks 1:5a364ac20fa4 38 /*
greenroshks 1:5a364ac20fa4 39
greenroshks 1:5a364ac20fa4 40 Lines of code to be given by Shruti and Jahnavi
greenroshks 1:5a364ac20fa4 41
greenroshks 1:5a364ac20fa4 42 */
greenroshks 1:5a364ac20fa4 43 pc.printf("\nInitializing the sensors.. \n");
greenroshks 1:5a364ac20fa4 44 }
greenroshks 0:f1f148215d00 45
greenroshks 0:f1f148215d00 46 void FUNC_ACS_READDATA(sens_data * s)
greenroshks 0:f1f148215d00 47 {
greenroshks 1:5a364ac20fa4 48 /*
greenroshks 1:5a364ac20fa4 49
greenroshks 1:5a364ac20fa4 50 Lines of code to be given by Shruti and Jahnavi
greenroshks 1:5a364ac20fa4 51
greenroshks 1:5a364ac20fa4 52 Request sensor data
greenroshks 1:5a364ac20fa4 53
greenroshks 1:5a364ac20fa4 54 */
greenroshks 1:5a364ac20fa4 55
greenroshks 1:5a364ac20fa4 56
greenroshks 1:5a364ac20fa4 57 // this is the dummy data
greenroshks 0:f1f148215d00 58 s->B=10;
greenroshks 0:f1f148215d00 59 s->omega=100;
greenroshks 1:5a364ac20fa4 60
greenroshks 1:5a364ac20fa4 61 pc.printf("\nReceived sensor data\n");
greenroshks 0:f1f148215d00 62 }
greenroshks 0:f1f148215d00 63
greenroshks 1:5a364ac20fa4 64 float FUNC_ACS_CONTROLALGO(sens_data * s)
greenroshks 0:f1f148215d00 65 {
greenroshks 1:5a364ac20fa4 66 /*
greenroshks 1:5a364ac20fa4 67
greenroshks 1:5a364ac20fa4 68 Lines of code to be given by Shruti and Jahnavi
greenroshks 1:5a364ac20fa4 69
greenroshks 1:5a364ac20fa4 70 Control algorithm implementation
greenroshks 1:5a364ac20fa4 71
greenroshks 1:5a364ac20fa4 72 */
greenroshks 1:5a364ac20fa4 73 float m;
greenroshks 1:5a364ac20fa4 74 s->B=10 *10;
greenroshks 1:5a364ac20fa4 75 s->omega=100*10;
greenroshks 1:5a364ac20fa4 76 m = 10;
greenroshks 1:5a364ac20fa4 77 pc.printf("\nImplemented control algo\n");
greenroshks 1:5a364ac20fa4 78
greenroshks 1:5a364ac20fa4 79 return(m);
greenroshks 0:f1f148215d00 80 }
greenroshks 0:f1f148215d00 81
greenroshks 1:5a364ac20fa4 82 void FUNC_ACS_PWMGEN(float m)
greenroshks 0:f1f148215d00 83 {
greenroshks 1:5a364ac20fa4 84 float dc;
greenroshks 1:5a364ac20fa4 85 dc = m*2;
greenroshks 1:5a364ac20fa4 86
greenroshks 1:5a364ac20fa4 87 /*
greenroshks 1:5a364ac20fa4 88
greenroshks 1:5a364ac20fa4 89 Lines of code to be given by Kumar and Karthik
greenroshks 1:5a364ac20fa4 90
greenroshks 1:5a364ac20fa4 91 PWM implementation
greenroshks 1:5a364ac20fa4 92
greenroshks 1:5a364ac20fa4 93 */
greenroshks 1:5a364ac20fa4 94
greenroshks 1:5a364ac20fa4 95
greenroshks 0:f1f148215d00 96 pc.printf("\nGenerating pwm signal\n");
greenroshks 1:5a364ac20fa4 97
greenroshks 1:5a364ac20fa4 98
greenroshks 0:f1f148215d00 99 }
greenroshks 0:f1f148215d00 100
greenroshks 1:5a364ac20fa4 101 // Definitions of functions for thread T_ACS_MAIN end here
greenroshks 1:5a364ac20fa4 102 //----------------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 1:5a364ac20fa4 103
greenroshks 1:5a364ac20fa4 104
greenroshks 1:5a364ac20fa4 105
greenroshks 1:5a364ac20fa4 106 // Definitions of functions for thread T_ACS_WRITE2FLASH starts here
greenroshks 1:5a364ac20fa4 107 //----------------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 1:5a364ac20fa4 108
greenroshks 0:f1f148215d00 109 void FUNC_ACS_WRITE2FLASH(sens_data *s1)
greenroshks 0:f1f148215d00 110 {
greenroshks 0:f1f148215d00 111 pc.printf("\nWritng ACS data to BAE flash\n");
greenroshks 0:f1f148215d00 112 pc.printf("\nB :%d",s1->B);
greenroshks 0:f1f148215d00 113 pc.printf("\nomega :%d",s1->omega);
greenroshks 0:f1f148215d00 114
greenroshks 0:f1f148215d00 115 }
greenroshks 0:f1f148215d00 116
greenroshks 1:5a364ac20fa4 117 // Definitions of functions for thread T_ACS_WRITE2FLASH end here
greenroshks 1:5a364ac20fa4 118 //----------------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 1:5a364ac20fa4 119
greenroshks 1:5a364ac20fa4 120 // This is the main thread of ACS
greenroshks 1:5a364ac20fa4 121
greenroshks 1:5a364ac20fa4 122 void T_ACS_MAIN(void const * args)
greenroshks 0:f1f148215d00 123 {
greenroshks 2:1792c9cda669 124 FUNC_ACS_SENSORINIT(); //Initializing sensors
greenroshks 0:f1f148215d00 125 while(1)
greenroshks 0:f1f148215d00 126 {
greenroshks 1:5a364ac20fa4 127
greenroshks 1:5a364ac20fa4 128 float m;
greenroshks 2:1792c9cda669 129 Thread::signal_wait(0x1); // waiting for signal from scheduler every ten seconds
greenroshks 0:f1f148215d00 130 printf("\nACS :%fn",t.read());
greenroshks 2:1792c9cda669 131 printf("\nACS thread state is %d\n",t_acs->get_state());
greenroshks 2:1792c9cda669 132 printf("\nBeacon thread state :%d\n",t_bea->get_state());
greenroshks 2:1792c9cda669 133 printf("\nACS_WRITE2FLASH thread state is %d\n",t_acs_write2flash->get_state());
greenroshks 2:1792c9cda669 134 printf("\nHK_ACQ thread state is %d\n",t_hk_acq->get_state());
greenroshks 2:1792c9cda669 135 printf("\nHK_WRITE2CDMS thread state is %d\n",t_hk_write2cdms->get_state());
greenroshks 0:f1f148215d00 136
greenroshks 2:1792c9cda669 137 sens_data * s = q_sensor.alloc();
greenroshks 1:5a364ac20fa4 138
greenroshks 0:f1f148215d00 139 FUNC_ACS_READDATA(s);
greenroshks 0:f1f148215d00 140 q_sensor.put(s);
greenroshks 1:5a364ac20fa4 141 m=FUNC_ACS_CONTROLALGO(s);
greenroshks 1:5a364ac20fa4 142 FUNC_ACS_PWMGEN(m);
greenroshks 0:f1f148215d00 143 pc.printf("\nTorque rods actuated\n");
greenroshks 0:f1f148215d00 144 //Thread::wait(9899);
greenroshks 1:5a364ac20fa4 145 }
greenroshks 0:f1f148215d00 146 }
greenroshks 0:f1f148215d00 147
greenroshks 0:f1f148215d00 148 void T_ACS_WRITE2FLASH(void const * args)
greenroshks 0:f1f148215d00 149 {
greenroshks 0:f1f148215d00 150 while(1)
greenroshks 0:f1f148215d00 151 {
greenroshks 0:f1f148215d00 152
greenroshks 0:f1f148215d00 153 osEvent evt=q_sensor.get();
greenroshks 0:f1f148215d00 154 if(evt.status==osEventMail)
greenroshks 0:f1f148215d00 155 {
greenroshks 2:1792c9cda669 156 printf("\nACS thread status is %d\n",t_acs->get_state());
greenroshks 2:1792c9cda669 157 printf("\nBeacon thread status :%d\n",t_bea->get_state());
greenroshks 2:1792c9cda669 158 printf("\nACS_WRITE2FLASH thread status is %d\n",t_acs_write2flash->get_state());
greenroshks 2:1792c9cda669 159 printf("\nHK_ACQ thread status is %d\n",t_hk_acq->get_state());
greenroshks 2:1792c9cda669 160 printf("\nHK_WRITE2CDMS thread status is %d\n",t_hk_write2cdms->get_state());
greenroshks 1:5a364ac20fa4 161 sens_data *s1 =(sens_data *)evt.value.p;// please see
greenroshks 0:f1f148215d00 162 FUNC_ACS_WRITE2FLASH(s1);
greenroshks 1:5a364ac20fa4 163
greenroshks 1:5a364ac20fa4 164 q_sensor.free(s1);
greenroshks 0:f1f148215d00 165 }
greenroshks 0:f1f148215d00 166 }
greenroshks 0:f1f148215d00 167 }
greenroshks 0:f1f148215d00 168
greenroshks 0:f1f148215d00 169 /*-----------------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 0:f1f148215d00 170 TASK 2 : HK
greenroshks 0:f1f148215d00 171 ------------------------------------------------------------------------------------------------------------------------------------------------------*/
greenroshks 1:5a364ac20fa4 172
greenroshks 1:5a364ac20fa4 173 //Functions for the thread T_HK_ACQ begins here
greenroshks 1:5a364ac20fa4 174 //----------------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 2:1792c9cda669 175 extern void FUNC_HK_MAIN(); // declared in HK.h
greenroshks 0:f1f148215d00 176
greenroshks 1:5a364ac20fa4 177 //Functions of the thread T_HK_SEND2CDMS starts here.
greenroshks 1:5a364ac20fa4 178 //----------------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 1:5a364ac20fa4 179
greenroshks 2:1792c9cda669 180 extern void FUNC_I2C_SLAVE_MAIN();
greenroshks 1:5a364ac20fa4 181
greenroshks 1:5a364ac20fa4 182 //----------------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 1:5a364ac20fa4 183 // Defintion of thread for sending data to CDMS
greenroshks 1:5a364ac20fa4 184 //----------------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 0:f1f148215d00 185 void T_HK_SEND2CDMS(void const * args)
greenroshks 0:f1f148215d00 186 {
greenroshks 2:1792c9cda669 187
greenroshks 0:f1f148215d00 188 while(1)
greenroshks 0:f1f148215d00 189 {
greenroshks 1:5a364ac20fa4 190 Thread::signal_wait(0x1); // Waiting for signal from T_HK_ACQ
greenroshks 0:f1f148215d00 191 printf("\nACS thread status is %d\n",t_acs->get_state());
greenroshks 0:f1f148215d00 192 printf("\nBeacon thread status :%d\n",t_bea->get_state());
greenroshks 0:f1f148215d00 193 printf("\nACS_WRITE2FLASH thread status is %d\n",t_acs_write2flash->get_state());
greenroshks 0:f1f148215d00 194 printf("\nHK_ACQ thread status is %d\n",t_hk_acq->get_state());
greenroshks 0:f1f148215d00 195 printf("\nHK_WRITE2CDMS thread status is %d\n",t_hk_write2cdms->get_state());
greenroshks 2:1792c9cda669 196 FUNC_I2C_SLAVE_MAIN();
greenroshks 0:f1f148215d00 197 }
greenroshks 0:f1f148215d00 198 }
greenroshks 0:f1f148215d00 199
greenroshks 1:5a364ac20fa4 200 //----------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 1:5a364ac20fa4 201 //Definition for the thread to collect HK data and store to flash memory
greenroshks 1:5a364ac20fa4 202 //----------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 1:5a364ac20fa4 203
greenroshks 0:f1f148215d00 204 void T_HK_ACQ(void const *args)
greenroshks 0:f1f148215d00 205 {
greenroshks 0:f1f148215d00 206 //t_hk_write2cdms = new Thread(T_HK_SEND2CDMS);
greenroshks 1:5a364ac20fa4 207 //t_hk_write2cdms->set_priority(osPriorityLow);
greenroshks 0:f1f148215d00 208 while(1)
greenroshks 0:f1f148215d00 209 {
greenroshks 1:5a364ac20fa4 210
greenroshks 2:1792c9cda669 211 Thread::signal_wait(0x1); //Waiting for the signal from sceduler every 20 seconds
greenroshks 0:f1f148215d00 212 printf("\n\nHK :%f\n",t.read());
greenroshks 2:1792c9cda669 213 printf("\nACS thread status is %d\n",t_acs->get_state());
greenroshks 0:f1f148215d00 214 printf("\nBeacon thread status :%d\n",t_bea->get_state());
greenroshks 0:f1f148215d00 215 printf("\nACS_WRITE2FLASH thread status is %d\n",t_acs_write2flash->get_state());
greenroshks 0:f1f148215d00 216 printf("\nHK_ACQ thread status is %d\n",t_hk_acq->get_state());
greenroshks 2:1792c9cda669 217 printf("\nHK_WRITE2CDMS thread status is %d\n",t_hk_write2cdms->get_state());
greenroshks 0:f1f148215d00 218
greenroshks 2:1792c9cda669 219 FUNC_HK_MAIN();
greenroshks 0:f1f148215d00 220 t_hk_write2cdms->signal_set(0x1);
greenroshks 0:f1f148215d00 221 //Thread::wait(19925);
greenroshks 0:f1f148215d00 222 }
greenroshks 1:5a364ac20fa4 223
greenroshks 0:f1f148215d00 224 }
greenroshks 0:f1f148215d00 225
greenroshks 0:f1f148215d00 226 /*--------------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 2:1792c9cda669 227 TASK 3 : BEACON
greenroshks 0:f1f148215d00 228 -----------------------------------------------------------------------------------------------------------------------------------------------------*/
greenroshks 1:5a364ac20fa4 229
greenroshks 1:5a364ac20fa4 230
greenroshks 2:1792c9cda669 231 void FUNC_BEA_READBAERAM()
greenroshks 0:f1f148215d00 232 {
greenroshks 1:5a364ac20fa4 233 /*
greenroshks 1:5a364ac20fa4 234 Code to be given by Nathaniel
greenroshks 1:5a364ac20fa4 235 */
greenroshks 1:5a364ac20fa4 236
greenroshks 2:1792c9cda669 237 pc.printf("\nReading HK data from BAE RAM\n");
greenroshks 0:f1f148215d00 238 }
greenroshks 0:f1f148215d00 239
greenroshks 0:f1f148215d00 240 void FUNC_BEA_WRITE2SPI()
greenroshks 0:f1f148215d00 241 {
greenroshks 1:5a364ac20fa4 242 /*
greenroshks 1:5a364ac20fa4 243 Code to be given by Nathaniel
greenroshks 1:5a364ac20fa4 244 */
greenroshks 1:5a364ac20fa4 245
greenroshks 0:f1f148215d00 246 pc.printf("\nSending data through SPI\n");
greenroshks 0:f1f148215d00 247 }
greenroshks 0:f1f148215d00 248
greenroshks 0:f1f148215d00 249
greenroshks 0:f1f148215d00 250 void T_BEA(void const * args)
greenroshks 0:f1f148215d00 251 {
greenroshks 2:1792c9cda669 252 extern SensorData Sensor; //Defined in HK.h
greenroshks 0:f1f148215d00 253 while(1)
greenroshks 0:f1f148215d00 254 {
greenroshks 1:5a364ac20fa4 255
greenroshks 2:1792c9cda669 256 Thread::signal_wait(0x1); //waiting for signal from scheduler every 30 seconds.
greenroshks 0:f1f148215d00 257 pc.printf("\nBEACON :%f\n",t.read());
greenroshks 0:f1f148215d00 258 printf("\nACS thread status is %d\n",t_acs->get_state());
greenroshks 0:f1f148215d00 259 printf("\nBeacon thread status :%d\n",t_bea->get_state());
greenroshks 0:f1f148215d00 260 printf("\nACS_WRITE2FLASH thread status is %d\n",t_acs_write2flash->get_state());
greenroshks 0:f1f148215d00 261 printf("\nHK_ACQ thread status is %d\n",t_hk_acq->get_state());
greenroshks 0:f1f148215d00 262 printf("\nHK_WRITE2CDMS thread status is %d\n",t_hk_write2cdms->get_state());
greenroshks 0:f1f148215d00 263
greenroshks 0:f1f148215d00 264 if(flag==0)
greenroshks 0:f1f148215d00 265 {
greenroshks 0:f1f148215d00 266
greenroshks 2:1792c9cda669 267 FUNC_BEA_READBAERAM();
greenroshks 0:f1f148215d00 268 FUNC_BEA_WRITE2SPI();
greenroshks 1:5a364ac20fa4 269 // Thread::wait(30000);
greenroshks 0:f1f148215d00 270 }
greenroshks 0:f1f148215d00 271 else
greenroshks 0:f1f148215d00 272 {
greenroshks 0:f1f148215d00 273 //led=1;
greenroshks 0:f1f148215d00 274 Thread::wait(60000);
greenroshks 0:f1f148215d00 275
greenroshks 0:f1f148215d00 276 flag=0;
greenroshks 0:f1f148215d00 277 //myled=0;
greenroshks 0:f1f148215d00 278 }
greenroshks 1:5a364ac20fa4 279 }
greenroshks 1:5a364ac20fa4 280
greenroshks 0:f1f148215d00 281 }
greenroshks 0:f1f148215d00 282
greenroshks 0:f1f148215d00 283 void keypress(void const *args)
greenroshks 0:f1f148215d00 284 {
greenroshks 0:f1f148215d00 285
greenroshks 0:f1f148215d00 286 while(1)
greenroshks 0:f1f148215d00 287 {
greenroshks 0:f1f148215d00 288 if(pc.getc()=='s')
greenroshks 0:f1f148215d00 289 {
greenroshks 0:f1f148215d00 290 pc.printf("\nTime of telecommand %f",t.read());
greenroshks 0:f1f148215d00 291 flag=1;
greenroshks 0:f1f148215d00 292 }
greenroshks 0:f1f148215d00 293 }
greenroshks 0:f1f148215d00 294 }
greenroshks 0:f1f148215d00 295
greenroshks 1:5a364ac20fa4 296
greenroshks 2:1792c9cda669 297 //---------------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 2:1792c9cda669 298 //TASK 4 : FAULT MANAGEMENT
greenroshks 2:1792c9cda669 299 //---------------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 2:1792c9cda669 300 //Dummy fault rectifier functions
greenroshks 2:1792c9cda669 301
greenroshks 2:1792c9cda669 302 Mail<int,16> faults;
greenroshks 2:1792c9cda669 303
greenroshks 2:1792c9cda669 304 void FUNC_FAULT_FUNCT1()
greenroshks 2:1792c9cda669 305 {
greenroshks 2:1792c9cda669 306 pc.printf("\nFault 1 detected... \n");
greenroshks 2:1792c9cda669 307 }
greenroshks 2:1792c9cda669 308
greenroshks 2:1792c9cda669 309 void FUNC_FAULT_FUNCT2()
greenroshks 2:1792c9cda669 310 {
greenroshks 2:1792c9cda669 311 pc.printf("\nFault 2 detected...\n");
greenroshks 2:1792c9cda669 312 }
greenroshks 2:1792c9cda669 313
greenroshks 2:1792c9cda669 314 void T_FAULT(void const *args)
greenroshks 2:1792c9cda669 315 {
greenroshks 2:1792c9cda669 316 while(1)
greenroshks 2:1792c9cda669 317 {
greenroshks 2:1792c9cda669 318 osEvent evt = faults.get();
greenroshks 2:1792c9cda669 319 if(evt.status==osEventMail)
greenroshks 2:1792c9cda669 320 {
greenroshks 2:1792c9cda669 321 int *fault_id= (int *)evt.value.p;
greenroshks 2:1792c9cda669 322 switch(*fault_id)
greenroshks 2:1792c9cda669 323 {
greenroshks 2:1792c9cda669 324 case 1: FUNC_FAULT_FUNCT1();
greenroshks 2:1792c9cda669 325 break;
greenroshks 2:1792c9cda669 326 case 2: FUNC_FAULT_FUNCT2();
greenroshks 2:1792c9cda669 327 break;
greenroshks 2:1792c9cda669 328 }
greenroshks 2:1792c9cda669 329 faults.free(fault_id);
greenroshks 2:1792c9cda669 330 }
greenroshks 2:1792c9cda669 331 }
greenroshks 2:1792c9cda669 332 }
greenroshks 2:1792c9cda669 333
greenroshks 2:1792c9cda669 334 //----------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 2:1792c9cda669 335 //Scheduler
greenroshks 2:1792c9cda669 336 //----------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 1:5a364ac20fa4 337 int schedcount=1;
greenroshks 1:5a364ac20fa4 338 void scheduler(void const * args)
greenroshks 1:5a364ac20fa4 339 {
greenroshks 2:1792c9cda669 340 if(schedcount == 7)
greenroshks 2:1792c9cda669 341 {
greenroshks 2:1792c9cda669 342 int * fault_id = faults.alloc();
greenroshks 2:1792c9cda669 343 *fault_id = 1;
greenroshks 2:1792c9cda669 344 faults.put(fault_id);
greenroshks 2:1792c9cda669 345 }
greenroshks 1:5a364ac20fa4 346 t_acs->signal_set(0x1);
greenroshks 1:5a364ac20fa4 347
greenroshks 1:5a364ac20fa4 348 if(schedcount%2==0)
greenroshks 1:5a364ac20fa4 349 {
greenroshks 2:1792c9cda669 350 //pc.printf("\nHK signal at %f",t.read());
greenroshks 1:5a364ac20fa4 351 t_hk_acq->signal_set(0x1);
greenroshks 1:5a364ac20fa4 352
greenroshks 1:5a364ac20fa4 353 }
greenroshks 1:5a364ac20fa4 354 if(schedcount%3==0)
greenroshks 1:5a364ac20fa4 355 {
greenroshks 2:1792c9cda669 356 //pc.printf("\nBeacon signal at %f",t.read());
greenroshks 1:5a364ac20fa4 357 t_bea->signal_set(0x1);
greenroshks 1:5a364ac20fa4 358
greenroshks 1:5a364ac20fa4 359 }
greenroshks 1:5a364ac20fa4 360 schedcount++;
greenroshks 1:5a364ac20fa4 361 }
greenroshks 1:5a364ac20fa4 362
greenroshks 0:f1f148215d00 363
greenroshks 0:f1f148215d00 364 /*-----------------------------------------------------------------------------------------------------------------------------------------------------
greenroshks 0:f1f148215d00 365 MAIN
greenroshks 0:f1f148215d00 366 -----------------------------------------------------------------------------------------------------------------------------------------------------*/
greenroshks 0:f1f148215d00 367 int main()
greenroshks 0:f1f148215d00 368 {
greenroshks 0:f1f148215d00 369 t.start();
greenroshks 2:1792c9cda669 370
greenroshks 1:5a364ac20fa4 371 t_acs = new Thread(T_ACS_MAIN);
greenroshks 0:f1f148215d00 372 t_bea = new Thread(T_BEA);
greenroshks 0:f1f148215d00 373 t_hk_acq = new Thread(T_HK_ACQ);
greenroshks 0:f1f148215d00 374 t_acs_write2flash = new Thread(T_ACS_WRITE2FLASH);
greenroshks 0:f1f148215d00 375 Thread key(keypress);
greenroshks 2:1792c9cda669 376 t_fault = new Thread(T_FAULT);
greenroshks 2:1792c9cda669 377 t_hk_write2cdms = new Thread(T_HK_SEND2CDMS);
greenroshks 1:5a364ac20fa4 378
greenroshks 2:1792c9cda669 379 t_fault->set_priority(osPriorityRealtime);
greenroshks 2:1792c9cda669 380 t_acs->set_priority(osPriorityHigh);
greenroshks 0:f1f148215d00 381 t_bea->set_priority(osPriorityAboveNormal);
greenroshks 0:f1f148215d00 382 t_hk_acq->set_priority(osPriorityNormal);
greenroshks 0:f1f148215d00 383 t_acs_write2flash->set_priority(osPriorityBelowNormal);
greenroshks 2:1792c9cda669 384
greenroshks 0:f1f148215d00 385 key.set_priority(osPriorityIdle);
greenroshks 0:f1f148215d00 386
greenroshks 2:1792c9cda669 387
greenroshks 1:5a364ac20fa4 388 /*RtosTimer t_hk_timer(T_HK_ACQ,osTimerPeriodic);
greenroshks 1:5a364ac20fa4 389 RtosTimer t_bea_timer(T_BEA,osTimerPeriodic);
greenroshks 1:5a364ac20fa4 390 RtosTimer t_acs_timer(T_ACS_MAIN,osTimerPeriodic);
greenroshks 1:5a364ac20fa4 391
greenroshks 1:5a364ac20fa4 392 t_hk_timer.start(10000);
greenroshks 1:5a364ac20fa4 393 t_bea_timer.start(20000);
greenroshks 1:5a364ac20fa4 394 t_acs_timer.start(30000);*/
greenroshks 1:5a364ac20fa4 395
greenroshks 1:5a364ac20fa4 396 RtosTimer schedule(scheduler,osTimerPeriodic);
greenroshks 1:5a364ac20fa4 397 schedule.start(10000);
greenroshks 1:5a364ac20fa4 398 t_hk_write2cdms->set_priority(osPriorityLow);
greenroshks 1:5a364ac20fa4 399 pc.printf("\n T_HK_SEND2CDMS priority is %d",t_hk_write2cdms->get_priority());
greenroshks 2:1792c9cda669 400 pc.printf("\n T_ACS priority is %d",t_acs->get_priority());
greenroshks 2:1792c9cda669 401 pc.printf("\n T_FAULTS priority is %d",t_fault->get_priority());
greenroshks 2:1792c9cda669 402
greenroshks 0:f1f148215d00 403 while(1)
greenroshks 0:f1f148215d00 404 {
greenroshks 1:5a364ac20fa4 405 /*if(i%10==0)
greenroshks 0:f1f148215d00 406 {
greenroshks 0:f1f148215d00 407 t_acs->signal_set(0x1);
greenroshks 0:f1f148215d00 408 pc.printf("Priority of t_hk_write2cdms is %d and t_acs_write2flash is %d",t_hk_write2cdms->get_priority(),t_acs_write2flash->get_priority());
greenroshks 0:f1f148215d00 409 }
greenroshks 0:f1f148215d00 410 if(i%20==0)
greenroshks 0:f1f148215d00 411 t_hk_acq->signal_set(0x1);
greenroshks 0:f1f148215d00 412 if(i%30==0)
greenroshks 0:f1f148215d00 413 t_bea->signal_set(0x1);
greenroshks 1:5a364ac20fa4 414
greenroshks 1:5a364ac20fa4 415 i++;*/
greenroshks 1:5a364ac20fa4 416 Thread::wait(1000);
greenroshks 2:1792c9cda669 417
greenroshks 2:1792c9cda669 418 // pc.printf("\n%f\n",t.read());
greenroshks 0:f1f148215d00 419 }
greenroshks 0:f1f148215d00 420 }