New Version with OS5

Committer:
tgrosch
Date:
Sun Oct 25 10:45:04 2020 +0000
Revision:
3:0eb6a9927171
Parent:
0:62b846b3988a
New version with OS5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tgrosch 0:62b846b3988a 1 /*!
tgrosch 0:62b846b3988a 2 * \file OPT3101Crosstalk.cpp
tgrosch 0:62b846b3988a 3 * \author Karthik Rajagopal <krthik@ti.com>
tgrosch 0:62b846b3988a 4 * \version 0.9.1
tgrosch 0:62b846b3988a 5 *
tgrosch 0:62b846b3988a 6 * \section COPYRIGHT
tgrosch 0:62b846b3988a 7 * TEXAS INSTRUMENTS TEXT FILE LICENSE
tgrosch 0:62b846b3988a 8 * Copyright (c) 2018 Texas Instruments Incorporated
tgrosch 0:62b846b3988a 9 * All rights reserved not granted herein.
tgrosch 0:62b846b3988a 10 * Limited License.
tgrosch 0:62b846b3988a 11 * 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.
tgrosch 0:62b846b3988a 12 * 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
tgrosch 0:62b846b3988a 13 * Redistribution and use in binary form, without modification, are permitted provided that the following conditions are met:
tgrosch 0:62b846b3988a 14 * * No reverse engineering, decompilation, or disassembly of this software is permitted with respect to any software provided in binary form.
tgrosch 0:62b846b3988a 15 * * any redistribution and use are licensed by TI for use only with TI Devices.
tgrosch 0:62b846b3988a 16 * * Nothing shall obligate TI to provide you with source code for the software licensed and provided to you in object code.
tgrosch 0:62b846b3988a 17 * If software source code is provided to you, modification and redistribution of the source code are permitted provided that the following conditions are met:
tgrosch 0:62b846b3988a 18 * * any redistribution and use of the source code, including any resulting derivative works, are licensed by TI for use only with TI Devices.
tgrosch 0:62b846b3988a 19 * * 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.
tgrosch 0:62b846b3988a 20 * 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.
tgrosch 0:62b846b3988a 21 * DISCLAIMER.
tgrosch 0:62b846b3988a 22 * 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.
tgrosch 0:62b846b3988a 23 *
tgrosch 0:62b846b3988a 24 * \section DESCRIPTION
tgrosch 0:62b846b3988a 25 * The file contains class OPT3101::crosstalkC member function definitions
tgrosch 0:62b846b3988a 26 */
tgrosch 0:62b846b3988a 27 #include <stdlib.h>
tgrosch 0:62b846b3988a 28 #include <math.h>
tgrosch 0:62b846b3988a 29 #include "OPT3101Crosstalk.h"
tgrosch 0:62b846b3988a 30 #include "hostController.h"
tgrosch 0:62b846b3988a 31 #include "OPT3101device.h"
tgrosch 0:62b846b3988a 32
tgrosch 0:62b846b3988a 33
tgrosch 0:62b846b3988a 34 OPT3101::crosstalkC::crosstalkC(){
tgrosch 0:62b846b3988a 35 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 36 this->I = 0;
tgrosch 0:62b846b3988a 37 this->Q = 0;
tgrosch 0:62b846b3988a 38 this->xtalkScale = 0;
tgrosch 0:62b846b3988a 39 this->illumScale = 0;
tgrosch 0:62b846b3988a 40 this->illumDac = 0;
tgrosch 0:62b846b3988a 41 this->illumDCdac = 0;
tgrosch 0:62b846b3988a 42 this->tmain = 0;
tgrosch 0:62b846b3988a 43 this->tillum = 0;
tgrosch 0:62b846b3988a 44 this->shiftIllumPhase = 0;
tgrosch 0:62b846b3988a 45 this->commonScale = 0;
tgrosch 0:62b846b3988a 46 this->illumXtalk=false; ///* sets OPT3101::crosstalkC::illumXtalk to false by default
tgrosch 0:62b846b3988a 47 }
tgrosch 0:62b846b3988a 48
tgrosch 0:62b846b3988a 49 void OPT3101::crosstalkC::readCrosstalkRegisters(OPT3101::device *dev){
tgrosch 0:62b846b3988a 50 int32_t iRead,qRead;
tgrosch 0:62b846b3988a 51 uint32_t mRead;
tgrosch 0:62b846b3988a 52 uint8_t c0;
tgrosch 0:62b846b3988a 53
tgrosch 0:62b846b3988a 54 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 55 iRead=((int32_t) (dev->reg.iphase_xtalk.read()<<8))>>8; ///* Reads register OPT3101::registers::iphase_xtalk in 24 bit from and converts to signed number
tgrosch 0:62b846b3988a 56 qRead=((int32_t) (dev->reg.qphase_xtalk.read()<<8))>>8; ///* Reads register OPT3101::registers::qphase_xtalk in 24 bit from and converts to signed number
tgrosch 0:62b846b3988a 57 mRead=abs(iRead)>abs(qRead)?abs(iRead):abs(qRead); ///* Finds absolute max among the read I and Q register values to determine the OPT3101::crosstalkC::illumXtalk
tgrosch 0:62b846b3988a 58
tgrosch 0:62b846b3988a 59 this->xtalkScale = 0;
tgrosch 0:62b846b3988a 60 for (c0 = 15; c0 < 23; c0++) {
tgrosch 0:62b846b3988a 61 if (mRead > (((uint32_t)1) << c0) && mRead <= (((uint32_t)1) << (c0 + 1))){
tgrosch 0:62b846b3988a 62 this->xtalkScale = c0-14; // replaced c0+1-15 due to weird problem
tgrosch 0:62b846b3988a 63 break;
tgrosch 0:62b846b3988a 64 }
tgrosch 0:62b846b3988a 65 }
tgrosch 0:62b846b3988a 66
tgrosch 0:62b846b3988a 67 ///* Determines OPT3101::crosstalkC::illumXtalk and assigns. The algorithm finds the minimum OPT3101::crosstalkC::illumXtalk value for which the raw I and Q registers can be fit to a 16 bit register
tgrosch 0:62b846b3988a 68 this->I=(int16_t) (iRead>>this->xtalkScale); ///* Scales down the 24 bit raw register I and Q values with OPT3101::crosstalkC::illumXtalk and assigns to OPT3101::crosstalkC::I and OPT3101::crosstalkC::Q
tgrosch 0:62b846b3988a 69 this->Q=(int16_t) (qRead>>this->xtalkScale);
tgrosch 0:62b846b3988a 70 }
tgrosch 0:62b846b3988a 71
tgrosch 0:62b846b3988a 72 double OPT3101::crosstalkC::magnitude(){
tgrosch 0:62b846b3988a 73 double amplitude, xTalkI, xTalkQ;
tgrosch 0:62b846b3988a 74 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 75 xTalkI = this->I>>(9-this->xtalkScale);
tgrosch 0:62b846b3988a 76 xTalkQ = this->Q>>(9-this->xtalkScale);
tgrosch 0:62b846b3988a 77 amplitude=sqrt(pow(xTalkI,2)+pow(xTalkQ,2))*1.646; ///* Calculates the magnitude of crosstalk based on a predefined formula. <b>Warning:</b> This uses floating point arithmetic and math.h library for power and sqrt functions
tgrosch 0:62b846b3988a 78 return amplitude;
tgrosch 0:62b846b3988a 79 }
tgrosch 0:62b846b3988a 80
tgrosch 0:62b846b3988a 81 void OPT3101::crosstalkC::readTemperatureMain(OPT3101::device *dev){
tgrosch 0:62b846b3988a 82 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 83 this->tmain=dev->reg.tmain.read(); ///* Reads register OPT3101Register::tmain and assigns to OPT3101::crosstalkC::tmain
tgrosch 0:62b846b3988a 84 }
tgrosch 0:62b846b3988a 85 void OPT3101::crosstalkC::readTemperatureIllum(OPT3101::device *dev){
tgrosch 0:62b846b3988a 86 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 87 this->tillum=dev->reg.tillum.read(); ///* Reads register OPT3101Register::illum and assigns to OPT3101::crosstalkC::illum
tgrosch 0:62b846b3988a 88 }
tgrosch 0:62b846b3988a 89
tgrosch 0:62b846b3988a 90 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 91 void OPT3101::crosstalkC::storeToFile(char *fileName)
tgrosch 0:62b846b3988a 92 {
tgrosch 0:62b846b3988a 93 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 94 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 95 std::ofstream ofs(fileName);
tgrosch 0:62b846b3988a 96 ofs << this;
tgrosch 0:62b846b3988a 97 ofs.close(); ///* User needs to implement file storage based on host.
tgrosch 0:62b846b3988a 98 #endif
tgrosch 0:62b846b3988a 99 }
tgrosch 0:62b846b3988a 100 #endif
tgrosch 0:62b846b3988a 101
tgrosch 0:62b846b3988a 102 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 103 void OPT3101::crosstalkC::loadFromFile(char * fileName)
tgrosch 0:62b846b3988a 104 {
tgrosch 0:62b846b3988a 105 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 106 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 107 std::ifstream ifs(fileName);
tgrosch 0:62b846b3988a 108 ifs >> this;
tgrosch 0:62b846b3988a 109 ifs.close(); ///* User needs to implement file load/restore based on host.
tgrosch 0:62b846b3988a 110 #endif
tgrosch 0:62b846b3988a 111 }
tgrosch 0:62b846b3988a 112 #endif
tgrosch 0:62b846b3988a 113
tgrosch 0:62b846b3988a 114 void OPT3101::crosstalkC::report()
tgrosch 0:62b846b3988a 115 {
tgrosch 0:62b846b3988a 116 //#ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 117 // This is template function to report and analyze the crosstalk value.
tgrosch 0:62b846b3988a 118 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 119 host.printf("----------------------\r\n");
tgrosch 0:62b846b3988a 120 host.printf("Crosstalk Class Report\r\n");
tgrosch 0:62b846b3988a 121 host.printf("----------------------\r\n"); ///* Prints all the members and values of members on screen.
tgrosch 0:62b846b3988a 122 host.printf("I=%d\r\n", this->I);
tgrosch 0:62b846b3988a 123 host.printf("Q=%d\r\n", this->Q); ///* User needs to implement file load/restore based on host.
tgrosch 0:62b846b3988a 124 host.printf("xtalkScale=%d\r\n", this->xtalkScale);
tgrosch 0:62b846b3988a 125 host.printf("illumXtalk=%d\r\n", this->illumXtalk);
tgrosch 0:62b846b3988a 126 host.printf("illumScale=%d\r\n", this->illumScale);
tgrosch 0:62b846b3988a 127 host.printf("illumDac=%d\r\n", this->illumDac);
tgrosch 0:62b846b3988a 128 host.printf("tmain=%d\r\n", this->tmain);
tgrosch 0:62b846b3988a 129 host.printf("tillum=%d\r\n", this->tillum);
tgrosch 0:62b846b3988a 130 host.printf("shiftIllumPhase=%d\r\n", this->shiftIllumPhase);
tgrosch 0:62b846b3988a 131 host.printf("commonScale=%d\r\n", this->commonScale);
tgrosch 0:62b846b3988a 132 host.printf("Magnitude=%4.2f\r\n", this->magnitude());
tgrosch 0:62b846b3988a 133 host.printf("----------------------\r\n");
tgrosch 0:62b846b3988a 134
tgrosch 0:62b846b3988a 135 //#endif
tgrosch 0:62b846b3988a 136 }
tgrosch 0:62b846b3988a 137 void OPT3101::crosstalkC::printHeader()
tgrosch 0:62b846b3988a 138 {
tgrosch 0:62b846b3988a 139
tgrosch 0:62b846b3988a 140 host.printfSetColor(0b001);
tgrosch 0:62b846b3988a 141 host.printf(" I,");
tgrosch 0:62b846b3988a 142 host.printf(" Q,");
tgrosch 0:62b846b3988a 143 host.printf("S,");
tgrosch 0:62b846b3988a 144 host.printf(" ScaledI,");
tgrosch 0:62b846b3988a 145 host.printf(" ScaledQ,");
tgrosch 0:62b846b3988a 146 host.printf("tMain,");
tgrosch 0:62b846b3988a 147 host.printf("tIlum,");
tgrosch 0:62b846b3988a 148 host.printf("tMain(C),");
tgrosch 0:62b846b3988a 149 host.printf(" tIlum(C),");
tgrosch 0:62b846b3988a 150 host.printf("Magnitd\u001b[0m\r\n");
tgrosch 0:62b846b3988a 151 host.printfSetColor(0xFF);
tgrosch 0:62b846b3988a 152
tgrosch 0:62b846b3988a 153 }
tgrosch 0:62b846b3988a 154 void OPT3101::crosstalkC::print()
tgrosch 0:62b846b3988a 155 {
tgrosch 0:62b846b3988a 156 //#ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 157 // This is template function to report and analyze the crosstalk value.
tgrosch 0:62b846b3988a 158 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 159 host.printfSetColor(0b001);
tgrosch 0:62b846b3988a 160 host.printf("%+07d,",this->I);
tgrosch 0:62b846b3988a 161 host.printf("%+07d,",this->Q);
tgrosch 0:62b846b3988a 162 host.printf("%01d,",this->xtalkScale);
tgrosch 0:62b846b3988a 163 host.printf("%+08ld,",(int32_t) ((int32_t)this->I)<<this->xtalkScale);
tgrosch 0:62b846b3988a 164 host.printf("%+08ld,",(int32_t) ((int32_t)this->Q)<<this->xtalkScale);
tgrosch 0:62b846b3988a 165 host.printf(" %04d,",this->tmain);
tgrosch 0:62b846b3988a 166 host.printf(" %04d,",this->tillum);
tgrosch 0:62b846b3988a 167 host.printf(" %+03d,",(int8_t) ((((int16_t)this->tmain)>>3)-256));
tgrosch 0:62b846b3988a 168 host.printf(" %+07.4f,",((double)(((int16_t)this->tillum)-2048))/16.0);
tgrosch 0:62b846b3988a 169 host.printf("%5.1f\r\n",this->magnitude());
tgrosch 0:62b846b3988a 170 host.printfSetColor(0xFF);
tgrosch 0:62b846b3988a 171 //#endif
tgrosch 0:62b846b3988a 172 }
tgrosch 0:62b846b3988a 173
tgrosch 0:62b846b3988a 174 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 175 std::istream& OPT3101::operator>>(std::istream &is, OPT3101::crosstalkC *data) {
tgrosch 0:62b846b3988a 176 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 177 is >> data->I; ///* From input stream members are de-serialized and restored
tgrosch 0:62b846b3988a 178 is >> data->Q;
tgrosch 0:62b846b3988a 179 is >> data->xtalkScale;
tgrosch 0:62b846b3988a 180 is >> data->illumXtalk;
tgrosch 0:62b846b3988a 181 is >> data->illumScale;
tgrosch 0:62b846b3988a 182 is >> data->illumDac;
tgrosch 0:62b846b3988a 183 is >> data->illumDCdac;
tgrosch 0:62b846b3988a 184 is >> data->tmain;
tgrosch 0:62b846b3988a 185 is >> data->tillum;
tgrosch 0:62b846b3988a 186 is >> data->shiftIllumPhase;
tgrosch 0:62b846b3988a 187 is >> data->commonScale;
tgrosch 0:62b846b3988a 188 return is;
tgrosch 0:62b846b3988a 189 }
tgrosch 0:62b846b3988a 190 #endif
tgrosch 0:62b846b3988a 191
tgrosch 0:62b846b3988a 192 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 193 std::ostream& OPT3101::operator<<(std::ostream &os, const OPT3101::crosstalkC *data) {
tgrosch 0:62b846b3988a 194 os << data->I << '\n'; ///* From class serialize the members
tgrosch 0:62b846b3988a 195 os << data->Q << '\n';
tgrosch 0:62b846b3988a 196 os << data->xtalkScale << '\n';
tgrosch 0:62b846b3988a 197 os << data->illumXtalk << '\n';
tgrosch 0:62b846b3988a 198 os << data->illumScale << '\n';
tgrosch 0:62b846b3988a 199 os << data->illumDac << '\n';
tgrosch 0:62b846b3988a 200 os << data->illumDCdac << '\n';
tgrosch 0:62b846b3988a 201 os << data->tmain << '\n';
tgrosch 0:62b846b3988a 202 os << data->tillum << '\n';
tgrosch 0:62b846b3988a 203 os << data->shiftIllumPhase << '\n';
tgrosch 0:62b846b3988a 204 os << data->commonScale << '\n';
tgrosch 0:62b846b3988a 205 //printf("Writing the data to file I[%d] Q[%d]\n", xtalk->I, xtalk->Q);
tgrosch 0:62b846b3988a 206 return os;
tgrosch 0:62b846b3988a 207 }
tgrosch 0:62b846b3988a 208 #endif
tgrosch 0:62b846b3988a 209