no beacon yes yes beacon no

Dependencies:   mbed-rtos mbed

Fork of all_combined_week6 by green rosh

Committer:
harshit_felicity
Date:
Thu Jul 10 11:35:40 2014 +0000
Revision:
0:cbe0ea884289
Child:
1:37fa1c3eba16
Fuck Yeahh..btich

Who changed what in which revision?

UserRevisionLine numberNew contents of line
harshit_felicity 0:cbe0ea884289 1 #include "mbed.h"
harshit_felicity 0:cbe0ea884289 2 #include "rtos.h"
harshit_felicity 0:cbe0ea884289 3 #include "hkfinal.h"
harshit_felicity 0:cbe0ea884289 4 #include "slave.h"
harshit_felicity 0:cbe0ea884289 5 #include "ShortBeacon.h"
harshit_felicity 0:cbe0ea884289 6
harshit_felicity 0:cbe0ea884289 7 Serial pc(USBTX, USBRX);
harshit_felicity 0:cbe0ea884289 8
harshit_felicity 0:cbe0ea884289 9 DigitalOut led1(LED1);
harshit_felicity 0:cbe0ea884289 10
harshit_felicity 0:cbe0ea884289 11 Timer t;
harshit_felicity 0:cbe0ea884289 12 Timer t1;
harshit_felicity 0:cbe0ea884289 13
harshit_felicity 0:cbe0ea884289 14 Thread *ptr_t_hk_acq;
harshit_felicity 0:cbe0ea884289 15 Thread *ptr_t_acs;
harshit_felicity 0:cbe0ea884289 16 Thread *ptr_t_acs_write2flash;
harshit_felicity 0:cbe0ea884289 17 Thread *ptr_t_bea;
harshit_felicity 0:cbe0ea884289 18 Thread *ptr_t_bea_telecommand;
harshit_felicity 0:cbe0ea884289 19 Thread *ptr_t_sc;
harshit_felicity 0:cbe0ea884289 20
harshit_felicity 0:cbe0ea884289 21 //----------------------------------------------HOUSE-KEEPING(HK)------------------------------------------------------------------------------------------
harshit_felicity 0:cbe0ea884289 22 //void func_hk_mux()
harshit_felicity 0:cbe0ea884289 23 //{
harshit_felicity 0:cbe0ea884289 24 // pc.printf("Something related to mux\n");
harshit_felicity 0:cbe0ea884289 25 //}
harshit_felicity 0:cbe0ea884289 26 //
harshit_felicity 0:cbe0ea884289 27 //void func_hk_adc()
harshit_felicity 0:cbe0ea884289 28 //{
harshit_felicity 0:cbe0ea884289 29 // pc.printf("Converting analog to digital\n");
harshit_felicity 0:cbe0ea884289 30 //}
harshit_felicity 0:cbe0ea884289 31 //
harshit_felicity 0:cbe0ea884289 32 //void func_hk_write2flash()
harshit_felicity 0:cbe0ea884289 33 //{
harshit_felicity 0:cbe0ea884289 34 // pc.printf("Writing the house keeping data to flash\n");
harshit_felicity 0:cbe0ea884289 35 //}
harshit_felicity 0:cbe0ea884289 36 //
harshit_felicity 0:cbe0ea884289 37 //void func_hk_readram()
harshit_felicity 0:cbe0ea884289 38 //{
harshit_felicity 0:cbe0ea884289 39 // pc.printf("Reading hk data from ram\n");
harshit_felicity 0:cbe0ea884289 40 //}
harshit_felicity 0:cbe0ea884289 41
harshit_felicity 0:cbe0ea884289 42 //void func_hk_send2cdms()
harshit_felicity 0:cbe0ea884289 43 //{
harshit_felicity 0:cbe0ea884289 44 // pc.printf("Send the data to sd card\n");
harshit_felicity 0:cbe0ea884289 45 //}
harshit_felicity 0:cbe0ea884289 46
harshit_felicity 0:cbe0ea884289 47 void t_hk_send2cdms(void const *args)
harshit_felicity 0:cbe0ea884289 48 {
harshit_felicity 0:cbe0ea884289 49 while(1)
harshit_felicity 0:cbe0ea884289 50 {
harshit_felicity 0:cbe0ea884289 51 t.start();
harshit_felicity 0:cbe0ea884289 52
harshit_felicity 0:cbe0ea884289 53 printf("The state of hk_acq thread is %d\n",ptr_t_hk_acq->get_state());
harshit_felicity 0:cbe0ea884289 54 printf("The state of acs_main thread is %d\n",ptr_t_acs->get_state());
harshit_felicity 0:cbe0ea884289 55 printf("The state of acs_write2flash thread is %d\n",ptr_t_acs_write2flash->get_state());
harshit_felicity 0:cbe0ea884289 56 printf("The state of beacon thread is %d\n",ptr_t_bea->get_state());
harshit_felicity 0:cbe0ea884289 57 Thread::signal_wait(0x4);
harshit_felicity 0:cbe0ea884289 58 //func_hk_readram();
harshit_felicity 0:cbe0ea884289 59 //func_hk_send2cdms();
harshit_felicity 0:cbe0ea884289 60 FUNC_I2C_SLAVE_MAIN();
harshit_felicity 0:cbe0ea884289 61 printf("The time to execute send2cdms is %f\n",t.read());
harshit_felicity 0:cbe0ea884289 62 t.reset();
harshit_felicity 0:cbe0ea884289 63 }
harshit_felicity 0:cbe0ea884289 64 }
harshit_felicity 0:cbe0ea884289 65
harshit_felicity 0:cbe0ea884289 66 void t_hk_acq(void const *args)
harshit_felicity 0:cbe0ea884289 67 {
harshit_felicity 0:cbe0ea884289 68 Thread thread_2(t_hk_send2cdms);
harshit_felicity 0:cbe0ea884289 69 while(1)
harshit_felicity 0:cbe0ea884289 70 {
harshit_felicity 0:cbe0ea884289 71 Thread::signal_wait(0x2);
harshit_felicity 0:cbe0ea884289 72 printf("\nTHIS IS HK\n");
harshit_felicity 0:cbe0ea884289 73 t.start();
harshit_felicity 0:cbe0ea884289 74 //func_hk_mux();
harshit_felicity 0:cbe0ea884289 75 //func_hk_adc();
harshit_felicity 0:cbe0ea884289 76 //func_hk_write2flash();
harshit_felicity 0:cbe0ea884289 77 FUNC_HK_MAIN();
harshit_felicity 0:cbe0ea884289 78 thread_2.signal_set(0x4);
harshit_felicity 0:cbe0ea884289 79 printf("The state of hk_acq thread is %d\n",ptr_t_hk_acq->get_state());
harshit_felicity 0:cbe0ea884289 80 printf("The state of acs_main thread is %d\n",ptr_t_acs->get_state());
harshit_felicity 0:cbe0ea884289 81 printf("The state of acs_write2flash thread is %d\n",ptr_t_acs_write2flash->get_state());
harshit_felicity 0:cbe0ea884289 82 printf("The state of beacon thread is %d\n",ptr_t_bea->get_state());
harshit_felicity 0:cbe0ea884289 83 t.stop();
harshit_felicity 0:cbe0ea884289 84 printf("The time to execute hk_acq is %f seconds\n",t.read());
harshit_felicity 0:cbe0ea884289 85 t.reset();
harshit_felicity 0:cbe0ea884289 86 }
harshit_felicity 0:cbe0ea884289 87 }
harshit_felicity 0:cbe0ea884289 88
harshit_felicity 0:cbe0ea884289 89 //---------------------------------------------------------------------------------------------------------------------------------------
harshit_felicity 0:cbe0ea884289 90
harshit_felicity 0:cbe0ea884289 91 typedef struct {
harshit_felicity 0:cbe0ea884289 92 float mag_field;
harshit_felicity 0:cbe0ea884289 93 float omega;
harshit_felicity 0:cbe0ea884289 94 } sensor_data;
harshit_felicity 0:cbe0ea884289 95
harshit_felicity 0:cbe0ea884289 96 Mail <sensor_data, 16> q_acs;
harshit_felicity 0:cbe0ea884289 97
harshit_felicity 0:cbe0ea884289 98 void func_acs_readdata(sensor_data *ptr)
harshit_felicity 0:cbe0ea884289 99 {
harshit_felicity 0:cbe0ea884289 100 pc.printf("Reading the data\n");
harshit_felicity 0:cbe0ea884289 101 ptr -> mag_field = 10;
harshit_felicity 0:cbe0ea884289 102 ptr -> omega = 3;
harshit_felicity 0:cbe0ea884289 103 }
harshit_felicity 0:cbe0ea884289 104
harshit_felicity 0:cbe0ea884289 105 void func_acs_ctrlalgo()
harshit_felicity 0:cbe0ea884289 106 {
harshit_felicity 0:cbe0ea884289 107 pc.printf("Executing control algo\n");
harshit_felicity 0:cbe0ea884289 108 }
harshit_felicity 0:cbe0ea884289 109
harshit_felicity 0:cbe0ea884289 110 void func_acs_pwmgen()
harshit_felicity 0:cbe0ea884289 111 {
harshit_felicity 0:cbe0ea884289 112 pc.printf("Generating PWM signal\n");
harshit_felicity 0:cbe0ea884289 113 }
harshit_felicity 0:cbe0ea884289 114
harshit_felicity 0:cbe0ea884289 115 void func_acs_write2flash(sensor_data *ptr2)
harshit_felicity 0:cbe0ea884289 116 {
harshit_felicity 0:cbe0ea884289 117 pc.printf("The magnetic field is %.2f T\n\r",ptr2->mag_field);
harshit_felicity 0:cbe0ea884289 118 pc.printf("The angular velocity is %.2f rad/s\n\r",ptr2->omega);
harshit_felicity 0:cbe0ea884289 119 }
harshit_felicity 0:cbe0ea884289 120
harshit_felicity 0:cbe0ea884289 121 void t_acs(void const *args)
harshit_felicity 0:cbe0ea884289 122 {
harshit_felicity 0:cbe0ea884289 123 while(1)
harshit_felicity 0:cbe0ea884289 124 {
harshit_felicity 0:cbe0ea884289 125 Thread::signal_wait(0x1);
harshit_felicity 0:cbe0ea884289 126 printf("\nTHIS IS ACS\n");
harshit_felicity 0:cbe0ea884289 127 t.start();
harshit_felicity 0:cbe0ea884289 128 sensor_data *ptr = q_acs.alloc();
harshit_felicity 0:cbe0ea884289 129 func_acs_readdata(ptr);
harshit_felicity 0:cbe0ea884289 130 func_acs_ctrlalgo();
harshit_felicity 0:cbe0ea884289 131 func_acs_pwmgen();
harshit_felicity 0:cbe0ea884289 132 q_acs.put(ptr);
harshit_felicity 0:cbe0ea884289 133 printf("The state of hk_acq thread is %d\n",ptr_t_hk_acq->get_state());
harshit_felicity 0:cbe0ea884289 134 printf("The state of acs_main thread is %d\n",ptr_t_acs->get_state());
harshit_felicity 0:cbe0ea884289 135 printf("The state of acs_write2flash thread is %d\n",ptr_t_acs_write2flash->get_state());
harshit_felicity 0:cbe0ea884289 136 printf("The state of beacon thread is %d\n",ptr_t_bea->get_state());
harshit_felicity 0:cbe0ea884289 137 printf("The time to execute t_acs is %f seconds\n",t.read());
harshit_felicity 0:cbe0ea884289 138 // Thread::wait(10000);
harshit_felicity 0:cbe0ea884289 139 t.reset();
harshit_felicity 0:cbe0ea884289 140 }
harshit_felicity 0:cbe0ea884289 141 }
harshit_felicity 0:cbe0ea884289 142
harshit_felicity 0:cbe0ea884289 143 void t_acs_write2flash(void const *args)
harshit_felicity 0:cbe0ea884289 144 {
harshit_felicity 0:cbe0ea884289 145 while(1)
harshit_felicity 0:cbe0ea884289 146 {
harshit_felicity 0:cbe0ea884289 147 //printf("Writing in the flash\n");
harshit_felicity 0:cbe0ea884289 148 osEvent evt = q_acs.get();
harshit_felicity 0:cbe0ea884289 149 if(evt.status == osEventMail)
harshit_felicity 0:cbe0ea884289 150 {
harshit_felicity 0:cbe0ea884289 151 sensor_data *ptr = (sensor_data*)evt.value.p;
harshit_felicity 0:cbe0ea884289 152 func_acs_write2flash(ptr);
harshit_felicity 0:cbe0ea884289 153 q_acs.free(ptr);
harshit_felicity 0:cbe0ea884289 154 }
harshit_felicity 0:cbe0ea884289 155 printf("Writing in the flash\n");
harshit_felicity 0:cbe0ea884289 156 }
harshit_felicity 0:cbe0ea884289 157 }
harshit_felicity 0:cbe0ea884289 158
harshit_felicity 0:cbe0ea884289 159 //---------------------------------------------------BEACON--------------------------------------------------------------------------------------------
harshit_felicity 0:cbe0ea884289 160
harshit_felicity 0:cbe0ea884289 161 int flag=0;
harshit_felicity 0:cbe0ea884289 162
harshit_felicity 0:cbe0ea884289 163 /*void func_bea_readbaeflash()
harshit_felicity 0:cbe0ea884289 164 {
harshit_felicity 0:cbe0ea884289 165 pc.printf("Reading data from beacon flash\n");
harshit_felicity 0:cbe0ea884289 166 wait(0.01);
harshit_felicity 0:cbe0ea884289 167 }
harshit_felicity 0:cbe0ea884289 168
harshit_felicity 0:cbe0ea884289 169 void func_bea_spiwrite()
harshit_felicity 0:cbe0ea884289 170 {
harshit_felicity 0:cbe0ea884289 171 pc.printf("Writing through SPI\n");
harshit_felicity 0:cbe0ea884289 172 wait(0.01);
harshit_felicity 0:cbe0ea884289 173 }
harshit_felicity 0:cbe0ea884289 174 */
harshit_felicity 0:cbe0ea884289 175 void t_bea_telecommand(void const *args)
harshit_felicity 0:cbe0ea884289 176 {
harshit_felicity 0:cbe0ea884289 177 char c = pc.getc();
harshit_felicity 0:cbe0ea884289 178 if(c=='a')
harshit_felicity 0:cbe0ea884289 179 {
harshit_felicity 0:cbe0ea884289 180 pc.printf("Telecommand detected\n");
harshit_felicity 0:cbe0ea884289 181 flag=1;
harshit_felicity 0:cbe0ea884289 182 }
harshit_felicity 0:cbe0ea884289 183 }
harshit_felicity 0:cbe0ea884289 184
harshit_felicity 0:cbe0ea884289 185 void t_bea(void const *args)
harshit_felicity 0:cbe0ea884289 186 {
harshit_felicity 0:cbe0ea884289 187
harshit_felicity 0:cbe0ea884289 188 while(1)
harshit_felicity 0:cbe0ea884289 189 {
harshit_felicity 0:cbe0ea884289 190 Thread::signal_wait(0x3);
harshit_felicity 0:cbe0ea884289 191 printf("\nTHIS IS BEACON\n");
harshit_felicity 0:cbe0ea884289 192 t.start();
harshit_felicity 0:cbe0ea884289 193 printf("The state of hk_acq thread is %d\n",ptr_t_hk_acq->get_state());
harshit_felicity 0:cbe0ea884289 194 printf("The state of acs_main thread is %d\n",ptr_t_acs->get_state());
harshit_felicity 0:cbe0ea884289 195 printf("The state of acs_write2flash thread is %d\n",ptr_t_acs_write2flash->get_state());
harshit_felicity 0:cbe0ea884289 196 printf("The state of beacon thread is %d\n",ptr_t_bea->get_state());
harshit_felicity 0:cbe0ea884289 197 if(flag==0)
harshit_felicity 0:cbe0ea884289 198 {
harshit_felicity 0:cbe0ea884289 199 //func_bea_readbaeflash();
harshit_felicity 0:cbe0ea884289 200 //func_bea_spiwrite();
harshit_felicity 0:cbe0ea884289 201 Thread::wait(30000);
harshit_felicity 0:cbe0ea884289 202 }
harshit_felicity 0:cbe0ea884289 203 else
harshit_felicity 0:cbe0ea884289 204 {
harshit_felicity 0:cbe0ea884289 205 Thread::wait(10000);
harshit_felicity 0:cbe0ea884289 206 flag = 0;
harshit_felicity 0:cbe0ea884289 207 }
harshit_felicity 0:cbe0ea884289 208
harshit_felicity 0:cbe0ea884289 209 printf("The time to execute beacon thread is %f seconds\n",t.read());
harshit_felicity 0:cbe0ea884289 210 t.reset();
harshit_felicity 0:cbe0ea884289 211 }
harshit_felicity 0:cbe0ea884289 212 }
harshit_felicity 0:cbe0ea884289 213
harshit_felicity 0:cbe0ea884289 214 //------------------------------------------------------------------------------------------------------------------------------------------------
harshit_felicity 0:cbe0ea884289 215 int i=0;
harshit_felicity 0:cbe0ea884289 216 void t_sc(void const *args)
harshit_felicity 0:cbe0ea884289 217 {
harshit_felicity 0:cbe0ea884289 218
harshit_felicity 0:cbe0ea884289 219 printf("The value of i in scheduler is %d\n",i);
harshit_felicity 0:cbe0ea884289 220 if(i%10==0)
harshit_felicity 0:cbe0ea884289 221 {
harshit_felicity 0:cbe0ea884289 222 ptr_t_acs -> signal_set(0x1);
harshit_felicity 0:cbe0ea884289 223 }
harshit_felicity 0:cbe0ea884289 224 if(i%20==0)
harshit_felicity 0:cbe0ea884289 225 {
harshit_felicity 0:cbe0ea884289 226 ptr_t_hk_acq -> signal_set(0x2);
harshit_felicity 0:cbe0ea884289 227 }
harshit_felicity 0:cbe0ea884289 228 if(i%30==0)
harshit_felicity 0:cbe0ea884289 229 {
harshit_felicity 0:cbe0ea884289 230 ptr_t_bea -> signal_set(0x3);
harshit_felicity 0:cbe0ea884289 231 }
harshit_felicity 0:cbe0ea884289 232 i++;
harshit_felicity 0:cbe0ea884289 233 }
harshit_felicity 0:cbe0ea884289 234
harshit_felicity 0:cbe0ea884289 235 //---------------------------------------------------------------------------------------------------------------------------------------------
harshit_felicity 0:cbe0ea884289 236
harshit_felicity 0:cbe0ea884289 237 int main()
harshit_felicity 0:cbe0ea884289 238 {
harshit_felicity 0:cbe0ea884289 239 t1.start();
harshit_felicity 0:cbe0ea884289 240
harshit_felicity 0:cbe0ea884289 241 ptr_t_hk_acq = new Thread(t_hk_acq);
harshit_felicity 0:cbe0ea884289 242 ptr_t_acs = new Thread(t_acs);
harshit_felicity 0:cbe0ea884289 243 ptr_t_acs_write2flash = new Thread(t_acs_write2flash);
harshit_felicity 0:cbe0ea884289 244 ptr_t_bea = new Thread(t_bea);
harshit_felicity 0:cbe0ea884289 245 ptr_t_bea_telecommand = new Thread(t_bea_telecommand);
harshit_felicity 0:cbe0ea884289 246 //ptr_t_sc = new Thread(t_sc);
harshit_felicity 0:cbe0ea884289 247
harshit_felicity 0:cbe0ea884289 248 ptr_t_acs->set_priority(osPriorityRealtime);
harshit_felicity 0:cbe0ea884289 249 ptr_t_hk_acq->set_priority(osPriorityHigh);
harshit_felicity 0:cbe0ea884289 250 ptr_t_acs_write2flash->set_priority(osPriorityBelowNormal);
harshit_felicity 0:cbe0ea884289 251 ptr_t_bea->set_priority(osPriorityAboveNormal);
harshit_felicity 0:cbe0ea884289 252 ptr_t_bea_telecommand->set_priority(osPriorityIdle);
harshit_felicity 0:cbe0ea884289 253 //ptr_t_sc->set_priority(osPriorityAboveNormal);
harshit_felicity 0:cbe0ea884289 254
harshit_felicity 0:cbe0ea884289 255 /*RtosTimer for individual thread-------------------------------------------------------------------------------------------
harshit_felicity 0:cbe0ea884289 256 RtosTimer t_hk_acq_timer(t_hk_acq, osTimerPeriodic);
harshit_felicity 0:cbe0ea884289 257 RtosTimer t_acs_timer(t_acs, osTimerPeriodic);
harshit_felicity 0:cbe0ea884289 258 RtosTimer t_bea_timer(t_bea, osTimerPeriodic);
harshit_felicity 0:cbe0ea884289 259
harshit_felicity 0:cbe0ea884289 260 t_hk_acq_timer.start(20000);
harshit_felicity 0:cbe0ea884289 261 t_acs_timer.start(10000);
harshit_felicity 0:cbe0ea884289 262 t_bea_timer.start(30000);
harshit_felicity 0:cbe0ea884289 263 ----------------------------------------------------------------------------------------------*/
harshit_felicity 0:cbe0ea884289 264
harshit_felicity 0:cbe0ea884289 265 RtosTimer t_sc_timer(t_sc,osTimerPeriodic);
harshit_felicity 0:cbe0ea884289 266 t_sc_timer.start(1000);
harshit_felicity 0:cbe0ea884289 267 printf("%f\n",t1.read());
harshit_felicity 0:cbe0ea884289 268 while(1)
harshit_felicity 0:cbe0ea884289 269 {
harshit_felicity 0:cbe0ea884289 270 ;
harshit_felicity 0:cbe0ea884289 271 }
harshit_felicity 0:cbe0ea884289 272
harshit_felicity 0:cbe0ea884289 273 }