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