fault management added

Dependencies:   mbed-rtos mbed

Fork of BAE_FRDM by green rosh

Committer:
sakthipriya
Date:
Thu Dec 04 07:17:44 2014 +0000
Revision:
5:255b43e8e21a
Parent:
3:02b45de29c0f
power modified

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sakthipriya 3:02b45de29c0f 1 /* Added fault to hk structure and being sent through I2C. Need to verify the format */
greenroshks 0:8b0d43fe6c05 2 #include "slave.h"
greenroshks 0:8b0d43fe6c05 3 #include "HK.h"
greenroshks 0:8b0d43fe6c05 4
greenroshks 0:8b0d43fe6c05 5 extern struct SensorData Sensor;
greenroshks 1:b4bb78a9b92e 6 I2CSlave slave(PTC9,PTC8); //configuring pins p27, p28 as I2Cslave
greenroshks 0:8b0d43fe6c05 7 Serial screen (USBTX,USBRX);
greenroshks 0:8b0d43fe6c05 8 void write_to_master(char send) //function to write data to master
greenroshks 0:8b0d43fe6c05 9 {
greenroshks 0:8b0d43fe6c05 10 int acknowledge;
greenroshks 0:8b0d43fe6c05 11 int loopvariable4=1;
greenroshks 0:8b0d43fe6c05 12 while(loopvariable4)
greenroshks 0:8b0d43fe6c05 13 {
greenroshks 0:8b0d43fe6c05 14 acknowledge = slave.write(send); //sending the byte to master
greenroshks 0:8b0d43fe6c05 15 if(acknowledge==1)
greenroshks 0:8b0d43fe6c05 16 {
greenroshks 0:8b0d43fe6c05 17 screen.printf(" acknowledge %d sent %u \n",acknowledge,send);
greenroshks 0:8b0d43fe6c05 18 loopvariable4=0;
greenroshks 0:8b0d43fe6c05 19 }
greenroshks 0:8b0d43fe6c05 20 }
greenroshks 0:8b0d43fe6c05 21 }
greenroshks 0:8b0d43fe6c05 22
greenroshks 0:8b0d43fe6c05 23
greenroshks 0:8b0d43fe6c05 24
greenroshks 0:8b0d43fe6c05 25
greenroshks 0:8b0d43fe6c05 26 void FUNC_I2C_SLAVE_MAIN(int iterations)
greenroshks 0:8b0d43fe6c05 27 {
greenroshks 0:8b0d43fe6c05 28
greenroshks 0:8b0d43fe6c05 29 screen.printf("\nSlave entered\n");
greenroshks 0:8b0d43fe6c05 30 slave.address(slave_address); //assigning slave address
greenroshks 0:8b0d43fe6c05 31 slave.stop();
greenroshks 0:8b0d43fe6c05 32 char Switch_Variable;
greenroshks 0:8b0d43fe6c05 33
greenroshks 0:8b0d43fe6c05 34
greenroshks 0:8b0d43fe6c05 35 int loopvariable1=1;
greenroshks 0:8b0d43fe6c05 36 int loopvariable2=0;
greenroshks 0:8b0d43fe6c05 37 int loopvariable3=1;
greenroshks 0:8b0d43fe6c05 38 //initialising dummy sensor data
greenroshks 0:8b0d43fe6c05 39
greenroshks 0:8b0d43fe6c05 40 while(loopvariable1)
greenroshks 0:8b0d43fe6c05 41 {
greenroshks 0:8b0d43fe6c05 42 //to read data from master
greenroshks 0:8b0d43fe6c05 43 if(slave.receive()==WriteGeneral) //checking if slave is addressed to write
greenroshks 0:8b0d43fe6c05 44 {
greenroshks 1:b4bb78a9b92e 45 slave.stop();
greenroshks 0:8b0d43fe6c05 46 Switch_Variable=slave.read(); //receiving data
greenroshks 0:8b0d43fe6c05 47 screen.printf("switch variable=%d\n",Switch_Variable);
greenroshks 0:8b0d43fe6c05 48 slave.stop(); //reset slave to default receiving state
greenroshks 0:8b0d43fe6c05 49 loopvariable1=0;
greenroshks 0:8b0d43fe6c05 50 //to interpret and write data to master
greenroshks 0:8b0d43fe6c05 51 switch(Switch_Variable)
greenroshks 0:8b0d43fe6c05 52 {
greenroshks 0:8b0d43fe6c05 53
greenroshks 0:8b0d43fe6c05 54
greenroshks 0:8b0d43fe6c05 55 case 1: printf("\nEntered switch\n");
greenroshks 0:8b0d43fe6c05 56 while(loopvariable3)
greenroshks 0:8b0d43fe6c05 57 {
greenroshks 0:8b0d43fe6c05 58 if(slave.receive()==ReadAddressed) //check if slave is addressed to read
greenroshks 0:8b0d43fe6c05 59 {
greenroshks 0:8b0d43fe6c05 60 while(loopvariable2<iterations)
greenroshks 0:8b0d43fe6c05 61 {
greenroshks 0:8b0d43fe6c05 62 if(loopvariable2%3==0)
greenroshks 0:8b0d43fe6c05 63 {
greenroshks 0:8b0d43fe6c05 64 screen.printf("\nvoltage%d\n",loopvariable2/3);
greenroshks 0:8b0d43fe6c05 65 write_to_master(Sensor.Voltage[loopvariable2/3]);
greenroshks 0:8b0d43fe6c05 66 }
greenroshks 0:8b0d43fe6c05 67 else if(loopvariable2%3==1)
greenroshks 0:8b0d43fe6c05 68 {
greenroshks 0:8b0d43fe6c05 69 screen.printf("\ncurrent%d\n",loopvariable2/3);
greenroshks 0:8b0d43fe6c05 70 write_to_master(Sensor.Current[loopvariable2/3]);
greenroshks 0:8b0d43fe6c05 71 }
greenroshks 0:8b0d43fe6c05 72 else if(loopvariable2%3==2)
greenroshks 0:8b0d43fe6c05 73 {
greenroshks 0:8b0d43fe6c05 74 screen.printf("\ntemp%d\n",loopvariable2/3);
greenroshks 0:8b0d43fe6c05 75 write_to_master(Sensor.Temperature[loopvariable2/3]);
greenroshks 0:8b0d43fe6c05 76 }
greenroshks 0:8b0d43fe6c05 77 loopvariable2++;
sakthipriya 3:02b45de29c0f 78 }
sakthipriya 3:02b45de29c0f 79 screen.printf("\nfault %c\n",Sensor.fault);
sakthipriya 5:255b43e8e21a 80 write_to_master(Sensor.fault);
sakthipriya 5:255b43e8e21a 81 screen.printf("\npower mode %c\n",Sensor.power_mode);
sakthipriya 5:255b43e8e21a 82 write_to_master(Sensor.power_mode);
greenroshks 0:8b0d43fe6c05 83 printf("\nExited i2c while loop\n");
greenroshks 0:8b0d43fe6c05 84 slave.stop();
greenroshks 0:8b0d43fe6c05 85 loopvariable3=0;
greenroshks 0:8b0d43fe6c05 86 }//if(read addressed)
greenroshks 0:8b0d43fe6c05 87
greenroshks 0:8b0d43fe6c05 88 }//while(loopvariable3)
greenroshks 0:8b0d43fe6c05 89
greenroshks 0:8b0d43fe6c05 90 break;
greenroshks 0:8b0d43fe6c05 91 case 2 : screen.printf(" telecommand 2\n");
greenroshks 0:8b0d43fe6c05 92 break;
greenroshks 0:8b0d43fe6c05 93
greenroshks 0:8b0d43fe6c05 94 }//switch case ends
greenroshks 0:8b0d43fe6c05 95 }
greenroshks 0:8b0d43fe6c05 96 }
greenroshks 0:8b0d43fe6c05 97 screen.printf("\nexited slave function\n");
greenroshks 0:8b0d43fe6c05 98 }
greenroshks 0:8b0d43fe6c05 99