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