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
// //
2007-04-20 10:58:20 +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 //
2017-10-08 22:28:35 +02:00
// 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
2019-03-18 18:27:36 +01:00
class BusIO
2000-02-05 22:37:44 +00:00
{
2018-10-16 18:42:23 +02: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
{
2019-03-27 17:23:24 +01: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
{
2019-03-27 17:23:24 +01: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
{
2017-04-21 01:43:13 +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
{
2017-04-21 01:43:13 +02:00
( void ) type ;
2017-04-18 01:25:22 +02:00
return NOTSUPPORTED ;
}
2000-02-05 22:37:44 +00:00
2017-05-02 17:54:17 +02: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
{
2017-04-21 01:43:13 +02:00
( void ) addr ;
2017-04-18 01:25:22 +02:00
return OK ;
}
2009-11-16 23:40:43 +00:00
virtual int WriteLockBits ( uint32_t val , long model = 0 )
2017-04-18 01:25:22 +02:00
{
2017-04-21 01:43:13 +02:00
( void ) val ;
( void ) model ;
2017-04-18 01:25:22 +02:00
return OK ;
}
2009-11-16 23:40:43 +00:00
virtual int WriteFuseBits ( uint32_t val , long model = 0 )
2017-04-18 01:25:22 +02:00
{
2017-04-21 01:43:13 +02:00
( void ) val ;
( void ) model ;
2017-04-18 01:25:22 +02:00
return OK ;
}
2009-11-16 23:40:43 +00:00
virtual uint32_t ReadLockBits ( long model = 0 )
2017-04-18 01:25:22 +02:00
{
2017-04-21 01:43:13 +02:00
( void ) model ;
2017-04-18 01:25:22 +02:00
return 0 ;
}
2009-11-16 23:40:43 +00:00
virtual uint32_t ReadFuseBits ( long model = 0 )
2017-04-18 01:25:22 +02:00
{
2017-04-21 01:43:13 +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
{
2017-04-21 01:43:13 +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
2009-11-16 23:40:43 +00:00
virtual int CompareMultiWord ( uint8_t * data1 , uint8_t * data2 , long length , int split )
2017-04-18 01:25:22 +02:00
{
2017-04-21 01:43:13 +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 )
2019-04-10 20:53:08 +02:00
{
2017-04-18 01:25:22 +02:00
busI = ptr ;
2019-04-10 20:53:08 +02:00
}
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
{
2019-03-27 17:23:24 +01:00
Q_CHECK_PTR ( busI ) ;
2019-03-23 01:26:31 +01:00
return busI - > GetDelay ( ) ;
2017-04-18 01:25:22 +02:00
}
2000-02-05 22:37:44 +00:00
2008-02-04 17:18:20 +00:00
long GetLastProgrammedAddress ( ) const
2017-04-18 01:25:22 +02:00
{
return last_programmed_addr ;
}
2008-02-04 17:18:20 +00:00
void ClearLastProgrammedAddress ( )
2017-04-18 01:25:22 +02:00
{
last_programmed_addr = 0 ;
}
2008-02-04 17:18:20 +00:00
void SetLastProgrammedAddress ( long addr )
{
if ( addr > last_programmed_addr )
2017-04-18 01:25:22 +02:00
{
2008-02-04 17:18:20 +00:00
last_programmed_addr = addr ;
2017-04-18 01:25:22 +02:00
}
2008-02-04 17:18:20 +00:00
}
2019-03-18 18:27:36 +01:00
void WaitMsec ( unsigned int msec )
{
2019-03-27 17:23:24 +01:00
Q_CHECK_PTR ( busI ) ;
2019-03-18 18:27:36 +01:00
busI - > WaitMsec ( msec ) ;
}
2018-10-16 18:42:23 +02:00
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 ;
2019-03-18 18:27:36 +01:00
void WaitUsec ( unsigned int usec )
{
2019-03-27 17:23:24 +01:00
Q_CHECK_PTR ( busI ) ;
2019-03-18 18:27:36 +01:00
busI - > WaitUsec ( usec ) ;
}
2019-03-23 01:26:31 +01:00
void ShotDelay ( int n = 1 )
{
2019-03-27 17:23:24 +01:00
Q_CHECK_PTR ( busI ) ;
2019-03-23 01:26:31 +01:00
busI - > ShotDelay ( n ) ;
}
2018-10-16 18:42:23 +02:00
private :
2000-02-05 22:37:44 +00:00
2017-05-02 17:54:17 +02: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
2008-02-04 17:18:20 +00:00
2000-02-05 22:37:44 +00:00
} ;
# endif