ponyprog/SrcPony/busio.h

220 lines
4.8 KiB
C
Raw Normal View History

2000-02-05 22:37:44 +00:00
//=========================================================================//
// //
// PonyProg - Serial Device Programmer //
// //
2019-02-08 00:29:55 +01:00
// Copyright (C) 1997-2019 Claudio Lanconelli //
2000-02-05 22:37:44 +00:00
// //
// http://ponyprog.sourceforge.net //
2000-02-05 22:37:44 +00:00
// //
//-------------------------------------------------------------------------//
// //
// 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 version2 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 (see LICENSE); if not, write to the //
2000-02-05 22:37:44 +00:00
// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
// //
//=========================================================================//
2017-04-18 01:25:22 +02:00
#ifndef _BUSIO_H
#define _BUSIO_H
2000-02-05 22:37:44 +00:00
#include "types.h"
#include "businter.h"
2017-04-18 01:25:22 +02:00
#include "errcode.h"
2000-02-05 22:37:44 +00:00
//Formato di bus generico seriale
class BusIO
2000-02-05 22:37:44 +00:00
{
public:
2000-02-05 22:37:44 +00:00
BusIO(BusInterface *p = 0);
2019-03-28 00:35:39 +01:00
//virtual ~BusIO() { }
2000-02-05 22:37:44 +00:00
virtual int Open(int port)
2017-04-18 01:25:22 +02:00
{
Q_CHECK_PTR(busI);
err_no = busI->Open(port);
return err_no;
2017-04-18 01:25:22 +02:00
}
2000-02-05 22:37:44 +00:00
virtual void Close()
2017-04-18 01:25:22 +02:00
{
Q_CHECK_PTR(busI);
2017-04-18 01:25:22 +02:00
busI->Close();
}
2000-02-05 22:37:44 +00:00
virtual int Error();
virtual int TestPort(int port)
2017-04-18 01:25:22 +02:00
{
(void)port;
2017-04-18 01:25:22 +02:00
return OK;
}
2000-02-05 22:37:44 +00:00
virtual int Reset() = 0;
2009-11-16 22:29:18 +00:00
virtual long Read(int addr, uint8_t *data, long length, int page_size = 0) = 0;
2017-04-18 01:25:22 +02:00
virtual long Write(int addr, uint8_t const *data, long length, int page_size = 0) = 0;
2004-11-30 17:46:48 +00:00
virtual int Erase(int type = 0)
2017-04-18 01:25:22 +02:00
{
(void)type;
2017-04-18 01:25:22 +02:00
return NOTSUPPORTED;
}
2000-02-05 22:37:44 +00:00
void ReadStart()
{
CheckAbort(0);
}
void ReadEnd()
{
CheckAbort(100);
}
int ReadProgress(int progress)
{
return CheckAbort(progress);
}
void WriteStart()
{
CheckAbort(0);
}
void WriteEnd()
{
CheckAbort(100);
}
int WriteProgress(int progress)
{
return CheckAbort(progress);
}
void EraseStart()
{
CheckAbort(0);
}
void EraseEnd()
{
CheckAbort(100);
}
2004-11-30 17:46:48 +00:00
virtual int ReadDeviceCode(int addr)
2017-04-18 01:25:22 +02:00
{
(void)addr;
2017-04-18 01:25:22 +02:00
return OK;
}
virtual int WriteLockBits(uint32_t val, long model = 0)
2017-04-18 01:25:22 +02:00
{
(void)val;
(void)model;
2017-04-18 01:25:22 +02:00
return OK;
}
virtual int WriteFuseBits(uint32_t val, long model = 0)
2017-04-18 01:25:22 +02:00
{
(void)val;
(void)model;
2017-04-18 01:25:22 +02:00
return OK;
}
virtual uint32_t ReadLockBits(long model = 0)
2017-04-18 01:25:22 +02:00
{
(void)model;
2017-04-18 01:25:22 +02:00
return 0;
}
virtual uint32_t ReadFuseBits(long model = 0)
2017-04-18 01:25:22 +02:00
{
(void)model;
2017-04-18 01:25:22 +02:00
return 0;
}
2004-11-30 17:46:48 +00:00
virtual long ReadCalibration(int addr = 0)
2017-04-18 01:25:22 +02:00
{
(void)addr;
2017-04-18 01:25:22 +02:00
return -1; //No calibration value available
}
2004-11-30 17:46:48 +00:00
virtual int CompareMultiWord(uint8_t *data1, uint8_t *data2, long length, int split)
2017-04-18 01:25:22 +02:00
{
(void)split;
2017-04-18 01:25:22 +02:00
return memcmp(data1, data2, length);
}
2000-02-29 11:01:48 +00:00
2000-02-05 22:37:44 +00:00
int GetErrNo()
2017-04-18 01:25:22 +02:00
{
return err_no;
}
int GetLastAddr() const //useful in I2C Bus transaction,
{
return last_addr; // tell the address where error occurs
}
2000-02-05 22:37:44 +00:00
void SetBusInterface(BusInterface *ptr)
2017-04-18 01:25:22 +02:00
{
if (ptr)
{
2017-04-18 01:25:22 +02:00
busI = ptr;
}
2017-04-18 01:25:22 +02:00
}
2000-02-05 22:37:44 +00:00
int GetDelay() const
2017-04-18 01:25:22 +02:00
{
Q_CHECK_PTR(busI);
return busI->GetDelay();
2017-04-18 01:25:22 +02:00
}
2000-02-05 22:37:44 +00:00
long GetLastProgrammedAddress() const
2017-04-18 01:25:22 +02:00
{
return last_programmed_addr;
}
void ClearLastProgrammedAddress()
2017-04-18 01:25:22 +02:00
{
last_programmed_addr = 0;
}
void SetLastProgrammedAddress(long addr)
{
if (addr > last_programmed_addr)
2017-04-18 01:25:22 +02:00
{
last_programmed_addr = addr;
2017-04-18 01:25:22 +02:00
}
}
void WaitMsec(unsigned int msec)
{
Q_CHECK_PTR(busI);
busI->WaitMsec(msec);
}
protected:
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
int err_no; //error code
int last_addr;
2000-02-05 22:37:44 +00:00
BusInterface *busI;
void WaitUsec(unsigned int usec)
{
Q_CHECK_PTR(busI);
busI->WaitUsec(usec);
}
void ShotDelay(int n = 1)
{
Q_CHECK_PTR(busI);
busI->ShotDelay(n);
}
private:
2000-02-05 22:37:44 +00:00
int CheckAbort(int progress = 0);
2000-02-05 22:37:44 +00:00
int old_progress;
2017-04-18 01:25:22 +02:00
long last_programmed_addr; //record last programmed address for verify
2000-02-05 22:37:44 +00:00
};
#endif