mag n gyro included

Dependencies:   mbed-rtos mbed

Fork of BAE_vr2_gingerbread2 by Seeker of Truth ,

Committer:
sakthipriya
Date:
Wed Dec 17 06:52:26 2014 +0000
Revision:
0:e9c32e1df869
Child:
1:bd715ccef1bb
i2c working with new hk(no battery gauge)

Who changed what in which revision?

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