![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
pwm gen works.new pins assigned to all except interrupt. everything works except beacon spi.
Fork of pcb_test_v1_1 by
main.cpp@0:e91ee0e99213, 2015-04-07 (annotated)
- Committer:
- sakthipriya
- Date:
- Tue Apr 07 16:11:54 2015 +0000
- Revision:
- 0:e91ee0e99213
- Child:
- 1:bbddd1763652
acs integration working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sakthipriya | 0:e91ee0e99213 | 1 | #include "mbed.h" |
sakthipriya | 0:e91ee0e99213 | 2 | #include "rtos.h" |
sakthipriya | 0:e91ee0e99213 | 3 | #include "HK.h" |
sakthipriya | 0:e91ee0e99213 | 4 | #include "slave.h" |
sakthipriya | 0:e91ee0e99213 | 5 | #include "beacon.h" |
sakthipriya | 0:e91ee0e99213 | 6 | #include "ACS.h" |
sakthipriya | 0:e91ee0e99213 | 7 | #include "fault.h" |
sakthipriya | 0:e91ee0e99213 | 8 | #include "slave.h" |
sakthipriya | 0:e91ee0e99213 | 9 | #include "mnm.h" |
sakthipriya | 0:e91ee0e99213 | 10 | |
sakthipriya | 0:e91ee0e99213 | 11 | Serial pc(USBTX, USBRX); |
sakthipriya | 0:e91ee0e99213 | 12 | |
sakthipriya | 0:e91ee0e99213 | 13 | InterruptIn interrupt(D9); //I2c interrupt from CDMS |
sakthipriya | 0:e91ee0e99213 | 14 | DigitalOut data_ready(D10); //Sends interrupt to CDMS |
sakthipriya | 0:e91ee0e99213 | 15 | |
sakthipriya | 0:e91ee0e99213 | 16 | Timer t; //To know the time of execution each thread |
sakthipriya | 0:e91ee0e99213 | 17 | Timer t1; //To know the time of entering of each thread |
sakthipriya | 0:e91ee0e99213 | 18 | Timer t2; //To check the time sync in i2c communication |
sakthipriya | 0:e91ee0e99213 | 19 | Timer t3; //To know the time taken by i2c read/write function |
sakthipriya | 0:e91ee0e99213 | 20 | |
sakthipriya | 0:e91ee0e99213 | 21 | /*****************************************************************Threads USed***********************************************************************************/ |
sakthipriya | 0:e91ee0e99213 | 22 | Thread *ptr_t_hk_acq; |
sakthipriya | 0:e91ee0e99213 | 23 | Thread *ptr_t_acs; |
sakthipriya | 0:e91ee0e99213 | 24 | Thread *ptr_t_bea; |
sakthipriya | 0:e91ee0e99213 | 25 | Thread *ptr_t_i2c; |
sakthipriya | 0:e91ee0e99213 | 26 | Thread *ptr_t_wdt; |
sakthipriya | 0:e91ee0e99213 | 27 | |
sakthipriya | 0:e91ee0e99213 | 28 | /****************************************************************configuring I2c*********************************************************************************/ |
sakthipriya | 0:e91ee0e99213 | 29 | I2CSlave slave(D14,D15); //configuring pins p27, p28 as I2Cslave |
sakthipriya | 0:e91ee0e99213 | 30 | |
sakthipriya | 0:e91ee0e99213 | 31 | int i2c_status=0; //read or write mode for i2c 0: write2slave 1: write2master |
sakthipriya | 0:e91ee0e99213 | 32 | typedef struct //structure of i2c data |
sakthipriya | 0:e91ee0e99213 | 33 | { |
sakthipriya | 0:e91ee0e99213 | 34 | char data[25]; |
sakthipriya | 0:e91ee0e99213 | 35 | int length; |
sakthipriya | 0:e91ee0e99213 | 36 | }i2c_data; |
sakthipriya | 0:e91ee0e99213 | 37 | |
sakthipriya | 0:e91ee0e99213 | 38 | |
sakthipriya | 0:e91ee0e99213 | 39 | //Mail<i2c_data,16> i2c_data_receive; |
sakthipriya | 0:e91ee0e99213 | 40 | Mail<i2c_data,16> i2c_data_send; |
sakthipriya | 0:e91ee0e99213 | 41 | |
sakthipriya | 0:e91ee0e99213 | 42 | //-------------------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 43 | //TASK 2 : HK |
sakthipriya | 0:e91ee0e99213 | 44 | //-------------------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 45 | |
sakthipriya | 0:e91ee0e99213 | 46 | char hk_data[25]; |
sakthipriya | 0:e91ee0e99213 | 47 | extern SensorDataQuantised SensorQuantised; |
sakthipriya | 0:e91ee0e99213 | 48 | void T_HK_ACQ(void const *args) |
sakthipriya | 0:e91ee0e99213 | 49 | { |
sakthipriya | 0:e91ee0e99213 | 50 | |
sakthipriya | 0:e91ee0e99213 | 51 | while(1) |
sakthipriya | 0:e91ee0e99213 | 52 | { |
sakthipriya | 0:e91ee0e99213 | 53 | Thread::signal_wait(0x2); |
sakthipriya | 0:e91ee0e99213 | 54 | SensorQuantised.power_mode='3'; //default power mode(dummy) |
sakthipriya | 0:e91ee0e99213 | 55 | printf("\n\rTHIS IS HK %f\n\r",t1.read()); |
sakthipriya | 0:e91ee0e99213 | 56 | t.start(); |
sakthipriya | 0:e91ee0e99213 | 57 | FUNC_HK_FAULTS(); // !Actual fault management is not implemented |
sakthipriya | 0:e91ee0e99213 | 58 | FUNC_HK_POWER(SensorQuantised.power_mode); // !The power mode algorithm is yet to be obtained |
sakthipriya | 0:e91ee0e99213 | 59 | FUNC_HK_MAIN(); //Collecting HK data |
sakthipriya | 0:e91ee0e99213 | 60 | FUNC_I2C_IR2CDMS(); //sending HK data to CDMS |
sakthipriya | 0:e91ee0e99213 | 61 | t.stop(); |
sakthipriya | 0:e91ee0e99213 | 62 | printf("The time to execute hk_acq is %f seconds\n\r",t.read()); |
sakthipriya | 0:e91ee0e99213 | 63 | t.reset(); |
sakthipriya | 0:e91ee0e99213 | 64 | } |
sakthipriya | 0:e91ee0e99213 | 65 | } |
sakthipriya | 0:e91ee0e99213 | 66 | |
sakthipriya | 0:e91ee0e99213 | 67 | //--------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 68 | //TASK 1 : ACS |
sakthipriya | 0:e91ee0e99213 | 69 | //--------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 70 | |
sakthipriya | 0:e91ee0e99213 | 71 | int acs_pflag = 1; |
sakthipriya | 0:e91ee0e99213 | 72 | void T_ACS(void const *args) |
sakthipriya | 0:e91ee0e99213 | 73 | { |
sakthipriya | 0:e91ee0e99213 | 74 | float mag_field[3]; |
sakthipriya | 0:e91ee0e99213 | 75 | float omega[3]; |
sakthipriya | 0:e91ee0e99213 | 76 | float *mnm_data; |
sakthipriya | 0:e91ee0e99213 | 77 | float mag_field1[3]; |
sakthipriya | 0:e91ee0e99213 | 78 | float omega1[3]; |
sakthipriya | 0:e91ee0e99213 | 79 | float tauc1[3]; |
sakthipriya | 0:e91ee0e99213 | 80 | float moment[3]; |
sakthipriya | 0:e91ee0e99213 | 81 | while(1) |
sakthipriya | 0:e91ee0e99213 | 82 | { |
sakthipriya | 0:e91ee0e99213 | 83 | Thread::signal_wait(0x1); |
sakthipriya | 0:e91ee0e99213 | 84 | printf("\n\rEntered ACS %f\n",t1.read()); |
sakthipriya | 0:e91ee0e99213 | 85 | t.start(); |
sakthipriya | 0:e91ee0e99213 | 86 | FUNC_ACS_MAG_EXEC(mag_field); |
sakthipriya | 0:e91ee0e99213 | 87 | printf("\n\r check"); |
sakthipriya | 0:e91ee0e99213 | 88 | for(int i=0; i<3; i++) |
sakthipriya | 0:e91ee0e99213 | 89 | { |
sakthipriya | 0:e91ee0e99213 | 90 | printf("%f\t",mag_field[i]); |
sakthipriya | 0:e91ee0e99213 | 91 | } |
sakthipriya | 0:e91ee0e99213 | 92 | FUNC_ACS_EXEC_GYR(omega); |
sakthipriya | 0:e91ee0e99213 | 93 | acs_pflag =1; //to be removed later |
sakthipriya | 0:e91ee0e99213 | 94 | omega[0] = 1.0; |
sakthipriya | 0:e91ee0e99213 | 95 | omega[1] = 1.0; |
sakthipriya | 0:e91ee0e99213 | 96 | omega[2] = 1.0; |
sakthipriya | 0:e91ee0e99213 | 97 | |
sakthipriya | 0:e91ee0e99213 | 98 | |
sakthipriya | 0:e91ee0e99213 | 99 | |
sakthipriya | 0:e91ee0e99213 | 100 | /* mnm_data=EXECUTE_PNI(); //the angular velocity is stored in the first 3 values and magnetic field values in next 3 |
sakthipriya | 0:e91ee0e99213 | 101 | printf("\n\rmnm gyro values\n"); //printing the angular velocity and magnetic field values |
sakthipriya | 0:e91ee0e99213 | 102 | for(int i=0; i<3; i++) |
sakthipriya | 0:e91ee0e99213 | 103 | { |
sakthipriya | 0:e91ee0e99213 | 104 | printf("%f\t",mnm_data[i]); |
sakthipriya | 0:e91ee0e99213 | 105 | } |
sakthipriya | 0:e91ee0e99213 | 106 | printf("\n\r mnm mag values\n"); |
sakthipriya | 0:e91ee0e99213 | 107 | for(int i=3; i<6; i++) |
sakthipriya | 0:e91ee0e99213 | 108 | { |
sakthipriya | 0:e91ee0e99213 | 109 | printf("%f\t",mnm_data[i]); |
sakthipriya | 0:e91ee0e99213 | 110 | } |
sakthipriya | 0:e91ee0e99213 | 111 | for(int i = 0 ; i<3;i++) |
sakthipriya | 0:e91ee0e99213 | 112 | { |
sakthipriya | 0:e91ee0e99213 | 113 | omega1[i] = mnm_data[i]; |
sakthipriya | 0:e91ee0e99213 | 114 | } |
sakthipriya | 0:e91ee0e99213 | 115 | for( int i = 3;i<6;i++) |
sakthipriya | 0:e91ee0e99213 | 116 | { |
sakthipriya | 0:e91ee0e99213 | 117 | mag_field1[i-3] = mnm_data[i]; |
sakthipriya | 0:e91ee0e99213 | 118 | } |
sakthipriya | 0:e91ee0e99213 | 119 | */ |
sakthipriya | 0:e91ee0e99213 | 120 | if(acs_pflag == 1) |
sakthipriya | 0:e91ee0e99213 | 121 | { |
sakthipriya | 0:e91ee0e99213 | 122 | |
sakthipriya | 0:e91ee0e99213 | 123 | FUNC_ACS_CNTRLALGO(mag_field,omega,tauc1); |
sakthipriya | 0:e91ee0e99213 | 124 | printf("\n\r control algo values "); |
sakthipriya | 0:e91ee0e99213 | 125 | for(int i=0; i<3; i++) |
sakthipriya | 0:e91ee0e99213 | 126 | { |
sakthipriya | 0:e91ee0e99213 | 127 | printf("%f\t",tauc1[i]); |
sakthipriya | 0:e91ee0e99213 | 128 | } |
sakthipriya | 0:e91ee0e99213 | 129 | moment_calc (tauc1, mag_field,moment); |
sakthipriya | 0:e91ee0e99213 | 130 | printf("\n\r moment values "); |
sakthipriya | 0:e91ee0e99213 | 131 | for(int i=0; i<3; i++) |
sakthipriya | 0:e91ee0e99213 | 132 | { |
sakthipriya | 0:e91ee0e99213 | 133 | printf("%f\t",moment[i]); |
sakthipriya | 0:e91ee0e99213 | 134 | } |
sakthipriya | 0:e91ee0e99213 | 135 | FUNC_ACS_GENPWM(moment); |
sakthipriya | 0:e91ee0e99213 | 136 | } |
sakthipriya | 0:e91ee0e99213 | 137 | t.reset(); |
sakthipriya | 0:e91ee0e99213 | 138 | } |
sakthipriya | 0:e91ee0e99213 | 139 | } |
sakthipriya | 0:e91ee0e99213 | 140 | |
sakthipriya | 0:e91ee0e99213 | 141 | //---------------------------------------------------BEACON-------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 142 | |
sakthipriya | 0:e91ee0e99213 | 143 | int beac_flag=0; //To receive telecommand from ground. |
sakthipriya | 0:e91ee0e99213 | 144 | |
sakthipriya | 0:e91ee0e99213 | 145 | |
sakthipriya | 0:e91ee0e99213 | 146 | /*void T_BEA_TELECOMMAND(void const *args) |
sakthipriya | 0:e91ee0e99213 | 147 | { |
sakthipriya | 0:e91ee0e99213 | 148 | char c = pc.getc(); |
sakthipriya | 0:e91ee0e99213 | 149 | if(c=='a') |
sakthipriya | 0:e91ee0e99213 | 150 | { |
sakthipriya | 0:e91ee0e99213 | 151 | printf("Telecommand detected\n\r"); |
sakthipriya | 0:e91ee0e99213 | 152 | beac_flag=1; |
sakthipriya | 0:e91ee0e99213 | 153 | } |
sakthipriya | 0:e91ee0e99213 | 154 | } |
sakthipriya | 0:e91ee0e99213 | 155 | */ |
sakthipriya | 0:e91ee0e99213 | 156 | |
sakthipriya | 0:e91ee0e99213 | 157 | void T_BEA(void const *args) |
sakthipriya | 0:e91ee0e99213 | 158 | { |
sakthipriya | 0:e91ee0e99213 | 159 | |
sakthipriya | 0:e91ee0e99213 | 160 | while(1) |
sakthipriya | 0:e91ee0e99213 | 161 | { |
sakthipriya | 0:e91ee0e99213 | 162 | Thread::signal_wait(0x3); |
sakthipriya | 0:e91ee0e99213 | 163 | printf("\n\rTHIS IS BEACON %f\n\r",t1.read()); |
sakthipriya | 0:e91ee0e99213 | 164 | t.start(); |
sakthipriya | 0:e91ee0e99213 | 165 | FUNC_BEA(); |
sakthipriya | 0:e91ee0e99213 | 166 | if(beac_flag==1) |
sakthipriya | 0:e91ee0e99213 | 167 | { |
sakthipriya | 0:e91ee0e99213 | 168 | Thread::wait(600000); |
sakthipriya | 0:e91ee0e99213 | 169 | beac_flag = 0; |
sakthipriya | 0:e91ee0e99213 | 170 | } |
sakthipriya | 0:e91ee0e99213 | 171 | printf("The time to execute beacon thread is %f seconds\n\r",t.read()); |
sakthipriya | 0:e91ee0e99213 | 172 | t.reset(); |
sakthipriya | 0:e91ee0e99213 | 173 | } |
sakthipriya | 0:e91ee0e99213 | 174 | } |
sakthipriya | 0:e91ee0e99213 | 175 | |
sakthipriya | 0:e91ee0e99213 | 176 | |
sakthipriya | 0:e91ee0e99213 | 177 | |
sakthipriya | 0:e91ee0e99213 | 178 | extern SensorDataQuantised SensorQuantised; |
sakthipriya | 0:e91ee0e99213 | 179 | |
sakthipriya | 0:e91ee0e99213 | 180 | /*------------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 181 | -------------------------------------------------------WATCHDOG----------------------------------------------------------------------------*/ |
sakthipriya | 0:e91ee0e99213 | 182 | DigitalOut trigger(PIN63); // has to be changed |
sakthipriya | 0:e91ee0e99213 | 183 | void T_WDT(void const * args) |
sakthipriya | 0:e91ee0e99213 | 184 | { |
sakthipriya | 0:e91ee0e99213 | 185 | trigger = 1; |
sakthipriya | 0:e91ee0e99213 | 186 | while(true) |
sakthipriya | 0:e91ee0e99213 | 187 | { |
sakthipriya | 0:e91ee0e99213 | 188 | Thread::signal_wait(0x5); //signal set from scheduler or sthing. r RTOS timer nce the timing is finalized |
sakthipriya | 0:e91ee0e99213 | 189 | printf("\n\rEntered WD\n\r"); |
sakthipriya | 0:e91ee0e99213 | 190 | trigger = !trigger; |
sakthipriya | 0:e91ee0e99213 | 191 | } |
sakthipriya | 0:e91ee0e99213 | 192 | } |
sakthipriya | 0:e91ee0e99213 | 193 | |
sakthipriya | 0:e91ee0e99213 | 194 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 195 | //TASK 5 : i2c data |
sakthipriya | 0:e91ee0e99213 | 196 | //--------------------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 197 | |
sakthipriya | 0:e91ee0e99213 | 198 | void FUNC_I2C_WRITE2CDMS(char *data, int length=1) |
sakthipriya | 0:e91ee0e99213 | 199 | { |
sakthipriya | 0:e91ee0e99213 | 200 | int slave_status = 1; |
sakthipriya | 0:e91ee0e99213 | 201 | if(interrupt ==1) |
sakthipriya | 0:e91ee0e99213 | 202 | { |
sakthipriya | 0:e91ee0e99213 | 203 | if(slave.receive() == 0) |
sakthipriya | 0:e91ee0e99213 | 204 | t2.stop(); |
sakthipriya | 0:e91ee0e99213 | 205 | if( slave.receive()==1) |
sakthipriya | 0:e91ee0e99213 | 206 | { |
sakthipriya | 0:e91ee0e99213 | 207 | t2.stop(); |
sakthipriya | 0:e91ee0e99213 | 208 | t3.start(); |
sakthipriya | 0:e91ee0e99213 | 209 | slave_status=slave.write(data,length); |
sakthipriya | 0:e91ee0e99213 | 210 | t3.stop(); |
sakthipriya | 0:e91ee0e99213 | 211 | } |
sakthipriya | 0:e91ee0e99213 | 212 | else if( slave.receive()==3 || slave.receive()==2) |
sakthipriya | 0:e91ee0e99213 | 213 | { |
sakthipriya | 0:e91ee0e99213 | 214 | t2.stop(); |
sakthipriya | 0:e91ee0e99213 | 215 | t3.start(); |
sakthipriya | 0:e91ee0e99213 | 216 | slave_status=slave.read(data,length); |
sakthipriya | 0:e91ee0e99213 | 217 | t3.stop(); |
sakthipriya | 0:e91ee0e99213 | 218 | } |
sakthipriya | 0:e91ee0e99213 | 219 | } |
sakthipriya | 0:e91ee0e99213 | 220 | printf("\n\r%d\r",t2.read_us()); |
sakthipriya | 0:e91ee0e99213 | 221 | t2.reset(); |
sakthipriya | 0:e91ee0e99213 | 222 | printf("\n\r%d\r",t3.read_us()); |
sakthipriya | 0:e91ee0e99213 | 223 | t3.reset(); |
sakthipriya | 0:e91ee0e99213 | 224 | } |
sakthipriya | 0:e91ee0e99213 | 225 | |
sakthipriya | 0:e91ee0e99213 | 226 | char data_send[25],data_receive; |
sakthipriya | 0:e91ee0e99213 | 227 | void T_I2C_BAE(void const * args) |
sakthipriya | 0:e91ee0e99213 | 228 | { |
sakthipriya | 0:e91ee0e99213 | 229 | while(1) |
sakthipriya | 0:e91ee0e99213 | 230 | { |
sakthipriya | 0:e91ee0e99213 | 231 | Thread::signal_wait(0x4); |
sakthipriya | 0:e91ee0e99213 | 232 | if(i2c_status == 0 ) |
sakthipriya | 0:e91ee0e99213 | 233 | { |
sakthipriya | 0:e91ee0e99213 | 234 | wait_ms(23); |
sakthipriya | 0:e91ee0e99213 | 235 | FUNC_I2C_WRITE2CDMS(&data_receive,1); |
sakthipriya | 0:e91ee0e99213 | 236 | /*i2c_data * i2c_data_r = i2c_data_receive.alloc(); |
sakthipriya | 0:e91ee0e99213 | 237 | i2c_data_r->data = data_receive; |
sakthipriya | 0:e91ee0e99213 | 238 | i2c_data_r->length = 1; |
sakthipriya | 0:e91ee0e99213 | 239 | i2c_data_receive.put(i2c_data_r);*/ |
sakthipriya | 0:e91ee0e99213 | 240 | printf("\n\r Data received from CDMS is %c \n\r",data_receive); |
sakthipriya | 0:e91ee0e99213 | 241 | FUNC_I2C_TC_EXECUTE(data_receive); // This has to be done from a differen thread |
sakthipriya | 0:e91ee0e99213 | 242 | |
sakthipriya | 0:e91ee0e99213 | 243 | } |
sakthipriya | 0:e91ee0e99213 | 244 | else if(i2c_status ==1) |
sakthipriya | 0:e91ee0e99213 | 245 | { |
sakthipriya | 0:e91ee0e99213 | 246 | osEvent evt = i2c_data_send.get(); |
sakthipriya | 0:e91ee0e99213 | 247 | if (evt.status == osEventMail) |
sakthipriya | 0:e91ee0e99213 | 248 | { |
sakthipriya | 0:e91ee0e99213 | 249 | i2c_data *i2c_data_s = (i2c_data*)evt.value.p; |
sakthipriya | 0:e91ee0e99213 | 250 | strcpy(data_send,i2c_data_s -> data); |
sakthipriya | 0:e91ee0e99213 | 251 | wait_ms(29); |
sakthipriya | 0:e91ee0e99213 | 252 | FUNC_I2C_WRITE2CDMS(data_send,25); |
sakthipriya | 0:e91ee0e99213 | 253 | printf("\n\rData sent to CDMS is %s\n\r",data_send); |
sakthipriya | 0:e91ee0e99213 | 254 | |
sakthipriya | 0:e91ee0e99213 | 255 | i2c_data_send.free(i2c_data_s); |
sakthipriya | 0:e91ee0e99213 | 256 | i2c_status = 0; |
sakthipriya | 0:e91ee0e99213 | 257 | } |
sakthipriya | 0:e91ee0e99213 | 258 | } |
sakthipriya | 0:e91ee0e99213 | 259 | |
sakthipriya | 0:e91ee0e99213 | 260 | } |
sakthipriya | 0:e91ee0e99213 | 261 | } |
sakthipriya | 0:e91ee0e99213 | 262 | |
sakthipriya | 0:e91ee0e99213 | 263 | |
sakthipriya | 0:e91ee0e99213 | 264 | |
sakthipriya | 0:e91ee0e99213 | 265 | void FUNC_I2C_INT() |
sakthipriya | 0:e91ee0e99213 | 266 | { |
sakthipriya | 0:e91ee0e99213 | 267 | |
sakthipriya | 0:e91ee0e99213 | 268 | t2.start(); |
sakthipriya | 0:e91ee0e99213 | 269 | // t3.start(); |
sakthipriya | 0:e91ee0e99213 | 270 | ptr_t_i2c->signal_set(0x4); |
sakthipriya | 0:e91ee0e99213 | 271 | |
sakthipriya | 0:e91ee0e99213 | 272 | |
sakthipriya | 0:e91ee0e99213 | 273 | } |
sakthipriya | 0:e91ee0e99213 | 274 | |
sakthipriya | 0:e91ee0e99213 | 275 | void FUNC_I2C_IR2CDMS() |
sakthipriya | 0:e91ee0e99213 | 276 | { |
sakthipriya | 0:e91ee0e99213 | 277 | data_ready=0; |
sakthipriya | 0:e91ee0e99213 | 278 | //char data[25]; |
sakthipriya | 0:e91ee0e99213 | 279 | strcpy(hk_data,"hk_Data"); |
sakthipriya | 0:e91ee0e99213 | 280 | strcat(hk_data,SensorQuantised.Voltage); |
sakthipriya | 0:e91ee0e99213 | 281 | strcat(hk_data,SensorQuantised.Current); |
sakthipriya | 0:e91ee0e99213 | 282 | strcat(hk_data,SensorQuantised.Temperature); |
sakthipriya | 0:e91ee0e99213 | 283 | strcat(hk_data,SensorQuantised.PanelTemperature); |
sakthipriya | 0:e91ee0e99213 | 284 | strcat(hk_data,SensorQuantised.AngularSpeed); |
sakthipriya | 0:e91ee0e99213 | 285 | strcat(hk_data,SensorQuantised.Bnewvalue); |
sakthipriya | 0:e91ee0e99213 | 286 | char fdata[5] = {SensorQuantised.BatteryTemperature,SensorQuantised.faultpoll,SensorQuantised.faultir,SensorQuantised.power_mode}; |
sakthipriya | 0:e91ee0e99213 | 287 | |
sakthipriya | 0:e91ee0e99213 | 288 | /*strcat(hk_data,sfaultpoll); |
sakthipriya | 0:e91ee0e99213 | 289 | strcat(hk_data,sfaultir); |
sakthipriya | 0:e91ee0e99213 | 290 | strcat(hk_data,spower_mode);*/ |
sakthipriya | 0:e91ee0e99213 | 291 | strcat(hk_data,fdata); |
sakthipriya | 0:e91ee0e99213 | 292 | printf("\n\r hk data being sent %s ",hk_data); |
sakthipriya | 0:e91ee0e99213 | 293 | //for(int i=0;i<100000000000;i++) |
sakthipriya | 0:e91ee0e99213 | 294 | //; |
sakthipriya | 0:e91ee0e99213 | 295 | |
sakthipriya | 0:e91ee0e99213 | 296 | /*for(int d=0;d<23;d++) //was written just to check hk data |
sakthipriya | 0:e91ee0e99213 | 297 | { |
sakthipriya | 0:e91ee0e99213 | 298 | if(hk_data[d]>10) |
sakthipriya | 0:e91ee0e99213 | 299 | printf("\n\rhk data : %d\n\r",hk_data[d]); |
sakthipriya | 0:e91ee0e99213 | 300 | } */ |
sakthipriya | 0:e91ee0e99213 | 301 | |
sakthipriya | 0:e91ee0e99213 | 302 | //data = pcslave.getc(); |
sakthipriya | 0:e91ee0e99213 | 303 | |
sakthipriya | 0:e91ee0e99213 | 304 | i2c_status=1; |
sakthipriya | 0:e91ee0e99213 | 305 | i2c_data * i2c_data_s = i2c_data_send.alloc(); |
sakthipriya | 0:e91ee0e99213 | 306 | strcpy(i2c_data_s->data,hk_data); |
sakthipriya | 0:e91ee0e99213 | 307 | i2c_data_s->length = 25; |
sakthipriya | 0:e91ee0e99213 | 308 | i2c_data_send.put(i2c_data_s); |
sakthipriya | 0:e91ee0e99213 | 309 | data_ready=1; |
sakthipriya | 0:e91ee0e99213 | 310 | //temp = i2c_status; |
sakthipriya | 0:e91ee0e99213 | 311 | } |
sakthipriya | 0:e91ee0e99213 | 312 | |
sakthipriya | 0:e91ee0e99213 | 313 | |
sakthipriya | 0:e91ee0e99213 | 314 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
sakthipriya | 0:e91ee0e99213 | 315 | //TELECOMMAND |
sakthipriya | 0:e91ee0e99213 | 316 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
sakthipriya | 0:e91ee0e99213 | 317 | void FUNC_I2C_TC_EXECUTE (char command) |
sakthipriya | 0:e91ee0e99213 | 318 | { switch(command) |
sakthipriya | 0:e91ee0e99213 | 319 | { case '0' : printf("command 0 executed"); |
sakthipriya | 0:e91ee0e99213 | 320 | break; |
sakthipriya | 0:e91ee0e99213 | 321 | case '1' : printf("command 1 executed"); |
sakthipriya | 0:e91ee0e99213 | 322 | break; |
sakthipriya | 0:e91ee0e99213 | 323 | case '2' : printf("command 2 executed"); |
sakthipriya | 0:e91ee0e99213 | 324 | break; |
sakthipriya | 0:e91ee0e99213 | 325 | case '3' : printf("command 3 executed"); |
sakthipriya | 0:e91ee0e99213 | 326 | } |
sakthipriya | 0:e91ee0e99213 | 327 | } |
sakthipriya | 0:e91ee0e99213 | 328 | |
sakthipriya | 0:e91ee0e99213 | 329 | |
sakthipriya | 0:e91ee0e99213 | 330 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
sakthipriya | 0:e91ee0e99213 | 331 | //SCHEDULER |
sakthipriya | 0:e91ee0e99213 | 332 | //------------------------------------------------------------------------------------------------------------------------------------------------ |
sakthipriya | 0:e91ee0e99213 | 333 | int beacon_sc = 3; |
sakthipriya | 0:e91ee0e99213 | 334 | uint16_t schedcount=1; |
sakthipriya | 0:e91ee0e99213 | 335 | void T_SC(void const *args) |
sakthipriya | 0:e91ee0e99213 | 336 | { |
sakthipriya | 0:e91ee0e99213 | 337 | //DRDY=0; |
sakthipriya | 0:e91ee0e99213 | 338 | printf("The value of i in scheduler is %d\n\r",schedcount); |
sakthipriya | 0:e91ee0e99213 | 339 | if(schedcount == 65532) //to reset the counter |
sakthipriya | 0:e91ee0e99213 | 340 | { |
sakthipriya | 0:e91ee0e99213 | 341 | schedcount = 0; |
sakthipriya | 0:e91ee0e99213 | 342 | } |
sakthipriya | 0:e91ee0e99213 | 343 | |
sakthipriya | 0:e91ee0e99213 | 344 | if(schedcount%1==0) |
sakthipriya | 0:e91ee0e99213 | 345 | { |
sakthipriya | 0:e91ee0e99213 | 346 | ptr_t_acs -> signal_set(0x1); |
sakthipriya | 0:e91ee0e99213 | 347 | //ptr_t_wdt -> signal_set(0x5); |
sakthipriya | 0:e91ee0e99213 | 348 | } |
sakthipriya | 0:e91ee0e99213 | 349 | if(schedcount%2==0) |
sakthipriya | 0:e91ee0e99213 | 350 | { |
sakthipriya | 0:e91ee0e99213 | 351 | // ptr_t_fault -> signal_set(0x2); |
sakthipriya | 0:e91ee0e99213 | 352 | //ptr_t_hk_acq -> signal_set(0x2); |
sakthipriya | 0:e91ee0e99213 | 353 | |
sakthipriya | 0:e91ee0e99213 | 354 | } |
sakthipriya | 0:e91ee0e99213 | 355 | if(schedcount%beacon_sc==0) |
sakthipriya | 0:e91ee0e99213 | 356 | { |
sakthipriya | 0:e91ee0e99213 | 357 | if(beac_flag==0) |
sakthipriya | 0:e91ee0e99213 | 358 | { |
sakthipriya | 0:e91ee0e99213 | 359 | |
sakthipriya | 0:e91ee0e99213 | 360 | //ptr_t_bea -> signal_set(0x3); |
sakthipriya | 0:e91ee0e99213 | 361 | } |
sakthipriya | 0:e91ee0e99213 | 362 | } |
sakthipriya | 0:e91ee0e99213 | 363 | schedcount++; |
sakthipriya | 0:e91ee0e99213 | 364 | } |
sakthipriya | 0:e91ee0e99213 | 365 | |
sakthipriya | 0:e91ee0e99213 | 366 | //--------------------------------------------------------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 367 | |
sakthipriya | 0:e91ee0e99213 | 368 | int main() |
sakthipriya | 0:e91ee0e99213 | 369 | { |
sakthipriya | 0:e91ee0e99213 | 370 | t1.start(); |
sakthipriya | 0:e91ee0e99213 | 371 | printf("\n\rIITMSAT BAE Activated \n"); |
sakthipriya | 0:e91ee0e99213 | 372 | INIT_PNI(); // Initializing mnm blue |
sakthipriya | 0:e91ee0e99213 | 373 | FUNC_ACS_MAG_INIT(); // Initializing magnetometer |
sakthipriya | 0:e91ee0e99213 | 374 | //FUNC_ACS_INIT_GYR(); // Initializing Gyroscope |
sakthipriya | 0:e91ee0e99213 | 375 | slave.address(0x20); // setting slave address for BAE for I2C communication |
sakthipriya | 0:e91ee0e99213 | 376 | |
sakthipriya | 0:e91ee0e99213 | 377 | ptr_t_hk_acq = new Thread(T_HK_ACQ); |
sakthipriya | 0:e91ee0e99213 | 378 | ptr_t_acs = new Thread(T_ACS); |
sakthipriya | 0:e91ee0e99213 | 379 | ptr_t_bea = new Thread(T_BEA); |
sakthipriya | 0:e91ee0e99213 | 380 | ptr_t_i2c = new Thread(T_I2C_BAE); |
sakthipriya | 0:e91ee0e99213 | 381 | //ptr_t_sc = new Thread(T_SC); |
sakthipriya | 0:e91ee0e99213 | 382 | ptr_t_wdt = new Thread(T_WDT); |
sakthipriya | 0:e91ee0e99213 | 383 | |
sakthipriya | 0:e91ee0e99213 | 384 | interrupt_fault(); // Dummy function called when a fault interrupt is detected |
sakthipriya | 0:e91ee0e99213 | 385 | |
sakthipriya | 0:e91ee0e99213 | 386 | ptr_t_acs->set_priority(osPriorityAboveNormal); |
sakthipriya | 0:e91ee0e99213 | 387 | ptr_t_i2c->set_priority(osPriorityHigh); |
sakthipriya | 0:e91ee0e99213 | 388 | ptr_t_hk_acq->set_priority(osPriorityAboveNormal); |
sakthipriya | 0:e91ee0e99213 | 389 | ptr_t_bea->set_priority(osPriorityAboveNormal); |
sakthipriya | 0:e91ee0e99213 | 390 | //ptr_t_sc->set_priority(osPriorityAboveNormal); |
sakthipriya | 0:e91ee0e99213 | 391 | ptr_t_wdt -> set_priority(osPriorityIdle); |
sakthipriya | 0:e91ee0e99213 | 392 | |
sakthipriya | 0:e91ee0e99213 | 393 | |
sakthipriya | 0:e91ee0e99213 | 394 | // ---------------------------------------------------------------------------------------------- |
sakthipriya | 0:e91ee0e99213 | 395 | printf("\n\r T_ACS priority is %d",ptr_t_acs->get_priority()); |
sakthipriya | 0:e91ee0e99213 | 396 | printf("\n\r T_HK_ACQ priority is %d",ptr_t_hk_acq->get_priority()); |
sakthipriya | 0:e91ee0e99213 | 397 | printf("\n\r T_BEA priority is %d",ptr_t_bea->get_priority()); |
sakthipriya | 0:e91ee0e99213 | 398 | RtosTimer t_sc_timer(T_SC,osTimerPeriodic); |
sakthipriya | 0:e91ee0e99213 | 399 | t_sc_timer.start(10000); |
sakthipriya | 0:e91ee0e99213 | 400 | printf("\n\r%f\n\r",t1.read()); |
sakthipriya | 0:e91ee0e99213 | 401 | |
sakthipriya | 0:e91ee0e99213 | 402 | // interrupt.rise(&FUNC_I2C_INT); //interrupt received from CDMS |
sakthipriya | 0:e91ee0e99213 | 403 | while(1) //required to prevent main from terminating |
sakthipriya | 0:e91ee0e99213 | 404 | { |
sakthipriya | 0:e91ee0e99213 | 405 | Thread::wait(5000); |
sakthipriya | 0:e91ee0e99213 | 406 | } |
sakthipriya | 0:e91ee0e99213 | 407 | |
sakthipriya | 0:e91ee0e99213 | 408 | } |