green rosh
/
BAE_FRDM_INTEGRATION
bae integrated final (may be)
Fork of BAE_FRDMTESIN2 by
Diff: main.cpp
- Revision:
- 8:667fbc82d634
- Parent:
- 7:f06840d848e3
--- a/main.cpp Wed Dec 10 06:34:17 2014 +0000 +++ b/main.cpp Mon Dec 15 05:58:23 2014 +0000 @@ -6,6 +6,7 @@ #include "ACS.h" #include "fault.h" +#define DEFAULT_POW_MODE 0 //power mode initialization Serial pc(USBTX, USBRX); @@ -14,12 +15,14 @@ Timer t1; //To know the time of entering of each thread -Thread *ptr_t_hk_acq; -Thread *ptr_t_acs; -Thread *ptr_t_acs_write2flash; -Thread *ptr_t_bea; -Thread *ptr_t_bea_telecommand; -Thread *ptr_t_fault; +Thread *ptr_t_hk; //every 20 seconds +Thread *ptr_t_acs; //every 10 seconds +//Thread *ptr_t_acs_write2flash; +Thread *ptr_t_bea; //every 30 seconds +//Thread *ptr_t_bea_telecommand; +//Thread *ptr_t_fault; //will be taken care by HK thread and interrupts +Thread *ptr_t_i2c; //for interprocessor communication +Thread *ptr_t_exec_tc; //Taking data from i2c mail box and execute the stuff //-------------------------------------------------------------------------------------------------------------------------------------------------- @@ -27,38 +30,39 @@ //-------------------------------------------------------------------------------------------------------------------------------------------------- - -void t_hk_acq(void const *args) +extern SensorData Sensor; +void t_hk(void const *args) { - + Sensor.power_mode = DEFAULT_POW_MODE; while(1) { Thread::signal_wait(0x2); printf("\nTHIS IS HK %f\n",t1.read()); - t.start(); - + //t.start(); + FAULTS(); + POWER(Sensor.power_mode); FUNC_HK_MAIN(); //Collecting HK data //thread_2.signal_set(0x4); - FUNC_I2C_SLAVE_MAIN(24); //Sending to CDMS via I2C + // FUNC_I2C_SLAVE_MAIN(24); //Put HK data to I2C thread instead - t.stop(); - printf("The time to execute hk_acq is %f seconds\n",t.read()); - t.reset(); + // t.stop(); + //printf("The time to execute hk_acq is %f seconds\n",t.read()); + //t.reset(); } } //--------------------------------------------------------------------------------------------------------------------------------------- //TASK 1 : ACS //--------------------------------------------------------------------------------------------------------------------------------------- -typedef struct { +/*typedef struct { float mag_field; float omega; } sensor_data; + */ +//Mail <sensor_data, 16> q_acs; //Will be taken care of by HK structure every 20 seconds -Mail <sensor_data, 16> q_acs; - -void func_acs_readdata(sensor_data *ptr) +/*void func_acs_readdata(sensor_data *ptr) { printf("Reading the data\n"); ptr -> mag_field = 10; @@ -76,32 +80,38 @@ { printf("The magnetic field is %.2f T\n\r",ptr2->mag_field); printf("The angular velocity is %.2f rad/s\n\r",ptr2->omega); -} +}*/ -int acs_pflag = 1; +int acs_pflag = 1; //for executing acs power modes void t_acs(void const *args) { + float *mag_field; + float *omega; + float *moment; while(1) { Thread::signal_wait(0x1); printf("\nTHIS IS ACS %f\n",t1.read()); - t.start(); - sensor_data *ptr = q_acs.alloc(); + // t.start(); + // sensor_data *ptr = q_acs.alloc(); //done by HK instead + + //func_acs_readda=ta(ptr); + mag_field= FUNC_ACS_MAG_EXEC(); //actual execution + omega = FUNC_ACS_EXEC_GYR(); - func_acs_readdata(ptr); - //printf("\ngdhd\n"); - q_acs.put(ptr); - if(acs_pflag == 1) + + //q_acs.put(ptr); //done by HK + if(acs_pflag == 1) //for the respective power mode { - func_acs_ctrlalgo(); - FUNC_ACS_GENPWM(); //Generating PWM signal. + moment = FUNC_ACS_CNTRLALGO(mag_field,omega); + FUNC_ACS_GENPWM(moment); //Generating PWM signal. } - t.reset(); + //t.reset(); } } -void t_acs_write2flash(void const *args) +/*void t_acs_write2flash(void const *args) //unwanted thread { while(1) { @@ -115,7 +125,7 @@ } printf("Writing acs data in the flash\n"); } -} +}*/ //---------------------------------------------------BEACON-------------------------------------------------------------------------------------------- @@ -123,7 +133,7 @@ int beac_flag=0; //To receive telecommand from ground. -void t_bea_telecommand(void const *args) +/*void t_bea_telecommand(void const *args) //taken care of by t_exec_tc { char c = pc.getc(); if(c=='a') @@ -132,7 +142,7 @@ beac_flag=1; } } - +*/ void t_bea(void const *args) { @@ -140,21 +150,21 @@ { Thread::signal_wait(0x3); printf("\nTHIS IS BEACON %f\n",t1.read()); - t.start(); + //t.start(); FUNC_BEA(); - if(beac_flag==1) + /*if(beac_flag==1) //beacon standby can be doe to { Thread::wait(600000); beac_flag = 0; - } + }*/ - printf("The time to execute beacon thread is %f seconds\n",t.read()); - t.reset(); + //printf("The time to execute beacon thread is %f seconds\n",t.read()); + //t.reset(); } } @@ -195,9 +205,9 @@ } }*/ -extern SensorData Sensor; +/* void T_FAULT(void const *args) { Sensor.power_mode='0'; @@ -209,7 +219,7 @@ //Sensor.power_mode++; //testing ... should be removed } } - +*/ //------------------------------------------------------------------------------------------------------------------------------------------------ //SCHEDULER //------------------------------------------------------------------------------------------------------------------------------------------------ @@ -230,8 +240,8 @@ } if(schedcount%2==0) { - ptr_t_fault -> signal_set(0x2); - ptr_t_hk_acq -> signal_set(0x2); + // ptr_t_fault -> signal_set(0x2); + ptr_t_hk -> signal_set(0x2); } if(schedcount%beacon_sc==0) @@ -251,28 +261,28 @@ { t1.start(); - ptr_t_hk_acq = new Thread(t_hk_acq); + ptr_t_hk = new Thread(t_hk); ptr_t_acs = new Thread(t_acs); - ptr_t_acs_write2flash = new Thread(t_acs_write2flash); + //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_bea_telecommand = new Thread(t_bea_telecommand); + //ptr_t_fault = new Thread(T_FAULT); //ptr_t_sc = new Thread(t_sc); - ptr_t_fault -> set_priority(osPriorityRealtime); + // 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_hk->set_priority(osPriorityNormal); + //ptr_t_acs_write2flash->set_priority(osPriorityBelowNormal); ptr_t_bea->set_priority(osPriorityAboveNormal); - ptr_t_bea_telecommand->set_priority(osPriorityIdle); + //ptr_t_bea_telecommand->set_priority(osPriorityIdle); //ptr_t_sc->set_priority(osPriorityAboveNormal); // ---------------------------------------------------------------------------------------------- - printf("\n T_FAULT priority is %d",ptr_t_fault->get_priority()); + //printf("\n T_FAULT priority is %d",ptr_t_fault->get_priority()); printf("\n T_ACS priority is %d",ptr_t_acs->get_priority()); - printf("\n T_HK_ACQ priority is %d",ptr_t_hk_acq->get_priority()); - printf("\n T_ACS_WRITE2FLASH priority is %d",ptr_t_acs_write2flash->get_priority()); + printf("\n T_HK_ACQ priority is %d",ptr_t_hk->get_priority()); + //printf("\n T_ACS_WRITE2FLASH priority is %d",ptr_t_acs_write2flash->get_priority()); printf("\n T_BEA priority is %d",ptr_t_bea->get_priority()); RtosTimer t_sc_timer(t_sc,osTimerPeriodic); t_sc_timer.start(10000);