![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
i2c slave integrated
Fork of BAE_FRDM_INTEGRATION by
main.cpp@9:a9de938283f9, 2014-12-15 (annotated)
- Committer:
- sakthipriya
- Date:
- Mon Dec 15 11:21:57 2014 +0000
- Revision:
- 9:a9de938283f9
- Parent:
- 8:667fbc82d634
i2c_slave integrated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
greenroshks | 0:8b0d43fe6c05 | 1 | #include "mbed.h" |
greenroshks | 0:8b0d43fe6c05 | 2 | #include "rtos.h" |
greenroshks | 0:8b0d43fe6c05 | 3 | #include "HK.h" |
greenroshks | 0:8b0d43fe6c05 | 4 | #include "slave.h" |
greenroshks | 0:8b0d43fe6c05 | 5 | #include "beacon.h" |
greenroshks | 0:8b0d43fe6c05 | 6 | #include "ACS.h" |
sakthipriya | 2:80b8a2e999f7 | 7 | #include "fault.h" |
sakthipriya | 9:a9de938283f9 | 8 | #include "pin_config.h" |
greenroshks | 0:8b0d43fe6c05 | 9 | |
greenroshks | 8:667fbc82d634 | 10 | #define DEFAULT_POW_MODE 0 //power mode initialization |
greenroshks | 0:8b0d43fe6c05 | 11 | Serial pc(USBTX, USBRX); |
greenroshks | 0:8b0d43fe6c05 | 12 | |
sakthipriya | 9:a9de938283f9 | 13 | InterruptIn interrupt (PIN95); |
sakthipriya | 9:a9de938283f9 | 14 | InterruptIn master_reset(PIN99); |
sakthipriya | 9:a9de938283f9 | 15 | int reset =0; |
sakthipriya | 9:a9de938283f9 | 16 | int i2c_status=0; //read/write mode for i2c 0 : write2slave, 1 : write2master |
sakthipriya | 9:a9de938283f9 | 17 | char data_send[40],data_receive; |
greenroshks | 0:8b0d43fe6c05 | 18 | |
sakthipriya | 5:255b43e8e21a | 19 | Timer t; //To know the time of execution each thread |
sakthipriya | 4:8f6c24eca109 | 20 | Timer t1; |
sakthipriya | 5:255b43e8e21a | 21 | //To know the time of entering of each thread |
greenroshks | 0:8b0d43fe6c05 | 22 | |
greenroshks | 8:667fbc82d634 | 23 | Thread *ptr_t_hk; //every 20 seconds |
greenroshks | 8:667fbc82d634 | 24 | Thread *ptr_t_acs; //every 10 seconds |
greenroshks | 8:667fbc82d634 | 25 | //Thread *ptr_t_acs_write2flash; |
greenroshks | 8:667fbc82d634 | 26 | Thread *ptr_t_bea; //every 30 seconds |
greenroshks | 8:667fbc82d634 | 27 | //Thread *ptr_t_bea_telecommand; |
greenroshks | 8:667fbc82d634 | 28 | //Thread *ptr_t_fault; //will be taken care by HK thread and interrupts |
greenroshks | 8:667fbc82d634 | 29 | Thread *ptr_t_i2c; //for interprocessor communication |
sakthipriya | 9:a9de938283f9 | 30 | Thread *ptr_t_exec_tc; //Taking data from i2c mail box and execute the stuffread |
sakthipriya | 9:a9de938283f9 | 31 | Thread *ptr_t_wdt; //Thread ofr watchdog implementation |
sakthipriya | 9:a9de938283f9 | 32 | |
sakthipriya | 9:a9de938283f9 | 33 | |
sakthipriya | 9:a9de938283f9 | 34 | |
greenroshks | 0:8b0d43fe6c05 | 35 | |
greenroshks | 0:8b0d43fe6c05 | 36 | |
greenroshks | 0:8b0d43fe6c05 | 37 | //-------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 0:8b0d43fe6c05 | 38 | //TASK 2 : HK |
greenroshks | 0:8b0d43fe6c05 | 39 | //-------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 0:8b0d43fe6c05 | 40 | |
sakthipriya | 9:a9de938283f9 | 41 | //char hk_data[100]; |
sakthipriya | 9:a9de938283f9 | 42 | extern SensorData Sensor; |
sakthipriya | 9:a9de938283f9 | 43 | typedef struct{ |
sakthipriya | 9:a9de938283f9 | 44 | char data[40]; |
sakthipriya | 9:a9de938283f9 | 45 | }i2c_hk_data; |
sakthipriya | 9:a9de938283f9 | 46 | DigitalOut data_ready(D10); //PIN NAME TO BE CHANGED |
greenroshks | 0:8b0d43fe6c05 | 47 | |
sakthipriya | 9:a9de938283f9 | 48 | Mail<i2c_hk_data,16> i2c_hk_send; |
sakthipriya | 9:a9de938283f9 | 49 | |
sakthipriya | 9:a9de938283f9 | 50 | |
greenroshks | 8:667fbc82d634 | 51 | void t_hk(void const *args) |
greenroshks | 0:8b0d43fe6c05 | 52 | { |
greenroshks | 8:667fbc82d634 | 53 | Sensor.power_mode = DEFAULT_POW_MODE; |
greenroshks | 0:8b0d43fe6c05 | 54 | while(1) |
greenroshks | 0:8b0d43fe6c05 | 55 | { |
greenroshks | 0:8b0d43fe6c05 | 56 | Thread::signal_wait(0x2); |
greenroshks | 0:8b0d43fe6c05 | 57 | |
greenroshks | 0:8b0d43fe6c05 | 58 | printf("\nTHIS IS HK %f\n",t1.read()); |
greenroshks | 8:667fbc82d634 | 59 | //t.start(); |
greenroshks | 8:667fbc82d634 | 60 | FAULTS(); |
greenroshks | 8:667fbc82d634 | 61 | POWER(Sensor.power_mode); |
sakthipriya | 9:a9de938283f9 | 62 | FUNC_HK_MAIN(); |
sakthipriya | 9:a9de938283f9 | 63 | reset =0; |
sakthipriya | 9:a9de938283f9 | 64 | i2c_status = 1; |
sakthipriya | 9:a9de938283f9 | 65 | data_ready = 0; |
sakthipriya | 9:a9de938283f9 | 66 | char hk_data[40]={Sensor.Voltage[10],Sensor.Current[10],Sensor.Temperature[10],Sensor.PanelTemperature[2],Sensor.Vcell,Sensor.soc,Sensor.alerts,Sensor.crate,Sensor.faultpoll,Sensor.faultir,Sensor.power_mode}; |
sakthipriya | 9:a9de938283f9 | 67 | i2c_hk_data * i2c_hk_data_s = i2c_hk_send.alloc(); |
sakthipriya | 9:a9de938283f9 | 68 | strcpy(i2c_hk_data_s->data,hk_data); |
sakthipriya | 9:a9de938283f9 | 69 | i2c_hk_send.put(i2c_hk_data_s); |
sakthipriya | 9:a9de938283f9 | 70 | data_ready = 1; |
sakthipriya | 9:a9de938283f9 | 71 | |
sakthipriya | 9:a9de938283f9 | 72 | //Collecting HK data |
greenroshks | 0:8b0d43fe6c05 | 73 | //thread_2.signal_set(0x4); |
greenroshks | 8:667fbc82d634 | 74 | // FUNC_I2C_SLAVE_MAIN(24); //Put HK data to I2C thread instead |
greenroshks | 0:8b0d43fe6c05 | 75 | |
greenroshks | 8:667fbc82d634 | 76 | // t.stop(); |
greenroshks | 8:667fbc82d634 | 77 | //printf("The time to execute hk_acq is %f seconds\n",t.read()); |
greenroshks | 8:667fbc82d634 | 78 | //t.reset(); |
greenroshks | 0:8b0d43fe6c05 | 79 | } |
greenroshks | 0:8b0d43fe6c05 | 80 | } |
greenroshks | 0:8b0d43fe6c05 | 81 | |
greenroshks | 0:8b0d43fe6c05 | 82 | //--------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 0:8b0d43fe6c05 | 83 | //TASK 1 : ACS |
greenroshks | 0:8b0d43fe6c05 | 84 | //--------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 8:667fbc82d634 | 85 | /*typedef struct { |
greenroshks | 0:8b0d43fe6c05 | 86 | float mag_field; |
greenroshks | 0:8b0d43fe6c05 | 87 | float omega; |
greenroshks | 0:8b0d43fe6c05 | 88 | } sensor_data; |
greenroshks | 8:667fbc82d634 | 89 | */ |
greenroshks | 8:667fbc82d634 | 90 | //Mail <sensor_data, 16> q_acs; //Will be taken care of by HK structure every 20 seconds |
greenroshks | 0:8b0d43fe6c05 | 91 | |
greenroshks | 8:667fbc82d634 | 92 | /*void func_acs_readdata(sensor_data *ptr) |
greenroshks | 0:8b0d43fe6c05 | 93 | { |
greenroshks | 0:8b0d43fe6c05 | 94 | printf("Reading the data\n"); |
greenroshks | 0:8b0d43fe6c05 | 95 | ptr -> mag_field = 10; |
greenroshks | 0:8b0d43fe6c05 | 96 | ptr -> omega = 3; |
greenroshks | 0:8b0d43fe6c05 | 97 | } |
greenroshks | 0:8b0d43fe6c05 | 98 | |
greenroshks | 0:8b0d43fe6c05 | 99 | void func_acs_ctrlalgo() |
greenroshks | 0:8b0d43fe6c05 | 100 | { |
greenroshks | 0:8b0d43fe6c05 | 101 | printf("Executing control algo\n"); |
greenroshks | 0:8b0d43fe6c05 | 102 | } |
greenroshks | 0:8b0d43fe6c05 | 103 | |
greenroshks | 0:8b0d43fe6c05 | 104 | |
greenroshks | 0:8b0d43fe6c05 | 105 | |
greenroshks | 0:8b0d43fe6c05 | 106 | void func_acs_write2flash(sensor_data *ptr2) |
greenroshks | 0:8b0d43fe6c05 | 107 | { |
greenroshks | 0:8b0d43fe6c05 | 108 | printf("The magnetic field is %.2f T\n\r",ptr2->mag_field); |
greenroshks | 0:8b0d43fe6c05 | 109 | printf("The angular velocity is %.2f rad/s\n\r",ptr2->omega); |
greenroshks | 8:667fbc82d634 | 110 | }*/ |
greenroshks | 0:8b0d43fe6c05 | 111 | |
greenroshks | 8:667fbc82d634 | 112 | int acs_pflag = 1; //for executing acs power modes |
greenroshks | 0:8b0d43fe6c05 | 113 | void t_acs(void const *args) |
greenroshks | 0:8b0d43fe6c05 | 114 | { |
greenroshks | 8:667fbc82d634 | 115 | float *mag_field; |
greenroshks | 8:667fbc82d634 | 116 | float *omega; |
greenroshks | 8:667fbc82d634 | 117 | float *moment; |
greenroshks | 0:8b0d43fe6c05 | 118 | while(1) |
greenroshks | 0:8b0d43fe6c05 | 119 | { |
greenroshks | 0:8b0d43fe6c05 | 120 | Thread::signal_wait(0x1); |
greenroshks | 0:8b0d43fe6c05 | 121 | printf("\nTHIS IS ACS %f\n",t1.read()); |
greenroshks | 8:667fbc82d634 | 122 | // t.start(); |
greenroshks | 8:667fbc82d634 | 123 | // sensor_data *ptr = q_acs.alloc(); //done by HK instead |
greenroshks | 8:667fbc82d634 | 124 | |
greenroshks | 8:667fbc82d634 | 125 | //func_acs_readda=ta(ptr); |
greenroshks | 8:667fbc82d634 | 126 | mag_field= FUNC_ACS_MAG_EXEC(); //actual execution |
greenroshks | 8:667fbc82d634 | 127 | omega = FUNC_ACS_EXEC_GYR(); |
greenroshks | 0:8b0d43fe6c05 | 128 | |
greenroshks | 8:667fbc82d634 | 129 | |
greenroshks | 8:667fbc82d634 | 130 | //q_acs.put(ptr); //done by HK |
greenroshks | 8:667fbc82d634 | 131 | if(acs_pflag == 1) //for the respective power mode |
sakthipriya | 5:255b43e8e21a | 132 | { |
greenroshks | 8:667fbc82d634 | 133 | moment = FUNC_ACS_CNTRLALGO(mag_field,omega); |
greenroshks | 8:667fbc82d634 | 134 | FUNC_ACS_GENPWM(moment); //Generating PWM signal. |
sakthipriya | 5:255b43e8e21a | 135 | } |
greenroshks | 0:8b0d43fe6c05 | 136 | |
greenroshks | 8:667fbc82d634 | 137 | //t.reset(); |
greenroshks | 0:8b0d43fe6c05 | 138 | } |
greenroshks | 0:8b0d43fe6c05 | 139 | } |
greenroshks | 0:8b0d43fe6c05 | 140 | |
greenroshks | 8:667fbc82d634 | 141 | /*void t_acs_write2flash(void const *args) //unwanted thread |
greenroshks | 0:8b0d43fe6c05 | 142 | { |
greenroshks | 0:8b0d43fe6c05 | 143 | while(1) |
greenroshks | 0:8b0d43fe6c05 | 144 | { |
greenroshks | 0:8b0d43fe6c05 | 145 | //printf("Writing in the flash\n"); |
greenroshks | 0:8b0d43fe6c05 | 146 | osEvent evt = q_acs.get(); |
greenroshks | 0:8b0d43fe6c05 | 147 | if(evt.status == osEventMail) |
greenroshks | 0:8b0d43fe6c05 | 148 | { |
greenroshks | 0:8b0d43fe6c05 | 149 | sensor_data *ptr = (sensor_data*)evt.value.p; |
greenroshks | 0:8b0d43fe6c05 | 150 | func_acs_write2flash(ptr); |
greenroshks | 0:8b0d43fe6c05 | 151 | q_acs.free(ptr); |
greenroshks | 0:8b0d43fe6c05 | 152 | } |
greenroshks | 0:8b0d43fe6c05 | 153 | printf("Writing acs data in the flash\n"); |
greenroshks | 0:8b0d43fe6c05 | 154 | } |
greenroshks | 8:667fbc82d634 | 155 | }*/ |
greenroshks | 0:8b0d43fe6c05 | 156 | |
greenroshks | 0:8b0d43fe6c05 | 157 | |
greenroshks | 0:8b0d43fe6c05 | 158 | //---------------------------------------------------BEACON-------------------------------------------------------------------------------------------- |
greenroshks | 0:8b0d43fe6c05 | 159 | |
greenroshks | 0:8b0d43fe6c05 | 160 | int beac_flag=0; //To receive telecommand from ground. |
greenroshks | 0:8b0d43fe6c05 | 161 | |
greenroshks | 0:8b0d43fe6c05 | 162 | |
greenroshks | 8:667fbc82d634 | 163 | /*void t_bea_telecommand(void const *args) //taken care of by t_exec_tc |
greenroshks | 0:8b0d43fe6c05 | 164 | { |
greenroshks | 0:8b0d43fe6c05 | 165 | char c = pc.getc(); |
greenroshks | 0:8b0d43fe6c05 | 166 | if(c=='a') |
greenroshks | 0:8b0d43fe6c05 | 167 | { |
greenroshks | 0:8b0d43fe6c05 | 168 | printf("Telecommand detected\n"); |
greenroshks | 0:8b0d43fe6c05 | 169 | beac_flag=1; |
greenroshks | 0:8b0d43fe6c05 | 170 | } |
greenroshks | 0:8b0d43fe6c05 | 171 | } |
greenroshks | 8:667fbc82d634 | 172 | */ |
greenroshks | 0:8b0d43fe6c05 | 173 | void t_bea(void const *args) |
greenroshks | 0:8b0d43fe6c05 | 174 | { |
greenroshks | 0:8b0d43fe6c05 | 175 | |
greenroshks | 0:8b0d43fe6c05 | 176 | while(1) |
greenroshks | 0:8b0d43fe6c05 | 177 | { |
greenroshks | 0:8b0d43fe6c05 | 178 | Thread::signal_wait(0x3); |
greenroshks | 0:8b0d43fe6c05 | 179 | printf("\nTHIS IS BEACON %f\n",t1.read()); |
greenroshks | 8:667fbc82d634 | 180 | //t.start(); |
greenroshks | 0:8b0d43fe6c05 | 181 | |
greenroshks | 0:8b0d43fe6c05 | 182 | |
greenroshks | 0:8b0d43fe6c05 | 183 | |
greenroshks | 0:8b0d43fe6c05 | 184 | FUNC_BEA(); |
greenroshks | 0:8b0d43fe6c05 | 185 | |
greenroshks | 0:8b0d43fe6c05 | 186 | |
greenroshks | 8:667fbc82d634 | 187 | /*if(beac_flag==1) //beacon standby can be doe to |
greenroshks | 0:8b0d43fe6c05 | 188 | { |
greenroshks | 0:8b0d43fe6c05 | 189 | Thread::wait(600000); |
greenroshks | 0:8b0d43fe6c05 | 190 | beac_flag = 0; |
greenroshks | 8:667fbc82d634 | 191 | }*/ |
greenroshks | 0:8b0d43fe6c05 | 192 | |
greenroshks | 8:667fbc82d634 | 193 | //printf("The time to execute beacon thread is %f seconds\n",t.read()); |
greenroshks | 8:667fbc82d634 | 194 | //t.reset(); |
greenroshks | 0:8b0d43fe6c05 | 195 | } |
greenroshks | 0:8b0d43fe6c05 | 196 | } |
greenroshks | 0:8b0d43fe6c05 | 197 | |
greenroshks | 0:8b0d43fe6c05 | 198 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 0:8b0d43fe6c05 | 199 | //TASK 4 : FAULT MANAGEMENT |
greenroshks | 0:8b0d43fe6c05 | 200 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 0:8b0d43fe6c05 | 201 | //Dummy fault rectifier functions |
greenroshks | 0:8b0d43fe6c05 | 202 | |
sakthipriya | 2:80b8a2e999f7 | 203 | /*Mail<int,16> faults; |
greenroshks | 0:8b0d43fe6c05 | 204 | |
greenroshks | 0:8b0d43fe6c05 | 205 | void FUNC_FAULT_FUNCT1() |
greenroshks | 0:8b0d43fe6c05 | 206 | { |
greenroshks | 0:8b0d43fe6c05 | 207 | printf("\nFault 1 detected... \n"); |
greenroshks | 0:8b0d43fe6c05 | 208 | } |
greenroshks | 0:8b0d43fe6c05 | 209 | |
greenroshks | 0:8b0d43fe6c05 | 210 | void FUNC_FAULT_FUNCT2() |
greenroshks | 0:8b0d43fe6c05 | 211 | { |
greenroshks | 0:8b0d43fe6c05 | 212 | printf("\nFault 2 detected...\n"); |
greenroshks | 0:8b0d43fe6c05 | 213 | } |
greenroshks | 0:8b0d43fe6c05 | 214 | |
greenroshks | 0:8b0d43fe6c05 | 215 | void T_FAULT(void const *args) |
greenroshks | 0:8b0d43fe6c05 | 216 | { |
greenroshks | 0:8b0d43fe6c05 | 217 | while(1) |
greenroshks | 0:8b0d43fe6c05 | 218 | { |
greenroshks | 0:8b0d43fe6c05 | 219 | osEvent evt = faults.get(); |
greenroshks | 0:8b0d43fe6c05 | 220 | if(evt.status==osEventMail) |
greenroshks | 0:8b0d43fe6c05 | 221 | { |
greenroshks | 0:8b0d43fe6c05 | 222 | int *fault_id= (int *)evt.value.p; |
greenroshks | 0:8b0d43fe6c05 | 223 | switch(*fault_id) |
greenroshks | 0:8b0d43fe6c05 | 224 | { |
greenroshks | 0:8b0d43fe6c05 | 225 | case 1: FUNC_FAULT_FUNCT1(); |
greenroshks | 0:8b0d43fe6c05 | 226 | break; |
greenroshks | 0:8b0d43fe6c05 | 227 | case 2: FUNC_FAULT_FUNCT2(); |
greenroshks | 0:8b0d43fe6c05 | 228 | break; |
greenroshks | 0:8b0d43fe6c05 | 229 | } |
greenroshks | 0:8b0d43fe6c05 | 230 | faults.free(fault_id); |
greenroshks | 0:8b0d43fe6c05 | 231 | } |
greenroshks | 0:8b0d43fe6c05 | 232 | } |
sakthipriya | 2:80b8a2e999f7 | 233 | }*/ |
sakthipriya | 5:255b43e8e21a | 234 | |
raizel_varun | 6:e65b1ab79f36 | 235 | |
raizel_varun | 6:e65b1ab79f36 | 236 | |
greenroshks | 8:667fbc82d634 | 237 | /* |
sakthipriya | 2:80b8a2e999f7 | 238 | void T_FAULT(void const *args) |
sakthipriya | 4:8f6c24eca109 | 239 | { |
sakthipriya | 5:255b43e8e21a | 240 | Sensor.power_mode='0'; |
sakthipriya | 2:80b8a2e999f7 | 241 | while(1) |
sakthipriya | 2:80b8a2e999f7 | 242 | { |
sakthipriya | 2:80b8a2e999f7 | 243 | Thread :: signal_wait(0x2); |
sakthipriya | 2:80b8a2e999f7 | 244 | FAULTS(); |
sakthipriya | 5:255b43e8e21a | 245 | POWER(Sensor.power_mode); |
sakthipriya | 5:255b43e8e21a | 246 | //Sensor.power_mode++; //testing ... should be removed |
sakthipriya | 2:80b8a2e999f7 | 247 | } |
greenroshks | 0:8b0d43fe6c05 | 248 | } |
sakthipriya | 9:a9de938283f9 | 249 | /*------------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 9:a9de938283f9 | 250 | -------------------------------------------------------WATCHDOG----------------------------------------------------------------------------*/ |
sakthipriya | 9:a9de938283f9 | 251 | DigitalOut trigger(PIN63); // has to be changed |
sakthipriya | 9:a9de938283f9 | 252 | void T_WDT(void const * args) |
sakthipriya | 9:a9de938283f9 | 253 | { |
sakthipriya | 9:a9de938283f9 | 254 | trigger = 1; |
sakthipriya | 9:a9de938283f9 | 255 | while(true) |
sakthipriya | 9:a9de938283f9 | 256 | { |
sakthipriya | 9:a9de938283f9 | 257 | Thread::signal_wait(0x5); //signal set from scheduler or sthing. r RTOS timer nce the timing is finalized |
sakthipriya | 9:a9de938283f9 | 258 | printf("\nEntered WD\n"); |
sakthipriya | 9:a9de938283f9 | 259 | trigger = !trigger; |
sakthipriya | 9:a9de938283f9 | 260 | } |
sakthipriya | 9:a9de938283f9 | 261 | } |
sakthipriya | 9:a9de938283f9 | 262 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
sakthipriya | 9:a9de938283f9 | 263 | //SLAVE |
sakthipriya | 9:a9de938283f9 | 264 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
sakthipriya | 9:a9de938283f9 | 265 | typedef struct |
sakthipriya | 9:a9de938283f9 | 266 | { |
sakthipriya | 9:a9de938283f9 | 267 | char data; // To avoid dynamic memory allocation |
sakthipriya | 9:a9de938283f9 | 268 | }i2c_data; |
sakthipriya | 9:a9de938283f9 | 269 | Mail<i2c_data,16> i2c_data_receive; //to be uncommented when receiving data |
sakthipriya | 9:a9de938283f9 | 270 | |
sakthipriya | 9:a9de938283f9 | 271 | |
sakthipriya | 9:a9de938283f9 | 272 | void FUNC_INT() |
sakthipriya | 9:a9de938283f9 | 273 | { |
sakthipriya | 9:a9de938283f9 | 274 | reset = 0; |
sakthipriya | 9:a9de938283f9 | 275 | ptr_t_i2c->signal_set(0x4); |
sakthipriya | 9:a9de938283f9 | 276 | } |
sakthipriya | 9:a9de938283f9 | 277 | |
sakthipriya | 9:a9de938283f9 | 278 | void FUNC_RESET() |
sakthipriya | 9:a9de938283f9 | 279 | { |
sakthipriya | 9:a9de938283f9 | 280 | reset = 1; |
sakthipriya | 9:a9de938283f9 | 281 | } |
sakthipriya | 9:a9de938283f9 | 282 | |
sakthipriya | 9:a9de938283f9 | 283 | |
sakthipriya | 9:a9de938283f9 | 284 | void T_I2C_BAE(void const * args) |
sakthipriya | 9:a9de938283f9 | 285 | { |
sakthipriya | 9:a9de938283f9 | 286 | //char data_send,data_receive; |
sakthipriya | 9:a9de938283f9 | 287 | while(1) |
sakthipriya | 9:a9de938283f9 | 288 | { |
sakthipriya | 9:a9de938283f9 | 289 | Thread::signal_wait(0x4); |
sakthipriya | 9:a9de938283f9 | 290 | printf("\n entered thread\n\r"); |
sakthipriya | 9:a9de938283f9 | 291 | if(i2c_status == 0 && reset !=1) |
sakthipriya | 9:a9de938283f9 | 292 | { |
sakthipriya | 9:a9de938283f9 | 293 | |
sakthipriya | 9:a9de938283f9 | 294 | FUNC_I2C_WRITE2CDMS(&data_receive,1); |
sakthipriya | 9:a9de938283f9 | 295 | i2c_data * i2c_data_r = i2c_data_receive.alloc(); |
sakthipriya | 9:a9de938283f9 | 296 | i2c_data_r->data = data_receive; |
sakthipriya | 9:a9de938283f9 | 297 | |
sakthipriya | 9:a9de938283f9 | 298 | i2c_data_receive.put(i2c_data_r); |
sakthipriya | 9:a9de938283f9 | 299 | printf("\n Data received from CDMS is %c\n\r",data_receive); |
sakthipriya | 9:a9de938283f9 | 300 | i2c_data_receive.free(i2c_data_r); // This has to be done from a differen thread |
sakthipriya | 9:a9de938283f9 | 301 | |
sakthipriya | 9:a9de938283f9 | 302 | } |
sakthipriya | 9:a9de938283f9 | 303 | else if(i2c_status ==1 && reset !=1) |
sakthipriya | 9:a9de938283f9 | 304 | { |
sakthipriya | 9:a9de938283f9 | 305 | osEvent evt = i2c_hk_send.get(); |
sakthipriya | 9:a9de938283f9 | 306 | if (evt.status == osEventMail) |
sakthipriya | 9:a9de938283f9 | 307 | { |
sakthipriya | 9:a9de938283f9 | 308 | i2c_hk_data *i2c_hk_data_s = (i2c_hk_data*)evt.value.p; |
sakthipriya | 9:a9de938283f9 | 309 | strcpy(data_send,i2c_hk_data_s -> data); |
sakthipriya | 9:a9de938283f9 | 310 | FUNC_I2C_WRITE2CDMS(data_send,40); |
sakthipriya | 9:a9de938283f9 | 311 | printf("\nData sent to CDMS is %s\n\r",data_send); |
sakthipriya | 9:a9de938283f9 | 312 | i2c_hk_send.free(i2c_hk_data_s); //This has to be done in a different thread |
sakthipriya | 9:a9de938283f9 | 313 | i2c_status = 0; |
sakthipriya | 9:a9de938283f9 | 314 | //temp = i2c_status; |
sakthipriya | 9:a9de938283f9 | 315 | } |
sakthipriya | 9:a9de938283f9 | 316 | } |
sakthipriya | 9:a9de938283f9 | 317 | |
sakthipriya | 9:a9de938283f9 | 318 | } |
sakthipriya | 9:a9de938283f9 | 319 | } |
sakthipriya | 9:a9de938283f9 | 320 | |
sakthipriya | 9:a9de938283f9 | 321 | |
greenroshks | 0:8b0d43fe6c05 | 322 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
greenroshks | 0:8b0d43fe6c05 | 323 | //SCHEDULER |
greenroshks | 0:8b0d43fe6c05 | 324 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
sakthipriya | 4:8f6c24eca109 | 325 | int beacon_sc = 3; |
greenroshks | 0:8b0d43fe6c05 | 326 | uint16_t schedcount=1; |
greenroshks | 0:8b0d43fe6c05 | 327 | void t_sc(void const *args) |
greenroshks | 0:8b0d43fe6c05 | 328 | { |
greenroshks | 0:8b0d43fe6c05 | 329 | |
greenroshks | 0:8b0d43fe6c05 | 330 | printf("The value of i in scheduler is %d\n",schedcount); |
greenroshks | 0:8b0d43fe6c05 | 331 | if(schedcount == 65532) //to reset the counter |
greenroshks | 0:8b0d43fe6c05 | 332 | { |
greenroshks | 0:8b0d43fe6c05 | 333 | schedcount = 0; |
greenroshks | 0:8b0d43fe6c05 | 334 | } |
greenroshks | 0:8b0d43fe6c05 | 335 | |
greenroshks | 0:8b0d43fe6c05 | 336 | if(schedcount%1==0) |
greenroshks | 0:8b0d43fe6c05 | 337 | { |
greenroshks | 0:8b0d43fe6c05 | 338 | ptr_t_acs -> signal_set(0x1); |
greenroshks | 0:8b0d43fe6c05 | 339 | } |
greenroshks | 0:8b0d43fe6c05 | 340 | if(schedcount%2==0) |
greenroshks | 0:8b0d43fe6c05 | 341 | { |
greenroshks | 8:667fbc82d634 | 342 | // ptr_t_fault -> signal_set(0x2); |
greenroshks | 8:667fbc82d634 | 343 | ptr_t_hk -> signal_set(0x2); |
sakthipriya | 2:80b8a2e999f7 | 344 | |
greenroshks | 0:8b0d43fe6c05 | 345 | } |
sakthipriya | 4:8f6c24eca109 | 346 | if(schedcount%beacon_sc==0) |
greenroshks | 0:8b0d43fe6c05 | 347 | { |
greenroshks | 0:8b0d43fe6c05 | 348 | if(beac_flag==0) |
greenroshks | 0:8b0d43fe6c05 | 349 | { |
greenroshks | 0:8b0d43fe6c05 | 350 | |
greenroshks | 0:8b0d43fe6c05 | 351 | ptr_t_bea -> signal_set(0x3); |
greenroshks | 0:8b0d43fe6c05 | 352 | } |
greenroshks | 0:8b0d43fe6c05 | 353 | } |
greenroshks | 0:8b0d43fe6c05 | 354 | schedcount++; |
greenroshks | 0:8b0d43fe6c05 | 355 | } |
greenroshks | 0:8b0d43fe6c05 | 356 | |
greenroshks | 0:8b0d43fe6c05 | 357 | //--------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 0:8b0d43fe6c05 | 358 | |
greenroshks | 0:8b0d43fe6c05 | 359 | int main() |
greenroshks | 0:8b0d43fe6c05 | 360 | { |
greenroshks | 0:8b0d43fe6c05 | 361 | t1.start(); |
greenroshks | 0:8b0d43fe6c05 | 362 | |
greenroshks | 8:667fbc82d634 | 363 | ptr_t_hk = new Thread(t_hk); |
greenroshks | 0:8b0d43fe6c05 | 364 | ptr_t_acs = new Thread(t_acs); |
sakthipriya | 9:a9de938283f9 | 365 | |
greenroshks | 0:8b0d43fe6c05 | 366 | ptr_t_bea = new Thread(t_bea); |
sakthipriya | 9:a9de938283f9 | 367 | ptr_t_wdt = new Thread(T_WDT); |
sakthipriya | 9:a9de938283f9 | 368 | ptr_t_i2c = new Thread(T_I2C_BAE); |
greenroshks | 0:8b0d43fe6c05 | 369 | |
greenroshks | 8:667fbc82d634 | 370 | // ptr_t_fault -> set_priority(osPriorityRealtime); |
greenroshks | 0:8b0d43fe6c05 | 371 | ptr_t_acs->set_priority(osPriorityHigh); |
greenroshks | 8:667fbc82d634 | 372 | ptr_t_hk->set_priority(osPriorityNormal); |
greenroshks | 8:667fbc82d634 | 373 | //ptr_t_acs_write2flash->set_priority(osPriorityBelowNormal); |
greenroshks | 0:8b0d43fe6c05 | 374 | ptr_t_bea->set_priority(osPriorityAboveNormal); |
sakthipriya | 9:a9de938283f9 | 375 | ptr_t_i2c->set_priority(osPriorityAboveNormal); |
greenroshks | 8:667fbc82d634 | 376 | //ptr_t_bea_telecommand->set_priority(osPriorityIdle); |
greenroshks | 0:8b0d43fe6c05 | 377 | //ptr_t_sc->set_priority(osPriorityAboveNormal); |
sakthipriya | 9:a9de938283f9 | 378 | ptr_t_wdt -> set_priority(osPriorityIdle); |
greenroshks | 0:8b0d43fe6c05 | 379 | |
greenroshks | 0:8b0d43fe6c05 | 380 | |
greenroshks | 0:8b0d43fe6c05 | 381 | // ---------------------------------------------------------------------------------------------- |
greenroshks | 8:667fbc82d634 | 382 | //printf("\n T_FAULT priority is %d",ptr_t_fault->get_priority()); |
greenroshks | 0:8b0d43fe6c05 | 383 | printf("\n T_ACS priority is %d",ptr_t_acs->get_priority()); |
greenroshks | 8:667fbc82d634 | 384 | printf("\n T_HK_ACQ priority is %d",ptr_t_hk->get_priority()); |
greenroshks | 8:667fbc82d634 | 385 | //printf("\n T_ACS_WRITE2FLASH priority is %d",ptr_t_acs_write2flash->get_priority()); |
greenroshks | 0:8b0d43fe6c05 | 386 | printf("\n T_BEA priority is %d",ptr_t_bea->get_priority()); |
greenroshks | 0:8b0d43fe6c05 | 387 | RtosTimer t_sc_timer(t_sc,osTimerPeriodic); |
greenroshks | 0:8b0d43fe6c05 | 388 | t_sc_timer.start(10000); |
greenroshks | 0:8b0d43fe6c05 | 389 | printf("\n%f\n",t1.read()); |
sakthipriya | 9:a9de938283f9 | 390 | |
sakthipriya | 9:a9de938283f9 | 391 | interrupt.rise(&FUNC_INT); |
sakthipriya | 9:a9de938283f9 | 392 | master_reset.fall(&FUNC_RESET); |
greenroshks | 0:8b0d43fe6c05 | 393 | |
greenroshks | 0:8b0d43fe6c05 | 394 | while(1) |
raizel_varun | 7:f06840d848e3 | 395 | { |
greenroshks | 0:8b0d43fe6c05 | 396 | Thread::wait(10000); |
greenroshks | 0:8b0d43fe6c05 | 397 | ; |
greenroshks | 0:8b0d43fe6c05 | 398 | } |
greenroshks | 0:8b0d43fe6c05 | 399 | |
greenroshks | 0:8b0d43fe6c05 | 400 | } |