publishing to check changes in cdms code

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE_samp_23SEP_DMA_flag by samp Srinivasan

Committer:
shreeshas95
Date:
Fri Jan 29 17:50:20 2016 +0000
Revision:
104:a50ae79ca36e
Parent:
103:b55559925dc1
Child:
105:5ce0337e7c15
Added cdms hk thread : ready for testing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shreeshas95 103:b55559925dc1 1 //#include "cdms_rtc.h"
shreeshas95 103:b55559925dc1 2 #include "pinconfig.h"
shreeshas95 103:b55559925dc1 3
shreeshas95 103:b55559925dc1 4 void FCTN_CDMS_HK_MAIN();
shreeshas95 103:b55559925dc1 5 void FCTN_CDMS_HK();
shreeshas95 103:b55559925dc1 6 //extern uint8_t CDMS_HK_STATUS;
shreeshas95 103:b55559925dc1 7 //extern uint8_t Power_level;
shreeshas95 103:b55559925dc1 8 //extern uint8_t Att_level;
shreeshas95 103:b55559925dc1 9 //extern char CDMS_HK[8];
shreeshas95 103:b55559925dc1 10
shreeshas95 103:b55559925dc1 11 Serial hk_cdms(USBTX, USBRX);
shreeshas95 103:b55559925dc1 12
shreeshas95 103:b55559925dc1 13 AnalogIn TempInput(PIN27); // Input from Current Multiplexer
shreeshas95 103:b55559925dc1 14 AnalogIn CDMS_temp_sensor(PIN53);
shreeshas95 103:b55559925dc1 15
shreeshas95 103:b55559925dc1 16 DigitalOut SelectLinec3 (PIN79); // MSB of Select Lines
shreeshas95 103:b55559925dc1 17 DigitalOut SelectLinec2 (PIN78);
shreeshas95 103:b55559925dc1 18 DigitalOut SelectLinec1 (PIN77);
shreeshas95 103:b55559925dc1 19 DigitalOut SelectLinec0 (PIN76); // LSB of Select Lines
shreeshas95 103:b55559925dc1 20
shreeshas95 104:a50ae79ca36e 21 void FCTN_CDMS_HK_MAIN(void const *args)
shreeshas95 103:b55559925dc1 22 {
shreeshas95 103:b55559925dc1 23 // CDMS_HK_STATUS=(CDMS_HK_STATUS)|(HK_MAIN_STATUS);
shreeshas95 103:b55559925dc1 24 FCTN_CDMS_HK;
shreeshas95 103:b55559925dc1 25 hk_cdms.printf(" \r\nCDMS HK entered Verify COM RX RSSI >0.4 \r\n");
shreeshas95 103:b55559925dc1 26
shreeshas95 103:b55559925dc1 27 int HK_I2C;
shreeshas95 103:b55559925dc1 28 char BAE_HK[73];
shreeshas95 103:b55559925dc1 29 FCTN_I2C_READ(BAE_HK,73);
shreeshas95 103:b55559925dc1 30 printf("BAE_HK=%s",BAE_HK);
shreeshas95 103:b55559925dc1 31 /*if(HK_I2C==0)
shreeshas95 103:b55559925dc1 32 {
shreeshas95 103:b55559925dc1 33 if(Power_level!=0)
shreeshas95 103:b55559925dc1 34 {
shreeshas95 103:b55559925dc1 35 printf("Update Power_level to 0 in Flash");
shreeshas95 103:b55559925dc1 36 }
shreeshas95 103:b55559925dc1 37 Att_level=0;
shreeshas95 103:b55559925dc1 38 CDMS_HK_STATUS=(CDMS_HK_STATUS)|(HK_BAE_ERR_I2C);
shreeshas95 103:b55559925dc1 39 CDMS_HK_STATUS=(CDMS_HK_STATUS)&(~(HK_MAIN_STATUS));
shreeshas95 103:b55559925dc1 40 }**/
shreeshas95 103:b55559925dc1 41 uint8_t CDMS_quant[17];
shreeshas95 103:b55559925dc1 42 // printf("BAE HK is %s",BAE_HK);
shreeshas95 103:b55559925dc1 43 for(int i=0;i<16;i++)
shreeshas95 103:b55559925dc1 44 {
shreeshas95 103:b55559925dc1 45 CDMS_quant[i]= (uint8_t)quant_data.temp_quant[i];
shreeshas95 103:b55559925dc1 46 }
shreeshas95 103:b55559925dc1 47 CDMS_quant[16]= (uint8_t)quant_data.CDMS_temp_quant;
shreeshas95 103:b55559925dc1 48 uint64_t time=0x00;//replace with rtc function
shreeshas95 103:b55559925dc1 49 char tree[61];
shreeshas95 103:b55559925dc1 50 hk_cdms.printf("i am done\r\n");
shreeshas95 103:b55559925dc1 51 uint8_t data[512];
shreeshas95 103:b55559925dc1 52 for(int i=0;i<512;i++)
shreeshas95 103:b55559925dc1 53 {
shreeshas95 103:b55559925dc1 54 data[i]=0x00;
shreeshas95 103:b55559925dc1 55 }
shreeshas95 103:b55559925dc1 56 tree[0]=(char)(time>>(56))&(0xFF);
shreeshas95 103:b55559925dc1 57 tree[1]=(char)(time>>(48))&(0xFF);
shreeshas95 103:b55559925dc1 58 tree[2]=(char)(time>>(40))&(0xFF);
shreeshas95 103:b55559925dc1 59 tree[3]=(char)(time>>(32))&(0xFF);
shreeshas95 103:b55559925dc1 60 tree[4]=(char)(time>>(24))&(0xFF);
shreeshas95 103:b55559925dc1 61 tree[5]=(char)(time>>(16))&(0xFF);
shreeshas95 103:b55559925dc1 62 tree[6]=(char)(time>>(8))&(0xFF);
shreeshas95 103:b55559925dc1 63 tree[7]=(char)(time)&(0xFF);
shreeshas95 103:b55559925dc1 64 for(int i=0;i<73;i++)
shreeshas95 103:b55559925dc1 65 {
shreeshas95 103:b55559925dc1 66 tree[i+8]=BAE_HK[i];
shreeshas95 103:b55559925dc1 67 }
shreeshas95 103:b55559925dc1 68 printf("Hope u r alive \r\n");
shreeshas95 103:b55559925dc1 69 for(int i=0;i<81;i++)
shreeshas95 103:b55559925dc1 70 {
shreeshas95 103:b55559925dc1 71 data[i]=(uint8_t)tree[i];
shreeshas95 103:b55559925dc1 72 }
shreeshas95 103:b55559925dc1 73 for(int i=81;i<98;i++)
shreeshas95 103:b55559925dc1 74 {
shreeshas95 103:b55559925dc1 75 data[i]=CDMS_quant[i];
shreeshas95 103:b55559925dc1 76 }
shreeshas95 103:b55559925dc1 77 for(int i=0;i<512;i++)
shreeshas95 103:b55559925dc1 78 {
shreeshas95 103:b55559925dc1 79 printf("%d",data[i]);
shreeshas95 103:b55559925dc1 80 }
shreeshas95 103:b55559925dc1 81 uint8_t fsc=FCTN_SD_MNGR(0x3);
shreeshas95 103:b55559925dc1 82 printf("FSC where SD is written is %d\r\n",fsc);
shreeshas95 103:b55559925dc1 83 int a=SD_WRITE(data,0x00000012,0x3);
shreeshas95 103:b55559925dc1 84 printf("Result of writing is %d \r\n",a);
shreeshas95 103:b55559925dc1 85 //BCN long frame ???
shreeshas95 103:b55559925dc1 86 //CDMS_HK_STATUS=(CDMS_HK_STATUS)&(~(HK_MAIN_STATUS));
shreeshas95 103:b55559925dc1 87 hk_cdms.printf("CDMS executed succesfully\r\n");
shreeshas95 103:b55559925dc1 88 }
shreeshas95 103:b55559925dc1 89
shreeshas95 103:b55559925dc1 90
shreeshas95 103:b55559925dc1 91
shreeshas95 103:b55559925dc1 92 int quantiz(float start,float step,float x)
shreeshas95 103:b55559925dc1 93 {
shreeshas95 103:b55559925dc1 94 int y=(x-start)/step;
shreeshas95 103:b55559925dc1 95 if(y<=0)y=0;
shreeshas95 103:b55559925dc1 96 if(y>=255)y=255;
shreeshas95 103:b55559925dc1 97 return y;
shreeshas95 103:b55559925dc1 98 }
shreeshas95 103:b55559925dc1 99
shreeshas95 103:b55559925dc1 100
shreeshas95 103:b55559925dc1 101
shreeshas95 103:b55559925dc1 102 void saveMin(char x,char y){
shreeshas95 103:b55559925dc1 103 if(y<x){
shreeshas95 103:b55559925dc1 104 x=y;
shreeshas95 103:b55559925dc1 105 }
shreeshas95 103:b55559925dc1 106
shreeshas95 103:b55559925dc1 107 }
shreeshas95 103:b55559925dc1 108 void saveMax(char x,char y){
shreeshas95 103:b55559925dc1 109 if (y>x)
shreeshas95 103:b55559925dc1 110 {
shreeshas95 103:b55559925dc1 111 x=y;
shreeshas95 103:b55559925dc1 112 }
shreeshas95 103:b55559925dc1 113 }
shreeshas95 103:b55559925dc1 114 void minMaxHkData(){
shreeshas95 103:b55559925dc1 115
shreeshas95 103:b55559925dc1 116
shreeshas95 103:b55559925dc1 117
shreeshas95 103:b55559925dc1 118 if(firstCount==true){
shreeshas95 103:b55559925dc1 119 for (int i = 0; i < 16; ++i){
shreeshas95 103:b55559925dc1 120 min_max_data.temp_min[i] = quant_data.temp_quant[i];
shreeshas95 103:b55559925dc1 121 min_max_data.temp_max[i] = quant_data.temp_quant[i];
shreeshas95 103:b55559925dc1 122 }
shreeshas95 103:b55559925dc1 123
shreeshas95 103:b55559925dc1 124 min_max_data.CDMS_temp_min=quant_data.CDMS_temp_quant;
shreeshas95 103:b55559925dc1 125 min_max_data.CDMS_temp_max=quant_data.CDMS_temp_quant;
shreeshas95 103:b55559925dc1 126
shreeshas95 103:b55559925dc1 127
shreeshas95 103:b55559925dc1 128 }
shreeshas95 103:b55559925dc1 129 else {
shreeshas95 103:b55559925dc1 130 for (int i = 0; i < 16; ++i)
shreeshas95 103:b55559925dc1 131 {
shreeshas95 103:b55559925dc1 132 saveMin(min_max_data.temp_min[i],quant_data.temp_quant[i]);
shreeshas95 103:b55559925dc1 133 saveMax(min_max_data.temp_max[i],quant_data.temp_quant[i]);
shreeshas95 103:b55559925dc1 134 }
shreeshas95 103:b55559925dc1 135
shreeshas95 103:b55559925dc1 136 saveMin(min_max_data.CDMS_temp_min,quant_data.CDMS_temp_quant);
shreeshas95 103:b55559925dc1 137 saveMax(min_max_data.CDMS_temp_max,quant_data.CDMS_temp_quant);
shreeshas95 103:b55559925dc1 138
shreeshas95 103:b55559925dc1 139
shreeshas95 103:b55559925dc1 140 }
shreeshas95 103:b55559925dc1 141 firstCount=false;
shreeshas95 103:b55559925dc1 142 }
shreeshas95 103:b55559925dc1 143
shreeshas95 103:b55559925dc1 144 void FCTN_CDMS_HK()
shreeshas95 103:b55559925dc1 145 {
shreeshas95 103:b55559925dc1 146
shreeshas95 103:b55559925dc1 147 int Iteration=0;
shreeshas95 103:b55559925dc1 148
shreeshas95 103:b55559925dc1 149 SelectLinec0=0;
shreeshas95 103:b55559925dc1 150 SelectLinec1=0;
shreeshas95 103:b55559925dc1 151 SelectLinec2=0;
shreeshas95 103:b55559925dc1 152 SelectLinec3=0;
shreeshas95 103:b55559925dc1 153
shreeshas95 103:b55559925dc1 154 for(Iteration=0; Iteration<16; Iteration++){
shreeshas95 103:b55559925dc1 155
shreeshas95 103:b55559925dc1 156 actual_data.temp_actual[Iteration]=TempInput.read();
shreeshas95 103:b55559925dc1 157
shreeshas95 103:b55559925dc1 158 SelectLinec0=!(SelectLinec0);
shreeshas95 103:b55559925dc1 159 if(Iteration%2==1)
shreeshas95 103:b55559925dc1 160 SelectLinec1=!(SelectLinec1);
shreeshas95 103:b55559925dc1 161 if(Iteration%4==3)
shreeshas95 103:b55559925dc1 162 SelectLinec2=!(SelectLinec2);
shreeshas95 103:b55559925dc1 163 if(Iteration%8==7)
shreeshas95 103:b55559925dc1 164 SelectLinec3=!(SelectLinec3);
shreeshas95 103:b55559925dc1 165 }
shreeshas95 103:b55559925dc1 166
shreeshas95 103:b55559925dc1 167 actual_data.CDMS_temp_actual=(-90.7*3.3*CDMS_temp_sensor.read())+190.1543;
shreeshas95 103:b55559925dc1 168
shreeshas95 103:b55559925dc1 169 for(Iteration=0;Iteration<16;Iteration++){
shreeshas95 103:b55559925dc1 170
shreeshas95 103:b55559925dc1 171 if(Iteration<14){
shreeshas95 103:b55559925dc1 172
shreeshas95 103:b55559925dc1 173 actual_data.temp_actual[Iteration]=actual_data.temp_actual[Iteration]*3.3;
shreeshas95 103:b55559925dc1 174 int resistance;
shreeshas95 103:b55559925dc1 175
shreeshas95 103:b55559925dc1 176 resistance=24000*actual_data.temp_actual[Iteration]/(3.3-actual_data.temp_actual[Iteration]);
shreeshas95 103:b55559925dc1 177 if(actual_data.temp_actual[Iteration]>1.47)
shreeshas95 103:b55559925dc1 178 {
shreeshas95 103:b55559925dc1 179 actual_data.temp_actual[Iteration]=3694/log(24.032242*resistance);
shreeshas95 103:b55559925dc1 180 }
shreeshas95 103:b55559925dc1 181 else{
shreeshas95 103:b55559925dc1 182
shreeshas95 103:b55559925dc1 183 actual_data.temp_actual[Iteration]=3365.4/log(7.60573*resistance);
shreeshas95 103:b55559925dc1 184 }
shreeshas95 103:b55559925dc1 185 }
shreeshas95 103:b55559925dc1 186 else
shreeshas95 103:b55559925dc1 187 actual_data.temp_actual[Iteration]=(-90.7*3.3*actual_data.temp_actual[Iteration])+190.1543;
shreeshas95 103:b55559925dc1 188 }
shreeshas95 103:b55559925dc1 189
shreeshas95 103:b55559925dc1 190 for(Iteration=0;Iteration<16;Iteration++){
shreeshas95 103:b55559925dc1 191
shreeshas95 103:b55559925dc1 192 if(Iteration<14){
shreeshas95 103:b55559925dc1 193
shreeshas95 103:b55559925dc1 194 quant_data.temp_quant[Iteration]=quantiz(tstart_thermistor,tstep_thermistor,actual_data.temp_actual[Iteration]);
shreeshas95 103:b55559925dc1 195 }
shreeshas95 103:b55559925dc1 196 else
shreeshas95 103:b55559925dc1 197 quant_data.temp_quant[Iteration]=quantiz(tstart,tstep,actual_data.temp_actual[Iteration]);
shreeshas95 103:b55559925dc1 198 }
shreeshas95 103:b55559925dc1 199
shreeshas95 103:b55559925dc1 200 quant_data.CDMS_temp_quant=quantiz(tstart,tstep,actual_data.CDMS_temp_actual);
shreeshas95 103:b55559925dc1 201
shreeshas95 103:b55559925dc1 202 minMaxHkData();
shreeshas95 103:b55559925dc1 203 }