00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <math.h>
00023 #include <string.h>
00024 #include "mscbemb.h"
00025 #include "LPB.h"
00026
00027 #include "Devices/adc_internal.h"
00028
00029 #ifdef _HUMSEN_
00030 #include "Devices/Humidity_sensor.h"
00031 #endif
00032
00033 #ifdef _ADT7486A_
00034 #include "Devices/ADT7486A_tsensor.h"
00035 #endif
00036
00037 #ifdef _LTC2620_
00038 #include "Devices/LTC2620.h"
00039 #endif
00040
00041 #ifdef _ExtEEPROM_
00042 #include "Devices/ExtEEPROM.h"
00043 #endif
00044
00045 #include "Protocols/LPB_SPI_handler.h"
00046
00047
00048
00049
00050 char code node_name[] = "LPB";
00051 char idata svn_rev_code[] = "$Rev: 1189 $";
00052
00053
00054
00055 unsigned char idata _n_sub_addr = 1;
00056
00057
00058
00059 unsigned char bdata bChange;
00060
00061
00062 sbit bCPupdoitNOW = bChange ^ 0;
00063 sbit bDacdoitNOW = bChange ^ 1;
00064
00065
00066 sbit LTC2620_Flag = bChange ^ 3;
00067 sbit EEP_CTR_Flag = bChange ^ 4;
00068 sbit DELAY_Flag = bChange ^ 5;
00069
00070 sbit SPI_SCK = MSCB_SPI_SCK;
00071 sbit SPI_MOSI = MSCB_SPI_MOSI;
00072 sbit SPI_MISO = MSCB_SPI_MISO;
00073
00074 sbit LPB_CSn = P0 ^ 4;
00075 sbit CPLDMode = P2 ^ 6;
00076
00077 unsigned char channel;
00078 unsigned long xdata humidTime=0, currentTime=0, currentTime2=0;
00079 unsigned char lbyte, hbyte;
00080
00081
00082 unsigned char xdata status, humicount;
00083 float xdata humidity, htemperature;
00084 unsigned int xdata rSHTtemp1, rSHThumi1;
00085 unsigned char xdata FCSorig1, FCSdevi1;
00086
00087
00088 float* xdata eep_address;
00089 unsigned char tcounter;
00090 unsigned char xdata eeprom_flag=CLEAR;
00091 unsigned char xdata eeprom_wstatus, eeprom_rstatus;
00092 unsigned int xdata eeptemp_addr;
00093 unsigned char xdata * eeptemp_source;
00094 unsigned char xdata eep_request;
00095
00096
00097
00098 MSCB_INFO_VAR code vars[] = {
00099 4, UNIT_BYTE, 0, 0, 0, "SerialN", &user_data.SerialN,
00100 2, UNIT_BYTE, 0, 0, 0, "Error", &user_data.error,
00101 1, UNIT_BYTE, 0, 0, 0, "Control", &user_data.control,
00102 1, UNIT_BYTE, 0, 0, 0, "Status", &user_data.status,
00103 1, UNIT_BYTE, 0, 0, 0, "eepage", &user_data.eepage,
00104 1, UNIT_BYTE, 0, 0, 0, "Spare", &user_data.spare,
00105 2, UNIT_BYTE, 0, 0, 0, "Delay", &user_data.delay,
00106 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "D2Ashft" , &user_data.iadc[0],
00107 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "pDVsc", &user_data.iadc[1],
00108 4, UNIT_AMPERE, 0, 0, MSCBF_FLOAT, "pDIsc", &user_data.iadc[2],
00109 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "pDV6", &user_data.iadc[3],
00110 4, UNIT_AMPERE, 0, 0, MSCBF_FLOAT, "pDI6", &user_data.iadc[4],
00111 4, UNIT_AMPERE, 0, 0, MSCBF_FLOAT, "pDI5", &user_data.iadc[5],
00112 4, UNIT_AMPERE, 0, 0, MSCBF_FLOAT, "pDI33", &user_data.iadc[6],
00113 4, UNIT_AMPERE, 0, 0, MSCBF_FLOAT, "pDI18", &user_data.iadc[7],
00114 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "uCTemp", &user_data.uCTemp,
00115
00116 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "IntTemp", &user_data.IntTemp,
00117 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp58", &user_data.Temp58,
00118 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "Temp33", &user_data.Temp33,
00119
00120 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "SHTtemp", &user_data.SHTtemp,
00121 4, UNIT_PERCENT, 0, 0, MSCBF_FLOAT, "RHumid", &user_data.SHThumid,
00122
00123 2, UNIT_BYTE, 0, 0, 0, "rdac0", &user_data.rdac[0],
00124 2, UNIT_BYTE, 0, 0, 0, "rdac4", &user_data.rdac[1],
00125 2, UNIT_BYTE, 0, 0, 0, "rdac8", &user_data.rdac[2],
00126 2, UNIT_BYTE, 0, 0, 0, "rdac12", &user_data.rdac[3],
00127 2, UNIT_BYTE, 0, 0, 0, "rdac16", &user_data.rdac[4],
00128 2, UNIT_BYTE, 0, 0, 0, "rdac20", &user_data.rdac[5],
00129 2, UNIT_BYTE, 0, 0, 0, "rdac24", &user_data.rdac[6],
00130 2, UNIT_BYTE, 0, 0, 0, "rdac28", &user_data.rdac[7],
00131 2, UNIT_BYTE, 0, 0, 0, "rdac32", &user_data.rdac[8],
00132 2, UNIT_BYTE, 0, 0, 0, "rdac36", &user_data.rdac[9],
00133 2, UNIT_BYTE, 0, 0, 0, "rdac40", &user_data.rdac[10],
00134 2, UNIT_BYTE, 0, 0, 0, "rdac44", &user_data.rdac[11],
00135 2, UNIT_BYTE, 0, 0, 0, "rdac48", &user_data.rdac[12],
00136 2, UNIT_BYTE, 0, 0, 0, "rdac52", &user_data.rdac[13],
00137 2, UNIT_BYTE, 0, 0, 0, "rdac56", &user_data.rdac[14],
00138 2, UNIT_BYTE, 0, 0, 0, "rdacsp", &user_data.rdac[15],
00139
00140 2, UNIT_BYTE, 0, 0, 0, "rD2Ashft", &user_data.riadc[0],
00141 2, UNIT_BYTE, 0, 0, 0, "rpDVsc", &user_data.riadc[1],
00142 2, UNIT_BYTE, 0, 0, 0, "rpDIsc", &user_data.riadc[2],
00143 2, UNIT_BYTE, 0, 0, 0, "rpDV6", &user_data.riadc[3],
00144 2, UNIT_BYTE, 0, 0, 0, "rpDI6", &user_data.riadc[4],
00145 2, UNIT_BYTE, 0, 0, 0, "rpDI5", &user_data.riadc[5],
00146 2, UNIT_BYTE, 0, 0, 0, "rpDI33", &user_data.riadc[6],
00147 2, UNIT_BYTE, 0, 0, 0, "rpDI18", &user_data.riadc[7],
00148 2, UNIT_BYTE, 0, 0, 0, "rSHTemp", &user_data.rSHTemp,
00149 2, UNIT_BYTE, 0, 0, 0, "rRHumid", &user_data.rSHhumid,
00150
00151 4, UNIT_BYTE, 0, 0, MSCBF_FLOAT, "eepValue", &user_data.eepValue,
00152 4, UNIT_BYTE, 0, 0, 0, "eeCtrSet", &user_data.eeCtrSet,
00153 0
00154 };
00155
00156 MSCB_INFO_VAR *variables = vars;
00157
00158 extern SYS_INFO sys_info;
00159
00160
00161
00162 void publishCtlCsr(void) {
00163 DISABLE_INTERRUPTS;
00164 user_data.control = rCTL;
00165 user_data.status = rCSR;
00166 ENABLE_INTERRUPTS;
00167 }
00168
00169
00170
00171 void publishErr(bit errbit) {
00172 DISABLE_INTERRUPTS;
00173 errbit = ON;
00174 user_data.error = rESR;
00175 ENABLE_INTERRUPTS;
00176 }
00177
00178
00179
00180 void publishAll() {
00181 user_data.control = rCTL;
00182 user_data.status = rCSR;
00183 user_data.error = rESR;
00184 ENABLE_INTERRUPTS;
00185 }
00186
00187
00188
00189 void PublishVariable(float xdata * pvarDest, float varSrce, bit errbit) {
00190 DISABLE_INTERRUPTS;
00191 *pvarDest = varSrce;
00192 if (errbit) user_data.error = rESR;
00193 ENABLE_INTERRUPTS;
00194 }
00195
00196
00197
00198 float read_voltage(unsigned char channel,unsigned int *rvalue, unsigned char gain)
00199 {
00200 unsigned int xdata i;
00201 float xdata voltage;
00202 unsigned int xdata rawbin;
00203 unsigned long xdata rawsum = 0;
00204
00205
00206 for (i=0 ; i<10 ; i++) {
00207 rawbin = adc_read(channel, gain);
00208 rawsum += rawbin;
00209 yield();
00210 }
00211
00212
00213 *rvalue = rawsum/10;
00214 voltage = (float) *rvalue;
00215 voltage = (float) voltage / 1024.0 * VREF;
00216 if ( channel != TCHANNEL)
00217 voltage = voltage * coeff[channel] + offset[channel];
00218
00219 return voltage;
00220 }
00221
00222
00223
00224 void delay_Operation(void)
00225 {
00226 LPB_CSn = 1;
00227 LPBSPI_Init();
00228
00229 LPBSPI_WriteByte(0x80 | ((user_data.delay >> 8) & 0x3));
00230 LPBSPI_WriteByte(user_data.delay & 0xFF);
00231 LPB_CSn = 0;
00232 delay_us(100);
00233 LPB_CSn = 1;
00234 LPBSPI_Init();
00235
00236 hbyte = LPBSPI_ReadByteRising();
00237 lbyte = LPBSPI_ReadByteRising();
00238 LPB_CSn = 0;
00239 delay_us(100);
00240 DISABLE_INTERRUPTS;
00241 user_data.delay = (hbyte << 8);
00242 user_data.delay |= lbyte;
00243 ENABLE_INTERRUPTS;
00244 }
00245
00246
00247
00248 void switchonoff(unsigned char command)
00249 {
00250 char xdata i;
00251
00252 if(command==ON)
00253 {
00254 SFRPAGE = CONFIG_PAGE;
00255 VCC_EN = ON;
00256 VREG_5 = VREG_3 = ON;
00257 P0MDOUT |= 0xCC;
00258
00259
00260
00261
00262 for(i=0;i<16;i++) ltc2620mirror[i] = 0x001;
00263
00264
00265
00266 LTC2620_Flag = ON;
00267
00268 } else if(command==OFF) {
00269
00270 SFRPAGE = CONFIG_PAGE;
00271 VCC_EN = OFF;
00272 VREG_5 = VREG_3 = OFF;
00273
00274
00275
00276
00277
00278 P0MDOUT &= ~0xCC;
00279
00280 }
00281 }
00282
00283
00284
00285
00286
00287 void user_init(unsigned char init)
00288 {
00289
00290 unsigned char xdata i, pca_add=0;
00291 unsigned int xdata crate_add=0, board_address=0;
00292 if(init) {
00293
00294 }
00295
00296
00297 for (i=0;i<4;i++) {
00298 if (svn_rev_code[6+i] < 48) {
00299 svn_rev_code[6+i] = '0';
00300 }
00301 }
00302 sys_info.svn_revision = (svn_rev_code[6]-'0')*1000+
00303 (svn_rev_code[7]-'0')*100+
00304 (svn_rev_code[8]-'0')*10+
00305 (svn_rev_code[9]-'0');
00306
00307
00308 sys_info.group_addr = 500;
00309
00310
00311 memset((char *) &user_data, 0x00, sizeof(user_data));
00312
00313
00314 rCTL = rCSR = 0;
00315 LTC2620_Flag = EEP_CTR_Flag = 0;
00316
00317
00318
00319
00320 SFRPAGE = CONFIG_PAGE;
00321
00322 P0MDOUT |= 0x20;
00323
00324 XBR2 &= ~0x04;
00325
00326
00327
00328
00329 SFRPAGE = CONFIG_PAGE;
00330 VREG_5 = VREG_3 = OFF;
00331 VCC_EN = OFF;
00332 P1MDOUT |= 0x08;
00333 P1MDOUT &= ~0x40;
00334 P2MDOUT |= 0xE0;
00335 switchonoff(OFF);
00336
00337
00338
00339
00340 adc_internal_init();
00341
00342
00343
00344
00345
00346
00347
00348
00349 #ifdef _ADT7486A_
00350 SFRPAGE = CONFIG_PAGE;
00351 P1MDOUT |= 0x01;
00352 SFRPAGE = CPT1_PAGE;
00353 CPT1CN |= 0x80;
00354 CPT1MD = 0x03;
00355
00356
00357 ADT7486A_Init(SST_LINE1);
00358 #endif
00359
00360
00361
00362
00363 SFRPAGE = CONFIG_PAGE;
00364 SPI_MISO = 1;
00365 P2MDOUT |= 0x18;
00366 SPI_SCK = 0;
00367 SPI_MOSI = 0;
00368
00369
00370
00371
00372 #ifdef _ExtEEPROM_
00373 SFRPAGE = CONFIG_PAGE;
00374 P2MDOUT |= 0x01;
00375 P2MDOUT |= 0x04;
00376 RAM_HLDn = 1;
00377 P1MDOUT |= 0x04;
00378
00379 ExtEEPROM_Init();
00380
00381
00382 ExtEEPROM_Read(SERIALN_ADD,(unsigned char xdata *)&eepage.SerialN, SERIALN_LENGTH);
00383 user_data.SerialN = eepage.SerialN;
00384
00385 memset((char *) &eepage, 0x00, PAGE_SIZE);
00386
00387
00388 ExtEEPROM_Read(PageAddr[0], (unsigned char xdata *)&eepage, PAGE_SIZE);
00389
00390
00391 DISABLE_INTERRUPTS;
00392 for(i=0;i<16;i++) user_data.rdac[i] = eepage.rdac[i];
00393 user_data.delay = eepage.delay;
00394 ENABLE_INTERRUPTS;
00395
00396 #endif
00397
00398
00399
00400
00401 #ifdef _HUMSEN_
00402 SFRPAGE = CONFIG_PAGE;
00403 P1MDOUT |= 0x20;
00404
00405 HumiSensor_Init(humsense);
00406
00407 user_data.SHTtemp = 0;
00408 user_data.SHThumid = 0;
00409 user_data.rSHTemp = 0;
00410 user_data.rSHhumid = 0;
00411 #endif
00412
00413
00414
00415
00416
00417
00418 SFRPAGE = CONFIG_PAGE;
00419 P3MDOUT |= 0xFF;
00420 pca_add= P3;
00421 board_address= (((~pca_add)<<1) & 0x01F8)| 0x0005;
00422 sys_info.node_addr = board_address;
00423
00424 #ifdef _ADT7486A_
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441 #endif
00442
00443
00444
00445
00446 for(i=0;i<16;i++) {
00447 user_data.rdac[i] = eepage.rdac[i];
00448 ltc2620mirror[i] = eepage.rdac[i];
00449 }
00450
00451
00452 #ifdef _LTC2620_
00453
00454
00455
00456 LTC2620_Init(1);
00457 LTC2620_Init(2);
00458 #endif
00459
00460
00461
00462
00463
00464 SFRPAGE = CONFIG_PAGE;
00465
00466
00467
00468
00469
00470 P0MDOUT |= 0x80;
00471 P0MDOUT |= 0x40;
00472 P2MDOUT &= ~0x80;
00473 P0MDOUT |= 0x10;
00474
00475 P2MDOUT |= 0x40;
00476 CPLDMode = 1;
00477 }
00478
00479
00480
00481 #pragma NOAREGS
00482
00483 void user_write(unsigned char index) reentrant
00484 {
00485
00486 if((index >= IDXDAC) && (index < IDXDAC+16))
00487 LTC2620_Flag = SET;
00488
00489
00490 if(index==IDXCTL)
00491 rCTL = user_data.control;
00492
00493
00494 if (index==IDXDELAY) {
00495 DELAY_Flag = SET;
00496 }
00497
00498
00499 if (index == IDXEEP_CTL)
00500 EEP_CTR_Flag = SET;
00501 }
00502
00503
00504 unsigned char user_read(unsigned char index)
00505 {
00506 if (index);
00507 return 0;
00508 }
00509
00510
00511 unsigned char user_func(unsigned char *data_in, unsigned char *data_out)
00512 {
00513
00514 data_out[0] = data_in[0];
00515 data_out[1] = data_in[1];
00516 return 2;
00517 }
00518
00519
00520
00521
00522 void user_loop(void) {
00523
00524 float xdata volt, temperature;
00525 unsigned int xdata rvolt, i;
00526 unsigned char xdata status, ltc2620_idx, ltc2620_chip, ltc2620_chan;
00527 float* xdata pfData;
00528 unsigned long xdata mask;
00529 unsigned int xdata *rpfData;
00530
00531
00532
00533
00534 if (SPup && DELAY_Flag) {
00535 delay_Operation();
00536 DELAY_Flag = CLEAR;
00537 }
00538
00539
00540
00541 if (Cmode) {
00542 rCSR = user_data.status;
00543 if (Smode) { CPLDMode = 1; Smode = 0; }
00544 else { CPLDMode = 0; Smode = 1; }
00545 Cmode = 0;
00546 publishCtlCsr();
00547 }
00548
00549
00550
00551 if (CPup) {
00552 rCSR = user_data.status;
00553 rESR = 0x0000;
00554
00555 SsS = OFF;
00556 DISABLE_INTERRUPTS;
00557 user_data.status = rCSR;
00558 user_data.error = rESR;
00559 ENABLE_INTERRUPTS;
00560
00561 switchonoff(ON);
00562
00563 bCPupdoitNOW = ON;
00564
00565 currentTime2 = uptime();
00566
00567
00568 CPup = CLEAR;
00569 }
00570
00571
00572
00573 if (CmSd) {
00574 rCSR = user_data.status;
00575 SmSd = ON;
00576 switchonoff(OFF);
00577 SPup = OFF;
00578 CmSd = CLEAR;
00579 publishCtlCsr();
00580 }
00581
00582
00583
00584
00585 #ifdef _LTC2620_
00586
00587 rCSR = user_data.status;
00588
00589
00590
00591 if(SPup) {
00592 for(ltc2620_idx=0; ltc2620_idx < 16; ltc2620_idx++) {
00593 if(bDacdoitNOW || (ltc2620mirror[ltc2620_idx]!= user_data.rdac[ltc2620_idx])) {
00594 ltc2620_chip = (ltc2620_idx > 7) ? 2 : 1;
00595 ltc2620_chan = (ltc2620_chip == 2) ? ltc2620_idx - 8: ltc2620_idx;
00596 LTC2620_Cmd(WriteTo_Update, ltc2620_chip, ltc2620_chan, user_data.rdac[ltc2620_idx]);
00597 ltc2620mirror[ltc2620_idx] = user_data.rdac[ltc2620_idx];
00598 }
00599 }
00600 LTC2620_Flag = bDacdoitNOW = CLEAR;
00601 }
00602 #endif
00603
00604
00605
00606
00607 if ( !bCPupdoitNOW && (uptime() - humidTime) > 2) {
00608
00609 #ifdef _ADT7486A_
00610
00611
00612 if(!ADT7486A_Cmd(ADT7486A_ADDR0, GetIntTemp, SST_LINE1, &temperature)) {
00613 RdssT = CLEAR;
00614 if ((temperature < eepage.luCTlimit) || (temperature > eepage.uuCTlimit)) pcbssTT = ON;
00615 PublishVariable(&(user_data.IntTemp), temperature, pcbssTT);
00616 } else publishErr(RdssT);
00617
00618 if(!ADT7486A_Cmd(ADT7486A_ADDR0, GetExt1Temp, SST_LINE1, &temperature)) {
00619 RdssT = CLEAR;
00620 if ((temperature < eepage.lSSTlimit) || (temperature > eepage.uSSTlimit)) pcbssTT = ON;
00621 PublishVariable(&(user_data.Temp58), temperature, pcbssTT);
00622 } else publishErr(RdssT);
00623
00624 if(!ADT7486A_Cmd(ADT7486A_ADDR0, GetExt2Temp, SST_LINE1, &temperature)) {
00625 RdssT = CLEAR;
00626 if ((temperature < eepage.lSSTlimit) || (temperature > eepage.uSSTlimit)) pcbssTT = ON;
00627 PublishVariable(&(user_data.Temp33), temperature, pcbssTT);
00628 } else publishErr(RdssT);
00629 #endif
00630
00631 #ifdef _HUMSEN_
00632
00633
00634 if (humicount) {
00635 status = HumidSensor_Cmd (&rSHThumi1
00636 ,&rSHTtemp1
00637 ,&humidity
00638 ,&htemperature
00639 ,&FCSorig1
00640 ,&FCSdevi1
00641 ,humsense);
00642 if (status == DONE) {
00643 humicount = 5;
00644 DISABLE_INTERRUPTS;
00645 user_data.rSHTemp = rSHTtemp1;
00646 user_data.rSHhumid = rSHThumi1;
00647 user_data.SHThumid = humidity;
00648 user_data.SHTtemp = htemperature;
00649 ENABLE_INTERRUPTS;
00650 }
00651 humicount--;
00652 }
00653 humidTime = uptime();
00654
00655 #endif
00656
00657 }
00658
00659
00660
00661
00662 V6Fault = (V6ddFlag == 1) ? 0 : 1;
00663
00664
00665
00666
00667
00668 if ( bCPupdoitNOW || ((uptime() - currentTime) > 1)) {
00669
00670
00671
00672 volt = read_voltage(TCHANNEL, &rvolt, IntGAIN1 );
00673
00674 temperature = 1000 * (volt - 0.776) / 2.86;
00675
00676 temperature = ((int) (temperature * 10 + 0.5)) / 10.0;
00677 if ((temperature < eepage.luCTlimit) || (temperature > eepage.uuCTlimit)) uCT = ON;
00678 PublishVariable(&(user_data.uCTemp), temperature, uCT);
00679
00680
00681
00682
00683 pfData = &(user_data.iadc);
00684 rpfData = &(user_data.riadc);
00685 for (channel=0 ; channel<INTERNAL_N_CHN ; channel++) {
00686 volt = read_voltage(channel, &rvolt, IntGAIN1);
00687 DISABLE_INTERRUPTS;
00688 pfData[channel] = volt;
00689 rpfData[channel] = rvolt;
00690 ENABLE_INTERRUPTS;
00691
00692
00693
00694
00695 if (channel) {
00696 mask = (1<<(channel-1));
00697 if ((volt < eepage.lVIlimit[channel]) || (volt > eepage.uVIlimit[channel])) rESR |= mask;
00698 else rESR &= ~mask;
00699 }
00700 }
00701
00702
00703 currentTime = uptime();
00704 }
00705
00706
00707
00708
00709
00710 if ((uptime() - currentTime2) > 1) {
00711 if (SPup && (rESR & (VOLTAGE_MASK | UCTEMPERATURE_MASK | BTEMPERATURE_MASK | MAIN_CURRENT_MASK))) {
00712 SPup = OFF;
00713 switchonoff(OFF);
00714 SsS = ON;
00715 } else if (bCPupdoitNOW) {
00716 bCPupdoitNOW = OFF;
00717 SsS = SmSd = OFF;
00718 SPup = ON;
00719 LTC2620_Flag = bDacdoitNOW = ON;
00720 DELAY_Flag = ON;
00721 }
00722 }
00723
00724
00725 publishAll();
00726
00727 #ifdef _ExtEEPROM_
00728
00729
00730
00731 if (EEP_CTR_Flag) {
00732
00733 if (user_data.eeCtrSet & EEP_CTRL_KEY) {
00734
00735 if( (int)(user_data.eeCtrSet & 0x000000ff) >= EEP_RW_IDX) {
00736
00737 eep_address = (float*)&eepage + (user_data.eeCtrSet & 0x000000ff);
00738
00739 if (user_data.eeCtrSet & EEP_CTRL_WRITE){
00740 *eep_address = user_data.eepValue;
00741
00742 } else if (user_data.eeCtrSet & EEP_CTRL_READ) {
00743 DISABLE_INTERRUPTS;
00744 user_data.eepValue = *eep_address;
00745 ENABLE_INTERRUPTS;
00746 } else {
00747
00748 DISABLE_INTERRUPTS;
00749 user_data.eeCtrSet = EEP_CTRL_INVAL_REQ;
00750 ENABLE_INTERRUPTS;
00751 }
00752 } else {
00753 DISABLE_INTERRUPTS;
00754 user_data.eeCtrSet = EEP_CTRL_OFF_RANGE;
00755 ENABLE_INTERRUPTS;
00756 }
00757 } else {
00758
00759 DISABLE_INTERRUPTS;
00760 user_data.eeCtrSet = EEP_CTRL_INVAL_KEY;
00761 ENABLE_INTERRUPTS;
00762 }
00763 EEP_CTR_Flag = CLEAR;
00764 }
00765
00766
00767
00768
00769 if (CeeS) {
00770
00771 if (!eeprom_flag) {
00772 rCSR = user_data.status;
00773
00774
00775 for(i=0;i<16;i++) eepage.rdac[i] = user_data.rdac[i];
00776 eepage.delay = user_data.delay;
00777
00778
00779 eeptemp_addr = PageAddr[(unsigned char)(user_data.eepage & 0x07)];
00780
00781 eeptemp_source = (unsigned char xdata *) &eepage;
00782 }
00783
00784
00785 if (CeeClr) eep_request = WRITE_EEPROM;
00786 else eep_request = WRITE_EEPROM;
00787
00788 status = ExtEEPROM_Write_Clear (eeptemp_addr
00789 , &eeptemp_source
00790 , PAGE_SIZE
00791 , eep_request
00792 , &eeprom_flag);
00793
00794 if (status == DONE) {
00795 SeeS = DONE;
00796 eeprom_flag = CLEAR;
00797 CeeS = CLEAR;
00798
00799 user_data.eepage |= ((user_data.eepage & 0x07) << 5);
00800 } else SeeS = FAILED;
00801
00802 publishCtlCsr();
00803 }
00804
00805
00806
00807
00808 if (CeeR) {
00809 rCSR = user_data.status;
00810
00811 eeptemp_addr = PageAddr[(unsigned char)(user_data.eepage & 0x07)];
00812 eeptemp_source = (unsigned char xdata *) &eepage;
00813 channel = ExtEEPROM_Read (eeptemp_addr, eeptemp_source, PAGE_SIZE);
00814 if (channel == DONE) {
00815 SeeR = DONE;
00816
00817
00818 DISABLE_INTERRUPTS;
00819 for(i=0;i<16;i++) user_data.rdac[i] = eepage.rdac[i];
00820 user_data.delay = eepage.delay;
00821 ENABLE_INTERRUPTS;
00822
00823 LTC2620_Flag = bDacdoitNOW = ON;
00824 DELAY_Flag = ON;
00825 } else SeeR = FAILED;
00826
00827 CeeR = CLEAR;
00828 publishCtlCsr();
00829 }
00830 #endif // EEPROM
00831
00832
00833 delay_ms(10);
00834 }