From f508189682b6fba62e08feeb1596f682bad5fff9 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 24 Feb 2010 18:42:24 +0000 Subject: Added KDE3 version of PikLab git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/piklab@1095639 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/progs/tbl_bootloader/base/Makefile.am | 11 + src/progs/tbl_bootloader/base/base.pro | 6 + src/progs/tbl_bootloader/base/tbl_bootloader.cpp | 327 +++++++++++++++++++++ src/progs/tbl_bootloader/base/tbl_bootloader.h | 74 +++++ src/progs/tbl_bootloader/base/tbl_bootloader.xml | 70 +++++ .../tbl_bootloader/base/tbl_bootloader_data.h | 21 ++ .../tbl_bootloader/base/tbl_bootloader_prog.cpp | 14 + .../tbl_bootloader/base/tbl_bootloader_prog.h | 46 +++ 8 files changed, 569 insertions(+) create mode 100644 src/progs/tbl_bootloader/base/Makefile.am create mode 100644 src/progs/tbl_bootloader/base/base.pro create mode 100644 src/progs/tbl_bootloader/base/tbl_bootloader.cpp create mode 100644 src/progs/tbl_bootloader/base/tbl_bootloader.h create mode 100644 src/progs/tbl_bootloader/base/tbl_bootloader.xml create mode 100644 src/progs/tbl_bootloader/base/tbl_bootloader_data.h create mode 100644 src/progs/tbl_bootloader/base/tbl_bootloader_prog.cpp create mode 100644 src/progs/tbl_bootloader/base/tbl_bootloader_prog.h (limited to 'src/progs/tbl_bootloader/base') diff --git a/src/progs/tbl_bootloader/base/Makefile.am b/src/progs/tbl_bootloader/base/Makefile.am new file mode 100644 index 0000000..60b11bc --- /dev/null +++ b/src/progs/tbl_bootloader/base/Makefile.am @@ -0,0 +1,11 @@ +INCLUDES = -I$(top_srcdir)/src $(all_includes) +METASOURCES = AUTO + +noinst_LTLIBRARIES = libtblbootloader.la +libtblbootloader_la_SOURCES = tbl_bootloader_data.cpp tbl_bootloader.cpp tbl_bootloader_prog.cpp +libtblbootloader_la_DEPENDENCIES = tbl_bootloader_data.cpp + +noinst_DATA = tbl_bootloader.xml +tbl_bootloader_data.cpp: ../xml/xml_tbl_bootloader_parser tbl_bootloader.xml + ../xml/xml_tbl_bootloader_parser +CLEANFILES = tbl_bootloader_data.cpp diff --git a/src/progs/tbl_bootloader/base/base.pro b/src/progs/tbl_bootloader/base/base.pro new file mode 100644 index 0000000..1ccb8e9 --- /dev/null +++ b/src/progs/tbl_bootloader/base/base.pro @@ -0,0 +1,6 @@ +STOPDIR = ../../../.. +include($${STOPDIR}/lib.pro) + +TARGET = tbl_bootloader +HEADERS += tbl_bootloader_data.h tbl_bootloader.h tbl_bootloader_prog.h +SOURCES += tbl_bootloader_data.cpp tbl_bootloader.cpp tbl_bootloader_prog.cpp diff --git a/src/progs/tbl_bootloader/base/tbl_bootloader.cpp b/src/progs/tbl_bootloader/base/tbl_bootloader.cpp new file mode 100644 index 0000000..419ad86 --- /dev/null +++ b/src/progs/tbl_bootloader/base/tbl_bootloader.cpp @@ -0,0 +1,327 @@ +/*************************************************************************** + * Copyright (C) 2007 Nicolas Hadacek * + * * + * 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 "tbl_bootloader.h" + +#include "tbl_bootloader_data.h" +#include "progs/base/prog_config.h" + +//----------------------------------------------------------------------------- +Port::Serial::Speed TinyBootloader::Config::readSpeed() +{ + uint speed = readUIntEntry("port_speed", 19200); + for (uint i=0; iopen() ) return false; + Config config; + if ( !port()->setMode(Port::Serial::IgnoreBreak | Port::Serial::IgnoreParity, + Port::Serial::ByteSize8 | Port::Serial::IgnoreControlLines, + config.readSpeed(), _timeout) ) + return false; + return true; +} + +bool TinyBootloader::Hardware::internalConnectHardware() +{ + if ( !openPort() ) return false; + // #### possibly do hard (RTS) or soft reset (codes) + uchar uc = 0xC1; + if ( !port()->sendChar(uc, _timeout) ) return false; + if ( !port()->receiveChar((char &)_id, _timeout) ) return false; + if ( !waitReady(0) ) return false; + return true; +} + +bool TinyBootloader::Hardware::verifyDeviceId() +{ + uchar id = data(device().name()).id; + QValueVector list = _base.group().supportedDevices(); + QStringList devices; + for (uint i=0; ireceiveChar(c, _timeout) ) return false; + if ( c=='K' ) { + if (checkCRC) *checkCRC = true; + return true; + } + if (checkCRC) { + *checkCRC = false; + if ( c=='N' ) return true; + log(Log::LineType::Error, i18n("Received unexpected character ('%1' received; 'K' or 'N' expected).").arg(toPrintable(c, PrintAlphaNum))); + return true; + } + log(Log::LineType::Error, i18n("Received unexpected character ('%1' received; 'K' expected).").arg(toPrintable(c, PrintAlphaNum))); + return false; +} + +bool TinyBootloader::Hardware::sendChar(char c, uchar *crc) +{ + if (crc) *crc += c; + return port()->sendChar(c, 10*_timeout); +} + +bool TinyBootloader::Hardware::sendCodeAddress(uint address, uchar &crc) +{ + switch (device().architecture().type()) { + case Pic::Architecture::P16X: + if ( !sendChar(address >> 8, &crc) ) return false; // address high + if ( !sendChar(address & 0xFF, &crc) ) return false; // address low + break; + case Pic::Architecture::P18F: + if ( !sendChar(address >> 16, &crc) ) return false; // address upper + if ( !sendChar((address >> 8) & 0xFF, &crc) ) return false; // address high + if ( !sendChar(address & 0xFF, &crc) ) return false; // address low + break; + case Pic::Architecture::P30F: + if ( !sendChar(address & 0xFF, &crc) ) return false; // address low + if ( !sendChar((address >> 8) & 0xFF, &crc) ) return false; // address high + if ( !sendChar(address >> 16, &crc) ) return false; // address upper + break; + default: Q_ASSERT(false); return false; + } + return true; +} + +bool TinyBootloader::Hardware::endWrite(uchar crc, uint &retries, bool &ok) +{ + if ( !sendChar(-crc & 0xFF, 0) ) return false; + if ( !waitReady(&ok) ) return false; + if ( !ok ) { + if ( retries==0 ) { + log(Log::LineType::Error, i18n("Too many failures: bailing out.")); + return false; + } + retries--; + log(Log::LineType::Warning, i18n("CRC error from bootloader: retrying...")); + } + return true; +} + +bool TinyBootloader::Hardware::writeCode(const Device::Array &data, bool erase) +{ + uint nb = data.count() - 100; + Device::Array wdata(nb+4); + + // check that there is nothing on top of bootloader + for (uint i=nb; i(hardware()).writeCode(memory.arrayForWriting(type), true); + return hardware().write(type, memory.arrayForWriting(type)); +} diff --git a/src/progs/tbl_bootloader/base/tbl_bootloader.h b/src/progs/tbl_bootloader/base/tbl_bootloader.h new file mode 100644 index 0000000..b6e759f --- /dev/null +++ b/src/progs/tbl_bootloader/base/tbl_bootloader.h @@ -0,0 +1,74 @@ +/*************************************************************************** + * Copyright (C) 2007 Nicolas Hadacek * + * * + * 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 TBL_BOOTLOADER_H +#define TBL_BOOTLOADER_H + +#include "progs/bootloader/base/bootloader.h" +#include "progs/bootloader/base/bootloader_prog.h" +#include "common/port/serial.h" +#include "common/global/generic_config.h" + +namespace TinyBootloader +{ +//----------------------------------------------------------------------------- +class Config : public GenericConfig +{ +public: + Config() : GenericConfig("tiny_bootloader") {} + Port::Serial::Speed readSpeed(); + void writeSpeed(Port::Serial::Speed speed); + uint readTimeout(); // ms + void writeTimeout(uint timeout); // ms + uint readRetries(); + void writeRetries(uint nb); +}; + +//----------------------------------------------------------------------------- +class Hardware : public ::Bootloader::Hardware +{ +public: + Hardware(::Programmer::Base &base, const QString &portDevice); + Port::Serial *port() { return static_cast(_port); } + bool verifyDeviceId(); + virtual bool write(Pic::MemoryRangeType type, const Device::Array &data); + virtual bool read(Pic::MemoryRangeType, Device::Array &, const ::Programmer::VerifyData *) { return false; } + bool writeCode(const Device::Array &data, bool erase); + bool writeConfig(const Device::Array &data); + bool writeEeprom(const Device::Array &data); + virtual bool internalConnectHardware(); + virtual bool openPort(); + +private: + uchar _id; + uint _timeout; // ms + uint _retries; + + bool waitReady(bool *checkCRC); + bool sendChar(char c, uchar *crc); + bool sendCodeAddress(uint address, uchar &crc); + bool endWrite(uchar crc, uint &retries, bool &ok); +}; + +//----------------------------------------------------------------------------- +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 canWriteRange(type); } + virtual bool emulatedErase() const { return true; } + virtual bool canReadRange(Pic::MemoryRangeType) const { return false; } + virtual bool canWriteRange(Pic::MemoryRangeType type) const; + virtual bool doEraseRange(Pic::MemoryRangeType type); + virtual bool doErase(bool); +}; + +} // namespace + +#endif diff --git a/src/progs/tbl_bootloader/base/tbl_bootloader.xml b/src/progs/tbl_bootloader/base/tbl_bootloader.xml new file mode 100644 index 0000000..bbad6dd --- /dev/null +++ b/src/progs/tbl_bootloader/base/tbl_bootloader.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/progs/tbl_bootloader/base/tbl_bootloader_data.h b/src/progs/tbl_bootloader/base/tbl_bootloader_data.h new file mode 100644 index 0000000..51be528 --- /dev/null +++ b/src/progs/tbl_bootloader/base/tbl_bootloader_data.h @@ -0,0 +1,21 @@ +/*************************************************************************** + * Copyright (C) 2007 Nicolas Hadacek * + * * + * 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 TBL_BOOTLOADER_DATA_H +#define TBL_BOOTLOADER_DATA_H + +namespace TinyBootloader +{ + struct Data { + uchar id; + }; + extern bool isSupported(const QString &device); + extern const Data &data(const QString &device); +} // namespace + +#endif diff --git a/src/progs/tbl_bootloader/base/tbl_bootloader_prog.cpp b/src/progs/tbl_bootloader/base/tbl_bootloader_prog.cpp new file mode 100644 index 0000000..22c831e --- /dev/null +++ b/src/progs/tbl_bootloader/base/tbl_bootloader_prog.cpp @@ -0,0 +1,14 @@ +/*************************************************************************** + * Copyright (C) 2007 Nicolas Hadacek * + * * + * 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 "tbl_bootloader_prog.h" + +//----------------------------------------------------------------------------- +TinyBootloader::ProgrammerBase::ProgrammerBase(const Programmer::Group &group, const Pic::Data *data) + : Bootloader::ProgrammerBase(group, data, "tiny_bootloader_programmer_base") +{} diff --git a/src/progs/tbl_bootloader/base/tbl_bootloader_prog.h b/src/progs/tbl_bootloader/base/tbl_bootloader_prog.h new file mode 100644 index 0000000..75b986d --- /dev/null +++ b/src/progs/tbl_bootloader/base/tbl_bootloader_prog.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2007 Nicolas Hadacek * + * * + * 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 TBL_BOOTLOADER_PROG_H +#define TBL_BOOTLOADER_PROG_H + +#include "tbl_bootloader.h" + +namespace TinyBootloader +{ + +//----------------------------------------------------------------------------- +class ProgrammerBase : public ::Bootloader::ProgrammerBase +{ +Q_OBJECT +public: + ProgrammerBase(const Programmer::Group &group, const Pic::Data *data); + virtual bool verifyDeviceId() { return static_cast(hardware()).verifyDeviceId(); } +}; + +//----------------------------------------------------------------------------- +class Group : public ::Bootloader::Group +{ +public: + virtual QString name() const { return "tbl_bootloader"; } + virtual QString label() const { return i18n("Tiny Bootloader"); } + virtual ::Programmer::Properties properties() const { return ::Programmer::Programmer; } + virtual ::Programmer::TargetPowerMode targetPowerMode() const { return ::Programmer::TargetSelfPowered; } + virtual bool isPortSupported(PortType type) const { return type==PortType::Serial; } + 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(data)); } + virtual ::Programmer::Hardware *createHardware(::Programmer::Base &base, const ::Programmer::HardwareDescription &hd) const { return new Hardware(base, hd.port.device); } + virtual ::Programmer::DeviceSpecific *createDeviceSpecific(::Programmer::Base &base) const { return new DeviceSpecific(base); } +}; + +} // namespace + +#endif -- cgit v1.2.3