2004-11-30 17:46:48 +00:00
//=========================================================================//
// //
// PonyProg - Serial Device Programmer //
// //
2020-02-05 17:23:29 +01:00
// Copyright (C) 1997-2020 Claudio Lanconelli //
2004-11-30 17:46:48 +00:00
// //
2007-04-20 10:58:20 +00:00
// http://ponyprog.sourceforge.net //
2004-11-30 17:46:48 +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 //
2004-11-30 17:46:48 +00:00
// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
// //
//=========================================================================//
2017-04-18 01:25:22 +02:00
# ifndef _PIC12BUS_H
# define _PIC12BUS_H
2004-11-30 17:46:48 +00:00
# include "types.h"
# include "busio.h"
# include "pgminter.h"
class Pic12Bus : public BusIO
{
2018-10-16 18:42:23 +02:00
public :
2004-11-30 17:46:48 +00:00
Pic12Bus ( BusInterface * ptr = 0 ) ;
virtual ~ Pic12Bus ( ) ;
2009-11-16 22:29:18 +00:00
long Read ( int addr , uint8_t * data , long length , int page_size = 0 ) ;
long Write ( int addr , uint8_t const * data , long length , int page_size = 0 ) ;
2004-11-30 17:46:48 +00:00
2017-04-18 01:25:22 +02:00
// int Erase(int type = ALL_TYPE);
2004-11-30 17:46:48 +00:00
int Reset ( ) ;
2009-11-16 23:40:43 +00:00
long ReadConfig ( uint16_t & data ) ;
long WriteConfig ( uint16_t data ) ;
2004-11-30 17:46:48 +00:00
void DisableCodeProtect ( ) ;
2009-11-16 23:40:43 +00:00
int CompareSingleWord ( uint16_t data1 , uint16_t data2 , uint16_t mask ) ;
int CompareMultiWord ( uint8_t * data1 , uint8_t * data2 , long length , int split ) ;
2004-11-30 17:46:48 +00:00
void SetDelay ( ) ;
long BlankCheck ( long length ) ;
void IncAddress ( int n ) ;
2018-10-16 18:42:23 +02:00
protected :
2004-11-30 17:46:48 +00:00
int SendDataWord ( long wo , int wlen = 16 ) ;
long RecDataWord ( int wlen = 16 ) ;
int WaitReadyAfterWrite ( long timeout = 5000 ) ;
2009-11-16 23:40:43 +00:00
int WriteProgWord ( uint16_t val , long rc_addr ) ;
2017-04-18 01:25:22 +02:00
int ProgramPulse ( uint16_t val , int verify = 0 , int width = 100 ) ; //100uSec default pulse width
2004-11-30 17:46:48 +00:00
int SendCmdCode ( int opcode )
2017-04-18 01:25:22 +02:00
{
return SendDataWord ( opcode , 6 ) ;
}
2009-11-16 23:40:43 +00:00
int SendProgCode ( uint16_t data )
2004-11-30 17:46:48 +00:00
{
//the code is 14 bit data with leading and trailing 0's
data & = ProgMask ;
data < < = 1 ;
return SendDataWord ( data ) ;
}
2009-11-16 23:40:43 +00:00
uint16_t RecvProgCode ( )
2004-11-30 17:46:48 +00:00
{
2009-11-16 23:40:43 +00:00
return ( uint16_t ) ( RecDataWord ( ) > > 1 ) & ProgMask ;
2004-11-30 17:46:48 +00:00
}
2017-04-18 01:25:22 +02:00
/**
2009-11-16 23:40:43 +00:00
int SendDataCode ( uint16_t data )
2004-11-30 17:46:48 +00:00
{
2017-04-18 01:25:22 +02:00
//the code is 8 bit data with leading and trailing 0's
data & = DataMask ;
data < < = 1 ;
return SendDataWord ( data ) ;
2004-11-30 17:46:48 +00:00
}
2009-11-16 23:40:43 +00:00
uint16_t RecvDataCode ( )
2004-11-30 17:46:48 +00:00
{
2017-04-18 01:25:22 +02:00
return ( uint16_t ) ( RecDataWord ( ) > > 1 ) & DataMask ;
2004-11-30 17:46:48 +00:00
}
2017-04-18 01:25:22 +02:00
* */
2004-11-30 17:46:48 +00:00
void SetMCLR ( )
2017-04-18 01:25:22 +02:00
{
busI - > SetControlLine ( 1 ) ;
}
2004-11-30 17:46:48 +00:00
void ClearMCLR ( )
2017-04-18 01:25:22 +02:00
{
busI - > SetControlLine ( 0 ) ;
}
2004-11-30 17:46:48 +00:00
long current_address ;
int OverProgrammingMult ;
int OverProgrammingAdd ;
2017-04-18 01:25:22 +02:00
// const uint16_t DataMask;
2009-11-16 23:40:43 +00:00
const uint16_t ProgMask ;
2004-11-30 17:46:48 +00:00
//Command Opcode
2009-11-16 22:29:18 +00:00
const uint8_t ReadProgCode ;
const uint8_t LoadProgCode ;
2017-04-18 01:25:22 +02:00
// const uint8_t ReadDataCode;
// const uint8_t LoadDataCode;
// const uint8_t LoadConfigCode;
2009-11-16 22:29:18 +00:00
const uint8_t IncAddressCode ;
2017-04-18 01:25:22 +02:00
// const uint8_t EraseProgMem;
// const uint8_t EraseDataMem;
2009-11-16 22:29:18 +00:00
const uint8_t BeginProgCode ;
2017-04-18 01:25:22 +02:00
// const uint8_t BeginProgOnlyCode;
2009-11-16 22:29:18 +00:00
const uint8_t EndProgCode ;
2004-11-30 17:46:48 +00:00
2018-10-16 18:42:23 +02:00
private :
2004-11-30 17:46:48 +00:00
int SendDataBit ( int b ) ;
int RecDataBit ( ) ;
void bitDI ( int b )
2017-04-18 01:25:22 +02:00
{
busI - > SetDataOut ( ! b ) ;
}
2004-11-30 17:46:48 +00:00
void setDI ( )
2017-04-18 01:25:22 +02:00
{
busI - > SetDataOut ( 0 ) ;
}
2004-11-30 17:46:48 +00:00
void clearDI ( )
2017-04-18 01:25:22 +02:00
{
busI - > SetDataOut ( 1 ) ;
}
2004-11-30 17:46:48 +00:00
void setCLK ( )
2017-04-18 01:25:22 +02:00
{
busI - > SetClock ( 1 ) ;
}
2004-11-30 17:46:48 +00:00
void clearCLK ( )
2017-04-18 01:25:22 +02:00
{
busI - > SetClock ( 0 ) ;
}
2004-11-30 17:46:48 +00:00
int getDO ( ) const
2017-04-18 01:25:22 +02:00
{
return busI - > GetDataIn ( ) ;
}
2004-11-30 17:46:48 +00:00
} ;
# endif