sakthi priya amirtharaj
/
BAE_vr2_1_3
i2c working with old hk
Fork of BAE_vr2_1_1 by
Diff: main.cpp
- Revision:
- 12:ba2556c6b990
- Parent:
- 10:ed6d3b8d1d56
- Child:
- 13:1b37d98840d3
--- a/main.cpp Tue Dec 16 10:17:49 2014 +0000 +++ b/main.cpp Tue Dec 16 11:07:33 2014 +0000 @@ -25,12 +25,39 @@ Thread *ptr_t_fault; Thread *ptr_t_i2c; + + + +void write_to_master(char); //function to write data to master + +I2CSlave slave(D14,D15); //configuring pins p27, p28 as I2Cslave + + +DigitalOut data_ready(D10); +int i2c_status=0; //read/write mode for i2c 0 : write2slave, 1 : write2master +int reset=0; +int temp; + +typedef struct +{ + char data[35]; // To avoid dynamic memory allocation + int length; +}i2c_data; + + + + + + +Mail<i2c_data,16> i2c_data_receive; +Mail<i2c_data,16> i2c_data_send; + //-------------------------------------------------------------------------------------------------------------------------------------------------- //TASK 2 : HK //-------------------------------------------------------------------------------------------------------------------------------------------------- - - +char hk_data[35]; +extern SensorData Sensor; void t_hk_acq(void const *args) { @@ -43,8 +70,8 @@ FUNC_HK_MAIN(); //Collecting HK data //thread_2.signal_set(0x4); - //FUNC_I2C_SLAVE_MAIN(24); //Sending to CDMS via I2C - + //FUNC_I2C_SLAVE_MAIN(24); + t.stop(); printf("The time to execute hk_acq is %f seconds\n",t.read()); t.reset(); @@ -275,6 +302,122 @@ +void FUNC_I2C_WRITE2CDMS(char *data, int length=1) +{ + int slave_status = 1; + + while(slave_status) + { + slave.address(0x20); + if(slave.receive()==1) + { + slave_status=slave.write(data,length); + + + } + else if(slave.receive()==3 || slave.receive()==2) + { + slave_status=slave.read(data,length); + } + + } + printf("\ndone\n\r"); + +} +char data_send[35],data_receive[35]; +void T_I2C_BAE() +{ + //char data_send,data_receive; + //while(1) + //{ + // Thread::signal_wait(0x1); + //i2c_status = temp; + //wait(0.5); + printf("\n entered thread %d\n\r",i2c_status); + if(i2c_status == 0 && reset !=1) + { + + FUNC_I2C_WRITE2CDMS(data_receive,35); + i2c_data * i2c_data_r = i2c_data_receive.alloc(); + strcpy(i2c_data_r->data,data_receive); + i2c_data_r->length = 35; + i2c_data_receive.put(i2c_data_r); + printf("\n Data received from CDMS is %s \n\r",data_receive); + i2c_data_receive.free(i2c_data_r); // This has to be done from a differen thread + + } + else if(i2c_status ==1 && reset !=1) + { + osEvent evt = i2c_data_send.get(); + if (evt.status == osEventMail) + { + i2c_data *i2c_data_s = (i2c_data*)evt.value.p; + strcpy(data_send,i2c_data_s -> data); + FUNC_I2C_WRITE2CDMS(data_send,35); + printf("\nData sent to CDMS is %s\n\r",data_send); + i2c_data_send.free(i2c_data_s); + i2c_status = 0; + //temp = i2c_status; + + } + } + + //} +} + + + +void FUNC_INT() +{ + reset = 0; + + +} + +void FUNC_RESET() +{ + reset = 1; +} + + + +char ffp[4] = {Sensor.faultpoll,Sensor.faultir, Sensor.power_mode}; +void ir2master() +{ + + //char data[35]; + //strcpy(data,"sakthi "); + //strcat(data,"priya"); + + strcpy(hk_data,Sensor.Temperature); //Sending to CDMS via I2C + strcat(hk_data,Sensor.Current); + strcat(hk_data,Sensor.Voltage); + /*strcat(hk_data,sfaultpoll); + strcat(hk_data,sfaultir); + strcat(hk_data,spower_mode);*/ + strcat(hk_data,ffp); + data_ready=0; + //data = pcslave.getc(); + reset =0; + i2c_status=1; + i2c_data * i2c_data_s = i2c_data_send.alloc(); + strcpy(i2c_data_s->data,hk_data); + i2c_data_s->length = 35; + i2c_data_send.put(i2c_data_s); + data_ready=1; + //temp = i2c_status; +} + + + + + + + + + + + //------------------------------------------------------------------------------------------------------------------------------------------------ //SCHEDULER