Issue 2 move folders and use deep path include file names to prevent collisions (#4)
* moving folders and files and adjust server demo build * Fix Makefile for apps/server on Linux * fix unit test source file folders * fix datetime convert UTC functions. Add Code::Blocks project for datetime testing * added some ignore extensions * disable parallel make option * fix build for abort, dcc, and epics apps * fix build for dcc, epics, error, and getevent apps. * Fixed building of all apps * fix the ipv4 to ipv6 router app build * Change indent style from Google to Webkit * make pretty to re-format style * removed common Makefile since we already had one and two was too many * remove scripts from root folder that are no longer maintained or used * remove mercurial EOL and ignore files for git repo * remove .vscodeconfig files from repo * tweak clang-format style * clang-format src and apps with tweaked style * added clang-tidy to fix readability if braces in src * result of make tidy for src and apps * fix clang-tidy mangling * Added code::blocks project for BACnet server simulation * added code::blocks linux project for WhoIs app * update text files for EOL * fix EOL in some files * fixed make win32 apps for older gcc * Removed Borland C++ Makefile in apps. Unable to maintain support for Borland C++ compiler. * created codeblocks project for apps/epics for Windows * fixing ports/xplained to work with new data structure. * fix ports/xplained example for Atmel Studio compile * fix ports/stm32f10x example for gcc Makefile compile * fix ports/stm32f10x example for IAR EWARM compile * fix ports/xplained timer callback * fix ports/bdk_atxx_mspt build with subdirs * fix ports/bdk_atxx_mspt build with subdirs * updated git ignore for IAR build artifacts * updated gitignore for non-tracked files and folders * fixed bdk-atxx4-mstp port for Rowley Crossworks project file * fixed bdk-atxx4-mstp port for GCC AVR Makefile * fixed atmega168 port for IAR AVR and GCC AVR Makefile * fixed at91sam7s port for IAR ARM and GCC ARM Makefile * removed unmaintainable DOS, RTOS32, and atmega8 ports. Updated rx62n (untested). * changed arm7 to uip port
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,84 +1,84 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : AVRBootloader.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class providing an interface to the AVR bootloader
|
||||
* described in Application Note AVR109.
|
||||
* This class is derived from AVRPRogrammer.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef AVRBOOTLOADER_HPP
|
||||
#define AVRBOOTLOADER_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "AVRProgrammer.hpp"
|
||||
#include "Utility.hpp"
|
||||
|
||||
class AVRBootloader : public AVRProgrammer
|
||||
{
|
||||
protected:
|
||||
virtual void setAddress( long address );
|
||||
virtual void writeFlashLowByte( long value ); // Alwyas low byte first...
|
||||
virtual void writeFlashHighByte( long value ); // ...then high byte.
|
||||
virtual void writeFlashPage();
|
||||
|
||||
virtual bool writeFlashBlock( HEXFile * data );
|
||||
virtual bool readFlashBlock( HEXFile * data );
|
||||
virtual bool writeEEPROMBlock( HEXFile * data );
|
||||
virtual bool readEEPROMBlock( HEXFile * data );
|
||||
|
||||
public:
|
||||
/* Constructor */
|
||||
AVRBootloader( CommChannel * _comm );
|
||||
|
||||
/* Destructor */
|
||||
~AVRBootloader();
|
||||
|
||||
/* Methods */
|
||||
virtual bool enterProgrammingMode();
|
||||
virtual bool leaveProgrammingMode();
|
||||
|
||||
virtual bool chipErase();
|
||||
|
||||
virtual bool readOSCCAL( long pos, long * value );
|
||||
virtual bool readSignature( long * sig0, long * sig1, long * sig2 );
|
||||
virtual bool checkSignature( long sig0, long sig1, long sig2 );
|
||||
|
||||
virtual bool writeFlashByte( long address, long value );
|
||||
virtual bool writeEEPROMByte( long address, long value );
|
||||
|
||||
virtual bool writeFlash( HEXFile * data );
|
||||
virtual bool readFlash( HEXFile * data );
|
||||
|
||||
virtual bool writeEEPROM( HEXFile * data );
|
||||
virtual bool readEEPROM( HEXFile * data );
|
||||
|
||||
virtual bool writeLockBits( long bits );
|
||||
virtual bool readLockBits( long * bits );
|
||||
|
||||
virtual bool writeFuseBits( long bits );
|
||||
virtual bool readFuseBits( long * bits );
|
||||
virtual bool writeExtendedFuseBits( long bits );
|
||||
virtual bool readExtendedFuseBits( long * bits );
|
||||
|
||||
virtual bool programmerSoftwareVersion( long * major, long * minor );
|
||||
virtual bool programmerHardwareVersion( long * major, long * minor );
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : AVRBootloader.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class providing an interface to the AVR bootloader
|
||||
* described in Application Note AVR109.
|
||||
* This class is derived from AVRPRogrammer.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef AVRBOOTLOADER_HPP
|
||||
#define AVRBOOTLOADER_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "AVRProgrammer.hpp"
|
||||
#include "Utility.hpp"
|
||||
|
||||
class AVRBootloader : public AVRProgrammer
|
||||
{
|
||||
protected:
|
||||
virtual void setAddress( long address );
|
||||
virtual void writeFlashLowByte( long value ); // Alwyas low byte first...
|
||||
virtual void writeFlashHighByte( long value ); // ...then high byte.
|
||||
virtual void writeFlashPage();
|
||||
|
||||
virtual bool writeFlashBlock( HEXFile * data );
|
||||
virtual bool readFlashBlock( HEXFile * data );
|
||||
virtual bool writeEEPROMBlock( HEXFile * data );
|
||||
virtual bool readEEPROMBlock( HEXFile * data );
|
||||
|
||||
public:
|
||||
/* Constructor */
|
||||
AVRBootloader( CommChannel * _comm );
|
||||
|
||||
/* Destructor */
|
||||
~AVRBootloader();
|
||||
|
||||
/* Methods */
|
||||
virtual bool enterProgrammingMode();
|
||||
virtual bool leaveProgrammingMode();
|
||||
|
||||
virtual bool chipErase();
|
||||
|
||||
virtual bool readOSCCAL( long pos, long * value );
|
||||
virtual bool readSignature( long * sig0, long * sig1, long * sig2 );
|
||||
virtual bool checkSignature( long sig0, long sig1, long sig2 );
|
||||
|
||||
virtual bool writeFlashByte( long address, long value );
|
||||
virtual bool writeEEPROMByte( long address, long value );
|
||||
|
||||
virtual bool writeFlash( HEXFile * data );
|
||||
virtual bool readFlash( HEXFile * data );
|
||||
|
||||
virtual bool writeEEPROM( HEXFile * data );
|
||||
virtual bool readEEPROM( HEXFile * data );
|
||||
|
||||
virtual bool writeLockBits( long bits );
|
||||
virtual bool readLockBits( long * bits );
|
||||
|
||||
virtual bool writeFuseBits( long bits );
|
||||
virtual bool readFuseBits( long * bits );
|
||||
virtual bool writeExtendedFuseBits( long bits );
|
||||
virtual bool readExtendedFuseBits( long * bits );
|
||||
|
||||
virtual bool programmerSoftwareVersion( long * major, long * minor );
|
||||
virtual bool programmerHardwareVersion( long * major, long * minor );
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,157 +1,157 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : AVRDevice.cpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 4017 $
|
||||
* Date : $Date: 2008-06-02 14:26:03 +0200 (ma, 02 jun 2008) $
|
||||
* Updated by : $Author: khole $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class containing information of device memory sizes etc.
|
||||
* It also provides funcitons for reading these parameters from
|
||||
* the PartDescriptionFiles supplied with AVR Studio 4.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "AVRDevice.hpp"
|
||||
|
||||
|
||||
/* Constructor */
|
||||
AVRDevice::AVRDevice( const string & _deviceName ) :
|
||||
deviceName( _deviceName )
|
||||
{
|
||||
flashSize =
|
||||
eepromSize = 0;
|
||||
hasFuseBits = false;
|
||||
hasExtendedFuseBits = false;
|
||||
signature0 =
|
||||
signature1 =
|
||||
signature2 = 0;
|
||||
pagesize = -1;
|
||||
}
|
||||
|
||||
|
||||
/* Destructor */
|
||||
AVRDevice::~AVRDevice()
|
||||
{
|
||||
/* no code here */
|
||||
}
|
||||
|
||||
/* Read parameters from AVR Studio XML files */
|
||||
void AVRDevice::readParametersFromAVRStudio( vector<string> & searchpath )
|
||||
{
|
||||
string path;
|
||||
string signature;
|
||||
string cache;
|
||||
|
||||
#ifndef NOREGISTRY
|
||||
/* Locate the directory containing the XML files from the Windows registry database */
|
||||
try
|
||||
{
|
||||
path = Util.getRegistryValue( "SOFTWARE\\Atmel\\AVRTools\\", "AVRToolsPath" );
|
||||
path += "\\PartDescriptionFiles";
|
||||
searchpath.push_back( path );
|
||||
} catch( ErrorMsg * e )
|
||||
{
|
||||
delete e;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Search for file */
|
||||
path.erase();
|
||||
int i;
|
||||
for( i = 0; i < searchpath.size(); i++ )
|
||||
{
|
||||
path = searchpath[i] + "\\" + deviceName + ".xml";
|
||||
if( Util.fileExists( path ) )
|
||||
break;
|
||||
}
|
||||
|
||||
if( i == searchpath.size() )
|
||||
throw new ErrorMsg( "Device XML file not found in search path!" );
|
||||
|
||||
/* Parse the file for required info */
|
||||
Util.log( "Parsing '" + path + "'...\r\n" );
|
||||
XMLFile f( path ); // Load XML info
|
||||
|
||||
flashSize = atoi( f.getValue( "AVRPART\\MEMORY\\PROG_FLASH" ).c_str() );
|
||||
eepromSize = atoi( f.getValue( "AVRPART\\MEMORY\\EEPROM" ).c_str() );
|
||||
|
||||
cache += "<AVRPART><MEMORY><PROG_FLASH>";
|
||||
cache += f.getValue( "AVRPART\\MEMORY\\PROG_FLASH" );
|
||||
cache += "</PROG_FLASH><EEPROM>";
|
||||
cache += f.getValue( "AVRPART\\MEMORY\\EEPROM" );
|
||||
cache += "</EEPROM>";
|
||||
|
||||
if( f.exists( "AVRPART\\MEMORY\\BOOT_CONFIG" ) )
|
||||
{
|
||||
pagesize = atoi( f.getValue( "AVRPART\\MEMORY\\BOOT_CONFIG\\PAGESIZE" ).c_str() );
|
||||
pagesize <<= 1; // We want pagesize in bytes.
|
||||
|
||||
cache += "<BOOT_CONFIG><PAGESIZE>";
|
||||
cache += f.getValue( "AVRPART\\MEMORY\\BOOT_CONFIG\\PAGESIZE" );
|
||||
cache += "</PAGESIZE></BOOT_CONFIG>";
|
||||
}
|
||||
|
||||
cache += "</MEMORY>";
|
||||
|
||||
if( f.exists( "AVRPART\\FUSE" ) )
|
||||
{
|
||||
hasFuseBits = true;
|
||||
|
||||
cache += "<FUSE>";
|
||||
|
||||
if( f.exists( "AVRPART\\FUSE\\EXTENDED" ) )
|
||||
{
|
||||
hasExtendedFuseBits = true;
|
||||
cache += "<EXTENDED></EXTENDED>";
|
||||
}
|
||||
|
||||
cache += "</FUSE>";
|
||||
}
|
||||
|
||||
signature = f.getValue( "AVRPART\\ADMIN\\SIGNATURE\\ADDR000" );
|
||||
signature.erase( 0, 1 ); // Remove the $ character.
|
||||
signature0 = Util.convertHex( signature );
|
||||
|
||||
signature = f.getValue( "AVRPART\\ADMIN\\SIGNATURE\\ADDR001" );
|
||||
signature.erase( 0, 1 ); // Remove the $ character.
|
||||
signature1 = Util.convertHex( signature );
|
||||
|
||||
signature = f.getValue( "AVRPART\\ADMIN\\SIGNATURE\\ADDR002" );
|
||||
signature.erase( 0, 1 ); // Remove the $ character.
|
||||
signature2 = Util.convertHex( signature );
|
||||
|
||||
cache += "<ADMIN><SIGNATURE><ADDR000>";
|
||||
cache += f.getValue( "AVRPART\\ADMIN\\SIGNATURE\\ADDR000" );
|
||||
cache += "</ADDR000><ADDR001>";
|
||||
cache += f.getValue( "AVRPART\\ADMIN\\SIGNATURE\\ADDR001" );
|
||||
cache += "</ADDR001><ADDR002>";
|
||||
cache += f.getValue( "AVRPART\\ADMIN\\SIGNATURE\\ADDR002" );
|
||||
cache += "</ADDR002></SIGNATURE></ADMIN></AVRPART>\r\n";
|
||||
|
||||
/* Save cached file to application directory */
|
||||
Util.log( "Saving cached XML parameters...\r\n" );
|
||||
Util.saveString( cache, searchpath[1] + "\\" + deviceName + ".xml" );
|
||||
}
|
||||
|
||||
|
||||
void AVRDevice::getSignature( long * sig0, long * sig1, long * sig2 )
|
||||
{
|
||||
if( sig0 == NULL || sig1 == NULL || sig2 == NULL )
|
||||
throw new ErrorMsg( "Cannot copy signature bytes to NULL-pointers!" );
|
||||
|
||||
*sig0 = signature0;
|
||||
*sig1 = signature1;
|
||||
*sig2 = signature2;
|
||||
}
|
||||
|
||||
|
||||
/* end of file */
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : AVRDevice.cpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 4017 $
|
||||
* Date : $Date: 2008-06-02 14:26:03 +0200 (ma, 02 jun 2008) $
|
||||
* Updated by : $Author: khole $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class containing information of device memory sizes etc.
|
||||
* It also provides funcitons for reading these parameters from
|
||||
* the PartDescriptionFiles supplied with AVR Studio 4.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "AVRDevice.hpp"
|
||||
|
||||
|
||||
/* Constructor */
|
||||
AVRDevice::AVRDevice( const string & _deviceName ) :
|
||||
deviceName( _deviceName )
|
||||
{
|
||||
flashSize =
|
||||
eepromSize = 0;
|
||||
hasFuseBits = false;
|
||||
hasExtendedFuseBits = false;
|
||||
signature0 =
|
||||
signature1 =
|
||||
signature2 = 0;
|
||||
pagesize = -1;
|
||||
}
|
||||
|
||||
|
||||
/* Destructor */
|
||||
AVRDevice::~AVRDevice()
|
||||
{
|
||||
/* no code here */
|
||||
}
|
||||
|
||||
/* Read parameters from AVR Studio XML files */
|
||||
void AVRDevice::readParametersFromAVRStudio( vector<string> & searchpath )
|
||||
{
|
||||
string path;
|
||||
string signature;
|
||||
string cache;
|
||||
|
||||
#ifndef NOREGISTRY
|
||||
/* Locate the directory containing the XML files from the Windows registry database */
|
||||
try
|
||||
{
|
||||
path = Util.getRegistryValue( "SOFTWARE\\Atmel\\AVRTools\\", "AVRToolsPath" );
|
||||
path += "\\PartDescriptionFiles";
|
||||
searchpath.push_back( path );
|
||||
} catch( ErrorMsg * e )
|
||||
{
|
||||
delete e;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Search for file */
|
||||
path.erase();
|
||||
int i;
|
||||
for( i = 0; i < searchpath.size(); i++ )
|
||||
{
|
||||
path = searchpath[i] + "\\" + deviceName + ".xml";
|
||||
if( Util.fileExists( path ) )
|
||||
break;
|
||||
}
|
||||
|
||||
if( i == searchpath.size() )
|
||||
throw new ErrorMsg( "Device XML file not found in search path!" );
|
||||
|
||||
/* Parse the file for required info */
|
||||
Util.log( "Parsing '" + path + "'...\r\n" );
|
||||
XMLFile f( path ); // Load XML info
|
||||
|
||||
flashSize = atoi( f.getValue( "AVRPART\\MEMORY\\PROG_FLASH" ).c_str() );
|
||||
eepromSize = atoi( f.getValue( "AVRPART\\MEMORY\\EEPROM" ).c_str() );
|
||||
|
||||
cache += "<AVRPART><MEMORY><PROG_FLASH>";
|
||||
cache += f.getValue( "AVRPART\\MEMORY\\PROG_FLASH" );
|
||||
cache += "</PROG_FLASH><EEPROM>";
|
||||
cache += f.getValue( "AVRPART\\MEMORY\\EEPROM" );
|
||||
cache += "</EEPROM>";
|
||||
|
||||
if( f.exists( "AVRPART\\MEMORY\\BOOT_CONFIG" ) )
|
||||
{
|
||||
pagesize = atoi( f.getValue( "AVRPART\\MEMORY\\BOOT_CONFIG\\PAGESIZE" ).c_str() );
|
||||
pagesize <<= 1; // We want pagesize in bytes.
|
||||
|
||||
cache += "<BOOT_CONFIG><PAGESIZE>";
|
||||
cache += f.getValue( "AVRPART\\MEMORY\\BOOT_CONFIG\\PAGESIZE" );
|
||||
cache += "</PAGESIZE></BOOT_CONFIG>";
|
||||
}
|
||||
|
||||
cache += "</MEMORY>";
|
||||
|
||||
if( f.exists( "AVRPART\\FUSE" ) )
|
||||
{
|
||||
hasFuseBits = true;
|
||||
|
||||
cache += "<FUSE>";
|
||||
|
||||
if( f.exists( "AVRPART\\FUSE\\EXTENDED" ) )
|
||||
{
|
||||
hasExtendedFuseBits = true;
|
||||
cache += "<EXTENDED></EXTENDED>";
|
||||
}
|
||||
|
||||
cache += "</FUSE>";
|
||||
}
|
||||
|
||||
signature = f.getValue( "AVRPART\\ADMIN\\SIGNATURE\\ADDR000" );
|
||||
signature.erase( 0, 1 ); // Remove the $ character.
|
||||
signature0 = Util.convertHex( signature );
|
||||
|
||||
signature = f.getValue( "AVRPART\\ADMIN\\SIGNATURE\\ADDR001" );
|
||||
signature.erase( 0, 1 ); // Remove the $ character.
|
||||
signature1 = Util.convertHex( signature );
|
||||
|
||||
signature = f.getValue( "AVRPART\\ADMIN\\SIGNATURE\\ADDR002" );
|
||||
signature.erase( 0, 1 ); // Remove the $ character.
|
||||
signature2 = Util.convertHex( signature );
|
||||
|
||||
cache += "<ADMIN><SIGNATURE><ADDR000>";
|
||||
cache += f.getValue( "AVRPART\\ADMIN\\SIGNATURE\\ADDR000" );
|
||||
cache += "</ADDR000><ADDR001>";
|
||||
cache += f.getValue( "AVRPART\\ADMIN\\SIGNATURE\\ADDR001" );
|
||||
cache += "</ADDR001><ADDR002>";
|
||||
cache += f.getValue( "AVRPART\\ADMIN\\SIGNATURE\\ADDR002" );
|
||||
cache += "</ADDR002></SIGNATURE></ADMIN></AVRPART>\r\n";
|
||||
|
||||
/* Save cached file to application directory */
|
||||
Util.log( "Saving cached XML parameters...\r\n" );
|
||||
Util.saveString( cache, searchpath[1] + "\\" + deviceName + ".xml" );
|
||||
}
|
||||
|
||||
|
||||
void AVRDevice::getSignature( long * sig0, long * sig1, long * sig2 )
|
||||
{
|
||||
if( sig0 == NULL || sig1 == NULL || sig2 == NULL )
|
||||
throw new ErrorMsg( "Cannot copy signature bytes to NULL-pointers!" );
|
||||
|
||||
*sig0 = signature0;
|
||||
*sig1 = signature1;
|
||||
*sig2 = signature2;
|
||||
}
|
||||
|
||||
|
||||
/* end of file */
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : AVRDevice.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class containing information of device memory sizes etc.
|
||||
* It also provides funcitons for reading these parameters from
|
||||
* the PartDescriptionFiles supplied with AVR Studio 4.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef AVRDEVICE_HPP
|
||||
#define AVRDEVICE_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Utility.hpp"
|
||||
#include "XMLParser.hpp"
|
||||
#include "ErrorMsg.hpp"
|
||||
|
||||
class AVRDevice
|
||||
{
|
||||
protected:
|
||||
string deviceName; // The name of the device, eg. ATmega128.
|
||||
|
||||
long flashSize; // Size of Flash memory in bytes.
|
||||
long eepromSize; // Size of EEPROM memory in bytes.
|
||||
bool hasFuseBits; // Does this device have fuse bits at all?
|
||||
bool hasExtendedFuseBits; // Does this device have extended fuses?
|
||||
long signature0;
|
||||
long signature1;
|
||||
long signature2; // The three signature bytes, read from XML PartDescriptionFiles.
|
||||
long pagesize; // Flash page size.
|
||||
|
||||
public:
|
||||
/* Constructor */
|
||||
AVRDevice( const string & _deviceName );
|
||||
|
||||
/* Destructor */
|
||||
~AVRDevice();
|
||||
|
||||
/* Methods */
|
||||
void readParametersFromAVRStudio( vector<string> & searchpath );
|
||||
|
||||
long getFlashSize() { return flashSize; }
|
||||
long getEEPROMSize() { return eepromSize; }
|
||||
long getPageSize() { return pagesize; }
|
||||
bool getFuseStatus() { return hasFuseBits; }
|
||||
bool getXFuseStatus() { return hasExtendedFuseBits; }
|
||||
|
||||
void getSignature( long * sig0, long * sig1, long * sig2 );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : AVRDevice.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class containing information of device memory sizes etc.
|
||||
* It also provides funcitons for reading these parameters from
|
||||
* the PartDescriptionFiles supplied with AVR Studio 4.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef AVRDEVICE_HPP
|
||||
#define AVRDEVICE_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Utility.hpp"
|
||||
#include "XMLParser.hpp"
|
||||
#include "ErrorMsg.hpp"
|
||||
|
||||
class AVRDevice
|
||||
{
|
||||
protected:
|
||||
string deviceName; // The name of the device, eg. ATmega128.
|
||||
|
||||
long flashSize; // Size of Flash memory in bytes.
|
||||
long eepromSize; // Size of EEPROM memory in bytes.
|
||||
bool hasFuseBits; // Does this device have fuse bits at all?
|
||||
bool hasExtendedFuseBits; // Does this device have extended fuses?
|
||||
long signature0;
|
||||
long signature1;
|
||||
long signature2; // The three signature bytes, read from XML PartDescriptionFiles.
|
||||
long pagesize; // Flash page size.
|
||||
|
||||
public:
|
||||
/* Constructor */
|
||||
AVRDevice( const string & _deviceName );
|
||||
|
||||
/* Destructor */
|
||||
~AVRDevice();
|
||||
|
||||
/* Methods */
|
||||
void readParametersFromAVRStudio( vector<string> & searchpath );
|
||||
|
||||
long getFlashSize() { return flashSize; }
|
||||
long getEEPROMSize() { return eepromSize; }
|
||||
long getPageSize() { return pagesize; }
|
||||
bool getFuseStatus() { return hasFuseBits; }
|
||||
bool getXFuseStatus() { return hasExtendedFuseBits; }
|
||||
|
||||
void getSignature( long * sig0, long * sig1, long * sig2 );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,78 +1,78 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : AVRInSystemProg.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class providing an interface to the AVR ISP described
|
||||
* in Application Note AVR910. This class is derived from AVRPRogrammer.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef AVRINSYSTEMPROG_HPP
|
||||
#define AVRINSYSTEMPROG_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "AVRProgrammer.hpp"
|
||||
#include "Utility.hpp"
|
||||
|
||||
class AVRInSystemProg : public AVRProgrammer
|
||||
{
|
||||
protected:
|
||||
void setAddress( long address );
|
||||
void writeFlashLowByte( long value ); // Alwyas low byte first...
|
||||
void writeFlashHighByte( long value ); // ...then high byte.
|
||||
void writeFlashPage();
|
||||
|
||||
public:
|
||||
/* Constructor */
|
||||
AVRInSystemProg( CommChannel * _comm );
|
||||
|
||||
/* Destructor */
|
||||
~AVRInSystemProg();
|
||||
|
||||
/* Methods */
|
||||
virtual bool enterProgrammingMode();
|
||||
virtual bool leaveProgrammingMode();
|
||||
|
||||
virtual bool chipErase();
|
||||
|
||||
virtual bool readOSCCAL( long pos, long * value );
|
||||
virtual bool readSignature( long * sig0, long * sig1, long * sig2 );
|
||||
virtual bool checkSignature( long sig0, long sig1, long sig2 );
|
||||
|
||||
virtual bool writeFlashByte( long address, long value );
|
||||
virtual bool writeEEPROMByte( long address, long value );
|
||||
|
||||
virtual bool writeFlash( HEXFile * data );
|
||||
virtual bool readFlash( HEXFile * data );
|
||||
|
||||
virtual bool writeEEPROM( HEXFile * data );
|
||||
virtual bool readEEPROM( HEXFile * data );
|
||||
|
||||
virtual bool writeLockBits( long bits );
|
||||
virtual bool readLockBits( long * bits );
|
||||
|
||||
virtual bool writeFuseBits( long bits );
|
||||
virtual bool readFuseBits( long * bits );
|
||||
virtual bool writeExtendedFuseBits( long bits );
|
||||
virtual bool readExtendedFuseBits( long * bits );
|
||||
|
||||
virtual bool programmerSoftwareVersion( long * major, long * minor );
|
||||
virtual bool programmerHardwareVersion( long * major, long * minor );
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : AVRInSystemProg.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class providing an interface to the AVR ISP described
|
||||
* in Application Note AVR910. This class is derived from AVRPRogrammer.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef AVRINSYSTEMPROG_HPP
|
||||
#define AVRINSYSTEMPROG_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "AVRProgrammer.hpp"
|
||||
#include "Utility.hpp"
|
||||
|
||||
class AVRInSystemProg : public AVRProgrammer
|
||||
{
|
||||
protected:
|
||||
void setAddress( long address );
|
||||
void writeFlashLowByte( long value ); // Alwyas low byte first...
|
||||
void writeFlashHighByte( long value ); // ...then high byte.
|
||||
void writeFlashPage();
|
||||
|
||||
public:
|
||||
/* Constructor */
|
||||
AVRInSystemProg( CommChannel * _comm );
|
||||
|
||||
/* Destructor */
|
||||
~AVRInSystemProg();
|
||||
|
||||
/* Methods */
|
||||
virtual bool enterProgrammingMode();
|
||||
virtual bool leaveProgrammingMode();
|
||||
|
||||
virtual bool chipErase();
|
||||
|
||||
virtual bool readOSCCAL( long pos, long * value );
|
||||
virtual bool readSignature( long * sig0, long * sig1, long * sig2 );
|
||||
virtual bool checkSignature( long sig0, long sig1, long sig2 );
|
||||
|
||||
virtual bool writeFlashByte( long address, long value );
|
||||
virtual bool writeEEPROMByte( long address, long value );
|
||||
|
||||
virtual bool writeFlash( HEXFile * data );
|
||||
virtual bool readFlash( HEXFile * data );
|
||||
|
||||
virtual bool writeEEPROM( HEXFile * data );
|
||||
virtual bool readEEPROM( HEXFile * data );
|
||||
|
||||
virtual bool writeLockBits( long bits );
|
||||
virtual bool readLockBits( long * bits );
|
||||
|
||||
virtual bool writeFuseBits( long bits );
|
||||
virtual bool readFuseBits( long * bits );
|
||||
virtual bool writeExtendedFuseBits( long bits );
|
||||
virtual bool readExtendedFuseBits( long * bits );
|
||||
|
||||
virtual bool programmerSoftwareVersion( long * major, long * minor );
|
||||
virtual bool programmerHardwareVersion( long * major, long * minor );
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,169 +1,169 @@
|
||||
[Project]
|
||||
FileName=AVROSP.dev
|
||||
Name=AVROSP
|
||||
UnitCount=12
|
||||
Type=1
|
||||
Ver=1
|
||||
ObjFiles=
|
||||
Includes=
|
||||
Libs=
|
||||
PrivateResource=
|
||||
ResourceIncludes=
|
||||
MakeIncludes=
|
||||
Compiler=
|
||||
CppCompiler=
|
||||
Linker=
|
||||
IsCpp=1
|
||||
Icon=
|
||||
ExeOutput=
|
||||
ObjectOutput=
|
||||
OverrideOutput=0
|
||||
OverrideOutputName=AVROSP.exe
|
||||
HostApplication=
|
||||
Folders=
|
||||
CommandLine= -dATmega16 -if\temp\rnd8KB.hex -pf
|
||||
IncludeVersionInfo=0
|
||||
SupportXPThemes=0
|
||||
CompilerSet=0
|
||||
CompilerSettings=000000000000000100
|
||||
UseCustomMakefile=0
|
||||
CustomMakefile=
|
||||
|
||||
[Unit1]
|
||||
FileName=main.cpp
|
||||
CompileCpp=1
|
||||
Folder=
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[VersionInfo]
|
||||
Major=0
|
||||
Minor=1
|
||||
Release=1
|
||||
Build=1
|
||||
LanguageID=1033
|
||||
CharsetID=1252
|
||||
CompanyName=
|
||||
FileVersion=
|
||||
FileDescription=Developed using the Dev-C++ IDE
|
||||
InternalName=
|
||||
LegalCopyright=
|
||||
LegalTrademarks=
|
||||
OriginalFilename=
|
||||
ProductName=
|
||||
ProductVersion=
|
||||
AutoIncBuildNr=0
|
||||
|
||||
[Unit2]
|
||||
FileName=CommChannel.cpp
|
||||
CompileCpp=1
|
||||
Folder=Serialtest
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit3]
|
||||
FileName=ErrorMsg.cpp
|
||||
CompileCpp=1
|
||||
Folder=Serialtest
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit4]
|
||||
FileName=JobInfo.cpp
|
||||
CompileCpp=1
|
||||
Folder=AVROSP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit5]
|
||||
FileName=AVRDevice.cpp
|
||||
CompileCpp=1
|
||||
Folder=AVROSP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit6]
|
||||
FileName=HEXParser.cpp
|
||||
CompileCpp=1
|
||||
Folder=AVROSP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit7]
|
||||
FileName=XMLParser.cpp
|
||||
CompileCpp=1
|
||||
Folder=AVROSP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit8]
|
||||
FileName=AVRBootloader.cpp
|
||||
CompileCpp=1
|
||||
Folder=AVROSP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit9]
|
||||
FileName=AVRProgrammer.cpp
|
||||
CompileCpp=1
|
||||
Folder=AVROSP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit10]
|
||||
FileName=Utility.cpp
|
||||
CompileCpp=1
|
||||
Folder=
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit11]
|
||||
FileName=SerialPort.cpp
|
||||
CompileCpp=1
|
||||
Folder=AVROSP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit12]
|
||||
FileName=AVRInSystemProg.cpp
|
||||
CompileCpp=1
|
||||
Folder=AVROSP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Project]
|
||||
FileName=AVROSP.dev
|
||||
Name=AVROSP
|
||||
UnitCount=12
|
||||
Type=1
|
||||
Ver=1
|
||||
ObjFiles=
|
||||
Includes=
|
||||
Libs=
|
||||
PrivateResource=
|
||||
ResourceIncludes=
|
||||
MakeIncludes=
|
||||
Compiler=
|
||||
CppCompiler=
|
||||
Linker=
|
||||
IsCpp=1
|
||||
Icon=
|
||||
ExeOutput=
|
||||
ObjectOutput=
|
||||
OverrideOutput=0
|
||||
OverrideOutputName=AVROSP.exe
|
||||
HostApplication=
|
||||
Folders=
|
||||
CommandLine= -dATmega16 -if\temp\rnd8KB.hex -pf
|
||||
IncludeVersionInfo=0
|
||||
SupportXPThemes=0
|
||||
CompilerSet=0
|
||||
CompilerSettings=000000000000000100
|
||||
UseCustomMakefile=0
|
||||
CustomMakefile=
|
||||
|
||||
[Unit1]
|
||||
FileName=main.cpp
|
||||
CompileCpp=1
|
||||
Folder=
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[VersionInfo]
|
||||
Major=0
|
||||
Minor=1
|
||||
Release=1
|
||||
Build=1
|
||||
LanguageID=1033
|
||||
CharsetID=1252
|
||||
CompanyName=
|
||||
FileVersion=
|
||||
FileDescription=Developed using the Dev-C++ IDE
|
||||
InternalName=
|
||||
LegalCopyright=
|
||||
LegalTrademarks=
|
||||
OriginalFilename=
|
||||
ProductName=
|
||||
ProductVersion=
|
||||
AutoIncBuildNr=0
|
||||
|
||||
[Unit2]
|
||||
FileName=CommChannel.cpp
|
||||
CompileCpp=1
|
||||
Folder=Serialtest
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit3]
|
||||
FileName=ErrorMsg.cpp
|
||||
CompileCpp=1
|
||||
Folder=Serialtest
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit4]
|
||||
FileName=JobInfo.cpp
|
||||
CompileCpp=1
|
||||
Folder=AVROSP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit5]
|
||||
FileName=AVRDevice.cpp
|
||||
CompileCpp=1
|
||||
Folder=AVROSP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit6]
|
||||
FileName=HEXParser.cpp
|
||||
CompileCpp=1
|
||||
Folder=AVROSP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit7]
|
||||
FileName=XMLParser.cpp
|
||||
CompileCpp=1
|
||||
Folder=AVROSP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit8]
|
||||
FileName=AVRBootloader.cpp
|
||||
CompileCpp=1
|
||||
Folder=AVROSP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit9]
|
||||
FileName=AVRProgrammer.cpp
|
||||
CompileCpp=1
|
||||
Folder=AVROSP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit10]
|
||||
FileName=Utility.cpp
|
||||
CompileCpp=1
|
||||
Folder=
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit11]
|
||||
FileName=SerialPort.cpp
|
||||
CompileCpp=1
|
||||
Folder=AVROSP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit12]
|
||||
FileName=AVRInSystemProg.cpp
|
||||
CompileCpp=1
|
||||
Folder=AVROSP
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : AVRProgrammer.cpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : An abstract class containing a framework for a generic
|
||||
* programmer for AVR parts. Reading and writing Flash, EEPROM
|
||||
* lock bits and all fuse bits and reading OSCCAL and reading
|
||||
* signature bytes are supported.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "AVRProgrammer.hpp"
|
||||
|
||||
|
||||
/* Constructor */
|
||||
AVRProgrammer::AVRProgrammer( CommChannel * _comm ) :
|
||||
pagesize( -1 )
|
||||
{
|
||||
if( _comm == NULL )
|
||||
throw new ErrorMsg( "NULL pointer provided for communication channel!" );
|
||||
|
||||
comm = _comm;
|
||||
}
|
||||
|
||||
|
||||
/* Destructor */
|
||||
AVRProgrammer::~AVRProgrammer()
|
||||
{
|
||||
/* No code here */
|
||||
}
|
||||
|
||||
|
||||
string AVRProgrammer::readProgrammerID( CommChannel * _comm )
|
||||
{
|
||||
string id( "1234567" ); // Reserve 7 characters.
|
||||
|
||||
if( _comm == NULL )
|
||||
throw new ErrorMsg( "NULL pointer provided for communication channel!" );
|
||||
|
||||
/* Synchonize with programmer */
|
||||
for( int i = 0; i < 10; i++ )
|
||||
_comm->sendByte( 27 ); // Send ESC
|
||||
|
||||
/* Send 'S' command to programmer */
|
||||
_comm->sendByte( 'S' );
|
||||
_comm->flushTX();
|
||||
|
||||
/* Read 7 characters */
|
||||
for( long i = 0; i < id.size(); i++ )
|
||||
{
|
||||
id[i] = _comm->getByte();
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/* end of file */
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : AVRProgrammer.cpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : An abstract class containing a framework for a generic
|
||||
* programmer for AVR parts. Reading and writing Flash, EEPROM
|
||||
* lock bits and all fuse bits and reading OSCCAL and reading
|
||||
* signature bytes are supported.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "AVRProgrammer.hpp"
|
||||
|
||||
|
||||
/* Constructor */
|
||||
AVRProgrammer::AVRProgrammer( CommChannel * _comm ) :
|
||||
pagesize( -1 )
|
||||
{
|
||||
if( _comm == NULL )
|
||||
throw new ErrorMsg( "NULL pointer provided for communication channel!" );
|
||||
|
||||
comm = _comm;
|
||||
}
|
||||
|
||||
|
||||
/* Destructor */
|
||||
AVRProgrammer::~AVRProgrammer()
|
||||
{
|
||||
/* No code here */
|
||||
}
|
||||
|
||||
|
||||
string AVRProgrammer::readProgrammerID( CommChannel * _comm )
|
||||
{
|
||||
string id( "1234567" ); // Reserve 7 characters.
|
||||
|
||||
if( _comm == NULL )
|
||||
throw new ErrorMsg( "NULL pointer provided for communication channel!" );
|
||||
|
||||
/* Synchonize with programmer */
|
||||
for( int i = 0; i < 10; i++ )
|
||||
_comm->sendByte( 27 ); // Send ESC
|
||||
|
||||
/* Send 'S' command to programmer */
|
||||
_comm->sendByte( 'S' );
|
||||
_comm->flushTX();
|
||||
|
||||
/* Read 7 characters */
|
||||
for( long i = 0; i < id.size(); i++ )
|
||||
{
|
||||
id[i] = _comm->getByte();
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/* end of file */
|
||||
|
||||
|
||||
@@ -1,84 +1,84 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : AVRProgrammer.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : An abstract class containing a framework for a generic
|
||||
* programmer for AVR parts. Reading and writing Flash, EEPROM
|
||||
* lock bits and all fuse bits and reading OSCCAL and reading
|
||||
* signature bytes are supported.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef AVRPROGRAMMER_HPP
|
||||
#define AVRPROGRAMMER_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "ErrorMsg.hpp"
|
||||
#include "HEXParser.hpp"
|
||||
#include "CommChannel.hpp"
|
||||
|
||||
class AVRProgrammer
|
||||
{
|
||||
protected:
|
||||
long pagesize; // Flash page size.
|
||||
CommChannel * comm;
|
||||
|
||||
public:
|
||||
/* Constructor */
|
||||
AVRProgrammer( CommChannel * _comm );
|
||||
|
||||
/* Destructor */
|
||||
~AVRProgrammer();
|
||||
|
||||
/* Static member */
|
||||
static string readProgrammerID( CommChannel * _comm ); // Reads 7-character ID.
|
||||
|
||||
/* Methods */
|
||||
void setPagesize( long _pagesize ) { pagesize = _pagesize; }
|
||||
|
||||
virtual bool enterProgrammingMode() = 0;
|
||||
virtual bool leaveProgrammingMode() = 0;
|
||||
|
||||
virtual bool chipErase() = 0;
|
||||
|
||||
virtual bool readOSCCAL( long pos, long * value ) = 0;
|
||||
virtual bool readSignature( long * sig0, long * sig1, long * sig2 ) = 0;
|
||||
virtual bool checkSignature( long sig0, long sig1, long sig2 ) = 0;
|
||||
|
||||
virtual bool writeFlashByte( long address, long value ) = 0;
|
||||
virtual bool writeEEPROMByte( long address, long value ) = 0;
|
||||
|
||||
virtual bool writeFlash( HEXFile * data ) = 0;
|
||||
virtual bool readFlash( HEXFile * data ) = 0;
|
||||
|
||||
virtual bool writeEEPROM( HEXFile * data ) = 0;
|
||||
virtual bool readEEPROM( HEXFile * data ) = 0;
|
||||
|
||||
virtual bool writeLockBits( long bits ) = 0;
|
||||
virtual bool readLockBits( long * bits ) = 0;
|
||||
|
||||
virtual bool writeFuseBits( long bits ) = 0;
|
||||
virtual bool readFuseBits( long * bits ) = 0;
|
||||
virtual bool writeExtendedFuseBits( long bits ) = 0;
|
||||
virtual bool readExtendedFuseBits( long * bits ) = 0;
|
||||
|
||||
virtual bool programmerSoftwareVersion( long * major, long * minor ) = 0;
|
||||
virtual bool programmerHardwareVersion( long * major, long * minor ) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : AVRProgrammer.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : An abstract class containing a framework for a generic
|
||||
* programmer for AVR parts. Reading and writing Flash, EEPROM
|
||||
* lock bits and all fuse bits and reading OSCCAL and reading
|
||||
* signature bytes are supported.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef AVRPROGRAMMER_HPP
|
||||
#define AVRPROGRAMMER_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "ErrorMsg.hpp"
|
||||
#include "HEXParser.hpp"
|
||||
#include "CommChannel.hpp"
|
||||
|
||||
class AVRProgrammer
|
||||
{
|
||||
protected:
|
||||
long pagesize; // Flash page size.
|
||||
CommChannel * comm;
|
||||
|
||||
public:
|
||||
/* Constructor */
|
||||
AVRProgrammer( CommChannel * _comm );
|
||||
|
||||
/* Destructor */
|
||||
~AVRProgrammer();
|
||||
|
||||
/* Static member */
|
||||
static string readProgrammerID( CommChannel * _comm ); // Reads 7-character ID.
|
||||
|
||||
/* Methods */
|
||||
void setPagesize( long _pagesize ) { pagesize = _pagesize; }
|
||||
|
||||
virtual bool enterProgrammingMode() = 0;
|
||||
virtual bool leaveProgrammingMode() = 0;
|
||||
|
||||
virtual bool chipErase() = 0;
|
||||
|
||||
virtual bool readOSCCAL( long pos, long * value ) = 0;
|
||||
virtual bool readSignature( long * sig0, long * sig1, long * sig2 ) = 0;
|
||||
virtual bool checkSignature( long sig0, long sig1, long sig2 ) = 0;
|
||||
|
||||
virtual bool writeFlashByte( long address, long value ) = 0;
|
||||
virtual bool writeEEPROMByte( long address, long value ) = 0;
|
||||
|
||||
virtual bool writeFlash( HEXFile * data ) = 0;
|
||||
virtual bool readFlash( HEXFile * data ) = 0;
|
||||
|
||||
virtual bool writeEEPROM( HEXFile * data ) = 0;
|
||||
virtual bool readEEPROM( HEXFile * data ) = 0;
|
||||
|
||||
virtual bool writeLockBits( long bits ) = 0;
|
||||
virtual bool readLockBits( long * bits ) = 0;
|
||||
|
||||
virtual bool writeFuseBits( long bits ) = 0;
|
||||
virtual bool readFuseBits( long * bits ) = 0;
|
||||
virtual bool writeExtendedFuseBits( long bits ) = 0;
|
||||
virtual bool readExtendedFuseBits( long * bits ) = 0;
|
||||
|
||||
virtual bool programmerSoftwareVersion( long * major, long * minor ) = 0;
|
||||
virtual bool programmerHardwareVersion( long * major, long * minor ) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : CommChannel.cpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : An abstract class for general byte-by-byte communication.
|
||||
* Serialport, USB, TCP/IP or similar implementations can be derived
|
||||
* from this class to create a technology-independent
|
||||
* communication interface.
|
||||
*
|
||||
* This abstract class does not provide any constructor as it is
|
||||
* too specific for this generalized class. Derived classes should
|
||||
* implement their own constructors for specific communication devices.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "CommChannel.hpp"
|
||||
|
||||
|
||||
/* Destructor */
|
||||
CommChannel::~CommChannel()
|
||||
{
|
||||
/* no code here */
|
||||
}
|
||||
|
||||
/* end of file */
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : CommChannel.cpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : An abstract class for general byte-by-byte communication.
|
||||
* Serialport, USB, TCP/IP or similar implementations can be derived
|
||||
* from this class to create a technology-independent
|
||||
* communication interface.
|
||||
*
|
||||
* This abstract class does not provide any constructor as it is
|
||||
* too specific for this generalized class. Derived classes should
|
||||
* implement their own constructors for specific communication devices.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "CommChannel.hpp"
|
||||
|
||||
|
||||
/* Destructor */
|
||||
CommChannel::~CommChannel()
|
||||
{
|
||||
/* no code here */
|
||||
}
|
||||
|
||||
/* end of file */
|
||||
|
||||
|
||||
@@ -1,61 +1,61 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : CommChannel.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : An abstract class for general byte-by-byte communication.
|
||||
* Serialport, USB, TCP/IP or similar implementations can be derived
|
||||
* from this class to create a technology-independent
|
||||
* communication interface.
|
||||
*
|
||||
* This abstract class does not provide any constructor as it is
|
||||
* too specific for this generalized class. Derived classes should
|
||||
* implement their own constructors for specific communication devices.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef COMMCHANNEL_HPP
|
||||
#define COMMCHANNEL_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
class CommChannel
|
||||
{
|
||||
public:
|
||||
// Destructor
|
||||
virtual ~CommChannel() = 0;
|
||||
|
||||
// Open the communication channel.
|
||||
virtual void openChannel() = 0;
|
||||
|
||||
// Close the communication channel.
|
||||
virtual void closeChannel() = 0;
|
||||
|
||||
// Transmit a single byte.
|
||||
virtual void sendByte( long data ) = 0;
|
||||
|
||||
// Receive a single byte.
|
||||
virtual long getByte() = 0;
|
||||
|
||||
// Flush the transmit buffer.
|
||||
virtual void flushTX() = 0;
|
||||
|
||||
// Flush the receive buffer.
|
||||
virtual void flushRX() = 0;
|
||||
|
||||
// Transmit multiple bytes.
|
||||
virtual void sendMultiple( unsigned char * data, long bufsize ) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : CommChannel.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : An abstract class for general byte-by-byte communication.
|
||||
* Serialport, USB, TCP/IP or similar implementations can be derived
|
||||
* from this class to create a technology-independent
|
||||
* communication interface.
|
||||
*
|
||||
* This abstract class does not provide any constructor as it is
|
||||
* too specific for this generalized class. Derived classes should
|
||||
* implement their own constructors for specific communication devices.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef COMMCHANNEL_HPP
|
||||
#define COMMCHANNEL_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
class CommChannel
|
||||
{
|
||||
public:
|
||||
// Destructor
|
||||
virtual ~CommChannel() = 0;
|
||||
|
||||
// Open the communication channel.
|
||||
virtual void openChannel() = 0;
|
||||
|
||||
// Close the communication channel.
|
||||
virtual void closeChannel() = 0;
|
||||
|
||||
// Transmit a single byte.
|
||||
virtual void sendByte( long data ) = 0;
|
||||
|
||||
// Receive a single byte.
|
||||
virtual long getByte() = 0;
|
||||
|
||||
// Flush the transmit buffer.
|
||||
virtual void flushTX() = 0;
|
||||
|
||||
// Flush the receive buffer.
|
||||
virtual void flushRX() = 0;
|
||||
|
||||
// Transmit multiple bytes.
|
||||
virtual void sendMultiple( unsigned char * data, long bufsize ) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : ErrorMsg.cpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class providing a container for general error messages. This
|
||||
* class can be thrown as an exception.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "ErrorMsg.hpp"
|
||||
|
||||
|
||||
ErrorMsg::ErrorMsg( const string & _message ) :
|
||||
message( _message )
|
||||
{
|
||||
// No code here.
|
||||
}
|
||||
|
||||
|
||||
/* Destructor */
|
||||
ErrorMsg::~ErrorMsg()
|
||||
{
|
||||
// No code here.
|
||||
}
|
||||
|
||||
|
||||
/* Get message */
|
||||
const string & ErrorMsg::What()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
/* end of file */
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : ErrorMsg.cpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class providing a container for general error messages. This
|
||||
* class can be thrown as an exception.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "ErrorMsg.hpp"
|
||||
|
||||
|
||||
ErrorMsg::ErrorMsg( const string & _message ) :
|
||||
message( _message )
|
||||
{
|
||||
// No code here.
|
||||
}
|
||||
|
||||
|
||||
/* Destructor */
|
||||
ErrorMsg::~ErrorMsg()
|
||||
{
|
||||
// No code here.
|
||||
}
|
||||
|
||||
|
||||
/* Get message */
|
||||
const string & ErrorMsg::What()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
/* end of file */
|
||||
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : ErrorMsg.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class providing a container for general error messages. This
|
||||
* class can be thrown as an exception.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef ERRORMSG_HPP
|
||||
#define ERRORMSG_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
class ErrorMsg
|
||||
{
|
||||
protected:
|
||||
string message; // Contains the error message.
|
||||
|
||||
public:
|
||||
// Constructors taking the string as parameter.
|
||||
ErrorMsg( const string & _message );
|
||||
|
||||
// Destructor
|
||||
~ErrorMsg();
|
||||
|
||||
// Function returning the error msg.
|
||||
virtual const string & What();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : ErrorMsg.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class providing a container for general error messages. This
|
||||
* class can be thrown as an exception.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef ERRORMSG_HPP
|
||||
#define ERRORMSG_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
class ErrorMsg
|
||||
{
|
||||
protected:
|
||||
string message; // Contains the error message.
|
||||
|
||||
public:
|
||||
// Constructors taking the string as parameter.
|
||||
ErrorMsg( const string & _message );
|
||||
|
||||
// Destructor
|
||||
~ErrorMsg();
|
||||
|
||||
// Function returning the error msg.
|
||||
virtual const string & What();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,364 +1,364 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : HEXParser.cpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A simple Intel HEX file format reader/writer.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "HEXParser.hpp"
|
||||
|
||||
|
||||
/* Internal struct for managing HEX records */
|
||||
struct HEXRecord // Intel HEX file record
|
||||
{
|
||||
unsigned char length; // Record length in number of data bytes.
|
||||
unsigned long offset; // Offset address.
|
||||
unsigned char type; // Record type.
|
||||
unsigned char * data; // Optional data bytes.
|
||||
};
|
||||
|
||||
|
||||
void HEXFile::writeRecord( ofstream & f, HEXRecord * recp )
|
||||
{
|
||||
unsigned char checksum;
|
||||
long recordPos; // Position inside record data field
|
||||
|
||||
/* Calculate checksum */
|
||||
checksum = recp->length;
|
||||
checksum += (unsigned char) ((recp->offset >> 8) & 0xff);
|
||||
checksum += (unsigned char) (recp->offset & 0xff);
|
||||
checksum += recp->type;
|
||||
|
||||
/* Write record header */
|
||||
f.fill('0');
|
||||
f << ":" << hex
|
||||
<< setw(2) << (long) recp->length
|
||||
<< setw(4) << (long) recp->offset
|
||||
<< setw(2) << (long) recp->type;
|
||||
|
||||
/* Write data bytes */
|
||||
for( recordPos = 0; recordPos < recp->length; recordPos++ )
|
||||
{
|
||||
checksum += recp->data[ recordPos ]; // Further checksum calculation
|
||||
f << hex << setw(2) << (long) recp->data[ recordPos ];
|
||||
}
|
||||
|
||||
/* Write checksum */
|
||||
checksum = 0 - checksum; // Final checksum preparation
|
||||
f << setw(2) << (long) checksum << endl;
|
||||
|
||||
/* Check for errors */
|
||||
if( !f.good() )
|
||||
throw new ErrorMsg( "Error writing HEX record to file!" );
|
||||
}
|
||||
|
||||
|
||||
void HEXFile::parseRecord( const string & hexLine, HEXRecord * recp )
|
||||
{
|
||||
unsigned char checksum;
|
||||
long recordPos; // Position inside record data fields.
|
||||
|
||||
if( hexLine.size() < 11 ) // At least 11 characters.
|
||||
throw new ErrorMsg( "Wrong HEX file format, missing fields! "
|
||||
"Line from file was: (" + hexLine + ")." );
|
||||
|
||||
/* Check format for line */
|
||||
if( hexLine[0] != ':' ) // Always start with colon.
|
||||
throw new ErrorMsg( "Wrong HEX file format, does not start with colon! "
|
||||
"Line from file was: (" + hexLine + ")." );
|
||||
|
||||
/* Parse length, offset and type */
|
||||
recp->length = Util.convertHex( hexLine.substr( 1, 2 ) );
|
||||
recp->offset = Util.convertHex( hexLine.substr( 3, 4 ) );
|
||||
recp->type = Util.convertHex( hexLine.substr( 7, 2 ) );
|
||||
|
||||
/* We now know how long the record should be */
|
||||
if( hexLine.size() < (11+recp->length*2) )
|
||||
throw new ErrorMsg( "Wrong HEX file format, missing fields! "
|
||||
"Line from file was: (" + hexLine + ")." );
|
||||
|
||||
/* Process checksum */
|
||||
checksum = recp->length;
|
||||
checksum += (unsigned char) ((recp->offset >> 8) & 0xff);
|
||||
checksum += (unsigned char) (recp->offset & 0xff);
|
||||
checksum += recp->type;
|
||||
|
||||
/* Parse data fields */
|
||||
if( recp->length )
|
||||
{
|
||||
recp->data = new unsigned char[ recp->length ];
|
||||
|
||||
/* Read data from record */
|
||||
for( recordPos = 0; recordPos < recp->length; recordPos++ )
|
||||
{
|
||||
recp->data[ recordPos ] = Util.convertHex( hexLine.substr( 9 + recordPos*2, 2 ) );
|
||||
checksum += recp->data[ recordPos ];
|
||||
}
|
||||
}
|
||||
|
||||
/* Correct checksum? */
|
||||
checksum += Util.convertHex( hexLine.substr( 9 + recp->length*2, 2 ) );
|
||||
if( checksum != 0 )
|
||||
{
|
||||
throw new ErrorMsg( "Wrong checksum for HEX record! "
|
||||
"Line from file was: (" + hexLine + ")." );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Constructor */
|
||||
HEXFile::HEXFile( long buffersize, long value )
|
||||
{
|
||||
if( buffersize <= 0 )
|
||||
throw new ErrorMsg( "Cannot have zero-size HEX buffer!" );
|
||||
|
||||
data = new unsigned char[ buffersize ];
|
||||
|
||||
if( !data )
|
||||
throw new ErrorMsg( "Memory allocation failed for HEX-line-buffer!" );
|
||||
|
||||
size = buffersize;
|
||||
|
||||
clearAll( value );
|
||||
}
|
||||
|
||||
|
||||
/* Destructor */
|
||||
HEXFile::~HEXFile()
|
||||
{
|
||||
if( data ) delete data;
|
||||
}
|
||||
|
||||
|
||||
void HEXFile::readFile( const string & _filename )
|
||||
{
|
||||
ifstream f;
|
||||
string hexLine; // Contains one line of the HEX file.
|
||||
HEXRecord rec; // Temp record.
|
||||
|
||||
long baseAddress; // Base address for extended addressing modes.
|
||||
long dataPos; // Data position in record.
|
||||
|
||||
/* Attempt to open file */
|
||||
f.open( _filename.c_str(), ios::in );
|
||||
if( !f )
|
||||
throw new ErrorMsg( "Error opening HEX file for input!" );
|
||||
|
||||
/* Prepare */
|
||||
baseAddress = 0;
|
||||
start = size;
|
||||
end = 0;
|
||||
|
||||
/* Parse records */
|
||||
f >> hexLine; // Read one line.
|
||||
while( !f.eof() )
|
||||
{
|
||||
Util.progress( "#" ); // Advance progress indicator.
|
||||
|
||||
/* Process record according to type */
|
||||
parseRecord( hexLine, &rec );
|
||||
|
||||
switch( rec.type )
|
||||
{
|
||||
case 0x00 : // Data record ?
|
||||
/* Copy data */
|
||||
if( baseAddress + rec.offset + rec.length > size )
|
||||
throw new ErrorMsg( "HEX file defines data outside buffer limits! "
|
||||
"Make sure file does not contain data outside device "
|
||||
"memory limits. "
|
||||
"Line from file was: (" + hexLine + ")." );
|
||||
|
||||
for( dataPos = 0; dataPos < rec.length; dataPos++ )
|
||||
data[ baseAddress + rec.offset + dataPos ] = rec.data[ dataPos ];
|
||||
|
||||
/* Update byte usage */
|
||||
if( baseAddress + rec.offset < start )
|
||||
start = baseAddress + rec.offset;
|
||||
|
||||
if( baseAddress + rec.offset + rec.length - 1 > end )
|
||||
end = baseAddress + rec.offset + rec.length - 1;
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case 0x02 : // Extended segment address record ?
|
||||
baseAddress = (rec.data[0] << 8) | rec.data[1];
|
||||
baseAddress <<= 4;
|
||||
break;
|
||||
|
||||
case 0x03 : // Start segment address record ?
|
||||
break; // Ignore it, since we have no influence on execution start address.
|
||||
|
||||
case 0x04 : // Extended linear address record ?
|
||||
baseAddress = (rec.data[0] << 8) | rec.data[1];
|
||||
baseAddress <<= 16;
|
||||
break;
|
||||
|
||||
case 0x05 : // Start linear address record ?
|
||||
break; // Ignore it, since we have no influence on exectuion start address.
|
||||
|
||||
case 0x01 : // End of file record ?
|
||||
f.close();
|
||||
Util.progress( "\r\n" ); // Finish progress indicator.
|
||||
return;
|
||||
|
||||
default:
|
||||
throw new ErrorMsg( "Unsupported HEX record format! "
|
||||
"Line from file was: (" + hexLine + ")." );
|
||||
}
|
||||
|
||||
f >> hexLine; // Read next line.
|
||||
}
|
||||
|
||||
|
||||
/* We should not end up here */
|
||||
throw new ErrorMsg( "Premature end of file encountered! Make sure file "
|
||||
"contains an EOF-record." );
|
||||
}
|
||||
|
||||
|
||||
void HEXFile::writeFile( const string & _filename )
|
||||
{
|
||||
ofstream f;
|
||||
HEXRecord rec; // Temp record.
|
||||
|
||||
long baseAddress; // Absolute data position.
|
||||
long offset; // Offset from base address.
|
||||
long dataPos; // Position inside data record.
|
||||
|
||||
enum
|
||||
{
|
||||
_first,
|
||||
_writing,
|
||||
_passed64k
|
||||
} status; // Write status, see usage below.
|
||||
|
||||
/* Attempt to create file */
|
||||
f.open( _filename.c_str(), ios::out );
|
||||
if( !f )
|
||||
throw new ErrorMsg( "Error opening HEX file for output!" );
|
||||
|
||||
/* Prepare */
|
||||
status = _first;
|
||||
rec.data = new unsigned char[ 16 ]; // Use only 16 byte records.
|
||||
|
||||
baseAddress = start & ~0xffff; // 64K aligned address.
|
||||
offset = start & 0xffff; // Offset from the aligned address.
|
||||
dataPos = 0;
|
||||
|
||||
/* Write first base address record to HEX file */
|
||||
rec.length = 2;
|
||||
rec.offset = 0;
|
||||
rec.type = 0x02;
|
||||
rec.data[1] = 0x00;
|
||||
rec.data[0] = baseAddress >> 12; // Give 4k page index.
|
||||
writeRecord( f, &rec ); // Write the HEX record to file.
|
||||
|
||||
|
||||
/* Write all bytes in used range */
|
||||
do
|
||||
{
|
||||
/* Put data into record */
|
||||
rec.data[ dataPos ] = data[ baseAddress + offset + dataPos ];
|
||||
dataPos++;
|
||||
|
||||
/* Check if we need to write out the current data record */
|
||||
if( offset + dataPos >= 0x10000 || // Reached 64k boundary?
|
||||
dataPos >= 16 || // Data record full?
|
||||
baseAddress + offset + dataPos > end ) // End of used range reached?
|
||||
{
|
||||
/* Write current data record */
|
||||
rec.length = dataPos;
|
||||
rec.offset = offset;
|
||||
rec.type = 0x00; // Data record.
|
||||
|
||||
Util.progress( "#" ); // Advance progress indicator.
|
||||
writeRecord( f, &rec );
|
||||
|
||||
offset += dataPos;
|
||||
dataPos = 0;
|
||||
}
|
||||
|
||||
/* Check if we have passed a 64k boundary */
|
||||
if( offset + dataPos >= 0x10000 )
|
||||
{
|
||||
/* Update address pointers */
|
||||
offset -= 0x10000;
|
||||
baseAddress += 0x10000;
|
||||
|
||||
/* Write new base address record to HEX file */
|
||||
rec.length = 2;
|
||||
rec.offset = 0;
|
||||
rec.type = 0x02;
|
||||
rec.data[0] = baseAddress >> 12; // Give 4k page index.
|
||||
rec.data[1] = 0x00;
|
||||
|
||||
writeRecord( f, &rec ); // Write the HEX record to file.
|
||||
}
|
||||
} while( baseAddress + offset + dataPos <= end );
|
||||
|
||||
|
||||
/* Write EOF record */
|
||||
rec.length = 0;
|
||||
rec.offset = 0;
|
||||
rec.type = 0x01;
|
||||
|
||||
writeRecord( f, &rec );
|
||||
|
||||
f.close();
|
||||
Util.progress( "\r\n" ); // Finish progress indicator.
|
||||
}
|
||||
|
||||
|
||||
void HEXFile::setUsedRange( long _start, long _end )
|
||||
{
|
||||
if( _start < 0 || _end >= size || _start > _end )
|
||||
throw new ErrorMsg( "Invalid range! Start must be 0 or larger, end must be "
|
||||
"inside allowed memory range." );
|
||||
|
||||
start = _start;
|
||||
end = _end;
|
||||
}
|
||||
|
||||
|
||||
void HEXFile::clearAll( long value )
|
||||
{
|
||||
for( long i = 0; i < size; i++ )
|
||||
data[i] = (unsigned char) (value & 0xff);
|
||||
}
|
||||
|
||||
|
||||
long HEXFile::getData( long address )
|
||||
{
|
||||
if( address < 0 || address >= size )
|
||||
throw new ErrorMsg( "Address outside legal range!" );
|
||||
|
||||
return data[ address ];
|
||||
}
|
||||
|
||||
|
||||
void HEXFile::setData( long address, long value )
|
||||
{
|
||||
if( address < 0 || address >= size )
|
||||
throw new ErrorMsg( "Address outside legal range!" );
|
||||
|
||||
data[ address ] = (unsigned char) (value & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/* end of file */
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : HEXParser.cpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A simple Intel HEX file format reader/writer.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "HEXParser.hpp"
|
||||
|
||||
|
||||
/* Internal struct for managing HEX records */
|
||||
struct HEXRecord // Intel HEX file record
|
||||
{
|
||||
unsigned char length; // Record length in number of data bytes.
|
||||
unsigned long offset; // Offset address.
|
||||
unsigned char type; // Record type.
|
||||
unsigned char * data; // Optional data bytes.
|
||||
};
|
||||
|
||||
|
||||
void HEXFile::writeRecord( ofstream & f, HEXRecord * recp )
|
||||
{
|
||||
unsigned char checksum;
|
||||
long recordPos; // Position inside record data field
|
||||
|
||||
/* Calculate checksum */
|
||||
checksum = recp->length;
|
||||
checksum += (unsigned char) ((recp->offset >> 8) & 0xff);
|
||||
checksum += (unsigned char) (recp->offset & 0xff);
|
||||
checksum += recp->type;
|
||||
|
||||
/* Write record header */
|
||||
f.fill('0');
|
||||
f << ":" << hex
|
||||
<< setw(2) << (long) recp->length
|
||||
<< setw(4) << (long) recp->offset
|
||||
<< setw(2) << (long) recp->type;
|
||||
|
||||
/* Write data bytes */
|
||||
for( recordPos = 0; recordPos < recp->length; recordPos++ )
|
||||
{
|
||||
checksum += recp->data[ recordPos ]; // Further checksum calculation
|
||||
f << hex << setw(2) << (long) recp->data[ recordPos ];
|
||||
}
|
||||
|
||||
/* Write checksum */
|
||||
checksum = 0 - checksum; // Final checksum preparation
|
||||
f << setw(2) << (long) checksum << endl;
|
||||
|
||||
/* Check for errors */
|
||||
if( !f.good() )
|
||||
throw new ErrorMsg( "Error writing HEX record to file!" );
|
||||
}
|
||||
|
||||
|
||||
void HEXFile::parseRecord( const string & hexLine, HEXRecord * recp )
|
||||
{
|
||||
unsigned char checksum;
|
||||
long recordPos; // Position inside record data fields.
|
||||
|
||||
if( hexLine.size() < 11 ) // At least 11 characters.
|
||||
throw new ErrorMsg( "Wrong HEX file format, missing fields! "
|
||||
"Line from file was: (" + hexLine + ")." );
|
||||
|
||||
/* Check format for line */
|
||||
if( hexLine[0] != ':' ) // Always start with colon.
|
||||
throw new ErrorMsg( "Wrong HEX file format, does not start with colon! "
|
||||
"Line from file was: (" + hexLine + ")." );
|
||||
|
||||
/* Parse length, offset and type */
|
||||
recp->length = Util.convertHex( hexLine.substr( 1, 2 ) );
|
||||
recp->offset = Util.convertHex( hexLine.substr( 3, 4 ) );
|
||||
recp->type = Util.convertHex( hexLine.substr( 7, 2 ) );
|
||||
|
||||
/* We now know how long the record should be */
|
||||
if( hexLine.size() < (11+recp->length*2) )
|
||||
throw new ErrorMsg( "Wrong HEX file format, missing fields! "
|
||||
"Line from file was: (" + hexLine + ")." );
|
||||
|
||||
/* Process checksum */
|
||||
checksum = recp->length;
|
||||
checksum += (unsigned char) ((recp->offset >> 8) & 0xff);
|
||||
checksum += (unsigned char) (recp->offset & 0xff);
|
||||
checksum += recp->type;
|
||||
|
||||
/* Parse data fields */
|
||||
if( recp->length )
|
||||
{
|
||||
recp->data = new unsigned char[ recp->length ];
|
||||
|
||||
/* Read data from record */
|
||||
for( recordPos = 0; recordPos < recp->length; recordPos++ )
|
||||
{
|
||||
recp->data[ recordPos ] = Util.convertHex( hexLine.substr( 9 + recordPos*2, 2 ) );
|
||||
checksum += recp->data[ recordPos ];
|
||||
}
|
||||
}
|
||||
|
||||
/* Correct checksum? */
|
||||
checksum += Util.convertHex( hexLine.substr( 9 + recp->length*2, 2 ) );
|
||||
if( checksum != 0 )
|
||||
{
|
||||
throw new ErrorMsg( "Wrong checksum for HEX record! "
|
||||
"Line from file was: (" + hexLine + ")." );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Constructor */
|
||||
HEXFile::HEXFile( long buffersize, long value )
|
||||
{
|
||||
if( buffersize <= 0 )
|
||||
throw new ErrorMsg( "Cannot have zero-size HEX buffer!" );
|
||||
|
||||
data = new unsigned char[ buffersize ];
|
||||
|
||||
if( !data )
|
||||
throw new ErrorMsg( "Memory allocation failed for HEX-line-buffer!" );
|
||||
|
||||
size = buffersize;
|
||||
|
||||
clearAll( value );
|
||||
}
|
||||
|
||||
|
||||
/* Destructor */
|
||||
HEXFile::~HEXFile()
|
||||
{
|
||||
if( data ) delete data;
|
||||
}
|
||||
|
||||
|
||||
void HEXFile::readFile( const string & _filename )
|
||||
{
|
||||
ifstream f;
|
||||
string hexLine; // Contains one line of the HEX file.
|
||||
HEXRecord rec; // Temp record.
|
||||
|
||||
long baseAddress; // Base address for extended addressing modes.
|
||||
long dataPos; // Data position in record.
|
||||
|
||||
/* Attempt to open file */
|
||||
f.open( _filename.c_str(), ios::in );
|
||||
if( !f )
|
||||
throw new ErrorMsg( "Error opening HEX file for input!" );
|
||||
|
||||
/* Prepare */
|
||||
baseAddress = 0;
|
||||
start = size;
|
||||
end = 0;
|
||||
|
||||
/* Parse records */
|
||||
f >> hexLine; // Read one line.
|
||||
while( !f.eof() )
|
||||
{
|
||||
Util.progress( "#" ); // Advance progress indicator.
|
||||
|
||||
/* Process record according to type */
|
||||
parseRecord( hexLine, &rec );
|
||||
|
||||
switch( rec.type )
|
||||
{
|
||||
case 0x00 : // Data record ?
|
||||
/* Copy data */
|
||||
if( baseAddress + rec.offset + rec.length > size )
|
||||
throw new ErrorMsg( "HEX file defines data outside buffer limits! "
|
||||
"Make sure file does not contain data outside device "
|
||||
"memory limits. "
|
||||
"Line from file was: (" + hexLine + ")." );
|
||||
|
||||
for( dataPos = 0; dataPos < rec.length; dataPos++ )
|
||||
data[ baseAddress + rec.offset + dataPos ] = rec.data[ dataPos ];
|
||||
|
||||
/* Update byte usage */
|
||||
if( baseAddress + rec.offset < start )
|
||||
start = baseAddress + rec.offset;
|
||||
|
||||
if( baseAddress + rec.offset + rec.length - 1 > end )
|
||||
end = baseAddress + rec.offset + rec.length - 1;
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case 0x02 : // Extended segment address record ?
|
||||
baseAddress = (rec.data[0] << 8) | rec.data[1];
|
||||
baseAddress <<= 4;
|
||||
break;
|
||||
|
||||
case 0x03 : // Start segment address record ?
|
||||
break; // Ignore it, since we have no influence on execution start address.
|
||||
|
||||
case 0x04 : // Extended linear address record ?
|
||||
baseAddress = (rec.data[0] << 8) | rec.data[1];
|
||||
baseAddress <<= 16;
|
||||
break;
|
||||
|
||||
case 0x05 : // Start linear address record ?
|
||||
break; // Ignore it, since we have no influence on exectuion start address.
|
||||
|
||||
case 0x01 : // End of file record ?
|
||||
f.close();
|
||||
Util.progress( "\r\n" ); // Finish progress indicator.
|
||||
return;
|
||||
|
||||
default:
|
||||
throw new ErrorMsg( "Unsupported HEX record format! "
|
||||
"Line from file was: (" + hexLine + ")." );
|
||||
}
|
||||
|
||||
f >> hexLine; // Read next line.
|
||||
}
|
||||
|
||||
|
||||
/* We should not end up here */
|
||||
throw new ErrorMsg( "Premature end of file encountered! Make sure file "
|
||||
"contains an EOF-record." );
|
||||
}
|
||||
|
||||
|
||||
void HEXFile::writeFile( const string & _filename )
|
||||
{
|
||||
ofstream f;
|
||||
HEXRecord rec; // Temp record.
|
||||
|
||||
long baseAddress; // Absolute data position.
|
||||
long offset; // Offset from base address.
|
||||
long dataPos; // Position inside data record.
|
||||
|
||||
enum
|
||||
{
|
||||
_first,
|
||||
_writing,
|
||||
_passed64k
|
||||
} status; // Write status, see usage below.
|
||||
|
||||
/* Attempt to create file */
|
||||
f.open( _filename.c_str(), ios::out );
|
||||
if( !f )
|
||||
throw new ErrorMsg( "Error opening HEX file for output!" );
|
||||
|
||||
/* Prepare */
|
||||
status = _first;
|
||||
rec.data = new unsigned char[ 16 ]; // Use only 16 byte records.
|
||||
|
||||
baseAddress = start & ~0xffff; // 64K aligned address.
|
||||
offset = start & 0xffff; // Offset from the aligned address.
|
||||
dataPos = 0;
|
||||
|
||||
/* Write first base address record to HEX file */
|
||||
rec.length = 2;
|
||||
rec.offset = 0;
|
||||
rec.type = 0x02;
|
||||
rec.data[1] = 0x00;
|
||||
rec.data[0] = baseAddress >> 12; // Give 4k page index.
|
||||
writeRecord( f, &rec ); // Write the HEX record to file.
|
||||
|
||||
|
||||
/* Write all bytes in used range */
|
||||
do
|
||||
{
|
||||
/* Put data into record */
|
||||
rec.data[ dataPos ] = data[ baseAddress + offset + dataPos ];
|
||||
dataPos++;
|
||||
|
||||
/* Check if we need to write out the current data record */
|
||||
if( offset + dataPos >= 0x10000 || // Reached 64k boundary?
|
||||
dataPos >= 16 || // Data record full?
|
||||
baseAddress + offset + dataPos > end ) // End of used range reached?
|
||||
{
|
||||
/* Write current data record */
|
||||
rec.length = dataPos;
|
||||
rec.offset = offset;
|
||||
rec.type = 0x00; // Data record.
|
||||
|
||||
Util.progress( "#" ); // Advance progress indicator.
|
||||
writeRecord( f, &rec );
|
||||
|
||||
offset += dataPos;
|
||||
dataPos = 0;
|
||||
}
|
||||
|
||||
/* Check if we have passed a 64k boundary */
|
||||
if( offset + dataPos >= 0x10000 )
|
||||
{
|
||||
/* Update address pointers */
|
||||
offset -= 0x10000;
|
||||
baseAddress += 0x10000;
|
||||
|
||||
/* Write new base address record to HEX file */
|
||||
rec.length = 2;
|
||||
rec.offset = 0;
|
||||
rec.type = 0x02;
|
||||
rec.data[0] = baseAddress >> 12; // Give 4k page index.
|
||||
rec.data[1] = 0x00;
|
||||
|
||||
writeRecord( f, &rec ); // Write the HEX record to file.
|
||||
}
|
||||
} while( baseAddress + offset + dataPos <= end );
|
||||
|
||||
|
||||
/* Write EOF record */
|
||||
rec.length = 0;
|
||||
rec.offset = 0;
|
||||
rec.type = 0x01;
|
||||
|
||||
writeRecord( f, &rec );
|
||||
|
||||
f.close();
|
||||
Util.progress( "\r\n" ); // Finish progress indicator.
|
||||
}
|
||||
|
||||
|
||||
void HEXFile::setUsedRange( long _start, long _end )
|
||||
{
|
||||
if( _start < 0 || _end >= size || _start > _end )
|
||||
throw new ErrorMsg( "Invalid range! Start must be 0 or larger, end must be "
|
||||
"inside allowed memory range." );
|
||||
|
||||
start = _start;
|
||||
end = _end;
|
||||
}
|
||||
|
||||
|
||||
void HEXFile::clearAll( long value )
|
||||
{
|
||||
for( long i = 0; i < size; i++ )
|
||||
data[i] = (unsigned char) (value & 0xff);
|
||||
}
|
||||
|
||||
|
||||
long HEXFile::getData( long address )
|
||||
{
|
||||
if( address < 0 || address >= size )
|
||||
throw new ErrorMsg( "Address outside legal range!" );
|
||||
|
||||
return data[ address ];
|
||||
}
|
||||
|
||||
|
||||
void HEXFile::setData( long address, long value )
|
||||
{
|
||||
if( address < 0 || address >= size )
|
||||
throw new ErrorMsg( "Address outside legal range!" );
|
||||
|
||||
data[ address ] = (unsigned char) (value & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/* end of file */
|
||||
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : HEXParser.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A simple Intel HEX file format reader/writer.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef HEXPARSER_HPP
|
||||
#define HEXPARSER_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "ErrorMsg.hpp"
|
||||
#include "Utility.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
|
||||
struct HEXRecord; // Preliminary definition.
|
||||
|
||||
class HEXFile
|
||||
{
|
||||
protected:
|
||||
unsigned char * data; // Holds the data bytes.
|
||||
long start, end; // Used data range.
|
||||
long size; // Size of databuffer.
|
||||
|
||||
void writeRecord( ofstream & f, HEXRecord * recp );
|
||||
void parseRecord( const string & hexLine, HEXRecord * recp );
|
||||
|
||||
public:
|
||||
/* Constructor */
|
||||
HEXFile( long buffersize, long value = 0xff );
|
||||
|
||||
/* Destructor */
|
||||
~HEXFile();
|
||||
|
||||
/* Methods */
|
||||
void readFile( const string & _filename ); // Read data from HEX file.
|
||||
void writeFile( const string & _filename ); // Write data to HEX file.
|
||||
|
||||
void setUsedRange( long _start, long _end ); // Sets the used range.
|
||||
void clearAll( long value = 0xff ); // Set databuffer to this value.
|
||||
|
||||
long getRangeStart() { return start; }
|
||||
long getRangeEnd() { return end; }
|
||||
long getData( long address );
|
||||
void setData( long address, long value );
|
||||
long getSize() { return size; }
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : HEXParser.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A simple Intel HEX file format reader/writer.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef HEXPARSER_HPP
|
||||
#define HEXPARSER_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "ErrorMsg.hpp"
|
||||
#include "Utility.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
|
||||
struct HEXRecord; // Preliminary definition.
|
||||
|
||||
class HEXFile
|
||||
{
|
||||
protected:
|
||||
unsigned char * data; // Holds the data bytes.
|
||||
long start, end; // Used data range.
|
||||
long size; // Size of databuffer.
|
||||
|
||||
void writeRecord( ofstream & f, HEXRecord * recp );
|
||||
void parseRecord( const string & hexLine, HEXRecord * recp );
|
||||
|
||||
public:
|
||||
/* Constructor */
|
||||
HEXFile( long buffersize, long value = 0xff );
|
||||
|
||||
/* Destructor */
|
||||
~HEXFile();
|
||||
|
||||
/* Methods */
|
||||
void readFile( const string & _filename ); // Read data from HEX file.
|
||||
void writeFile( const string & _filename ); // Write data to HEX file.
|
||||
|
||||
void setUsedRange( long _start, long _end ); // Sets the used range.
|
||||
void clearAll( long value = 0xff ); // Set databuffer to this value.
|
||||
|
||||
long getRangeStart() { return start; }
|
||||
long getRangeEnd() { return end; }
|
||||
long getData( long address );
|
||||
void setData( long address, long value );
|
||||
long getSize() { return size; }
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+1296
-1296
File diff suppressed because it is too large
Load Diff
@@ -1,105 +1,105 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : JobInfo.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class holding information on what the AVR Open-Source Programmer
|
||||
* should do. The information is derived from the command-line.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef JOBINFO_HPP
|
||||
#define JOBINFO_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
#include "ErrorMsg.hpp"
|
||||
#include "AVRProgrammer.hpp"
|
||||
#include "AVRBootloader.hpp"
|
||||
#include "AVRInSystemProg.hpp"
|
||||
#include "AVRDevice.hpp"
|
||||
#include "SerialPort.hpp"
|
||||
#include "Utility.hpp"
|
||||
|
||||
|
||||
class JobInfo
|
||||
{
|
||||
protected:
|
||||
long convertHex( char * txt );
|
||||
void help();
|
||||
void doDeviceIndependent( AVRProgrammer * prog );
|
||||
void doDeviceDependent( AVRProgrammer * prog, AVRDevice * avr );
|
||||
|
||||
|
||||
bool showHelp; // Show help screen?
|
||||
bool silentMode; // No text output?
|
||||
bool noProgressIndicator; // Do not show progress indicators?
|
||||
bool readSignature; // Output signature bytes to screen?
|
||||
bool chipErase; // Erase chip before any programming operations?
|
||||
bool getHWrevision; // Get hardware revision of programmer?
|
||||
bool getSWrevision; // Get software revision of programmer?
|
||||
bool programFlash; // Flash programming desired?
|
||||
bool programEEPROM; // E2 programming desired?
|
||||
bool readFlash; // Flash readout desired?
|
||||
bool readEEPROM; // E2 readout desired?
|
||||
bool verifyFlash; // Flash verification desired?
|
||||
bool verifyEEPROM; // E2 verification desired?
|
||||
bool readLockBits; // Lock bit readout desired?
|
||||
bool readFuseBits; // Fuse bit readout desired?
|
||||
bool readOSCCAL; // Read or use specified OSCCAL value, if -O is used?
|
||||
|
||||
string deviceName; // Specified device name.
|
||||
string inputFileFlash; // Input file for Flash writing and verification.
|
||||
string inputFileEEPROM; // Input file for E2 writing and verification.
|
||||
string outputFileFlash; // Output file for Flash readout.
|
||||
string outputFileEEPROM; // Output file for E2 readout.
|
||||
|
||||
long OSCCAL_Parameter; // Value of the -O parameter, -1 if unspecified.
|
||||
|
||||
long OSCCAL_FlashAddress; // Where to put OSCCAL value in flash, -1 if not.
|
||||
long OSCCAL_EEPROMAddress; // Where to put OSCCAL value in E2, -1 if not.
|
||||
|
||||
long programLockBits; // Change lock bits to this value, -1 if not.
|
||||
long verifyLockBits; // Verify lock bits against this value, -1 if not.
|
||||
|
||||
long programFuseBits; // Change fuse bits to this value, -1 if not.
|
||||
long programExtendedFuseBits; // Same as above for extended fuse bits.
|
||||
long verifyFuseBits; // Verify fuse bits against this value, -1 if not.
|
||||
long verifyExtendedFuseBits; // Same as above for extended fuse bits.
|
||||
|
||||
long memoryFillPattern; // Fill unspecified locations, -1 if not.
|
||||
|
||||
long flashStartAddress; // Limit Flash operations, -1 if not.
|
||||
long flashEndAddress; // ...to this address, inclusive, -1 if not.
|
||||
|
||||
long eepromStartAddress; // Same as above for E2.
|
||||
long eepromEndAddress; // ...
|
||||
|
||||
long comPort; // Desired COM port to use, -1 if unspecified.
|
||||
|
||||
vector<string> searchpath; // Search path for XML-files.
|
||||
|
||||
public:
|
||||
JobInfo(); // Constructor
|
||||
|
||||
void parseCommandline( int argc, char *argv[] );
|
||||
void doJob();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : JobInfo.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class holding information on what the AVR Open-Source Programmer
|
||||
* should do. The information is derived from the command-line.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef JOBINFO_HPP
|
||||
#define JOBINFO_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iomanip>
|
||||
#include "ErrorMsg.hpp"
|
||||
#include "AVRProgrammer.hpp"
|
||||
#include "AVRBootloader.hpp"
|
||||
#include "AVRInSystemProg.hpp"
|
||||
#include "AVRDevice.hpp"
|
||||
#include "SerialPort.hpp"
|
||||
#include "Utility.hpp"
|
||||
|
||||
|
||||
class JobInfo
|
||||
{
|
||||
protected:
|
||||
long convertHex( char * txt );
|
||||
void help();
|
||||
void doDeviceIndependent( AVRProgrammer * prog );
|
||||
void doDeviceDependent( AVRProgrammer * prog, AVRDevice * avr );
|
||||
|
||||
|
||||
bool showHelp; // Show help screen?
|
||||
bool silentMode; // No text output?
|
||||
bool noProgressIndicator; // Do not show progress indicators?
|
||||
bool readSignature; // Output signature bytes to screen?
|
||||
bool chipErase; // Erase chip before any programming operations?
|
||||
bool getHWrevision; // Get hardware revision of programmer?
|
||||
bool getSWrevision; // Get software revision of programmer?
|
||||
bool programFlash; // Flash programming desired?
|
||||
bool programEEPROM; // E2 programming desired?
|
||||
bool readFlash; // Flash readout desired?
|
||||
bool readEEPROM; // E2 readout desired?
|
||||
bool verifyFlash; // Flash verification desired?
|
||||
bool verifyEEPROM; // E2 verification desired?
|
||||
bool readLockBits; // Lock bit readout desired?
|
||||
bool readFuseBits; // Fuse bit readout desired?
|
||||
bool readOSCCAL; // Read or use specified OSCCAL value, if -O is used?
|
||||
|
||||
string deviceName; // Specified device name.
|
||||
string inputFileFlash; // Input file for Flash writing and verification.
|
||||
string inputFileEEPROM; // Input file for E2 writing and verification.
|
||||
string outputFileFlash; // Output file for Flash readout.
|
||||
string outputFileEEPROM; // Output file for E2 readout.
|
||||
|
||||
long OSCCAL_Parameter; // Value of the -O parameter, -1 if unspecified.
|
||||
|
||||
long OSCCAL_FlashAddress; // Where to put OSCCAL value in flash, -1 if not.
|
||||
long OSCCAL_EEPROMAddress; // Where to put OSCCAL value in E2, -1 if not.
|
||||
|
||||
long programLockBits; // Change lock bits to this value, -1 if not.
|
||||
long verifyLockBits; // Verify lock bits against this value, -1 if not.
|
||||
|
||||
long programFuseBits; // Change fuse bits to this value, -1 if not.
|
||||
long programExtendedFuseBits; // Same as above for extended fuse bits.
|
||||
long verifyFuseBits; // Verify fuse bits against this value, -1 if not.
|
||||
long verifyExtendedFuseBits; // Same as above for extended fuse bits.
|
||||
|
||||
long memoryFillPattern; // Fill unspecified locations, -1 if not.
|
||||
|
||||
long flashStartAddress; // Limit Flash operations, -1 if not.
|
||||
long flashEndAddress; // ...to this address, inclusive, -1 if not.
|
||||
|
||||
long eepromStartAddress; // Same as above for E2.
|
||||
long eepromEndAddress; // ...
|
||||
|
||||
long comPort; // Desired COM port to use, -1 if unspecified.
|
||||
|
||||
vector<string> searchpath; // Search path for XML-files.
|
||||
|
||||
public:
|
||||
JobInfo(); // Constructor
|
||||
|
||||
void parseCommandline( int argc, char *argv[] );
|
||||
void doJob();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,203 +1,203 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : SerialPort.cpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class providing serial communication through the PC COM port.
|
||||
* This class is derived from the CommChannel abstract class.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "SerialPort.hpp"
|
||||
|
||||
|
||||
/* Constructor */
|
||||
SerialPort::SerialPort( long _portNumber, long _timeout )
|
||||
{
|
||||
if( _timeout < 0 )
|
||||
throw new ErrorMsg( "Negative COM-port timeout not allowed!" );
|
||||
|
||||
if( _portNumber < 1 || _portNumber > 99 )
|
||||
throw new ErrorMsg( "Only COM1 to COM99 is supported!" );
|
||||
|
||||
/* Initialize internal parameters */
|
||||
portNumber = _portNumber;
|
||||
timeout = _timeout;
|
||||
channelOpen = false;
|
||||
}
|
||||
|
||||
|
||||
/* Destructor */
|
||||
SerialPort::~SerialPort()
|
||||
{
|
||||
closeChannel();
|
||||
}
|
||||
|
||||
|
||||
/* Open the communication channel */
|
||||
void SerialPort::openChannel()
|
||||
{
|
||||
/* CreateFile expects a constant char, or char from the heap */
|
||||
static char comName[64] = "COM1";
|
||||
|
||||
COMMTIMEOUTS comTimeouts;
|
||||
|
||||
/* Check if channel already open */
|
||||
if( channelOpen )
|
||||
throw new ErrorMsg( "Channel already open! Cannot open port twice." );
|
||||
|
||||
/* Generate COM filename and attempt open */
|
||||
if (portNumber < 10) {
|
||||
comName[3] = '0' + portNumber;
|
||||
} else if (portNumber < 100) {
|
||||
/* For COM ports greater than 9 you have to use a special syntax
|
||||
for CreateFile. The syntax also works for COM ports 1-9. */
|
||||
/* http://support.microsoft.com/kb/115831 */
|
||||
sprintf(comName, "\\\\.\\COM%ld", portNumber);
|
||||
}
|
||||
serialHandle = CreateFile( comName, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
|
||||
|
||||
/* Print error and return if failed opening port */
|
||||
if( serialHandle == INVALID_HANDLE_VALUE )
|
||||
throw new ErrorMsg( "Error opening COM port!" );
|
||||
|
||||
channelOpen = true;
|
||||
|
||||
/* Store old COM port settings */
|
||||
if( !GetCommTimeouts( serialHandle, &oldComTimeouts ) )
|
||||
throw new ErrorMsg( "Error reading COM port settings!" );
|
||||
|
||||
/* Get another copy of the COM settings, and change them */
|
||||
if( !GetCommTimeouts( serialHandle, &comTimeouts ) )
|
||||
throw new ErrorMsg( "Error reading COM port settings!" );
|
||||
|
||||
comTimeouts.ReadIntervalTimeout = MAXDWORD;
|
||||
comTimeouts.ReadTotalTimeoutConstant = 0;
|
||||
comTimeouts.ReadTotalTimeoutMultiplier = 0;
|
||||
|
||||
/* Apply new settings */
|
||||
if( !SetCommTimeouts( serialHandle, &comTimeouts ) )
|
||||
throw new ErrorMsg( "Error changing COM port settings!" );
|
||||
}
|
||||
|
||||
|
||||
/* Close the communication channel */
|
||||
void SerialPort::closeChannel()
|
||||
{
|
||||
if( !channelOpen )
|
||||
return;
|
||||
|
||||
/* Restore old COM parameters */
|
||||
if( !SetCommTimeouts( serialHandle, &oldComTimeouts ) )
|
||||
throw new ErrorMsg( "Error changing COM port settings!" );
|
||||
|
||||
/* Release port */
|
||||
if( serialHandle != INVALID_HANDLE_VALUE )
|
||||
if( !CloseHandle( serialHandle ) )
|
||||
throw new ErrorMsg( "Error closing COM port!" );
|
||||
|
||||
channelOpen = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Transmit a single byte */
|
||||
void SerialPort::sendByte( long data )
|
||||
{
|
||||
DWORD written;
|
||||
|
||||
/* Check if channel is open */
|
||||
if( !channelOpen )
|
||||
throw new ErrorMsg( "Channel not open! Cannot send to unopened channel." );
|
||||
|
||||
/* Attempt writing */
|
||||
if( !WriteFile( serialHandle, &data, 1, &written, NULL ) )
|
||||
throw new ErrorMsg( "Error writing byte to COM port!" );
|
||||
}
|
||||
|
||||
|
||||
/* Receive a single byte */
|
||||
long SerialPort::getByte()
|
||||
{
|
||||
time_t startTime;
|
||||
startTime = time( NULL ); // Read current time in seconds
|
||||
DWORD readnum;
|
||||
unsigned char data;
|
||||
|
||||
/* Check if channel is open */
|
||||
if( !channelOpen )
|
||||
throw new ErrorMsg( "Channel not open! Cannot read from unopened channel." );
|
||||
|
||||
/* Attempt receiving byte until timeout limit exceeded */
|
||||
do
|
||||
{
|
||||
/* Read byte from port */
|
||||
if( !ReadFile( serialHandle, &data, 1, &readnum, NULL ) )
|
||||
{
|
||||
throw new ErrorMsg( "Error reading byte from COM port!" );
|
||||
}
|
||||
|
||||
if( readnum == 1 )
|
||||
return ((long) data) & 0xff;
|
||||
|
||||
} while( time(NULL) - startTime < timeout );
|
||||
|
||||
/* Timeout */
|
||||
throw new ErrorMsg( "Timeout during COM-port read operation!" );
|
||||
}
|
||||
|
||||
|
||||
/* Flush the transmit buffer */
|
||||
void SerialPort::flushTX()
|
||||
{
|
||||
/* Check if channel is open */
|
||||
if( !channelOpen )
|
||||
throw new ErrorMsg( "Channel not open! Cannot flush an unopened channel." );
|
||||
|
||||
/* Purge data from write buffer */
|
||||
if( !PurgeComm( serialHandle, PURGE_TXCLEAR ) )
|
||||
throw new ErrorMsg( "Error flushing COM port TX buffer!" );
|
||||
}
|
||||
|
||||
|
||||
/* Flush the receive buffer */
|
||||
void SerialPort::flushRX()
|
||||
{
|
||||
/* Check if channel is open */
|
||||
if( !channelOpen )
|
||||
throw new ErrorMsg( "Channel not open! Cannot flush an unopened channel." );
|
||||
|
||||
/* Purge data from write buffer */
|
||||
if( !PurgeComm( serialHandle, PURGE_RXCLEAR ) )
|
||||
throw new ErrorMsg( "Error flushing COM port RX buffer!" );
|
||||
}
|
||||
|
||||
|
||||
/* Transmit multiple bytes */
|
||||
void SerialPort::sendMultiple( unsigned char * data, long bufsize )
|
||||
{
|
||||
DWORD written;
|
||||
|
||||
/* Check if channel is open */
|
||||
if( !channelOpen )
|
||||
throw new ErrorMsg( "Channel not open! Cannot write to unopened channel." );
|
||||
|
||||
/* Attempt writing */
|
||||
if( !WriteFile( serialHandle, data, bufsize, &written, NULL ) )
|
||||
throw new ErrorMsg( "Error writing multiple bytes to COM port!" );
|
||||
}
|
||||
|
||||
/* end of file */
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : SerialPort.cpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class providing serial communication through the PC COM port.
|
||||
* This class is derived from the CommChannel abstract class.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "SerialPort.hpp"
|
||||
|
||||
|
||||
/* Constructor */
|
||||
SerialPort::SerialPort( long _portNumber, long _timeout )
|
||||
{
|
||||
if( _timeout < 0 )
|
||||
throw new ErrorMsg( "Negative COM-port timeout not allowed!" );
|
||||
|
||||
if( _portNumber < 1 || _portNumber > 99 )
|
||||
throw new ErrorMsg( "Only COM1 to COM99 is supported!" );
|
||||
|
||||
/* Initialize internal parameters */
|
||||
portNumber = _portNumber;
|
||||
timeout = _timeout;
|
||||
channelOpen = false;
|
||||
}
|
||||
|
||||
|
||||
/* Destructor */
|
||||
SerialPort::~SerialPort()
|
||||
{
|
||||
closeChannel();
|
||||
}
|
||||
|
||||
|
||||
/* Open the communication channel */
|
||||
void SerialPort::openChannel()
|
||||
{
|
||||
/* CreateFile expects a constant char, or char from the heap */
|
||||
static char comName[64] = "COM1";
|
||||
|
||||
COMMTIMEOUTS comTimeouts;
|
||||
|
||||
/* Check if channel already open */
|
||||
if( channelOpen )
|
||||
throw new ErrorMsg( "Channel already open! Cannot open port twice." );
|
||||
|
||||
/* Generate COM filename and attempt open */
|
||||
if (portNumber < 10) {
|
||||
comName[3] = '0' + portNumber;
|
||||
} else if (portNumber < 100) {
|
||||
/* For COM ports greater than 9 you have to use a special syntax
|
||||
for CreateFile. The syntax also works for COM ports 1-9. */
|
||||
/* http://support.microsoft.com/kb/115831 */
|
||||
sprintf(comName, "\\\\.\\COM%ld", portNumber);
|
||||
}
|
||||
serialHandle = CreateFile( comName, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
|
||||
|
||||
/* Print error and return if failed opening port */
|
||||
if( serialHandle == INVALID_HANDLE_VALUE )
|
||||
throw new ErrorMsg( "Error opening COM port!" );
|
||||
|
||||
channelOpen = true;
|
||||
|
||||
/* Store old COM port settings */
|
||||
if( !GetCommTimeouts( serialHandle, &oldComTimeouts ) )
|
||||
throw new ErrorMsg( "Error reading COM port settings!" );
|
||||
|
||||
/* Get another copy of the COM settings, and change them */
|
||||
if( !GetCommTimeouts( serialHandle, &comTimeouts ) )
|
||||
throw new ErrorMsg( "Error reading COM port settings!" );
|
||||
|
||||
comTimeouts.ReadIntervalTimeout = MAXDWORD;
|
||||
comTimeouts.ReadTotalTimeoutConstant = 0;
|
||||
comTimeouts.ReadTotalTimeoutMultiplier = 0;
|
||||
|
||||
/* Apply new settings */
|
||||
if( !SetCommTimeouts( serialHandle, &comTimeouts ) )
|
||||
throw new ErrorMsg( "Error changing COM port settings!" );
|
||||
}
|
||||
|
||||
|
||||
/* Close the communication channel */
|
||||
void SerialPort::closeChannel()
|
||||
{
|
||||
if( !channelOpen )
|
||||
return;
|
||||
|
||||
/* Restore old COM parameters */
|
||||
if( !SetCommTimeouts( serialHandle, &oldComTimeouts ) )
|
||||
throw new ErrorMsg( "Error changing COM port settings!" );
|
||||
|
||||
/* Release port */
|
||||
if( serialHandle != INVALID_HANDLE_VALUE )
|
||||
if( !CloseHandle( serialHandle ) )
|
||||
throw new ErrorMsg( "Error closing COM port!" );
|
||||
|
||||
channelOpen = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Transmit a single byte */
|
||||
void SerialPort::sendByte( long data )
|
||||
{
|
||||
DWORD written;
|
||||
|
||||
/* Check if channel is open */
|
||||
if( !channelOpen )
|
||||
throw new ErrorMsg( "Channel not open! Cannot send to unopened channel." );
|
||||
|
||||
/* Attempt writing */
|
||||
if( !WriteFile( serialHandle, &data, 1, &written, NULL ) )
|
||||
throw new ErrorMsg( "Error writing byte to COM port!" );
|
||||
}
|
||||
|
||||
|
||||
/* Receive a single byte */
|
||||
long SerialPort::getByte()
|
||||
{
|
||||
time_t startTime;
|
||||
startTime = time( NULL ); // Read current time in seconds
|
||||
DWORD readnum;
|
||||
unsigned char data;
|
||||
|
||||
/* Check if channel is open */
|
||||
if( !channelOpen )
|
||||
throw new ErrorMsg( "Channel not open! Cannot read from unopened channel." );
|
||||
|
||||
/* Attempt receiving byte until timeout limit exceeded */
|
||||
do
|
||||
{
|
||||
/* Read byte from port */
|
||||
if( !ReadFile( serialHandle, &data, 1, &readnum, NULL ) )
|
||||
{
|
||||
throw new ErrorMsg( "Error reading byte from COM port!" );
|
||||
}
|
||||
|
||||
if( readnum == 1 )
|
||||
return ((long) data) & 0xff;
|
||||
|
||||
} while( time(NULL) - startTime < timeout );
|
||||
|
||||
/* Timeout */
|
||||
throw new ErrorMsg( "Timeout during COM-port read operation!" );
|
||||
}
|
||||
|
||||
|
||||
/* Flush the transmit buffer */
|
||||
void SerialPort::flushTX()
|
||||
{
|
||||
/* Check if channel is open */
|
||||
if( !channelOpen )
|
||||
throw new ErrorMsg( "Channel not open! Cannot flush an unopened channel." );
|
||||
|
||||
/* Purge data from write buffer */
|
||||
if( !PurgeComm( serialHandle, PURGE_TXCLEAR ) )
|
||||
throw new ErrorMsg( "Error flushing COM port TX buffer!" );
|
||||
}
|
||||
|
||||
|
||||
/* Flush the receive buffer */
|
||||
void SerialPort::flushRX()
|
||||
{
|
||||
/* Check if channel is open */
|
||||
if( !channelOpen )
|
||||
throw new ErrorMsg( "Channel not open! Cannot flush an unopened channel." );
|
||||
|
||||
/* Purge data from write buffer */
|
||||
if( !PurgeComm( serialHandle, PURGE_RXCLEAR ) )
|
||||
throw new ErrorMsg( "Error flushing COM port RX buffer!" );
|
||||
}
|
||||
|
||||
|
||||
/* Transmit multiple bytes */
|
||||
void SerialPort::sendMultiple( unsigned char * data, long bufsize )
|
||||
{
|
||||
DWORD written;
|
||||
|
||||
/* Check if channel is open */
|
||||
if( !channelOpen )
|
||||
throw new ErrorMsg( "Channel not open! Cannot write to unopened channel." );
|
||||
|
||||
/* Attempt writing */
|
||||
if( !WriteFile( serialHandle, data, bufsize, &written, NULL ) )
|
||||
throw new ErrorMsg( "Error writing multiple bytes to COM port!" );
|
||||
}
|
||||
|
||||
/* end of file */
|
||||
|
||||
|
||||
@@ -1,75 +1,75 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : SerialPort.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class providing serial communication through the PC COM port.
|
||||
* This class is derived from the CommChannel abstract class.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef SERIALPORT_HPP
|
||||
#define SERIALPORT_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <time.h>
|
||||
#include <iostream>
|
||||
#include "CommChannel.hpp"
|
||||
#include "ErrorMsg.hpp"
|
||||
|
||||
|
||||
class SerialPort : public CommChannel
|
||||
{
|
||||
protected:
|
||||
long portNumber; // COMx port number.
|
||||
long timeout; // Desired timeout limit when receiving data.
|
||||
HANDLE serialHandle; // Win32 device handle for the com port.
|
||||
COMMTIMEOUTS oldComTimeouts; // Store old serial port timeout parameters.
|
||||
bool channelOpen; // Is channel open?
|
||||
|
||||
public:
|
||||
// Constructor taking port number, baudrate and
|
||||
// timeout limit as parameters.
|
||||
SerialPort( long portnumber, long timeout );
|
||||
|
||||
// Destructor.
|
||||
~SerialPort();
|
||||
|
||||
// Open the communication channel.
|
||||
virtual void openChannel();
|
||||
|
||||
// Close the communication channel.
|
||||
virtual void closeChannel();
|
||||
|
||||
// Transmit a single byte.
|
||||
virtual void sendByte( long data );
|
||||
|
||||
// Receive a single byte.
|
||||
virtual long getByte();
|
||||
|
||||
// Flush the transmit buffer.
|
||||
virtual void flushTX();
|
||||
|
||||
// Flush the receive buffer.
|
||||
virtual void flushRX();
|
||||
|
||||
// Transmit multiple bytes.
|
||||
virtual void sendMultiple( unsigned char * data, long bufsize );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : SerialPort.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class providing serial communication through the PC COM port.
|
||||
* This class is derived from the CommChannel abstract class.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef SERIALPORT_HPP
|
||||
#define SERIALPORT_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <time.h>
|
||||
#include <iostream>
|
||||
#include "CommChannel.hpp"
|
||||
#include "ErrorMsg.hpp"
|
||||
|
||||
|
||||
class SerialPort : public CommChannel
|
||||
{
|
||||
protected:
|
||||
long portNumber; // COMx port number.
|
||||
long timeout; // Desired timeout limit when receiving data.
|
||||
HANDLE serialHandle; // Win32 device handle for the com port.
|
||||
COMMTIMEOUTS oldComTimeouts; // Store old serial port timeout parameters.
|
||||
bool channelOpen; // Is channel open?
|
||||
|
||||
public:
|
||||
// Constructor taking port number, baudrate and
|
||||
// timeout limit as parameters.
|
||||
SerialPort( long portnumber, long timeout );
|
||||
|
||||
// Destructor.
|
||||
~SerialPort();
|
||||
|
||||
// Open the communication channel.
|
||||
virtual void openChannel();
|
||||
|
||||
// Close the communication channel.
|
||||
virtual void closeChannel();
|
||||
|
||||
// Transmit a single byte.
|
||||
virtual void sendByte( long data );
|
||||
|
||||
// Receive a single byte.
|
||||
virtual long getByte();
|
||||
|
||||
// Flush the transmit buffer.
|
||||
virtual void flushTX();
|
||||
|
||||
// Flush the receive buffer.
|
||||
virtual void flushRX();
|
||||
|
||||
// Transmit multiple bytes.
|
||||
virtual void sendMultiple( unsigned char * data, long bufsize );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,181 +1,181 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : Utility.cpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class holding misc. utility methods used in AVROSP.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "Utility.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Global object */
|
||||
Utility Util;
|
||||
|
||||
|
||||
/* Constructor */
|
||||
Utility::Utility() :
|
||||
noLog( false ),
|
||||
noProgress( false )
|
||||
{
|
||||
/* No code here */
|
||||
}
|
||||
|
||||
|
||||
/* Destructor */
|
||||
Utility::~Utility()
|
||||
{
|
||||
/* No code here */
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Utility::log( const string & txt )
|
||||
{
|
||||
if( !noLog )
|
||||
cout << txt;
|
||||
}
|
||||
|
||||
|
||||
void Utility::progress( const string & txt )
|
||||
{
|
||||
if( !noProgress )
|
||||
cout << txt;
|
||||
}
|
||||
|
||||
|
||||
long Utility::convertHex( const string & txt )
|
||||
{
|
||||
long result = 0;
|
||||
long digit;
|
||||
long i;
|
||||
|
||||
if( txt.size() == 0 )
|
||||
throw new ErrorMsg( "Cannot convert zero-length hex-string to number!" );
|
||||
|
||||
if( txt.size() > 8 )
|
||||
throw new ErrorMsg( "Hex conversion overflow! Too many hex digits in string." );
|
||||
|
||||
|
||||
for( i = 0; i < txt.size(); i++ )
|
||||
{
|
||||
/* Convert hex digit */
|
||||
if( txt[i] >= '0' && txt[i] <= '9' )
|
||||
digit = txt[i] - '0';
|
||||
else if( txt[i] >= 'a' && txt[i] <= 'f' )
|
||||
digit = txt[i] - 'a' + 10;
|
||||
else if( txt[i] >= 'A' && txt[i] <= 'F' )
|
||||
digit = txt[i] - 'A' + 10;
|
||||
else
|
||||
throw new ErrorMsg( "Invalid hex digit found!" );
|
||||
|
||||
/* Add digit as least significant 4 bits of result */
|
||||
result = (result << 4) | digit;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
string Utility::convertLong( long num, long radix )
|
||||
{
|
||||
char buf[18];
|
||||
string res;
|
||||
|
||||
itoa( num, buf, radix );
|
||||
res = buf;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void Utility::parsePath( vector<string> & list )
|
||||
{
|
||||
/* Get environment variable and parse if it exists */
|
||||
char * pathptr = getenv( "PATH" );
|
||||
if( pathptr != NULL && pathptr[0] != 0 ) {
|
||||
string path = pathptr;
|
||||
int pos;
|
||||
|
||||
while( (pos = path.find_first_of( ";" )) < path.length() ) {
|
||||
list.push_back( path.substr( 0, pos ) );
|
||||
path.erase( 0, pos+1 );
|
||||
}
|
||||
|
||||
list.push_back( path ); // Last directory.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Utility::fileExists( string filename )
|
||||
{
|
||||
/* Attempt to open file */
|
||||
ifstream f;
|
||||
f.open( filename.c_str(), ios::in );
|
||||
if( !f ) {
|
||||
return false;
|
||||
} else {
|
||||
f.close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Utility::saveString( string txt, string filename )
|
||||
{
|
||||
ofstream f;
|
||||
|
||||
f.open( filename.c_str(), ios::out );
|
||||
if( !f )
|
||||
throw new ErrorMsg( "Error opening HEX file for output!" );
|
||||
|
||||
f << txt;
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
|
||||
#ifndef NOREGISTRY
|
||||
string Utility::getRegistryValue( const string & path, const string & value )
|
||||
{
|
||||
/* Code modified from MSDN */
|
||||
const long BUFSIZE=1000;
|
||||
string result;
|
||||
HKEY hKey;
|
||||
char szAVRPath[BUFSIZE];
|
||||
DWORD dwBufLen=BUFSIZE;
|
||||
LONG lRet;
|
||||
|
||||
/* Open key */
|
||||
lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE, path.c_str(), 0, KEY_QUERY_VALUE, &hKey );
|
||||
if( lRet != ERROR_SUCCESS )
|
||||
throw new ErrorMsg( "Error when opening registry key: (" + path + ")!" );
|
||||
|
||||
/* Get value */
|
||||
lRet = RegQueryValueEx( hKey, value.c_str(), NULL, NULL, (LPBYTE) szAVRPath, &dwBufLen);
|
||||
if( (lRet != ERROR_SUCCESS) || (dwBufLen > BUFSIZE) )
|
||||
throw new ErrorMsg( "Error when reading key value: (" + value + ")!" );
|
||||
|
||||
/* Clean up and return result */
|
||||
RegCloseKey( hKey );
|
||||
result = szAVRPath;
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* end of file */
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : Utility.cpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class holding misc. utility methods used in AVROSP.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "Utility.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Global object */
|
||||
Utility Util;
|
||||
|
||||
|
||||
/* Constructor */
|
||||
Utility::Utility() :
|
||||
noLog( false ),
|
||||
noProgress( false )
|
||||
{
|
||||
/* No code here */
|
||||
}
|
||||
|
||||
|
||||
/* Destructor */
|
||||
Utility::~Utility()
|
||||
{
|
||||
/* No code here */
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Utility::log( const string & txt )
|
||||
{
|
||||
if( !noLog )
|
||||
cout << txt;
|
||||
}
|
||||
|
||||
|
||||
void Utility::progress( const string & txt )
|
||||
{
|
||||
if( !noProgress )
|
||||
cout << txt;
|
||||
}
|
||||
|
||||
|
||||
long Utility::convertHex( const string & txt )
|
||||
{
|
||||
long result = 0;
|
||||
long digit;
|
||||
long i;
|
||||
|
||||
if( txt.size() == 0 )
|
||||
throw new ErrorMsg( "Cannot convert zero-length hex-string to number!" );
|
||||
|
||||
if( txt.size() > 8 )
|
||||
throw new ErrorMsg( "Hex conversion overflow! Too many hex digits in string." );
|
||||
|
||||
|
||||
for( i = 0; i < txt.size(); i++ )
|
||||
{
|
||||
/* Convert hex digit */
|
||||
if( txt[i] >= '0' && txt[i] <= '9' )
|
||||
digit = txt[i] - '0';
|
||||
else if( txt[i] >= 'a' && txt[i] <= 'f' )
|
||||
digit = txt[i] - 'a' + 10;
|
||||
else if( txt[i] >= 'A' && txt[i] <= 'F' )
|
||||
digit = txt[i] - 'A' + 10;
|
||||
else
|
||||
throw new ErrorMsg( "Invalid hex digit found!" );
|
||||
|
||||
/* Add digit as least significant 4 bits of result */
|
||||
result = (result << 4) | digit;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
string Utility::convertLong( long num, long radix )
|
||||
{
|
||||
char buf[18];
|
||||
string res;
|
||||
|
||||
itoa( num, buf, radix );
|
||||
res = buf;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void Utility::parsePath( vector<string> & list )
|
||||
{
|
||||
/* Get environment variable and parse if it exists */
|
||||
char * pathptr = getenv( "PATH" );
|
||||
if( pathptr != NULL && pathptr[0] != 0 ) {
|
||||
string path = pathptr;
|
||||
int pos;
|
||||
|
||||
while( (pos = path.find_first_of( ";" )) < path.length() ) {
|
||||
list.push_back( path.substr( 0, pos ) );
|
||||
path.erase( 0, pos+1 );
|
||||
}
|
||||
|
||||
list.push_back( path ); // Last directory.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Utility::fileExists( string filename )
|
||||
{
|
||||
/* Attempt to open file */
|
||||
ifstream f;
|
||||
f.open( filename.c_str(), ios::in );
|
||||
if( !f ) {
|
||||
return false;
|
||||
} else {
|
||||
f.close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Utility::saveString( string txt, string filename )
|
||||
{
|
||||
ofstream f;
|
||||
|
||||
f.open( filename.c_str(), ios::out );
|
||||
if( !f )
|
||||
throw new ErrorMsg( "Error opening HEX file for output!" );
|
||||
|
||||
f << txt;
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
|
||||
#ifndef NOREGISTRY
|
||||
string Utility::getRegistryValue( const string & path, const string & value )
|
||||
{
|
||||
/* Code modified from MSDN */
|
||||
const long BUFSIZE=1000;
|
||||
string result;
|
||||
HKEY hKey;
|
||||
char szAVRPath[BUFSIZE];
|
||||
DWORD dwBufLen=BUFSIZE;
|
||||
LONG lRet;
|
||||
|
||||
/* Open key */
|
||||
lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE, path.c_str(), 0, KEY_QUERY_VALUE, &hKey );
|
||||
if( lRet != ERROR_SUCCESS )
|
||||
throw new ErrorMsg( "Error when opening registry key: (" + path + ")!" );
|
||||
|
||||
/* Get value */
|
||||
lRet = RegQueryValueEx( hKey, value.c_str(), NULL, NULL, (LPBYTE) szAVRPath, &dwBufLen);
|
||||
if( (lRet != ERROR_SUCCESS) || (dwBufLen > BUFSIZE) )
|
||||
throw new ErrorMsg( "Error when reading key value: (" + value + ")!" );
|
||||
|
||||
/* Clean up and return result */
|
||||
RegCloseKey( hKey );
|
||||
result = szAVRPath;
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* end of file */
|
||||
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : Utility.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class holding misc. utility methods used in AVROSP.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef UTILITY_HPP
|
||||
#define UTILITY_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifndef NOREGISTRY
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "ErrorMsg.hpp"
|
||||
|
||||
class Utility
|
||||
{
|
||||
protected:
|
||||
bool noLog;
|
||||
bool noProgress;
|
||||
|
||||
public:
|
||||
/* Constructor */
|
||||
Utility();
|
||||
|
||||
/* Destructor */
|
||||
~Utility();
|
||||
|
||||
/* Methods */
|
||||
void muteLog() { noLog = true; }
|
||||
void muteProgress() { noProgress = true; }
|
||||
|
||||
void log( const string & txt );
|
||||
void progress( const string & txt );
|
||||
|
||||
long convertHex( const string & txt );
|
||||
string convertLong( long num, long radix = 10 );
|
||||
|
||||
void parsePath( vector<string> & list );
|
||||
bool fileExists( string filename );
|
||||
void saveString( string txt, string filename );
|
||||
|
||||
#ifndef NOREGISTRY
|
||||
string getRegistryValue( const string & path, const string & value );
|
||||
#endif
|
||||
};
|
||||
|
||||
extern Utility Util;
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : Utility.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A class holding misc. utility methods used in AVROSP.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef UTILITY_HPP
|
||||
#define UTILITY_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifndef NOREGISTRY
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "ErrorMsg.hpp"
|
||||
|
||||
class Utility
|
||||
{
|
||||
protected:
|
||||
bool noLog;
|
||||
bool noProgress;
|
||||
|
||||
public:
|
||||
/* Constructor */
|
||||
Utility();
|
||||
|
||||
/* Destructor */
|
||||
~Utility();
|
||||
|
||||
/* Methods */
|
||||
void muteLog() { noLog = true; }
|
||||
void muteProgress() { noProgress = true; }
|
||||
|
||||
void log( const string & txt );
|
||||
void progress( const string & txt );
|
||||
|
||||
long convertHex( const string & txt );
|
||||
string convertLong( long num, long radix = 10 );
|
||||
|
||||
void parsePath( vector<string> & list );
|
||||
bool fileExists( string filename );
|
||||
void saveString( string txt, string filename );
|
||||
|
||||
#ifndef NOREGISTRY
|
||||
string getRegistryValue( const string & path, const string & value );
|
||||
#endif
|
||||
};
|
||||
|
||||
extern Utility Util;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,65 +1,65 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : XMLParser.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 3419 $
|
||||
* Date : $Date: 2008-02-22 09:56:34 +0100 (fr, 22 feb 2008) $
|
||||
* Updated by : $Author: khole $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A simple XML DOM-like parser. It builds a complete tree from
|
||||
* the XML file. IT supports <section/> tags, but not tag attributes.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef XMLPARSER_HPP
|
||||
#define XMLPARSER_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "ErrorMsg.hpp"
|
||||
#include "Utility.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <list>
|
||||
|
||||
class XMLAbstractNode; // Preliminary definitions.
|
||||
class XMLTree;
|
||||
class XMLNode;
|
||||
|
||||
|
||||
/* Main XML file class. Contains search methods and entire XML tree */
|
||||
class XMLFile
|
||||
{
|
||||
protected:
|
||||
XMLTree * root; // The root node, either a subtree or an ordinary node.
|
||||
|
||||
void XMLFile::removeStartXML( string & txt ); // Remove the start xml tag.
|
||||
void removeComments( string & txt ); // Remove comment tags.
|
||||
void removeAttributes( string & txt ); // Remove attributes from tags.
|
||||
void readFile( const string & _filename ); // Read XML file.
|
||||
void parseFragment( string & fragment, XMLTree * parent );
|
||||
|
||||
public:
|
||||
/* Constructors */
|
||||
XMLFile( const string & _filename );
|
||||
|
||||
/* Destructor */
|
||||
~XMLFile();
|
||||
|
||||
/* Methods */
|
||||
bool exists( const string & path ); // Checks if node exists.
|
||||
const string & getValue( const string & path ); // Get node value.
|
||||
|
||||
void print();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : XMLParser.hpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 3419 $
|
||||
* Date : $Date: 2008-02-22 09:56:34 +0100 (fr, 22 feb 2008) $
|
||||
* Updated by : $Author: khole $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : A simple XML DOM-like parser. It builds a complete tree from
|
||||
* the XML file. IT supports <section/> tags, but not tag attributes.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#ifndef XMLPARSER_HPP
|
||||
#define XMLPARSER_HPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "ErrorMsg.hpp"
|
||||
#include "Utility.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <list>
|
||||
|
||||
class XMLAbstractNode; // Preliminary definitions.
|
||||
class XMLTree;
|
||||
class XMLNode;
|
||||
|
||||
|
||||
/* Main XML file class. Contains search methods and entire XML tree */
|
||||
class XMLFile
|
||||
{
|
||||
protected:
|
||||
XMLTree * root; // The root node, either a subtree or an ordinary node.
|
||||
|
||||
void XMLFile::removeStartXML( string & txt ); // Remove the start xml tag.
|
||||
void removeComments( string & txt ); // Remove comment tags.
|
||||
void removeAttributes( string & txt ); // Remove attributes from tags.
|
||||
void readFile( const string & _filename ); // Read XML file.
|
||||
void parseFragment( string & fragment, XMLTree * parent );
|
||||
|
||||
public:
|
||||
/* Constructors */
|
||||
XMLFile( const string & _filename );
|
||||
|
||||
/* Destructor */
|
||||
~XMLFile();
|
||||
|
||||
/* Methods */
|
||||
bool exists( const string & path ); // Checks if node exists.
|
||||
const string & getValue( const string & path ); // Get node value.
|
||||
|
||||
void print();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : main.cpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : AVROSP main entry function.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "JobInfo.hpp"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
JobInfo j;
|
||||
|
||||
try
|
||||
{
|
||||
j.parseCommandline( argc, argv );
|
||||
j.doJob();
|
||||
}
|
||||
catch( ErrorMsg * e )
|
||||
{
|
||||
cout << endl << "An error occurred:" << endl;
|
||||
cout << " [" << e->What() << "]" << endl;
|
||||
|
||||
delete e;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Atmel Corporation
|
||||
*
|
||||
* File : main.cpp
|
||||
* Compiler : Dev-C++ 4.9.8.0 - http://bloodshed.net/dev/
|
||||
* Revision : $Revision: 1163 $
|
||||
* Date : $Date: 2006-08-02 15:38:16 +0200 (on, 02 aug 2006) $
|
||||
* Updated by : $Author: ohlia $
|
||||
*
|
||||
* Support mail : avr@atmel.com
|
||||
*
|
||||
* Target platform : Win32
|
||||
*
|
||||
* AppNote : AVR911 - AVR Open-source Programmer
|
||||
*
|
||||
* Description : AVROSP main entry function.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "JobInfo.hpp"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
JobInfo j;
|
||||
|
||||
try
|
||||
{
|
||||
j.parseCommandline( argc, argv );
|
||||
j.doJob();
|
||||
}
|
||||
catch( ErrorMsg * e )
|
||||
{
|
||||
cout << endl << "An error occurred:" << endl;
|
||||
cout << " [" << e->What() << "]" << endl;
|
||||
|
||||
delete e;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user