2012-05-26 05:38:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011-2012 Doug Brown
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-05-13 07:33:24 +00:00
|
|
|
#ifndef PROGRAMMER_H
|
|
|
|
#define PROGRAMMER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QFile>
|
2012-05-20 18:14:36 +00:00
|
|
|
#include <QIODevice>
|
2012-05-13 07:33:24 +00:00
|
|
|
#include <qextserialport.h>
|
2012-05-13 22:16:53 +00:00
|
|
|
#include <qextserialenumerator.h>
|
2012-05-20 00:29:20 +00:00
|
|
|
#include <stdint.h>
|
2012-09-30 19:15:11 +00:00
|
|
|
#include <QBuffer>
|
2012-05-13 07:33:24 +00:00
|
|
|
|
2012-05-13 16:42:16 +00:00
|
|
|
typedef enum StartStatus
|
|
|
|
{
|
|
|
|
ProgrammerInitializing,
|
|
|
|
ProgrammerInitialized
|
|
|
|
} StartStatus;
|
|
|
|
|
2012-05-13 07:33:24 +00:00
|
|
|
typedef enum ReadStatus
|
|
|
|
{
|
2012-05-13 16:42:16 +00:00
|
|
|
ReadStarting,
|
2012-05-13 07:33:24 +00:00
|
|
|
ReadComplete,
|
|
|
|
ReadError,
|
|
|
|
ReadCancelled,
|
|
|
|
ReadTimedOut
|
|
|
|
} ReadStatus;
|
|
|
|
|
|
|
|
typedef enum WriteStatus
|
|
|
|
{
|
2012-05-13 16:42:16 +00:00
|
|
|
WriteErasing,
|
2012-09-30 19:15:11 +00:00
|
|
|
WriteCompleteNoVerify,
|
2012-05-13 07:33:24 +00:00
|
|
|
WriteError,
|
|
|
|
WriteCancelled,
|
|
|
|
WriteEraseComplete,
|
|
|
|
WriteEraseFailed,
|
2012-05-20 05:56:30 +00:00
|
|
|
WriteTimedOut,
|
2012-09-02 23:06:44 +00:00
|
|
|
WriteFileTooBig,
|
2012-09-30 19:15:11 +00:00
|
|
|
WriteNeedsFirmwareUpdateBiggerSIMM,
|
|
|
|
WriteNeedsFirmwareUpdateVerifyWhileWrite,
|
|
|
|
WriteVerifying,
|
|
|
|
WriteVerificationFailure,
|
|
|
|
WriteVerifyStarting,
|
|
|
|
WriteVerifyError,
|
|
|
|
WriteVerifyCancelled,
|
|
|
|
WriteVerifyTimedOut,
|
2012-10-17 04:35:43 +00:00
|
|
|
WriteCompleteVerifyOK,
|
|
|
|
WriteEraseBlockWrongSize,
|
2013-07-05 01:34:27 +00:00
|
|
|
WriteNeedsFirmwareUpdateErasePortion,
|
|
|
|
WriteNeedsFirmwareUpdateIndividualChips
|
2012-05-13 07:33:24 +00:00
|
|
|
} WriteStatus;
|
|
|
|
|
|
|
|
typedef enum ElectricalTestStatus
|
|
|
|
{
|
|
|
|
ElectricalTestStarted,
|
|
|
|
ElectricalTestPassed,
|
|
|
|
ElectricalTestFailed,
|
|
|
|
ElectricalTestTimedOut,
|
|
|
|
ElectricalTestCouldntStart
|
|
|
|
} ElectricalTestStatus;
|
|
|
|
|
|
|
|
typedef enum IdentificationStatus
|
|
|
|
{
|
2012-05-13 16:42:16 +00:00
|
|
|
IdentificationStarting,
|
2012-05-13 07:33:24 +00:00
|
|
|
IdentificationComplete,
|
|
|
|
IdentificationError,
|
2012-09-02 23:06:44 +00:00
|
|
|
IdentificationTimedOut,
|
|
|
|
IdentificationNeedsFirmwareUpdate
|
2012-05-13 07:33:24 +00:00
|
|
|
} IdentificationStatus;
|
|
|
|
|
|
|
|
typedef enum FirmwareFlashStatus
|
|
|
|
{
|
2012-05-13 16:42:16 +00:00
|
|
|
FirmwareFlashStarting,
|
2012-05-13 07:33:24 +00:00
|
|
|
FirmwareFlashComplete,
|
|
|
|
FirmwareFlashError,
|
|
|
|
FirmwareFlashCancelled,
|
|
|
|
FirmwareFlashTimedOut
|
|
|
|
} FirmwareFlashStatus;
|
|
|
|
|
2012-09-30 19:15:11 +00:00
|
|
|
// Various choices for verification
|
|
|
|
typedef enum VerificationOption
|
|
|
|
{
|
|
|
|
NoVerification,
|
|
|
|
VerifyWhileWriting,
|
|
|
|
VerifyAfterWrite
|
|
|
|
} VerificationOption;
|
|
|
|
|
2012-05-13 07:33:24 +00:00
|
|
|
// Electrical test indexes
|
|
|
|
#define GROUND_FAIL_INDEX 0xFF
|
|
|
|
|
|
|
|
#define FIRST_ADDRESS_LINE_FAIL_INDEX 0
|
|
|
|
#define LAST_ADDRESS_LINE_FAIL_INDEX (FIRST_ADDRESS_LINE_FAIL_INDEX + 20)
|
|
|
|
#define FIRST_DATA_LINE_FAIL_INDEX (LAST_ADDRESS_LINE_FAIL_INDEX + 1)
|
|
|
|
#define LAST_DATA_LINE_FAIL_INDEX (FIRST_DATA_LINE_FAIL_INDEX + 31)
|
|
|
|
#define CS_FAIL_INDEX (LAST_DATA_LINE_FAIL_INDEX + 1)
|
|
|
|
#define OE_FAIL_INDEX (CS_FAIL_INDEX + 1)
|
|
|
|
#define WE_FAIL_INDEX (OE_FAIL_INDEX + 1)
|
|
|
|
|
|
|
|
class Programmer : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit Programmer(QObject *parent = 0);
|
|
|
|
virtual ~Programmer();
|
2012-09-15 22:16:43 +00:00
|
|
|
void readSIMM(QIODevice *device, uint32_t len = 0);
|
2013-07-05 01:34:27 +00:00
|
|
|
void writeToSIMM(QIODevice *device, uint8_t chipsMask = 0x0F);
|
|
|
|
void writeToSIMM(QIODevice *device, uint32_t startOffset, uint32_t length, uint8_t chipsMask = 0x0F);
|
2012-05-13 22:16:53 +00:00
|
|
|
void runElectricalTest();
|
2012-05-13 07:33:24 +00:00
|
|
|
QString electricalTestPinName(uint8_t index);
|
2012-05-13 22:16:53 +00:00
|
|
|
void identifySIMMChips();
|
|
|
|
void getChipIdentity(int chipIndex, uint8_t *manufacturer, uint8_t *device);
|
|
|
|
void flashFirmware(QString filename);
|
|
|
|
void startCheckingPorts();
|
2012-05-14 03:30:21 +00:00
|
|
|
void setSIMMCapacity(uint32_t bytes);
|
2012-09-30 19:15:11 +00:00
|
|
|
uint32_t SIMMCapacity() const;
|
|
|
|
void setVerifyMode(VerificationOption mode);
|
|
|
|
VerificationOption verifyMode() const;
|
|
|
|
uint8_t verifyBadChipMask() const { return _verifyBadChipMask; }
|
2012-05-13 07:33:24 +00:00
|
|
|
signals:
|
2012-05-13 16:42:16 +00:00
|
|
|
void startStatusChanged(StartStatus status);
|
|
|
|
|
2012-05-13 07:33:24 +00:00
|
|
|
void readStatusChanged(ReadStatus status);
|
|
|
|
void readTotalLengthChanged(uint32_t total);
|
|
|
|
void readCompletionLengthChanged(uint32_t total);
|
|
|
|
|
|
|
|
void writeStatusChanged(WriteStatus status);
|
|
|
|
void writeTotalLengthChanged(uint32_t total);
|
|
|
|
void writeCompletionLengthChanged(uint32_t len);
|
2012-09-30 19:15:11 +00:00
|
|
|
void writeVerifyTotalLengthChanged(uint32_t total);
|
|
|
|
void writeVerifyCompletionLengthChanged(uint32_t total);
|
2012-05-13 07:33:24 +00:00
|
|
|
|
|
|
|
void electricalTestStatusChanged(ElectricalTestStatus status);
|
|
|
|
void electricalTestFailLocation(uint8_t loc1, uint8_t loc2);
|
|
|
|
|
|
|
|
void identificationStatusChanged(IdentificationStatus status);
|
|
|
|
|
|
|
|
void firmwareFlashStatusChanged(FirmwareFlashStatus status);
|
|
|
|
void firmwareFlashTotalLengthChanged(uint32_t total);
|
|
|
|
void firmwareFlashCompletionLengthChanged(uint32_t total);
|
2012-05-13 22:16:53 +00:00
|
|
|
|
|
|
|
void programmerBoardConnected();
|
|
|
|
void programmerBoardDisconnected();
|
|
|
|
void programmerBoardDisconnectedDuringOperation();
|
2012-05-13 07:33:24 +00:00
|
|
|
public slots:
|
|
|
|
|
|
|
|
private:
|
2012-05-20 18:14:36 +00:00
|
|
|
//QFile *readFile;
|
|
|
|
//QFile *writeFile;
|
|
|
|
QIODevice *readDevice;
|
|
|
|
QIODevice *writeDevice;
|
2012-05-13 07:33:24 +00:00
|
|
|
QFile *firmwareFile;
|
|
|
|
|
|
|
|
QextSerialPort *serialPort;
|
|
|
|
void sendByte(uint8_t b);
|
2012-10-17 04:35:43 +00:00
|
|
|
void sendWord(uint32_t w);
|
2012-05-13 07:33:24 +00:00
|
|
|
uint8_t readByte();
|
|
|
|
void handleChar(uint8_t c);
|
2012-05-14 03:30:21 +00:00
|
|
|
uint32_t _simmCapacity;
|
2012-05-13 07:33:24 +00:00
|
|
|
|
|
|
|
uint32_t writeLenRemaining;
|
|
|
|
uint32_t lenWritten;
|
|
|
|
uint32_t electricalTestErrorCounter;
|
|
|
|
uint8_t electricalTestFirstErrorLoc;
|
|
|
|
|
|
|
|
uint32_t readChunkLenRemaining;
|
|
|
|
uint32_t lenRead;
|
2012-09-15 22:16:43 +00:00
|
|
|
uint32_t trueLenToRead;
|
2012-05-20 05:56:30 +00:00
|
|
|
uint32_t lenRemaining;
|
2012-10-18 04:30:40 +00:00
|
|
|
uint32_t readOffset;
|
2012-05-13 07:33:24 +00:00
|
|
|
|
|
|
|
int identificationCounter;
|
|
|
|
uint8_t chipManufacturerIDs[4];
|
|
|
|
uint8_t chipDeviceIDs[4];
|
|
|
|
|
|
|
|
uint32_t firmwareLenRemaining;
|
|
|
|
uint32_t firmwareLenWritten;
|
|
|
|
|
2012-09-30 19:15:11 +00:00
|
|
|
VerificationOption _verifyMode;
|
|
|
|
uint8_t _verifyBadChipMask;
|
|
|
|
bool isReadVerifying;
|
|
|
|
QBuffer *verifyBuffer;
|
|
|
|
QByteArray *verifyArray;
|
2012-10-18 04:30:40 +00:00
|
|
|
uint32_t verifyLength;
|
2012-09-30 19:15:11 +00:00
|
|
|
|
2012-10-17 04:35:43 +00:00
|
|
|
uint32_t writeOffset;
|
|
|
|
uint32_t writeLength;
|
2013-07-05 01:34:27 +00:00
|
|
|
uint8_t writeChipMask;
|
2012-10-17 04:35:43 +00:00
|
|
|
|
2012-05-13 22:16:53 +00:00
|
|
|
void openPort();
|
|
|
|
void closePort();
|
|
|
|
|
2012-10-18 04:30:40 +00:00
|
|
|
void internalReadSIMM(QIODevice *device, uint32_t len, uint32_t offset = 0);
|
2012-05-13 07:33:24 +00:00
|
|
|
void startProgrammerCommand(uint8_t commandByte, uint32_t newState);
|
|
|
|
void startBootloaderCommand(uint8_t commandByte, uint32_t newState);
|
2012-09-30 19:15:11 +00:00
|
|
|
void doVerifyAfterWriteCompare();
|
2012-05-13 07:33:24 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void dataReady();
|
2012-05-13 22:16:53 +00:00
|
|
|
|
|
|
|
void portDiscovered(const QextPortInfo &info);
|
2012-05-19 02:39:24 +00:00
|
|
|
void portDiscovered_internal();
|
2012-05-13 22:16:53 +00:00
|
|
|
void portRemoved(const QextPortInfo &info);
|
2012-05-13 07:33:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PROGRAMMER_H
|