diff options
Diffstat (limited to 'src/devices/mem24/prog')
-rw-r--r-- | src/devices/mem24/prog/Makefile.am | 5 | ||||
-rw-r--r-- | src/devices/mem24/prog/mem24_prog.cpp | 88 | ||||
-rw-r--r-- | src/devices/mem24/prog/mem24_prog.h | 63 | ||||
-rw-r--r-- | src/devices/mem24/prog/prog.pro | 6 |
4 files changed, 162 insertions, 0 deletions
diff --git a/src/devices/mem24/prog/Makefile.am b/src/devices/mem24/prog/Makefile.am new file mode 100644 index 0000000..1c1a55e --- /dev/null +++ b/src/devices/mem24/prog/Makefile.am @@ -0,0 +1,5 @@ +INCLUDES = -I$(top_srcdir)/src $(all_includes) +METASOURCES = AUTO + +noinst_LTLIBRARIES = libmem24prog.la +libmem24prog_la_SOURCES = mem24_prog.cpp diff --git a/src/devices/mem24/prog/mem24_prog.cpp b/src/devices/mem24/prog/mem24_prog.cpp new file mode 100644 index 0000000..4c4b201 --- /dev/null +++ b/src/devices/mem24/prog/mem24_prog.cpp @@ -0,0 +1,88 @@ +/*************************************************************************** + * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#include "mem24_prog.h" + +#include "common/global/global.h" +#include "devices/list/device_list.h" +#include "progs/base/prog_config.h" + +//----------------------------------------------------------------------------- +bool Programmer::Mem24DeviceSpecific::read(Device::Array &data, const VerifyData *vdata) +{ + setPowerOn(); + doRead(data, vdata); + setPowerOff(); + return !hasError(); +} + +bool Programmer::Mem24DeviceSpecific::write(const Device::Array &data) +{ + setPowerOn(); + doWrite(data); + setPowerOff(); + return !hasError(); +} + +bool Programmer::Mem24DeviceSpecific::verifyByte(uint index, BitValue d, const VerifyData &vdata) +{ + BitValue v = static_cast<const Mem24::Memory &>(vdata.memory).byte(index); + v = v.maskWith(0xFF); + d = d.maskWith(0xFF); + if ( v==d ) return true; + Address address = index; + if ( vdata.actions & BlankCheckVerify ) + log(Log::LineType::Error, i18n("Device memory is not blank (at address %1: reading %2 and expecting %3).") + .arg(toHexLabel(address, device().nbCharsAddress())).arg(toHexLabel(d, 2)).arg(toHexLabel(v, 2))); + else log(Log::LineType::Error, i18n("Device memory doesn't match hex file (at address %1: reading %2 and expecting %3).") + .arg(toHexLabel(address, device().nbCharsAddress())).arg(toHexLabel(d, 2)).arg(toHexLabel(v, 2))); + return false; +} + +//---------------------------------------------------------------------------- +uint Programmer::Mem24Base::nbSteps(Task task, const Device::MemoryRange *) const +{ + uint nb = device()->nbBytes(); + if ( task==Task::Write && readConfigEntry(Config::VerifyAfterProgram).toBool() ) nb += device()->nbBytes(); + return nb; +} + +bool Programmer::Mem24Base::internalErase(const Device::MemoryRange &) +{ + initProgramming(); + Mem24::Memory memory(*device()); + return specific()->write(memory.arrayForWriting()); +} + +bool Programmer::Mem24Base::internalRead(Device::Memory *memory, const Device::MemoryRange &, const VerifyData *vdata) +{ + initProgramming(); + Device::Array data; + if ( !specific()->read(data, vdata) ) return false; + if (memory) for (uint i=0; i<data.count(); i++) static_cast<Mem24::Memory *>(memory)->setByte(i, data[i]); + return true; +} + +bool Programmer::Mem24Base::internalProgram(const Device::Memory &memory, const Device::MemoryRange &) +{ + initProgramming(); + const Mem24::Memory &pmemory = static_cast<const Mem24::Memory &>(memory); + const Device::Array &data = pmemory.arrayForWriting(); + if ( !specific()->write(data) ) return false; + if ( !readConfigEntry(Config::VerifyAfterProgram).toBool() ) return true; + VerifyActions actions = IgnoreProtectedVerify; + if ( readConfigEntry(Config::OnlyVerifyProgrammed).toBool() ) actions |= OnlyProgrammedVerify; + VerifyData vdata(actions, pmemory); + Device::Array adata; + return specific()->read(adata, &vdata); +} + +bool Programmer::Mem24Base::verifyDeviceId() +{ + return specific()->verifyPresence(); +} diff --git a/src/devices/mem24/prog/mem24_prog.h b/src/devices/mem24/prog/mem24_prog.h new file mode 100644 index 0000000..86948c2 --- /dev/null +++ b/src/devices/mem24/prog/mem24_prog.h @@ -0,0 +1,63 @@ +/*************************************************************************** + * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ +#ifndef MEM24_PROG_H +#define MEM24_PROG_H + +#include "progs/base/generic_prog.h" +#include "devices/mem24/mem24/mem24_memory.h" + +namespace Programmer +{ +//----------------------------------------------------------------------------- +class Mem24DeviceSpecific : public DeviceSpecific +{ +public: + Mem24DeviceSpecific(::Programmer::Base &base) : DeviceSpecific(base) {} + const Mem24::Data &device() const { return static_cast<const Mem24::Data &>(*_base.device()); } + bool read(Device::Array &data, const VerifyData *vdata); + bool write(const Device::Array &data); + bool verifyByte(uint index, BitValue d, const VerifyData &vdata); + virtual bool verifyPresence() = 0; + +protected: + virtual bool doRead(Device::Array &data, const VerifyData *vdata) = 0; + virtual bool doWrite(const Device::Array &data) = 0; +}; + +//----------------------------------------------------------------------------- +class Mem24Hardware : public Hardware +{ +public: + Mem24Hardware(::Programmer::Base &base, Port::Base *port, const QString &name) : Hardware(base, port, name) {} + const Mem24::Data &device() const { return static_cast<const Mem24::Data &>(*_base.device()); } +}; + +//----------------------------------------------------------------------------- +class Mem24Base : public Base +{ +public: + Mem24Base(const Group &group, const Mem24::Data *data, const char *name) : Base(group, data, name) {} + const Mem24::Data *device() const { return static_cast<const Mem24::Data *>(_device); } + +protected: + Mem24DeviceSpecific *specific() const { return static_cast<Mem24DeviceSpecific *>(_specific); } + virtual bool verifyDeviceId(); + virtual uint nbSteps(Task task, const Device::MemoryRange *range) const; + virtual bool initProgramming() { return true; } + virtual bool checkErase() { return true; } + virtual bool internalErase(const Device::MemoryRange &range); + virtual bool checkRead() { return true; } + virtual bool internalRead(Device::Memory *memory, const Device::MemoryRange &range, const VerifyData *vdata); + virtual bool checkProgram(const Device::Memory &) { return true; } + virtual bool internalProgram(const Device::Memory &memory, const Device::MemoryRange &range); +}; + +} // namespace + +#endif diff --git a/src/devices/mem24/prog/prog.pro b/src/devices/mem24/prog/prog.pro new file mode 100644 index 0000000..2acd347 --- /dev/null +++ b/src/devices/mem24/prog/prog.pro @@ -0,0 +1,6 @@ +STOPDIR = ../../../.. +include($${STOPDIR}/lib.pro) + +TARGET = mem24prog +HEADERS += mem24_prog.h +SOURCES += mem24_prog.cpp |