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