00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "LOW_linkDS2490.h"
00020 #include "LOW_device.h"
00021
00022
00023
00024
00025
00026
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)
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
00054
00055
00056
00057
00058
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),
00069 false,
00070 resultOnError_rsltHdl,
00071 true);
00072 }
00073
00074 comCmd_bitIO( inSendBit,
00075 inPullup==pullUp_NONE?false:true,
00076 false,
00077 resultOnError_rsltHdl,
00078 false);
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),
00108 false,
00109 resultOnError_rsltHdl,
00110 true);
00111 }
00112
00113 comCmd_byteIO( inSendByte,
00114 inPullup==pullUp_NONE?false:true,
00115 resultOnError_rsltHdl,
00116 false);
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),
00152 false,
00153 resultOnError_rsltHdl,
00154 true);
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,
00173 false,
00174 (remaining==0) ? (inPullup==pullUp_NONE?false:true) : false,
00175 resultOnError_rsltHdl,
00176 false);
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
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;
00228 LOW_deviceID::deviceIDVec_t returnIDs;
00229
00230 LOW_deviceIDRaw preloadVec = inPreload;
00231
00232
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,
00247 inOnlyAlarm ? LOW_device::SearchAlarmROM_COMMAND : LOW_device::SearchROM_COMMAND,
00248 true,
00249 true,
00250 true,
00251 true,
00252 resultAlways_rsltHdl,
00253 false);
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
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
00317 ctlCmd_resetDevice();
00318
00319 modCmd_setEnablePulse( true, allowProgPulse);
00320 modCmd_setEnableSpeedChange( false);
00321
00322
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,
00346 false,
00347 normal_OWSPEED,
00348 true,
00349 resultAlways_rsltHdl,
00350 false);
00351 ctlCmd_startExecution();
00352
00353 deviceFeedback_t deviceFeedback;
00354 resultCodeVec_t resultCodeVec;
00355 waitUntilIdle( deviceFeedback, resultCodeVec, 1000);
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
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
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 ) {
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,
00407 false,
00408 resultOnError_rsltHdl,
00409 true);
00410
00411 comCmd_pulse( false,
00412 true,
00413 resultOnError_rsltHdl,
00414 true);
00415
00416 LOW_platformMisc::milliSleep( inMilliSecs);
00417 ctlCmd_haltExecutionWhenDone();
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 ) {
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,
00462 true,
00463 resultOnError_rsltHdl,
00464 true);
00465
00466 comCmd_pulse( true,
00467 true,
00468 resultAlways_rsltHdl,
00469 true);
00470
00471 LOW_platformMisc::microSleep( inMicroSecs);;
00472 ctlCmd_haltExecutionWhenDone();
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& ,
00508 LOW_deviceIDRaw& , LOW_deviceIDRaw& )
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
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);
00529
00530 modCmd_setOneWireSpeed( wireSpeed_2_OWSPEED_val( inWireSpeed));
00531
00532
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);
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();
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);
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();
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);
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();
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
00656
00657
00658
00659
00660
00661
00662
00663
00664 void LOW_linkDS2490::commonConstructorActions()
00665 {
00666 LOW_helper_msglog::printDebug( LOW_helper_msglog::linkDS2490_dl, "commonConstructorActions() called\n");
00667
00668
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
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
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
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
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
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
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
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
00830
00831 comCmd_setDuration( inPullupFactor,
00832 false,
00833 resultOnError_rsltHdl,
00834 true);
00835
00836 comCmd_pulse( false,
00837 true,
00838 resultOnError_rsltHdl,
00839 true);
00840
00841 deviceFeedback_t deviceFeedback;
00842 resultCodeVec_t resultCodeVec;
00843 waitUntilIdle( deviceFeedback, resultCodeVec, (16*inPullupFactor) + 1000);
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
00857
00858 comCmd_setDuration( inPulseFactor,
00859 true,
00860 resultOnError_rsltHdl,
00861 true);
00862
00863 comCmd_pulse( true,
00864 true,
00865 resultAlways_rsltHdl,
00866 true);
00867
00868 deviceFeedback_t deviceFeedback;
00869 resultCodeVec_t resultCodeVec;
00870 waitUntilIdle( deviceFeedback, resultCodeVec, (8*inPulseFactor)/1000 + 1000);
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
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
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
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
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
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
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
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
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
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
00981
00982 usbDevice->controlMsg( vendorCmd_requestType, control_cmdType, getCommCmds_ctlCmd,
00983 0x0000, outBytes, ctlCmd_usbTimeout);
00984 }
00985
00986
00987
00988
00989
00990
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
01266
01267 LOW_portUsbDevice::wValue_t valueCmd = readStraight_comCmdBase;
01268 if ( inBusResetBefore ) valueCmd = 0x0000 | ((inWritePreambleSize&0xff)<<8);
01269
01270
01271 switch ( inResultHandling ) {
01272 case noResult_rsltHdl: valueCmd |= 0x0004; break;
01273 case resultOnError_rsltHdl: break;
01274 case resultAlways_rsltHdl: valueCmd |= 0x0008; break;
01275 default : throw internal_error( "Unknown resultHandling_t value detected", __FILE__, __LINE__);
01276 }
01277 if ( inBusResetBefore ) valueCmd |= 0x0002;
01278 if ( inImmediateExec ) valueCmd |= 0x0001;
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
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
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
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
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
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
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
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
01464
01465
01466 switch ( inResultHandling ) {
01467 case noResult_rsltHdl: inOutValueCmd |= ICP_bitmask; break;
01468 case resultOnError_rsltHdl: break;
01469 case resultAlways_rsltHdl: inOutValueCmd |= NTF_bitmask; break;
01470 default : throw internal_error( "Unknown resultHandling_t value detected", __FILE__, __LINE__);
01471 }
01472 if ( inImmediateExec ) inOutValueCmd |= IM_bitmask;
01473 }
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483 const LOW_linkDS2490::pdSlewRate_t LOW_linkDS2490::PDSR_val_2_pdSlewRate( const PDSR_val_t inPDSR_val) const
01484 {
01485
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
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
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
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
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
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
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
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
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
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