Chaitanya Viswa
/
BAE_SEM5
no beacon yes yes beacon no
Fork of all_combined_week6 by
Diff: main.cpp
- Revision:
- 2:94ca2059f8b2
- Parent:
- 1:37fa1c3eba16
- Child:
- 4:79b97f9cab00
--- a/main.cpp Thu Jul 10 11:37:47 2014 +0000 +++ b/main.cpp Fri Jul 11 05:14:12 2014 +0000 @@ -3,10 +3,10 @@ #include "hkfinal.h" #include "slave.h" #include "ShortBeacon.h" -//What da ?? + Serial pc(USBTX, USBRX); -DigitalOut led1(LED1); + Timer t; Timer t1; @@ -16,7 +16,8 @@ Thread *ptr_t_acs_write2flash; Thread *ptr_t_bea; Thread *ptr_t_bea_telecommand; -Thread *ptr_t_sc; +Thread *ptr_t_fault; + //----------------------------------------------HOUSE-KEEPING(HK)------------------------------------------------------------------------------------------ //void func_hk_mux() @@ -49,14 +50,12 @@ while(1) { t.start(); - + Thread::signal_wait(0x4); printf("The state of hk_acq thread is %d\n",ptr_t_hk_acq->get_state()); printf("The state of acs_main thread is %d\n",ptr_t_acs->get_state()); printf("The state of acs_write2flash thread is %d\n",ptr_t_acs_write2flash->get_state()); printf("The state of beacon thread is %d\n",ptr_t_bea->get_state()); - Thread::signal_wait(0x4); - //func_hk_readram(); - //func_hk_send2cdms(); + FUNC_I2C_SLAVE_MAIN(); printf("The time to execute send2cdms is %f\n",t.read()); t.reset(); @@ -69,11 +68,10 @@ while(1) { Thread::signal_wait(0x2); - printf("\nTHIS IS HK\n"); + + printf("\nTHIS IS HK %f\n",t1.read()); t.start(); - //func_hk_mux(); - //func_hk_adc(); - //func_hk_write2flash(); + FUNC_HK_MAIN(); thread_2.signal_set(0x4); printf("The state of hk_acq thread is %d\n",ptr_t_hk_acq->get_state()); @@ -123,13 +121,14 @@ while(1) { Thread::signal_wait(0x1); - printf("\nTHIS IS ACS\n"); + printf("\nTHIS IS ACS %f\n",t1.read()); t.start(); sensor_data *ptr = q_acs.alloc(); func_acs_readdata(ptr); + q_acs.put(ptr); func_acs_ctrlalgo(); func_acs_pwmgen(); - q_acs.put(ptr); + printf("The state of hk_acq thread is %d\n",ptr_t_hk_acq->get_state()); printf("The state of acs_main thread is %d\n",ptr_t_acs->get_state()); printf("The state of acs_write2flash thread is %d\n",ptr_t_acs_write2flash->get_state()); @@ -158,7 +157,7 @@ //---------------------------------------------------BEACON-------------------------------------------------------------------------------------------- -int flag=0; +int beac_flag=0; /*void func_bea_readbaeflash() { @@ -178,7 +177,7 @@ if(c=='a') { pc.printf("Telecommand detected\n"); - flag=1; + beac_flag=1; } } @@ -188,13 +187,13 @@ while(1) { Thread::signal_wait(0x3); - printf("\nTHIS IS BEACON\n"); + printf("\nTHIS IS BEACON %f\n",t1.read()); t.start(); printf("The state of hk_acq thread is %d\n",ptr_t_hk_acq->get_state()); printf("The state of acs_main thread is %d\n",ptr_t_acs->get_state()); printf("The state of acs_write2flash thread is %d\n",ptr_t_acs_write2flash->get_state()); printf("The state of beacon thread is %d\n",ptr_t_bea->get_state()); - if(flag==0) + if(beac_flag==0) { //func_bea_readbaeflash(); //func_bea_spiwrite(); @@ -202,8 +201,8 @@ } else { - Thread::wait(10000); - flag = 0; + Thread::wait(600000); + beac_flag = 0; } printf("The time to execute beacon thread is %f seconds\n",t.read()); @@ -211,25 +210,69 @@ } } +//--------------------------------------------------------------------------------------------------------------------------------------------------- +//TASK 4 : FAULT MANAGEMENT +//--------------------------------------------------------------------------------------------------------------------------------------------------- +//Dummy fault rectifier functions + +Mail<int,16> faults; + +void FUNC_FAULT_FUNCT1() +{ + pc.printf("\nFault 1 detected... \n"); +} + +void FUNC_FAULT_FUNCT2() +{ + pc.printf("\nFault 2 detected...\n"); +} + +void T_FAULT(void const *args) +{ + while(1) + { + osEvent evt = faults.get(); + if(evt.status==osEventMail) + { + int *fault_id= (int *)evt.value.p; + switch(*fault_id) + { + case 1: FUNC_FAULT_FUNCT1(); + break; + case 2: FUNC_FAULT_FUNCT2(); + break; + } + faults.free(fault_id); + } + } +} + //------------------------------------------------------------------------------------------------------------------------------------------------ -int i=0; +//SCHEDULER +//------------------------------------------------------------------------------------------------------------------------------------------------ +uint16_t schedcount=1; void t_sc(void const *args) { - printf("The value of i in scheduler is %d\n",i); - if(i%10==0) + //printf("The value of i in scheduler is %d\n",i); + if(schedcount == 65532) //to reset the counter + { + schedcount = 0; + } + + if(schedcount%1==0) { ptr_t_acs -> signal_set(0x1); } - if(i%20==0) + if(schedcount%2==0) { ptr_t_hk_acq -> signal_set(0x2); } - if(i%30==0) + if(schedcount%3==0) { ptr_t_bea -> signal_set(0x3); } - i++; + schedcount++; } //--------------------------------------------------------------------------------------------------------------------------------------------- @@ -243,10 +286,12 @@ ptr_t_acs_write2flash = new Thread(t_acs_write2flash); ptr_t_bea = new Thread(t_bea); ptr_t_bea_telecommand = new Thread(t_bea_telecommand); + ptr_t_fault = new Thread(T_FAULT); //ptr_t_sc = new Thread(t_sc); - ptr_t_acs->set_priority(osPriorityRealtime); - ptr_t_hk_acq->set_priority(osPriorityHigh); + ptr_t_fault -> set_priority(osPriorityRealtime); + ptr_t_acs->set_priority(osPriorityHigh); + ptr_t_hk_acq->set_priority(osPriorityNormal); ptr_t_acs_write2flash->set_priority(osPriorityBelowNormal); ptr_t_bea->set_priority(osPriorityAboveNormal); ptr_t_bea_telecommand->set_priority(osPriorityIdle); @@ -261,10 +306,15 @@ t_acs_timer.start(10000); t_bea_timer.start(30000); ----------------------------------------------------------------------------------------------*/ - + pc.printf("\n T_FAULT priority is %d",ptr_t_fault->get_priority()); + pc.printf("\n T_ACS priority is %d",ptr_t_acs->get_priority()); + pc.printf("\n T_HK_ACQ priority is %d",ptr_t_hk_acq->get_priority()); + pc.printf("\n T_ACS_WRITE2FLASH priority is %d",ptr_t_acs_write2flash->get_priority()); + pc.printf("\n T_BEA priority is %d",ptr_t_bea->get_priority()); RtosTimer t_sc_timer(t_sc,osTimerPeriodic); - t_sc_timer.start(1000); - printf("%f\n",t1.read()); + t_sc_timer.start(10000); + printf("\n%f\n",t1.read()); + while(1) { ;