From 925d0670c45e1100e412070fa0ce2405604f219a Mon Sep 17 00:00:00 2001 From: Attila Veghelyi Date: Thu, 29 Jun 2023 16:24:54 +0200 Subject: Init repo --- .gitignore | 3 + 24c02.hex | 18 + I2CSPI.c | 243 +++ I2CSPI.h | 2 + Makefile_op | 52 + Makefile_opgui | 67 + coff.c | 207 ++ coff.h | 208 ++ common.h | 5 + common_op.h | 114 + common_opgui.h | 117 + deviceRW.c | 1248 +++++++++++ deviceRW.h | 52 + fileIO.c | 835 ++++++++ fileIO.h | 8 + gpl-2.0.txt | 339 +++ hid-example.c | 182 ++ hid_test.c | 575 +++++ icd.c | 1541 +++++++++++++ icd.h | 185 ++ icons.c | 546 +++++ ihex.c | 15 + instructions.h | 99 + op.c | 1358 ++++++++++++ opgui.c | 2503 ++++++++++++++++++++++ opgui.glade | 3797 ++++++++++++++++++++++++++++++++ progAVR.c | 2450 +++++++++++++++++++++ progAVR.h | 8 + progEEPROM.c | 2311 ++++++++++++++++++++ progEEPROM.h | 12 + progP12.c | 666 ++++++ progP12.h | 3 + progP16.c | 6546 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ progP16.h | 20 + progP18.c | 2662 +++++++++++++++++++++++ progP18.h | 6 + progP24.c | 3917 +++++++++++++++++++++++++++++++++ progP24.h | 7 + progP32.c | 2454 +++++++++++++++++++++ progP32.h | 4 + read.png | Bin 0 -> 1305 bytes read_eeprom.sh | 1 + readme | 98 + resources.xml | 10 + strings.c | 1070 +++++++++ strings.h | 282 +++ style.css | 3 + sys.png | Bin 0 -> 312 bytes write.png | Bin 0 -> 1228 bytes 49 files changed, 36849 insertions(+) create mode 100644 .gitignore create mode 100644 24c02.hex create mode 100644 I2CSPI.c create mode 100644 I2CSPI.h create mode 100644 Makefile_op create mode 100644 Makefile_opgui create mode 100644 coff.c create mode 100644 coff.h create mode 100644 common.h create mode 100644 common_op.h create mode 100644 common_opgui.h create mode 100644 deviceRW.c create mode 100644 deviceRW.h create mode 100644 fileIO.c create mode 100644 fileIO.h create mode 100644 gpl-2.0.txt create mode 100644 hid-example.c create mode 100644 hid_test.c create mode 100644 icd.c create mode 100644 icd.h create mode 100644 icons.c create mode 100644 ihex.c create mode 100644 instructions.h create mode 100644 op.c create mode 100644 opgui.c create mode 100644 opgui.glade create mode 100644 progAVR.c create mode 100644 progAVR.h create mode 100644 progEEPROM.c create mode 100644 progEEPROM.h create mode 100644 progP12.c create mode 100644 progP12.h create mode 100644 progP16.c create mode 100644 progP16.h create mode 100644 progP18.c create mode 100644 progP18.h create mode 100644 progP24.c create mode 100644 progP24.h create mode 100644 progP32.c create mode 100644 progP32.h create mode 100644 read.png create mode 100644 read_eeprom.sh create mode 100644 readme create mode 100644 resources.xml create mode 100644 strings.c create mode 100644 strings.h create mode 100644 style.css create mode 100644 sys.png create mode 100644 write.png diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a51f015 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.[ado] +op +opgui diff --git a/24c02.hex b/24c02.hex new file mode 100644 index 0000000..ff0489b --- /dev/null +++ b/24c02.hex @@ -0,0 +1,18 @@ +:020000040000FA +:100000004828000000000000A8000308A9001030E4 +:100010008506A003031D1428A1030F3021052730F6 +:1000200003192830A00026140B111F302405031DCE +:100030003C2819302506031D3C2810302006031DDE +:100040003C28271C252827103C28FF302C050319A5 +:100050003C2800302406031935283C30AA00230828 +:10006000AA022C082A0203183C28AC03A71C3B2830 +:10007000A00A27143C28A0032908830028080900A7 +:100080000000000000000000000000000000000070 +:1000900083160313803081002830850000308600ED +:1000A000831207309F00A0308B0007308500FF309F +:1000B00086003230A5002830A0000E30A2000F309C +:1000C000A3000430AB000030A400A600A70081000C +:1000D000261C7028B220CB20A61C7028A610342124 +:1000E0000630051A103E8500FF302406261D7A28AA +:1000F000FE309C208600AD20FF308600A320053016 +:00000001FF diff --git a/I2CSPI.c b/I2CSPI.c new file mode 100644 index 0000000..e911792 --- /dev/null +++ b/I2CSPI.c @@ -0,0 +1,243 @@ +/* + * I2CSPI.c - algorithms to interface generic I2C/SPI devices + * Copyright (C) 2010-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 + */ + + +//configure for GUI or command-line +#include "common.h" +#ifdef __GTK_H__ +#define _GTKGUI +#endif + + +#ifdef _GTKGUI + #define printM(id) PrintMessageI2C(id); +#else + #define printM(id) printf(id); +#endif + +#define CS 8 +#define HLD 16 + +void I2CReceive(int mode,int speed,int N,BYTE *buffer) +// I2C/SPI receive +// mode: +// 0 = I2C 8bit +// 1 = I2C 16bit +// 2 = SPI 00 +// 3 = SPI 01 +// 4 = SPI 10 +// 5 = SPI 11 +// speed: +// 0 = 100 kbps +// 1 = 200 kbps +// 2 = 300/400 kbps (SPI/I2C) +// 3 = 500/800 kbps (SPI/I2C) +{ + int j=0; + if(N<0) N=0; + if(N>60) N=60; + if(mode<0) mode=0; + if(mode>5) mode=5; + if(speed<0) speed=0; + if(speed>3) speed=3; + if(saveLog){ + OpenLogFile(); //"Log.txt" + fprintf(logfile,"I2C-SPI receive\tmode=%d\tspeed=%d\n",mode,speed); + } + bufferU[j++]=VREG_DIS; //Disable HV reg + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + if(mode<2){ //I2C mode + bufferU[j++]=I2C_INIT; + bufferU[j++]=(speed<<3)+(speed>0?0x40:0); //enable slew control if >100k + } + else{ //SPI mode + bufferU[j++]=EXT_PORT; //CS=1 + bufferU[j++]=CS; + bufferU[j++]=0; + bufferU[j++]=EXT_PORT; //CS=0 + bufferU[j++]=0; + bufferU[j++]=0; + bufferU[j++]=SPI_INIT; + bufferU[j++]=speed+((mode-2)<<2); + } + bufferU[j++]=FLUSH; + for(;j(DIMBUF-4)?DIMBUF-4:N; + bufferU[j++]=buffer[0]; //Control byte + bufferU[j++]=buffer[1]; //Address; + } + else if(mode==1){ //I2C read 16bit + bufferU[j++]=I2C_READ2; + bufferU[j++]=N>(DIMBUF-4)?DIMBUF-4:N; + bufferU[j++]=buffer[0]; //Control byte + bufferU[j++]=buffer[1]; //Address H; + bufferU[j++]=buffer[2]; //Address L; + } + else if(mode>=2){ //SPI read + bufferU[j++]=SPI_READ; + bufferU[j++]=N>(DIMBUF-5)?DIMBUF-5:N; + bufferU[j++]=EXT_PORT; //CS=1 + bufferU[j++]=CS; + bufferU[j++]=0; + } + bufferU[j++]=FLUSH; + for(;j0xFA){ + printM(strings[S_InsErr]); //"unknown instruction" + } + else{ + char str[1024]=""; + char t[16]=""; + int i; + if(mode==0) sprintf(str,"> %02X %02X\r\n",bufferU[2],bufferU[3]); + else if(mode==1) sprintf(str,"> %02X %02X\r\n",bufferU[2],bufferU[3]); + strcat(str,"< "); + for(i=0;i57) N=57; + if(mode<0) mode=0; + if(mode>5) mode=5; + if(speed<0) speed=0; + if(speed>3) speed=3; + if(saveLog){ + OpenLogFile(); //"Log.txt" + fprintf(logfile,"I2C-SPI send\tmode=%d\tspeed=%d\n",mode,speed); + } + bufferU[j++]=VREG_DIS; //Disable HV reg + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + if(mode<2){ //I2C mode + bufferU[j++]=I2C_INIT; + bufferU[j++]=(speed<<3)+(speed>0?0x40:0); //enable slew control if >100k + } + else{ //SPI mode + bufferU[j++]=EXT_PORT; //CS=1 + bufferU[j++]=CS; + bufferU[j++]=0; + bufferU[j++]=EXT_PORT; //CS=0 + bufferU[j++]=0; + bufferU[j++]=0; + bufferU[j++]=SPI_INIT; + bufferU[j++]=speed+((mode-2)<<2); + } + bufferU[j++]=FLUSH; + for(;j(DIMBUF-5)?DIMBUF-5:N; + bufferU[j++]=buffer[0]; //Control byte + bufferU[j++]=buffer[1]; //Address + for(i=0;i(DIMBUF-5)?DIMBUF-5:N+1; + bufferU[j++]=buffer[0]; //Control byte + bufferU[j++]=buffer[1]; //Address + bufferU[j++]=buffer[2]; //Address L + for(i=0;i=2){ //SPI write + bufferU[j++]=SPI_WRITE; + bufferU[j++]=N>(DIMBUF-5)?DIMBUF-5:N; + for(i=0;i0xFA){ + printM(strings[S_InsErr]); //"unknown instruction" + } + else{ + char str[1024]; + char t[16]; + int n=2; + int i; + sprintf(str,"> "); + if(mode<2) n=4; + for(i=0;i +#include +#include +#include "coff.h" + +// Analyze COFF file named filename, extract code labels in label[address], undefined labels in ulabel[address], +// info about each symbol (name, source line, source file index) in source_info, +// list of source files (index, name, file pointer) in s_files, raw data in data[0x2200] +int analyzeCOFF(char *filename,char* label[LMAX],char* ulabel[ULMAX],struct src_i source_info[LMAX],struct srcfile **s_files_p,unsigned short data[0x2200],struct symbol **sym_p, int* nsym) +{ + int i,j,k; + FILE*f=fopen(filename,"rb"); + if(!f) return 0; + scnhdr_t* sections; + filehdr_t FileHeader; + opthdr_t OptHeader; + fread((char*)&FileHeader,sizeof(filehdr_t),1,f); //file header +/* printf("File header:\nmagic %X, sections %d, time %d, symbol ptr %d, nsymbol %d, opt size %d, flags %X\n",\ + FileHeader.f_magic,FileHeader.f_nscns,FileHeader.f_timdat,FileHeader.f_symptr,FileHeader.f_nsyms,FileHeader.f_opthdr,FileHeader.f_flags);*/ + if(FileHeader.f_opthdr==18){ //optional header + fread((char*)&OptHeader,2,1,f); + fread((char*)&OptHeader+4,16,1,f); +/* printf("Optional header:\nmagic %X, version %X, processor %X, rom width %d, data width %d\n",\ + OptHeader.magic,OptHeader.vstamp,OptHeader.proc_type,OptHeader.rom_width_bits,OptHeader.ram_width_bits);*/ + } + sections=(scnhdr_t*)malloc(sizeof(scnhdr_t)*FileHeader.f_nscns); + for(i=0;i0&§ions[symbol.n_scnum-1].s_size>0){ //store symbols defined in non-empty sections up to ULMAX + if(ulabel[symbol.n_value]==0){ + ulabel[symbol.n_value]=malloc(strlen(name)+1); + strcpy(ulabel[symbol.n_value],name); + } + else{ + printf("conflicting labels at address %X: %s vs. %s\n",(unsigned int)symbol.n_value,ulabel[symbol.n_value],name); +/* char* temp=malloc(strlen(ulabel[symbol.n_value])+strlen(name)+2); + sprintf(temp,"%s %s",ulabel[symbol.n_value],name); + free(ulabel[symbol.n_value]); + ulabel[symbol.n_value]=temp;*/ + } +// printf("%d %s\n",symbol.n_value,name); + } + if(symbol.n_sclass==7){ + //store all symbols in the sym_p array + (*nsym)++; + *sym_p=realloc(*sym_p,(*nsym)*sizeof(struct symbol)); + (*sym_p)[*nsym-1].name=strdup(name); + (*sym_p)[*nsym-1].value=symbol.n_value; + } +/* printf("\"%s\", Value %X, Section %d, type %X, Storage class %d, Naux %d, %d\n",\ + name,symbol.n_value,symbol.n_scnum,symbol.n_type,symbol.n_sclass,symbol.n_numaux,i);*/ + // store file info in s_files + if(symbol.n_sclass==103){ //type C_FILE + aux_file_t aux; + fread(&aux,20,1,f); + symbol.n_numaux--; +// printf("-> \"%s\", line %d, flags %X\n",&strtable[aux.x_offset],aux.x_incline,aux.x_flags); + filemax++; + *s_files_p=realloc(*s_files_p,filemax*sizeof(struct srcfile)); + (*s_files_p)[filemax-1].name=strdup(&strtable[aux.x_offset]); + (*s_files_p)[filemax-1].ptr=0; + (*s_files_p)[filemax-1].l_srcndx=i; + (*s_files_p)[filemax-1].nlines=0; + (*s_files_p)[filemax-1].lineptr=NULL; +// printf("%s, idx %d, a %X, i=%d\n",(*s_files_p)[filemax-1].name,(*s_files_p)[filemax-1].l_srcndx,&(*s_files_p)[filemax-1],filemax-1); + i++; + } + i+=symbol.n_numaux; + for(j=symbol.n_numaux;j;j--)fread(&symbol,20,1,f); + } +// printf("filemax=%d a[0]=%X\n",filemax,&s_files[0]); + // read line info for all sections (line physical address should be unique) + struct coff_lineno line; + for(i=0;i0){ + if(fseek(f,sections[i].s_scnptr,SEEK_SET)) printf("seek error\n"); + raw=malloc(sections[i].s_size); + fread(raw,sections[i].s_size,1,f); + if((sections[i].s_paddr+sections[i].s_size/2)<0x2200)memcpy(&data[sections[i].s_paddr],raw,sections[i].s_size); + free(raw); + } + } + free(strtable); + free(strings); + free(raw); + return 1; +} + +//open a source file and store a pointer for each line +FILE* scanSourceFile(struct srcfile *s_files_p){ +// printf("Scansource ptr %X, file %s, nlines %d\n",s_files_p,(*s_files_p).name,(*s_files_p).nlines); + FILE* f=fopen((*s_files_p).name,"rb"); + char line[4096]; + long int p; + char* i; + (*s_files_p).ptr=f; + if(!f) return f; + (*s_files_p).nlines=1; //line # start from index 1 + p=ftell(f); + for(i=fgets(line,4096,f);i;){ + (*s_files_p).lineptr=realloc((*s_files_p).lineptr,((*s_files_p).nlines+1)*sizeof(long int)); + (*s_files_p).lineptr[(*s_files_p).nlines]=p; + //printf("nlines%d ptr%d %s",(*s_files_p).nlines,p,line); + (*s_files_p).nlines++; + p=ftell(f); + i=fgets(line,4096,f); + } +// printf("file %s, nlines %d\n",(*s_files_p).name,(*s_files_p).nlines); + return f; +} diff --git a/coff.h b/coff.h new file mode 100644 index 0000000..1175c04 --- /dev/null +++ b/coff.h @@ -0,0 +1,208 @@ +// COFF file parser +// COFF file structure: +// file header +// optional header +// sections(name, address, size, raw data pointer, reloc entry, ptr to first line, number of lines) +// relocation entries +// symbols (name, value, section, type, class) + optional info +// lines (source file symbol, line number, address of code) +// symbol table +// string table + +#define LMAX 0x2200 +#define DATA_MAX 0x2200 +#define ULMAX 0x400 + +typedef struct filehdr +{ + unsigned short f_magic; + unsigned short f_nscns; + unsigned long f_timdat; + unsigned long f_symptr; + unsigned long f_nsyms; + unsigned short f_opthdr; + unsigned short f_flags; +} filehdr_t; + +typedef struct opthdr +{ + unsigned short magic; + unsigned long vstamp; + unsigned long proc_type; + unsigned long rom_width_bits; + unsigned long ram_width_bits; +} opthdr_t; + +typedef struct scnhdr +{ + union + { + char _s_name[8]; /* section name is a string */ + struct + { + unsigned long _s_zeroes; + unsigned long _s_offset; + }_s_s; + }_s; + unsigned long s_paddr; + unsigned long s_vaddr; + unsigned long s_size; + unsigned long s_scnptr; + unsigned long s_relptr; + unsigned long s_lnnoptr; + unsigned short s_nreloc; + unsigned short s_nlnno; + unsigned long s_flags; +} scnhdr_t; + +typedef struct reloc +{ + unsigned long r_vaddr; + unsigned long r_symndx; + short r_offset; + unsigned short r_type; +} reloc_t; + +#define SYMNMLEN 8 +typedef struct syment +{ + union + { + char _n_name[SYMNMLEN]; + struct + { + unsigned long _n_zeroes; + unsigned long _n_offset; + } _n_n; + char *_n_nptr[2]; + } _n; + unsigned long n_value; + short n_scnum; + unsigned long n_type; + char n_sclass; + unsigned char n_numaux; +} syment_t; + +typedef struct coff_lineno +{ + unsigned long l_srcndx; + unsigned short l_lnno; + unsigned long l_paddr; + unsigned short l_flags; + unsigned long l_fcnndx; +} coff_lineno_t; + +typedef struct aux_file +{ + unsigned long x_offset; + unsigned long x_incline; + unsigned char x_flags; + char _unused[11]; +} aux_file_t; + +typedef struct aux_scn +{ + unsigned long x_scnlen; + unsigned short x_nreloc; + unsigned short x_nlinno; + char _unused[12]; +} aux_scn_t; + +typedef struct aux_tag +{ + char _unused[6]; + unsigned short x_size; + char _unused2[4]; + unsigned long x_endndx; + char _unused3[4]; +} aux_tag_t; + +typedef struct aux_eos +{ + unsigned long x_tagndx; + char _unused[2]; + unsigned short x_size; + char _unused2[12]; +} aux_eos_t; + +typedef struct aux_fcn +{ + unsigned long x_tagndx; + unsigned long x_size; + unsigned long x_lnnoptr; + unsigned long x_endndx; + short x_actscnum; + char _unused[2]; +} aux_fcn_t; + +typedef struct aux_fcn_calls +{ + unsigned long x_calleendx; + unsigned long x_is_interrupt; + char _unused[12]; +} aux_fcn_calls_t; + +#define X_DIMNUM 4 +typedef struct aux_arr +{ + unsigned long x_tagndx; + unsigned short x_lnno; + unsigned short x_size; + unsigned short x_dimen[X_DIMNUM]; + char _unused[4]; +} aux_arr_t; + +typedef struct aux_eobf +{ + char _unused[4]; + unsigned short x_lnno; + char _unused2[14]; +} aux_eobf_t; + +typedef struct aux_bobf +{ + char _unused[4]; + unsigned short x_lnno; + char _unused2[6]; + unsigned long x_endndx; + char _unused3[4]; +} aux_bobf_t; + +typedef struct aux_var +{ + unsigned long x_tagndx; + char _unused[2]; + unsigned short x_size; + char _unused2[12]; +} aux_var_t; + +typedef struct aux_field +{ + char _unused[6]; + unsigned short x_size; + char _unused2[12]; +} aux_field_t; + +struct src_i +{ + char* label; + int src_file; + int src_line; +}; + +struct srcfile { + unsigned long l_srcndx; + char* name; + FILE* ptr; + int nlines; + long int *lineptr; //line pointer array +}; + +struct symbol { + char* name; + int value; +}; + +FILE* scanSourceFile(struct srcfile *s_files_p); +int analyzeCOFF(char *filename,char* label[LMAX],char* ulabel[ULMAX],struct src_i source_info[LMAX],\ + struct srcfile **s_files_p,unsigned short data[0x2200],struct symbol **sym_p, int* nsym); diff --git a/common.h b/common.h new file mode 100644 index 0000000..59ab489 --- /dev/null +++ b/common.h @@ -0,0 +1,5 @@ +#ifdef OPGUI + #include "common_opgui.h" +#else + #include "common_op.h" +#endif diff --git a/common_op.h b/common_op.h new file mode 100644 index 0000000..c1f688a --- /dev/null +++ b/common_op.h @@ -0,0 +1,114 @@ +#ifndef _COMMON_DECLARATIONS +#define _COMMON_DECLARATIONS +//#define DEBUG +#define _APPNAME "OP" +#define _CMD + +#if !defined _WIN32 && !defined __CYGWIN__ +//linux: + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include +#else +//windows + #include + #include + #include + #include + #include + #include + #include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include "strings.h" +#include "instructions.h" + +typedef unsigned long DWORD; +typedef unsigned short WORD; +typedef unsigned char BYTE; + +//to use the same code of windows version +#define PrintMessage printf +#define PrintMessage1 printf +#define PrintMessage2 printf +#define PrintMessage3 printf +#define PrintMessage4 printf +#define PrintStatus(s,p1,p2) printf("\b\b\b\b%3d%%",p1); fflush(stdout); +#define PrintStatusSetup() printf(" "); +#define PrintStatusEnd() printf("\b\b\b\b"); +#define PrintStatusClear() //only for GUI +#define COL 16 +//Version defined in makefile +#if !defined VERSION + #define VERSION "unknown" +#endif +#define G (12.0/34*1024/5) //=72,2823529412 +#define LOCK 1 +#define FUSE 2 +#define FUSE_H 4 +#define FUSE_X 8 +#define CAL 16 +#define SLOW 256 + +#if !defined _WIN32 && !defined __CYGWIN__ //Linux + #define SYSNAME "Linux" + #define DIMBUF 64 + DWORD GetTickCount(); + extern unsigned char bufferU[128],bufferI[128]; +#else //Windows + #define SYSNAME "Windows" + #define DIMBUF 64 + extern unsigned char bufferU0[128],bufferI0[128]; + extern unsigned char *bufferU,*bufferI; + extern DWORD NumberOfBytesRead,BytesWritten; + extern ULONG Result; + extern HANDLE WriteHandle,ReadHandle; + extern OVERLAPPED HIDOverlapped; + extern HANDLE hEventObject; +#endif + +extern char str[4096]; +extern int saveLog; +extern char** strings; +extern int fd; +extern int saveLog,programID,MinDly,load_osccal,load_BKosccal; +extern int use_osccal,use_BKosccal; +extern int load_calibword,max_err; +extern int AVRlock,AVRfuse,AVRfuse_h,AVRfuse_x; +extern int ICDenable,ICDaddr; +extern int FWVersion,HwID; +extern FILE* logfile; +extern char LogFileName[512]; +extern char loadfile[512],savefile[512]; +extern WORD *memCODE_W; +extern int size,sizeW,sizeEE,sizeCONFIG,sizeUSERID; +extern unsigned char *memCODE,*memEE,memID[64],memCONFIG[48],memUSERID[8]; +extern double hvreg; +extern int RWstop; + +int StartHVReg(double V); +void msDelay(double delay); +void DisplayEE(); +void PrintMessageI2C(const char *msg); +int CheckV33Regulator(void); +void OpenLogFile(void); +void WriteLogIO(); +void CloseLogFile(); +unsigned int htoi(const char *hex, int length); +void PacketIO(double delay); +#endif diff --git a/common_opgui.h b/common_opgui.h new file mode 100644 index 0000000..e8b1afa --- /dev/null +++ b/common_opgui.h @@ -0,0 +1,117 @@ +#ifndef _COMMON_DECLARATIONS +#define _COMMON_DECLARATIONS +//#define DEBUG +#define _APPNAME "OPGUI" + +#if !defined _WIN32 && !defined __CYGWIN__ +//linux: + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include +#else +//windows + #include + #include + #include + #include + #include + #include + #include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include "strings.h" +#include "instructions.h" + +typedef unsigned long DWORD; +typedef unsigned short WORD; +typedef unsigned char BYTE; + +//to use the same code of windows version +#define PrintMessage1(s,p) {sprintf(str,s,p); PrintMessage(str);} +#define PrintMessage2(s,p1,p2) {sprintf(str,s,p1,p2); PrintMessage(str);} +#define PrintMessage3(s,p1,p2,p3) {sprintf(str,s,p1,p2,p3); PrintMessage(str);} +#define PrintMessage4(s,p1,p2,p3,p4) {sprintf(str,s,p1,p2,p3,p4); PrintMessage(str);} +#define PrintStatus(s,p1,p2) {sprintf(str,s,p1,p2); gtk_statusbar_push(GTK_STATUSBAR(status_bar),statusID,str);while (gtk_events_pending ()) gtk_main_iteration();} +#define PrintStatusSetup() //only needed for console version +#define PrintStatusEnd() //only needed for console version +#define PrintStatusClear() gtk_statusbar_push(GTK_STATUSBAR(status_bar),statusID,""); + +#define COL 16 +//Version defined in makefile +#if !defined VERSION + #define VERSION "unknown" +#endif +#define G (12.0/34*1024/5) //=72,2823529412 +#define LOCK 1 +#define FUSE 2 +#define FUSE_H 4 +#define FUSE_X 8 +#define CAL 16 +#define SLOW 256 + +#if !defined _WIN32 && !defined __CYGWIN__ //Linux + #define SYSNAME "Linux" + #define DIMBUF 64 + DWORD GetTickCount(); + extern unsigned char bufferU[128],bufferI[128]; +#else //Windows + #define SYSNAME "Windows" + #define DIMBUF 64 + extern unsigned char bufferU0[128],bufferI0[128]; + extern unsigned char *bufferU,*bufferI; + extern DWORD NumberOfBytesRead,BytesWritten; + extern ULONG Result; + extern HANDLE WriteHandle,ReadHandle; + extern OVERLAPPED HIDOverlapped; + extern HANDLE hEventObject; +#endif + +extern int statusID; +extern GtkWidget *status_bar; +extern char str[4096]; +extern int saveLog; +extern char** strings; +extern int fd; +extern int saveLog,programID,MinDly,load_osccal,load_BKosccal; +extern int use_osccal,use_BKosccal; +extern int load_calibword,max_err; +extern int AVRlock,AVRfuse,AVRfuse_h,AVRfuse_x; +extern int ICDenable,ICDaddr; +extern int FWVersion,HwID; +extern FILE* logfile; +extern char LogFileName[512]; +extern char loadfile[512],savefile[512]; +extern WORD *memCODE_W; +extern int size,sizeW,sizeEE,sizeCONFIG,sizeUSERID; +extern unsigned char *memCODE,*memEE,memID[64],memCONFIG[48],memUSERID[8]; +extern double hvreg; +extern int RWstop; + +int StartHVReg(double V); +void msDelay(double delay); +void DisplayEE(); +void PrintMessage(const char *msg); +void PrintMessageI2C(const char *msg); +int CheckV33Regulator(void); +void OpenLogFile(void); +void WriteLogIO(); +void CloseLogFile(); +unsigned int htoi(const char *hex, int length); +void PacketIO(double delay); +#endif diff --git a/deviceRW.c b/deviceRW.c new file mode 100644 index 0000000..127a7b6 --- /dev/null +++ b/deviceRW.c @@ -0,0 +1,1248 @@ +/* + * deviceRW.c - Read-write calls for various devices + * Copyright (C) 2010-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 + */ + +//configure for GUI or command-line +#include "common.h" +#include "progP12.h" +#include "progP16.h" +#include "progP18.h" +#include "progP24.h" +#include "progEEPROM.h" +#include "progAVR.h" +//#include "progP32.h" + +#ifdef __GTK_H__ +#define _GTKGUI +#endif + +#include "deviceRW.h" + +char* devices[]={ +"10F200","10F202","10F204","10F206","10F220","10F222", +"10F320","10F322", +"12C508","12C508A","12C509","12C509A","12F508","12F509","12F510","12F519", +"12F609","12F615","12F617","12F629","12F635","12C671","12C672","12CE673","12CE674","12F675","12F683", +"12F752", +"12F529T39","12F529T48", +"12F1501","12F1571","12F1572","12F1612","12F1822","12F1840", +"16F505","16F506","16F526","16F527","16F54","16F57","16F570","16F59", +"16F610","16F616","16F627","16F627A","16F628","16F628A","16F630","16F631", +"16F636","16F639","16F648A","16F676","16F677","16F684","16F685","16F687", +"16F688","16F689","16F690", +"16F707","16F716","16F72","16F720","16F721","16F722","16F722A","16F723","16F723A", +"16F724","16F726","16F727","16F73","16F737","16F74","16F747","16F753","16F76", +"16F767","16F77","16F777","16F785", +"16F818","16F819","16C83","16F83","16F83A","16C84","16F84","16F84A","16F87","16F870","16F871","16F872", +"16F873","16F873A","16F874","16F874A","16F876","16F876A","16F877","16F877A", +"16F88","16F882","16F883","16F884","16F886","16F887", +"16F913","16F914","16F916","16F917","16F946", +"16F1454","16F1455","16F1459", +"16F1503","16F1507","16F1508","16F1509","16F1512","16F1513","16F1516","16F1517","16F1518","16F1519", +"16F1526","16F1527","16LF1554","16LF1559","16F1574","16F1575","16F1578","16F1579", +"16F1613","16F1614","16F1615","16F1618","16F1619", +"16F1703","16F1704","16F1705","16F1707","16F1708","16F1709","16F1713","16F1716","16F1717","16F1718","16F1719", +"16F1764","16F1765","16F1768","16F1769","16F1773","16F1776","16F1777","16F17784","16F1779", +"16F1782","16F1783","16F1784","16F1786","16F1787","16F1788","16F1789", +"16F1823","16F1824","16F1825","16F1826","16F1827","16F1828","16F1829","16F1847", +"16LF1902","16LF1903","16LF1904","16LF1906","16LF1907", +"16F1933","16F1934","16F1936","16F1937","16F1938","16F1939","16F1946","16F1947", +"16F15213","16F15214","16F15223""16F15224","16F15225","16F15243","16F15244","16F15245", +"16F15254","16F15255","16F15256","16F15274","16F15275","16F15276", +"16F15313","16F15323","16F15324","16F15325","16F15344","16F15345","16F15354","16F15355","16F15356", +"16F15375","16F15376","16F15385","16F15386", +"16F17114","16F17115","16F17124","16F17125","16F17126","16F17144","16F17145","16F17146", +"16F17154","16F17155","16F17156","16F17174","16F17175","16F17176", +"16F18013","16F18014","16F18015","16F18023","16F18024","16F18025","16F18026","16F18044","16F18045","16F18046", +"16F18054","16F18055","16F18056","16F18074","16F18075","16F18076", +"16F18114","16F18115","16F18124","16F18125","16F18126","16F18144","16F18145","16F18146", +"16F18154","16F18155","16F18156","16F18174","16F18175","16F18176", +"16F18313","16F18323","16F18324","16F18325","16F18326","16F18344","16F18345","16F18346", +"16F18424","16F18425","16F18426","16F18444","16F18445","16F18446","16F18455","16F18456", +"16F18854","16F18855","16F18856","16F18857","16F18875","16F18876","16F18877", +"16F19155","16F19156","16F19175","16F19176","16F19185","16F19186","16F19195","16F19196","16F19197", +"18F04Q40","18F04Q41","18F05Q40","18F05Q41","18F06Q40","18F06Q41","18F14Q40","18F14Q41","18F15Q40","18F15Q41","18F16Q40","18F16Q41", +"18F242","18F248","18F252","18F258","18F442","18F448","18F452","18F458", +"18F1220","18F1230","18F1320","18F1330","18F13K22","18F13K50","18F14K22","18F14K50", +"18F2220","18F2221","18F2320","18F23K20","18F23K22","18F2321","18F2331","18F2410", +"18F24J10","18F24J11","18F2420","18F24K20","18F24K22","18F2423","18F2431","18F2439", +"18F2450","18F24J50","18F24K50","18F2455","18F2458","18F24Q71","18F2480", +"18F2510","18F25J10","18F25J11","18F2515","18F2520","18F25K20","18F25K22","18F2523", +"18F2525","18F2539","18F25K42","18F25Q43","18F2550","18F25J50","18F25K50","18F2553","18F25Q71","18F2580","18F25K80","18F25K83","18F2585", +"18F2610","18F26J11","18F26J13","18F2620","18F26K20","18F26K22","18F26K42","18F26Q43","18F26J50","18F26K50", +"18F26J53","18F26Q71","18F2680","18F26K80","18F2682","18F26K83","18F26Q83","18F26Q84","18F2685", +"18F27J13","18F27K42","18F27Q43","18F27J53","18F27Q83","18F27Q84", +"18F4220","18F4221","18F4320","18F43K20","18F43K22","18F4321","18F4331", +"18F4410","18F44J10","18F44J11","18F4420","18F44K20","18F44K22","18F4423","18F4431", +"18F4439","18F4450","18F44J50","18F4455","18F4458","18F44Q71","18F4480", +"18F4510","18F45J10","18F45J11","18F4515","18F4520","18F45K20","18F45K22","18F4523", +"18F4525","18F4539","18F45K42","18F45Q43","18F4550","18F45J50","18F45K50","18F4553","18F45Q71","18F4580","18F45K80","18F4585", +"18F4610","18F46J11","18F46J13","18F4620","18F46K20","18F46K22","18F46K42","18F46Q43","18F46J50","18F46K50", +"18F46J53","18F46Q71","18F4680","18F46K80","18F4682","18F46Q83","18F46Q84","18F4685", +"18F47J13","18F47K42","18F47Q43","18F47J53","18F47Q83","18F47Q84", +"18F54Q71","18F55K42","18F55Q43","18F55Q71","18F56K42","18F56Q43","18F56Q71","18F56Q83","18F56Q84","18F57K42","18F57Q43","18F57Q83","18F57Q84", +"18F63J11","18F63J90","18F64J11","18F64J90", +"18F65J10","18F65J11","18F65J15","18F65J50","18F65J90","18F65K80", +"18F66J10","18F66J11","18F66J15","18F66J16","18F66J50","18F66J55","18F66J60","18F66J65","18F66J90","18F66J93", +"18F67J10","18F67J11","18F67J50","18F67J60","18F66K80","18F67J90","18F67J93", +"18F83J11","18F83J90","18F84J11","18F84J90","18F85J10","18F85J11","18F85J15","18F85J50","18F85J90", +"18F8520","18F86J10","18F86J11","18F86J15","18F86J16","18F86J50","18F86J55","18F86J60","18F86J65", +"18F86J72","18F86J90","18F86J93", +"18F8722","18F87J10","18F87J11","18F87J50","18F87J60","18F87J72","18F87J90","18F87J93", +"18F96J60","18F96J65","18F97J60", +"24F04KA200","24F04KA201", +"24F08KA101","24F08KA102", +"24F16KA101","24F16KA102", +"24FJ16GA002","24FJ16GA004", +"24FJ32GA002","24FJ32GA004","24FJ32GA102","24FJ32GA104", +"24FJ32GB002","24FJ32GB004", +"24FJ48GA002","24FJ48GA004", +"24FJ64GA002","24FJ64GA004","24FJ64GA006","24FJ64GA008","24FJ64GA010", +"24FJ64GA102","24FJ64GA104","24FJ64GA306","24FJ64GA308","24FJ64GA310", +"24FJ64GB002","24FJ64GB004","24FJ64GB106","24FJ64GB108","24FJ64GB110", +"24FJ64GC006","24FJ64GC008","24FJ64GC010", +"24FJ96GA006","24FJ96GA008","24FJ96GA010", +"24FJ128GA006","24FJ128GA008","24FJ128GA010","24FJ128GA106","24FJ128GA108","24FJ128GA110", +"24FJ128GA306","24FJ128GA308","24FJ128GA310", +"24FJ128GB106","24FJ128GB108","24FJ128GB110","24FJ128GB206","24FJ128GB210", +"24FJ128GC006","24FJ128GC008","24FJ128GC010", +"24FJ128DA106","24FJ128DA110","24FJ128DA206","24FJ128DA210", +"24FJ192GA106","24FJ192GA108","24FJ192GA110", +"24FJ192GB106","24FJ192GB108","24FJ192GB110", +"24FJ256GA106","24FJ256GA108","24FJ256GA110", +"24FJ256GB106","24FJ256GB108","24FJ256GB110", +"24FJ256GB206","24FJ256GB210", +"24FJ256DA106","24FJ256DA110","24FJ256DA206","24FJ256DA210", +"24EP32GP202","24EP32GP203","24EP32GP204", +"24EP32MC202","24EP32MC203","24EP32MC204", +"24EP64GP202","24EP64GP203","24EP64GP204","24EP64GP206", +"24EP64MC202","24EP64MC203","24EP64MC204","24EP64MC206", +"24EP128GP202","24EP128GP204","24EP128GP206", +"24EP128MC202","24EP128MC204","24EP128MC206", +"24EP256GP202","24EP256GP204","24EP256GP206", +"24EP256MC202","24EP256MC204","24EP256MC206", +"24EP512GP202","24EP512GP204","24EP512GP206", +"24EP512MC202","24EP512MC204","24EP512MC206", +"24HJ12GP201","24HJ12GP202", +"24HJ16GP304", +"24HJ32GP202","24HJ32GP204","24HJ32GP302","24HJ32GP304", +"24HJ64GP202","24HJ64GP204","24HJ64GP206","24HJ64GP210","24HJ64GP502", +"24HJ64GP504","24HJ64GP506","24HJ64GP510", +"24HJ128GP202","24HJ128GP204","24HJ128GP206","24HJ128GP210", +"24HJ128GP306","24HJ128GP310","24HJ128GP502","24HJ128GP504","24HJ128GP506","24HJ128GP510", +"24HJ256GP206","24HJ256GP210","24HJ256GP610", +"30F1010","30F2010","30F2011","30F2012","30F2020","30F2023", +"30F3010","30F3011","30F3012","30F3013","30F3014", +"30F4011","30F4012","30F4013", +"30F5011","30F5013","30F5015","30F5016", +"30F6010","30F6011","30F6012","30F6013","30F6014","30F6015", +//"32MX270F256", +"33FJ06GS101","33FJ06GS102","33FJ06GS202", +"33FJ12GP201","33FJ12GP202","33FJ12MC201","33FJ12MC202", +"33FJ16GP304","33FJ16GS402","33FJ16GS404","33FJ16GS502","33FJ16GS504","33FJ16MC304", +"33FJ32GP202","33FJ32GP204","33FJ32GP302","33FJ32GP304", +"33FJ32GS406","33FJ32GS606","33FJ32GS608","33FJ32GS610", +"33FJ32MC202","33FJ32MC204","33FJ32MC302","33FJ32MC304", +"33FJ64GP202","33FJ64GP204","33FJ64GP206","33FJ64GP306","33FJ64GP310", +"33FJ64GP706","33FJ64GP708","33FJ64GP710","33FJ64GP802","33FJ64GP804", +"33FJ64GS406","33FJ64GS606","33FJ64GS608","33FJ64GS610", +"33FJ64MC202","33FJ64MC204","33FJ64MC506","33FJ64MC508","33FJ64MC510", +"33FJ64MC706","33FJ64MC710","33FJ64MC802","33FJ64MC804", +"33FJ128GP202","33FJ128GP204","33FJ128GP206","33FJ128GP306","33FJ128GP310","33FJ128GP706", +"33FJ128GP708","33FJ128GP710","33FJ128GP802","33FJ128GP804", +"33FJ128MC202","33FJ128MC204","33FJ128MC506","33FJ128MC510","33FJ128MC706","33FJ128MC708", +"33FJ128MC710","33FJ128MC802","33FJ128MC804", +"33FJ256GP506","33FJ256GP510","33FJ256GP710", +"33FJ256MC510","33FJ256MC710", +"33EP32GP502","33EP32GP503","33EP32GP504", +"33EP32MC202","33EP32MC203","33EP32MC204","33EP32MC502","33EP32MC503","33EP32MC504", +"33EP64GP502","33EP64GP503","33EP64GP504","33EP64GP506", +"33EP64MC202","33EP64MC203","33EP64MC204","33EP64MC206","33EP64MC502","33EP64MC503","33EP64MC504","33EP64MC506", +"33EP128GP502","33EP128GP504","33EP128GP506", +"33EP128MC202","33EP128MC204","33EP128MC206","33EP128MC502","33EP128MC504","33EP128MC506", +"33EP256GP502","33EP256GP504","33EP256GP506", +"33EP256MC202","33EP256MC204","33EP256MC206","33EP256MC502","33EP256MC504","33EP256MC506", +"33EP512GP502","33EP512GP504","33EP512GP506", +"33EP512MC202","33EP512MC204","33EP512MC206","33EP512MC502","33EP512MC504","33EP512MC506", +"AT90S1200","AT90S2313", +"AT90S8515","AT90S8535","ATmega48","ATmega8","ATmega88","ATmega8515", +"ATmega8535","ATmega16","ATmega164","ATmega168","ATmega32","ATmega324", +"ATmega328","ATmega64","ATmega644","ATmega1284", +"ATtiny11","ATtiny12","ATtiny13", +"ATtiny2313","ATtiny24","ATtiny25","ATtiny26","ATtiny261","ATtiny4313","ATtiny44","ATtiny45", +"ATtiny461","ATtiny48","ATtiny84","ATtiny85","ATtiny88","ATtiny861", +"2400","2401","2402","2404","2408","2416","2432","2464","24128","24256","24512","241024","241025", +"25010","25020","25040","25080","25160","25320","25640","25128","25256","25512","251024", +"95010","95020","95040","95080","95160","95320","95640","95128","95256","95512","95M01","95M02", +"251005","252005","254005","258005","251605", +"25X05","25X10","25X20","25X40","25X80","25X16","25X32","25X64","25X128","25Q40", +"93S46","93x46","93x46A","93S56","93x56","93x56A","93S66","93x66", "93x66A","93x76","93x76A","93x86","93x86A", +"DS2430","DS2431","DS2433","DS28EC20","DS1820", +"11010","11020","11040","11080","11160" +}; + +int Ndevices=sizeof(devices)/sizeof(char*); + +struct DEVICES DEVLIST[]={ +//-------------PIC10-16--------------------------------------------------------- + {"10F200,10F204,10F220", + PIC12,13.0,0,Read12F5xx,{0x100,5},0x40,Write12F5xx,{0x100,0xFF},0}, //256 + {"10F320", + PIC16,9.0,1,Read16Fxxx,{0x100,0,10,0},0x80,Write12F6xx,{0x100,0,-10},0}, //256, vpp, 3.3V + {"12C508,12C508A", + PIC12,13.0,0,Read12F5xx,{0x200,4},0x40,Write12C5xx,{0x200,0},0}, //512 + {"12F508,10F202,10F206,10F222", + PIC12,13.0,0,Read12F5xx,{0x200,5},0x40,Write12F5xx,{0x200,0x1FF},0}, //512 + {"16F54", + PIC12,13.0,0,Read12F5xx,{0x200,4},0x40,Write12F5xx,{0x200,-1},0}, //512, no osccal + {"10F322", + PIC16,9.0,1,Read16Fxxx,{0x200,0,10,0},0x80,Write12F6xx,{0x200,0,-10},0}, //512, vpp, 3.3V + {"12C509,12C509A", + PIC12,13.0,0,Read12F5xx,{0x400,4},0x40,Write12C5xx,{0x400,0},0}, //1K + {"12F509,12F510,16F505,16F506", + PIC12,13.0,0,Read12F5xx,{0x400,5},0x40,Write12F5xx,{0x400,0x3FF},0}, //1K + {"12F519,16F526,16F527", + PIC12,13.0,0,Read12F5xx,{0x440,8},0x60,Write12F5xx,{0x440,0x3FF},0}, //1K + 64 + {"12F529T39,12F529T48", + PIC12,13.0,0,Read12F5xx,{0x640,8},0x78,Write12F5xx,{0x640,0x5FF},0}, //1.5K + 64 + {"16F57,16F59", + PIC12,13.0,0,Read12F5xx,{0x800,4},0x40,Write12F5xx,{0x800,-1},0}, //2K + {"16F570", + PIC12,13.0,0,Read12F5xx,{0x840,8},0x70,Write12F5xx,{0x840,0x7FF},0}, //2K + 64 + {"16C83,16F83,16F83A", + PIC16,13.0,0,Read16Fxxx,{0x200,0x40,8,1},0x10,Write16F8x,{0x200,0x40,-10},0}, //512, 64, vdd + {"12C671,12CE673", + PIC16,13.0,0,Read16Fxxx,{0x400,0,0,0},0x100,0,{},0}, //1K, vpp + {"12F1501", + PIC16,8.5,1,Read16F1xxx,{0x400,0,11,0},0x100,Write16F1xxx,{0x400,0,0},0}, //1K, vpp, 3.3V + {"12F1571", + PIC16,8.5,1,Read16F1xxx,{0x400,0,12,0},0x200,Write16F1xxx,{0x400,0,0},0}, //1K, vpp, 3.3V + {"12F609,12F615,16F610", + PIC16,13.0,0,Read16Fxxx,{0x400,0,9,0},0x40,Write12F61x,{0x400,0,0},0}, //1K, vpp, cal1 + {"12F752", + PIC16,13.0,0,Read16Fxxx,{0x400,0,10,0},0x80,Write12F61x,{0x400,0,0},0}, //1K, vpp, cal1 + {"16C84,16F84,16F84A", + PIC16,13.0,0,Read16Fxxx,{0x400,0x40,8,1},0x10,Write16F8x,{0x400,0x40,-10},0}, //1K, 64, vdd + {"12F635", + PIC16,13.0,0,Read16Fxxx,{0x400,0x80,10,0},0x80,Write12F6xx,{0x400,0x80,-10},0}, //1K, 128, vpp, cal1 + cal2 + {"16F631", + PIC16,13.0,0,Read16Fxxx,{0x400,0x80,9,0},0x80,Write12F6xx,{0x400,0x80,-10},0}, //1K, 128, vpp, cal1 + {"12F629,12F675,16F630,16F676", + PIC16,13.0,0,Read16Fxxx,{0x400,0x80,8,0},0x20,Write12F62x,{0x400,0x80,-10},0}, //1K, 128, vpp + {"16F627", + PIC16,13.0,0,Read16Fxxx,{0x400,-0x80,8,0},0x10,Write16F62x,{0x400,0x80,-10},0}, //1K, 128, vpp, ee@0x2200 + {"16F627A", + PIC16,13.0,0,Read16Fxxx,{0x400,0x80,8,0},0x10,Write12F6xx,{0x400,0x80,-10},0}, //1K, 128, vpp + {"16F818", + PIC16,13.0,0,Read16Fxxx,{0x400,0x80,8,2},0x10,Write16F81x,{0x400,0x80,-10},0}, //1K, 128, vdd short delay + {"16F72", + PIC16,8.5,1,Read16Fxxx,{0x800,0,8,1},0x20,Write16F7x,{0x800,0,-10},0}, //2K, vdd, 3.3V + {"16F720,16F722,16F722A", + PIC16,13.0,0,Read16Fxxx,{0x800,0,11,0},0x100,Write16F72x,{0x800,0,0},0}, //2K, vpp, config1-2 + cal1-2, 3.3V + {"12C672,12CE674", + PIC16,13.0,0,Read16Fxxx,{0x800,0,0,0},0x100,0,{},0}, //2K, vpp + {"16F716", + PIC16,13.0,0,Read16Fxxx,{0x800,0,8,2},8,Write16F71x,{0x800,1,-10},0}, //2K, vdd + {"16F616,12F617", + PIC16,13.0,0,Read16Fxxx,{0x800,0,9,0},0x40,Write12F61x,{0x800,0,0},0}, //2K, vpp, cal1 + {"16F753", + PIC16,12.5,0,Read16Fxxx,{0x800,0,10,0},0x80,Write12F61x,{0x800,0,0},0}, //2K, vpp, cal1 + {"16LF1902,16F1503,16F1507,16F1512", + PIC16,8.5,1,Read16F1xxx,{0x800,0,11,0},0x200,Write16F1xxx,{0x800,0,0},0}, //2K, vpp, 3.3V + {"12F1572", + PIC16,8.5,1,Read16F1xxx,{0x800,0,12,0},0x200,Write16F1xxx,{0x800,0,0},0}, //2K, vpp, 3.3V + {"16F1703,16F1707", + PIC16,8.5,1,Read16F1xxx,{0x800,0,13,0},0x200,Write16F1xxx,{0x800,0,0},0}, //2K, vpp, 3.3V + {"12F1612,16F1613", + PIC16,8.5,1,Read16F1xxx,{0x800,0,13,4},0x200,Write16F1xxx,{0x800,0,4},0}, //2K, vpp, 3.3V + {"16F15213,16F15223,16F15243,16F15313,16F15323", + PIC16,8.5,1,Read16F18xxx,{0x800,0,0,0},0,Write16F18xxx,{0x800,0,0},0}, //2K, vpp, 3.3V, 8b commands + {"16F870,16F871,16F872", + PIC16,13.0,0,Read16Fxxx,{0x800,0x40,8,1},0x100,Write16F87x,{0x800,0x40,-10},0}, //2K, 64, vdd + {"16F628", + PIC16,13.0,0,Read16Fxxx,{0x800,-0x80,8,0},0x10,Write16F62x,{0x800,0x80,-10},0}, //2K, 128, vpp, ee@0x2200 + {"16F628A", + PIC16,13.0,0,Read16Fxxx,{0x800,0x80,8,0},0x10,Write12F6xx,{0x800,0x80,-10},0}, //2K, 128, vpp + {"16F882", + PIC16,13.0,0,Read16Fxxx,{0x800,0x80,10,0},0x80,Write16F88x,{0x800,0x80,-10},0}, //2K, 128, vpp, config2 + cal1 + {"16F819", + PIC16,13.0,0,Read16Fxxx,{0x800,0x100,8,2},0x10,Write16F81x,{0x800,0x100,-10},0}, //2K, 256, vdd short delay + {"12F683,16F684", + PIC16,13.0,0,Read16Fxxx,{0x800,0x100,9,0},0x40,Write12F6xx,{0x800,0x100,-10},0}, //2K, 256, vpp, cal1 + {"16F636,16F639,16F785", + PIC16,13.0,0,Read16Fxxx,{0x800,0x100,10,0},0x40,Write12F6xx,{0x800,0x100,-10},0}, //2K, 256, vpp, cal1 + cal2 + {"16F677,16F687", + PIC16,13.0,0,Read16Fxxx,{0x800,0x100,9,0},0x80,Write12F6xx,{0x800,0x100,-10},0}, //2K, 256, vpp, cal1 + {"12F1822,16F1823,16F1826", + PIC16,8.5,1,Read16F1xxx,{0x800,0x100,11,0},0x200,Write16F1xxx,{0x800,0x100,0},0}, //2K, 256, vpp, 3.3V + {"16F1782", + PIC16,8.5,1,Read16F1xxx,{0x800,0x100,19,0},0x200,Write16F1xxx,{0x800,0x100,0},0}, //2K, 256, vpp, 3.3V + {"16F18313,16F18323", + PIC16,8.5,1,Read16F1xxx,{0x800,0x100,11,0x1C},0x20,Write16F1xxx,{0x800,0x100,0x1C},0}, //2K, 256, vpp, 3.3V, new cmd + {"16F18013,16F18023", + PIC16,8.5,1,Read16F18xxx,{0x800,1,0,0},0,Write16F18xxx,{0x800,0x100,0},0}, //2K, 256, vpp, 3.3V, 8b commands + {"16F73,16F74", + PIC16,13.0,0,Read16Fxxx,{0x1000,0,8,1},0x20,Write16F7x,{0x1000,0,-10},0}, //4K, vdd + {"16F737,16F747", + PIC16,13.0,0,Read16Fxxx,{0x1000,0,9,2},9,Write16F7x,{0x1000,1,-10},0}, //4K, vdd short/no delay + {"16F721,16F723,16F723A,16F724", + PIC16,13.0,0,Read16Fxxx,{0x1000,0,11,0},0x100,Write16F72x,{0x1000,0,0},0}, //4K, vpp, config1-2 + cal1-2, 3.3V + {"16LF1903,16LF1904,16F1508,16F1513,16LF1554", + PIC16,8.5,1,Read16F1xxx,{0x1000,0,11,0},0x200,Write16F1xxx,{0x1000,0,0},0}, //4K, vpp, 3.3V + {"16F1574,16F1578", + PIC16,8.5,1,Read16F1xxx,{0x1000,0,12,0},0x200,Write16F1xxx,{0x1000,0,0},0}, //4K, vpp, 3.3V + {"16F1704,16F1708", + PIC16,8.5,1,Read16F1xxx,{0x1000,0,13,0},0x200,Write16F1xxx,{0x1000,0,0},0}, //4K, vpp, 3.3V + {"16F1614,16F1618", + PIC16,8.5,1,Read16F1xxx,{0x1000,0,13,4},0x200,Write16F1xxx,{0x1000,0,4},0}, //4K, vpp, 3.3V + {"16F1713", + PIC16,8.5,1,Read16F1xxx,{0x1000,0,17,0},0x200,Write16F1xxx,{0x1000,0,0},0}, //4K, vpp, 3.3V + {"16F1783,16F1784", + PIC16,8.5,1,Read16F1xxx,{0x1000,0,19,0},0x200,Write16F1xxx,{0x1000,0,0},0}, //4K, vpp, 3.3V + {"16F1764,16F1768", + PIC16,8.5,1,Read16F1xxx,{0x1000,0,20,0},0x200,Write16F1xxx,{0x1000,0,0},0}, //4K, vpp, 3.3V + {"16F1773", + PIC16,8.5,1,Read16F1xxx,{0x1000,0,24,0},0x200,Write16F1xxx,{0x1000,0,0},0}, //4K, vpp, 3.3V + {"16F15214,16F15224,16F15244,16F15254,16F15274,16F15324,16F15344,16F15354", + PIC16,8.5,1,Read16F18xxx,{0x1000,0,0,0},0,Write16F18xxx,{0x1000,0,0},0}, //4K, vpp, 3.3V, 8b commands + {"16F873A,16F874A", + PIC16,13.0,0,Read16Fxxx,{0x1000,0x80,8,1},0x100,Write16F87xA,{0x1000,0x80,1},0}, //4K, 128, vdd + {"16F873,16F874", + PIC16,13.0,0,Read16Fxxx,{0x1000,-0x80,8,1},0x100,Write16F87x,{0x1000,-0x80,-10},0}, //4K, 128, vdd, ee@0x2200 + {"16F685,16F689,16F690", + PIC16,13.0,0,Read16Fxxx,{0x1000,0x100,9,0},0x80,Write12F6xx,{0x1000,0x100,-10},0}, //4K, 256, vpp, cal1 + {"16F688", + PIC16,13.0,0,Read16Fxxx,{0x1000,0x100,9,0},0x40,Write12F6xx,{0x1000,0x100,-10},0}, //4K, 256, vpp, cal1 + {"16F883,16F884", + PIC16,13.0,0,Read16Fxxx,{0x1000,0x100,10,0},0x80,Write16F88x,{0x1000,0x100,-10},0}, //4K, 256, vpp, config2 + cal1 + {"16F648A", + PIC16,13.0,0,Read16Fxxx,{0x1000,0x100,8,0},0x10,Write12F6xx,{0x1000,0x100,-10},0}, //4K, 256, vpp + {"16F87,16F88", + PIC16,13.0,0,Read16Fxxx,{0x1000,0x100,9,2},0x10,Write16F81x,{0x1000,0x100,-10},0}, //4K, 256, vdd short delay + {"16F913,16F914", + PIC16,13.0,0,Read16Fxxx,{0x1000,0x100,10,0},0x40,Write12F6xx,{0x1000,0x100,-10},0}, //4K, 256, vpp, cal1 + cal2 + {"16F1933,16F1934,16F1824,16F1827,16F1828,12F1840", + PIC16,8.5,1,Read16F1xxx,{0x1000,0x100,11,0},0x200,Write16F1xxx,{0x1000,0x100,0},0}, //4K, 256, vpp, 3.3V + {"16F18324,16F18344", + PIC16,8.5,1,Read16F1xxx,{0x1000,0x100,11,0x1C},0x20,Write16F1xxx,{0x1000,0x100,0x1C},0}, //4K, 256, vpp, 3.3V, new cmd + {"16F17114,16F17124,16F17144,16F17154,16F17174,16F18014,16F18024,16F18044,16F18054,16F18074,16F18114,16F18124,16F18144,\ + 16F18154,16F18174,16F18424,16F18444", + PIC16,8.5,1,Read16F18xxx,{0x1000,1,0,0},0,Write16F18xxx,{0x1000,0x100,0},0}, //4K, 256, vpp, 3.3V, 8b commands + {"16F18854", + PIC16,8.5,1,Read16F18xxx,{0x1000,0x100,0,0x10},0,Write16F18xxx,{0x1000,0x100,0x10},0}, //4K, 256, vpp, 3.3V, 8b commands no DIA + {"16F76,16F77", + PIC16,13.0,0,Read16Fxxx,{0x2000,0,8,1},0x20,Write16F7x,{0x2000,0,-10},0}, //8K, vdd + {"16F767,16F777", + PIC16,13.0,0,Read16Fxxx,{0x2000,0,9,2},0x40,Write16F7x,{0x2000,1,-10},0}, //8K, vdd short delay + {"16F726,16F727,16F707", + PIC16,8.5,1,Read16Fxxx,{0x2000,0,11,0},0x100,Write16F72x,{0x2000,0,0},0}, //8K, vpp, config1-2 + cal1-2, 3.3V + {"16LF1906,16LF1907,16F1509,16F1454,16F1455,16F1459,16F1516,16F1517,16F1526,16LF1559", + PIC16,8.5,1,Read16F1xxx,{0x2000,0,11,0},0x200,Write16F1xxx,{0x2000,0,0},0}, //8K, vpp, 3.3V + {"16F1575,16F1579", + PIC16,8.5,1,Read16F1xxx,{0x2000,0,12,0},0x200,Write16F1xxx,{0x2000,0,0},0}, //8K, vpp, 3.3V + {"16F1705,16F1709", + PIC16,8.5,1,Read16F1xxx,{0x2000,0,13,0},0x200,Write16F1xxx,{0x2000,0,0},0}, //8K, vpp, 3.3V + {"16F1615,16F1619", + PIC16,8.5,1,Read16F1xxx,{0x2000,0,13,4},0x200,Write16F1xxx,{0x2000,0,4},0}, //8K, vpp, 3.3V + {"16F1716,16F1717", + PIC16,8.5,1,Read16F1xxx,{0x2000,0,17,0},0x200,Write16F1xxx,{0x2000,0,0},0}, //8K, vpp, 3.3V + {"16F1765,16F1769", + PIC16,8.5,1,Read16F1xxx,{0x2000,0,20,0},0x200,Write16F1xxx,{0x2000,0,0},0}, //8K, vpp, 3.3V + {"16F1776,16F1777", + PIC16,8.5,1,Read16F1xxx,{0x2000,0,24,0},0x200,Write16F1xxx,{0x2000,0,0},0}, //8K, vpp, 3.3V + {"16F15225,16F15245,16F15255,16F15275,16F15325,16F15345,16F15355,16F15375,16F15385", + PIC16,8.5,1,Read16F18xxx,{0x2000,0,0,0},0,Write16F18xxx,{0x2000,0,0},0}, //8K, vpp, 3.3V, 8b commands + {"16F876A,16F877A", + PIC16,13.0,0,Read16Fxxx,{0x2000,0x100,8,1},0x100,Write16F87xA,{0x2000,0x100,1},0}, //8K, 256, vdd + {"16F876,16F877", + PIC16,13.0,0,Read16Fxxx,{0x2000,-0x100,8,1},0x100,Write16F87x,{0x2000,-0x100,-10},0}, //8K, 256, vdd, ee@0x2200 + {"16F886,16F887", + PIC16,11.0,0,Read16Fxxx,{0x2000,0x100,10,0},0x80,Write16F88x,{0x2000,0x100,-10},0}, //8K, 256, vpp, config2 + cal1 + {"16F916,16F917,16F946", + PIC16,13.0,0,Read16Fxxx,{0x2000,0x100,10,0},0x40,Write12F6xx,{0x2000,0x100,-10},0}, //8K, 256, vpp, cal1 + cal2 + {"16F1936,16F1937,16F1946,16F1825,16F1829,16F1847", + PIC16,8.5,1,Read16F1xxx,{0x2000,0x100,11,0},0x200,Write16F1xxx,{0x2000,0x100,0},0}, //8K, 256, vpp, 3.3V + {"16F1786,16F1787", + PIC16,8.5,1,Read16F1xxx,{0x2000,0x100,19,0},0x200,Write16F1xxx,{0x2000,0x100,0},0}, //8K, 256, vpp, 3.3V + {"16F18325,16F18345", + PIC16,8.5,1,Read16F1xxx,{0x2000,0x100,11,0x1C},0x20,Write16F1xxx,{0x2000,0x100,0x1C},0}, //8K, 256, vpp, 3.3V, new cmd + {"16F17115,16F17125,16F17145,16F17155,16F17175,16F18015,16F18025,16F18045,16F18055,16F18075,16F18115,16F18125,16F18145,16F18155,16F18175,\ + 16F18425,16F18445,16F18455,16F19155,16F19175,16F19185,16F19195", + PIC16,8.5,1,Read16F18xxx,{0x2000,1,0,0},0,Write16F18xxx,{0x2000,0x100,0},0}, //8K, 256, vpp, 3.3V, 8b commands + {"16F18855,16F18875", + PIC16,8.5,1,Read16F18xxx,{0x2000,0x100,0,0x10},0,Write16F18xxx,{0x2000,0x100,0x10},0}, //8K, 256, vpp, 3.3V, 8b commands no DIA + {"16F1518,16F1519,16F1527", + PIC16,8.5,1,Read16F1xxx,{0x4000,0,11,0},0x200,Write16F1xxx,{0x4000,0,0},0}, //16K, vpp, 3.3V + {"16F1718,16F1719", + PIC16,8.5,1,Read16F1xxx,{0x4000,0,17,0},0x200,Write16F1xxx,{0x4000,0,0},0}, //16K, vpp, 3.3V + {"16F1778,16F1779", + PIC16,8.5,1,Read16F1xxx,{0x4000,0,24,0},0x200,Write16F1xxx,{0x4000,0,0},0}, //16K, vpp, 3.3V + {"16F15256,16F15276,16F15356,16F15376,16F15386", + PIC16,8.5,1,Read16F18xxx,{0x4000,0,0,0},0,Write16F18xxx,{0x4000,0,0},0}, //16K, vpp, 3.3V, 8b commands + {"16F1938,16F1939,16F1947", + PIC16,8.5,1,Read16F1xxx,{0x4000,0x100,11,0},0x200,Write16F1xxx,{0x4000,0x100,0},0}, //16K, 256, vpp, 3.3V + {"16F1788,16F1789", + PIC16,8.5,1,Read16F1xxx,{0x4000,0x100,19,0},0x200,Write16F1xxx,{0x4000,0x100,0},0}, //16K, 256, vpp, 3.3V + {"16F18326,16F18346", + PIC16,8.5,1,Read16F1xxx,{0x4000,0x100,11,0x1C},0x20,Write16F1xxx,{0x4000,0x100,0x1C},0}, //16K, 256, vpp, 3.3V, new cmd + {"16F17126,16F17146,16F17156,16F17176,16F18026,16F18046,16F18056,16F18076,16F18126,16F18146,16F18156,16F18176,\ + 16F18426,16F18446,16F18456,16F19156,16F19176,16F19186,16F19196", + PIC16,8.5,1,Read16F18xxx,{0x4000,1,0,0},0,Write16F18xxx,{0x4000,0x100,0},0}, //16K, 256, vpp, 3.3V, 8b commands + {"16F18856,16F18876", + PIC16,8.5,1,Read16F18xxx,{0x4000,0x100,0,0x10},0,Write16F18xxx,{0x4000,0x100,0x10},0}, //16K, 256, vpp, 3.3V, 8b commands no DIA + {"16F19197", + PIC16,8.5,1,Read16F18xxx,{0x8000,1,0,0},0,Write16F18xxx,{0x8000,0x100,0},0}, //32K, 256, vpp, 3.3V, 8b commands + {"16F18857,16F18877", + PIC16,8.5,1,Read16F18xxx,{0x8000,0x100,0,0x10},0,Write16F18xxx,{0x8000,0x100,0x10},0}, //32K, 256, vpp, 3.3V, 8b commands no DIA +//-------------PIC18--------------------------------------------------------- +// Read18Fx options: +// bit [3:0] +// 0 = vdd before vpp (12V) +// 1 = vdd before vpp (9V) +// 2 = low voltage entry with 32 bit key +// bit [7:4] +// 0 = normal control registers address +// 1 = new control registers address (18FxxK80) +// +// Write18Fx options: +// bit [3:0] +// 0 = vdd before vpp (12V) +// 1 = vdd before vpp (9V) +// 2 = low voltage entry with 32 bit key +// bit [7:4] +// 0 = normal eeprom write algoritm +// 1 = with unlock sequence 55 AA +// bit [11:8] +// 0 = 15ms erase delay, 1ms code write time, 5ms EE write, 5ms config write +// 1 = 550ms erase delay, 1.2ms code write time, no config or EEPROM +// 2 = 550ms erase delay, 3.4ms code write time, no config or EEPROM +// 3 = separate block erase with 5ms delay, 1ms code write, 5ms EE write, 5ms config write +// + new control registers address (18FxxK80) + {"18F1230", + PIC18,12,0,Read18Fx,{0x1000,0x80,0},0,Write18Fx,{0x1000,0x80,8,0x0F0F,0x8787,0},0}, //4K, 128, 8 + {"18F2221,18F4221", + PIC18,12,0,Read18Fx,{0x1000,0x100,0},0,Write18Fx,{0x1000,0x100,8,0x3F3F,0x8F8F,0},0}, //4K, 256, 8 + {"18F1220,18F2220,18F4220", + PIC18,12,0,Read18Fx,{0x1000,0x100,0},0,Write18Fx,{0x1000,0x100,8,0x10000,0x80,0x10},0}, //4K, 256, 8, EE with unlock + {"18F63J11,18F63J90,18F83J11,18F83J90", + PIC18,-1,1,Read18Fx,{0x2000,0,2},0,Write18Fx,{0x2000,0,64,0x0101,0x8080,0x202},0}, //8K, 0, 64, LV + {"18F1330", + PIC18,12,0,Read18Fx,{0x2000,0x80,0},0,Write18Fx,{0x2000,0x80,8,0x0F0F,0x8787,0},0}, //8K, 128, 8 + {"18F2321,18F4321", + PIC18,12,0,Read18Fx,{0x2000,0x100,0},0,Write18Fx,{0x2000,0x100,8,0x3F3F,0x8F8F,0},0}, //8K, 256, 8 + {"18F1320,18F2320,18F4320,18F2331,18F4331", + PIC18,12,0,Read18Fx,{0x2000,0x100,0},0,Write18Fx,{0x2000,0x100,8,0x10000,0x80,0x10},0}, //8K, 256, 8, EE with unlock + {"18F13K50,18F13K22", + PIC18,8.5,1,Read18Fx,{0x2000,0x100,1},0,Write18Fx,{0x2000,0x100,8,0x0F0F,0x8F8F,1},0}, //8K, 256, 8, 9V + {"18F23K20,18F43K20", + PIC18,8.5,1,Read18Fx,{0x2000,0x100,1},0,Write18Fx,{0x2000,0x100,16,0x0F0F,0x8F8F,1},0}, //8K, 256, 16, 9V + {"18F23K22,18F43K22", + PIC18,8.5,1,Read18Fx,{0x2000,0x100,1},0,Write18Fx,{0x2000,0x100,64,0x0F0F,0x8F8F,1},0}, //8K, 256, 64, 9V + {"18F2439,18F4439", + PIC18,12,0,Read18Fx,{0x3000,0x100,0},0,Write18Fx,{0x3000,0x100,8,0x10000,0x80,0x10},0}, //12K, 256, 8, EE with unlock + {"18F2410,18F4410", + PIC18,12,0,Read18Fx,{0x4000,0,0},0,Write18Fx,{0x4000,0,32,0x3F3F,0x8F8F,0},0}, //16K, 0, 32 + {"18F24J10,18F44J10,18F64J11,18F64J90,18F84J11,18F84J90", + PIC18,-1,1,Read18Fx,{0x4000,0,2},0,Write18Fx,{0x4000,0,64,0x0101,0x8080,0x202},0}, //16K, 0, 64, LV + {"18F24J11,18F24J50,18F44J11,18F44J50", + PIC18,-1,1,Read18Fx,{0x4000,0,2},0,Write18Fx,{0x4000,0,64,0x0101,0x8080,0x102},0}, //16K, 0, 64, LV + {"18F2420,18F2423,18F4420,18F4423,18F2480,18F4480", + PIC18,12,0,Read18Fx,{0x4000,0x100,0},0,Write18Fx,{0x4000,0x100,32,0x3F3F,0x8F8F,0},0}, //16K, 256, 32 + {"18F2431,18F4431,18F242,18F248,18F442,18F448", + PIC18,12,0,Read18Fx,{0x4000,0x100,0},0,Write18Fx,{0x4000,0x100,8,0x10000,0x80,0x10},0}, //16K, 256, 8, EE with unlock + {"18F2450,18F4450", + PIC18,12,0,Read18Fx,{0x4000,0,0},0,Write18Fx,{0x4000,0,16,0x3F3F,0x8F8F,0},0}, //16K, 0, 16 + {"18F14K50,18F14K22", + PIC18,8.5,1,Read18Fx,{0x4000,0x100,1},0,Write18Fx,{0x4000,0x100,16,0x0F0F,0x8F8F,1},0}, //16K, 256, 16, 9V + {"18F24K20,18F44K20", + PIC18,8.5,1,Read18Fx,{0x4000,0x100,1},0,Write18Fx,{0x4000,0x100,32,0x0F0F,0x8F8F,1},0}, //16K, 256, 32, 9V + {"18F24K22,18F44K22,18F24K50", + PIC18,8.5,1,Read18Fx,{0x4000,0x100,1},0,Write18Fx,{0x4000,0x100,64,0x0F0F,0x8F8F,1},0}, //16K, 256, 64, 9V + {"18F04Q40,18F14Q40,18F04Q41,18F14Q41,18F24Q71,18F44Q71,18F54Q71", + PIC18,8.5,1,Read18FKx,{0x4000,1,0x10},0,Write18FKx,{0x4000,0x200,0x10,0,0,0},0}, //16K, 256, --, LV + {"18F2455,18F2458,18F4455,18F4458", + PIC18,12,0,Read18Fx,{0x6000,0x100,0},0,Write18Fx,{0x6000,0x100,32,0x3F3F,0x8F8F,0},0}, //24K, 256, 32 + {"18F2539,18F4539", + PIC18,12,0,Read18Fx,{0x6000,0x100,0},0,Write18Fx,{0x6000,0x100,8,0x10000,0x80,0x10},0}, //24K, 256, 8, EE with unlock + {"18F2510,18F4510", + PIC18,12,0,Read18Fx,{0x8000,0,0},0,Write18Fx,{0x8000,0,32,0x3F3F,0x8F8F,0},0}, //32K, 0, 32 + {"18F25J10,18F45J10,18F65J10,18F65J11,18F65J50,18F65J90,18F85J10,18F85J11,18F85J50,18F85J90", + PIC18,-1,1,Read18Fx,{0x8000,0,2},0,Write18Fx,{0x8000,0,64,0x0101,0x8080,0x202},0}, //32K, 0, 64, LV + {"18F25J11,18F25J50,18F45J11,18F45J50", + PIC18,-1,1,Read18Fx,{0x8000,0,2},0,Write18Fx,{0x8000,0,64,0x0101,0x8080,0x102},0}, //32K, 0, 64, LV + {"18F252,18F258,18F452,18F458", + PIC18,12,0,Read18Fx,{0x8000,0x100,0},0,Write18Fx,{0x8000,0x100,8,0x10000,0x80,0x10},0}, //32K, 256, 8, EE with unlock + {"18F2550,18F2553,18F4550,18F4553,18F2520,18F2523,18F4520,18F4523,18F2580,18F4580", + PIC18,12,0,Read18Fx,{0x8000,0x100,0},0,Write18Fx,{0x8000,0x100,32,0x3F3F,0x8F8F,0},0}, //32K, 256, 32 + {"18F25K20,18F45K20", + PIC18,8.5,1,Read18Fx,{0x8000,0x100,1},0,Write18Fx,{0x8000,0x100,32,0x0F0F,0x8F8F,1},0}, //32K, 256, 32, 9V + {"18F25K22,18F45K22,18F25K50,18F45K50", + PIC18,8.5,1,Read18Fx,{0x8000,0x100,1},0,Write18Fx,{0x8000,0x100,64,0x0F0F,0x8F8F,1},0}, //32K, 256, 64, 9V + {"18F25K42,18F45K42,18F55K42", + PIC18,8.5,1,Read18FKx,{0x8000,1,0},0,Write18FKx,{0x8000,0x100,0,0,0,0},0}, //32K, 256, --, LV + {"18F05Q40,18F15Q40,18F05Q41,18F15Q41,18F25Q71,18F45Q71,18F55Q71", + PIC18,8.5,1,Read18FKx,{0x8000,1,0x10},0,Write18FKx,{0x8000,0x200,0x10,0,0,0},0}, //32K, 256, --, LV + {"18F25K80,18F45K80,18F65K80", + PIC18,8.5,1,Read18Fx,{0x8000,0x400,0x13},0,Write18Fx,{0x8000,0x400,64,0,0,0x303},0}, //32K, 1K, 64, 9V, xxK80 + {"18F8520", + PIC18,12,0,Read18Fx,{0x8000,0x400,0},0,Write18Fx,{0x8000,0x400,8,0x10000,0x0080,0x10},0},//32K, 1K, 8, EE with unlock + {"18F25Q43,18F45Q43,18F55Q43", + PIC18,8.5,1,Read18FKx,{0x8000,1,0x10},0,Write18FKx,{0x8000,0x400,0x10,0,0,0},0}, //32K, 1k, --, LV + {"18F25K83", + PIC18,8.5,1,Read18FKx,{0x8000,1,0},0,Write18FKx,{0x8000,0x400,0,0,0,0},0}, //32K, 1k, --, LV + {"18F2515,18F4515", + PIC18,12,0,Read18Fx,{0xC000,0,0},0,Write18Fx,{0xC000,0,64,0x3F3F,0x8F8F,0},0}, //48K, 0, 64 + {"18F65J15,18F85J15", + PIC18,-1,1,Read18Fx,{0xC000,0,2},0,Write18Fx,{0xC000,0,64,0x0101,0x8080,0x202},0}, //48K, 0, 64, LV + {"18F2525,18F2585,18F4525,18F4585", + PIC18,12,0,Read18Fx,{0xC000,0x400,0},0,Write18Fx,{0xC000,0x400,64,0x3F3F,0x8F8F,0},0}, //48K, 1K, 64 + {"18F2610,18F4610", + PIC18,12,0,Read18Fx,{0x10000,0,0},0,Write18Fx,{0x10000,0,64,0x3F3F,0x8F8F,0},0}, //64K, 0, 64 + {"18F26J11,18F26J13,18F26J50,18F26J53,18F46J11,18F46J13,18F46J50,18F46J53", + PIC18,-1,1,Read18Fx,{0x10000,0,2},0,Write18Fx,{0x10000,0,64,0x0101,0x8080,0x102},0}, //64K, 0, 64, LV + {"18F66J60,18F86J60,18F96J60,18F66J10,18F66J11,18F66J50,18F66J90,18F66J93,18F86J10,18F86J11,18F86J50,18F86J72,18F86J90,18F86J93", + PIC18,-1,1,Read18Fx,{0x10000,0,2},0,Write18Fx,{0x10000,0,64,0x0101,0x8080,0x202},0}, //64K, 0, 64, LV + {"18F2620,18F2680,18F4620,18F4680", + PIC18,12,0,Read18Fx,{0x10000,0x400,0},0,Write18Fx,{0x10000,0x400,64,0x3F3F,0x8F8F,0},0},//64K, 1K, 64 + {"18F26K20,18F46K20,18F26K22,18F46K22,18F26K50,18F46K50", + PIC18,12,0,Read18Fx,{0x10000,0x100,1},0,Write18Fx,{0x10000,0x100,64,0x0F0F,0x8F8F,1},0},//64K, 256, 64, 9V + {"18F06Q40,18F16Q40,18F06Q41,18F16Q41,18F26Q71,18F46Q71,18F56Q71", + PIC18,8.5,1,Read18FKx,{0x10000,1,0x10},0,Write18FKx,{0x10000,0x200,0x10,0,0,0},0}, //64K, 256, --, LV + {"18F26K80,18F46K80,18F66K80", + PIC18,8.5,1,Read18Fx,{0x10000,0x400,0x13},0,Write18Fx,{0x10000,0x400,64,0,0,0x303},0}, //64K, 1K, 64, 9V, xxK80 + {"18F26Q43,18F46Q43,18F56Q43", + PIC18,8.5,1,Read18FKx,{0x10000,1,0x10},0,Write18FKx,{0x10000,0x400,0x10,0,0,0},0}, //64K, 1k, --, LV + {"18F26K42,18F46K42,18F56K42,18F26K83", + PIC18,8.5,1,Read18FKx,{0x10000,1,0},0,Write18FKx,{0x10000,0x400,0,0,0,0},0}, //64K, 1k, --, LV + {"18F26Q83,18F26Q84,18F46Q83,18F46Q84,18F56Q83,18F56Q84", + PIC18,8.5,1,Read18FKx,{0x10000,1,0x20},0,Write18FKx,{0x10000,0x400,0x20,0,0,0},0}, //64K, 1k, --, LV + {"18F2682,18F4682", + PIC18,12,0,Read18Fx,{0x14000,0x400,0},0,Write18Fx,{0x14000,0x400,64,0x3F3F,0x8F8F,0},0},//80K, 1K, 64 + {"18F66J65,18F86J65,18F96J65,18F66J15,18F66J16,18F66J55,18F86J15,18F86J16,18F86J55", + PIC18,-1,1,Read18Fx,{0x18000,0,2},0,Write18Fx,{0x18000,0,64,0x0101,0x8080,0x202},0}, //96K, 0, 64, LV + {"18F2685,18F4685", + PIC18,12,0,Read18Fx,{0x18000,0x400,0},0,Write18Fx,{0x18000,0x400,64,0x3F3F,0x8F8F,0},0},//96K, 1K, 64 + {"18F27J13,18F27J53,18F47J13,18F47J53,18F67J10,18F87J10", + PIC18,-1,1,Read18Fx,{0x20000,0,2},0,Write18Fx,{0x20000,0,64,0x0101,0x8080,0x102},0}, //128K, 0, 64, LV + {"18F67J60,18F87J60,18F97J60,18F67J11,18F67J50,18F67J90,18F67J93,18F87J11,18F87J50,18F87J72,18F87J90,18F87J93", + PIC18,-1,1,Read18Fx,{0x20000,0,2},0,Write18Fx,{0x20000,0,64,0x0101,0x8080,0x202},0}, //128K, 0, 64, LV + {"18F8722", + PIC18,12,0,Read18Fx,{0x20000,0x400,0},0,Write18Fx,{0x20000,0x400,64,0xFFFF,0x8787,0},0},//128K, 1K, 64 + {"18F27Q43,18F47Q43,18F57Q43", + PIC18,8.5,1,Read18FKx,{0x20000,1,0x10},0,Write18FKx,{0x20000,0x400,0x10,0,0,0},0}, //128K, 1k, --, LV + {"18F27K42,18F47K42,18F57K42", + PIC18,8.5,1,Read18FKx,{0x20000,1,0},0,Write18FKx,{0x20000,0x400,0,0,0,0},0}, //128K, 1k, --, LV + {"18F27Q83,18F27Q84,18F47Q83,18F47Q84,18F57Q83,18F57Q84", + PIC18,8.5,1,Read18FKx,{0x20000,1,0x20},0,Write18FKx,{0x20000,0x400,0x20,0,0,0},0}, //128K, 1k, --, LV +//-------------PIC24--------------------------------------------------------- +// options: +// bit [3:0] +// 0 = low voltage ICSP entry +// 1 = High voltage ICSP entry (6V) +// 2 = High voltage ICSP entry (12V) + PIC30F sequence (additional NOPs) +// 3 = low voltage ICSP entry (5V power supply) +// bit [7:4] +// 0 = config area in the last 2 program words +// 1 = config area in the last 3 program words +// 2 = config area in the last 4 program words +// 3 = 0xF80000 to 0xF80010 except 02 (24F) +// 4 = 0xF80000 to 0xF80016 (24H-33F) +// 5 = 0xF80000 to 0xF8000C (x16 bit, 30F) +// 6 = 0xF80000 to 0xF8000E (30FSMPS) +// bit [11:8] +// 0 = code erase word is 0x4064, row write is 0x4004 +// 1 = code erase word is 0x404F, row write is 0x4001 +// 2 = code erase word is 0x407F, row write is 0x4001, 55AA unlock and external timing (2 ms) +// 3 = code erase word is 0x407F, row write is 0x4001, 55AA unlock and external timing (200 ms) +// bit [15:12] +// 0 = eeprom erase word is 0x4050, write word is 0x4004 +// 1 = eeprom erased with bulk erase, write word is 0x4004 +// 2 = eeprom erased with special sequence, write word is 0x4004 +// bit [19:16] +// 0 = config write is 0x4000 +// 1 = config write is 0x4003 +// 2 = config write is 0x4004 +// 3 = config write is 0x4008 + {"24F04KA200,24F04KA201", + PIC24,6,1,Read24Fx,{0xB00,0,0x31,0x05BE},0x800,Write24Fx,{0xB00,0,0x20031,0x05BE,32},2.0}, //1.375KW, HV + {"24F08KA101,24F08KA102", + PIC24,6,1,Read24Fx,{0x1600,0x200,0x31,0x05BE},0x800,Write24Fx,{0x1600,0x200,0x20031,0x05BE,32},2.0}, //2.75KW, HV, 512 + {"24F16KA101,24F16KA102", + PIC24,6,1,Read24Fx,{0x2C00,0x200,0x31,0x05BE},0x800,Write24Fx,{0x2C00,0x200,0x20031,0x05BE,32},2.0}, //5.5KW, HV, 512 + {"24FJ16GA002,24FJ16GA004", + PIC24,-1,1,Read24Fx,{0x2C00,0,0,0x05BE},0x800,Write24Fx,{0x2C00,0,0x10100,0x05BE,64},2.0}, //5.5KW + {"24FJ32GA002,24FJ32GA004", + PIC24,-1,1,Read24Fx,{0x5800,0,0,0x05BE},0x800,Write24Fx,{0x5800,0,0x10100,0x05BE,64},2.0}, //11KW + {"24FJ32GA102,24FJ32GA104,24FJ32GB002,24FJ32GB004", + PIC24,-1,1,Read24Fx,{0x5800,0,0x20,0x07F0},0x800,Write24Fx,{0x5800,0,0x10120,0x07F0,64},2.0}, //11KW 4 Config Word + {"24FJ48GA002,24FJ48GA004", + PIC24,-1,1,Read24Fx,{0x8400,0,0,0x05BE},0x800,Write24Fx,{0x8400,0,0x10100,0x05BE,64},2.0}, //16.5KW + {"24FJ64GA002,24FJ64GA004,24FJ64GA006,24FJ64GA008,24FJ64GA010", + PIC24,-1,1,Read24Fx,{0xAC00,0,0,0x05BE},0x800,Write24Fx,{0xAC00,0,0x10100,0x05BE,64},2.0}, //22KW + {"24FJ64GA102,24FJ64GA104,24FJ64GB002,24FJ64GB004", + PIC24,-1,1,Read24Fx,{0xAC00,0,0x20,0x07F0},0x800,Write24Fx,{0xAC00,0,0x10120,0x07F0,64},2.0}, //22KW 4 Config Word + {"24FJ64GA306,24FJ64GA308,24FJ64GA310,24FJ64GC006,24FJ64GC008,24FJ64GC010", + PIC24,-1,1,Read24Fx,{0xAC00,0,0x120,0x07F0},0x800,Write24Fx,{0xAC00,0,0x110120,0x07F0,64},2.0}, //22KW 4 Config Word new TABLPAG + {"24FJ64GB106,24FJ64GB108,24FJ64GB110", + PIC24,-1,1,Read24Fx,{0xAC00,0,0x10,0x07F0},0x800,Write24Fx,{0xAC00,0,0x10110,0x07F0,64},2.0}, //22KW 3 Config Word + {"24FJ96GA006,24FJ96GA008,24FJ96GA010", + PIC24,-1,1,Read24Fx,{0x10000,0,0,0x05BE},0x800,Write24Fx,{0x10000,0,0x10100,0x05BE,64},2.0}, //32KW + {"24FJ128GA006,24FJ128GA008,24FJ128GA010", + PIC24,-1,1,Read24Fx,{0x15800,0,0,0x05BE},0x800,Write24Fx,{0x15800,0,0x10100,0x05BE,64},2.0}, //44KW + {"24FJ128GA106,24FJ128GA108,24FJ128GA110,24FJ128GB106,24FJ128GB108,24FJ128GB110", + PIC24,-1,1,Read24Fx,{0x15800,0,0x10,0x07F0},0x800,Write24Fx,{0x15800,0,0x10110,0x07F0,64},2.0}, //44KW 3 Config Word + {"24FJ128GA306,24FJ128GA308,24FJ128GA310,24FJ128GB206,24FJ128GB210,24FJ128GC006,24FJ128GC008,\ +24FJ128GC010,24FJ128DA106,24FJ128DA110,24FJ128DA206,24FJ128DA210", + PIC24,-1,1,Read24Fx,{0x15800,0,0x120,0x07F0},0x800,Write24Fx,{0x15800,0,0x110120,0x07F0,64},2.0}, //44KW 4 Config Word new TABLPAG + {"24FJ192GA106,24FJ192GA108,24FJ192GA110,24FJ192GB106,24FJ192GB108,24FJ192GB110", + PIC24,-1,1,Read24Fx,{0x20C00,0,0x10,0x07F0},0x800,Write24Fx,{0x20C00,0,0x10110,0x07F0,64},2.0}, //68KW 3 Config Word + {"24FJ256GA106,24FJ256GA108,24FJ256GA110,24FJ256GB106,24FJ256GB108,24FJ256GB110", + PIC24,-1,1,Read24Fx,{0x2AC00,0,0x10,0x07F0},0x800,Write24Fx,{0x2AC00,0,0x10110,0x07F0,64},2.0}, //88KW 3 Config Word + {"24FJ256DA106,24FJ256DA110,24FJ256DA206,24FJ256DA210,24FJ256GB206,24FJ256GB210", + PIC24,-1,1,Read24Fx,{0x2AC00,0,0x120,0x07F0},0x800,Write24Fx,{0x2AC00,0,0x110120,0x07F0,64},2.0}, //88KW 4 Config Word new TABLPAG + {"33FJ06GS101,33FJ06GS102,33FJ06GS202", + PIC24,-1,1,Read24Fx,{0x1000,0,0x40,0x07F0},0x800,Write24Fx,{0x1000,0,0x00140,0x07F0,64},2.0}, //2KW + {"24HJ12GP201,24HJ12GP202,33FJ12GP201,33FJ12GP202,33FJ12MC201,33FJ12MC202", + PIC24,-1,1,Read24Fx,{0x2000,0,0x40,0x07F0},0x800,Write24Fx,{0x2000,0,0x00140,0x07F0,64},2.0}, //4KW + {"24HJ16GP304,33FJ16GP304,33FJ16GS402,33FJ16GS404,33FJ16GS502,33FJ16GS504,33FJ16MC304", + PIC24,-1,1,Read24Fx,{0x2C00,0,0x40,0x07F0},0x800,Write24Fx,{0x2C00,0,0x00140,0x07F0,64},2.0}, //5.5KW + {"24HJ32GP202,24HJ32GP204,24HJ32GP302,24HJ32GP304,33FJ32GP202,33FJ32GP204,33FJ32GP302,\ +33FJ32GP304,33FJ32GS406,33FJ32GS606,33FJ32GS608,33FJ32GS610,33FJ32MC202,33FJ32MC204,33FJ32MC302,33FJ32MC304", + PIC24,-1,1,Read24Fx,{0x5800,0,0x40,0x07F0},0x1000,Write24Fx,{0x5800,0,0x00140,0x07F0,64},2.0}, //11KW + {"24HJ64GP202,24HJ64GP204,24HJ64GP206,24HJ64GP210,24HJ64GP502,24HJ64GP504,24HJ64GP506,24HJ64GP510,\ +33FJ64GP202,33FJ64GP204,33FJ64GP206,33FJ64GP306,33FJ64GP310,33FJ64GP706,33FJ64GP708,33FJ64GP710,33FJ64GP802,\ +33FJ64GP804,33FJ64GS406,33FJ64GS606,33FJ64GS608,33FJ64GS610,33FJ64MC202,33FJ64MC204,33FJ64MC506,33FJ64MC508,33FJ64MC510,\ +33FJ64MC706,33FJ64MC710,33FJ64MC802,33FJ64MC804", + PIC24,-1,1,Read24Fx,{0xAC00,0,0x40,0x07F0},0x1000,Write24Fx,{0xAC00,0,0x00140,0x07F0,64},2.0}, //22KW + {"24HJ128GP202,24HJ128GP204,24HJ128GP206,24HJ128GP210,24HJ128GP306,24HJ128GP310,24HJ128GP502,\ +24HJ128GP504,24HJ128GP506,24HJ128GP510,\ +33FJ128GP202,33FJ128GP204,33FJ128GP206,33FJ128GP306,33FJ128GP310,33FJ128GP706,33FJ128GP708,33FJ128GP710,\ +33FJ128GP802,33FJ128GP804,33FJ128MC202,33FJ128MC204,33FJ128MC506,33FJ128MC510,33FJ128MC706,33FJ128MC708,\ +33FJ128MC710,33FJ128MC802,33FJ128MC804", + PIC24,-1,1,Read24Fx,{0x15800,0,0x40,0x07F0},0x1000,Write24Fx,{0x15800,0,0x00140,0x07F0,64},2.0}, //44KW + {"24HJ256GP206,24HJ256GP210,24HJ256GP610,\ +33FJ256GP506,33FJ256GP510,33FJ256GP710,33FJ256MC510,33FJ256MC710", + PIC24,-1,1,Read24Fx,{0x2AC00,0,0x40,0x07F0},0x1000,Write24Fx,{0x2AC00,0,0x00140,0x07F0,64},2.0}, //88KW + {"24EP32GP202,24EP32GP203,24EP32GP204,33EP32GP502,33EP32GP503,33EP32GP504,\ +24EP32MC202,24EP32MC203,24EP32MC204,33EP32MC202,33EP32MC203,33EP32MC204,33EP32MC502,33EP32MC503,33EP32MC504", + PIC24,-1,1,Read24Ex,{0x5800,0,0,0x0FF0},0x1000,Write24Ex,{0x5800,0,0,0,0,0},2.0}, //11KW 10 Config Word + {"24EP64GP202,24EP64GP203,24EP64GP204,24EP64GP206,33EP64GP502,33EP64GP503,33EP64GP504,33EP64GP506,\ +24EP64MC202,24EP64MC203,24EP64MC204,24EP64MC206,33EP64MC202,33EP64MC203,33EP64MC204,33EP64MC206,\ +33EP64MC502,33EP64MC503,33EP64MC504,33EP64MC506", + PIC24,-1,1,Read24Ex,{0xB000,0,0,0x0FF0},0x1000,Write24Ex,{0xB000,0,0,0,0,0},2.0}, //22.5KW 10 Config Word + {"24EP128GP202,24EP128GP204,24EP128GP206,33EP128GP502,33EP128GP504,33EP128GP506,\ +24EP128MC202,24EP128MC204,24EP128MC206,33EP128MC202,33EP128MC204,33EP128MC206,\ +33EP128MC502,33EP128MC504,33EP128MC506", + PIC24,-1,1,Read24Ex,{0x15800,0,0,0x0FF0},0x1000,Write24Ex,{0x15800,0,0,0,0,0},2.0}, //44KW 10 Config Word + {"24EP256GP202,24EP256GP204,24EP256GP206,33EP256GP502,33EP256GP504,33EP256GP506,\ +24EP256MC202,24EP256MC204,24EP256MC206,33EP256MC202,33EP256MC204,33EP256MC206,\ +33EP256MC502,33EP256MC504,33EP256MC506", + PIC24,-1,1,Read24Ex,{0x2B000,0,0,0x0FF0},0x1000,Write24Ex,{0x2B000,0,0,0,0,0},2.0}, //88KW 10 Config Word + {"24EP512GP202,24EP512GP204,24EP512GP206,33EP512GP502,33EP512GP504,33EP512GP506,\ +24EP512MC202,24EP512MC204,24EP512MC206,33EP512MC202,33EP512MC204,33EP512MC206,\ +33EP512MC502,33EP512MC504,33EP512MC506", + PIC24,-1,1,Read24Ex,{0x56000,0,0,0x0FF0},0x1000,Write24Ex,{0x56000,0,0,0,0,0},2.0}, //175KW 10 Config Word + {"30F1010", + PIC24,-1,0,Read24Fx,{0x1000,0,0x63,0x05BE},0x600,Write24Fx,{0x1000,0,0x30263,0x05BE,32},2.0}, //1KW, LV5V + {"30F2020,30F2023", + PIC24,-1,0,Read24Fx,{0x2000,0,0x63,0x05BE},0x600,Write24Fx,{0x2000,0,0x30263,0x05BE,32},2.0}, //2KW, LV5V + {"30F2010", + PIC24,12,0,Read24Fx,{0x2000,0x400,0x52,0x05BE},0x600,Write24Fx,{0x2000,0x400,0x31252,0x05BE,32},2.0}, //4KW, 1K, HV12 + {"30F2011,30F2012", + PIC24,12,0,Read24Fx,{0x2000,0,0x52,0x05BE},0x600,Write24Fx,{0x2000,0,0x31252,0x05BE,32},2.0}, //4KW, HV12 + {"30F3010,30F3011,30F3012,30F3013,30F3014", + PIC24,12,0,Read24Fx,{0x4000,0x400,0x52,0x05BE},0x600,Write24Fx,{0x4000,0x400,0x31252,0x05BE,32},2.0}, //8KW, 1K, HV12 + {"30F4011,30F4012,30F4013", + PIC24,12,0,Read24Fx,{0x8000,0x400,0x52,0x05BE},0x600,Write24Fx,{0x8000,0x400,0x31252,0x05BE,32},2.0}, //16KW, 1K, HV12 + {"30F5011,30F5013,30F5015,30F5016", + PIC24,12,0,Read24Fx,{0xB000,0x400,0x52,0x05BE},0x600,Write24Fx,{0xB000,0x400,0x31252,0x05BE,32},2.0}, //22KW, 1K, HV12 + {"30F6011,30F6013", + PIC24,12,0,Read24Fx,{0x16000,0x800,0x52,0x05BE},0x600,Write24Fx,{0x16000,0x800,0x31252,0x05BE,32},2.0}, //44KW, 2K, HV12 + {"30F6010,30F6012,30F6014,30F6015", + PIC24,12,0,Read24Fx,{0x18000,0x1000,0x52,0x05BE},0x600,Write24Fx,{0x18000,0x1000,0x31252,0x05BE,32},2.0}, //49KW, 4K, HV12 +//-------------PIC32--------------------------------------------------------- +// options: +// {"32MX270F256", +// PIC32,-1,1,Read32x,{0x40000,0},0x800,0,{0,0,0,0,0},0.0}, //256K +//-------------ATMEL--------------------------------------------------------- + {"AT90S1200", + AVR,-1,0,ReadAT,{0x400,0x40,0},0,WriteAT,{0x400,0x40,0,0},0}, //1K, 64 + {"ATtiny11", + AVR,12,0,ReadAT_HV,{0x400,0,LOCK+FUSE+CAL},0,WriteAT_HV,{0x400,0,0,0},0}, //1K, HV + {"ATtiny12", + AVR,12,0,ReadAT_HV,{0x400,0x40,LOCK+FUSE+CAL},0,WriteAT_HV,{0x400,0x40,0,0},0}, //1K, 64, HV + {"ATtiny13", + AVR,12,0,ReadAT_HV,{0x400,0x40,LOCK+FUSE+FUSE_H+CAL},0,WriteAT_HV,{0x400,0x40,16,0},0}, //1K, 64, HV + {"AT90S2313", + AVR,-1,0,ReadAT,{0x800,0x80,0},0,WriteAT,{0x800,0x80,0,0},0}, //2K, 128 + {"ATtiny2313", + AVR,-1,0,ReadAT,{0x800,0x80,LOCK+FUSE+FUSE_H+FUSE_X+CAL},0,WriteATmega,{0x800,0x80,16,0},0},//2K, 128 + {"ATtiny24,ATtiny25", + AVR,12,0,ReadAT_HV,{0x800,0x80,LOCK+FUSE+FUSE_H+FUSE_X+CAL},0,WriteAT_HV,{0x800,0x80,16,0},0}, //2K, 128, HV + {"ATtiny26", + AVR,-1,0,ReadAT,{0x800,0x80,LOCK+FUSE+FUSE_H+CAL},0,WriteATmega,{0x800,0x80,16,0},0}, //2K, 128 + {"ATtiny261", + AVR,-1,0,ReadAT,{0x800,0x80,LOCK+FUSE+FUSE_H+FUSE_X+CAL},0,WriteATmega,{0x800,0x80,16,0},0}, //2K, 128 + {"ATtiny44,ATtiny45", + AVR,12,0,ReadAT_HV,{0x1000,0x100,LOCK+FUSE+FUSE_H+FUSE_X+CAL},0,WriteAT_HV,{0x1000,0x100,32,0},0}, //4K, 256, HV + {"ATtiny461,ATtiny4313,ATmega48", + AVR,-1,0,ReadAT,{0x1000,0x100,LOCK+FUSE+FUSE_H+FUSE_X+CAL},0,WriteATmega,{0x1000,0x100,32,0},0}, //4K, 256 + {"ATtiny48", + AVR,-1,0,ReadAT,{0x1000,0x40,LOCK+FUSE+FUSE_H+FUSE_X+CAL},0,WriteATmega,{0x1000,0x40,32,0},0}, //4K, 64 + {"ATtiny88", + AVR,-1,0,ReadAT,{0x2000,0x40,LOCK+FUSE+FUSE_H+FUSE_X+CAL},0,WriteATmega,{0x2000,0x40,32,0},0}, //8K, 64 + {"AT90S8515,AT90S8535", + AVR,-1,0,ReadAT,{0x2000,0x100,0},0,WriteAT,{0x2000,0x100,0,0},0}, //8K, 256 + {"ATmega8,ATmega8515,ATmega8535", + AVR,-1,0,ReadAT,{0x2000,0x200,LOCK+FUSE+FUSE_H+CAL},0,WriteATmega,{0x2000,0x200,32,0},0}, //8K, 512 + {"ATmega88,ATtiny861", + AVR,-1,0,ReadAT,{0x2000,0x200,LOCK+FUSE+FUSE_H+FUSE_X+CAL},0,WriteATmega,{0x2000,0x200,32,0},0}, //8K, 512 + {"ATtiny84,ATtiny85", + AVR,12,0,ReadAT_HV,{0x2000,0x200,LOCK+FUSE+FUSE_H+FUSE_X+CAL},0,WriteAT_HV,{0x2000,0x200,32,0},0}, //8K, 512, HV + {"ATmega16", + AVR,-1,0,ReadAT,{0x4000,0x200,LOCK+FUSE+FUSE_H+CAL},0,WriteATmega,{0x4000,0x200,64,0},0}, //16K, 512 + {"ATmega164,ATmega168", + AVR,-1,0,ReadAT,{0x4000,0x200,LOCK+FUSE+FUSE_H+FUSE_X+CAL},0,WriteATmega,{0x4000,0x200,64,0},0}, //16K, 512 + {"ATmega32", + AVR,-1,0,ReadAT,{0x8000,0x400,LOCK+FUSE+FUSE_H+CAL},0,WriteATmega,{0x8000,0x400,64,0},0}, //32K, 1K + {"ATmega324,ATmega328", + AVR,-1,0,ReadAT,{0x8000,0x400,LOCK+FUSE+FUSE_H+FUSE_X+CAL},0,WriteATmega,{0x8000,0x400,64,0},0}, //32K, 1K + {"ATmega64,ATmega644", + AVR,-1,0,ReadAT,{0x10000,0x800,LOCK+FUSE+FUSE_H+FUSE_X+CAL},0,WriteATmega,{0x10000,0x800,128,0},0}, //64K, 2K + {"ATmega1284", + AVR,-1,0,ReadAT,{0x20000,0x1000,LOCK+FUSE+FUSE_H+FUSE_X+CAL},0,WriteATmega,{0x20000,0x1000,128,0},0},//128K, 4K +//-------------I2C--------------------------------------------------------- + {"2400", + I2CEE,-1,0,ReadI2C,{0x10,0},0,WriteI2C,{0x10,0,1},0}, //16, 1B addr. + {"2401", + I2CEE,-1,0,ReadI2C,{0x80,0},0,WriteI2C,{0x80,0,8},0}, //128, 1B addr. + {"2402", + I2CEE,-1,0,ReadI2C,{0x100,0},0,WriteI2C,{0x100,0,8},0}, //256, 1B addr. + {"2404", + I2CEE,-1,0,ReadI2C,{0x200,0},0,WriteI2C,{0x200,0,16},0}, //512, 1B addr. + {"2408", + I2CEE,-1,0,ReadI2C,{0x400,0},0,WriteI2C,{0x400,0,16},0}, //1K, 1B addr. + {"2416", + I2CEE,-1,0,ReadI2C,{0x800,0},0,WriteI2C,{0x800,0,16},0}, //2K, 1B addr. + {"2432", + I2CEE,-1,0,ReadI2C,{0x1000,1},0,WriteI2C,{0x1000,1,32},0}, //4K, 2B addr. + {"2464", + I2CEE,-1,0,ReadI2C,{0x2000,1},0,WriteI2C,{0x2000,1,32},0}, //8K, 2B addr. + {"24128", + I2CEE,-1,0,ReadI2C,{0x4000,1},0,WriteI2C,{0x4000,1,64},0}, //16K, 2B addr. + {"24256", + I2CEE,-1,0,ReadI2C,{0x8000,1},0,WriteI2C,{0x8000,1,64},0}, //32K, 2B addr. + {"24512", + I2CEE,-1,0,ReadI2C,{0x10000,1},0,WriteI2C,{0x10000,1,128},0}, //64K, 2B addr. + {"241024", + I2CEE,-1,0,ReadI2C,{0x20000,0x201},0,WriteI2C,{0x20000,0x201,256},0}, //128K, 2B addr. + {"241025", + I2CEE,-1,0,ReadI2C,{0x20000,0x841},0,WriteI2C,{0x20000,0x841,128},0}, //128K, 2B addr. +//-------------Microwire EEPROM--------------------------------------------------------- + {"93S46", + UWEE,-1,0,Read93x,{0x80,6,0},0,Write93Sx,{0x80,6,8},0}, //128, 6b addr, 4W page + {"93x46", + UWEE,-1,0,Read93x,{0x80,6,0},0,Write93Cx,{0x80,6,0},0}, //128, 6b addr + {"93x46A", + UWEE,-1,0,Read93x,{0x80,7,1},0,Write93Cx,{0x80,7,1},0}, //128, 6b addr x8 + {"93S56", + UWEE,-1,0,Read93x,{0x100,8,0},0,Write93Sx,{0x100,8,8},0}, //256, 8b addr, 4W page + {"93x56", + UWEE,-1,0,Read93x,{0x100,8,0},0,Write93Cx,{0x100,8,0},0}, //256, 8b addr + {"93x56A", + UWEE,-1,0,Read93x,{0x100,9,1},0,Write93Cx,{0x100,9,1},0}, //256, 8b addr x8 + {"93S66", + UWEE,-1,0,Read93x,{0x200,8,0},0,Write93Sx,{0x200,8,8},0}, //512, 8b addr, 4W page + {"93x66", + UWEE,-1,0,Read93x,{0x200,8,0},0,Write93Cx,{0x200,8,0},0}, //512, 8b addr + {"93x66A", + UWEE,-1,0,Read93x,{0x200,9,1},0,Write93Cx,{0x200,9,1},0}, //512, 8b addr x8 + {"93x76", + UWEE,-1,0,Read93x,{0x400,10,0},0,Write93Cx,{0x400,10,0},0}, //1k, 10b addr + {"93x76A", + UWEE,-1,0,Read93x,{0x400,11,1},0,Write93Cx,{0x400,11,1},0}, //1k, 10b addr x8 + {"93x86", + UWEE,-1,0,Read93x,{0x800,10,0},0,Write93Cx,{0x800,10,0},0}, //2k, 10b addr + {"93x86A", + UWEE,-1,0,Read93x,{0x800,11,1},0,Write93Cx,{0x800,11,1},0}, //2k, 10b addr x8 +//-------------SPI--------------------------------------------------------- + {"25010,95010", + SPIEE,-1,0,Read25xx,{0x80},0,Write25xx,{0x80,16},0}, //128 + {"25020,95020", + SPIEE,-1,0,Read25xx,{0x100},0,Write25xx,{0x100,16},0}, //256 + {"25040,95040", + SPIEE,-1,0,Read25xx,{0x200},0,Write25xx,{0x200,16},0}, //512 + {"25080,95080", + SPIEE,-1,0,Read25xx,{0x400},0,Write25xx,{0x400,16},0}, //1K + {"25160,95160", + SPIEE,-1,0,Read25xx,{0x800},0,Write25xx,{0x800,16},0}, //2K + {"25320,95320", + SPIEE,-1,0,Read25xx,{0x1000},0,Write25xx,{0x1000,32},0}, //4K + {"25640,95640", + SPIEE,-1,0,Read25xx,{0x2000},0,Write25xx,{0x2000,32},0}, //8K + {"25128,95128", + SPIEE,-1,0,Read25xx,{0x4000},0,Write25xx,{0x4000,64},0}, //16K + {"25256,95256", + SPIEE,-1,0,Read25xx,{0x8000},0,Write25xx,{0x8000,64},0}, //32K + {"25512,95512", + SPIEE,-1,0,Read25xx,{0x10000},0,Write25xx,{0x10000,128},0}, //64K + {"251024,95M01", + SPIEE,-1,0,Read25xx,{0x20000},0,Write25xx,{0x20000,256},0}, //128K + {"95M02", + SPIEE,-1,0,Read25xx,{0x40000},0,Write25xx,{0x40000,256},0}, //256K + {"25X05", + SPIEE,-1,0,Read25xx,{0x10000},0,Write25xx,{0x10000,0x1000+256},0}, //64K flash 3.3V + {"251005,25X10", + SPIEE,-1,0,Read25xx,{0x20000},0,Write25xx,{0x20000,0x1000+256},0}, //128K flash 3.3V + {"252005,25X20", + SPIEE,-1,0,Read25xx,{0x40000},0,Write25xx,{0x40000,0x1000+256},0}, //256K flash 3.3V + {"254005,25X40", + SPIEE,-1,0,Read25xx,{0x80000},0,Write25xx,{0x80000,0x1000+256},0}, //512K flash 3.3V + {"25Q40", + SPIEE,-1,0,Read25xx,{0x80000},0,Write25xx,{0x80000,0x3000+256},0}, //512K flash 3.3V STATUS2 + {"258005,25X80", + SPIEE,-1,0,Read25xx,{0x100000},0,Write25xx,{0x100000,0x1000+256},0},//1M flash 3.3V + {"251605,25X16", + SPIEE,-1,0,Read25xx,{0x200000},0,Write25xx,{0x200000,0x1000+256},0},//2M flash 3.3V + {"25X32", + SPIEE,-1,0,Read25xx,{0x400000},0,Write25xx,{0x400000,0x1000+256},0},//4M flash 3.3V + {"25X64", + SPIEE,-1,0,Read25xx,{0x800000},0,Write25xx,{0x800000,0x1000+256},0},//8M flash 3.3V + {"25X128", + SPIEE,-1,0,Read25xx,{0x1000000},0,Write25xx,{0x1000000,0x1000+256},0},//16M flash 3.3V +//-------------One wire devices--------------------------------------------------------- + {"DS2430", + OWEE,-1,0,ReadOneWireMem,{0x20,1},0,WriteOneWireMem,{0x20,1},0}, //32 + {"DS2431", + OWEE,-1,0,ReadOneWireMem,{0x80,2},0,WriteOneWireMem,{0x80,0},0}, //128 + {"DS2433", + OWEE,-1,0,ReadOneWireMem,{0x200,0},0,WriteOneWireMem,{0x200,1},0}, //512 + {"DS28EC20", + OWEE,-1,0,ReadOneWireMem,{0xA00,2},0,WriteOneWireMem,{0xA00,1},0}, //2560 + {"DS1820", + OWEE,-1,0,ReadDS1820,{-10},0,0,{0},0}, //digital thermometer +//-------------UNIO devices--------------------------------------------------------- + {"11010", + UNIOEE,-1,0,Read11xx,{0x80},0,Write11xx,{0x80,16},0}, //128 + {"11020", + UNIOEE,-1,0,Read11xx,{0x100},0,Write11xx,{0x100,16},0}, //256 + {"11040", + UNIOEE,-1,0,Read11xx,{0x200},0,Write11xx,{0x200,16},0}, //512 + {"11080", + UNIOEE,-1,0,Read11xx,{0x400},0,Write11xx,{0x400,16},0}, //1k + {"11160", + UNIOEE,-1,0,Read11xx,{0x800},0,Write11xx,{0x800,16},0} //2k +}; + +int NDEVLIST = (sizeof(DEVLIST)/sizeof(struct DEVICES)); + +//Add all devices to the appropriate structure +#ifndef _GTKGUI +void AddDevices(char *list){ //make sure list is long enough + int i; + static char last[8]=""; + for(i=0;i0){ //3.3V required + if(!CheckV33Regulator()){ + PrintMessage(strings[S_noV33reg]); //Can't find 3.3V expansion board + return; + } + } + if(hvreg!=DEVLIST[i].HV) hvreg=StartHVReg(DEVLIST[i].HV)>0?DEVLIST[i].HV:0; + if(DEVLIST[i].ReadPtr==0){ + PrintMessage(strings[S_nodev_r]); //"Device not supported for reading\r\n"); + return; + } + switch(DEVLIST[i].family){ //call read function with the right number of arguments (better ways to do it???) + case PIC12: + if(r) params[1]=DEVLIST[i].ResArea; //modify reserved area parameter + (*DEVLIST[i].ReadPtr)(params[0],params[1]); + break; + case PIC16: + if(r) params[2]=DEVLIST[i].ResArea; //modify reserved area parameter + if(!ee) params[1]=0; //clear eeprom parameter + (*DEVLIST[i].ReadPtr)(params[0],params[1],params[2],params[3]); + break; + case PIC18: + if(!ee) params[1]=0; //clear eeprom parameter + (*DEVLIST[i].ReadPtr)(params[0],params[1],params[2]); + break; + case PIC24: + if(!ee) params[1]=0; //clear eeprom parameter + (*DEVLIST[i].ReadPtr)(params[0],params[1],params[2],params[3],r?DEVLIST[i].ResArea:0); + break; + case PIC32: +// if(!ee) params[1]=0; //clear eeprom parameter + (*DEVLIST[i].ReadPtr)(params[0],params[1]); + break; + case AVR: + if(!ee) params[1]=0; //clear eeprom parameter + (*DEVLIST[i].ReadPtr)(params[0],params[1],params[2]); + break; + case I2CEE: + (*DEVLIST[i].ReadPtr)(params[0],params[1]); + break; + case UWEE: + (*DEVLIST[i].ReadPtr)(params[0],params[1],params[2]); + break; + case SPIEE: + (*DEVLIST[i].ReadPtr)(params[0]); + break; + case OWEE: + if(params[0]==-10) (*DEVLIST[i].ReadPtr)(); + else (*DEVLIST[i].ReadPtr)(params[0],params[1]); + break; + case UNIOEE: + (*DEVLIST[i].ReadPtr)(params[0]); + break; + default: + PrintMessage(strings[S_nodev_r]); //"Device not supported for reading\r\n"); + } + return; + } + } + } + PrintMessage(strings[S_nodev_r]); //"Device not supported for reading\r\n"); +} + + +void Write(char* dev,int ee) +{ + int i,j; + int params[6]; + char *str=0,*tok; + //parse all device names until "dev" is found, + //then execute the write function with the right number of parameters + for(i=0;i0){ //3.3V required + if(!CheckV33Regulator()){ + PrintMessage(strings[S_noV33reg]); //Can't find 3.3V expansion board + return; + } + } + if(hvreg!=DEVLIST[i].HV) hvreg=StartHVReg(DEVLIST[i].HV)>0?DEVLIST[i].HV:0; + if(DEVLIST[i].WritePtr==0){ + PrintMessage(strings[S_nodev_w]); //"Device not supported for writing\r\n"); + return; + } + switch(DEVLIST[i].family){ //call write function with the right number of arguments (better ways to do it???) + case PIC12: + (*DEVLIST[i].WritePtr)(params[0],params[1]); + break; + case PIC16: + if(!ee) params[1]=0; //clear eeprom parameter + if(params[2]==-10) (*DEVLIST[i].WritePtr)(params[0],params[1]); + else (*DEVLIST[i].WritePtr)(params[0],params[1],params[2]); + break; + case PIC18: + if(!ee) params[1]=0; //clear eeprom parameter + (*DEVLIST[i].WritePtr)(params[0],params[1],params[2],params[3],params[4],params[5]); + break; + case PIC24: + if(!ee) params[1]=0; //clear eeprom parameter + (*DEVLIST[i].WritePtr)(params[0],params[1],params[2],params[3],params[4],DEVLIST[i].WriteParamD); + break; + case AVR: + if(!ee) params[1]=0; //clear eeprom parameter + (*DEVLIST[i].WritePtr)(params[0],params[1],params[2],params[3]); + break; + case I2CEE: + (*DEVLIST[i].WritePtr)(params[0],params[1],params[2]); + break; + case UWEE: + (*DEVLIST[i].WritePtr)(params[0],params[1],params[2]); + break; + case SPIEE: + (*DEVLIST[i].WritePtr)(params[0],params[1]); + break; + case OWEE: + (*DEVLIST[i].WritePtr)(params[0],params[1]); + break; + case UNIOEE: + (*DEVLIST[i].WritePtr)(params[0],params[1]); + break; + default: + PrintMessage(strings[S_nodev_w]); //"Device not supported for writing\r\n"); + } + return; + } + } + } + PrintMessage(strings[S_nodev_w]); //"Device not supported for writing\r\n"); +} + +///Search the device type +int GetDevType(const char* dev) +{ + int i,type=-1; + char *str=0,*tok; + //parse all device names until "dev" is found + for(i=0;ifamily=devlistEntry->family; + info->HV=devlistEntry->HV; + info->V33=devlistEntry->V33; + info->size=devlistEntry->ReadParam[0]; + info->sizeEE=devlistEntry->ReadParam[1]; + str2[0]=0; + double x=info->size/1024.0; + if(x-(int)x) sprintf(strF,"%.1f",x); + else sprintf(strF,"%d",(int)x); + switch(info->family){ + case -1: + sprintf(str2,"?? "); + break; + case PIC12: + sprintf(str2,"PIC12, "); + if(info->size<1024) sprintf(str3,"%dW FLASH",info->size); + else sprintf(str3,"%sKW FLASH",strF); + strcat(str2,str3); + break; + case PIC16: + sprintf(str2,"PIC16, "); + if(info->size<1024) sprintf(str3,"%dW FLASH",info->size); + else sprintf(str3,"%sKW FLASH",strF); + strcat(str2,str3); + if(info->sizeEE){ + int ee=info->sizeEE; + if(ee<0) ee=-ee; + sprintf(str3," + %dB EEPROM",ee); + strcat(str2,str3); + } + break; + case PIC18: + sprintf(str2,"PIC18, "); + if(info->size<1024) sprintf(str3,"%dB FLASH ",info->size); + else sprintf(str3,"%sKB FLASH ",strF); + strcat(str2,str3); + if(info->sizeEE){ + sprintf(str3,"+ %dB EEPROM ",info->sizeEE); + strcat(str2,str3); + } + break; + case PIC24: + sprintf(str2,"PIC24, "); + if(info->size<1024) sprintf(str3,"%dW FLASH",info->size); + else sprintf(str3,"%sKW FLASH",strF); + strcat(str2,str3); + if(info->sizeEE){ + sprintf(str3," + %dB EEPROM",info->sizeEE); + strcat(str2,str3); + } + break; + case PIC32: + sprintf(str2,"PIC32, "); + if(info->size<1024) sprintf(str3,"%dW FLASH",info->size); + else sprintf(str3,"%sKW FLASH",strF); + strcat(str2,str3); + if(info->sizeEE){ + sprintf(str3," + %dB EEPROM",info->sizeEE); + strcat(str2,str3); + } + break; + case AVR: + sprintf(str2,"AVR, "); + if(info->size<1024) sprintf(str3,"%dB FLASH",info->size); + else sprintf(str3,"%sKB FLASH",strF); + strcat(str2,str3); + if(info->sizeEE){ + sprintf(str3," + %dB EEPROM",info->sizeEE); + strcat(str2,str3); + } + break; + case I2CEE: + if(info->size<1024) sprintf(str2,"%s, %dB",strings[I_I2CMEM],info->size); //I2C Memory + else sprintf(str2,"%s, %sKB",strings[I_I2CMEM],strF); //I2C Memory + break; + case SPIEE: + if(info->size<1024) sprintf(str2,"%s, %dB",strings[I_SPIMEM],info->size); //SPI Memory + else sprintf(str2,"%s, %sKB",strings[I_SPIMEM],strF); //SPI Memory + break; + case UWEE: + if(info->size<1024) sprintf(str2,"%s, %dB",strings[I_UWMEM],info->size); //Microwire Memory + else sprintf(str2,"%s,%sKB",strings[I_UWMEM],strF); + break; + case OWEE: + if(info->size<0) sprintf(str2,strings[I_OWDEV]); //OneWire device + else if(info->size<1024) sprintf(str2,"%s, %dB",strings[I_OWMEM],info->size); //OneWire Memory + else sprintf(str2,"%s, %sKB",strings[I_OWMEM],strF); + break; + case UNIOEE: + if(info->size<1024) sprintf(str2,"%s, %dB",strings[I_UNIOMEM],info->size); //UNI/O Memory + else sprintf(str2,"%s, %sKB",strings[I_UNIOMEM],strF); + break; + } + if(info->HV>0){ + sprintf(str3,", %.1fV",info->HV); + strcat(str2,str3); + } + if(info->V33){ + strcat(str2,", "); + strcat(str2,strings[I_3V3REQUIRED]); // 3.3V adapter + } + info->features=malloc(strlen(str2)+1); + strcpy(info->features,str2); +} + + +///Search and return device info +struct DevInfo GetDevInfo(const char* dev) +{ + int i; + char *str=0,*tok; + struct DevInfo info; + info.device=0; + info.family=-1; + info.HV=-1; + info.V33=-1; + info.size=-1; + info.sizeEE=-1; + info.features=0; + //parse all device names until "dev" is found + for(i=0;i + */ + +//configure for GUI or command-line +#include "common.h" +#include "progP12.h" +#include "progP16.h" +#include "progP18.h" +#include "progP24.h" +#include "progAVR.h" + +unsigned int htoi(const char *hex, int length) +{ + int i; + unsigned int v = 0; + for (i = 0; i < length; i++) { + v <<= 4; + if (hex[i] >= '0' && hex[i] <= '9') v += hex[i] - '0'; + else if (hex[i] >= 'a' && hex[i] <= 'f') v += hex[i] - 'a' + 10; + else if (hex[i] >= 'A' && hex[i] <= 'F') v += hex[i] - 'A' + 10; + else PrintMessage1(strings[S_Inohex],hex); //"Error: '%.4s' doesn't look very hexadecimal, right?\n" + } + return v; +} + +void Save(char* dev,char* savefile) +{ + FILE* f=fopen(savefile,"w"); + if(!f) return; + char str[512],str1[512]=""; + int i,sum=0,count=0,ext=0,s,base; +//**************** 10-16F ******************************************* + if(!strncmp(dev,"10",2)||!strncmp(dev,"12",2)||!strncmp(dev,"16",2)){ + int x=0x3fff,addr; + //if(!strncmp(dev,"16",2)||!strncmp(dev,"12F6",4)) x=0x3fff; + fprintf(f,":020000040000FA\n"); //extended address=0 + for(i=0;i=x;i++); //remove leading 0xFFF + for(;i>8)+(memCODE_W[i]&0xff); + sprintf(str,"%02X%02X",memCODE_W[i]&0xff,memCODE_W[i]>>8); + strcat(str1,str); + count++; + if(count==8||i==sizeW-1){ + base=i-count+1; + for(s=i;s>=base&&memCODE_W[s]>=x;s--){ //remove trailing 0xFFF + sum-=(memCODE_W[s]>>8)+(memCODE_W[s]&0xff); + str1[strlen(str1)-4]=0; + } + count-=i-s; + addr=(s-count+1)*2; + sum+=count*2+(addr&0xff)+(addr>>8); + if(base>>15>ext){ + ext=base>>15; + fprintf(f,":02000004%04X%02X\n",ext,(-6-ext)&0xff); + } + if(count) fprintf(f,":%02X%04X00%s%02X\n",count*2,addr&0xFFFF,str1,(-sum)&0xff); + str1[0]=0; + count=sum=0; + } + } + if(sizeEE){ //this is only for 16F1xxx + if(ext!=0x01) fprintf(f,":020000040001F9\n"); + for(i=0,count=sum=0;ii-count&&memEE[s]>=0xff;s--){ //remove trailing 0xFF + sum-=memEE[s]&0xff; + str1[strlen(str1)-4]=0; + } + count-=i-s; + addr=(s-count+1)*2+0xE000; + sum+=count*2+(addr&0xff)+(addr>>8); + if(count){ + fprintf(f,":%02X%04X00%s%02X\n",count*2,addr,str1,(-sum)&0xff); + } + str1[0]=0; + count=sum=0; + } + } + } + fprintf(f,":00000001FF\n"); + } +//**************** 18F ******************************************* + else if(!strncmp(dev,"18F",3)){ + fprintf(f,":020000040000FA\n"); //extended address=0 + for(i=0;i=base&&memCODE[s]==0xff;s--){ //remove trailing 0xFF + sum-=memCODE[s]; + str1[strlen(str1)-2]=0; + } + count-=i-s; + sum+=count+(base&0xff)+((base>>8)&0xff); + if(base>>16>ext){ + ext=base>>16; + fprintf(f,":02000004%04X%02X\n",ext,(-6-ext)&0xff); + } + if(count){ + fprintf(f,":%02X%04X00%s%02X\n",count,base&0xFFFF,str1,(-sum)&0xff); + } + str1[0]=0; + count=sum=0; + } + } + for(i=0,count=sum=0;i<8;i++){ + sum+=memID[i]; + sprintf(str,"%02X",memID[i]&0xff); + strcat(str1,str); + count++; + if(count==8){ + fprintf(f,":020000040020DA\n"); + base=i-count+1; + for(s=i;s>i-count&&memID[s]>=0xff;s--){ //remove trailing 0xFF + sum-=memID[s]&0xff; + str1[strlen(str1)-2]=0; + } + count-=i-s; + sum+=count+(base&0xff)+((base>>8)&0xff); + if(count){ + fprintf(f,":%02X%04X00%s%02X\n",count,base&0xFFFF,str1,(-sum)&0xff); + } + str1[0]=0; + count=sum=0; + } + } + for(i=0,count=sum=0;i<14;i++){ + sum+=memCONFIG[i]; + sprintf(str,"%02X",memCONFIG[i]&0xff); + strcat(str1,str); + count++; + if(count==14){ + fprintf(f,":020000040030CA\n"); + base=i-count+1; + for(s=i;s>i-count&&memCONFIG[s]>=0xff;s--){ //remove trailing 0xFF + sum-=memCONFIG[s]&0xff; + str1[strlen(str1)-2]=0; + } + count-=i-s; + sum+=count+(base&0xff)+((base>>8)&0xff); + if(count){ + fprintf(f,":%02X%04X00%s%02X\n",count,base&0xFFFF,str1,(-sum)&0xff); + } + str1[0]=0; + count=sum=0; + } + } + if(sizeEE){ + fprintf(f,":0200000400F00A\n"); + for(i=0,count=sum=0;ii-count&&memEE[s]>=0xff;s--){ //remove trailing 0xFF + sum-=memEE[s]&0xff; + str1[strlen(str1)-2]=0; + } + count-=i-s; + sum+=count+(base&0xff)+((base>>8)&0xff); + if(count){ + fprintf(f,":%02X%04X00%s%02X\n",count,base&0xFFFF,str1,(-sum)&0xff); + } + str1[0]=0; + count=sum=0; + } + } + } + fprintf(f,":00000001FF\n"); + } +//**************** 24F ******************************************* + else if((!strncmp(dev,"24F",3)||!strncmp(dev,"24H",3)||!strncmp(dev,"24E",3)||!strncmp(dev,"30F",3)||!strncmp(dev,"33F",3)||!strncmp(dev,"33E",3))){ + int valid; + fprintf(f,":020000040000FA\n"); //extended address=0 + int sum=0,count=0,s,word; + word=memCODE[0]+(memCODE[1]<<8)+(memCODE[2]<<16)+(memCODE[3]<<24); + for(i=0;i>8)&0xff); + if(base>>16>ext){ + ext=base>>16; + fprintf(f,":02000004%04X%02X\n",ext,(-6-ext)&0xff); + } + if(count&&valid){ + fprintf(f,":%02X%04X00%s%02X\n",count,base&0xFFFF,str1,(-sum)&0xff); + } + str1[0]=0; + count=sum=0; + } + } + if(sizeCONFIG){ + fprintf(f,":0200000401F009\n"); + for(i=0,count=sum=0;i>8)&0xff); + if(count){ + fprintf(f,":%02X%04X00%s%02X\n",count,base&0xFFFF,str1,(-sum)&0xff); + } + str1[0]=0; + count=sum=0; + } + } + } + if(sizeEE){ + fprintf(f,":0200000400FFFB\n"); + str1[0]=0; + for(i=0,count=sum=0;i>8); + if(count&&valid){ + fprintf(f,":%02X%04X00%s%02X\n",count,base+0xE000,str1,(-sum)&0xff); + } + str1[0]=0; + count=sum=0; + } + } + } + fprintf(f,":00000001FF\n"); + } +//**************** ATxxxx ******************************************* + else if(!strncmp(dev,"AT",2)){ + fprintf(f,":020000040000FA\n"); //extended address=0 + for(i=0;i=base&&memCODE[s]==0xff;s--){ //remove trailing 0xFF + sum-=memCODE[s]; + str1[strlen(str1)-2]=0; + } + count-=i-s; + sum+=count+(base&0xff)+((base>>8)&0xff); + if(base>>16>ext){ + ext=base>>16; + fprintf(f,":02000004%04X%02X\n",ext,(-6-ext)&0xff); + } + if(count){ + fprintf(f,":%02X%04X00%s%02X\n",count,base&0xFFFF,str1,(-sum)&0xff); + } + str1[0]=0; + count=sum=0; + } + } + fprintf(f,":00000001FF\n"); + } +//**************** 24xxx / 93xxx / 25xxx / 95xxx / DSxxxx ******************************************* + else if(!strncmp(dev,"24",2)||!strncmp(dev,"93",2)||!strncmp(dev,"25",2)||!strncmp(dev,"95",2)||\ + !strncmp(dev,"DS",2)||!strncmp(dev,"11",2)){ + if(strstr(savefile,".bin")||strstr(savefile,".BIN")){ + #ifdef _WIN32 + //brain-damaged op. systems need this to avoid messing with some bytes + f=freopen(savefile,"wb",f); + if(!f) return; + #endif + fwrite(memEE,1,sizeEE,f); + } + else{ //HEX + int valid; + fprintf(f,":020000040000FA\n"); //extended address=0 + for(i=0;i>8)&0xff); + if(base>>16>ext){ + ext=base>>16; + fprintf(f,":02000004%04X%02X\n",ext,(-6-ext)&0xff); + } + if(count){ + fprintf(f,":%02X%04X00%s%02X\n",count,base&0xFFFF,str1,(-sum)&0xff); + } + } + str1[0]=0; + count=sum=0; + } + } + fprintf(f,":00000001FF\n"); + } + } + if(f) fclose(f); +} + +void SaveEE(char* dev,char* savefile){ + FILE* f=fopen(savefile,"w"); + if(!f) return; +//**************** ATMEL ******************************************* + if(!strncmp(dev,"AT",2)){ + char str[512],str1[512]=""; + int i,base; + fprintf(f,":020000040000FA\n"); //extended address=0 + int sum=0,count=0,s; + for(i=0,count=sum=0;ii-count&&memEE[s]>=0xff;s--){ //remove trailing 0xFF + sum-=memEE[s]&0xff; + str1[strlen(str1)-2]=0; + } + count-=i-s; + sum+=count+(base&0xff)+((base>>8)&0xff); + if(count){ + fprintf(f,":%02X%04X00%s%02X\n",count,base&0xFFFF,str1,(-sum)&0xff); + } + str1[0]=0; + count=sum=0; + } + } + fprintf(f,":00000001FF\n"); + } + if(f) fclose(f); +} + +int Load(char*dev,char*loadfile){ + int i,input_address=0,ext_addr=0,sum,valid; + char line[256]; + FILE* f=fopen(loadfile,"r"); + if(!f) return -1; + PrintMessage1("%s :\r\n",loadfile); +//**************** 10-16F ******************************************* + if(!strncmp(dev,"10",2)||!strncmp(dev,"12",2)||!strncmp(dev,"16",2)){ + unsigned char buffer[0x20000],bufferEE[0x1000]; + int sizeM=0; + memset(buffer,0xFF,sizeof(buffer)); + memset(bufferEE,0xFF,sizeof(bufferEE)); + sizeEE=0; + for(;fgets(line,256,f);){ + if(strlen(line)>9&&line[0]==':'){ + int hex_count = htoi(line+1, 2); + if((int)strlen(line)-11sizeW) sizeW=sizeM; + for (i=0;i=0x1E000&&input_address<0x1F000){ //EEPROM + sizeM=(input_address-0x1E000+hex_count)/2; + if(sizeM>sizeEE) sizeEE=sizeM; + for (i=0;i14) ext_addr=htoi(line+9,4); + break; + default: + break; + } + } + } + } + } + sizeW/=2; + if(memCODE_W) free(memCODE_W); + memCODE_W=(WORD*)malloc(sizeof(WORD)*sizeW); + for(i=0;i0x8000?0x8500:0x2100; + DisplayCODE16F(imax); + if(sizeW>=0x2100&&sizeW<0x3000){ //EEPROM@0x2100 + PrintMessage(strings[S_EEMem]); //"\r\nEEPROM memory:\r\n" + DisplayEE16F(0x700); + } + else if(sizeEE) DisplayEE(); + PrintMessage("\r\n"); + } +//**************** 18F ******************************************* + else if(!strncmp(dev,"18F",3)){ + unsigned char buffer[0x30000],bufferEE[0x1000]; + int sizeM; + memset(buffer,0xFF,sizeof(buffer)); + memset(bufferEE,0xFF,sizeof(bufferEE)); + memset(memID,0xFF,sizeof(memID)); + memset(memCONFIG,0xFF,sizeof(memCONFIG)); + for(;fgets(line,256,f);){ + if(strlen(line)>9&&line[0]==':'){ + int hex_count = htoi(line+1, 2); + if((int)strlen(line) - 11 < hex_count * 2) { + PrintMessage1(strings[S_IhexShort],line); //"Intel hex8 line too short:\r\n%s\r\n" + } + else{ + input_address=htoi(line+3,4); + sum=0; + for (i=1;i<=hex_count*2+9;i+=2) + sum += htoi(line+i,2); + if ((sum & 0xff)!=0) { + PrintMessage1(strings[S_IhexChecksum],line); //"Intel hex8 checksum error in line:\r\n%s\r\n" + } + else{ + switch(htoi(line+7,2)){ + case 0: //Data record + if(ext_addr<0x20){ //Code <0x200000 + sizeM=(ext_addr<<16)+input_address+hex_count; + if(sizeM>size) size=sizeM; + for (i=0;isizeEE) sizeEE=sizeM; + + } + break; + case 4: //extended linear address record + if(strlen(line)>14) ext_addr=htoi(line+9,4); + break; + default: + break; + } + } + } + } + } + if(memCODE) free(memCODE); + memCODE=(unsigned char*)malloc(size); + memcpy(memCODE,buffer,size); + if(memEE) free(memEE); + memEE=(unsigned char*)malloc(sizeEE); + memcpy(memEE,bufferEE,sizeEE); + PrintMessage(strings[S_IDMem]); //"ID memory:\r\n" + for(i=0;i<8;i+=2) PrintMessage4("ID%d: 0x%02X ID%d: 0x%02X\r\n",i,memID[i],i+1,memID[i+1]); + PrintMessage(strings[S_ConfigMem]); //"CONFIG memory:\r\n" + for(i=0;i<7;i++){ + PrintMessage2(strings[S_ConfigWordH],i+1,memCONFIG[i*2+1]); //"CONFIG%dH: 0x%02X\t" + PrintMessage2(strings[S_ConfigWordL],i+1,memCONFIG[i*2]); //"CONFIG%dL: 0x%02X\r\n" + } + PrintMessage(strings[S_CodeMem]); //"\r\nCODE memory:\r\n" + DisplayCODE18F(size); + if(sizeEE) DisplayEE(); + PrintMessage("\r\n"); + } +//**************** 24F ******************************************* + else if(!strncmp(dev,"24F",3)||!strncmp(dev,"24H",3)||!strncmp(dev,"24E",3)||!strncmp(dev,"30F",3)||!strncmp(dev,"33F",3)||!strncmp(dev,"33E",3)){ + unsigned char *buffer,bufferEE[0x2000]; + int d; + buffer=(unsigned char*)malloc(0x100000); + memset(buffer,0xFF,0x100000); + memset(bufferEE,0xFF,sizeof(bufferEE)); + memset(memCONFIG,0xFF,sizeof(memCONFIG)); + memset(memUSERID,0xFF,sizeof(memUSERID)); + sizeUSERID=0; + for(;fgets(line,256,f);){ + if(strlen(line)>9&&line[0]==':'){ + int hex_count = htoi(line+1, 2); + if((int)strlen(line) - 11 < hex_count * 2) { + PrintMessage1(strings[S_IhexShort],line); //"Intel hex8 line too short:\r\n%s\r\n" + } + else{ + input_address=htoi(line+3,4); + sum=0; + for (i=1;i<=hex_count*2+9;i+=2) + sum += htoi(line+i,2); + if ((sum & 0xff)!=0) { + PrintMessage1(strings[S_IhexChecksum],line); //"Intel hex8 checksum error in line:\r\n%s\r\n" + } + else{ + switch(htoi(line+7,2)){ + case 0: //Data record + if(ext_addr<0x20){ //Code + int end1=(ext_addr<<16)+input_address+hex_count; + if(size=0xE000){ //EEPROM + for (i=0;i14) ext_addr=htoi(line+9,4); + break; + default: + break; + } + } + } + } + } + if(memCODE) free(memCODE); + memCODE=(unsigned char*)malloc(size); + memcpy(memCODE,buffer,size); + free(buffer); + sizeEE=sizeEE?0x1000:0; + if(memEE) free(memEE); + memEE=(unsigned char*)malloc(sizeEE); + for(i=0;i9&&line[0]==':'){ + int hex_count = htoi(line+1, 2); + if((int)strlen(line) - 11 < hex_count * 2) { + PrintMessage1(strings[S_IhexShort],line); //"Intel hex8 line too short:\r\n%s\r\n" + } + else{ + input_address=htoi(line+3,4); + sum=0; + for (i=1;i<=hex_count*2+9;i+=2) + sum += htoi(line+i,2); + if ((sum & 0xff)!=0) { + PrintMessage1(strings[S_IhexChecksum],line); //"Intel hex8 checksum error in line:\r\n%s\r\n" + } + else{ + switch(htoi(line+7,2)){ + case 0: //Data record + if(ext_addr<0x20){ //Code + size=input_address+hex_count; + for (i=0;i14) ext_addr=htoi(line+9,4); + break; + default: + break; + } + } + } + } + } + if(memCODE) free(memCODE); + memCODE=(unsigned char*)malloc(size); + memcpy(memCODE,buffer,size); + if(size) PrintMessage(strings[S_CodeMem]); //"\r\nmemoria CODICE:\r\n" + DisplayCODEAVR(size); + PrintMessage("\r\n"); + } +//**************** 24xxx / 93xxx / 25xxx / 95xxx / DSxxxx /11xxx ******************************* + else if(!strncmp(dev,"24",2)||!strncmp(dev,"93",2)||!strncmp(dev,"25",2)||!strncmp(dev,"95",2)||\ + !strncmp(dev,"DS",2)||!strncmp(dev,"11",2)){ + if(strstr(loadfile,".bin")||strstr(loadfile,".BIN")){ + #ifdef _WIN32 + //brain-damaged op. systems need this to avoid messing with some bytes + f=freopen(loadfile,"rb",f); + if(!f) return -1; + #endif + fseek(f, 0L, SEEK_END); + sizeEE=ftell(f); + fseek(f, 0L, SEEK_SET); + if(sizeEE>0x1000000) sizeEE=0x1000000; //max 16MB + if(memEE) free(memEE); + memEE=(unsigned char*)malloc(sizeEE); + sizeEE=fread(memEE,1,sizeEE,f); + } + else{ //Hex file + int bufSize=0x40000; //256K + unsigned char *bufferEE=(unsigned char*)malloc(bufSize); + memset(bufferEE,0xFF,bufSize); + for(;fgets(line,256,f);){ + if(strlen(line)>9&&line[0]==':'){ + int hex_count = htoi(line+1, 2); + if((int)strlen(line) - 11 < hex_count * 2) { + PrintMessage1(strings[S_IhexShort],line); //"Intel hex8 line too short:\r\n%s\r\n" + } + else{ + input_address=htoi(line+3,4); + sum=0; + int end1; + for (i=1;i<=hex_count*2+9;i+=2) sum+=htoi(line+i,2); + if ((sum & 0xff)!=0) { + PrintMessage1(strings[S_IhexChecksum],line); //"Intel hex8 checksum error in line:\r\n%s\r\n" + } + else{ + switch(htoi(line+7,2)){ + case 0: //Data record + end1=(ext_addr<<16)+input_address+hex_count; + if(end1>=0x1000000) break; //max 16MB + if(sizeEE14) ext_addr=htoi(line+9,4); + break; + default: + break; + } + } + } + } + } + if(memEE) free(memEE); + memEE=(unsigned char*)malloc(sizeEE); + memcpy(memEE,bufferEE,sizeEE); + free(bufferEE); + } + DisplayEE(); //visualize + int sum=0; + for(i=0;i9&&line[0]==':'){ + int hex_count = htoi(line+1, 2); + if((int)strlen(line) - 11 < hex_count * 2) { + PrintMessage1(strings[S_IhexShort],line); //"Intel hex8 line too short:\r\n%s\r\n" + } + else{ + input_address=htoi(line+3,4); + int sum = 0; + for (i=1;i<=hex_count*2+9;i+=2) sum+=htoi(line+i,2); + if ((sum & 0xff)!=0) { + PrintMessage1(strings[S_IhexChecksum],line); //"Intel hex8 checksum error in line:\r\n%s\r\n" + } + else{ + switch(htoi(line+7,2)){ + case 0: //Data record + if(ext_addr==0&&input_address<0x1000){ //EEPROM + for (i=0;i14) ext_addr=htoi(line+9,4); + break; + default: + break; + } + } + } + } + } + if(memEE) free(memEE); + memEE=(unsigned char*)malloc(sizeEE); + memcpy(memEE,bufferEE,sizeEE); + if(sizeEE) DisplayEE(); //visualize + PrintMessage("\r\n"); + fclose(f); + } +} + +void OpenLogFile() +{ + logfile=fopen(LogFileName,"w"); + if(!logfile) return; + fprintf(logfile,_APPNAME " version %s (%s)\n",VERSION,SYSNAME); + fprintf(logfile,"Firmware version %d.%d.%d\n",FWVersion>>16,(FWVersion>>8)&0xFF,FWVersion&0xFF); + struct tm * timeinfo; + time_t rawtime; + time( &rawtime ); /* Get time as long integer. */ + timeinfo = localtime( &rawtime ); /* Convert to local time. */ + fprintf(logfile,"%s\n", asctime (timeinfo) ); +} + +void CloseLogFile() +{ + if(logfile)fclose(logfile); + logfile=0; +} + +void WriteLogIO() +{ + int i; + //fprintf(logfile,"bufferU=[%02X\n",bufferU[0]); + fprintf(logfile,"bufferU=["); + for(i=0;i + Copyright (C) + + 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., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/hid-example.c b/hid-example.c new file mode 100644 index 0000000..37a0ffc --- /dev/null +++ b/hid-example.c @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Hidraw Userspace Example + * + * Copyright (c) 2010 Alan Ott + * Copyright (c) 2010 Signal 11 Software + * + * The code may be used by anyone for any purpose, + * and can serve as a starting point for developing + * applications using hidraw. + */ + +/* Linux */ +#include +#include +#include + +/* + * Ugly hack to work around failing compilation on systems that don't + * yet populate new version of hidraw.h to userspace. + */ +#ifndef HIDIOCSFEATURE +#warning Please have your distro update the userspace kernel headers +#define HIDIOCSFEATURE(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x06, len) +#define HIDIOCGFEATURE(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x07, len) +#endif + +/* Unix */ +#include +#include +#include +#include +#include + +/* C */ +#include +#include +#include +#include + +const char *bus_str(int bus); + +int main(int argc, char **argv) +{ + int fd; + int i, res, desc_size = 0; + char buf[256]; + struct hidraw_report_descriptor rpt_desc; + struct hidraw_devinfo info; + char *device = "/dev/hidraw0"; + + if (argc > 1) + device = argv[1]; + + /* Open the Device with non-blocking reads. In real life, + don't use a hard coded path; use libudev instead. */ + fd = open(device, O_RDWR|O_NONBLOCK); + + if (fd < 0) { + perror("Unable to open device"); + return 1; + } + + memset(&rpt_desc, 0x0, sizeof(rpt_desc)); + memset(&info, 0x0, sizeof(info)); + memset(buf, 0x0, sizeof(buf)); + + /* Get Report Descriptor Size */ + res = ioctl(fd, HIDIOCGRDESCSIZE, &desc_size); + if (res < 0) + perror("HIDIOCGRDESCSIZE"); + else + printf("Report Descriptor Size: %d\n", desc_size); + + /* Get Report Descriptor */ + rpt_desc.size = desc_size; + res = ioctl(fd, HIDIOCGRDESC, &rpt_desc); + if (res < 0) { + perror("HIDIOCGRDESC"); + } else { + printf("Report Descriptor:\n"); + for (i = 0; i < rpt_desc.size; i++) + printf("%hhx ", rpt_desc.value[i]); + puts("\n"); + } + + /* Get Raw Name */ + res = ioctl(fd, HIDIOCGRAWNAME(256), buf); + if (res < 0) + perror("HIDIOCGRAWNAME"); + else + printf("Raw Name: %s\n", buf); + + /* Get Physical Location */ + res = ioctl(fd, HIDIOCGRAWPHYS(256), buf); + if (res < 0) + perror("HIDIOCGRAWPHYS"); + else + printf("Raw Phys: %s\n", buf); + + /* Get Raw Info */ + res = ioctl(fd, HIDIOCGRAWINFO, &info); + if (res < 0) { + perror("HIDIOCGRAWINFO"); + } else { + printf("Raw Info:\n"); + printf("\tbustype: %d (%s)\n", + info.bustype, bus_str(info.bustype)); + printf("\tvendor: 0x%04hx\n", info.vendor); + printf("\tproduct: 0x%04hx\n", info.product); + } + + /* Set Feature */ + buf[0] = 0x9; /* Report Number */ + buf[1] = 0xff; + buf[2] = 0xff; + buf[3] = 0xff; + res = ioctl(fd, HIDIOCSFEATURE(4), buf); + if (res < 0) + perror("HIDIOCSFEATURE"); + else + printf("ioctl HIDIOCSFEATURE returned: %d\n", res); + + /* Get Feature */ + buf[0] = 0x9; /* Report Number */ + res = ioctl(fd, HIDIOCGFEATURE(256), buf); + if (res < 0) { + perror("HIDIOCGFEATURE"); + } else { + printf("ioctl HIDIOCGFEATURE returned: %d\n", res); + printf("Report data (not containing the report number):\n\t"); + for (i = 0; i < res; i++) + printf("%hhx ", buf[i]); + puts("\n"); + } + + /* Send a Report to the Device */ + buf[0] = 0x1; /* Report Number */ + buf[1] = 0x77; + res = write(fd, buf, 2); + if (res < 0) { + printf("Error: %d\n", errno); + perror("write"); + } else { + printf("write() wrote %d bytes\n", res); + } + + /* Get a report from the device */ + res = read(fd, buf, 16); + if (res < 0) { + perror("read"); + } else { + printf("read() read %d bytes:\n\t", res); + for (i = 0; i < res; i++) + printf("%hhx ", buf[i]); + puts("\n"); + } + close(fd); + return 0; +} + +const char * +bus_str(int bus) +{ + switch (bus) { + case BUS_USB: + return "USB"; + break; + case BUS_HIL: + return "HIL"; + break; + case BUS_BLUETOOTH: + return "Bluetooth"; + break; + case BUS_VIRTUAL: + return "Virtual"; + break; + default: + return "Other"; + break; + } +} diff --git a/hid_test.c b/hid_test.c new file mode 100644 index 0000000..ccc519d --- /dev/null +++ b/hid_test.c @@ -0,0 +1,575 @@ +/* + * 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-1307 USA + */ + + +#if !defined _WIN32 && !defined __CYGWIN__ + #include + #include + #include + #include + #include + #include + #include + #include +#else + #include + #include + #include + #include + #include + #include + #include +#endif + +#include +#include +#include +#include +#include +#include +#include + +int FindDevice(); + +#if !defined _WIN32 && !defined __CYGWIN__ +DWORD GetTickCount(); +struct hiddev_report_info rep_info_i,rep_info_u; +struct hiddev_usage_ref_multi ref_multi_i,ref_multi_u; +struct hiddev_devinfo device_info; + +#else + #define write() Result = WriteFile(WriteHandle,bufferU,n,&BytesWritten,NULL); + #define read() Result = ReadFile(ReadHandle,bufferI,n,&NumberOfBytesRead,(LPOVERLAPPED) &HIDOverlapped);\ + Result = WaitForSingleObject(hEventObject,50);\ + ResetEvent(hEventObject);\ + if(Result!=WAIT_OBJECT_0){\ + printf("communication timeout\r\n");\ + } + +unsigned char bufferU[128],bufferI[128]; +DWORD NumberOfBytesRead,BytesWritten; +ULONG Result; +HANDLE WriteHandle,ReadHandle; +OVERLAPPED HIDOverlapped; +HANDLE hEventObject; + +#endif + +int vid=0x1209,pid=0x5432,info=0; + +int main (int argc, char **argv) { +#define L_IT 0 +#define L_EN 1 + int d=0,v=0,q=0,r=1,lang=L_EN,c,i,j,block=0,R=0; + char path[512]=""; + char buf[256]; + for(i=0;i<256;i++) buf[i]=0; + #if defined _WIN32 + int n=65; + int langID=GetUserDefaultLangID(); + if((langID&0xFF)==0x10) lang=L_IT; + #else + int n=64; + if(getenv("LANG")&&strstr(getenv("LANG"),"it")!=0) lang=L_IT; + #endif + opterr = 0; + int option_index = 0; + struct option long_options[] = + { + {"b", no_argument, &block, 1}, + {"block", no_argument, &block, 1}, + {"verbose", no_argument, &v, 1}, + {"v", no_argument, &v, 1}, + {"quiet", no_argument, &q, 1}, + {"q", no_argument, &q, 1}, + {"info", no_argument, &info, 1}, + {"i", no_argument, &info, 1}, + {"help", no_argument, 0, 'h'}, + {"path", required_argument, 0, 'p'}, + {"read", required_argument, 0, 'R'}, + {"repeat", required_argument, 0, 'r'}, + {"delay", required_argument, 0, 'd'}, + {0, 0, 0, 0} + }; + while ((c = getopt_long_only (argc, argv, "n:d:p:hr:R:",long_options,&option_index)) != -1) + switch (c) + { + case 'h': //guida + if(!lang) printf("hid_test [opzioni] [dati]\n" + "opzioni: \n" + "-b, block\tusa lettura bloccante\n" + "-d, delay\tritardo lettura (ms) [0]\n" + "-h, help\tguida\n" + "-i, info\tinformazioni sul dispositivo [no]\n" + "-n\t\tdimensione report [64]\n" + "-p, path\tpercorso dispositivo [/dev/usb/hiddev0] \n" + "-q, quiet\tmostra solo risposta [no]\n" + "-R, read\tripeti lettura N volte [0]\n\n" + "-r, repeat\tripeti scrittura-lettura N volte [1]\n\n" + "-v, verbose\tmostra funzioni [no]\n" + "es. hid_test -i 1 2 3 4\n"); + else printf("hid_test [otions] [data]\n" + "options: \n" + "-b, block\tuse blocking read\n" + "-d, delay\tread delay (ms) [0]\n" + "-h, help\thelp\n" + "-i, info\tdevice info [no]\n" + "-n\t\treport size [64]\n" + "-p, path\tdevice path [/dev/usb/hiddev0]\n" + "-q, quiet\tprint response only [no]\n" + "-R, repeat\trepeat read N times [0]\n\n" + "-r, repeat\trepeat N times [1]\n\n" + "-v, verbose\tshow functions [no]\n" + "e.g. hid_test -i 1 2 3 4\n"); + exit(1); + break; + case 'n': //dim report + n = atoi(optarg); + break; + case 'd': //ritardo lettura + d = atoi(optarg); + break; + case 'p': //percorso hiddev + strncpy(path,optarg,sizeof(path)); + break; + case 'r': //ripeti IO + r = atoi(optarg); + break; + case 'R': //ripeti lettura + R = atoi(optarg); + break; + case '?': + if (optopt == 'c') + fprintf (stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint (optopt)) + fprintf (stderr, "Unknown option `-%c'.\n", optopt); + else + fprintf (stderr, "Unknown option character 0x%02x\n", optopt); + return 1; + default: + //abort (); + break; + } + + for (j=0,i = optind; i < argc&&i<128; i++,j++) sscanf(argv[i], "%x", &buf[j]); + for (;j "); + for(i=0;i0){ + ioctl(fd, HIDIOCGDEVINFO, &device_info); + if(device_info.vendor==vid&&device_info.product==pid) break; + else close(fd); + } + } + if(i==16){ + printf(strings[S_noprog]); + return -1; + } + } + else{ //user supplied path + if ((fd = open(path, O_RDONLY )) < 0) { + printf(strings[S_DevPermission],path); + exit(1); + } + ioctl(fd, HIDIOCGDEVINFO, &device_info); + if(device_info.vendor!=vid||device_info.product!=pid){ + printf(strings[S_noprog]); + return -1; + } + } + printf(strings[S_progDev],path); + + rep_info_u.report_type=HID_REPORT_TYPE_OUTPUT; + rep_info_i.report_type=HID_REPORT_TYPE_INPUT; + rep_info_u.report_id=rep_info_i.report_id=HID_REPORT_ID_FIRST; + rep_info_u.num_fields=rep_info_i.num_fields=1; + ref_multi_u.uref.report_type=HID_REPORT_TYPE_OUTPUT; + ref_multi_i.uref.report_type=HID_REPORT_TYPE_INPUT; + ref_multi_u.uref.report_id=ref_multi_i.uref.report_id=HID_REPORT_ID_FIRST; + ref_multi_u.uref.field_index=ref_multi_i.uref.field_index=0; + ref_multi_u.uref.usage_index=ref_multi_i.uref.usage_index=0; + ref_multi_u.num_values=ref_multi_i.num_values=DIMBUF; + + if(info){ + ioctl(fd, HIDIOCGDEVINFO, &device_info); + printf("vendor 0x%04hx product 0x%04hx version 0x%04hx ", + device_info.vendor, device_info.product, device_info.version); + printf("has %i application%s ", device_info.num_applications, + (device_info.num_applications==1?"":"s")); + printf("and is on bus: %d devnum: %d ifnum: %d\n", + device_info.busnum, device_info.devnum, device_info.ifnum); + char name[256]= "Unknown"; + if(ioctl(fd, HIDIOCGNAME(sizeof(name)), name) < 0) perror("evdev ioctl"); + printf("The device on %s says its name is %s\n", path, name); + } + +#else + char string[256]; + PSP_DEVICE_INTERFACE_DETAIL_DATA detailData; + HANDLE DeviceHandle; + HANDLE hDevInfo; + GUID HidGuid; + int MyDeviceDetected; + char MyDevicePathName[1024]; + ULONG Length; + ULONG Required; + typedef struct _HIDD_ATTRIBUTES { + ULONG Size; + USHORT VendorID; + USHORT ProductID; + USHORT VersionNumber; + } HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES; + + typedef void (__stdcall*GETHIDGUID) (OUT LPGUID HidGuid); + typedef BOOLEAN (__stdcall*GETATTRIBUTES)(IN HANDLE HidDeviceObject,OUT PHIDD_ATTRIBUTES Attributes); + typedef BOOLEAN (__stdcall*SETNUMINPUTBUFFERS)(IN HANDLE HidDeviceObject,OUT ULONG NumberBuffers); + typedef BOOLEAN (__stdcall*GETNUMINPUTBUFFERS)(IN HANDLE HidDeviceObject,OUT PULONG NumberBuffers); + typedef BOOLEAN (__stdcall*GETFEATURE) (IN HANDLE HidDeviceObject, OUT PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*SETFEATURE) (IN HANDLE HidDeviceObject, IN PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*GETREPORT) (IN HANDLE HidDeviceObject, OUT PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*SETREPORT) (IN HANDLE HidDeviceObject, IN PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*GETMANUFACTURERSTRING) (IN HANDLE HidDeviceObject, OUT PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*GETPRODUCTSTRING) (IN HANDLE HidDeviceObject, OUT PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*GETINDEXEDSTRING) (IN HANDLE HidDeviceObject, IN ULONG StringIndex, OUT PVOID ReportBuffer, IN ULONG ReportBufferLength); + HIDD_ATTRIBUTES Attributes; + SP_DEVICE_INTERFACE_DATA devInfoData; + int LastDevice = FALSE; + int MemberIndex = 0; + LONG Result; + //char UsageDescription[256]; + + Length=0; + detailData=NULL; + DeviceHandle=NULL; + + HMODULE hHID=0; + GETHIDGUID HidD_GetHidGuid=0; + GETATTRIBUTES HidD_GetAttributes=0; + SETNUMINPUTBUFFERS HidD_SetNumInputBuffers=0; + GETNUMINPUTBUFFERS HidD_GetNumInputBuffers=0; + GETFEATURE HidD_GetFeature=0; + SETFEATURE HidD_SetFeature=0; + GETREPORT HidD_GetInputReport=0; + SETREPORT HidD_SetOutputReport=0; + GETMANUFACTURERSTRING HidD_GetManufacturerString=0; + GETPRODUCTSTRING HidD_GetProductString=0; + hHID = LoadLibrary("hid.dll"); + if(!hHID){ + printf("Can't find hid.dll"); + return 0; + } + HidD_GetHidGuid=(GETHIDGUID)GetProcAddress(hHID,"HidD_GetHidGuid"); + HidD_GetAttributes=(GETATTRIBUTES)GetProcAddress(hHID,"HidD_GetAttributes"); + HidD_SetNumInputBuffers=(SETNUMINPUTBUFFERS)GetProcAddress(hHID,"HidD_SetNumInputBuffers"); + HidD_GetNumInputBuffers=(GETNUMINPUTBUFFERS)GetProcAddress(hHID,"HidD_GetNumInputBuffers"); + HidD_GetFeature=(GETFEATURE)GetProcAddress(hHID,"HidD_GetFeature"); + HidD_SetFeature=(SETFEATURE)GetProcAddress(hHID,"HidD_SetFeature"); + HidD_GetInputReport=(GETREPORT)GetProcAddress(hHID,"HidD_GetInputReport"); + HidD_SetOutputReport=(SETREPORT)GetProcAddress(hHID,"HidD_SetOutputReport"); + HidD_GetManufacturerString=(GETMANUFACTURERSTRING)GetProcAddress(hHID,"HidD_GetManufacturerString"); + HidD_GetProductString=(GETPRODUCTSTRING)GetProcAddress(hHID,"HidD_GetProductString"); + if(HidD_GetHidGuid==NULL\ + ||HidD_GetAttributes==NULL\ + ||HidD_GetFeature==NULL\ + ||HidD_SetFeature==NULL\ + ||HidD_GetInputReport==NULL\ + ||HidD_SetOutputReport==NULL\ + ||HidD_GetManufacturerString==NULL\ + ||HidD_GetProductString==NULL\ + ||HidD_SetNumInputBuffers==NULL\ + ||HidD_GetNumInputBuffers==NULL) return -1; + + + HMODULE hSAPI=0; + hSAPI = LoadLibrary("setupapi.dll"); + if(!hSAPI){ + printf("Can't find setupapi.dll"); + return 0; + } + typedef HDEVINFO (WINAPI* SETUPDIGETCLASSDEVS) (CONST GUID*,PCSTR,HWND,DWORD); + typedef BOOL (WINAPI* SETUPDIENUMDEVICEINTERFACES) (HDEVINFO,PSP_DEVINFO_DATA,CONST GUID*,DWORD,PSP_DEVICE_INTERFACE_DATA); + typedef BOOL (WINAPI* SETUPDIGETDEVICEINTERFACEDETAIL) (HDEVINFO,PSP_DEVICE_INTERFACE_DATA,PSP_DEVICE_INTERFACE_DETAIL_DATA_A,DWORD,PDWORD,PSP_DEVINFO_DATA); + typedef BOOL (WINAPI* SETUPDIDESTROYDEVICEINFOLIST) (HDEVINFO); + SETUPDIGETCLASSDEVS SetupDiGetClassDevsA=0; + SETUPDIENUMDEVICEINTERFACES SetupDiEnumDeviceInterfaces=0; + SETUPDIGETDEVICEINTERFACEDETAIL SetupDiGetDeviceInterfaceDetailA=0; + SETUPDIDESTROYDEVICEINFOLIST SetupDiDestroyDeviceInfoList=0; + SetupDiGetClassDevsA=(SETUPDIGETCLASSDEVS) GetProcAddress(hSAPI,"SetupDiGetClassDevsA"); + SetupDiEnumDeviceInterfaces=(SETUPDIENUMDEVICEINTERFACES) GetProcAddress(hSAPI,"SetupDiEnumDeviceInterfaces"); + SetupDiGetDeviceInterfaceDetailA=(SETUPDIGETDEVICEINTERFACEDETAIL) GetProcAddress(hSAPI,"SetupDiGetDeviceInterfaceDetailA"); + SetupDiDestroyDeviceInfoList=(SETUPDIDESTROYDEVICEINFOLIST) GetProcAddress(hSAPI,"SetupDiDestroyDeviceInfoList"); + if(SetupDiGetClassDevsA==NULL\ + ||SetupDiEnumDeviceInterfaces==NULL\ + ||SetupDiDestroyDeviceInfoList==NULL\ + ||SetupDiGetDeviceInterfaceDetailA==NULL) return -1; + + + /* + The following code is adapted from Usbhidio_vc6 application example by Jan Axelson + for more information see see http://www.lvr.com/hidpage.htm + */ + + /* + API function: HidD_GetHidGuid + Get the GUID for all system HIDs. + Returns: the GUID in HidGuid. + */ + HidD_GetHidGuid(&HidGuid); + + /* + API function: SetupDiGetClassDevs + Returns: a handle to a device information set for all installed devices. + Requires: the GUID returned by GetHidGuid. + */ + hDevInfo=SetupDiGetClassDevs(&HidGuid,NULL,NULL,DIGCF_PRESENT|DIGCF_INTERFACEDEVICE); + devInfoData.cbSize = sizeof(devInfoData); + + //Step through the available devices looking for the one we want. + //Quit on detecting the desired device or checking all available devices without success. + MemberIndex = 0; + LastDevice = FALSE; + do + { + /* + API function: SetupDiEnumDeviceInterfaces + On return, MyDeviceInterfaceData contains the handle to a + SP_DEVICE_INTERFACE_DATA structure for a detected device. + Requires: + The DeviceInfoSet returned in SetupDiGetClassDevs. + The HidGuid returned in GetHidGuid. + An index to specify a device. + */ + Result=SetupDiEnumDeviceInterfaces (hDevInfo, 0, &HidGuid, MemberIndex, &devInfoData); + if (Result != 0) + { + //A device has been detected, so get more information about it. + /* + API function: SetupDiGetDeviceInterfaceDetail + Returns: an SP_DEVICE_INTERFACE_DETAIL_DATA structure + containing information about a device. + To retrieve the information, call this function twice. + The first time returns the size of the structure in Length. + The second time returns a pointer to the data in DeviceInfoSet. + Requires: + A DeviceInfoSet returned by SetupDiGetClassDevs + The SP_DEVICE_INTERFACE_DATA structure returned by SetupDiEnumDeviceInterfaces. + + The final parameter is an optional pointer to an SP_DEV_INFO_DATA structure. + This application doesn't retrieve or use the structure. + If retrieving the structure, set + MyDeviceInfoData.cbSize = length of MyDeviceInfoData. + and pass the structure's address. + */ + //Get the Length value. + //The call will return with a "buffer too small" error which can be ignored. + Result = SetupDiGetDeviceInterfaceDetail(hDevInfo, &devInfoData, NULL, 0, &Length, NULL); + + //Allocate memory for the hDevInfo structure, using the returned Length. + detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(Length); + + //Set cbSize in the detailData structure. + detailData -> cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); + + //Call the function again, this time passing it the returned buffer size. + Result = SetupDiGetDeviceInterfaceDetail(hDevInfo, &devInfoData, detailData, Length,&Required, NULL); + + // Open a handle to the device. + // To enable retrieving information about a system mouse or keyboard, + // don't request Read or Write access for this handle. + /* + API function: CreateFile + Returns: a handle that enables reading and writing to the device. + Requires: + The DevicePath in the detailData structure + returned by SetupDiGetDeviceInterfaceDetail. + */ + DeviceHandle=CreateFile(detailData->DevicePath, + 0, FILE_SHARE_READ|FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL,OPEN_EXISTING, 0, NULL); + + /* + API function: HidD_GetAttributes + Requests information from the device. + Requires: the handle returned by CreateFile. + Returns: a HIDD_ATTRIBUTES structure containing + the Vendor ID, Product ID, and Product Version Number. + Use this information to decide if the detected device is + the one we're looking for. + */ + + //Set the Size to the number of bytes in the structure. + Attributes.Size = sizeof(Attributes); + Result = HidD_GetAttributes(DeviceHandle,&Attributes); + + //Is it the desired device? + MyDeviceDetected = FALSE; + if (Attributes.VendorID == vid) + { + if (Attributes.ProductID == pid) + { + //Both the Vendor ID and Product ID match. + MyDeviceDetected = TRUE; + strcpy(MyDevicePathName,detailData->DevicePath); + + // Get a handle for writing Output reports. + WriteHandle=CreateFile(detailData->DevicePath, + GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL,OPEN_EXISTING,0,NULL); + + //Get a handle to the device for the overlapped ReadFiles. + ReadHandle=CreateFile(detailData->DevicePath, + GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,(LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL); + + if (hEventObject) CloseHandle(hEventObject); + hEventObject = CreateEvent(NULL,TRUE,TRUE,""); + + //Set the members of the overlapped structure. + HIDOverlapped.hEvent = hEventObject; + HIDOverlapped.Offset = 0; + HIDOverlapped.OffsetHigh = 0; + Result=HidD_SetNumInputBuffers(DeviceHandle,64); + } + else + //The Product ID doesn't match. + CloseHandle(DeviceHandle); + } + else + //The Vendor ID doesn't match. + CloseHandle(DeviceHandle); + //Free the memory used by the detailData structure (no longer needed). + free(detailData); + } + else + //SetupDiEnumDeviceInterfaces returned 0, so there are no more devices to check. + LastDevice=TRUE; + //If we haven't found the device yet, and haven't tried every available device, + //try the next one. + MemberIndex = MemberIndex + 1; + } //do + while ((LastDevice == FALSE) && (MyDeviceDetected == FALSE)); + //Free the memory reserved for hDevInfo by SetupDiClassDevs. + SetupDiDestroyDeviceInfoList(hDevInfo); + + if (MyDeviceDetected == FALSE){ + printf("Can't find device\n"); + return -1; + } + + if(info){ + printf("Device detected: vid=0x%04X pid=0x%04X\nPath: %s\n",vid,pid,MyDevicePathName); + if(HidD_GetManufacturerString(DeviceHandle,string,sizeof(string))==TRUE) wprintf(L"Manufacturer string: %s\n",string); + if(HidD_GetProductString(DeviceHandle,string,sizeof(string))==TRUE) wprintf(L"Product string: %s\n",string); + } +#endif + return 0; +} diff --git a/icd.c b/icd.c new file mode 100644 index 0000000..3cf8e39 --- /dev/null +++ b/icd.c @@ -0,0 +1,1541 @@ +//General routines to communicate via ICD with a target +#include "common.h" +#include "coff.h" + +extern int saveLog; +extern double Tcom; +extern int running; +extern int DeviceDetected; +extern GtkWidget * b_log; +extern char* cur_path; + +GtkWidget * statusTxt; +GtkWidget * sourceTxt; +GtkTextBuffer * sourceBuf; +GtkWidget * icdVbox1; +GtkWidget * icdMenuPC; +GtkWidget * icdMenuSTAT; +GtkWidget * icdMenuBank0; +GtkWidget * icdMenuBank1; +GtkWidget * icdMenuBank2; +GtkWidget * icdMenuBank3; +GtkWidget * icdMenuEE; +GtkWidget * icdCommand; +GtkTextBuffer * statusBuf; +int icdTimer=0; +int break_addr,print_addr; +int currentSource=-1; +int sourceHilight=0; +char lastCmd[64]=""; +int UseCoff=0; +struct src_i source_info[LMAX]; +struct srcfile *s_files; +struct symbol *sym; +int nsym=0; +char* Slabel[LMAX],*Sulabel[ULMAX]; +struct symbol *watch; +int nwatch=0; +unsigned short coff_data[DATA_MAX]; +int ver=0,reset=1,freeze=0,icdConnected=0,running=0; +#define Tck 30 +double Tcom=0.001*Tck*18+0.03; //communication time for a 16 bit tranfer (ms) + +void ShowContext(); + +//The following commands are implemented in the debugger monitor +//routine which is written in the last memory page on the target chip. +#define VER 1 //;version +#define STEP 2 //;step +#define GO 3 //;go +#define RREG 4 //;read register +#define WREG 5 //;write register +#define EEADR 0x10D +#define EEADRH 0x10F +#define EEDATA 0x10C +#define EEDATH 0x10E +#define EECON1 0x18C +#define EECON2 0x18D +#define w_temp 0x6B +#define status_temp 0x6C +#define pclath_temp 0x6D +#define fsr_temp 0x6E + +struct var{ char* name; int display;} variables[0x200]; + +//Prepare ICD interface by resetting the target with a power-up sequence. +//MCLR is low so the target is reset even if power is not supplied by the programmer. +//Set communication speed at 1/(2*Tck us) +void startICD(int tck){ + int j=0; + bufferU[j++]=PROG_RST; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T1T2; + bufferU[j++]=tck; //T1=XXu + bufferU[j++]=100; //T2=100u + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; //2ms + bufferU[j++]=2000>>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=VREG_DIS; //disable HV regulator + bufferU[j++]=EN_VPP_VCC; // reset target + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x2; //set D as input + bufferU[j++]=EN_VPP_VCC; // power-up + bufferU[j++]=0x1; + bufferU[j++]=FLUSH; + for(;j debugger monitor running +int isRunning(){ + int z,j=0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //D=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x2; //set D as input + bufferU[j++]=READ_PINS; + bufferU[j++]=FLUSH; + for(;j>8)+(freeze?0x40:0); + bufferU[j++]=0x1; + bufferU[j++]=0x8E; + bufferU[j++]=TX16; + bufferU[j++]=0x2; + bufferU[j++]=WREG; //write register + bufferU[j++]=break_addr&0xFF; + bufferU[j++]=0x1; + bufferU[j++]=0x8F; + bufferU[j++]=TX16; + bufferU[j++]=0x1; + bufferU[j++]=GO; //GO + bufferU[j++]=0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x2; //set D as input + bufferU[j++]=FLUSH; + for(;j>8)&0xFF; + bufferU[j++]=addr&0xFF; + bufferU[j++]=RX16; + bufferU[j++]=0x1; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x2; //set D as input + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=(addr+i)&0xFF; + bufferU[j++]=RX16; + bufferU[j++]=w; + bufferU[j++]=FLUSH; + for(;j>8)&0xFF; + bufferU[j++]=addr&0xFF; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x2; //set D as input + bufferU[j++]=FLUSH; + for(;j>8); + WriteRegister(EEADR,addr&0xFF); + WriteRegister(EECON1,eecon_temp|0x80); //EEPGD=1 + WriteRegister(EECON1,eecon_temp|0x81); //EEPGD=1 + RD=1 + data=(ReadRegister(EEDATH)<<8)+ReadRegister(EEDATA); + WriteRegister(EEADRH,addr_temp<<8); + WriteRegister(EEADR,addr_temp&0xFF); + WriteRegister(EEDATH,data_temp<<8); + WriteRegister(EEDATA,data_temp&0xFF); + WriteRegister(EECON1,eecon_temp); + return data; +} + +//Read program memory (n locations) starting at address addr +int ReadProgMemN(int addr,int n,int* buf){ + int addr_temp, data_temp, eecon_temp; + if(saveLog) fprintf(logfile,"ReadProgMemN(0x%X,%d)\n",addr,n); + int i,j=0,z,w,k; + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=RREG; //Read register + bufferU[j++]=4; //4 bytes: EEDATA,EEADR,EEDATH,EEADRH + bufferU[j++]=(EEDATA>>8)&0xFF; + bufferU[j++]=EEDATA&0xFF; + bufferU[j++]=RX16; + bufferU[j++]=4; + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=RREG; //Read register + bufferU[j++]=1; //1 byte + bufferU[j++]=(EECON1>>8)&0xFF; + bufferU[j++]=EECON1&0xFF; + bufferU[j++]=RX16; + bufferU[j++]=1; + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=WREG; //write register + bufferU[j++]=0x80; //EEPGD=1 + bufferU[j++]=(EECON1>>8)&0xFF; + bufferU[j++]=EECON1&0xFF; + bufferU[j++]=FLUSH; + for(;j>8)&0xFF; + bufferU[j++]=EEADR&0xFF; + bufferU[j++]=WREG; //write register + bufferU[j++]=((addr+i)>>8)&0xFF; + bufferU[j++]=(EEADRH>>8)&0xFF; + bufferU[j++]=EEADRH&0xFF; + bufferU[j++]=WREG; //write register + bufferU[j++]=0x81; //RD=1 + bufferU[j++]=(EECON1>>8)&0xFF; + bufferU[j++]=EECON1&0xFF; + bufferU[j++]=RREG; //Read register + bufferU[j++]=3; //3 bytes: EEDATA,EEADR,EEDATH + bufferU[j++]=(EEDATA>>8)&0xFF; + bufferU[j++]=EEDATA&0xFF; + bufferU[j++]=RX16; + bufferU[j++]=3; + w++; + if(j>DIMBUF-21||i==n-1){ + bufferU[j++]=FLUSH; + for(;j>8)&0xFF; + bufferU[j++]=EECON1&0xFF; + bufferU[j++]=WREG; //write register + bufferU[j++]=data_temp&0xFF; + bufferU[j++]=(EEDATA>>8)&0xFF; + bufferU[j++]=EEDATA&0xFF; + bufferU[j++]=WREG; //write register + bufferU[j++]=data_temp>>8; + bufferU[j++]=(EEDATH>>8)&0xFF; + bufferU[j++]=EEDATH&0xFF; + bufferU[j++]=WREG; //write register + bufferU[j++]=addr_temp&0xFF; + bufferU[j++]=(EEADR>>8)&0xFF; + bufferU[j++]=EEADR&0xFF; + bufferU[j++]=WREG; //write register + bufferU[j++]=addr_temp>>8; + bufferU[j++]=(EEADRH>>8)&0xFF; + bufferU[j++]=EEADRH&0xFF; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x2; //set D as input + bufferU[j++]=FLUSH; + for(;j>8)&0xFF; + bufferU[j++]=EEDATA&0xFF; + bufferU[j++]=RX16; + bufferU[j++]=2; + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=RREG; //Read register + bufferU[j++]=1; //1 byte + bufferU[j++]=(EECON1>>8)&0xFF; + bufferU[j++]=EECON1&0xFF; + bufferU[j++]=RX16; + bufferU[j++]=1; + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=WREG; //write register + bufferU[j++]=0; //EEPGD=0 + bufferU[j++]=(EECON1>>8)&0xFF; + bufferU[j++]=EECON1&0xFF; + bufferU[j++]=FLUSH; + for(;j>8)&0xFF; + bufferU[j++]=EEADR&0xFF; + bufferU[j++]=WREG; //write register + bufferU[j++]=0x1; //RD=1 + bufferU[j++]=(EECON1>>8)&0xFF; + bufferU[j++]=EECON1&0xFF; + bufferU[j++]=RREG; //Read register + bufferU[j++]=1; // EEDATA + bufferU[j++]=(EEDATA>>8)&0xFF; + bufferU[j++]=EEDATA&0xFF; + bufferU[j++]=RX16; + bufferU[j++]=1; + w++; + if(j>DIMBUF-17||i==n-1){ + bufferU[j++]=FLUSH; + for(;j>8)&0xFF; + bufferU[j++]=EECON1&0xFF; + bufferU[j++]=WREG; //write register + bufferU[j++]=data_temp&0xFF; + bufferU[j++]=(EEDATA>>8)&0xFF; + bufferU[j++]=EEDATA&0xFF; + bufferU[j++]=WREG; //write register + bufferU[j++]=addr_temp&0xFF; + bufferU[j++]=(EEADR>>8)&0xFF; + bufferU[j++]=EEADR&0xFF; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x2; //set D as input + bufferU[j++]=FLUSH; + for(;j>12)==0){ //byte oriented instructions + if((cmd>>8)==0&&cmd&0x80) sprintf(str,"movwf %s",getVar(addrH+(cmd&0x7F),reg)); + else if((cmd>>8)==1){ + if(cmd&0x80) sprintf(str,"clrf %s",getVar(addrH+(cmd&0x7F),reg)); + else sprintf(str,"clrf w"); + } + else{ + switch(cmd>>8){ + case 2: + sprintf(ins,"subwf"); + break; + case 3: + sprintf(ins,"decf"); + break; + case 4: + sprintf(ins,"iorwf"); + break; + case 5: + sprintf(ins,"andwf"); + break; + case 6: + sprintf(ins,"xorwf"); + break; + case 7: + sprintf(ins,"addwf"); + break; + case 8: + sprintf(ins,"movf"); + break; + case 9: + sprintf(ins,"comf"); + break; + case 10: + sprintf(ins,"incf"); + break; + case 11: + sprintf(ins,"decfsz"); + break; + case 12: + sprintf(ins,"rrf"); + break; + case 13: + sprintf(ins,"rlf"); + break; + case 14: + sprintf(ins,"swapf"); + break; + case 15: + sprintf(ins,"incfsz"); + break; + default: + sprintf(ins,"???"); + break; + } + sprintf(str,"%s %s,%c",ins,getVar(addrH+(cmd&0x7F),reg),cmd&0x80?'f':'w'); + } + } + else if((cmd>>12)==1){ //bit oriented instructions + switch(cmd>>10){ + case 4: + sprintf(ins,"bcf"); + break; + case 5: + sprintf(ins,"bsf"); + break; + case 6: + sprintf(ins,"btfsc"); + break; + case 7: + sprintf(ins,"btfss"); + break; + default: + sprintf(ins,"??"); //(not possible) + } + sprintf(str,"%s %s,%d",ins,getVar(addrH+(cmd&0x7F),reg),(cmd&0x380)>>7); + } + else if((cmd>>12)==2) sprintf(str,"%s 0x%X",cmd&0x800?"goto":"call",cmd&0x7FF); + else if((cmd>>10)==0xC) sprintf(str,"movlw 0x%X",cmd&0xFF); + else if((cmd>>10)==0xD) sprintf(str,"retlw 0x%X",cmd&0xFF); + else if((cmd>>9)==0x1E) sprintf(str,"sublw 0x%X",cmd&0xFF); + else if((cmd>>9)==0x1F) sprintf(str,"addlw 0x%X",cmd&0xFF); + else if((cmd>>8)==0x38) sprintf(str,"iorlw 0x%X",cmd&0xFF); + else if((cmd>>8)==0x39) sprintf(str,"andlw 0x%X",cmd&0xFF); + else if((cmd>>8)==0x3A) sprintf(str,"xorlw 0x%X",cmd&0xFF); + else sprintf(str,"unknown command"); + return str; +} + +//Functions tied to GUI: +/// +///Print a message on the ICD data field +void PrintMessageICD(const char *msg){ + GtkTextIter iter; + gtk_text_buffer_set_text(statusBuf,msg,-1); + gtk_text_buffer_get_start_iter(statusBuf,&iter); + gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(statusTxt),&iter,0.0,FALSE,0,0); + while (gtk_events_pending ()) gtk_main_iteration(); +} +/// +///Append a message on the ICD data field +void AppendMessageICD(const char *msg){ + GtkTextIter iter; + gtk_text_buffer_get_end_iter(statusBuf,&iter); + gtk_text_buffer_insert(statusBuf,&iter,msg,-1); + gtk_text_buffer_get_start_iter(statusBuf,&iter); + gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(statusTxt),&iter,0.0,FALSE,0,0); + while (gtk_events_pending ()) gtk_main_iteration(); +} +/// +///Scroll source file +void scrollToLine(int line) +{ + GtkTextIter iter,iter2; + gtk_text_buffer_get_end_iter(sourceBuf,&iter); + if(line>0){ + gtk_text_iter_set_line(&iter,line-1); + iter2=iter; + gtk_text_iter_forward_char(&iter2); + gtk_text_iter_forward_to_line_end(&iter2); + } + else{ + gtk_text_buffer_get_selection_bounds(sourceBuf,&iter,&iter2); + iter2=iter; + } + gtk_text_buffer_select_range(sourceBuf,&iter,&iter2); + while (gtk_events_pending ()) gtk_main_iteration(); + gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(sourceTxt),&iter,0.0,TRUE,0,0.5); +} +/// +///Hilight line in source code +void SourceHilightLine(int line) +{ + GtkTextIter iter,iter2; + GtkTextTag* tag; + if(line>0){ + tag=gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(sourceBuf),"break_text"); + if(!tag) tag=gtk_text_buffer_create_tag(sourceBuf,"break_text","background","red", NULL); + gtk_text_buffer_get_end_iter(sourceBuf,&iter); + gtk_text_iter_set_line(&iter,line-1); + iter2=iter; + gtk_text_iter_forward_char(&iter2); + gtk_text_iter_forward_to_line_end(&iter2); + gtk_text_buffer_apply_tag (sourceBuf,tag,&iter,&iter2); + } + while (gtk_events_pending ()) gtk_main_iteration(); +} +/// +///Remove hilight line in source code +void SourceRemoveHilightLine(int line) +{ + GtkTextIter iter,iter2; + if(line>0){ + gtk_text_buffer_get_end_iter(sourceBuf,&iter); + gtk_text_iter_set_line(&iter,line-1); + iter2=iter; + gtk_text_iter_forward_char(&iter2); + gtk_text_iter_forward_to_line_end(&iter2); + gtk_text_buffer_remove_tag_by_name(sourceBuf,"break_text",&iter,&iter2); + } + while (gtk_events_pending ()) gtk_main_iteration(); +} +/// +///load source file into source pane +int loadSource(FILE *f){ + if(!f) return 0; + fseek(f,0,SEEK_END); + int size=ftell(f); + fseek(f,0,SEEK_SET); + char* tmp=(char*)malloc(size+1); + size=fread(tmp,1,size,f); + tmp[size]=0; + char* g=g_locale_to_utf8(tmp,-1,NULL,NULL,NULL); + gtk_text_buffer_set_text(sourceBuf,g,-1); + free(tmp); + g_free(g); + return 1; +} +/// +///load and analyze coff file +void loadCoff(GtkWidget *widget,GtkWidget *window) +{ + GtkFileChooser *dialog; + dialog = (GtkFileChooser*) gtk_file_chooser_dialog_new (strings[I_LOAD_COFF], //"Open Coff File", + GTK_WINDOW(window), + GTK_FILE_CHOOSER_ACTION_OPEN, + strings[I_CANCEL], GTK_RESPONSE_CANCEL, + strings[I_OPEN], GTK_RESPONSE_ACCEPT, + NULL); + if(cur_path) gtk_file_chooser_set_current_folder(dialog,cur_path); + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT){ + char *filename; + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + if(cur_path) free(cur_path); + cur_path = gtk_file_chooser_get_current_folder(dialog); + UseCoff=analyzeCOFF(filename,Slabel,Sulabel,source_info,&s_files,coff_data,&sym,&nsym); + g_free (filename); + //load source for address 0 + if(source_info[0].src_file!=-1){ + if(currentSource==source_info[0].src_file){ + scrollToLine(source_info[0].src_line); + } + else if(loadSource(s_files[source_info[0].src_file].ptr)){ + scrollToLine(source_info[0].src_line); + currentSource=source_info[0].src_file; + } + } + } + gtk_widget_destroy (GTK_WIDGET(dialog)); +} +/// +/// List of variables used when decoding an assembly word +void initVar(){ + int i; + for(i=0;i<0x200;i++){//clear variable list + variables[i].name=0; + variables[i].display=0; + } + variables[0].name="INDF"; + variables[1].name="TMR0"; + variables[2].name="PCL"; + variables[3].name="STATUS"; + variables[4].name="FSR"; + variables[5].name="PORTA"; + variables[6].name="PORTB"; + variables[7].name="PORTC"; + variables[8].name="PORTD"; + variables[9].name="PORTE"; + variables[10].name="PCLATH"; + variables[11].name="INTCON"; + variables[12].name="PIR1"; + variables[13].name="PIR2"; + variables[14].name="TMR1L"; + variables[15].name="TMR1H"; + variables[16].name="T1CON"; + variables[17].name="TMR2"; + variables[18].name="T2CON"; + variables[19].name="SSPBUF"; + variables[20].name="SSPCON"; + variables[21].name="CCPR1L"; + variables[22].name="CCPR1H"; + variables[23].name="CCP1CON"; + variables[24].name="RCSTA"; + variables[25].name="TXREG"; + variables[26].name="RCREG"; + variables[27].name="CCPR2L"; + variables[28].name="CCPR2H"; + variables[29].name="CCP2CON"; + variables[30].name="ADRESH"; + variables[31].name="ADCON0"; + variables[0x6B].name="DEBUG_VAR1"; + variables[0x6C].name="DEBUG_VAR2"; + variables[0x6D].name="DEBUG_VAR3"; + variables[0x6E].name="DEBUG_VAR4"; + variables[0x6F].name="DEBUG_VAR5"; + variables[0x70].name="DEBUG_VAR6"; + variables[0x71].name="DEBUG_VAR7"; + variables[0x72].name="DEBUG_VAR8"; + variables[0x80].name="INDF"; + variables[0x81].name="OPTION_REG"; + variables[0x82].name="PCL"; + variables[0x83].name="STATUS"; + variables[0x84].name="FSR"; + variables[0x85].name="TRISA"; + variables[0x86].name="TRISB"; + variables[0x87].name="TRISC"; + variables[0x88].name="TRISD"; + variables[0x89].name="TRISE"; + variables[0x8A].name="PCLATH"; + variables[0x8B].name="INTCON"; + variables[0x8C].name="PIE1"; + variables[0x8D].name="PIE2"; + variables[0x8E].name="PCON"; + variables[0x91].name="SSPCON2"; + variables[0x92].name="PR2"; + variables[0x93].name="SSPADD"; + variables[0x94].name="SSPSTAT"; + variables[0x98].name="TXSTA"; + variables[0x99].name="SPBRG"; + variables[0x9E].name="ADRESL"; + variables[0x9F].name="ADCON1"; + variables[0x100].name="INDF"; + variables[0x101].name="TMR0"; + variables[0x102].name="PCL"; + variables[0x103].name="STATUS"; + variables[0x104].name="FSR"; + variables[0x106].name="PORTB"; + variables[0x10A].name="PCLATH"; + variables[0x10B].name="INTCON"; + variables[0x10C].name="EEDATA"; + variables[0x10D].name="EEADR"; + variables[0x10E].name="EEDATH"; + variables[0x10F].name="EEADRH"; + variables[0x180].name="INDF"; + variables[0x181].name="OPTION_REG"; + variables[0x182].name="PCL"; + variables[0x183].name="STATUS"; + variables[0x184].name="FSR"; + variables[0x186].name="TRISB"; + variables[0x18A].name="PCLATH"; + variables[0x18B].name="INTCON"; + variables[0x18C].name="EECON1"; + variables[0x18D].name="EECON2"; +} +/// +///Show ICD help window +void ICDHelp(GtkWidget *widget,GtkWidget *window) +{ + GtkWidget* dialog = gtk_message_dialog_new (GTK_WINDOW(window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_CLOSE, + strings[I_ICD_HELP_TXT]); + + g_signal_connect_swapped (GTK_WINDOW(dialog), "response",G_CALLBACK (gtk_widget_destroy),dialog); + gtk_window_set_title(GTK_WINDOW(dialog),strings[I_ICD_HELP]); + gtk_widget_show_all (dialog); +} +/// +///ICD: check if program is running +void icdCheck(GtkWidget *widget,GtkWidget *window) +{ +#ifndef DEBUG + if(DeviceDetected!=1) return; +#endif + if(!isRunning()){ + g_source_remove(icdTimer); + ShowContext(); + } +} +/// +///ICD: run program +void icdRun(GtkWidget *widget,GtkWidget *window) +{ +#ifndef DEBUG + if(DeviceDetected!=1) return; +#endif + if(!icdConnected){ + saveLog = (int) gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b_log)); + if(saveLog){ + OpenLogFile(); //"Log.txt" + fprintf(logfile,"ICD start\n"); + } + startICD(Tck); //start ICD mode by supplying the target and forcing a reset + run(); //remove reset + icdConnected=1; + icdTimer=g_timeout_add(20,(GSourceFunc)icdCheck,NULL); + PrintMessageICD("running"); + } + else if(!running){ + cont(break_addr,freeze); //continue execution + icdTimer=g_timeout_add(20,(GSourceFunc)icdCheck,NULL); + PrintMessageICD("running"); + } +} +/// +///ICD: halt program +void icdHalt(GtkWidget *widget,GtkWidget *window) +{ +#ifndef DEBUG + if(DeviceDetected!=1) return; +#endif + if(running){ + g_source_remove(icdTimer); + Halt(); + ShowContext(); + } +} +/// +///ICD: step program +void icdStep(GtkWidget *widget,GtkWidget *window) +{ +#ifndef DEBUG + if(DeviceDetected!=1) return; +#endif + if(running){ + g_source_remove(icdTimer); + Halt(); + } + step(); +#ifdef DEBUG + addrDebug++; +#endif + ShowContext(); +} +/// +///ICD: step program jumping over calls +void icdStepOver(GtkWidget *widget,GtkWidget *window) +{ +#ifndef DEBUG + if(DeviceDetected!=1) return; +#endif + int addr,data; + if(running){ + g_source_remove(icdTimer); + Halt(); + } + addr=((ReadRegister(0x18E)&0x1F)<<8)+ReadRegister(0x18F); + data=ReadProgMem(addr); + if((data>>11)==4){ //if call break at return address + cont(addr+1,freeze); + icdTimer=g_timeout_add(20,(GSourceFunc)icdCheck,NULL); + } + else{ //normal step + step(); + #ifdef DEBUG + addrDebug++; + #endif + ShowContext(); + } +} +/// +///ICD: stop program +void icdStop(GtkWidget *widget,GtkWidget *window) +{ +#ifndef DEBUG + if(DeviceDetected!=1) return; +#endif + if(running){ + g_source_remove(icdTimer); + Halt(); + } +// bufferU[0]=0; + int j=0; + bufferU[j++]=EN_VPP_VCC; // reset target + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x2; //set D as input + bufferU[j++]=FLUSH; + for(;j3) bank=3; + if(bank<0) bank=0; + int b[128]; + char temp[128]; + int i; + sprintf(temp,"bank %d:",bank); + strcat(status,temp); + ReadRegisterN(bank*0x80,128,b); + for(i=0;i<128;i++){ + if(i%16==0){ + sprintf(temp,"\n0x%03X:",i+bank*0x80); + strcat(status,temp); + } + sprintf(temp,"%02X",b[i]); + strcat(status,temp); + } + strcat(status,"\n"); +} +/// +/// Main ICD show function: +/// prints status info according to selected options +/// and the value of variables in the watch list +void ShowContext(){ + int i,addr,data,s; + char cmd[32]=""; + char status[4096]="",temp[128]; + addr=((ReadRegister(0x18E)&0x1F)<<8)+ReadRegister(0x18F); + data=ReadProgMem(addr); + s=ReadRegister(status_temp); + s=(s>>4)+((s<<4)&0xF0); //STATUS is swapped +// printf("addr %X, status %X, data %X\n",addr,s,data); +#ifdef DEBUG + addr=addrDebug; + s=statusDebug; + if(UseCoff) data=coff_data[addr]; +#endif + if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(icdMenuPC))){ + sprintf(temp,"%s: %s (0x%04X) \nPC=0x%04X\n",strings[S_NextIns],decodeCmd(data,cmd,(s&0x60)<<2),data,addr); //"Next instruction" + strcat(status,temp); + } + if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(icdMenuSTAT))){ + sprintf(temp,"STATUS=0x%02X (",s); + strcat(status,temp); + sprintf(temp,"%s ",s&0x80?"IRP":" "); + strcat(status,temp); + sprintf(temp,"%s ",s&0x40?"RP1":" "); + strcat(status,temp); + sprintf(temp,"%s ",s&0x20?"RP0":" "); + strcat(status,temp); + sprintf(temp,"%s ",s&0x10?"TO":" "); + strcat(status,temp); + sprintf(temp,"%s ",s&0x8?"PD":" "); + strcat(status,temp); + sprintf(temp,"%s ",s&0x4?"Z":" "); + strcat(status,temp); + sprintf(temp,"%s ",s&0x2?"DC":" "); + strcat(status,temp); + sprintf(temp,"%s)\n",s&0x1?"C":" "); + strcat(status,temp); + sprintf(temp,"W=0x%02X PCLATH=0x%02X FSR=0x%02X\n",ReadRegister(w_temp),ReadRegister(pclath_temp),ReadRegister(fsr_temp)); + strcat(status,temp); + } + if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(icdMenuBank0))) ShowBank(0,status); + if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(icdMenuBank1))) ShowBank(1,status); + if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(icdMenuBank2))) ShowBank(2,status); + if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(icdMenuBank3))) ShowBank(3,status); + int rawsource=0; + if(UseCoff){ //hilight corresponding source line + if(data!=coff_data[addr]){ + sprintf(temp,"code at address 0x%04X (0x%04X) is different than what specified in coff file (0x%04X)\n",addr,data,coff_data[addr]); + strcat(status,temp); + rawsource=1; + } +#ifndef DEBUG + else{ +#endif +// printf("addr %d, file %d, line %d, current %d, ptr %X\n",addr,source_info[addr].src_file,source_info[addr].src_line,currentSource,s_files[source_info[addr].src_file].ptr); + if(source_info[addr].src_file!=-1){ + if(currentSource==source_info[addr].src_file) scrollToLine(source_info[addr].src_line); + else if(loadSource(s_files[source_info[addr].src_file].ptr)){ + scrollToLine(source_info[addr].src_line); + currentSource=source_info[addr].src_file; + } + else rawsource=1; + } + else rawsource=1; +#ifndef DEBUG + } +#endif + } + if(!UseCoff || rawsource==1){ //show raw source if no source file is available + #define LINES_BEFORE 5 + #define LINES_AFTER 7 + #define NLINES LINES_BEFORE + LINES_AFTER + int addr0,addr1,line_pc=0; + char tmp[64*NLINES],t2[64]; + tmp[0]=0; + int progmem[NLINES]; + addr0=addr-LINES_BEFORE<0?0:addr-LINES_BEFORE; + addr1=addr+LINES_AFTER>0x1FFF?0x1FFF:addr+LINES_AFTER; + ReadProgMemN(addr0,addr1-addr0,progmem); + for(i=addr0;i>8)+(freeze?0x40:0)); + } + sprintf(str,"peripheral freeze is %s\n",freeze?"on":"off"); + AppendMessageICD(str); + } +//******************* halt ******************************** + else if(!strcmp(command,"h")||!strcmp(command,"halt")){ + icdHalt(NULL,NULL); + } +//******************* help ******************************** + else if(!strcmp(command,"help")){ + ICDHelp(NULL,NULL); + } +//******************* list ******************************** + else if(strstr(command,"list ")){ + #define LISTLINES 10 + int addr,i; + char tmp[32*LISTLINES],t2[32],cmd[32]=""; + tmp[0]=0; + int progmem[LISTLINES]; + if(sscanf(command,"list %x",&addr)==1){ + addr&=0x1FFF; + ReadProgMemN(addr,LISTLINES,progmem); + for(i=0;i3) bank/=0x80; + if(running) Halt(); + ShowBank(bank,str); + AppendMessageICD(str); + } + else if(sscanf(command,"print 0x%x",&print_addr)==1||sscanf(command,"p 0x%x",&print_addr)==1){ //mem address + print_addr&=0x1FF; + if(running) Halt(); + sprintf(str,"[0x%03X]=0x%02X\n",print_addr,ReadRegister(print_addr)); + AppendMessageICD(str); + } + else if(sscanf(command,"print %s",var)==1||sscanf(command,"p %s",var)==1){ //var name + str[0]=0; + if(running) Halt(); + if(!strcmp("W",var)||!strcmp("w",var)) sprintf(str,"W = 0x%02X\n",ReadRegister(w_temp)); + else if(!strcmp("STATUS",var)) sprintf(str,"0x003: STATUS = 0x%02X\n",ReadRegister(status_temp)); + else if(!strcmp("FSR",var)) sprintf(str,"0x004: FSR = 0x%02X\n",ReadRegister(fsr_temp)); + else if(!strcmp("PCLATH",var)) sprintf(str,"0x00A: PCLATH = 0x%02X\n",ReadRegister(pclath_temp)); + else{ + for(i=0;i1)sprintf(str,"step %d\n",n); + else str[0]=0; + ShowContext(); + AppendMessageICD(str); + } +//******************* step over ******************************** + else if(!strcmp(command,"ss")||!strcmp(command,"step over")||strstr(command,"step over ")||strstr(command,"ss ")){ + int i,n=1; + sscanf(command,"step over %d",&n); + sscanf(command,"ss %d",&n); +#ifdef DEBUG + addrDebug+=n; +#endif + for(i=0;i1)sprintf(str,"step over %d\n",n); + AppendMessageICD(str); + } +//******************* version ******************************** + else if(!strcmp(command,"ver")||!strcmp(command,"version")){ + if(running) Halt(); + sprintf(str,"debugger version: %.1f\n",version()/10.0); + AppendMessageICD(str); + } +//******************* watch ******************************** + else if(strstr(command,"watch ")||strstr(command,"w ")){ + int i,var_addr; + char var[64]; + if(sscanf(command,"watch 0x%x",&var_addr)||sscanf(command,"w 0x%x",&var_addr)){ + struct symbol s; + sprintf(var,"[0x%X]",var_addr); + s.name=strdup(var); + s.value=var_addr; + addWatch(s); + if(!running) ShowContext(); + } + else if(sscanf(command,"watch %s",var)||sscanf(command,"w %s",var)){ + for(i=0;itype==GDK_2BUTTON_PRESS){ + gint x,y,i; + GtkTextIter iter,iter2,itx; + gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(widget),GTK_TEXT_WINDOW_WIDGET,event->x,event->y,&x,&y); + gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget),&iter,x,y); +// printf("x %d y %d\n",x,y); + iter2=iter; + char c; + for(itx=iter2,c=gtk_text_iter_get_char(&itx);isalnum(c)||c=='_';iter2=itx){ + gtk_text_iter_forward_char(&itx); + c=gtk_text_iter_get_char(&itx); + } + for(itx=iter,c=gtk_text_iter_get_char(&itx);isalnum(c)||c=='_';iter=itx){ + gtk_text_iter_backward_char(&itx); + c=gtk_text_iter_get_char(&itx); + } + gtk_text_iter_forward_char(&iter); + char* selection=gtk_text_buffer_get_text(sourceBuf,&iter,&iter2,FALSE); + for(i=0;i0 && (coff_data[i-1]>>11)!=4) i--; //if not a call break at previous address; + break_addr=i; + sprintf(str,"break at address 0x%x\n",i); + AppendMessageICD(str); + SourceRemoveHilightLine(sourceHilight); + SourceHilightLine(line); + sourceHilight=line; + break; + } + } + } + return FALSE; +} +/// +///Handle mouse events in ICD status window +gint icdStatus_mouse_event(GtkWidget *widget, GdkEventButton *event, gpointer func_data) +{ + if(GTK_IS_TEXT_VIEW(widget)&&event->type==GDK_2BUTTON_PRESS){ + gint x,y; + GtkTextIter iter,iter2,itx; + gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(widget),GTK_TEXT_WINDOW_WIDGET,event->x,event->y,&x,&y); + gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(widget),&iter,x,y); + iter2=iter; + char c; + for(itx=iter2,c=gtk_text_iter_get_char(&itx);isalnum(c)||c=='_';iter2=itx){ + gtk_text_iter_forward_char(&itx); + c=gtk_text_iter_get_char(&itx); + } + for(itx=iter,c=gtk_text_iter_get_char(&itx);isalnum(c)||c=='_';iter=itx){ + gtk_text_iter_backward_char(&itx); + c=gtk_text_iter_get_char(&itx); + } + gtk_text_iter_forward_char(&iter); + char* selection=gtk_text_buffer_get_text(statusBuf,&iter,&iter2,FALSE); + if(removeWatch(selection)) ShowContext(); + } + return FALSE; +} +/// +///Handle keyboard events in ICD command edit box +gint icdCommand_key_event(GtkWidget *widget, GdkEventButton *event, gpointer func_data) +{ + if(event->type==GDK_KEY_PRESS&&((GdkEventKey*)event)->keyval==0xFF0D){ //enter + char s[64]; + strncpy(s,gtk_entry_get_text(GTK_ENTRY(icdCommand)),63); + if(!strlen(s)){ + strcpy(s,lastCmd); + gtk_entry_set_text(GTK_ENTRY(icdCommand),s); //briefly flash last command + while (gtk_events_pending ()) gtk_main_iteration(); + msDelay(60); + } + else strcpy(lastCmd,s); + if(executeCommand(s)) gtk_entry_set_text(GTK_ENTRY(icdCommand),""); +// sprintf(s,"k=%X\n",((GdkEventKey*)event)->keyval); +// AppendMessageICD(gtk_entry_get_text(icdCommand)); + } + return FALSE; +} +/// +///Handle keyboard events in ICD tab +gint icd_key_event(GtkWidget *widget, GdkEventButton *event, gpointer func_data) +{ + while (gtk_events_pending ()) gtk_main_iteration(); //wait completion of other tasks + if(event->type==GDK_KEY_PRESS){ + switch(((GdkEventKey*)event)->keyval){ + case 0xFFBE: + ICDHelp(NULL,NULL); //F1 = help + break; + case 0xFFC2: + icdHalt(NULL,NULL); //F5 = halt + break; + case 0xFFC4: + icdStep(NULL,NULL); //F7 = step + break; + case 0xFFC5: + icdStepOver(NULL,NULL); //F8 = step over + break; + case 0xFFC6: + icdRun(NULL,NULL); //F9 = run + break; + } +// char s[64]; +// sprintf(s,"k=%X\n",((GdkEventKey*)event)->keyval); +// AppendMessageICD(s); + } + return FALSE; +} + diff --git a/icd.h b/icd.h new file mode 100644 index 0000000..e9f7ead --- /dev/null +++ b/icd.h @@ -0,0 +1,185 @@ +//General routines to communicate via ICD with a target + +//The following commands are implemented in the debugger monitor +//routine which is written in the last memory page on the target chip. +#define VER 1 //;version +#define STEP 2 //;step +#define GO 3 //;go +#define RREG 4 //;read register +#define WREG 5 //;write register +#define EEADR 0x10D +#define EEADRH 0x10F +#define EEDATA 0x10C +#define EEDATH 0x10E +#define EECON1 0x18C +#define EECON2 0x18D +#define w_temp 0x6B +#define status_temp 0x6C +#define pclath_temp 0x6D +#define fsr_temp 0x6E + +extern struct var{ char* name; int display;} variables[0x200]; + +extern GtkWidget * statusTxt; +extern GtkWidget * sourceTxt; +extern GtkTextBuffer * sourceBuf; +extern GtkWidget * icdVbox1; +extern GtkWidget * icdMenuPC; +extern GtkWidget * icdMenuSTAT; +extern GtkWidget * icdMenuBank0; +extern GtkWidget * icdMenuBank1; +extern GtkWidget * icdMenuBank2; +extern GtkWidget * icdMenuBank3; +extern GtkWidget * icdMenuEE; +extern GtkWidget * icdCommand; +extern GtkTextBuffer * statusBuf; + +extern int icdTimer; + +//Prepare ICD interface by resetting the target with a power-up sequence. +//MCLR is low so the target is reset even if power is not supplied by the programmer. +//Set communication speed at 1/(2*Tck us) +void startICD(int Tck); + +//Check whether the target is running or is executing the debug routine. +//This is signaled by RB7 (Data): D=1 -> debugger monitor running +int isRunning(); + +//Set the next breakpoint address, the freeze bit, +//and continue execution. +//This is necessary because at every break +//the ICD register is loaded with the last address. +void cont(int break_addr, int freeze); + +//Execute a single step +void step(); + +//Remove reset so that the target can start executing its code. +void run(); + +//Get the debugger monitor version +int version(); + +//Halt execution by setting RB6 (Clock) low +void Halt(); + +//Read register at address addr +int ReadRegister(int addr); + +//Read n registers starting at address addr +int ReadRegisterN(int addr,int n,int* buf); + +//Write data at address addr +void WriteRegister(int addr,int data); + +//Read program memory at address addr +int ReadProgMem(int addr); + +//Read program memory at address addr +int ReadProgMemN(int addr,int n,int* buf); + +//Read data memory at address addr +int ReadDataMem(int addr); + +//Read data memory at address addr +int ReadDataMemN(int addr,int n,unsigned char* buf); + +//Disassemble a command and return string +char* decodeCmd(int cmd,char *str, int addrH); + +// get register name from list +char* getVar(int addr,char *var); + +/// +///Scroll source file +void scrollToLine(int line); + +/// +///Hilight line in source code +void SourceHilightLine(int line); + +/// +///Remove hilight line in source code +void SourceRemoveHilightLine(int line); + +/// +///load source file into source pane +int loadSource(FILE *f); + +/// +///load and analyze coff file +void loadCoff(GtkWidget *widget,GtkWidget *window); + +/// +/// List of variables used when decoding an assembly word +void initVar(); + +/// +///Show ICD help window +void ICDHelp(GtkWidget *widget,GtkWidget *window); + +/// +///ICD: check if program is running +void icdCheck(GtkWidget *widget,GtkWidget *window); + +/// +///ICD: run program +void icdRun(GtkWidget *widget,GtkWidget *window); + +/// +///ICD: halt program +void icdHalt(GtkWidget *widget,GtkWidget *window); + +/// +///ICD: step program +void icdStep(GtkWidget *widget,GtkWidget *window); + +/// +///ICD: step program jumping over calls +void icdStepOver(GtkWidget *widget,GtkWidget *window); + +/// +///ICD: stop program +void icdStop(GtkWidget *widget,GtkWidget *window); + +/// +///ICD: refresh status +void icdRefresh(GtkWidget *widget,GtkWidget *window); + +/// +/// Read and display an entire bank of memory +void ShowBank(int bank,char* status); + +/// +/// Main ICD show function: +/// prints status info according to selected options +/// and the value of variables in the watch list +void ShowContext(); + +/// +///Add symbol to the list of watched variables +int addWatch(struct symbol s); + +/// +/// ICD Command parser +int executeCommand(char *command); + +/// +///Remove variable from watch list +int removeWatch(char* name); + +/// +///Handle mouse events in source code window +gint source_mouse_event(GtkWidget *widget, GdkEventButton *event, gpointer func_data); + +/// +///Handle mouse events in ICD status window +gint icdStatus_mouse_event(GtkWidget *widget, GdkEventButton *event, gpointer func_data); + +/// +///Handle keyboard events in ICD command edit box +gint icdCommand_key_event(GtkWidget *widget, GdkEventButton *event, gpointer func_data); + +/// +///Handle keyboard events in ICD tab +gint icd_key_event(GtkWidget *widget, GdkEventButton *event, gpointer func_data); diff --git a/icons.c b/icons.c new file mode 100644 index 0000000..7705a09 --- /dev/null +++ b/icons.c @@ -0,0 +1,546 @@ +#include +/* GdkPixbuf RGBA C-Source image dump 1-byte-run-length-encoded */ + +#ifdef __SUNPRO_C +#pragma align 4 (write_icon) +#endif +#ifdef __GNUC__ +const guint8 write_icon[] __attribute__ ((__aligned__ (4))) = +#else +const guint8 write_icon[] = +#endif +{ "" + /* Pixbuf magic (0x47646b50) */ + "GdkP" + /* length: header (24) + pixel_data (1667) */ + "\0\0\6\233" + /* pixdata_type (0x2010002) */ + "\2\1\0\2" + /* rowstride (96) */ + "\0\0\0`" + /* width (24) */ + "\0\0\0\30" + /* height (24) */ + "\0\0\0\30" + /* pixel_data: */ + "\211\0\0\0\0\5\34\33\33\6\0\0\0\0\0\0\0-\0\1\1C\0\0\0=\202\0\0\0<\2\4" + "\0\0@\0\0\0\15\220\0\0\0\0\10@BBC\2\11\11\377*\0\0\3770\0\0\3774\0\0" + "\377/\0\0\377\0\0\0\377\3\0\0J\216\0\0\0\0\11\0\0\0\13\0\0\0\0\0\22\22" + "\217H\5\5\377\367\0\0\370\365\0\0\372\377\0\0\371b\0\0\377\0\0\0\253" + "\217\0\0\0\0\13\23\24\24\5\0\0\0\0\0\0\0qV\0\0\377\377\0\0\376\377\0" + "\0\377\363\0\0\377\0\0\0\377\0\1\1T\0\0\0\0\0\0\0\1\216\0\0\0\0\3\272" + "\201\201\23\0\26\26\312\205\0\0\377\202\377\0\0\377\2[\2\2\377\1\37\37" + "\265\221\0\0\0\0\12\0\12\12\77\40\11\11\377\354\0\0\370\377\0\0\376\377" + "\0\0\377.\1\1\377\0\15\15\361\10\0\0\303\0\0\0\275\0\0\0\1\216\0\0\0" + "\0\11\0\32\32l9\0\0\377\373\0\0\373\377\0\0\376\377\0\0\377\266\0\0\375" + "t\0\0\375$\0\0\377\0\0\0[\215\0\0\0\0\15\0\0\0\6\0""88\14\21\25\25\377" + "\265\0\0\377\377\0\0\377\376\0\0\376\377\0\0\377\377\0\0\376f\0\0\377" + "\0\0\0\317c\0\0\7\0\0\0\0\35\35\35\0\213\0\0\0\0\12\24\24\24\1\0\0\0" + "\7\4\0\0\3641\0\0\377\77\0\0\377\375\0\0\376\377\0\0\377\373\0\0\377" + "\27\0\0\377\0\0\0n\203\0\0\0\0\1""999\2\205\0\0\0\0\3""222\0""333\3A" + "AA\0\202\0\0\0\0\1###\2\202\0\0\0\0\11\0\0\0\23\0\0\0\325\352\0\0\377" + "\377\0\0\376\233\0\0\377\0\0\0\340\0\0\0\0\0\0\0\312$$$\355\202\0\0\0" + "\0\1\7\7\7\2\207\0\0\0\0\17///\15>>>X\0\0\0\0\5\5\5\20\0\0\0S\0\0\0\0" + "\3\0\0\314\355\0\0\377\360\0\0\377R\0\0\377\0\1\1=\0\0\0\26\24\24\24" + "\365\11\11\11\377\24\24\24\331\202\0\0\0\0\6+++\0\0\0\0\0\0\0\0\3\0\0" + "\0\0MMM\12,,,\225\202\0\0\0\0\17\17\17\17\377\0\0\0\\\0\0\0\0\3\3\3\377" + "\0\0\0T\4\0\0\266\365\0\0\377\307\0\0\377\3\0\0\373\0\0\0\247\0\0\0\357" + "\14\14\14\377\0\0\0\367\0\0\0\377###\327\202\0\0\0\0\17\377\377\377\0" + "\0\0\0:\0\0\0\265\0\0\0\0\15\15\15\377\12\12\12\234\202\202\202+\31\31" + "\31\377\0\0\0\377\11\11\11h\35\35\35\364\0\0\0\377\3\0\0\372\377\0\0" + "\377\205\0\0\376\203\0\0\0\377\16\0\0\0\374\2\2\2\377\0\0\0\375\6\6\6" + "\377%%%\271\0\0\0\0///\6""666\233\14\14\14\377\0\0\0\243\23\23\23\361" + "\14\14\14\377\35\35\35\377\0\0\0\376\204\0\0\0\377\3\1\0\0\377\377\0" + "\0\376\214\0\0\377\205\0\0\0\377\7\1\1\1\376\0\0\0\377\10\10\10\362Z" + "ZZ0\0\0\0\0\21\21\21\377\10\10\10\370\202\0\0\0\377\12\0\0\0\374\0\0" + "\0\372\0\0\0\376\0\0\0\377\1\1\1\373\0\0\0\376\0\0\0\377\16\2\2\376\373" + "\0\0\376K\1\1\377\202\0\0\0\376\15\15\15\15\377\11\11\11\376\213\213" + "\213\376\0\0\0\377\1\1\1\374\5\5\5\377\27\27\27\221\0\0\0\0\0\0\0\376" + "\0\0\0\377\3\3\3\376\1\1\1\376\2\2\2\377\202\0\0\0\376\23\7\7\7\377\0" + "\0\0\376\7\7\7\376.44\377\14\0\0\376\257\1\1\376\0\0\0\377.))\376QQQ" + "\376\377\377\377\377ccc\376\12\12\12\376\0\0\0\377\0\0\0\376\0\0\0\374" + "\21\21\21\377\77\77\77j\0\0\0\377\1\1\1\377\203\0\0\0\377\2\17\17\17" + "\377mmm\377\202\0\0\0\377\12\244\244\244\377MNN\377\0\0\0\377(\2\2\377" + "\0\0\0\377fee\377\77\77\77\377777\377[[[\377\12\12\12\377\202\0\0\0\377" + "\21\0\0\0\376\0\0\0\377\23\23\23\377\3\3\3\376\0\0\0\377\201\201\201" + "\376aaa\376vvv\377\0\0\0\376iii\376\331\331\331\377666\376'''\376\0\0" + "\0\377\3\4\4\376\0\0\0\376\2\1\1\377\202\0\0\0\376\1\0\0\0\377\202\0" + "\0\0\376\1\0\0\0\377\202\0\0\0\376\15\0\0\0\377\0\0\0\371\0\0\0\376\0" + "\0\0\377!!!\376\203\203\203\376qqq\377<<<\376\0\0\0\376\35\35\35\377" + "\3\3\3\376\0\0\0\376\1\1\1\377\202\0\0\0\376\5\0\0\0\377\0\0\0\376\0" + "\0\0\377\0\0\0\374\0\0\0\375\202\0\0\0\374\202\0\0\0\377\4\11\11\11\377" + "\10\10\10*\0\0\0\377\1\1\1\376\210\0\0\0\377\1\0\0\0\376\202\0\0\0\377" + "\3\0\0\0\376\0\0\0\377\0\0\0\374\204\0\0\0\377\12\0\0\0\177\0\0\0\222" + "\15\15\15\377111\250\33\33\33\374\0\0\0\377\1\1\1\376\2\2\2\376\2\2\2" + "\377\1\1\1\375\202\0\0\0\377\2\0\0\0\376\0\0\0\377\202\0\0\0\375\17\0" + "\0\0\374\3\3\3\377\0\0\0\377\10\10\10\377'''\221\0\0\0\254###{\21\21" + "\21\377\37\37\37\312\0\0\0\0\0\0\0\254\23\23\23\217!!!H\10\10\10\377" + "\0\0\0\364\202\0\0\0\377\21\1\1\1\377\16\16\16\350\0\0\0\332\10\10\10" + "\377\0\0\0\314\36\36\36\377MMMC\4\4\4\374\26\26\26\354NNN.\11\11\11\377" + "\1\1\1m\3\3\3\306&&&\311\0\0\0J\7\7\7\371444\213\202\0\0\0\0\23\325\325" + "\325\12\25\25\25\330\0\0\0\377\0\0\0\340\0\0\0g\2\2\2\377\"\"\"\253\0" + "\0\0n+++\377\16\16\16.\12\12\12\377@@@.\37\37\37\250\0\0\0\213\0\0\0" + "\0(((\215\0\0\0""7\1\1\1_\0\0\0o\207\0\0\0\0\14\37\37\37\360\4\4\4\315" + "\0\0\0\0\0\0\0C\0\0\0\305\0\0\0\3\12\12\12\322\13\13\13#\0\0\0B\0\0\0" + "\6\0\0\0\0\6\6\6(\205\0\0\0\0\5\0\0\0\4\5\5\5\4""222\3\0\0\0\0""333\0"}; + + +/* GdkPixbuf RGBA C-Source image dump 1-byte-run-length-encoded */ + +#ifdef __SUNPRO_C +#pragma align 4 (read_icon) +#endif +#ifdef __GNUC__ +const guint8 read_icon[] __attribute__ ((__aligned__ (4))) = +#else +const guint8 read_icon[] = +#endif +{ "" + /* Pixbuf magic (0x47646b50) */ + "GdkP" + /* length: header (24) + pixel_data (1755) */ + "\0\0\6\363" + /* pixdata_type (0x2010002) */ + "\2\1\0\2" + /* rowstride (96) */ + "\0\0\0`" + /* width (24) */ + "\0\0\0\30" + /* height (24) */ + "\0\0\0\30" + /* pixel_data: */ + "\203\0\0\0\0\1\25\25\25\6\205\0\0\0\0\4HQHA\377VWV\377\77\77\77\377777\377[[[\377\12\12" + "\12\377\202\0\0\0\377\21\0\0\0\376\0\0\0\377\23\23\23\377\3\3\3\376\0" + "\0\0\377\201\201\201\376aaa\376vvv\377\0\0\0\376iii\376\333\333\333\377" + ",,,\376\0\0\0\376\0\0\0\377666\376\16\16\16\376444\377\202\0\0\0\376" + "\1\0\0\0\377\202\0\0\0\376\1\0\0\0\377\202\0\0\0\376\15\0\0\0\377\0\0" + "\0\371\0\0\0\376\0\0\0\377!!!\376\203\203\203\376qqq\377<<<\376\0\0\0" + "\376\35\35\35\377\4\4\4\376\0\0\0\376\1\1\1\377\202\0\0\0\376\7\0\0\0" + "\377\2\2\2\376\0\0\0\377\0\0\0\374\0\0\0\375\0\0\0\372\0\0\0\374\203" + "\0\0\0\377\3\0\0\0)\0\0\0\377\1\1\1\376\212\0\0\0\377\1\0\0\0\376\202" + "\0\0\0\377\1\0\0\0\374\204\0\0\0\377\12\26\26\26\375\7\7\7q\0\0\0\313" + "\36\36\36\254\33\33\33\374\0\0\0\377\1\1\1\376\2\2\2\376\2\2\2\377\1" + "\1\1\375\204\0\0\0\3777\0\0\0\373\3\3\3\377\0\0\0\377\0\0\0\356\0\0\0" + "\367\13\13\13\377'''\216\0\0\0\315\2\2\2P\0\0\0\232\13\13\13\377\0\0" + "\0\0\0\0\0h$$$\377!!!H\10\10\10\377\0\0\0\367\0\0\0\373\0\0\0\377\2\2" + "\2\377\16\16\16\347\0\0\0\340\0\0\0\322\0\0\0\311\35\35\35\377<<<\307" + "\0\0\0\346\15\15\15\262\0\0\0\0\0\0\0\360\0\0\0{888~\6\6\6\216\0\0\0" + "\0\0\0\0\227\0\0\0\21\0\0\0\0###\3\325\325\325\12\25\25\25\330\0\0\0" + "\377\10\10\10\377\26\26\26\277\0\0\0\370!!!\251\0\0\0s\2\2\2""2\0\0\0" + "\25\14\14\14\377333\40\0\0\0\0\22\22\22\373&&&C\0\0\0\1\0\0\0N\211\0" + "\0\0\0\15\36\36\36\351\12\12\12\352\0\0\0\0\0\0\0""9\0\0\0\253\0\0\0" + "\206\0\0\0W\0\0\0\0\0\0\0G\0\0\0\23\0\0\0\0\0\0\0\22\0\0\0\30\202\0\0" + "\0\0\4\30\30\30\6\5\5\5\3\0\0\0\0\0\0\0\3\203\0\0\0\0"}; + + +/* GdkPixbuf RGBA C-Source image dump 1-byte-run-length-encoded */ + +#ifdef __SUNPRO_C +#pragma align 4 (system_icon) +#endif +#ifdef __GNUC__ +const guint8 system_icon[] __attribute__ ((__aligned__ (4))) = +#else +const guint8 system_icon[] = +#endif +{ "" + /* Pixbuf magic (0x47646b50) */ + "GdkP" + /* length: header (24) + pixel_data (695) */ + "\0\0\2\317" + /* pixdata_type (0x2010002) */ + "\2\1\0\2" + /* rowstride (96) */ + "\0\0\0`" + /* width (24) */ + "\0\0\0\30" + /* height (24) */ + "\0\0\0\30" + /* pixel_data: */ + "\215\240\345\201\0\207\0\0\0\377\221\240\345\201\0\1\0\0\0\377\204\377" + "\377\0\377\1\0\0\0\377\221\240\345\201\0\1\0\0\0\377\204\377\377\0\377" + "\1\0\0\0\377\222\240\345\201\0\1\0\0\0\377\204\377\377\0\377\1\0\0\0" + "\377\222\240\345\201\0\1\0\0\0\377\204\377\377\0\377\222\240\345\201" + "\0\1\0\0\0\377\204\377\377\0\377\203\0\0\0\377\220\240\345\201\0\1\0" + "\0\0\377\205\377\377\0\377\1\0\0\0\377\221\240\345\201\0\202\0\0\0\377" + "\204\377\377\0\377\1\0\0\0\377\213\240\345\201\0\1\0\0\0\377\203\240" + "\345\201\0\5\0\0\0\377\200\200\200\377\240\345\201\0\0\0\0\377\240\345" + "\201\0\203\377\377\0\377\202\240\345\201\0\3\200\200\200\377\0\0\0\377" + "\200\200\200\377\205\240\345\201\0\4\0\0\0\377\200\200\200\377\0\0\0" + "\377\200\200\200\377\202\240\345\201\0\5\0\0\0\377\200\200\200\377\240" + "\345\201\0\0\0\0\377\240\345\201\0\202\377\377\0\377\6\0\0\0\377\240" + "\345\201\0\0\0\0\377\200\200\200\377\0\0\0\377\200\200\200\377\205\240" + "\345\201\0\4\0\0\0\377\200\200\200\377\0\0\0\377\200\200\200\377\202" + "\240\345\201\0\5\0\0\0\377\200\200\200\377\240\345\201\0\0\0\0\377\240" + "\345\201\0\202\377\377\0\377\207\0\0\0\377\203\240\345\201\0\214\0\0" + "\0\377\1\377\377\0\377\210\0\0\0\377\202\240\345\201\0\226\0\0\0\377" + "\1\240\345\201\0\227\0\0\0\377\1\240\345\201\0\205\0\0\0\377\2\200\200" + "\200\377\377\377\377\377\202\0\0\0\377\3\377\377\377\377\0\0\0\377\377" + "\377\377\377\202\0\0\0\377\203\377\377\377\377\202\0\0\0\377\1\377\377" + "\377\377\203\0\0\0\377\1\240\345\201\0\202\0\0\0\377\1\377\377\377\377" + "\202\0\0\0\377\202\377\377\377\377\202\0\0\0\377\2\377\377\377\377\0" + "\0\0\377\202\377\377\377\377\4\0\0\0\377\377\377\377\377\0\0\0\377\377" + "\377\377\377\206\0\0\0\377\1\240\345\201\0\227\0\0\0\377\1\240\345\201" + "\0\227\0\0\0\377\1\240\345\201\0\227\0\0\0\377\1\240\345\201\0\221\0" + "\0\0\377\203\240\345\201\0\1\200\200\200\377\205\240\345\201\0\5\0\0" + "\0\377\200\200\200\377\240\345\201\0\0\0\0\377\200\200\200\377\202\240" + "\345\201\0\2\0\0\0\377\200\200\200\377\202\240\345\201\0\1\0\0\0\377" + "\203\240\345\201\0\1\200\200\200\377\210\240\345\201\0\5\0\0\0\377\200" + "\200\200\377\240\345\201\0\0\0\0\377\200\200\200\377\202\240\345\201" + "\0\1\0\0\0\377\203\240\345\201\0\1\0\0\0\377\214\240\345\201\0\5\0\0" + "\0\377\200\200\200\377\240\345\201\0\0\0\0\377\200\200\200\377\251\240" + "\345\201\0"}; + + +/* GdkPixbuf RGBA C-Source image dump 1-byte-run-length-encoded */ + +#ifdef __SUNPRO_C +#pragma align 4 (go_icon) +#endif +#ifdef __GNUC__ +const guint8 go_icon[] __attribute__ ((__aligned__ (4))) = +#else +const guint8 go_icon[] = +#endif +{ "" + /* Pixbuf magic (0x47646b50) */ + "GdkP" + /* length: header (24) + pixel_data (599) */ + "\0\0\2o" + /* pixdata_type (0x2010002) */ + "\2\1\0\2" + /* rowstride (96) */ + "\0\0\0`" + /* width (24) */ + "\0\0\0\30" + /* height (24) */ + "\0\0\0\30" + /* pixel_data: */ + "\313\377\377\377\0\203\0\0\0\377\202\0\0\0\0\223\377\377\377\0\2\0\0" + "\0\377\252\0\0\377\203\0\0\0\377\202\0\0\0\0\221\377\377\377\0\1\0\0" + "\0\377\203\252\0\0\377\203\0\0\0\377\202\0\0\0\0\203\377\377\377\0\202" + "\0\0\0\0\212\377\377\377\0\3\0\0\0\377\252\0\0\377\377\0\0\377\203\252" + "\0\0\377\203\0\0\0\377\202\0\0\0\0\3\377\377\377\0\0\0\0\0\377\377\377" + "\0\202\0\0\0\0\210\377\377\377\0\2\0\0\0\377\252\0\0\377\203\377\0\0" + "\377\203\252\0\0\377\203\0\0\0\377\202\0\0\0\0\213\377\377\377\0\2\0" + "\0\0\377\252\0\0\377\205\377\0\0\377\203\252\0\0\377\203\0\0\0\377\203" + "\0\0\0\0\210\377\377\377\0\2\0\0\0\377\252\0\0\377\207\377\0\0\377\203" + "\252\0\0\377\203\0\0\0\377\203\0\0\0\0\206\377\377\377\0\2\0\0\0\377" + "\252\0\0\377\211\377\0\0\377\203\252\0\0\377\203\0\0\0\377\202\0\0\0" + "\0\205\377\377\377\0\2\0\0\0\377\252\0\0\377\213\377\0\0\377\203\252" + "\0\0\377\202\0\0\0\377\202\0\0\0\0\204\377\377\377\0\2\0\0\0\377\252" + "\0\0\377\211\377\0\0\377\203\252\0\0\377\203\0\0\0\377\202\0\0\0\0\205" + "\377\377\377\0\2\0\0\0\377\252\0\0\377\207\377\0\0\377\203\252\0\0\377" + "\203\0\0\0\377\202\0\0\0\0\207\377\377\377\0\2\0\0\0\377\252\0\0\377" + "\205\377\0\0\377\203\252\0\0\377\203\0\0\0\377\1\0\0\0\1\202\0\0\0\0" + "\210\377\377\377\0\2\0\0\0\377\252\0\0\377\203\377\0\0\377\203\252\0" + "\0\377\203\0\0\0\377\202\0\0\0\0\3\0\0\0\4\377\377\377\0\0\0\0\0\210" + "\377\377\377\0\3\0\0\0\377\252\0\0\377\377\0\0\377\203\252\0\0\377\203" + "\0\0\0\377\202\0\0\0\0\215\377\377\377\0\1\0\0\0\377\203\252\0\0\377" + "\203\0\0\0\377\202\0\0\0\0\217\377\377\377\0\2\0\0\0\377\252\0\0\377" + "\203\0\0\0\377\202\0\0\0\0\2\377\377\377\0\0\0\0\0\202\377\377\377\0" + "\2\0\0\0\0\377\377\377\0\202\0\0\0\0\211\377\377\377\0\203\0\0\0\377" + "\202\0\0\0\0\202\377\377\377\0\203\0\0\0\0\202\377\377\377\0\1\0\0\0" + "\0\350\377\377\377\0"}; + + +/* GdkPixbuf RGBA C-Source image dump 1-byte-run-length-encoded */ + +#ifdef __SUNPRO_C +#pragma align 4 (halt_icon) +#endif +#ifdef __GNUC__ +const guint8 halt_icon[] __attribute__ ((__aligned__ (4))) = +#else +const guint8 halt_icon[] = +#endif +{ "" + /* Pixbuf magic (0x47646b50) */ + "GdkP" + /* length: header (24) + pixel_data (944) */ + "\0\0\3\310" + /* pixdata_type (0x2010002) */ + "\2\1\0\2" + /* rowstride (96) */ + "\0\0\0`" + /* width (24) */ + "\0\0\0\30" + /* height (24) */ + "\0\0\0\30" + /* pixel_data: */ + "\315\0\0\0\0\206\0\0\0\377\202\0\0\0\0\206\0\0\0\377\212\0\0\0\0\1\0" + "\0\0\377\203\252\0\0\377\2\254\6\6\371\0\0\0\377\202\0\0\0\0\1\0\0\0" + "\377\204\252\0\0\377\1\0\0\0\377\212\0\0\0\0\2\0\0\0\377\252\0\0\377" + "\202\377\0\0\377\2\261\30\27\354\0\0\0\377\202\0\0\0\0\2\0\0\0\377\252" + "\0\0\377\202\377\0\0\377\2\252\0\0\377\0\0\0\377\212\0\0\0\0\2\0\0\0" + "\377\252\0\0\377\202\377\0\0\377\6\257\20\20\362\0\0\0\377\377\377\377" + "\2\0\0\0\0\0\0\0\377\252\0\0\377\202\377\0\0\377\3\252\0\0\377\0\0\0" + "\377\377\377\377\0\211\0\0\0\0\2\0\0\0\377\252\0\0\377\202\377\0\0\377" + "\6\254\10\7\371\0\0\0\377\377\377\377\12\0\0\0\0\0\0\0\377\252\0\0\377" + "\202\377\0\0\377\3\252\0\0\377\0\0\0\377\377\377\377\0\211\0\0\0\0\2" + "\0\0\0\377\252\0\0\377\202\377\0\0\377\6\252\0\0\377\0\0\0\377\377\377" + "\377\12\0\0\0\0\0\0\0\377\252\0\0\377\202\377\0\0\377\3\252\0\0\377\0" + "\0\0\377\377\377\377\0\211\0\0\0\0\2\0\0\0\377\252\0\0\377\202\377\0" + "\0\377\6\252\0\0\377\0\0\0\377\377\377\377\0\0\0\0\0\0\0\0\377\252\0" + "\0\377\202\377\0\0\377\3\252\0\0\377\0\0\0\377\377\377\377\0\211\0\0" + "\0\0\2\0\0\0\377\252\0\0\377\202\377\0\0\377\6\252\0\0\377\0\0\0\377" + "\377\377\377\0\0\0\0\0\0\0\0\377\254\10\7\371\202\377\0\0\377\3\252\0" + "\0\377\0\0\0\377\377\377\377\0\211\0\0\0\0\2\0\0\0\377\252\0\0\377\202" + "\377\0\0\377\6\252\0\0\377\0\0\0\377\377\377\377\0\0\0\0\0\0\0\0\377" + "\252\0\0\377\202\377\0\0\377\3\252\0\0\377\0\0\0\377\377\377\377\0\211" + "\0\0\0\0\2\0\0\0\377\252\0\0\377\202\377\0\0\377\6\252\0\0\377\0\0\0" + "\377\377\377\377\0\0\0\0\0\0\0\0\377\252\0\0\377\202\377\0\0\377\3\252" + "\0\0\377\0\0\0\377\377\377\377\0\211\0\0\0\0\2\0\0\0\377\252\0\0\377" + "\202\377\0\0\377\6\252\0\0\377\0\0\0\377\377\377\377\0\0\0\0\0\0\0\0" + "\377\252\0\0\377\202\377\0\0\377\3\252\0\0\377\0\0\0\377\377\377\377" + "\0\211\0\0\0\0\2\0\0\0\377\252\0\0\377\202\377\0\0\377\6\252\0\0\377" + "\0\0\0\377\377\377\377\0\0\0\0\0\0\0\0\377\252\0\0\377\202\377\0\0\377" + "\3\252\0\0\377\0\0\0\377\377\377\377\0\211\0\0\0\0\2\0\0\0\377\252\0" + "\0\377\202\377\0\0\377\6\252\0\0\377\0\0\0\377\377\377\377\0\0\0\0\0" + "\0\0\0\377\252\0\0\377\202\377\0\0\377\3\252\0\0\377\0\0\0\377\377\377" + "\377\0\211\0\0\0\0\2\0\0\0\377\252\0\0\377\202\377\0\0\377\6\252\0\0" + "\377\0\0\0\377\377\377\377\0\0\0\0\0\0\0\0\377\252\0\0\377\202\377\0" + "\0\377\3\252\0\0\377\0\0\0\377\377\377\377\0\211\0\0\0\0\2\0\0\0\377" + "\252\0\0\377\202\377\0\0\377\6\252\0\0\377\0\0\0\377\377\377\377\0\0" + "\0\0\0\0\0\0\377\252\0\0\377\202\377\0\0\377\3\252\0\0\377\0\0\0\377" + "\377\377\377\0\211\0\0\0\0\1\0\0\0\377\204\252\0\0\377\4\0\0\0\377\377" + "\377\377\0\0\0\0\0\0\0\0\377\204\252\0\0\377\2\0\0\0\377\377\377\377" + "\0\211\0\0\0\0\206\0\0\0\377\2\377\377\377\0\0\0\0\0\206\0\0\0\377\1" + "\377\377\377\0\344\0\0\0\0"}; + + +/* GdkPixbuf RGBA C-Source image dump 1-byte-run-length-encoded */ + +#ifdef __SUNPRO_C +#pragma align 4 (step_icon) +#endif +#ifdef __GNUC__ +const guint8 step_icon[] __attribute__ ((__aligned__ (4))) = +#else +const guint8 step_icon[] = +#endif +{ "" + /* Pixbuf magic (0x47646b50) */ + "GdkP" + /* length: header (24) + pixel_data (1265) */ + "\0\0\5\11" + /* pixdata_type (0x2010002) */ + "\2\1\0\2" + /* rowstride (96) */ + "\0\0\0`" + /* width (24) */ + "\0\0\0\30" + /* height (24) */ + "\0\0\0\30" + /* pixel_data: */ + "\262\0\0\0\0\203\0\0\0\377\210\0\0\0\0\204\0\0\0\377\1\0\0\0\0\204\0" + "\0\0\377\204\0\0\0\0\1\0\0\0\377\202\252\0\0\377\1\0\0\0\377\206\0\0" + "\0\0\2\377\377\377\0\0\0\0\377\202\252\0\0\377\3\0\0\0\377\377\377\377" + "\0\0\0\0\377\202\252\0\0\377\1\0\0\0\377\204\0\0\0\0\5\0\0\0\377\252" + "\0\0\377\377\0\0\377\252\0\0\377\0\0\0\377\205\0\0\0\0\2\377\377\377" + "\0\0\0\0\377\202\252\0\0\377\3\0\0\0\377\0\0\0\0\0\0\0\377\202\252\0" + "\0\377\1\0\0\0\377\204\0\0\0\0\2\0\0\0\377\252\0\0\377\202\377\0\0\377" + "\2\252\0\0\377\0\0\0\377\204\0\0\0\0\2\377\377\377\0\0\0\0\377\202\252" + "\0\0\377\3\0\0\0\377\0\0\0\0\0\0\0\377\202\252\0\0\377\1\0\0\0\377\204" + "\0\0\0\0\2\0\0\0\377\252\0\0\377\203\377\0\0\377\4\252\0\0\377\0\0\0" + "\377\377\377\377\4\0\0\0\0\202\377\377\377\0\1\0\0\0\377\202\252\0\0" + "\377\3\0\0\0\377\0\0\0\0\0\0\0\377\202\252\0\0\377\1\0\0\0\377\204\0" + "\0\0\0\2\0\0\0\377\252\0\0\377\204\377\0\0\377\6\252\0\0\377\0\0\0\377" + "\377\377\377\2\0\0\0\0\377\377\377\0\0\0\0\377\202\252\0\0\377\3\0\0" + "\0\377\0\0\0\0\0\0\0\377\202\252\0\0\377\1\0\0\0\377\204\0\0\0\0\2\0" + "\0\0\377\252\0\0\377\203\377\0\0\377\4\376\3\2\377\377\0\0\377\252\0" + "\0\377\0\0\0\377\202\377\377\377\0\1\0\0\0\371\202\252\0\0\377\3\0\0" + "\0\377\0\0\0\0\0\0\0\377\202\252\0\0\377\1\0\0\0\377\204\0\0\0\0\2\0" + "\0\0\377\252\0\0\377\203\377\0\0\377\1\376\14\13\375\202\377\0\0\377" + "\4\252\0\0\377\0\0\0\377\377\377\377\0\0\0\0\323\202\252\0\0\377\3\0" + "\0\0\377\0\0\0\0\0\0\0\377\202\252\0\0\377\1\0\0\0\377\204\0\0\0\0\2" + "\0\0\0\377\252\0\0\377\207\377\0\0\377\1\252\0\0\377\202\0\0\0\377\202" + "\252\0\0\377\3\0\0\0\377\0\0\0\0\0\0\0\377\202\252\0\0\377\1\0\0\0\377" + "\204\0\0\0\0\2\0\0\0\377\252\0\0\377\206\377\0\0\377\4\376\33\32\376" + "\377\0\0\377\252\0\0\377\0\0\0\377\202\252\0\0\377\3\0\0\0\377\0\0\0" + "\0\0\0\0\377\202\252\0\0\377\1\0\0\0\377\204\0\0\0\0\2\0\0\0\377\252" + "\0\0\377\207\377\0\0\377\3\252\0\0\377$$$\362\0\0\0\377\202\252\0\0\377" + "\3\0\0\0\377\0\0\0\0\0\0\0\377\202\252\0\0\377\1\0\0\0\377\204\0\0\0" + "\0\2\0\0\0\377\252\0\0\377\206\377\0\0\377\4\252\0\0\377\23\23\23\367" + "\377\377\377\0\0\0\0\377\202\252\0\0\377\3\0\0\0\377\0\0\0\0\0\0\0\377" + "\202\252\0\0\377\1\0\0\0\377\204\0\0\0\0\2\0\0\0\377\252\0\0\377\205" + "\377\0\0\377\5\252\0\0\377\5\5\5\376\377\377\377\1\377\377\377\0\0\0" + "\0\377\202\252\0\0\377\3\0\0\0\377\0\0\0\0\0\0\0\377\202\252\0\0\377" + "\1\0\0\0\377\204\0\0\0\0\2\0\0\0\377\252\0\0\377\204\377\0\0\377\6\252" + "\0\0\377\0\0\0\377\377\377\3772\0\0\0\0\377\377\377\0\0\0\0\377\202\252" + "\0\0\377\3\0\0\0\377\0\0\0\0\0\0\0\377\202\252\0\0\377\1\0\0\0\377\204" + "\0\0\0\0\2\0\0\0\377\252\0\0\377\203\377\0\0\377\4\252\0\0\377\0\0\0" + "\377\377\377\377\0\0\0\0\0\202\377\377\377\0\1\0\0\0\377\202\252\0\0" + "\377\3\0\0\0\377\0\0\0\0\0\0\0\377\202\252\0\0\377\1\0\0\0\377\204\0" + "\0\0\0\2\0\0\0\377\252\0\0\377\202\377\0\0\377\10\252\0\0\377\0\0\0\377" + "\377\377\377\0\0\0\0\0\377\377\377\0\0\0\0\0\377\377\377\0\0\0\0\377" + "\202\252\0\0\377\3\0\0\0\377\0\0\0\0\0\0\0\377\202\252\0\0\377\1\0\0" + "\0\377\204\0\0\0\0\10\0\0\0\377\252\0\0\377\377\0\0\377\252\0\0\377\0" + "\0\0\377\377\377\377\0\0\0\0\0\377\377\377\0\202\0\0\0\0\2\377\377\377" + "\0\0\0\0\377\202\252\0\0\377\3\0\0\0\377\0\0\0\0\0\0\0\377\202\252\0" + "\0\377\1\0\0\0\377\204\0\0\0\0\1\0\0\0\377\202\252\0\0\377\4\0\0\0\377" + "\377\377\377\0\0\0\0\0\377\377\377\0\203\0\0\0\0\2\377\377\377\0\0\0" + "\0\377\202\252\0\0\377\3\0\0\0\377\377\377\377\0\0\0\0\377\202\252\0" + "\0\377\1\0\0\0\377\204\0\0\0\0\203\0\0\0\377\3\377\377\377\0\0\0\0\0" + "\377\377\377\0\205\0\0\0\0\204\0\0\0\377\1\0\0\0\0\204\0\0\0\377\312" + "\0\0\0\0"}; + + +/* GdkPixbuf RGBA C-Source image dump 1-byte-run-length-encoded */ + +#ifdef __SUNPRO_C +#pragma align 4 (stepover_icon) +#endif +#ifdef __GNUC__ +const guint8 stepover_icon[] __attribute__ ((__aligned__ (4))) = +#else +const guint8 stepover_icon[] = +#endif +{ "" + /* Pixbuf magic (0x47646b50) */ + "GdkP" + /* length: header (24) + pixel_data (1098) */ + "\0\0\4b" + /* pixdata_type (0x2010002) */ + "\2\1\0\2" + /* rowstride (96) */ + "\0\0\0`" + /* width (24) */ + "\0\0\0\30" + /* height (24) */ + "\0\0\0\30" + /* pixel_data: */ + "\263\0\0\0\0\1\0\0\0\377\210\0\0\0\0\1\0\0\0\377\216\0\0\0\0\202\0\0" + "\0\377\207\0\0\0\0\202\0\0\0\377\215\0\0\0\0\3\0\0\0\377\252\0\0\377" + "\0\0\0\377\206\0\0\0\0\3\0\0\0\377\252\0\0\377\0\0\0\377\213\0\0\0\0" + "\2\377\377\377\12\0\0\0\377\202\252\0\0\377\2\0\0\0\377\377\377\377\3" + "\203\0\0\0\0\6\377\377\377\0\0\0\0\377\263\34\33\373\252\0\0\377\0\0" + "\0\377\377\377\3772\211\0\0\0\0\21\377\377\377\12\0\0\0\377\252\0\0\377" + "\377\0\0\377\252\0\0\377\0\0\0\377\377\377\377\1\377\377\377\12\0\0\0" + "\0\377\377\377\0\0\0\0\377\263\34\34\375\377\0\0\377\252\0\0\377\0\0" + "\0\377\377\377\377\40\377\377\377!\207\0\0\0\0\3\377\377\377\12\0\0\0" + "\377\252\0\0\377\202\377\0\0\377\3\252\0\0\377\0\0\0\341\355\377\355" + "\1\202\377\377\377\0\2\0\0\0\377\261\30\30\375\202\377\0\0\377\4\252" + "\0\0\377\0\0\0\377\355\377\355\15\377\377\377\0\206\0\0\0\0\3\377\377" + "\377\12\0\0\0\377\252\0\0\377\203\377\0\0\377\6\252\0\0\377\0\0\0\273" + "\377\377\377\2\377\377\377\0\0\0\0\377\260\23\23\375\203\377\0\0\377" + "\4\252\0\0\377\0\0\0\377\377\377\377\33\377\377\377\23\205\0\0\0\0\3" + "\377\377\377\12\0\0\0\377\252\0\0\377\204\377\0\0\377\5\252\0\0\377\0" + "\0\0\377\377\377\377\0\0\0\0\377\261\27\26\375\204\377\0\0\377\4\252" + "\0\0\377\0\0\0\377\377\377\377\16\377\377\377\5\204\0\0\0\0\3\377\377" + "\377\12\0\0\0\377\252\0\0\377\205\377\0\0\377\1\252\0\0\377\202\0\0\0" + "\377\1\254\11\10\376\205\377\0\0\377\4\252\0\0\377\0\0\0\377\377\377" + "\372\3\377\377\377\5\203\0\0\0\0\3\377\377\377\12\0\0\0\377\252\0\0\377" + "\206\377\0\0\377\3\252\0\0\377\0\0\0\377\252\0\0\377\206\377\0\0\377" + "\4\252\0\0\377\0\0\0\377\377\377\377\4\377\377\377\3\202\0\0\0\0\3\377" + "\377\377\12\0\0\0\377\252\0\0\377\205\377\0\0\377\4\252\0\0\377\24\25" + "\24\362\0\0\0\377\252\0\0\377\205\377\0\0\377\4\252\0\0\377\22\23\22" + "\360\377\377\371\1\377\377\377\0\203\0\0\0\0\3\377\377\377\10\0\0\0\377" + "\252\0\0\377\204\377\0\0\377\5\252\0\0\377\7\7\6\372\373\377\373\0\0" + "\0\0\377\252\0\0\377\204\377\0\0\377\4\252\0\0\377\7\7\6\372\370\377" + "\370\0\377\377\377\0\204\0\0\0\0\3\377\377\377\0\0\0\0\377\252\0\0\377" + "\203\377\0\0\377\6\252\0\0\377\0\0\0\377\377\377\377\3\377\377\377\0" + "\0\0\0\377\252\0\0\377\203\377\0\0\377\4\252\0\0\377\0\0\0\377\377\377" + "\377\0\377\377\377\1\205\0\0\0\0\3\377\377\377\2\0\0\0\377\252\0\0\377" + "\202\377\0\0\377\7\252\0\0\377\0\0\0\377\370\377\370\10\377\377\377\5" + "\377\377\377\0\0\0\0\377\252\0\0\377\202\377\0\0\377\4\252\0\0\377\0" + "\0\0\377\370\377\370\0\377\377\377\0\206\0\0\0\0\21\377\377\3770\0\0" + "\0\377\252\0\0\377\377\0\0\377\252\0\0\377\0\0\0\330\377\377\377\2\377" + "\377\377\0\0\0\0\0\377\377\377\0\0\0\0\377\252\0\0\377\377\0\0\377\252" + "\0\0\377\0\0\0\377\377\377\377\2\377\377\377\1\207\0\0\0\0\2\377\377" + "\377\22\0\0\0\377\202\252\0\0\377\3\0\0\0\377\377\377\377\6\377\377\377" + "\0\202\0\0\0\0\2\377\377\377\0\0\0\0\377\202\252\0\0\377\3\0\0\0\377" + "\377\377\377\7\377\377\377\1\210\0\0\0\0\6\377\377\377\"\0\0\0\377\252" + "\0\0\377\0\0\0\377\377\377\377\5\377\377\377\1\203\0\0\0\0\6\377\377" + "\377\0\0\0\0\377\252\0\0\377\0\0\0\377\377\377\377\4\377\377\377\1\211" + "\0\0\0\0\1\377\377\377\0\202\0\0\0\377\2\377\377\377\14\377\377\377\5" + "\204\0\0\0\0\1\377\377\377\0\202\0\0\0\377\2\377\377\377\16\377\377\377" + "\2\212\0\0\0\0\2\377\377\377\0\0\0\0\377\202\377\377\377\1\205\0\0\0" + "\0\4\377\377\377\0\0\0\0\377\377\377\377\7\377\377\377\1\321\0\0\0\0"}; + + +/* GdkPixbuf RGBA C-Source image dump 1-byte-run-length-encoded */ + +#ifdef __SUNPRO_C +#pragma align 4 (stop_icon) +#endif +#ifdef __GNUC__ +const guint8 stop_icon[] __attribute__ ((__aligned__ (4))) = +#else +const guint8 stop_icon[] = +#endif +{ "" + /* Pixbuf magic (0x47646b50) */ + "GdkP" + /* length: header (24) + pixel_data (435) */ + "\0\0\1\313" + /* pixdata_type (0x2010002) */ + "\2\1\0\2" + /* rowstride (96) */ + "\0\0\0`" + /* width (24) */ + "\0\0\0\30" + /* height (24) */ + "\0\0\0\30" + /* pixel_data: */ + "\344\0\0\0\0\213\0\0\0\377\5\10\0\0\373\22\0\0\366\35\0\0\361'\0\0\355" + "\11\0\0\372\210\0\0\0\0\1\0\0\0\377\216\252\0\0\377\1+\0\0\353\210\0" + "\0\0\0\2\0\0\0\377\252\0\0\377\214\377\0\0\377\2\252\0\0\377/\0\0\351" + "\210\0\0\0\0\2\0\0\0\377\252\0\0\377\214\377\0\0\377\2\252\0\0\3775\0" + "\0\347\210\0\0\0\0\2\0\0\0\377\252\0\0\377\214\377\0\0\377\2\252\0\0" + "\3779\0\0\346\210\0\0\0\0\2\0\0\0\377\252\0\0\377\214\377\0\0\377\2\252" + "\0\0\377:\0\0\345\210\0\0\0\0\2\0\0\0\377\252\0\0\377\214\377\0\0\377" + "\2\252\0\0\377;\0\0\344\210\0\0\0\0\2\0\0\0\377\252\0\0\377\214\377\0" + "\0\377\2\252\0\0\377;\0\0\344\210\0\0\0\0\2\0\0\0\377\252\0\0\377\214" + "\377\0\0\377\2\252\0\0\377:\0\0\345\210\0\0\0\0\2\0\0\0\377\252\0\0\377" + "\214\377\0\0\377\2\252\0\0\3779\0\0\346\210\0\0\0\0\2\0\0\0\377\252\0" + "\0\377\214\377\0\0\377\2\252\0\0\3775\0\0\347\210\0\0\0\0\2\0\0\0\377" + "\252\0\0\377\214\377\0\0\377\2\252\0\0\3770\0\0\351\210\0\0\0\0\2\0\0" + "\0\377\252\0\0\377\214\377\0\0\377\2\252\0\0\377+\0\0\353\210\0\0\0\0" + "\2\0\0\0\377\252\0\0\377\214\377\0\0\377\2\252\0\0\377%\0\0\355\210\0" + "\0\0\0\1\0\0\0\377\216\252\0\0\377\1\36\0\0\360\210\0\0\0\0\215\0\0\0" + "\377\3\7\0\0\373\20\0\0\367\2\0\0\376\344\0\0\0\0"}; + + diff --git a/ihex.c b/ihex.c new file mode 100644 index 0000000..39d3b94 --- /dev/null +++ b/ihex.c @@ -0,0 +1,15 @@ +#include +#include +#include + + +int main (int argc, char **argv) { + int i,s=0,t; + for (i = 1; i < argc; i++){ + sscanf(argv[i], "%X", &t); + s+=t; + } + printf("checksum=%02X\n",(-s)&0xff); + return 0; +} + diff --git a/instructions.h b/instructions.h new file mode 100644 index 0000000..bb96aa0 --- /dev/null +++ b/instructions.h @@ -0,0 +1,99 @@ +// programmer instructions v0.12.0 +#define NOP 0x00 +#define PROG_RST 0x01 // ->10B +#define PROG_ID 0x02 // ->6B +#define CHECK_INS 0x03 //+1B ->1B +#define FLUSH 0x04 //no echo +#define VREG_EN 0x05 +#define VREG_DIS 0x06 +#define SET_PARAMETER 0x07 //+3B: 1B parameter, 2B data + #define SET_T1T2 0 //T1, T2 + #define SET_T3 1 //T3(H,L) + #define SET_timeout 2 //timeout(H,L) + #define SET_MN 3 //M, N +#define WAIT_T1 0x08 +#define WAIT_T2 0x09 +#define WAIT_T3 0x0A +#define WAIT_US 0x0B //+1B +#define READ_ADC 0x0C // ->2B +#define SET_VPP 0x0D //+1B ->1B +#define EN_VPP_VCC 0x0E //+1B +#define SET_CK_D 0x0F //+1B +#define READ_PINS 0x10 // ->1B +#define LOAD_CONF 0x11 //+2B 000000 +#define LOAD_DATA_PROG 0x12 //+2B 000010 +#define LOAD_DATA_DATA 0x13 //+2B 000011 +#define READ_DATA_PROG 0x14 // ->2B 000100 +#define READ_DATA_DATA 0x15 // ->1B 000101 +#define INC_ADDR 0x16 // 000110 +#define INC_ADDR_N 0x17 //+1B 000110 +#define BEGIN_PROG 0x18 // 001000 +#define BULK_ERASE_PROG 0x19 // 001001 +#define END_PROG 0x1A // 001010 +#define BULK_ERASE_DATA 0x1B // 001011 +#define END_PROG2 0x1C // 001110 +#define ROW_ERASE_PROG 0x1D // 010001 +#define BEGIN_PROG2 0x1E // 011000 +#define CUST_CMD 0x1F //+1B +#define PROG_C 0x20 //+2B ->1B 001000&001110 +#define CORE_INS 0x21 //+2B 0000 +#define SHIFT_TABLAT 0x22 // ->1B 0010 +#define TABLE_READ 0x23 // ->1B 1000 +#define TBLR_INC_N 0x24 //+1B ->1+NB 1001 +#define TABLE_WRITE 0x25 //+2B 1100 +#define TBLW_INC_N 0x26 //+1+2NB 1101 +#define TBLW_PROG 0x27 //+4B 1111 +#define TBLW_PROG_INC 0x28 //+4B 1110 +#define SEND_DATA 0x29 //+3B +#define READ_DATA 0x2A //+1B ->1B +#define I2C_INIT 0x2B //+1B +#define I2C_READ 0x2C //+3B ->1+NB +#define I2C_WRITE 0x2D //+3+NB ->1B +#define I2C_READ2 0x2E //+4B ->1+NB +#define SPI_INIT 0x2F //+1B +#define SPI_READ 0x30 //+1B ->1+NB +#define SPI_WRITE 0x31 //+1+NB ->1B +#define EXT_PORT 0x32 //+2B +#define AT_READ_DATA 0x33 //+3B ->1+2NB +#define AT_LOAD_DATA 0x34 //+3+2NB ->1B +#define CLOCK_GEN 0x35 //+1B +#define SIX 0x36 //+3B +#define REGOUT 0x37 // ->2B +#define ICSP_NOP 0x38 // +#define TX16 0x39 //+1+2NB +#define RX16 0x3A //+1B ->1+2NB +#define uW_INIT 0x3B // +#define uWTX 0x3C //+1+NB +#define uWRX 0x3D //+1B ->+1+NB +#define SIX_LONG 0x3E //+3B +#define SIX_N 0x3F //+1+3NB ->1B +#define OW_RESET 0x40 // ->1B +#define OW_WRITE 0x41 //+1+NB +#define OW_READ 0x42 //+1B ->1+NB +#define UNIO_STBY 0x43 // +#define UNIO_COM 0x44 //+2+NB ->1+NB +#define SET_PORT_DIR 0x45 //+2B +#define READ_B 0x46 // ->1B +#define READ_AC 0x47 // ->1B +#define AT_HV_RTX 0x48 //+1+NB ->1B +#define SIX_LONG5 0x49 //+3B +#define LOAD_PC 0x50 //+2B 011101 +#define LOAD_DATA_INC 0x51 //+2B 100010 +#define READ_DATA_INC 0x52 // ->2B 100100 +#define JTAG_SET_MODE 0x53 //+1B +#define JTAG_SEND_CMD 0x54 //+1B +#define JTAG_XFER_DATA 0x55 //+4B -> 4B +#define JTAG_XFER_F_DATA 0x56 //+4B -> 4B +#define ICSP8_SHORT 0x57 //+1B +#define ICSP8_READ 0x58 //+1B -> 2B +#define ICSP8_LOAD 0x59 //+3B +// special ins. +#define SPI_TEST 0xEF //+2B ->2B +#define READ_RAM 0xF0 //+2B ->3B +#define WRITE_RAM 0xF1 //+3B ->3B +#define LOOP 0xF2 +#define TBLRD 0xF3 //+3B ->2B +#define TBLWT 0xF4 //+5B +#define REPEAT 0xF5 //+1B +#define REPEAT_END 0xF6 +#define MAX_INS 0x59 //last instruction diff --git a/op.c b/op.c new file mode 100644 index 0000000..3e55dbc --- /dev/null +++ b/op.c @@ -0,0 +1,1358 @@ +/* + * op.c - control program for the open programmer + * Copyright (C) 2009-2020 Alberto Maccioni + * for detailed info see: + * http://openprog.altervista.org/ + * + * 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" +#include "I2CSPI.h" +#include "deviceRW.h" +#include "fileIO.h" +#include "progAVR.h" + + +#if !defined _WIN32 && !defined __CYGWIN__ +DWORD GetTickCount(); +#include +int kbhit() +{ + struct timeval tv; + fd_set read_fd; + tv.tv_sec=0; + tv.tv_usec=0; + FD_ZERO(&read_fd); + FD_SET(0,&read_fd); + if(select(1, &read_fd, NULL, NULL, &tv) == -1) return 0; + if(FD_ISSET(0,&read_fd)) return 1; + return 0; +} +#define getch getchar +#else +#include "conio.h" +#endif +#define MinDly 0 + +void msDelay(double delay); +void TestHw(); +int StartHVReg(double V); +void ProgID(); +void DisplayEE(); +int FindDevice(); +int CheckS1(); + +char** strings; +int saveLog=0,programID=0,load_osccal=0,load_BKosccal=0; +int use_osccal=1,use_BKosccal=0; +int load_calibword=0,max_err=200; +int AVRlock=0x100,AVRfuse=0x100,AVRfuse_h=0x100,AVRfuse_x=0x100; +int ICDenable=0,ICDaddr=0x1FF0; +int FWVersion=0,HwID=0; + +FILE* logfile=0; +char LogFileName[512]=""; +char loadfile[512]="",savefile[512]=""; +char loadfileEE[512]="",savefileEE[512]=""; +int info=0; +int vid=0x1209,pid=0x5432; +int new_vid=0x1209,new_pid=0x5432; +int old_vid=0x04D8,old_pid=0x0100; + +WORD *memCODE_W=0; +int size=0,sizeW=0,sizeEE=0,sizeCONFIG=0,sizeUSERID=0; +unsigned char *memCODE=0,*memEE=0,memID[64],memCONFIG[48],memUSERID[8]; +double hvreg=0; +int DeviceDetected=0; +int skipV33check=0; +int progress=0; +int RWstop=0; +int forceConfig=0; +char dev[64]=""; +int devType=0x10000; +char str[4096]; + +#if !defined _WIN32 && !defined __CYGWIN__ //Linux + int fd = -1; + struct hiddev_report_info rep_info_i,rep_info_u; + struct hiddev_usage_ref_multi ref_multi_i,ref_multi_u; + char path[512]=""; + unsigned char bufferU[128],bufferI[128]; +#else //Windows + unsigned char bufferU0[128],bufferI0[128]; + unsigned char *bufferU,*bufferI; + DWORD NumberOfBytesRead,BytesWritten; + ULONG Result; + HANDLE WriteHandle,ReadHandle; + OVERLAPPED HIDOverlapped; + HANDLE hEventObject; +#endif + + + +int main (int argc, char **argv) { + + int ee=0,r=0,ver=0,c=0,support=0,i2c=0,spi_mode=0,i,j,testhw=0,s1=0; + int spi_speed=0,command=0,langfile=0,help=0; + char lang[32]=""; + unsigned char tmpbuf[128]; + opterr = 0; + int option_index = 0; + int fuse3k=0; + char* langid=0; + int cw1,cw2,cw3,cw4,cw5,cw6,cw7; + cw1=cw2=cw3=cw4=cw5=cw6=cw7=0x10000; +#if defined _WIN32 || defined __CYGWIN__ //Windows + bufferI=bufferI0+1; + bufferU=bufferU0+1; + bufferI0[0]=0; + bufferU0[0]=0; +#endif + + struct option long_options[] = + { + {"BKosccal", no_argument, &load_BKosccal, 1}, + {"calib", no_argument, &load_calibword, 1}, + {"command", no_argument, &command, 1}, + {"cw1", required_argument, 0, '1'}, + {"cw2", required_argument, 0, '2'}, + {"cw3", required_argument, 0, '3'}, + {"cw4", required_argument, 0, '4'}, + {"cw5", required_argument, 0, '5'}, + {"cw6", required_argument, 0, '6'}, + {"cw7", required_argument, 0, '7'}, + {"d", required_argument, 0, 'd'}, + {"device", required_argument, 0, 'd'}, + {"ee", no_argument, &ee, 1}, + {"err", required_argument, 0, 'e'}, + {"fuse", required_argument, 0, 'f'}, + {"fuseh", required_argument, 0, 'F'}, + {"fusex", required_argument, 0, 'X'}, + {"fuse3k", required_argument, 0, 'k'}, + {"h", no_argument, &help,1}, + {"help", no_argument, &help,1}, + {"HWtest", no_argument, &testhw, 1}, + {"info", no_argument, &info, 1}, + {"i", no_argument, &info, 1}, + {"i2c_r", no_argument, &i2c, 1}, + {"i2c_r2", no_argument, &i2c, 2}, + {"i2c_w", no_argument, &i2c, 3}, + {"i2c_w2", no_argument, &i2c, 4}, + {"i2cspeed", required_argument, 0, 'D'}, + {"id", no_argument, &programID, 1}, + {"icd", required_argument, 0, 'I'}, + {"l", optional_argument, 0, 'l'}, //-l=val + {"log", optional_argument, 0, 'l'}, + {"lang", required_argument, 0, 'n'}, + {"langfile", no_argument, &langfile, 1}, + {"lock", required_argument, 0, 'L'}, + {"mode", required_argument, 0, 'm'}, + {"nolvcheck", no_argument, &skipV33check, 1}, + {"osccal", no_argument, &load_osccal, 1}, +#if !defined _WIN32 && !defined __CYGWIN__ + {"p", required_argument, 0, 'p'}, + {"path", required_argument, 0, 'p'}, +#endif + {"pid", required_argument, 0, 'P'}, + {"rep" , required_argument, 0, 'R'}, + {"reserved", no_argument, &r, 1}, + {"r", no_argument, &r, 1}, + {"s1", no_argument, &s1, 1}, + {"S1", no_argument, &s1, 1}, + {"s", required_argument, 0, 's'}, + {"save", required_argument, 0, 's'}, + {"saveEE", required_argument, 0, 'S'}, + {"se", required_argument, 0, 'S'}, + {"spi_r", no_argument, &i2c, 5}, + {"spi_w", no_argument, &i2c, 6}, + {"spispeed", required_argument, 0, 'D'}, + {"support", no_argument, &support, 1}, + {"use_BKosccal", no_argument, &use_BKosccal, 1}, + {"version", no_argument, &ver, 1}, + {"v", no_argument, &ver, 1}, + {"vid", required_argument, 0, 'V'}, + {"w", required_argument, 0, 'w'}, + {"write", required_argument, 0, 'w'}, + {"we", required_argument, 0, 'W'}, + {"writeEE", required_argument, 0, 'W'}, + {0, 0, 0, 0} + }; + while ((c = getopt_long_only (argc, argv, "",long_options,&option_index)) != -1) + /*{ printf("optarg=%X\n",optarg); + if(optarg) printf("%s\n",optarg); + printf("c=%X %c\noption_index=%d name=%s\n",c,c,option_index,long_options[option_index].name); } + exit(0);*/ + switch (c) + { + case '1': //force config word 1 + i=sscanf(optarg, "%x", &cw1); + if(i!=1||cw1<0||cw1>0x3FFF) cw1=0x10000; + break; + case '2': //force config word 2 + i=sscanf(optarg, "%x", &cw2); + if(i!=1||cw2<0||cw2>0x3FFF) cw2=0x10000; + break; + case '3': //force config word 3 + i=sscanf(optarg, "%x", &cw3); + if(i!=1||cw3<0||cw3>0x3FFF) cw3=0x10000; + break; + case '4': //force config word 4 + i=sscanf(optarg, "%x", &cw4); + if(i!=1||cw4<0||cw4>0x3FFF) cw4=0x10000; + break; + case '5': //force config word 5 + i=sscanf(optarg, "%x", &cw5); + if(i!=1||cw5<0||cw5>0x3FFF) cw5=0x10000; + break; + case '6': //force config word 6 + i=sscanf(optarg, "%x", &cw6); + if(i!=1||cw6<0||cw6>0x3FFF) cw6=0x10000; + break; + case '7': //force config word 7 + i=sscanf(optarg, "%x", &cw7); + if(i!=1||cw7<0||cw7>0x3FFF) cw7=0x10000; + break; + case 'd': //device + strncpy(dev,optarg,sizeof(dev)-1); + break; + case 'e': //max write errors + max_err = atoi(optarg); + break; + case 'D': //spi speed + spi_speed = atoi(optarg); + if(spi_speed<0)spi_speed=0; + if(spi_speed>3)spi_speed=3; + break; + case 'f': //Atmel FUSE low + i=sscanf(optarg, "%x", &AVRfuse); + if(i!=1||AVRfuse<0||AVRfuse>0xFF) AVRfuse=0x100; + break; + case 'F': //Atmel FUSE high + i=sscanf(optarg, "%x", &AVRfuse_h); + if(i!=1||AVRfuse_h<0||AVRfuse_h>0xFF) AVRfuse_h=0x100; + break; + case 'I': //ICD routine address + i=sscanf(optarg, "%x", &ICDaddr); + if(i!=1||ICDaddr<0||ICDaddr>0xFFFF) ICDaddr=0x1F00; + ICDenable=1; + break; + case 'k': //Atmel FUSE low @ 3kHz + i=sscanf(optarg, "%x", &AVRfuse); + if(i!=1||AVRfuse<0||AVRfuse>0xFF) AVRfuse=0x100; + else fuse3k=1; + break; + case 'l': //save Log + saveLog=1; + if(optarg) strncpy(LogFileName,optarg,sizeof(LogFileName)); + break; + case 'L': //Atmel LOCK + i=sscanf(optarg, "%x", &AVRlock); + if(i!=1||AVRlock<0||AVRlock>0xFF) AVRlock=0x100; + break; + case 'm': //SPI mode + spi_mode = atoi(optarg); + if(spi_mode<0) spi_mode=0; + if(spi_mode>3) spi_mode=3; + break; + case 'n': //language + strncpy(lang,optarg,sizeof(lang)-1); + break; +#if !defined _WIN32 && !defined __CYGWIN__ + case 'p': //hiddev path + strncpy(path,optarg,sizeof(path)-1); + break; +#endif + case 'P': //pid + sscanf(optarg, "%x", &pid); + break; + case 'R': //USB HID report size + //DIMBUF = atoi(optarg); + break; + case 's': //save + strncpy(savefile,optarg,sizeof(savefile)-1); + break; + case 'S': //save EE + strncpy(savefileEE,optarg,sizeof(savefileEE)-1); + break; + case 'V': //vid + sscanf(optarg, "%x", &vid); + break; + case 'X': //Atmel extended FUSE + i=sscanf(optarg, "%x", &AVRfuse_x); + if(i!=1||AVRfuse_x<0||AVRfuse_x>0xFF) AVRfuse_x=0x100; + break; + case 'w': //write file + strncpy(loadfile,optarg,sizeof(loadfile)-1); + break; + case 'W': //write EE file + strncpy(loadfileEE,optarg,sizeof(loadfileEE)-1); + break; + case '?': + fprintf (stderr,strings[L_OPTERR]); //errore opzioni + return 1; + default: + + break; + } + + for(j=0,i = optind; i < argc&&i<128; i++,j++) sscanf(argv[i], "%x", &tmpbuf[j]); + for(;j<128;j++) tmpbuf[j]=0; + + strinit(); + i=0; + if(lang[0]){ //explicit language selection + if(lang[0]=='i'&&langid[1]=='t'){ //built-in + strings=strings_it; + i=1; + } + else if(lang[0]=='e'&&lang[1]=='n'){ //built-in + strings=strings_en; + i=1; + } + else i=strfind(lang,"languages.rc"); //file look-up + } + if(i==0){ + #if defined _WIN32 + langid=malloc(19); + int n=GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SISO639LANGNAME,langid,9); + langid[n-1] = '-'; + GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SISO3166CTRYNAME,langid+n, 9); + //printf("%d >%s<\n",n,langid); + #else + langid=getenv("LANG"); + #endif + if(langid){ + if(langid[0]=='i'&&langid[1]=='t') strings=strings_it; + else if(langid[0]=='e'&&langid[1]=='n') strings=strings_en; + else if(strfind(langid,"languages.rc")); //first try full code + else { //then only first language code + char* p=strchr(langid,'-'); + if(p) *p=0; + if(!strfind(langid,"languages.rc")) strings=strings_en; + } + } + else strings=strings_en; + } + + strncpy(LogFileName,strings[S_LogFile],sizeof(LogFileName)); + if(argc==1){ + printf(strings[L_HELP]); + exit(1); + } + + if(help){ + printf(strings[L_HELP]); + return 1; + } + + if(langfile) GenerateLangFile(langid,"languages.rc"); + + if (ver){ + printf("OP v%s\nCopyright (C) Alberto Maccioni 2009-2022\ +\n For detailed info see http://openprog.altervista.org/\ +\nThis 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.\ + \n",VERSION); + return 0; + } + if (support){ + char list[20000]; //make sure list is long enough!! + AddDevices(list); + printf("%s\n",list); + return 0; + } + DeviceDetected=FindDevice(vid,pid); //connect to USB programmer + if(!DeviceDetected){ + DeviceDetected=FindDevice(new_vid,new_pid); //try default + if(DeviceDetected){ + vid=new_vid; + pid=new_pid; + } + } + if(!DeviceDetected) DeviceDetected=FindDevice(old_vid,old_pid); //try old one + if(!DeviceDetected) exit(1); + ProgID(); //get firmware version and reset + +#if !defined _WIN32 && !defined __CYGWIN__ + if(info){ + #ifndef hiddevIO //use raw USB device + struct hidraw_devinfo device_info; + char name[256],path[256]; + ioctl(fd, HIDIOCGRAWINFO, &device_info); + ioctl(fd, HIDIOCGRAWNAME(256), name); + ioctl(fd, HIDIOCGRAWPHYS(256), path); + printf("VID 0x%04X PID 0x%04X\n",device_info.vendor, device_info.product); + printf(strings[L_NAME], path, name);//"The device on %s says its name is %s\n" + #else //use hiddev device (old method) + struct hiddev_devinfo device_info; + ioctl(fd, HIDIOCGDEVINFO, &device_info); + printf(strings[L_INFO1],device_info.vendor, device_info.product, device_info.version); + printf(strings[L_INFO2],device_info.busnum, device_info.devnum, device_info.ifnum); + char name[256]; + strcpy(name,strings[L_UNKNOWN]);//"Unknown" + if(ioctl(fd, HIDIOCGNAME(sizeof(name)), name) < 0) perror("evdev ioctl"); + printf(strings[L_NAME], path, name);//"The device on %s says its name is %s\n" + #endif + return 0; + } +#endif + + DWORD t0,t; + t=t0=GetTickCount(); + if(testhw){ + TestHw(); + return 0; + } + + if(command){ + //bufferU[0]=0; + for(i=0;i "); + for(i=0;i0x8008){ //16F1xxx + if(cw1<=0x3FFF){ + memCODE_W[0x8007]=cw1; + PrintMessage3(strings[S_ForceConfigWx],1,0x8007,cw1); //"forcing config word%d [0x%04X]=0x%04X" + } + if(cw2<=0x3FFF){ + memCODE_W[0x8008]=cw2; + PrintMessage3(strings[S_ForceConfigWx],2,0x8008,cw2); //"forcing config word%d [0x%04X]=0x%04X" + } + } + else{ //16Fxxx + if(cw1<=0x3FFF&&sizeW>0x2007){ + memCODE_W[0x2007]=cw1; + PrintMessage3(strings[S_ForceConfigWx],1,0x2007,cw1); //"forcing config word%d [0x%04X]=0x%04X" + } + if(cw2<=0x3FFF&&sizeW>0x2008){ + memCODE_W[0x2008]=cw2; + printf("2\n"); + PrintMessage3(strings[S_ForceConfigWx],2,0x2008,cw2); //"forcing config word%d [0x%04X]=0x%04X" + } + } + } + else if(devType==PIC12){ //12Fxxx + if(cw1<=0xFFF&&sizeW>0xFFF){ + memCODE_W[0xFFF]=cw1; + PrintMessage3(strings[S_ForceConfigWx],1,0xFFF,cw1); //"forcing config word%d [0x%04X]=0x%04X" + } + } + else if(devType==PIC18){ //18Fxxx + if(cw1<=0xFFFF){ + memCONFIG[0]=cw1&0xFF; + memCONFIG[1]=(cw1>>8)&0xFF; + } + if(cw2<=0xFFFF){ + memCONFIG[2]=cw2&0xFF; + memCONFIG[3]=(cw2>>8)&0xFF; + } + if(cw3<=0xFFFF){ + memCONFIG[4]=cw3&0xFF; + memCONFIG[5]=(cw3>>8)&0xFF; + } + if(cw4<=0xFFFF){ + memCONFIG[6]=cw4&0xFF; + memCONFIG[7]=(cw4>>8)&0xFF; + } + if(cw5<=0xFFFF){ + memCONFIG[8]=cw5&0xFF; + memCONFIG[9]=(cw5>>8)&0xFF; + } + if(cw6<=0xFFFF){ + memCONFIG[10]=cw6&0xFF; + memCONFIG[11]=(cw6>>8)&0xFF; + } + if(cw7<=0xFFFF){ + memCONFIG[12]=cw7&0xFF; + memCONFIG[13]=(cw7>>8)&0xFF; + } + PrintMessage(strings[S_ForceConfigW]); //"forcing config words" + for(i=0;i<7;i++){ + PrintMessage2(strings[S_ConfigWordH],i+1,memCONFIG[i*2+1]); //"CONFIG%dH: 0x%02X\t" + PrintMessage2(strings[S_ConfigWordL],i+1,memCONFIG[i*2]); //"CONFIG%dL: 0x%02X\r\n" + } + } +/* if(CW1_force!=-1||CW2_force!=-1){ + if((!strncmp(dev,"16F1",4)||!strncmp(dev,"12F1",4))){ //16F1xxx + if(CW1_force!=-1&&sizeW>0x8007) memCODE_W[0x8007]=CW1_force; + if(CW2_force!=-1&&sizeW>0x8008) memCODE_W[0x8008]=CW2_force; + } + else if((!strncmp(dev,"16F",3)||!strncmp(dev,"12F6",4))&&strncmp(dev,"16F5",4)){ //16Fxxx + if(CW1_force!=-1&&sizeW>0x2007) memCODE_W[0x2007]=CW1_force; + if(CW2_force!=-1&&sizeW>0x2008) memCODE_W[0x2008]=CW2_force; + } + else if((!strncmp(dev,"12F",3)||!strncmp(dev,"10F",3)||!strncmp(dev,"16F5",4))){ //12Fxxx + if(CW1_force!=-1&&sizeW>0xFFF) memCODE_W[0xFFF]=CW1_force&0xFFF; + } + if(CW1_force!=-1) PrintMessage1(strings[S_ForceConfigWx],CW1_force); //"forcing config word1 (0x%04X)" + if(CW2_force!=-1) PrintMessage1(strings[S_ForceConfigWx],CW2_force); //"forcing config word2 (0x%04X)" + } +*/ + //Start with button + if(s1){ + PrintMessage(strings[S_WaitS1W]); //"Press S1 to program, any key to exit" + fflush(stdout); + for(;!kbhit();msDelay(50)){ + if(CheckS1()){ //wait for S1 + Write(dev,ee); //choose the right function + PrintMessage(strings[S_WaitS1W]); //"Press S1 to program, any key to exit" + fflush(stdout); + for(;CheckS1();msDelay(50)); //wait for S1 open + } + } + getch(); + } + else Write(dev,ee); //choose the right function + } + else{ //read + if(s1){ + PrintMessage(strings[S_WaitS1R]); //"Press S1 to read, any key to exit" + fflush(stdout); + for(;!kbhit();msDelay(50)){ + if(CheckS1()){ //wait for S1 + Read(dev,ee,r); //choose the right function + PrintMessage(strings[S_WaitS1R]); //"Press S1 to read, any key to exit" + fflush(stdout); + for(;CheckS1();msDelay(50)); //wait for S1 open + } + } + getch(); + } + else Read(dev,ee,r); //choose the right function + + if(savefile[0]) Save(dev,savefile); + if(!strncmp(dev,"AT",2)&&savefileEE[0]) SaveEE(dev,savefileEE); + } + +#if !defined _WIN32 && !defined __CYGWIN__ //Linux + close(fd); +#endif + return 0 ; +} + + +/// +///Display contents of EEprom memory +void DisplayEE(){ + char s[256],t[256],v[256]; + int valid=0,empty=1; + int i,j; + s[0]=0; + v[0]=0; + PrintMessage(strings[S_EEMem]); //"\r\nmemoria EEPROM:\r\n" + for(i=0;i>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=WAIT_T3; + bufferU[j++]=READ_ADC; + bufferU[j++]=FLUSH; + for(;j(vreg/10.0+1)*G)&&t>=2; //if 12 bit ADC +// PrintMessage2("v=%d=%fV\n",v,v/G); + } + if(v>(vreg/10.0+1)*G){ + PrintMessage(strings[S_HiVPP]); //"Attenzione: tensione regolatore troppo alta\r\n\r\n" + return 0; + } + else if(v<(vreg/10.0-1)*G){ + PrintMessage(strings[S_LowVPP]); //"Attenzione: tensione regolatore troppo bassa\r\n\r\n" + return 0; + } + else if(v==0){ + PrintMessage(strings[S_lowUsbV]); //"Tensione USB troppo bassa (VUSB<4.5V)\r\n" + return 0; + } + else{ + PrintMessage2(strings[S_reg],t-t0,v/G); //"Regolatore avviato e funzionante dopo T=%d ms VPP=%.1f\r\n\r\n" + if(saveLog&&logfile) fprintf(logfile,strings[S_reg],t-t0,v/G); + return vreg; + } +} + +/// +///Read programmer ID +void ProgID() +{ + if(DeviceDetected!=1) return; + int j=0; + bufferU[j++]=PROG_RST; + bufferU[j++]=FLUSH; + for(;j E3=1 +} + +/// +///Execute hardware test +void TestHw() +{ +#ifndef DEBUG + if(DeviceDetected!=1) return; +#endif + char str[256]; + StartHVReg(13); + int j=0; + PrintMessage(strings[I_TestHW]); //"Test hardware ..." + fflush(stdout); + getchar(); + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=FLUSH; + for(;j=0x900){ //IO test + int j=0,i,x,r; + strcpy(str,"0000000000000"); + PrintMessage("IO test\nRC|RA|--RB--|\n"); + for(i=0;i<13;i++){ + x=1<>5)&0xFF; //PORTA-C + bufferU[j++]=READ_B; + bufferU[j++]=READ_AC; + bufferU[j++]=FLUSH; + for(;jMinDly?x:MinDly); +#else +// Sleep((long)ceil(delay)>MinDly?(long)ceil(delay):MinDly); + __int64 stop,freq,timeout; + QueryPerformanceCounter((LARGE_INTEGER *)&stop); + QueryPerformanceFrequency((LARGE_INTEGER *)&freq); + timeout=stop+delay*freq/1000.0; + while(stop0){ //try with this first + sprintf(path,"/dev/openprogrammer"); + ioctl(fd, HIDIOCGRAWINFO, &device_info); + if(device_info.vendor==vid&&device_info.product==pid) i=0; + else{ + close(fd); + i=-1; + } + } + if(i){ + for(i=0;i<16;i++){ + sprintf(path,"/dev/hidraw%d",i); + if((fd = open(path, O_RDWR|O_NONBLOCK))>0){ + ioctl(fd, HIDIOCGRAWINFO, &device_info); + if(device_info.vendor==vid&&device_info.product==pid) break; + else close(fd); + } + } + } + if(i==16){ + PrintMessage(strings[S_noprog]); + path[0]=0; + return 0; + } + } + else{ //user supplied path + if((fd = open(path, O_RDWR|O_NONBLOCK)) < 0) { + PrintMessage1(strings[S_DevPermission],path); //"cannot open %s, make sure you have read permission on it",path); + return 0; + } + ioctl(fd, HIDIOCGRAWINFO, &device_info); + if(device_info.vendor!=vid||device_info.product!=pid){ + PrintMessage(strings[S_noprog]); + return 0; + } + } + printf(strings[S_progDev],path); + return 1; + #else //use hiddev device (old method) + struct hiddev_devinfo device_info; + int i=-1; + if(path[0]==0){ //search all devices + if((fd = open("/dev/openprogrammer", O_RDONLY ))>0){ //try with this first + ioctl(fd, HIDIOCGDEVINFO, &device_info); + if(device_info.vendor==vid&&device_info.product==pid) i=0; + else{ + close(fd); + i=-1; + } + } + if(i){ + for(i=0;i<16;i++){ + sprintf(path,"/dev/usb/hiddev%d",i); + if((fd = open(path, O_RDONLY ))>0){ + ioctl(fd, HIDIOCGDEVINFO, &device_info); + if(device_info.vendor==vid&&device_info.product==pid) break; + else close(fd); + } + } + } + if(i==16){ + PrintMessage(strings[S_noprog]); + path[0]=0; + return 0; + } + } + else{ //user supplied path + if ((fd = open(path, O_RDONLY )) < 0) { + PrintMessage1(strings[S_DevPermission],path); //"cannot open %s, make sure you have read permission on it",path); + return 0; + } + ioctl(fd, HIDIOCGDEVINFO, &device_info); + if(device_info.vendor!=vid||device_info.product!=pid){ + PrintMessage(strings[S_noprog]); + return 0; + } + } + printf(strings[S_progDev],path); + MyDeviceDetected = TRUE; + rep_info_u.report_type=HID_REPORT_TYPE_OUTPUT; + rep_info_i.report_type=HID_REPORT_TYPE_INPUT; + rep_info_u.report_id=rep_info_i.report_id=HID_REPORT_ID_FIRST; + rep_info_u.num_fields=rep_info_i.num_fields=1; + ref_multi_u.uref.report_type=HID_REPORT_TYPE_OUTPUT; + ref_multi_i.uref.report_type=HID_REPORT_TYPE_INPUT; + ref_multi_u.uref.report_id=ref_multi_i.uref.report_id=HID_REPORT_ID_FIRST; + ref_multi_u.uref.field_index=ref_multi_i.uref.field_index=0; + ref_multi_u.uref.usage_index=ref_multi_i.uref.usage_index=0; + ref_multi_u.num_values=ref_multi_i.num_values=DIMBUF; + #endif +#else //Windows + PSP_DEVICE_INTERFACE_DETAIL_DATA detailData; + HANDLE DeviceHandle; + HANDLE hDevInfo; + GUID HidGuid; + char MyDevicePathName[1024]; + ULONG Length; + ULONG Required; + typedef struct _HIDD_ATTRIBUTES { + ULONG Size; + USHORT VendorID; + USHORT ProductID; + USHORT VersionNumber; + } HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES; + typedef void (__stdcall*GETHIDGUID) (OUT LPGUID HidGuid); + typedef BOOLEAN (__stdcall*GETATTRIBUTES)(IN HANDLE HidDeviceObject,OUT PHIDD_ATTRIBUTES Attributes); + typedef BOOLEAN (__stdcall*SETNUMINPUTBUFFERS)(IN HANDLE HidDeviceObject,OUT ULONG NumberBuffers); + typedef BOOLEAN (__stdcall*GETNUMINPUTBUFFERS)(IN HANDLE HidDeviceObject,OUT PULONG NumberBuffers); + typedef BOOLEAN (__stdcall*GETFEATURE) (IN HANDLE HidDeviceObject, OUT PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*SETFEATURE) (IN HANDLE HidDeviceObject, IN PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*GETREPORT) (IN HANDLE HidDeviceObject, OUT PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*SETREPORT) (IN HANDLE HidDeviceObject, IN PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*GETMANUFACTURERSTRING) (IN HANDLE HidDeviceObject, OUT PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*GETPRODUCTSTRING) (IN HANDLE HidDeviceObject, OUT PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*GETINDEXEDSTRING) (IN HANDLE HidDeviceObject, IN ULONG StringIndex, OUT PVOID ReportBuffer, IN ULONG ReportBufferLength); + HIDD_ATTRIBUTES Attributes; + SP_DEVICE_INTERFACE_DATA devInfoData; + int LastDevice = FALSE; + int MemberIndex = 0; + LONG Result; + Length=0; + detailData=NULL; + DeviceHandle=NULL; + HMODULE hHID=0; + GETHIDGUID HidD_GetHidGuid=0; + GETATTRIBUTES HidD_GetAttributes=0; + SETNUMINPUTBUFFERS HidD_SetNumInputBuffers=0; + GETNUMINPUTBUFFERS HidD_GetNumInputBuffers=0; + GETFEATURE HidD_GetFeature=0; + SETFEATURE HidD_SetFeature=0; + GETREPORT HidD_GetInputReport=0; + SETREPORT HidD_SetOutputReport=0; + GETMANUFACTURERSTRING HidD_GetManufacturerString=0; + GETPRODUCTSTRING HidD_GetProductString=0; + hHID = LoadLibrary("hid.dll"); + if(!hHID){ + PrintMessage("Can't find hid.dll"); + return 0; + } + HidD_GetHidGuid=(GETHIDGUID)GetProcAddress(hHID,"HidD_GetHidGuid"); + HidD_GetAttributes=(GETATTRIBUTES)GetProcAddress(hHID,"HidD_GetAttributes"); + HidD_SetNumInputBuffers=(SETNUMINPUTBUFFERS)GetProcAddress(hHID,"HidD_SetNumInputBuffers"); + HidD_GetNumInputBuffers=(GETNUMINPUTBUFFERS)GetProcAddress(hHID,"HidD_GetNumInputBuffers"); + HidD_GetFeature=(GETFEATURE)GetProcAddress(hHID,"HidD_GetFeature"); + HidD_SetFeature=(SETFEATURE)GetProcAddress(hHID,"HidD_SetFeature"); + HidD_GetInputReport=(GETREPORT)GetProcAddress(hHID,"HidD_GetInputReport"); + HidD_SetOutputReport=(SETREPORT)GetProcAddress(hHID,"HidD_SetOutputReport"); + HidD_GetManufacturerString=(GETMANUFACTURERSTRING)GetProcAddress(hHID,"HidD_GetManufacturerString"); + HidD_GetProductString=(GETPRODUCTSTRING)GetProcAddress(hHID,"HidD_GetProductString"); + if(HidD_GetHidGuid==NULL\ + ||HidD_GetAttributes==NULL\ + ||HidD_GetFeature==NULL\ + ||HidD_SetFeature==NULL\ + ||HidD_GetInputReport==NULL\ + ||HidD_SetOutputReport==NULL\ + ||HidD_GetManufacturerString==NULL\ + ||HidD_GetProductString==NULL\ + ||HidD_SetNumInputBuffers==NULL\ + ||HidD_GetNumInputBuffers==NULL) return 0; + HMODULE hSAPI=0; + hSAPI = LoadLibrary("setupapi.dll"); + if(!hSAPI){ + PrintMessage("Can't find setupapi.dll"); + return 0; + } + typedef HDEVINFO (WINAPI* SETUPDIGETCLASSDEVS) (CONST GUID*,PCSTR,HWND,DWORD); + typedef BOOL (WINAPI* SETUPDIENUMDEVICEINTERFACES) (HDEVINFO,PSP_DEVINFO_DATA,CONST GUID*,DWORD,PSP_DEVICE_INTERFACE_DATA); + typedef BOOL (WINAPI* SETUPDIGETDEVICEINTERFACEDETAIL) (HDEVINFO,PSP_DEVICE_INTERFACE_DATA,PSP_DEVICE_INTERFACE_DETAIL_DATA_A,DWORD,PDWORD,PSP_DEVINFO_DATA); + typedef BOOL (WINAPI* SETUPDIDESTROYDEVICEINFOLIST) (HDEVINFO); + SETUPDIGETCLASSDEVS SetupDiGetClassDevsA=0; + SETUPDIENUMDEVICEINTERFACES SetupDiEnumDeviceInterfaces=0; + SETUPDIGETDEVICEINTERFACEDETAIL SetupDiGetDeviceInterfaceDetailA=0; + SETUPDIDESTROYDEVICEINFOLIST SetupDiDestroyDeviceInfoList=0; + SetupDiGetClassDevsA=(SETUPDIGETCLASSDEVS) GetProcAddress(hSAPI,"SetupDiGetClassDevsA"); + SetupDiEnumDeviceInterfaces=(SETUPDIENUMDEVICEINTERFACES) GetProcAddress(hSAPI,"SetupDiEnumDeviceInterfaces"); + SetupDiGetDeviceInterfaceDetailA=(SETUPDIGETDEVICEINTERFACEDETAIL) GetProcAddress(hSAPI,"SetupDiGetDeviceInterfaceDetailA"); + SetupDiDestroyDeviceInfoList=(SETUPDIDESTROYDEVICEINFOLIST) GetProcAddress(hSAPI,"SetupDiDestroyDeviceInfoList"); + if(SetupDiGetClassDevsA==NULL\ + ||SetupDiEnumDeviceInterfaces==NULL\ + ||SetupDiDestroyDeviceInfoList==NULL\ + ||SetupDiGetDeviceInterfaceDetailA==NULL) return 0; + /* + The following code is adapted from Usbhidio_vc6 application example by Jan Axelson + for more information see see http://www.lvr.com/hidpage.htm + */ + /* + API function: HidD_GetHidGuid + Get the GUID for all system HIDs. + Returns: the GUID in HidGuid. + */ + HidD_GetHidGuid(&HidGuid); + /* + API function: SetupDiGetClassDevs + Returns: a handle to a device information set for all installed devices. + Requires: the GUID returned by GetHidGuid. + */ + hDevInfo=SetupDiGetClassDevs(&HidGuid,NULL,NULL,DIGCF_PRESENT|DIGCF_INTERFACEDEVICE); + devInfoData.cbSize = sizeof(devInfoData); + //Step through the available devices looking for the one we want. + //Quit on detecting the desired device or checking all available devices without success. + MemberIndex = 0; + LastDevice = FALSE; + do + { + /* + API function: SetupDiEnumDeviceInterfaces + On return, MyDeviceInterfaceData contains the handle to a + SP_DEVICE_INTERFACE_DATA structure for a detected device. + Requires: + The DeviceInfoSet returned in SetupDiGetClassDevs. + The HidGuid returned in GetHidGuid. + An index to specify a device. + */ + Result=SetupDiEnumDeviceInterfaces (hDevInfo, 0, &HidGuid, MemberIndex, &devInfoData); + if (Result != 0) + { + //A device has been detected, so get more information about it. + /* + API function: SetupDiGetDeviceInterfaceDetail + Returns: an SP_DEVICE_INTERFACE_DETAIL_DATA structure + containing information about a device. + To retrieve the information, call this function twice. + The first time returns the size of the structure in Length. + The second time returns a pointer to the data in DeviceInfoSet. + Requires: + A DeviceInfoSet returned by SetupDiGetClassDevs + The SP_DEVICE_INTERFACE_DATA structure returned by SetupDiEnumDeviceInterfaces. + The final parameter is an optional pointer to an SP_DEV_INFO_DATA structure. + This application doesn't retrieve or use the structure. + If retrieving the structure, set + MyDeviceInfoData.cbSize = length of MyDeviceInfoData. + and pass the structure's address. + */ + //Get the Length value. + //The call will return with a "buffer too small" error which can be ignored. + Result = SetupDiGetDeviceInterfaceDetail(hDevInfo, &devInfoData, NULL, 0, &Length, NULL); + //Allocate memory for the hDevInfo structure, using the returned Length. + detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(Length); + //Set cbSize in the detailData structure. + detailData -> cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); + //Call the function again, this time passing it the returned buffer size. + Result = SetupDiGetDeviceInterfaceDetail(hDevInfo, &devInfoData, detailData, Length,&Required, NULL); + // Open a handle to the device. + // To enable retrieving information about a system mouse or keyboard, + // don't request Read or Write access for this handle. + /* + API function: CreateFile + Returns: a handle that enables reading and writing to the device. + Requires: + The DevicePath in the detailData structure + returned by SetupDiGetDeviceInterfaceDetail. + */ + DeviceHandle=CreateFile(detailData->DevicePath, + 0, FILE_SHARE_READ|FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL,OPEN_EXISTING, 0, NULL); + /* + API function: HidD_GetAttributes + Requests information from the device. + Requires: the handle returned by CreateFile. + Returns: a HIDD_ATTRIBUTES structure containing + the Vendor ID, Product ID, and Product Version Number. + Use this information to decide if the detected device is + the one we're looking for. + */ + //Set the Size to the number of bytes in the structure. + Attributes.Size = sizeof(Attributes); + Result = HidD_GetAttributes(DeviceHandle,&Attributes); + //Is it the desired device? + MyDeviceDetected = FALSE; + if (Attributes.VendorID == vid) + { + if (Attributes.ProductID == pid) + { + //Both the Vendor ID and Product ID match. + MyDeviceDetected = TRUE; + strcpy(MyDevicePathName,detailData->DevicePath); + // Get a handle for writing Output reports. + WriteHandle=CreateFile(detailData->DevicePath, + GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL,OPEN_EXISTING,0,NULL); + //Get a handle to the device for the overlapped ReadFiles. + ReadHandle=CreateFile(detailData->DevicePath, + GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,(LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL); + if (hEventObject) CloseHandle(hEventObject); + hEventObject = CreateEvent(NULL,TRUE,TRUE,""); + //Set the members of the overlapped structure. + HIDOverlapped.hEvent = hEventObject; + HIDOverlapped.Offset = 0; + HIDOverlapped.OffsetHigh = 0; + Result=HidD_SetNumInputBuffers(DeviceHandle,64); + } + else + //The Product ID doesn't match. + CloseHandle(DeviceHandle); + } + else + //The Vendor ID doesn't match. + CloseHandle(DeviceHandle); + //Free the memory used by the detailData structure (no longer needed). + free(detailData); + } + else + //SetupDiEnumDeviceInterfaces returned 0, so there are no more devices to check. + LastDevice=TRUE; + //If we haven't found the device yet, and haven't tried every available device, + //try the next one. + MemberIndex = MemberIndex + 1; + } //do + while ((LastDevice == FALSE) && (MyDeviceDetected == FALSE)); + //Free the memory reserved for hDevInfo by SetupDiClassDevs. + SetupDiDestroyDeviceInfoList(hDevInfo); + + if(info&&MyDeviceDetected == TRUE){ + char string[1024]; + PrintMessage3("Device detected: vid=0x%04X pid=0x%04X\nPath: %s\n",vid,pid,MyDevicePathName); + if(HidD_GetManufacturerString(DeviceHandle,string,sizeof(string))==TRUE) wprintf(L"Manufacturer string: %s\n",string); + if(HidD_GetProductString(DeviceHandle,string,sizeof(string))==TRUE) wprintf(L"Product string: %s\n",string); + } +#endif + if (MyDeviceDetected == FALSE){ + PrintMessage(strings[S_noprog]); //"Programmer not detected\r\n" + //gtk_statusbar_push(status_bar,statusID,strings[S_noprog]); + } + else{ + PrintMessage(strings[S_prog]); //"Programmer detected\r\n"); + //gtk_statusbar_push(status_bar,statusID,strings[S_prog]); + } + return MyDeviceDetected; +} \ No newline at end of file diff --git a/opgui.c b/opgui.c new file mode 100644 index 0000000..1268901 --- /dev/null +++ b/opgui.c @@ -0,0 +1,2503 @@ +/** + * \file opgui.c + * main control program for the open programmer + * + * Copyright (C) 2009-2023 Alberto Maccioni + * for detailed info see: + * http://openprog.altervista.org/ + * + * 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" +#include "I2CSPI.h" +#include "coff.h" +#include "icd.h" +#include "deviceRW.h" +#include "fileIO.h" +#include "progAVR.h" +#include + +#define MAXLINES 600 +#define CONFIG_FILE "opgui.ini" +#define CONFIG_DIR ".opgui" +#define MinDly 0 +void Connect(GtkWidget *widget,GtkWidget *window); +void Quit(GtkWidget *widget,GtkWidget *window) { gtk_main_quit(); } +void I2cspiR(); +void I2cspiS(); +void ProgID(); +void PrintMessageI2C(const char *msg); +void ShowContext(); +int FindDevice(int vid,int pid); +void TestHw(); +int CheckS1(); +char** strings; //!localized strings +int cmdline=0; +int saveLog=0,programID=0,load_osccal=0,load_BKosccal=0; +int use_osccal=1,use_BKosccal=0; +int load_calibword=0,max_err=200; +int AVRlock=0x100,AVRfuse=0x100,AVRfuse_h=0x100,AVRfuse_x=0x100; +int ICDenable=0,ICDaddr=0x1FF0; +int FWVersion=0,HwID=0; +FILE* logfile=0; +char LogFileName[512]=""; +char loadfile[512]="",savefile[512]=""; +char loadfileEE[512]="",savefileEE[512]=""; +char CoffFileName[512]=""; +int vid=0x1209,pid=0x5432; +int new_vid=0x1209,new_pid=0x5432; +int old_vid=0x04D8,old_pid=0x0100; +WORD *memCODE_W=0; +int size=0,sizeW=0,sizeEE=0,sizeCONFIG=0,sizeUSERID=0; +unsigned char *memCODE=0,*memEE=0,memID[64],memCONFIG[48],memUSERID[8]; +double hvreg=0; +int DeviceDetected=0; +int IOTimer=0; +int skipV33check=0; +int waitS1=0,waitingS1=0; +int progress=0; +int RWstop=0; +int forceConfig=0; +#ifdef DEBUG + int addrDebug=0; + unsigned short dataDebug=0; + unsigned short statusDebug=0x3FFF; +#endif +//List of gtk controls +GtkTextBuffer * dataBuf; +GtkWidget * data,*data_scroll; +GtkWidget * window; +GtkWidget * toolbar; +GtkWidget * button; +GtkWidget * b_open; +GtkWidget * b_save; +GtkWidget * b_read; +GtkWidget * b_write; +GtkWidget * notebook; +GtkWidget * label; +GtkWidget * status_bar; +GtkWidget * img; +GtkWidget * devTree; +GtkWidget * devTypeCombo; +GtkWidget * devFramePIC; +GtkWidget * ICD_check; +GtkWidget * ICD_addr_entry; +GtkWidget * EEPROM_RW; +GtkWidget * ReadReserved; +GtkWidget * Write_ID_BKCal; +GtkWidget * WriteCalib12; +GtkWidget * UseOSCCAL; +GtkWidget * UseBKOSCCAL; +GtkWidget * UseFileCal; +GtkWidget * devFrameAVR; +GtkWidget * AVR_FuseLow,* AVR_FuseLowWrite,* AVR_FuseHigh,* AVR_FuseHighWrite,* AVR_FuseExt; +GtkWidget * AVR_FuseExtWrite,* AVR_Lock,* AVR_LockWrite; +GtkWidget * b_WfuseLF; +GtkWidget * b_connect; +GtkWidget * b_testhw; +GtkWidget * b_log; +GtkWidget * VID_entry; +GtkWidget * PID_entry; +GtkWidget * Errors_entry; +GtkWidget * I2C8bit; +GtkWidget * I2C16bit; +GtkWidget * SPI00; +GtkWidget * SPI01; +GtkWidget * SPI10; +GtkWidget * SPI11; +GtkWidget * I2CDataSend; +GtkWidget * I2CDataReceive; +GtkWidget * I2CSendBtn; +GtkWidget * I2CReceiveBtn; +GtkWidget * I2CNbyte; +GtkWidget * I2CSpeed; +GtkWidget * DCDC_ON; +GtkWidget * DCDC_voltage; +GtkWidget * VPP_ON; +GtkWidget * VDD_ON; +GtkWidget * b_io_active; +GtkWidget * commandSend; +GtkWidget * commandTransfer; +GtkWidget * b_V33check; +GtkWidget * Hex_entry; +GtkWidget * Address_entry; +GtkWidget * Data_entry; +GtkWidget * Hex_data; +GtkWidget * Hex_data2; +GtkWidget * CW1_entry; +GtkWidget * CW2_entry; +GtkWidget * CW3_entry; +GtkWidget * CW4_entry; +GtkWidget * CW5_entry; +GtkWidget * CW6_entry; +GtkWidget * CW7_entry; +GtkWidget * ConfigForce; +GtkWidget * b_WaitS1; +GtkWidget * devFrameConfigW; +GtkWidget * devFrameICD; +GtkWidget * devFrameOsc; +GtkWidget * devPIC_CW1; +GtkWidget * devPIC_CW2; +GtkWidget * devPIC_CW3; +GtkWidget * devPIC_CW4; +GtkWidget * devPIC_CW5; +GtkWidget * devPIC_CW6; +GtkWidget * devPIC_CW7; +GtkWidget * devPIC_CW8; +GtkWidget * devinfo; +GtkWidget* stopBtn; +GtkWidget* readBtn; +GtkWidget* writeBtn; +GtkListStore *devStore; +GtkWidget *devTree, *devFiltEntry, *devFrame; +GtkTreeSelection *devSel; +///array of radio buttons for IO manual control +struct io_btn { char * name; + int x; + int y; + GtkWidget * r_0; //radio button 0 + GtkWidget * r_1; //radio button 1 + GtkWidget * r_I; //radio button I + GtkWidget * e_I; //entry + } ioButtons[13]; +int statusID; +int ee = 0; +int readRes=0; +char dev[64]=""; +int devType=-1; +char str[4096]=""; +char* cur_path=0; +char* cur_pathEE=0; +enum dev_column_t { + DEVICE_ID_COLUMN = 0, + DEVICE_NAME_COLUMN, + DEVICE_GROUP_COLUMN, + DEVICE_N_COLUMNS +}; +enum sort_type_t { + SORT_STRING_NAME = 0, + SORT_STRING_GROUP +}; +enum sort_data_type_t { SDT_STRING = 0 }; +char *groupNames[NUM_GROUPS] = { + "PIC10/12", + "PIC16", + "PIC18", + "PIC24", + "PIC30/33", + "ATMEL AVR", + "MEMORY" +}; +char *GROUP_ALL="*"; + +#if !defined _WIN32 && !defined __CYGWIN__ //Linux + int fd = -1; +#ifdef hiddevIO + struct hiddev_report_info rep_info_i,rep_info_u; + struct hiddev_usage_ref_multi ref_multi_i,ref_multi_u; +#endif + char path[512]=""; + unsigned char bufferU[128],bufferI[128]; +#else //Windows + unsigned char bufferU0[128],bufferI0[128]; + unsigned char *bufferU,*bufferI; + DWORD NumberOfBytesRead,BytesWritten; + ULONG Result; + HANDLE WriteHandle,ReadHandle; + OVERLAPPED HIDOverlapped; + HANDLE hEventObject; +#endif +/// +///Exit +gint delete_event( GtkWidget *widget,GdkEvent *event,gpointer data ) +{ +gtk_main_quit (); +return FALSE; +} +/// +///Show program info window +void info(GtkWidget *widget,GtkWidget *window) +{ + const gchar *license = + "This program is free software; you can redistribute it and/or\n" + "modify it under the terms of the GNU Library General Public License as\n" + "published by the Free Software Foundation; either version 2 of the\n" + "License, or (at your option) any later version.\n" + "\n" + "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" + "Library General Public License for more details.\n" + "\n" + "You should have received a copy of the GNU Library General Public\n" + "License along with the Gnome Library; see the file COPYING.LIB. If not,\n" + "write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\n" + "Boston, MA 02111-1307, USA.\n"; + gtk_show_about_dialog (NULL, + //"artists" GStrv* : Read / Write + //"authors" GStrv* : Read / Write + //"authors","Alberto Maccioni",NULL, + "comments", "A graphical interface for the Open Programmer", + "copyright", + "Copyright (C) Alberto Maccioni 2009-2022\n\n" + "This program is free software; you can \n" + "redistribute it and/or modify it under \n" + "the terms of the GNU General Public License \n" + "as published by the Free Software Foundation;\n" + "either version 2 of the License, or \n" + "(at your option) any later version.", + //"documenters" GStrv* : Read / Write + "license",license, + "logo",gdk_pixbuf_new_from_resource("/res/sys.png", NULL), + // "logo-icon-name" gchar* : Read / Write + "program-name", "OPGUI", + // "translator-credits" gchar* : Read / Write + "version",VERSION, + "website","www.openprog.altervista.org", + // "website-label" gchar* : Read / Write + "wrap-license",TRUE, + "title","Info about OPGUI", + NULL); +} +/// +///Append a message on the data tab; shorten the length of the entry field to MAXLINES +void PrintMessage(const char *msg){ + if(cmdline) return; //do not print anything if using command line mode + GtkTextIter iter,iter2; + gtk_text_buffer_get_end_iter(dataBuf,&iter); + gtk_text_buffer_insert(dataBuf,&iter,msg,-1); + gtk_text_buffer_get_start_iter(dataBuf,&iter2); + gtk_text_buffer_get_end_iter(dataBuf,&iter); + int l=gtk_text_buffer_get_line_count(dataBuf); + if(l>MAXLINES+10){ //MAXLINES + gtk_text_iter_set_line(&iter,l-MAXLINES); + gtk_text_buffer_delete(dataBuf,&iter2,&iter); + } + while (gtk_events_pending ()) gtk_main_iteration(); + gtk_text_buffer_get_end_iter(dataBuf,&iter); + gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(data),&iter,0.0,FALSE,0,0); +} +/// +///Print a message on the I2C data field +void PrintMessageI2C(const char *msg){ + GtkTextIter iter; + GtkTextBuffer * dataBuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(I2CDataReceive)); + gtk_text_buffer_set_text(dataBuf,msg,-1); + gtk_text_buffer_get_end_iter(dataBuf,&iter); + gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(I2CDataReceive),&iter,0.0,FALSE,0,0); + while (gtk_events_pending ()) gtk_main_iteration(); +} +/// +///Print a message on the "command" data field +void PrintMessageCMD(const char *msg){ + GtkTextIter iter; + GtkTextBuffer * dataBuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(commandTransfer)); + gtk_text_buffer_set_text(dataBuf,msg,-1); + gtk_text_buffer_get_end_iter(dataBuf,&iter); + gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(commandTransfer),&iter,0.0,FALSE,0,0); +} +/// +///Update option variables according to actual control values +void getOptions() +{ + vid=htoi(gtk_entry_get_text(GTK_ENTRY(VID_entry)),4); + pid=htoi(gtk_entry_get_text(GTK_ENTRY(PID_entry)),4); + saveLog = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b_log)); + ee = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(EEPROM_RW))?0xFFFF:0; + programID = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Write_ID_BKCal)); + max_err=atoi(gtk_entry_get_text(GTK_ENTRY(Errors_entry))); + load_calibword= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(WriteCalib12)); + load_osccal= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(UseOSCCAL)); + load_BKosccal= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(UseBKOSCCAL)); + ICDenable= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ICD_check)); + readRes= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ReadReserved)); + skipV33check=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b_V33check)); + waitS1=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b_WaitS1)); + int i=sscanf(gtk_entry_get_text(GTK_ENTRY(ICD_addr_entry)),"%x",&ICDaddr); + if(i!=1||ICDaddr<0||ICDaddr>0xFFFF) ICDaddr=0x1FF0; + char *str=0;//gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(devCombo)); + if(str) strncpy(dev,str,sizeof(dev)-1); + g_free(str); + AVRfuse=AVRfuse_h=AVRfuse_x=AVRlock=0x100; + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(AVR_FuseLowWrite))){ + i=sscanf(gtk_entry_get_text(GTK_ENTRY(AVR_FuseLow)),"%x",&AVRfuse); + if(i!=1||AVRfuse<0||AVRfuse>0xFF) AVRfuse=0x100; + } + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(AVR_FuseHighWrite))){ + i=sscanf(gtk_entry_get_text(GTK_ENTRY(AVR_FuseHigh)),"%x",&AVRfuse_h); + if(i!=1||AVRfuse_h<0||AVRfuse_h>0xFF) AVRfuse_h=0x100; + } + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(AVR_FuseExtWrite))){ + i=sscanf(gtk_entry_get_text(GTK_ENTRY(AVR_FuseExt)),"%x",&AVRfuse_x); + if(i!=1||AVRfuse_x<0||AVRfuse_x>0xFF) AVRfuse_x=0x100; + } + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(AVR_LockWrite))){ + i=sscanf(gtk_entry_get_text(GTK_ENTRY(AVR_Lock)),"%x",&AVRlock); + if(i!=1||AVRlock<0||AVRlock>0xFF) AVRlock=0x100; + } + str=malloc(128); + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ConfigForce))){ + int cw1,cw2,cw3,cw4,cw5,cw6,cw7; + cw1=cw2=cw3=cw4=cw5=cw6=cw7=0x10000; + i=sscanf(gtk_entry_get_text(GTK_ENTRY(CW1_entry)),"%x",&cw1); + i=sscanf(gtk_entry_get_text(GTK_ENTRY(CW2_entry)),"%x",&cw2); + i=sscanf(gtk_entry_get_text(GTK_ENTRY(CW3_entry)),"%x",&cw3); + i=sscanf(gtk_entry_get_text(GTK_ENTRY(CW4_entry)),"%x",&cw4); + i=sscanf(gtk_entry_get_text(GTK_ENTRY(CW5_entry)),"%x",&cw5); + i=sscanf(gtk_entry_get_text(GTK_ENTRY(CW6_entry)),"%x",&cw6); + i=sscanf(gtk_entry_get_text(GTK_ENTRY(CW7_entry)),"%x",&cw7); + if(devType==PIC16){ + if((!strncmp(dev,"16F1",4)||!strncmp(dev,"12F1",4))&&sizeW>0x8008){ //16F1xxx + if(cw1<=0x3FFF){ + memCODE_W[0x8007]=cw1; + PrintMessage3(strings[S_ForceConfigWx],1,0x8007,cw1); //"forcing config word%d [0x%04X]=0x%04X" + } + if(cw2<=0x3FFF){ + memCODE_W[0x8008]=cw2; + PrintMessage3(strings[S_ForceConfigWx],2,0x8008,cw2); //"forcing config word%d [0x%04X]=0x%04X" + } + } + else{ //16Fxxx + if(cw1<=0x3FFF&&sizeW>0x2007){ + memCODE_W[0x2007]=cw1; + PrintMessage3(strings[S_ForceConfigWx],1,0x2007,cw1); //"forcing config word%d [0x%04X]=0x%04X" + } + if(cw2<=0x3FFF&&sizeW>0x2008){ + memCODE_W[0x2008]=cw2; + printf("2\n"); + PrintMessage3(strings[S_ForceConfigWx],2,0x2008,cw2); //"forcing config word%d [0x%04X]=0x%04X" + } + } + } + else if(devType==PIC12){ //12Fxxx + if(cw1<=0xFFF&&sizeW>0xFFF){ + memCODE_W[0xFFF]=cw1; + PrintMessage3(strings[S_ForceConfigWx],1,0xFFF,cw1); //"forcing config word%d [0x%04X]=0x%04X" + } + } + else if(devType==PIC18){ //18Fxxx + if(cw1<=0xFFFF){ + memCONFIG[0]=cw1&0xFF; + memCONFIG[1]=(cw1>>8)&0xFF; + } + if(cw2<=0xFFFF){ + memCONFIG[2]=cw2&0xFF; + memCONFIG[3]=(cw2>>8)&0xFF; + } + if(cw3<=0xFFFF){ + memCONFIG[4]=cw3&0xFF; + memCONFIG[5]=(cw3>>8)&0xFF; + } + if(cw4<=0xFFFF){ + memCONFIG[6]=cw4&0xFF; + memCONFIG[7]=(cw4>>8)&0xFF; + } + if(cw5<=0xFFFF){ + memCONFIG[8]=cw5&0xFF; + memCONFIG[9]=(cw5>>8)&0xFF; + } + if(cw6<=0xFFFF){ + memCONFIG[10]=cw6&0xFF; + memCONFIG[11]=(cw6>>8)&0xFF; + } + if(cw7<=0xFFFF){ + memCONFIG[12]=cw7&0xFF; + memCONFIG[13]=(cw7>>8)&0xFF; + } + PrintMessage(strings[S_ForceConfigW]); //"forcing config words" + for(i=0;i<7;i++){ + PrintMessage2(strings[S_ConfigWordH],i+1,memCONFIG[i*2+1]); //"CONFIG%dH: 0x%02X\t" + PrintMessage2(strings[S_ConfigWordL],i+1,memCONFIG[i*2]); //"CONFIG%dL: 0x%02X\r\n" + } + } + } + free(str); +} +/// +///Check GUI for selected device and put in variable 'dev'. Also enable/disable R/W buttons +void GetSelectedDevice() { + GtkTreeModel *tmpModel; + GtkTreeIter tmpIter; + char *devName; + if (!GTK_IS_TREE_SELECTION(devSel)) { // Not initialised yet + return; + } + if (gtk_tree_selection_get_selected(devSel, &tmpModel, &tmpIter)) { + gtk_tree_model_get(tmpModel, &tmpIter, DEVICE_NAME_COLUMN, &devName, -1); + strcpy(dev,devName); + gtk_widget_set_sensitive(GTK_WIDGET(readBtn), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(writeBtn), TRUE); + g_free(devName); + } else { // Shouldn't ever happen, but just in case + dev[0] = '\0'; + gtk_widget_set_sensitive(GTK_WIDGET(readBtn), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(writeBtn), FALSE); + } +} +/// +///Choose a file to open and call Load() +void Fopen(GtkWidget *widget,GtkWidget *window) +{ + GetSelectedDevice(); + if(progress) return; + progress=1; + GtkFileChooser *dialog; + dialog = (GtkFileChooser*) gtk_file_chooser_dialog_new (strings[I_Fopen], //"Open File" + GTK_WINDOW(window), + GTK_FILE_CHOOSER_ACTION_OPEN, + strings[I_CANCEL], GTK_RESPONSE_CANCEL, + strings[I_OPEN], GTK_RESPONSE_ACCEPT, + NULL); + if(cur_path) gtk_file_chooser_set_current_folder(dialog,cur_path); + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT){ + char *filename; + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + if(cur_path) free(cur_path); + cur_path = gtk_file_chooser_get_current_folder(dialog); + Load(dev,filename); + g_free (filename); + if(!strncmp(dev,"AT",2)){ //load EEPROM from separate file for ATMEL chips + GtkFileChooser *dialog2; + dialog2 = (GtkFileChooser*) gtk_file_chooser_dialog_new (strings[S_openEEfile], + GTK_WINDOW(window), + GTK_FILE_CHOOSER_ACTION_OPEN, + strings[I_CANCEL],GTK_RESPONSE_CANCEL, + strings[I_OPEN],GTK_RESPONSE_ACCEPT, + NULL); + if(!cur_pathEE) cur_pathEE = gtk_file_chooser_get_current_folder(dialog); + if(cur_pathEE) gtk_file_chooser_set_current_folder(dialog2,cur_pathEE); + if (gtk_dialog_run (GTK_DIALOG (dialog2)) == GTK_RESPONSE_ACCEPT){ + char *filename2; + filename2 = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog2)); + if(cur_pathEE) free(cur_pathEE); + cur_pathEE = gtk_file_chooser_get_current_folder(dialog2); + LoadEE(dev,filename2); + g_free (filename2); + } + gtk_widget_destroy(GTK_WIDGET(dialog2)); + } + } + gtk_widget_destroy (GTK_WIDGET(dialog)); + progress=0; +} +/// +///Choose a file to save and call Save() +void Fsave(GtkWidget *widget,GtkWidget *window) +{ + if(progress) return; + progress=1; + GtkFileChooser *dialog; + dialog = (GtkFileChooser*) gtk_file_chooser_dialog_new (strings[I_Fsave], //"Save File", + GTK_WINDOW(window), + GTK_FILE_CHOOSER_ACTION_SAVE, + strings[I_CANCEL], GTK_RESPONSE_CANCEL, + strings[I_SAVE], GTK_RESPONSE_ACCEPT, + NULL); + if(cur_path) gtk_file_chooser_set_current_folder(dialog,cur_path); + gtk_file_chooser_set_do_overwrite_confirmation(dialog,TRUE); + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) + { + char *filename; + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + if(cur_path) free(cur_path); + cur_path = gtk_file_chooser_get_current_folder(dialog); + Save(dev,filename); + PrintMessage1(strings[S_FileSaved],filename); + g_free (filename); + if(!strncmp(dev,"AT",2)&&sizeEE){ //save EEPROM on separate file for ATMEL chips + GtkFileChooser *dialog2; + dialog2 = (GtkFileChooser*) gtk_file_chooser_dialog_new (strings[S_saveEEfile], + GTK_WINDOW(window), + GTK_FILE_CHOOSER_ACTION_SAVE, + strings[I_CANCEL], GTK_RESPONSE_CANCEL, + strings[I_SAVE], GTK_RESPONSE_ACCEPT, + NULL); + if(!cur_pathEE) cur_pathEE = gtk_file_chooser_get_current_folder(dialog); + if(cur_pathEE) gtk_file_chooser_set_current_folder(dialog2,cur_pathEE); + gtk_file_chooser_set_do_overwrite_confirmation(dialog2,TRUE); + if (gtk_dialog_run (GTK_DIALOG (dialog2)) == GTK_RESPONSE_ACCEPT){ + char *filename2; + filename2 = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog2)); + if(cur_pathEE) free(cur_pathEE); + cur_pathEE = gtk_file_chooser_get_current_folder(dialog2); + SaveEE(dev,filename2); + PrintMessage1(strings[S_FileSaved],filename2); + g_free (filename2); + } + gtk_widget_destroy(GTK_WIDGET(dialog2)); + } + } + gtk_widget_destroy (GTK_WIDGET(dialog)); + progress=0; +} +/// +///Select data tab +void selectDataTab() { gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0); } +/// +///Call device write function +void DevWrite(GtkWidget *widget,GtkWidget *window) +{ +#ifndef DEBUG + if(DeviceDetected!=1) return; +#endif + selectDataTab(); + gtk_statusbar_push(GTK_STATUSBAR(status_bar),statusID,""); + RWstop=0; + getOptions(); + if(!waitingS1&&waitS1){ + waitingS1=1; + int i,S1=0; + PrintMessage(strings[I_PRESSS1]); //"press S1 to start" + for(i=0;!S1&&waitS1&&waitingS1;i++){ + S1=CheckS1(); + msDelay(50); + PrintMessage("."); + if(i%64==63) PrintMessage(strings[S_NL]); //"\n" + while (gtk_events_pending ()) gtk_main_iteration(); //handle UI events, including write button + msDelay(50); + } + PrintMessage(strings[S_NL]); //"\n" + if(!progress&&S1){ + gtk_widget_set_sensitive(stopBtn,TRUE); + progress=1; + Write(dev,ee); //choose the right function + progress=0; + gtk_widget_set_sensitive(stopBtn,FALSE); + } + waitingS1=0; + } + else if(waitingS1) waitingS1=0; + else if(!progress){ + gtk_widget_set_sensitive(stopBtn,TRUE); + progress=1; + Write(dev,ee); //choose the right function + progress=0; + gtk_widget_set_sensitive(stopBtn,FALSE); + } +} +/// +///Call device read function +void DevRead(GtkWidget *widget,GtkWidget *window) +{ +#ifndef DEBUG + if(DeviceDetected!=1) return; +#endif + selectDataTab(); + gtk_statusbar_push(GTK_STATUSBAR(status_bar),statusID,""); + getOptions(); + RWstop=0; + if(!waitingS1&&waitS1){ + waitingS1=1; + int i,S1=0; + PrintMessage(strings[I_PRESSS1]); //"press S1 to start" + for(i=0;!S1&&waitS1&&waitingS1;i++){ + S1=CheckS1(); + msDelay(50); + PrintMessage("."); + if(i%64==63) PrintMessage(strings[S_NL]); //"\n" + while (gtk_events_pending ()) gtk_main_iteration(); //handle UI events, including write button + msDelay(50); + } + PrintMessage(strings[S_NL]); //"\n" + if(!progress&&S1){ + gtk_widget_set_sensitive(stopBtn,TRUE); + progress=1; + Read(dev,ee,readRes); //choose the right function + progress=0; + gtk_widget_set_sensitive(stopBtn,FALSE); + } + waitingS1=0; + } + else if(waitingS1) waitingS1=0; + else if(!progress){ + gtk_widget_set_sensitive(stopBtn,TRUE); + progress=1; + Read(dev,ee,readRes); //choose the right function + progress=0; + gtk_widget_set_sensitive(stopBtn,FALSE); + } +} +/// +/// Write fuse low byte at low frequency +void WriteATfuseLowLF(GtkWidget *widget,GtkWidget *window){ +#ifndef DEBUG + if(DeviceDetected!=1) return; +#endif + if(progress) return; + getOptions(); + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(AVR_FuseLowWrite))){ + progress=1; + if(AVRfuse<0x100) WriteATfuseSlow(AVRfuse); + progress=0; + } +} +/// +///Callback function to set available options for each device type +void onDevSel_Changed(GtkWidget *widget,GtkWidget *window) +{ + struct DevInfo info; + char str2[256],str3[64],strF[32]; + double x; + GetSelectedDevice(); + if (strlen(dev) == 0) return; // None selected + info=GetDevInfo(dev); + sprintf(str, "%s: %s", strings[I_Dev], dev); + gtk_label_set_markup(GTK_LABEL(devFrame), str); + devType=info.family; + gtk_label_set_text(GTK_LABEL(devinfo),info.features); + if(devType==PIC12||devType==PIC16||devType==PIC18||devType==PIC24){ + gtk_widget_show_all(GTK_WIDGET(devFramePIC)); + gtk_widget_hide(GTK_WIDGET(devFrameAVR)); + gtk_widget_show_all(GTK_WIDGET(EEPROM_RW)); + } + else if(devType==AVR){ //ATMEL + gtk_widget_hide(GTK_WIDGET(devFramePIC)); + gtk_widget_show_all(GTK_WIDGET(devFrameAVR)); + gtk_widget_show_all(GTK_WIDGET(EEPROM_RW)); + } + else{ + gtk_widget_hide(GTK_WIDGET(devFramePIC)); + gtk_widget_hide(GTK_WIDGET(devFrameAVR)); + gtk_widget_hide(GTK_WIDGET(EEPROM_RW)); + } + if(devType==PIC16) //ICD + gtk_widget_show_all(GTK_WIDGET(devFrameICD)); + else gtk_widget_hide(GTK_WIDGET(devFrameICD)); + if(devType==PIC12||devType==PIC16) //Osc options + gtk_widget_show_all(GTK_WIDGET(devFrameOsc)); + else gtk_widget_hide(GTK_WIDGET(devFrameOsc)); + if(devType==PIC12||devType==PIC16||devType==PIC18) //program ID + gtk_widget_show_all(GTK_WIDGET(Write_ID_BKCal)); + else gtk_widget_hide(GTK_WIDGET(Write_ID_BKCal)); + if(devType==PIC16) //Program Calib + gtk_widget_show_all(GTK_WIDGET(WriteCalib12)); + else gtk_widget_hide(GTK_WIDGET(WriteCalib12)); + if(devType==PIC12||devType==PIC16||devType==PIC18){ //Force config + gtk_widget_show_all(GTK_WIDGET(devFrameConfigW)); + gtk_widget_hide(GTK_WIDGET(devPIC_CW2)); + gtk_widget_hide(GTK_WIDGET(devPIC_CW3)); + gtk_widget_hide(GTK_WIDGET(devPIC_CW4)); + gtk_widget_hide(GTK_WIDGET(devPIC_CW5)); + gtk_widget_hide(GTK_WIDGET(devPIC_CW6)); + gtk_widget_hide(GTK_WIDGET(devPIC_CW7)); + gtk_widget_hide(GTK_WIDGET(devPIC_CW8)); + if(devType==PIC16){ + gtk_widget_show_all(GTK_WIDGET(devPIC_CW2)); + } + else if(devType==PIC18){ + gtk_widget_show_all(GTK_WIDGET(devPIC_CW2)); + gtk_widget_show_all(GTK_WIDGET(devPIC_CW3)); + gtk_widget_show_all(GTK_WIDGET(devPIC_CW4)); + gtk_widget_show_all(GTK_WIDGET(devPIC_CW5)); + gtk_widget_show_all(GTK_WIDGET(devPIC_CW6)); + gtk_widget_show_all(GTK_WIDGET(devPIC_CW7)); + gtk_widget_show_all(GTK_WIDGET(devPIC_CW8)); + } + } + else{ + gtk_widget_hide(GTK_WIDGET(devFrameConfigW)); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ConfigForce),FALSE); + } + gtk_statusbar_push(GTK_STATUSBAR(status_bar),statusID,dev); +} +/// Walk the TreeModel until we find an entry with the passed device name +/// Select that entry and then stop walking +gboolean selectDev_ForeachFunc(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, char *devNameToSelect) { + char *thisEntryDevName; + gtk_tree_model_get(model, iter, DEVICE_NAME_COLUMN, &thisEntryDevName, -1); + int matched = (strcmp(thisEntryDevName, devNameToSelect) == 0); + if (matched) gtk_tree_selection_select_iter(devSel, iter); + g_free(thisEntryDevName); + return matched; +} +/// +/// Comparison function used when sorting the device tree +int sortIterCompareFunc(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer userdata) { + enum sort_type_t sortcol = GPOINTER_TO_INT(userdata); + int ret = 0; + enum sort_data_type_t sortDataType; + int dataCol; + switch (sortcol) { + case SORT_STRING_NAME: + sortDataType = SDT_STRING; + dataCol = DEVICE_NAME_COLUMN; + break; + case SORT_STRING_GROUP: + sortDataType = SDT_STRING; + dataCol = DEVICE_GROUP_COLUMN; + break; + default: + return 0; + } + switch (sortDataType) { + case SDT_STRING: + { + char *nameA, *nameB; + gtk_tree_model_get(model, a, dataCol, &nameA, -1); + gtk_tree_model_get(model, b, dataCol, &nameB, -1); + if (nameA == NULL || nameB == NULL) { + if (nameA == NULL && nameB == NULL) break; // Both null. return 0 (no need to free) + ret = (nameA == NULL) ? -1 : 1; + } + else { + ret = g_utf8_collate(nameA,nameB); + } + g_free(nameA); + g_free(nameB); + break; + } + default: + g_return_val_if_reached(0); + } + return ret; +} +/// +///Add devices to the device ListStore (which may not have been created) +///groupFilter: add devices in this group (-1 for all) +///textFilter: only add devices containing this string (NULL for all) +void AddDevices(enum group_t groupFilter, const char *textFilter) { + if (GTK_IS_TREE_SELECTION(devSel)) + g_signal_handlers_disconnect_by_func(G_OBJECT(devSel),G_CALLBACK(onDevSel_Changed),NULL); + if (!GTK_IS_LIST_STORE(devStore)) { + devStore = gtk_list_store_new (DEVICE_N_COLUMNS, + G_TYPE_UINT, + G_TYPE_STRING, + G_TYPE_STRING); + gtk_tree_view_set_model(GTK_TREE_VIEW(devTree), GTK_TREE_MODEL(devStore)); + gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(devStore), SORT_STRING_NAME, + sortIterCompareFunc, GINT_TO_POINTER(SORT_STRING_NAME), NULL); + gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(devStore), SORT_STRING_GROUP, + sortIterCompareFunc, GINT_TO_POINTER(SORT_STRING_GROUP), NULL); + gtk_tree_view_column_set_sort_column_id( + gtk_tree_view_get_column(GTK_TREE_VIEW(devTree), 0), SORT_STRING_NAME); + gtk_tree_view_column_set_sort_column_id( + gtk_tree_view_get_column(GTK_TREE_VIEW(devTree), 1), SORT_STRING_GROUP); + g_object_unref (G_OBJECT(devStore)); + } + else gtk_list_store_clear(devStore); + int i,j=0; + char *devices=0,*tok; + for(i=0;i0){ + if(hex[0]==':'&&strlen(hex)>8){ + length=htoi(hex+1,2); + address=htoi(hex+3,4); + if(strlen(hex)<11+length*2) gtk_entry_set_text(GTK_ENTRY(Hex_data),"__line too short"); + else{ + for (i=1;i<=length*2+9;i+=2) sum += htoi(hex+i,2); + if ((sum & 0xff)!=0){ + sprintf(str,"__checksum error, expected 0x%02X",(-sum+htoi(hex+9+length*2,2))&0xFF); + gtk_entry_set_text(GTK_ENTRY(Hex_data),str); + } + else{ + switch(htoi(hex+7,2)){ + case 0: //Data record + sprintf(str,"address: 0x%04X ",address); + if(i&&length) strcat(str,"data: 0x"); + for (i=0;i14){ + sprintf(str,"extended linear address = %04X",htoi(hex+9,4)); + gtk_entry_set_text(GTK_ENTRY(Hex_data),str); + } + break; + default: + gtk_entry_set_text(GTK_ENTRY(Hex_data),"__unknown record type"); + break; + } + } + } + } + else gtk_entry_set_text(GTK_ENTRY(Hex_data),"__invalid line"); + } + else gtk_entry_set_text(GTK_ENTRY(Hex_entry),""); +} +/// +/// convert address & data to hex line +void DataToHexConvert(GtkWidget *widget,GtkWidget *window) +{ + char hex[256],str[256],s2[32]; + int i,address,length,sum=0,x; + i=sscanf(gtk_entry_get_text(GTK_ENTRY(Address_entry)),"%x",&address); + if(i!=1) address=0; + strncpy(hex,(const char *)gtk_entry_get_text(GTK_ENTRY(Data_entry)),sizeof(hex)); + length=strlen(hex); + length&=0xFF; + if(length>0){ + sprintf(str,":--%04X00",address&0xFFFF); + for(i=0;i+1>8)&0xff); + sprintf(s2,"%02X",(-sum)&0xFF); + strcat(str,s2); + gtk_entry_set_text(GTK_ENTRY(Hex_data2),str); + } +} +/// +///Choose a file to save a hex line +void HexSave(GtkWidget *widget,GtkWidget *window) +{ + GtkFileChooser *dialog; + if(strlen((const char *)gtk_entry_get_text(GTK_ENTRY(Hex_data2)))<11) return; + dialog = (GtkFileChooser*) gtk_file_chooser_dialog_new (strings[I_Fsave], //"Save File", + GTK_WINDOW(window), + GTK_FILE_CHOOSER_ACTION_SAVE, + strings[I_CANCEL], GTK_RESPONSE_CANCEL, + strings[I_SAVE], GTK_RESPONSE_ACCEPT, + NULL); + if(cur_path) gtk_file_chooser_set_current_folder(dialog,cur_path); + gtk_file_chooser_set_do_overwrite_confirmation(dialog,TRUE); + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) + { + char *filename; + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + if(cur_path) free(cur_path); + cur_path = gtk_file_chooser_get_current_folder(dialog); + FILE* f=fopen(filename,"w"); + if(f){ + fprintf(f,(const char *)gtk_entry_get_text(GTK_ENTRY(Hex_data2))); + fclose(f); + } + g_free (filename); + } + gtk_widget_destroy (GTK_WIDGET(dialog)); +} +/// +/// Stop read or write +void Stop(GtkWidget *widget,GtkWidget *window) +{ +#ifndef DEBUG + if(DeviceDetected!=1) return; +#endif + if(progress==1&&RWstop==0){ + RWstop=1; + PrintMessage(strings[I_STOP]); + } +} +/// +///Close program +void Xclose(){ +// char *str=gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(devCombo)); +// if(str) strncpy(dev,str,sizeof(dev)-1); + gtk_main_quit(); +} +/// +/// Show a message box +void MsgBox(const char* msg) +{ + GtkWidget * dialog = gtk_message_dialog_new (GTK_WINDOW(window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + msg); + gtk_window_set_title(GTK_WINDOW(dialog)," "); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); +} +/// +/// Find the programmer and setup communication +void Connect(GtkWidget *widget,GtkWidget *window){ + vid=htoi(gtk_entry_get_text(GTK_ENTRY(VID_entry)),4); + pid=htoi(gtk_entry_get_text(GTK_ENTRY(PID_entry)),4); + DeviceDetected=FindDevice(vid,pid); //connect to USB programmer + if(!DeviceDetected){ + DeviceDetected=FindDevice(new_vid,new_pid); //try default + if(DeviceDetected){ + vid=new_vid; + pid=new_pid; + } + } + if(!DeviceDetected) DeviceDetected=FindDevice(old_vid,old_pid); //try old one + hvreg=0; + ProgID(); +} +/// +/// I2C/SPI receive +void I2cspiR() +{ + //if(DeviceDetected!=1) return; + gtk_statusbar_push(GTK_STATUSBAR(status_bar),statusID,""); + saveLog = (int) gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b_log)); + int nbyte=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(I2CNbyte)); + if(nbyte<0) nbyte=0; + if(nbyte>60) nbyte=60; + int mode=0; + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(I2C16bit))) mode=1; //I2C mode + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(SPI00))) mode=2; //SPI mode 00 + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(SPI01))) mode=3; //SPI mode 01 + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(SPI10))) mode=4; //SPI mode 10 + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(SPI11))) mode=5; //SPI mode 11 + char* tok; + char tokbuf[512]; + BYTE tmpbuf[128]; + int i=0,x; + strncpy(tokbuf, (const char *)gtk_entry_get_text(GTK_ENTRY(I2CDataSend)), sizeof(tokbuf)); + for(tok=strtok(tokbuf," ");tok&&i<128;tok=strtok(NULL," ")){ + if(sscanf(tok,"%x",&x)){ + tmpbuf[i] = (BYTE)x; + i++; + } + } + for(;i<128;i++) tmpbuf[i]=0; + I2CReceive(mode,gtk_combo_box_get_active(GTK_COMBO_BOX(I2CSpeed)),nbyte,tmpbuf); +} +/// +/// I2C/SPI send +void I2cspiS() +{ + //if(DeviceDetected!=1) return; + gtk_statusbar_push(GTK_STATUSBAR(status_bar),statusID,""); + saveLog = (int) gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b_log)); + int nbyte=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(I2CNbyte)); + if(nbyte<0) nbyte=0; + if(nbyte>57) nbyte=57; + int mode=0; + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(I2C16bit))) mode=1; //I2C mode + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(SPI00))) mode=2; //SPI mode 00 + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(SPI01))) mode=3; //SPI mode 01 + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(SPI10))) mode=4; //SPI mode 10 + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(SPI11))) mode=5; //SPI mode 11 + char* tok; + char tokbuf[512]; + BYTE tmpbuf[128]; + int i=0,x; + strncpy(tokbuf, (const char *)gtk_entry_get_text(GTK_ENTRY(I2CDataSend)), sizeof(tokbuf)); + for(tok=strtok(tokbuf," ");tok&&i<128;tok=strtok(NULL," ")){ + if(sscanf(tok,"%x",&x)){ + tmpbuf[i] = (BYTE)x; + i++; + } + } + for(;i<128;i++) tmpbuf[i]=0; + I2CSend(mode,gtk_combo_box_get_active(GTK_COMBO_BOX(I2CSpeed)),nbyte,tmpbuf); +} +/// +/// send manual command +void CommandIO() +{ + if(DeviceDetected!=1) return; + gtk_statusbar_push(GTK_STATUSBAR(status_bar),statusID,""); + saveLog = (int) gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b_log)); + char* tok; + char tokbuf[512],str[16]; + int i=0,x; + strncpy(tokbuf, (const char *)gtk_entry_get_text(GTK_ENTRY(commandSend)), sizeof(tokbuf)); + for(tok=strtok(tokbuf," ");tok&&i["); + for(i=0;i7000?7000:sizeEE; + for(i=0;i500){ //limit number of lines printed + strcat(aux,"(...)\r\n"); + i=max-COL*2; + lines=490; + } + } + s[0]=0; + v[0]=0; + } + if(empty) PrintMessage(strings[S_Empty]); //empty + else{ + PrintMessage(aux); + if(sizeEE>max) PrintMessage("(...)\r\n"); + } + free(aux); +} +/// +///Start HV regulator +int StartHVReg(double V){ + int j=0,z; + int vreg=(int)(V*10.0); + if(saveLog&&logfile) fprintf(logfile,"StartHVReg(%.2f)\n",V); + DWORD t0,t; + if(V==-1){ + bufferU[j++]=VREG_DIS; //disable HV regulator + bufferU[j++]=FLUSH; + PacketIO(5); + msDelay(40); + return -1; + } + t=t0=GetTickCount(); + bufferU[j++]=VREG_EN; //enable HV regulator + bufferU[j++]=SET_VPP; + bufferU[j++]=vreg; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=2000>>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=WAIT_T3; + bufferU[j++]=READ_ADC; + bufferU[j++]=FLUSH; + for(;j(vreg/10.0+1)*G)&&t>=2; //if 12 bit ADC +// PrintMessage2("v=%d=%fV\n",v,v/G); + } + if(v>(vreg/10.0+1)*G){ + PrintMessage(strings[S_HiVPP]); //"Attenzione: tensione regolatore troppo alta\r\n\r\n" + return 0; + } + else if(v<(vreg/10.0-1)*G){ + PrintMessage(strings[S_LowVPP]); //"Attenzione: tensione regolatore troppo bassa\r\n\r\n" + return 0; + } + else if(v==0){ + PrintMessage(strings[S_lowUsbV]); //"Tensione USB troppo bassa (VUSB<4.5V)\r\n" + return 0; + } + else{ + PrintMessage2(strings[S_reg],t-t0,v/G); //"Regolatore avviato e funzionante dopo T=%d ms VPP=%.1f\r\n\r\n" + if(saveLog&&logfile) fprintf(logfile,strings[S_reg],t-t0,v/G); + return vreg; + } +} +/// +///Read programmer ID +void ProgID() +{ + if(DeviceDetected!=1) return; + int j=0; + bufferU[j++]=PROG_RST; + bufferU[j++]=FLUSH; + for(;j E3=1 +} +/// +///Execute hardware test +void TestHw(GtkWidget *widget,GtkWindow* parent) +{ +#ifndef DEBUG + if(DeviceDetected!=1) return; +#endif + char str[256]; + StartHVReg(13); + int j=0; + MsgBox(strings[I_TestHW]); //"Test hardware ..." + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=FLUSH; + for(;j=0x900){ //IO test + int j=0,i,x,r; + strcpy(str,"0000000000000"); + PrintMessage("IO test\nRC|RA|--RB--|\n"); + for(i=0;i<13;i++){ + x=1<>5)&0xFF; //PORTA-C + bufferU[j++]=READ_B; + bufferU[j++]=READ_AC; + bufferU[j++]=FLUSH; + for(;jMinDly?x:MinDly); +#else +// Sleep((long)ceil(delay)>MinDly?(long)ceil(delay):MinDly); + __int64 stop,freq,timeout; + QueryPerformanceCounter((LARGE_INTEGER *)&stop); + QueryPerformanceFrequency((LARGE_INTEGER *)&freq); + timeout=stop+delay*freq/1000.0; + while(stop0) strcpy(dev,temp); + else if(sscanf(line,"vid %X",&X)>0) vid=X; + else if(sscanf(line,"pid %X",&X)>0) pid=X; + else sscanf(line,"maxerr %d",&max_err); + } + fclose(f); + } + } + char dev_ini[64]; + strncpy(dev_ini,dev,sizeof(dev_ini)); + int vid_ini=vid,pid_ini=pid,max_err_ini=max_err; + vid_ini=vid; + pid_ini=pid; + max_err_ini=max_err; +#if defined _WIN32 || defined __CYGWIN__ //Windows + bufferI=bufferI0+1; + bufferU=bufferU0+1; + bufferI0[0]=0; + bufferU0[0]=0; +#endif + gtk_init(&argc, &argv); + unsigned int tmpbuf[128]; + opterr = 0; + int option_index = 0; + int help=0,command=0,i,j; + char c; + struct option long_options[] = + { + {"?", no_argument, &help, 1}, + {"h", no_argument, &help, 1}, + {"help", no_argument, &help, 1}, + {"c", no_argument, &command, 1}, + {"command", no_argument, &command, 1}, + {"lang", required_argument, 0, 'l'}, + {"langfile", no_argument, &langfile, 1}, + {0, 0, 0, 0} + }; + while ((j = getopt_long_only (argc, argv, "",long_options,&option_index)) != -1){ + if(j=='l'){ //language + strncpy(lang,optarg,sizeof(lang)-1); + } + } + for(j=0,i = optind; i < argc&&i<128; i++,j++) sscanf(argv[i], "%x", &tmpbuf[j]); + for(;j<128;j++) tmpbuf[j]=0; + strinit(); + char* langid=0; + i=0; + if(lang[0]){ //explicit language selection + if(lang[0]=='i'&&langid[1]=='t'){ //built-in + strings=strings_it; + i=1; + } + else if(lang[0]=='e'&&lang[1]=='n'){ //built-in + strings=strings_en; + i=1; + } + else i=strfind(lang,"languages.rc"); //file look-up + } + if(i==0){ + #if defined _WIN32 + langid=malloc(19); + int n=GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SISO639LANGNAME,langid,9); + langid[n-1] = '-'; + GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SISO3166CTRYNAME,langid+n, 9); + //printf("%d >%s<\n",n,langid); + #else + langid=getenv("LANG"); + #endif + if(langid){ + if(langid[0]=='i'&&langid[1]=='t') strings=strings_it; + else if(langid[0]=='e'&&langid[1]=='n') strings=strings_en; + else if(strfind(langid,"languages.rc")); //first try full code + else { //then only first language code + char* p=strchr(langid,'-'); + if(p) *p=0; + if(!strfind(langid,"languages.rc")) strings=strings_en; + } + } + else strings=strings_en; + } + if(langfile) GenerateLangFile(langid,"languages.rc"); + if(help){ + printf(strings[I_GUI_CMD_HELP]); + exit(0); + } + if(command){ + cmdline=1; + DeviceDetected=FindDevice(vid,pid); //connect to USB programmer + if(!DeviceDetected){ + DeviceDetected=FindDevice(new_vid,new_pid); //try default + if(DeviceDetected){ + vid=new_vid; + pid=new_pid; + } + } + if(!DeviceDetected) DeviceDetected=FindDevice(old_vid,old_pid); //try old one + if(DeviceDetected){ + bufferU[0]=0; + for(i=1;i "); + for(i=1;i0) { + struct DevInfo info = GetDevInfo(dev); + gtk_combo_box_set_active_id(GTK_COMBO_BOX(devTypeCombo), groupNames[info.group]); + } + else { + gtk_combo_box_set_active_id(GTK_COMBO_BOX(devTypeCombo), GROUP_ALL); + } + DeviceDetected=FindDevice(vid,pid); //connect to USB programmer + if(!DeviceDetected){ + DeviceDetected=FindDevice(new_vid,new_pid); //try default + if(DeviceDetected){ + vid=new_vid; + pid=new_pid; + } + } + if(!DeviceDetected) DeviceDetected=FindDevice(old_vid,old_pid); //try old one + ProgID(); //get firmware version and reset + gtk_main(); +// printf(ListDevices()); +//******Save ini file****** +// only if parameters are changed + if(strcmp(dev_ini,dev)||vid_ini!=vid||pid_ini!=pid||max_err_ini!=max_err){ + if(homedir){ + f=fopen(fname,"w"); + if(f){ + fprintf(f,"device %s\n",dev); + fprintf(f,"maxerr %d\n",max_err); + fprintf(f,"vid %X\n",vid); + fprintf(f,"pid %X\n",pid); + } + fclose(f); + } + } + return 0; +} + +/// +///Find the USB peripheral with proper vid&pid code +/// return 0 if not found +int FindDevice(int vid,int pid){ + int MyDeviceDetected = FALSE; +#if !defined _WIN32 && !defined __CYGWIN__ //Linux + #ifndef hiddevIO //use raw USB device + struct hidraw_devinfo device_info; + int i=-1; + if(path[0]==0){ //search all devices + if((fd = open("/dev/openprogrammer", O_RDWR|O_NONBLOCK))>0){ //try with this first + sprintf(path,"/dev/openprogrammer"); + ioctl(fd, HIDIOCGRAWINFO, &device_info); + if(device_info.vendor==vid&&device_info.product==pid) i=0; + else{ + close(fd); + i=-1; + } + } + if(i){ + for(i=0;i<16;i++){ + sprintf(path,"/dev/hidraw%d",i); + if((fd = open(path, O_RDWR|O_NONBLOCK))>0){ + ioctl(fd, HIDIOCGRAWINFO, &device_info); + if(device_info.vendor==vid&&device_info.product==pid) break; + else close(fd); + } + } + } + if(i==16){ + PrintMessage(strings[S_noprog]); + path[0]=0; + return 0; + } + } + else{ //user supplied path + if((fd = open(path, O_RDWR|O_NONBLOCK)) < 0) { + PrintMessage1(strings[S_DevPermission],path); //"cannot open %s, make sure you have read permission on it",path); + return 0; + } + ioctl(fd, HIDIOCGRAWINFO, &device_info); + if(device_info.vendor!=vid||device_info.product!=pid){ + PrintMessage(strings[S_noprog]); + return 0; + } + } + printf(strings[S_progDev],path); + return 1; + #else //use hiddev device (old method) + struct hiddev_devinfo device_info; + int i=-1; + if(path[0]==0){ //search all devices + if((fd = open("/dev/openprogrammer", O_RDONLY ))>0){ //try with this first + ioctl(fd, HIDIOCGDEVINFO, &device_info); + if(device_info.vendor==vid&&device_info.product==pid) i=0; + else{ + close(fd); + i=-1; + } + } + if(i){ + for(i=0;i<16;i++){ + sprintf(path,"/dev/usb/hiddev%d",i); + if((fd = open(path, O_RDONLY ))>0){ + ioctl(fd, HIDIOCGDEVINFO, &device_info); + if(device_info.vendor==vid&&device_info.product==pid) break; + else close(fd); + } + } + } + if(i==16){ + PrintMessage(strings[S_noprog]); + path[0]=0; + return 0; + } + } + else{ //user supplied path + if ((fd = open(path, O_RDONLY )) < 0) { + PrintMessage1(strings[S_DevPermission],path); //"cannot open %s, make sure you have read permission on it",path); + return 0; + } + ioctl(fd, HIDIOCGDEVINFO, &device_info); + if(device_info.vendor!=vid||device_info.product!=pid){ + PrintMessage(strings[S_noprog]); + return 0; + } + } + MyDeviceDetected = TRUE; + rep_info_u.report_type=HID_REPORT_TYPE_OUTPUT; + rep_info_i.report_type=HID_REPORT_TYPE_INPUT; + rep_info_u.report_id=rep_info_i.report_id=HID_REPORT_ID_FIRST; + rep_info_u.num_fields=rep_info_i.num_fields=1; + ref_multi_u.uref.report_type=HID_REPORT_TYPE_OUTPUT; + ref_multi_i.uref.report_type=HID_REPORT_TYPE_INPUT; + ref_multi_u.uref.report_id=ref_multi_i.uref.report_id=HID_REPORT_ID_FIRST; + ref_multi_u.uref.field_index=ref_multi_i.uref.field_index=0; + ref_multi_u.uref.usage_index=ref_multi_i.uref.usage_index=0; + ref_multi_u.num_values=ref_multi_i.num_values=DIMBUF; + #endif +#else //Windows + PSP_DEVICE_INTERFACE_DETAIL_DATA detailData; + HANDLE DeviceHandle; + HANDLE hDevInfo; + GUID HidGuid; + char MyDevicePathName[1024]; + ULONG Length; + ULONG Required; + typedef struct _HIDD_ATTRIBUTES { + ULONG Size; + USHORT VendorID; + USHORT ProductID; + USHORT VersionNumber; + } HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES; + typedef void (__stdcall*GETHIDGUID) (OUT LPGUID HidGuid); + typedef BOOLEAN (__stdcall*GETATTRIBUTES)(IN HANDLE HidDeviceObject,OUT PHIDD_ATTRIBUTES Attributes); + typedef BOOLEAN (__stdcall*SETNUMINPUTBUFFERS)(IN HANDLE HidDeviceObject,OUT ULONG NumberBuffers); + typedef BOOLEAN (__stdcall*GETNUMINPUTBUFFERS)(IN HANDLE HidDeviceObject,OUT PULONG NumberBuffers); + typedef BOOLEAN (__stdcall*GETFEATURE) (IN HANDLE HidDeviceObject, OUT PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*SETFEATURE) (IN HANDLE HidDeviceObject, IN PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*GETREPORT) (IN HANDLE HidDeviceObject, OUT PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*SETREPORT) (IN HANDLE HidDeviceObject, IN PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*GETMANUFACTURERSTRING) (IN HANDLE HidDeviceObject, OUT PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*GETPRODUCTSTRING) (IN HANDLE HidDeviceObject, OUT PVOID ReportBuffer, IN ULONG ReportBufferLength); + typedef BOOLEAN (__stdcall*GETINDEXEDSTRING) (IN HANDLE HidDeviceObject, IN ULONG StringIndex, OUT PVOID ReportBuffer, IN ULONG ReportBufferLength); + HIDD_ATTRIBUTES Attributes; + SP_DEVICE_INTERFACE_DATA devInfoData; + int LastDevice = FALSE; + int MemberIndex = 0; + LONG Result; + Length=0; + detailData=NULL; + DeviceHandle=NULL; + HMODULE hHID=0; + GETHIDGUID HidD_GetHidGuid=0; + GETATTRIBUTES HidD_GetAttributes=0; + SETNUMINPUTBUFFERS HidD_SetNumInputBuffers=0; + GETNUMINPUTBUFFERS HidD_GetNumInputBuffers=0; + GETFEATURE HidD_GetFeature=0; + SETFEATURE HidD_SetFeature=0; + GETREPORT HidD_GetInputReport=0; + SETREPORT HidD_SetOutputReport=0; + GETMANUFACTURERSTRING HidD_GetManufacturerString=0; + GETPRODUCTSTRING HidD_GetProductString=0; + hHID = LoadLibrary("hid.dll"); + if(!hHID){ + PrintMessage("Can't find hid.dll"); + return 0; + } + HidD_GetHidGuid=(GETHIDGUID)GetProcAddress(hHID,"HidD_GetHidGuid"); + HidD_GetAttributes=(GETATTRIBUTES)GetProcAddress(hHID,"HidD_GetAttributes"); + HidD_SetNumInputBuffers=(SETNUMINPUTBUFFERS)GetProcAddress(hHID,"HidD_SetNumInputBuffers"); + HidD_GetNumInputBuffers=(GETNUMINPUTBUFFERS)GetProcAddress(hHID,"HidD_GetNumInputBuffers"); + HidD_GetFeature=(GETFEATURE)GetProcAddress(hHID,"HidD_GetFeature"); + HidD_SetFeature=(SETFEATURE)GetProcAddress(hHID,"HidD_SetFeature"); + HidD_GetInputReport=(GETREPORT)GetProcAddress(hHID,"HidD_GetInputReport"); + HidD_SetOutputReport=(SETREPORT)GetProcAddress(hHID,"HidD_SetOutputReport"); + HidD_GetManufacturerString=(GETMANUFACTURERSTRING)GetProcAddress(hHID,"HidD_GetManufacturerString"); + HidD_GetProductString=(GETPRODUCTSTRING)GetProcAddress(hHID,"HidD_GetProductString"); + if(HidD_GetHidGuid==NULL\ + ||HidD_GetAttributes==NULL\ + ||HidD_GetFeature==NULL\ + ||HidD_SetFeature==NULL\ + ||HidD_GetInputReport==NULL\ + ||HidD_SetOutputReport==NULL\ + ||HidD_GetManufacturerString==NULL\ + ||HidD_GetProductString==NULL\ + ||HidD_SetNumInputBuffers==NULL\ + ||HidD_GetNumInputBuffers==NULL) return 0; + HMODULE hSAPI=0; + hSAPI = LoadLibrary("setupapi.dll"); + if(!hSAPI){ + PrintMessage("Can't find setupapi.dll"); + return 0; + } + typedef HDEVINFO (WINAPI* SETUPDIGETCLASSDEVS) (CONST GUID*,PCSTR,HWND,DWORD); + typedef BOOL (WINAPI* SETUPDIENUMDEVICEINTERFACES) (HDEVINFO,PSP_DEVINFO_DATA,CONST GUID*,DWORD,PSP_DEVICE_INTERFACE_DATA); + typedef BOOL (WINAPI* SETUPDIGETDEVICEINTERFACEDETAIL) (HDEVINFO,PSP_DEVICE_INTERFACE_DATA,PSP_DEVICE_INTERFACE_DETAIL_DATA_A,DWORD,PDWORD,PSP_DEVINFO_DATA); + typedef BOOL (WINAPI* SETUPDIDESTROYDEVICEINFOLIST) (HDEVINFO); + SETUPDIGETCLASSDEVS SetupDiGetClassDevsA=0; + SETUPDIENUMDEVICEINTERFACES SetupDiEnumDeviceInterfaces=0; + SETUPDIGETDEVICEINTERFACEDETAIL SetupDiGetDeviceInterfaceDetailA=0; + SETUPDIDESTROYDEVICEINFOLIST SetupDiDestroyDeviceInfoList=0; + SetupDiGetClassDevsA=(SETUPDIGETCLASSDEVS) GetProcAddress(hSAPI,"SetupDiGetClassDevsA"); + SetupDiEnumDeviceInterfaces=(SETUPDIENUMDEVICEINTERFACES) GetProcAddress(hSAPI,"SetupDiEnumDeviceInterfaces"); + SetupDiGetDeviceInterfaceDetailA=(SETUPDIGETDEVICEINTERFACEDETAIL) GetProcAddress(hSAPI,"SetupDiGetDeviceInterfaceDetailA"); + SetupDiDestroyDeviceInfoList=(SETUPDIDESTROYDEVICEINFOLIST) GetProcAddress(hSAPI,"SetupDiDestroyDeviceInfoList"); + if(SetupDiGetClassDevsA==NULL\ + ||SetupDiEnumDeviceInterfaces==NULL\ + ||SetupDiDestroyDeviceInfoList==NULL\ + ||SetupDiGetDeviceInterfaceDetailA==NULL) return 0; + /* + The following code is adapted from Usbhidio_vc6 application example by Jan Axelson + for more information see see http://www.lvr.com/hidpage.htm + */ + /* + API function: HidD_GetHidGuid + Get the GUID for all system HIDs. + Returns: the GUID in HidGuid. + */ + HidD_GetHidGuid(&HidGuid); + /* + API function: SetupDiGetClassDevs + Returns: a handle to a device information set for all installed devices. + Requires: the GUID returned by GetHidGuid. + */ + hDevInfo=SetupDiGetClassDevs(&HidGuid,NULL,NULL,DIGCF_PRESENT|DIGCF_INTERFACEDEVICE); + devInfoData.cbSize = sizeof(devInfoData); + //Step through the available devices looking for the one we want. + //Quit on detecting the desired device or checking all available devices without success. + MemberIndex = 0; + LastDevice = FALSE; + do + { + /* + API function: SetupDiEnumDeviceInterfaces + On return, MyDeviceInterfaceData contains the handle to a + SP_DEVICE_INTERFACE_DATA structure for a detected device. + Requires: + The DeviceInfoSet returned in SetupDiGetClassDevs. + The HidGuid returned in GetHidGuid. + An index to specify a device. + */ + Result=SetupDiEnumDeviceInterfaces (hDevInfo, 0, &HidGuid, MemberIndex, &devInfoData); + if (Result != 0) + { + //A device has been detected, so get more information about it. + /* + API function: SetupDiGetDeviceInterfaceDetail + Returns: an SP_DEVICE_INTERFACE_DETAIL_DATA structure + containing information about a device. + To retrieve the information, call this function twice. + The first time returns the size of the structure in Length. + The second time returns a pointer to the data in DeviceInfoSet. + Requires: + A DeviceInfoSet returned by SetupDiGetClassDevs + The SP_DEVICE_INTERFACE_DATA structure returned by SetupDiEnumDeviceInterfaces. + The final parameter is an optional pointer to an SP_DEV_INFO_DATA structure. + This application doesn't retrieve or use the structure. + If retrieving the structure, set + MyDeviceInfoData.cbSize = length of MyDeviceInfoData. + and pass the structure's address. + */ + //Get the Length value. + //The call will return with a "buffer too small" error which can be ignored. + Result = SetupDiGetDeviceInterfaceDetail(hDevInfo, &devInfoData, NULL, 0, &Length, NULL); + //Allocate memory for the hDevInfo structure, using the returned Length. + detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(Length); + //Set cbSize in the detailData structure. + detailData -> cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); + //Call the function again, this time passing it the returned buffer size. + Result = SetupDiGetDeviceInterfaceDetail(hDevInfo, &devInfoData, detailData, Length,&Required, NULL); + // Open a handle to the device. + // To enable retrieving information about a system mouse or keyboard, + // don't request Read or Write access for this handle. + /* + API function: CreateFile + Returns: a handle that enables reading and writing to the device. + Requires: + The DevicePath in the detailData structure + returned by SetupDiGetDeviceInterfaceDetail. + */ + DeviceHandle=CreateFile(detailData->DevicePath, + 0, FILE_SHARE_READ|FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL,OPEN_EXISTING, 0, NULL); + /* + API function: HidD_GetAttributes + Requests information from the device. + Requires: the handle returned by CreateFile. + Returns: a HIDD_ATTRIBUTES structure containing + the Vendor ID, Product ID, and Product Version Number. + Use this information to decide if the detected device is + the one we're looking for. + */ + //Set the Size to the number of bytes in the structure. + Attributes.Size = sizeof(Attributes); + Result = HidD_GetAttributes(DeviceHandle,&Attributes); + //Is it the desired device? + MyDeviceDetected = FALSE; + if (Attributes.VendorID == vid) + { + if (Attributes.ProductID == pid) + { + //Both the Vendor ID and Product ID match. + MyDeviceDetected = TRUE; + strcpy(MyDevicePathName,detailData->DevicePath); + // Get a handle for writing Output reports. + WriteHandle=CreateFile(detailData->DevicePath, + GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL,OPEN_EXISTING,0,NULL); + //Get a handle to the device for the overlapped ReadFiles. + ReadHandle=CreateFile(detailData->DevicePath, + GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,(LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL); + if (hEventObject) CloseHandle(hEventObject); + hEventObject = CreateEvent(NULL,TRUE,TRUE,""); + //Set the members of the overlapped structure. + HIDOverlapped.hEvent = hEventObject; + HIDOverlapped.Offset = 0; + HIDOverlapped.OffsetHigh = 0; + Result=HidD_SetNumInputBuffers(DeviceHandle,64); + } + else + //The Product ID doesn't match. + CloseHandle(DeviceHandle); + } + else + //The Vendor ID doesn't match. + CloseHandle(DeviceHandle); + //Free the memory used by the detailData structure (no longer needed). + free(detailData); + } + else + //SetupDiEnumDeviceInterfaces returned 0, so there are no more devices to check. + LastDevice=TRUE; + //If we haven't found the device yet, and haven't tried every available device, + //try the next one. + MemberIndex = MemberIndex + 1; + } //do + while ((LastDevice == FALSE) && (MyDeviceDetected == FALSE)); + //Free the memory reserved for hDevInfo by SetupDiClassDevs. + SetupDiDestroyDeviceInfoList(hDevInfo); +/* if(info){ + PrintMessage3("Device detected: vid=0x%04X pid=0x%04X\nPath: %s\n",vid,pid,MyDevicePathName); + if(HidD_GetManufacturerString(DeviceHandle,string,sizeof(string))==TRUE) wprintf(L"Manufacturer string: %s\n",string); + if(HidD_GetProductString(DeviceHandle,string,sizeof(string))==TRUE) wprintf(L"Product string: %s\n",string); + }*/ +#endif + if (MyDeviceDetected == FALSE){ + PrintMessage(strings[S_noprog]); //"Programmer not detected\r\n" + //gtk_statusbar_push(status_bar,statusID,strings[S_noprog]); + } + else{ + PrintMessage(strings[S_prog]); //"Programmer detected\r\n"); + PrintMessage2("VID=0x%04X PID=0x%04X\r\n",vid,pid); + //gtk_statusbar_push(status_bar,statusID,strings[S_prog]); + } + return MyDeviceDetected; +} diff --git a/opgui.glade b/opgui.glade new file mode 100644 index 0000000..60b9c1a --- /dev/null +++ b/opgui.glade @@ -0,0 +1,3797 @@ + + + + + + 100 + 1 + 1 + 10 + + + 5 + 15 + 5 + 1 + 10 + + + True + False + /res/read.png + + + True + False + /res/write.png + + + False + center + 850 + 250 + + + + True + False + vertical + + + True + False + 10 + 10 + 6 + 6 + 2 + bottom + + + False + True + end + 0 + + + + + True + False + + + OPEN_T + True + False + True + document-open-symbolic + + + False + True + + + + + True + False + True + document-save-symbolic + + + False + True + + + + + True + False + + + False + True + + + + + True + False + True + imageRead + + + False + True + + + + + True + False + True + imageWrite + + + False + True + + + + + True + False + + + False + True + + + + + True + False + False + stop + True + media-playback-stop-symbolic + + + False + True + + + + + True + False + reconn + True + gtk-connect + + + False + True + + + + + True + False + info + True + help-browser-symbolic + + + False + True + + + + + True + False + quit + True + application-exit-symbolic + + + False + True + + + + + False + True + 1 + + + + + True + True + + + True + True + in + + + True + True + 5 + 5 + + + + + + + + True + False + dati + + + False + + + + + True + False + 5 + 5 + 5 + + + True + False + vertical + + + True + False + 5 + + + True + False + _tipo + + + False + True + 0 + + + + + True + False + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + + + True + False + label + + + False + True + 0 + + + + + True + True + + + False + True + 1 + + + + + False + True + 1 + + + + + True + True + in + + + True + True + start + start + True + + + + + + + + True + True + 2 + + + + + False + True + 0 + + + + + True + False + start + 8 + 0 + in + + + True + False + 6 + 6 + 3 + 6 + vertical + + + True + False + + + False + True + 0 + + + + + ee + True + True + False + start + 5 + True + True + + + False + True + 1 + + + + + False + 5 + vertical + 1 + + + True + False + + + True + False + vertical + 5 + + + _reserved + True + True + False + True + + + False + True + 0 + + + + + _progID + True + True + False + True + + + False + True + 1 + + + + + _progCal + True + True + False + True + + + False + True + 2 + + + + + True + False + 0 + in + + + True + False + 5 + 5 + 5 + vertical + + + _osccal + True + True + False + True + FILECAL + + + False + True + 0 + + + + + _bkosccal + True + True + False + True + FILECAL + + + False + True + 1 + + + + + _file + True + True + False + True + OSCCAL + + + False + True + 2 + + + + + + + True + False + __osccal + + + + + False + True + 3 + + + + + False + True + 0 + + + + + True + False + 6 + 0 + in + + + True + False + 5 + 5 + 5 + vertical + 5 + + + _forcecw + True + True + False + True + + + False + True + 0 + + + + + True + False + + + True + False + + + True + False + CW1 + + + False + True + 0 + + + + + True + True + 4 + 4 + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + + + True + False + CW2 + + + False + True + 0 + + + + + True + True + 4 + 4 + + + False + True + 1 + + + + + False + True + 1 + + + + + True + False + + + True + False + CW3 + + + False + True + 0 + + + + + True + True + 4 + 4 + + + False + True + 1 + + + + + False + True + 2 + + + + + True + False + + + True + False + CW4 + + + False + True + 0 + + + + + True + True + 4 + 4 + + + False + True + 1 + + + + + False + True + 3 + + + + + False + True + 1 + + + + + True + False + + + True + False + + + True + False + CW5 + + + False + True + 0 + + + + + True + True + 4 + 4 + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + + + True + False + CW6 + + + False + True + 0 + + + + + True + True + 4 + 4 + + + False + True + 1 + + + + + False + True + 1 + + + + + True + False + + + True + False + CW7 + + + False + True + 0 + + + + + True + True + 4 + 4 + + + False + True + 1 + + + + + False + True + 2 + + + + + True + False + + + True + False + CW8 + + + False + True + 0 + + + + + True + True + 4 + 4 + + + False + True + 1 + + + + + False + True + 3 + + + + + False + True + 2 + + + + + + + True + False + Config Word + + + + + False + False + 1 + + + + + False + True + 5 + 0 + + + + + True + False + start + 0 + in + + + True + False + 5 + 5 + 5 + 48 + + + _icd + True + True + False + True + + + False + True + 0 + + + + + True + False + + + True + False + _address + + + False + True + 0 + + + + + True + True + 5 + + + False + True + 1 + + + + + False + True + 1 + + + + + + + True + False + ICD + + + + + False + True + 1 + + + + + False + True + 5 + 2 + + + + + False + 5 + vertical + 5 + + + True + False + + + True + True + 2 + + + False + True + 0 + + + + + _fuselow + True + True + False + True + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + + + True + True + 2 + + + False + True + 0 + + + + + _fusehigh + True + True + False + True + + + False + True + 1 + + + + + False + True + 1 + + + + + True + False + + + True + True + 2 + + + False + True + 0 + + + + + _fuseext + True + True + False + True + + + False + True + 1 + + + + + False + True + 2 + + + + + True + False + + + True + True + 2 + + + False + True + 0 + + + + + _fuselock + True + True + False + True + + + False + True + 1 + + + + + False + True + 3 + + + + + _writefuselow3k + True + True + True + start + + + False + False + 4 + + + + + False + True + 3 + + + + + + + True + False + _dev + + + + + False + False + 1 + + + + + 1 + + + + + True + False + _dev + + + 1 + False + + + + + True + False + 5 + 5 + vertical + 5 + + + _connect + True + True + True + start + + + False + True + 0 + + + + + True + False + + + True + False + + + True + False + VID + + + False + True + 0 + + + + + True + True + 4 + 4 + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + + + True + False + PID + + + False + True + 0 + + + + + True + True + 4 + 4 + + + False + True + 1 + + + + + False + True + 20 + 1 + + + + + False + True + 1 + + + + + _test + True + True + True + start + + + False + True + 2 + + + + + _log + True + True + False + start + True + + + False + True + 3 + + + + + 3v3nocheck + True + True + False + start + True + + + False + True + 4 + + + + + _s1 + True + True + False + start + True + + + False + True + 5 + + + + + True + False + + + True + False + _maxerr + + + False + True + 0 + + + + + True + True + 4 + 4 + + + False + True + 1 + + + + + False + True + 6 + + + + + 2 + + + + + True + False + _options + + + 2 + False + + + + + True + False + 10 + 5 + 15 + + + True + False + start + 0 + in + + + True + False + vertical + 5 + + + I2C 8 Bit + True + True + False + True + True + + + False + True + 0 + + + + + I2C 16 Bit + True + True + False + True + True + I2C8BIT + + + False + True + 1 + + + + + True + False + + + False + True + 2 + + + + + SPI(00) + True + True + False + True + True + I2C8BIT + + + False + True + 3 + + + + + SPI(01) + True + True + False + True + True + I2C8BIT + + + False + True + 4 + + + + + SPI(10) + True + True + False + True + True + I2C8BIT + + + False + True + 5 + + + + + SPI(11) + True + True + False + True + True + I2C8BIT + + + False + True + 6 + + + + + + + True + False + _mode + + + + + False + False + 0 + + + + + True + False + vertical + 5 + + + True + False + 5 + + + True + False + _byte + + + False + True + 0 + + + + + True + True + 3 + number + I2C_adj + 1 + True + 1 + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + 5 + + + True + False + _speed + + + False + True + 0 + + + + + True + False + 0 + + 100 kbps + 200 kbps + 300/400 kbps + 500/800 kbps + + + + False + True + 1 + + + + + False + True + 1 + + + + + True + False + 5 + True + + + _send + True + True + True + + + False + True + 0 + + + + + _receive + True + True + True + + + False + True + 1 + + + + + False + True + 2 + + + + + True + False + _datasend + + + False + True + 3 + + + + + True + True + + + False + True + 4 + + + + + True + False + _datatransferred + + + False + True + 5 + + + + + True + False + 0 + out + + + 250 + 60 + True + True + False + + + + + True + False + + + + + False + True + 6 + + + + + False + True + 1 + + + + + 3 + + + + + True + False + I2C/SPI + + + 3 + False + + + + + True + False + 5 + vertical + + + True + False + + + True + False + True + go-next-symbolic + + + False + True + + + + + True + False + True + media-playback-pause-symbolic + + + False + True + + + + + True + False + True + go-last-symbolic + + + False + True + + + + + True + False + True + media-seek-forward-symbolic + + + False + True + + + + + True + False + + + False + True + + + + + True + False + True + media-playback-stop-symbolic + + + False + True + + + + + True + False + + + False + True + + + + + True + False + True + media-playlist-repeat-symbolic + + + False + True + + + + + True + False + + + False + True + + + + + True + False + _loadcoff + True + + + False + True + + + + + True + False + + + False + True + + + + + True + False + + + True + True + 10 + + + + + False + False + + + + + True + False + + + False + False + + + + + True + False + help + True + help-browser-symbolic + + + False + True + + + + + False + True + 0 + + + + + True + False + True + + + True + False + vertical + + + True + False + _source + + + False + True + 7 + 0 + + + + + True + True + in + + + True + True + False + + + + + True + True + 2 + + + + + False + True + 0 + + + + + True + False + vertical + + + True + False + True + + + True + False + _status + + + False + True + 0 + + + + + True + False + + + True + False + _opt + True + + + True + False + + + True + False + _counter + True + True + + + + + True + False + _status + True + True + + + + + True + False + _b0 + True + + + + + True + False + _b1 + True + + + + + True + False + _b2 + True + + + + + True + False + _b3 + True + + + + + True + False + _ee + True + + + + + + + + + False + True + 3 + + + + + False + True + 0 + + + + + True + True + in + + + True + True + False + + + + + True + True + 2 + + + + + False + True + 1 + + + + + True + True + 1 + + + + + 4 + + + + + True + False + ICD + + + 4 + False + + + + + True + False + 5 + 5 + vertical + 10 + + + True + False + start + 0 + in + + + True + False + vertical + + + _io + True + True + False + start + True + + + False + True + 0 + + + + + True + False + 5 + 5 + 5 + 30 + + + True + False + vertical + + + True + False + 4 + + + True + False + RB7 + + + False + True + 0 + + + + + 0 + True + True + False + True + + + False + True + 1 + + + + + 1 + True + True + False + True + RB7_0 + + + False + True + 2 + + + + + INPUT: + True + True + False + True + True + RB7_0 + + + False + True + 3 + + + + + True + False + 2 + + + False + True + 4 + + + + + False + True + 0 + + + + + True + False + 4 + + + True + False + RB6 + + + False + True + 0 + + + + + 0 + True + True + False + True + + + False + True + 1 + + + + + 1 + True + True + False + True + RB6_0 + + + False + True + 2 + + + + + INPUT: + True + True + False + True + True + RB6_0 + + + False + True + 3 + + + + + True + False + 2 + + + False + True + 4 + + + + + False + True + 1 + + + + + True + False + 4 + + + True + False + RB5 + + + False + True + 0 + + + + + 0 + True + True + False + True + True + + + False + True + 1 + + + + + 1 + True + True + False + True + RB5_0 + + + False + True + 2 + + + + + INPUT: + True + True + False + True + True + RB5_0 + + + False + True + 3 + + + + + True + False + 2 + + + False + True + 4 + + + + + False + True + 2 + + + + + True + False + 4 + + + True + False + RB4 + + + False + True + 0 + + + + + 0 + True + True + False + True + True + + + False + True + 1 + + + + + 1 + True + True + False + True + RB4_0 + + + False + True + 2 + + + + + INPUT: + True + True + False + True + True + RB4_0 + + + False + True + 3 + + + + + True + False + 2 + + + False + True + 4 + + + + + False + True + 3 + + + + + True + False + 4 + + + True + False + RB3 + + + False + True + 0 + + + + + 0 + True + True + False + True + True + + + False + True + 1 + + + + + 1 + True + True + False + True + RB3_0 + + + False + True + 2 + + + + + INPUT: + True + True + False + True + True + RB3_0 + + + False + True + 3 + + + + + True + False + 2 + + + False + True + 4 + + + + + False + True + 4 + + + + + True + False + 4 + + + True + False + RB2 + + + False + True + 0 + + + + + 0 + True + True + False + True + True + + + False + True + 1 + + + + + 1 + True + True + False + True + RB2_0 + + + False + True + 2 + + + + + INPUT: + True + True + False + True + True + RB2_0 + + + False + True + 3 + + + + + True + False + 2 + + + False + True + 4 + + + + + False + True + 5 + + + + + True + False + 4 + + + True + False + RB1 + + + False + True + 0 + + + + + 0 + True + True + False + True + True + + + False + True + 1 + + + + + 1 + True + True + False + True + RB1_0 + + + False + True + 2 + + + + + INPUT: + True + True + False + True + True + RB1_0 + + + False + True + 3 + + + + + True + False + 2 + + + False + True + 4 + + + + + False + True + 6 + + + + + True + False + 4 + + + True + False + RB0 + + + False + True + 0 + + + + + 0 + True + True + False + True + True + + + False + True + 1 + + + + + 1 + True + True + False + True + RB0_0 + + + False + True + 2 + + + + + INPUT: + True + True + False + True + True + RB0_0 + + + False + True + 3 + + + + + True + False + 2 + + + False + True + 4 + + + + + False + True + 7 + + + + + False + True + 0 + + + + + True + False + vertical + + + True + False + 4 + + + True + False + RC7 + + + False + True + 0 + + + + + 0 + True + True + False + True + True + + + False + True + 1 + + + + + 1 + True + True + False + True + RC7_0 + + + False + True + 2 + + + + + INPUT: + True + True + False + True + True + RC7_0 + + + False + True + 3 + + + + + True + False + 2 + + + False + True + 4 + + + + + False + True + 0 + + + + + True + False + 4 + + + True + False + RC6 + + + False + True + 0 + + + + + 0 + True + True + False + True + True + + + False + True + 1 + + + + + 1 + True + True + False + True + RC6_0 + + + False + True + 2 + + + + + INPUT: + True + True + False + True + True + RC6_0 + + + False + True + 3 + + + + + True + False + 2 + + + False + True + 4 + + + + + False + True + 1 + + + + + True + False + 4 + + + True + False + RA5 + + + False + True + 0 + + + + + 0 + True + True + False + True + True + + + False + True + 1 + + + + + 1 + True + True + False + True + RA5_0 + + + False + True + 2 + + + + + INPUT: + True + True + False + True + True + RA5_0 + + + False + True + 3 + + + + + True + False + 2 + + + False + True + 4 + + + + + False + True + 2 + + + + + True + False + 4 + + + True + False + RA4 + + + False + True + 0 + + + + + 0 + True + True + False + True + True + + + False + True + 1 + + + + + 1 + True + True + False + True + RA4_0 + + + False + True + 2 + + + + + INPUT: + True + True + False + True + True + RA4_0 + + + False + True + 3 + + + + + True + False + 2 + + + False + True + 4 + + + + + False + True + 3 + + + + + True + False + 4 + + + True + False + RA3 + + + False + True + 0 + + + + + 0 + True + True + False + True + True + + + False + True + 1 + + + + + 1 + True + True + False + True + RA3_0 + + + False + True + 2 + + + + + INPUT: + True + True + False + True + True + RA3_0 + + + False + True + 3 + + + + + True + False + 2 + + + False + True + 4 + + + + + False + True + 4 + + + + + False + True + 1 + + + + + False + True + 1 + + + + + + + True + False + I/O + + + + + False + True + 0 + + + + + True + False + 10 + + + VDDU + True + True + False + True + + + False + True + 0 + + + + + VPPU + True + True + False + True + + + False + True + 1 + + + + + DCDC + True + True + False + True + + + False + True + 2 + + + + + True + True + False + VPP_adj + False + 0 + 1 + + + True + True + 3 + + + + + False + True + 1 + + + + + True + False + 5 + 5 + 0 + in + + + True + False + vertical + 5 + + + True + False + 5 + + + True + False + start + vertical + + + True + False + _datasend + + + False + True + 0 + + + + + True + True + 5 + 10 + 35 + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + 5 + vertical + + + True + False + _datatransferred + + + False + True + 0 + + + + + True + False + 0 + out + + + 200 + True + True + False + number + + + + + True + False + + + + + False + False + 1 + + + + + False + True + 1 + + + + + False + True + 0 + + + + + _send + True + True + True + start + 5 + 5 + + + False + True + 1 + + + + + + + True + False + _cmd + + + + + False + True + 2 + + + + + 5 + + + + + True + False + I/O + + + 5 + False + + + + + True + False + 5 + 5 + vertical + 10 + + + True + False + 5 + 0 + in + + + True + False + 5 + 5 + 5 + vertical + 5 + + + True + False + 10 + + + True + False + Hex + + + False + True + 0 + + + + + True + True + + + True + True + 1 + + + + + False + True + 0 + + + + + True + True + False + + + True + True + 1 + + + + + + + True + False + HEX -> DATA + + + + + False + True + 0 + + + + + True + False + 5 + 0 + in + + + True + False + 5 + 5 + 5 + vertical + 5 + + + True + False + 10 + + + True + False + _addr + + + False + True + 0 + + + + + True + True + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + 10 + + + True + False + _data + + + False + True + 0 + + + + + True + True + + + True + True + 1 + + + + + False + True + 1 + + + + + True + False + 10 + + + True + False + Hex + + + False + True + 0 + + + + + True + True + False + + + True + True + 1 + + + + + False + True + 2 + + + + + _save + True + True + True + start + + + False + True + 3 + + + + + + + True + False + DATA -> HEX + + + + + False + True + 1 + + + + + 6 + + + + + True + False + Utility + + + 6 + False + + + + + True + True + 2 + + + + + + diff --git a/progAVR.c b/progAVR.c new file mode 100644 index 0000000..47fdcc4 --- /dev/null +++ b/progAVR.c @@ -0,0 +1,2450 @@ +/* + * progAVR.c - algorithms to program the Atmel AVR family of microcontrollers + * Copyright (C) 2009-2021 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" + +#define LOCK 1 +#define FUSE 2 +#define FUSE_H 4 +#define FUSE_X 8 +#define CAL 16 +#define SLOW 256 +#define RST 0x40 + +struct AVRID{ + int id; + char *device; +} AVRLIST[]={ + //1K + {0x9001,"AT90S1200"}, + {0x9004,"ATtiny11"}, + {0x9005,"ATtiny12"}, + {0x9007,"ATtiny13"}, + //2K + {0x9101,"AT90S2313"}, + {0x9109,"ATtiny26"}, + {0x910A,"ATtiny2313"}, + {0x910B,"ATtiny24"}, + {0x910C,"ATtiny261"}, + //4K + {0x9205,"ATmega48"}, + {0x920A,"ATmega48PA"}, + {0x9207,"ATtiny44"}, + {0x9208,"ATtiny461"}, + {0x9209,"ATtiny48"}, + {0x920D,"ATtiny4313"}, + //8K + {0x9301,"AT90S8515"}, + {0x9303,"AT90S8535"}, + {0x9306,"ATmega8515"}, + {0x9307,"ATmega8"}, + {0x9308,"ATmega8535"}, + {0x930A,"ATmega88"}, + {0x930C,"ATtiny84"}, + {0x930D,"ATtiny861"}, + {0x930F,"ATmega88PA"}, + {0x9311,"ATtiny88"}, + //16K + {0x9403,"ATmega16"}, + {0x9406,"ATmega168"}, + {0x940A,"ATmega164PA"}, + {0x940B,"ATmega168PA"}, + {0x940F,"ATmega164A"}, + //32K + {0x950F,"ATmega328P"}, + {0x9511,"ATmega324PA"}, + {0x9514,"ATmega328"}, + {0x9515,"ATmega324A"}, + //64K + {0x9602,"ATmega64"}, + {0x9609,"ATmega644A"}, + {0x960A,"ATmega644PA"}, + //128K + {0x9705,"ATmega1284P"}, + {0x9706,"ATmega1284"}, +}; + +void AtmelID(BYTE id[]) +{ + char str[128]=""; + int i,idw=(id[1]<<8)+id[2]; + if(id[0]==0&&id[1]==1&&id[2]==2){ + PrintMessage(strings[S_Protected]); //"Device protected" + return; + } + if(id[0]==0x1E) strcat(str,"Atmel "); + for(i=0;i500){ //limit number of lines printed + strcat(aux,"(...)\r\n"); + i=(dim>8; + bufferU[j++]=(int)(Tbit/2)&0xff; + bufferU[j++]=SET_PORT_DIR; + bufferU[j++]=0xF5; //TRISB + bufferU[j++]=0x3F; //TRISA-C (RC7:RC6:RA5:RA4:RA3:X:X:X) + for(i=0;i<4;i++){ //first nibble + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; //PORTB CLK=0 + bufferU[j++]=data&0x80; //PORTA-C + bufferU[j++]=WAIT_T3; //half bit delay + bufferU[j++]=EXT_PORT; + bufferU[j++]=2; //PORTB CLK=1 + bufferU[j++]=data&0x80; //PORTA-C + bufferU[j++]=READ_B; + bufferU[j++]=WAIT_T3; //half bit delay + data<<=1; + } + bufferU[j++]=FLUSH; + for(;j10) i++; + if(i>20) i+=2; + if(i>40) i+=4; + if(i>80) i+=4; + if(i>160) i+=8; + Tbyte=(20+i*4)/1000.0; //from firmware simulation + j=0; + bufferU[j++]=CLOCK_GEN; //reset with clock at 0 + bufferU[j++]=0xFF; + bufferU[j++]=EN_VPP_VCC; //VDD=0 + bufferU[j++]=0x0; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=0; + bufferU[j++]=WAIT_T3; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=WAIT_T3; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T1T2; + bufferU[j++]=i; //force T + bufferU[j++]=0; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=RST; + bufferU[j++]=WAIT_T3; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=0; + bufferU[j++]=CLOCK_GEN; + bufferU[j++]=5; //0=100k,200k,500k,1M,2M,3M + bufferU[j++]=FLUSH; + for(;j256){ + PrintMessage(strings[S_SyncErr]); //"Synchronization error\r\n" + if(saveLog) fprintf(logfile,strings[S_SyncErr]); + return 0; + } + //Add some margin + i++; + i+=i/10; + if(i>255) i=255; + Tbyte=(20+i*4)/1000.0; //from firmware simulation + j=0; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T1T2; + bufferU[j++]=i; //force T + bufferU[j++]=0; + bufferU[j++]=FLUSH; + for(;j0x20000||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n" + return; + } + if(dim2>0x1000||dim2<0){ + PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n" + return; + } + if(saveLog){ + OpenLogFile(); //"Log.txt" + fprintf(logfile,"ReadAT(0x%X,0x%X,0x%X)\n",dim,dim2,options); + } + size=dim; + sizeEE=dim2; + if(memCODE) free(memCODE); + memCODE=(unsigned char*)malloc(dim); //CODE + if(memEE) free(memEE); + memEE=(unsigned char*)malloc(dim2); //EEPROM + for(j=0;j>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=VREG_DIS; //Disable HV reg + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j>9; + bufferU[j++]=i>>1; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=i; + bufferU[j++]=SPI_READ; + bufferU[j++]=1; + n++; + if(j>DIMBUF-9||i==dim-1){ + bufferU[j++]=FLUSH; + for(;j0x20000||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n" + return; + } + if(dim2>0x800||dim2<0){ + PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n" + return; + } + if(saveLog){ + OpenLogFile(); //"Log.txt" + fprintf(logfile,"ReadAT_HV(0x%X,0x%X,0x%X)\n",dim,dim2,options); + } + size=dim; + sizeEE=dim2; + if(memCODE) free(memCODE); + memCODE=(unsigned char*)malloc(dim); //CODE + if(memEE) free(memEE); + memEE=(unsigned char*)malloc(dim2); //EEPROM + for(j=0;j>9; + bufferU[j++]=FLUSH; + for(;j>1)&0xFF; + bufferU[j++]=0x68; + bufferU[j++]=0x00; + bufferU[j++]=0x6C; + bufferU[j++]=0x00; + bufferU[j++]=AT_HV_RTX; + bufferU[j++]=2; + bufferU[j++]=0x78; + bufferU[j++]=0x00; + bufferU[j++]=0x7C; + bufferU[j++]=0x00; + i+=2; + if(j>DIMBUF-14||i>=dim-2){ + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=FLUSH; + for(;jDIMBUF-8||i>=dim2-2){ + bufferU[j++]=FLUSH; + for(;j0x8000||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n" + return; + } + if(dim2>0x800||dim2<0){ + PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n" + return; + } + if(saveLog){ + OpenLogFile(); //"Log.txt" + fprintf(logfile,"WriteAT(0x%X,0x%X)\n",dim,dim2); + } + if(dim>size) dim=size; + if(dim2>sizeEE) dim2=sizeEE; + if(dim<1){ + PrintMessage(strings[S_NoCode]); //"Data area is empty\r\n" + return; + } + unsigned int start=GetTickCount(); + j=0; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=2000>>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=VREG_DIS; //Disable HV reg + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=20000&0xff; + bufferU[j++]=VREG_DIS; //Disable HV reg + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x0; + bufferU[j++]=SPI_INIT; + bufferU[j++]=1; + bufferU[j++]=CLOCK_GEN; + bufferU[j++]=5; + bufferU[j++]=CLOCK_GEN; + bufferU[j++]=0xFF; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=0; + bufferU[j++]=WAIT_T3; //20ms + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=WAIT_T3; //20ms + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=FLUSH; + for(;j>9; + bufferU[j++]=i>>1; + bufferU[j++]=memCODE[i]; + bufferU[j++]=WAIT_T3; //6ms + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=SPI_WRITE; //Read program memory + bufferU[j++]=3; + bufferU[j++]=0x20+(i&1?8:0); + bufferU[j++]=i>>9; + bufferU[j++]=i>>1; + bufferU[j++]=SPI_READ; + bufferU[j++]=1; + bufferU[j++]=FLUSH; + for(;jmax_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim; + } + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, err=%d\n" + } + } + } + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" +//****************** write eeprom ******************** + if(dim2){ + PrintMessage(strings[S_EEAreaW]); //"Write EEPROM ... " + if(saveLog) fprintf(logfile,"%s\n",strings[S_EEAreaW]); + PrintStatusSetup(); + int errEE=0; + for(i=0,j=0;i>8; + bufferU[j++]=i; + bufferU[j++]=memEE[i]; + bufferU[j++]=WAIT_T3; //6ms + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=SPI_WRITE; //Read EEPROM memory + bufferU[j++]=3; + bufferU[j++]=0xA0; + bufferU[j++]=i>>8; + bufferU[j++]=i; + bufferU[j++]=SPI_READ; + bufferU[j++]=1; + bufferU[j++]=FLUSH; + for(;jmax_err){ + PrintMessage1(strings[S_MaxErr],err+errEE); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim2; + } + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,errEE); //"i=%d, k=%d, err=%d\n" + } + } + } + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],errEE); //"completed, %d errors\r\n" + err+=errEE; + } +// if(maxTry) PrintMessage1(strings[S_MaxRetry],maxTry); //"Max retries in writing: %d\r\n" +//****************** write FUSE ******************** + if(AVRlock<0x100){ + PrintMessage(strings[S_FuseAreaW]); //"Write Fuse ... " + if(saveLog) fprintf(logfile,"%s\n",strings[S_FuseAreaW]); + bufferU[j++]=SPI_WRITE; //Write lock + bufferU[j++]=4; + bufferU[j++]=0xAC; + bufferU[j++]=0xF9+(AVRlock&0x06); + bufferU[j++]=0; + bufferU[j++]=0; + bufferU[j++]=WAIT_T3; //9ms + bufferU[j++]=FLUSH; + for(;j0x20000||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n" + return; + } + if(dim2>0x1000||dim2<0){ + PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n" + return; + } + if(saveLog){ + OpenLogFile(); //"Log.txt" + fprintf(logfile,"WriteATmega(0x%X,0x%X,0x%X,0x%X)\n",dim,dim2,page,options); + } + if(dim>size) dim=size; + else{ + size=dim; + memCODE=(unsigned char*)realloc(memCODE,dim); + } + if(size%(page*2)){ //grow to an integer number of pages + j=size; + dim=(j/(page*2)+1)*page*2; + memCODE=(unsigned char*)realloc(memCODE,dim); + for(;jsizeEE) dim2=sizeEE; + if(dim<1){ + PrintMessage(strings[S_NoCode]); //"Data area is empty\r\n" + return; + } + unsigned int start=GetTickCount(); + j=0; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=2000>>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=VREG_DIS; //Disable HV reg + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=5000&0xff; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=k; + for(z=0;z>9; + bufferU[j++]=i>>1; + bufferU[j++]=0; + bufferU[j++]=WAIT_T3; //5ms + bufferU[j++]=FLUSH; + for(;j>9; + bufferU[j++]=(i+k*2)>>1; + bufferU[j++]=FLUSH; + for(;jmax_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim; + } + } + } + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" +//****************** write eeprom ******************** + if(dim2){ + PrintMessage(strings[S_EEAreaW]); //"Write EEPROM ... " + if(saveLog) fprintf(logfile,"%s\n",strings[S_EEAreaW]); + PrintStatusSetup(); + int errEE=0; + for(i=0,j=0;i>8; + bufferU[j++]=i; + bufferU[j++]=memEE[i]; + bufferU[j++]=WAIT_T3; //5ms + bufferU[j++]=WAIT_T3; //5ms + bufferU[j++]=SPI_WRITE; //Read EEPROM memory + bufferU[j++]=3; + bufferU[j++]=0xA0; + bufferU[j++]=i>>8; + bufferU[j++]=i; + bufferU[j++]=SPI_READ; + bufferU[j++]=1; + bufferU[j++]=FLUSH; + for(;jmaxTry) maxTry=Rtry; + i--; + } + else{ + errEE++; + Rtry=0; + } + } + if(max_err&&err+errEE>max_err){ + PrintMessage1(strings[S_MaxErr],err+errEE); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim2; + } + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,errEE); //"i=%d, k=%d, err=%d\n" + } + } + } + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],errEE); //"completed, %d errors\r\n" + err+=errEE; + } +//****************** write FUSE ******************** + int err_f=0; + if(AVRlock<0x100||AVRfuse<0x100||AVRfuse_h<0x100||AVRfuse_x<0x100){ + PrintMessage(strings[S_FuseAreaW]); //"Write Fuse ... " + if(saveLog) fprintf(logfile,"%s\n",strings[S_FuseAreaW]); + } + if(AVRfuse<0x100){ + bufferU[j++]=SPI_WRITE; //Write fuse + bufferU[j++]=4; + bufferU[j++]=0xAC; + bufferU[j++]=0xA0; + bufferU[j++]=0; + bufferU[j++]=AVRfuse; + bufferU[j++]=WAIT_T3; //5ms + bufferU[j++]=SPI_WRITE; + bufferU[j++]=3; + bufferU[j++]=0x50; + bufferU[j++]=0; + bufferU[j++]=0; + bufferU[j++]=SPI_READ; + bufferU[j++]=1; + bufferU[j++]=FLUSH; + for(;j0x10000||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n" + return; + } + if(dim2>0x800||dim2<0){ + PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n" + return; + } + if(saveLog){ + OpenLogFile(); //"Log.txt" + fprintf(logfile,"WriteAT_HV(0x%X,0x%X,0x%X,0x%X)\n",dim,dim2,page,options); + } + if(dim>size) dim=size; + else{ + size=dim; + memCODE=(unsigned char*)realloc(memCODE,dim); + } + if(page&&(size%(page*2))){ //grow to an integer number of pages + j=size; + dim=(j/(page*2)+1)*page*2; + memCODE=(unsigned char*)realloc(memCODE,dim); + for(;jsizeEE) dim2=sizeEE; + if(dim<1){ + PrintMessage(strings[S_NoCode]); //"Data area is empty\r\n" + return; + } + if(!StartHVReg(12)){ + PrintMessage(strings[S_HVregErr]); //"HV regulator error\r\n" + return; + } + unsigned int start=GetTickCount(); + j=0; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x0; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=0; + bufferU[j++]=SET_PORT_DIR; + bufferU[j++]=0xFC; + bufferU[j++]=0x7; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=SCI; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=0; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=SCI; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=0; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=SCI; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=0; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=SCI; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=0; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=SCI; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=0; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=SCI; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; + bufferU[j++]=0; + bufferU[j++]=EN_VPP_VCC; //VDD + VPP + bufferU[j++]=0x5; + bufferU[j++]=SET_PORT_DIR; //RELEASE SDO + bufferU[j++]=0xFE; + bufferU[j++]=0x7; + bufferU[j++]=FLUSH; + for(;j>9; + bufferU[j++]=0x0C; + bufferU[j++]=(i/2)&0xFF; + bufferU[j++]=0x2C; + bufferU[j++]=memCODE[i]; + bufferU[j++]=0x64; //write data low + bufferU[j++]=0x00; + bufferU[j++]=0x6C; + bufferU[j++]=0x00; + bufferU[j++]=READ_B; //check SDO + bufferU[j++]=FLUSH; + for(;jmax_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim; + } + } + } + } + else{ //page write + for(i=0;ipage){ //only pages with data!=0xFF + bufferU[j++]=AT_HV_RTX; + bufferU[j++]=1; + bufferU[j++]=0x4C; //Write FLASH + bufferU[j++]=0x10; + for(k=0;kDIMBUF-13||k>=page||i>=dim-2){ + bufferU[j++]=FLUSH; + for(;j>9)!=currPage){ //change high address if changed + bufferU[j++]=AT_HV_RTX; + bufferU[j++]=1; + bufferU[j++]=0x1C; + bufferU[j++]=i>>9; + currPage=i>>9; + } + bufferU[j++]=AT_HV_RTX; //write page + bufferU[j++]=2; + bufferU[j++]=0x64; + bufferU[j++]=0x00; + bufferU[j++]=0x6C; + bufferU[j++]=0x00; + bufferU[j++]=READ_B; //check SDO + bufferU[j++]=FLUSH; + for(;jDIMBUF-14||k>=page||i>=dim-2){ + bufferU[j++]=FLUSH; + for(;jmax_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim; + } + } + } + } + } + } + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" +//****************** write eeprom ******************** + if(dim2){ + int errEE=0; + PrintMessage(strings[S_EEAreaW]); //"Write EEPROM ... " + PrintStatusSetup(); + if(saveLog)fprintf(logfile,"WRITE EEPROM\n"); + j=0; + for(i=0;i>8; + bufferU[j++]=0x2C; + bufferU[j++]=memEE[i]; + bufferU[j++]=0x6D; + bufferU[j++]=0x00; + bufferU[j++]=0x64; + bufferU[j++]=0x00; + bufferU[j++]=0x6C; + bufferU[j++]=0x00; + bufferU[j++]=READ_B; //check SDO + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=0x0C; + bufferU[j++]=i&0xFF; + bufferU[j++]=0x68; + bufferU[j++]=0x00; + bufferU[j++]=0x6C; + bufferU[j++]=0x00; + bufferU[j++]=FLUSH; + for(;j=max_err) break; + } + } + PrintStatusEnd(); + err+=errEE; + if(err>=max_err){ + PrintMessage("\r\n"); + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + } + PrintMessage1(strings[S_ComplErr],errEE); //"completed: %d errors\r\n" + } +//****************** write FUSE ******************** + int err_f=0; + if(AVRlock<0x100||AVRfuse<0x100||AVRfuse_h<0x100||AVRfuse_x<0x100)PrintMessage(strings[S_FuseAreaW]); //"Write Fuse ... " + if(AVRfuse<0x100){ + if(saveLog)fprintf(logfile,"WRITE FUSE\n"); + bufferU[j++]=AT_HV_RTX; + bufferU[j++]=4; + bufferU[j++]=0x4C; + bufferU[j++]=0x40; + bufferU[j++]=0x2C; + bufferU[j++]=AVRfuse; + bufferU[j++]=0x64; + bufferU[j++]=0x00; + bufferU[j++]=0x6C; + bufferU[j++]=0x00; + bufferU[j++]=READ_B; //check SDO + bufferU[j++]=FLUSH; + for(;j + */ + +#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 + */ + +#include "common.h" + +void Read12F5xx(int dim,int dim2) +// read 12 bit PIC +// dim=program size dim2=config size +// vdd before vpp +// CONFIG @ 0x7FF (upon entering in program mode) +// OSCCAL in last memory location +// 4 ID + reserved area beyond code memory +{ + int k=0,z=0,i,j; + char s[256],t[256]; + if(dim2<4) dim2=4; + sizeW=0x1000; + if(memCODE_W) free(memCODE_W); + memCODE_W=(WORD*)malloc(sizeof(WORD)*sizeW); + if(saveLog){ + OpenLogFile(); //"Log.txt" + fprintf(logfile,"Read12F5xx(%d,%d)\n",dim,dim2); + } + unsigned int start=GetTickCount(); + j=0; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T1T2; + bufferU[j++]=1; //T1=1u + bufferU[j++]=100; //T2=100u + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=2000>>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=NOP; + bufferU[j++]=READ_DATA_PROG; //configuration word + bufferU[j++]=INC_ADDR; // 7FF->000 + bufferU[j++]=FLUSH; + for(;jDIMBUF*2/4-3||i==dim+dim2-1){ //2 ins -> 4 ans + bufferU[j++]=FLUSH; + for(;j4){ + PrintMessage1(strings[S_BKOsccal],memCODE_W[dim+4]); //"Backup OSCCAL: 0x%03X\r\n" + } + PrintMessage(strings[S_CodeMem]); //"\r\nCode memory\r\n" + s[0]=0; + int valid=0,empty=1; + char* aux=(char*)malloc((dim/COL+1)*(16+COL*5)); + aux[0]=0; + for(i=0;i5){ + aux=(char*)malloc((dim2/COL+1)*(16+COL*5)); + aux[0]=0; + s[0]=0; + PrintMessage(strings[S_ConfigResMem]); //"\r\nConfig and reserved memory:\r\n" + empty=1; + for(i=dim;idim) OscAddr=dim-1; + if(OscAddr==-1) use_BKosccal=use_osccal=0; + if(sizeW<0x1000){ + PrintMessage(strings[S_NoConfigW2]); //"Can't find CONFIG (0xFFF)\r\n" + return; + } + if(saveLog){ + OpenLogFile(); //"Log.txt" + fprintf(logfile,"Write12F5xx(%d,%d)\n",dim,OscAddr); + } + for(i=0;i404 + bufferU[j++]=READ_DATA_PROG; // backup OSCCAL + } + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=10000>>8; + bufferU[j++]=10000&0xff; + bufferU[j++]=WAIT_T3; + bufferU[j++]=FLUSH; + for(;jOscAddr+1){ //12F519 (Flash+EEPROM) + bufferU[j++]=BULK_ERASE_PROG; // Bulk erase + bufferU[j++]=WAIT_T3; // delay T3=10ms + for(i=-1;i000 + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=2000>>8; //T3=2ms + bufferU[j++]=2000&0xff; + bufferU[j++]=FLUSH; + for(;jOscAddr+1)?50:30); + PrintMessage(strings[S_Compl]); //"completed\r\n" +//****************** write code ******************** + PrintMessage(strings[S_StartCodeProg]); //"Write code ... " + PrintStatusSetup(); + int dim1=dim; + if(programID) dim1=dim+5; + if(memCODE_W[dim+4]>=0xFFF) memCODE_W[dim+4]=BKosccal; //reload BKosccal if not present + if(use_BKosccal) memCODE_W[OscAddr]=BKosccal; + else if(use_osccal) memCODE_W[OscAddr]=osccal; + for(i=k=w=0,j=0;i>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; + bufferU[j++]=WAIT_T3; //Tprogram 2ms + bufferU[j++]=END_PROG2; + bufferU[j++]=WAIT_T2; //Tdischarge + bufferU[j++]=READ_DATA_PROG; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-10||i==dim1-1){ + PrintStatus(strings[S_CodeWriting],i*100/dim,i); //"Write: %d%%, ind. %03X" + bufferU[j++]=FLUSH; + for(;j=0xfff) k++; + else if(bufferI[z]==LOAD_DATA_PROG&&bufferI[z+5]==READ_DATA_PROG){ + if (memCODE_W[k]!=(bufferI[z+6]<<8)+bufferI[z+7]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError],k,memCODE_W[k],(bufferI[z+6]<<8)+bufferI[z+7]); //"Error writing address %3X: written %03X, read %03X" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"write interrupted" + i=dim1; + z=DIMBUF; + } + } + k++; + z+=8; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d\n" + } + } + } + PrintStatusEnd(); + err+=i-k; + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" +//****************** write CONFIG ******************** + PrintMessage(strings[S_ConfigW]); //"Write CONFIG ... " + int err_c=0; + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; //10 ms tra uscita e rientro prog. mode + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x1; + bufferU[j++]=NOP; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x5; + bufferU[j++]=LOAD_DATA_PROG; //config word + bufferU[j++]=memCODE_W[0xfff]>>8; //MSB + bufferU[j++]=memCODE_W[0xfff]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; + bufferU[j++]=WAIT_T3; //Tprogram 2ms + bufferU[j++]=END_PROG2; + bufferU[j++]=WAIT_T2; //Tdischarge + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;jDIMBUF-2){ + PrintMessage("\r\n"); + PrintMessage(strings[S_ConfigWErr2]); //"Error writing CONFIG" + } + PrintMessage1(strings[S_ComplErr],err_c); //"completed, %d errors\r\n" + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d\n" + } + sprintf(str,strings[S_EndErr],(stop-start)/1000.0,err,err!=1?strings[S_ErrPlur]:strings[S_ErrSing]); //"\r\nEnd (%.2f s) %d %s\r\n\r\n" + PrintMessage(str); + if(saveLog){ + fprintf(logfile,str); + CloseLogFile(); + } + PrintStatusClear(); //clear status report +} + +void Write12C5xx(int dim,int dummy) +{ +// write 12 bit PIC with OTP +// dim=program size max~4300=10CC +// vdd before vpp +// CONFIG @ 0x7FF upon entering program mode +// write: BEGIN_PROG (1000) + Tprogram 100us + END_PROG2 (1110); +// 8 pulses + 11N overpulses + int k=0,z=0,i,j; + int err=0; + WORD osccal=-1; + int OscAddr=dim-1; + if(FWVersion<0x800){ + PrintMessage1(strings[S_FWver2old],"0.8.0"); //"This firmware is too old. Version %s is required\r\n" + return; + } + if(sizeW<0x1000){ + PrintMessage(strings[S_NoConfigW2]); //"Can't find CONFIG (0xFFF)\r\n" + return; + } + if(saveLog){ + OpenLogFile(); //"Log.txt" + fprintf(logfile,"Write12C5xx(%d)\n",dim); + } + for(i=0;i>8; + bufferU[j++]=10000&0xff; + bufferU[j++]=WAIT_T3; + bufferU[j++]=FLUSH; + for(;j000 + bufferU[j++]=READ_ADC; + bufferU[j++]=FLUSH; + for(;j>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=READ_ADC; + bufferU[j++]=INC_ADDR; + } + else{ + for(;memCODE_W[i]>=0xfff&&jNmax)Nmax=N; + } + if(memCODE_W[k]!=(bufferI[4]<<8)+bufferI[5]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError],k,memCODE_W[k],(bufferI[4]<<8)+bufferI[5]); //"Error writing address %3X: written %03X, read %03X" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"write interrupted" + i=dim1; + z=DIMBUF; + } + } + k++; + } + else for(z=0;z=0xfff) k++; + } + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d\n" + } + } + PrintStatusEnd(); + err+=i-k; + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" + if(saveLog && xN) fprintf(logfile,"Programming pulses: avg %.1f, min %d, max %d\r\n",(double)Nt/xN,Nmin,Nmax); +//****************** write CONFIG ******************** + if(memCODE_W[0xfff]<0xfff){ + PrintMessage(strings[S_ConfigW]); //"Write CONFIG ... " + int err_c=0; + bufferU[j++]=EN_VPP_VCC; //exit program mode + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; //10 ms + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x5; + bufferU[j++]=LOAD_DATA_PROG; //config word + bufferU[j++]=memCODE_W[0xfff]>>8; //MSB + bufferU[j++]=memCODE_W[0xfff]&0xff; //LSB + bufferU[j++]=FLUSH; + for(;j + */ + +#include "common.h" + +struct ID16{ + int id; + char *device; + int revmask; +} PIC16LIST[]={ + {0x00A>>1,"16F72 rev%d\r\n",0x1F}, //00 0000 101x xxxx + {0x046>>1,"12F683 rev%d\r\n",0x1F}, //00 0100 011x xxxx + {0x04A>>1,"16F685 rev%d\r\n",0x1F}, //00 0100 101x xxxx + {0x04C>>1,"16F818 rev%d\r\n",0x1F}, //00 0100 110x xxxx + {0x04E>>1,"16F819 rev%d\r\n",0x1F}, //00 0100 111x xxxx + {0x056>>1,"16F84A rev%d\r\n",0x1F}, //00 0101 011x xxxx + {0x060>>1,"16F73 rev%d\r\n",0x1F}, //00 0110 000x xxxx + {0x062>>1,"16F74 rev%d\r\n",0x1F}, //00 0110 001x xxxx + {0x064>>1,"16F76 rev%d\r\n",0x1F}, //00 0110 010x xxxx + {0x066>>1,"16F77 rev%d\r\n",0x1F}, //00 0110 011x xxxx + {0x072>>1,"16F87 rev%d\r\n",0x1F}, //00 0111 001x xxxx + {0x076>>1,"16F88 rev%d\r\n",0x1F}, //00 0111 011x xxxx + {0x07A>>1,"16F627 rev%d\r\n",0x1F}, //00 0111 101x xxxx + {0x07C>>1,"16F628 rev%d\r\n",0x1F}, //00 0111 110x xxxx + {0x08E>>1,"16F872 rev%d\r\n",0x1F}, //00 1000 111x xxxx + {0x092>>1,"16F874 rev%d\r\n",0x1F}, //00 1001 001x xxxx + {0x096>>1,"16F873 rev%d\r\n",0x1F}, //00 1001 011x xxxx + {0x09A>>1,"16F877 rev%d\r\n",0x1F}, //00 1001 101x xxxx + {0x09E>>1,"16F876 rev%d\r\n",0x1F}, //00 1001 111x xxxx + {0x0BA>>1,"16F737 rev%d\r\n",0x1F}, //00 1011 101x xxxx + {0x0BE>>1,"16F747 rev%d\r\n",0x1F}, //00 1011 111x xxxx + {0x0D0>>1,"16F870 rev%d\r\n",0x1F}, //00 1101 000x xxxx + {0x0D2>>1,"16F871 rev%d\r\n",0x1F}, //00 1101 001x xxxx + {0x0DE>>1,"16F777 rev%d\r\n",0x1F}, //00 1101 111x xxxx + {0x0E0>>1,"16F876A rev%d\r\n",0xF}, //00 1110 0000 xxxx + {0x0E2>>1,"16F877A rev%d\r\n",0xF}, //00 1110 0010 xxxx + {0x0E4>>1,"16F873A rev%d\r\n",0xF}, //00 1110 0100 xxxx + {0x0E6>>1,"16F874A rev%d\r\n",0xF}, //00 1110 0110 xxxx + {0x0EA>>1,"16F767 rev%d\r\n",0x1F}, //00 1110 101x xxxx + {0x0F8>>1,"12F629 rev%d\r\n",0x1F}, //00 1111 100x xxxx + {0x0FA>>1,"12F635 rev%d\r\n",0x1F}, //00 1111 101x xxxx + {0x0FC>>1,"12F675 rev%d\r\n",0x1F}, //00 1111 110x xxxx + {0x104>>1,"16F627A rev%d\r\n",0x1F}, //01 0000 010x xxxx + {0x106>>1,"16F628A rev%d\r\n",0x1F}, //01 0000 011x xxxx + {0x108>>1,"16F684 rev%d\r\n",0x1F}, //01 0000 100x xxxx + {0x110>>1,"16F648A rev%d\r\n",0x1F}, //01 0001 000x xxxx + {0x10A>>1,"16F636-639 rev%d\r\n",0x1F}, //01 0000 101x xxxx + {0x10C>>1,"16F630 rev%d\r\n",0x1F}, //01 0000 110x xxxx + {0x10E>>1,"16F676 rev%d\r\n",0x1F}, //01 0000 111x xxxx + {0x114>>1,"16F716 rev%d\r\n",0x1F}, //01 0001 010x xxxx + {0x118>>1,"16F688 rev%d\r\n",0x1F}, //01 0001 100x xxxx + {0x120>>1,"16F785 rev%d\r\n",0x1F}, //01 0010 000x xxxx + {0x122>>1,"16HV785 rev%d\r\n",0x1F}, //01 0010 001x xxxx + {0x124>>1,"16F616 rev%d\r\n",0x1F}, //01 0010 010x xxxx + {0x126>>1,"16HV616 rev%d\r\n",0x1F}, //01 0010 011x xxxx + {0x132>>1,"16F687 rev%d\r\n",0x1F}, //01 0011 001x xxxx + {0x134>>1,"16F689 rev%d\r\n",0x1F}, //01 0011 010x xxxx + {0x138>>1,"16F917 rev%d\r\n",0xF}, //01 0011 1000 xxxx + {0x13A>>1,"16F916 rev%d\r\n",0xF}, //01 0011 1010 xxxx + {0x13C>>1,"16F914 rev%d\r\n",0xF}, //01 0011 1100 xxxx + {0x13E>>1,"16F913 rev%d\r\n",0xF}, //01 0011 1110 xxxx + {0x140>>1,"16F690 rev%d\r\n",0x1F}, //01 0100 000x xxxx + {0x142>>1,"16F631 rev%d\r\n",0x1F}, //01 0100 001x xxxx + {0x144>>1,"16F677 rev%d\r\n",0x1F}, //01 0100 010x xxxx + {0x146>>1,"16F946 rev%d\r\n",0xF}, //01 0100 0110 xxxx + {0x148>>1,"16F1847 rev%d\r\n",0x1F}, //01 0100 100x xxxx + {0x14A>>1,"16LF1847 rev%d\r\n",0x1F}, //01 0100 101x xxxx + {0x150>>1,"12F752 rev%d\r\n",0x1F}, //01 0101 000x xxxx + {0x152>>1,"12HV752 rev%d\r\n",0x1F}, //01 0101 001x xxxx + {0x158>>1,"16F1526 rev%d\r\n",0x1F}, //01 0101 100x xxxx + {0x15A>>1,"16F1527 rev%d\r\n",0x1F}, //01 0101 101x xxxx + {0x15C>>1,"16LF1526 rev%d\r\n",0x1F}, //01 0101 110x xxxx + {0x15E>>1,"16LF1527 rev%d\r\n",0x1F}, //01 0101 111x xxxx + {0x164>>1,"16F1513 rev%d\r\n",0x1F}, //01 0110 010x xxxx + {0x168>>1,"16F1516 rev%d\r\n",0x1F}, //01 0110 100x xxxx + {0x16A>>1,"16F1517 rev%d\r\n",0x1F}, //01 0110 101x xxxx + {0x16C>>1,"16F1518 rev%d\r\n",0x1F}, //01 0110 110x xxxx + {0x16E>>1,"16F1519 rev%d\r\n",0x1F}, //01 0110 111x xxxx + {0x170>>1,"16F1512 rev%d\r\n",0x1F}, //01 0111 000x xxxx + {0x172>>1,"16LF1512 rev%d\r\n",0x1F}, //01 0111 001x xxxx + {0x174>>1,"16LF1513 rev%d\r\n",0x1F}, //01 0111 010x xxxx + {0x178>>1,"16LF1516 rev%d\r\n",0x1F}, //01 0111 100x xxxx + {0x17A>>1,"16LF1517 rev%d\r\n",0x1F}, //01 0111 101x xxxx + {0x17C>>1,"16LF1518 rev%d\r\n",0x1F}, //01 0111 110x xxxx + {0x17E>>1,"16LF1519 rev%d\r\n",0x1F}, //01 0111 111x xxxx + {0x180>>1,"16F727 rev%d\r\n",0x1F}, //01 1000 000x xxxx + {0x182>>1,"16F726 rev%d\r\n",0x1F}, //01 1000 001x xxxx + {0x184>>1,"16F724 rev%d\r\n",0x1F}, //01 1000 010x xxxx + {0x186>>1,"16F723 rev%d\r\n",0x1F}, //01 1000 011x xxxx + {0x188>>1,"16F722 rev%d\r\n",0x1F}, //01 1000 100x xxxx + {0x190>>1,"16LF727 rev%d\r\n",0x1F}, //01 1001 000x xxxx + {0x192>>1,"16LF726 rev%d\r\n",0x1F}, //01 1001 001x xxxx + {0x194>>1,"16LF724 rev%d\r\n",0x1F}, //01 1001 010x xxxx + {0x196>>1,"16LF723 rev%d\r\n",0x1F}, //01 1001 011x xxxx + {0x198>>1,"16LF722 rev%d\r\n",0x1F}, //01 1001 100x xxxx + {0x1AC>>1,"16F707 rev%d\r\n",0x1F}, //01 1010 110x xxxx + {0x1AE>>1,"16LF707 rev%d\r\n",0x1F}, //01 1010 111x xxxx + {0x1B0>>1,"16F723A rev%d\r\n",0x1F}, //01 1011 000x xxxx + {0x1B2>>1,"16F722A rev%d\r\n",0x1F}, //01 1011 001x xxxx + {0x1B4>>1,"16LF723A rev%d\r\n",0x1F}, //01 1011 010x xxxx + {0x1B6>>1,"16LF722A rev%d\r\n",0x1F}, //01 1011 011x xxxx + {0x1B8>>1,"12F1840 rev%d\r\n",0x1F}, //01 1011 100x xxxx + {0x1BA>>1,"12LF1840 rev%d\r\n",0x1F}, //01 1011 101x xxxx + {0x1C0>>1,"16F720 rev%d\r\n",0x1F}, //01 1100 000x xxxx + {0x1C2>>1,"16F721 rev%d\r\n",0x1F}, //01 1100 001x xxxx + {0x1C4>>1,"16LF720 rev%d\r\n",0x1F}, //01 1100 010x xxxx + {0x1C6>>1,"16LF721 rev%d\r\n",0x1F}, //01 1100 011x xxxx + {0x200>>1,"16F882 rev%d\r\n",0x1F}, //10 0000 000x xxxx + {0x202>>1,"16F883 rev%d\r\n",0x1F}, //10 0000 001x xxxx + {0x204>>1,"16F884 rev%d\r\n",0x1F}, //10 0000 010x xxxx + {0x206>>1,"16F886 rev%d\r\n",0x1F}, //10 0000 011x xxxx + {0x208>>1,"16F887 rev%d\r\n",0x1F}, //10 0000 100x xxxx + {0x218>>1,"12F615 rev%d\r\n",0x1F}, //10 0001 100x xxxx + {0x21A>>1,"12HV615 rev%d\r\n",0x1F}, //10 0001 101x xxxx + {0x224>>1,"12F609 rev%d\r\n",0x1F}, //10 0010 010x xxxx + {0x226>>1,"16F610 rev%d\r\n",0x1F}, //10 0010 011x xxxx + {0x228>>1,"12HV609 rev%d\r\n",0x1F}, //10 0010 100x xxxx + {0x22A>>1,"16HV610 rev%d\r\n",0x1F}, //10 0010 101x xxxx + {0x232>>1,"16F1933 rev%d\r\n",0x1F}, //10 0011 001x xxxx + {0x234>>1,"16F1934 rev%d\r\n",0x1F}, //10 0011 010x xxxx + {0x236>>1,"16F1936 rev%d\r\n",0x1F}, //10 0011 011x xxxx + {0x238>>1,"16F1937 rev%d\r\n",0x1F}, //10 0011 100x xxxx + {0x23A>>1,"16F1938 rev%d\r\n",0x1F}, //10 0011 101x xxxx + {0x23C>>1,"16F1939 rev%d\r\n",0x1F}, //10 0011 110x xxxx + {0x242>>1,"16LF1933 rev%d\r\n",0x1F}, //10 0100 001x xxxx + {0x244>>1,"16LF1934 rev%d\r\n",0x1F}, //10 0100 010x xxxx + {0x246>>1,"16LF1936 rev%d\r\n",0x1F}, //10 0100 011x xxxx + {0x248>>1,"16LF1937 rev%d\r\n",0x1F}, //10 0100 100x xxxx + {0x24A>>1,"16LF1938 rev%d\r\n",0x1F}, //10 0100 101x xxxx + {0x24C>>1,"16LF1939 rev%d\r\n",0x1F}, //10 0100 110x xxxx + {0x250>>1,"16F1946 rev%d\r\n",0x1F}, //10 0101 000x xxxx + {0x252>>1,"16F1947 rev%d\r\n",0x1F}, //10 0101 001x xxxx + {0x258>>1,"16LF1946 rev%d\r\n",0x1F}, //10 0101 100x xxxx + {0x25A>>1,"16LF1947 rev%d\r\n",0x1F}, //10 0101 101x xxxx + {0x270>>1,"12F1822 rev%d\r\n",0x1F}, //10 0111 000x xxxx + {0x272>>1,"16F1823 rev%d\r\n",0x1F}, //10 0111 001x xxxx + {0x274>>1,"16F1824 rev%d\r\n",0x1F}, //10 0111 010x xxxx + {0x276>>1,"16F1825 rev%d\r\n",0x1F}, //10 0111 011x xxxx + {0x278>>1,"16F1826 rev%d\r\n",0x1F}, //10 0111 100x xxxx + {0x27A>>1,"16F1827 rev%d\r\n",0x1F}, //10 0111 101x xxxx + {0x280>>1,"12LF1822 rev%d\r\n",0x1F}, //10 1000 000x xxxx + {0x282>>1,"16LF1823 rev%d\r\n",0x1F}, //10 1000 001x xxxx + {0x284>>1,"16LF1824 rev%d\r\n",0x1F}, //10 1000 010x xxxx + {0x286>>1,"16LF1825 rev%d\r\n",0x1F}, //10 1000 011x xxxx + {0x288>>1,"16LF1826 rev%d\r\n",0x1F}, //10 1000 100x xxxx + {0x28A>>1,"16LF1827 rev%d\r\n",0x1F}, //10 1000 101x xxxx + {0x298>>1,"10F322 rev%d\r\n",0x1F}, //10 1001 100x xxxx + {0x29A>>1,"10F320 rev%d\r\n",0x1F}, //10 1001 101x xxxx + {0x29C>>1,"10LF322 rev%d\r\n",0x1F}, //10 1001 110x xxxx + {0x29E>>1,"10LF320 rev%d\r\n",0x1F}, //10 1001 111x xxxx + {0x2A0>>1,"16F1782 rev%d\r\n",0x1F}, //10 1010 000x xxxx + {0x2A2>>1,"16F1783 rev%d\r\n",0x1F}, //10 1010 001x xxxx + {0x2A4>>1,"16F1784 rev%d\r\n",0x1F}, //10 1010 010x xxxx + {0x2A6>>1,"16F1786 rev%d\r\n",0x1F}, //10 1010 011x xxxx + {0x2A8>>1,"16F1787 rev%d\r\n",0x1F}, //10 1010 100x xxxx + {0x2AA>>1,"16LF1782 rev%d\r\n",0x1F}, //10 1010 101x xxxx + {0x2AC>>1,"16LF1783 rev%d\r\n",0x1F}, //10 1010 110x xxxx + {0x2AE>>1,"16LF1784 rev%d\r\n",0x1F}, //10 1010 111x xxxx + {0x2B0>>1,"16LF1786 rev%d\r\n",0x1F}, //10 1011 000x xxxx + {0x2B2>>1,"16LF1787 rev%d\r\n",0x1F}, //10 1011 001x xxxx + {0x2C0>>1,"16LF1903 rev%d\r\n",0x1F}, //10 1100 000x xxxx + {0x2C2>>1,"16LF1902 rev%d\r\n",0x1F}, //10 1100 001x xxxx + {0x2C4>>1,"16LF1907 rev%d\r\n",0x1F}, //10 1100 010x xxxx + {0x2C6>>1,"16LF1906 rev%d\r\n",0x1F}, //10 1100 011x xxxx + {0x2C8>>1,"16LF1904 rev%d\r\n",0x1F}, //10 1100 100x xxxx + {0x2CC>>1,"12F1501 rev%d\r\n",0x1F}, //10 1100 110x xxxx + {0x2CE>>1,"16F1503 rev%d\r\n",0x1F}, //10 1100 111x xxxx + {0x2D0>>1,"16F1507 rev%d\r\n",0x1F}, //10 1101 000x xxxx + {0x2D2>>1,"16F1508 rev%d\r\n",0x1F}, //10 1101 001x xxxx + {0x2D4>>1,"16F1509 rev%d\r\n",0x1F}, //10 1101 010x xxxx + {0x2D8>>1,"12LF1501 rev%d\r\n",0x1F}, //10 1101 100x xxxx + {0x2DA>>1,"16LF1503 rev%d\r\n",0x1F}, //10 1101 101x xxxx + {0x2DC>>1,"16LF1507 rev%d\r\n",0x1F}, //10 1101 110x xxxx + {0x2DE>>1,"16LF1508 rev%d\r\n",0x1F}, //10 1101 111x xxxx + {0x2E0>>1,"16LF1509 rev%d\r\n",0x1F}, //10 1110 000x xxxx + {0x2F0>>1,"16LF1554 rev%d\r\n",0x1F}, //10 1111 000x xxxx + {0x2F2>>1,"16LF1559 rev%d\r\n",0x1F}, //10 1111 001x xxxx +// New devices with DevID & DevRev in different locations: + {0x3000,"16F1574\r\n",0}, + {0x3001,"16F1575\r\n",0}, + {0x3002,"16F1578\r\n",0}, + {0x3003,"16F1579\r\n",0}, + {0x3004,"16LF1574\r\n",0}, + {0x3005,"16LF1575\r\n",0}, + {0x3006,"16LF1578\r\n",0}, + {0x3007,"16LF1579\r\n",0}, + {0x3020,"16F1454\r\n",0}, + {0x3021,"16F1455\r\n",0}, + {0x3023,"16F1459\r\n",0}, + {0x3024,"16LF1454\r\n",0}, + {0x3025,"16LF1455\r\n",0}, + {0x3027,"16LF1459\r\n",0}, + {0x302A,"16F1789\r\n",0}, + {0x302B,"16F1788\r\n",0}, + {0x302C,"16LF1789\r\n",0}, + {0x302D,"16LF1788\r\n",0}, + {0x3030,"16F753\r\n",0}, + {0x3031,"16HV753\r\n",0}, + {0x303A,"16F18324\r\n",0}, + {0x303B,"16F18344\r\n",0}, + {0x303C,"16LF18324\r\n",0}, + {0x303D,"16LF18344\r\n",0}, + {0x303E,"16F18325\r\n",0}, + {0x303F,"16F18345\r\n",0}, + {0x3040,"16LF18325\r\n",0}, + {0x3041,"16LF18345\r\n",0}, + {0x3042,"16F1708\r\n",0}, + {0x3043,"16F1704\r\n",0}, + {0x3044,"16LF1708\r\n",0}, + {0x3045,"16LF1704\r\n",0}, + {0x3048,"16F1716\r\n",0}, + {0x3049,"16F1713\r\n",0}, + {0x304A,"16LF1716\r\n",0}, + {0x304B,"16LF1713\r\n",0}, + {0x304C,"16F1613\r\n",0}, + {0x304D,"16LF1613\r\n",0}, + {0x3050,"12F1572\r\n",0}, + {0x3051,"12F1571\r\n",0}, + {0x3052,"12LF1572\r\n",0}, + {0x3053,"12LF1571\r\n",0}, + {0x3054,"16F1709\r\n",0}, + {0x3055,"16F1705\r\n",0}, + {0x3056,"16LF1709\r\n",0}, + {0x3057,"16LF1705\r\n",0}, + {0x3058,"12F1612\r\n",0}, + {0x3059,"12LF1612\r\n",0}, + {0x305A,"16F1719\r\n",0}, + {0x305B,"16F1718\r\n",0}, + {0x305C,"16F1717\r\n",0}, + {0x305D,"16LF1719\r\n",0}, + {0x305E,"16LF1718\r\n",0}, + {0x305F,"16LF1717\r\n",0}, + {0x3060,"16F1707\r\n",0}, + {0x3061,"16F1703\r\n",0}, + {0x3062,"16LF1707\r\n",0}, + {0x3063,"16LF1703\r\n",0}, + {0x3066,"16F18313\r\n",0}, + {0x3067,"16F18323\r\n",0}, + {0x3068,"16LF18313\r\n",0}, + {0x3069,"16LF18323\r\n",0}, + {0x306A,"16F18854\r\n",0}, + {0x306B,"16LF18854\r\n",0}, + {0x306C,"16F18855\r\n",0}, + {0x306D,"16F18875\r\n",0}, + {0x306E,"16LF18855\r\n",0}, + {0x306F,"16LF18875\r\n",0}, + {0x3070,"16F18856\r\n",0}, + {0x3071,"16F18876\r\n",0}, + {0x3072,"16LF18856\r\n",0}, + {0x3073,"16LF18876\r\n",0}, + {0x3074,"16F18857\r\n",0}, + {0x3075,"16F18877\r\n",0}, + {0x3076,"16LF18857\r\n",0}, + {0x3077,"16LF18877\r\n",0}, + {0x3078,"16F1614\r\n",0}, + {0x3079,"16F1618\r\n",0}, + {0x307A,"16LF1614\r\n",0}, + {0x307B,"16LF1618\r\n",0}, + {0x307C,"16F1615\r\n",0}, + {0x307D,"16F1619\r\n",0}, + {0x307E,"16LF1615\r\n",0}, + {0x307F,"16LF1619\r\n",0}, + {0x3080,"16F1764\r\n",0}, + {0x3081,"16F1765\r\n",0}, + {0x3082,"16LF1764\r\n",0}, + {0x3083,"16LF1765\r\n",0}, + {0x3084,"16F1768\r\n",0}, + {0x3085,"16F1769\r\n",0}, + {0x3086,"16LF1768\r\n",0}, + {0x3087,"16LF1769\r\n",0}, + {0x308A,"16F1773\r\n",0}, + {0x308B,"16F1776\r\n",0}, + {0x308C,"16LF1773\r\n",0}, + {0x308D,"16LF1776\r\n",0}, + {0x308E,"16F1777\r\n",0}, + {0x308F,"16F1778\r\n",0}, + {0x3090,"16F1779\r\n",0}, + {0x3091,"16LF1777\r\n",0}, + {0x3092,"16LF1778\r\n",0}, + {0x3093,"16LF1779\r\n",0}, + {0x3096,"16F19155\r\n",0}, + {0x3097,"16LF19155\r\n",0}, + {0x3098,"16F19156\r\n",0}, + {0x3099,"16LF19156\r\n",0}, + {0x309A,"16F19175\r\n",0}, + {0x309B,"16LF19175\r\n",0}, + {0x309C,"16F19176\r\n",0}, + {0x309D,"16LF19176\r\n",0}, + {0x309E,"16F19195\r\n",0}, + {0x309F,"16LF19195\r\n",0}, + {0x30A0,"16F19196\r\n",0}, + {0x30A1,"16LF19196\r\n",0}, + {0x30A2,"16F19197\r\n",0}, + {0x30A3,"16LF19197\r\n",0}, + {0x30A4,"16F18326\r\n",0}, + {0x30A5,"16F18346\r\n",0}, + {0x30A6,"16LF18326\r\n",0}, + {0x30A7,"16LF18346\r\n",0}, + {0x30AC,"16F15354\r\n",0}, + {0x30AD,"16LF15354\r\n",0}, + {0x30AE,"16F15355\r\n",0}, + {0x30AF,"16LF15355\r\n",0}, + {0x30B0,"16F15356\r\n",0}, + {0x30B1,"16LF15356\r\n",0}, + {0x30B2,"16F15375\r\n",0}, + {0x30B3,"16LF15375\r\n",0}, + {0x30B4,"16F15376\r\n",0}, + {0x30B5,"16LF15376\r\n",0}, + {0x30B6,"16F15385\r\n",0}, + {0x30B7,"16LF15385\r\n",0}, + {0x30B8,"16F15386\r\n",0}, + {0x30B9,"16LF15386\r\n",0}, + {0x30BE,"16F15313\r\n",0}, + {0x30BF,"16LF15313\r\n",0}, + {0x30BA,"16F19185\r\n",0}, + {0x30BB,"16LF19185\r\n",0}, + {0x30BC,"16F19186\r\n",0}, + {0x30BD,"16LF19186\r\n",0}, + {0x30C0,"16F15323\r\n",0}, + {0x30C1,"16LF15323\r\n",0}, + {0x30C2,"16F15324\r\n",0}, + {0x30C3,"16LF15324\r\n",0}, + {0x30C4,"16F15344\r\n",0}, + {0x30C5,"16LF15344\r\n",0}, + {0x30C6,"16F15325\r\n",0}, + {0x30C7,"16LF15325\r\n",0}, + {0x30C8,"16F15345\r\n",0}, + {0x30C9,"16LF15345\r\n",0}, + {0x30CA,"16F18424\r\n",0}, + {0x30CB,"16LF18424\r\n",0}, + {0x30CC,"16F18425\r\n",0}, + {0x30CD,"16LF18425\r\n",0}, + {0x30CE,"16F18444\r\n",0}, + {0x30CF,"16LF18444\r\n",0}, + {0x30D0,"16F18445\r\n",0}, + {0x30D1,"16LF18445\r\n",0}, + {0x30D2,"16F18426\r\n",0}, + {0x30D3,"16LF18426\r\n",0}, + {0x30D4,"16F18446\r\n",0}, + {0x30D5,"16LF18446\r\n",0}, + {0x30D7,"16F18455\r\n",0}, + {0x30D8,"16LF18455\r\n",0}, + {0x30D9,"16F18456\r\n",0}, + {0x30DA,"16LF18456\r\n",0}, + {0x30DB,"16F17114\r\n",0}, + {0x30DC,"16F17124\r\n",0}, + {0x30DD,"16F17144\r\n",0}, + {0x30DE,"16F17125\r\n",0}, + {0x30DF,"16F17145\r\n",0}, + {0x30E0,"16F17126\r\n",0}, + {0x30E1,"16F17146\r\n",0}, + {0x30E2,"16F17115\r\n",0}, + {0x30E3,"16F15213\r\n",0}, + {0x30E4,"16F15223\r\n",0}, + {0x30E5,"16F15243\r\n",0}, + {0x30E6,"16F15214\r\n",0}, + {0x30E7,"16F15224\r\n",0}, + {0x30E8,"16F15244\r\n",0}, + {0x30E9,"16F15225\r\n",0}, + {0x30EA,"16F15245\r\n",0}, + {0x30EB,"16F15256\r\n",0}, + {0x30EC,"16F15276\r\n",0}, + {0x30ED,"16F15275\r\n",0}, + {0x30EE,"16F15274\r\n",0}, + {0x30EF,"16F15255\r\n",0}, + {0x30F0,"16F15254\r\n",0}, + {0x30F1,"16F18013\r\n",0}, + {0x30F2,"16F18014\r\n",0}, + {0x30F3,"16F18023\r\n",0}, + {0x30F4,"16F18024\r\n",0}, + {0x30F5,"16F18015\r\n",0}, + {0x30F6,"16F18025\r\n",0}, + {0x30F7,"16F18044\r\n",0}, + {0x30F8,"16F18045\r\n",0}, + {0x30F9,"16F18026\r\n",0}, + {0x30FA,"16F18046\r\n",0}, + {0x30FB,"16F18054\r\n",0}, + {0x30FC,"16F18055\r\n",0}, + {0x30FD,"16F18074\r\n",0}, + {0x30FE,"16F18075\r\n",0}, + {0x30FF,"16F18056\r\n",0}, + {0x3100,"16F18076\r\n",0}, + {0x3107,"16F18114\r\n",0}, + {0x3108,"16F18124\r\n",0}, + {0x3109,"16F18144\r\n",0}, + {0x310A,"16F18154\r\n",0}, + {0x310B,"16F18174\r\n",0}, + {0x310C,"16F18115\r\n",0}, + {0x310D,"16F18125\r\n",0}, + {0x310E,"16F18145\r\n",0}, + {0x310F,"16F18155\r\n",0}, + {0x3110,"16F18175\r\n",0}, + {0x3111,"16F18126\r\n",0}, + {0x3112,"16F18146\r\n",0}, + {0x3113,"16F18156\r\n",0}, + {0x3114,"16F18176\r\n",0}, + {0x3101,"16F17154\r\n",0}, + {0x3102,"16F17174\r\n",0}, + {0x3103,"16F17155\r\n",0}, + {0x3104,"16F17175\r\n",0}, + {0x3105,"16F17156\r\n",0}, + {0x3106,"16F17176\r\n",0}, +}; + +void PIC16_ID(int id) +{ + char s[64]; + int i; + for(i=0;i>5)==PIC16LIST[i].id){ //id + rev in same location + sprintf(s,PIC16LIST[i].device,id&PIC16LIST[i].revmask); + PrintMessage(s); + return; + } + else if(!PIC16LIST[i].revmask&&id==PIC16LIST[i].id){ //id separate from rev + sprintf(s,PIC16LIST[i].device); + PrintMessage(s); + return; + } + } + sprintf(s,"%s",strings[S_nodev]); //"Unknown device\r\n"); + PrintMessage(s); +} + +void DisplayCODE16F(int size){ +// display 14 bit PIC CODE memory + char s[256]="",t[256]=""; + char* aux=(char*)malloc((size/COL+1)*(16+COL*5)); + aux[0]=0; + int valid=0,empty=1,i,j,lines=0; + for(i=0;i500){ //limit number of lines printed + strcat(aux,"(...)\r\n"); + i=(sizeW eeprom @ 0x2200 +// vdd=0 -> vpp before vdd +// vdd=1 -> vdd (+50ms) before vpp +// vdd=2 -> vdd before vpp +// DevREV@0x2005 +// DevID@0x2006 +// Config@0x2007 +// Calib1/Config2@0x2008 +// Calib2/Calib1@0x2009 +// eeprom@0x2100 +{ + int k=0,k2=0,z=0,i,j,ee2200=0; + char s[512],t[256],*aux; + if(dim2<0){ + dim2=-dim2; + ee2200=1; + } + if(dim>0x2000||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size exceeds limits\r\n" + return; + } + if(dim2>0x400||dim2<0){ //Max 1K + PrintMessage(strings[S_EELim]); //"EEPROM size exceeds limits\r\n" + return; + } + if(dim3>0x100||dim3<0){ + PrintMessage(strings[S_ConfigLim]); //"Config area size exceeds limits\r\n" + return; + } + if(dim3<8)dim3=8; + if(saveLog){ + OpenLogFile(); //"log.txt" + fprintf(logfile,"Read16Fxxx(%d,%d,%d,%d)\n",dim,dim2,dim3,vdd); + } + sizeW=0x2100+dim2; + if(memCODE_W) free(memCODE_W); + memCODE_W=(WORD*)malloc(sizeof(WORD)*sizeW); + unsigned int start=GetTickCount(); + j=0; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T1T2; + bufferU[j++]=1; //T1=1u + bufferU[j++]=100; //T2=100u + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=2000>>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + if(vdd==0){ //VPP before VDD + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=4; //VPP + bufferU[j++]=NOP; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x5; //VDD+VPP + } + else if(vdd==1){ //VDD before VPP with delay 50ms + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=1; //VDD + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=25000>>8; + bufferU[j++]=25000&0xff; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=2000>>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x5; //VDD+VPP + } + else if(vdd==2){ //VDD before VPP without delay + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=1; //VDD + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x5; //VDD+VPP + } + bufferU[j++]=FLUSH; + for(;jDIMBUF*2/4-3||i==dim-1){ //2B cmd -> 4B data + bufferU[j++]=FLUSH; + for(;jDIMBUF*2/4-3||i==0x2000+dim3-1){ //2B cmd -> 4B data + bufferU[j++]=FLUSH; + for(;jDIMBUF*2/3-3||i==0x2100+dim2-1){ //2B cmd -> 3B data + bufferU[j++]=FLUSH; + for(;j8){ + PrintMessage1(strings[S_Config2Cal1],memCODE_W[0x2008]); //"Config2 or Cal1: 0x%04X\r\n" + } + if(dim3>9){ + PrintMessage1(strings[S_Calib1_2],memCODE_W[0x2009]); //"Calibration word 1 or 2: 0x%04X\r\n" + } + PrintMessage(strings[S_CodeMem2]); //"\r\nCode memory\r\n" + DisplayCODE16F(dim); + s[0]=0; + int valid=0,empty=1; + if(dim3>8){ + aux=(char*)malloc((dim3/COL+1)*(16+COL*5)); + aux[0]=0; + empty=1; + PrintMessage(strings[S_ConfigResMem]); //"\r\nConfig and reserved memory:\r\n" + for(i=0x2000;i<0x2000+dim3;i+=COL){ + valid=0; + for(j=i;j vpp before vdd +// bit0=1 -> vdd before vpp +// bit1=1 -> LVP programming +// bit2=1 -> Config3@0x8009 +// bit3=1 -> Config4@0x800A +// bit4=1 -> PIC16F18xxx (calib words @0xE000 + new commands) +// DevREV@0x8005 DevID@0x8006 +// Config1@0x8007 Config2@0x8008 +// Config3@0x8009 Config4@0x800A +// Calib1@0x8009/A Calib2@0x800A/B Calib3@0x800B/C +// eeprom@0x0 or 0xF000 +{ + int k=0,k2=0,z=0,i,j; + int F18x=options&16; + if(F18x&&FWVersion<0xA00){ //only for 16F18xxx + PrintMessage1(strings[S_FWver2old],"0.10.0"); //"This firmware is too old. Version %s is required\r\n" + return; + } + if(!CheckV33Regulator()){ + PrintMessage(strings[S_noV33reg]); //Can't find 3.3V expansion board + return; + } + char s[256],t[256],*aux; + if(dim>0x8000||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size exceeds limits\r\n" + return; + } + if(dim2>0x400||dim2<0){ //Max 1K + PrintMessage(strings[S_EELim]); //"EEPROM size exceeds limits\r\n" + return; + } + if(dim3>0x200||dim3<0){ + PrintMessage(strings[S_ConfigLim]); //"Config area size exceeds limits\r\n" + return; + } + if(dim3<11)dim3=11; //at least config1-2 + calib1-2 + if(saveLog){ + OpenLogFile(); //"Log.txt" + fprintf(logfile,"Read16F1xxx(%d,%d,%d,%d)\n",dim,dim2,dim3,options); + } + if((options&2)==0){ //HV entry + if(!StartHVReg(8.5)){ + PrintMessage(strings[S_HVregErr]); //"HV regulator error\r\n" + return; + } + else hvreg=8.5; + } + else StartHVReg(-1); //LVP mode, turn off HV + sizeW=0x8200; + if(F18x) sizeW=0xE004; + sizeEE=dim2; + if(memCODE_W) free(memCODE_W); + memCODE_W=(WORD*)malloc(sizeof(WORD)*sizeW); + for(i=0;i>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + if((options&2)==0){ //HV entry + if((options&1)==0){ //VPP before VDD + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=4; //VPP + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x5; //VDD+VPP + } + else{ //VDD before VPP without delay + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=1; //VDD + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x5; //VDD+VPP + } + } + else{ //Low voltage programming + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=4; //VPP + bufferU[j++]=WAIT_T3; + bufferU[j++]=TX16; //0000 1010 0001 0010 1100 0010 1011 0010 = 0A12C2B2 + bufferU[j++]=2; + bufferU[j++]=0x0A; + bufferU[j++]=0x12; + bufferU[j++]=0xC2; + bufferU[j++]=0xB2; + bufferU[j++]=SET_CK_D; //Clock pulse + bufferU[j++]=0x4; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + } + bufferU[j++]=FLUSH; + for(;jDIMBUF*2/4-3||i==dim-1){ //2B cmd -> 4B data + bufferU[j++]=FLUSH; //remember: FLUSH generates a response even empty! + for(;jDIMBUF*2/4-3||i==0x8000+dim3-1){ //2B cmd -> 4B data + bufferU[j++]=FLUSH; + for(;jDIMBUF*2/3-3||i==dim2-1){ //2B cmd -> 3B data + bufferU[j++]=FLUSH; + for(;jDIMBUF/3-3||i==dim2-1){ //1B cmd -> 3B answer + bufferU[j++]=FLUSH; + for(;j15){ + int valid=0,empty=1; + s[0]=0; + aux=(char*)malloc(dim3/COL*(16+COL*5)); + aux[0]=0; + empty=1; + PrintMessage(strings[S_ConfigResMem]); //"\r\nConfig and reserved memory:\r\n" + for(i=0x8000;i<0x8000+dim3;i+=COL){ + valid=0; + for(j=i;j0 use eeprom, size is automatic when reading DCI +// dim3=not used +// options: +// bit0=0 -> vpp before vdd +// bit0=1 -> vdd before vpp +// bit1=1 -> LVP programming +// bit4=1 -> do not use DIA&DCI +// DevREV@0x8005 DevID@0x8006 +// Config1@0x8007 Config2@0x8008 ... +// Device info area @0x8100 +// Device configuration info area @0x8200 +{ + int k=0,k2=0,z=0,i,j; + int useDCI=(options&0x10)==0?1:0; + if(FWVersion<0xB00){ //only for 16F18xxx + PrintMessage1(strings[S_FWver2old],"0.11.0"); //"This firmware is too old. Version %s is required\r\n" + return; + } + if(!CheckV33Regulator()){ + PrintMessage(strings[S_noV33reg]); //Can't find 3.3V expansion board + return; + } + char s[256],t[256],*aux; + if(dim>0x8000||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size exceeds limits\r\n" + return; + } + if(saveLog){ + OpenLogFile(); //"Log.txt" + fprintf(logfile,"Read16F18xxx(%d,%d,%d,%d)\n",dim,dim2,dim3,options); + } + if((options&2)==0){ //HV entry + if(!StartHVReg(8.5)){ + PrintMessage(strings[S_HVregErr]); //"HV regulator error\r\n" + return; + } + else hvreg=8.5; + } + else StartHVReg(-1); //LVP mode, turn off HV + sizeW=0x8220; + if(memCODE_W) free(memCODE_W); + memCODE_W=(WORD*)malloc(sizeof(WORD)*sizeW); + for(i=0;i>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + if((options&2)==0){ //HV entry + if((options&1)==0){ //VPP before VDD + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=4; //VPP + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x5; //VDD+VPP + } + else{ //VDD before VPP without delay + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=1; //VDD + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x5; //VDD+VPP + } + } + else{ //Low voltage programming + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=4; //VPP + bufferU[j++]=WAIT_T3; + bufferU[j++]=TX16; //0000 1010 0001 0010 1100 0010 1011 0010 = 0A12C2B2 + bufferU[j++]=2; + bufferU[j++]=0x0A; + bufferU[j++]=0x12; + bufferU[j++]=0xC2; + bufferU[j++]=0xB2; + bufferU[j++]=SET_CK_D; //Clock pulse + bufferU[j++]=0x4; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + } + bufferU[j++]=FLUSH; + for(;jDIMBUF||i==dim-1){ //2B cmd -> 3B data + bufferU[j++]=FLUSH; //remember: FLUSH generates a response (even empty)! + for(;jDIMBUF||i==0x800F){ //2B cmd -> 3B data + bufferU[j++]=FLUSH; + for(;jDIMBUF||i==0x811F){ //2B cmd -> 3B data + bufferU[j++]=FLUSH; + for(;jDIMBUF||i==0x821F){ //2B cmd -> 3B data + bufferU[j++]=FLUSH; + for(;j0x1000||dim2<0){ //Max 4K + PrintMessage(strings[S_EELim]); //"EEPROM size exceeds limits\r\n" + return; + } + sizeEE=dim2; + if(memEE) free(memEE); + memEE=(unsigned char*)malloc(sizeEE); //EEPROM + for(i=0;iDIMBUF||i==dim2-1){ //2B cmd -> 3B answer + bufferU[j++]=FLUSH; + for(;j%d Flash words\r\n",memCODE_W[0x8200]*memCODE_W[0x8202]); + PrintMessage1("EE data memory size: %d\r\n",memCODE_W[0x8203]); + PrintMessage1("Pin count: %d\r\n",memCODE_W[0x8204]); + if(dim!=memCODE_W[0x8200]*memCODE_W[0x8202]) PrintMessage(strings[S_WarnFlashSize]); //"Warning, flash size is different from the expected value" + } + PrintMessage(strings[S_CodeMem2]); //"\r\nCode memory:\r\n" + DisplayCODE16F(dim); + if(dim2) DisplayEE(); //visualize + sprintf(str,strings[S_End],(stop-start)/1000.0); //"\r\nEnd (%.2f s)\r\n" + PrintMessage(str); + if(saveLog){ + fprintf(logfile,str); + CloseLogFile(); + } + PrintStatusClear(); //clear status report +} + +void Write12F6xx(int dim,int dim2) +// write 14 bit PIC +// dim=program size dim2=eeprom size +// vpp before vdd +// DevID@0x2006 +// Config@0x2007 +// Calib1@0x2008 (save) +// Calib2@0x2009 (save) +// eeprom@0x2100 +// erase: BULK_ERASE_PROG (1001) +10ms +// write:LOAD_DATA_PROG (0010) + BEGIN_PROG (1000) + 4ms +// eeprom: BULK_ERASE_DATA (1011) + 16ms +// LOAD_DATA_DATA (0011) + BEGIN_PROG (1000) + 8ms +// verify during write +{ + int err=0; + WORD devID=0x3fff,calib1=0x3fff,calib2=0x3fff; + int k=0,z=0,i,j,w; + if(sizeW<0x2007){ + PrintMessage(strings[S_NoConfigW3]); //"Can't find CONFIG (0x2007)\r\nEnd\r\n" + return; + } + if(load_calibword){ + if(sizeW>0x2009) load_calibword=2; + else if(sizeW>0x2008) load_calibword=1; + else{ + PrintMessage(strings[S_NoCalibW]); //"Can't find calibration data\r\n" + load_calibword=0; + } + } + if(dim2){ + if(sizeW<0x2100){ + dim2=0; + PrintMessage(strings[S_NoEEMem]); //"Can't find EEPROM data\r\n" + } + else if(dim2>sizeW-0x2100) dim2=sizeW-0x2100; + } + if(saveLog){ + OpenLogFile(); //"log.txt" + fprintf(logfile,"Write12F6xx(%d,%d)\n",dim,dim2); + } + for(i=0;i<0x2009&&i>8; + bufferU[j++]=10000&0xff; + bufferU[j++]=WAIT_T3; //delay after exiting prog mode + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=4000&0xff; + bufferU[j++]=FLUSH; + for(;j>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 4ms + bufferU[j++]=READ_DATA_PROG; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-12||i==dim-1){ + PrintStatus(strings[S_CodeWriting],i*100/dim,i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0x3fff) k++; + else if(bufferI[z]==LOAD_DATA_PROG&&bufferI[z+3]==READ_DATA_PROG){ + if (memCODE_W[k]!=(bufferI[z+4]<<8)+bufferI[z+5]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError2],k,memCODE_W[k],(bufferI[z+4]<<8)+bufferI[z+5]); //"Error writing address %3X: written %04X, read %04X\r\n" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim; + z=DIMBUF; + } + } + k++; + z+=6; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d,\n" + } + } + } + err+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" +//****************** write eeprom ******************** + if(dim2){ + int err_e=0; + PrintMessage(strings[S_EEAreaW]); //"Writing EEPROM ... " + PrintStatusSetup(); + j=0; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=8000>>8; + bufferU[j++]=8000&0xff; + bufferU[j++]=BULK_ERASE_DATA; + bufferU[j++]=WAIT_T3; // delay T3=8ms + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + bufferU[j++]=INC_ADDR_N; //use only INC_ADDR_N so verification does not look at it + bufferU[j++]=1; + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=0x2100-0x2001; //EEPROM area: counter at 0x2100 + for(w=2,i=k=0x2100;i<0x2100+dim2;i++){ + if(memCODE_W[i]<0xff){ + bufferU[j++]=LOAD_DATA_DATA; + bufferU[j++]=memCODE_W[i]&0xff; + bufferU[j++]=BEGIN_PROG; //internally timed, T=6ms min + bufferU[j++]=WAIT_T3; //Tprogram 8ms + bufferU[j++]=READ_DATA_DATA; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-12||i==0x2100+dim2-1){ + PrintStatus(strings[S_CodeWriting],(i-0x2100+dim)*100/(dim+dim2),i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0xff) k++; + else if(bufferI[z]==LOAD_DATA_DATA&&bufferI[z+3]==READ_DATA_DATA){ + if (memCODE_W[k]!=bufferI[z+4]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError3],k,memCODE_W[k],bufferI[z+4]); //"Error writing address %4X: written %02X, read %02X\r\n" + err_e++; + if(max_err&&err+err_e>max_err){ + PrintMessage1(strings[S_MaxErr],err+err_e); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=0x2200; + z=DIMBUF; + } + } + k++; + z+=5; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d \n" + } + } + } + err_e+=i-k; + err+=err_e; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err_e); //"completed, %d errors\r\n" + } +//****************** write ID, CONFIG, CALIB ******************** + PrintMessage(strings[S_ConfigAreaW]); //"Writing CONFIG area ... " + int err_c=0; + int ICDgoto=0x2800+(ICDaddr&0x7FF); //GOTO ICD routine (0x28xx) + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=4000>>8; + bufferU[j++]=4000&0xff; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + if(programID){ + for(i=0x2000;i<0x2004;i++){ + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=memCODE_W[i]>>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 4ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + } + } + else{ + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=4; + } + if(ICDenable){ //write a GOTO ICD routine (0x28xx) + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=ICDgoto>>8; //MSB + bufferU[j++]=ICDgoto&0xFF; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=READ_DATA_PROG; + } + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=3; + bufferU[j++]=LOAD_DATA_PROG; //Config word 0x2007 + bufferU[j++]=memCODE_W[0x2007]>>8; //MSB + bufferU[j++]=memCODE_W[0x2007]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 4ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + if(load_calibword){ + bufferU[j++]=LOAD_DATA_PROG; //Calib word 1 + bufferU[j++]=memCODE_W[0x2008]>>8; //MSB + bufferU[j++]=memCODE_W[0x2008]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 4ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + bufferU[j++]=LOAD_DATA_PROG; //Calib word 2 + bufferU[j++]=memCODE_W[0x2009]>>8; //MSB + bufferU[j++]=memCODE_W[0x2009]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 4ms + bufferU[j++]=READ_DATA_PROG; + } + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;jsizeW-0x2100) dim2=sizeW-0x2100; + } + if(saveLog){ + OpenLogFile(); //"log.txt" + fprintf(logfile,"Write16F8x(%d,%d)\n",dim,dim2); + } + for(i=0;i<0x2009&&i>8; + bufferU[j++]=25000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=NOP; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=0x06; + bufferU[j++]=READ_DATA_PROG; //DevID + bufferU[j++]=INC_ADDR; + bufferU[j++]=READ_DATA_PROG; //Config + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; //delay after exiting prog mode + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=WAIT_T3; //50ms + bufferU[j++]=WAIT_T3; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=NOP; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=10000&0xff; + if(config<0x3FF0){ + PrintMessage(strings[S_ProtErase]); //"Override write protection\r\n" + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0x3F; //fake config + bufferU[j++]=0xFF; //fake config + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=0x07; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x01; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x07; + bufferU[j++]=BEGIN_PROG; + bufferU[j++]=WAIT_T3; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x01; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x07; + } + else if(devID>>5==0x2B){ //16F84A + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=0x3f; //MSB + bufferU[j++]=0xff; //LSB + bufferU[j++]=BULK_ERASE_PROG; + bufferU[j++]=BEGIN_PROG; + bufferU[j++]=WAIT_T3; + if(dim2){ + bufferU[j++]=LOAD_DATA_DATA; + bufferU[j++]=0xff; //LSB + bufferU[j++]=BULK_ERASE_DATA; + bufferU[j++]=BEGIN_PROG; + bufferU[j++]=WAIT_T3; + } + } + else{ //altri + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=0x3f; //MSB + bufferU[j++]=0xff; //LSB + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x01; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x07; + bufferU[j++]=BEGIN_PROG; + bufferU[j++]=WAIT_T3; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x01; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x07; + if(dim2){ + bufferU[j++]=LOAD_DATA_DATA; //EEPROM: spec error? + bufferU[j++]=0xff; //LSB + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x01; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x07; + bufferU[j++]=BEGIN_PROG; + bufferU[j++]=WAIT_T3; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x01; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x07; + } + } + if(!programID){ //back to program memory + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; //delay after exiting prog mode + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=WAIT_T3; //50ms + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + } + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + r=(devID>>5==0x2B)?8000:20000; + bufferU[j++]=r>>8; + bufferU[j++]=r&0xff; + bufferU[j++]=FLUSH; + r/=1000; + for(;j>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=READ_DATA_PROG; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-10||i==dim-1){ + PrintStatus(strings[S_CodeWriting],i*100/dim,i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0x3fff) k++; + else if(bufferI[z]==LOAD_DATA_PROG&&bufferI[z+3]==READ_DATA_PROG){ + if (memCODE_W[k]!=(bufferI[z+4]<<8)+bufferI[z+5]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError2],k,memCODE_W[k],(bufferI[z+4]<<8)+bufferI[z+5]); //"Error writing address %3X: written %04X, read %04X\r\n" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim; + z=DIMBUF; + } + } + k++; + z+=6; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d \n" + } + } + } + err+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" +//****************** write eeprom ******************** + if(dim2){ + PrintMessage(strings[S_EEAreaW]); //"Writing EEPROM ... " + PrintStatusSetup(); + j=0; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + bufferU[j++]=INC_ADDR_N; //use only INC_ADDR_N so verification does not look at it + bufferU[j++]=0xFF; + bufferU[j++]=INC_ADDR_N; //EEPROM: counter at 0x2100 + bufferU[j++]=1; + for(w=0,i=k=0x2100;i<0x2100+dim2;i++){ + if(memCODE_W[i]<0xff){ + bufferU[j++]=LOAD_DATA_DATA; + bufferU[j++]=memCODE_W[i]&0xff; + bufferU[j++]=BEGIN_PROG; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=READ_DATA_DATA; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-10||i==0x2100+dim2-1){ + PrintStatus(strings[S_CodeWriting],(i-0x2100+dim)*100/(dim+dim2),i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0xff) k++; + else if(bufferI[z]==LOAD_DATA_DATA&&bufferI[z+3]==READ_DATA_DATA){ + if (memCODE_W[k]!=bufferI[z+4]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError3],k,memCODE_W[k],bufferI[z+4]); //"Error writing address %4X: written %02X, read %02X\r\n" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=0x2200; + z=DIMBUF; + } + } + k++; + z+=5; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d \n" + } + } + } + err+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],i-k); //"completed, %d errors\r\n" + } +//****************** write ID, CONFIG ******************** + PrintMessage(strings[S_ConfigAreaW]); //"Writing CONFIG area ... " + int err_c=0; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + if(programID){ + for(i=0x2000;i<0x2004;i++){ + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=memCODE_W[i]>>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + } + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=3; + } + else{ + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=7; + } + bufferU[j++]=LOAD_DATA_PROG; //Config word 0x2007 + bufferU[j++]=memCODE_W[0x2007]>>8; //MSB + bufferU[j++]=memCODE_W[0x2007]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed + bufferU[j++]=WAIT_T3; + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=FLUSH; + for(;jsizeW-0x2100) dim2=sizeW-0x2100; + } + if(saveLog){ + OpenLogFile(); //"log.txt" + fprintf(logfile,"Write16F62x(%d,%d)\n",dim,dim2); + } + for(i=0;i<0x2009&&i>8; + bufferU[j++]=10000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=EN_VPP_VCC; //VPP + bufferU[j++]=0x4; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=NOP; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=0x06; + bufferU[j++]=READ_DATA_PROG; //DevID + bufferU[j++]=INC_ADDR; + bufferU[j++]=READ_DATA_PROG; //Config + bufferU[j++]=EN_VPP_VCC; //VPP + bufferU[j++]=0x4; + bufferU[j++]=EN_VPP_VCC; //0 + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; //delay exit-enter prog mode + bufferU[j++]=EN_VPP_VCC; //VPP + bufferU[j++]=0x4; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=5000&0xff; + if(config<0x3C00){ + PrintMessage(strings[S_ProtErase]); //"Override write protection\r\n" + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0x3F; //fake config spec ERROR!!! is written data=0!! + bufferU[j++]=0xFF; //fake config + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=0x07; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x01; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x07; + bufferU[j++]=BEGIN_PROG; //Tera+Tprog=5+8 ms + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x01; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x07; + } + else{ + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=0x3f; //MSB + bufferU[j++]=0xff; //LSB + bufferU[j++]=BULK_ERASE_PROG; + bufferU[j++]=BEGIN_PROG; //Tera=5ms + bufferU[j++]=WAIT_T3; + if(dim2){ + bufferU[j++]=LOAD_DATA_DATA; + bufferU[j++]=0xff; //LSB + bufferU[j++]=BULK_ERASE_DATA; + bufferU[j++]=BEGIN_PROG; //Tera=5ms + bufferU[j++]=WAIT_T3; + } + } + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; //delay after exiting prog mode + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x4; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=8000>>8; + bufferU[j++]=8000&0xff; + bufferU[j++]=FLUSH; + for(;j>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //program only, internally timed + bufferU[j++]=WAIT_T3; //Tprogram=8ms + bufferU[j++]=READ_DATA_PROG; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-10||i==dim-1){ + PrintStatus(strings[S_CodeWriting],i*100/dim,i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0x3fff) k++; + else if(bufferI[z]==LOAD_DATA_PROG&&bufferI[z+3]==READ_DATA_PROG){ + if (memCODE_W[k]!=(bufferI[z+4]<<8)+bufferI[z+5]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError2],k,memCODE_W[k],(bufferI[z+4]<<8)+bufferI[z+5]); //"Error writing address %3X: written %04X, read %04X\r\n" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim; + z=DIMBUF; + } + } + k++; + z+=6; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d \n" + } + } + } + err+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" +//****************** write eeprom ******************** + if(dim2){ + PrintMessage(strings[S_EEAreaW]); //"Writing EEPROM ... " + PrintStatusSetup(); + j=0; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + bufferU[j++]=INC_ADDR_N; //use only INC_ADDR_N so verification does not look at it + bufferU[j++]=0xFF; //20FF + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=0xFF; //21FE + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=0x2; //EEPROM: counter at 0x2200 + for(w=0,i=k=0x2100;i<0x2100+dim2;i++){ + if(memCODE_W[i]<0xff){ + bufferU[j++]=LOAD_DATA_DATA; + bufferU[j++]=memCODE_W[i]&0xff; + bufferU[j++]=BEGIN_PROG2; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram=8ms + bufferU[j++]=READ_DATA_DATA; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-10||i==0x2100+dim2-1){ + PrintStatus(strings[S_CodeWriting],(i-0x2100+dim)*100/(dim+dim2),i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0xff) k++; + else if(bufferI[z]==LOAD_DATA_DATA&&bufferI[z+3]==READ_DATA_DATA){ + if (memCODE_W[k]!=bufferI[z+4]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError3],k,memCODE_W[k],bufferI[z+4]); //"Error writing address %4X: written %02X, read %02X\r\n" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=0x2200; + z=DIMBUF; + } + } + k++; + z+=5; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d \n" + } + } + } + err+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],i-k); //"completed, %d errors\r\n" + } +//****************** write ID, CONFIG ******************** + PrintMessage(strings[S_ConfigAreaW]); //"Writing CONFIG area ... " + int err_c=0; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + if(programID){ + for(i=0x2000;i<0x2004;i++){ + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=memCODE_W[i]>>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //erase + prog internally timed, T=8+5 ms + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + } + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=3; + } + else{ + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=7; + } + bufferU[j++]=LOAD_DATA_PROG; //Config word 0x2007 + bufferU[j++]=memCODE_W[0x2007]>>8; //MSB + bufferU[j++]=memCODE_W[0x2007]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //prog only, internally timed, T=8 ms + bufferU[j++]=WAIT_T3; //Tprogram 8ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=FLUSH; + for(;jsizeW-0x2100) dim2=sizeW-0x2100; + } + if(saveLog){ + OpenLogFile(); //"log.txt" + fprintf(logfile,"Write12F62x(%d,%d)\n",dim,dim2); + } + for(i=0;i>8; + bufferU[j++]=10000&0xff; + bufferU[j++]=WAIT_T3; //delay after exiting prog mode + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=3000&0xff; + bufferU[j++]=FLUSH; + for(;j>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms + bufferU[j++]=WAIT_T3; //Tprogram 3ms + bufferU[j++]=READ_DATA_PROG; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-10||i==dim-1){ + PrintStatus(strings[S_CodeWriting],i*100/dim,i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0x3fff) k++; + else if(bufferI[z]==LOAD_DATA_PROG&&bufferI[z+3]==READ_DATA_PROG){ + if (memCODE_W[k]!=(bufferI[z+4]<<8)+bufferI[z+5]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError2],k,memCODE_W[k],(bufferI[z+4]<<8)+bufferI[z+5]); //"Error writing address %3X: written %04X, read %04X\r\n" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim; + z=DIMBUF; + } + } + k++; + z+=6; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d \n" + } + } + } + PrintStatusEnd(); + err+=i-k; + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" +//****************** write eeprom ******************** + if(dim2){ + PrintMessage(strings[S_EEAreaW]); //"Writing EEPROM ... " + PrintStatusSetup(); + j=0; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=6000>>8; + bufferU[j++]=6000&0xff; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + bufferU[j++]=INC_ADDR_N; //use only INC_ADDR_N so verification does not look at it + bufferU[j++]=0xFF; + bufferU[j++]=INC_ADDR_N; //EEPROM: counter at 0x2100 + bufferU[j++]=1; + bufferU[j++]=BULK_ERASE_DATA; + bufferU[j++]=WAIT_T3; // delay=12ms + bufferU[j++]=WAIT_T3; + for(w=3,i=k=0x2100;i<0x2100+dim2;i++){ + if(memCODE_W[i]<0xff){ + bufferU[j++]=LOAD_DATA_DATA; + bufferU[j++]=memCODE_W[i]&0xff; + bufferU[j++]=BEGIN_PROG; //internally timed, T=6ms + bufferU[j++]=WAIT_T3; //Tprogram 6ms + bufferU[j++]=READ_DATA_DATA; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-10||i==0x2100+dim2-1){ + PrintStatus(strings[S_CodeWriting],(i-0x2100+dim)*100/(dim+dim2),i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0xff) k++; + else if(bufferI[z]==LOAD_DATA_DATA&&bufferI[z+3]==READ_DATA_DATA){ + if (memCODE_W[k]!=bufferI[z+4]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError3],k,memCODE_W[k],bufferI[z+4]); //"Error writing address %4X: written %02X, read %02X\r\n" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=0x2200; + z=DIMBUF; + } + } + k++; + z+=5; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d \n" + } + } + } + err+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],i-k); //"completed, %d errors\r\n" + } +//****************** write ID, CONFIG, CALIB ******************** + PrintMessage(strings[S_ConfigAreaW]); //"Writing CONFIG area ... " + int err_c=0; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + if(programID){ + for(i=0x2000;i<0x2004;i++){ + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=memCODE_W[i]>>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms + bufferU[j++]=WAIT_T3; //Tprogram 3ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + } + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=3; + } + else{ + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=7; + } + if(!load_calibword) memCODE_W[0x2007]=(memCODE_W[0x2007]&0xfff)+(config&0x3000); + bufferU[j++]=LOAD_DATA_PROG; //Config word 0x2007 + bufferU[j++]=memCODE_W[0x2007]>>8; //MSB + bufferU[j++]=memCODE_W[0x2007]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms + bufferU[j++]=WAIT_T3; //Tprogram 3ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; //exit program mode + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j eeprom @ 0x2200 +// vdd + (50ms?) + vdd&vpp +// DevID@0x2006 +// Config@0x2007 +// eeprom@0x2100 +// erase if protected: +// LOAD_CONF (0000)(0x3FFF) + CUST_CMD (0001) + CUST_CMD (0111) +// + BEGIN_PROG (1000) + 8ms +// + CUST_CMD (0001) + CUST_CMD (0111) +// erase if not protected: +// LOAD_DATA_PROG (0010)(0x3FFF) + CUST_CMD (0001) + CUST_CMD (0111) +// + BEGIN_PROG (1000) + 8ms + CUST_CMD (0001) + CUST_CMD (0111) +// LOAD_DATA_DATA (0011)(0xFF) + CUST_CMD (0001) + CUST_CMD (0111) +// + BEGIN_PROG (1000) + 8ms + CUST_CMD (0001) + CUST_CMD (0111) +// write: LOAD_DATA_PROG (0010) + BEGIN_PROG2 (11000) + 4ms +// write eeprom: LOAD_DATA_DATA (0011) + BEGIN_PROG (1000) + 8ms +// verify during write +{ + int err=0; + WORD devID,config; + int k=0,z=0,i,j,w,ee2200=0; + if(dim2<0){ + dim2=-dim2; + ee2200=1; + } + if(sizeW<0x2007){ + PrintMessage(strings[S_NoConfigW3]); //"Can't find CONFIG (0x2007)\r\nEnd\r\n" + return; + } + if(dim2){ + if(sizeW<0x2100){ + dim2=0; + PrintMessage(strings[S_NoEEMem]); //"Can't find EEPROM data\r\n" + } + else if(dim2>sizeW-0x2100) dim2=sizeW-0x2100; + } + if(saveLog){ + OpenLogFile(); //"log.txt" + fprintf(logfile,"Write16F87x(%d,%d)\n",dim,dim2); + } + for(i=0;i>8; + bufferU[j++]=8000&0xff; + if((config&0x3130)!=0x3130){ + PrintMessage(strings[S_ProtErase]); //"override write protection\r\n" + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0x3F; //fake config + bufferU[j++]=0xFF; //fake config + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=0x07; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x01; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x07; + bufferU[j++]=BEGIN_PROG; + bufferU[j++]=WAIT_T3; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x01; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x07; + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; //delay after exiting prog mode + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + } + else{ + if(ICDenable||programID){ //erase 0x2000-2004 also + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0x3F; //fake config + bufferU[j++]=0xFF; //fake config + } + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=0x3f; //MSB + bufferU[j++]=0xff; //LSB + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x01; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x07; + bufferU[j++]=BEGIN_PROG; + bufferU[j++]=WAIT_T3; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x01; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x07; + if(dim2){ + bufferU[j++]=LOAD_DATA_DATA; //EEPROM: spec error? + bufferU[j++]=0xff; //LSB + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x01; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x07; + bufferU[j++]=BEGIN_PROG; + bufferU[j++]=WAIT_T3; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x01; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x07; + } + if(ICDenable||programID){ //back to addr 0 + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; //delay after exiting prog mode + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + } + } + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=4000>>8; + bufferU[j++]=4000&0xff; + bufferU[j++]=FLUSH; + for(;j>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=READ_DATA_PROG; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-10||i==dim-1){ + PrintStatus(strings[S_CodeWriting],i*100/dim,i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0x3fff) k++; + else if(bufferI[z]==LOAD_DATA_PROG&&bufferI[z+3]==READ_DATA_PROG){ + if (memCODE_W[k]!=(bufferI[z+4]<<8)+bufferI[z+5]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError2],k,memCODE_W[k],(bufferI[z+4]<<8)+bufferI[z+5]); //"Error writing address %3X: written %04X, read %04X\r\n" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim; + z=DIMBUF; + } + } + k++; + z+=6; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d \n" + } + } + } + err+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" +//****************** write eeprom ******************** + if(dim2){ + int err_e=0; + PrintMessage(strings[S_EEAreaW]); //"Writing EEPROM ... " + PrintStatusSetup(); + j=0; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + bufferU[j++]=INC_ADDR_N; //use only INC_ADDR_N so verification does not look at it + bufferU[j++]=0xFF; + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=1; //EEPROM: counter at 0x2100 + if(ee2200){ //eeprom at 0x2200 + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=0xFF; + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=1; + } + for(w=0,i=k=0x2100;i<0x2100+dim2;i++){ + if(memCODE_W[i]<0xff){ + bufferU[j++]=LOAD_DATA_DATA; + bufferU[j++]=memCODE_W[i]&0xff; + bufferU[j++]=BEGIN_PROG2; //internally timed ????? + bufferU[j++]=WAIT_T3; //Tprogram ????? + bufferU[j++]=READ_DATA_DATA; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-10||i==0x2100+dim2-1){ + PrintStatus(strings[S_CodeWriting],(i-0x2100+dim)*100/(dim+dim2),i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0xff) k++; + else if(bufferI[z]==LOAD_DATA_DATA&&bufferI[z+3]==READ_DATA_DATA){ + if (memCODE_W[k]!=bufferI[z+4]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError3],k,memCODE_W[k],bufferI[z+4]); //"Error writing address %4X: written %02X, read %02X\r\n" + err_e++; + if(max_err&&err+err_e>max_err){ + PrintMessage1(strings[S_MaxErr],err+err_e); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=0x2200; + z=DIMBUF; + } + } + k++; + z+=5; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d \n" + } + } + } + err_e+=i-k; + err+=err_e; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err_e); //"completed, %d errors\r\n" + } +//****************** write ID, CONFIG, CALIB ******************** + PrintMessage(strings[S_ConfigAreaW]); //"Writing CONFIG area ... " + int err_c=0; + int ICDgoto=0x2800+(ICDaddr&0x7FF); //GOTO ICD routine (0x28xx) + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=8000>>8; + bufferU[j++]=8000&0xff; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + if(programID){ + for(i=0x2000;i<0x2004;i++){ + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=memCODE_W[i]>>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + } + } + else{ + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=4; + } + if(ICDenable){ //write a GOTO ICD routine (0x28xx) + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=ICDgoto>>8; //MSB + bufferU[j++]=ICDgoto&0xFF; //LSB + bufferU[j++]=BEGIN_PROG2; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=READ_DATA_PROG; + } + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=3; + bufferU[j++]=LOAD_DATA_PROG; //Config word 0x2007 + bufferU[j++]=memCODE_W[0x2007]>>8; //MSB + bufferU[j++]=memCODE_W[0x2007]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //internally timed + bufferU[j++]=WAIT_T3; + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;jsizeW-0x2100) dim2=sizeW-0x2100; + } + if(saveLog){ + OpenLogFile(); //"log.txt" + fprintf(logfile,"Write16F87xA(%d,%d,%d)\n",dim,dim2,seq); + } + for(i=0;i>8; + bufferU[j++]=25000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + if(seq==0){ + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + } + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=NOP; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=0x06; + bufferU[j++]=READ_DATA_PROG; //DevID + bufferU[j++]=INC_ADDR; + bufferU[j++]=READ_DATA_PROG; //Config + bufferU[j++]=EN_VPP_VCC; //exit program mode + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; //delay after exiting prog mode + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=15000&0xff; + if(ICDenable||programID){ //erase 0x2000-2004 also + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0x3F; //fake config + bufferU[j++]=0xFF; //fake config + } + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x1F; // CHIP_ERASE (11111) + bufferU[j++]=WAIT_T3; + bufferU[j++]=EN_VPP_VCC; //exit program mode + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; //delay after exiting prog mode + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=1200>>8; + bufferU[j++]=1200&0xff; + bufferU[j++]=FLUSH; + for(;j>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //externally timed + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x17; //END_PROGX (10111) + bufferU[j++]=READ_DATA_PROG; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-11||i==dim-1){ + PrintStatus(strings[S_CodeWriting],i*100/dim,i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0x3fff) k++; + else if(bufferI[z]==LOAD_DATA_PROG&&bufferI[z+4]==READ_DATA_PROG){ + if (memCODE_W[k]!=(bufferI[z+5]<<8)+bufferI[z+6]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError2],k,memCODE_W[k],(bufferI[z+5]<<8)+bufferI[z+6]); //"Error writing address %3X: written %04X, read %04X\r\n" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim; + z=DIMBUF; + } + } + k++; + z+=7; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d \n" + } + } + } + err+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" +//****************** write eeprom ******************** + if(dim2){ + int err_e=0; + PrintMessage(strings[S_EEAreaW]); //"Writing EEPROM ... " + PrintStatusSetup(); + j=0; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=12000>>8; + bufferU[j++]=12000&0xff; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + bufferU[j++]=INC_ADDR_N; //use only INC_ADDR_N so verification does not look at it + bufferU[j++]=0xFF; + bufferU[j++]=INC_ADDR_N; //EEPROM: counter at 0x2100 + bufferU[j++]=1; + for(w=0,i=k=0x2100;i<0x2100+dim2;i++){ + if(memCODE_W[i]<0xff){ + bufferU[j++]=LOAD_DATA_DATA; + bufferU[j++]=memCODE_W[i]&0xff; + bufferU[j++]=BEGIN_PROG; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram 8ms + bufferU[j++]=READ_DATA_DATA; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-10||i==0x2100+dim2-1){ + PrintStatus(strings[S_CodeWriting],(i-0x2100+dim)*100/(dim+dim2),i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0xff) k++; + else if(bufferI[z]==LOAD_DATA_DATA&&bufferI[z+3]==READ_DATA_DATA){ + if (memCODE_W[k]!=bufferI[z+4]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError3],k,memCODE_W[k],bufferI[z+4]); //"Error writing address %4X: written %02X, read %02X\r\n" + err_e++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=0x2200; + z=DIMBUF; + } + } + k++; + z+=5; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d \n" + } + } + } + err_e+=i-k; + err+=err_e; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err_e); //"completed, %d errors\r\n" + } +//****************** write ID, CONFIG, CALIB ******************** + PrintMessage(strings[S_ConfigAreaW]); //"Writing CONFIG area ... " + int err_c=0; + int ICDgoto=0x2800+(ICDaddr&0x7FF); //GOTO ICD routine (0x28xx) + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=12000>>8; + bufferU[j++]=12000&0xff; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + if(programID){ + for(i=0x2000;i<0x2004;i++){ + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=memCODE_W[i]>>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + } + } + else{ + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=4; + } + if(ICDenable){ //write a GOTO ICD routine (0x28xx) + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=ICDgoto>>8; //MSB + bufferU[j++]=ICDgoto&0xFF; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=READ_DATA_PROG; + } + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=3; + bufferU[j++]=LOAD_DATA_PROG; //Config word 0x2007 + bufferU[j++]=memCODE_W[0x2007]>>8; //MSB + bufferU[j++]=memCODE_W[0x2007]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + if(sizeW>0x2008&&memCODE_W[0x2008]!=0x3fff){ + bufferU[j++]=LOAD_DATA_PROG; //Config word2 0x2008 + bufferU[j++]=memCODE_W[0x2008]>>8; //MSB + bufferU[j++]=memCODE_W[0x2008]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=READ_DATA_PROG; + } + bufferU[j++]=FLUSH; + for(;j0x2008&&memCODE_W[0x2008]!=0x3fff){ + for(z+=6;z>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;jsizeW-0x2100) dim2=sizeW-0x2100; + } + if(saveLog){ + OpenLogFile(); //"log.txt" + fprintf(logfile,"Write16F81x(%d,%d)\n",dim,dim2); + } + for(i=0;i>8; + bufferU[j++]=25000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=NOP; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=0x06; + bufferU[j++]=READ_DATA_PROG; //DevID + bufferU[j++]=INC_ADDR; + bufferU[j++]=READ_DATA_PROG; //Config + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; //delay after exiting prog mode + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=2000&0xff; + if(programID||ICDenable){ + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0x3F; //fake config + bufferU[j++]=0xFF; //fake config + } + if((config&0x2100)!=0x2100){ + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x1F; // CHIP_ERASE (11111) + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + } + else{ + bufferU[j++]=BULK_ERASE_PROG; + bufferU[j++]=BEGIN_PROG; + bufferU[j++]=WAIT_T3; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x17; //END_PROGX (10111) + } + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; //delay after exiting prog mode + bufferU[j++]=WAIT_T3; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=FLUSH; + for(;j>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //externally timed + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x17; //END_PROGX (10111) + bufferU[j++]=READ_DATA_PROG; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-11||i==dim-1){ + PrintStatus(strings[S_CodeWriting],i*100/dim,i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0x3fff) k++; + else if(bufferI[z]==LOAD_DATA_PROG&&bufferI[z+4]==READ_DATA_PROG){ + if (memCODE_W[k]!=(bufferI[z+5]<<8)+bufferI[z+6]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError2],k,memCODE_W[k],(bufferI[z+5]<<8)+bufferI[z+6]); //"Error writing address %3X: written %04X, read %04X\r\n" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim; + z=DIMBUF; + } + } + k++; + z+=7; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d \n" + } + } + } + err+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" +//****************** write eeprom ******************** + if(dim2){ + int err_e=0; + PrintMessage(strings[S_EEAreaW]); //"Writing EEPROM ... " + PrintStatusSetup(); + j=0; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; //delay after exiting prog mode + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=LOAD_DATA_DATA; + bufferU[j++]=0x01; + bufferU[j++]=BULK_ERASE_DATA; + bufferU[j++]=BEGIN_PROG; + bufferU[j++]=WAIT_T3; + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x17; //END_PROGX (10111) + bufferU[j++]=FLUSH; + for(;jDIMBUF-10||i==0x2100+dim2-1){ + PrintStatus(strings[S_CodeWriting],(i-0x2100+dim)*100/(dim+dim2),i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0xff) k++; + else if(bufferI[z]==LOAD_DATA_DATA&&bufferI[z+4]==READ_DATA_DATA){ + if (memCODE_W[k]!=bufferI[z+5]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError3],k,memCODE_W[k],bufferI[z+5]); //"Error writing address %4X: written %02X, read %02X\r\n" + err_e++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=0x2200; + z=DIMBUF; + } + } + k++; + z+=6; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d \n" + } + } + } + err_e+=i-k; + err+=err_e; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err_e); //"completed, %d errors\r\n" + } +//****************** write ID, CONFIG, CALIB ******************** + PrintMessage(strings[S_ConfigAreaW]); //"Writing CONFIG area ... " + int err_c=0; + int ICDgoto=0x2800+(ICDaddr&0x7FF); //GOTO ICD routine (0x28xx) + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + if(programID){ + for(i=0x2000;i<0x2004;i++){ + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=memCODE_W[i]>>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //externally timed + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x17; //END_PROGX (10111) + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + } + } + else{ + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=4; + } + if(ICDenable){ //write a GOTO ICD routine (0x28xx) + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=ICDgoto>>8; //MSB + bufferU[j++]=ICDgoto&0xFF; //LSB + bufferU[j++]=BEGIN_PROG2; //externally timed + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x17; //END_PROGX (10111) + bufferU[j++]=READ_DATA_PROG; + } + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=3; + bufferU[j++]=LOAD_DATA_PROG; //Config word 0x2007 + bufferU[j++]=memCODE_W[0x2007]>>8; //MSB + bufferU[j++]=memCODE_W[0x2007]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //externally timed + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x17; //END_PROGX (10111) + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + if(sizeW>0x2008&&memCODE_W[0x2008]!=0x3fff){ + bufferU[j++]=LOAD_DATA_PROG; //Config word2 0x2008 + bufferU[j++]=memCODE_W[0x2008]>>8; //MSB + bufferU[j++]=memCODE_W[0x2008]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //externally timed + bufferU[j++]=WAIT_T3; //Tprogram + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x17; //END_PROGX (10111) + bufferU[j++]=READ_DATA_PROG; + } + bufferU[j++]=FLUSH; + for(;j0x2008&&memCODE_W[0x2008]!=0x3fff){ + for(z+=7;z>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j0x2008) load_calibword=1; + else{ + PrintMessage(strings[S_NoCalibW]); //"Can't find calibration data\r\n" + load_calibword=0; + } + } + if(saveLog){ + OpenLogFile(); //"log.txt" + fprintf(logfile,"Write12F61x(%d)\n",dim); + } + for(i=0;i<0x2009&&i>8; + bufferU[j++]=10000&0xff; + bufferU[j++]=WAIT_T3; //delay after exiting prog mode + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=4000&0xff; + bufferU[j++]=FLUSH; + for(;j>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //externally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 4ms + bufferU[j++]=END_PROG; + bufferU[j++]=WAIT_T2; //Tdischarge 100us + bufferU[j++]=READ_DATA_PROG; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-12||i==dim-1){ + PrintStatus(strings[S_CodeWriting],i*100/dim,i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0x3fff) k++; + else if(bufferI[z]==LOAD_DATA_PROG&&bufferI[z+5]==READ_DATA_PROG){ + if (memCODE_W[k]!=(bufferI[z+6]<<8)+bufferI[z+7]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError2],k,memCODE_W[k],(bufferI[z+4]<<8)+bufferI[z+5]); //"Error writing address %3X: written %04X, read %04X\r\n" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim; + z=DIMBUF; + } + } + k++; + z+=8; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d,\n" + } + } + } + err+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" +//****************** write ID, CONFIG, CALIB ******************** + PrintMessage(strings[S_ConfigAreaW]); //"Writing CONFIG area ... " + int err_c=0; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + if(programID){ + for(i=0x2000;i<0x2004;i++){ + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=memCODE_W[i]>>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //externally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 4ms + bufferU[j++]=END_PROG; + bufferU[j++]=WAIT_T2; //Tdischarge 100us + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + } + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=3; + } + else{ + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=7; + } + bufferU[j++]=LOAD_DATA_PROG; //Config word 0x2007 + bufferU[j++]=memCODE_W[0x2007]>>8; //MSB + bufferU[j++]=memCODE_W[0x2007]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //externally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 4ms + bufferU[j++]=END_PROG; + bufferU[j++]=WAIT_T2; //Tdischarge 100us + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + if(load_calibword){ + bufferU[j++]=LOAD_DATA_PROG; //Calib word 1 + bufferU[j++]=memCODE_W[0x2008]>>8; //MSB + bufferU[j++]=memCODE_W[0x2008]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //externally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 4ms + bufferU[j++]=END_PROG; + bufferU[j++]=WAIT_T2; //Tdischarge 100us + bufferU[j++]=READ_DATA_PROG; + } + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j0x200A) load_calibword=1; + else{ + PrintMessage(strings[S_NoCalibW]); //"Can't find calibration data\r\n" + load_calibword=0; + } + } + if(dim2){ + if(sizeW<0x2100){ + dim2=0; + PrintMessage(strings[S_NoEEMem]); //"Can't find EEPROM data\r\n" + } + else if(dim2>sizeW-0x2100) dim2=sizeW-0x2100; + } + if(saveLog){ + OpenLogFile(); //"log.txt" + fprintf(logfile,"Write16F88x(%d,%d)\n",dim,dim2); + } + for(i=0;i<0x200A&&i>8; + bufferU[j++]=6000&0xff; + bufferU[j++]=WAIT_T3; //delay after exiting prog mode + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=3000&0xff; + bufferU[j++]=FLUSH; + for(;j>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 3ms + bufferU[j++]=READ_DATA_PROG; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-12||i==dim-1){ + PrintStatus(strings[S_CodeWriting],i*100/dim,i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0x3fff) k++; + else if(bufferI[z]==LOAD_DATA_PROG&&bufferI[z+3]==READ_DATA_PROG){ + if (memCODE_W[k]!=(bufferI[z+4]<<8)+bufferI[z+5]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError2],k,memCODE_W[k],(bufferI[z+4]<<8)+bufferI[z+5]); //"Error writing address %3X: written %04X, read %04X\r\n" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim; + z=DIMBUF; + } + } + k++; + z+=6; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d,\n" + } + } + } + err+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" +//****************** write eeprom ******************** + if(dim2){ + PrintMessage(strings[S_EEAreaW]); //"Writing EEPROM ... " + PrintStatusSetup(); + j=0; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=6000>>8; + bufferU[j++]=6000&0xff; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + bufferU[j++]=BULK_ERASE_DATA; + bufferU[j++]=WAIT_T3; // delay T3=6ms + bufferU[j++]=INC_ADDR_N; //use only INC_ADDR_N so verification does not look at it + bufferU[j++]=0xFF; + bufferU[j++]=INC_ADDR_N; //EEPROM: counter at 0x2100 + bufferU[j++]=1; + for(w=2,i=k=0x2100;i<0x2100+dim2;i++){ + if(memCODE_W[i]<0xff){ + bufferU[j++]=LOAD_DATA_DATA; + bufferU[j++]=memCODE_W[i]&0xff; + bufferU[j++]=BEGIN_PROG; //internally timed, T=6ms min + bufferU[j++]=WAIT_T3; //Tprogram 6ms + bufferU[j++]=READ_DATA_DATA; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-12||i==0x2100+dim2-1){ + PrintStatus(strings[S_CodeWriting],(i-0x2100+dim)*100/(dim+dim2),i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0xff) k++; + else if(bufferI[z]==LOAD_DATA_DATA&&bufferI[z+3]==READ_DATA_DATA){ + if (memCODE_W[k]!=bufferI[z+4]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError3],k,memCODE_W[k],bufferI[z+4]); //"Error writing address %4X: written %02X, read %02X\r\n" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=0x2200; + z=DIMBUF; + } + } + k++; + z+=5; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d \n" + } + } + } + err+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],i-k); //"completed, %d errors\r\n" + } +//****************** write ID, CONFIG, CALIB ******************** + PrintMessage(strings[S_ConfigAreaW]); //"Writing CONFIG area ... " + int err_c=0; + int ICDgoto=0x2800+(ICDaddr&0x7FF); //GOTO ICD routine (0x28xx) + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=3000>>8; + bufferU[j++]=3000&0xff; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + if(programID){ + for(i=0x2000;i<0x2004;i++){ + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=memCODE_W[i]>>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 3ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + } + } + else{ + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=4; + } + if(ICDenable){ //write a GOTO ICD routine (0x28xx) + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=ICDgoto>>8; //MSB + bufferU[j++]=ICDgoto&0xFF; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 3ms + bufferU[j++]=READ_DATA_PROG; + } + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=3; + bufferU[j++]=LOAD_DATA_PROG; //Config word 0x2007 + bufferU[j++]=memCODE_W[0x2007]>>8; //MSB + bufferU[j++]=memCODE_W[0x2007]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 3ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + bufferU[j++]=LOAD_DATA_PROG; //Config word2 0x2008 + bufferU[j++]=memCODE_W[0x2008]>>8; //MSB + bufferU[j++]=memCODE_W[0x2008]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 3ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + if(load_calibword){ + bufferU[j++]=LOAD_DATA_PROG; //Calib word 1 + bufferU[j++]=memCODE_W[0x2009]>>8; //MSB + bufferU[j++]=memCODE_W[0x2009]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 3ms + bufferU[j++]=READ_DATA_PROG; + } + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=10000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + if(vdd==0){ + bufferU[j++]=WAIT_T3; //delay between vdd and vpp + bufferU[j++]=WAIT_T3; //delay between vdd and vpp + bufferU[j++]=WAIT_T3; //delay between vdd and vpp + bufferU[j++]=WAIT_T3; //delay between vdd and vpp + bufferU[j++]=WAIT_T3; //delay between vdd and vpp + } + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=NOP; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=0x06; + bufferU[j++]=READ_DATA_PROG; //DevID + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; //delay after exiting prog mode + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=1000&0xff; + bufferU[j++]=FLUSH; + for(;j>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //externally timed, T=1ms min + bufferU[j++]=WAIT_T3; //Tprogram 1ms min + bufferU[j++]=END_PROG2; + bufferU[j++]=READ_DATA_PROG; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-10||i==dim-1){ + PrintStatus(strings[S_CodeWriting],i*100/dim,i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0x3fff) k++; + else if(bufferI[z]==LOAD_DATA_PROG&&bufferI[z+4]==READ_DATA_PROG){ + if (memCODE_W[k]!=(bufferI[z+5]<<8)+bufferI[z+6]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError2],k,memCODE_W[k],(bufferI[z+5]<<8)+bufferI[z+6]); //"Error writing address %3X: written %04X, read %04X\r\n" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim; + z=DIMBUF; + } + } + k++; + z+=7; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d,\n" + } + } + } + err+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" +//****************** write ID, CONFIG, CALIB ******************** + PrintMessage(strings[S_ConfigAreaW]); //"Writing CONFIG area ... " + int err_c=0; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + if(programID){ + for(i=0x2000;i<0x2004;i++){ + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=memCODE_W[i]>>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //externally timed, T=1ms min + bufferU[j++]=WAIT_T3; //Tprogram 1ms + bufferU[j++]=END_PROG2; + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + } + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=3; + } + else{ + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=7; + } + bufferU[j++]=LOAD_DATA_PROG; //Config word 0x2007 + bufferU[j++]=memCODE_W[0x2007]>>8; //MSB + bufferU[j++]=memCODE_W[0x2007]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //externally timed, T=1ms min + bufferU[j++]=WAIT_T3; //Tprogram 1ms + bufferU[j++]=END_PROG2; + bufferU[j++]=WAIT_T3; //Tprogram 1ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + if(sizeW>0x2008&&memCODE_W[0x2008]<0x3fff){ + bufferU[j++]=LOAD_DATA_PROG; //Config word 2 0x2008 + bufferU[j++]=memCODE_W[0x2008]>>8; //MSB + bufferU[j++]=memCODE_W[0x2008]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //externally timed, T=1ms min + bufferU[j++]=WAIT_T3; //Tprogram 1ms + bufferU[j++]=END_PROG2; + bufferU[j++]=WAIT_T3; //Tprogram 1ms + bufferU[j++]=READ_DATA_PROG; + } + bufferU[j++]=FLUSH; + for(;j0x2008&&memCODE_W[0x2008]<0x3fff){ + for(z+=6;z>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=10000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + if(vdd==0){ + bufferU[j++]=WAIT_T3; //delay between vdd and vpp + bufferU[j++]=WAIT_T3; //delay between vdd and vpp + bufferU[j++]=WAIT_T3; //delay between vdd and vpp + bufferU[j++]=WAIT_T3; //delay between vdd and vpp + bufferU[j++]=WAIT_T3; //delay between vdd and vpp + } + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=NOP; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=0x06; + bufferU[j++]=READ_DATA_PROG; //DevID + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T3; //delay after exiting prog mode + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=FLUSH; + for(;j>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //externally timed, T=1ms min + bufferU[j++]=WAIT_T3; //Tprogram 1ms min + bufferU[j++]=END_PROG2; + bufferU[j++]=WAIT_T2; //Tdischarge 100us + bufferU[j++]=READ_DATA_PROG; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-11||i==dim-1){ + PrintStatus(strings[S_CodeWriting],i*100/dim,i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0x3fff) k++; + else if(bufferI[z]==LOAD_DATA_PROG&&bufferI[z+5]==READ_DATA_PROG){ + if (memCODE_W[k]!=(bufferI[z+6]<<8)+bufferI[z+7]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError2],k,memCODE_W[k],(bufferI[z+6]<<8)+bufferI[z+7]); //"Error writing address %3X: written %04X, read %04X\r\n" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim; + z=DIMBUF; + } + } + k++; + z+=8; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d,\n" + } + } + } + err+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" +//****************** write ID, CONFIG, CALIB ******************** + PrintMessage(strings[S_ConfigAreaW]); //"Writing CONFIG area ... " + int err_c=0; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + if(programID){ + for(i=0x2000;i<0x2004;i++){ + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=memCODE_W[i]>>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //externally timed, T=1ms min + bufferU[j++]=WAIT_T3; //Tprogram 1ms + bufferU[j++]=END_PROG2; + bufferU[j++]=WAIT_T2; //Tdischarge 100us + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + } + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=3; + } + else{ + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=7; + } + bufferU[j++]=LOAD_DATA_PROG; //Config word 0x2007 + bufferU[j++]=memCODE_W[0x2007]>>8; //MSB + bufferU[j++]=memCODE_W[0x2007]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //externally timed, T=1ms min + bufferU[j++]=WAIT_T3; //Tprogram 1ms + bufferU[j++]=END_PROG2; + bufferU[j++]=WAIT_T2; //Tdischarge 100us + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + if(sizeW>0x2008&&memCODE_W[0x2008]<0x3fff){ + bufferU[j++]=LOAD_DATA_PROG; //Config word 2 0x2008 + bufferU[j++]=memCODE_W[0x2008]>>8; //MSB + bufferU[j++]=memCODE_W[0x2008]&0xff; //LSB + bufferU[j++]=BEGIN_PROG2; //externally timed, T=1ms min + bufferU[j++]=WAIT_T3; //Tprogram 1ms + bufferU[j++]=END_PROG2; + bufferU[j++]=WAIT_T2; //Tdischarge 100us + bufferU[j++]=READ_DATA_PROG; + } + bufferU[j++]=FLUSH; + for(;j0x2008&&memCODE_W[0x2008]<0x3fff){ + for(z+=6;z>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=6000&0xff; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=2500&0xff; + bufferU[j++]=FLUSH; + for(;j>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 3ms + bufferU[j++]=READ_DATA_PROG; + w++; + } + bufferU[j++]=INC_ADDR; + if(j>DIMBUF-12||i==dim-1){ + PrintStatus(strings[S_CodeWriting],i*100/dim,i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0x3fff) k++; + else if(bufferI[z]==LOAD_DATA_PROG&&bufferI[z+3]==READ_DATA_PROG){ + if (memCODE_W[k]!=(bufferI[z+4]<<8)+bufferI[z+5]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError2],k,memCODE_W[k],(bufferI[z+4]<<8)+bufferI[z+5]); //"Error writing address %3X: written %04X, read %04X\r\n" + err++; + if(max_err&&err>max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim; + z=DIMBUF; + } + } + k++; + z+=6; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d,\n" + } + } + } + err+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" +//****************** write ID, CONFIG, CALIB ******************** + PrintMessage(strings[S_ConfigAreaW]); //"Writing CONFIG area ... " + int err_c=0; + int ICDgoto=0x2800+(ICDaddr&0x7FF); //GOTO ICD routine (0x28xx) + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=6000>>8; + bufferU[j++]=6000&0xff; + bufferU[j++]=LOAD_CONF; //counter at 0x2000 + bufferU[j++]=0xFF; //fake config + bufferU[j++]=0xFF; //fake config + if(programID){ + for(i=0x2000;i<0x2004;i++){ + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=memCODE_W[i]>>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 3ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + } + } + else{ + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=4; + } + if(ICDenable){ //write a GOTO ICD routine (0x28xx) + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=ICDgoto>>8; //MSB + bufferU[j++]=ICDgoto&0xFF; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=3ms min + bufferU[j++]=WAIT_T3; //Tprogram 3ms + bufferU[j++]=READ_DATA_PROG; + } + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=3; + bufferU[j++]=LOAD_DATA_PROG; //Config word 0x2007 + bufferU[j++]=memCODE_W[0x2007]>>8; //MSB + bufferU[j++]=memCODE_W[0x2007]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=5ms min + bufferU[j++]=WAIT_T3; //Tprogram 3ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + if(sizeW>0x2008){ //only if Config2 is present + bufferU[j++]=LOAD_DATA_PROG; //Config word 2 0x2008 + bufferU[j++]=memCODE_W[0x2008]>>8; //MSB + bufferU[j++]=memCODE_W[0x2008]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed, T=5ms min + bufferU[j++]=WAIT_T3; //Tprogram 3ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=FLUSH; + } + for(;j0x2008){ //only if Config2 is present + for(z+=6;z>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j vpp before vdd +// bit0=1 -> vdd before vpp +// bit1=1 -> LVP programming +// bit2=1 -> Config3@0x8009 +// bit3=1 -> Config4@0x800A +// bit4=1 -> PIC16F18xxx (calib words @0xE000 + new commands) +// DevREV@0x8005 DevID@0x8006 +// Config1@0x8007 Config2@0x8008 +// Config3@0x8009 Config4@0x800A +// Calib1@0x8009/A Calib2@0x800A/B Calib3@0x800B/C +// eeprom@0x0 or 0xF000 +// erase: BULK_ERASE_PROG (1001) +5ms +// write:LOAD_DATA_PROG (0010) + BEGIN_PROG (1000) + 2.5ms (8 word algorithm) +// config write time 5ms +// eeprom: BULK_ERASE_DATA (1011) + 5ms +// LOAD_DATA_DATA (0011) + BEGIN_PROG (1000) + 2.5ms +// verify after write +// write (16F18xxx): LOAD_DATA_INC (100010) + BEGIN_PROG (1000) + 2.5ms (32 word algorithm) +{ + int err=0; + WORD devID=0x3fff,devREV=0x3fff,calib1=0x3fff,calib2=0x3fff,calib3=0x3fff; + int k=0,k2=0,z=0,i,j,w; + int F18x=options&16; + if(F18x&&FWVersion<0xA00){ //only for 16F18xxx + PrintMessage1(strings[S_FWver2old],"0.10.0"); //"This firmware is too old. Version %s is required\r\n" + return; + } + if(!CheckV33Regulator()){ + PrintMessage(strings[S_noV33reg]); //Can't find 3.3V expansion board + return; + } + if(sizeW<0x8009){ + PrintMessage(strings[S_NoConfigW5]); //"Can't find CONFIG (0x8007-0x8008)\r\n" + PrintMessage(strings[S_End]); + return; + } + if((options&4)&&sizeW<0x800A){ //Config3 defaults to 0x3FFF + sizeW=0x800A; + memCODE_W=(WORD*)realloc(memCODE_W,sizeof(WORD)*sizeW); + memCODE_W[0x8009]=0x3FFF; + } + if((options&8)&&sizeW<0x800B){ //Config4 defaults to 0x3FFF + sizeW=0x800B; + memCODE_W=(WORD*)realloc(memCODE_W,sizeof(WORD)*sizeW); + memCODE_W[0x800A]=0x3FFF; + } + if(saveLog){ + OpenLogFile(); //"Log.txt" + fprintf(logfile,"Write16F1xxx(%d,%d,%d)\n",dim,dim2,options); + } + if(dim2>sizeEE) dim2=sizeEE; + if((options&2)==0){ //HV entry + if(!StartHVReg(8.5)){ + PrintMessage(strings[S_HVregErr]); //"HV regulator error\r\n" + return; + } + } + else StartHVReg(-1); //LVP mode, turn off HV + for(i=0;i<0x800C&&i>8; + bufferU[j++]=2500&0xff; + bufferU[j++]=FLUSH; + for(;j0&&memCODE_W[dim]>=0x3fff;dim--); //skip empty space at end + if(!F18x){ //16F1xxx + if(dim%8) dim+=8-dim%8; //grow to 8 word multiple + for(i=k=0,j=0;iDIMBUF-4||(valid&&j>1)){ + bufferU[j++]=FLUSH; + for(;j>8; //MSB + bufferU[j++]=memCODE_W[i+k]&0xff; //LSB + for(k=1;k<8;k++){ + bufferU[j++]=INC_ADDR; + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=memCODE_W[i+k]>>8; //MSB + bufferU[j++]=memCODE_W[i+k]&0xff; //LSB + } + bufferU[j++]=BEGIN_PROG; //internally timed, T=2.5ms + bufferU[j++]=WAIT_T3; + bufferU[j++]=INC_ADDR; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=i&0xFF; + for(k=0;k<32&&i>8; //MSB + bufferU[j++]=memCODE_W[i+k]&0xff; //LSB + if(j>DIMBUF-4){ + bufferU[j++]=FLUSH; + for(;j16){ //increase address to skip empty words, if enough are found + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=k2; + i+=k2; + k+=k2; + } + if(j>DIMBUF-4||(valid&&j>1)){ //if buffer is full or last skip + bufferU[j++]=FLUSH; + for(;jDIMBUF*2/4-3||i==dim-1){ //2B cmd -> 4B data + bufferU[j++]=FLUSH; + for(;j=max_err) i=dim; + } + } + PrintStatusEnd(); + if(k=max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + } +//****************** write eeprom ******************** + if(dim2&&err>8; + bufferU[j++]=5000&0xff; + bufferU[j++]=BULK_ERASE_DATA; + bufferU[j++]=WAIT_T3; // wait 5ms + bufferU[j++]=CUST_CMD; + bufferU[j++]=0x16; //Reset address + bufferU[j++]=FLUSH; + for(;jDIMBUF-12||i==dim2-1){ + PrintStatus(strings[S_CodeWriting],(i+dim)*100/(dim+dim2),i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0xff) k++; + else if(bufferI[z]==LOAD_DATA_DATA&&bufferI[z+3]==READ_DATA_DATA){ + if (memEE[k]!=bufferI[z+4]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError3],k,memEE[k],bufferI[z+4]); //"Error writing address %4X: written %02X, read %02X\r\n" + errEE++; + if(max_err&&err+errEE>max_err){ + PrintMessage1(strings[S_MaxErr],err+errEE); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"write interrupted" + i=dim2; + z=DIMBUF; + } + } + k++; + z+=5; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,errEE); //"i=%d, k=%d, errors=%d\n" + } + } + } + errEE+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],errEE); //"completed, %d errors\r\n" + err+=errEE; + } + else if(dim2&&err>8; + bufferU[j++]=5000&0xff; + bufferU[j++]=LOAD_PC; //update counter + bufferU[j++]=0xF0; + bufferU[j++]=0x00; + bufferU[j++]=FLUSH; + for(;jDIMBUF-12||i==dim2-1){ + PrintStatus(strings[S_CodeWriting],(i+dim)*100/(dim+dim2),i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0xff) k++; + else if(bufferI[z]==LOAD_DATA_PROG&&bufferI[z+3]==READ_DATA_PROG){ + if (memEE[k]!=bufferI[z+5]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError3],k,memEE[k],bufferI[z+5]); //"Error writing address %4X: written %02X, read %02X\r\n" + errEE++; + if(max_err&&err+errEE>max_err){ + PrintMessage1(strings[S_MaxErr],err+errEE); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"write interrupted" + i=dim2; + z=DIMBUF; + } + } + k++; + z+=6; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,errEE); //"i=%d, k=%d, errors=%d\n" + } + } + } + errEE+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],errEE); //"completed, %d errors\r\n" + err+=errEE; + + } + if(err>=max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + } +//****************** write ID, CONFIG, CALIB ******************** + if(max_err&&err>8; + bufferU[j++]=5000&0xff; + bufferU[j++]=LOAD_CONF; //PC @ 0x8000 + bufferU[j++]=0xFF; + bufferU[j++]=0xFF; + if(programID){ + for(i=0x8000;i<0x8004;i++){ + bufferU[j++]=LOAD_DATA_PROG; + bufferU[j++]=memCODE_W[i]>>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram 5ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + } + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=3; + } + else{ + bufferU[j++]=INC_ADDR_N; + bufferU[j++]=7; + } + bufferU[j++]=LOAD_DATA_PROG; //Config word 0x8007 + bufferU[j++]=memCODE_W[0x8007]>>8; //MSB + bufferU[j++]=memCODE_W[0x8007]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram 5ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + bufferU[j++]=LOAD_DATA_PROG; //Config word 2 + bufferU[j++]=memCODE_W[0x8008]>>8; //MSB + bufferU[j++]=memCODE_W[0x8008]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram 5ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + if(options&0xC){ + bufferU[j++]=LOAD_DATA_PROG; //Config word 3 + bufferU[j++]=memCODE_W[0x8009]>>8; //MSB + bufferU[j++]=memCODE_W[0x8009]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram 5ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + } + if(options&8){ + bufferU[j++]=LOAD_DATA_PROG; //Config word 4 + bufferU[j++]=memCODE_W[0x800A]>>8; //MSB + bufferU[j++]=memCODE_W[0x800A]&0xff; //LSB + bufferU[j++]=BEGIN_PROG; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram 5ms + bufferU[j++]=READ_DATA_PROG; + bufferU[j++]=INC_ADDR; + } + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j vpp before vdd +// bit0=1 -> vdd before vpp +// bit1=1 -> LVP programming +// bit4=1 -> do not use DIA&DCI +// DevREV@0x8005 DevID@0x8006 +// Config@0x8007-800B +// Device info area @0x8100 +// Device configuration info area @0x8200 +// erase: BULK_ERASE_PROGRAM_MEM (0x18) +14ms +// EEPROM erase: idem +// write flash: LOAD_NVM (0x0/2) + BEGIN_INT_PROG (0xE0) + 2.8ms (32 word algorithm) +// EEPROM write: one word, 6ms +// config write: one word, 10ms +// verify after write +{ + int err=0; + WORD devID=0x3fff,devREV=0x3fff; + int k=0,k2=0,z=0,i,j,w; + int useDCI=(options&0x10)==0?1:0; + int rowN=32; //32 word algorithm + if(FWVersion<0xB00){ + PrintMessage1(strings[S_FWver2old],"0.11.0"); //"This firmware is too old. Version %s is required\r\n" + return; + } + if(!CheckV33Regulator()){ + PrintMessage(strings[S_noV33reg]); //Can't find 3.3V expansion board + return; + } + if(sizeW<0x800C){ + PrintMessage(strings[S_NoConfigW6]); //"Can't find CONFIG (0x8007-0x800B)\r\n" + PrintMessage1(strings[S_End],0); + return; + } + if(saveLog){ + OpenLogFile(); //"Log.txt" + fprintf(logfile,"Write16F18xxx(%d,%d,%d)\n",dim,dim2,options); + } + if(dim2>0) dim2=sizeEE; + if(dim2>0x1000) dim2=0x100; + if((options&2)==0){ //HV entry + if(!StartHVReg(8.5)){ + PrintMessage(strings[S_HVregErr]); //"HV regulator error\r\n" + return; + } + } + else StartHVReg(-1); //LVP mode, turn off HV + for(i=0;i<0x800C&&i>8; + bufferU[j++]=2800&0xff; + bufferU[j++]=FLUSH; + for(;jDIMBUF||i==0x1F){ //2B cmd -> 3B data + bufferU[j++]=FLUSH; + for(;jDIMBUF||i==0x1F){ //2B cmd -> 3B data + bufferU[j++]=FLUSH; + for(;j%d Flash words\r\n",DCI[0]*DCI[2]); + PrintMessage1("EE data memory size: %d\r\n",DCI[3]); + PrintMessage1("Pin count: %d\r\n",DCI[4]); + if(DCI[0]*DCI[2]!=dim) PrintMessage(strings[S_WarnFlashSize]); //"Warning, flash size is different from the expected value" + if(dim2>DCI[3]) dim2=DCI[3]; //limit EE to the real one + } +//****************** erase memory ******************** + PrintMessage(strings[S_StartErase]); //"Erasing ... " + if(saveLog) fprintf(logfile,"%s\n",strings[S_StartErase]); + j=0; + bufferU[j++]=ICSP8_LOAD; + bufferU[j++]=LOAD_PC_ADDR; + if(programID){ //0x8000 to erase UserID + bufferU[j++]=0x80; + bufferU[j++]=0x00; + } + else{ + bufferU[j++]=0x00; + bufferU[j++]=0x00; + } + bufferU[j++]=ICSP8_SHORT; + bufferU[j++]=BULK_ERASE_PROGRAM_MEM; + bufferU[j++]=WAIT_T3; // wait ~14ms + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + //separate EEPROM erase (undocumented on 16F184xx devices) + bufferU[j++]=ICSP8_LOAD; + bufferU[j++]=LOAD_PC_ADDR; + bufferU[j++]=0xF0; + bufferU[j++]=0x00; + bufferU[j++]=ICSP8_SHORT; + bufferU[j++]=BULK_ERASE_PROGRAM_MEM; + bufferU[j++]=WAIT_T3; // wait ~14ms + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=FLUSH; + for(;j0&&memCODE_W[dim-1]>=0x3fff;dim--); //skip empty space at end + if(dim%rowN) dim+=rowN-dim%rowN; //grow to 32 word multiple + for(i=k=0,j=0;i>8; + bufferU[j++]=i&0xFF; + for(k=0;k>8; //MSB + bufferU[j++]=memCODE_W[i+k]&0xff; //LSB + if(j>DIMBUF-5){ + bufferU[j++]=FLUSH; + for(;j=0x3fff;k2++); + if(k2>i+10){ //at least 10 skipped + i=k2; + k=i; + bufferU[j++]=ICSP8_LOAD; + bufferU[j++]=LOAD_PC_ADDR; //update counter + bufferU[j++]=(i>>8)&0xFF; + bufferU[j++]=i&0xFF; + } + } + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + if((j+1)/2*3+3>DIMBUF||i==dim-1){ //2B cmd -> 3B data + bufferU[j++]=FLUSH; + for(;j=max_err) i=dim; + } + } + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed, %d errors\r\n" + if(err>=max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + } +//****************** write eeprom ******************** + else if(dim2&&err>8; //5.6ms in datasheet? + bufferU[j++]=5600&0xff; + bufferU[j++]=ICSP8_LOAD; + bufferU[j++]=LOAD_PC_ADDR; //load address + bufferU[j++]=0xF0; + bufferU[j++]=0x00; + for(w=i=k=0;iDIMBUF-10||i==dim2-1){ + PrintStatus(strings[S_CodeWriting],(i+dim)*100/(dim+dim2),i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;j=0xff) k++; + else if(bufferI[z]==ICSP8_LOAD&&bufferI[z+3]==ICSP8_READ){ + if(memEE[k]!=bufferI[z+5]){ + PrintMessage("\r\n"); + PrintMessage3(strings[S_CodeWError3],k,memEE[k],bufferI[z+5]); //"Error writing address %4X: written %02X, read %02X\r\n" + errEE++; + if(max_err&&err+errEE>max_err){ + PrintMessage1(strings[S_MaxErr],err+errEE); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"write interrupted" + i=dim2; + z=DIMBUF; + } + } + k++; + z+=5; + } + } + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,errEE); //"i=%d, k=%d, errors=%d\n" + } + } + } + errEE+=i-k; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],errEE); //"completed, %d errors\r\n" + if(max_err&&err+errEE>max_err){ + PrintMessage1(strings[S_MaxErr],err+errEE); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + } + err+=errEE; + } +//****************** write ID, CONFIG, CALIB ******************** + if(max_err&&err>8; //5.6ms in datasheet, but requires more in practice + bufferU[j++]=10000&0xff; + if(programID){ + bufferU[j++]=ICSP8_LOAD; + bufferU[j++]=LOAD_PC_ADDR; //load address + bufferU[j++]=0x80; + bufferU[j++]=0x00; + for(i=0x8000;i<0x8004;i++){ + bufferU[j++]=ICSP8_LOAD; + bufferU[j++]=LOAD_NVM; + bufferU[j++]=memCODE_W[i]>>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=ICSP8_SHORT; + bufferU[j++]=BEGIN_INT_PROG; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram 10ms + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + } + bufferU[j++]=FLUSH; + for(;j>8; //MSB + bufferU[j++]=memCODE_W[i]&0xff; //LSB + bufferU[j++]=ICSP8_SHORT; + bufferU[j++]=BEGIN_INT_PROG; //internally timed + bufferU[j++]=WAIT_T3; //Tprogram 10ms + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + } + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=NOP; //exit program mode + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j + */ + +//This cannot be executed conditionally on MSVC +//#include "stdafx.h" + +#include "common.h" + +struct ID18{ + int id; + char *device; + int revmask; +} PIC18LIST[]={ + {0x0400,"18F252/2539 rev%d\r\n",0x1F}, + {0x0420,"18F452/4539 rev%d\r\n",0x1F}, + {0x0480,"18F242/2439 rev%d\r\n",0x1F}, + {0x04A0,"18F442/4439 rev%d\r\n",0x1F}, + {0x0500,"18F2320 rev%d\r\n",0x1F}, + {0x0520,"18F4320 rev%d\r\n",0x1F}, + {0x0580,"18F2220 rev%d\r\n",0x1F}, + {0x05A0,"18F4220 rev%d\r\n",0x1F}, + {0x0600,"18F8720 rev%d\r\n",0x1F}, + {0x0620,"18F6720 rev%d\r\n",0x1F}, + {0x0640,"18F8620 rev%d\r\n",0x1F}, + {0x0660,"18F6620 rev%d\r\n",0x1F}, + {0x07C0,"18F1320 rev%d\r\n",0x1F}, + {0x07E0,"18F1220 rev%d\r\n",0x1F}, + {0x0800,"18F248 rev%d\r\n",0x1F}, + {0x0820,"18F448 rev%d\r\n",0x1F}, + {0x0840,"18F258 rev%d\r\n",0x1F}, + {0x0860,"18F458 rev%d\r\n",0x1F}, + {0x0880,"18F4431 rev%d\r\n",0x1F}, + {0x08A0,"18F4331 rev%d\r\n",0x1F}, + {0x08C0,"18F2431 rev%d\r\n",0x1F}, + {0x08E0,"18F2331 rev%d\r\n",0x1F}, + {0x0B20,"18F6520 rev%d\r\n",0x1F}, + {0x0B00,"18F8520 rev%d\r\n",0x1F}, + {0x0C00,"18F4620 rev%d\r\n",0x1F}, + {0x0C20,"18F4610 rev%d\r\n",0x1F}, + {0x0C40,"18F4525 rev%d\r\n",0x1F}, + {0x0C60,"18F4515 rev%d\r\n",0x1F}, + {0x0C80,"18F2620 rev%d\r\n",0x1F}, + {0x0CA0,"18F2610 rev%d\r\n",0x1F}, + {0x0CC0,"18F2525 rev%d\r\n",0x1F}, + {0x0CE0,"18F2515 rev%d\r\n",0x1F}, + {0x0E80,"18F4680 rev%d\r\n",0x1F}, + {0x0EA0,"18F4585 rev%d\r\n",0x1F}, + {0x0EC0,"18F2680 rev%d\r\n",0x1F}, + {0x0EE0,"18F2585 rev%d\r\n",0x1F}, + {0x1081,"18F4523 rev%d\r\n",0x0F}, + {0x1080,"18F4520 rev%d\r\n",0x0F}, + {0x10A0,"18F4510 rev%d\r\n",0x1F}, + {0x10C1,"18F4423 rev%d\r\n",0x0F}, + {0x10C0,"18F4420 rev%d\r\n",0x0F}, + {0x10E0,"18F4410 rev%d\r\n",0x1F}, + {0x1100,"18F2523 rev%d\r\n",0x0F}, + {0x1100,"18F2520 rev%d\r\n",0x0F}, + {0x1120,"18F2510 rev%d\r\n",0x1F}, + {0x1140,"18F2423 rev%d\r\n",0x0F}, + {0x1140,"18F2420 rev%d\r\n",0x0F}, + {0x1160,"18F2410 rev%d\r\n",0x1F}, + {0x1200,"18F4550 rev%d\r\n",0x1F}, + {0x1220,"18F4455 rev%d\r\n",0x1F}, + {0x1240,"18F2550 rev%d\r\n",0x1F}, + {0x1260,"18F2455 rev%d\r\n",0x1F}, + {0x1340,"18F6527 rev%d\r\n",0x1F}, + {0x1360,"18F8527 rev%d\r\n",0x1F}, + {0x1380,"18F6622 rev%d\r\n",0x1F}, + {0x13A0,"18F8622 rev%d\r\n",0x1F}, + {0x13C0,"18F6627 rev%d\r\n",0x1F}, + {0x13E0,"18F8627 rev%d\r\n",0x1F}, + {0x1400,"18F6722 rev%d\r\n",0x1F}, + {0x1420,"18F8722 rev%d\r\n",0x1F}, + {0x1520,"18F65J10 rev%d\r\n",0x1F}, + {0x1540,"18F65J15 rev%d\r\n",0x1F}, + {0x1560,"18F66J10 rev%d\r\n",0x1F}, + {0x1580,"18F66J15 rev%d\r\n",0x1F}, + {0x15A0,"18F67J10 rev%d\r\n",0x1F}, + {0x15E0,"18F85J10 rev%d\r\n",0x1F}, + {0x1700,"18F85J15 rev%d\r\n",0x1F}, + {0x1720,"18F86J10 rev%d\r\n",0x1F}, + {0x1740,"18F86J15 rev%d\r\n",0x1F}, + {0x1760,"18F87J10 rev%d\r\n",0x1F}, + {0x1800,"18F66J60 rev%d\r\n",0x1F}, + {0x1820,"18F86J60 rev%d\r\n",0x1F}, + {0x1840,"18F96J60 rev%d\r\n",0x1F}, + {0x1A80,"18F4580 rev%d\r\n",0x1F}, + {0x1AA0,"18F4480 rev%d\r\n",0x1F}, + {0x1AC0,"18F2580 rev%d\r\n",0x1F}, + {0x1AE0,"18F2480 rev%d\r\n",0x1F}, + {0x1C00,"18F25J10 rev%d\r\n",0x1F}, + {0x1C20,"18F45J10 rev%d\r\n",0x1F}, + {0x1C40,"18LF25J10 rev%d\r\n",0x1F}, + {0x1C60,"18LF45J10 rev%d\r\n",0x1F}, + {0x1D00,"18F24J10 rev%d\r\n",0x1F}, + {0x1D20,"18F44J10 rev%d\r\n",0x1F}, + {0x1D40,"18LF24J10 rev%d\r\n",0x1F}, + {0x1D60,"18LF44J10 rev%d\r\n",0x1F}, + {0x1E00,"18F1230 rev%d\r\n",0x1F}, + {0x1E20,"18F1330 rev%d\r\n",0x1F}, + {0x1F00,"18F66J65 rev%d\r\n",0x1F}, + {0x1F20,"18F67J60 rev%d\r\n",0x1F}, + {0x1F40,"18F86J65 rev%d\r\n",0x1F}, + {0x1F60,"18F87J60 rev%d\r\n",0x1F}, + {0x1F80,"18F96J65 rev%d\r\n",0x1F}, + {0x1FA0,"18F97J60 rev%d\r\n",0x1F}, + {0x1FE0,"18F1330-ICD rev%d\r\n",0x1F}, + {0x2000,"18F46K20 rev%d\r\n",0x1F}, + {0x2020,"18F26K20 rev%d\r\n",0x1F}, + {0x2040,"18F45K20 rev%d\r\n",0x1F}, + {0x2060,"18F25K20 rev%d\r\n",0x1F}, + {0x2080,"18F44K20 rev%d\r\n",0x1F}, + {0x20A0,"18F24K20 rev%d\r\n",0x1F}, + {0x20C0,"18F43K20 rev%d\r\n",0x1F}, + {0x20E0,"18F23K20 rev%d\r\n",0x1F}, + {0x2100,"18F4321 rev%d\r\n",0x1F}, + {0x2120,"18F2321 rev%d\r\n",0x1F}, + {0x2140,"18F4221 rev%d\r\n",0x1F}, + {0x2160,"18F2221 rev%d\r\n",0x1F}, + {0x2400,"18F4450 rev%d\r\n",0x1F}, + {0x2420,"18F2450 rev%d\r\n",0x1F}, + {0x2700,"18F2682 rev%d\r\n",0x1F}, + {0x2720,"18F2685 rev%d\r\n",0x1F}, + {0x2740,"18F4682 rev%d\r\n",0x1F}, + {0x2760,"18F4685 rev%d\r\n",0x1F}, + {0x2A00,"18F4553 rev%d\r\n",0x1F}, + {0x2A20,"18F4458 rev%d\r\n",0x1F}, + {0x2A40,"18F2553 rev%d\r\n",0x1F}, + {0x2A60,"18F2458 rev%d\r\n",0x1F}, + {0x3800,"18F63J90 rev%d\r\n",0x1F}, + {0x3820,"18F64J90 rev%d\r\n",0x1F}, + {0x3860,"18F65J90 rev%d\r\n",0x1F}, + {0x3880,"18F83J90 rev%d\r\n",0x1F}, + {0x38A0,"18F84J90 rev%d\r\n",0x1F}, + {0x38E0,"18F85J90 rev%d\r\n",0x1F}, + {0x3900,"18F63J11 rev%d\r\n",0x1F}, + {0x3920,"18F64J11 rev%d\r\n",0x1F}, + {0x3960,"18F65J11 rev%d\r\n",0x1F}, + {0x3980,"18F83J11 rev%d\r\n",0x1F}, + {0x39A0,"18F84J11 rev%d\r\n",0x1F}, + {0x39E0,"18F85J11 rev%d\r\n",0x1F}, + {0x4100,"18F65J50 rev%d\r\n",0x1F}, + {0x4140,"18F66J50 rev%d\r\n",0x1F}, + {0x4160,"18F66J55 rev%d\r\n",0x1F}, + {0x4180,"18F67J50 rev%d\r\n",0x1F}, + {0x41A0,"18F85J50 rev%d\r\n",0x1F}, + {0x41E0,"18F86J50 rev%d\r\n",0x1F}, + {0x4200,"18F86J55 rev%d\r\n",0x1F}, + {0x4220,"18F87J50 rev%d\r\n",0x1F}, + {0x4440,"18F66J11 rev%d\r\n",0x1F}, + {0x4460,"18F66J16 rev%d\r\n",0x1F}, + {0x4480,"18F67J11 rev%d\r\n",0x1F}, + {0x44E0,"18F86J11 rev%d\r\n",0x1F}, + {0x4500,"18F86J16 rev%d\r\n",0x1F}, + {0x4520,"18F87J11 rev%d\r\n",0x1F}, + {0x4700,"18LF13K50 rev%d\r\n",0x1F}, + {0x4720,"18LF14K50 rev%d\r\n",0x1F}, + {0x4740,"18F13K50 rev%d\r\n",0x1F}, + {0x4760,"18F14K50 rev%d\r\n",0x1F}, + {0x49C0,"18F6628 rev%d\r\n",0x1F}, + {0x49E0,"18F8628 rev%d\r\n",0x1F}, + {0x4A00,"18F6723 rev%d\r\n",0x1F}, + {0x4A20,"18F8723 rev%d\r\n",0x1F}, + {0x4C00,"18F24J50 rev%d\r\n",0x1F}, + {0x4C20,"18F25J50 rev%d\r\n",0x1F}, + {0x4C40,"18F26J50 rev%d\r\n",0x1F}, + {0x4C60,"18F44J50 rev%d\r\n",0x1F}, + {0x4C80,"18F45J50 rev%d\r\n",0x1F}, + {0x4D80,"18F24J11 rev%d\r\n",0x1F}, + {0x4DA0,"18F25J11 rev%d\r\n",0x1F}, + {0x4DC0,"18F26J11 rev%d\r\n",0x1F}, + {0x4DE0,"18F44J11 rev%d\r\n",0x1F}, + {0x4E00,"18F45J11 rev%d\r\n",0x1F}, + {0x4E20,"18F46J11 rev%d\r\n",0x1F}, + {0x4E60,"18LF25J11 rev%d\r\n",0x1F}, + {0x4E80,"18LF26J11 rev%d\r\n",0x1F}, + {0x4EA0,"18LF44J11 rev%d\r\n",0x1F}, + {0x4EC0,"18LF45J11 rev%d\r\n",0x1F}, + {0x4EE0,"18LF46J11 rev%d\r\n",0x1F}, + {0x4F20,"18F14K22 rev%d\r\n",0x1F}, + {0x4F40,"18F13K22 rev%d\r\n",0x1F}, + {0x4F60,"18LF14K22 rev%d\r\n",0x1F}, + {0x4F80,"18LF13K22 rev%d\r\n",0x1F}, + {0x5000,"18F66J90 rev%d\r\n",0x1F}, + {0x5020,"18F67J90 rev%d\r\n",0x1F}, + {0x5040,"18F66J93/86J72 rev%d\r\n",0x1F}, + {0x5060,"18F67J93/87J72 rev%d\r\n",0x1F}, + {0x5080,"18F86J90 rev%d\r\n",0x1F}, + {0x50A0,"18F87J90 rev%d\r\n",0x1F}, + {0x50C0,"18F86J93 rev%d\r\n",0x1F}, + {0x50E0,"18F87J93 rev%d\r\n",0x1F}, + {0x5400,"18F46K22 rev%d\r\n",0x1F}, + {0x5420,"18LF46K22 rev%d\r\n",0x1F}, + {0x5440,"18F26K22 rev%d\r\n",0x1F}, + {0x5460,"18LF26K22 rev%d\r\n",0x1F}, + {0x5500,"18F45K22 rev%d\r\n",0x1F}, + {0x5520,"18LF45K22 rev%d\r\n",0x1F}, + {0x5540,"18F25K22 rev%d\r\n",0x1F}, + {0x5560,"18LF25K22 rev%d\r\n",0x1F}, + {0x5600,"18F44K22 rev%d\r\n",0x1F}, + {0x5620,"18LF44K22 rev%d\r\n",0x1F}, + {0x5640,"18F24K22 rev%d\r\n",0x1F}, + {0x5660,"18LF24K22 rev%d\r\n",0x1F}, + {0x5700,"18F43K22 rev%d\r\n",0x1F}, + {0x5720,"18LF43K22 rev%d\r\n",0x1F}, + {0x5740,"18F23K22 rev%d\r\n",0x1F}, + {0x5760,"18LF23K22 rev%d\r\n",0x1F}, + {0x5820,"18F26J53 rev%d\r\n",0x1F}, + {0x5860,"18F27J53 rev%d\r\n",0x1F}, + {0x58A0,"18F46J53 rev%d\r\n",0x1F}, + {0x58E0,"18F47J53 rev%d\r\n",0x1F}, + {0x5920,"18F26J13 rev%d\r\n",0x1F}, + {0x5960,"18F27J13 rev%d\r\n",0x1F}, + {0x59A0,"18F46J13 rev%d\r\n",0x1F}, + {0x59E0,"18F47J13 rev%d\r\n",0x1F}, + {0x5A20,"18LF26J53 rev%d\r\n",0x1F}, + {0x5A60,"18LF27J53 rev%d\r\n",0x1F}, + {0x5AA0,"18LF46J53 rev%d\r\n",0x1F}, + {0x5AE0,"18LF47J53 rev%d\r\n",0x1F}, + {0x5B20,"18LF26J13 rev%d\r\n",0x1F}, + {0x5B60,"18LF27J13 rev%d\r\n",0x1F}, + {0x5BA0,"18LF46J13 rev%d\r\n",0x1F}, + {0x5BE0,"18LF47J13 rev%d\r\n",0x1F}, + {0x5C00,"18F45K50 rev%d\r\n",0x1F}, + {0x5C20,"18F25K50 rev%d\r\n",0x1F}, + {0x5C60,"18F24K50 rev%d\r\n",0x1F}, + {0x5C80,"18LF45K50 rev%d\r\n",0x1F}, + {0x5CA0,"18LF25K50 rev%d\r\n",0x1F}, + {0x5CE0,"18LF24K50 rev%d\r\n",0x1F}, + {0x5D00,"18F46K50 rev%d\r\n",0x1F}, + {0x5D20,"18F26K50 rev%d\r\n",0x1F}, + {0x5D40,"18LF46K50 rev%d\r\n",0x1F}, + {0x5D60,"18LF26K50 rev%d\r\n",0x1F}, + {0x60E0,"18F66K80 rev%d\r\n",0x1F}, + {0x6100,"18F46K80 rev%d\r\n",0x1F}, + {0x6120,"18F26K80 rev%d\r\n",0x1F}, + {0x6140,"18F65K80 rev%d\r\n",0x1F}, + {0x6160,"18F45K80 rev%d\r\n",0x1F}, + {0x6180,"18F25K80 rev%d\r\n",0x1F}, + {0x61C0,"18LF66K80 rev%d\r\n",0x1F}, + {0x61E0,"18LF46K80 rev%d\r\n",0x1F}, + {0x6200,"18LF26K80 rev%d\r\n",0x1F}, + {0x6220,"18LF65K80 rev%d\r\n",0x1F}, + {0x6240,"18LF45K80 rev%d\r\n",0x1F}, + {0x6260,"18LF25K80 rev%d\r\n",0x1F}, + {0x6B80,"18F57K42 rev%c%d\r\n",0xFFFF}, + {0x6BA0,"18F56K42 rev%c%d\r\n",0xFFFF}, + {0x6BC0,"18F55K42 rev%c%d\r\n",0xFFFF}, + {0x6BE0,"18F47K42 rev%c%d\r\n",0xFFFF}, + {0x6C00,"18F46K42 rev%c%d\r\n",0xFFFF}, + {0x6C20,"18F45K42 rev%c%d\r\n",0xFFFF}, + {0x6C40,"18F27K42 rev%c%d\r\n",0xFFFF}, + {0x6C60,"18F26K42 rev%c%d\r\n",0xFFFF}, + {0x6CC0,"18LF57K42 rev%c%d\r\n",0xFFFF}, + {0x6CE0,"18LF56K42 rev%c%d\r\n",0xFFFF}, + {0x6D00,"18LF55K42 rev%c%d\r\n",0xFFFF}, + {0x6D20,"18LF47K42 rev%c%d\r\n",0xFFFF}, + {0x6D40,"18LF46K42 rev%c%d\r\n",0xFFFF}, + {0x6D60,"18LF45K42 rev%c%d\r\n",0xFFFF}, + {0x6D80,"18LF27K42 rev%c%d\r\n",0xFFFF}, + {0x6DA0,"18LF26K42 rev%c%d\r\n",0xFFFF}, + {0x6EC0,"18F26K83 rev%c%d\r\n",0xFFFF}, + {0x6EE0,"18F25K83 rev%c%d\r\n",0xFFFF}, + {0x6F00,"18LF26K83 rev%c%d\r\n",0xFFFF}, + {0x6F20,"18LF25K83 rev%c%d\r\n",0xFFFF}, + {0x73C0,"18F25Q43 rev%c%d\r\n",0xFFFF}, + {0x73E0,"18F45Q43 rev%c%d\r\n",0xFFFF}, + {0x7400,"18F55Q43 rev%c%d\r\n",0xFFFF}, + {0x7420,"18F26Q43 rev%c%d\r\n",0xFFFF}, + {0x7440,"18F46Q43 rev%c%d\r\n",0xFFFF}, + {0x7460,"18F56Q43 rev%c%d\r\n",0xFFFF}, + {0x7480,"18F27Q43 rev%c%d\r\n",0xFFFF}, + {0x74A0,"18F47Q43 rev%c%d\r\n",0xFFFF}, + {0x74C0,"18F57Q43 rev%c%d\r\n",0xFFFF}, + {0x74E0,"18F15Q41 rev%c%d\r\n",0xFFFF}, + {0x7500,"18F05Q41 rev%c%d\r\n",0xFFFF}, + {0x7520,"18F14Q41 rev%c%d\r\n",0xFFFF}, + {0x7540,"18F04Q41 rev%c%d\r\n",0xFFFF}, + {0x7560,"18F16Q41 rev%c%d\r\n",0xFFFF}, + {0x7580,"18F06Q41 rev%c%d\r\n",0xFFFF}, + {0x75A0,"18F16Q40 rev%c%d\r\n",0xFFFF}, + {0x75C0,"18F06Q40 rev%c%d\r\n",0xFFFF}, + {0x75E0,"18F15Q40 rev%c%d\r\n",0xFFFF}, + {0x7600,"18F05Q40 rev%c%d\r\n",0xFFFF}, + {0x7620,"18F14Q40 rev%c%d\r\n",0xFFFF}, + {0x7640,"18F04Q40 rev%c%d\r\n",0xFFFF}, + {0x7660,"18F24Q71 rev%c%d\r\n",0xFFFF}, + {0x76A0,"18F25Q71 rev%c%d\r\n",0xFFFF}, + {0x76E0,"18F26Q71 rev%c%d\r\n",0xFFFF}, + {0x7720,"18F46Q71 rev%c%d\r\n",0xFFFF}, + {0x7760,"18F56Q71 rev%c%d\r\n",0xFFFF}, + {0x77A0,"18F44Q71 rev%c%d\r\n",0xFFFF}, + {0x77E0,"18F45Q71 rev%c%d\r\n",0xFFFF}, + {0x7820,"18F54Q71 rev%c%d\r\n",0xFFFF}, + {0x7860,"18F55Q71 rev%c%d\r\n",0xFFFF}, + {0x9900,"18F26Q84 rev%c%d\r\n",0xFFFF}, + {0x9901,"18F46Q84 rev%c%d\r\n",0xFFFF}, + {0x9902,"18F56Q84 rev%c%d\r\n",0xFFFF}, + {0x9903,"18F27Q84 rev%c%d\r\n",0xFFFF}, + {0x9904,"18F47Q84 rev%c%d\r\n",0xFFFF}, + {0x9905,"18F57Q84 rev%c%d\r\n",0xFFFF}, + {0x9906,"18F26Q83 rev%c%d\r\n",0xFFFF}, + {0x9907,"18F46Q83 rev%c%d\r\n",0xFFFF}, + {0x9908,"18F56Q83 rev%c%d\r\n",0xFFFF}, + {0x9909,"18F27Q83 rev%c%d\r\n",0xFFFF}, + {0x990A,"18F47Q83 rev%c%d\r\n",0xFFFF}, + {0x990B,"18F57Q83 rev%c%d\r\n",0xFFFF}, +}; + +void PIC18_ID(int id) +{ + char s[128]; + int i; + for(i=0;i>22)&0x3F; + int MNrev=(id>>16)&0x3F; + sprintf(s,PIC18LIST[i].device,MJrev+'A',MNrev); + PrintMessage(s); + return; + } + } + sprintf(s,"%s",strings[S_nodev]); //"Unknown device\r\n"); + PrintMessage(s); +} + +void DisplayCODE18F(int dim){ +// display PIC18F CODE memory + char s[256]="",t[256]=""; + char* aux=(char*)malloc((dim/COL+1)*(16+COL*6)); + aux[0]=0; + int valid=0,empty=1,i,j,lines=0; + for(i=0;i500){ //limit number of lines printed + strcat(aux,"(...)\r\n"); + i=(dim>4)&0xF; + if(dim>0x1FFFFF||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n" + return; + } + if(dim2>0x800||dim2<0){ + PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n" + return; + } + if(entry>0&&!CheckV33Regulator()){ + PrintMessage(strings[S_noV33reg]); //Can't find 3.3V expansion board + return; + } + double vpp=-1; + if(entry==0) vpp=12; + else if(entry==1||entry==3) vpp=8.5; + if(!StartHVReg(vpp)){ + PrintMessage(strings[S_HVregErr]); //"HV regulator error\r\n" + return; + } + if(saveLog){ + OpenLogFile(); //"log.txt" + fprintf(logfile,"Read18F(%d,%d,%d) (0x%X,0x%X,0x%X)\n",dim,dim2,options,dim,dim2,options); + } + size=dim; + sizeEE=dim2; + if(memCODE) free(memCODE); + memCODE=(unsigned char*)malloc(size); //CODE + if(memEE) free(memEE); + memEE=(unsigned char*)malloc(sizeEE); //EEPROM + for(j=0;j<8;j++) memID[j]=0xFF; + for(j=0;j<14;j++) memCONFIG[j]=0xFF; + unsigned int start=GetTickCount(); + j=0; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T1T2; + bufferU[j++]=1; //T1=1u + bufferU[j++]=100; //T2=100u + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=2000>>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=NOP; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + if(entry==2){ //LV entry with key + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + } + if(entry==2||entry==3){ //entry with key + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x4D; + bufferU[j++]=0x43; + bufferU[j++]=0x48; + bufferU[j++]=0x50; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=WAIT_T3; + } + bufferU[j++]=WAIT_T3; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; //3F + bufferU[j++]=0x3F; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //-> TBLPTRU + bufferU[j++]=0xF8; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; //FF + bufferU[j++]=0xFF; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //-> TBLPTRH + bufferU[j++]=0xF7; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; //FE + bufferU[j++]=0xFE; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //-> TBLPTRL + bufferU[j++]=0xF6; + bufferU[j++]=TBLR_INC_N; //DevID1-2 0x3FFFFE-F + bufferU[j++]=2; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6A; //CLRF TBLPTRU + bufferU[j++]=0xF8; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6A; //CLRF TBLPTRH + bufferU[j++]=0xF7; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6A; //CLRF TBLPTRL + bufferU[j++]=0xF6; + bufferU[j++]=FLUSH; + for(;j>8)&0xFF; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //MOVWF + bufferU[j++]=newAddr==0?0xAA:0x75; //ADDRH + bufferU[j++]=CORE_INS; + bufferU[j++]=0x80; //RD=1 + bufferU[j++]=newAddr==0?0xA6:0x7F; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x50; //MOVF EEDATA,w + bufferU[j++]=newAddr==0?0xA8:0x73; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //MOVWF TABLAT + bufferU[j++]=0xF5; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x00; //NOP + bufferU[j++]=0x00; + bufferU[j++]=SHIFT_TABLAT; + if(j>DIMBUF-26||i==dim2-1){ + bufferU[j++]=FLUSH; + for(;j= 0x10000) +// eraseW2=erase word @3C0004 (not used if >= 0x10000) +// options: +// bit [3:0] +// 0 = vdd before vpp (12V) +// 1 = vdd before vpp (9V) +// 2 = low voltage entry with 32 bit key +// 3 = vdd before vpp (9V) with 32 bit key +// bit [7:4] +// 0 = normal eeprom write algoritm +// 1 = with unlock sequence 55 AA +// bit [11:8] +// 0 = 15ms erase delay, 1ms code write time, 5ms EE write, 5ms config write +// 1 = 550ms erase delay, 1.2ms code write time, no config or EEPROM +// 2 = 550ms erase delay, 3.4ms code write time, no config or EEPROM +// 3 = separate block erase with 5ms delay, 1ms code write, 5ms EE write, 5ms config write +// + new control registers address (18FxxK80) +{ + int k=0,k2,z=0,i,j; + int err=0; + int EEalgo=(options>>4)&0xF,entry=options&0xF,optWrite=(options>>8)&0xF; + if(dim>0x1FFFFF||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n" + return; + } + if(dim2>0x800||dim2<0){ + PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n" + return; + } + if(wbuf>64){ + PrintMessage(strings[S_WbufLim]); //"Write buffer size out of limits\r\n" + return; + } + if(entry>0&&!CheckV33Regulator()){ + PrintMessage(strings[S_noV33reg]); //Can't find 3.3V expansion board + return; + } + double vpp=-1; + if(entry==0) vpp=12; + else if(entry==1||entry==3) vpp=8.5; + if(!StartHVReg(vpp)){ + PrintMessage(strings[S_HVregErr]); //"HV regulator error\r\n" + return; + } + if(saveLog){ + OpenLogFile(); //"log.txt" + fprintf(logfile,"Write18F(%d,%d,%d,%d) (0x%X,0x%X,0x%X,0x%X)\n",dim,dim2,wbuf,options,dim,dim2,wbuf,options); + } + if(dim>size) dim=size; + if(dim%wbuf){ //grow to an integer number of rows + dim+=wbuf-dim%wbuf; + j=size; + if(jsizeEE) dim2=sizeEE; + if(dim<1){ + PrintMessage(strings[S_NoCode]); //"Empty data area\r\n" + return; + } + unsigned int start=GetTickCount(); + j=0; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T1T2; + bufferU[j++]=1; //T1=1u + bufferU[j++]=100; //T2=100u + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + if(entry==2){ //LV entry with key + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + } + if(entry==2||entry==3){ //entry with key + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x4D; + bufferU[j++]=0x43; + bufferU[j++]=0x48; + bufferU[j++]=0x50; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=WAIT_T3; + } + bufferU[j++]=WAIT_T3; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; //3F + bufferU[j++]=0x3F; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //-> TBLPTRU + bufferU[j++]=0xF8; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; //FF + bufferU[j++]=0xFF; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //-> TBLPTRH + bufferU[j++]=0xF7; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; //FE + bufferU[j++]=0xFE; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //-> TBLPTRL + bufferU[j++]=0xF6; + bufferU[j++]=TBLR_INC_N; //DevID1-2 0x3FFFFE-F + bufferU[j++]=2; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=5100>>8; + bufferU[j++]=5100&0xff; + bufferU[j++]=FLUSH; + for(;j TBLPTRU + bufferU[j++]=0xF8; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6A; //TBLPTRH=0 + bufferU[j++]=0xF7; + if(eraseW1<0x10000){ + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; //05 + bufferU[j++]=0x05; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //-> TBLPTRL + bufferU[j++]=0xF6; + bufferU[j++]=TABLE_WRITE; // eraseW1@3C0005 + bufferU[j++]=(eraseW1>>8)&0xFF; //0x3F; + bufferU[j++]=eraseW1&0xFF; //0x3F; + } + if(eraseW2<0x10000){ + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; //04 + bufferU[j++]=0x04; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //-> TBLPTRL + bufferU[j++]=0xF6; + bufferU[j++]=TABLE_WRITE; // eraseW2@3C0004 + bufferU[j++]=(eraseW2>>8)&0xFF; //0x8F; + bufferU[j++]=eraseW2&0xFF; //0x8F; + } + bufferU[j++]=CORE_INS; //NOP + bufferU[j++]=0x00; + bufferU[j++]=0x00; + bufferU[j++]=CORE_INS; //NOP + bufferU[j++]=0x00; + bufferU[j++]=0x00; + bufferU[j++]=FLUSH; + for(;j=dim) break; + if(i>i0){ //some rows were skipped; update current address + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; + bufferU[j++]=(i>>16)&0xFF; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //MOVWF TBLPTRU + bufferU[j++]=0xF8; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; + bufferU[j++]=(i>>8)&0xFF; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //MOVWF TBLPTRH + bufferU[j++]=0xF7; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; + bufferU[j++]=i&0xFF; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //MOVWF TBLPTRL + bufferU[j++]=0xF6; + bufferU[j++]=FLUSH; + for(;jDIMBUF-8){ + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=1200&0xFF; + } + else if(optWrite==2){ //3.4ms + bufferU[j++]=3400>>8; + bufferU[j++]=3400&0xFF; + } + else{ //1ms + bufferU[j++]=1000>>8; + bufferU[j++]=1000&0xFF; + } + i+=2; + k=0; + } + bufferU[j++]=FLUSH; + for(;j>8; //only one write so no need to specify different delay + bufferU[j++]=1000&0xFF; + bufferU[j++]=FLUSH; + for(;j>8)&0xFF; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //MOVWF + bufferU[j++]=optWrite!=3?0xAA:0x75; //ADDRH + } + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; //MOVLW + bufferU[j++]=memEE[i]; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //MOVWF + bufferU[j++]=optWrite!=3?0xA8:0x73; //EEDATA + if(EEalgo==1){ //memory unlock + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; //MOVLW + bufferU[j++]=0x55; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //MOVWF + bufferU[j++]=0xA7; //EECON2 + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; //MOVLW + bufferU[j++]=0xAA; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //MOVWF + bufferU[j++]=0xA7; //EECON2 + } + bufferU[j++]=CORE_INS; + bufferU[j++]=0x82; + bufferU[j++]=optWrite!=3?0xA6:0x7F; //WR=1 + bufferU[j++]=CORE_INS; + bufferU[j++]=0x00; + bufferU[j++]=0x00; //NOP + bufferU[j++]=CORE_INS; + bufferU[j++]=0x00; + bufferU[j++]=0x00; //NOP + bufferU[j++]=WAIT_T3; //write delay + bufferU[j++]=CORE_INS; + bufferU[j++]=0x80; //RD=1 + bufferU[j++]=optWrite!=3?0xA6:0x7F; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x50; //MOVF EEDATA,w + bufferU[j++]=optWrite!=3?0xA8:0x73; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //MOVWF TABLAT + bufferU[j++]=0xF5; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x00; //NOP + bufferU[j++]=0x00; + bufferU[j++]=SHIFT_TABLAT; + bufferU[j++]=FLUSH; + for(;j=dim) break; + if(i>i0){ //some data was skipped; update current address + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; + bufferU[j++]=(i>>16)&0xFF; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //MOVWF TBLPTRU + bufferU[j++]=0xF8; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; + bufferU[j++]=(i>>8)&0xFF; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //MOVWF TBLPTRH + bufferU[j++]=0xF7; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x0E; + bufferU[j++]=i&0xFF; + bufferU[j++]=CORE_INS; + bufferU[j++]=0x6E; //MOVWF TBLPTRL + bufferU[j++]=0xF6; + bufferU[j++]=FLUSH; + for(;j=max_err) break; + } + PrintStatusEnd(); + if(i=max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + } +//****************** verify ID ******************** + if(programID&&err=max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,0,0,err); //"i=%d, k=%d, errors=%d\n" + } + } +//****************** write CONFIG ******************** + if(err>8; + bufferU[j++]=5000&0xFF; + } + bufferU[j++]=CORE_INS; + bufferU[j++]=0x2A; //INCF + bufferU[j++]=0xF6; //TBLPTRL + i++; + if(memCONFIG[i]<0xFF){ + bufferU[j++]=TBLW_PROG; + bufferU[j++]=memCONFIG[i]; + bufferU[j++]=0; + bufferU[j++]=5000>>8; + bufferU[j++]=5000&0xFF; + } + bufferU[j++]=CORE_INS; + bufferU[j++]=0x2A; //INCF + bufferU[j++]=0xF6; //TBLPTRL + bufferU[j++]=FLUSH; + for(;j=max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,0,0,err); //"i=%d, k=%d, errors=%d\n" + } + } + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=2000>>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=1; + bufferU[j++]=EN_VPP_VCC; //0 + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j0 use eeprom, size is automatic when reading DCI +// options: +// bit [3:0] +// 0 = vpp before vdd (8.5V) +// bit [7:4] memory layout +// code config EE DCI DIA model +// 0 5 0x310000 0x3FFF00 0x3F0000 K42 K83 +// 1 10 0x380000 0x3C0000 0x2C0000 Q40-43 +// 2 35 0x380000 0x3C0000 0x2C0000 Q83-84 +{ + int k=0,k2=0,z=0,i,j; + int devID=0,devREV=0; + int MemAddr; + int EEaddr=0,DCIaddr=0,DIAaddr=0,DIAlen=0,UIDlen=0,CONFIGlen=0; + int type=(options>>4)&0xF; + if(type==0){ //K42 K83 + EEaddr=0x310000; + DCIaddr=0x3FFF00; + DIAaddr=0x3F0000; + DIAlen=0x40; + UIDlen=0x10; + CONFIGlen=5; + } + else if(type==1){ //Q43 + EEaddr=0x380000; + DCIaddr=0x3C0000; + DIAaddr=0x2C0000; + DIAlen=0x100; + UIDlen=0x40; + CONFIGlen=10; + } + else if(type==2){ //Q83-84 + EEaddr=0x380000; + DCIaddr=0x3C0000; + DIAaddr=0x2C0000; + DIAlen=0x100; + UIDlen=0x40; + CONFIGlen=35; + } + else PrintMessage("unexpected parameter"); + if(dim>0x1FFFFF||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n" + return; + } + if(dim2>0x800||dim2<0){ + PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n" + return; + } + if(!CheckV33Regulator()){ + PrintMessage(strings[S_noV33reg]); //Can't find 3.3V expansion board + return; + } + double vpp=8.5; + if(!StartHVReg(vpp)){ + PrintMessage(strings[S_HVregErr]); //"HV regulator error\r\n" + return; + } + if(saveLog){ + OpenLogFile(); //"log.txt" + fprintf(logfile,"Read18FKx(%d,%d,%d) (0x%X,0x%X,0x%X)\n",dim,dim2,options,dim,dim2,options); + } + size=dim; + if(memCODE) free(memCODE); + memCODE=(unsigned char*)malloc(size); //CODE + unsigned char* memDIA=(unsigned char*)malloc(DIAlen); //DIA + for(j=0;j<64;j++) memID[j]=0xFF; + for(j=0;j<14;j++) memCONFIG[j]=0xFF; + for(j=0;j>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=EN_VPP_VCC; //VPP + bufferU[j++]=0x4; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=WAIT_T3; + MemAddr=0x3FFFFc<<1; //devREV + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x80; + bufferU[j++]=MemAddr>>16; + bufferU[j++]=(MemAddr>>8)&0xFF; + bufferU[j++]=MemAddr&0xFF; + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + MemAddr=DCIaddr<<1; //DCI + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x80; + bufferU[j++]=MemAddr>>16; + bufferU[j++]=(MemAddr>>8)&0xFF; + bufferU[j++]=MemAddr&0xFF; + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x80; + bufferU[j++]=0x0; + bufferU[j++]=0x0; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;jDIMBUF||i==dim-2){ //2B cmd -> 3B data + bufferU[j++]=FLUSH; //remember: FLUSH generates a response (even empty)! + for(;j>16; + bufferU[j++]=(MemAddr>>8)&0xFF; + bufferU[j++]=MemAddr&0xFF; + k2=0; + for(i=0;iDIMBUF||i==CONFIGlen-1){ //2B cmd -> 3B data + bufferU[j++]=FLUSH; + for(;j>16; + bufferU[j++]=(MemAddr>>8)&0xFF; + bufferU[j++]=MemAddr&0xFF; + k2=0; + for(i=0;iDIMBUF||i==UIDlen-2){ //2B cmd -> 3B data + bufferU[j++]=FLUSH; + for(;j>16; + bufferU[j++]=(MemAddr>>8)&0xFF; + bufferU[j++]=MemAddr&0xFF; + k2=0; + for(i=0;iDIMBUF||i==DIAlen-2){ //2B cmd -> 3B data + bufferU[j++]=FLUSH; + for(;j0x1000||sizeEE<0){ //Max 4K + PrintMessage(strings[S_EELim]); //"EEPROM size exceeds limits\r\n" + return; + } + if(memEE) free(memEE); + memEE=(unsigned char*)malloc(sizeEE); //EEPROM + for(i=0;i>16; + bufferU[j++]=(MemAddr>>8)&0xFF; + bufferU[j++]=MemAddr&0xFF; + for(i=k=0;iDIMBUF||i==sizeEE-1){ //2B cmd -> 3B answer + bufferU[j++]=FLUSH; + for(;j>4)&0xF; + if(type==0){ //K42 K83 + EEaddr=0x310000; + DCIaddr=0x3FFF00; + DIAaddr=0x3F0000; + DIAlen=0x40; + UIDlen=0x10; + CONFIGlen=5; + } + else if(type==1){ //Q43 + EEaddr=0x380000; + DCIaddr=0x3C0000; + DIAaddr=0x2C0000; + DIAlen=0x100; + UIDlen=0x40; + CONFIGlen=10; + } + else if(type==2){ //Q83-84 + EEaddr=0x380000; + DCIaddr=0x3C0000; + DIAaddr=0x2C0000; + DIAlen=0x100; + UIDlen=0x40; + CONFIGlen=35; + } + else PrintMessage("unexpected parameter"); + if(dim>0x1FFFFF||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n" + return; + } + if(dim2>0x800||dim2<0){ + PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n" + return; + } + if(!CheckV33Regulator()){ + PrintMessage(strings[S_noV33reg]); //Can't find 3.3V expansion board + return; + } + double vpp=8.5; + if(!StartHVReg(vpp)){ + PrintMessage(strings[S_HVregErr]); //"HV regulator error\r\n" + return; + } + if(saveLog){ + OpenLogFile(); //"log.txt" + fprintf(logfile,"Write18FKx(%d,%d,%d) (0x%X,0x%X,0x%X)\n",dim,dim2,options,dim,dim2,options); + } + if(dim>size) dim=size; + if(dim2>sizeEE) dim2=sizeEE; + if(dim<1){ + PrintMessage(strings[S_NoCode]); //"Empty data area\r\n" + return; + } + unsigned int start=GetTickCount(); + j=0; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T1T2; + bufferU[j++]=2; //T1=2u + bufferU[j++]=35; //T2 adjusted to obtain ~80us when needed + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=11000>>8; + bufferU[j++]=11000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=EN_VPP_VCC; //VPP + bufferU[j++]=0x4; + bufferU[j++]=EN_VPP_VCC; //VDD+VPP + bufferU[j++]=0x5; + bufferU[j++]=WAIT_T3; + MemAddr=0x3FFFFc<<1; //devREV + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x80; + bufferU[j++]=MemAddr>>16; + bufferU[j++]=(MemAddr>>8)&0xFF; + bufferU[j++]=MemAddr&0xFF; + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + MemAddr=DCIaddr<<1; //DCI + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x80; + bufferU[j++]=MemAddr>>16; + bufferU[j++]=(MemAddr>>8)&0xFF; + bufferU[j++]=MemAddr&0xFF; + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x80; + bufferU[j++]=0x0; + bufferU[j++]=0x0; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=25500&0xff; + MemAddr=0x300000<<1; //address to erase Flash+User+Config + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x80; + bufferU[j++]=MemAddr>>16; + bufferU[j++]=(MemAddr>>8)&0xFF; + bufferU[j++]=MemAddr&0xFF; + bufferU[j++]=ICSP8_SHORT; + bufferU[j++]=BULK_ERASE; + bufferU[j++]=WAIT_T3; //TERAB + MemAddr=0x310000<<1; //address to erase EEPROM + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x80; + bufferU[j++]=MemAddr>>16; + bufferU[j++]=(MemAddr>>8)&0xFF; + bufferU[j++]=MemAddr&0xFF; + bufferU[j++]=ICSP8_SHORT; + bufferU[j++]=BULK_ERASE; + bufferU[j++]=WAIT_T3; //TERAB + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=2800>>8; + bufferU[j++]=2800&0xff; + bufferU[j++]=FLUSH; + for(;j9){ //set new address + i+=x; + MemAddr=i<<1; + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x80; + bufferU[j++]=MemAddr>>16; + bufferU[j++]=(MemAddr>>8)&0xFF; + bufferU[j++]=MemAddr&0xFF; + i-=2; + } + else{ + bufferU[j++]=ICSP8_SHORT; + bufferU[j++]=INC_ADDR8; + } + } + if(j>DIMBUF-8||i==dim-2){ + PrintStatus(strings[S_CodeWriting],i*100/(dim+dim2),i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;jmax_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + i=dim; + z=DIMBUF; + } + } + k+=2; + z+=4; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,err); //"i=%d, k=%d, errors=%d,\n" + } + } + } + err+=i-k; + } + else if(type==0){ //K42 K83 + int valid; + for(;dim>0&&memCODE[dim-1]==0xff&&memCODE[dim-2]==0xff;dim-=2); //skip empty space at end + if(dim%rowN) dim+=rowN-dim%rowN; //grow to N byte multiple + if(dim>size){ + memCODE=(unsigned char*)realloc(memCODE,dim); + for(;size>16; + bufferU[j++]=(MemAddr>>8)&0xFF; + bufferU[j++]=MemAddr&0xFF; + for(k=0;kDIMBUF-5){ + bufferU[j++]=FLUSH; + for(;j9){ //set new address + i+=x; + k=i; + MemAddr=i<<1; + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x80; + bufferU[j++]=MemAddr>>16; + bufferU[j++]=(MemAddr>>8)&0xFF; + bufferU[j++]=MemAddr&0xFF; + } + } + bufferU[j++]=ICSP8_READ; + bufferU[j++]=READ_NVM_INC; + if((j+1)/2*3+3>DIMBUF||i==dim-2){ //2B cmd -> 3B data + bufferU[j++]=FLUSH; + for(;j=max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + i=dim; + } + } + } + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=5600>>8; + bufferU[j++]=5600&0xff; + bufferU[j++]=FLUSH; + for(;j>16; + bufferU[j++]=(MemAddr>>8)&0xFF; + bufferU[j++]=MemAddr&0xFF; + for(i=k=0;iDIMBUF-8||i==dim2-1){ + PrintStatus(strings[S_CodeWriting],(i+dim)*100/(dim+dim2),i+EEaddr); //"Writing: %d%%, addr. %03X" + bufferU[j++]=FLUSH; + for(;jmax_err){ + PrintMessage1(strings[S_MaxErr],err+errEE); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim2; + z=DIMBUF; + } + } + k++; + z+=type==1?4:5; + } + } + j=0; + w=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,errEE); //"i=%d, k=%d, errors=%d,\n" + } + } + } + errEE+=i-k; + err+=errEE; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],errEE); //"completed, %d errors\r\n" + } +//****************** write and verify ID ******************** + #define IDaddr 0x200000 + if(programID){ + PrintMessage(strings[S_IDW]); //"Write ID ... " + if(saveLog) fprintf(logfile,"Write ID\n"); + int errID=0; + j=0; + MemAddr=IDaddr<<1; + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x80; + bufferU[j++]=MemAddr>>16; + bufferU[j++]=(MemAddr>>8)&0xFF; + bufferU[j++]=MemAddr&0xFF; + for(i=k=0;iDIMBUF-8||i==UIDlen-2){ + PrintStatus(strings[S_CodeWriting],99,IDaddr+i); //"Writing: %d%%, add. %03X" + bufferU[j++]=FLUSH; + for(;jmax_err){ + PrintMessage1(strings[S_MaxErr],err+errID); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=UIDlen; + z=DIMBUF; + } + } + k+=2; + z+=type==1?4:5; + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,errID); //"i=%d, k=%d, errors=%d,\n" + } + } + } + errID+=i-k; + err+=errID; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],errID); //"completed, %d errors\r\n" + } +//****************** write and verify CONFIG ******************** + #define CONFIGaddr 0x300000 + if(err>16; + bufferU[j++]=(MemAddr>>8)&0xFF; + bufferU[j++]=MemAddr&0xFF; + for(i=k=0;iDIMBUF-8||i==CONFIGlen-1){ + PrintStatus(strings[S_CodeWriting],99,i+CONFIGaddr); //"Writing: %d%%, addr. %03X" + bufferU[j++]=FLUSH; + for(;jmax_err){ + PrintMessage1(strings[S_MaxErr],err+errC); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + PrintMessage(strings[S_IntW]); //"Write interrupted" + i=dim2; + z=DIMBUF; + } + } + if(type==1){ //Q43 single byte + k++; + z+=4; + } + else if(type==0){ //K42 K83 2 bytes + k+=2; + z+=5; + } + } + } + j=0; + if(saveLog){ + fprintf(logfile,strings[S_Log8],i,i,k,k,errC); //"i=%d, k=%d, errors=%d,\n" + } + } + } + errC+=10-k; + err+=errC; + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],errC); //"completed, %d errors\r\n" + } + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=1; + bufferU[j++]=EN_VPP_VCC; //0 + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j + */ + +/* + ICSP Code(KWord) EE(B) Config Code_er Row Row_wr EE_er EE_wr Conf_wr wr_seq +24F0xKAxxx HV|LV 1.375-5.5 512 00-10(8b) 4064 32 4004 4050 4004 4004 NO +24FJxxGA0xx LV 5.5-44 NO Code-2(16b) 404F 64 4001 - - 4003 NO +24FJxxGA1x/GB0x LV 11-22 NO Code-4(16b) 404F 64 4001 - - 4003 NO +xDA/GB2/GA3/GC " 22-87 " " " +(new TABLPAG) +24FJxxGB1x LV 22-87 NO Code-3(16b) 404F 64 4001 - - 4003 NO +24HJ-33FJ LV 2-88 NO 00-12/16(8b) 404F 64 4001 - - 4000 NO +24E-33E LV 11-88 NO Code-20(8b) 400F 2 4001 - - 4001 55-AA +(new TABLPAG, new algorithm) +30Fxx10-16 HV2 4-48 0-4K 00-0C(16b) 407F 32 4001 seq. 4004 4008 55-AA +30F2020-23 LV5V 2-4 NO 00-0E(16b) 407F 32 4001 - - 4008 55-AA + +*/ + +#include "common.h" + +void CheckData(int a,int b,int addr,int *err) +{ + if(a!=b){ +#ifdef _MSC_VER + CString str; +#endif + PrintMessage(strings[S_NL]); + PrintMessage4(strings[S_CodeVError],addr,addr,a,b); //"Error writing address %4X: written %02X, read %02X\r\n" + (*err)++; + } +} + +struct ID24{ + int id; + char *device; +} PIC24LIST[]={ + {0x0040,"30F2010"}, + {0x0041,"24HJ64GP206"}, + {0x0047,"24HJ64GP210"}, + {0x0049,"24HJ64GP506"}, + {0x004B,"24HJ64GP510"}, + {0x005D,"24HJ128GP206"}, + {0x005F,"24HJ128GP210"}, + {0x0061,"24HJ128GP506"}, + {0x0063,"24HJ128GP510"}, + {0x0065,"24HJ128GP306"}, + {0x0067,"24HJ128GP310"}, + {0x0071,"24HJ256GP206"}, + {0x0073,"24HJ256GP210"}, + {0x007B,"24HJ256GP610"}, + {0x0080,"30F5011"}, + {0x0081,"30F5013"}, + {0x0089,"33FJ64MC506"}, + {0x008A,"33FJ64MC508"}, + {0x008B,"33FJ64MC510"}, + {0x0091,"33FJ64MC706"}, + {0x0097,"33FJ64MC710"}, + {0x00A1,"33FJ128MC506"}, + {0x00A3,"33FJ128MC510"}, + {0x00A9,"33FJ128MC706"}, + {0x00AE,"33FJ128MC708"}, + {0x00AF,"33FJ128MC710"}, + {0x00B7,"33FJ256MC510"}, + {0x00BF,"33FJ256MC710"}, + {0x00C1,"30F3012/33FJ64GP206"}, + {0x00C3,"30F3013"}, + {0x00CD,"33FJ64GP306"}, + {0x00CF,"33FJ64GP310"}, + {0x00D5,"33FJ64GP706"}, + {0x00D6,"33FJ64GP708"}, + {0x00D7,"33FJ64GP710"}, + {0x00D9,"33FJ128GP206"}, + {0x00E5,"33FJ128GP306"}, + {0x00E7,"33FJ128GP310"}, + {0x00ED,"33FJ128GP706"}, + {0x00EE,"33FJ128GP708"}, + {0x00EF,"33FJ128GP710"}, + {0x00F5,"33FJ256GP506"}, + {0x00F7,"33FJ256GP510"}, + {0x00FF,"33FJ256GP710"}, + {0x0100,"30F4012"}, + {0x0101,"30F4011"}, + {0x0141,"30F4013"}, + {0x0160,"30F3014"}, + {0x0188,"30F6010"}, + {0x0192,"30F6011"}, + {0x0193,"30F6012"}, + {0x0197,"30F6013"}, + {0x0198,"30F6014"}, + {0x01C0,"30F3010"}, + {0x01C1,"30F3011"}, + {0x0200,"30F5015"}, + {0x0201,"30F5016"}, + {0x0240,"30F2011"}, + {0x0241,"30F2012"}, + {0x0280,"30F6015"}, + {0x0281,"30F6010A"}, + {0x02C0,"30F6011A"}, + {0x02C1,"30F6013A"}, + {0x02C2,"30F6012A"}, + {0x02C3,"30F6014A"}, + {0x0400,"30F2020"}, + {0x0403,"30F2023"}, + {0x0404,"30F1010"}, + {0x0405,"24FJ64GA006"}, + {0x0406,"24FJ96GA006"}, + {0x0407,"24FJ128GA006"}, + {0x0408,"24FJ64GA008"}, + {0x0409,"24FJ96GA008"}, + {0x040A,"24FJ128GA008"}, + {0x040B,"24FJ64GA010"}, + {0x040C,"24FJ96GA010"}, + {0x040D,"24FJ128GA010"}, + {0x0444,"24FJ16GA002"}, + {0x0445,"24FJ32GA002"}, + {0x0446,"24FJ48GA002"}, + {0x0447,"24FJ64GA002"}, + {0x044C,"24FJ16GA004"}, + {0x044D,"24FJ32GA004"}, + {0x044E,"24FJ48GA004"}, + {0x044F,"24FJ64GA004"}, + {0x0601,"33FJ32MC302"}, + {0x0603,"33FJ32MC304"}, + {0x0605,"33FJ32GP302"}, + {0x0607,"33FJ32GP304"}, + {0x0611,"33FJ64MC202"}, + {0x0613,"33FJ64MC204"}, + {0x0615,"33FJ64GP202"}, + {0x0617,"33FJ64GP204"}, + {0x0619,"33FJ64MC802"}, + {0x061B,"33FJ64MC804"}, + {0x061D,"33FJ64GP802"}, + {0x061F,"33FJ64GP804"}, + {0x0621,"33FJ128MC202"}, + {0x0623,"33FJ128MC204"}, + {0x0625,"33FJ128GP202"}, + {0x0627,"33FJ128GP204"}, + {0x0629,"33FJ128MC802"}, + {0x062B,"33FJ128MC804"}, + {0x062D,"33FJ128GP802"}, + {0x062F,"33FJ128GP804"}, + {0x0645,"24HJ32GP302"}, + {0x0647,"24HJ32GP304"}, + {0x0655,"24HJ64GP202"}, + {0x0657,"24HJ64GP204"}, + {0x0665,"24HJ128GP202"}, + {0x0667,"24HJ128GP204"}, + {0x0675,"24HJ64GP502"}, + {0x0677,"24HJ64GP504"}, + {0x067D,"24HJ128GP502"}, + {0x067F,"24HJ128GP504"}, + {0x0771,"24HJ256GP206A"}, + {0x0773,"24HJ256GP210A"}, + {0x077B,"24HJ256GP610A"}, + {0x07B7,"33FJ256MC510A"}, + {0x07BF,"33FJ256MC710A"}, + {0x07F5,"33FJ256GP506A"}, + {0x07F7,"33FJ256GP510A"}, + {0x07FF,"33FJ256GP710A"}, + {0x0800,"33FJ12MC201"}, + {0x0801,"33FJ12MC202"}, + {0x0802,"33FJ12GP201"}, + {0x0803,"33FJ12GP202"}, + {0x080A,"24HJ12GP201"}, + {0x080B,"24HJ12GP202"}, + {0x0C00,"33FJ06GS101"}, + {0x0C01,"33FJ06GS102"}, + {0x0C02,"33FJ06GS202"}, + {0x0C03,"33FJ16GS502"}, + {0x0C04,"33FJ16GS402"}, + {0x0C05,"33FJ16GS504"}, + {0x0C06,"33FJ16GS404"}, + {0x0D00,"24F04KA201"}, + {0x0D01,"24F16KA101"}, + {0x0D02,"24F04KA200"}, + {0x0D03,"24F16KA102"}, + {0x0D08,"24F08KA101"}, + {0x0D0A,"24F08KA102"}, + {0x0F03,"33FJ16MC304"}, + {0x0F07,"33FJ16GP304"}, + {0x0F09,"33FJ32MC202"}, + {0x0F0B,"33FJ32MC204"}, + {0x0F0D,"33FJ32GP202"}, + {0x0F0F,"33FJ32GP204"}, + {0x0F17,"24HJ16GP304"}, + {0x0F1D,"24HJ32GP202"}, + {0x0F1F,"24HJ32GP204"}, + {0x1001,"24FJ64GB106"}, + {0x1003,"24FJ64GB108"}, + {0x1007,"24FJ64GB110"}, + {0x1008,"24FJ128GA106"}, + {0x1009,"24FJ128GB106"}, + {0x100A,"24FJ128GA100"}, + {0x100B,"24FJ128GB108"}, + {0x100E,"24FJ128GA110"}, + {0x100F,"24FJ128GB110"}, + {0x1010,"24FJ192GA106"}, + {0x1011,"24FJ192GB106"}, + {0x1012,"24FJ192GA108"}, + {0x1013,"24FJ192GB108"}, + {0x1016,"24FJ192GA110"}, + {0x1017,"24FJ192GB110"}, + {0x1018,"24FJ256GA106"}, + {0x1019,"24FJ256GB106"}, + {0x101A,"24FJ256GA108"}, + {0x101B,"24FJ256GB108"}, + {0x101E,"24FJ256GA110"}, + {0x101F,"24FJ256GB110"}, + {0x1780,"33EP512MC204"}, + {0x1781,"33EP512MC202"}, + {0x1783,"33EP512MC206"}, + {0x1784,"33EP512MC504"}, + {0x1785,"33EP512MC502"}, + {0x1787,"33EP512MC506"}, + {0x178F,"33EP512GP506"}, + {0x1790,"24EP512MC204"}, + {0x1791,"24EP512MC202"}, + {0x1793,"24EP512MC206"}, + {0x1798,"24EP512GP204"}, + {0x1799,"24EP512GP202"}, + {0x179B,"24EP512GP206"}, + {0x178C,"33EP512GP504"}, + {0x178D,"33EP512GP502"}, + {0x1C00,"33EP32MC204"}, + {0x1C01,"33EP32MC202"}, + {0x1C02,"33EP32MC203"}, + {0x1C04,"33EP32MC504"}, + {0x1C05,"33EP32MC502"}, + {0x1C06,"33EP32MC503"}, + {0x1C0C,"33EP32GP504"}, + {0x1C0D,"33EP32GP502"}, + {0x1C0E,"33EP32GP503"}, + {0x1C10,"24EP32MC204"}, + {0x1C11,"24EP32MC202"}, + {0x1C12,"24EP32MC203"}, + {0x1C18,"24EP32GP204"}, + {0x1C19,"24EP32GP202"}, + {0x1C1A,"24EP32GP203"}, + {0x1D20,"33EP64MC204"}, + {0x1D21,"33EP64MC202"}, + {0x1D22,"33EP64MC203"}, + {0x1D23,"33EP64MC206"}, + {0x1D24,"33EP64MC504"}, + {0x1D25,"33EP64MC502"}, + {0x1D26,"33EP64MC503"}, + {0x1D27,"33EP64MC506"}, + {0x1D2C,"33EP64GP504"}, + {0x1D2D,"33EP64GP502"}, + {0x1D2E,"33EP64GP503"}, + {0x1D2F,"33EP64GP506"}, + {0x1D30,"24EP64MC204"}, + {0x1D31,"24EP64MC202"}, + {0x1D32,"24EP64MC203"}, + {0x1D33,"24EP64MC206"}, + {0x1D38,"24EP64GP204"}, + {0x1D39,"24EP64GP202"}, + {0x1D3A,"24EP64GP203"}, + {0x1D3B,"24EP64GP206"}, + {0x1E40,"33EP128MC204"}, + {0x1E41,"33EP128MC202"}, + {0x1E43,"33EP128MC206"}, + {0x1E44,"33EP128MC504"}, + {0x1E45,"33EP128MC502"}, + {0x1E47,"33EP128MC506"}, + {0x1E4C,"33EP128GP504"}, + {0x1E4D,"33EP128GP502"}, + {0x1E4F,"33EP128GP506"}, + {0x1E50,"24EP128MC204"}, + {0x1E51,"24EP128MC202"}, + {0x1E53,"24EP128MC206"}, + {0x1E58,"24EP128GP204"}, + {0x1E59,"24EP128GP202"}, + {0x1E5B,"24EP128GP206"}, + {0x1F60,"33EP256MC204"}, + {0x1F61,"33EP256MC202"}, + {0x1F63,"33EP256MC206"}, + {0x1F64,"33EP256MC504"}, + {0x1F65,"33EP256MC502"}, + {0x1F67,"33EP256MC506"}, + {0x1F6C,"33EP256GP504"}, + {0x1F6D,"33EP256GP502"}, + {0x1F6F,"33EP256GP506"}, + {0x1F70,"24EP256MC204"}, + {0x1F71,"24EP256MC202"}, + {0x1F73,"24EP256MC206"}, + {0x1F78,"24EP256GP204"}, + {0x1F79,"24EP256GP202"}, + {0x1F7B,"24EP256GP206"}, + {0x4000,"33FJ32GS406"}, + {0x4001,"33FJ64GS406"}, + {0x4002,"33FJ32GS606"}, + {0x4003,"33FJ64GS606"}, + {0x4004,"33FJ32GS608"}, + {0x4005,"33FJ64GS608"}, + {0x4008,"33FJ32GS610"}, + {0x4009,"33FJ64GS610"}, + {0x4100,"24FJ128GB206"}, + {0x4102,"24FJ128GB210"}, + {0x4104,"24FJ256GB206"}, + {0x4106,"24FJ256GB210"}, + {0x4108,"24FJ128DA206"}, + {0x4109,"24FJ128DA106"}, + {0x410A,"24FJ128DA210"}, + {0x410B,"24FJ128DA110"}, + {0x410C,"24FJ256DA206"}, + {0x410D,"24FJ256DA106"}, + {0x410E,"24FJ256DA210"}, + {0x410F,"24FJ256DA110"}, + {0x4202,"24FJ32GA102"}, + {0x4203,"24FJ32GB002"}, + {0x4206,"24FJ64GA102"}, + {0x4207,"24FJ64GB002"}, + {0x420A,"24FJ32GA104"}, + {0x420B,"24FJ32GB004"}, + {0x420E,"24FJ64GA104"}, + {0x420F,"24FJ64GB004"}, + {0x46C0,"24FJ64GA306"}, + {0x46C2,"24FJ128GA306"}, + {0x46C4,"24FJ64GA308"}, + {0x46C6,"24FJ128GA308"}, + {0x46C8,"24FJ64GA310"}, + {0x46CA,"24FJ128GA310"}, + {0x4884,"24FJ64GC010"}, + {0x4885,"24FJ128GC010"}, + {0x4888,"24FJ64GC006"}, + {0x4889,"24FJ128GC006"}, + {0x488A,"24FJ64GC008"}, + {0x488B,"24FJ128GC008"}, +}; + +void PIC24_ID(int id) +{ + char s[64]; + int i; + for(i=0;i500){ //limit number of lines printed + strcat(aux,"(...)\r\n"); + i=(dim>4)&0xF; + int EEbaseAddr=0x1000-dim2; + int newTABLPAG=options&0x100?1:0; + if(FWVersion<0x700){ + PrintMessage1(strings[S_FWver2old],"0.7.0"); //"This firmware is too old. Version %s is required\r\n" + return; + } + if(entry<2&&!CheckV33Regulator()){ //except 30Fxx which is on 5V + PrintMessage(strings[S_noV33reg]); //Can't find 3.3V expansion board + return; + } + if(saveLog){ + OpenLogFile(); + fprintf(logfile,"Read24Fx(%d,%d,%d,%d,%d) (0x%X,0x%X,0x%X,0x%X,0x%X)\n",dim,dim2,options,appIDaddr,executiveArea,dim,dim2,options,appIDaddr,executiveArea); + } + dim*=2; //from words to bytes + if(dim>0x80000||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n" + return; + } + if(dim2>0x4000||dim2<0){ + PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n" + return; + } + unsigned char *memExec=0; + executiveArea*=2; + if(executiveArea) memExec=(unsigned char *)malloc(executiveArea); + for(i=0;i2){ //only if separate config area + sizeCONFIG=48; + for(i=0;i<48;i++) memCONFIG[i]=0xFF; + } + if((entry==1)||(entry==2)){ //High voltage programming: 3.3V + 1.5V + R drop + margin + if(!StartHVReg(entry==2?12:6)){ //12V only for 30Fxx !!! + PrintMessage(strings[S_HVregErr]); //"HV regulator error\r\n" + return; + } + } + else StartHVReg(-1); //LVP: current limited to (5-0.7-3.6)/10k = 50uA + unsigned int start=GetTickCount(); + j=0; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=10000>>8; + bufferU[j++]=10000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T2; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD + VPP + bufferU[j++]=0x5; + if((entry==0)||(entry==3)){ //LVP: pulse on MCLR + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + } + else PrintMessage(strings[S_HVICSP]); //"High Voltage ICSP\r\n" + bufferU[j++]=WAIT_T3; //>10ms before key (GA3xx-GC0xx) + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x4D; + bufferU[j++]=0x43; + bufferU[j++]=0x48; + bufferU[j++]=0x51; + bufferU[j++]=WAIT_T3; //min 1ms + bufferU[j++]=EN_VPP_VCC; //VDD + VPP + bufferU[j++]=0x5; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=30000>>8; + bufferU[j++]=30000&0xff; + bufferU[j++]=WAIT_T3; //min 25ms + if(entry==2){ //30Fx entry + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD + VPP + bufferU[j++]=0x5; + bufferU[j++]=ICSP_NOP; + } + else{ + //Additional 5 clock cycles upon entering program mode + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + } + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j>12)&0xF); //MOV XXXX,W6 + bufferU[j++]=(appIDaddr>>4)&0xFF; + bufferU[j++]=((appIDaddr<<4)&0xF0)+6; + bufferU[j++]=0x20; //MOV #VISI,W7 + bufferU[j++]=0x78; + bufferU[j++]=0x47; + bufferU[j++]=SIX_LONG; //TBLRDL [W6],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0x96; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=SIX_N; + bufferU[j++]=4; + bufferU[j++]=0x20; //MOV XXXX,W0 + bufferU[j++]=0x00; + bufferU[j++]=0x00; + bufferU[j++]=0x88; //MOV W0,TABLPAG + if(newTABLPAG){ + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + } + else{ + bufferU[j++]=0x01; + bufferU[j++]=0x90; + } + bufferU[j++]=0x20; //MOV 0,W6 + bufferU[j++]=0x00; + bufferU[j++]=0x06; + bufferU[j++]=0x20; //MOV #VISI,W7 + bufferU[j++]=0x78; + bufferU[j++]=0x47; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j>17)!=High){ //advance page + bufferU[j++]=SIX; //MOV XXXX,W0 + bufferU[j++]=0x20; + bufferU[j++]=(i>>21)&0xFF; + bufferU[j++]=(i>>13)&0xF0; + bufferU[j++]=SIX; //MOV W0,TABLPAG + bufferU[j++]=0x88; + if(newTABLPAG){ + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + } + else{ + bufferU[j++]=0x01; + bufferU[j++]=0x90; + } + bufferU[j++]=SIX; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j>17; + } + bufferU[j++]=SIX_LONG; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=SIX_LONG; //TBLRDL [W6],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0x96; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDH.B [W6++],[W7++] + bufferU[j++]=0xBA; + bufferU[j++]=0xDB; + bufferU[j++]=0xB6; + bufferU[j++]=SIX_LONG; //TBLRDH.B [++W6],[W7--] + bufferU[j++]=0xBA; + bufferU[j++]=0xD3; + bufferU[j++]=0xD6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + if(i2){ //config area @ 0xF80000 + if(saveLog) fprintf(logfile,"\nCONFIG:\n"); + bufferU[j++]=SIX_N; + bufferU[j++]=4; + bufferU[j++]=0x20; //MOV XXXX,W0 + bufferU[j++]=0x0F; + bufferU[j++]=0x80; + bufferU[j++]=0x88; //MOV W0,TABLPAG + if(newTABLPAG){ + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + } + else{ + bufferU[j++]=0x01; + bufferU[j++]=0x90; + } + bufferU[j++]=0x20; //MOV XXXX,W6 + bufferU[j++]=0x00; + bufferU[j++]=0x06; + bufferU[j++]=0x20; //MOV #VISI,W7 + bufferU[j++]=0x78; + bufferU[j++]=0x47; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + bufferU[j++]=FLUSH; + for(;j,W6 (base address) + bufferU[j++]=(EEbaseAddr>>4)&0xFF; + bufferU[j++]=(EEbaseAddr&0xF0)+6; + bufferU[j++]=0x20; //MOV #VISI,W7 + bufferU[j++]=0x78; + bufferU[j++]=0x47; + bufferU[j++]=0x04; //GOTO 0x200 + bufferU[j++]=0x02; + bufferU[j++]=0x00; + for(k2=0,i=0;iDIMBUF-6||i==dim2-2){ + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=EN_VPP_VCC; //0 + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j2){ //only if separate config area + PrintMessage(strings[S_ConfigMem]); //"\r\nConfig Memory:\r\n" + if(config==3||config==4||config==6){ + PrintMessage1("0xF80000: FBS = 0x%02X\r\n",memCONFIG[0]); + if(config==4){ //0xF80000-16 + PrintMessage1("0xF80002: FSS = 0x%02X\r\n",memCONFIG[4]); + } + PrintMessage1("0xF80004: FGS = 0x%02X\r\n",memCONFIG[8]); + PrintMessage1("0xF80006: FOSCSEL = 0x%02X\r\n",memCONFIG[12]); + PrintMessage1("0xF80008: FOSC = 0x%02X\r\n",memCONFIG[16]); + PrintMessage1("0xF8000A: FWDT = 0x%02X\r\n",memCONFIG[20]); + PrintMessage1("0xF8000C: FPOR = 0x%02X\r\n",memCONFIG[24]); + PrintMessage1("0xF8000E: FICD = 0x%02X\r\n",memCONFIG[28]); + if(config==3){ //0xF80000-10 except 02 + PrintMessage1("0xF80010: FDS = 0x%02X\r\n",memCONFIG[32]); + } + else if(config==4){ //0xF80000-16 + PrintMessage1("0xF80010: UID0 = 0x%02X\r\n",memCONFIG[32]); + PrintMessage1("0xF80012: UID1 = 0x%02X\r\n",memCONFIG[36]); + PrintMessage1("0xF80014: UID2 = 0x%02X\r\n",memCONFIG[40]); + PrintMessage1("0xF80016: UID3 = 0x%02X\r\n",memCONFIG[44]); + } + } + else if(config==5){ //0xF80000-0C (16 bit) + PrintMessage2("0xF80000: FOSC = 0x%02X%02X\r\n",memCONFIG[1],memCONFIG[0]); + PrintMessage2("0xF80002: FWDT = 0x%02X%02X\r\n",memCONFIG[5],memCONFIG[4]); + PrintMessage2("0xF80004: FBORPOR = 0x%02X%02X\r\n",memCONFIG[9],memCONFIG[8]); + PrintMessage2("0xF80006: FBS = 0x%02X%02X\r\n",memCONFIG[13],memCONFIG[12]); + PrintMessage2("0xF80008: FSS = 0x%02X%02X\r\n",memCONFIG[17],memCONFIG[16]); + PrintMessage2("0xF8000A: FGS = 0x%02X%02X\r\n",memCONFIG[21],memCONFIG[20]); + PrintMessage2("0xF8000C: FICD = 0x%02X%02X\r\n",memCONFIG[25],memCONFIG[24]); + } + } + else{ + //last 2 program words + PrintMessage2("CONFIG1: 0x%04X\r\nCONFIG2: 0x%04X\r\n",(memCODE[dim-3]<<8)+memCODE[dim-4]\ + ,(memCODE[dim-7]<<8)+memCODE[dim-8]); + if(config==1){ //last 3 program words + PrintMessage1("CONFIG3: 0x%04X\r\n",(memCODE[dim-11]<<8)+memCODE[dim-12]); + } + if(config==2){ //last 4 program words + PrintMessage1("CONFIG4: 0x%04X\r\n",(memCODE[dim-15]<<8)+memCODE[dim-16]); + } + } + PrintMessage(strings[S_CodeMem]); //"\r\nCode memory:\r\n" + DisplayCODE24F(dim); + if(dim2){ + PrintMessage(strings[S_EEMem]); //"\r\nEEPROM memory:\r\n" + DisplayEE24F(); + } + if(executiveArea){ + char s[256],t[256]; + int d,valid,empty=1; + char* aux=(char*)malloc((dim/COL+1)*2*(16+COL*9)); + aux[0]=0; + s[0]=0; + empty=1; + PrintMessage(strings[S_ExeMem]); //"\r\nExecutive memory:\r\n" + for(i=0;i0x100000||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n" + return; + } + unsigned char *memExec=0; + executiveArea*=2; + if(executiveArea) memExec=(unsigned char *)malloc(executiveArea); + for(i=0;i>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T2; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD + VPP + bufferU[j++]=0x5; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=WAIT_T3; + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x4D; + bufferU[j++]=0x43; + bufferU[j++]=0x48; + bufferU[j++]=0x51; + bufferU[j++]=WAIT_T3; //min 1ms + bufferU[j++]=EN_VPP_VCC; //VDD + VPP + bufferU[j++]=0x5; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=55000>>8; + bufferU[j++]=55000&0xff; + bufferU[j++]=WAIT_T3; //min 50ms + //Additional 5 clock cycles upon entering program mode + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j>12)&0xF); //MOV XXXX,W6 + bufferU[j++]=(appIDaddr>>4)&0xFF; + bufferU[j++]=((appIDaddr<<4)&0xF0)+6; + bufferU[j++]=0x20; //MOV #VISI,W7 + bufferU[j++]=0xF8; + bufferU[j++]=0x87; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG5; //TBLRDL [W6],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0x96; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG5; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=SIX_N; + bufferU[j++]=4; + bufferU[j++]=0x20; //MOV XXXX,W0 + bufferU[j++]=0x00; + bufferU[j++]=0x00; + bufferU[j++]=0x88; //MOV W0,TABLPAG + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + bufferU[j++]=0x20; //MOV 0,W6 + bufferU[j++]=0x00; + bufferU[j++]=0x06; + bufferU[j++]=0x20; //MOV #VISI,W7 + bufferU[j++]=0xF8; + bufferU[j++]=0x87; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j>17)!=High){ //advance page + bufferU[j++]=SIX; //MOV XXXX,W0 + bufferU[j++]=0x20; + bufferU[j++]=(i>>21)&0xFF; + bufferU[j++]=(i>>13)&0xF0; + bufferU[j++]=SIX; //MOV W0,TABLPAG + bufferU[j++]=0x88; + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + bufferU[j++]=SIX_LONG; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j>17; + } + bufferU[j++]=SIX_LONG5; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=SIX_LONG5; //TBLRDL [W6],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0x96; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG5; //TBLRDH.B [W6++],[W7++] + bufferU[j++]=0xBA; + bufferU[j++]=0xDB; + bufferU[j++]=0xB6; + bufferU[j++]=SIX_LONG5; //TBLRDH.B [++W6],[W7--] + bufferU[j++]=0xBA; + bufferU[j++]=0xD3; + bufferU[j++]=0xD6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG5; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + if(i>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=EN_VPP_VCC; //0 + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j>4)&0xF; + int EEbaseAddr=0x1000-dim2; + int newTABLPAG=options&0x100000?1:0; + int err=0; + if(FWVersion<0x700){ + PrintMessage1(strings[S_FWver2old],"0.7.0"); //"This firmware is too old. Version %s is required\r\n" + return; + } + if(entry<2&&!CheckV33Regulator()){ //except 30Fxx which is on 5V + PrintMessage(strings[S_noV33reg]); //Can't find 3.3V expansion board + return; + } + if(saveLog){ + OpenLogFile(); + fprintf(logfile,"Write24Fx(%d,%d,%d,%d,%d,%.1f) (0x%X,0x%X,0x%X,0x%X,0x%X,%.3f)\n" + ,dim,dim2,options,appIDaddr,rowSize,wait,dim,dim2,options,appIDaddr,rowSize,wait); + } + dim*=2; //from words to bytes + if(dim>0x80000||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n" + return; + } + if(dim2>0x1000||dim2<0){ + PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n" + return; + } + j=size; + if(j%(rowSize*4)){ //grow to an integer number of rows + size=(j/(rowSize*4)+1)*rowSize*4; + memCODE=(unsigned char*)realloc(memCODE,size); + for(;jsize) dim=size; + if(sizeEE<0x1000) dim2=0; + if(dim<1){ + PrintMessage(strings[S_NoCode]); //"Empty code area\r\n" + return; + } + if((entry==1)||(entry==2)){ //High voltage programming: 3.3V + 1.5V + R drop + margin + if(!StartHVReg(entry==2?12:6)){ //12V only for 30Fxx !!! + PrintMessage(strings[S_HVregErr]); //"HV regulator error\r\n" + return; + } + } + else StartHVReg(-1); //LVP: current limited to (5-0.7-3.6)/10k = 50uA + if(config>2){ //only if separate config area + PrintMessage(strings[S_ConfigMem]); //"\r\nConfig Memory:\r\n" + if(config==3||config==4||config==6){ + PrintMessage1("0xF80000: FBS = 0x%02X\r\n",memCONFIG[0]); + if(config==4){ //0xF80000-16 + PrintMessage1("0xF80002: FSS = 0x%02X\r\n",memCONFIG[4]); + } + PrintMessage1("0xF80004: FGS = 0x%02X\r\n",memCONFIG[8]); + PrintMessage1("0xF80006: FOSCSEL = 0x%02X\r\n",memCONFIG[12]); + PrintMessage1("0xF80008: FOSC = 0x%02X\r\n",memCONFIG[16]); + PrintMessage1("0xF8000A: FWDT = 0x%02X\r\n",memCONFIG[20]); + PrintMessage1("0xF8000C: FPOR = 0x%02X\r\n",memCONFIG[24]); + PrintMessage1("0xF8000E: FICD = 0x%02X\r\n",memCONFIG[28]); + if(config==3){ //0xF80000-10 except 02 + PrintMessage1("0xF80010: FDS = 0x%02X\r\n",memCONFIG[32]); + } + else if(config==4){ //0xF80000-16 + PrintMessage1("0xF80010: UID0 = 0x%02X\r\n",memCONFIG[32]); + PrintMessage1("0xF80012: UID1 = 0x%02X\r\n",memCONFIG[36]); + PrintMessage1("0xF80014: UID2 = 0x%02X\r\n",memCONFIG[40]); + PrintMessage1("0xF80016: UID3 = 0x%02X\r\n",memCONFIG[44]); + } + } + else if(config==5){ //0xF80000-0C (16 bit) + PrintMessage2("0xF80000: FOSC = 0x%02X%02X\r\n",memCONFIG[1],memCONFIG[0]); + PrintMessage2("0xF80002: FWDT = 0x%02X%02X\r\n",memCONFIG[5],memCONFIG[4]); + PrintMessage2("0xF80004: FBORPOR = 0x%02X%02X\r\n",memCONFIG[9],memCONFIG[8]); + PrintMessage2("0xF80006: FBS = 0x%02X%02X\r\n",memCONFIG[13],memCONFIG[12]); + PrintMessage2("0xF80008: FSS = 0x%02X%02X\r\n",memCONFIG[17],memCONFIG[16]); + PrintMessage2("0xF8000A: FGS = 0x%02X%02X\r\n",memCONFIG[21],memCONFIG[20]); + PrintMessage2("0xF8000C: FICD = 0x%02X%02X\r\n",memCONFIG[25],memCONFIG[24]); + } + } + else{ + //last 2 program words + PrintMessage2("CONFIG1: 0x%04X\r\nCONFIG2: 0x%04X\r\n",(memCODE[dim-3]<<8)+memCODE[dim-4]\ + ,(memCODE[dim-7]<<8)+memCODE[dim-8]); + if(config==1){ //last 3 program words + PrintMessage1("CONFIG3: 0x%04X\r\n",(memCODE[dim-11]<<8)+memCODE[dim-12]); + } + if(config==2){ //last 4 program words + PrintMessage1("CONFIG4: 0x%04X\r\n",(memCODE[dim-15]<<8)+memCODE[dim-16]); + } + } + unsigned int start=GetTickCount(); + j=0; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=2000>>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T2; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD + VPP + bufferU[j++]=0x5; + if((entry==0)||(entry==3)){ //LVP: pulse on MCLR + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + } + else PrintMessage(strings[S_HVICSP]); //"High Voltage ICSP\r\n" + bufferU[j++]=WAIT_T3; + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x4D; + bufferU[j++]=0x43; + bufferU[j++]=0x48; + bufferU[j++]=0x51; + bufferU[j++]=WAIT_T3; //min 1ms + bufferU[j++]=EN_VPP_VCC; //VDD + VPP + bufferU[j++]=0x5; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=30000>>8; + bufferU[j++]=30000&0xff; + bufferU[j++]=WAIT_T3; //min 25ms + if(entry==2){ //30Fx entry + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD + VPP + bufferU[j++]=0x5; + bufferU[j++]=ICSP_NOP; + } + else{ + //Additional 5 clock cycles upon entering program mode + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + } + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j>12)&0xF); //MOV XXXX,W6 + bufferU[j++]=(appIDaddr>>4)&0xFF; + bufferU[j++]=((appIDaddr<<4)&0xF0)+6; + bufferU[j++]=0x20; //MOV #VISI,W7 + bufferU[j++]=0x78; + bufferU[j++]=0x47; + bufferU[j++]=SIX_LONG; //TBLRDL [W6],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0x96; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=2000>>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=FLUSH; + for(;j>8; + //bulk erase command + bufferU[j++]=SIX_N; + bufferU[j++]=4; + bufferU[j++]=0x24; //MOV XXXX,W10 + if(erase==0){ //0x4064 + bufferU[j++]=0x06; + bufferU[j++]=0x4A; + } + else if(erase==1){ //0x404F + bufferU[j++]=0x04; + bufferU[j++]=0xFA; + } + else if(erase>=2){ //0x407F + bufferU[j++]=0x07; + bufferU[j++]=0xFA; + } + bufferU[j++]=0x88; //MOV W10,NVMCON + bufferU[j++]=0x3B; + bufferU[j++]=0x0A; + bufferU[j++]=0x20; //MOV XXXX,W0 + bufferU[j++]=0x00; + bufferU[j++]=0x00; + bufferU[j++]=0x88; //MOV W0,TABLPAG + if(newTABLPAG){ + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + } + else{ + bufferU[j++]=0x01; + bufferU[j++]=0x90; + } + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //TBLWTL W0,[W0] (dummy write) + bufferU[j++]=0xBB; + bufferU[j++]=0x08; + bufferU[j++]=0x00; + if(erase>=2){ //30Fx, unlock and external timing + bufferU[j++]=SIX_N; + bufferU[j++]=4; + bufferU[j++]=0x20; //MOV 0x55,W8 + bufferU[j++]=0x05; + bufferU[j++]=0x58; + bufferU[j++]=0x88; //MOV W8,NVMKEY + bufferU[j++]=0x3B; + bufferU[j++]=0x38; + bufferU[j++]=0x20; //MOV 0xAA,W8 + bufferU[j++]=0x0A; + bufferU[j++]=0xA8; + bufferU[j++]=0x88; //MOV W8,NVMKEY + bufferU[j++]=0x3B; + bufferU[j++]=0x38; + bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + bufferU[j++]=WAIT_T3; + if(erase==3){ //200 ms timing + bufferU[j++]=FLUSH; + for(;j0?0x1A:0x4A; //0x4001/0x4004 + bufferU[j++]=0x88; //MOV W10,NVMCON + bufferU[j++]=0x3B; + bufferU[j++]=0x0A; + bufferU[j++]=0x20; //MOV XXXX,W0 + bufferU[j++]=0x00; + bufferU[j++]=0x00; + bufferU[j++]=0x88; //MOV W0,TABLPAG + if(newTABLPAG){ + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + } + else{ + bufferU[j++]=0x01; + bufferU[j++]=0x90; + } + bufferU[j++]=0x04; //GOTO 0x200 + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j=dim) break; + } + if((i>>17)!=High){ //advance page + bufferU[j++]=SIX; //MOV XXXX,W0 + bufferU[j++]=0x20; + bufferU[j++]=(i>>21)&0xFF; + bufferU[j++]=(i>>13)&0xF0; + bufferU[j++]=SIX; //MOV W0,TABLPAG + bufferU[j++]=0x88; + if(newTABLPAG){ + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + } + else{ + bufferU[j++]=0x01; + bufferU[j++]=0x90; + } + bufferU[j++]=SIX; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j>17; + } + bufferU[j++]=SIX_N; + bufferU[j++]=8; + bufferU[j++]=0x20+((i>>13)&0xF); //MOV i/2,W7 + bufferU[j++]=(i>>5)&0xFF; + bufferU[j++]=((i<<3)&0xF0)+7; + bufferU[j++]=0x20+((memCODE[i+1]>>4)&0xF); //MOV LSW0,W0 + bufferU[j++]=((memCODE[i+1]<<4)&0xF0)+((memCODE[i]>>4)&0xF); + bufferU[j++]=(memCODE[i]<<4)&0xF0; + bufferU[j++]=0x20+((memCODE[i+6]>>4)&0xF); //MOV MSB1:MSB0,W1 + bufferU[j++]=((memCODE[i+6]<<4)&0xF0)+((memCODE[i+2]>>4)&0xF); + bufferU[j++]=((memCODE[i+2]<<4)&0xF0)+1; + bufferU[j++]=0x20+((memCODE[i+5]>>4)&0xF); //MOV LSW1,W2 + bufferU[j++]=((memCODE[i+5]<<4)&0xF0)+((memCODE[i+4]>>4)&0xF); + bufferU[j++]=((memCODE[i+4]<<4)&0xF0)+2; + bufferU[j++]=0x20+((memCODE[i+9]>>4)&0xF); //MOV LSW2,W3 + bufferU[j++]=((memCODE[i+9]<<4)&0xF0)+((memCODE[i+8]>>4)&0xF); + bufferU[j++]=((memCODE[i+8]<<4)&0xF0)+3; + bufferU[j++]=0x20+((memCODE[i+14]>>4)&0xF); //MOV MSB3:MSB2,W4 + bufferU[j++]=((memCODE[i+14]<<4)&0xF0)+((memCODE[i+10]>>4)&0xF); + bufferU[j++]=((memCODE[i+10]<<4)&0xF0)+4; + bufferU[j++]=0x20+((memCODE[i+13]>>4)&0xF); //MOV LSW3,W5 + bufferU[j++]=((memCODE[i+13]<<4)&0xF0)+((memCODE[i+12]>>4)&0xF); + bufferU[j++]=((memCODE[i+12]<<4)&0xF0)+5; + bufferU[j++]=0xEB; //CLR W6 + bufferU[j++]=0x03; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_N; + bufferU[j++]=0x88; //Append 2 NOP + bufferU[j++]=0xBB; //TBLWTL [W6++],[W7] + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTH.B [W6++],[W7++] + bufferU[j++]=0xDB; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTH.B [W6++],[++W7] + bufferU[j++]=0xEB; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTL [W6++],[W7++] + bufferU[j++]=0x1B; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTL [W6++],[W7] + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTH.B [W6++],[W7++] + bufferU[j++]=0xDB; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTH.B [W6++],[++W7] + bufferU[j++]=0xEB; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTL [W6++],[W7++] + bufferU[j++]=0x1B; + bufferU[j++]=0xB6; + k++; + if(k==rowSize/4){ //Write row + if(erase>1){ //30Fx, unlock and external timing + bufferU[j++]=FLUSH; + for(;j0?0x1A:0x4A; //0x4001/0x4004 + bufferU[j++]=0x88; //MOV W10,NVMCON + bufferU[j++]=0x3B; + bufferU[j++]=0x0A; + bufferU[j++]=0x20; //MOV 0x55,W8 + bufferU[j++]=0x05; + bufferU[j++]=0x58; + bufferU[j++]=0x88; //MOV W8,NVMKEY + bufferU[j++]=0x3B; + bufferU[j++]=0x38; + bufferU[j++]=0x20; //MOV 0xAA,W8 + bufferU[j++]=0x0A; + bufferU[j++]=0xA8; + bufferU[j++]=0x88; //MOV W8,NVMKEY + bufferU[j++]=0x3B; + bufferU[j++]=0x38; + bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //BCLR NVMCON,#WR + bufferU[j++]=0xA9; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + bufferU[j++]=SIX_LONG; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + } + else{ //internal timing + bufferU[j++]=SIX_LONG; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + } + k=0; + } + bufferU[j++]=FLUSH; + for(;j=dim) break; + if((i>>17)!=High){ //advance page + bufferU[j++]=SIX; //MOV XXXX,W0 + bufferU[j++]=0x20; + bufferU[j++]=(i>>21)&0xFF; + bufferU[j++]=(i>>13)&0xF0; + bufferU[j++]=SIX; //MOV W0,TABLPAG + bufferU[j++]=0x88; + if(newTABLPAG){ + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + } + else{ + bufferU[j++]=0x01; + bufferU[j++]=0x90; + } + bufferU[j++]=SIX; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j>17; + } + bufferU[j++]=SIX; //MOV i/2,W6 + bufferU[j++]=0x20+((i>>13)&0xF); + bufferU[j++]=(i>>5)&0xFF; + bufferU[j++]=((i<<3)&0xF0)+6; + bufferU[j++]=SIX; //MOV #VISI,W7 + bufferU[j++]=0x20; + bufferU[j++]=0x78; + bufferU[j++]=0x47; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //TBLRDL [W6],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0x96; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDH.B [W6++],[W7++] + bufferU[j++]=0xBA; + bufferU[j++]=0xDB; + bufferU[j++]=0xB6; + bufferU[j++]=SIX_LONG; //TBLRDH.B [++W6],[W7--] + bufferU[j++]=0xBA; + bufferU[j++]=0xD3; + bufferU[j++]=0xD6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDL [W6],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0x96; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDH.B [W6++],[W7++] + bufferU[j++]=0xBA; + bufferU[j++]=0xDB; + bufferU[j++]=0xB6; + bufferU[j++]=SIX_LONG; //TBLRDH.B [++W6],[W7--] + bufferU[j++]=0xBA; + bufferU[j++]=0xD3; + bufferU[j++]=0xD6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=FLUSH; + for(;j=max_err) break; + } + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed: %d errors\r\n" + if(err>=max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + } +//****************** erase, write and verify EEPROM ******************** + if(dim2&&err>12; + if(eewrite==0){ //24FxxKAxx + bufferU[j++]=SIX; //MOV 0x4050,W10 + bufferU[j++]=0x24; + bufferU[j++]=0x05; + bufferU[j++]=0x0A; + bufferU[j++]=SIX; //MOV W10,NVMCON + bufferU[j++]=0x88; + bufferU[j++]=0x3B; + bufferU[j++]=0x0A; + bufferU[j++]=SIX; //MOV 0x7F,W0 + bufferU[j++]=0x20; + bufferU[j++]=0x07; + bufferU[j++]=0xF0; + bufferU[j++]=SIX; //MOV W0,TABLPAG + bufferU[j++]=0x88; + if(newTABLPAG){ + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + } + else{ + bufferU[j++]=0x01; + bufferU[j++]=0x90; + } + bufferU[j++]=SIX; //MOV EEbaseAddr,W0 + bufferU[j++]=0x2F; + bufferU[j++]=EEbaseAddr>>4; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX; //TBLWTL W0,[W0] + bufferU[j++]=0xBB; + bufferU[j++]=0x08; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP;/**/ + //Erase EEPROM + bufferU[j++]=SIX; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=SIX; //MOV 0x4004,W10 + bufferU[j++]=0x24; + bufferU[j++]=0x00; + bufferU[j++]=0x4A; + bufferU[j++]=SIX; //MOV W10,NVMCON + bufferU[j++]=0x88; + bufferU[j++]=0x3B; + bufferU[j++]=0x0A; + bufferU[j++]=SIX; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j>4; + bufferU[j++]=((i<<4)&0xF0)+7; + bufferU[j++]=SIX; //MOV XXXX,W0 + bufferU[j++]=0x20+((memEE[i+1]>>4)&0xF); + bufferU[j++]=((memEE[i+1]<<4)&0xF0)+((memEE[i]>>4)&0xF); + bufferU[j++]=(memEE[i]<<4)&0xF0; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //TBLWTL W0,[W7++] + bufferU[j++]=0xBB; + bufferU[j++]=0x1B; + bufferU[j++]=0x80; + if(eewrite==0){ //24FxxKAxx + bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + } + else if(eewrite==1){ //30Fxxxx + bufferU[j++]=SIX_N; + bufferU[j++]=6; + bufferU[j++]=0x24; //MOV 0x4004,W10 + bufferU[j++]=0x00; + bufferU[j++]=0x4A; + bufferU[j++]=0x88; //MOV W10,NVMCON + bufferU[j++]=0x3B; + bufferU[j++]=0x0A; + bufferU[j++]=0x20; //MOV 0x55,W8 + bufferU[j++]=0x05; + bufferU[j++]=0x58; + bufferU[j++]=0x88; //MOV W8,NVMKEY + bufferU[j++]=0x3B; + bufferU[j++]=0x38; + bufferU[j++]=0x20; //MOV 0xAA,W8 + bufferU[j++]=0x0A; + bufferU[j++]=0xA8; + bufferU[j++]=0x88; //MOV W8,NVMKEY + bufferU[j++]=0x3B; + bufferU[j++]=0x38; + bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + bufferU[j++]=WAIT_T3; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //BCLR NVMCON,#WR + bufferU[j++]=0xA9; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + } + bufferU[j++]=FLUSH; + for(;j>4; + bufferU[j++]=0x06; + bufferU[j++]=SIX; //MOV #VISI,W7 + bufferU[j++]=0x20; + bufferU[j++]=0x78; + bufferU[j++]=0x47; + bufferU[j++]=SIX; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + int errE=0; + for(i=k2=EEbaseAddr;iDIMBUF-7||i==dim2-4){ + bufferU[j++]=FLUSH; + for(;j2&&config<5&&err>16; + bufferU[j++]=SIX_N; + bufferU[j++]=6; + bufferU[j++]=0x20; //MOV 0xF8,W0 + bufferU[j++]=0x0F; + bufferU[j++]=0x80; + bufferU[j++]=0x88; //MOV W0,TABLPAG + if(newTABLPAG){ + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + } + else{ + bufferU[j++]=0x01; + bufferU[j++]=0x90; + } + bufferU[j++]=0x24; //MOV 0x400x,W10 + bufferU[j++]=0x00; + if(confword==0)bufferU[j++]=0x0A; //0x4000 + else if(confword==1)bufferU[j++]=0x3A; //0x4003 + else if(confword==2)bufferU[j++]=0x4A; //0x4004 + else if(confword==3)bufferU[j++]=0x8A; //0x4008 + bufferU[j++]=0x88; //MOV W10,NVMCON + bufferU[j++]=0x3B; + bufferU[j++]=0x0A; + bufferU[j++]=0x20; //MOV 0,W7 + bufferU[j++]=0x00; + bufferU[j++]=0x07; + bufferU[j++]=0x04; //GOTO 0x200 + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + for(i=0;i<12;i++){ + //Write CONFIG + bufferU[j++]=SIX; //MOV XXXX,W0 + bufferU[j++]=0x20; + bufferU[j++]=(memCONFIG[i*4]>>4)&0xF; + bufferU[j++]=(memCONFIG[i*4]<<4)&0xF0; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //TBLWTL W0,[W7++] + bufferU[j++]=0xBB; + bufferU[j++]=0x1B; + bufferU[j++]=0x80; + if(memCONFIG[i*4]<0xFF){ //write if not empty + bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + } + bufferU[j++]=FLUSH; + for(;j=5&&err>12); + bufferU[j++]=(value>>4); + bufferU[j++]=(value<<4); + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //TBLWTL W0,[W7++] + bufferU[j++]=0xBB; + bufferU[j++]=0x1B; + bufferU[j++]=0x80; + if(value<0xFFFF){ //write if not empty + bufferU[j++]=SIX_N; + bufferU[j++]=6; + bufferU[j++]=0x24; //MOV 0x400x,W10 + bufferU[j++]=0x00; + bufferU[j++]=0x8A; //0x4008 + bufferU[j++]=0x88; //MOV W10,NVMCON + bufferU[j++]=0x3B; + bufferU[j++]=0x0A; + bufferU[j++]=0x20; //MOV 0x55,W8 + bufferU[j++]=0x05; + bufferU[j++]=0x58; + bufferU[j++]=0x88; //MOV W8,NVMKEY + bufferU[j++]=0x3B; + bufferU[j++]=0x38; + bufferU[j++]=0x20; //MOV 0xAA,W8 + bufferU[j++]=0x0A; + bufferU[j++]=0xA8; + bufferU[j++]=0x88; //MOV W8,NVMKEY + bufferU[j++]=0x3B; + bufferU[j++]=0x38; + bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + bufferU[j++]=WAIT_T3; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //BCLR NVMCON,#WR + bufferU[j++]=0xA9; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + } + bufferU[j++]=FLUSH; + for(;j0x100000||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n" + return; + } + if(dim>size) for(i=size;i>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T2; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD + VPP + bufferU[j++]=0x5; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=WAIT_T3; + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x4D; + bufferU[j++]=0x43; + bufferU[j++]=0x48; + bufferU[j++]=0x51; + bufferU[j++]=WAIT_T3; //min 1ms + bufferU[j++]=EN_VPP_VCC; //VDD + VPP + bufferU[j++]=0x5; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=55000>>8; + bufferU[j++]=55000&0xff; + bufferU[j++]=WAIT_T3; //min 50ms + //Additional 5 clock cycles upon entering program mode + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j>12)&0xF); //MOV XXXX,W6 + bufferU[j++]=(appIDaddr>>4)&0xFF; + bufferU[j++]=((appIDaddr<<4)&0xF0)+6; + bufferU[j++]=0x20; //MOV #VISI,W7 + bufferU[j++]=0xF8; + bufferU[j++]=0x87; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG5; //TBLRDL [W6],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0x96; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG5; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=2000>>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=FLUSH; + for(;j=dim) break; + bufferU[j++]=SIX_N; + bufferU[j++]=5; + bufferU[j++]=0xEB; //CLR W6 + bufferU[j++]=0x03; + bufferU[j++]=0x00; + bufferU[j++]=0xEB; //CLR W7 + bufferU[j++]=0x03; + bufferU[j++]=0x80; + bufferU[j++]=0x20+((memCODE[i+1]>>4)&0xF); //MOV LSW0,W0 + bufferU[j++]=((memCODE[i+1]<<4)&0xF0)+((memCODE[i]>>4)&0xF); + bufferU[j++]=(memCODE[i]<<4)&0xF0; + bufferU[j++]=0x20+((memCODE[i+6]>>4)&0xF); //MOV MSB1:MSB0,W1 + bufferU[j++]=((memCODE[i+6]<<4)&0xF0)+((memCODE[i+2]>>4)&0xF); + bufferU[j++]=((memCODE[i+2]<<4)&0xF0)+1; + bufferU[j++]=0x20+((memCODE[i+5]>>4)&0xF); //MOV LSW1,W2 + bufferU[j++]=((memCODE[i+5]<<4)&0xF0)+((memCODE[i+4]>>4)&0xF); + bufferU[j++]=((memCODE[i+4]<<4)&0xF0)+2; + bufferU[j++]=SIX_N; + bufferU[j++]=0x84; //Append 2 NOP + bufferU[j++]=0xBB; //TBLWTL [W6++],[W7] + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTH.B [W6++],[W7++] + bufferU[j++]=0xDB; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTH.B [W6++],[++W7] + bufferU[j++]=0xEB; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTL [W6++],[W7++] + bufferU[j++]=0x1B; + bufferU[j++]=0xB6; + bufferU[j++]=SIX_N; + bufferU[j++]=8; + bufferU[j++]=0x20+((i>>13)&0xF); //MOV i/2,W3 + bufferU[j++]=(i>>5)&0xFF; + bufferU[j++]=((i<<3)&0xF0)+3; + bufferU[j++]=0x20; //MOV i/2/64K,W4 + bufferU[j++]=(i>>21)&0xFF; + bufferU[j++]=((i>>13)&0xF0)+4; + bufferU[j++]=0x88; //MOV W3,NVMADR + bufferU[j++]=0x39; + bufferU[j++]=0x53; + bufferU[j++]=0x88; //MOV W4,NVMADRU + bufferU[j++]=0x39; + bufferU[j++]=0x64; + bufferU[j++]=0x20; //MOV 0x55,W1 + bufferU[j++]=0x05; + bufferU[j++]=0x51; + bufferU[j++]=0x88; //MOV W1,NVMKEY + bufferU[j++]=0x39; + bufferU[j++]=0x71; + bufferU[j++]=0x20; //MOV 0xAA,W1 + bufferU[j++]=0x0A; + bufferU[j++]=0xA1; + bufferU[j++]=0x88; //MOV W1,NVMKEY + bufferU[j++]=0x39; + bufferU[j++]=0x71; + bufferU[j++]=SIX_LONG5; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x29; + bufferU[j++]=FLUSH; + for(;j=dim) break; + if((i>>17)!=High){ //advance page + bufferU[j++]=SIX; //MOV XXXX,W0 + bufferU[j++]=0x20; + bufferU[j++]=(i>>21)&0xFF; + bufferU[j++]=(i>>13)&0xF0; + bufferU[j++]=SIX; //MOV W0,TABLPAG + bufferU[j++]=0x88; + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + bufferU[j++]=SIX_LONG; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j>17; + } + bufferU[j++]=SIX; //MOV i/2,W6 + bufferU[j++]=0x20+((i>>13)&0xF); + bufferU[j++]=(i>>5)&0xFF; + bufferU[j++]=((i<<3)&0xF0)+6; + bufferU[j++]=SIX; //MOV #VISI,W7 + bufferU[j++]=0x20; + bufferU[j++]=0xF8; + bufferU[j++]=0x87; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG5; //TBLRDL [W6],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0x96; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG5; //TBLRDH.B [W6++],[W7++] + bufferU[j++]=0xBA; + bufferU[j++]=0xDB; + bufferU[j++]=0xB6; + bufferU[j++]=SIX_LONG5; //TBLRDH.B [++W6],[W7--] + bufferU[j++]=0xBA; + bufferU[j++]=0xD3; + bufferU[j++]=0xD6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG5; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG5; //TBLRDL [W6],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0x96; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG5; //TBLRDH.B [W6++],[W7++] + bufferU[j++]=0xBA; + bufferU[j++]=0xDB; + bufferU[j++]=0xB6; + bufferU[j++]=SIX_LONG5; //TBLRDH.B [++W6],[W7--] + bufferU[j++]=0xBA; + bufferU[j++]=0xD3; + bufferU[j++]=0xD6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG5; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG5; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=FLUSH; + for(;j=max_err) break; + } + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed: %d errors\r\n" + if(err>=max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + } +//****************** exit ******************** + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=EN_VPP_VCC; //0 + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j + */ + + +#include "common.h" + +/*#ifdef _MSC_VER +void COpenProgDlg::CheckData(int a,int b,int addr,int *err) +#else +void CheckData(int a,int b,int addr,int *err) +#endif +{ + if(a!=b){ +#ifdef _MSC_VER + CString str; +#endif + PrintMessage(strings[S_NL]); + PrintMessage4(strings[S_CodeVError],addr,addr,a,b); //"Error writing address %4X: written %02X, read %02X\r\n" + (*err)++; + } +} +*/ +struct ID32{ + int id; + char *device; +} PIC32LIST[]={ + {0x0938053,"PIC32MX360F512L"}, + {0x0934053,"PIC32MX360F256L"}, + {0x092D053,"PIC32MX340F128L"}, + {0x092A053,"PIC32MX320F128L"}, + {0x0916053,"PIC32MX340F512H"}, + {0x0912053,"PIC32MX340F256H"}, + {0x090D053,"PIC32MX340F128H"}, + {0x090A053,"PIC32MX320F128H"}, + {0x0906053,"PIC32MX320F064H"}, + {0x0902053,"PIC32MX320F032H"}, + {0x0978053,"PIC32MX460F512L"}, + {0x0974053,"PIC32MX460F256L"}, + {0x096D053,"PIC32MX440F128L"}, + {0x0952053,"PIC32MX440F256H"}, + {0x0956053,"PIC32MX440F512H"}, + {0x094D053,"PIC32MX440F128H"}, + {0x0942053,"PIC32MX420F032H"}, + {0x04317053,"PIC32MX575F256H"}, + {0x0430B053,"PIC32MX675F256H"}, + {0x04303053,"PIC32MX775F256H"}, + {0x04309053,"PIC32MX575F512H"}, + {0x0430C053,"PIC32MX675F512H"}, + {0x04325053,"PIC32MX695F512H"}, + {0x0430D053,"PIC32MX775F512H"}, + {0x0430E053,"PIC32MX795F512H"}, + {0x04333053,"PIC32MX575F256L"}, + {0x04305053,"PIC32MX675F256L"}, + {0x04312053,"PIC32MX775F256L"}, + {0x0430F053,"PIC32MX575F512L"}, + {0x04311053,"PIC32MX675F512L"}, + {0x04341053,"PIC32MX695F512L"}, + {0x04307053,"PIC32MX775F512L"}, + {0x04307053,"PIC32MX795F512L"}, + {0x04400053,"PIC32MX534F064H"}, + {0x04401053,"PIC32MX564F064H"}, + {0x04403053,"PIC32MX564F128H"}, + {0x04405053,"PIC32MX664F064H"}, + {0x04407053,"PIC32MX664F128H"}, + {0x0440B053,"PIC32MX764F128H"}, + {0x0440C053,"PIC32MX534F064L"}, + {0x0440D053,"PIC32MX564F064L"}, + {0x0440F053,"PIC32MX564F128L"}, + {0x04411053,"PIC32MX664F064L"}, + {0x04413053,"PIC32MX664F128L"}, + {0x04417053,"PIC32MX764F128L"}, + {0x04A07053,"PIC32MX110F016B"}, + {0x04A09053,"PIC32MX110F016C"}, + {0x04A0B053,"PIC32MX110F016D"}, + {0x04A01053,"PIC32MX210F016B"}, + {0x04A03053,"PIC32MX210F016C"}, + {0x04A05053,"PIC32MX210F016D"}, + {0x04A06053,"PIC32MX120F032B"}, + {0x04A08053,"PIC32MX120F032C"}, + {0x04A0A053,"PIC32MX120F032D"}, + {0x04A00053,"PIC32MX220F032B"}, + {0x04A02053,"PIC32MX220F032C"}, + {0x04A04053,"PIC32MX220F032D"}, + {0x04D07053,"PIC32MX130F064B"}, + {0x04D09053,"PIC32MX130F064C"}, + {0x04D0B053,"PIC32MX130F064D"}, + {0x04D01053,"PIC32MX230F064B"}, + {0x04D03053,"PIC32MX230F064C"}, + {0x04D05053,"PIC32MX230F064D"}, + {0x04D06053,"PIC32MX150F128B"}, + {0x04D08053,"PIC32MX150F128C"}, + {0x04D0A053,"PIC32MX150F128D"}, + {0x04D00053,"PIC32MX250F128B"}, + {0x04D02053,"PIC32MX250F128C"}, + {0x04D04053,"PIC32MX250F128D"}, + {0x06610053,"PIC32MX170F256B"}, + {0x0661A053,"PIC32MX170F256D"}, + {0x06600053,"PIC32MX270F256B"}, + {0x0660A053,"PIC32MX270F256D"}, + {0x0660C053,"PIC32MX270F256DB"}, + {0x06703053,"PIC32MX130F256B"}, + {0x06705053,"PIC32MX130F256D"}, + {0x06700053,"PIC32MX230F256B"}, + {0x06702053,"PIC32MX230F256D"}, + {0x05600053,"PIC32MX330F064H"}, + {0x05601053,"PIC32MX330F064L"}, + {0x05704053,"PIC32MX350F256H"}, + {0x05705053,"PIC32MX350F256L"}, + {0x05602053,"PIC32MX430F064H"}, + {0x05603053,"PIC32MX430F064L"}, + {0x05706053,"PIC32MX450F256H"}, + {0x05707053,"PIC32MX450F256L"}, + {0x0570C053,"PIC32MX350F128H"}, + {0x0570D053,"PIC32MX350F128L"}, + {0x0570E053,"PIC32MX450F128H"}, + {0x0570F053,"PIC32MX450F128L"}, + {0x05808053,"PIC32MX370F512H"}, + {0x05809053,"PIC32MX370F512L"}, + {0x0580A053,"PIC32MX470F512H"}, + {0x0580B053,"PIC32MX470F512L"}, + {0x05710053,"PIC32MX450F256HB"}, + {0x05811053,"PIC32MX470F512LB"}, + {0x05103053,"PIC32MZ1024ECG064"}, + {0x05108053,"PIC32MZ1024ECH064"}, + {0x05130053,"PIC32MZ1024ECM064"}, + {0x05104053,"PIC32MZ2048ECG064"}, + {0x05109053,"PIC32MZ2048ECH064"}, + {0x05131053,"PIC32MZ2048ECM064"}, + {0x0510D053,"PIC32MZ1024ECG100"}, + {0x05112053,"PIC32MZ1024ECH100"}, + {0x0513A053,"PIC32MZ1024ECM100"}, + {0x0510E053,"PIC32MZ2048ECG100"}, + {0x05113053,"PIC32MZ2048ECH100"}, + {0x0513B053,"PIC32MZ2048ECM100"}, + {0x05117053,"PIC32MZ1024ECG124"}, + {0x0511C053,"PIC32MZ1024ECH124"}, + {0x05144053,"PIC32MZ1024ECM124"}, + {0x05118053,"PIC32MZ2048ECG124"}, + {0x0511D053,"PIC32MZ2048ECH124"}, + {0x05145053,"PIC32MZ2048ECM124"}, + {0x05121053,"PIC32MZ1024ECG144"}, + {0x05126053,"PIC32MZ1024ECH144"}, + {0x0514E053,"PIC32MZ1024ECM144"}, + {0x05122053,"PIC32MZ2048ECG144"}, + {0x05127053,"PIC32MZ2048ECH144"}, + {0x0514F053,"PIC32MZ2048ECM144"}, + {0x06A10053,"PIC32MX150F256H"}, + {0x06A11053,"PIC32MX150F256L"}, + {0x06A30053,"PIC32MX170F512H"}, + {0x06A31053,"PIC32MX170F512L"}, + {0x06A12053,"PIC32MX250F256H"}, + {0x06A13053,"PIC32MX250F256L"}, + {0x06A32053,"PIC32MX270F512H"}, + {0x06A33053,"PIC32MX270F512L"}, + {0x06A14053,"PIC32MX550F256H"}, + {0x06A15053,"PIC32MX550F256L"}, + {0x06A34053,"PIC32MX570F512H"}, + {0x06A35053,"PIC32MX570F512L"}, + {0x06A50053,"PIC32MX120F064H"}, + {0x06A00053,"PIC32MX130F128H"}, + {0x06A01053,"PIC32MX130F128L"}, + {0x06A02053,"PIC32MX230F128H"}, + {0x06A03053,"PIC32MX230F128L"}, + {0x06A04053,"PIC32MX530F128H"}, + {0x06A05053,"PIC32MX530F128L"}, + {0x07201053,"PIC32MZ0512EFE064"}, + {0x07206053,"PIC32MZ0512EFF064"}, + {0x0722E053,"PIC32MZ0512EFK064"}, + {0x07202053,"PIC32MZ1024EFE064"}, + {0x07207053,"PIC32MZ1024EFF064"}, + {0x0722F053,"PIC32MZ1024EFK064"}, + {0x07203053,"PIC32MZ1024EFG064"}, + {0x07208053,"PIC32MZ1024EFH064"}, + {0x07230053,"PIC32MZ1024EFM064"}, + {0x07204053,"PIC32MZ2048EFG064"}, + {0x07209053,"PIC32MZ2048EFH064"}, + {0x07231053,"PIC32MZ2048EFM064"}, + {0x0720B053,"PIC32MZ0512EFE100"}, + {0x07210053,"PIC32MZ0512EFF100"}, + {0x07238053,"PIC32MZ0512EFK100"}, + {0x0720C053,"PIC32MZ1024EFE100"}, + {0x07211053,"PIC32MZ1024EFF100"}, + {0x07239053,"PIC32MZ1024EFK100"}, + {0x0720D053,"PIC32MZ1024EFG100"}, + {0x07212053,"PIC32MZ1024EFH100"}, + {0x0723A053,"PIC32MZ1024EFM100"}, + {0x0720E053,"PIC32MZ2048EFG100"}, + {0x07213053,"PIC32MZ2048EFH100"}, + {0x0723B053,"PIC32MZ2048EFM100"}, + {0x07215053,"PIC32MZ0512EFE124"}, + {0x0721A053,"PIC32MZ0512EFF124"}, + {0x07242053,"PIC32MZ0512EFK124"}, + {0x07216053,"PIC32MZ1024EFE124"}, + {0x0721B053,"PIC32MZ1024EFF124"}, + {0x07243053,"PIC32MZ1024EFK124"}, + {0x07217053,"PIC32MZ1024EFG124"}, + {0x0721C053,"PIC32MZ1024EFH124"}, + {0x07244053,"PIC32MZ1024EFM124"}, + {0x07218053,"PIC32MZ2048EFG124"}, + {0x0721D053,"PIC32MZ2048EFH124"}, + {0x07245053,"PIC32MZ2048EFM124"}, + {0x0721F053,"PIC32MZ0512EFE144"}, + {0x07224053,"PIC32MZ0512EFF144"}, + {0x0724C053,"PIC32MZ0512EFK144"}, + {0x07220053,"PIC32MZ1024EFE144"}, + {0x07225053,"PIC32MZ1024EFF144"}, + {0x0724D053,"PIC32MZ1024EFK144"}, + {0x07221053,"PIC32MZ1024EFG144"}, + {0x07226053,"PIC32MZ1024EFH144"}, + {0x0724E053,"PIC32MZ1024EFM144"}, + {0x07222053,"PIC32MZ2048EFG144"}, + {0x07227053,"PIC32MZ2048EFH144"}, + {0x0724F053,"PIC32MZ2048EFM144"}, + {0x05F0C053,"PIC32MZ1025DAA169"}, + {0x05F0D053,"PIC32MZ1025DAB169"}, + {0x05F0F053,"PIC32MZ1064DAA169"}, + {0x05F10053,"PIC32MZ1064DAB169"}, + {0x05F15053,"PIC32MZ2025DAA169"}, + {0x05F16053,"PIC32MZ2025DAB169"}, + {0x05F18053,"PIC32MZ2064DAA169"}, + {0x05F19053,"PIC32MZ2064DAB169"}, + {0x05F42053,"PIC32MZ1025DAG169"}, + {0x05F43053,"PIC32MZ1025DAH169"}, + {0x05F45053,"PIC32MZ1064DAG169"}, + {0x05F46053,"PIC32MZ1064DAH169"}, + {0x05F4B053,"PIC32MZ2025DAG169"}, + {0x05F4C053,"PIC32MZ2025DAH169"}, + {0x05F4E053,"PIC32MZ2064DAG169"}, + {0x05F4F053,"PIC32MZ2064DAH169"}, + {0x05F78053,"PIC32MZ1025DAA176"}, + {0x05F79053,"PIC32MZ1025DAB176"}, + {0x05F7B053,"PIC32MZ1064DAA176"}, + {0x05F7C053,"PIC32MZ1064DAB176"}, + {0x05F81053,"PIC32MZ2025DAA176"}, + {0x05F82053,"PIC32MZ2025DAB176"}, + {0x05F84053,"PIC32MZ2064DAA176"}, + {0x05F85053,"PIC32MZ2064DAB176"}, + {0x05FAE053,"PIC32MZ1025DAG176"}, + {0x05FAF053,"PIC32MZ1025DAH176"}, + {0x05FB1053,"PIC32MZ1064DAG176"}, + {0x05FB2053,"PIC32MZ1064DAH176"}, + {0x05FB7053,"PIC32MZ2025DAG176"}, + {0x05FB8053,"PIC32MZ2025DAH176"}, + {0x05FBA053,"PIC32MZ2064DAG176"}, + {0x05FBB053,"PIC32MZ2064DAH176"}, + {0x05F5D053,"PIC32MZ1025DAA288"}, + {0x05F5E053,"PIC32MZ1025DAB288"}, + {0x05F60053,"PIC32MZ1064DAA288"}, + {0x05F61053,"PIC32MZ1064DAB288"}, + {0x05F66053,"PIC32MZ2025DAA288"}, + {0x05F67053,"PIC32MZ2025DAB288"}, + {0x05F69053,"PIC32MZ2064DAA288"}, + {0x05F6A053,"PIC32MZ2064DAB288"}, + {0x07800053,"PIC32MX154F128B"}, + {0x07804053,"PIC32MX154F128D"}, + {0x07808053,"PIC32MX155F128B"}, + {0x0780C053,"PIC32MX155F128D"}, + {0x07801053,"PIC32MX174F256B"}, + {0x07805053,"PIC32MX174F256D"}, + {0x07809053,"PIC32MX175F256B"}, + {0x0780D053,"PIC32MX175F256D"}, + {0x07802053,"PIC32MX254F128B"}, + {0x07806053,"PIC32MX254F128D"}, + {0x0780A053,"PIC32MX255F128B"}, + {0x0780E053,"PIC32MX255F128D"}, + {0x07803053,"PIC32MX274F256B"}, + {0x07807053,"PIC32MX274F256D"}, + {0x0780B053,"PIC32MX275F256B"}, + {0x0780F053,"PIC32MX275F256D"}, + {0x06211053,"PIC32MK0512GPD064"}, + {0x0620E053,"PIC32MK1024GPD064"}, + {0x06210053,"PIC32MK0512GPD100"}, + {0x0620D053,"PIC32MK1024GPD100"}, + {0x0620B053,"PIC32MK0512GPE064"}, + {0x06208053,"PIC32MK1024GPE064"}, + {0x0620A053,"PIC32MK0512GPE100"}, + {0x06207053,"PIC32MK1024GPE100"}, + {0x06205053,"PIC32MK0512MCF064"}, + {0x06202053,"PIC32MK1024MCF064"}, + {0x06201053,"PIC32MK0512MCF100"}, + {0x06201053,"PIC32MK1024MCF100"}, +}; + +void PIC32_ID(int id) +{ + char s[64]; + int i; + for(i=0;i500){ //limit number of lines printed + strcat(aux,"(...)\r\n"); + i=(dim +TCK=RB6 -> +TDO=RB5 <- +TMS=RB4 -> +MCLR=RB3 -> +*/ +//MCHP TAP INSTRUCTIONS (sent via JTAGSendCommand) +#define MTAP_COMMAND 0x07 //TDI and TDO connected to MCHP Command Shift register +#define MTAP_SW_MTAP 0x04 //Switch TAP controller to MCHP TAP controller +#define MTAP_SW_ETAP 0x05 //Switch TAP controller to EJTAG TAP controller +#define MTAP_IDCODE 0x01 //Select Chip Identification Data register +//MTAP_COMMAND DR COMMANDS (sent via xferData) +#define MCHP_STATUS 0x00 //NOP and return Status. +#define MCHP_ASSERT_RST 0xD1 //Requests the reset controller to assert device Reset. +#define MCHP_DE_ASSERT_RST 0xD0 //Removes the request for device Reset, which causes the reset controller + //to deassert device Reset if there is no other source requesting Reset (i.e., MCLR). +#define MCHP_ERASE 0xFC //Cause the Flash controller to perform a Chip Erase. +#define MCHP_FLASH_ENABLE 0xFE //Enables fetches and loads to the Flash (from the processor). +#define MCHP_FLASH_DISABLE 0xFD //Disables fetches and loads to the Flash (from the processor). +//EJTAG TAP INSTRUCTIONS +#define ETAP_ADDRESS 0x08 //Select Address register. +#define ETAP_DATA 0x09 //Select Data register. +#define ETAP_CONTROL 0x0A //Select EJTAG Control register. +#define ETAP_EJTAGBOOT 0x0C //Set EjtagBrk, ProbEn and ProbTrap to ‘1’ as the reset value. +#define ETAP_FASTDATA 0x0E //Selects the Data and Fastdata registers. + +void XferInstruction(int* j,int instruction){ +// fill buffer with XferInstruction (14 bytes) +// if j<0 use separate counter and perform IO directly (also wait for CPU ready) + int i=0,z,w0=0; + int IO=0; + if((int)j==-1){ + j=&i; + IO=1; + } + if(IO){ +// bufferU[(*j)++]=JTAG_SEND_CMD; +// bufferU[(*j)++]=MTAP_SW_ETAP; +// bufferU[(*j)++]=JTAG_SET_MODE; +// bufferU[(*j)++]=0x3E;//0x1F; + bufferU[(*j)++]=JTAG_SEND_CMD; + bufferU[(*j)++]=ETAP_CONTROL; + bufferU[(*j)++]=FLUSH; + for(;(*j)>24)&0xFF; + bufferU[(*j)++]=(instruction>>16)&0xFF; + bufferU[(*j)++]=(instruction>>8)&0xFF; + bufferU[(*j)++]=instruction&0xFF; + bufferU[(*j)++]=JTAG_SEND_CMD; + bufferU[(*j)++]=ETAP_CONTROL; + bufferU[(*j)++]=JTAG_XFER_DATA; + bufferU[(*j)++]=0x00; + bufferU[(*j)++]=0x00; + bufferU[(*j)++]=0xC0; + bufferU[(*j)++]=0x00; + if(IO){ + bufferU[(*j)++]=FLUSH; + for(;(*j)0x80000||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n" + return; + } + //unsigned char *memExec=0; + //executiveArea*=2; + //if(executiveArea) memExec=(unsigned char *)malloc(executiveArea); + //for(i=0;i>8; + bufferU[j++]=10000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T2; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=WAIT_T3; + bufferU[j++]=SET_PORT_DIR; + bufferU[j++]=0x27; //RB7-6-4-3 output + bufferU[j++]=0xFF; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0x08; //MCLR=1 + bufferU[j++]=0; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; //MCLR=0 + bufferU[j++]=0; + bufferU[j++]=JTAG_SET_MODE; + bufferU[j++]=0x3E;//0x1F; + bufferU[j++]=JTAG_SEND_CMD; + bufferU[j++]=MTAP_SW_MTAP; + bufferU[j++]=JTAG_SET_MODE; + bufferU[j++]=0x3E;//0x1F; + bufferU[j++]=JTAG_SEND_CMD; + bufferU[j++]=MTAP_COMMAND; + bufferU[j++]=JTAG_XFER_DATA; + bufferU[j++]=0; + bufferU[j++]=0; + bufferU[j++]=0; + bufferU[j++]=MCHP_STATUS; + bufferU[j++]=FLUSH; + for(;j>16)); //lui $t0, + XferInstruction(&j,0x35080000+(i%0xFFFF)); //ori $t0, + XferInstruction(&j,0x8d090000); //lw $t1, 0($t0) + bufferU[j++]=FLUSH; + for(;j>16)); //lui $t0, + XferInstruction(-1,0x35080000+(i&0xFFFF)); //ori $t0, + XferInstruction(-1,0x8d090000); //lw $t1, 0($t0) + XferInstruction(-1,0xae690000); //sw $t1, 0($s3) + XferInstruction(-1,0); //nop + j=0; + bufferU[j++]=JTAG_SEND_CMD; + bufferU[j++]=ETAP_FASTDATA; + bufferU[j++]=JTAG_XFER_F_DATA; + bufferU[j++]=0x00; + bufferU[j++]=0x00; + bufferU[j++]=0x00; + bufferU[j++]=0x00; + bufferU[j++]=FLUSH; + for(;j>16)); //lui $t0, + XferInstruction(-1,0x35080000+(i&0xFFFF)); //ori $t0, + XferInstruction(-1,0x8d090000); //lw $t1, 0($t0) + XferInstruction(-1,0xae690000); //sw $t1, 0($s3) + XferInstruction(-1,0); //nop + j=0; + +/* XferInstruction(&j,0x3C13FF20); //lui $s3, 0xFF20 + XferInstruction(&j,0x3C080000+(i>>16)); //lui $t0, + XferInstruction(&j,0x35080000+(i%0xFFFF)); //ori $t0, + XferInstruction(&j,0x8d090000); //lw $t1, 0($t0) + bufferU[j++]=FLUSH; + for(;j>16)); //lui $t0, + XferInstruction(-1,0x35080000+(i&0xFFFF)); //ori $t0, + XferInstruction(-1,0x8d090000); //lw $t1, 0($t0) + XferInstruction(-1,0xae690000); //sw $t1, 0($s3) + XferInstruction(-1,0); //nop + j=0; + bufferU[j++]=JTAG_SEND_CMD; + bufferU[j++]=ETAP_FASTDATA; + bufferU[j++]=JTAG_XFER_F_DATA; + bufferU[j++]=0x00; + bufferU[j++]=0x00; + bufferU[j++]=0x00; + bufferU[j++]=0x00; + bufferU[j++]=FLUSH; + for(;j>16)); //lui $t0, + XferInstruction(&j,0x35080000+(i%0xFFFF)); //ori $t0, + XferInstruction(&j,0x8d090000); //lw $t1, 0($t0) + bufferU[j++]=FLUSH; + for(;j2){ //config area @ 0xF80000 + if(saveLog) fprintf(logfile,"\nCONFIG:\n"); + bufferU[j++]=SIX_N; + bufferU[j++]=4; + bufferU[j++]=0x20; //MOV XXXX,W0 + bufferU[j++]=0x0F; + bufferU[j++]=0x80; + bufferU[j++]=0x88; //MOV W0,TABLPAG + if(newTABLPAG){ + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + } + else{ + bufferU[j++]=0x01; + bufferU[j++]=0x90; + } + bufferU[j++]=REGOUT; + bufferU[j++]=FLUSH; + for(;j>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EXT_PORT; + bufferU[j++]=0; //MCLR=0 + bufferU[j++]=0; + bufferU[j++]=EN_VPP_VCC; //0 + bufferU[j++]=0x0; + bufferU[j++]=FLUSH; + for(;j2){ //only if separate config area + PrintMessage(strings[S_ConfigMem]); //"\r\nConfig Memory:\r\n" + if(config==3||config==4||config==6){ + PrintMessage1("0xF80000: FBS = 0x%02X\r\n",memCONFIG[0]); + if(config==4){ //0xF80000-16 + PrintMessage1("0xF80002: FSS = 0x%02X\r\n",memCONFIG[4]); + } + PrintMessage1("0xF80004: FGS = 0x%02X\r\n",memCONFIG[8]); + PrintMessage1("0xF80006: FOSCSEL = 0x%02X\r\n",memCONFIG[12]); + PrintMessage1("0xF80008: FOSC = 0x%02X\r\n",memCONFIG[16]); + PrintMessage1("0xF8000A: FWDT = 0x%02X\r\n",memCONFIG[20]); + PrintMessage1("0xF8000C: FPOR = 0x%02X\r\n",memCONFIG[24]); + PrintMessage1("0xF8000E: FICD = 0x%02X\r\n",memCONFIG[28]); + if(config==3){ //0xF80000-10 except 02 + PrintMessage1("0xF80010: FDS = 0x%02X\r\n",memCONFIG[32]); + } + else if(config==4){ //0xF80000-16 + PrintMessage1("0xF80010: UID0 = 0x%02X\r\n",memCONFIG[32]); + PrintMessage1("0xF80012: UID1 = 0x%02X\r\n",memCONFIG[36]); + PrintMessage1("0xF80014: UID2 = 0x%02X\r\n",memCONFIG[40]); + PrintMessage1("0xF80016: UID3 = 0x%02X\r\n",memCONFIG[44]); + } + } + else if(config==5){ //0xF80000-0C (16 bit) + PrintMessage2("0xF80000: FOSC = 0x%02X%02X\r\n",memCONFIG[1],memCONFIG[0]); + PrintMessage2("0xF80002: FWDT = 0x%02X%02X\r\n",memCONFIG[5],memCONFIG[4]); + PrintMessage2("0xF80004: FBORPOR = 0x%02X%02X\r\n",memCONFIG[9],memCONFIG[8]); + PrintMessage2("0xF80006: FBS = 0x%02X%02X\r\n",memCONFIG[13],memCONFIG[12]); + PrintMessage2("0xF80008: FSS = 0x%02X%02X\r\n",memCONFIG[17],memCONFIG[16]); + PrintMessage2("0xF8000A: FGS = 0x%02X%02X\r\n",memCONFIG[21],memCONFIG[20]); + PrintMessage2("0xF8000C: FICD = 0x%02X%02X\r\n",memCONFIG[25],memCONFIG[24]); + } + } + else{ + //last 2 program words + PrintMessage2("CONFIG1: 0x%04X\r\nCONFIG2: 0x%04X\r\n",(memCODE[dim-3]<<8)+memCODE[dim-4]\ + ,(memCODE[dim-7]<<8)+memCODE[dim-8]); + if(config==1){ //last 3 program words + PrintMessage1("CONFIG3: 0x%04X\r\n",(memCODE[dim-11]<<8)+memCODE[dim-12]); + } + if(config==2){ //last 4 program words + PrintMessage1("CONFIG4: 0x%04X\r\n",(memCODE[dim-15]<<8)+memCODE[dim-16]); + } + } + PrintMessage(strings[S_CodeMem]); //"\r\nCode memory:\r\n" + DisplayCODE24F(dim); + if(dim2){ + PrintMessage(strings[S_EEMem]); //"\r\nEEPROM memory:\r\n" + DisplayEE24F(); + } + if(executiveArea){ + char s[256],t[256]; + int d,valid,empty=1; + char* aux=(char*)malloc((dim/COL+1)*2*(16+COL*9)); + aux[0]=0; + s[0]=0; + empty=1; + PrintMessage(strings[S_ExeMem]); //"\r\nExecutive memory:\r\n" + for(i=0;i>4)&0xF; + int EEbaseAddr=0x1000-dim2; + int newTABLPAG=options&0x100000?1:0; + int err=0; + if(FWVersion<0x700){ + PrintMessage1(strings[S_FWver2old],"0.7.0"); //"This firmware is too old. Version %s is required\r\n" + return; + } + if(entry<2&&!CheckV33Regulator()){ //except 30Fxx which is on 5V + PrintMessage(strings[S_noV33reg]); //Can't find 3.3V expansion board + return; + } + if(saveLog){ + OpenLogFile(); + fprintf(logfile,"Write24Fx(%d,%d,%d,%d,%d,%.1f) (0x%X,0x%X,0x%X,0x%X,0x%X,%.3f)\n" + ,dim,dim2,options,appIDaddr,rowSize,wait,dim,dim2,options,appIDaddr,rowSize,wait); + } + dim*=2; //from words to bytes + if(dim>0x80000||dim<0){ + PrintMessage(strings[S_CodeLim]); //"Code size out of limits\r\n" + return; + } + if(dim2>0x1000||dim2<0){ + PrintMessage(strings[S_EELim]); //"EEPROM size out of limits\r\n" + return; + } + j=size; + if(j%(rowSize*4)){ //grow to an integer number of rows + size=(j/(rowSize*4)+1)*rowSize*4; + memCODE=(unsigned char*)realloc(memCODE,size); + for(;jsize) dim=size; + if(sizeEE<0x1000) dim2=0; + if(dim<1){ + PrintMessage(strings[S_NoCode]); //"Empty code area\r\n" + return; + } + if((entry==1)||(entry==2)){ //High voltage programming: 3.3V + 1.5V + R drop + margin + if(!StartHVReg(entry==2?12:6)){ //12V only for 30Fxx !!! + PrintMessage(strings[S_HVregErr]); //"HV regulator error\r\n" + return; + } + } + else StartHVReg(-1); //LVP: current limited to (5-0.7-3.6)/10k = 50uA + if(config>2){ //only if separate config area + PrintMessage(strings[S_ConfigMem]); //"\r\nConfig Memory:\r\n" + if(config==3||config==4||config==6){ + PrintMessage1("0xF80000: FBS = 0x%02X\r\n",memCONFIG[0]); + if(config==4){ //0xF80000-16 + PrintMessage1("0xF80002: FSS = 0x%02X\r\n",memCONFIG[4]); + } + PrintMessage1("0xF80004: FGS = 0x%02X\r\n",memCONFIG[8]); + PrintMessage1("0xF80006: FOSCSEL = 0x%02X\r\n",memCONFIG[12]); + PrintMessage1("0xF80008: FOSC = 0x%02X\r\n",memCONFIG[16]); + PrintMessage1("0xF8000A: FWDT = 0x%02X\r\n",memCONFIG[20]); + PrintMessage1("0xF8000C: FPOR = 0x%02X\r\n",memCONFIG[24]); + PrintMessage1("0xF8000E: FICD = 0x%02X\r\n",memCONFIG[28]); + if(config==3){ //0xF80000-10 except 02 + PrintMessage1("0xF80010: FDS = 0x%02X\r\n",memCONFIG[32]); + } + else if(config==4){ //0xF80000-16 + PrintMessage1("0xF80010: UID0 = 0x%02X\r\n",memCONFIG[32]); + PrintMessage1("0xF80012: UID1 = 0x%02X\r\n",memCONFIG[36]); + PrintMessage1("0xF80014: UID2 = 0x%02X\r\n",memCONFIG[40]); + PrintMessage1("0xF80016: UID3 = 0x%02X\r\n",memCONFIG[44]); + } + } + else if(config==5){ //0xF80000-0C (16 bit) + PrintMessage2("0xF80000: FOSC = 0x%02X%02X\r\n",memCONFIG[1],memCONFIG[0]); + PrintMessage2("0xF80002: FWDT = 0x%02X%02X\r\n",memCONFIG[5],memCONFIG[4]); + PrintMessage2("0xF80004: FBORPOR = 0x%02X%02X\r\n",memCONFIG[9],memCONFIG[8]); + PrintMessage2("0xF80006: FBS = 0x%02X%02X\r\n",memCONFIG[13],memCONFIG[12]); + PrintMessage2("0xF80008: FSS = 0x%02X%02X\r\n",memCONFIG[17],memCONFIG[16]); + PrintMessage2("0xF8000A: FGS = 0x%02X%02X\r\n",memCONFIG[21],memCONFIG[20]); + PrintMessage2("0xF8000C: FICD = 0x%02X%02X\r\n",memCONFIG[25],memCONFIG[24]); + } + } + else{ + //last 2 program words + PrintMessage2("CONFIG1: 0x%04X\r\nCONFIG2: 0x%04X\r\n",(memCODE[dim-3]<<8)+memCODE[dim-4]\ + ,(memCODE[dim-7]<<8)+memCODE[dim-8]); + if(config==1){ //last 3 program words + PrintMessage1("CONFIG3: 0x%04X\r\n",(memCODE[dim-11]<<8)+memCODE[dim-12]); + } + if(config==2){ //last 4 program words + PrintMessage1("CONFIG4: 0x%04X\r\n",(memCODE[dim-15]<<8)+memCODE[dim-16]); + } + } + unsigned int start=GetTickCount(); + bufferU[0]=0; + j=1; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=2000>>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=EN_VPP_VCC; //enter program mode + bufferU[j++]=0x0; + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; + bufferU[j++]=WAIT_T2; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD + VPP + bufferU[j++]=0x5; + if((entry==0)||(entry==3)){ //LVP: pulse on MCLR + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + } + else PrintMessage(strings[S_HVICSP]); //"High Voltage ICSP\r\n" + bufferU[j++]=WAIT_T3; + bufferU[j++]=TX16; + bufferU[j++]=2; + bufferU[j++]=0x4D; + bufferU[j++]=0x43; + bufferU[j++]=0x48; + bufferU[j++]=0x51; + bufferU[j++]=WAIT_T3; //min 1ms + bufferU[j++]=EN_VPP_VCC; //VDD + VPP + bufferU[j++]=0x5; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=30000>>8; + bufferU[j++]=30000&0xff; + bufferU[j++]=WAIT_T3; //min 25ms + if(entry==2){ //30Fx entry + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=EN_VPP_VCC; //VDD + bufferU[j++]=0x1; + bufferU[j++]=EN_VPP_VCC; //VDD + VPP + bufferU[j++]=0x5; + bufferU[j++]=ICSP_NOP; + } + else{ + //Additional 5 clock cycles upon entering program mode + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x4; //CK=1 + bufferU[j++]=SET_CK_D; + bufferU[j++]=0x0; //CK=0 + } + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j>12)&0xF); //MOV XXXX,W6 + bufferU[j++]=(appIDaddr>>4)&0xFF; + bufferU[j++]=((appIDaddr<<4)&0xF0)+6; + bufferU[j++]=0x20; //MOV #VISI,W7 + bufferU[j++]=0x78; + bufferU[j++]=0x47; + bufferU[j++]=SIX_LONG; //TBLRDL [W6],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0x96; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=SET_PARAMETER; + bufferU[j++]=SET_T3; + bufferU[j++]=2000>>8; + bufferU[j++]=2000&0xff; + bufferU[j++]=FLUSH; + for(;j>8; + //bulk erase command + bufferU[j++]=SIX_N; + bufferU[j++]=4; + bufferU[j++]=0x24; //MOV XXXX,W10 + if(erase==0){ //0x4064 + bufferU[j++]=0x06; + bufferU[j++]=0x4A; + } + else if(erase==1){ //0x404F + bufferU[j++]=0x04; + bufferU[j++]=0xFA; + } + else if(erase>=2){ //0x407F + bufferU[j++]=0x07; + bufferU[j++]=0xFA; + } + bufferU[j++]=0x88; //MOV W10,NVMCON + bufferU[j++]=0x3B; + bufferU[j++]=0x0A; + bufferU[j++]=0x20; //MOV XXXX,W0 + bufferU[j++]=0x00; + bufferU[j++]=0x00; + bufferU[j++]=0x88; //MOV W0,TABLPAG + if(newTABLPAG){ + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + } + else{ + bufferU[j++]=0x01; + bufferU[j++]=0x90; + } + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //TBLWTL W0,[W0] (dummy write) + bufferU[j++]=0xBB; + bufferU[j++]=0x08; + bufferU[j++]=0x00; + if(erase>=2){ //30Fx, unlock and external timing + bufferU[j++]=SIX_N; + bufferU[j++]=4; + bufferU[j++]=0x20; //MOV 0x55,W8 + bufferU[j++]=0x05; + bufferU[j++]=0x58; + bufferU[j++]=0x88; //MOV W8,NVMKEY + bufferU[j++]=0x3B; + bufferU[j++]=0x38; + bufferU[j++]=0x20; //MOV 0xAA,W8 + bufferU[j++]=0x0A; + bufferU[j++]=0xA8; + bufferU[j++]=0x88; //MOV W8,NVMKEY + bufferU[j++]=0x3B; + bufferU[j++]=0x38; + bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + bufferU[j++]=WAIT_T3; + if(erase==3){ //200 ms timing + bufferU[j++]=FLUSH; + for(;j0?0x1A:0x4A; //0x4001/0x4004 + bufferU[j++]=0x88; //MOV W10,NVMCON + bufferU[j++]=0x3B; + bufferU[j++]=0x0A; + bufferU[j++]=0x20; //MOV XXXX,W0 + bufferU[j++]=0x00; + bufferU[j++]=0x00; + bufferU[j++]=0x88; //MOV W0,TABLPAG + if(newTABLPAG){ + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + } + else{ + bufferU[j++]=0x01; + bufferU[j++]=0x90; + } + bufferU[j++]=0x04; //GOTO 0x200 + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j=dim) break; + } + if((i>>17)!=High){ //advance page + bufferU[j++]=SIX; //MOV XXXX,W0 + bufferU[j++]=0x20; + bufferU[j++]=(i>>21)&0xFF; + bufferU[j++]=(i>>13)&0xF0; + bufferU[j++]=SIX; //MOV W0,TABLPAG + bufferU[j++]=0x88; + if(newTABLPAG){ + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + } + else{ + bufferU[j++]=0x01; + bufferU[j++]=0x90; + } + bufferU[j++]=SIX; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j>17; + } + bufferU[j++]=SIX_N; + bufferU[j++]=8; + bufferU[j++]=0x20+((i>>13)&0xF); //MOV i/2,W7 + bufferU[j++]=(i>>5)&0xFF; + bufferU[j++]=((i<<3)&0xF0)+7; + bufferU[j++]=0x20+((memCODE[i+1]>>4)&0xF); //MOV LSW0,W0 + bufferU[j++]=((memCODE[i+1]<<4)&0xF0)+((memCODE[i]>>4)&0xF); + bufferU[j++]=(memCODE[i]<<4)&0xF0; + bufferU[j++]=0x20+((memCODE[i+6]>>4)&0xF); //MOV MSB1:MSB0,W1 + bufferU[j++]=((memCODE[i+6]<<4)&0xF0)+((memCODE[i+2]>>4)&0xF); + bufferU[j++]=((memCODE[i+2]<<4)&0xF0)+1; + bufferU[j++]=0x20+((memCODE[i+5]>>4)&0xF); //MOV LSW1,W2 + bufferU[j++]=((memCODE[i+5]<<4)&0xF0)+((memCODE[i+4]>>4)&0xF); + bufferU[j++]=((memCODE[i+4]<<4)&0xF0)+2; + bufferU[j++]=0x20+((memCODE[i+9]>>4)&0xF); //MOV LSW2,W3 + bufferU[j++]=((memCODE[i+9]<<4)&0xF0)+((memCODE[i+8]>>4)&0xF); + bufferU[j++]=((memCODE[i+8]<<4)&0xF0)+3; + bufferU[j++]=0x20+((memCODE[i+14]>>4)&0xF); //MOV MSB3:MSB2,W4 + bufferU[j++]=((memCODE[i+14]<<4)&0xF0)+((memCODE[i+10]>>4)&0xF); + bufferU[j++]=((memCODE[i+10]<<4)&0xF0)+4; + bufferU[j++]=0x20+((memCODE[i+13]>>4)&0xF); //MOV LSW3,W5 + bufferU[j++]=((memCODE[i+13]<<4)&0xF0)+((memCODE[i+12]>>4)&0xF); + bufferU[j++]=((memCODE[i+12]<<4)&0xF0)+5; + bufferU[j++]=0xEB; //CLR W6 + bufferU[j++]=0x03; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_N; + bufferU[j++]=0x88; //Append 2 NOP + bufferU[j++]=0xBB; //TBLWTL [W6++],[W7] + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTH.B [W6++],[W7++] + bufferU[j++]=0xDB; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTH.B [W6++],[++W7] + bufferU[j++]=0xEB; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTL [W6++],[W7++] + bufferU[j++]=0x1B; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTL [W6++],[W7] + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTH.B [W6++],[W7++] + bufferU[j++]=0xDB; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTH.B [W6++],[++W7] + bufferU[j++]=0xEB; + bufferU[j++]=0xB6; + bufferU[j++]=0xBB; //TBLWTL [W6++],[W7++] + bufferU[j++]=0x1B; + bufferU[j++]=0xB6; + k++; + if(k==rowSize/4){ //Write row + if(erase>1){ //30Fx, unlock and external timing + bufferU[j++]=FLUSH; + for(;j0?0x1A:0x4A; //0x4001/0x4004 + bufferU[j++]=0x88; //MOV W10,NVMCON + bufferU[j++]=0x3B; + bufferU[j++]=0x0A; + bufferU[j++]=0x20; //MOV 0x55,W8 + bufferU[j++]=0x05; + bufferU[j++]=0x58; + bufferU[j++]=0x88; //MOV W8,NVMKEY + bufferU[j++]=0x3B; + bufferU[j++]=0x38; + bufferU[j++]=0x20; //MOV 0xAA,W8 + bufferU[j++]=0x0A; + bufferU[j++]=0xA8; + bufferU[j++]=0x88; //MOV W8,NVMKEY + bufferU[j++]=0x3B; + bufferU[j++]=0x38; + bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //BCLR NVMCON,#WR + bufferU[j++]=0xA9; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + bufferU[j++]=SIX_LONG; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + } + else{ //internal timing + bufferU[j++]=SIX_LONG; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + } + k=0; + } + bufferU[j++]=FLUSH; + for(;j=dim) break; + if((i>>17)!=High){ //advance page + bufferU[j++]=SIX; //MOV XXXX,W0 + bufferU[j++]=0x20; + bufferU[j++]=(i>>21)&0xFF; + bufferU[j++]=(i>>13)&0xF0; + bufferU[j++]=SIX; //MOV W0,TABLPAG + bufferU[j++]=0x88; + if(newTABLPAG){ + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + } + else{ + bufferU[j++]=0x01; + bufferU[j++]=0x90; + } + bufferU[j++]=SIX; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j>17; + } + bufferU[j++]=SIX; //MOV i/2,W6 + bufferU[j++]=0x20+((i>>13)&0xF); + bufferU[j++]=(i>>5)&0xFF; + bufferU[j++]=((i<<3)&0xF0)+6; + bufferU[j++]=SIX; //MOV #VISI,W7 + bufferU[j++]=0x20; + bufferU[j++]=0x78; + bufferU[j++]=0x47; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //TBLRDL [W6],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0x96; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDH.B [W6++],[W7++] + bufferU[j++]=0xBA; + bufferU[j++]=0xDB; + bufferU[j++]=0xB6; + bufferU[j++]=SIX_LONG; //TBLRDH.B [++W6],[W7--] + bufferU[j++]=0xBA; + bufferU[j++]=0xD3; + bufferU[j++]=0xD6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDL [W6],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0x96; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDH.B [W6++],[W7++] + bufferU[j++]=0xBA; + bufferU[j++]=0xDB; + bufferU[j++]=0xB6; + bufferU[j++]=SIX_LONG; //TBLRDH.B [++W6],[W7--] + bufferU[j++]=0xBA; + bufferU[j++]=0xD3; + bufferU[j++]=0xD6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //TBLRDL [W6++],[W7] + bufferU[j++]=0xBA; + bufferU[j++]=0x0B; + bufferU[j++]=0xB6; + bufferU[j++]=REGOUT; + bufferU[j++]=SIX_LONG; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=FLUSH; + for(;j=max_err) break; + } + PrintStatusEnd(); + PrintMessage1(strings[S_ComplErr],err); //"completed: %d errors\r\n" + if(err>=max_err){ + PrintMessage1(strings[S_MaxErr],err); //"Exceeded maximum number of errors (%d), write interrupted\r\n" + } +//****************** erase, write and verify EEPROM ******************** + if(dim2&&err>12; + if(eewrite==0){ //24FxxKAxx + bufferU[j++]=SIX; //MOV 0x4050,W10 + bufferU[j++]=0x24; + bufferU[j++]=0x05; + bufferU[j++]=0x0A; + bufferU[j++]=SIX; //MOV W10,NVMCON + bufferU[j++]=0x88; + bufferU[j++]=0x3B; + bufferU[j++]=0x0A; + bufferU[j++]=SIX; //MOV 0x7F,W0 + bufferU[j++]=0x20; + bufferU[j++]=0x07; + bufferU[j++]=0xF0; + bufferU[j++]=SIX; //MOV W0,TABLPAG + bufferU[j++]=0x88; + if(newTABLPAG){ + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + } + else{ + bufferU[j++]=0x01; + bufferU[j++]=0x90; + } + bufferU[j++]=SIX; //MOV EEbaseAddr,W0 + bufferU[j++]=0x2F; + bufferU[j++]=EEbaseAddr>>4; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX; //TBLWTL W0,[W0] + bufferU[j++]=0xBB; + bufferU[j++]=0x08; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP;/**/ + /* //Erase EEPROM + bufferU[j++]=SIX; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=WAIT_T3; + bufferU[j++]=SIX; //MOV 0x4004,W10 + bufferU[j++]=0x24; + bufferU[j++]=0x00; + bufferU[j++]=0x4A; + bufferU[j++]=SIX; //MOV W10,NVMCON + bufferU[j++]=0x88; + bufferU[j++]=0x3B; + bufferU[j++]=0x0A; + bufferU[j++]=SIX; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=FLUSH; + for(;j>4; + bufferU[j++]=((i<<4)&0xF0)+7; + bufferU[j++]=SIX; //MOV XXXX,W0 + bufferU[j++]=0x20+((memEE[i+1]>>4)&0xF); + bufferU[j++]=((memEE[i+1]<<4)&0xF0)+((memEE[i]>>4)&0xF); + bufferU[j++]=(memEE[i]<<4)&0xF0; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //TBLWTL W0,[W7++] + bufferU[j++]=0xBB; + bufferU[j++]=0x1B; + bufferU[j++]=0x80; + if(eewrite==0){ //24FxxKAxx + bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + } + else if(eewrite==1){ //30Fxxxx + bufferU[j++]=SIX_N; + bufferU[j++]=6; + bufferU[j++]=0x24; //MOV 0x4004,W10 + bufferU[j++]=0x00; + bufferU[j++]=0x4A; + bufferU[j++]=0x88; //MOV W10,NVMCON + bufferU[j++]=0x3B; + bufferU[j++]=0x0A; + bufferU[j++]=0x20; //MOV 0x55,W8 + bufferU[j++]=0x05; + bufferU[j++]=0x58; + bufferU[j++]=0x88; //MOV W8,NVMKEY + bufferU[j++]=0x3B; + bufferU[j++]=0x38; + bufferU[j++]=0x20; //MOV 0xAA,W8 + bufferU[j++]=0x0A; + bufferU[j++]=0xA8; + bufferU[j++]=0x88; //MOV W8,NVMKEY + bufferU[j++]=0x3B; + bufferU[j++]=0x38; + bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + bufferU[j++]=WAIT_T3; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //BCLR NVMCON,#WR + bufferU[j++]=0xA9; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + } + bufferU[j++]=FLUSH; + for(;j>4; + bufferU[j++]=0x06; + bufferU[j++]=SIX; //MOV #VISI,W7 + bufferU[j++]=0x20; + bufferU[j++]=0x78; + bufferU[j++]=0x47; + bufferU[j++]=SIX; //GOTO 0x200 + bufferU[j++]=0x04; + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + int errE=0; + for(i=k2=EEbaseAddr;iDIMBUF-7||i==dim2-4){ + bufferU[j++]=FLUSH; + for(;j2&&config<5&&err>16; + bufferU[j++]=SIX_N; + bufferU[j++]=6; + bufferU[j++]=0x20; //MOV 0xF8,W0 + bufferU[j++]=0x0F; + bufferU[j++]=0x80; + bufferU[j++]=0x88; //MOV W0,TABLPAG + if(newTABLPAG){ + bufferU[j++]=0x02; + bufferU[j++]=0xA0; + } + else{ + bufferU[j++]=0x01; + bufferU[j++]=0x90; + } + bufferU[j++]=0x24; //MOV 0x400x,W10 + bufferU[j++]=0x00; + if(confword==0)bufferU[j++]=0x0A; //0x4000 + else if(confword==1)bufferU[j++]=0x3A; //0x4003 + else if(confword==2)bufferU[j++]=0x4A; //0x4004 + else if(confword==3)bufferU[j++]=0x8A; //0x4008 + bufferU[j++]=0x88; //MOV W10,NVMCON + bufferU[j++]=0x3B; + bufferU[j++]=0x0A; + bufferU[j++]=0x20; //MOV 0,W7 + bufferU[j++]=0x00; + bufferU[j++]=0x07; + bufferU[j++]=0x04; //GOTO 0x200 + bufferU[j++]=0x02; + bufferU[j++]=0x00; + bufferU[j++]=ICSP_NOP; + for(i=0;i<12;i++){ + //Write CONFIG + bufferU[j++]=SIX; //MOV XXXX,W0 + bufferU[j++]=0x20; + bufferU[j++]=(memCONFIG[i*4]>>4)&0xF; + bufferU[j++]=(memCONFIG[i*4]<<4)&0xF0; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //TBLWTL W0,[W7++] + bufferU[j++]=0xBB; + bufferU[j++]=0x1B; + bufferU[j++]=0x80; + //if(memCONFIG[i*4]<0xFF){ //write if not empty + bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + //} + bufferU[j++]=FLUSH; + for(;j=5&&err>12); + bufferU[j++]=(value>>4); + bufferU[j++]=(value<<4); + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //TBLWTL W0,[W7++] + bufferU[j++]=0xBB; + bufferU[j++]=0x1B; + bufferU[j++]=0x80; + if(value<0xFFFF){ //write if not empty + bufferU[j++]=SIX_N; + bufferU[j++]=6; + bufferU[j++]=0x24; //MOV 0x400x,W10 + bufferU[j++]=0x00; + bufferU[j++]=0x8A; //0x4008 + bufferU[j++]=0x88; //MOV W10,NVMCON + bufferU[j++]=0x3B; + bufferU[j++]=0x0A; + bufferU[j++]=0x20; //MOV 0x55,W8 + bufferU[j++]=0x05; + bufferU[j++]=0x58; + bufferU[j++]=0x88; //MOV W8,NVMKEY + bufferU[j++]=0x3B; + bufferU[j++]=0x38; + bufferU[j++]=0x20; //MOV 0xAA,W8 + bufferU[j++]=0x0A; + bufferU[j++]=0xA8; + bufferU[j++]=0x88; //MOV W8,NVMKEY + bufferU[j++]=0x3B; + bufferU[j++]=0x38; + bufferU[j++]=SIX_LONG; //BSET NVMCON,#WR + bufferU[j++]=0xA8; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + bufferU[j++]=WAIT_T3; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=ICSP_NOP; + bufferU[j++]=SIX_LONG; //BCLR NVMCON,#WR + bufferU[j++]=0xA9; + bufferU[j++]=0xE7; + bufferU[j++]=0x61; + } + bufferU[j++]=FLUSH; + for(;j 1MB; + modified prog mode entry for AVR; + fixed write of 93Sx6 with protection + +V 0.8.0 june 2012: added one-wire memories DS2430,DS2431,DS2433,DS28EC20, thermometer DS1820; + added UNIO memories 11010-20-40-80-160; + fixed algorithms for 24x1024/5 and 251024, + added SPI FLASH 251005,252005,254005,258005,251605,25X10,25X20,25X40,25X80, + 25X16,25X32,25X64; + added 16F1782-83-84-86-87,12C508-509 + +V 0.7.10 january 2012: added 12F617,12F1501,16F1503-07-08-09,16F720-21,16F72,16F707, + 18F13K22,18F14K22,18F23K22,18F43K22,18F24K22,18F44K22,18F25K22, + 18F45K22,18F26K22,18F46K22,18F8520,18F66J60,18F66J65,18F67J60, + 18F86J60,18F86J65,18F87J60,18F96J60,18F96J65,18F97J60, + fixed read/write binary files, various corrections, + added support for in-circuit debugging + +V 0.7.9 april 2011: first public version, using the same version number as op + +To compile: make +To install: make install +Can be compiled under windows with MinGW/MSYS and GTK bundle + diff --git a/resources.xml b/resources.xml new file mode 100644 index 0000000..3a37c27 --- /dev/null +++ b/resources.xml @@ -0,0 +1,10 @@ + + + + opgui.glade + read.png + sys.png + write.png + style.css + + diff --git a/strings.c b/strings.c new file mode 100644 index 0000000..5899abe --- /dev/null +++ b/strings.c @@ -0,0 +1,1070 @@ +// Strings.c v0.12.0 + +#include "common.h" +#define NL "\n" + +char *STR_ID[DIM]; +char *strings_it[DIM]; +char *strings_en[DIM]; + + +int strfind(const char* langid,const char* langfile){ + FILE* f=fopen(langfile,"r"); + char line[4096],*id,*string,*p; + char temp[32]; + int i=0; +// printf("file %s f=%d\n",langfile, f); fflush(stdout); + if(f){ + temp[0]=0; + for(;fgets(line,sizeof(line),f);){ + if(sscanf(line,"[%[^]]",temp)&&!strncmp(langid,temp,sizeof(temp))){ + strings=malloc(DIM*sizeof(char*)); + for(i=0;i0&&line[0]=='[') break; //start of new table + id=strtok(line," \t"); + string=strtok(0,"\n"); + for(i=0;string&&i imposta breakpoint all'indirizzo " NL + " freeze [on,off] freeze periferiche" NL + " h[alt] ferma esecuzione" NL + " list mostra codice a partire da " NL + " p[rint] 0x osserva variabile all'indirizzo " NL + " p[rint] osserva variabile " NL + " p[rint] bank osserva i registri nel banco " NL + " p[rint] p osserva la memoria programma all'indirizzo " NL + " p[rint] ee osserva la memoria eeprom all'indirizzo " NL + " p[rint] ee osserva tutta la memoria eeprom" NL + " r[un] vai" NL + " s[tep] [n] passo singolo [n volte]" NL + " step over / ss [n] passo sopra le chiamate [n volte]" NL + " version leggi versione debugger" NL + " w[atch] variabile aggiungi/rimuovi variabile alla lista di osservazione" NL + " w[atch] 0x aggiungi/rimuovi variabile all'indirizzo alla lista di osservazione" NL; + strings_it[I_GUI_CMD_HELP]= + "Opzioni da linea di comando:" NL + " ?,h,help guida comandi" NL + " command invia al programmatore ed esci." NL + " Il messaggio è composto da byte esadecimali separati da uno spazio," NL + " fino a un massimo di 64; quelli non specificati vengono posti a 0" NL + " lang carica " NL + " langfile scrivi tutte le stringhe su file" NL; + strings_it[L_HELP]= + "op [opzioni]" NL NL + "-BKosccal carica BKosccal da file" NL + "-calib carica calibration da file" NL + "-command invia al programmatore ed esci." NL + " Il messaggio è composto da byte esadecimali separati da uno spazio," NL + " fino a un massimo di 64; quelli non specificati vengono posti a 0" NL + "-cwX forza config word X [1-7]" NL + "-d, device dispositivo" NL + "-ee usa eeprom" NL + "-err imposta massimo errori in scrittura" NL + "-fuse scrive il byte fuse low (solo Atmel)" NL + "-fuseh scrive il byte fuse high (solo Atmel)" NL + "-fusex scrive il byte extended fuse (solo Atmel)" NL + "-fuse3k scrive il byte fuse low a 3kHz (solo Atmel)" NL + "-h, help guida" NL + "-HWtest test hardware" NL + "-i, info informazioni programmatore" NL + "-icd abilita ICD (goto indirizzo)" NL + "-i2c_r leggi N byte dal bus I2C" NL + "-i2c_r2 leggi N byte dal bus I2C (indirizzi 16b)" NL + "-i2c_w scrivi N byte sul bus I2C" NL + "-i2c_w2 scrivi N byte sul bus I2C (indirizzi 16b)" NL + "-i2cspeed cambia velocità I2C: 0=100k,1=200k,2=500k,3=800k" NL + "-id usa ID" NL + "-l, log [=file] salva registro" NL + "-lang carica " NL + "-langfile scrivi tutte le stringhe su file" NL + "-lock scrive il byte lock (solo Atmel)" NL + "-mode SPI mode: 00,01,10,11" NL + "-nolvcheck salta controllo regolatore a 3,3V" NL + "-osccal carica osccal da file invece che dal valore salvato prima della cancellazione" NL + "-p, path percorso programmatore [/dev/usb/hiddev0]" NL + "-pid pid programmatore [0x100]" NL + "-r, reserved leggi area riservata" NL + "-rep dimensione report [64]" NL + "-s1, S1 Programmazione multipla comandata da S1" NL + "-s, save salva su file Ihex" NL + "-se, saveEE salva EEPROM su file Ihex (solo ATxxxx)" NL + "-spi_r leggi N byte dal bus SPI" NL + "-spi_w scrivi N byte sul bus SPI" NL + "-spispeed cambia velocità SPI: 0=100k,1=200k,2=300k,3=500k" NL + "-support dispositivi supportati" NL + "-use_BKosccal copia BKosccal su osccal" NL + "-v, version versione" NL + "-vid vid programmatore [0x4D8]" NL + "-w, write scrivi file Ihex" NL + "-we, writeEE scrivi EEPROM file Ihex (solo ATxxxx)" NL + "" NL + "es. op -d 12F683 -s prova.hex" NL; + strings_it[L_OPTERR]="Errore nelle opzioni" NL; + strings_it[L_INFO1]="vid 0x%04hx pid 0x%04hx versione 0x%04hx "; + strings_it[L_INFO2]= NL "bus: %d devnum: %d ifnum: %d" NL; + strings_it[L_UNKNOWN]="sconosciuto"; + strings_it[L_NAME]="Il dispositivo su %s si chiama %s" NL; + strings_it[L_DEV_RO]="Dispositivi supportati in sola lettura:"; + strings_it[L_DEV_RW]="Dispositivi supportati in lettura e scrittura:"; + +// ENGLISH strings + strings_en[S_NL]=NL; + strings_en[S_noprog]="Programmer not detected" NL; + strings_en[S_prog]="Programmer detected" NL; + strings_en[S_progDev]="Programmer detected on %s" NL; + strings_en[S_DevPermission]="Cannot open %s, make sure you have read permission on it" NL; + strings_en[S_nodev_r]="Device not supported for reading" NL; + strings_en[S_nodev_w]="Device not supported for writing" NL; + strings_en[S_nodev]="Unknown device" NL; + strings_en[S_DevMismatch]="Warning: the device is different from what specified in source data" NL; + strings_en[S_noV33reg]="3.3V Regulator not detected" NL; + strings_en[S_progver]="Firmware version %d.%d.%d" NL; + strings_en[S_progid]="Hardware ID: %d.%d.%d"; + strings_en[S_FWver2old]="This firmware is too old. Version %s is required" NL; + strings_en[S_lowUsbV]="USB voltage too low (VUSB<4.5V)" NL; + strings_en[S_HiVPP]="Warning: regulator voltage too high" NL NL; + strings_en[S_LowVPP]="Warning: regulator voltage too low" NL NL; + strings_en[S_reg]="Regulator up and running after %dms VPP=%.1fV" NL NL; + strings_en[S_dev_det]="Device detected: vid=0x%04X pid=0x%04X" NL "Path: %s" NL; + strings_en[S_file]="Hex8 files (*.hex)|*.hex|All files (*.*)|*.*||"; + strings_en[S_file2]="Hex8 files (*.hex)|*.hex|Binary files (*.bin)|*.bin|All files (*.*)|*.*||"; + strings_en[S_fileEEP]="Hex8 files (*.hex *.eep)|*.hex;*.eep|All files (*.*)|*.*||"; + strings_en[S_noDLL]="Error opening hid.dll"; + strings_en[S_openEEfile]="Open EEPROM file"; + strings_en[S_saveEEfile]="Save EEPROM file"; + // + strings_en[S_IhexShort]="Intel hex8 line too short:" NL "%s" NL; + strings_en[S_IhexChecksum]="Intel hex8 checksum error in line:" NL "%s" NL; + strings_en[S_InvHandle]="Invalid handle" NL; + strings_en[S_LogFile]="Log.txt"; + strings_en[S_FileSaved]="Saved file %s" NL; + // + strings_en[S_HVICSP]="High Voltage ICSP" NL; + strings_en[S_StartRead]="Reading ..." NL; + strings_en[S_Read]="Reading ... "; + strings_en[S_CodeReading1]="Reading code ... "; + strings_en[S_CodeReading]="Reading: %3d%%, add. %03X"; + strings_en[S_CodeReading2]="Reading: %3d%%, add. %05X"; + strings_en[S_ReadEnd]="Reading completed: %d words" NL; + strings_en[S_ReadID_CONFIG]="Reading ID and CONFIG"; + strings_en[S_Read_CONFIG_A]="Reading CONFIG area ... "; + strings_en[S_Read_EXE_A]="Reading Executive area ... "; + strings_en[S_ReadEE]="Reading EEPROM ... "; + strings_en[S_StartErase]="Erasing ... "; + strings_en[S_Writing]="Writing ..." NL; + strings_en[S_StartCodeProg]="Writing code ... "; + strings_en[S_CodeWriting]="Writing: %3d%%, add. %03X"; + strings_en[S_CodeWriting2]="Writing: %3d%%, add. %04X"; + strings_en[S_IDW]="Writing ID ... "; + strings_en[S_ConfigW]="Writing CONFIG ... "; + strings_en[S_ConfigAreaW]="Writing CONFIG area ... "; + strings_en[S_EEAreaW]="Writing EEPROM ... "; + strings_en[S_FuseAreaW]="Writing FUSE area ... "; + strings_en[S_CodeV]="Verifying code ... "; + strings_en[S_CodeV2]="Verifying: %d%%, add. %04X"; + strings_en[S_IDV]="Verifying ID ... "; + strings_en[S_ConfigV]="Verifying CONFIG ... "; + strings_en[S_EEV]="Verifying EEPROM ... "; + strings_en[S_IntW]="Write interrupted" NL; + strings_en[S_TotErr]="completed, %d total errors" NL; + strings_en[S_ComplErr]="completed, %d errors" NL; + strings_en[S_Compl]="completed" NL; + strings_en[S_Ready]="ready"; + strings_en[S_End]= NL "End (%.2f s)" NL NL; + strings_en[S_EndErr]= NL "End (%.2f s) %d %s" NL NL; + strings_en[S_ProtErase]="Device protected, overriding protection." NL; + // + strings_en[S_Inohex]="Error: '%.4s' doesn't look very hexadecimal, right?" NL; + strings_en[S_ReadErr]="Read error: requested words=%d, read=%d" NL; + strings_en[S_ReadCodeErr]="Error reading code area, requested %d words, read %d" NL; + strings_en[S_ReadCodeErr2]="Error reading code area, requested %d bytes, read %d" NL; + strings_en[S_ReadEEErr]="Error reading EEPROM area, requested %d bytes, read %d" NL; + strings_en[S_ConfigErr]="Error reading configuration area, requested %d words, read %d" NL; + strings_en[S_ReadConfigErr]="Error reading configuration area, requested %d bytes, read %d" NL; + strings_en[S_ErrOsccal]="Error reading OSCCAL and BKOSCCAL"; + strings_en[S_CodeWError]="Error writing address %3X: written %03X, read %03X" NL; + strings_en[S_CodeWError2]="Error writing address %3X: written %04X, read %04X" NL; + strings_en[S_CodeWError3]="Error writing address %4X: written %02X, read %02X" NL; + strings_en[S_CodeWError4]="Error writing code area, requested %d bytes, written %d" NL; + strings_en[S_ConfigWErr]="Error writing config area: written %03X, read %03X" NL; + strings_en[S_ConfigWErr2]="Error writing CONFIG"; + strings_en[S_ConfigWErr3]="Error writing config area: written %04X, read %04X" NL; + strings_en[S_WErr1]="Error writing %s: written %02X, read %02X" NL; + strings_en[S_WErr2]="Error writing %s: written %04X, read %04X" NL; + strings_en[S_IDErr]="Error writing ID%d: written %04X, read %04X" NL; + strings_en[S_ICDErr]="Error writing ICD (0x%X): written %04X, read %04X" NL; + strings_en[S_Calib1Err]="Error writing Calib1: written %04X, read %04X" NL; + strings_en[S_Calib2Err]="Error writing Calib2: written %04X, read %04X" NL; + strings_en[S_CodeVError]="Error verifying address %04X (%d), written %02X, read %02X" NL; + strings_en[S_CodeVError2]="Error verifying code area, requested %d bytes, read %d" NL; + strings_en[S_CodeVError3]="Error verifying code area, requested %d words, read %d" NL; + strings_en[S_ErrSing]="error"; + strings_en[S_ErrPlur]="errors"; + strings_en[S_MaxErr]="Exceeded maximum number of errors (%d), write interrupted" NL; + strings_en[S_I2CInitErr]="Error initializing I2C bus" NL; + strings_en[S_I2CAckErr]="I2C acknowledge error" NL; + strings_en[S_ComErr]="Communication error" NL; + strings_en[S_InsErr]="Unknown instruction" NL; + strings_en[S_SyncErr]="Synchronization error" NL; + strings_en[S_HVregErr]="HV regulator error" NL; + // + strings_en[S_Log1]="i=%d(0x%X), k=%d(0x%X) NumberOfBytesRead=%d" NL; + strings_en[S_Log2]="i=%d, k=%d, errors=%d, NumberOfBytesRead=%d" NL NL; + strings_en[S_Log3]="i=%d, k2=%d NumberOfBytesRead=%d" NL; + strings_en[S_Log4]="Config area. errors=%d NumberOfBytesRead=%d" NL; + strings_en[S_Log5]="dim=%d(0x%X), dimx=%d(0x%X), dimx/wbuf=%d " NL NL; + strings_en[S_Log6]="i=%d(0x%X), NumberOfBytesRead=%d" NL NL; + strings_en[S_Log7]="i=%d(0x%X), k=%d(0x%X)" NL; + strings_en[S_Log8]="i=%d(0x%X), k=%d(0x%X), errors=%d" NL; + strings_en[S_Log9]="Config area. errors=%d" NL; + // + strings_en[S_comTimeout]="Communication timeout" NL; + strings_en[S_EraseTimeout]="Timeout during erase" NL; + strings_en[S_ConfigTimeout]="Timeout reading CONFIG" NL; + strings_en[S_ConfigTimeout2]="Timeout reading config area" NL; + strings_en[S_CodeTimeout]="Timeout reading address %02X (%d)" NL; + strings_en[S_CodeTimeout2]="Timeout reading address %04X (%d)" NL; + strings_en[S_OsccalTimeout]="Timeout reading osccal" NL; + strings_en[S_EETimeout]="Timeout reading EEPROM, address %02X (%d)" NL; + strings_en[S_ConfigWTimeout]="Timeout verifying config" NL; + strings_en[S_CodeWTimeout]="Timeout writing address %02X (%d)" NL; + strings_en[S_ConfigWTimeout2]="Timeout writing config area" NL; + strings_en[S_EEWTimeout]="Timeout writing EEPROM, address %03X (%d)" NL; + strings_en[S_IDWTimeout]="Timeout writing ID" NL; + strings_en[S_ConfigNWTimeout]="Timeout writing CONFIG%d" NL; + strings_en[S_CodeVTimeout]="Timeout verifying address %04X (%d)" NL; + strings_en[S_ConfigVTimeout]="Timeout verifying config area" NL; + strings_en[S_ProgModeTimeout]="Timeout entering program mode" NL; + strings_en[S_ProgModeXTimeout]="Timeout exiting program mode" NL; + strings_en[S_LogTimeout]="Timeout" NL; + // + strings_en[S_CodeMem]= NL "Code memory:" NL; + strings_en[S_EEMem]= NL "EEPROM memory:" NL; + strings_en[S_IDMem]= NL "ID:" NL; + strings_en[S_ConfigMem]= NL "CONFIG:" NL; + strings_en[S_ConfigResMem]= NL "Configuration and reserved memory:" NL; + strings_en[S_CodeMem2]= NL "Code memory:" NL; + strings_en[S_ExeMem]= NL "Executive memory:" NL; + // + strings_en[S_LPOsc]="LP oscillator" NL; + strings_en[S_XTOsc]="XT oscillator" NL; + strings_en[S_IntOsc]="Internal osc." NL; + strings_en[S_RCOsc]="RC oscillator" NL; + strings_en[S_WDTON]="WDT ON" NL; + strings_en[S_WDTOFF]="WDT OFF" NL; + strings_en[S_CPOFF]="Code protection OFF" NL; + strings_en[S_CPON]="Code protection ON" NL; + strings_en[S_MCLRON]="Master clear ON" NL; + strings_en[S_MCLROFF]="Master clear OFF" NL; + strings_en[S_ChipID]="ID%d: 0x%03X ID%d: 0x%03X" NL; + strings_en[S_ChipID2]="ID%d: 0x%02X ID%d: 0x%02X" NL; + strings_en[S_BKOsccal]="Backup OSCCAL: 0x%03X" NL; + strings_en[S_Osccal]="OSCCAL: 0x%03X" NL; + strings_en[S_DevID]="DevID: 0x%04X" NL; + strings_en[S_DevID2]="DevID: 0x%02X%02X" NL; + strings_en[S_DevREV]="DevREV: 0x%04X" NL; + strings_en[S_ConfigWord]="Configuration word: 0x%03X" NL; + strings_en[S_Config2Cal1]="Configuration word2 or calibration word 1: 0x%03X" NL; + strings_en[S_ConfigWord2]="Configuration word2: 0x%04X" NL; + strings_en[S_ConfigWordX]="Configuration word %d: 0x%04X" NL; + strings_en[S_ConfigWordH]="CONFIG%dH: 0x%02X\t"; + strings_en[S_ConfigWordL]="CONFIG%dL: 0x%02X" NL; + strings_en[S_CalibWord1]="Calibration word1: 0x%04X" NL; + strings_en[S_Calib1_2]="Calibration word 1 or 2: 0x%04X" NL; + strings_en[S_CalibWord2]="Calibration word2: 0x%04X" NL; + strings_en[S_CalibWordX]="Calibration word %d: 0x%04X" NL; + strings_en[S_Protected]="protected device"; + // + strings_en[S_CodeLim]="Code size exceeds limits" NL; + strings_en[S_EELim]="Eeprom size exceeds limits" NL; + strings_en[S_ConfigLim]="Config area size exceeds limits" NL; + strings_en[S_WbufLim]="Write buffer size exceeds limits" NL; + strings_en[S_MaxRetry]="Max retries in writing: %d" NL; + // + strings_en[S_NoCode]="Data area is empty" NL; + strings_en[S_NoCode2]="Nothing to write" NL; + strings_en[S_NoCalibW]="Can't find calibration data" NL; + strings_en[S_NoEEMem]="Can't find EEPROM data" NL; + strings_en[S_NoConfigW]="Impossibile leggere la config word" NL; + strings_en[S_NoConfigW2]="Can't find CONFIG location (0xFFF)" NL; + strings_en[S_NoConfigW3]="Can't find CONFIG location (0x2007)" NL "End" NL; + strings_en[S_NoConfigW4]="Can't find CONFIG location (0x2008)" NL "End" NL; + strings_en[S_NoConfigW5]="Can't find CONFIG location (0x8007-0x8008)" NL "End" NL; + strings_en[S_NoConfigW6]="Can't find CONFIG location (0x8007-0x800B)" NL "End" NL; + strings_en[S_Empty]="(empty)" NL; + strings_en[S_NextIns]="Next instruction"; + strings_en[S_ForceConfigW]="Forcing config words" NL; + strings_en[S_ForceConfigWx]="Forcing config word%d [0x%04X]=0x%04X" NL; + strings_en[S_WarnFlashSize]="Warning, flash size is different from the expected value" NL; + // + strings_en[I_CANCEL]="_Cancel"; + strings_en[I_OPEN]="_Open"; + strings_en[I_SAVE]="_Save"; + strings_en[I_Fopen]="Open file"; + strings_en[I_Fsave]="Save file"; + strings_en[I_DevR]="Read device"; + strings_en[I_DevW]="Write device"; + strings_en[I_Info]="Info"; + strings_en[I_Data]="Data"; + strings_en[I_Opt]="Options"; + strings_en[I_Dev]="Device"; + strings_en[I_Type]="Filter by type"; + strings_en[I_Speed]="Speed"; + strings_en[I_ReadRes]="Read reserved area"; + strings_en[I_ID_BKo_W]="Write ID and BKosccal"; + strings_en[I_EE]="Read and write EEPROM"; + strings_en[I_CalW]="Write Calib1 e 2"; + strings_en[I_OSCW]="Write OSCCal"; + strings_en[I_OSC]="OSCCal"; + strings_en[I_BKOSC]="Backup OSCCal"; + strings_en[I_OSCF]="From File"; + strings_en[I_CONN]="Reconnect"; + strings_en[I_QUIT]="Quit"; + strings_en[I_LOG]="Log activity"; + strings_en[I_CK_V33]="Skip 3.3V regulator check"; + strings_en[I_LANG]="Language"; + strings_en[I_MAXERR]="Max errors during write"; + strings_en[I_ADDR]="Address"; + strings_en[I_USBD]="Min USB delay (ms)"; + strings_en[I_I2CDATAOUT]="Data to send"; + strings_en[I_I2CDATATR]="Data transferred"; + strings_en[I_I2C_NB]="Bytes to read/write"; + strings_en[I_I2CMode]="Mode"; + strings_en[I_I2CSend]="Send"; + strings_en[I_I2CReceive]="Receive"; + strings_en[I_TestHW]="Hardware test: remove any device from programmer"; + strings_en[I_TestHWB]="Hardware test"; + strings_en[I_TestMSG]="Verify on the programmer the value of the following voltages:"; + strings_en[I_IO_Enable]="Enable IO"; + strings_en[I_IO_Commands]="Manual commands"; + strings_en[I_SPIMEM]="SPI Memory"; + strings_en[I_I2CMEM]="I2C Memory"; + strings_en[I_UWMEM]="Microwire Memory"; + strings_en[I_OWMEM]="OneWire Memory"; + strings_en[I_OWDEV]="OneWire Device"; + strings_en[I_UNIOMEM]="UNI/O Memory"; + strings_en[I_3V3REQUIRED]="3.3V adapter"; + strings_en[I_PIC_FORCECW]="Force config word"; + strings_en[I_AT_FUSE]="Write Fuse Low"; + strings_en[I_AT_FUSEH]="Write Fuse High"; + strings_en[I_AT_FUSEX]="Write Extended Fuse"; + strings_en[I_AT_LOCK]="Write Lock"; + strings_en[I_AT_FUSELF]="Write Fuse Low @3kHz"; + strings_en[I_AT_COMM]="Communicating @ %.0f kbps" NL; + strings_en[I_W_LANGFILE]="Write language file"; + strings_en[I_WAITS1]="Wait for S1 before read/write"; + strings_en[I_PRESSS1]="Press S1 to start" NL; + strings_en[S_WaitS1W]="Press S1 to program, any key to exit"; + strings_en[S_WaitS1R]="Press S1 to read, any key to exit"; + strings_en[I_ICD_ENABLE]="Enable ICD"; + strings_en[I_ICD_ADDRESS]="ICD routine address"; + strings_en[I_LOAD_COFF]="Load COFF file ..."; + strings_en[I_SHOW_PC]="Show Program Counter"; + strings_en[I_SHOW_STATUS]="Show status registers"; + strings_en[I_SHOW_BANK0]="Show memory bank 0"; + strings_en[I_SHOW_BANK1]="Show memory bank 1"; + strings_en[I_SHOW_BANK2]="Show memory bank 2"; + strings_en[I_SHOW_BANK3]="Show memory bank 3"; + strings_en[I_SHOW_EE]="show EEPROM"; + strings_en[I_STOP]="Stopped" NL; + strings_en[I_ICD_RUN]="Run/Continue"; + strings_en[I_ICD_HALT]="Halt"; + strings_en[I_ICD_STEP]="Step"; + strings_en[I_ICD_STEPOVER]="Step over"; + strings_en[I_ICD_STOP]="Stop"; + strings_en[I_ICD_REFRESH]="Refresh"; + strings_en[I_ICD_CMD]="Command line"; + strings_en[I_ICD_HELP]="Help"; + strings_en[I_ICD_SOURCE]="Source"; + strings_en[I_ICD_STATUS]="Status"; + strings_en[I_ICD_HELP_TXT]= + "ICD help" NL NL + "Double click variable name to add to watch list;" NL + "double click again to remove it." NL + "Key shortcuts:" NL + " F1 help" NL + " F5 halt" NL + " F7 step" NL + " F8 step over" NL + " F9 run" NL + "Command-line help:" NL + " variable=x set variable to x" NL + " [var addr]=x set variable at addr to x" NL + " help command help" NL + " break set breakpoint at address " NL + " freeze [on,off] freeze peripherals" NL + " h[alt] halt execution" NL + " list show code starting from " NL + " p[rint] 0x print variable at address " NL + " p[rint] print variable " NL + " p[rint] bank print registers in bank " NL + " p[rint] p print program memory at address " NL + " p[rint] ee print eeprom memory at address " NL + " p[rint] ee print all eeprom memory" NL + " r[un] run" NL + " s[tep] [n] single step [n times]" NL + " step over / ss [n] step over calls [n times]" NL + " version read debugger version" NL + " w[atch] variable add/remove watch for variable" NL + " w[atch] 0x add/remove watch at address " NL; + strings_en[I_GUI_CMD_HELP]= + "Command line options:" NL + " ?,h,help this help" NL + " command send to the programmer and exit." NL + " The message is composed of up to 64 hexadecimal bytes separated by a space;" NL + " those not specified are 0" NL + " lang load strings" NL + " langfile write all strings to file" NL; + strings_en[L_HELP]="op [options]" NL + "-BKosccal load BKosccal from file" NL + "-calib load calibration from file" NL + "-command send to the programmer and exit." NL + " The message is composed of up to 64 hexadecimal bytes separated by a space;" NL + " those not specified are 0" NL + "-cwX force config word X [1-7]" NL + "-d, device device" NL + "-ee use eeprom" NL + "-err max errors during writing" NL + "-fuse write fuse low byte (Atmel only)" NL + "-fuseh write fuse high byte (Atmel only)" NL + "-fusex write extended fuse byte (Atmel only)" NL + "-fuse3k write fuse low byte at 3 kHz (Atmel only)" NL + "-h, help help" NL + "-HWtest hardware test" NL + "-i, info informations about programmer" NL + "-i2c_r read N bytes from I2C bus" NL + "-i2c_r2 read N bytes from I2C bus (16b address)" NL + "-i2c_w write N bytes to I2C bus" NL + "-i2c_w2 write N bytes to I2C bus (16b address)" NL + "-i2cspeed set I2C speed: 0=100k,1=200k,2=500k,3=800k" NL + "-id use ID" NL + "-icd enable ICD (goto address)" NL + "-l, log [=file] save log" NL + "-lang load strings" NL + "-langfile write all strings to file" NL + "-lock write lock byte (Atmel only)" NL + "-mode SPI mode: 00,01,10,11" NL + "-nolvcheck skip 3.3V regulator check" NL + "-osccal loads osccal from file instead of using the value saved before erase" NL + "-p, path programmer path [/dev/usb/hiddev0]" NL + "-pid programmer pid [0x100]" NL + "-r, reserved read reserved area" NL + "-rep report size [64]" NL + "-s1, S1 Multiple programming triggered by S1" NL + "-s, save save Ihex file" NL + "-se, saveEE save EEPROM on Ihex file (ATxxxx only)" NL + "-spi_r read N bytes from SPI bus" NL + "-spi_w write N bytes to SPI bus" NL + "-spispeed set SPI speed: 0=100k,1=200k,2=500k,3=800k" NL + "-support supported devices" NL + "-use_BKosccal copy BKosccal to osccal" NL + "-v, version version" NL + "-vid programmer vid [0x4D8]" NL + "-w, write write Ihex file" NL + "-we, writeEE write EEPROM on Ihex file (ATxxxx only)" NL + "" NL + "ex. op -d 12F683 -s test.hex" NL; + strings_en[L_OPTERR]="Error in command-line options" NL; + strings_en[L_INFO1]="vid 0x%04hx pid 0x%04hx version 0x%04hx "; + strings_en[L_INFO2]= NL "bus: %d devnum: %d ifnum: %d" NL; + strings_en[L_UNKNOWN]="Unknown"; + strings_en[L_NAME]="The device on %s says its name is %s" NL; + strings_en[L_DEV_RO]="Devices supported for reading only:"; + strings_en[L_DEV_RW]="Devices supported for reading and writing:"; +} diff --git a/strings.h b/strings.h new file mode 100644 index 0000000..7c3c58a --- /dev/null +++ b/strings.h @@ -0,0 +1,282 @@ +// Strings.h v0.12.0 + +enum S { + S_NL, + S_noprog, + S_prog, + S_progDev, + S_DevPermission, + S_nodev_r, + S_nodev_w, + S_nodev, + S_DevMismatch, + S_noV33reg, + S_progver, + S_progid, + S_FWver2old, + S_lowUsbV, + S_HiVPP, + S_LowVPP, + S_reg, + S_dev_det, + S_file, + S_file2, + S_fileEEP, + S_noDLL, + S_openEEfile, + S_saveEEfile, + S_IhexShort, + S_IhexChecksum, + S_InvHandle, + S_LogFile, + S_FileSaved, + S_HVICSP, + S_StartRead, + S_Read, + S_CodeReading1, + S_CodeReading, + S_CodeReading2, + S_ReadEnd, + S_ReadID_CONFIG, + S_Read_CONFIG_A, + S_Read_EXE_A, + S_ReadEE, + S_StartErase, + S_Writing, + S_StartCodeProg, + S_CodeWriting, + S_CodeWriting2, + S_IDW, + S_ConfigW, + S_ConfigAreaW, + S_EEAreaW, + S_FuseAreaW, + S_CodeV, + S_CodeV2, + S_IDV, + S_ConfigV, + S_EEV, + S_IntW, + S_TotErr, + S_ComplErr, + S_Compl, + S_Ready, + S_End, + S_EndErr, + S_ProtErase, + S_Inohex, + S_ReadErr, + S_ReadCodeErr, + S_ReadCodeErr2, + S_ReadEEErr, + S_ConfigErr, + S_ReadConfigErr, + S_ErrOsccal, + S_CodeWError, + S_CodeWError2, + S_CodeWError3, + S_CodeWError4, + S_ConfigWErr, + S_ConfigWErr2, + S_ConfigWErr3, + S_WErr1, + S_WErr2, + S_IDErr, + S_ICDErr, + S_Calib1Err, + S_Calib2Err, + S_CodeVError, + S_CodeVError2, + S_CodeVError3, + S_ErrSing, + S_ErrPlur, + S_MaxErr, + S_I2CInitErr, + S_I2CAckErr, + S_ComErr, + S_InsErr, + S_SyncErr, + S_HVregErr, + S_Log1, + S_Log2, + S_Log3, + S_Log4, + S_Log5, + S_Log6, + S_Log7, + S_Log8, + S_Log9, + S_comTimeout, + S_EraseTimeout, + S_ConfigTimeout, + S_ConfigTimeout2, + S_CodeTimeout, + S_CodeTimeout2, + S_OsccalTimeout, + S_EETimeout, + S_ConfigWTimeout, + S_CodeWTimeout, + S_ConfigWTimeout2, + S_EEWTimeout, + S_IDWTimeout, + S_ConfigNWTimeout, + S_CodeVTimeout, + S_ConfigVTimeout, + S_ProgModeTimeout, + S_ProgModeXTimeout, + S_LogTimeout, + S_CodeMem, + S_EEMem, + S_IDMem, + S_ConfigMem, + S_ConfigResMem, + S_CodeMem2, + S_ExeMem, + S_LPOsc, + S_XTOsc, + S_IntOsc, + S_RCOsc, + S_WDTON, + S_WDTOFF, + S_CPOFF, + S_CPON, + S_MCLRON, + S_MCLROFF, + S_ChipID, + S_ChipID2, + S_BKOsccal, + S_Osccal, + S_DevID, + S_DevID2, + S_DevREV, + S_ConfigWord, + S_ConfigWord2, + S_ConfigWordX, + S_Config2Cal1, + S_ConfigWordH, + S_ConfigWordL, + S_CalibWord1, + S_Calib1_2, + S_CalibWord2, + S_CalibWordX, + S_Protected, + S_CodeLim, + S_EELim, + S_ConfigLim, + S_WbufLim, + S_MaxRetry, + S_NoCode, + S_NoCode2, + S_NoCalibW, + S_NoEEMem, + S_NoConfigW, + S_NoConfigW2, + S_NoConfigW3, + S_NoConfigW4, + S_NoConfigW5, + S_NoConfigW6, + S_Empty, + S_NextIns, + S_ForceConfigW, + S_ForceConfigWx, + S_WaitS1W, + S_WaitS1R, + S_WarnFlashSize, +// GUI strings + I_CANCEL, + I_OPEN, + I_SAVE, + I_Fopen, + I_Fsave, + I_DevR, + I_DevW, + I_Info, + I_Data, + I_Opt, + I_Dev, + I_Type, + I_Speed, + I_ReadRes, + I_ID_BKo_W, + I_EE, + I_CalW, + I_OSCW, + I_OSC, + I_BKOSC, + I_OSCF, + I_CONN, + I_QUIT, + I_LOG, + I_CK_V33, + I_LANG, + I_MAXERR, + I_ADDR, + I_USBD, + I_I2CDATAOUT, + I_I2CDATATR, + I_I2C_NB, + I_I2CMode, + I_I2CSend, + I_I2CReceive, + I_TestHW, + I_TestHWB, + I_TestMSG, + I_IO_Enable, + I_IO_Commands, + I_SPIMEM, + I_I2CMEM, + I_UWMEM, + I_OWMEM, + I_OWDEV, + I_UNIOMEM, + I_3V3REQUIRED, + I_PIC_FORCECW, + I_AT_FUSE, + I_AT_FUSEH, + I_AT_FUSEX, + I_AT_LOCK, + I_AT_FUSELF, + I_AT_COMM, + I_W_LANGFILE, + I_WAITS1, + I_PRESSS1, + I_ICD_ENABLE, + I_ICD_ADDRESS, + I_LOAD_COFF, + I_SHOW_PC, + I_SHOW_STATUS, + I_SHOW_BANK0, + I_SHOW_BANK1, + I_SHOW_BANK2, + I_SHOW_BANK3, + I_SHOW_EE, + I_STOP, + I_ICD_RUN, + I_ICD_HALT, + I_ICD_STEP, + I_ICD_STEPOVER, + I_ICD_STOP, + I_ICD_REFRESH, + I_ICD_CMD, + I_ICD_HELP, + I_ICD_SOURCE, + I_ICD_STATUS, + I_ICD_HELP_TXT, + I_GUI_CMD_HELP, +// command-line strings + L_HELP, + L_OPTERR, + L_INFO1, + L_INFO2, + L_UNKNOWN, + L_NAME, + L_DEV_RO, + L_DEV_RW, + DIM}; + +extern char *strings_it[DIM]; +extern char *strings_en[DIM]; +extern char *STR_ID[DIM]; +void strinit(); +int strfind(const char* langid,const char* langfile); +void GenerateLangFile(const char* langid,const char* langfile); diff --git a/style.css b/style.css new file mode 100644 index 0000000..1e3edad --- /dev/null +++ b/style.css @@ -0,0 +1,3 @@ +.mono { + font: 14px monospace; +} \ No newline at end of file diff --git a/sys.png b/sys.png new file mode 100644 index 0000000..b518787 Binary files /dev/null and b/sys.png differ diff --git a/write.png b/write.png new file mode 100644 index 0000000..6ed5776 Binary files /dev/null and b/write.png differ -- cgit v1.2.3-54-g00ecf