00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include <stdio.h>
00043
00044 #include <math.h>
00045 #include "mscbemb.h"
00046 #include "feb64.h"
00047
00048 #include "Devices/pca_internal.h"
00049 #include "Devices/adc_internal.h"
00050
00051 #ifdef _ADT7486A_
00052 #include "Devices/ADT7486A_tsensor.h"
00053 #endif
00054
00055 #ifdef _PCA9539_
00056 #include "Devices/PCA9539_io.h"
00057 #endif
00058
00059 #ifdef _LTC1669_
00060 #include "Devices/LTC1669_dac.h"
00061 #endif
00062
00063 #ifdef _LTC1665_
00064 #include "Devices/LTC1665_dac.h"
00065 #endif
00066
00067 #ifdef _LTC2600_
00068 #include "Devices/LTC2600_dac.h"
00069 #endif
00070
00071 #ifdef _LTC2497_
00072 #include "Devices/LTC2497_adc.h"
00073 #endif
00074
00075 #ifdef _LTC2495_
00076 #include "Devices/LTC2495_adc.h"
00077 #endif
00078
00079 #ifdef _ExtEEPROM_
00080 #include "Devices/ExtEEPROM.h"
00081 #endif
00082
00083
00084
00085 char code node_name[] = "FEB64";
00086 char idata svn_rev_code[] = "$Rev: 1185 $";
00087
00088
00089
00090 unsigned char idata _n_sub_addr = 1;
00091
00092
00093 int xdata k, calState=0, calCount=0;
00094 float xdata calNumber = 10.0;
00095 char xdata calQpumpSave=0, calSwSave=0;
00096 unsigned long xdata currentTime=0, sstTime=0,sstExtTime=0, calTime=0;
00097 unsigned char xdata status, channel, chipAdd, chipChan;
00098 unsigned char xdata BiasIndex, AsumIndex, NodeOK=0;
00099
00100
00101
00102 unsigned char bdata bChange;
00103
00104
00105 sbit bCPupdoitNOW = bChange ^ 0;
00106 sbit bDacdoitNOW = bChange ^ 1;
00107
00108
00109 sbit PCA_Flag = bChange ^ 2;
00110 sbit LTC2600_Flag = bChange ^ 3;
00111 sbit LTC1665_Flag = bChange ^ 4;
00112 sbit LTC1669_Flag = bChange ^ 5;
00113 sbit EEP_CTR_Flag = bChange ^ 6;
00114 sbit CAsum_Flag = bChange ^ 7;
00115
00116
00117 sbit DACRESETN = P1 ^ 0;
00118 sbit PCARESETN = P1 ^ 2;
00119
00120
00121 sbit ASUM_SYNC = P1 ^ 7;
00122 sbit ASUM_TESTN = P1 ^ 6;
00123 sbit ASUM_PWDN = P1 ^ 5;
00124
00125
00126 sbit REG_EN = P3 ^ 2;
00127
00128
00129
00130 MSCB_INFO_VAR code vars[] = {
00131 4, UNIT_BYTE, 0, 0, 0, "SerialN", &user_data.SerialN,
00132 2, UNIT_BYTE, 0, 0, 0, "Error", &user_data.error,
00133 1, UNIT_BYTE, 0, 0, 0, "Control", &user_data.control,
00134 1, UNIT_BYTE, 0, 0, 0, "Status", &user_data.status,
00135 1, UNIT_BYTE, 0, 0, 0, "EEPage", &user_data.eepage,
00136 1, UNIT_BYTE, 0, 0, 0, "swBias", &user_data.swBias,
00137 2, UNIT_BYTE, 0, 0, 0, "rQpump", &user_data.rQpump,
00138
00139 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "VBias", &user_data.VBias,
00140 4, UNIT_AMPERE, PRFX_MICRO, 0, MSCBF_FLOAT, "IBias", &user_data.IBias,
00141 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "pDVMon", &user_data.pDVMon,
00142 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "pAVMon", &user_data.pAVMon,
00143 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "nAVMon", &user_data.nAVMon,
00144 4, UNIT_AMPERE, 0, 0, MSCBF_FLOAT, "nAIMon", &user_data.nAIMon,
00145 4, UNIT_AMPERE, 0, 0, MSCBF_FLOAT, "pAIMon", &user_data.pAIMon,
00146 4, UNIT_AMPERE, 0, 0, MSCBF_FLOAT, "pDIMon", &user_data.pDIMon,
00147 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "uCTemp", &user_data.uCTemp,
00148
00149 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "adcTemp", &user_data.adcTemp,
00150 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "aftTemp", &user_data.afterTemp,
00151 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "regTemp", &user_data.regTemp,
00152
00153 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "ssTemp0", &user_data.ssTemp[0],
00154 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "ssTemp1", &user_data.ssTemp[1],
00155 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "ssTemp2", &user_data.ssTemp[2],
00156 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "ssTemp3", &user_data.ssTemp[3],
00157
00158 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp0", &user_data.Temp[0],
00159 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp1", &user_data.Temp[1],
00160 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp2", &user_data.Temp[2],
00161 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp3", &user_data.Temp[3],
00162 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp4", &user_data.Temp[4],
00163 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp5", &user_data.Temp[5],
00164 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp6", &user_data.Temp[6],
00165 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp7", &user_data.Temp[7],
00166
00167 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "VBMon0", &user_data.VBMon[0],
00168 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "VBMon1", &user_data.VBMon[1],
00169 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "VBMon2", &user_data.VBMon[2],
00170 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "VBMon3", &user_data.VBMon[3],
00171 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "VBMon4", &user_data.VBMon[4],
00172 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "VBMon5", &user_data.VBMon[5],
00173 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "VBMon6", &user_data.VBMon[6],
00174 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "VBMon7", &user_data.VBMon[7],
00175
00176 4, UNIT_AMPERE, PRFX_MICRO, 0, MSCBF_FLOAT, "IBMon0", &user_data.IBMon[0],
00177 4, UNIT_AMPERE, PRFX_MICRO, 0, MSCBF_FLOAT, "IBMon1", &user_data.IBMon[1],
00178 4, UNIT_AMPERE, PRFX_MICRO, 0, MSCBF_FLOAT, "IBMon2", &user_data.IBMon[2],
00179 4, UNIT_AMPERE, PRFX_MICRO, 0, MSCBF_FLOAT, "IBMon3", &user_data.IBMon[3],
00180 4, UNIT_AMPERE, PRFX_MICRO, 0, MSCBF_FLOAT, "IBMon4", &user_data.IBMon[4],
00181 4, UNIT_AMPERE, PRFX_MICRO, 0, MSCBF_FLOAT, "IBMon5", &user_data.IBMon[5],
00182 4, UNIT_AMPERE, PRFX_MICRO, 0, MSCBF_FLOAT, "IBMon6", &user_data.IBMon[6],
00183 4, UNIT_AMPERE, PRFX_MICRO, 0, MSCBF_FLOAT, "IBMon7", &user_data.IBMon[7],
00184
00185 2, UNIT_BYTE, 0, 0, 0, "rAsum0", &user_data.rAsum[0],
00186 2, UNIT_BYTE, 0, 0, 0, "rAsum1", &user_data.rAsum[1],
00187 2, UNIT_BYTE, 0, 0, 0, "rAsum2", &user_data.rAsum[2],
00188 2, UNIT_BYTE, 0, 0, 0, "rAsum3", &user_data.rAsum[3],
00189 2, UNIT_BYTE, 0, 0, 0, "rAsum4", &user_data.rAsum[4],
00190 2, UNIT_BYTE, 0, 0, 0, "rAsum5", &user_data.rAsum[5],
00191 2, UNIT_BYTE, 0, 0, 0, "rAsum6", &user_data.rAsum[6],
00192 2, UNIT_BYTE, 0, 0, 0, "rAsum7", &user_data.rAsum[7],
00193
00194 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias00", &user_data.rBias[0],
00195 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias01", &user_data.rBias[1],
00196 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias02", &user_data.rBias[2],
00197 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias03", &user_data.rBias[3],
00198 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias04", &user_data.rBias[4],
00199 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias05", &user_data.rBias[5],
00200 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias06", &user_data.rBias[6],
00201 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias07", &user_data.rBias[7],
00202 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias08", &user_data.rBias[8],
00203 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias09", &user_data.rBias[9],
00204 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias10", &user_data.rBias[10],
00205 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias11", &user_data.rBias[11],
00206 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias12", &user_data.rBias[12],
00207 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias13", &user_data.rBias[13],
00208 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias14", &user_data.rBias[14],
00209 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias15", &user_data.rBias[15],
00210 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias16", &user_data.rBias[16],
00211 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias17", &user_data.rBias[17],
00212 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias18", &user_data.rBias[18],
00213 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias19", &user_data.rBias[19],
00214 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias20", &user_data.rBias[20],
00215 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias21", &user_data.rBias[21],
00216 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias22", &user_data.rBias[22],
00217 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias23", &user_data.rBias[23],
00218 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias24", &user_data.rBias[24],
00219 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias25", &user_data.rBias[25],
00220 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias26", &user_data.rBias[26],
00221 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias27", &user_data.rBias[27],
00222 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias28", &user_data.rBias[28],
00223 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias29", &user_data.rBias[29],
00224 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias30", &user_data.rBias[30],
00225 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias31", &user_data.rBias[31],
00226 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias32", &user_data.rBias[32],
00227 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias33", &user_data.rBias[33],
00228 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias34", &user_data.rBias[34],
00229 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias35", &user_data.rBias[35],
00230 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias36", &user_data.rBias[36],
00231 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias37", &user_data.rBias[37],
00232 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias38", &user_data.rBias[38],
00233 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias39", &user_data.rBias[39],
00234 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias40", &user_data.rBias[40],
00235 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias41", &user_data.rBias[41],
00236 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias42", &user_data.rBias[42],
00237 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias43", &user_data.rBias[43],
00238 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias44", &user_data.rBias[44],
00239 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias45", &user_data.rBias[45],
00240 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias46", &user_data.rBias[46],
00241 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias47", &user_data.rBias[47],
00242 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias48", &user_data.rBias[48],
00243 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias49", &user_data.rBias[49],
00244 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias50", &user_data.rBias[50],
00245 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias51", &user_data.rBias[51],
00246 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias52", &user_data.rBias[52],
00247 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias53", &user_data.rBias[53],
00248 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias54", &user_data.rBias[54],
00249 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias55", &user_data.rBias[55],
00250 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias56", &user_data.rBias[56],
00251 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias57", &user_data.rBias[57],
00252 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias58", &user_data.rBias[58],
00253 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias59", &user_data.rBias[59],
00254 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias60", &user_data.rBias[60],
00255 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias61", &user_data.rBias[61],
00256 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias62", &user_data.rBias[62],
00257 1,UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "rBias63", &user_data.rBias[63],
00258
00259 2, UNIT_BYTE, 0, 0, 0, "rVBias", &user_data.rVBias,
00260 2, UNIT_BYTE, 0, 0, 0, "rIBias", &user_data.rIBias,
00261 2, UNIT_BYTE, 0, 0, 0, "rpDV", &user_data.rpDV,
00262 2, UNIT_BYTE, 0, 0, 0, "rpAV", &user_data.rpAV,
00263 2, UNIT_BYTE, 0, 0, 0, "rnAV", &user_data.rnAV,
00264 2, UNIT_BYTE, 0, 0, 0, "rnAI", &user_data.rnAI,
00265 2, UNIT_BYTE, 0, 0, 0, "rpAI", &user_data.rpAI,
00266 2, UNIT_BYTE, 0, 0, 0, "rpDI", &user_data.rpDI,
00267
00268 4, UNIT_BYTE, 0, 0, 0, "rVBMon0", &user_data.rVBMon[0],
00269 4, UNIT_BYTE, 0, 0, 0, "rVBMon1", &user_data.rVBMon[1],
00270 4, UNIT_BYTE, 0, 0, 0, "rVBMon2", &user_data.rVBMon[2],
00271 4, UNIT_BYTE, 0, 0, 0, "rVBMon3", &user_data.rVBMon[3],
00272 4, UNIT_BYTE, 0, 0, 0, "rVBMon4", &user_data.rVBMon[4],
00273 4, UNIT_BYTE, 0, 0, 0, "rVBMon5", &user_data.rVBMon[5],
00274 4, UNIT_BYTE, 0, 0, 0, "rVBMon6", &user_data.rVBMon[6],
00275 4, UNIT_BYTE, 0, 0, 0, "rVBMon7", &user_data.rVBMon[7],
00276 4, UNIT_BYTE, 0, 0, 0, "rIBMon0", &user_data.rIBMon[0],
00277 4, UNIT_BYTE, 0, 0, 0, "rIBMon1", &user_data.rIBMon[1],
00278 4, UNIT_BYTE, 0, 0, 0, "rIBMon2", &user_data.rIBMon[2],
00279 4, UNIT_BYTE, 0, 0, 0, "rIBMon3", &user_data.rIBMon[3],
00280 4, UNIT_BYTE, 0, 0, 0, "rIBMon4", &user_data.rIBMon[4],
00281 4, UNIT_BYTE, 0, 0, 0, "rIBMon5", &user_data.rIBMon[5],
00282 4, UNIT_BYTE, 0, 0, 0, "rIBMon6", &user_data.rIBMon[6],
00283 4, UNIT_BYTE, 0, 0, 0, "rIBMon7", &user_data.rIBMon[7],
00284
00285 4, UNIT_BYTE, 0, 0,MSCBF_FLOAT|MSCBF_HIDDEN, "eepValue", &user_data.eepValue,
00286 4, UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "eeCtrSet", &user_data.eeCtrSet,
00287 4, UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "asumctl", &user_data.asumCtl,
00288 4, UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "watchdog", &user_data.watchdog,
00289 4, UNIT_BYTE, 0, 0,MSCBF_HIDDEN, "smbdebug", &user_data.debugsmb,
00290
00291 2, UNIT_BYTE, 0, 0, 0, "GeoAdd", &user_data.geoadd,
00292 0
00293 };
00294
00295 MSCB_INFO_VAR *variables = vars;
00296
00297
00298 extern SYS_INFO sys_info;
00299
00300 #ifdef _ADT7486A_
00301 unsigned char ADT7486A_addrArray[] = { ADT7486A_ADDR1
00302 , ADT7486A_ADDR0
00303 , ADT7486A_ADDR3
00304 , ADT7486A_ADDR2 };
00305 #endif
00306
00307 #ifdef _LTC2600_
00308 unsigned char xdata LTC2600_LOAD[] = { LTC2600_LOAD_A,LTC2600_LOAD_B
00309 , LTC2600_LOAD_C,LTC2600_LOAD_D
00310 , LTC2600_LOAD_E,LTC2600_LOAD_F
00311 , LTC2600_LOAD_G,LTC2600_LOAD_H };
00312 #endif
00313
00314
00315
00316 void publishCtlCsr(void) {
00317 DISABLE_INTERRUPTS;
00318 user_data.control = rCTL;
00319 user_data.status = rCSR;
00320 ENABLE_INTERRUPTS;
00321 }
00322
00323
00324
00325 void publishErr(bit errbit) {
00326 DISABLE_INTERRUPTS;
00327 errbit = ON;
00328 user_data.error = rESR;
00329 ENABLE_INTERRUPTS;
00330 }
00331
00332
00333
00334 void publishAll() {
00335 user_data.control = rCTL;
00336 user_data.status = rCSR;
00337 user_data.error = rESR;
00338 ENABLE_INTERRUPTS;
00339 }
00340
00341
00342
00343 void PublishVariable(float xdata * pvarDest, float varSrce, bit errbit) {
00344 DISABLE_INTERRUPTS;
00345 *pvarDest = varSrce;
00346 if (errbit) user_data.error = rESR;
00347 errbit = 0;
00348 ENABLE_INTERRUPTS;
00349 }
00350
00351
00352
00353 void updateAdc2Table(void)
00354 {
00355 int i, j;
00356 for(i=0;i<16;i++) {
00357 if (adc2mscb_table[i].current) {
00358 j = adc2mscb_table[i].mscbIdx;
00359 adc2mscb_table[i].Offst = (signed int) eepage.iBiasOffset[j];
00360 } else {
00361 j = adc2mscb_table[i].mscbIdx;
00362 adc2mscb_table[i].Offst = (signed int) eepage.vBiasOffset[j];
00363 }
00364 }
00365 }
00366
00367
00368
00369 #if 0
00370 void watchdog(short int state)
00371 {
00372 loopcnt++;
00373 DISABLE_INTERRUPTS;
00374 user_data.watchdog = ((loopcnt<<16) | (state & 0xFFFF));
00375 ENABLE_INTERRUPTS;
00376 }
00377 #endif
00378
00379
00380
00381 unsigned int NodeAdd_get(void)
00382 {
00383 unsigned int xdata crate_add=0;
00384 char xdata pca_add=0;
00385
00386 PCA9539_Read(BACKPLANE_READ, &pca_add, 1);
00387
00388
00389
00390 crate_add= ((~pca_add)<<1) & 0x01F8;
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410 return (crate_add | ((pca_add) & 0x0003));
00411 }
00412
00413
00414
00415 float read_voltage(unsigned char channel,unsigned int *rvalue, float coeff, float offset, unsigned char gain)
00416 {
00417 unsigned int xdata i;
00418 float xdata voltage;
00419 unsigned int xdata rawbin;
00420 unsigned long xdata rawsum = 0;
00421
00422
00423 for (i=0 ; i<10 ; i++) {
00424 rawbin = adc_read(channel, gain);
00425 rawsum += rawbin;
00426 yield();
00427 }
00428
00429
00430 *rvalue = rawsum/10;
00431 voltage = (float) *rvalue;
00432 voltage = (float) voltage / 1024.0 * INT_VREF;
00433 if ( channel != TCHANNEL)
00434 voltage = voltage * coeff + offset;
00435
00436 return voltage;
00437 }
00438
00439
00440
00441 void switchonoff(unsigned char command)
00442 {
00443 char xdata i;
00444 char xdata swConversion;
00445 if(command==ON)
00446 {
00447
00448
00449 SFRPAGE = CONFIG_PAGE;
00450 P3MDOUT |= 0x04;
00451 REG_EN = ON;
00452
00453
00454
00455 P1MDOUT |= 0xE0;
00456
00457
00458 ASUM_PWDN = 1;
00459 delay_ms(1000);
00460 ASUM_SYNC = 1;
00461 delay_us(100);
00462 ASUM_TESTN = 1;
00463 ASUM_SYNC = 0;
00464
00465
00466
00467 pca_operation(Q_PUMP_INIT);
00468
00469 pca_operation(Q_PUMP_ON);
00470
00471
00472
00473 #ifdef _LTC1665_
00474
00475
00476
00477
00478 SFRPAGE = CONFIG_PAGE;
00479 P2MDOUT |= 0x18;
00480 P0MDOUT |= 0xC0;
00481 P3MDOUT |= 0x63;
00482 P2MDOUT |= 0x60;
00483 P1MDOUT |= 0x01;
00484 DACRESETN = 1;
00485 LTC1665_Init();
00486 #endif
00487
00488 #ifdef _LTC2600_
00489
00490
00491 SFRPAGE = CONFIG_PAGE;
00492 P2MDOUT |= 0x18;
00493 P1MDOUT |= 0x10;
00494 LTC2600_Init();
00495 #endif
00496
00497 #ifdef _ExtEEPROM_
00498
00499
00500 SFRPAGE = CONFIG_PAGE;
00501 P2MDOUT |= 0x18;
00502 P3MDOUT |= 0x80;
00503 P2MDOUT &= ~0x01;
00504 ExtEEPROM_Init();
00505 #endif
00506
00507 #ifdef _LTC1669_
00508
00509
00510 LTC1669_Init();
00511 #endif
00512
00513 #ifdef _LTC2497_
00514 LTC2497_Init();
00515 #endif
00516
00517 #ifdef _LTC2495_
00518 LTC2495_Init();
00519 #endif
00520
00521 #ifdef _ADT7486A_
00522
00523
00524 SFRPAGE = CONFIG_PAGE;
00525 P1MDOUT |= 0x08;
00526 #endif
00527
00528 #ifdef _PCA9539_
00529
00530
00531 SFRPAGE = CONFIG_PAGE;
00532 P1MDOUT |= 0x04;
00533 PCA9539_Init();
00534 delay_us(10);
00535 PCA9539_WriteByte(BIAS_OUTPUT_ENABLE);
00536 delay_us(10);
00537 swConversion = user_data.swBias;
00538 PCA9539_Conversion(&swConversion);
00539 PCA9539_WriteByte(BIAS_WRITE, ~swConversion);
00540 delay_us(10);
00541 PCA9539_WriteByte(BACKPLANE_INPUT_ENABLE);
00542 delay_us(10);
00543 #endif
00544
00545
00546 LTC1669_Flag = ON;
00547
00548
00549
00550
00551 for(i=0;i<64;i++) ltc1665mirror[i] = 0xFF;
00552
00553
00554
00555 LTC1665_Flag = ON;
00556
00557
00558
00559
00560
00561 for(i=0;i<8;i++) ltc2600mirror[i] = 0xFFFF;
00562
00563
00564
00565 LTC2600_Flag = ON;
00566 }
00567 else if(command==OFF) {
00568 pca_operation(Q_PUMP_OFF);
00569
00570
00571 SFRPAGE = CONFIG_PAGE;
00572
00573
00574
00575 P3MDOUT = 0x80;
00576 P3 &= 0x80;
00577
00578
00579
00580
00581 REG_EN = OFF;
00582
00583
00584
00585 P2MDOUT &= 0x1F;
00586 P2 &= 0x0F;
00587
00588
00589
00590 P1MDOUT &= ~0xF9;
00591 PCARESETN = 1;
00592 P1 |= 0x06;
00593
00594
00595
00596 P0MDOUT &= 0xE0;
00597 P0 &= ~0xC0;
00598 }
00599 }
00600
00601
00602
00603
00604
00605
00606 void user_init(unsigned char init)
00607 {
00608 char xdata i;
00609 float xdata temperature;
00610
00611
00612
00613 for (i=0;i<4;i++) {
00614 if (svn_rev_code[6+i] < 48) {
00615 svn_rev_code[6+i] = '0';
00616 }
00617 }
00618 sys_info.svn_revision = (svn_rev_code[6]-'0')*1000+
00619 (svn_rev_code[7]-'0')*100+
00620 (svn_rev_code[8]-'0')*10+
00621 (svn_rev_code[9]-'0');
00622
00623
00624
00625 if(init) {
00626 user_data.control = 0x00;
00627 user_data.status = 0x80;
00628 user_data.swBias = 0x00;
00629 user_data.rQpump = 0x00;
00630 for(i=0;i<8;i++) {
00631 user_data.rAsum[i] = 0x80;
00632 user_data.Temp[i] = 0.0;
00633 }
00634 for(i=0;i<64;i++) {
00635 user_data.rBias[i] = 0xFF;
00636 ltc1665mirror[i] = 0xFF;
00637 }
00638 }
00639 sys_info.group_addr = 100;
00640
00641
00642
00643
00644 bChange = 0;
00645
00646
00647
00648 SFRPAGE = CONFIG_PAGE;
00649 P0MDOUT |= 0x20;
00650
00651
00652
00653 adc_internal_init();
00654
00655
00656
00657 #ifdef _ExtEEPROM_
00658 SFRPAGE = CONFIG_PAGE;
00659 P2MDOUT |= 0x18;
00660 P2MDOUT &= ~0x01;
00661 P3MDOUT |= 0x80;
00662 ExtEEPROM_Init();
00663 #endif
00664
00665
00666
00667
00668
00669 SFRPAGE = CONFIG_PAGE;
00670 P1MDOUT |= 0x5;
00671 DACRESETN = 1;
00672 PCARESETN = 1;
00673
00674
00675
00676 #ifdef _PCA9539_
00677 SFRPAGE = CONFIG_PAGE;
00678
00679 PCA9539_Init();
00680 delay_us(10);
00681
00682 PCA9539_WriteByte(BIAS_OUTPUT_ENABLE);
00683 delay_us(10);
00684
00685 PCA9539_WriteByte(BIAS_ENABLE);
00686 delay_us(10);
00687
00688 PCA9539_WriteByte(BACKPLANE_INPUT_ENABLE);
00689 delay_us(10);
00690
00691
00692
00693 #endif
00694
00695
00696
00697 #ifdef _ExtEEPROM_
00698
00699
00700
00701 ExtEEPROM_Read(SERIALN_ADD,(unsigned char xdata *)&eepage.SerialN, SERIALN_LENGTH);
00702 user_data.SerialN = eepage.SerialN;
00703 sys_info.node_addr = 500 + (eepage.SerialN - 76300000);
00704
00705
00706 ExtEEPROM_Read(PageAddr[0], (unsigned char xdata *)&eepage, PAGE_SIZE);
00707 DISABLE_INTERRUPTS;
00708 for(i=0;i<8;i++) {
00709 user_data.rAsum[i] = eepage.rasum[i];
00710 ltc2600mirror[i] = eepage.rasum[i];
00711 }
00712 for(i=0;i<64;i++) {
00713 user_data.rBias[i] = eepage.rbias[i];
00714 ltc1665mirror[i] = eepage.rbias[i];
00715 }
00716 user_data.rQpump = (unsigned int) (eepage.rqpump & 0x3FF);
00717 user_data.swBias = eepage.SWbias;
00718 ENABLE_INTERRUPTS;
00719
00720
00721 updateAdc2Table();
00722 #endif
00723
00724
00725
00726 #ifdef _ADT7486A_
00727 SFRPAGE = CONFIG_PAGE;
00728 P1MDOUT |= 0x0A;
00729
00730 SFRPAGE = CPT1_PAGE;
00731 CPT1CN |= 0x80;
00732 CPT1MD = 0x03;
00733
00734 SFRPAGE = CPT0_PAGE;
00735 CPT0CN |= 0x80;
00736 CPT0MD = 0x03;
00737
00738
00739 ADT7486A_Init(SST_LINE1);
00740 ADT7486A_Init(SST_LINE2);
00741
00742 for (channel=0;channel < NCHANNEL_ADT7486A; channel++){
00743 ADT7486A_Cmd(ADT7486A_addrArray[channel]
00744 , SetExt1Offset
00745 , ((int)eepage.ext1offset[channel]>>8)
00746 , (int)eepage.ext1offset[channel]
00747 , SST_LINE1
00748 , &temperature);
00749 delay_us(100);
00750
00751 }
00752 for (channel=0;channel < NCHANNEL_ADT7486A; channel++){
00753 ADT7486A_Cmd(ADT7486A_addrArray[channel]
00754 , SetExt2Offset
00755 , ((int)eepage.ext2offset[channel]>>8)
00756 , (int)eepage.ext2offset[channel]
00757 , SST_LINE1
00758 , &temperature);
00759 delay_us(100);
00760 }
00761
00762
00763 #endif
00764
00765
00766
00767 switchonoff(OFF);
00768
00769
00770
00771 rESR = 0x0000;
00772 rEER = 0x00;
00773 rCTL = 0;
00774 rCSR = 0x00;
00775 user_data.error = rESR;
00776 user_data.eepage = rEER;
00777 user_data.status = rCSR;
00778 user_data.control = 0x80;
00779 user_data.watchdog = 0;
00780 for(i=0;i<8;i++){
00781 user_data.VBMon[i] = 0;
00782 user_data.IBMon[i] = 0;
00783 user_data.rVBMon[i] = 0;
00784 user_data.rIBMon[i] = 0;
00785 user_data.Temp[i] = -128.0;
00786 user_data.eepValue = 0.0;
00787 user_data.eeCtrSet = 0;
00788 }
00789
00790
00791 P2MDOUT |= 0x80; P2 |= 0x80;
00792 }
00793
00794
00795
00796
00797
00798
00799
00800
00801 #pragma NOAREGS
00802
00803 void user_write(unsigned char index) reentrant
00804 {
00805
00806
00807
00808 rCSR = user_data.status;
00809 if (index == IDXCTL) {
00810 rCTL = user_data.control;
00811 if (Ccal) calState = 10;
00812 }
00813
00814
00815
00816 if (index == IDXBSWITCH) {
00817 #ifdef _PCA9539_
00818 if (!SsS) PCA_Flag = 1;
00819 #endif
00820 }
00821
00822
00823
00824 if (index == IDXEEP_CTL) EEP_CTR_Flag = 1;
00825
00826
00827 if ((index >= FIRST_ASUM) && (index < LAST_ASUM)) {
00828 #ifdef _LTC2600_
00829
00830 if (!SsS) LTC2600_Flag = 1;
00831 #endif
00832 }
00833
00834
00835 if ((index >= FIRST_BIAS) && (index < LAST_BIAS)) {
00836 #ifdef _LTC1665_
00837 if (!SsS) LTC1665_Flag = 1;
00838 #endif
00839 }
00840
00841
00842 #ifdef _LTC1669_ //SqPump &&
00843 if((index == IDXQVOLT) && !SsS) LTC1669_Flag = 1;
00844 #endif
00845
00846
00847
00848 if (index == IDXASUM_CTL) {
00849
00850
00851
00852
00853 ASUM_SYNC = user_data.asumCtl & 0x1;
00854 ASUM_TESTN = (user_data.asumCtl & 0x2) >> 1;
00855 ASUM_PWDN = (user_data.asumCtl & 0x4) >> 2;
00856 }
00857 }
00858
00859
00860 unsigned char user_read(unsigned char index)
00861 {
00862 if (index == 0) {
00863 }
00864 return 0;
00865 }
00866
00867
00868 unsigned char user_func(unsigned char *data_in, unsigned char *data_out)
00869 {
00870
00871 data_out[0] = data_in[0];
00872 data_out[1] = data_in[1];
00873 return 2;
00874 }
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906 void user_loop(void) {
00907 static unsigned char xdata eeprom_flag = CLEAR;
00908 static char xdata adcChannel = 0;
00909 float xdata volt, temperature, adc_value, ftemp;
00910 float* xdata pfData;
00911 float* xdata eep_address;
00912 unsigned long xdata mask;
00913 signed long xdata result;
00914 unsigned int xdata eeptemp_addr, *rpfData, rvolt, i;
00915 unsigned char xdata * eeptemp_source;
00916 unsigned char xdata swConversion, eep_request;
00917 char xdata ltc1665_index, ltc1665_chipChan, ltc1665_chipAdd;
00918 char xdata ltc2600_index;
00919 char xdata str[32];
00920
00921 timing=1;
00922
00923
00924
00925
00926 user_data.geoadd = NodeAdd_get();
00927
00928
00929
00930
00931
00932 #ifdef _LTC2497_
00933 LTC2497_StartConversion(ADDR_LTC2497, adcChannel);
00934
00935 if(!LTC2497_ReadConversion(ADDR_LTC2497, adcChannel, &result)) {
00936 result = CONVER_FAC1;
00937 }
00938 adc_value = ((float)((result) + CONVER_FAC1) * (float)(EXT_VREF / CONVER_FAC2));
00939 adc_value = (adc_value * adc2mscb_table[adcChannel].Coef + adc2mscb_table[adcChannel].Offst);
00940
00941 DISABLE_INTERRUPTS;
00942 if(adc2mscb_table[adcChannel].current) {
00943 user_data.IBMon[adc2mscb_table[adcChannel].mscbIdx] = adc_value;
00944 user_data.rIBMon[adc2mscb_table[adcChannel].mscbIdx] = result;
00945 } else {
00946 user_data.VBMon[adc2mscb_table[adcChannel].mscbIdx] = adc_value;
00947 user_data.rVBMon[adc2mscb_table[adcChannel].mscbIdx] = result;
00948 }
00949 ENABLE_INTERRUPTS;
00950
00951 adcChannel++;
00952 adcChannel %= N_RB_CHANNEL;
00953
00954 #endif
00955
00956
00957
00958
00959 #ifdef _LTC2495_
00960
00961 LTC2495_StartConversion(ADDR_LTC2495, adcChannel, adc2mscb_table[adcChannel].gain);
00962
00963 if(!LTC2495_ReadConversion(ADDR_LTC2495, adcChannel, &result, adc2mscb_table[adcChannel].gain)) {
00964 result = -CONVER_FAC1;
00965 }
00966
00967 adc_value = ((float)((result - adc2mscb_table[adcChannel].Offst)) * (float)(EXT_VREF / CONVER_FAC2));
00968 adc_value = (adc_value * adc2mscb_table[adcChannel].Coef) ;
00969
00970 adc_value /= pow(2, (adc2mscb_table[adcChannel].gain + adc2mscb_table[adcChannel].current));
00971 DISABLE_INTERRUPTS;
00972 if(adc2mscb_table[adcChannel].current) {
00973 user_data.IBMon[adc2mscb_table[adcChannel].mscbIdx] = adc_value;
00974 user_data.rIBMon[adc2mscb_table[adcChannel].mscbIdx] = result;
00975 } else {
00976 user_data.VBMon[adc2mscb_table[adcChannel].mscbIdx] = adc_value;
00977 user_data.rVBMon[adc2mscb_table[adcChannel].mscbIdx] = result;
00978 }
00979 ENABLE_INTERRUPTS;
00980
00981 adcChannel++;
00982 adcChannel %= N_RB_CHANNEL;
00983
00984 #endif
00985
00986
00987
00988 #ifdef _PCA9539_
00989 if(PCA_Flag) {
00990 swConversion = user_data.swBias;
00991 PCA9539_Conversion(&swConversion);
00992 PCA9539_WriteByte(BIAS_WRITE, ~swConversion);
00993 PCA_Flag = CLEAR;
00994 }
00995 #endif
00996
00997
00998
00999 #ifdef _LTC1669_
01000 if(LTC1669_Flag) {
01001 LTC1669_SetDAC(ADDR_LTC1669, LTC1669_INT_BG_REF, user_data.rQpump);
01002 LTC1669_Flag = CLEAR;
01003 }
01004 #endif
01005
01006
01007
01008 if (CPup) {
01009 rCSR = user_data.status;
01010 rESR = 0x0000;
01011
01012 SsS = OFF;
01013 DISABLE_INTERRUPTS;
01014 user_data.status = rCSR;
01015 user_data.error = rESR;
01016 ENABLE_INTERRUPTS;
01017
01018 switchonoff(ON);
01019 delay_ms(100);
01020
01021 bCPupdoitNOW = ON;
01022
01023
01024 CPup = CLEAR;
01025 }
01026
01027 #ifdef _ADT7486A_
01028
01029
01030
01031 if ( bCPupdoitNOW || ((uptime() - sstTime) > SST_TIME)) {
01032
01033 for (channel=0;channel < NCHANNEL_ADT7486A; channel++) {
01034 if(!ADT7486A_Cmd(ADT7486A_addrArray[channel], GetIntTemp, SST_LINE1, &temperature)) {
01035 RdssT = CLEAR;
01036 if (temperature > eepage.uuCTlimit) IntssTT = ON;
01037 PublishVariable(&(user_data.ssTemp[channel]), temperature, IntssTT);
01038 } else publishErr(RdssT);
01039 }
01040 sstTime = uptime();
01041 }
01042
01043 yield();
01044
01045
01046
01047
01048 if (bCPupdoitNOW || ((uptime() - sstExtTime) > SST_TIME)) {
01049
01050 for (channel=0;channel < NCHANNEL_ADT7486A; channel++) {
01051 if(!ADT7486A_Cmd(ADT7486A_addrArray[channel], GetExt1Temp, SST_LINE1, &temperature)) {
01052 RdssT = CLEAR;
01053 if (temperature > eepage.uSSTlimit) ExtssTT = ON;
01054 PublishVariable(&(user_data.Temp[(channel*2)]), temperature, ExtssTT);
01055 } else publishErr(RdssT);
01056 }
01057
01058 for (channel=0;channel < NCHANNEL_ADT7486A; channel++) {
01059 if(!ADT7486A_Cmd(ADT7486A_addrArray[channel], GetExt2Temp, SST_LINE1, &temperature)) {
01060 RdssT = CLEAR;
01061 if (temperature > eepage.uSSTlimit) ExtssTT = ON;
01062 PublishVariable(&(user_data.Temp[(channel*2)+1]), temperature, ExtssTT);
01063 } else publishErr(RdssT);
01064 }
01065
01066 yield();
01067
01068
01069
01070 rCSR = user_data.status;
01071 if (SPup) {
01072 pcbssTT = OFF;
01073 if(!ADT7486A_Cmd(ADT7486A_ADDR4, GetExt1Temp, SST_LINE2, &temperature)) {
01074 RdssT = CLEAR;
01075 if (temperature > eepage.uuCTlimit) pcbssTT = ON;
01076
01077 PublishVariable(&(user_data.afterTemp), temperature, pcbssTT);
01078 } else publishErr(RdssT);
01079
01080 if(!ADT7486A_Cmd(ADT7486A_ADDR4, GetExt2Temp, SST_LINE2, &temperature)) {
01081 RdssT = CLEAR;
01082 if (temperature > eepage.uuCTlimit) pcbssTT = ON;
01083
01084 PublishVariable(&(user_data.adcTemp), temperature, pcbssTT);
01085 } else publishErr(RdssT);
01086
01087 if(!ADT7486A_Cmd(ADT7486A_ADDR4, GetIntTemp, SST_LINE2, &temperature)) {
01088 RdssT = CLEAR;
01089 if (temperature > eepage.uuCTlimit) pcbssTT = ON;
01090
01091 PublishVariable(&(user_data.regTemp), temperature, pcbssTT);
01092 } else publishErr(RdssT);
01093 }
01094
01095
01096
01097
01098
01099
01100
01101
01102 sstExtTime = uptime();
01103 }
01104 #endif
01105
01106
01107
01108
01109 if ( bCPupdoitNOW || ((uptime() - currentTime) > 1)) {
01110
01111
01112
01113 volt = read_voltage(TCHANNEL, &rvolt, 0, 0, IntGAIN1 );
01114
01115 temperature = 1000 * (volt - 0.776) / 2.86;
01116
01117 temperature = ((int) (temperature * 10 + 0.5)) / 10.0;
01118 if ((temperature < eepage.luCTlimit) || (temperature > eepage.uuCTlimit)) uCT = ON;
01119 PublishVariable(&(user_data.uCTemp), temperature, uCT);
01120
01121
01122
01123
01124 pfData = &(user_data.VBias);
01125 rpfData = &(user_data.rVBias);
01126
01127 for (channel=0 ; channel<INTERNAL_N_CHN ; channel++) {
01128 volt = read_voltage(channel, &rvolt, iadc_table[channel].coeff
01129 , iadc_table[channel].offset
01130 , iadc_table[channel].gain );
01131 DISABLE_INTERRUPTS;
01132 pfData[channel] = volt;
01133 rpfData[channel] = rvolt;
01134 ENABLE_INTERRUPTS;
01135 mask = (1<<channel);
01136
01137
01138 if (channel == 0)
01139 if ((volt < eepage.lVIlimit[channel])) SqPump = OFF;
01140 else SqPump = ON;
01141
01142
01143 if ((channel > 1)) {
01144 if ((volt < eepage.lVIlimit[channel]) || (volt > eepage.uVIlimit[channel])) {
01145 rESR |= mask;
01146 sprintf (str, "Last Trip: %6.3f [%6.3f /", volt, eepage.lVIlimit[channel]);
01147
01148 }
01149 }
01150 }
01151
01152
01153
01154
01155 currentTime = uptime();
01156 }
01157
01158
01159
01160 if (rESR & (VOLTAGE_MASK | BTEMPERATURE_MASK | CURRENT_MASK)) {
01161 SPup = SqPump = OFF;
01162 switchonoff(OFF);
01163 SsS = ON;
01164 } else if (bCPupdoitNOW) {
01165 bCPupdoitNOW = OFF;
01166 SsS = SmSd = OFF;
01167 LTC2600_Flag = LTC1665_Flag = bDacdoitNOW = ON;
01168 SPup = ON;
01169 }
01170
01171
01172 publishAll();
01173
01174
01175
01176 #ifdef _LTC2600_
01177 rCSR = user_data.status;
01178 if(SPup && LTC2600_Flag) {
01179 for(ltc2600_index=0; ltc2600_index < 8; ltc2600_index++) {
01180 if(bDacdoitNOW || (ltc2600mirror[ltc2600_index] != user_data.rAsum[ltc2600_index])) {
01181 LTC2600_Cmd(WriteTo_Update, LTC2600_LOAD[ltc2600_index], user_data.rAsum[ltc2600_index]);
01182 ltc2600mirror[ltc2600_index] = user_data.rBias[ltc2600_index];
01183 }
01184 }
01185 LTC2600_Flag = CLEAR;
01186 }
01187 #endif
01188
01189
01190
01191 #ifdef _LTC1665_
01192
01193 rCSR = user_data.status;
01194 if(SPup && LTC1665_Flag) {
01195 for(ltc1665_index=0; ltc1665_index<64; ltc1665_index++) {
01196 if(bDacdoitNOW || (ltc1665mirror[ltc1665_index] != user_data.rBias[ltc1665_index])) {
01197 ltc1665_chipChan = (ltc1665_index / 8) + 1;
01198 ltc1665_chipAdd = (ltc1665_index % 8) + 1;
01199 LTC1665_Cmd(ltc1665_chipAdd, user_data.rBias[ltc1665_index] , ltc1665_chipChan);
01200 ltc1665mirror[ltc1665_index] = user_data.rBias[ltc1665_index];
01201 }
01202 }
01203
01204 LTC1665_Flag = CLEAR;
01205 }
01206 #endif
01207
01208
01209
01210 bDacdoitNOW = OFF;
01211
01212
01213
01214 if (CmSd) {
01215 rCSR = user_data.status;
01216 SmSd = ON;
01217 pca_operation(Q_PUMP_OFF);
01218 switchonoff(OFF);
01219 SPup = SqPump = OFF;
01220 CmSd = CLEAR;
01221 publishCtlCsr();
01222 }
01223
01224
01225
01226 if (CAsum) {
01227 if (ASUM_TESTN) ASUM_TESTN = OFF;
01228 else ASUM_TESTN = ON;
01229 SAsum = ASUM_TESTN;
01230 CAsum = CLEAR;
01231 publishCtlCsr();
01232 }
01233
01234
01235
01236 if (EEP_CTR_Flag) {
01237
01238 if (user_data.eeCtrSet & EEP_CTRL_KEY) {
01239
01240 if( (int)(user_data.eeCtrSet & 0x000000ff) >= EEP_RW_IDX) {
01241
01242 eep_address = (float*)&eepage + (user_data.eeCtrSet & 0x000000ff);
01243
01244 if (user_data.eeCtrSet & EEP_CTRL_WRITE){
01245 *eep_address = user_data.eepValue;
01246
01247 } else if (user_data.eeCtrSet & EEP_CTRL_READ) {
01248 DISABLE_INTERRUPTS;
01249 user_data.eepValue = *eep_address;
01250 ENABLE_INTERRUPTS;
01251 } else {
01252
01253 DISABLE_INTERRUPTS;
01254 user_data.eeCtrSet = EEP_CTRL_INVAL_REQ;
01255 ENABLE_INTERRUPTS;
01256 }
01257 } else {
01258 DISABLE_INTERRUPTS;
01259 user_data.eeCtrSet = EEP_CTRL_OFF_RANGE;
01260 ENABLE_INTERRUPTS;
01261 }
01262 } else {
01263
01264 DISABLE_INTERRUPTS;
01265 user_data.eeCtrSet = EEP_CTRL_INVAL_KEY;
01266 ENABLE_INTERRUPTS;
01267 }
01268 EEP_CTR_Flag = CLEAR;
01269 }
01270
01271
01272
01273 #ifdef _ExtEEPROM_
01274 if (CeeS) {
01275
01276 if (!eeprom_flag) {
01277 rCSR = user_data.status;
01278
01279
01280 for(i=0;i<8;i++) eepage.rasum[i] = user_data.rAsum[i];
01281 for(i=0;i<64;i++) eepage.rbias[i] = user_data.rBias[i];
01282 eepage.rqpump = ((unsigned int) user_data.rQpump & 0x3FF);
01283 eepage.SWbias = user_data.swBias;
01284
01285
01286 eeptemp_addr = PageAddr[(unsigned char)(user_data.eepage & 0x07)];
01287
01288 eeptemp_source = (unsigned char xdata *)&eepage;
01289 }
01290
01291
01292 if (CeeClr) eep_request = WRITE_EEPROM;
01293 else eep_request = WRITE_EEPROM;
01294
01295 status = ExtEEPROM_Write_Clear (eeptemp_addr
01296 , &eeptemp_source
01297 , PAGE_SIZE
01298 , eep_request
01299 , &eeprom_flag);
01300
01301 if (status == DONE) {
01302 SeeS = DONE;
01303 eeprom_flag = CLEAR;
01304 CeeS = CLEAR;
01305
01306 user_data.eepage |= ((user_data.eepage & 0x07) << 5);
01307 } else SeeS = FAILED;
01308
01309 publishCtlCsr();
01310 }
01311
01312
01313
01314 if (CeeR) {
01315 rCSR = user_data.status;
01316
01317 status = ExtEEPROM_Read (PageAddr[(unsigned char)(user_data.eepage & 0x07)]
01318 , (unsigned char xdata *) &eepage, PAGE_SIZE);
01319 if (status == DONE) {
01320 SeeR = DONE;
01321
01322
01323 DISABLE_INTERRUPTS;
01324 for(i=0;i<8;i++) user_data.rAsum[i] = ltc2600mirror[i] = eepage.rasum[i];
01325 for(i=0;i<64;i++) user_data.rBias[i] = ltc1665mirror[i] = eepage.rbias[i];
01326 user_data.rQpump = (unsigned int) (eepage.rqpump & 0x3FF);
01327 user_data.swBias = eepage.SWbias;
01328 ENABLE_INTERRUPTS;
01329
01330 LTC2600_Flag = LTC1665_Flag = bDacdoitNOW = ON;
01331
01332
01333 updateAdc2Table();
01334 } else SeeR = FAILED;
01335
01336 CeeR = CLEAR;
01337 publishCtlCsr();
01338 }
01339 #endif
01340
01341
01342
01343 if (Ccal) {
01344 switch (calState) {
01345 case 10:
01346
01347 rCSR = user_data.status;
01348 if (SPup && SqPump && (user_data.swBias == 0xff)) {
01349 Scal = ON;
01350
01351 DISABLE_INTERRUPTS;
01352 user_data.status = rCSR;
01353 ENABLE_INTERRUPTS;
01354 calState = 15;
01355 } else {
01356 SeeS = CLEAR;
01357 Ccal = CLEAR;
01358 Scal = OFF;
01359 calState = 0;
01360
01361 publishCtlCsr();
01362 }
01363 break;
01364 case 15:
01365
01366 calQpumpSave = user_data.rQpump;
01367 calSwSave = user_data.swBias;
01368 #ifdef _LTC1669_
01369 LTC1669_SetDAC(ADDR_LTC1669, LTC1669_INT_BG_REF, eepage.calQpump);
01370 #endif
01371
01372 for (k=0;k<8;k++) eepage.iBiasOffset[k] = 0.0;
01373 calState = 30;
01374
01375 calTime = uptime();
01376 break;
01377 case 30:
01378
01379 if ((uptime() - calTime) > 10) {
01380 calCount = 0;
01381 calState = 40;
01382 }
01383 break;
01384 case 40:
01385
01386 if (calCount < calNumber) {
01387 if (adcChannel == 0) {
01388 calCount++;
01389 for (k=0;k<8;k++) eepage.iBiasOffset[k] += (float) user_data.rIBMon[k];
01390 }
01391 } else calState = 50;
01392 break;
01393 case 50:
01394
01395 for (k=0;k<8;k++) {
01396 ftemp = eepage.iBiasOffset[k] / calNumber;
01397 eepage.iBiasOffset[k] = ftemp;
01398 }
01399
01400 updateAdc2Table();
01401 calState = 60;
01402 break;
01403 case 60:
01404
01405 #ifdef _LTC1669_
01406 LTC1669_SetDAC(ADDR_LTC1669, LTC1669_INT_BG_REF, calQpumpSave);
01407 #endif
01408
01409 Ccal = CLEAR;
01410 calState = 0;
01411 Scal = OFF;
01412
01413 CeeS = ON;
01414
01415 publishCtlCsr();
01416 break;
01417 default:
01418 break;
01419 }
01420 DISABLE_INTERRUPTS;
01421 SFRPAGE = SMB0_PAGE;
01422 user_data.debugsmb = SMB0STA;
01423 ENABLE_INTERRUPTS;
01424 }
01425
01426
01427
01428 DISABLE_INTERRUPTS;
01429 user_data.debugsmb = smbdebug;
01430 ENABLE_INTERRUPTS;
01431 timing=0;
01432 delay_ms(10);
01433
01434 }