i2c slave integrated

Dependencies:   mbed-rtos mbed

Fork of BAE_FRDM_INTEGRATION by green rosh

Committer:
sakthipriya
Date:
Mon Dec 15 11:21:57 2014 +0000
Revision:
9:a9de938283f9
Parent:
8:667fbc82d634
i2c_slave integrated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sakthipriya 2:80b8a2e999f7 1 #include "fault.h"
sakthipriya 3:02b45de29c0f 2 #include "HK.h"
greenroshks 8:667fbc82d634 3
greenroshks 8:667fbc82d634 4
greenroshks 8:667fbc82d634 5 DigitalIn fault0(FAULT0,PullUp);
raizel_varun 7:f06840d848e3 6 DigitalIn fault1(FAULT1,PullUp);
raizel_varun 7:f06840d848e3 7 DigitalIn fault2(FAULT2,PullUp);
raizel_varun 7:f06840d848e3 8 DigitalIn fault3(FAULT3,PullUp);
raizel_varun 7:f06840d848e3 9 DigitalIn fault4(FAULT4,PullUp);
raizel_varun 7:f06840d848e3 10 //DigitalIn fault5(FAULT5,PullUp);
raizel_varun 7:f06840d848e3 11 //DigitalIn fault6(FAULT6,PullUp);
raizel_varun 7:f06840d848e3 12 //DigitalIn fault7(FAULT7,PullUp);
raizel_varun 7:f06840d848e3 13 //DigitalIn fault8(FAULT8,PullUp);
greenroshks 8:667fbc82d634 14
greenroshks 8:667fbc82d634 15
raizel_varun 7:f06840d848e3 16 InterruptIn fault_IR1(FAULT5);
raizel_varun 7:f06840d848e3 17 InterruptIn fault_IR2(FAULT6);
raizel_varun 7:f06840d848e3 18 InterruptIn fault_IR3(FAULT7);
raizel_varun 7:f06840d848e3 19 InterruptIn fault_IR4(FAULT8);
raizel_varun 7:f06840d848e3 20 InterruptIn fault_IR5(FAULT9);
greenroshks 8:667fbc82d634 21
greenroshks 8:667fbc82d634 22
greenroshks 8:667fbc82d634 23
raizel_varun 6:e65b1ab79f36 24 DigitalOut clear1(FAULT_CLEAR1,0);
raizel_varun 6:e65b1ab79f36 25 DigitalOut clear2(FAULT_CLEAR2,0);
raizel_varun 6:e65b1ab79f36 26 DigitalOut clear3(FAULT_CLEAR3,0);
raizel_varun 6:e65b1ab79f36 27 DigitalOut clear4(FAULT_CLEAR4,0);
greenroshks 8:667fbc82d634 28 DigitalOut clear5(FAULT_CLEAR5);
greenroshks 8:667fbc82d634 29 DigitalOut clear6(FAULT_CLEAR6);
greenroshks 8:667fbc82d634 30 DigitalOut clear7(FAULT_CLEAR7);
greenroshks 8:667fbc82d634 31 DigitalOut clear8(FAULT_CLEAR8);
greenroshks 8:667fbc82d634 32 DigitalOut clear9(FAULT_CLEAR9);
greenroshks 8:667fbc82d634 33
greenroshks 8:667fbc82d634 34
sakthipriya 5:255b43e8e21a 35 DigitalOut acs_active(ACS);
greenroshks 8:667fbc82d634 36
greenroshks 8:667fbc82d634 37
greenroshks 8:667fbc82d634 38 BusIn fault_poll(FAULT0,FAULT1,FAULT2,FAULT3,FAULT4);
greenroshks 8:667fbc82d634 39 BusIn fault_ir(FAULT5,FAULT6,FAULT7,FAULT8,FAULT9);
greenroshks 8:667fbc82d634 40
raizel_varun 7:f06840d848e3 41 BusOut clear_poll(FAULT_CLEAR1,FAULT_CLEAR2,FAULT_CLEAR3,FAULT_CLEAR4);//to send fault data along with hk
greenroshks 8:667fbc82d634 42 BusOut clear_ir(FAULT_CLEAR5,FAULT_CLEAR6,FAULT_CLEAR7,FAULT_CLEAR8,FAULT_CLEAR9);
greenroshks 8:667fbc82d634 43
greenroshks 8:667fbc82d634 44
sakthipriya 3:02b45de29c0f 45 extern SensorData Sensor;
sakthipriya 5:255b43e8e21a 46 extern int beacon_sc; //to switch beacon between low and high power mode
sakthipriya 5:255b43e8e21a 47 extern int acs_pflag; //to activate/deactivate control algo
greenroshks 8:667fbc82d634 48 char out_poll;
greenroshks 8:667fbc82d634 49 char out_ir;
greenroshks 8:667fbc82d634 50
sakthipriya 2:80b8a2e999f7 51 void FAULTS()
sakthipriya 2:80b8a2e999f7 52 {
raizel_varun 6:e65b1ab79f36 53
sakthipriya 2:80b8a2e999f7 54 printf("Entered Fault management \n");
greenroshks 8:667fbc82d634 55 if(fault0==0)printf("CHARGER IS CHARGING THE BATTERY ");
greenroshks 8:667fbc82d634 56 if(fault0==1)printf("CHRGER GONE OFFLINE, BATTERY DRAINING");
greenroshks 8:667fbc82d634 57
greenroshks 8:667fbc82d634 58 if(fault1==0)
greenroshks 8:667fbc82d634 59 { clear1=1;printf("");}
greenroshks 8:667fbc82d634 60 else
greenroshks 8:667fbc82d634 61 { clear1=0;}
greenroshks 8:667fbc82d634 62
greenroshks 8:667fbc82d634 63 if(fault2==0)
greenroshks 8:667fbc82d634 64 { clear2=1;printf("");}
greenroshks 8:667fbc82d634 65 else
greenroshks 8:667fbc82d634 66 { clear2=0;}
greenroshks 8:667fbc82d634 67
greenroshks 8:667fbc82d634 68 if(fault3==0)
greenroshks 8:667fbc82d634 69 { clear3=1;printf("");}
greenroshks 8:667fbc82d634 70 else
greenroshks 8:667fbc82d634 71 { clear3=0;}
greenroshks 8:667fbc82d634 72
greenroshks 8:667fbc82d634 73 if(fault4==0)
greenroshks 8:667fbc82d634 74 { clear4=1;printf("");}
greenroshks 8:667fbc82d634 75 else
greenroshks 8:667fbc82d634 76 { clear4=0;}
greenroshks 8:667fbc82d634 77
greenroshks 8:667fbc82d634 78
greenroshks 8:667fbc82d634 79
greenroshks 8:667fbc82d634 80
greenroshks 8:667fbc82d634 81
greenroshks 8:667fbc82d634 82
greenroshks 8:667fbc82d634 83
greenroshks 8:667fbc82d634 84
greenroshks 8:667fbc82d634 85 //clear1 = !fault1;
greenroshks 8:667fbc82d634 86 //clear2 = !fault2;
greenroshks 8:667fbc82d634 87 //clear3 = !fault3;
greenroshks 8:667fbc82d634 88 //clear4 = !fault4;
raizel_varun 7:f06840d848e3 89 //clear5 = !fault5;
raizel_varun 7:f06840d848e3 90 //clear6 = !fault6;
raizel_varun 7:f06840d848e3 91 //clear7 = !fault7;
raizel_varun 7:f06840d848e3 92 //clear8 = !fault8;
greenroshks 8:667fbc82d634 93
greenroshks 8:667fbc82d634 94
greenroshks 8:667fbc82d634 95 out_poll = clear_poll;
greenroshks 8:667fbc82d634 96 out_ir = clear_ir;
greenroshks 8:667fbc82d634 97 Sensor.faultpoll = fault_poll ;
greenroshks 8:667fbc82d634 98 Sensor.faultir=fault_ir ;
greenroshks 8:667fbc82d634 99 printf(" %d , %d \n %d , %d\n",Sensor.faultpoll, Sensor.faultir , out_poll , out_ir) ;
sakthipriya 2:80b8a2e999f7 100
sakthipriya 4:8f6c24eca109 101 }
greenroshks 8:667fbc82d634 102
greenroshks 8:667fbc82d634 103
greenroshks 8:667fbc82d634 104
raizel_varun 7:f06840d848e3 105 void Clear_IR1()
raizel_varun 7:f06840d848e3 106 {clear5=!clear5;
raizel_varun 7:f06840d848e3 107 }
greenroshks 8:667fbc82d634 108
raizel_varun 7:f06840d848e3 109 void Clear_IR2()
raizel_varun 7:f06840d848e3 110 {clear6=!clear6;
raizel_varun 7:f06840d848e3 111 }
greenroshks 8:667fbc82d634 112
raizel_varun 7:f06840d848e3 113 void Clear_IR3()
raizel_varun 7:f06840d848e3 114 {clear7=!clear7;
raizel_varun 7:f06840d848e3 115 }
greenroshks 8:667fbc82d634 116
raizel_varun 7:f06840d848e3 117 void Clear_IR4()
raizel_varun 7:f06840d848e3 118 {clear8=!clear8;
raizel_varun 7:f06840d848e3 119 }
greenroshks 8:667fbc82d634 120
raizel_varun 7:f06840d848e3 121 void Clear_IR5()
raizel_varun 7:f06840d848e3 122 {clear9=!clear9;
raizel_varun 7:f06840d848e3 123 }
greenroshks 8:667fbc82d634 124
raizel_varun 7:f06840d848e3 125 void interrupt_fault()
raizel_varun 7:f06840d848e3 126 {
greenroshks 8:667fbc82d634 127 fault_IR1.rise(&Clear_IR1);
raizel_varun 7:f06840d848e3 128 fault_IR2.rise(&Clear_IR2);
raizel_varun 7:f06840d848e3 129 fault_IR3.rise(&Clear_IR3);
raizel_varun 7:f06840d848e3 130 fault_IR4.rise(&Clear_IR4);
greenroshks 8:667fbc82d634 131 fault_IR5.rise(&Clear_IR5);
raizel_varun 7:f06840d848e3 132 fault_IR1.fall(&Clear_IR1);
raizel_varun 7:f06840d848e3 133 fault_IR2.fall(&Clear_IR2);
raizel_varun 7:f06840d848e3 134 fault_IR3.fall(&Clear_IR3);
raizel_varun 7:f06840d848e3 135 fault_IR4.fall(&Clear_IR4);
raizel_varun 7:f06840d848e3 136 fault_IR5.fall(&Clear_IR5);
raizel_varun 7:f06840d848e3 137 }
raizel_varun 7:f06840d848e3 138
greenroshks 8:667fbc82d634 139
sakthipriya 5:255b43e8e21a 140 void POWER(char flag) //flag corresponds to the power mode
sakthipriya 4:8f6c24eca109 141 {
sakthipriya 4:8f6c24eca109 142 printf("Entered Power Management \n");
sakthipriya 4:8f6c24eca109 143 printf("Entering mode %c \n", flag);
sakthipriya 4:8f6c24eca109 144 switch (flag)
sakthipriya 4:8f6c24eca109 145 {
sakthipriya 5:255b43e8e21a 146 case '0': beacon_sc = 6; //least power mode
sakthipriya 5:255b43e8e21a 147 acs_pflag = 0;
sakthipriya 5:255b43e8e21a 148 acs_active = 0; //switching off a component of acs
sakthipriya 4:8f6c24eca109 149 break;
sakthipriya 5:255b43e8e21a 150 case '1': beacon_sc = 3;
sakthipriya 5:255b43e8e21a 151 acs_pflag = 0;
sakthipriya 5:255b43e8e21a 152 acs_active = 0;
sakthipriya 4:8f6c24eca109 153 break;
sakthipriya 5:255b43e8e21a 154 case '2': beacon_sc = 3;
sakthipriya 5:255b43e8e21a 155 acs_pflag = 0;
sakthipriya 5:255b43e8e21a 156 acs_active = 0;
sakthipriya 4:8f6c24eca109 157 break;
sakthipriya 5:255b43e8e21a 158 case '3': beacon_sc = 3; //normal mode
sakthipriya 5:255b43e8e21a 159 acs_pflag = 1;
sakthipriya 5:255b43e8e21a 160 acs_active = 1;
sakthipriya 5:255b43e8e21a 161 break;
sakthipriya 4:8f6c24eca109 162 }
sakthipriya 5:255b43e8e21a 163 /* if (flag == '0')
sakthipriya 4:8f6c24eca109 164 beacon_sc = 30;
sakthipriya 4:8f6c24eca109 165 else
sakthipriya 4:8f6c24eca109 166 beacon_sc = 3;
sakthipriya 5:255b43e8e21a 167 if (flag == '3')
sakthipriya 5:255b43e8e21a 168 acs_pflag = 1;
sakthipriya 5:255b43e8e21a 169 else
sakthipriya 5:255b43e8e21a 170 acs_pflag = 0; */
greenroshks 8:667fbc82d634 171 }
greenroshks 8:667fbc82d634 172