Exemple #1
0
void LOW_devDS2406::readMemUniversal( const uint16_t inStartAddr, byteVec_t &outBytes, 
                                      const uint16_t inMaxLen, const owCommand_t inCommand) const
{
  if ( inStartAddr >= inMaxLen )
    throw devDS2406_error( "Illegal address to read", __FILE__, __LINE__);
  
  if ( inStartAddr+outBytes.size() > inMaxLen )
    throw devDS2406_error( "Too many bytes to read", __FILE__, __LINE__);

  linkLock  lock( *this);
    
  byteVec_t  sendBytes = byteVec_t( 3);
  sendBytes[0] = inCommand;
  sendBytes[1] = inStartAddr&0xff;
  sendBytes[2] = inStartAddr>>8;
  
  cmd_MatchROM();

  getLink().writeData( sendBytes);
  getLink().readData( outBytes);
  
  if ( inStartAddr+outBytes.size() == inMaxLen ) { // read to end of mem => CRC16 checksumm is available
    uint16_t expectedCrc16 = 0x0000;
    expectedCrc16 |= (getLink().readDataByte() ^ 0xff);      // NOTE: CRC bytzes are sent _inverted_!
    expectedCrc16 |= (getLink().readDataByte() ^ 0xff) << 8; // NOTE: CRC bytzes are sent _inverted_!
    if ( LOW_helper_CRC::calcCRC16( outBytes, LOW_helper_CRC::calcCRC16( sendBytes)) != expectedCrc16 )
      throw LOW_helper_CRC::crc_error( "DS2406 - CRC error in read operation", __FILE__, __LINE__);
  }

  //getLink().resetBus();
}
Exemple #2
0
LOW_devDS2406::channelInfo_t LOW_devDS2406::getChannel(const CRCtype_t inCRCtype, const chanSelect_t inChanSelect,
	    const interleaveMode_t inInterleaveMode, const toggleMode_t inToggleMode,
	    const initialMode_t inInitialMode, const activityLatchReset_t inALR)
{
	// locking done by initializer

	  if ( inChanSelect == noneSelect )
	    throw devDS2406_error( "At least one channel must be selected", __FILE__, __LINE__);

	  if ( ! getHasPioB() && ( inChanSelect==chanBSelect || inChanSelect==chanBothSelect ) )
	    throw devDS2406_error( "Channel B selected, but device has only PIO A", __FILE__, __LINE__);

	  if ( inChanSelect!=chanBothSelect && inInterleaveMode )
	    throw devDS2406_error( "Interleave mode only available when selected both channels", __FILE__, __LINE__);

	  byteVec_t  outBytes = byteVec_t( 3 );
	  outBytes[0] =  ChannelAccess_COMMAND;
	  outBytes[1] =  (inCRCtype & 0x03)                  |
	                 ((inChanSelect&0x3) <<2 )          |
	                 ((static_cast<uint8_t>(inInterleaveMode))<<4) |
	                 ((static_cast<uint8_t>(inToggleMode))<<5)     |
	                 ((static_cast<uint8_t>(inInitialMode))<<6)    |
	                 ((static_cast<int8_t>(inALR))<<7);
	  outBytes[2] =  0xff;  // reserved, 0xff sent as specified


	  cmd_MatchROM();
	  getLink().writeData( outBytes );

	  uint8_t infoByte = getLink().readDataByte();

	  LOW_devDS2406::channelInfo_t channelInfo;
	  channelInfo.channelFFQ_pioA    = (infoByte>>0)&0x01;
	  channelInfo.channelFFQ_pioB    = (infoByte>>1)&0x01;
	  channelInfo.sensedLevel_pioA   = (infoByte>>2)&0x01;
	  channelInfo.sensedLevel_pioB   = (infoByte>>3)&0x01;
	  channelInfo.activityLatch_pioA = (infoByte>>4)&0x01;
	  channelInfo.activityLatch_pioB = (infoByte>>5)&0x01;
	  channelInfo.hasPioB            = (infoByte>>6)&0x01;
	  channelInfo.isExternalPowered  = (infoByte>>7)&0x01;

//	  if (inCRCtype==CRCtype_t::CRC_after1Byte )
//	  {
//		  vector<uint8_t> crc(2);
//		  getLink().readData(crc);
//		  uint16_t expectedCrc16 =0;
//		  expectedCrc16 |= (crc[0] ^ 0xff);      // NOTE: CRC bytzes are sent _inverted_!
//		  expectedCrc16 |= (crc[1] ^ 0xff) << 8; // NOTE: CRC bytzes are sent _inverted_!
//		  if ( LOW_helper_CRC::calcCRC16( &infoByte,1 , expectedCrc16) != expectedCrc16 )
//			  throw LOW_helper_CRC::crc_error( "CRC error in read operation", __FILE__, __LINE__);
//	  }

	  return channelInfo;
}
Exemple #3
0
bool LOW_devDS2408::ReadPIO(uint8_t & value)
{
	linkLock  lock( *this);

	cmd_MatchROM();
	getLink().writeData(static_cast<uint8_t>(W1_F29_FUNC_CHANN_ACCESS_READ));

	value = getLink().readDataByte();

	value =~value;

	return true;
}
Exemple #4
0
bool LOW_devDS2408::WriteControlStatus(uint8_t status)
{
	linkLock  lock( *this);
	vector<uint8_t> writedata;
	writedata.push_back(static_cast<uint8_t>(W1_F29_FUNC_WRITE_COND_SEARCH_REG));
	writedata.push_back(static_cast<uint8_t>(W1_F29_REG_CONTROL_AND_STATUS));
	writedata.push_back(static_cast<uint8_t>(0x00));
	writedata.push_back(static_cast<uint8_t>(status));
	cmd_MatchROM();
	getLink().writeData(writedata);

	return true;
}
Exemple #5
0
bool LOW_devDS2408::WritePIO(uint8_t pin, bool value)
{
	linkLock  lock( *this);

	cmd_MatchROM();

	uint8_t oldvalue = 0x00;
	if (!ReadPIO(oldvalue))
		return false;

	uint8_t newvalue = value ? oldvalue | (0x01 << pin) : oldvalue & ~(0x01 << pin);

	if (!WritePIO(newvalue))
		return false;

	return true;
}
Exemple #6
0
//=====================================================================================
//
// public methods
//
bool LOW_devDS2408::WritePIO(uint8_t piobyte)
{
	linkLock  lock( *this);

	cmd_MatchROM();
	vector<uint8_t> writedata;
	writedata.push_back(static_cast<uint8_t>(W1_F29_FUNC_CHANN_ACCESS_WRITE));
	uint8_t invertedpiobyte = ~piobyte;
	writedata.push_back(invertedpiobyte);
	writedata.push_back(piobyte);
	getLink().writeData(writedata);

	if (getLink().readDataByte() != 0xAA)
		return false;
	uint8_t newstate = getLink().readDataByte();

	if (newstate!=invertedpiobyte)
		return false;

	return true;
}
Exemple #7
0
void LOW_devDS2406::cmd_WriteStatus( const uint8_t inStartAddr, const byteVec_t &inWriteBytes) const
{
  if ( inStartAddr+inWriteBytes.size() > 8 )
    throw devDS2406_error( "Too many bytes to write", __FILE__, __LINE__);
  
  if ( inStartAddr==0x05 || inStartAddr==0x06 )
    throw devDS2406_error( "Address not writeable", __FILE__, __LINE__);
  
  // not yet supported registers
  if ( /*inStartAddr>=0x00 &&*/ inStartAddr<=0x04 )
    throw devDS2406_error( "Access to address not supported in this version", __FILE__, __LINE__);
  
  linkLock  lock( *this);

  // only address 7 remains, i.e. address must be 7 and length of inWriteBytes is 1
  
  byteVec_t  sendBytes = byteVec_t( 4);
  sendBytes[0] = WriteStatus_COMMAND;
  sendBytes[1] = inStartAddr&0xff;
  sendBytes[2] = inStartAddr>>8;
  sendBytes[3] = inWriteBytes[0];
  
  cmd_MatchROM();

  getLink().writeData( sendBytes);
    
  uint16_t expectedCrc16 = 0x0000;
  expectedCrc16 |= (getLink().readDataByte() ^ 0xff);      // NOTE: CRC bytzes are sent _inverted_!
  expectedCrc16 |= (getLink().readDataByte() ^ 0xff) << 8; // NOTE: CRC bytzes are sent _inverted_!
  if ( LOW_helper_CRC::calcCRC16( sendBytes) != expectedCrc16 )
    throw LOW_helper_CRC::crc_error( "CRC error in write operation", __FILE__, __LINE__);

  //getLink().writeData( static_cast<uint8_t>(0xff));

  // skip validation byte
  //uint8_t validationByte = getLink().readDataByte();

  //getLink().resetBus();
}