BAE RTOS..working hopefully

Dependencies:   mbed-rtos mbed

Committer:
harshit_felicity
Date:
Thu Jul 10 11:37:47 2014 +0000
Revision:
1:37fa1c3eba16
Parent:
0:cbe0ea884289
BAE RTOS..Working hopefully

Who changed what in which revision?

UserRevisionLine numberNew contents of line
harshit_felicity 0:cbe0ea884289 1 #include "hkfinal.h"
harshit_felicity 0:cbe0ea884289 2
harshit_felicity 0:cbe0ea884289 3 DigitalOut SelectLine3 (p24); // MSB of Select Lines
harshit_felicity 0:cbe0ea884289 4 DigitalOut SelectLine2 (p23);
harshit_felicity 0:cbe0ea884289 5 DigitalOut SelectLine1 (p22);
harshit_felicity 0:cbe0ea884289 6 DigitalOut SelectLine0 (p21); // LSB of Select Lines
harshit_felicity 0:cbe0ea884289 7
harshit_felicity 0:cbe0ea884289 8 AnalogIn CurrentInput(p15); // Input from Current Multiplexer
harshit_felicity 0:cbe0ea884289 9 AnalogIn VoltageInput(p16); // Input from Voltage Multiplexer
harshit_felicity 0:cbe0ea884289 10 AnalogIn TemperatureInput(p17); // input from Temperature Multiplexer
harshit_felicity 0:cbe0ea884289 11
harshit_felicity 0:cbe0ea884289 12 typedef struct SensorData {
harshit_felicity 0:cbe0ea884289 13 char Voltage[10];
harshit_felicity 0:cbe0ea884289 14 char Current[10];
harshit_felicity 0:cbe0ea884289 15 char Temperature[10];
harshit_felicity 0:cbe0ea884289 16 //float Battery[2];
harshit_felicity 0:cbe0ea884289 17 }SensorDaty;
harshit_felicity 0:cbe0ea884289 18
harshit_felicity 0:cbe0ea884289 19 typedef struct ShortBeacon {
harshit_felicity 0:cbe0ea884289 20 char Voltage[1];
harshit_felicity 0:cbe0ea884289 21 char AngularSpeed[2];
harshit_felicity 0:cbe0ea884289 22 char SubsystemStatus[1];
harshit_felicity 0:cbe0ea884289 23 char Temp[3];
harshit_felicity 0:cbe0ea884289 24 char ErrorFlag[1];
harshit_felicity 0:cbe0ea884289 25 }ShortBeacy;
harshit_felicity 0:cbe0ea884289 26
harshit_felicity 0:cbe0ea884289 27 int quantiz(float start,float step,float x)
harshit_felicity 0:cbe0ea884289 28 {
harshit_felicity 0:cbe0ea884289 29 int y=(x-start)/step;
harshit_felicity 0:cbe0ea884289 30 if(y<=0)y=0;
harshit_felicity 0:cbe0ea884289 31 if(y>=15)y=15;
harshit_felicity 0:cbe0ea884289 32 return y;
harshit_felicity 0:cbe0ea884289 33 }
harshit_felicity 0:cbe0ea884289 34
harshit_felicity 0:cbe0ea884289 35 void init_beacon(ShortBeacy x){
harshit_felicity 0:cbe0ea884289 36 x.Voltage[0]=1;
harshit_felicity 0:cbe0ea884289 37 x.AngularSpeed[0]=2;
harshit_felicity 0:cbe0ea884289 38 x.AngularSpeed[1]=3;
harshit_felicity 0:cbe0ea884289 39 x.SubsystemStatus[0]=145;
harshit_felicity 0:cbe0ea884289 40 x.Temp[0]=1;
harshit_felicity 0:cbe0ea884289 41 x.Temp[1]=2;
harshit_felicity 0:cbe0ea884289 42 x.Temp[2]=3;
harshit_felicity 0:cbe0ea884289 43 x.ErrorFlag[0]=3;
harshit_felicity 0:cbe0ea884289 44 }
harshit_felicity 0:cbe0ea884289 45
harshit_felicity 0:cbe0ea884289 46 void FUNC_HK_MAIN()
harshit_felicity 0:cbe0ea884289 47 {
harshit_felicity 0:cbe0ea884289 48 SensorDaty SensorData;
harshit_felicity 0:cbe0ea884289 49 ShortBeacy ShortBeacon;
harshit_felicity 0:cbe0ea884289 50 init_beacon(ShortBeacon);
harshit_felicity 0:cbe0ea884289 51
harshit_felicity 0:cbe0ea884289 52 int LoopIterator;
harshit_felicity 0:cbe0ea884289 53
harshit_felicity 0:cbe0ea884289 54 SelectLine0=0;
harshit_felicity 0:cbe0ea884289 55 SelectLine1=0;
harshit_felicity 0:cbe0ea884289 56 SelectLine2=0;
harshit_felicity 0:cbe0ea884289 57 SelectLine3=0;
harshit_felicity 0:cbe0ea884289 58
harshit_felicity 0:cbe0ea884289 59 for(LoopIterator=0; LoopIterator<16; LoopIterator++) {
harshit_felicity 0:cbe0ea884289 60
harshit_felicity 0:cbe0ea884289 61 if(LoopIterator%2==0) {
harshit_felicity 0:cbe0ea884289 62 SensorData.Current[LoopIterator]=quantiz(cstart,cstep,(CurrentInput.read()/(50*rsens)));
harshit_felicity 0:cbe0ea884289 63 SensorData.Voltage[LoopIterator]=quantiz(vstart,vstep,(VoltageInput.read()/5.37));
harshit_felicity 0:cbe0ea884289 64 SensorData.Temperature[LoopIterator]=quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543));
harshit_felicity 0:cbe0ea884289 65 } else {
harshit_felicity 0:cbe0ea884289 66 SensorData.Current[LoopIterator-1]=SensorData.Current[LoopIterator-1]<<4+quantiz(cstart,cstep,(CurrentInput.read()/(50*rsens)));
harshit_felicity 0:cbe0ea884289 67 SensorData.Voltage[LoopIterator-1]=SensorData.Voltage[LoopIterator-1]<<4+quantiz(vstart,vstep,(VoltageInput.read()/5.37));
harshit_felicity 0:cbe0ea884289 68 SensorData.Temperature[LoopIterator-1]=SensorData.Temperature[LoopIterator-1]<<4+quantiz(tstart,tstep,(-90.7*3.18*TemperatureInput.read()+190.1543));
harshit_felicity 0:cbe0ea884289 69 }
harshit_felicity 0:cbe0ea884289 70 // The following lines are used to iterate the select lines from 0 to 15
harshit_felicity 0:cbe0ea884289 71 SelectLine0=!(SelectLine0);
harshit_felicity 0:cbe0ea884289 72
harshit_felicity 0:cbe0ea884289 73 if(LoopIterator%2==1)
harshit_felicity 0:cbe0ea884289 74 SelectLine1=!(SelectLine1);
harshit_felicity 0:cbe0ea884289 75
harshit_felicity 0:cbe0ea884289 76 if(LoopIterator%4==3)
harshit_felicity 0:cbe0ea884289 77 SelectLine2=!(SelectLine2);
harshit_felicity 0:cbe0ea884289 78
harshit_felicity 0:cbe0ea884289 79 if(LoopIterator%8==7)
harshit_felicity 0:cbe0ea884289 80 SelectLine3=!(SelectLine3);
harshit_felicity 0:cbe0ea884289 81
harshit_felicity 0:cbe0ea884289 82 wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed.
harshit_felicity 0:cbe0ea884289 83
harshit_felicity 0:cbe0ea884289 84 }
harshit_felicity 0:cbe0ea884289 85
harshit_felicity 0:cbe0ea884289 86 }