cdms i2c working - but not working after hk data is sent
Fork of pcb_test_vr1_1_2 by
Diff: main.cpp
- Revision:
- 5:bf1f3504cd9d
- Parent:
- 4:65a2d0b97d01
--- a/main.cpp Thu May 14 10:22:50 2015 +0000 +++ b/main.cpp Sun May 17 06:18:41 2015 +0000 @@ -10,10 +10,10 @@ Serial pc(USBTX, USBRX); -InterruptIn interrupt(PIN97); //I2c interrupt from CDMS -DigitalOut data_ready(PIN90); //Sends interrupt to CDMS -//InterruptIn interrupt(D9); //I2c interrupt from CDMS -//DigitalOut data_ready(D10); +//InterruptIn interrupt( PIN97); //I2c interrupt from CDMS +//DigitalOut data_ready(PIN90); //Sends interrupt to CDMS +InterruptIn interrupt(D9); //I2c interrupt from CDMS +DigitalOut data_ready(D10); Timer t; //To know the time of execution each thread Timer t1; //To know the time of entering of each thread @@ -21,12 +21,19 @@ Timer t3; //To know the time taken by i2c read/write function Timer i1; Timer i2; +Timeout bea_timeout ; // timeout used to revive beacon 10 min after it is switched off /*****************************************************************Threads USed***********************************************************************************/ Thread *ptr_t_hk_acq; //pointer:::::::::to read state of one thread from another Thread *ptr_t_acs; Thread *ptr_t_bea; Thread *ptr_t_i2c; -Thread *ptr_t_wdt; +Thread *ptr_t_wdt; + +/****************************************************************FUNC_HEADER**********************************************************************************/ +void FUNC_I2C_INT(); +void FUNC_I2C_IR2CDMS(); +void FUNC_I2C_TC_EXECUTE (char command); +void FUNC_BEA_TIMEOUT(); /****************************************************************configuring I2c*********************************************************************************/ I2CSlave slave(PIN1,PIN2); //configuring pins p27, p28 as I2Cslave @@ -202,36 +209,45 @@ void FUNC_I2C_WRITE2CDMS(char *data, int length=1) /// BAE to CDMS read/write { int slave_status = 1; - int inter_test = interrupt; - int slr = slave.receive(); - wait_ms(20); + //int inter_test = interrupt; + //int slr = slave.receive(); + //wait_ms(20); //printf("\n\r time is %d\n",t2.read_us()); //if(interrupt ==1) //{ - //printf("\n\r slave status %d",slave.receive()); - //t2.stop(); + wait_us(100); + int slave_r = slave.receive(); + printf("\n%d\r",slave_r); + // printf("\n%d\r",slave.receive()); + t2.stop(); + // wait_ms(2); if(slave.receive() == 0) // 0 when not ack refer doc. - t2.stop(); + //t2.stop(); if( slave.receive()==1) // slave to master { - t2.stop(); + // t2.stop(); t3.start(); slave_status=slave.write(data,length); // ack to + t3.stop(); + slave.stop(); + //printf("\n\r slave status %d",slave.receive()); } - else if( slave.receive()==3 || slave.receive()==2) // master to slave + if( slave.receive()==3 || slave.receive()==2) // master to slave { - t2.stop(); + //t2.stop(); t3.start(); slave_status=slave.read(data,length); t3.stop(); + slave.stop(); + //printf("\n\r slave status %d",slave.receive()); } //} // printf("\n\r time taken to receive intrpt 4m cdms %d",i1.read_us()); //i1.reset(); - printf("\n\r slave status %d %d %d",slave.receive(),t2.read_us(),t3.read_us()); + printf("\n\r slave status %d %d ",t2.read_us(),t3.read_us()); // printf("\n\r time taken from interrupt to reach i2c fn %d",t2.read_us()); - t2.stop(); + //t2.stop(); t2.reset(); //printf("\n\r time to execute i2c function %d",t3.read_us()); t3.reset(); @@ -255,7 +271,7 @@ i2c_data_r->length = 1; i2c_data_receive.put(i2c_data_r);*/ printf("\n\r Data received from CDMS is %c \n\r",data_receive); - FUNC_I2C_TC_EXECUTE(data_receive); // telecommand // This has to be done from a differen thread + // FUNC_I2C_TC_EXECUTE(data_receive); // telecommand // This has to be done from a differen thread } else if(i2c_status ==1) @@ -336,7 +352,9 @@ //------------------------------------------------------------------------------------------------------------------------------------------------ void FUNC_I2C_TC_EXECUTE (char command) { switch(command) - { case '0' : printf("command 0 executed"); + { case '0' : printf("command 0 executed"); // assuming telecommand to switch of beacon + beac_flag = 1; + bea_timeout.attach(&FUNC_BEA_TIMEOUT, 600); break; case '1' : printf("command 1 executed"); break; @@ -344,6 +362,11 @@ break; case '3' : printf("command 3 executed"); } +} + +void FUNC_BEA_TIMEOUT() +{ + beac_flag = 0; } @@ -363,8 +386,8 @@ if(schedcount%1==0) { - //ptr_t_acs -> signal_set(0x1); - //ptr_t_wdt -> signal_set(0x5); + // ptr_t_acs -> signal_set(0x1); + // ptr_t_wdt -> signal_set(0x5); } if(schedcount%2==0) { @@ -376,8 +399,7 @@ { if(beac_flag==0) { - - //ptr_t_bea -> signal_set(0x3); + //ptr_t_bea -> signal_set(0x3); } } schedcount++;