summaryrefslogtreecommitdiffstats
path: root/src/progs/pickit2_bootloader/base
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 18:42:24 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 18:42:24 +0000
commitf508189682b6fba62e08feeb1596f682bad5fff9 (patch)
tree28aeb0e6c19386c385c1ce5edf8a92c1bca15281 /src/progs/pickit2_bootloader/base
downloadpiklab-f508189682b6fba62e08feeb1596f682bad5fff9.tar.gz
piklab-f508189682b6fba62e08feeb1596f682bad5fff9.zip
Added KDE3 version of PikLab
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/piklab@1095639 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/progs/pickit2_bootloader/base')
-rw-r--r--src/progs/pickit2_bootloader/base/Makefile.am11
-rw-r--r--src/progs/pickit2_bootloader/base/base.pro6
-rw-r--r--src/progs/pickit2_bootloader/base/pickit2_bootloader.cpp73
-rw-r--r--src/progs/pickit2_bootloader/base/pickit2_bootloader.h43
-rw-r--r--src/progs/pickit2_bootloader/base/pickit2_bootloader.xml16
-rw-r--r--src/progs/pickit2_bootloader/base/pickit2_bootloader_data.h19
-rw-r--r--src/progs/pickit2_bootloader/base/pickit2_bootloader_prog.cpp14
-rw-r--r--src/progs/pickit2_bootloader/base/pickit2_bootloader_prog.h47
8 files changed, 229 insertions, 0 deletions
diff --git a/src/progs/pickit2_bootloader/base/Makefile.am b/src/progs/pickit2_bootloader/base/Makefile.am
new file mode 100644
index 0000000..db87222
--- /dev/null
+++ b/src/progs/pickit2_bootloader/base/Makefile.am
@@ -0,0 +1,11 @@
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
+METASOURCES = AUTO
+
+noinst_LTLIBRARIES = libpickit2bootloader.la
+libpickit2bootloader_la_SOURCES = pickit2_bootloader_data.cpp pickit2_bootloader_prog.cpp pickit2_bootloader.cpp
+libpickit2bootloader_la_DEPENDENCIES = pickit2_bootloader_data.cpp
+
+noinst_DATA = pickit2_bootloader.xml
+pickit2_bootloader_data.cpp: ../xml/xml_pickit2_bootloader_parser pickit2_bootloader.xml
+ ../xml/xml_pickit2_bootloader_parser
+CLEANFILES = pickit2_bootloader_data.cpp
diff --git a/src/progs/pickit2_bootloader/base/base.pro b/src/progs/pickit2_bootloader/base/base.pro
new file mode 100644
index 0000000..9a2fe76
--- /dev/null
+++ b/src/progs/pickit2_bootloader/base/base.pro
@@ -0,0 +1,6 @@
+STOPDIR = ../../../..
+include($${STOPDIR}/lib.pro)
+
+TARGET = pickit2_bootloader
+HEADERS += pickit2_bootloader.h pickit2_bootloader_prog.h pickit2_bootloader_data.h
+SOURCES += pickit2_bootloader.cpp pickit2_bootloader_prog.cpp pickit2_bootloader_data.cpp
diff --git a/src/progs/pickit2_bootloader/base/pickit2_bootloader.cpp b/src/progs/pickit2_bootloader/base/pickit2_bootloader.cpp
new file mode 100644
index 0000000..d080481
--- /dev/null
+++ b/src/progs/pickit2_bootloader/base/pickit2_bootloader.cpp
@@ -0,0 +1,73 @@
+/***************************************************************************
+ * Copyright (C) 2007 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 "pickit2_bootloader.h"
+
+//-----------------------------------------------------------------------------
+Pickit2Bootloader::Hardware::Hardware(::Programmer::Base &base)
+ : Bootloader::Hardware(base, new Pickit2::USBPort(base))
+{}
+
+bool Pickit2Bootloader::Hardware::internalConnectHardware()
+{
+ if ( !openPort() ) return false;
+ ::Programmer::Mode mode;
+ VersionData version;
+ if ( !port().getMode(version, mode) ) return false;
+ if ( mode!=::Programmer::BootloadMode ) {
+ log(Log::LineType::Information, i18n("Trying to enter bootloader mode..."));
+ if ( !port().resetFirmwareDevice(::Programmer::BootloadMode) ) return false;
+ for (uint i=0;; i++) {
+ port().close();
+ Port::usleep(500000); // ??
+ if ( !openPort() ) continue;
+ if ( !port().getMode(version, mode) ) continue;
+ if ( i==4 || mode!=::Programmer::BootloadMode ) {
+ log(Log::LineType::Error, i18n("Could not detect device in bootloader mode."));
+ return false;
+ }
+ }
+ }
+ log(Log::LineType::Information, i18n("Bootloader version %1 detected.").arg(version.pretty()));
+ if ( version.majorNum()!=2 ) {
+ log(Log::LineType::Error, i18n("Only bootloader version 2.x is supported."));
+ return false;
+ }
+ return true;
+}
+
+bool Pickit2Bootloader::Hardware::write(Pic::MemoryRangeType type, const Device::Array &data)
+{
+ Q_ASSERT( data.count()==device().nbWords(type) );
+ Q_ASSERT( type==Pic::MemoryRangeType::Code );
+ // check that there is nothing in bootloader reserved area
+ for (uint i=0; i<data.count(); i++) {
+ if ( i>=0x1000 && i<0x3FF0 ) continue;
+ if ( data[i]==device().mask(Pic::MemoryRangeType::Code) ) continue;
+ uint address = device().addressIncrement(Pic::MemoryRangeType::Code) * i;
+ log(Log::LineType::Warning, " " + i18n("Code is present in bootloader reserved area (at address %1). It will be ignored.").arg(toHexLabel(address, device().nbCharsAddress())));
+ break;
+ }
+ return port().writeFirmwareCodeMemory(data, _base.progressMonitor());
+}
+
+bool Pickit2Bootloader::Hardware::read(Pic::MemoryRangeType type, Device::Array &data, const ::Programmer::VerifyData *vdata)
+{
+ Q_ASSERT( type==Pic::MemoryRangeType::Code );
+ data.resize(device().nbWords(type));
+ Device::Array varray;
+ if (vdata) varray = static_cast<const Pic::Memory &>(vdata->memory).arrayForWriting(Pic::MemoryRangeType::Code);
+ return port().readFirmwareCodeMemory(data, vdata ? &varray : 0, _base.progressMonitor());
+}
+
+//-----------------------------------------------------------------------------
+bool Pickit2Bootloader::DeviceSpecific::doEraseRange(Pic::MemoryRangeType type)
+{
+ Q_ASSERT( type==Pic::MemoryRangeType::Code );
+ return static_cast<Hardware &>(hardware()).port().eraseFirmwareCodeMemory();
+}
diff --git a/src/progs/pickit2_bootloader/base/pickit2_bootloader.h b/src/progs/pickit2_bootloader/base/pickit2_bootloader.h
new file mode 100644
index 0000000..7af0957
--- /dev/null
+++ b/src/progs/pickit2_bootloader/base/pickit2_bootloader.h
@@ -0,0 +1,43 @@
+/***************************************************************************
+ * Copyright (C) 2007 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 PICKIT2_BOOTLOADER_H
+#define PICKIT2_BOOTLOADER_H
+
+#include "progs/bootloader/base/bootloader.h"
+#include "progs/pickit2/base/pickit2.h"
+
+namespace Pickit2Bootloader
+{
+//-----------------------------------------------------------------------------
+class Hardware : public Bootloader::Hardware
+{
+public:
+ Hardware(::Programmer::Base &base);
+ Pickit2::USBPort &port() { return static_cast<Pickit2::USBPort &>(*_port); }
+ virtual bool write(Pic::MemoryRangeType type, const Device::Array &data);
+ virtual bool read(Pic::MemoryRangeType type, Device::Array &data, const ::Programmer::VerifyData *vdata);
+ virtual bool internalConnectHardware();
+};
+
+//-----------------------------------------------------------------------------
+class DeviceSpecific : public Bootloader::DeviceSpecific
+{
+public:
+ DeviceSpecific(::Programmer::Base &base) : Bootloader::DeviceSpecific(base) {}
+ virtual bool canEraseAll() const { return true; }
+ virtual bool canEraseRange(Pic::MemoryRangeType type) const { return ( type==Pic::MemoryRangeType::Code ); }
+ virtual bool canReadRange(Pic::MemoryRangeType type) const { return ( type==Pic::MemoryRangeType::Code ); }
+ virtual bool canWriteRange(Pic::MemoryRangeType type) const { return ( type==Pic::MemoryRangeType::Code ); }
+ virtual bool doEraseRange(Pic::MemoryRangeType type);
+ virtual bool doErase(bool) { return doEraseRange(Pic::MemoryRangeType::Code); }
+};
+
+} // namespace
+
+#endif
diff --git a/src/progs/pickit2_bootloader/base/pickit2_bootloader.xml b/src/progs/pickit2_bootloader/base/pickit2_bootloader.xml
new file mode 100644
index 0000000..2e87949
--- /dev/null
+++ b/src/progs/pickit2_bootloader/base/pickit2_bootloader.xml
@@ -0,0 +1,16 @@
+<!-- ************************************************************************* -->
+<!-- * Copyright (C) 2007 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. * -->
+<!-- *************************************************************************/-->
+<!DOCTYPE piklab>
+
+<type name="pickit2_bootloader">
+ <device name="18F2455" family="generic" />
+ <device name="18F2550" family="generic" />
+ <device name="18F4455" family="generic" />
+ <device name="18F4550" family="generic" />
+</type>
diff --git a/src/progs/pickit2_bootloader/base/pickit2_bootloader_data.h b/src/progs/pickit2_bootloader/base/pickit2_bootloader_data.h
new file mode 100644
index 0000000..87aead1
--- /dev/null
+++ b/src/progs/pickit2_bootloader/base/pickit2_bootloader_data.h
@@ -0,0 +1,19 @@
+/***************************************************************************
+ * Copyright (C) 2007 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 PICKIT2_BOOTLOADER_DATA_H
+#define PICKIT2_BOOTLOADER_DATA_H
+
+namespace Pickit2Bootloader
+{
+ struct Data {};
+ extern bool isSupported(const QString &device);
+ extern const Data &data(const QString &device);
+} // namespace
+
+#endif
diff --git a/src/progs/pickit2_bootloader/base/pickit2_bootloader_prog.cpp b/src/progs/pickit2_bootloader/base/pickit2_bootloader_prog.cpp
new file mode 100644
index 0000000..7f734ba
--- /dev/null
+++ b/src/progs/pickit2_bootloader/base/pickit2_bootloader_prog.cpp
@@ -0,0 +1,14 @@
+/***************************************************************************
+ * Copyright (C) 2007 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 "pickit2_bootloader_prog.h"
+
+//-----------------------------------------------------------------------------
+Pickit2Bootloader::ProgrammerBase::ProgrammerBase(const Programmer::Group &group, const Pic::Data *data)
+ : Bootloader::ProgrammerBase(group, data, "pickit2_bootloader_programmer_base")
+{}
diff --git a/src/progs/pickit2_bootloader/base/pickit2_bootloader_prog.h b/src/progs/pickit2_bootloader/base/pickit2_bootloader_prog.h
new file mode 100644
index 0000000..461d734
--- /dev/null
+++ b/src/progs/pickit2_bootloader/base/pickit2_bootloader_prog.h
@@ -0,0 +1,47 @@
+/***************************************************************************
+ * Copyright (C) 2007 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 PICKIT2_BOOTLOADER_PROG_H
+#define PICKIT2_BOOTLOADER_PROG_H
+
+#include "progs/bootloader/base/bootloader_prog.h"
+#include "pickit2_bootloader.h"
+
+namespace Pickit2Bootloader
+{
+
+//-----------------------------------------------------------------------------
+class ProgrammerBase : public ::Bootloader::ProgrammerBase
+{
+Q_OBJECT
+public:
+ ProgrammerBase(const Programmer::Group &group, const Pic::Data *data);
+ virtual bool verifyDeviceId() { return true; }
+};
+
+//-----------------------------------------------------------------------------
+class Group : public ::Bootloader::Group
+{
+public:
+ virtual QString name() const { return "pickit2_bootloader"; }
+ virtual QString label() const { return i18n("Pickit2 Bootloader"); }
+ virtual ::Programmer::Properties properties() const { return ::Programmer::Programmer | ::Programmer::CanReadMemory; }
+ virtual ::Programmer::TargetPowerMode targetPowerMode() const { return ::Programmer::TargetSelfPowered; }
+ virtual bool isPortSupported(PortType type) const { return type==PortType::USB; }
+ virtual bool canReadVoltage(Pic::VoltageType) const { return false; }
+
+protected:
+ virtual void initSupported();
+ virtual ::Programmer::Base *createBase(const Device::Data *data) const { return new ProgrammerBase(*this, static_cast<const Pic::Data *>(data)); }
+ virtual ::Programmer::Hardware *createHardware(::Programmer::Base &base, const ::Programmer::HardwareDescription &) const { return new Hardware(base); }
+ virtual ::Programmer::DeviceSpecific *createDeviceSpecific(::Programmer::Base &base) const { return new DeviceSpecific(base); }
+};
+
+} // namespace
+
+#endif