File: e24xx-5.cpp

package info (click to toggle)
ponyprog 3.1.4%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,904 kB
  • sloc: cpp: 35,932; python: 981; sh: 565; xml: 67; makefile: 45; ansic: 38
file content (99 lines) | stat: -rw-r--r-- 3,540 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//=========================================================================//
//                                                                         //
//  PonyProg - Serial Device Programmer                                    //
//                                                                         //
//  Copyright (C) 1997-2025   Claudio Lanconelli                           //
//                                                                         //
//  https://github.com/lancos/ponyprog                                        //
//                                                                         //
//-------------------------------------------------------------------------//
//                                                                         //
// 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         //
// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
//                                                                         //
//=========================================================================//

#include <QString>

#include "types.h"
#include "e2awinfo.h"
#include "e24xx-5.h"            // Header file
#include "errcode.h"
#include "eeptypes.h"


E24xx5::E24xx5(e2AppWinInfo *wininfo, BusIO *busp)
	:       E24xx(wininfo, busp, 128)
{
	//      writepage_size = E2Profile::GetI2CPageWrite();
	//      E2Profile::SetI2CPageWrite(writepage_size);
	writepage_size = 32;

	base_addr = 0x00;               // 24C325 or 24C645 use non standard I2C Bus address, Probe() will try ALL possible I2C Adresses from 0x00 to 0xFE
}


E24xx5::~E24xx5()
{
}

int E24xx5::Write(int probe, int type)
{
	E24xx5::Probe(0);

	if (type & PROG_TYPE)
	{
		//Enable writing
		uint8_t buffer[4];

		buffer[0] = 0xFF;       //last address (Write protect register)
		buffer[1] = 0x02;       //set WEL bit

		if (GetBus()->StartWrite(eeprom_addr[n_bank - 1], buffer, 2) != 2)
		{
			return GetBus()->Error();
		}

		buffer[0] = 0xFF;       //last address (Write protect register)
		buffer[1] = 0x06;       //set RWEL+WEL bit

		if (GetBus()->StartWrite(eeprom_addr[n_bank - 1], buffer, 2) != 2)
		{
			return GetBus()->Error();
		}

		buffer[0] = 0xFF;       //last address (Write protect register)
		buffer[1] = 0x02;       //reset WPEN, BP1, BP0 (disable any write protection)

		if (GetBus()->Write(eeprom_addr[n_bank - 1], buffer, 2) != 2)
		{
			return GetBus()->Error();
		}

		//Ack polling
		int k;

		for (k = timeout_loop; k > 0 && GetBus()->Read(eeprom_addr[0], buffer, 1) != 1; k--)
		{
			qApp->processEvents();
		}

		if (k == 0)
		{
			return E2P_TIMEOUT;
		}
	}

	return E24xx::Write(probe);
}