Ted Grosch / Mbed 2 deprecated Nucleo_TOF_I2C

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers OPT3101device_Functions.cpp Source File

OPT3101device_Functions.cpp

Go to the documentation of this file.
00001 /*!
00002 * \file OPT3101device_Functions.cpp
00003 * \author  Karthik Rajagopal <krthik@ti.com>
00004 * \version 0.9.1
00005 *
00006 * \section COPYRIGHT
00007 * TEXAS INSTRUMENTS TEXT FILE LICENSE
00008 * Copyright (c) 2018 Texas Instruments Incorporated
00009 * All rights reserved not granted herein.
00010 * Limited License.
00011 * Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive license under copyrights and patents it now or hereafter owns or controls to make, have made, use, import, offer to sell and sell ("Utilize") this software subject to the terms herein.  With respect to the foregoing patent license, such license is granted  solely to the extent that any such patent is necessary to Utilize the software alone.  The patent license shall not apply to any combinations which include this software, other than combinations with devices manufactured by or for TI ("TI Devices").  No hardware patent is licensed hereunder.
00012 * Redistributions must preserve existing copyright notices and reproduce this license (including the above copyright notice and the disclaimer and (if applicable) source code license limitations below) in the documentation and/or other materials provided with the distribution
00013 * Redistribution and use in binary form, without modification, are permitted provided that the following conditions are met:
00014 * * No reverse engineering, decompilation, or disassembly of this software is permitted with respect to any software provided in binary form.
00015 * * any redistribution and use are licensed by TI for use only with TI Devices.
00016 * * Nothing shall obligate TI to provide you with source code for the software licensed and provided to you in object code.
00017 * If software source code is provided to you, modification and redistribution of the source code are permitted provided that the following conditions are met:
00018 * * any redistribution and use of the source code, including any resulting derivative works, are licensed by TI for use only with TI Devices.
00019 * * any redistribution and use of any object code compiled from the source code and any resulting derivative works, are licensed by TI for use only with TI Devices.
00020 * Neither the name of Texas Instruments Incorporated nor the names of its suppliers may be used to endorse or promote products derived from this software without specific prior written permission.
00021 * DISCLAIMER.
00022 * THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00023 *
00024 * \section DESCRIPTION
00025 * The file contains methods definitions for classes OPT3101::device OPT3101::frameData OPT3101::calibrationC
00026 */
00027 #include "OPT3101device.h "
00028 //#include "definitions.h"
00029 
00030 void OPT3101::device::reset() {
00031     /// <b>Algorithm of the method is as follows</b>
00032     host.printf("INFO::Resetting Host\r\n");
00033     host.resetDevice(); ///* Invokes the hostController::reset method
00034     host.sleep(100);
00035 
00036 }
00037 
00038 void OPT3101::device::liveDataView(uint32_t nFrames,uint32_t refreshDelayinms,bool scroll){
00039     uint32_t c0;
00040     uint8_t c1;
00041     OPT3101::frameData data;
00042     host.printf("\r\n");
00043     for(c1=0;c1<3;c1++)
00044         host.printf("|Distmm, Phase,Amplud,SigS,AmbS,HDR|--");
00045     host.printf("|Amb,Cntr,Tmain,Tillum   |  Count/Total  |");
00046     host.printf("\r\n");
00047     for(c0=0;c0<nFrames;c0++){
00048         data.capture(&host, this,this->calibration->extTempSensor_connected);
00049         this->data[data.ledChannel]=data;
00050         for(c1=0;c1<3;c1++){
00051             if(this->data[c1].sigovl || this->data[c1].ambovl)
00052                 host.printfSetColor(0b100);
00053             else
00054                 host.printfSetColor(0b010);
00055             host.printf("|%06u,",(this->data[c1].phase*14989)>>16);
00056             host.printf("%06u,",this->data[c1].phase);
00057             host.printf("%06u,",this->data[c1].amplitude);
00058             host.printf("   %1u,",this->data[c1].sigovl);
00059             host.printf("   %1u,",this->data[c1].ambovl);
00060             host.printf("  %1u|--",this->data[c1].illumDac);
00061         }
00062         host.printfSetColor(0xFF);
00063         host.printf("|%03d,",data.ambient);
00064         host.printf("0x%02x,",data.frameCounter);
00065         host.printf("  %+03d,",(int32_t) (((int32_t)data.tmain>>3)-256));
00066         host.printf("%+07.4f|",((double)data.tillum/16-128));
00067         host.printf("%07u",c0);
00068         host.printf("/%07u|\r",nFrames);
00069         if(scroll)
00070             host.printf("\n");
00071         host.sleep(refreshDelayinms);
00072     }
00073     host.printf("\n");
00074 }
00075 
00076 void OPT3101::device::resetInitAndViewData(uint32_t nFrames,bool loadCalibration){
00077     this->reset();
00078     host.sleep(5000);
00079     this->initialize();
00080     this->measureAndCorrectInternalCrosstalk(&this->calibration->internalCrosstalk[0]); ///* Calls method OPT3101::device::measureAndCorrectInternalCrosstalk with argument OPT3101::calibrationC::internalCrosstalk
00081     this->calibration->internalCrosstalk[0].printHeader(); ///* Calls the method OPT3101::crosstalkC::report for debug and data analysis
00082     this->calibration->internalCrosstalk[0].print(); ///* Calls the method OPT3101::crosstalkC::report for debug and data analysis
00083     host.printf("\r\n");
00084     if(loadCalibration){
00085         this->manuallySetIllumCrosstalkTempCoffs();
00086         this->manuallySetPhaseTempCoffs();
00087         this->manuallySetPhaseAmbientCoffs();
00088 
00089         this->loadIllumCrosstalkSet(true);
00090         this->loadIllumCrosstalkTempCoffSet();
00091 
00092         this->loadPhaseOffsetSet(true);
00093         this->loadPhaseOffsetTempCoffSet();
00094 
00095         this->loadPhaseAmbientCoffSet();
00096     }
00097     this->liveDataView(nFrames, this->configurationFlags_frameTimeInMilliSeconds, false);
00098 }
00099 
00100 bool OPT3101::device::validateI2C() {
00101     /// <b>Algorithm of the method is as follows</b>
00102     uint32_t data;
00103     bool status;
00104     //0x8001A0
00105     //data=0xA001802E
00106     //data[0]=0x8;
00107     //data[1]=001A0
00108     status = 0;
00109     host.printf("INFO::Validating I2C Transaction\r\n");
00110 //#ifdef TIMSP430F5529_LAUNCHPAD_CALIBRATION_TOOL   
00111     status=host.i2c.read(0x2E,&data);
00112     if(status){
00113         host.printfSetColor(0b010);
00114         host.printf("INFO::I2C Transaction Successful\r\n");
00115         host.printfSetColor(0xFF);
00116     }
00117     else{
00118         host.printfSetColor(0b100);
00119         host.printf("EROR::I2C Transaction Failed. Please check Connection\r\n");
00120         host.printfSetColor(0xFF);
00121     }
00122     return status;
00123 //#endif
00124 
00125 //#ifndef TIMSP430F5529_LAUNCHPAD_CALIBRATION_TOOL
00126 //  host.printfSetColor(0b110);
00127 //  host.printf("WARN::I2C Status checking not implemented\r\n");
00128 //  host.printfSetColor(0xFF);
00129 //  return true;
00130 //#endif
00131 
00132 }
00133 
00134 bool OPT3101::device::validateDesignID() {
00135     /// <b>Algorithm of the method is as follows</b>
00136     uint32_t data[2];
00137     bool status;
00138     status = 0;
00139     host.printf("INFO::Validating OPT3101 Design ID\r\n");
00140     this->reg.iq_read_data_sel=4;
00141     data[0]=host.readI2C(0x3b);
00142     this->reg.iq_read_data_sel=5;
00143     data[1]=host.readI2C(0x3b);
00144 
00145     if(data[0]==0x100411 && data[1]==0xc01000){
00146         status=true;
00147         host.printfSetColor(0b010);
00148         host.printf("INFO::Design ID 0x%06lx%06lx Verified\r\n",data[1],data[0]);
00149         host.printfSetColor(0xFF);
00150     }
00151     else{
00152         status=false;
00153         host.printfSetColor(0b110);
00154         host.printf("WARN::Design ID 0x%06lx%06lx Not Maching\r\n",data[1],data[0]);
00155         host.printfSetColor(0xFF);
00156     }
00157     this->reg.iq_read_data_sel=0;
00158     return status;
00159 }
00160 
00161 
00162 void OPT3101::device::measureAndCorrectInternalCrosstalk(OPT3101::crosstalkC *internalXtalk){
00163     /// <b>Algorithm of the method is as follows</b>
00164     uint8_t regStore[5];
00165     regStore[0]=this->reg.en_adaptive_hdr.read();
00166     regStore[1]=this->reg.hdr_mode.read();
00167     regStore[2]=this->reg.en_sequencer.read(); ///* Critical registers which are modified in this method are read from the h/w and temporarily buffered to local variables.
00168     regStore[3]=this->reg.en_processor_values.read(); ///* Temporarily buffered register states are restored to the h/w with register writes while exiting this method.
00169     
00170     this->reg.tg_en=0;
00171     this->reg.en_adaptive_hdr=0;
00172     this->reg.hdr_mode=0;
00173     this->reg.en_sequencer=0;
00174     this->reg.en_processor_values=0;
00175     this->reg.tg_en=1;
00176 
00177     this->reg.use_xtalk_reg_int=0;
00178     this->reg.int_xtalk_calib=1; ///* Enables internal crosstalk measure and correct register OPT3101::registers::int_xtalk_calib
00179     host.printf("INFO::Performing Internal Cross talk Measurement...\r\n");
00180     host.sleep(this->configurationFlags_xtalkSettlingOneTauInMilliSeconds<<3); ///* Sleeps the host for 8 times the OPT3101::device::configurationFlags_xtalkSettlingOneTauInMilliSeconds so that device settles
00181     /* host.sleepDataReadyCounts(this->configurationFlags_xtalkSettlingOneTauInDataReadyCounts<<3);  */
00182     ///* Sleep delay can be replaced with wait for 8 times the OPT3101::device::configurationFlags_xtalkSettlingOneTauInDataReadyCounts data ready pulses.User needs to implement based on host configuration
00183 
00184     this->reg.int_xtalk_calib=0;  ///* Disables internal crosstalk measure register OPT3101::registers::int_xtalk_calib to complete internal crosstalk measurement
00185 
00186     regStore[4]=this->reg.iq_read_data_sel.read(); 
00187     this->reg.iq_read_data_sel=0;
00188     internalXtalk->readCrosstalkRegisters(this); ///* Reads the internal crosstalk registers OPT3101::registers::iphase_xtalk and OPT3101::registers::qphase_xtalk and assigns to internalXtalk input instance pointer of type OPT3101::crosstalkC class
00189     this->reg.iq_read_data_sel=regStore[4];
00190 
00191     this->reg.tg_en=0;
00192     this->reg.en_adaptive_hdr=regStore[0];
00193     this->reg.hdr_mode=regStore[1];
00194     this->reg.en_sequencer=regStore[2];
00195     this->reg.en_processor_values=regStore[3]; ///* Restores the device state to the same state as before entering this method from the buffered local variables
00196     this->reg.tg_en=1;
00197     host.printf("INFO::Internal Cross talk Measurement Completed\r\n");
00198 
00199 }
00200 
00201 void OPT3101::device::measureIllumCrosstalk(OPT3101::crosstalkC *illumXtalk) {
00202     uint8_t regStore[2];
00203     /// <b>Algorithm of the method is as follows</b>
00204     regStore[0] = this->reg.use_xtalk_reg_illum.read(); 
00205     this->reg.use_xtalk_reg_illum = 0;
00206     this->reg.illum_xtalk_calib = 1; ///* Enables illum crosstalk measure register OPT3101::registers::illum_xtalk_calib
00207     host.sleep(this->configurationFlags_xtalkSettlingOneTauInMilliSeconds << 3); ///* Sleeps the host for 8 times the OPT3101::device::configurationFlags_xtalkSettlingOneTauInMilliSeconds so that device settles
00208     // The same can be replated with 
00209     // host.sleepDataReadyCounts(this->configurationFlags_xtalkSettlingOneTauInDataReadyCounts<<3); // This is for 8 Tau settings
00210     ///* Sleep delay can be replaced with wait for 8 times the OPT3101::device::configurationFlags_xtalkSettlingOneTauInDataReadyCounts data ready pulses.User needs to implement based on host configuration
00211     
00212     this->reg.illum_xtalk_calib = 0;
00213     //Wait Time
00214 
00215     regStore[1] = this->reg.iq_read_data_sel.read(); ///* Reads the internal crosstalk registers OPT3101::registers::iphase_xtalk and OPT3101::registers::qphase_xtalk and assigns to illumXtalk input instance pointer of type OPT3101::crosstalkC class
00216     this->reg.iq_read_data_sel = 1;
00217     illumXtalk->readCrosstalkRegisters(this);
00218     illumXtalk->illumXtalk = true;
00219     
00220     this->reg.iq_read_data_sel = regStore[1];
00221     this->reg.use_xtalk_reg_illum = regStore[0];
00222     
00223     illumXtalk->readTemperatureMain(this); ///* Reads main temp sensor and captures the same to input argument illumXtalk's OPT3101::crosstalkC::tmain
00224     illumXtalk->readTemperatureIllum(this); ///* Reads external temp sensor and captures the same to input argument illumXtalk's OPT3101::crosstalkC::tillum
00225 
00226 }
00227 
00228 void OPT3101::device::measureIllumCrosstalkSet(bool saveToFile) {
00229     uint8_t c0, c1;
00230     uint16_t flashLocation;
00231 #ifdef OPT3101_USE_STDIOLIB
00232     char fileName[FILENAME_LENGTH];
00233 #endif
00234 
00235     envController.setTargetToInfinity_OR_coverPhotodiode(); ///* Calls the method environmentalController::setTargetToInfinity_OR_coverPhotodiode , which is expected to set the environment so as to be able to measure illumination crosstalk
00236     // Loop to iterate over all TX channels
00237     for (c0 = 0; c0 < 3; c0++) {  ///* Loops though all the valid TX channel and register set configurations
00238         if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile
00239             for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers
00240                 if (this->configurationFlags_isRegisterSetActive[c1]) { // Checking if registers are active for this profile
00241                     host.printf("INFO:Performing Illum Crosstalk for TX%d HDR %d\r\n",c0,c1);
00242                     this->measureIllumCrosstalk(&this->calibration->illumCrosstalk[c0][c1], c0, c1 ? 'h' : 'l');  ///* Calls method OPT3101::device::measureIllumCrosstalk with argument OPT3101::calibrationC::illumCrosstalk
00243                     this->calibration->illumCrosstalk[c0][c1].printHeader(); ///* Calls the method OPT3101::crosstalkC::report for debug and data analysis
00244                     this->calibration->illumCrosstalk[c0][c1].print(); ///* Calls the method OPT3101::crosstalkC::report for debug and data analysis
00245                     host.printf("\r\n");
00246 
00247                                                                       // Provide file name if save to File is implemented eg: illumCrosstalkTX{txChannel}Reg{regSet}_roomTemp
00248                    if(saveToFile){
00249 #ifdef OPT3101_USE_STDIOLIB
00250                         sprintf(fileName, "%s/illumCrosstalk_TX%d_%c.txt", filePath, c0, c1 ? 'h' : 'l'); ///* Creates filename  illumCrosstalk_TX{channel}_{h/l}.txt in path filePath
00251                         this->calibration->illumCrosstalk[c0][c1].storeToFile(fileName);  ///* Calls method OPT3101::crosstalkC::storeToFile to store the data
00252 #endif
00253 #ifdef TIMSP430F5529_LAUNCHPAD_CALIBRATION_TOOL
00254                         flashLocation=(c1+(c0<<1))<<4;
00255                         //TODO fix this host.flash.write(flashLocation, (uint8_t*)&this->calibration->illumCrosstalk[c0][c1] ,16);
00256                         host.printf("INFO:Writing Illum Cross talk for TX%d HDR %d to Flash location 0x%04x\r\n",c0,c1,flashLocation);
00257 #endif // TIHOST
00258                    }
00259 #ifdef TIMSP430F5529_LAUNCHPAD_CALIBRATION_TOOL
00260                     if(this->calibration->illumCrosstalk[c0][c1].magnitude()>800)
00261                         host.printf("WARN:Illumination Cross talk is very high. Check if Photo diode is covered well.. if so increase [force_scale_val] register by 1 count and add it to initialization method\r\n",flashLocation);
00262 #endif // TIHOST
00263                 }
00264             }
00265         }
00266     }
00267     host.printf("INFO:Completed Illumination cross talk measurement for all channels\r\n");
00268 }
00269 
00270 
00271 void OPT3101::device::measureIllumCrosstalk( OPT3101::crosstalkC *illumXtalk, uint8_t txChannel, char registerSet,uint8_t shiftIllumPhase) {
00272     uint8_t regStore[8];
00273     /// <b>Algorithm of the method is as follows</b>
00274     regStore[0] = this->reg.en_sequencer.read(); ///* Critical registers which are modified in this method are read from the h/w and temporarily buffered to local variables.
00275     regStore[1] = this->reg.en_processor_values.read();
00276     regStore[2] = this->reg.sel_hdr_mode.read();
00277     regStore[3] = this->reg.sel_tx_ch.read();
00278     regStore[4] = this->reg.en_adaptive_hdr.read();
00279     regStore[5] = this->reg.en_tx_switch.read();
00280     regStore[6] = this->reg.shift_illum_phase.read();
00281     regStore[7] = this->reg.en_temp_xtalk_corr.read();
00282 
00283     this->reg.tg_en = 0;
00284     this->reg.en_sequencer = 0;
00285     this->reg.en_processor_values = 0;
00286     if (registerSet == 'h')
00287         this->reg.sel_hdr_mode = 1; ///* Register set is chosen based on registerSet input to this method by setting OPT3101::registers::sel_hdr_mode
00288     if (registerSet == 'l')
00289         this->reg.sel_hdr_mode = 0;
00290     this->reg.sel_tx_ch = txChannel; ///* TX channel is chosen based on txChannel input to this method by setting OPT3101::registers::sel_tx_ch
00291     this->reg.en_tx_switch = 0;
00292     this->reg.en_adaptive_hdr = 0;
00293     this->reg.shift_illum_phase = shiftIllumPhase; ///* Sets up the OPT3101::registers::shift_illum_phase based on the input to this method shiftIllumPhase
00294     this->reg.tg_en = 1;
00295     
00296     this->measureIllumCrosstalk(illumXtalk); ///* Measures illum crosstalk from registers OPT3101::registers::iphase_xtalk , and OPT3101::registers::qphase_xtalk and assigns to illumXtalk instance pointer of type OPT3101::crosstalkC class
00297     illumXtalk->illumDCdac = this->reg.ILLUM_DC_CURR_DAC.read();
00298     illumXtalk->shiftIllumPhase = shiftIllumPhase; ///* Takes snapshot of device TX register configuration and assign them to illumXtalk instance pointer of type OPT3101::crosstalkC class
00299     switch (txChannel) {
00300         case 0:
00301             if (registerSet == 'h') {
00302                 illumXtalk->illumDac = this->reg.illum_dac_h_tx0.read();
00303                 illumXtalk->illumScale = this->reg.illum_scale_h_tx0.read();
00304             }
00305             else if (registerSet == 'l') {
00306                 illumXtalk->illumDac = this->reg.illum_dac_l_tx0.read();
00307                 illumXtalk->illumScale = this->reg.illum_scale_l_tx0.read();
00308             }
00309             break;
00310         case 1:
00311             if (registerSet == 'h') {
00312                 illumXtalk->illumDac = this->reg.illum_dac_h_tx1.read();
00313                 illumXtalk->illumScale = this->reg.illum_scale_h_tx1.read();
00314             }
00315             else if (registerSet == 'l') {
00316                 illumXtalk->illumDac = this->reg.illum_dac_l_tx1.read();
00317                 illumXtalk->illumScale = this->reg.illum_scale_l_tx1.read();
00318             }
00319             break;
00320         case 2:
00321             if (registerSet == 'h') {
00322                 illumXtalk->illumDac = this->reg.illum_dac_h_tx2.read();
00323                 illumXtalk->illumScale = this->reg.illum_scale_h_tx2.read();
00324             }
00325             else if (registerSet == 'l') {
00326                 illumXtalk->illumDac = this->reg.illum_dac_l_tx2.read();
00327                 illumXtalk->illumScale = this->reg.illum_scale_l_tx2.read();
00328             }
00329             break;
00330         default:
00331             break;
00332     }
00333     //printf("Illum Cross-talk for Illum current [%d] Magnitude is %4.2f [%d][%d][%d]\n", i, InternalXtalk.magnitude(), InternalXtalk.I, InternalXtalk.Q, InternalXtalk.xtalkScale);
00334     
00335     this->reg.tg_en = 0;
00336     this->reg.en_sequencer = regStore[0];  
00337     this->reg.en_processor_values = regStore[1];
00338     this->reg.sel_hdr_mode = regStore[2];
00339     this->reg.sel_tx_ch = regStore[3];
00340     this->reg.en_adaptive_hdr = regStore[4];
00341     this->reg.en_tx_switch = regStore[5];
00342     this->reg.shift_illum_phase = regStore[6];
00343     this->reg.en_temp_xtalk_corr = regStore[7]; ///* Restores the device state to the same state as before entering this method from the buffered local variables
00344 
00345     this->reg.tg_en = 1;
00346 }
00347 
00348 void OPT3101::device::loadIllumCrosstalk(OPT3101::crosstalkC *illumXtalk, uint8_t txChannel, char registerSet) {
00349     uint8_t maxIllumXtalkScale;
00350     
00351     /// <b>Algorithm of the method is as follows</b>
00352     maxIllumXtalkScale = illumXtalk->commonScale; ///* Load the common to all TX channels/register set registers (like for eg OPT3101::registers::illum_xtalk_reg_scale) to the h/w from the method input argument illumXtalk
00353     this->reg.illum_xtalk_reg_scale = illumXtalk->commonScale;
00354     this->reg.shift_illum_phase = illumXtalk->shiftIllumPhase;
00355     
00356     //printf("Scale reduction is [%d] [%d] [%d] \n", illumXtalk->I, maxIllumXtalkScale - illumXtalk->xtalkScale, illumXtalk->I >>(maxIllumXtalkScale - illumXtalk->xtalkScale));
00357     switch (txChannel) { ///* Based on txChannel and registerSet argument the the method loads the OPT3101::crosstalkC::I, OPT3101::crosstalkC::Q, OPT3101::crosstalkC::tmain and OPT3101::crosstalkC::tillum to device h/w specified TX channels and register set  
00358     case 0: ///* for eg: then txChannel=1 and registerSet='l' then the method loads the argument illumXtalk's OPT3101::crosstalkC::I to OPT3101::registers::iphase_xtalk_reg_hdr0_tx1 . Similarly the qphase_reg* registers, OPT3101::registers::tmain_calib_hdr0_tx1 and OPT3101::registers::tillum_calib_hdr0_tx1 are loaded from the input argument illumXtalk's  OPT3101::crosstalkC::tmain and OPT3101::crosstalkC::tillum
00359         if (registerSet == 'h') {
00360             this->reg.iphase_xtalk_reg_hdr1_tx0 = (uint16_t) (illumXtalk->I >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
00361             this->reg.qphase_xtalk_reg_hdr1_tx0 = (uint16_t) (illumXtalk->Q >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
00362             this->reg.tmain_calib_hdr1_tx0 = illumXtalk->tmain;
00363             this->reg.tillum_calib_hdr1_tx0 = illumXtalk->tillum;
00364         }
00365         else if (registerSet == 'l') {
00366             this->reg.iphase_xtalk_reg_hdr0_tx0 = (uint16_t)(illumXtalk->I >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
00367             this->reg.qphase_xtalk_reg_hdr0_tx0 = (uint16_t)(illumXtalk->Q >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
00368             this->reg.tmain_calib_hdr0_tx0 = illumXtalk->tmain;
00369             this->reg.tillum_calib_hdr0_tx0 = illumXtalk->tillum;
00370         }
00371         break;
00372     case 1:
00373         if (registerSet == 'h') {
00374             this->reg.iphase_xtalk_reg_hdr1_tx1 = (uint16_t)(illumXtalk->I >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
00375             this->reg.qphase_xtalk_reg_hdr1_tx1 = (uint16_t)(illumXtalk->Q >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
00376             this->reg.tmain_calib_hdr1_tx1 = illumXtalk->tmain;
00377             this->reg.tillum_calib_hdr1_tx1 = illumXtalk->tillum;
00378         }
00379         else if (registerSet == 'l') {
00380             this->reg.iphase_xtalk_reg_hdr0_tx1 = (uint16_t)(illumXtalk->I >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
00381             this->reg.qphase_xtalk_reg_hdr0_tx1 = (uint16_t)(illumXtalk->Q >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
00382             this->reg.tmain_calib_hdr0_tx1 = illumXtalk->tmain;
00383             this->reg.tillum_calib_hdr0_tx1 = illumXtalk->tillum;
00384         }
00385         break;
00386     case 2:
00387         if (registerSet == 'h') {
00388             this->reg.iphase_xtalk_reg_hdr1_tx2 = (uint16_t)(illumXtalk->I >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
00389             this->reg.qphase_xtalk_reg_hdr1_tx2 = (uint16_t)(illumXtalk->Q >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
00390             this->reg.tmain_calib_hdr1_tx2 = illumXtalk->tmain;
00391             this->reg.tillum_calib_hdr1_tx2 = illumXtalk->tillum;
00392         }
00393         else if (registerSet == 'l') {
00394             this->reg.iphase_xtalk_reg_hdr0_tx2 = (uint16_t)(illumXtalk->I >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
00395             this->reg.qphase_xtalk_reg_hdr0_tx2 = (uint16_t)(illumXtalk->Q >> (maxIllumXtalkScale - illumXtalk->xtalkScale));
00396             this->reg.tmain_calib_hdr0_tx2 = illumXtalk->tmain;
00397             this->reg.tillum_calib_hdr0_tx2 = illumXtalk->tillum;
00398         }
00399         break;
00400     default:
00401         break;
00402     }
00403 
00404 }
00405 
00406 void OPT3101::device::loadPhaseOffset(OPT3101::phaseOffsetC *phaseOffset, uint8_t txChannel, char registerSet)
00407 {
00408     /// <b>Algorithm of the method is as follows</b>
00409 
00410     //printf("Scale reduction is [%d] [%d] [%d] \n", illumXtalk->I, maxIllumXtalkScale - illumXtalk->xtalkScale, illumXtalk->I >>(maxIllumXtalkScale - illumXtalk->xtalkScale));
00411     this->reg.en_phase_corr = 1; ///* Enables the phase offset correction register OPT3101::registers::en_phase_corr
00412     switch (txChannel) {  ///* Based on txChannel and registerSet argument the the method loads the OPT3101::phaseOffsetC::phaseOffset, OPT3101::phaseOffsetC::frameData::tmain and OPT3101::phaseOffsetC::frameData::tillum to device h/w specified TX channels and register set  
00413     case 0: ///* for eg: then txChannel=1 and registerSet='l' then the method loads the argument phaseOffset's OPT3101::phaseOffsetC::phaseOffset to OPT3101::registers::phase_offset_hdr0_tx1 OPT3101::registers::tmain_calib_hdr0_tx1 and OPT3101::registers::tillum_calib_hdr0_tx1 are loaded from the input argument phaseOffset's  OPT3101::phaseOffsetC::frameData::tmain and OPT3101::phaseOffsetC::frameData::tillum
00414         if (registerSet == 'h') {
00415             this->reg.phase_offset_hdr1_tx0 = phaseOffset->phaseOffset;
00416             this->reg.tmain_calib_hdr1_tx0 = phaseOffset->data.tmain;
00417             this->reg.tillum_calib_hdr1_tx0 = phaseOffset->data.tillum;
00418         }
00419         else if (registerSet == 'l') {
00420             this->reg.phase_offset_hdr0_tx0 = phaseOffset->phaseOffset;
00421             this->reg.tmain_calib_hdr0_tx0 = phaseOffset->data.tmain;
00422             this->reg.tillum_calib_hdr0_tx0 = phaseOffset->data.tillum;
00423         }
00424         break;
00425     case 1:
00426         if (registerSet == 'h') {
00427             this->reg.phase_offset_hdr1_tx1 = phaseOffset->phaseOffset;
00428             this->reg.tmain_calib_hdr1_tx1 = phaseOffset->data.tmain;
00429             this->reg.tillum_calib_hdr1_tx1 = phaseOffset->data.tillum;
00430         }
00431         else if (registerSet == 'l') {
00432             this->reg.phase_offset_hdr0_tx1 = phaseOffset->phaseOffset;
00433             this->reg.tmain_calib_hdr0_tx1 = phaseOffset->data.tmain;
00434             this->reg.tillum_calib_hdr0_tx1 = phaseOffset->data.tillum;
00435         }
00436         break;
00437     case 2:
00438         if (registerSet == 'h') {
00439             this->reg.phase_offset_hdr1_tx2 = phaseOffset->phaseOffset;
00440             this->reg.tmain_calib_hdr1_tx2 = phaseOffset->data.tmain;
00441             this->reg.tillum_calib_hdr1_tx2 = phaseOffset->data.tillum;
00442         }
00443         else if (registerSet == 'l') {
00444             this->reg.phase_offset_hdr0_tx2 = phaseOffset->phaseOffset;
00445             this->reg.tmain_calib_hdr0_tx2 = phaseOffset->data.tmain;
00446             this->reg.tillum_calib_hdr0_tx2 = phaseOffset->data.tillum;
00447         }
00448         break;
00449     default:
00450         break;
00451     }
00452 }
00453 
00454 void OPT3101::device::loadIllumCrosstalkTempCoff(OPT3101::crosstalkTempCoffC *illumXtalkTempCoff, uint8_t txChannel, char registerSet)
00455 {
00456     /// <b>Algorithm of the method is as follows</b>
00457 
00458     this->reg.scale_temp_coeff_xtalk = illumXtalkTempCoff->commonScale; ///* loads common scale OPT3101::crosstalkTempCoffC::commonScale from input argument illumXtalkTempCoff to device register OPT3101::registers::scale_temp_coeff_xtalk
00459     switch (txChannel) { ///* Based on txChannel and registerSet argument the  method loads the OPT3101::crosstalkTempCoffC::coffIReg and OPT3101::crosstalkTempCoffC::coffQReg  to respective register set and channel registers 
00460     case 0: ///* for eg: then txChannel=1 and registerSet='l' then the method loads the argument illumXtalkTempCoff's OPT3101::crosstalkTempCoffC::coffIReg to OPT3101::registers::temp_coeff_xtalk_iphase_hdr0_tx1 and similarly for the qphase register as well
00461         if (registerSet == 'h') {
00462             this->reg.temp_coeff_xtalk_iphase_hdr1_tx0 = illumXtalkTempCoff->coffIReg;
00463             this->reg.temp_coeff_xtalk_qphase_hdr1_tx0 = illumXtalkTempCoff->coffQReg;
00464         }
00465         else if (registerSet == 'l') {
00466             this->reg.temp_coeff_xtalk_iphase_hdr0_tx0 = illumXtalkTempCoff->coffIReg;
00467             this->reg.temp_coeff_xtalk_qphase_hdr0_tx0 = illumXtalkTempCoff->coffQReg;
00468         }
00469         break;
00470     case 1:
00471         if (registerSet == 'h') {
00472             this->reg.temp_coeff_xtalk_iphase_hdr1_tx1 = illumXtalkTempCoff->coffIReg;
00473             this->reg.temp_coeff_xtalk_qphase_hdr1_tx1 = illumXtalkTempCoff->coffQReg;
00474         }
00475         else if (registerSet == 'l') {
00476             this->reg.temp_coeff_xtalk_iphase_hdr0_tx1 = illumXtalkTempCoff->coffIReg;
00477             this->reg.temp_coeff_xtalk_qphase_hdr0_tx1 = illumXtalkTempCoff->coffQReg;
00478         }
00479         break;
00480     case 2:
00481         if (registerSet == 'h') {
00482             this->reg.temp_coeff_xtalk_iphase_hdr1_tx2 = illumXtalkTempCoff->coffIReg;
00483             this->reg.temp_coeff_xtalk_qphase_hdr1_tx2 = illumXtalkTempCoff->coffQReg;
00484         }
00485         else if (registerSet == 'l') {
00486             this->reg.temp_coeff_xtalk_iphase_hdr0_tx2 = illumXtalkTempCoff->coffIReg;
00487             this->reg.temp_coeff_xtalk_qphase_hdr0_tx2 = illumXtalkTempCoff->coffQReg;
00488         }
00489         break;
00490     default:
00491         break;
00492     }
00493 
00494 }
00495 
00496 void OPT3101::device::loadPhaseOffsetTempCoff(OPT3101::phaseTempCoffC *phaseTempCoff, uint8_t txChannel, char registerSet)
00497 {
00498     /// <b>Algorithm of the method is as follows</b>
00499 
00500     this->reg.en_temp_corr = 1; ///* Enables the phase temp coefficient register OPT3101::registers::en_temp_corr
00501     this->reg.scale_phase_temp_coeff = phaseTempCoff->commonScale; ///* Sets the common scale register OPT3101::registers::scale_phase_temp_coeff with value from input argument phaseTempCoff's OPT3101::phaseTempCoffC::commonScale
00502     switch (txChannel) { ///* Based on txChannel and registerSet argument the  method loads the OPT3101::phaseTempCoffC::coffReg to respective register set and channel registers 
00503     case 0: ///* for eg: then txChannel=1 and registerSet='l' then the method loads the argument phaseTempCoff's OPT3101::phaseTempCoffC::coffReg to OPT3101::registers::temp_coeff_illum_hdr0_tx1 or OPT3101::registers::temp_coeff_main_hdr0_tx1 depending on if phaseTempCoff's OPT3101::phaseTempCoffC::istMainCoff is True or False
00504         if (registerSet == 'h') {
00505             if (phaseTempCoff->istMainCoff)
00506                 this->reg.temp_coeff_main_hdr1_tx0 = phaseTempCoff->coffReg;
00507             else
00508                 this->reg.temp_coeff_illum_hdr1_tx0 = phaseTempCoff->coffReg;
00509         }
00510         else if (registerSet == 'l') {
00511             if (phaseTempCoff->istMainCoff)
00512                 this->reg.temp_coeff_main_hdr0_tx0 = phaseTempCoff->coffReg;
00513             else
00514                 this->reg.temp_coeff_illum_hdr0_tx0 = phaseTempCoff->coffReg;
00515         }
00516         break;
00517     case 1:
00518         if (registerSet == 'h') {
00519             if (phaseTempCoff->istMainCoff)
00520                 this->reg.temp_coeff_main_hdr1_tx1 = phaseTempCoff->coffReg;
00521             else
00522                 this->reg.temp_coeff_illum_hdr1_tx1 = phaseTempCoff->coffReg;
00523         }
00524         else if (registerSet == 'l') {
00525             if (phaseTempCoff->istMainCoff)
00526                 this->reg.temp_coeff_main_hdr0_tx1 = phaseTempCoff->coffReg;
00527             else
00528                 this->reg.temp_coeff_illum_hdr0_tx1 = phaseTempCoff->coffReg;
00529         }
00530         break;
00531     case 2:
00532         if (registerSet == 'h') {
00533             if (phaseTempCoff->istMainCoff)
00534                 this->reg.temp_coeff_main_hdr1_tx2 = phaseTempCoff->coffReg;
00535             else
00536                 this->reg.temp_coeff_illum_hdr1_tx2 = phaseTempCoff->coffReg;
00537         }
00538         else if (registerSet == 'l') {
00539             if (phaseTempCoff->istMainCoff)
00540                 this->reg.temp_coeff_main_hdr0_tx2 = phaseTempCoff->coffReg;
00541             else
00542                 this->reg.temp_coeff_illum_hdr0_tx2 = phaseTempCoff->coffReg;
00543         }
00544         break;
00545     default:
00546         break;
00547     }
00548 }
00549 
00550 void OPT3101::device::loadPhaseAmbientCoff(OPT3101::phaseAmbientCoffC *phaseAmbientCoff)
00551 {
00552     /// <b>Algorithm of the method is as follows</b>
00553 
00554     this->reg.scale_amb_phase_corr_coeff = phaseAmbientCoff->commonScale; ///* Assigns all the register entries from phaseAmbientCoff OPT3101::phaseAmbientCoffC to h/w registers 
00555     this->reg.amb_phase_corr_pwl_coeff0 = phaseAmbientCoff->coffReg[0]; ///* for eg:  input argument phaseAmbientCoff's  OPT3101::phaseAmbientCoffC::coffReg is loaded to OPT3101::registers::amb_phase_corr_pwl_coeff0 and other related registers
00556     this->reg.amb_phase_corr_pwl_coeff1 = phaseAmbientCoff->coffReg[1];
00557     this->reg.amb_phase_corr_pwl_coeff2 = phaseAmbientCoff->coffReg[2];
00558     this->reg.amb_phase_corr_pwl_coeff3 = phaseAmbientCoff->coffReg[3];
00559     this->reg.amb_phase_corr_pwl_x0 = phaseAmbientCoff->splitsReg[0];
00560     this->reg.amb_phase_corr_pwl_x1 = phaseAmbientCoff->splitsReg[1];
00561     this->reg.amb_phase_corr_pwl_x2 = phaseAmbientCoff->splitsReg[2];
00562 }
00563 
00564 OPT3101::frameData::frameData()
00565 {
00566     /// <b>Algorithm of the method is as follows</b>
00567 
00568     this->phase = 0; ///* Initializes all members to 0
00569     this->phaseovl = false;
00570     this->phaseovlf2 = false;
00571     this->ambovl = false;
00572     this->illumDac = false;
00573     this->ledChannel = 0;
00574     this->frameStatus = false;
00575     this->dealiasFreq = false;
00576     this->frameCounter = 0;
00577     this->amplitude = 0;
00578     this->sigovl = false;
00579     this->dealiasBin = 0;
00580     this->ambient = 0;
00581     this->temp = 0;
00582     this->tmain = 0;
00583     this->tillum = 0;
00584 
00585 }
00586 
00587 void OPT3101::frameData::capture(hostController *host, OPT3101::device *dev,bool readTillum) {
00588     uint8_t c0;
00589     uint32_t data32[3];
00590     /// <b>Algorithm of the method is as follows</b>
00591     host->sleep((dev->configurationFlags_frameTimeInMilliSeconds)<<1); ///* Sleep host for a specified time depending on device configuration to OPT3101 AFE can update measurements to the registers.
00592     for (c0 = 8; c0 < 11; c0++) ///* Performs a direct read of I2C registers 0x08 0x09 and 0x0A directly though hostController::readI2C method 
00593         data32[c0-8] = (host->readI2C(c0));
00594 
00595     this->phase = data32[0] & 0xFFFF; ///* Maps the I2C read values to the class members like OPT3101::frameData::phase, OPT3101::frameData::amplitude etc 
00596     this->phaseovl = (data32[0] >> 16) & 0x1;
00597 
00598     this->phase |= (((uint32_t) this->phaseovl) << 16);
00599 
00600     this->illumDac = (data32[0] >> 17) & 0x01;
00601     this->ledChannel = (data32[0] >> 18) & 0x03;
00602     this->frameStatus = (data32[0] >> 20) & 0x01;
00603     this->dealiasFreq = (data32[0] >> 21) & 0x01;
00604     this->ambovl = (data32[0] >> 22) & 0x01;
00605     this->frameCounter = (data32[0] >> 23) & 0x01;
00606 
00607     this->amplitude = data32[1] & 0xFFFF;
00608     this->frameCounter |= ((data32[1] >> 16) & 0x03) << 1;
00609     this->sigovl = (data32[1] >> 18) & 0x01;
00610     this->phaseovlf2 = (data32[1] >> 19) & 0x01;
00611     this->dealiasBin = (data32[1] >> 20) & 0x0F;
00612 
00613     this->frameCounter |= (data32[2] & 0x03) << 3;
00614     this->ambient = (data32[2] >> 2) & 0x3FF;
00615     this->temp = (data32[2] >> 12) & 0xFFF;
00616     this->tmain = this->temp;
00617     if (readTillum)
00618         this->tillum = dev->reg.tillum.read(); ///* Based on readIllum flag reads the OPT3101::registers::tillum and assigns to OPT3101::frameData::tillum
00619 
00620 }
00621 
00622 void OPT3101::frameData::report()
00623 {
00624     /// <b>Algorithm of the method is as follows</b>
00625     host.printf("-----------------------\r\n");
00626     host.printf("Frame data Class Report\r\n");
00627     host.printf("-----------------------\r\n"); ///* Prints all the members and values of members on screen.
00628     host.printf("phase=%d\r\n", this->phase);
00629     host.printf("phaseovl=%d\r\n", this->phaseovl);
00630     host.printf("phaseovlf2=%d\r\n", this->phaseovlf2);
00631     host.printf("ambovl=%d\r\n", this->ambovl);
00632     host.printf("illumDac=%d\r\n", this->illumDac);
00633     host.printf("ledChannel=%d\r\n", this->ledChannel);
00634     host.printf("frameStatus=%d\r\n", this->frameStatus);
00635     host.printf("dealiasFreq=%d\r\n", this->dealiasFreq);
00636     host.printf("frameCounter=%d\r\n", this->frameCounter);
00637     host.printf("amplitude=%d\r\n", this->amplitude);
00638     host.printf("sigovl=%d\r\n", this->sigovl);
00639     host.printf("dealiasBin=%d\r\n", this->dealiasBin);
00640     host.printf("ambient=%d\r\n", this->ambient);
00641     host.printf("temp=%d\r\n", this->temp);
00642     host.printf("tmain=%d\r\n", this->tmain);
00643     host.printf("tillum=%d\r\n", this->tillum);
00644     host.printf("-----------------------\r\n"); ///* Prints all the members and values of members on screen.
00645 }
00646 void OPT3101::frameData::printHeader()
00647 {
00648     /// <b>Algorithm of the method is as follows</b>
00649     host.printfSetColor(0b001);
00650     host.printf("Phase,");
00651     host.printf("Amplt,");
00652     host.printf("SigOl,");
00653     host.printf("AmbOl,");
00654     host.printf("Amb,");
00655     host.printf("tMain,");
00656     host.printf("tIlum,");
00657     host.printf("tMain(C),");
00658     host.printf("  tIlum(C)\r\n");
00659     host.printfSetColor(0xFF);
00660 }
00661 
00662 
00663 void OPT3101::frameData::print()
00664 {
00665     /// <b>Algorithm of the method is as follows</b>
00666     host.printfSetColor(0b001);
00667     host.printf("%05u,",this->phase);
00668     host.printf("%05u,",this->amplitude);
00669     host.printf("    %1u,",this->sigovl);
00670     host.printf("    %1u,",this->ambovl);
00671     host.printf("%03u,",this->ambient);
00672     host.printf(" %04d,",this->tmain);
00673     host.printf(" %04d,",this->tillum);
00674     host.printf("     %+03d,",(int8_t) ((((int16_t)this->tmain)>>3)-256));
00675     host.printf(" %+07.4f\r\n",((double)(((int16_t)this->tillum)-2048))/16.0);
00676     host.printfSetColor(0xFF);
00677 }
00678 
00679 
00680 void OPT3101::frameData::populateWithMean(OPT3101::frameData *inputData, uint16_t nFrames)
00681 {
00682     uint16_t c0;
00683     uint16_t shiftBits;
00684     uint32_t accum;
00685     /// <b>Algorithm of the method is as follows</b>
00686     shiftBits = 0;
00687     nFrames = nFrames == 0 ? 1 : nFrames; ///* Sets nFrames to 1 when nFrames is 0
00688     if(nFrames>1)
00689         while (((nFrames-1) >> ++shiftBits) > 0); ///* Finds the smallest 2^N number higher than the nFrames provided in the argument of this method
00690     else
00691 
00692 
00693 
00694     // All flags
00695     this->phaseovl = 0;
00696     this->phaseovlf2 = 0;
00697     this->ambovl = 0;
00698     this->illumDac = inputData[0].illumDac;
00699     this->ledChannel = inputData[0].ledChannel;
00700     this->frameStatus = 0;
00701     this->dealiasFreq = inputData[0].dealiasFreq;
00702     this->sigovl = 0;
00703     this->dealiasBin = inputData[0].dealiasBin;
00704     this->frameCounter = 0;
00705 
00706     for (c0 = 0; c0 < nFrames; c0++) {
00707         this->phaseovl |= inputData[0].phaseovl;
00708         this->phaseovlf2 |= inputData[0].phaseovlf2;
00709         this->ambovl |= inputData[0].ambovl;
00710         this->sigovl |= inputData[0].sigovl;
00711     }
00712     
00713     
00714     // Mean of phase if found
00715     accum = 0; ///* Accumulates and measures mean for all the input class instance members and assigns them to the method's class members 
00716     for (c0 = 0; c0 < nFrames; c0++)
00717         accum += inputData[c0].phase;
00718     this->phase = accum >> shiftBits;
00719 
00720     // Mean of amplitude is found
00721     accum = 0;
00722     for (c0 = 0; c0 < nFrames; c0++)
00723         accum += inputData[c0].amplitude;
00724     this->amplitude = accum >> shiftBits;
00725     
00726     // Mean of ambient is found
00727     accum = 0;
00728     for (c0 = 0; c0 < nFrames; c0++)
00729         accum += inputData[c0].ambient;
00730     this->ambient = accum >> shiftBits;
00731 
00732     // Mean of temp is found
00733     accum = 0;
00734     for (c0 = 0; c0 < nFrames; c0++)
00735         accum += inputData[c0].temp;
00736     this->temp = accum >> shiftBits;
00737 
00738     // Mean of tmain is found
00739     accum = 0;
00740     for (c0 = 0; c0 < nFrames; c0++) 
00741         accum += inputData[c0].tmain;
00742 
00743     this->tmain = accum >> shiftBits;
00744 
00745     // Mean of tillum is found
00746     accum = 0;
00747     for (c0 = 0; c0 < nFrames; c0++)
00748         accum += inputData[c0].tillum;
00749     this->tillum = accum >> shiftBits;
00750     ///* <b>Warning:</b> When nFrames is a non 2^N number the mean results are expected to be lower than actual measurements
00751 
00752 }
00753 
00754 #ifdef OPT3101_USE_STREAMLIB
00755 std::ostream & OPT3101::operator<<(std::ostream & os, const OPT3101::frameData * data)
00756 {
00757     /// <b>Algorithm of the method is as follows</b>
00758     os << data->phase << '\n'; ///* Serializes all the members and returns to the stream 
00759     os << data->phaseovl << '\n';
00760     os << data->phaseovlf2 << '\n';
00761     os << data->ambovl << '\n';
00762     os << data->illumDac << '\n';
00763     os << data->ledChannel << '\n';
00764     os << data->frameStatus << '\n';
00765     os << data->dealiasFreq << '\n';
00766     os << data->frameCounter << '\n';
00767     os << data->amplitude << '\n';
00768     os << data->sigovl << '\n';
00769     os << data->dealiasBin << '\n';
00770     os << data->temp << '\n';
00771     os << data->tmain << '\n';
00772     os << data->tillum << '\n';
00773     return os;
00774 }
00775 #endif
00776 
00777 #ifdef OPT3101_USE_STREAMLIB
00778 std::istream & OPT3101::operator>>(std::istream & is, OPT3101::frameData * data)
00779 {
00780     /// <b>Algorithm of the method is as follows</b>
00781     is >> data->phase; ///* Serializes all the members and returns to the stream 
00782     is >> data->phaseovl;
00783     is >> data->phaseovlf2;
00784     is >> data->ambovl;
00785     is >> data->illumDac;
00786     is >> data->ledChannel;
00787     is >> data->frameStatus;
00788     is >> data->dealiasFreq;
00789     is >> data->frameCounter;
00790     is >> data->amplitude;
00791     is >> data->sigovl;
00792     is >> data->dealiasBin;
00793     is >> data->temp;
00794     is >> data->tmain;
00795     is >> data->tillum;
00796 
00797     return is;
00798 
00799 }
00800 #endif
00801 
00802 #ifdef OPT3101_USE_STDIOLIB
00803 void OPT3101::frameData::storeToFile(char * fileName)
00804 {
00805 #ifdef OPT3101_USE_STREAMLIB
00806     /// <b>Algorithm of the method is as follows</b>
00807     std::ofstream ofs(fileName);
00808     ofs << this;
00809     ofs.close(); ///* User needs to implement file storage based on host. 
00810 #endif
00811 }
00812 #endif
00813 
00814 #ifdef OPT3101_USE_STDIOLIB
00815 void OPT3101::frameData::loadFromFile(char * fileName)
00816 {
00817 #ifdef OPT3101_USE_STREAMLIB
00818     /// <b>Algorithm of the method is as follows</b>
00819     std::ifstream ifs(fileName);
00820     ifs >> this;
00821     ifs.close(); ///* User needs to implement file load/restore based on host. 
00822 #endif
00823 }
00824 #endif
00825 
00826 void OPT3101::device::measurePhaseOffsetSet(bool saveToFile) {
00827     uint8_t c0, c1;
00828     uint16_t flashLocation;
00829     uint16_t refDistanceInCodes;
00830     uint32_t refDistanceInMM;
00831 
00832 #ifdef OPT3101_USE_STDIOLIB
00833     char fileName[FILENAME_LENGTH];
00834 #endif
00835 
00836     envController.manuallySetReferenceDistances();
00837 
00838     // Loop to iterate over all TX channels
00839     for (c0 = 0; c0 < 3; c0++) { ///* Loops though all the valid TX channel and register set configurations
00840         if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile
00841             for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers
00842                 if (this->configurationFlags_isRegisterSetActive[c1]) { // Checking if registers are active for this profile
00843                     refDistanceInMM=envController.refDistancesInMM[c0][c1];
00844                     envController.setTargetDistance(refDistanceInMM); ///* Calls environmentalController::setTargetDistance method with the specified distance
00845                     refDistanceInCodes = (refDistanceInMM * 4477) >> 10; ///* Converts the reference distance specified in codes related to OPT3101::frameData::phase ADC codes
00846                     host.printf("INFO:Performing Phase Offset for TX%d HDR %d @ ref Distance %dmm\r\n",c0,c1,refDistanceInMM);
00847                     this->measurePhaseOffset(&this->calibration->phaseOffset[c0][c1], c0, c1 ? 'h' : 'l', refDistanceInCodes); ///* Measures phase offset by calling method OPT3101::device::measurePhaseOffset with specified reference distance and OPT3101::calibrationC::phaseOffset as argument to store the phase offset values
00848                     this->calibration->phaseOffset[c0][c1].printHeader();
00849                     this->calibration->phaseOffset[c0][c1].print();
00850                     host.printf("\r\n");
00851 
00852                     if(saveToFile){
00853 #ifdef OPT3101_USE_STDIOLIB
00854                         sprintf(fileName, "%s/phaseOffset_TX%d_%c.txt", filePath, c0, c1 ? 'h' : 'l'); ///* Creates filename  illumCrosstalk_TX{channel}_{h/l}.txt in path filePath
00855                         this->calibration->phaseOffset[c0][c1].storeToFile(fileName);  ///* Calls method OPT3101::crosstalkC::storeToFile to store the data
00856 #endif
00857 #ifdef TIMSP430F5529_LAUNCHPAD_CALIBRATION_TOOL
00858                         flashLocation=96+36*((c0<<1)+c1);
00859                         // TODO fix this flash host.flash.write(flashLocation, (uint8_t*)&this->calibration->phaseOffset[c0][c1] ,36);
00860                         host.printf("INFO:Writing Phase Offset for TX%d HDR %d to Flash location 0x%04x\r\n",c0,c1,flashLocation);
00861 #endif // TIHOST
00862                     }
00863                 }
00864             }
00865         }
00866     }
00867 
00868 }
00869 
00870 
00871 void OPT3101::device::measurePhaseOffset(OPT3101::phaseOffsetC *phaseOffset,uint16_t refDistanceInCodes) {
00872     OPT3101::frameData data[32], meanData;
00873     uint16_t nFrames;
00874     int32_t phaseOffsetRegister;
00875     uint16_t c0;
00876     /// <b>Algorithm of the method is as follows</b>
00877     nFrames = 1 << (this->configurationFlags_avgFrameCountExponentOfTwo <= 5 ? 5 - this->configurationFlags_avgFrameCountExponentOfTwo : 0); ///* Calculates number of frames to average the data. Based on the OPT3101::device::configurationFlags_avgFrameCountExponentOfTwo number of average is decided. More frames are captured and averaged if device configuration has low average frames and vice versa
00878     //data = new OPT3101::frameData[nFrames];
00879     for (c0 = 0; c0<nFrames; c0++)
00880         data[c0].capture(&host, this); ///* Captures all calculated number of frames from the h/w using OPT3101::frameData::capture method
00881 
00882     meanData.populateWithMean(&data[0], nFrames);  ///* Measures the mean of the captured frames OPT3101::frameData::populateWithMean method
00883     phaseOffsetRegister = (int32_t) (meanData.phase - refDistanceInCodes);  ///* Calculates the actual phase offset register value based on the input argument refDistanceInCodes and measured phase OPT3101::frameData::phase (mean over captured frames)
00884     phaseOffset->freqCount = this->reg.freq_count_read_reg.read(); ///* Captures snapshot of register value OPT3101::registers::freq_count_read_reg and assigns to input argument phaseOffset's OPT3101::phaseOffsetC::freqCount
00885     if (phaseOffset->freqCount > 0)
00886         phaseOffsetRegister = (int32_t)((phaseOffsetRegister * 16384) / phaseOffset->freqCount); ///* Scales phase offset value with OPT3101::phaseOffsetC::freqCount value 
00887     else
00888         phaseOffsetRegister = 0;
00889 
00890     phaseOffset->phaseOffset = (uint16_t)(phaseOffsetRegister & 0xFFFF); ///* Assigns input argument phaseOffset's  OPT3101::phaseOffsetC::phaseOffset with scaled register value
00891 
00892     phaseOffset->data = meanData; ///* Captures the calculated mean OPT3101::frameData to OPT3101::phaseOffsetC::data
00893     phaseOffset->referenceDistanceInCodes = refDistanceInCodes;  ///* Captures the snapshot of input argument refDistanceInCodes to the input argument phaseOffset's OPT3101::phaseOffsetC::referenceDistanceInCodes
00894 }
00895 
00896 void OPT3101::device::measurePhaseOffset(OPT3101::phaseOffsetC *phaseOffset, uint8_t txChannel, char registerSet, uint16_t refDistanceInCodes,uint8_t shiftIllumPhase) {
00897     uint8_t regStore[14];
00898     uint8_t dummy;
00899 
00900     /// <b>Algorithm of the method is as follows</b>
00901     regStore[0] = this->reg.en_sequencer.read();
00902     regStore[1] = this->reg.en_processor_values.read();
00903     regStore[2] = this->reg.sel_hdr_mode.read();
00904     regStore[3] = this->reg.sel_tx_ch.read();
00905     regStore[4] = this->reg.en_adaptive_hdr.read();
00906     regStore[5] = this->reg.en_tx_switch.read();
00907     regStore[6] = this->reg.en_phase_corr.read();
00908     regStore[7] = this->reg.en_nl_corr.read();
00909     regStore[8] = this->reg.en_temp_corr.read();
00910     regStore[9] = this->reg.amb_phase_corr_pwl_coeff0.read();
00911     regStore[10] = this->reg.amb_phase_corr_pwl_coeff1.read();
00912     regStore[11] = this->reg.amb_phase_corr_pwl_coeff2.read();
00913     regStore[12] = this->reg.amb_phase_corr_pwl_coeff3.read();
00914     regStore[13] = this->reg.shift_illum_phase.read(); ///* Critical registers which are modified in this method are read from the h/w and temporarily buffered to local variables.
00915 
00916 
00917     this->reg.tg_en = 0;
00918     this->reg.en_sequencer = 0;
00919     this->reg.en_processor_values = 0;
00920     if (registerSet == 'h')
00921         this->reg.sel_hdr_mode = 1; ///* Register set is chosen based on registerSet input to this method by setting OPT3101::registers::sel_hdr_mode
00922     if (registerSet == 'l')
00923         this->reg.sel_hdr_mode = 0;
00924     this->reg.sel_tx_ch = txChannel; ///* TX channel is chosen based on txChannel input to this method by setting OPT3101::registers::sel_tx_ch
00925     this->reg.en_tx_switch = 0;
00926     this->reg.en_adaptive_hdr = 0;
00927     this->reg.en_phase_corr = 0;
00928     this->reg.en_nl_corr = 0;
00929     this->reg.en_temp_corr = 0;
00930     this->reg.amb_phase_corr_pwl_coeff0 = 0;
00931     this->reg.amb_phase_corr_pwl_coeff1 = 0;
00932     this->reg.amb_phase_corr_pwl_coeff2 = 0;
00933     this->reg.amb_phase_corr_pwl_coeff3 = 0;
00934     this->reg.shift_illum_phase = shiftIllumPhase; ///* Sets up the OPT3101::registers::shift_illum_phase based on the input to this method shiftIllumPhase
00935     this->reg.tg_en = 1;
00936 
00937     this->measurePhaseOffset(phaseOffset, refDistanceInCodes); ///* Measures phase offset with following steps
00938     // Added dummy lines so that Doxygen can recognize these multi-line comments
00939     dummy = 0; ///* Calculates number of frames to average the data. Based on the OPT3101::device::configurationFlags_avgFrameCountExponentOfTwo number of average is decided. More frames are captured and averaged if device configuration has low average frames and vice versa
00940     dummy = 0; ///* Captures all calculated number of frames from the h/w using OPT3101::frameData::capture method
00941     dummy = 0; ///* Measures the mean of the captured frames OPT3101::frameData::populateWithMean method
00942     dummy = 0; ///* Calculates the actual phase offset register value based on the input argument refDistanceInCodes and measured phase OPT3101::frameData::phase (mean over captured frames)
00943     dummy = 0; ///* Captures snapshot of register value OPT3101::registers::freq_count_read_reg and assigns to input argument phaseOffset's OPT3101::phaseOffsetC::freqCount
00944     dummy = 0; ///* Scales phase offset value with OPT3101::phaseOffsetC::freqCount value
00945     dummy = 0; ///* Assigns input argument phaseOffset's  OPT3101::phaseOffsetC::phaseOffset with scaled register value
00946     dummy = 0; ///* Captures the calculated mean OPT3101::frameData to OPT3101::phaseOffsetC::data
00947     dummy = 0; ///* Captures the snapshot of input argument refDistanceInCodes to the input argument phaseOffset's OPT3101::phaseOffsetC::referenceDistanceInCodes
00948 
00949     phaseOffset->shiftIllumPhase = shiftIllumPhase;
00950     phaseOffset->illumDCdac = this->reg.ILLUM_DC_CURR_DAC.read();
00951     switch (txChannel) { ///* Captures the snapshot of the illum dac, illum DC and illum scale settings form h/w to the phaseOffset input argument 
00952     case 0:
00953         if (registerSet == 'h') {
00954             phaseOffset->illumDac = this->reg.illum_dac_h_tx0.read();
00955             phaseOffset->illumScale = this->reg.illum_scale_h_tx0.read();
00956         }
00957         else if (registerSet == 'l') {
00958             phaseOffset->illumDac = this->reg.illum_dac_l_tx0.read();
00959             phaseOffset->illumScale = this->reg.illum_scale_l_tx0.read();
00960         }
00961         break;
00962     case 1:
00963         if (registerSet == 'h') {
00964             phaseOffset->illumDac = this->reg.illum_dac_h_tx1.read();
00965             phaseOffset->illumScale = this->reg.illum_scale_h_tx1.read();
00966         }
00967         else if (registerSet == 'l') {
00968             phaseOffset->illumDac = this->reg.illum_dac_l_tx1.read();
00969             phaseOffset->illumScale = this->reg.illum_scale_l_tx1.read();
00970         }
00971         break;
00972     case 2:
00973         if (registerSet == 'h') {
00974             phaseOffset->illumDac = this->reg.illum_dac_h_tx2.read();
00975             phaseOffset->illumScale = this->reg.illum_scale_h_tx2.read();
00976         }
00977         else if (registerSet == 'l') {
00978             phaseOffset->illumDac = this->reg.illum_dac_l_tx2.read();
00979             phaseOffset->illumScale = this->reg.illum_scale_l_tx2.read();
00980         }
00981         break;
00982     default:
00983         break;
00984     }
00985 
00986     this->reg.tg_en = 0;
00987     this->reg.en_sequencer = regStore[0];
00988     this->reg.en_processor_values = regStore[1];
00989     this->reg.sel_hdr_mode = regStore[2];
00990     this->reg.sel_tx_ch = regStore[3];
00991     this->reg.en_adaptive_hdr = regStore[4];
00992     this->reg.en_tx_switch = regStore[5];
00993     this->reg.en_phase_corr = regStore[6];
00994     this->reg.en_nl_corr = regStore[7];
00995     this->reg.en_temp_corr = regStore[8];
00996     this->reg.amb_phase_corr_pwl_coeff0 = regStore[9];
00997     this->reg.amb_phase_corr_pwl_coeff1 = regStore[10];
00998     this->reg.amb_phase_corr_pwl_coeff2 = regStore[11];
00999     this->reg.amb_phase_corr_pwl_coeff3 = regStore[12];
01000     this->reg.shift_illum_phase = regStore[13]; ///* Restores the device state to the same state as before entering this method from the buffered local variables
01001     this->reg.tg_en = 1;
01002 
01003 }
01004 
01005 void OPT3101::device::writeDataToEEPROM(uint8_t location, uint8_t data) {
01006     this->reg.i2c_write_data1 = location;
01007     this->reg.i2c_write_data2 = data;
01008     this->reg.i2c_trig_reg = 1;
01009     host.sleep(1); ///* Added delay to initiate an I2C write transaction
01010     this->reg.i2c_trig_reg = 0;
01011     host.sleep(1); ///* Added delay to initiate an I2C write transaction
01012 }
01013 
01014 uint8_t OPT3101::device::readDataFromEEPROM(uint8_t location) {
01015 /* Will be updated in future revision of the SDK
01016     this->reg.i2c_write_data1 = location;
01017     this->reg.i2c_trig_reg = 1;
01018     host.sleep(50); ///* Added delay to initiate an I2C write transaction
01019     this->reg.i2c_trig_reg = 0;
01020     host.sleep(50); ///* Added delay to initiate an I2C write transaction
01021     return ((uint8_t) (this->reg.i2c_read_data.read()&0xFF));
01022 */
01023     return 0x00;
01024 }
01025 
01026 void OPT3101::device::loadIllumCrosstalkSet(bool loadFromFile)
01027 {
01028     uint8_t c0, c1;
01029     uint16_t flashLocation;
01030     /// <b>Algorithm of the method is as follows</b>
01031 #ifdef OPT3101_USE_STDIOLIB
01032     char fileName[FILENAME_LENGTH];
01033 #endif
01034     host.printf("INFO::Loading Illumination cross talk Set\r\n");
01035 
01036     // Loop to iterate over all TX channels
01037     if(loadFromFile){ ///* Checks if input argument loadFromFile is true. If true proceeds to load files in to  OPT3101::device::calibration
01038         for (c0 = 0; c0 < 3; c0++) {  ///* Loops though all the valid TX channel and register set configurations
01039             if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile 
01040                 for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers 
01041                     if (this->configurationFlags_isRegisterSetActive[c1]) { // Checking if registers are active for this profile
01042 #ifdef OPT3101_USE_STDIOLIB
01043                         sprintf(fileName, "%s/illumCrosstalk_TX%d_%c.txt", filePath, c0, c1 ? 'h' : 'l');
01044                         this->calibration->illumCrosstalk[c0][c1].loadFromFile(fileName);  ///* Calls method OPT3101::crosstalkC::loadFromFile to load data from non-volatile memory to all the OPT3101::device::calibration::illumCrosstalk members
01045 #endif
01046 #ifdef TIMSP430F5529_LAUNCHPAD_CALIBRATION_TOOL
01047                         flashLocation=(c1+(c0<<1))<<4;
01048                         // TODO fix this host.flash.read(flashLocation, (uint8_t*)&this->calibration->illumCrosstalk[c0][c1] ,16);
01049                         host.printf("INFO:Reading Illum Cross talk from Flash location 0x%04x\r\n",flashLocation);
01050 #endif
01051                         this->calibration->illumCrosstalk[c0][c1].printHeader();
01052                         this->calibration->illumCrosstalk[c0][c1].print();
01053                         host.printf("\r\n");
01054 
01055                     }
01056                 }
01057             }
01058         }
01059     }
01060 
01061     this->calibration->findCommonCrosstalkScale(&this->calibration->illumCrosstalk[0][0], this->configurationFlags_isTXChannelActive,this->configurationFlags_isTXChannelActive); ///* Finds common crosstalk scale for the illum Crosstalk values captured in OPT3101::device::calibrationC using method OPT3101::calibrationC::findCommonCrosstalkScale
01062     // Loop to iterate over all TX channels
01063     for (c0 = 0; c0 < 3; c0++) {  ///* Loops though all the valid TX channel and register set configurations
01064         if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile 
01065             for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers 
01066                 if (this->configurationFlags_isRegisterSetActive[c1])  // Checking if registers are active for this profile
01067                     this->loadIllumCrosstalk(&this->calibration->illumCrosstalk[c0][c1], c0, c1 ? 'h' : 'l'); ///* Loads all the illum crosstalk corresponding to TX and register set configurations to the device from the OPT3101::device::calibrationC::illumCrosstalk member by calling OPT3101::device::loadIllumCrosstalk
01068             }
01069         }
01070     }
01071 }
01072 
01073 void OPT3101::device::loadPhaseOffsetSet(bool loadFromFile)
01074 {
01075     uint8_t c0, c1;
01076     uint16_t flashLocation;
01077 #ifdef OPT3101_USE_STDIOLIB
01078     char fileName[FILENAME_LENGTH];
01079 #endif
01080     host.printf("INFO::Loading Phase Offset Set\r\n");
01081 
01082     /// <b>Algorithm of the method is as follows</b>
01083     // Loop to iterate over all TX channels
01084     
01085     if(loadFromFile){
01086         for (c0 = 0; c0 < 3; c0++) { ///* Loops though all the valid TX channel and register set configurations
01087             if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile
01088                 for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers
01089                     if (this->configurationFlags_isRegisterSetActive[c1]) { // Checking if registers are active for this profile
01090     #ifdef OPT3101_USE_STDIOLIB
01091                         sprintf(fileName, "%s/phaseOffset_TX%d_%c.txt", filePath, c0, c1 ? 'h' : 'l'); ///* Creates filename  illumCrosstalk_TX{channel}_{h/l}.txt in path filePath
01092                         this->calibration->phaseOffset[c0][c1].loadFromFile(fileName);  ///* Calls method OPT3101::crosstalkC::loadFromFile to store the data
01093     #endif
01094     #ifdef TIMSP430F5529_LAUNCHPAD_CALIBRATION_TOOL
01095                         flashLocation = 96 + 36 * ((c0 << 1) + c1);
01096                         // TODo Fix this host.flash.read(flashLocation, (uint8_t*)&this->calibration->phaseOffset[c0][c1], 36);
01097                         host.printf("INFO:Reading Phase Offset from TX%d HDR %d to Flash location 0x%04x\r\n", c0, c1, flashLocation);
01098     #endif // TIHOST
01099                         this->calibration->phaseOffset[c0][c1].printHeader();
01100                         this->calibration->phaseOffset[c0][c1].print();
01101                         host.printf("\r\n");
01102                     }
01103                 }
01104             }
01105         }
01106     }
01107     
01108     for (c0 = 0; c0 < 3; c0++) { ///* Loops though all the valid TX channel and register set configurations
01109         if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile 
01110             for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers 
01111                 if (this->configurationFlags_isRegisterSetActive[c1]) // Checking if registers are active for this profile
01112                     this->loadPhaseOffset(&this->calibration->phaseOffset[c0][c1], c0, c1 ? 'h' : 'l'); ///* Loads all the phase offset corresponding to TX and register set configurations to the device from the OPT3101::device::calibrationC::phaseOffset member by calling OPT3101::device::loadPhaseOffset
01113             }
01114         }
01115     }
01116 }
01117 
01118 uint8_t OPT3101::device::determineConfigCount() {
01119     return this->calibration->recordLength;
01120 }
01121 
01122 void OPT3101::device::loadIllumCrosstalkTempCoffSet()
01123 {
01124     uint8_t c0, c1;
01125 
01126     host.printf("INFO::Loading Illumination crosstalk Temperature Coefficient Set\r\n");
01127     this->loadIllumCrosstalkSet(true); ///* Calls OPT3101::device::loadIllumCrosstalkSet with the same loafFromFile flag specified to this method
01128     this->calibration->findCrosstalkTempRegisterValues(&this->calibration->illumCrosstalkTempCoff[0][0], this->configurationFlags_isTXChannelActive,this->configurationFlags_isTXChannelActive, &this->calibration->illumCrosstalk[0][0]); ///* Calls OPT3101::calibrationC::findCrosstalkTempRegisterValues based on the members from OPT3101::calibrationC class OPT3101::calibrationC::illumCrosstalkTempCoff and OPT3101::calibrationC::illumCrosstalk
01129     // Loop to iterate over all TX channels
01130     for (c0 = 0; c0 < 3; c0++) { ///* Loops though all the valid TX channel and register set configurations
01131         if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile 
01132             for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers 
01133                 if (this->configurationFlags_isRegisterSetActive[c1]) // Checking if registers are active for this profile
01134                     this->loadIllumCrosstalkTempCoff(&this->calibration->illumCrosstalkTempCoff[c0][c1], c0, c1 ? 'h' : 'l'); ///* Calls the method OPT3101::device::loadIllumCrosstalkTempCoff to load all the crosstalk temp coff values from the OPT3101::calibrationC::illumCrosstalkTempCoff member
01135             }
01136         }
01137     }
01138     this->reg.en_temp_xtalk_corr=1;
01139 }
01140 
01141 void OPT3101::device::loadPhaseOffsetTempCoffSet() {
01142     uint8_t c0, c1;
01143 
01144     host.printf("INFO::Loading Phase Temperature coefficient Set\r\n");
01145     this->calibration->findPhaseTempRegisterValues(&this->calibration->phaseTempCoff[0][0], this->configurationFlags_isTXChannelActive,this->configurationFlags_isTXChannelActive, this->reg.freq_count_read_reg.read()); ///* Calls OPT3101::calibrationC::findPhaseTempRegisterValues based on the members from OPT3101::calibrationC class OPT3101::calibrationC::phaseTempCoff and current device register OPT3101::registers::freq_count_read_reg
01146 
01147     // Loop to iterate over all TX channels
01148     for (c0 = 0; c0 < 3; c0++) { ///* Loops though all the valid TX channel and register set configurations
01149         if (this->configurationFlags_isTXChannelActive[c0]) { // Checking is TX channel is active for this profile 
01150             for (c1 = 0; c1 < 2; c1++) { // Loop to iterate over the H/L registers 
01151                 if (this->configurationFlags_isRegisterSetActive[c1]) // Checking if registers are active for this profile
01152                     this->loadPhaseOffsetTempCoff(&this->calibration->phaseTempCoff[c0][c1], c0, c1 ? 'h' : 'l');  ///* Calls the method OPT3101::device::loadPhaseOffsetTempCoff to load all the phase temp coff values from the OPT3101::calibrationC::phaseTempCoff member
01153             }
01154         }
01155     }
01156 }
01157 
01158 void OPT3101::device::loadPhaseAmbientCoffSet()
01159 {
01160     host.printf("INFO::Loading Phase Ambient Coefficient Set\r\n");
01161     this->calibration->phaseAmbientCoff[0].calculateCoff(this->reg.freq_count_read_reg.read()); ///* Calculates the phase ambient coff by calling method OPT3101::phaseAmbientCoffC::calculateCoff also passing argument of device register OPT3101::registers::freq_count_read_reg
01162     this->loadPhaseAmbientCoff(&this->calibration->phaseAmbientCoff[0]); ///* Calls method OPT3101::device::loadPhaseAmbientCoff to load ambient coff to device from OPT3101::calibrationC::phaseAmbientCoff member
01163 }
01164 
01165 void OPT3101::calibrationC::findCommonCrosstalkScale(OPT3101::crosstalkC* illumXtalk, bool *txActiveList,bool *registerSetActiveList) {
01166     uint8_t maxScale, c0,c1;
01167     maxScale = 0;
01168     /// <b>Algorithm of the method is as follows</b>
01169     for (c0 = 0; c0 < 3; c0++) {
01170         for (c1 = 0; c1 < 2; c1++){
01171             if(txActiveList[c0] && registerSetActiveList[c1])
01172                 maxScale = illumXtalk[(c0<<1)+c1].xtalkScale > maxScale ? illumXtalk[(c0<<1)+c1].xtalkScale : maxScale; ///* Finds the largest scale what will fit all the input OPT3101::crosstalkC arguments
01173         }
01174     }
01175     for (c0 = 0; c0 < 3; c0++) {
01176         for (c1 = 0; c1 < 2; c1++){
01177             if(txActiveList[c0] && registerSetActiveList[c1])
01178                 illumXtalk[(c0<<1)+c1].commonScale = maxScale; ///* Assigns the identified maxScale to all the input argument illum Crosstalk pointers OPT3101::crosstalkC
01179         }
01180     }
01181 }
01182 
01183 OPT3101::calibrationC::calibrationC(bool dummyFlag) {
01184     /// <b>Algorithm of the method is as follows</b>
01185     ///* Allocates memory for OPT3101::calibrationC::internalCrosstalk size based on system configuration 
01186     ///* Allocates memory for OPT3101::calibrationC::illumCrosstalk size based on system configuration 
01187     ///* Allocates memory for OPT3101::calibrationC::phaseOffset size based on system configuration 
01188     ///* Allocates memory for OPT3101::calibrationC::illumCrosstalkTempCoff size based on system configuration 
01189     ///* Allocates memory for OPT3101::calibrationC::phaseTempCoff size based on system configuration 
01190     ///* Allocates memory for OPT3101::calibrationC::phaseAmbientCoff size based on system configuration 
01191     ///* Sets the member OPT3101::calibrationC::registerAddressListSize based on number of calibration registers requires 
01192     ///* Allocates memory for OPT3101::calibrationC::registerAddressList based on  OPT3101::calibrationC::registerAddressListSize
01193     ///* Sets up the flag OPT3101::calibrationC::EEPROM_connected based on configuration
01194     ///* Sets up the flag OPT3101::calibrationC::extTempSensor_connected based on configuration
01195 }
01196