Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

LOW_linkDS2490.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           LOW_linkDS2490.cpp  -  description
00003                              -------------------
00004     begin                : Sun Oct 12 2003
00005     copyright            : (C) 2003 by Harald Roelle
00006     email                : roelle@informatik.uni-muenchen.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 
00019 #include "LOW_linkDS2490.h"
00020 #include "LOW_device.h"
00021 
00022 
00023 
00024 //=====================================================================================
00025 //
00026 // constructors
00027 //
00028 
00029 LOW_linkDS2490::LOW_linkDS2490( const LOW_portUsb_Factory::usbDeviceSpecifier_t inUsbDevSpec,
00030                                 const bool inHasExternalPower, const bool inAllowProgPulse) :
00031   LOW_link( true, inHasExternalPower, inAllowProgPulse),
00032   LOW_linkFlexibleSpeed( normal_speed, pdSlewRate_1_37, w1LowTime_11, soW0RecTime_10) // use normal speed, but preconfigure the recommeded optimal parameters as of app note #148
00033 {
00034   usbDevice = LOW_portUsb_Factory::new_portUsbDevice( inUsbDevSpec);
00035 
00036   if ( usbDevice->getVendorID() != usbVendorID || usbDevice->getProductID() != usbProductID )
00037     throw link_error( "Requested device has wrong vendor/product ID", __FILE__, __LINE__);
00038 
00039   commonConstructorActions();
00040 }
00041 
00042 
00043 LOW_linkDS2490::~LOW_linkDS2490()
00044 {
00045   ctlCmd_resetDevice();
00046   usbDevice->releaseInterface( usbDefaultInterface);
00047   delete usbDevice;
00048 }
00049 
00050 
00051 //=====================================================================================
00052 //
00053 // Standard methods required by LOW_link
00054 //
00055 
00056 //-------------------------------------------------------------------------------------
00057 //
00058 // Bus touch (write/read) methods required by LOW_link
00059 //
00060 
00061 bool LOW_linkDS2490::touchBit( const bool inSendBit, const strongPullup_t inPullup)
00062 {
00063   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "touchBit() called\n");
00064 
00065   commLock lock( *this);
00066 
00067   if ( inPullup != pullUp_NONE ) {
00068     comCmd_setDuration( strongPullup_2_spFactor( inPullup), // inTimeFactor
00069                         false,                              // inSpecifyProgPulse
00070                         resultOnError_rsltHdl,              // inResultHandling
00071                         true);                              // inImmediateExec
00072   }
00073 
00074   comCmd_bitIO( inSendBit,                        // inWriteBit
00075                 inPullup==pullUp_NONE?false:true, // inDoStrongPullup
00076                 false,                            // inSuppressPullupOnRead1
00077                 resultOnError_rsltHdl,            // inResultHandling, resultOnError_rsltHdl is necessary to get response byte
00078                 false);                           // inImmediateExec
00079 
00080   ctlCmd_startExecution();
00081 
00082   deviceFeedback_t  deviceFeedback;
00083   resultCodeVec_t   resultCodeVec;
00084   waitUntilIdle( deviceFeedback, resultCodeVec, 1000);
00085 
00086   if ( deviceFeedback.dataInBufferUsage != 1 )
00087     throw comm_error( "Unexpected data amount in IN buffer", __FILE__, __LINE__);
00088 
00089   uint8_t      readByte;
00090   unsigned int readSize = usbDevice->bulkRead( usbDataInEP, 1, &readByte, 1000);
00091   if ( readSize != 1 )
00092     throw comm_error( "Short read from IN buffer", __FILE__, __LINE__);
00093   
00094   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "touchBit() leaving\n");
00095 
00096   return (readByte&0x01)==0x01;
00097 }
00098 
00099 
00100 uint8_t LOW_linkDS2490::touchByte( const uint8_t inSendByte, const strongPullup_t inPullup)
00101 {
00102   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "touchByte() called (inSendByte: %d, inPullup: %d)\n", inSendByte, inPullup);
00103 
00104   commLock lock( *this);
00105 
00106   if ( inPullup != pullUp_NONE ) {
00107     comCmd_setDuration( strongPullup_2_spFactor( inPullup), // inTimeFactor
00108                         false,                              // inSpecifyProgPulse
00109                         resultOnError_rsltHdl,              // inResultHandling
00110                         true);                              // inImmediateExec
00111   }
00112 
00113   comCmd_byteIO( inSendByte,                       // inWriteByte
00114                  inPullup==pullUp_NONE?false:true, // inDoStrongPullup
00115                  resultOnError_rsltHdl,            // inResultHandling, resultOnError_rsltHdl is necessary to get response byte
00116                  false);                           // inImmediateExec
00117 
00118   ctlCmd_startExecution();
00119 
00120   deviceFeedback_t  deviceFeedback;
00121   resultCodeVec_t   resultCodeVec;
00122   waitUntilIdle( deviceFeedback, resultCodeVec, 1000);
00123 
00124   if ( deviceFeedback.dataInBufferUsage != 1 )
00125     throw comm_error( "Unexpected data amount in IN buffer", __FILE__, __LINE__);
00126 
00127   uint8_t      readByte;
00128   unsigned int readSize = usbDevice->bulkRead( usbDataInEP, 1, &readByte, 1000);
00129   if ( readSize != 1 )
00130     throw comm_error( "Short read from IN buffer", __FILE__, __LINE__);
00131 
00132   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "touchByte() leaving\n");
00133 
00134   return readByte;
00135 }
00136 
00137 
00138 byteVec_t LOW_linkDS2490::touchBlock( const byteVec_t &inBytes, const strongPullup_t inPullup)
00139 {
00140   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "touchBlock() called\n");
00141 
00142   commLock lock( *this);
00143   
00144   const unsigned int  maxBlockSize = (usbDataOutEP_FIFOsize < usbDataInEP_FIFOsize) ? usbDataOutEP_FIFOsize-1 : usbDataInEP_FIFOsize-1;
00145   const unsigned int  total        = inBytes.size();
00146   uint8_t             *writeBuffer = new uint8_t[total];
00147   uint8_t             *readBuffer  = new uint8_t[maxBlockSize];
00148   byteVec_t           retVec       = byteVec_t( total);
00149   
00150   if ( inPullup != pullUp_NONE ) {
00151     comCmd_setDuration( strongPullup_2_spFactor( inPullup), // inTimeFactor
00152                         false,                              // inSpecifyProgPulse
00153                         resultOnError_rsltHdl,              // inResultHandling
00154                         true);                              // inImmediateExec
00155   }
00156 
00157   try {
00158     std::copy( inBytes.begin(), inBytes.end(), writeBuffer);
00159     
00160     unsigned int  written   = 0;
00161     unsigned int  remaining = total;
00162     unsigned int  totalRead = 0;
00163     unsigned int  read      = 0;
00164     uint8_t       *writePtr = writeBuffer;
00165     do {
00166       const unsigned int blockSize = (remaining < maxBlockSize) ? remaining : maxBlockSize;
00167       
00168       written = usbDevice->bulkWrite( usbDataOutEP, blockSize, writePtr, 1000);
00169       remaining -= written;
00170       writePtr  += written;
00171     
00172       comCmd_blockIO( written,                                 // inWriteSize
00173                       false,                                   // inBusResetBefore
00174                       (remaining==0) ? (inPullup==pullUp_NONE?false:true) : false, // inDoStrongPullup
00175                       resultOnError_rsltHdl,                   // inResultHandling,
00176                       false);                                  // inImmediateExec
00177    
00178       ctlCmd_startExecution();
00179 
00180       deviceFeedback_t  deviceFeedback;
00181       resultCodeVec_t   resultCodeVec;
00182       waitUntilIdle( deviceFeedback, resultCodeVec, 1000);
00183    
00184       read = usbDevice->bulkRead( usbDataInEP, written, readBuffer, 1000);
00185       if ( read != written )
00186         throw comm_error( "Short read from IN buffer", __FILE__, __LINE__);
00187       std::copy( readBuffer, readBuffer+read, retVec.begin()+totalRead);
00188       totalRead += read;
00189     }
00190     while ( remaining != 0);
00191   }
00192   catch( ... ) {
00193     delete[] writeBuffer;
00194     delete[] readBuffer;
00195     throw;
00196   }
00197   
00198   delete[] writeBuffer;
00199   delete[] readBuffer;
00200   
00201   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "touchBlock() leaving\n");
00202 
00203   return retVec;
00204   
00205   
00206   byteVec_t retBytes = byteVec_t( inBytes.size());
00207   for( unsigned int a=0; a<inBytes.size()-1; ++a) {
00208     retBytes[a] = touchByte( inBytes[a], pullUp_NONE);
00209   }
00210   retBytes[inBytes.size()-1] = touchByte( inBytes[inBytes.size()-1], inPullup);
00211 
00212   return retBytes;
00213 }
00214 
00215 
00216 //-------------------------------------------------------------------------------------
00217 //
00218 // Higher level methods by LOW_link
00219   
00220 LOW_deviceID::deviceIDVec_t LOW_linkDS2490::searchDevices( const bool inOnlyAlarm, const LOW_deviceIDRaw inPreload,
00221                                                            const LOW_deviceIDRaw::devFamCode_t inFamCode, const bool inDoReset)
00222 {
00223   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "searchDevices() called\n");
00224 
00225   commLock lock( *this);
00226 
00227   const uint8_t                maxDevs = usbDataInEP_FIFOsize/sizeof( LOW_deviceIDRaw::devRomID_t) - 1;  // FIFO_size / ID_size - place_for_discr_vec
00228   LOW_deviceID::deviceIDVec_t  returnIDs;
00229 
00230   LOW_deviceIDRaw preloadVec = inPreload;
00231 
00232   // preload family type
00233   if ( inFamCode != LOW_device::anyDev_famCode )
00234     preloadVec.setFamilyCode( inFamCode);
00235 
00236   if ( resetBus() == false )
00237     return returnIDs;
00238 
00239   bool searchRunning = true;
00240   while ( searchRunning ) {
00241 
00242     unsigned int writeSize = usbDevice->bulkWrite( usbDataOutEP, preloadVec.getRomIDVec(), 1000);
00243     if ( writeSize != preloadVec.getRomIDVec().size() )
00244       throw comm_error( "Short write to OUT buffer", __FILE__, __LINE__);
00245 
00246     comCmd_searchAccess( maxDevs,              // inMaxDevNum
00247                          inOnlyAlarm ? LOW_device::SearchAlarmROM_COMMAND : LOW_device::SearchROM_COMMAND, // inSearchCommand
00248                          true,                 // inSearchWithoutFullAccess
00249                          true,                 // inReturnDiscrepancyInfo
00250                          true,                 // inBusResetBefore
00251                          true,                 // inFlushBuffersOnErr
00252                          resultAlways_rsltHdl, // inResultHandling
00253                          false);               // inImmediateExec
00254 
00255     ctlCmd_startExecution();
00256 
00257     deviceFeedback_t  deviceFeedback;
00258     resultCodeVec_t   resultCodeVec;
00259     waitUntilIdle( deviceFeedback, resultCodeVec, 30000);
00260 
00261     if ( (deviceFeedback.dataInBufferUsage % sizeof( LOW_deviceIDRaw::devRomID_t)) != 0 )
00262       throw comm_error( "Illegal byte count in IN buffer", __FILE__, __LINE__);
00263 
00264     unsigned int rawDevCnt = deviceFeedback.dataInBufferUsage / sizeof( LOW_deviceIDRaw::devRomID_t);
00265     LOW_deviceIDRaw::devRomID_t *readRawIDs = new LOW_deviceIDRaw::devRomID_t[rawDevCnt];
00266 
00267     try {
00268       unsigned int readSize = usbDevice->bulkRead( usbDataInEP, deviceFeedback.dataInBufferUsage, reinterpret_cast<LOW_portUsbDevice::msgData_t>(readRawIDs), 1000);
00269       if ( readSize != deviceFeedback.dataInBufferUsage )
00270         throw comm_error( "Short read from IN buffer", __FILE__, __LINE__);
00271 
00272       unsigned int realIDCnt = rawDevCnt<=maxDevs ? rawDevCnt : maxDevs;
00273       for( unsigned int a=0; a<realIDCnt; ++a) {
00274         LOW_deviceID newID = LOW_deviceID( readRawIDs[a]);
00275         if ( inFamCode!=LOW_device::anyDev_famCode && newID.getFamilyCode()!=inFamCode ) {
00276           searchRunning = false;
00277           break;
00278         }
00279         else
00280           returnIDs.push_back( newID);
00281       }
00282 
00283       if ( rawDevCnt <= maxDevs )
00284         searchRunning = false;
00285       else
00286         preloadVec = readRawIDs[rawDevCnt-1];
00287     }
00288     catch ( ... ) {
00289       delete[] readRawIDs;
00290       throw;
00291     }
00292 
00293     delete[] readRawIDs;
00294   }
00295 
00296   if ( inDoReset )
00297     resetBus();
00298 
00299   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "searchDevices() leaving (returning %d IDs)\n", returnIDs.size());
00300   return returnIDs;
00301 }
00302 
00303 
00304                                                      
00305 //-------------------------------------------------------------------------------------
00306 //
00307 // Misc methods required by LOW_link
00308 //
00309 
00310 void LOW_linkDS2490::resetLinkAdapter()
00311 {
00312   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetLinkAdapter() called\n");
00313 
00314   commLock lock( *this);
00315 
00316   // reset device
00317   ctlCmd_resetDevice();
00318   
00319   modCmd_setEnablePulse( true, allowProgPulse);
00320   modCmd_setEnableSpeedChange( false);
00321   
00322   // restore former settings
00323   setWireSpeed( wireSpeed);
00324   if ( wireSpeed == flexible_speed ) {
00325     setPullDownSlewRate( pdSlewRate);
00326     setWrite1LowTime( w1LowTime);
00327     setSampleOffsetWrite0Rec( soW0RecTime);
00328   }
00329   
00330   deviceFeedback_t devFeedback;
00331   resultCodeVec_t  resultCodeVec;
00332   readDeviceStatus( devFeedback, resultCodeVec);
00333   hasProgramPulse = devFeedback.progVoltagePresent;
00334 
00335   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetLinkAdapter() leaving\n");
00336 }
00337 
00338 
00339 bool LOW_linkDS2490::resetBus()
00340 {
00341   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus() called\n");
00342 
00343   commLock lock( *this);
00344   
00345   comCmd_oneWireReset( false,                // inLoopUntilPresenceDetect
00346                        false,                // inEnableSpeedChange
00347                        normal_OWSPEED,       // inSpeedSelector
00348                        true,                 // inFlushBuffersOnErr
00349                        resultAlways_rsltHdl, // inResultHandling
00350                        false);               // inImmediateExec
00351   ctlCmd_startExecution();
00352   
00353   deviceFeedback_t  deviceFeedback;
00354   resultCodeVec_t   resultCodeVec;
00355   waitUntilIdle( deviceFeedback, resultCodeVec, 1000);
00356 
00357 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): isStrongPullupEnabled       = %d\n", deviceFeedback.isStrongPullupEnabled);
00358 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): isProgPulseEnabled          = %d\n", deviceFeedback.isProgPulseEnabled);
00359 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): isDynSpeedChangeEnabled     = %d\n", deviceFeedback.isDynSpeedChangeEnabled);
00360 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): oneWireSpeed;               = %d\n", deviceFeedback.oneWireSpeed);
00361 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): strongPullupDurationFactor; = %d\n", deviceFeedback.strongPullupDurationFactor);
00362 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): progPulseDurationFactor;    = %d\n", deviceFeedback.progPulseDurationFactor);
00363 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): pulldownSlewRate;           = %d\n", deviceFeedback.pulldownSlewRate);
00364 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): write1LowTime;              = %d\n", deviceFeedback.write1LowTime);
00365 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): dsow0RecTime;               = %d\n", deviceFeedback.dsow0RecTime);
00366 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): strongPullupCurrentActive;  = %d\n", deviceFeedback.strongPullupCurrentActive);
00367 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): progPulseCurrentActive;     = %d\n", deviceFeedback.progPulseCurrentActive);
00368 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): progVoltagePresent;         = %d\n", deviceFeedback.progVoltagePresent);
00369 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): deviceExternalPowered;      = %d\n", deviceFeedback.deviceExternalPowered);
00370 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): deviceHalted;               = %d\n", deviceFeedback.deviceHalted);
00371 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): deviceIdle;                 = %d\n", deviceFeedback.deviceIdle);
00372 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): ep0FifoOverflowError;       = %d\n", deviceFeedback.ep0FifoOverflowError);
00373 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): currentCommCmd;             = %d\n", deviceFeedback.currentCommCmd);
00374 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): commCmdBufferUsage;         = %d\n", deviceFeedback.commCmdBufferUsage);
00375 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): dataOutBufferUsage;         = %d\n", deviceFeedback.dataOutBufferUsage);
00376 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): dataInBufferUsage;          = %d\n", deviceFeedback.dataInBufferUsage);
00377 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): resultCount;                = %d\n", deviceFeedback.resultCount);
00378 //  LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus(): resultCodeVec.size()        = %d\n", resultCodeVec.size());
00379   
00380   if ( resultCodeVec.size() == 0)
00381     throw comm_error( "Expected answer not found", __FILE__, __LINE__);
00382 
00383   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "resetBus() leaving\n");
00384 
00385     /** @todo Check if and how "alarming presence pulse" response works. */
00386   if ( resultCodeVec.back().alarmingPresencePulse )  return true;
00387   if ( resultCodeVec.back().noPresencePulse )        return false;
00388   if ( resultCodeVec.back().shortToGround )          throw comm_error( "Short to ground detected", __FILE__, __LINE__);
00389 
00390   return true;
00391 }
00392 
00393 
00394 void LOW_linkDS2490::strongPullup( const unsigned long inMilliSecs)
00395 {
00396   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "strongPullup(const unsigned long) called\n");
00397 
00398   commLock lock( *this);
00399 
00400   if ( inMilliSecs>=16 && inMilliSecs<=4064 && (inMilliSecs%16)==0 ) {  // 16ms <= length <= 4096ms AND dividable by 16ms
00401     strongPullupInternal( inMilliSecs/16);
00402     LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "strongPullup(const unsigned long) leaving\n");
00403     return;
00404   }
00405 
00406   comCmd_setDuration( 0x00,                  // inTimeFactor = infinite
00407                       false,                 // inSpecifyProgPulse
00408                       resultOnError_rsltHdl, // inResultHandling
00409                       true);                 // inImmediateExec
00410 
00411   comCmd_pulse( false,                  // inSpecifyProgPulse
00412                 true,                   // inFlushBuffersOnErr,
00413                 resultOnError_rsltHdl,  // inResultHandling
00414                 true);                  // inImmediateExec
00415 
00416   LOW_platformMisc::milliSleep( inMilliSecs);
00417   ctlCmd_haltExecutionWhenDone();  // stop the pullup
00418   ctlCmd_resumeExecution();
00419 
00420   deviceFeedback_t  deviceFeedback;
00421   resultCodeVec_t   resultCodeVec;
00422   readDeviceStatus( deviceFeedback, resultCodeVec);
00423 
00424   if ( resultCodeVec.size() != 0)
00425     throw comm_error( "Unexpected error reply found", __FILE__, __LINE__);
00426 
00427   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "strongPullup(const unsigned long) leaving\n");
00428 }
00429 
00430 
00431 void LOW_linkDS2490::strongPullup( const strongPullup_t inPullupTimes)
00432 {
00433   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "strongPullup(const strongPullup_t) called\n");
00434 
00435   commLock lock( *this);
00436 
00437   strongPullupInternal( strongPullup_2_spFactor( inPullupTimes));
00438 
00439   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "strongPullup(const strongPullup_t) leaving\n");
00440 }
00441 
00442 
00443 void LOW_linkDS2490::programPulse( const unsigned long inMicroSecs)
00444 {
00445   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "programPulse(const unsigned long) called\n");
00446 
00447   commLock lock( *this);
00448 
00449   if ( ! allowProgPulse )
00450     throw notAllowed_error( "Program pulse not allowed", __FILE__, __LINE__);
00451 
00452   if ( ! hasProgramPulse )
00453     throw illegalLevel_error( "Program pulse not available", __FILE__, __LINE__);
00454 
00455   if ( inMicroSecs>=8 && inMicroSecs<=2032 && (inMicroSecs%8)==0 ) { // 8us <= length <= 2032us AND dividable by 8us
00456     progPulseInternal( inMicroSecs/8);
00457     LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "programPulse(const unsigned long) leaving\n");
00458     return;
00459   }
00460 
00461   comCmd_setDuration( 0x00,                  // inTimeFactor = infinite
00462                       true,                  // inSpecifyProgPulse
00463                       resultOnError_rsltHdl, // inResultHandling
00464                       true);                 // inImmediateExec
00465 
00466   comCmd_pulse( true,                  // inSpecifyProgPulse
00467                 true,                  // inFlushBuffersOnErr,
00468                 resultAlways_rsltHdl,  // inResultHandling
00469                 true);                 // inImmediateExec
00470 
00471   LOW_platformMisc::microSleep( inMicroSecs);;
00472   ctlCmd_haltExecutionWhenDone();  // stop the pulse
00473   ctlCmd_resumeExecution();
00474 
00475   deviceFeedback_t  deviceFeedback;
00476   resultCodeVec_t   resultCodeVec;
00477   readDeviceStatus( deviceFeedback, resultCodeVec);
00478 
00479   if ( resultCodeVec.size() == 0)
00480     throw comm_error( "Expected answer not found", __FILE__, __LINE__);
00481 
00482   if ( resultCodeVec.back().progVoltageMissingOnBus )
00483     throw comm_error( "12V program pulse not detected on bus", __FILE__, __LINE__);
00484 
00485   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "programPulse(const unsigned long) leaving\n");
00486 }
00487 
00488 
00489 void LOW_linkDS2490::programPulse( const progPulse_t inPulseTime)
00490 {
00491   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "programPulse(const progPulse_tg) called\n");
00492 
00493   commLock lock( *this);
00494 
00495   if ( ! allowProgPulse )
00496     throw notAllowed_error( "Program pulse not allowed", __FILE__, __LINE__);
00497 
00498   if ( ! hasProgramPulse )
00499     throw illegalLevel_error( "Program pulse not available", __FILE__, __LINE__);
00500 
00501   progPulseInternal( progPulse_2_ppFactor( inPulseTime));
00502 
00503   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "programPulse(const progPulse_tg) leaving\n");
00504 }
00505 
00506 
00507 void LOW_linkDS2490::doSearchSequence( const LOW_deviceIDRaw& /*inBranchVector*/,
00508                                        LOW_deviceIDRaw& /*outFoundID*/, LOW_deviceIDRaw& /*outDiscrVec*/)
00509 {
00510   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "doSearchSequence() called\n");
00511 
00512   throw internal_error( "doSearchSequence() not implemented. Should never be called as searchDevices() is overloaded.", __FILE__, __LINE__);
00513 } 
00514 
00515 
00516 
00517 //=====================================================================================
00518 //
00519 // Standard methods required by LOW_linkFlexibleSpeed
00520 //
00521 
00522 void LOW_linkDS2490::setWireSpeed( const wireSpeed_t inWireSpeed)
00523 {
00524   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "setWireSpeed() called\n");
00525 
00526   commLock lock( *this);
00527 
00528   LOW_linkFlexibleSpeed::setWireSpeed( inWireSpeed); // conserve the setting via superclass
00529 
00530   modCmd_setOneWireSpeed( wireSpeed_2_OWSPEED_val( inWireSpeed));
00531 
00532   // restore former settings
00533   if ( wireSpeed == flexible_speed ) {
00534     setPullDownSlewRate( pdSlewRate);
00535     setWrite1LowTime( w1LowTime);
00536     setSampleOffsetWrite0Rec( soW0RecTime);
00537   }
00538 
00539   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "setWireSpeed() leaving\n");
00540 }
00541 
00542 
00543 LOW_linkDS2490::wireSpeed_t LOW_linkDS2490::getWireSpeed()
00544 {
00545   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "getWireSpeed() called\n");
00546 
00547   commLock lock( *this);
00548 
00549   deviceFeedback_t devFeedback;
00550   resultCodeVec_t  resultCodeVec;
00551   readDeviceStatus( devFeedback, resultCodeVec);
00552 
00553   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "getWireSpeed() leaving\n");
00554   return OWSPEED_val_2_wireSpeed( devFeedback.oneWireSpeed);
00555 }
00556 
00557 
00558 void LOW_linkDS2490::setPullDownSlewRate( const pdSlewRate_t inPDSR)
00559 {
00560   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "setPullDownSlewRate() called\n");
00561 
00562   commLock lock( *this);
00563 
00564   LOW_linkFlexibleSpeed::setPullDownSlewRate( inPDSR);  // conserve the setting via superclass
00565 
00566   modCmd_setPulldownSlewRate( pdSlewRate_2_PDSR_val( inPDSR));
00567 
00568   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "setPullDownSlewRate() leaving\n");
00569 }
00570 
00571 
00572 LOW_linkDS2490::pdSlewRate_t LOW_linkDS2490::getPullDownSlewRate()
00573 {
00574   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "getPullDownSlewRate() called\n");
00575 
00576   commLock lock( *this);
00577 
00578   LOW_linkFlexibleSpeed::getPullDownSlewRate();  // sanity checking in superclass
00579 
00580   deviceFeedback_t devFeedback;
00581   resultCodeVec_t  resultCodeVec;
00582   readDeviceStatus( devFeedback, resultCodeVec);
00583 
00584   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "getPullDownSlewRate() leaving\n");
00585   return PDSR_val_2_pdSlewRate( devFeedback.pulldownSlewRate);
00586 }
00587 
00588 
00589 void LOW_linkDS2490::setWrite1LowTime( const w1LowTime_t inW1LT)
00590 {
00591   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "setWrite1LowTime() called\n");
00592 
00593   commLock lock( *this);
00594 
00595   LOW_linkFlexibleSpeed::setWrite1LowTime( inW1LT);  // conserve the setting via superclass
00596 
00597   modCmd_setWrite1LowTime( w1LowTime_2_W1LT_val( inW1LT));
00598 
00599   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "setWrite1LowTime() leaving\n");
00600 }
00601 
00602 
00603 LOW_linkDS2490::w1LowTime_t LOW_linkDS2490::getWrite1LowTime()
00604 {
00605   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "getWrite1LowTime() called\n");
00606 
00607   commLock lock( *this);
00608 
00609   LOW_linkFlexibleSpeed::getWrite1LowTime();  // sanity checking in superclass
00610 
00611   deviceFeedback_t devFeedback;
00612   resultCodeVec_t  resultCodeVec;
00613   readDeviceStatus( devFeedback, resultCodeVec);
00614 
00615   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "getWrite1LowTime() leaving\n");
00616   return W1LT_val_2_w1LowTime( devFeedback.write1LowTime);
00617 }
00618 
00619 
00620 void LOW_linkDS2490::setSampleOffsetWrite0Rec( const soW0RecTime_t inSOW0RT)
00621 {
00622   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "setSampleOffsetWrite0Rec() called\n");
00623 
00624   commLock lock( *this);
00625 
00626   LOW_linkFlexibleSpeed::setSampleOffsetWrite0Rec( inSOW0RT);  // conserve the setting via superclass
00627 
00628   modCmd_setDsoW0RecoveryTime( soW0RecTime_2_SOW0RT_val( inSOW0RT));
00629 
00630   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "setSampleOffsetWrite0Rec() leaving\n");
00631 }
00632 
00633 
00634 LOW_linkDS2490::soW0RecTime_t LOW_linkDS2490::getSampleOffsetWrite0Rec()
00635 {
00636   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "getSampleOffsetWrite0Rec() called\n");
00637 
00638   commLock lock( *this);
00639 
00640   LOW_linkFlexibleSpeed::getSampleOffsetWrite0Rec();  // sanity checking in superclass
00641 
00642   deviceFeedback_t devFeedback;
00643   resultCodeVec_t  resultCodeVec;
00644   readDeviceStatus( devFeedback, resultCodeVec);
00645 
00646   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "getSampleOffsetWrite0Rec() leaving\n");
00647   return SOW0RT_val_2_soW0RecTime( devFeedback.dsow0RecTime);
00648 }
00649 
00650 
00651 
00652 
00653 //=====================================================================================
00654 //
00655 // private methods
00656 //
00657 
00658 
00659 //-------------------------------------------------------------------------------------
00660 //
00661 // Mid-layer methods.
00662 //
00663 
00664 void LOW_linkDS2490::commonConstructorActions()
00665 {
00666   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "commonConstructorActions() called\n");
00667 
00668   // locking done in publicly accessible methods
00669 
00670   usbDevice->claimInterface( usbDefaultInterface);
00671   
00672   resetLinkAdapter();
00673 
00674   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "commonConstructorActions() leaving\n");
00675 }
00676 
00677 
00678 void LOW_linkDS2490::readDeviceStatus( deviceFeedback_t &outDevFeedback, resultCodeVec_t &outResultCodeVec)
00679 {
00680   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "readDeviceStatus() called\n");
00681 
00682   // locking done in publicly accessible methods
00683 
00684   deviceFeedbackRaw_t  feedbackData;
00685 
00686   unsigned int readBytes = usbDevice->bulkRead( usbStatusInEP, sizeof( feedbackData),
00687                                                 reinterpret_cast<LOW_portUsbDevice::msgData_t>(&feedbackData), 500);
00688   if ( readBytes < 16 )
00689     throw comm_error( "Short read from status endpoint", __FILE__, __LINE__);
00690 
00691   // analyze standard data
00692   outDevFeedback.isStrongPullupEnabled      = feedbackData.enableFlags & SPUE_bitmask;
00693   outDevFeedback.isProgPulseEnabled         = feedbackData.enableFlags & PRGE_bitmask;
00694   outDevFeedback.isDynSpeedChangeEnabled    = feedbackData.enableFlags & SPCE_bitmask;
00695   outDevFeedback.oneWireSpeed               = static_cast<OWSPEED_val_t>(feedbackData.oneWireSpeed);
00696   outDevFeedback.strongPullupDurationFactor = feedbackData.strongPullupDuration;
00697   outDevFeedback.progPulseDurationFactor    = feedbackData.progPulseDuration;
00698   outDevFeedback.pulldownSlewRate           = static_cast<PDSR_val_t>(feedbackData.pulldownSlewRate);
00699   outDevFeedback.write1LowTime              = static_cast<W1LT_val_t>(feedbackData.write1LowTime);
00700   outDevFeedback.dsow0RecTime               = static_cast<SOW0RT_val_t>(feedbackData.dsow0RecTime);
00701   outDevFeedback.strongPullupCurrentActive  = feedbackData.deviceStatusFlags & SPUA_bitmask;
00702   outDevFeedback.progPulseCurrentActive     = feedbackData.deviceStatusFlags & PRGA_bitmask;
00703   outDevFeedback.progVoltagePresent         = feedbackData.deviceStatusFlags & VP12_bitmask;
00704   outDevFeedback.deviceExternalPowered      = feedbackData.deviceStatusFlags & PMOD_bitmask;
00705   outDevFeedback.deviceHalted               = feedbackData.deviceStatusFlags & HALT_bitmask;
00706   outDevFeedback.deviceIdle                 = feedbackData.deviceStatusFlags & IDLE_bitmask;
00707   outDevFeedback.ep0FifoOverflowError       = feedbackData.deviceStatusFlags & EP0F_bitmask;
00708   outDevFeedback.currentCommCmd             = (feedbackData.commCmdHI<<8) | feedbackData.commCmdLO;
00709   outDevFeedback.commCmdBufferUsage         = feedbackData.commCmdBufferStatus;
00710   outDevFeedback.dataOutBufferUsage         = feedbackData.dataOutBufferStatus;
00711   outDevFeedback.dataInBufferUsage          = feedbackData.dataInBufferStatus;
00712   outDevFeedback.resultCount                = readBytes - 16;
00713 
00714 //  printf( "isStrongPullupEnabled: %d\n", outDevFeedback.isStrongPullupEnabled);
00715 //  printf( "isProgPulseEnabled: %d\n", outDevFeedback.isProgPulseEnabled);
00716 //  printf( "isDynSpeedChangeEnabled: %d\n", outDevFeedback.isDynSpeedChangeEnabled);
00717 //  printf( "oneWireSpeed: %d\n", outDevFeedback.oneWireSpeed);
00718 //  printf( "strongPullupDurationFactor: %d\n", outDevFeedback.strongPullupDurationFactor);
00719 //  printf( "progPulseDurationFactor: %d\n", outDevFeedback.progPulseDurationFactor);
00720 //  printf( "pulldownSlewRate: %d\n", outDevFeedback.pulldownSlewRate);
00721 //  printf( "write1LowTime: %d\n", outDevFeedback.write1LowTime);
00722 //  printf( "dsow0RecTime: %d\n", outDevFeedback.dsow0RecTime);
00723 //  printf( "strongPullupCurrentActive: %d\n", outDevFeedback.strongPullupCurrentActive);
00724 //  printf( "progPulseCurrentActive: %d\n", outDevFeedback.progPulseCurrentActive);
00725 //  printf( "progVoltagePresent: %d\n", outDevFeedback.progVoltagePresent);
00726 //  printf( "deviceExternalPowered: %d\n", outDevFeedback.deviceExternalPowered);
00727 //  printf( "deviceHalted: %d\n", outDevFeedback.deviceHalted);
00728 //  printf( "deviceIdle: %d\n", outDevFeedback.deviceIdle);
00729 //  printf( "ep0FifoOverflowError: %d\n", outDevFeedback.ep0FifoOverflowError);
00730 //  printf( "currentCommCmd: %d\n", outDevFeedback.currentCommCmd);
00731 //  printf( "commCmdBufferUsage: %d\n", outDevFeedback.commCmdBufferUsage);
00732 //  printf( "dataOutBufferUsage: %d\n", outDevFeedback.dataOutBufferUsage);
00733 //  printf( "dataInBufferUsage: %d\n", outDevFeedback.dataInBufferUsage);
00734 //  printf( "resultCount: %d\n", outDevFeedback.resultCount);
00735 
00736   outDevFeedback.compoundResults.deviceDetected             = false;
00737   outDevFeedback.compoundResults.searchAccessDeviceUnderrun = false;
00738   outDevFeedback.compoundResults.pageIsRedirected           = false;
00739   outDevFeedback.compoundResults.crcError                   = false;
00740   outDevFeedback.compoundResults.compareError               = false;
00741   outDevFeedback.compoundResults.progVoltageMissingOnBus    = false;
00742   outDevFeedback.compoundResults.alarmingPresencePulse      = false;
00743   outDevFeedback.compoundResults.shortToGround              = false;
00744   outDevFeedback.compoundResults.noPresencePulse            = false;
00745   
00746   // analyze extra result codes and calc compound results
00747   for( int a=0; a<outDevFeedback.resultCount; a++) {
00748     resultCode_t theResult = { false, false, false, false, false, false, false, false, false};
00749 
00750     if ( feedbackData.resultCode[a] == devDetect_code ) {
00751       theResult.deviceDetected             = true;
00752     }
00753     else {
00754       theResult.searchAccessDeviceUnderrun = feedbackData.resultCode[a] & EOS_bitmask;
00755       theResult.pageIsRedirected           = feedbackData.resultCode[a] & RDP_bitmask;
00756       theResult.crcError                   = feedbackData.resultCode[a] & CRC_bitmask;
00757       theResult.compareError               = feedbackData.resultCode[a] & CMP_bitmask;
00758       theResult.progVoltageMissingOnBus    = feedbackData.resultCode[a] & VPP_bitmask;
00759       theResult.alarmingPresencePulse      = feedbackData.resultCode[a] & APP_bitmask;
00760       theResult.shortToGround              = feedbackData.resultCode[a] & SH_bitmask;
00761       theResult.noPresencePulse            = feedbackData.resultCode[a] & NRS_bitmask;
00762     }
00763 
00764     outDevFeedback.compoundResults.deviceDetected             |= theResult.deviceDetected;
00765     outDevFeedback.compoundResults.searchAccessDeviceUnderrun |= theResult.searchAccessDeviceUnderrun;
00766     outDevFeedback.compoundResults.pageIsRedirected           |= theResult.pageIsRedirected;
00767     outDevFeedback.compoundResults.crcError                   |= theResult.crcError;
00768     outDevFeedback.compoundResults.compareError               |= theResult.compareError;
00769     outDevFeedback.compoundResults.progVoltageMissingOnBus    |= theResult.progVoltageMissingOnBus;
00770     outDevFeedback.compoundResults.alarmingPresencePulse      |= theResult.alarmingPresencePulse;
00771     outDevFeedback.compoundResults.shortToGround              |= theResult.shortToGround;
00772     outDevFeedback.compoundResults.noPresencePulse            |= theResult.noPresencePulse;
00773 
00774     outResultCodeVec.push_back( theResult);
00775   }
00776 
00777   // ep0 fifo overrun makes the device unusable anyway so we handle it here centrally
00778   if ( outDevFeedback.ep0FifoOverflowError ) {
00779     ctlCmd_resetDevice();
00780     throw comm_error( "EP0 FIFO overrund. Reset command was sent to device.", __FILE__, __LINE__);
00781   }
00782 
00783   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "readDeviceStatus() leaving\n");
00784 }
00785 
00786 
00787 void LOW_linkDS2490::waitUntilIdle( deviceFeedback_t &outDeviceFeedback, resultCodeVec_t &outResultCodeVec,
00788                                     const LOW_portUsbDevice::usbTimeout_t inTimeout)
00789 {
00790   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "waitUntilIdle() called\n");
00791 
00792   // locking done in publicly accessible methods
00793 
00794   static const unsigned long sleepTime_ms = 1;
00795 
00796   resultCode_t cmpdResults = { false, false, false, false, false, false, false, false, false};
00797   
00798   for ( unsigned int a=0; a<(inTimeout/sleepTime_ms)+1; ++a) {
00799     deviceFeedback_t  feedbackData;
00800     readDeviceStatus( feedbackData, outResultCodeVec);
00801     
00802     cmpdResults.deviceDetected             |= feedbackData.compoundResults.deviceDetected;
00803     cmpdResults.searchAccessDeviceUnderrun |= feedbackData.compoundResults.searchAccessDeviceUnderrun;
00804     cmpdResults.pageIsRedirected           |= feedbackData.compoundResults.pageIsRedirected;
00805     cmpdResults.crcError                   |= feedbackData.compoundResults.crcError;
00806     cmpdResults.compareError               |= feedbackData.compoundResults.compareError;
00807     cmpdResults.progVoltageMissingOnBus    |= feedbackData.compoundResults.progVoltageMissingOnBus;
00808     cmpdResults.alarmingPresencePulse      |= feedbackData.compoundResults.alarmingPresencePulse;
00809     cmpdResults.shortToGround              |= feedbackData.compoundResults.shortToGround;
00810     cmpdResults.noPresencePulse            |= feedbackData.compoundResults.noPresencePulse;
00811     
00812     if ( feedbackData.deviceIdle && feedbackData.commCmdBufferUsage==0 ) {
00813       outDeviceFeedback = feedbackData;
00814       outDeviceFeedback.compoundResults = cmpdResults;
00815       LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "waitUntilIdle() leaving\n");
00816       return;
00817     }
00818 
00819     LOW_platformMisc::milliSleep( sleepTime_ms);
00820   }
00821   throw comm_error( "Timeout waiting for device to become idle.", __FILE__, __LINE__);
00822 }
00823 
00824 
00825 void LOW_linkDS2490::strongPullupInternal( const unsigned int inPullupFactor)
00826 {
00827   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "strongPullupInternal() called\n");
00828 
00829   // locking done in publicly accessible methods
00830 
00831   comCmd_setDuration( inPullupFactor,          // inTimeFactor
00832                       false,                   // inSpecifyProgPulse
00833                       resultOnError_rsltHdl,   // inResultHandling
00834                       true);                   // inImmediateExec
00835 
00836   comCmd_pulse( false,                 // inSpecifyProgPulse
00837                 true,                  // inFlushBuffersOnErr,
00838                 resultOnError_rsltHdl, // inResultHandling
00839                 true);                 // inImmediateExec
00840 
00841   deviceFeedback_t  deviceFeedback;
00842   resultCodeVec_t   resultCodeVec;
00843   waitUntilIdle( deviceFeedback, resultCodeVec, (16*inPullupFactor) + 1000);  // (16ms * factor) + 1s
00844 
00845   if ( resultCodeVec.size() != 0)
00846     throw comm_error( "Unexpected error reply found", __FILE__, __LINE__);
00847 
00848   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "strongPullupInternal() leaving\n");
00849 }
00850 
00851 
00852 void LOW_linkDS2490::progPulseInternal( const unsigned int inPulseFactor)
00853 {
00854   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "progPulseInternal() called\n");
00855 
00856   // locking done in publicly accessible methods
00857 
00858   comCmd_setDuration( inPulseFactor,           // inTimeFactor
00859                       true,                    // inSpecifyProgPulse
00860                       resultOnError_rsltHdl,   // inResultHandling
00861                       true);                   // inImmediateExec
00862 
00863   comCmd_pulse( true,                  // inSpecifyProgPulse
00864                 true,                  // inFlushBuffersOnErr,
00865                 resultAlways_rsltHdl,  // inResultHandling
00866                 true);                 // inImmediateExec
00867 
00868   deviceFeedback_t  deviceFeedback;
00869   resultCodeVec_t   resultCodeVec;
00870   waitUntilIdle( deviceFeedback, resultCodeVec, (8*inPulseFactor)/1000 + 1000);  // (8us * factor)/1000us + 1s
00871 
00872   if ( resultCodeVec.size() == 0)
00873     throw comm_error( "Expected answer not found", __FILE__, __LINE__);
00874 
00875   if ( resultCodeVec.back().progVoltageMissingOnBus )
00876     throw comm_error( "12V program pulse not detected on bus", __FILE__, __LINE__);
00877 
00878   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "progPulseInternal() leaving\n");
00879 }
00880 
00881 
00882 
00883 //-------------------------------------------------------------------------------------
00884 //
00885 // Control command methods.
00886 //
00887 
00888 void LOW_linkDS2490::ctlCmd_resetDevice()
00889 {
00890   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "ctlCmd_resetDevice() called\n");
00891 
00892   // locking done in publicly accessible methods
00893 
00894   usbDevice->controlMsg( vendorCmd_requestType, control_cmdType, resetDevice_ctlCmd,
00895                          0x0000, 0x0000, 0, ctlCmd_usbTimeout);
00896 }
00897 
00898 
00899 void LOW_linkDS2490::ctlCmd_startExecution()
00900 {
00901   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "ctlCmd_startExecution() called\n");
00902 
00903   // locking done in publicly accessible methods
00904 
00905   usbDevice->controlMsg( vendorCmd_requestType, control_cmdType, startExe_ctlCmd,
00906                          0x0000, 0x0000, 0, ctlCmd_usbTimeout);
00907 }
00908 
00909 
00910 void LOW_linkDS2490::ctlCmd_resumeExecution()
00911 {
00912   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "ctlCmd_resumeExecution() called\n");
00913 
00914   // locking done in publicly accessible methods
00915 
00916   usbDevice->controlMsg( vendorCmd_requestType, control_cmdType, resumeExe_ctlCmd,
00917                          0x0000, 0x0000, 0, ctlCmd_usbTimeout);
00918 }
00919 
00920 
00921 void LOW_linkDS2490::ctlCmd_haltExecutionWhenIdle()
00922 {
00923   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "ctlCmd_haltExecutionWhenIdle() called\n");
00924 
00925   // locking done in publicly accessible methods
00926 
00927   usbDevice->controlMsg( vendorCmd_requestType, control_cmdType, haltExeIdle_ctlCmd,
00928                          0x0000, 0x0000, 0, ctlCmd_usbTimeout);
00929 }
00930 
00931 
00932 void LOW_linkDS2490::ctlCmd_haltExecutionWhenDone()
00933 {
00934   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "ctlCmd_haltExecutionWhenDone() called\n");
00935 
00936   // locking done in publicly accessible methods
00937 
00938   usbDevice->controlMsg( vendorCmd_requestType, control_cmdType, haltExeDone_ctlCmd,
00939                          0x0000, 0x0000, 0, ctlCmd_usbTimeout);
00940 }
00941 
00942 
00943 void LOW_linkDS2490::ctlCmd_flushCommCmds()
00944 {
00945   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "ctlCmd_flushCommCmds() called\n");
00946 
00947   // locking done in publicly accessible methods
00948 
00949   usbDevice->controlMsg( vendorCmd_requestType, control_cmdType, flushCommCmds_ctlCmd,
00950                          0x0000, 0x0000, 0, ctlCmd_usbTimeout);
00951 }
00952 
00953 
00954 void LOW_linkDS2490::ctlCmd_flushDataRcvBuffer()
00955 {
00956   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "ctlCmd_flushDataRcvBuffer() called\n");
00957 
00958   // locking done in publicly accessible methods
00959 
00960   usbDevice->controlMsg( vendorCmd_requestType, control_cmdType, flushRcvBuffer_ctlCmd,
00961                          0x0000, 0x0000, 0, ctlCmd_usbTimeout);
00962 }
00963 
00964 
00965 void LOW_linkDS2490::ctlCmd_flushDataXmtBuffer()
00966 {
00967   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "ctlCmd_flushDataXmtBuffer() called\n");
00968 
00969   // locking done in publicly accessible methods
00970 
00971   usbDevice->controlMsg( vendorCmd_requestType, control_cmdType, flushXmtBuffer_ctlCmd,
00972                          0x0000, 0x0000, 0, ctlCmd_usbTimeout);
00973 }
00974 
00975 
00976 void LOW_linkDS2490::ctlCmd_getCommCmds( byteVec_t &outBytes)
00977 {
00978   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "ctlCmd_getCommCmds() called\n");
00979 
00980   // locking done in publicly accessible methods
00981 
00982   usbDevice->controlMsg( vendorCmd_requestType, control_cmdType, getCommCmds_ctlCmd,
00983                          0x0000, outBytes, ctlCmd_usbTimeout);
00984 }
00985 
00986 
00987 
00988 //-------------------------------------------------------------------------------------
00989 //
00990 // Mode command methods.
00991 //
00992   
00993 void LOW_linkDS2490::modCmd_setEnablePulse( const bool inEnableStrongPullup, const bool inEnableProgPulse)
00994 {
00995   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "modCmd_setEnablePulse() called\n");
00996 
00997   // locking done in publicly accessible methods
00998 
00999   LOW_portUsbDevice::wIndex_t indexVal = 0x0000;
01000   
01001   if ( inEnableStrongPullup ) indexVal |= 0x0002;
01002   if ( inEnableProgPulse )    indexVal |= 0x0001;
01003   
01004   usbDevice->controlMsg( vendorCmd_requestType, mode_cmdType, pulseEn_modCmd,
01005                          indexVal, 0x0000, 0, modCmd_usbTimeout);
01006 }
01007 
01008   
01009 void LOW_linkDS2490::modCmd_setEnableSpeedChange( const bool inEnableSpeedChange)
01010 {
01011   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "modCmd_setEnableSpeedChange() called\n");
01012 
01013   // locking done in publicly accessible methods
01014 
01015   LOW_portUsbDevice::wIndex_t indexVal = 0x0000;
01016   
01017   if ( inEnableSpeedChange ) indexVal |= 0x0001;
01018   
01019   usbDevice->controlMsg( vendorCmd_requestType, mode_cmdType, speedChangeEn_modCmd,
01020                          indexVal, 0x0000, 0, modCmd_usbTimeout);
01021 }
01022 
01023   
01024 void LOW_linkDS2490::modCmd_setOneWireSpeed( const OWSPEED_val_t inWireSpeed)
01025 {
01026   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "modCmd_setOneWireSpeed() called\n");
01027 
01028   // locking done in publicly accessible methods
01029 
01030   LOW_portUsbDevice::wIndex_t indexVal = 0x0000 | inWireSpeed;
01031   
01032   usbDevice->controlMsg( vendorCmd_requestType, mode_cmdType, oneWireSpeed_modCmd,
01033                          indexVal, 0x0000, 0, modCmd_usbTimeout);
01034 }
01035 
01036   
01037 void LOW_linkDS2490::modCmd_setStrongPullupDuration( const uint8_t inSpuDurationFactor)
01038 {
01039   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "modCmd_setStrongPullupDuration() called\n");
01040 
01041   // locking done in publicly accessible methods
01042 
01043   LOW_portUsbDevice::wIndex_t indexVal = 0x0000 | inSpuDurationFactor;
01044   
01045   usbDevice->controlMsg( vendorCmd_requestType, mode_cmdType, strongPuDuration_modCmd,
01046                          indexVal, 0x0000, 0, modCmd_usbTimeout);
01047 }
01048 
01049   
01050 void LOW_linkDS2490::modCmd_setProgPulseDuration( const uint8_t inPpDurationFactor)
01051 {
01052   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "modCmd_setProgPulseDuration() called\n");
01053 
01054   // locking done in publicly accessible methods
01055 
01056   LOW_portUsbDevice::wIndex_t indexVal = 0x0000 | inPpDurationFactor;
01057   
01058   usbDevice->controlMsg( vendorCmd_requestType, mode_cmdType, progPulseDuration_modCmd,
01059                          indexVal, 0x0000, 0, modCmd_usbTimeout);
01060 }
01061 
01062   
01063 void LOW_linkDS2490::modCmd_setPulldownSlewRate( const PDSR_val_t inPDSR)
01064 {
01065   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "modCmd_setPulldownSlewRate() called\n");
01066 
01067   // locking done in publicly accessible methods
01068 
01069   LOW_portUsbDevice::wIndex_t indexVal = 0x0000 | inPDSR;
01070   
01071   usbDevice->controlMsg( vendorCmd_requestType, mode_cmdType, pulldownSlewRate_modCmd,
01072                          indexVal, 0x0000, 0, modCmd_usbTimeout);
01073 }
01074 
01075   
01076 void LOW_linkDS2490::modCmd_setWrite1LowTime( const W1LT_val_t inW1LT)
01077 {
01078   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "modCmd_setWrite1LowTime() called\n");
01079 
01080   // locking done in publicly accessible methods
01081 
01082   LOW_portUsbDevice::wIndex_t indexVal = 0x0000 | inW1LT;
01083   
01084   usbDevice->controlMsg( vendorCmd_requestType, mode_cmdType, write1LowTime_modCmd,
01085                          indexVal, 0x0000, 0, modCmd_usbTimeout);
01086 }
01087 
01088   
01089 void LOW_linkDS2490::modCmd_setDsoW0RecoveryTime( const SOW0RT_val_t inSOW0RT)
01090 {
01091   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "modCmd_setDsoW0RecoveryTime() called\n");
01092 
01093   // locking done in publicly accessible methods
01094 
01095   LOW_portUsbDevice::wIndex_t indexVal = 0x0000 | inSOW0RT;
01096   
01097   usbDevice->controlMsg( vendorCmd_requestType, mode_cmdType, dsow0Trec_modCmd,
01098                          indexVal, 0x0000, 0, modCmd_usbTimeout);
01099 }
01100 
01101 
01102 
01103 //-------------------------------------------------------------------------------------
01104 //
01105 // Communication command methods.
01106 //
01107 
01108 void LOW_linkDS2490::comCmd_setDuration( const uint8_t inTimeFactor,
01109                                          const bool inSpecifyProgPulse,
01110                                          const resultHandling_t inResultHandling,
01111                                          const bool inImmediateExec)
01112 {
01113   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "comCmd_setDuration() called\n");
01114 
01115   // locking done in publicly accessible methods
01116 
01117   LOW_portUsbDevice::wValue_t valueCmd = setDuration_comCmdBase;
01118   if ( inSpecifyProgPulse ) valueCmd |= TYPE_bitmask;
01119   handleCommonComCmdBits( valueCmd, inResultHandling, inImmediateExec);
01120 
01121   LOW_portUsbDevice::wIndex_t indexVal = 0x0000 | inTimeFactor;
01122 
01123   usbDevice->controlMsg( vendorCmd_requestType, comm_cmdType, valueCmd,
01124                          indexVal, 0x0000, 0, comCmd_usbTimeout);
01125 }
01126 
01127 
01128 void LOW_linkDS2490::comCmd_pulse( const bool inSpecifyProgPulse,
01129                                    const bool inFlushBuffersOnErr,
01130                                    const resultHandling_t inResultHandling,
01131                                    const bool inImmediateExec)
01132 {
01133   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "comCmd_pulse() called\n");
01134 
01135   // locking done in publicly accessible methods
01136 
01137   LOW_portUsbDevice::wValue_t valueCmd = pulse_comCmdBase;
01138   if ( inSpecifyProgPulse )  valueCmd |= TYPE_bitmask;
01139   if ( inFlushBuffersOnErr ) valueCmd |= F_bitmask;
01140   handleCommonComCmdBits( valueCmd, inResultHandling, inImmediateExec);
01141 
01142   usbDevice->controlMsg( vendorCmd_requestType, comm_cmdType, valueCmd,
01143                          0x0000, 0x0000, 0, comCmd_usbTimeout);
01144 }
01145 
01146 
01147 void LOW_linkDS2490::comCmd_oneWireReset( const bool inLoopUntilPresenceDetect,
01148                                           const bool inEnableSpeedChange,
01149                                           const OWSPEED_val_t inSpeedSelector,
01150                                           const bool inFlushBuffersOnErr,
01151                                           const resultHandling_t inResultHandling,
01152                                           const bool inImmediateExec)
01153 {
01154   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "comCmd_oneWireReset() called\n");
01155 
01156   // locking done in publicly accessible methods
01157 
01158   LOW_portUsbDevice::wValue_t valueCmd = oneWireReset_comCmdBase;
01159   if ( inLoopUntilPresenceDetect ) valueCmd |= PST_bitmask;
01160   if ( inEnableSpeedChange )       valueCmd |= SE_bitmask;
01161   if ( inFlushBuffersOnErr )       valueCmd |= F_bitmask;
01162   handleCommonComCmdBits( valueCmd, inResultHandling, inImmediateExec);
01163 
01164   LOW_portUsbDevice::wIndex_t indexVal = 0x0000 | inSpeedSelector;
01165 
01166   usbDevice->controlMsg( vendorCmd_requestType, comm_cmdType, valueCmd,
01167                          indexVal, 0x0000, 0, comCmd_usbTimeout);
01168 }
01169 
01170 
01171 void LOW_linkDS2490::comCmd_bitIO( const bool inWriteBit,
01172                                    const bool inDoStrongPullup,
01173                                    const bool inSuppressPullupOnRead1,
01174                                    const resultHandling_t inResultHandling,
01175                                    const bool inImmediateExec)
01176 {
01177   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "comCmd_bitIO() called\n");
01178 
01179   // locking done in publicly accessible methods
01180 
01181   LOW_portUsbDevice::wValue_t valueCmd = bitIO_comCmdBase;
01182   if ( inWriteBit )              valueCmd |= D_bitmask;
01183   if ( inDoStrongPullup )        valueCmd |= SPU_bitmask;
01184   if ( inSuppressPullupOnRead1 ) valueCmd |= CIB_bitmask;
01185   handleCommonComCmdBits( valueCmd, inResultHandling, inImmediateExec);
01186 
01187   usbDevice->controlMsg( vendorCmd_requestType, comm_cmdType, valueCmd,
01188                          0x0000, 0x0000, 0, comCmd_usbTimeout);
01189 }
01190 
01191 
01192 void LOW_linkDS2490::comCmd_byteIO( const uint8_t inWriteByte,
01193                                     const bool inDoStrongPullup,
01194                                     const resultHandling_t inResultHandling,
01195                                     const bool inImmediateExec)
01196 {
01197   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "comCmd_byteIO() called\n");
01198 
01199   // locking done in publicly accessible methods
01200 
01201   LOW_portUsbDevice::wValue_t valueCmd = byteIO_comCmdBase;
01202   if ( inDoStrongPullup ) valueCmd |= SPU_bitmask;
01203   handleCommonComCmdBits( valueCmd, inResultHandling, inImmediateExec);
01204 
01205   LOW_portUsbDevice::wIndex_t indexVal = 0x0000 | inWriteByte;
01206 
01207   usbDevice->controlMsg( vendorCmd_requestType, comm_cmdType, valueCmd,
01208                          indexVal, 0x0000, 0, comCmd_usbTimeout);
01209 }
01210 
01211 
01212 void LOW_linkDS2490::comCmd_blockIO( const uint16_t inWriteSize,
01213                                      const bool inBusResetBefore,
01214                                      const bool inDoStrongPullup,
01215                                      const resultHandling_t inResultHandling,
01216                                      const bool inImmediateExec)
01217 {
01218   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "comCmd_blockIO() called\n");
01219 
01220   // locking done in publicly accessible methods
01221 
01222   LOW_portUsbDevice::wValue_t valueCmd = blockIO_comCmdBase;
01223   if ( inBusResetBefore ) valueCmd |= RST_bitmask;
01224   if ( inDoStrongPullup ) valueCmd |= SPU_bitmask;
01225   handleCommonComCmdBits( valueCmd, inResultHandling, inImmediateExec);
01226 
01227   LOW_portUsbDevice::wIndex_t indexVal = inWriteSize;
01228 
01229   usbDevice->controlMsg( vendorCmd_requestType, comm_cmdType, valueCmd,
01230                          indexVal, 0x0000, 0, comCmd_usbTimeout);
01231 }
01232 
01233 
01234 void LOW_linkDS2490::comCmd_matchAccess( const uint8_t inMatchCommand,
01235                                          const bool inBusResetBefore,
01236                                          const bool inEnableSpeedChange,
01237                                          const OWSPEED_val_t inSpeedSelector,
01238                                          const resultHandling_t inResultHandling,
01239                                          const bool inImmediateExec)
01240 {
01241   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "comCmd_matchAccess() called\n");
01242 
01243   // locking done in publicly accessible methods
01244 
01245   LOW_portUsbDevice::wValue_t valueCmd = matchAccess_comCmdBase;
01246   if ( inBusResetBefore )    valueCmd |= RST_bitmask;
01247   if ( inEnableSpeedChange ) valueCmd |= SE_bitmask;
01248   handleCommonComCmdBits( valueCmd, inResultHandling, inImmediateExec);
01249 
01250   LOW_portUsbDevice::wIndex_t indexVal = ((inSpeedSelector&0xff)<<8) | (inMatchCommand&0xff);
01251 
01252   usbDevice->controlMsg( vendorCmd_requestType, comm_cmdType, valueCmd,
01253                          indexVal, 0x0000, 0, comCmd_usbTimeout);
01254 }
01255 
01256 
01257 void LOW_linkDS2490::comCmd_readStraight( const uint8_t inWritePreambleSize,
01258                                           const uint16_t inReadSize,
01259                                           const bool inBusResetBefore,
01260                                           const resultHandling_t inResultHandling,
01261                                           const bool inImmediateExec)
01262 {
01263   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "comCmd_readStraight() called\n");
01264 
01265   // locking done in publicly accessible methods
01266 
01267   LOW_portUsbDevice::wValue_t valueCmd = readStraight_comCmdBase;
01268   if ( inBusResetBefore ) valueCmd = 0x0000 | ((inWritePreambleSize&0xff)<<8);
01269 
01270   // special bit positions for this command
01271   switch ( inResultHandling ) {
01272     case noResult_rsltHdl:      valueCmd |= 0x0004; break;  // NTF=x  ICP=1
01273     case resultOnError_rsltHdl:                     break;  // NTF=0  ICP=0
01274     case resultAlways_rsltHdl:  valueCmd |= 0x0008; break;  // NTF=1  ICP=0
01275     default :                   throw internal_error( "Unknown resultHandling_t value detected", __FILE__, __LINE__);
01276   }
01277   if ( inBusResetBefore )       valueCmd |= 0x0002;  // RST=1
01278   if ( inImmediateExec )        valueCmd |= 0x0001;  // IM=1
01279   
01280   LOW_portUsbDevice::wIndex_t indexVal = inReadSize;
01281 
01282   LOW_portUsbDevice::wLength_t lengthVal = 0x0000 | inWritePreambleSize;
01283 
01284   usbDevice->controlMsg( vendorCmd_requestType, comm_cmdType, valueCmd,
01285                          indexVal, lengthVal, 0, comCmd_usbTimeout);
01286 }
01287 
01288 
01289 void LOW_linkDS2490::comCmd_doAndRelease( const uint8_t inWritePreambleSize,
01290                                           const bool inDoReadOperation,
01291                                           const bool inDoStrongPullup,
01292                                           const bool inFlushBuffersOnErr,
01293                                           const resultHandling_t inResultHandling,
01294                                           const bool inImmediateExec)
01295 {
01296   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "comCmd_doAndRelease() called\n");
01297 
01298   // locking done in publicly accessible methods
01299 
01300   LOW_portUsbDevice::wValue_t valueCmd = doAndRelease_comCmdBase;
01301   if ( inDoReadOperation )   valueCmd |= R_bitmask;
01302   if ( inDoStrongPullup )    valueCmd |= SPU_bitmask;
01303   if ( inFlushBuffersOnErr ) valueCmd |= F_bitmask;
01304   handleCommonComCmdBits( valueCmd, inResultHandling, inImmediateExec);
01305 
01306   LOW_portUsbDevice::wIndex_t indexVal = 0x0000 | inWritePreambleSize;
01307 
01308   usbDevice->controlMsg( vendorCmd_requestType, comm_cmdType, valueCmd,
01309                          indexVal, 0x0000, 0, comCmd_usbTimeout);
01310 }
01311 
01312 
01313 void LOW_linkDS2490::comCmd_setPath( const uint8_t inPreloadPathSize,
01314                                      const bool inBusResetBefore,
01315                                      const bool inFlushBuffersOnErr,
01316                                      const resultHandling_t inResultHandling,
01317                                      const bool inImmediateExec)
01318 {
01319   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "comCmd_setPath() called\n");
01320 
01321   // locking done in publicly accessible methods
01322 
01323   LOW_portUsbDevice::wValue_t valueCmd = setPath_comCmdBase;
01324   if ( inBusResetBefore )    valueCmd |= RST_bitmask;
01325   if ( inFlushBuffersOnErr ) valueCmd |= F_bitmask;
01326   handleCommonComCmdBits( valueCmd, inResultHandling, inImmediateExec);
01327 
01328   LOW_portUsbDevice::wIndex_t indexVal = 0x0000 | inPreloadPathSize;
01329 
01330   usbDevice->controlMsg( vendorCmd_requestType, comm_cmdType, valueCmd,
01331                          indexVal, 0x0000, 0, comCmd_usbTimeout);
01332 }
01333 
01334 
01335 void LOW_linkDS2490::comCmd_writeSramPage( const uint8_t inWriteSize,
01336                                            const bool inShortPreambleSize,
01337                                            const bool inActivateCrc16,
01338                                            const bool inFlushBuffersOnErr,
01339                                            const resultHandling_t inResultHandling,
01340                                            const bool inImmediateExec)
01341 {
01342   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "comCmd_writeSramPage() called\n");
01343 
01344   // locking done in publicly accessible methods
01345 
01346   LOW_portUsbDevice::wValue_t valueCmd = writeSramPage_comCmdBase;
01347   if ( inShortPreambleSize ) valueCmd |= PS_bitmask;
01348   if ( inActivateCrc16 )     valueCmd |= DT_bitmask;
01349   if ( inFlushBuffersOnErr ) valueCmd |= F_bitmask;
01350   handleCommonComCmdBits( valueCmd, inResultHandling, inImmediateExec);
01351 
01352   LOW_portUsbDevice::wIndex_t indexVal = 0x0000 | inWriteSize;
01353 
01354   usbDevice->controlMsg( vendorCmd_requestType, comm_cmdType, valueCmd,
01355                          indexVal, 0x0000, 0, comCmd_usbTimeout);
01356 }
01357 
01358 
01359 void LOW_linkDS2490::comCmd_writeEprom( const uint16_t inWriteSize,
01360                                         const bool inActivateCrc16,
01361                                         const bool inCheck0BitsOnly,
01362                                         const bool inFlushBuffersOnErr,
01363                                         const resultHandling_t inResultHandling,
01364                                         const bool inImmediateExec)
01365 {
01366   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "comCmd_writeEprom() called\n");
01367 
01368   // locking done in publicly accessible methods
01369 
01370   LOW_portUsbDevice::wValue_t valueCmd = writeEprom_comCmdBase;
01371   if ( inActivateCrc16 )     valueCmd |= DT_bitmask;
01372   if ( inCheck0BitsOnly )    valueCmd |= Z_bitmask;
01373   if ( inFlushBuffersOnErr ) valueCmd |= F_bitmask;
01374   handleCommonComCmdBits( valueCmd, inResultHandling, inImmediateExec);
01375 
01376   LOW_portUsbDevice::wIndex_t indexVal = inWriteSize;
01377 
01378   usbDevice->controlMsg( vendorCmd_requestType, comm_cmdType, valueCmd,
01379                          indexVal, 0x0000, 0, comCmd_usbTimeout);
01380 }
01381 
01382 
01383 void LOW_linkDS2490::comCmd_readCrcProtPage( const uint8_t inPageCount,
01384                                              const uint8_t inPageSizeLog2,
01385                                              const bool inShortPreambleSize,
01386                                              const bool inActivateCrc16,
01387                                              const bool inFlushBuffersOnErr,
01388                                              const resultHandling_t inResultHandling,
01389                                              const bool inImmediateExec)
01390 {
01391   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "comCmd_readCrcProtPage() called\n");
01392 
01393   // locking done in publicly accessible methods
01394 
01395   LOW_portUsbDevice::wValue_t valueCmd = readCrcProtPage_comCmdBase;
01396   if ( inShortPreambleSize ) valueCmd |= PS_bitmask;
01397   if ( inActivateCrc16 )     valueCmd |= DT_bitmask;
01398   if ( inFlushBuffersOnErr ) valueCmd |= F_bitmask;
01399   handleCommonComCmdBits( valueCmd, inResultHandling, inImmediateExec);
01400 
01401   LOW_portUsbDevice::wIndex_t indexVal = ((inPageCount&0xff)<<8) | (inPageSizeLog2&0xff);
01402 
01403   usbDevice->controlMsg( vendorCmd_requestType, comm_cmdType, valueCmd,
01404                          indexVal, 0x0000, 0, comCmd_usbTimeout);
01405 }
01406 
01407 
01408 void LOW_linkDS2490::comCmd_readRedirectPageCrc( const uint8_t inPageNumber,
01409                                                  const uint8_t inPageSize,
01410                                                  const bool inFollowRedirect,
01411                                                  const bool inFlushBuffersOnErr,
01412                                                  const resultHandling_t inResultHandling,
01413                                                  const bool inImmediateExec)
01414 {
01415   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "comCmd_readRedirectPageCrc() called\n");
01416 
01417   // locking done in publicly accessible methods
01418 
01419   LOW_portUsbDevice::wValue_t valueCmd = readRedirectPageCrc_comCmdBase;
01420   if ( inFollowRedirect )    valueCmd |= CH_bitmask;
01421   if ( inFlushBuffersOnErr ) valueCmd |= F_bitmask;
01422   handleCommonComCmdBits( valueCmd, inResultHandling, inImmediateExec);
01423 
01424   LOW_portUsbDevice::wIndex_t indexVal = ((inPageNumber&0xff)<<8) | (inPageSize&0xff);
01425 
01426   usbDevice->controlMsg( vendorCmd_requestType, comm_cmdType, valueCmd,
01427                          indexVal, 0x0000, 0, comCmd_usbTimeout);
01428 }
01429 
01430 
01431 void LOW_linkDS2490::comCmd_searchAccess( const uint8_t inMaxDevNum,
01432                                           const uint8_t inSearchCommand,
01433                                           const bool inSearchWithoutFullAccess,
01434                                           const bool inReturnDiscrepancyInfo,
01435                                           const bool inBusResetBefore,
01436                                           const bool inFlushBuffersOnErr,
01437                                           const resultHandling_t inResultHandling,
01438                                           const bool inImmediateExec)
01439 {
01440   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "comCmd_searchAccess() called\n");
01441 
01442   // locking done in publicly accessible methods
01443 
01444   LOW_portUsbDevice::wValue_t valueCmd = searchAccess_comCmdBase;
01445   if ( inSearchWithoutFullAccess ) valueCmd |= SM_bitmask;
01446   if ( inReturnDiscrepancyInfo )   valueCmd |= RTS_bitmask;
01447   if ( inBusResetBefore )          valueCmd |= RST_bitmask;
01448   if ( inFlushBuffersOnErr )       valueCmd |= F_bitmask;
01449   handleCommonComCmdBits( valueCmd, inResultHandling, inImmediateExec);
01450 
01451   LOW_portUsbDevice::wIndex_t indexVal = ((inMaxDevNum&0xff)<<8) | (inSearchCommand&0xff);
01452 
01453   usbDevice->controlMsg( vendorCmd_requestType, comm_cmdType, valueCmd,
01454                          indexVal, 0x0000, 0, comCmd_usbTimeout);
01455 }
01456 
01457 
01458 void LOW_linkDS2490::handleCommonComCmdBits( LOW_portUsbDevice::wValue_t &inOutValueCmd,
01459                                              const resultHandling_t inResultHandling, const bool inImmediateExec)
01460 {
01461   LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "handleCommonComCmdBits() called\n");
01462 
01463   // locking done in publicly accessible methods
01464 
01465   // special bit positions for this command
01466   switch ( inResultHandling ) {
01467     case noResult_rsltHdl:      inOutValueCmd |= ICP_bitmask; break;  // NTF=x  ICP=1
01468     case resultOnError_rsltHdl:                               break;  // NTF=0  ICP=0
01469     case resultAlways_rsltHdl:  inOutValueCmd |= NTF_bitmask; break;  // NTF=1  ICP=0
01470     default :                   throw internal_error( "Unknown resultHandling_t value detected", __FILE__, __LINE__);
01471   }
01472   if ( inImmediateExec )        inOutValueCmd |= IM_bitmask;  // IM=1
01473 }
01474 
01475 
01476 
01477 
01478 //-------------------------------------------------------------------------------------
01479 //
01480 // Enumeration type conversion methods
01481 //
01482 
01483 const LOW_linkDS2490::pdSlewRate_t LOW_linkDS2490::PDSR_val_2_pdSlewRate( const PDSR_val_t inPDSR_val) const
01484 {
01485   // fully const, no locking necessary
01486 
01487   switch( inPDSR_val ) {
01488     case PDSR_15:   return pdSlewRate_15;
01489     case PDSR_2_2:  return pdSlewRate_2_2;
01490     case PDSR_1_65: return pdSlewRate_1_65;
01491     case PDSR_1_37: return pdSlewRate_1_37;
01492     case PDSR_1_1:  return pdSlewRate_1_1;
01493     case PDSR_0_83: return pdSlewRate_0_83;
01494     case PDSR_0_7:  return pdSlewRate_0_7;
01495     case PDSR_0_55: return pdSlewRate_0_55;
01496     default:           throw internal_error( "Unknown PDSR_val_t value detected", __FILE__, __LINE__);
01497   }
01498 }
01499 
01500 const LOW_linkDS2490::PDSR_val_t LOW_linkDS2490::pdSlewRate_2_PDSR_val( const pdSlewRate_t inPdSlewRate_t) const
01501 {
01502   // fully const, no locking necessary
01503 
01504   switch( inPdSlewRate_t ) {
01505     case pdSlewRate_15:    return PDSR_15;
01506     case pdSlewRate_2_2:   return PDSR_2_2;
01507     case pdSlewRate_1_65:  return PDSR_1_65;
01508     case pdSlewRate_1_37:  return PDSR_1_37;
01509     case pdSlewRate_1_1:   return PDSR_1_1;
01510     case pdSlewRate_0_83:  return PDSR_0_83;
01511     case pdSlewRate_0_7:   return PDSR_0_7;
01512     case pdSlewRate_0_55:  return PDSR_0_55;
01513     default:           throw internal_error( "Unknown pdSlewRate_t value detected", __FILE__, __LINE__);
01514   }
01515 }
01516 
01517 
01518 const LOW_linkDS2490::w1LowTime_t LOW_linkDS2490::W1LT_val_2_w1LowTime( const W1LT_val_t inW1LT_val) const
01519 {
01520   // fully const, no locking necessary
01521 
01522   switch( inW1LT_val ) {
01523     case W1LT_8:  return w1LowTime_8;
01524     case W1LT_9:  return w1LowTime_9;
01525     case W1LT_10: return w1LowTime_10;
01526     case W1LT_11: return w1LowTime_11;
01527     case W1LT_12: return w1LowTime_12;
01528     case W1LT_13: return w1LowTime_13;
01529     case W1LT_14: return w1LowTime_14;
01530     case W1LT_15: return w1LowTime_15;
01531     default:      throw internal_error( "Unknown W1LT_val_t value detected", __FILE__, __LINE__);
01532   }
01533 }
01534 
01535 const LOW_linkDS2490::W1LT_val_t LOW_linkDS2490::w1LowTime_2_W1LT_val( const w1LowTime_t inW1LowTime) const
01536 {
01537   // fully const, no locking necessary
01538 
01539   switch( inW1LowTime ) {
01540     case w1LowTime_8:  return W1LT_8;
01541     case w1LowTime_9:  return W1LT_9;
01542     case w1LowTime_10: return W1LT_10;
01543     case w1LowTime_11: return W1LT_11;
01544     case w1LowTime_12: return W1LT_12;
01545     case w1LowTime_13: return W1LT_13;
01546     case w1LowTime_14: return W1LT_14;
01547     case w1LowTime_15: return W1LT_15;
01548     default:           throw internal_error( "Unknown w1LowTime_t value detected", __FILE__, __LINE__);
01549   }
01550 }
01551 
01552 
01553 const LOW_linkDS2490::soW0RecTime_t LOW_linkDS2490::SOW0RT_val_2_soW0RecTime( const SOW0RT_val_t inSOW0RT_val) const
01554 {
01555   // fully const, no locking necessary
01556 
01557   switch( inSOW0RT_val ) {
01558     case SOW0RT_3:  return soW0RecTime_3;
01559     case SOW0RT_4:  return soW0RecTime_4;
01560     case SOW0RT_5:  return soW0RecTime_5;
01561     case SOW0RT_6:  return soW0RecTime_6;
01562     case SOW0RT_7:  return soW0RecTime_7;
01563     case SOW0RT_8:  return soW0RecTime_8;
01564     case SOW0RT_9:  return soW0RecTime_9;
01565     case SOW0RT_10: return soW0RecTime_10;
01566     default:        throw internal_error( "Unknown SOW0RT_val_t value detected", __FILE__, __LINE__);
01567   }
01568 }
01569 
01570 const LOW_linkDS2490::SOW0RT_val_t LOW_linkDS2490::soW0RecTime_2_SOW0RT_val( const soW0RecTime_t inSoW0RecTime) const
01571 {
01572   // fully const, no locking necessary
01573 
01574   switch( inSoW0RecTime ) {
01575     case soW0RecTime_3:  return SOW0RT_3;
01576     case soW0RecTime_4:  return SOW0RT_4;
01577     case soW0RecTime_5:  return SOW0RT_5;
01578     case soW0RecTime_6:  return SOW0RT_6;
01579     case soW0RecTime_7:  return SOW0RT_7;
01580     case soW0RecTime_8:  return SOW0RT_8;
01581     case soW0RecTime_9:  return SOW0RT_9;
01582     case soW0RecTime_10: return SOW0RT_10;
01583     default:             throw internal_error( "Unknown soW0RecTime_t value detected", __FILE__, __LINE__);
01584   }
01585 }
01586 
01587 
01588 const LOW_linkDS2490::wireSpeed_t LOW_linkDS2490::OWSPEED_val_2_wireSpeed( const OWSPEED_val_t inOWSPEED_val) const
01589 {
01590   // fully const, no locking necessary
01591 
01592   switch( inOWSPEED_val ) {
01593     case normal_OWSPEED:    return normal_speed;
01594     case flexible_OWSPEED:  return flexible_speed;
01595     case overdrive_OWSPEED: return overdrive_speed;
01596     default:                throw internal_error( "Unknown OWSPEED_val_t value detected", __FILE__, __LINE__);
01597   }
01598 }
01599 
01600 const LOW_linkDS2490::OWSPEED_val_t LOW_linkDS2490::wireSpeed_2_OWSPEED_val( const wireSpeed_t inWireSpeed) const
01601 {
01602   // fully const, no locking necessary
01603 
01604   switch( inWireSpeed ) {
01605     case normal_speed:    return normal_OWSPEED;
01606     case flexible_speed:  return flexible_OWSPEED;
01607     case overdrive_speed: return overdrive_OWSPEED;
01608     default:              throw internal_error( "Unknown wireSpeed_t value detected", __FILE__, __LINE__);
01609   }
01610 }
01611 
01612 
01613 const uint8_t LOW_linkDS2490::strongPullup_2_spFactor( const strongPullup_t inPullup) const
01614 {
01615   // fully const, no locking necessary
01616 
01617   switch( inPullup ) {
01618     case pullUp_16_4:  return  1;
01619     case pullUp_65_5:  return  4;
01620     case pullUp_131:   return  8;
01621     case pullUp_262:   return 16;
01622     case pullUp_524:   return 32;
01623     case pullUp_1048:  return 64;
01624     default:           throw internal_error( "Unknown strongPullup_t value detected", __FILE__, __LINE__);
01625   }
01626 }
01627 
01628 
01629 const uint8_t LOW_linkDS2490::progPulse_2_ppFactor( const progPulse_t inPulse) const
01630 {
01631   // fully const, no locking necessary
01632 
01633   switch( inPulse ) {
01634     case progPulse_32:   return   4;
01635     case progPulse_64:   return   8;
01636     case progPulse_128:  return  16;
01637     case progPulse_256:  return  32;
01638     case progPulse_512:  return  64;
01639     case progPulse_1024: return 128;
01640     case progPulse_2048: return 254;
01641     default:             throw internal_error( "Unknown progPulse_t value detected", __FILE__, __LINE__);
01642   }
01643 }
01644 

Generated on Tue Feb 3 11:30:25 2004 for OneWireLibrary++ by doxygen 1.3.2