📄 jobinfo.cpp
字号:
/* No pass through Util, since user wants the info */
cout.fill( '0' );
cout << hex
<< "0x" << setw(2) << sig0 << " "
<< "0x" << setw(2) << sig1 << " "
<< "0x" << setw(2) << sig2 << endl;
}
/* Get software version? */
if( getSWrevision )
{
Util.log( "Reading programmer software revision: " );
if( !prog->programmerSoftwareVersion( &major, &minor ) )
throw new ErrorMsg( "Software revision readout is not supported by this programmer!" );
/* No pass through Util, since user wants the info */
cout << (char) (major & 0xff) << "." << (char) (minor & 0xff) << endl;
}
/* Get software version? */
if( getHWrevision )
{
Util.log( "Reading programmer hardware revision: " );
if( !prog->programmerHardwareVersion( &major, &minor ) )
throw new ErrorMsg( "Hardware revision readout is not supported by this programmer!" );
/* No pass through Util, since user wants the info */
cout << (char) (major & 0xff) << "." << (char) (minor & 0xff) << endl;
}
}
void JobInfo::doDeviceDependent( AVRProgrammer * prog, AVRDevice * avr )
{
HEXFile * hex;
HEXFile * hex_v; // Used for verifying memory contents.
long pos; // Used when comparing data.
long bits; // Used for lock and fuse bits.
/* Set programmer pagesize */
prog->setPagesize( avr->getPageSize() );
/* Check if specified address limits are within device range */
if( flashEndAddress != -1 )
{
if( flashEndAddress >= avr->getFlashSize() )
throw new ErrorMsg( "Specified Flash address range is outside device address space!" );
} else
{
flashStartAddress = 0;
flashEndAddress = avr->getFlashSize() - 1;
}
if( eepromEndAddress != -1 )
{
if( eepromEndAddress >= avr->getEEPROMSize() )
throw new ErrorMsg( "Specified EEPROM address range is outside device address space!" );
} else
{
eepromStartAddress = 0;
eepromEndAddress = avr->getEEPROMSize() - 1;
}
/* Read out Flash contents? */
if( readFlash )
{
/* Check that filename has been specified */
if( outputFileFlash.size() == 0 )
throw new ErrorMsg( "Cannot read Flash without output file specified!" );
/* Prepare the file */
hex = new HEXFile( avr->getFlashSize() );
hex->setUsedRange( flashStartAddress, flashEndAddress );
/* Read data and save file */
Util.log( "Reading Flash contents...\r\n" );
if( !prog->readFlash( hex ) )
throw new ErrorMsg( "Flash readout is not supported by this programmer!" );
Util.log( "Writing HEX output file...\r\n" );
hex->writeFile( outputFileFlash );
delete hex;
}
/* Read out EEPROM contents? */
if( readEEPROM )
{
/* Check that filename has been specified */
if( outputFileEEPROM.size() == 0 )
throw new ErrorMsg( "Cannot read EEPROM without output file specified!" );
/* Prepare the file */
hex = new HEXFile( avr->getEEPROMSize() );
hex->setUsedRange( eepromStartAddress, eepromEndAddress );
/* Read data and save file */
Util.log( "Reading EEPROM contents...\r\n" );
if( !prog->readEEPROM( hex ) )
throw new ErrorMsg( "EEPROM readout is not supported by this programmer!" );
Util.log( "Writing HEX output file...\r\n" );
hex->writeFile( outputFileEEPROM );
delete hex;
}
/* Read lock bits? */
if( readLockBits )
{
Util.log( "Reading lock bits...\r\n" );
if( !prog->readLockBits( &bits ) )
throw new ErrorMsg( "Lock bit readout is not supported by this programmer!" );
cout << "0x" << std::hex << setw(2) << bits << endl;
}
/* Read fuse bits (both ordinary and extended)? */
if( readFuseBits )
{
if( !avr->getFuseStatus() )
throw new ErrorMsg( "Selected device has no fuse bits!" );
Util.log( "Reading fuse bits...\r\n" );
if( !prog->readFuseBits( &bits ) )
throw new ErrorMsg( "Fuse bit readout is not supported by this programmer!" );
cout << "0x" << std::hex << setw(4) << bits << endl;
if( avr->getXFuseStatus() )
{
if( !prog->readExtendedFuseBits( &bits ) )
throw new ErrorMsg( "Extended fuse bit readout is not supported by this programmer!" );
cout << "0x" << std::hex << setw(2) << bits << endl;
}
}
/* Erase chip before programming anything? */
if( chipErase )
{
Util.log( "Erasing chip contents...\r\n" );
if( !prog->chipErase() )
throw new ErrorMsg( "Chip erase is not supported by this programmer!" );
}
/* Prepare input hex file for flash */
if( programFlash || verifyFlash )
{
/* Check that filename has been specified */
if( inputFileFlash.size() == 0 )
throw new ErrorMsg( "Cannot program or verify Flash without input file specified!" );
/* Prepare the file */
hex = new HEXFile( avr->getFlashSize() );
/* Fill if wanted */
if( memoryFillPattern != -1 )
hex->clearAll( memoryFillPattern );
/* Read file */
Util.log( "Reading HEX input file for flash operations...\r\n" );
hex->readFile( inputFileFlash );
/* Check limits */
if( hex->getRangeStart() > flashEndAddress ||
hex->getRangeEnd() < flashStartAddress )
throw new ErrorMsg( "HEX file defines data outside specified range!" );
if( memoryFillPattern == -1 )
{
if( hex->getRangeStart() > flashStartAddress )
flashStartAddress = hex->getRangeStart();
if( hex->getRangeEnd() < flashEndAddress )
flashEndAddress = hex->getRangeEnd();
}
hex->setUsedRange( flashStartAddress, flashEndAddress );
}
/* Program new Flash contents? */
if( programFlash )
{
/* Program data */
Util.log( "Programming Flash contents...\r\n" );
if( !prog->writeFlash( hex ) )
throw new ErrorMsg( "Flash programming is not supported by this programmer!" );
}
/* Verify Flash contents? */
if( verifyFlash )
{
/* Prepare HEX file for comparision */
hex_v = new HEXFile( avr->getFlashSize() );
/* Compare to Flash */
Util.log( "Reading Flash contents...\r\n" );
hex_v->setUsedRange( hex->getRangeStart(), hex->getRangeEnd() );
if( !prog->readFlash( hex_v ) )
throw new ErrorMsg( "Flash readout is not supported by this programmer!" );
/* Compare data */
Util.log( "Comparing Flash data...\r\n" );
for( pos = hex->getRangeStart(); pos <= hex->getRangeEnd(); pos++ )
{
if( hex->getData( pos ) != hex_v->getData( pos ) )
{
cout << "Unequal at address 0x" << std::hex << pos << "!" << endl;
break;
}
}
if( pos > hex->getRangeEnd() ) // All equal?
{
cout << "Equal!" << endl;
}
delete hex_v;
}
if( programFlash || verifyFlash )
delete hex;
/* Prepare input hex file for EEPROM */
if( programEEPROM || verifyEEPROM )
{
/* Check that filename has been specified */
if( inputFileEEPROM.size() == 0 )
throw new ErrorMsg( "Cannot program or verify EEPROM without input file specified!" );
/* Prepare the file */
hex = new HEXFile( avr->getEEPROMSize() );
/* Fill if wanted */
if( memoryFillPattern != -1 )
hex->clearAll( memoryFillPattern );
/* Read file and program contents */
Util.log( "Reading HEX input file for EEPROM operations...\r\n" );
hex->readFile( inputFileEEPROM );
/* Check limits */
if( hex->getRangeStart() > eepromEndAddress ||
hex->getRangeEnd() < eepromStartAddress )
throw new ErrorMsg( "HEX file defines data outside specified range!" );
if( memoryFillPattern == -1 )
{
if( hex->getRangeStart() > eepromStartAddress )
eepromStartAddress = hex->getRangeStart();
if( hex->getRangeEnd() < eepromEndAddress )
eepromEndAddress = hex->getRangeEnd();
}
hex->setUsedRange( eepromStartAddress, eepromEndAddress );
}
/* Program new EEPROM contents? */
if( programEEPROM )
{
/* Program data */
Util.log( "Programming EEPROM contents...\r\n" );
if( !prog->writeEEPROM( hex ) )
throw new ErrorMsg( "EEPROM programming is not supported by this programmer!" );
}
/* Verify EEPROM contents? */
if( verifyEEPROM )
{
/* Prepare HEX file for comparision */
hex_v = new HEXFile( avr->getEEPROMSize() );
/* Compare to EEPROM */
Util.log( "Reading EEPROM contents...\r\n" );
hex_v->setUsedRange( hex->getRangeStart(), hex->getRangeEnd() );
if( !prog->readEEPROM( hex_v ) )
throw new ErrorMsg( "EEPROM readout is not supported by this programmer!" );
/* Compare data */
Util.log( "Comparing EEPROM data...\r\n" );
for( pos = hex->getRangeStart(); pos <= hex->getRangeEnd(); pos++ )
{
if( hex->getData( pos ) != hex_v->getData( pos ) )
{
cout << "Unequal at address 0x" << std::hex << pos << "!" << endl;
break;
}
}
if( pos > hex->getRangeEnd() ) // All equal?
{
cout << "Equal!" << endl;
}
delete hex_v;
}
if( programEEPROM || verifyEEPROM )
delete hex;
/* Program lock bits */
if( programLockBits != -1 )
{
Util.log( "Programming lock bits...\r\n" );
if( !prog->writeLockBits( programLockBits ) )
throw new ErrorMsg( "Lock bit programming is not supported by this programmer!" );
}
/* Program fuse bits */
if( programFuseBits != -1 )
{
if( !avr->getFuseStatus() )
throw new ErrorMsg( "Selected device has no fuse bits!" );
Util.log( "Programming fuse bits...\r\n" );
if( !prog->writeFuseBits( programFuseBits ) )
throw new ErrorMsg( "Fuse bit programming is not supported by this programmer!" );
}
/* Program extended fuse bits */
if( programExtendedFuseBits != -1 )
{
if( !avr->getXFuseStatus() )
throw new ErrorMsg( "Selected device has no extended fuse bits!" );
Util.log( "Programming extended fuse bits...\r\n" );
if( !prog->writeExtendedFuseBits( programExtendedFuseBits ) )
throw new ErrorMsg( "Extended fuse bit programming is not supported by this programmer!" );
}
/* Verify lock bits */
if( verifyLockBits != -1 )
{
Util.log( "Verifying lock bits...\r\n" );
if( !prog->readLockBits( &bits ) )
throw new ErrorMsg( "Lock bit readout is not supported by this programmer!" );
if( bits == verifyLockBits )
cout << "Equal!" << endl;
else
cout << "Unequal!" << endl;
}
/* Verify fuse bits */
if( verifyFuseBits != -1 )
{
if( !avr->getFuseStatus() )
throw new ErrorMsg( "Selected device has no fuse bits!" );
Util.log( "Verifying fuse bits...\r\n" );
if( !prog->readFuseBits( &bits ) )
throw new ErrorMsg( "Fuse bit readout is not supported by this programmer!" );
if( bits == verifyFuseBits )
cout << "Equal!" << endl;
else
cout << "Unequal!" << endl;
}
/* Verify extended fuse bits */
if( verifyExtendedFuseBits != -1 )
{
if( !avr->getXFuseStatus() )
throw new ErrorMsg( "Selected device has no extended fuse bits!" );
Util.log( "Verifying extended fuse bits...\r\n" );
if( !prog->readExtendedFuseBits( &bits ) )
throw new ErrorMsg( "Extended fuse bit readout is not supported by this programmer!" );
if( bits == verifyExtendedFuseBits )
cout << "Equal!" << endl;
else
cout << "Unequal!" << endl;
}
/* Read osccal value? */
if( OSCCAL_Parameter != -1 )
{
/* Output to log if read from device */
if( readOSCCAL )
{
Util.log( "Reading OSCCAL from device...\r\n" );
pos = OSCCAL_Parameter;
if( !prog->readOSCCAL( pos, &OSCCAL_Parameter ) )
throw new ErrorMsg( "OSCCAL parameter readout is not supported by this programmer!" );
cout << "0x" << std::hex << setw(2) << OSCCAL_Parameter << endl;
}
}
/* Write OSCCAL to Flash? */
if( OSCCAL_FlashAddress != -1 )
{
if( OSCCAL_Parameter == -1 )
throw new ErrorMsg( "OSCCAL value not specified!" );
Util.log( "Programming OSCCAL value to Flash...\r\n" );
if( !prog->writeFlashByte( OSCCAL_FlashAddress, OSCCAL_Parameter ) )
throw new ErrorMsg( "Flash programming is not supported by this programmer!" );
}
/* Write OSCCAL to EEPROM? */
if( OSCCAL_EEPROMAddress != -1 )
{
if( OSCCAL_Parameter == -1 )
throw new ErrorMsg( "OSCCAL value not specified!" );
Util.log( "Programming OSCCAL value to EEPROM...\r\n" );
if( !prog->writeEEPROMByte( OSCCAL_EEPROMAddress, OSCCAL_Parameter ) )
throw new ErrorMsg( "EEPROM programming is not supported by this programmer!" );
}
}
/* end of file */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -