/**
* \file progEEPROM.c
* algorithms to program various EEPROM types
* Copyright (C) 2009-2022 Alberto Maccioni
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA
* or see
*/
#include "common.h"
void ReadI2C(int dim,int addr)
// read I2C memories
// dim=size in bytes
// addr:
// [3:0] =0: 1 byte address =1: 2 byte address
// [7:4] A2:A0 value
// [11:8] 17th address bit location (added to control byte)
{
int k=0,z=0,i,j;
int AX=(addr>>4)&7;
int addr17=(addr>>8)&0xF;
addr&=1;
if(dim>0x30000||dim<0){
PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n"
return;
}
if(saveLog){
OpenLogFile(); //"Log.txt"
fprintf(logfile,"ReadI2C(%d,%d) (0x%X,0x%X)\n",dim,addr,dim,addr);
}
sizeEE=dim;
if(memEE) free(memEE);
memEE=(unsigned char*)malloc(dim); //EEPROM
unsigned int start=GetTickCount();
hvreg=0;
j=0;
bufferU[j++]=VREG_DIS;
bufferU[j++]=I2C_INIT;
bufferU[j++]=AX; //100k
bufferU[j++]=EN_VPP_VCC; //VDD
bufferU[j++]=0x1;
bufferU[j++]=FLUSH;
for(;j0x10000-(DIMBUF-4)) inc=0x10000-i; //do not cross 64KB boundary
else inc=i>7)&0x0E);
bufferU[j++]=i&0xFF;
}
else{ //2 byte address
bufferU[j++]=I2C_READ2;
bufferU[j++]=inc;
bufferU[j++]=0xA0+(i>0xFFFF?addr17:0); //17th bit if>64K
bufferU[j++]=(i>>8)&0xFF;
bufferU[j++]=i&0xFF;
}
bufferU[j++]=FLUSH;
for(;j>4)&7;
int addr17=(addr>>8)&0xF;
addr&=1;
hvreg=0;
if(dim>0x30000||dim<0){
PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n"
return;
}
if(saveLog){
OpenLogFile(); //"Log.txt"
fprintf(logfile,"WriteI2C(%d,%d,%d) (0x%X,0x%X)\n",dim,addr,page,dim,addr);
}
if(dim>sizeEE){
i=sizeEE;
memEE=(unsigned char*)realloc(memEE,dim);
for(;i=DIMBUF-6;page>>=1);
for(i=0,j=0;i>7)&0x0E);
bufferU[j++]=i&0xFF;
}
else{ //2 byte address
bufferU[j++]=page+1;
bufferU[j++]=0xA0+(i>0xFFFF?addr17:0); //17th bit if>64K
bufferU[j++]=(i>>8)&0xFF;
bufferU[j++]=i&0xFF;
}
for(k=0;k=0xFA) i=dim+10;
PrintStatus(strings[S_CodeWriting2],i*100/(dim),i); //"Write: %d%%, addr. %04X"
if(RWstop) i=dim;
j=0;
if(saveLog){
fprintf(logfile,strings[S_Log7],i,i,k,k); //"i=%d(0x%X), k=%d(0x%X)\n"
}
bufferU[j++]=I2C_WRITE;
bufferU[j++]=0;
bufferU[j++]=0xA0; //ACK polling
bufferU[j++]=0;
bufferU[j++]=FLUSH;
for(;j=0xFA) ack=0xFD;
else ack=bufferI[j+1];
}
j=0;
}
PrintStatusEnd();
PrintMessage(strings[S_Compl]); //"completed\r\n"
//****************** verify EEPROM ********************
PrintMessage(strings[S_EEV]); //"Verify EEPROM ... "
PrintStatusSetup();
k=0;
int inc;
for(i=0,j=0;i0x10000-(DIMBUF-4)) inc=0x10000-i; //do not cross 64KB boundary
else inc=i>7)&0x0E);
bufferU[j++]=i&0xFF;
}
else{ //2 byte address
bufferU[j++]=I2C_READ2;
bufferU[j++]=inc;
bufferU[j++]=0xA0+(i>0xFFFF?addr17:0); //17th bit if>64K
bufferU[j++]=(i>>8)&0xFF;
bufferU[j++]=i&0xFF;
}
bufferU[j++]=FLUSH;
for(;j=max_err) break;
}
PrintStatusEnd();
if(k!=dim){
PrintMessage("\r\n");
PrintMessage2(strings[S_ReadEEErr],dim,k); //"Error reading EEPROM area, requested %d bytes, read %d\r\n"
}
PrintMessage1(strings[S_ComplErr],err); //"completed: %d errors\r\n"
//****************** exit ********************
bufferU[j++]=EN_VPP_VCC;
bufferU[j++]=0x0;
bufferU[j++]=FLUSH;
for(;j0x3000||dim<0){
PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n"
return;
}
if(na>13) na=13;
if(saveLog){
OpenLogFile(); //"Log.txt"
fprintf(logfile,"Read93x(%d,%d,%d) (0x%X,0x%X)\n",dim,na,options,dim,na);
}
x8=options&1;
sizeEE=dim;
if(memEE) free(memEE);
memEE=(unsigned char*)malloc(dim); //EEPROM
unsigned int start=GetTickCount();
j=0;
bufferU[j++]=VREG_DIS;
bufferU[j++]=uW_INIT;
bufferU[j++]=EN_VPP_VCC; //VDD
bufferU[j++]=0x1;
bufferU[j++]=EXT_PORT;
bufferU[j++]=x8?S:S+ORG;
bufferU[j++]=0;
bufferU[j++]=FLUSH;
for(;j>(na-5))&0x1F); //110aaaaa aaax0000
bufferU[j++]=(i<<(13-na))&0xFF;
bufferU[j++]=uWRX;
bufferU[j++]=x8?8:16;
bufferU[j++]=EXT_PORT;
bufferU[j++]=x8?0:ORG;
bufferU[j++]=0;
bufferU[j++]=EXT_PORT;
bufferU[j++]=x8?S:S+ORG;
bufferU[j++]=0;
i++;
}
bufferU[j++]=FLUSH;
for(;j0x1000||dim<0){
PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n"
return;
}
if(na>13) na=13;
if(page>48) page=48;
if(saveLog){
OpenLogFile(); //"Log.txt"
fprintf(logfile,"Write93Sx(%d,%d,%d) (0x%X,0x%X)\n",dim,na,page,dim,na);
}
if(dim>sizeEE){
i=sizeEE;
memEE=(unsigned char*)realloc(memEE,dim);
for(;i>na)*page/2){
bufferU[j++]=EXT_PORT;
bufferU[j++]=W; //make sure to start with S=0
bufferU[j++]=0;
bufferU[j++]=EXT_PORT;
bufferU[j++]=S+W;
bufferU[j++]=0;
bufferU[j++]=uWTX;
bufferU[j++]=3;
bufferU[j++]=0xE0; //111aaaaa aaa(a) D page write
bufferU[j++]=uWTX;
bufferU[j++]=na;
bufferU[j++]=addr>>8;
if(na>8) bufferU[j++]=addr&0xFF;
bufferU[j++]=uWTX;
bufferU[j++]=8*page;
for(k=0;k=0xFA) i=dim+10;
bufferU[j++]=uWRX;
bufferU[j++]=1;
bufferU[j++]=FLUSH;
for(;j30) n=30; //max 240 bit = 30 Byte
for(i=0,j=0;i=max_err) break;
}
PrintStatusEnd();
if(k!=dim){
PrintMessage("\r\n");
PrintMessage2(strings[S_ReadEEErr],dim,k); //"Error reading EEPROM area, requested %d bytes, read %d\r\n"
}
PrintMessage1(strings[S_ComplErr],err); //"completed: %d errors\r\n"
//****************** exit ********************
bufferU[j++]=EXT_PORT;
bufferU[j++]=0;
bufferU[j++]=0;
bufferU[j++]=EN_VPP_VCC;
bufferU[j++]=0x0;
bufferU[j++]=FLUSH;
for(;j0x1000||dim<0){
PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n"
return;
}
if(na>13) na=13;
if(saveLog){
OpenLogFile(); //"Log.txt"
fprintf(logfile,"Write93Cx(%d,%d,%d) (0x%X,0x%X)\n",dim,na,options,dim,na);
}
if(dim>sizeEE){
i=sizeEE;
memEE=(unsigned char*)realloc(memEE,dim);
for(;i>na){
if(memEE[i]<0xFF||(options==0&&memEE[i+1]<0xFF)){
bufferU[j++]=EXT_PORT;
bufferU[j++]=options==0?ORG+PRE:PRE;
bufferU[j++]=0;
bufferU[j++]=EXT_PORT;
bufferU[j++]=options==0?S+ORG+PRE:S+PRE;
bufferU[j++]=0;
bufferU[j++]=uWTX;
bufferU[j++]=3;
bufferU[j++]=0xA0; //101aaaaa aaa(a) write
bufferU[j++]=uWTX;
bufferU[j++]=na;
bufferU[j++]=addr>>8;
if(na>8) bufferU[j++]=addr&0xFF;
bufferU[j++]=uWTX;
if(options==0){ //x16
bufferU[j++]=16;
bufferU[j++]=memEE[i+1];
bufferU[j++]=memEE[i];
}
else{ //x8
bufferU[j++]=8;
bufferU[j++]=memEE[i];
}
bufferU[j++]=EXT_PORT;
bufferU[j++]=options==0?ORG+PRE:PRE;
bufferU[j++]=0;
bufferU[j++]=EXT_PORT;
bufferU[j++]=options==0?S+ORG+PRE:S+PRE;
bufferU[j++]=0;
bufferU[j++]=uWRX;
bufferU[j++]=1;
bufferU[j++]=FLUSH;
for(;j>(na-5))&0x1F); //110aaaaa aaax0000
bufferU[j++]=(i<<(13-na))&0xFF;
bufferU[j++]=uWRX;
bufferU[j++]=options==0?16:8;
bufferU[j++]=EXT_PORT;
bufferU[j++]=options==0?ORG:0;
bufferU[j++]=0;
bufferU[j++]=EXT_PORT;
bufferU[j++]=options==0?S+ORG:S;
bufferU[j++]=0;
i++;
}
bufferU[j++]=FLUSH;
for(;j=max_err) break;
}
PrintStatusEnd();
if(k!=dim){
PrintMessage("\r\n");
PrintMessage2(strings[S_ReadEEErr],dim,k); //"Error reading EEPROM area, requested %d bytes, read %d\r\n"
}
PrintMessage1(strings[S_ComplErr],err); //"completed: %d errors\r\n"
//****************** exit ********************
bufferU[j++]=EXT_PORT;
bufferU[j++]=0;
bufferU[j++]=0;
bufferU[j++]=EN_VPP_VCC;
bufferU[j++]=0x0;
bufferU[j++]=FLUSH;
for(;j0x1000000||dim<0){
PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n"
return;
}
if(saveLog){
OpenLogFile(); //"Log.txt"
fprintf(logfile,"Read25xx(%d) (0x%X)\n",dim,dim);
}
sizeEE=dim;
if(memEE) free(memEE);
memEE=(unsigned char*)malloc(dim); //EEPROM
unsigned int start=GetTickCount();
j=0;
bufferU[j++]=VREG_DIS;
bufferU[j++]=SPI_INIT;
bufferU[j++]=3; //0=100k, 1=200k, 2=300k, 3=500k (in reality 200k)
// bufferU[j++]=SET_T1T2;
// bufferU[j++]=2; //force T=28us -> 286 kbps
// bufferU[j++]=0;
bufferU[j++]=EN_VPP_VCC; //VDD
bufferU[j++]=0x1;
bufferU[j++]=WAIT_T3;
bufferU[j++]=EXT_PORT; //CS=1, HLD=1, WP=0
bufferU[j++]=CS+HLD;
bufferU[j++]=0;
bufferU[j++]=EXT_PORT; //CS=0, HLD=1, WP=0
bufferU[j++]=HLD;
bufferU[j++]=0;
bufferU[j++]=SPI_WRITE; //READ ID
bufferU[j++]=1;
bufferU[j++]=0x9F;
bufferU[j++]=SPI_READ;
bufferU[j++]=3;
bufferU[j++]=EXT_PORT; //CS=1, HLD=1, WP=0
bufferU[j++]=CS+HLD;
bufferU[j++]=0;
bufferU[j++]=EXT_PORT; //CS=0, HLD=1, WP=0
bufferU[j++]=HLD;
bufferU[j++]=0;
bufferU[j++]=SPI_WRITE; //Read
if(dim>0x10000){ //24 bit address
bufferU[j++]=4;
bufferU[j++]=3;
bufferU[j++]=0;
bufferU[j++]=0;
bufferU[j++]=0;
}
else if(dim>0x200){ //16 bit address
bufferU[j++]=3;
bufferU[j++]=3;
bufferU[j++]=0;
bufferU[j++]=0;
}
else{ //8 bit address
bufferU[j++]=2;
bufferU[j++]=3;
bufferU[j++]=0;
}
bufferU[j++]=FLUSH;
for(;j0&&ID!=0xFFFFFF) PrintMessage1("DEVICE ID=0x%06X\r\n",ID);
//****************** read ********************
PrintMessage(strings[S_ReadEE]); //read EEPROM ...
PrintStatusSetup();
for(i=0,j=0;i0x1000000||dim<0){
PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n"
return;
}
if(saveLog){
OpenLogFile(); //"Log.txt"
fprintf(logfile,"Read25xxF(%d) (0x%X)\n",dim,dim);
}
sizeEE=dim;
if(memEE) free(memEE);
memEE=(unsigned char*)malloc(dim); //EEPROM
unsigned int start=GetTickCount();
j=0;
bufferU[j++]=VREG_DIS;
bufferU[j++]=SPI_INIT;
bufferU[j++]=3; //0=100k, 1=200k, 2=300k, 3=500k (in reality 200k)
// bufferU[j++]=SET_T1T2;
// bufferU[j++]=2; //force T=28us -> 286 kbps
// bufferU[j++]=0;
bufferU[j++]=EN_VPP_VCC; //VDD
bufferU[j++]=0x1;
bufferU[j++]=WAIT_T3;
bufferU[j++]=EXT_PORT; //CS=1, HLD=1, WP=0
bufferU[j++]=CS+HLD;
bufferU[j++]=0;
bufferU[j++]=EXT_PORT; //CS=0, HLD=1, WP=1
bufferU[j++]=HLD;
bufferU[j++]=WP;
bufferU[j++]=SPI_WRITE; //READ ID
bufferU[j++]=1;
bufferU[j++]=0x9F;
bufferU[j++]=SPI_READ;
bufferU[j++]=3;
bufferU[j++]=EXT_PORT; //CS=1, HLD=1, WP=1
bufferU[j++]=CS+HLD;
bufferU[j++]=WP;
bufferU[j++]=EXT_PORT; //CS=0, HLD=1, WP=0
bufferU[j++]=HLD;
bufferU[j++]=0;
bufferU[j++]=SPI_WRITE; //Read
if(dim>0x10000){ //24 bit address
bufferU[j++]=4;
bufferU[j++]=3;
bufferU[j++]=0;
bufferU[j++]=0;
bufferU[j++]=0;
}
else if(dim>0x200){ //16 bit address
bufferU[j++]=3;
bufferU[j++]=3;
bufferU[j++]=0;
bufferU[j++]=0;
}
else{ //8 bit address
bufferU[j++]=2;
bufferU[j++]=3;
bufferU[j++]=0;
}
bufferU[j++]=FLUSH;
for(;j0&&ID!=0xFFFFFF) PrintMessage1("DEVICE ID=0x%06X\r\n",ID);
//****************** read ********************
PrintMessage(strings[S_ReadEE]); //read EEPROM ...
PrintStatusSetup();
#define rSize (DIMBUF-5-2)
#define npack 255
j=0;
bufferU[j++]=0xF6;
bufferU[j++]=npack;
bufferU[j++]=SPI_READ;
bufferU[j++]=rSize;
bufferU[j++]=0xF7;
bufferU[j++]=FLUSH;
for(;j0x1000000||dim<0){
PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n"
return;
}
if(saveLog){
OpenLogFile(); //"Log.txt"
fprintf(logfile,"Write25xx(%d,%d) (0x%X,0x%X)\n",dim,options,dim,options);
}
if(dim>sizeEE){
i=sizeEE;
memEE=(unsigned char*)realloc(memEE,dim);
for(;i0&&ID!=0xFFFFFF){
PrintMessage1("DEVICE ID=0x%06X\r\n",ID);
if(saveLog) fprintf(logfile,"DEVICE ID=0x%06X\n",ID);
}
msDelay(10); //wait power-up timer in some devices
bufferU[j++]=EXT_PORT; //CS=0, HLD=1, WP=1
bufferU[j++]=HLD;
bufferU[j++]=WP;
bufferU[j++]=SPI_WRITE; //WRITE ENABLE
bufferU[j++]=1;
bufferU[j++]=6;
bufferU[j++]=EXT_PORT; //CS=1, HLD=1, WP=1
bufferU[j++]=CS+HLD;
bufferU[j++]=WP;
bufferU[j++]=EXT_PORT; //CS=0, HLD=1, WP=1
bufferU[j++]=HLD;
bufferU[j++]=WP;
if(options&0x2000){ //status 1+2
bufferU[j++]=SPI_WRITE; //WRITE STATUS
bufferU[j++]=3;
bufferU[j++]=1;
bufferU[j++]=0;
bufferU[j++]=0;
}
else{
bufferU[j++]=SPI_WRITE; //WRITE STATUS
bufferU[j++]=2;
bufferU[j++]=1;
bufferU[j++]=0;
}
bufferU[j++]=EXT_PORT; //CS=1, HLD=1, WP=1
bufferU[j++]=CS+HLD;
bufferU[j++]=WP;
bufferU[j++]=EXT_PORT; //CS=0, HLD=1, WP=1
bufferU[j++]=HLD;
bufferU[j++]=WP;
bufferU[j++]=SPI_WRITE; //READ STATUS
bufferU[j++]=1;
bufferU[j++]=5;
bufferU[j++]=SPI_READ;
bufferU[j++]=1;
bufferU[j++]=EXT_PORT; //CS=1, HLD=1, WP=1
bufferU[j++]=CS+HLD;
bufferU[j++]=WP;
bufferU[j++]=FLUSH;
for(;j0x10000){ //24 bit address
bufferU[j++]=4;
bufferU[j++]=2;
bufferU[j++]=i>>16;
bufferU[j++]=(i>>8)&0xFF;
bufferU[j++]=i&0xFF;
}
else if(dim>0x200){ //16 bit address
bufferU[j++]=3;
bufferU[j++]=2;
bufferU[j++]=i>>8;
bufferU[j++]=i&0xFF;
}
else{ //8 bit address
bufferU[j++]=2;
bufferU[j++]=2+(i&0x100?8:0);
bufferU[j++]=i&0xFF;
}
pp=page=0xFA) k=i=dim+10;
pp=(page-k)0x10000){ //24 bit address
bufferU[j++]=4;
bufferU[j++]=3;
bufferU[j++]=0;
bufferU[j++]=0;
bufferU[j++]=0;
}
else if(dim>0x200){ //16 bit address
bufferU[j++]=3;
bufferU[j++]=3;
bufferU[j++]=0;
bufferU[j++]=0;
}
else{ //8 bit address
bufferU[j++]=2;
bufferU[j++]=3;
bufferU[j++]=0;
}
bufferU[j++]=FLUSH;
for(;j=dim) break;
if(i>i0){ //some data was skipped; update current address
j=0;
bufferU[j++]=EXT_PORT; //CS=1, HLD=1, WP=1
bufferU[j++]=CS+HLD;
bufferU[j++]=WP;
bufferU[j++]=EXT_PORT; //CS=0, HLD=1, WP=0
bufferU[j++]=HLD;
bufferU[j++]=0;
bufferU[j++]=SPI_WRITE; //Read
if(dim>0x10000){ //24 bit address
bufferU[j++]=4;
bufferU[j++]=3;
bufferU[j++]=i>>16;
bufferU[j++]=(i>>8)&0xFF;
bufferU[j++]=i&0xFF;
}
else if(dim>0x200){ //16 bit address
bufferU[j++]=3;
bufferU[j++]=3;
bufferU[j++]=i>>8;
bufferU[j++]=i&0xFF;
}
else{ //8 bit address
bufferU[j++]=2;
bufferU[j++]=3+(i&0x100?8:0);
bufferU[j++]=i&0xFF;
}
bufferU[j++]=FLUSH;
for(;j=max_err) break;
}
PrintStatusEnd();
if(i0x10000||dim<0){
PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n"
return;
}
if(saveLog){
OpenLogFile(); //"Log.txt"
fprintf(logfile,"ReadOneWireMem(%d) (0x%X)\n",dim,dim);
}
sizeEE=dim;
if(memEE) free(memEE);
memEE=(unsigned char*)malloc(dim); //EEPROM
unsigned int start=GetTickCount();
j=0;
bufferU[j++]=VREG_DIS;
bufferU[j++]=uW_INIT; //set RB1=0 to use as GND terminal beside RB0
bufferU[j++]=EN_VPP_VCC; //VDD
bufferU[j++]=0x1;
bufferU[j++]=WAIT_T3;
bufferU[j++]=OW_RESET;
bufferU[j++]=OW_WRITE;
bufferU[j++]=1;
bufferU[j++]=READ_ROM;
bufferU[j++]=OW_READ;
bufferU[j++]=8;
if(dim<=32){ //1 byte address
bufferU[j++]=OW_WRITE;
bufferU[j++]=2;
bufferU[j++]=READ_MEMORY;
bufferU[j++]=0; //address
}
else{ //2 byte address
bufferU[j++]=OW_WRITE;
bufferU[j++]=3;
bufferU[j++]=READ_MEMORY;
bufferU[j++]=0; //address
bufferU[j++]=0; //address
}
bufferU[j++]=FLUSH;
for(;j0x10000||dim<0){
PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n"
return;
}
if(saveLog){
OpenLogFile(); //"Log.txt"
fprintf(logfile,"WriteOneWireMem(%d,%d) (0x%X,0x%X)\n",dim,options,dim,options);
}
if(dim>sizeEE){
i=sizeEE;
memEE=(unsigned char*)realloc(memEE,dim);
for(;i32) bufferU[j++]=i>>8;
for(k=0;k>8;
bufferU[j++]=page-1;
}
bufferU[j++]=FLUSH;
for(;j=max_err) break;
}
PrintStatusEnd();
if(k!=dim){
PrintMessage("\r\n");
PrintMessage2(strings[S_ReadEEErr],dim,k); //"Error reading EEPROM area, requested %d bytes, read %d\r\n"
sizeEE=k;
}
PrintMessage1(strings[S_ComplErr],err); //"completed: %d errors\r\n"
//****************** exit ********************
bufferU[j++]=EN_VPP_VCC; //turn off
bufferU[j++]=0x0;
bufferU[j++]=FLUSH;
for(;j0xF000) T|=0xFFFF0000; //adjust negative value
#ifdef _MSC_VER
PrintMessage2("T=%.4f°C (0x%04X)\r\n",T*TLSB,T);
#else
PrintMessage2("T=%.4f°C (0x%04X)\r\n",T*TLSB,T);
#endif
//****************** exit ********************
bufferU[j++]=EN_VPP_VCC; //turn off
bufferU[j++]=0x0;
bufferU[j++]=FLUSH;
for(;j=0x10000||dim<0){
PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n"
return;
}
if(saveLog){
OpenLogFile(); //"Log.txt"
fprintf(logfile,"Read11xx(%d) (0x%X)\n",dim,dim);
}
sizeEE=dim;
if(memEE) free(memEE);
memEE=(unsigned char*)malloc(dim); //EEPROM
unsigned int start=GetTickCount();
j=0;
bufferU[j++]=VREG_DIS;
bufferU[j++]=EN_VPP_VCC; //VDD
bufferU[j++]=0x1;
bufferU[j++]=WAIT_T3;
bufferU[j++]=UNIO_COM;
bufferU[j++]=2; //write x bytes
bufferU[j++]=1; //read x bytes
bufferU[j++]=0xA0;
bufferU[j++]=UNIO_RDSR;
bufferU[j++]=FLUSH;
for(;j>8;
bufferU[j++]=i&0xFF;
bufferU[j++]=FLUSH;
for(;j=0x10000||dim<0){
PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n"
return;
}
if(saveLog){
OpenLogFile(); //"Log.txt"
fprintf(logfile,"Write11xx(%d,%d) (0x%X,0x%X)\n",dim,page,dim,page);
}
if(dim>sizeEE){
i=sizeEE;
memEE=(unsigned char*)realloc(memEE,dim);
for(;i=DIMBUF-8;page>>=1);
for(i=0,j=0;i>8;
bufferU[j++]=i&0xFF;
for(k=0;k=0xFA) i=dim+10;
PrintStatus(strings[S_CodeWriting2],i*100/(dim),i); //"Write: %d%%, addr. %04X"
if(RWstop) i=dim;
j=0;
if(saveLog){
fprintf(logfile,strings[S_Log7],i,i,k,k); //"i=%d(0x%X), k=%d(0x%X)\n"
}
bufferU[j++]=UNIO_COM;
bufferU[j++]=2; //write x bytes
bufferU[j++]=1; //read x bytes
bufferU[j++]=0xA0;
bufferU[j++]=UNIO_RDSR;
bufferU[j++]=UNIO_COM;
bufferU[j++]=2; //write x bytes
bufferU[j++]=0; //read x bytes
bufferU[j++]=0xA0;
bufferU[j++]=UNIO_WREN;
bufferU[j++]=FLUSH;
for(;j>8;
bufferU[j++]=i&0xFF;
bufferU[j++]=FLUSH;
for(;j=max_err) break;
}
PrintStatusEnd();
if(k!=dim){
PrintMessage("\r\n");
PrintMessage2(strings[S_ReadEEErr],dim,k); //"Error reading EEPROM area, requested %d bytes, read %d\r\n"
}
PrintMessage1(strings[S_ComplErr],err); //"completed: %d errors\r\n"
//****************** exit ********************
bufferU[j++]=EN_VPP_VCC;
bufferU[j++]=0x0;
bufferU[j++]=FLUSH;
for(;j