sakthi priya amirtharaj
/
BAE_vr2_1_3
i2c working with old hk
Fork of BAE_vr2_1_1 by
main.cpp@13:1b37d98840d3, 2014-12-17 (annotated)
- Committer:
- greenroshks
- Date:
- Wed Dec 17 05:25:04 2014 +0000
- Revision:
- 13:1b37d98840d3
- Parent:
- 12:ba2556c6b990
- Child:
- 14:ef6be8ac6569
The one with the new HK
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" |
raizel_varun | 9:221d218f4690 | 8 | #include "slave.h" |
greenroshks | 0:8b0d43fe6c05 | 9 | |
greenroshks | 0:8b0d43fe6c05 | 10 | Serial pc(USBTX, USBRX); |
greenroshks | 0:8b0d43fe6c05 | 11 | |
raizel_varun | 9:221d218f4690 | 12 | InterruptIn interrupt(D9); |
raizel_varun | 9:221d218f4690 | 13 | InterruptIn master_reset(D11); |
greenroshks | 0:8b0d43fe6c05 | 14 | |
greenroshks | 0:8b0d43fe6c05 | 15 | |
sakthipriya | 5:255b43e8e21a | 16 | Timer t; //To know the time of execution each thread |
sakthipriya | 4:8f6c24eca109 | 17 | Timer t1; |
sakthipriya | 5:255b43e8e21a | 18 | //To know the time of entering of each thread |
greenroshks | 0:8b0d43fe6c05 | 19 | |
greenroshks | 0:8b0d43fe6c05 | 20 | Thread *ptr_t_hk_acq; |
greenroshks | 0:8b0d43fe6c05 | 21 | Thread *ptr_t_acs; |
greenroshks | 13:1b37d98840d3 | 22 | //Thread *ptr_t_acs_write2flash; |
greenroshks | 0:8b0d43fe6c05 | 23 | Thread *ptr_t_bea; |
greenroshks | 13:1b37d98840d3 | 24 | //Thread *ptr_t_bea_telecommand; |
greenroshks | 13:1b37d98840d3 | 25 | //Thread *ptr_t_fault; |
raizel_varun | 9:221d218f4690 | 26 | Thread *ptr_t_i2c; |
greenroshks | 0:8b0d43fe6c05 | 27 | |
raizel_varun | 12:ba2556c6b990 | 28 | |
raizel_varun | 12:ba2556c6b990 | 29 | |
raizel_varun | 12:ba2556c6b990 | 30 | |
raizel_varun | 12:ba2556c6b990 | 31 | void write_to_master(char); //function to write data to master |
raizel_varun | 12:ba2556c6b990 | 32 | |
raizel_varun | 12:ba2556c6b990 | 33 | I2CSlave slave(D14,D15); //configuring pins p27, p28 as I2Cslave |
raizel_varun | 12:ba2556c6b990 | 34 | |
raizel_varun | 12:ba2556c6b990 | 35 | |
raizel_varun | 12:ba2556c6b990 | 36 | DigitalOut data_ready(D10); |
raizel_varun | 12:ba2556c6b990 | 37 | int i2c_status=0; //read/write mode for i2c 0 : write2slave, 1 : write2master |
raizel_varun | 12:ba2556c6b990 | 38 | int reset=0; |
raizel_varun | 12:ba2556c6b990 | 39 | int temp; |
raizel_varun | 12:ba2556c6b990 | 40 | |
raizel_varun | 12:ba2556c6b990 | 41 | typedef struct |
raizel_varun | 12:ba2556c6b990 | 42 | { |
greenroshks | 13:1b37d98840d3 | 43 | char data[21]; // To avoid dynamic memory allocation |
raizel_varun | 12:ba2556c6b990 | 44 | int length; |
raizel_varun | 12:ba2556c6b990 | 45 | }i2c_data; |
raizel_varun | 12:ba2556c6b990 | 46 | |
raizel_varun | 12:ba2556c6b990 | 47 | |
raizel_varun | 12:ba2556c6b990 | 48 | |
raizel_varun | 12:ba2556c6b990 | 49 | |
raizel_varun | 12:ba2556c6b990 | 50 | |
raizel_varun | 12:ba2556c6b990 | 51 | |
raizel_varun | 12:ba2556c6b990 | 52 | Mail<i2c_data,16> i2c_data_receive; |
raizel_varun | 12:ba2556c6b990 | 53 | Mail<i2c_data,16> i2c_data_send; |
raizel_varun | 12:ba2556c6b990 | 54 | |
greenroshks | 0:8b0d43fe6c05 | 55 | //-------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 0:8b0d43fe6c05 | 56 | //TASK 2 : HK |
greenroshks | 0:8b0d43fe6c05 | 57 | //-------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 0:8b0d43fe6c05 | 58 | |
greenroshks | 13:1b37d98840d3 | 59 | char hk_data[21]; |
greenroshks | 13:1b37d98840d3 | 60 | extern SensorDataQuantised SensorQuantised; |
greenroshks | 0:8b0d43fe6c05 | 61 | void t_hk_acq(void const *args) |
greenroshks | 0:8b0d43fe6c05 | 62 | { |
greenroshks | 0:8b0d43fe6c05 | 63 | |
greenroshks | 0:8b0d43fe6c05 | 64 | while(1) |
greenroshks | 0:8b0d43fe6c05 | 65 | { |
greenroshks | 0:8b0d43fe6c05 | 66 | Thread::signal_wait(0x2); |
greenroshks | 13:1b37d98840d3 | 67 | SensorQuantised.power_mode='0'; |
greenroshks | 0:8b0d43fe6c05 | 68 | printf("\nTHIS IS HK %f\n",t1.read()); |
greenroshks | 0:8b0d43fe6c05 | 69 | t.start(); |
greenroshks | 13:1b37d98840d3 | 70 | FAULTS(); |
greenroshks | 13:1b37d98840d3 | 71 | POWER(SensorQuantised.power_mode); //The power mode algorithm is yet to be obtained |
greenroshks | 0:8b0d43fe6c05 | 72 | FUNC_HK_MAIN(); //Collecting HK data |
greenroshks | 0:8b0d43fe6c05 | 73 | //thread_2.signal_set(0x4); |
raizel_varun | 12:ba2556c6b990 | 74 | //FUNC_I2C_SLAVE_MAIN(24); |
greenroshks | 13:1b37d98840d3 | 75 | ir2master(); |
greenroshks | 0:8b0d43fe6c05 | 76 | t.stop(); |
greenroshks | 0:8b0d43fe6c05 | 77 | printf("The time to execute hk_acq is %f seconds\n",t.read()); |
greenroshks | 0:8b0d43fe6c05 | 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 | 0:8b0d43fe6c05 | 85 | |
sakthipriya | 5:255b43e8e21a | 86 | int acs_pflag = 1; |
greenroshks | 0:8b0d43fe6c05 | 87 | void t_acs(void const *args) |
greenroshks | 0:8b0d43fe6c05 | 88 | { |
greenroshks | 13:1b37d98840d3 | 89 | float *mag_field; |
greenroshks | 13:1b37d98840d3 | 90 | float *omega; |
greenroshks | 13:1b37d98840d3 | 91 | float *moment; |
greenroshks | 0:8b0d43fe6c05 | 92 | while(1) |
greenroshks | 0:8b0d43fe6c05 | 93 | { |
greenroshks | 0:8b0d43fe6c05 | 94 | Thread::signal_wait(0x1); |
greenroshks | 0:8b0d43fe6c05 | 95 | printf("\nTHIS IS ACS %f\n",t1.read()); |
greenroshks | 0:8b0d43fe6c05 | 96 | t.start(); |
greenroshks | 13:1b37d98840d3 | 97 | mag_field= FUNC_ACS_MAG_EXEC(); //actual execution |
greenroshks | 13:1b37d98840d3 | 98 | omega = FUNC_ACS_EXEC_GYR(); |
greenroshks | 0:8b0d43fe6c05 | 99 | |
greenroshks | 13:1b37d98840d3 | 100 | |
greenroshks | 13:1b37d98840d3 | 101 | |
sakthipriya | 5:255b43e8e21a | 102 | if(acs_pflag == 1) |
sakthipriya | 5:255b43e8e21a | 103 | { |
greenroshks | 13:1b37d98840d3 | 104 | moment = FUNC_ACS_CNTRLALGO(mag_field,omega); |
greenroshks | 13:1b37d98840d3 | 105 | FUNC_ACS_GENPWM(moment); |
sakthipriya | 5:255b43e8e21a | 106 | } |
greenroshks | 0:8b0d43fe6c05 | 107 | |
greenroshks | 0:8b0d43fe6c05 | 108 | t.reset(); |
greenroshks | 0:8b0d43fe6c05 | 109 | } |
greenroshks | 0:8b0d43fe6c05 | 110 | } |
greenroshks | 13:1b37d98840d3 | 111 | /* |
greenroshks | 0:8b0d43fe6c05 | 112 | void t_acs_write2flash(void const *args) |
greenroshks | 0:8b0d43fe6c05 | 113 | { |
greenroshks | 0:8b0d43fe6c05 | 114 | while(1) |
greenroshks | 0:8b0d43fe6c05 | 115 | { |
greenroshks | 0:8b0d43fe6c05 | 116 | //printf("Writing in the flash\n"); |
greenroshks | 0:8b0d43fe6c05 | 117 | osEvent evt = q_acs.get(); |
greenroshks | 0:8b0d43fe6c05 | 118 | if(evt.status == osEventMail) |
greenroshks | 0:8b0d43fe6c05 | 119 | { |
greenroshks | 0:8b0d43fe6c05 | 120 | sensor_data *ptr = (sensor_data*)evt.value.p; |
greenroshks | 0:8b0d43fe6c05 | 121 | func_acs_write2flash(ptr); |
greenroshks | 0:8b0d43fe6c05 | 122 | q_acs.free(ptr); |
greenroshks | 0:8b0d43fe6c05 | 123 | } |
greenroshks | 0:8b0d43fe6c05 | 124 | printf("Writing acs data in the flash\n"); |
greenroshks | 0:8b0d43fe6c05 | 125 | } |
greenroshks | 0:8b0d43fe6c05 | 126 | } |
greenroshks | 0:8b0d43fe6c05 | 127 | |
greenroshks | 13:1b37d98840d3 | 128 | */ |
greenroshks | 0:8b0d43fe6c05 | 129 | //---------------------------------------------------BEACON-------------------------------------------------------------------------------------------- |
greenroshks | 0:8b0d43fe6c05 | 130 | |
greenroshks | 0:8b0d43fe6c05 | 131 | int beac_flag=0; //To receive telecommand from ground. |
greenroshks | 0:8b0d43fe6c05 | 132 | |
greenroshks | 0:8b0d43fe6c05 | 133 | |
greenroshks | 13:1b37d98840d3 | 134 | /*void t_bea_telecommand(void const *args) |
greenroshks | 0:8b0d43fe6c05 | 135 | { |
greenroshks | 0:8b0d43fe6c05 | 136 | char c = pc.getc(); |
greenroshks | 0:8b0d43fe6c05 | 137 | if(c=='a') |
greenroshks | 0:8b0d43fe6c05 | 138 | { |
greenroshks | 0:8b0d43fe6c05 | 139 | printf("Telecommand detected\n"); |
greenroshks | 0:8b0d43fe6c05 | 140 | beac_flag=1; |
greenroshks | 0:8b0d43fe6c05 | 141 | } |
greenroshks | 0:8b0d43fe6c05 | 142 | } |
greenroshks | 13:1b37d98840d3 | 143 | */ |
greenroshks | 0:8b0d43fe6c05 | 144 | |
greenroshks | 0:8b0d43fe6c05 | 145 | void t_bea(void const *args) |
greenroshks | 0:8b0d43fe6c05 | 146 | { |
greenroshks | 0:8b0d43fe6c05 | 147 | |
greenroshks | 0:8b0d43fe6c05 | 148 | while(1) |
greenroshks | 0:8b0d43fe6c05 | 149 | { |
greenroshks | 0:8b0d43fe6c05 | 150 | Thread::signal_wait(0x3); |
greenroshks | 0:8b0d43fe6c05 | 151 | printf("\nTHIS IS BEACON %f\n",t1.read()); |
greenroshks | 0:8b0d43fe6c05 | 152 | t.start(); |
greenroshks | 0:8b0d43fe6c05 | 153 | |
greenroshks | 0:8b0d43fe6c05 | 154 | |
greenroshks | 0:8b0d43fe6c05 | 155 | |
greenroshks | 0:8b0d43fe6c05 | 156 | FUNC_BEA(); |
greenroshks | 0:8b0d43fe6c05 | 157 | |
greenroshks | 0:8b0d43fe6c05 | 158 | |
greenroshks | 0:8b0d43fe6c05 | 159 | if(beac_flag==1) |
greenroshks | 0:8b0d43fe6c05 | 160 | { |
greenroshks | 0:8b0d43fe6c05 | 161 | Thread::wait(600000); |
greenroshks | 0:8b0d43fe6c05 | 162 | beac_flag = 0; |
greenroshks | 0:8b0d43fe6c05 | 163 | } |
greenroshks | 0:8b0d43fe6c05 | 164 | |
greenroshks | 0:8b0d43fe6c05 | 165 | printf("The time to execute beacon thread is %f seconds\n",t.read()); |
greenroshks | 0:8b0d43fe6c05 | 166 | t.reset(); |
greenroshks | 0:8b0d43fe6c05 | 167 | } |
greenroshks | 0:8b0d43fe6c05 | 168 | } |
greenroshks | 0:8b0d43fe6c05 | 169 | |
greenroshks | 0:8b0d43fe6c05 | 170 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 0:8b0d43fe6c05 | 171 | //TASK 4 : FAULT MANAGEMENT |
greenroshks | 0:8b0d43fe6c05 | 172 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 0:8b0d43fe6c05 | 173 | //Dummy fault rectifier functions |
greenroshks | 0:8b0d43fe6c05 | 174 | |
sakthipriya | 2:80b8a2e999f7 | 175 | /*Mail<int,16> faults; |
greenroshks | 0:8b0d43fe6c05 | 176 | |
greenroshks | 0:8b0d43fe6c05 | 177 | void FUNC_FAULT_FUNCT1() |
greenroshks | 0:8b0d43fe6c05 | 178 | { |
greenroshks | 0:8b0d43fe6c05 | 179 | printf("\nFault 1 detected... \n"); |
greenroshks | 0:8b0d43fe6c05 | 180 | } |
greenroshks | 0:8b0d43fe6c05 | 181 | |
greenroshks | 0:8b0d43fe6c05 | 182 | void FUNC_FAULT_FUNCT2() |
greenroshks | 0:8b0d43fe6c05 | 183 | { |
greenroshks | 0:8b0d43fe6c05 | 184 | printf("\nFault 2 detected...\n"); |
greenroshks | 0:8b0d43fe6c05 | 185 | } |
greenroshks | 0:8b0d43fe6c05 | 186 | |
greenroshks | 0:8b0d43fe6c05 | 187 | void T_FAULT(void const *args) |
greenroshks | 0:8b0d43fe6c05 | 188 | { |
greenroshks | 0:8b0d43fe6c05 | 189 | while(1) |
greenroshks | 0:8b0d43fe6c05 | 190 | { |
greenroshks | 0:8b0d43fe6c05 | 191 | osEvent evt = faults.get(); |
greenroshks | 0:8b0d43fe6c05 | 192 | if(evt.status==osEventMail) |
greenroshks | 0:8b0d43fe6c05 | 193 | { |
greenroshks | 0:8b0d43fe6c05 | 194 | int *fault_id= (int *)evt.value.p; |
greenroshks | 0:8b0d43fe6c05 | 195 | switch(*fault_id) |
greenroshks | 0:8b0d43fe6c05 | 196 | { |
greenroshks | 0:8b0d43fe6c05 | 197 | case 1: FUNC_FAULT_FUNCT1(); |
greenroshks | 0:8b0d43fe6c05 | 198 | break; |
greenroshks | 0:8b0d43fe6c05 | 199 | case 2: FUNC_FAULT_FUNCT2(); |
greenroshks | 0:8b0d43fe6c05 | 200 | break; |
greenroshks | 0:8b0d43fe6c05 | 201 | } |
greenroshks | 0:8b0d43fe6c05 | 202 | faults.free(fault_id); |
greenroshks | 0:8b0d43fe6c05 | 203 | } |
greenroshks | 0:8b0d43fe6c05 | 204 | } |
sakthipriya | 2:80b8a2e999f7 | 205 | }*/ |
sakthipriya | 5:255b43e8e21a | 206 | |
greenroshks | 13:1b37d98840d3 | 207 | extern SensorDataQuantised SensorQuantised; |
raizel_varun | 6:e65b1ab79f36 | 208 | |
raizel_varun | 6:e65b1ab79f36 | 209 | |
greenroshks | 13:1b37d98840d3 | 210 | /*void T_FAULT(void const *args) |
sakthipriya | 4:8f6c24eca109 | 211 | { |
sakthipriya | 5:255b43e8e21a | 212 | Sensor.power_mode='0'; |
sakthipriya | 2:80b8a2e999f7 | 213 | while(1) |
sakthipriya | 2:80b8a2e999f7 | 214 | { |
sakthipriya | 2:80b8a2e999f7 | 215 | Thread :: signal_wait(0x2); |
sakthipriya | 2:80b8a2e999f7 | 216 | FAULTS(); |
sakthipriya | 5:255b43e8e21a | 217 | POWER(Sensor.power_mode); |
sakthipriya | 5:255b43e8e21a | 218 | //Sensor.power_mode++; //testing ... should be removed |
sakthipriya | 2:80b8a2e999f7 | 219 | } |
greenroshks | 0:8b0d43fe6c05 | 220 | } |
greenroshks | 13:1b37d98840d3 | 221 | */ |
raizel_varun | 9:221d218f4690 | 222 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
raizel_varun | 9:221d218f4690 | 223 | //TASK 5 : i2c data |
raizel_varun | 9:221d218f4690 | 224 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
raizel_varun | 9:221d218f4690 | 225 | |
raizel_varun | 9:221d218f4690 | 226 | |
raizel_varun | 9:221d218f4690 | 227 | void C_FUNC_INT() |
raizel_varun | 9:221d218f4690 | 228 | { |
raizel_varun | 9:221d218f4690 | 229 | FUNC_INT(); |
raizel_varun | 9:221d218f4690 | 230 | ptr_t_i2c->signal_set(0x4); |
raizel_varun | 9:221d218f4690 | 231 | |
raizel_varun | 9:221d218f4690 | 232 | } |
raizel_varun | 9:221d218f4690 | 233 | |
raizel_varun | 9:221d218f4690 | 234 | void C_FUNC_RESET() |
raizel_varun | 9:221d218f4690 | 235 | { |
raizel_varun | 9:221d218f4690 | 236 | FUNC_RESET(); |
raizel_varun | 9:221d218f4690 | 237 | } |
raizel_varun | 9:221d218f4690 | 238 | |
raizel_varun | 9:221d218f4690 | 239 | |
raizel_varun | 9:221d218f4690 | 240 | void C_T_I2C_BAE(void const * args) |
raizel_varun | 9:221d218f4690 | 241 | { |
raizel_varun | 9:221d218f4690 | 242 | //char data_send,data_receive; |
raizel_varun | 9:221d218f4690 | 243 | while(1) |
raizel_varun | 9:221d218f4690 | 244 | { |
raizel_varun | 9:221d218f4690 | 245 | Thread::signal_wait(0x4); |
raizel_varun | 9:221d218f4690 | 246 | T_I2C_BAE(); |
raizel_varun | 9:221d218f4690 | 247 | //i2c_status = temp; |
raizel_varun | 9:221d218f4690 | 248 | //wait(0.5); |
raizel_varun | 9:221d218f4690 | 249 | /*printf("\n entered thread\n\r"); |
raizel_varun | 9:221d218f4690 | 250 | if(i2c_status == 0 && reset !=1) |
raizel_varun | 9:221d218f4690 | 251 | { |
raizel_varun | 9:221d218f4690 | 252 | |
raizel_varun | 9:221d218f4690 | 253 | FUNC_I2C_WRITE2CDMS(&data_receive); |
raizel_varun | 9:221d218f4690 | 254 | i2c_data * i2c_data_r = i2c_data_receive.alloc(); |
raizel_varun | 9:221d218f4690 | 255 | i2c_data_r->data = data_receive; |
raizel_varun | 9:221d218f4690 | 256 | i2c_data_r->length = 1; |
raizel_varun | 9:221d218f4690 | 257 | i2c_data_receive.put(i2c_data_r); |
raizel_varun | 9:221d218f4690 | 258 | printf("\n Data received from CDMS is %c\n\r",data_receive); |
raizel_varun | 9:221d218f4690 | 259 | i2c_data_receive.free(i2c_data_r); // This has to be done from a differen thread |
raizel_varun | 9:221d218f4690 | 260 | |
raizel_varun | 9:221d218f4690 | 261 | } |
raizel_varun | 9:221d218f4690 | 262 | else if(i2c_status ==1 && reset !=1) |
raizel_varun | 9:221d218f4690 | 263 | { |
raizel_varun | 9:221d218f4690 | 264 | osEvent evt = i2c_data_send.get(); |
raizel_varun | 9:221d218f4690 | 265 | if (evt.status == osEventMail) |
raizel_varun | 9:221d218f4690 | 266 | { |
raizel_varun | 9:221d218f4690 | 267 | i2c_data *i2c_data_s = (i2c_data*)evt.value.p; |
raizel_varun | 9:221d218f4690 | 268 | data_send = i2c_data_s -> data; |
raizel_varun | 9:221d218f4690 | 269 | FUNC_I2C_WRITE2CDMS(&data_send); |
raizel_varun | 9:221d218f4690 | 270 | printf("\nData sent to CDMS is %c\n\r",data_send); |
raizel_varun | 9:221d218f4690 | 271 | i2c_data_send.free(i2c_data_s); |
raizel_varun | 9:221d218f4690 | 272 | i2c_status = 0; |
raizel_varun | 9:221d218f4690 | 273 | //temp = i2c_status; |
raizel_varun | 9:221d218f4690 | 274 | } |
raizel_varun | 9:221d218f4690 | 275 | } |
raizel_varun | 9:221d218f4690 | 276 | */ |
raizel_varun | 9:221d218f4690 | 277 | } |
raizel_varun | 9:221d218f4690 | 278 | } |
raizel_varun | 9:221d218f4690 | 279 | |
raizel_varun | 9:221d218f4690 | 280 | |
raizel_varun | 9:221d218f4690 | 281 | |
raizel_varun | 9:221d218f4690 | 282 | |
raizel_varun | 9:221d218f4690 | 283 | |
raizel_varun | 12:ba2556c6b990 | 284 | void FUNC_I2C_WRITE2CDMS(char *data, int length=1) |
raizel_varun | 12:ba2556c6b990 | 285 | { |
raizel_varun | 12:ba2556c6b990 | 286 | int slave_status = 1; |
raizel_varun | 12:ba2556c6b990 | 287 | |
raizel_varun | 12:ba2556c6b990 | 288 | while(slave_status) |
raizel_varun | 12:ba2556c6b990 | 289 | { |
raizel_varun | 12:ba2556c6b990 | 290 | slave.address(0x20); |
raizel_varun | 12:ba2556c6b990 | 291 | if(slave.receive()==1) |
raizel_varun | 12:ba2556c6b990 | 292 | { |
raizel_varun | 12:ba2556c6b990 | 293 | slave_status=slave.write(data,length); |
raizel_varun | 12:ba2556c6b990 | 294 | |
raizel_varun | 12:ba2556c6b990 | 295 | |
raizel_varun | 12:ba2556c6b990 | 296 | } |
raizel_varun | 12:ba2556c6b990 | 297 | else if(slave.receive()==3 || slave.receive()==2) |
raizel_varun | 12:ba2556c6b990 | 298 | { |
raizel_varun | 12:ba2556c6b990 | 299 | slave_status=slave.read(data,length); |
raizel_varun | 12:ba2556c6b990 | 300 | } |
raizel_varun | 12:ba2556c6b990 | 301 | |
raizel_varun | 12:ba2556c6b990 | 302 | } |
raizel_varun | 12:ba2556c6b990 | 303 | printf("\ndone\n\r"); |
raizel_varun | 12:ba2556c6b990 | 304 | |
raizel_varun | 12:ba2556c6b990 | 305 | } |
greenroshks | 13:1b37d98840d3 | 306 | char data_send[21],data_receive[21]; |
raizel_varun | 12:ba2556c6b990 | 307 | void T_I2C_BAE() |
raizel_varun | 12:ba2556c6b990 | 308 | { |
raizel_varun | 12:ba2556c6b990 | 309 | //char data_send,data_receive; |
raizel_varun | 12:ba2556c6b990 | 310 | //while(1) |
raizel_varun | 12:ba2556c6b990 | 311 | //{ |
raizel_varun | 12:ba2556c6b990 | 312 | // Thread::signal_wait(0x1); |
raizel_varun | 12:ba2556c6b990 | 313 | //i2c_status = temp; |
raizel_varun | 12:ba2556c6b990 | 314 | //wait(0.5); |
raizel_varun | 12:ba2556c6b990 | 315 | printf("\n entered thread %d\n\r",i2c_status); |
raizel_varun | 12:ba2556c6b990 | 316 | if(i2c_status == 0 && reset !=1) |
raizel_varun | 12:ba2556c6b990 | 317 | { |
raizel_varun | 12:ba2556c6b990 | 318 | |
greenroshks | 13:1b37d98840d3 | 319 | FUNC_I2C_WRITE2CDMS(data_receive,21); |
raizel_varun | 12:ba2556c6b990 | 320 | i2c_data * i2c_data_r = i2c_data_receive.alloc(); |
raizel_varun | 12:ba2556c6b990 | 321 | strcpy(i2c_data_r->data,data_receive); |
greenroshks | 13:1b37d98840d3 | 322 | i2c_data_r->length = 21; |
raizel_varun | 12:ba2556c6b990 | 323 | i2c_data_receive.put(i2c_data_r); |
raizel_varun | 12:ba2556c6b990 | 324 | printf("\n Data received from CDMS is %s \n\r",data_receive); |
raizel_varun | 12:ba2556c6b990 | 325 | i2c_data_receive.free(i2c_data_r); // This has to be done from a differen thread |
raizel_varun | 12:ba2556c6b990 | 326 | |
raizel_varun | 12:ba2556c6b990 | 327 | } |
raizel_varun | 12:ba2556c6b990 | 328 | else if(i2c_status ==1 && reset !=1) |
raizel_varun | 12:ba2556c6b990 | 329 | { |
raizel_varun | 12:ba2556c6b990 | 330 | osEvent evt = i2c_data_send.get(); |
raizel_varun | 12:ba2556c6b990 | 331 | if (evt.status == osEventMail) |
raizel_varun | 12:ba2556c6b990 | 332 | { |
raizel_varun | 12:ba2556c6b990 | 333 | i2c_data *i2c_data_s = (i2c_data*)evt.value.p; |
raizel_varun | 12:ba2556c6b990 | 334 | strcpy(data_send,i2c_data_s -> data); |
greenroshks | 13:1b37d98840d3 | 335 | FUNC_I2C_WRITE2CDMS(data_send,21); |
raizel_varun | 12:ba2556c6b990 | 336 | printf("\nData sent to CDMS is %s\n\r",data_send); |
raizel_varun | 12:ba2556c6b990 | 337 | i2c_data_send.free(i2c_data_s); |
raizel_varun | 12:ba2556c6b990 | 338 | i2c_status = 0; |
raizel_varun | 12:ba2556c6b990 | 339 | //temp = i2c_status; |
raizel_varun | 12:ba2556c6b990 | 340 | |
raizel_varun | 12:ba2556c6b990 | 341 | } |
raizel_varun | 12:ba2556c6b990 | 342 | } |
raizel_varun | 12:ba2556c6b990 | 343 | |
raizel_varun | 12:ba2556c6b990 | 344 | //} |
raizel_varun | 12:ba2556c6b990 | 345 | } |
raizel_varun | 12:ba2556c6b990 | 346 | |
raizel_varun | 12:ba2556c6b990 | 347 | |
raizel_varun | 12:ba2556c6b990 | 348 | |
raizel_varun | 12:ba2556c6b990 | 349 | void FUNC_INT() |
raizel_varun | 12:ba2556c6b990 | 350 | { |
raizel_varun | 12:ba2556c6b990 | 351 | reset = 0; |
raizel_varun | 12:ba2556c6b990 | 352 | |
raizel_varun | 12:ba2556c6b990 | 353 | |
raizel_varun | 12:ba2556c6b990 | 354 | } |
raizel_varun | 12:ba2556c6b990 | 355 | |
raizel_varun | 12:ba2556c6b990 | 356 | void FUNC_RESET() |
raizel_varun | 12:ba2556c6b990 | 357 | { |
raizel_varun | 12:ba2556c6b990 | 358 | reset = 1; |
raizel_varun | 12:ba2556c6b990 | 359 | } |
raizel_varun | 12:ba2556c6b990 | 360 | |
raizel_varun | 12:ba2556c6b990 | 361 | |
raizel_varun | 12:ba2556c6b990 | 362 | |
greenroshks | 13:1b37d98840d3 | 363 | char fdata[8] = {SensorQuantised.Vcell_soc,SensorQuantised.alerts,SensorQuantised.crate,SensorQuantised.BatteryTemperature,SensorQuantised.faultpoll,SensorQuantised.faultir, SensorQuantised.power_mode}; |
greenroshks | 13:1b37d98840d3 | 364 | |
raizel_varun | 12:ba2556c6b990 | 365 | void ir2master() |
raizel_varun | 12:ba2556c6b990 | 366 | { |
raizel_varun | 12:ba2556c6b990 | 367 | |
greenroshks | 13:1b37d98840d3 | 368 | //char data[21]; |
raizel_varun | 12:ba2556c6b990 | 369 | //strcpy(data,"sakthi "); |
raizel_varun | 12:ba2556c6b990 | 370 | //strcat(data,"priya"); |
greenroshks | 13:1b37d98840d3 | 371 | strcpy(hk_data,SensorQuantised.Voltage); |
greenroshks | 13:1b37d98840d3 | 372 | strcat(hk_data,SensorQuantised.Temperature); //Sending to CDMS via I2C |
greenroshks | 13:1b37d98840d3 | 373 | strcat(hk_data,SensorQuantised.Current); |
greenroshks | 13:1b37d98840d3 | 374 | strcat(hk_data,SensorQuantised.PanelTemperature); |
greenroshks | 13:1b37d98840d3 | 375 | strcat(hk_data,SensorQuantised.AngularSpeed); |
greenroshks | 13:1b37d98840d3 | 376 | strcat(hk_data,SensorQuantised.Bnewvalue); |
raizel_varun | 12:ba2556c6b990 | 377 | /*strcat(hk_data,sfaultpoll); |
raizel_varun | 12:ba2556c6b990 | 378 | strcat(hk_data,sfaultir); |
raizel_varun | 12:ba2556c6b990 | 379 | strcat(hk_data,spower_mode);*/ |
greenroshks | 13:1b37d98840d3 | 380 | strcat(hk_data,fdata); |
greenroshks | 13:1b37d98840d3 | 381 | printf("\nhk data : %s\n",hk_data); |
raizel_varun | 12:ba2556c6b990 | 382 | data_ready=0; |
raizel_varun | 12:ba2556c6b990 | 383 | //data = pcslave.getc(); |
raizel_varun | 12:ba2556c6b990 | 384 | reset =0; |
raizel_varun | 12:ba2556c6b990 | 385 | i2c_status=1; |
raizel_varun | 12:ba2556c6b990 | 386 | i2c_data * i2c_data_s = i2c_data_send.alloc(); |
raizel_varun | 12:ba2556c6b990 | 387 | strcpy(i2c_data_s->data,hk_data); |
greenroshks | 13:1b37d98840d3 | 388 | i2c_data_s->length = 21; |
raizel_varun | 12:ba2556c6b990 | 389 | i2c_data_send.put(i2c_data_s); |
raizel_varun | 12:ba2556c6b990 | 390 | data_ready=1; |
raizel_varun | 12:ba2556c6b990 | 391 | //temp = i2c_status; |
raizel_varun | 12:ba2556c6b990 | 392 | } |
raizel_varun | 12:ba2556c6b990 | 393 | |
raizel_varun | 12:ba2556c6b990 | 394 | |
raizel_varun | 12:ba2556c6b990 | 395 | |
raizel_varun | 12:ba2556c6b990 | 396 | |
raizel_varun | 12:ba2556c6b990 | 397 | |
raizel_varun | 12:ba2556c6b990 | 398 | |
raizel_varun | 12:ba2556c6b990 | 399 | |
raizel_varun | 12:ba2556c6b990 | 400 | |
raizel_varun | 12:ba2556c6b990 | 401 | |
raizel_varun | 12:ba2556c6b990 | 402 | |
raizel_varun | 12:ba2556c6b990 | 403 | |
raizel_varun | 9:221d218f4690 | 404 | |
greenroshks | 0:8b0d43fe6c05 | 405 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
greenroshks | 0:8b0d43fe6c05 | 406 | //SCHEDULER |
greenroshks | 0:8b0d43fe6c05 | 407 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
sakthipriya | 4:8f6c24eca109 | 408 | int beacon_sc = 3; |
greenroshks | 0:8b0d43fe6c05 | 409 | uint16_t schedcount=1; |
greenroshks | 0:8b0d43fe6c05 | 410 | void t_sc(void const *args) |
greenroshks | 0:8b0d43fe6c05 | 411 | { |
greenroshks | 0:8b0d43fe6c05 | 412 | |
greenroshks | 0:8b0d43fe6c05 | 413 | printf("The value of i in scheduler is %d\n",schedcount); |
greenroshks | 0:8b0d43fe6c05 | 414 | if(schedcount == 65532) //to reset the counter |
greenroshks | 0:8b0d43fe6c05 | 415 | { |
greenroshks | 0:8b0d43fe6c05 | 416 | schedcount = 0; |
greenroshks | 0:8b0d43fe6c05 | 417 | } |
greenroshks | 0:8b0d43fe6c05 | 418 | |
greenroshks | 0:8b0d43fe6c05 | 419 | if(schedcount%1==0) |
greenroshks | 0:8b0d43fe6c05 | 420 | { |
greenroshks | 0:8b0d43fe6c05 | 421 | ptr_t_acs -> signal_set(0x1); |
greenroshks | 0:8b0d43fe6c05 | 422 | } |
greenroshks | 0:8b0d43fe6c05 | 423 | if(schedcount%2==0) |
greenroshks | 0:8b0d43fe6c05 | 424 | { |
greenroshks | 13:1b37d98840d3 | 425 | //ptr_t_fault -> signal_set(0x2); |
greenroshks | 0:8b0d43fe6c05 | 426 | ptr_t_hk_acq -> signal_set(0x2); |
sakthipriya | 2:80b8a2e999f7 | 427 | |
greenroshks | 0:8b0d43fe6c05 | 428 | } |
sakthipriya | 4:8f6c24eca109 | 429 | if(schedcount%beacon_sc==0) |
greenroshks | 0:8b0d43fe6c05 | 430 | { |
greenroshks | 0:8b0d43fe6c05 | 431 | if(beac_flag==0) |
greenroshks | 0:8b0d43fe6c05 | 432 | { |
greenroshks | 0:8b0d43fe6c05 | 433 | |
greenroshks | 0:8b0d43fe6c05 | 434 | ptr_t_bea -> signal_set(0x3); |
greenroshks | 0:8b0d43fe6c05 | 435 | } |
greenroshks | 0:8b0d43fe6c05 | 436 | } |
greenroshks | 0:8b0d43fe6c05 | 437 | schedcount++; |
greenroshks | 0:8b0d43fe6c05 | 438 | } |
greenroshks | 0:8b0d43fe6c05 | 439 | |
greenroshks | 0:8b0d43fe6c05 | 440 | //--------------------------------------------------------------------------------------------------------------------------------------------- |
greenroshks | 0:8b0d43fe6c05 | 441 | |
greenroshks | 0:8b0d43fe6c05 | 442 | int main() |
greenroshks | 0:8b0d43fe6c05 | 443 | { |
greenroshks | 0:8b0d43fe6c05 | 444 | t1.start(); |
greenroshks | 0:8b0d43fe6c05 | 445 | |
greenroshks | 0:8b0d43fe6c05 | 446 | ptr_t_hk_acq = new Thread(t_hk_acq); |
greenroshks | 0:8b0d43fe6c05 | 447 | ptr_t_acs = new Thread(t_acs); |
greenroshks | 13:1b37d98840d3 | 448 | //ptr_t_acs_write2flash = new Thread(t_acs_write2flash); |
greenroshks | 0:8b0d43fe6c05 | 449 | ptr_t_bea = new Thread(t_bea); |
greenroshks | 13:1b37d98840d3 | 450 | //ptr_t_bea_telecommand = new Thread(t_bea_telecommand); |
greenroshks | 13:1b37d98840d3 | 451 | //ptr_t_fault = new Thread(T_FAULT); |
raizel_varun | 9:221d218f4690 | 452 | ptr_t_i2c = new Thread(C_T_I2C_BAE); |
greenroshks | 0:8b0d43fe6c05 | 453 | //ptr_t_sc = new Thread(t_sc); |
raizel_varun | 8:69475d16d23d | 454 | |
raizel_varun | 8:69475d16d23d | 455 | interrupt_fault(); |
raizel_varun | 8:69475d16d23d | 456 | |
greenroshks | 13:1b37d98840d3 | 457 | //ptr_t_fault -> set_priority(osPriorityRealtime); |
greenroshks | 0:8b0d43fe6c05 | 458 | ptr_t_acs->set_priority(osPriorityHigh); |
raizel_varun | 9:221d218f4690 | 459 | ptr_t_i2c->set_priority(osPriorityAboveNormal); |
greenroshks | 0:8b0d43fe6c05 | 460 | ptr_t_hk_acq->set_priority(osPriorityNormal); |
greenroshks | 13:1b37d98840d3 | 461 | //ptr_t_acs_write2flash->set_priority(osPriorityBelowNormal); |
greenroshks | 0:8b0d43fe6c05 | 462 | ptr_t_bea->set_priority(osPriorityAboveNormal); |
greenroshks | 13:1b37d98840d3 | 463 | //ptr_t_bea_telecommand->set_priority(osPriorityIdle); |
greenroshks | 0:8b0d43fe6c05 | 464 | //ptr_t_sc->set_priority(osPriorityAboveNormal); |
greenroshks | 0:8b0d43fe6c05 | 465 | |
greenroshks | 0:8b0d43fe6c05 | 466 | |
greenroshks | 0:8b0d43fe6c05 | 467 | // ---------------------------------------------------------------------------------------------- |
greenroshks | 13:1b37d98840d3 | 468 | //printf("\n T_FAULT priority is %d",ptr_t_fault->get_priority()); |
greenroshks | 0:8b0d43fe6c05 | 469 | printf("\n T_ACS priority is %d",ptr_t_acs->get_priority()); |
greenroshks | 0:8b0d43fe6c05 | 470 | printf("\n T_HK_ACQ priority is %d",ptr_t_hk_acq->get_priority()); |
greenroshks | 13:1b37d98840d3 | 471 | //printf("\n T_ACS_WRITE2FLASH priority is %d",ptr_t_acs_write2flash->get_priority()); |
greenroshks | 0:8b0d43fe6c05 | 472 | printf("\n T_BEA priority is %d",ptr_t_bea->get_priority()); |
greenroshks | 0:8b0d43fe6c05 | 473 | RtosTimer t_sc_timer(t_sc,osTimerPeriodic); |
greenroshks | 0:8b0d43fe6c05 | 474 | t_sc_timer.start(10000); |
greenroshks | 0:8b0d43fe6c05 | 475 | printf("\n%f\n",t1.read()); |
raizel_varun | 9:221d218f4690 | 476 | |
raizel_varun | 9:221d218f4690 | 477 | |
raizel_varun | 9:221d218f4690 | 478 | |
raizel_varun | 9:221d218f4690 | 479 | master_reset.fall(&C_FUNC_RESET); |
raizel_varun | 9:221d218f4690 | 480 | interrupt.rise(&C_FUNC_INT); |
raizel_varun | 9:221d218f4690 | 481 | |
greenroshks | 0:8b0d43fe6c05 | 482 | while(1) |
raizel_varun | 7:f06840d848e3 | 483 | { |
raizel_varun | 9:221d218f4690 | 484 | //Thread::wait(10000); |
greenroshks | 13:1b37d98840d3 | 485 | //ir2master(); |
greenroshks | 10:ed6d3b8d1d56 | 486 | Thread::wait(5000); |
greenroshks | 0:8b0d43fe6c05 | 487 | } |
greenroshks | 0:8b0d43fe6c05 | 488 | |
greenroshks | 0:8b0d43fe6c05 | 489 | } |