unknown version
This commit is contained in:
parent
c4b7c46a38
commit
a581ab3e4f
132
isp_down.c
132
isp_down.c
@ -3,34 +3,35 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
//#define BAUDRATE B115200
|
||||
//#define BAUDRATE B57600
|
||||
#define BAUDRATE B38400
|
||||
|
||||
struct termios oldtio, newtio;
|
||||
int ser;
|
||||
unsigned char sign[6][3]=
|
||||
{0x00,0x90,0x1E, /* AT90S1200 tested 05.04.2001 */
|
||||
0x01,0x91,0x1E, /* AT90S2313 tested 21.02.2001 */
|
||||
0x02,0x91,0x1E, /* AT90S2323 */
|
||||
0x03,0x91,0x1E, /* AT90S2343 */
|
||||
0x01,0x92,0x1E, /* AT90S4414 */
|
||||
0x01,0x93,0x1E}; /* AT90S8515 tested 12.11.2001 */
|
||||
|
||||
|
||||
char sign[6][3]=
|
||||
{0x1E,0x90,0x01, /* AT90S1200 */
|
||||
0x1E,0x91,0x01, /* AT90S2313 */
|
||||
0x1E,0x91,0x02, /* AT90S2323 */
|
||||
0x1E,0x91,0x03, /* AT90S2343 */
|
||||
0x1E,0x92,0x01, /* AT90S4414 */
|
||||
0x1E,0x93,0x01}; /* AT90S8515 */
|
||||
|
||||
int mem_size[6][2]=
|
||||
{0x1FF,0x3F, /* AT90S1200 */
|
||||
0x3FF,0x7F, /* AT90S2313 */
|
||||
unsigned int mem_size[6][2]=
|
||||
{0x1FF,0x3F, /* AT90S1200 tested 05.04.2001 */
|
||||
0x3FF,0x7F, /* AT90S2313 tested 21.02.2001 */
|
||||
0x3FF,0x7F, /* AT90S2323 */
|
||||
0x3FF,0x7F, /* AT90S2343 */
|
||||
0x7FF,0xFF, /* AT90S4414 */
|
||||
0xFFF,0x1FF}; /* AT90S8515 */
|
||||
0xFFF,0x1FF}; /* AT90S8515 tested 12.11.2001*/
|
||||
|
||||
struct termios oldtio, newtio;
|
||||
int ser;
|
||||
|
||||
void end_prg(char level);
|
||||
void show_usage();
|
||||
|
||||
main(int argc,char *argv[])
|
||||
{
|
||||
int avr_device=5, verify=0, flash=0, eeprom=0;
|
||||
int avr_device=5, verify=0, flash=0, eeprom=0, reset=0;
|
||||
char arg, ser_device[64]="/dev/ttyS0", flash_file[64]="", eeprom_file[64]="";
|
||||
|
||||
unsigned char inbuf[8], outbuf[8], databuf[8];
|
||||
@ -98,6 +99,10 @@ main(int argc,char *argv[])
|
||||
else if (!strcmp (argv[arg], "-verify"))
|
||||
verify=1;
|
||||
|
||||
/* check reset */
|
||||
else if (!strcmp (argv[arg], "-reset"))
|
||||
reset=1;
|
||||
|
||||
/* get flash-file */
|
||||
else if (flash == 1)
|
||||
{
|
||||
@ -159,6 +164,7 @@ main(int argc,char *argv[])
|
||||
/* detecting avr-isp adapter */
|
||||
printf(" Detecting ISP ----------> ");
|
||||
write (ser,"S",1);
|
||||
usleep(10000);
|
||||
read (ser,inbuf,7);
|
||||
inbuf[7]=0x00;
|
||||
if (!strcmp(inbuf, "AVR ISP"))
|
||||
@ -177,7 +183,7 @@ main(int argc,char *argv[])
|
||||
break;
|
||||
|
||||
case 1: printf(" Set device AT90S2313 ---> ");
|
||||
outbuf[1]=0x00;
|
||||
outbuf[1]=0x12;
|
||||
break;
|
||||
|
||||
case 2: printf(" Set device AT90S2323 ---> ");
|
||||
@ -198,6 +204,7 @@ main(int argc,char *argv[])
|
||||
}
|
||||
outbuf[0]=0x54;
|
||||
write (ser,outbuf,2);
|
||||
usleep(10000);
|
||||
read (ser,inbuf,1);
|
||||
if (inbuf[0]==0x0D)
|
||||
printf("OK\n");
|
||||
@ -207,83 +214,98 @@ main(int argc,char *argv[])
|
||||
end_prg(1);
|
||||
}
|
||||
|
||||
/* switch on red LED */
|
||||
write (ser,"x",1);
|
||||
usleep(10000);
|
||||
read (ser,inbuf,1);
|
||||
|
||||
/* enter programming mode */
|
||||
printf(" Set Prg Mode -----------> ");
|
||||
write (ser,"P",1);
|
||||
usleep(10000);
|
||||
read (ser,inbuf,1);
|
||||
if (inbuf[0]==0x0D)
|
||||
printf("OK\n");
|
||||
else
|
||||
{
|
||||
printf("Error: No Response\n");
|
||||
printf("ERROR: No response\n");
|
||||
end_prg(1);
|
||||
}
|
||||
|
||||
/* switch on red LED */
|
||||
write (ser,"x",1);
|
||||
read (ser,inbuf,1);
|
||||
|
||||
/* check the signature */
|
||||
printf(" Checking Signature -----> ");
|
||||
write (ser,"s",1);
|
||||
usleep(10000);
|
||||
read (ser,inbuf,3);
|
||||
if (sign[avr_device][0] == inbuf[0] && sign[avr_device][1] == inbuf[1] && sign[avr_device][2] == inbuf[2])
|
||||
printf ("OK\n");
|
||||
else
|
||||
{
|
||||
printf("Wrong Signature ");
|
||||
printf ("%2.2X %2.2X %2.2X\n",inbuf[0], inbuf[1], inbuf[2]);
|
||||
printf("ERROR: Wrong signature: ");
|
||||
printf ("%2.2X %2.2X %2.2X <-> ",inbuf[0], inbuf[1], inbuf[2]);
|
||||
printf ("%2.2X %2.2X %2.2X\n",sign[avr_device][0], sign[avr_device][1], sign[avr_device][2]);
|
||||
end_prg(2);
|
||||
}
|
||||
|
||||
|
||||
if (!reset)
|
||||
{
|
||||
/* clear the chip */
|
||||
printf(" Erase FLASH & EEPROM ---> ");
|
||||
write (ser,"e",1);
|
||||
usleep(10000);
|
||||
read (ser,inbuf,1);
|
||||
if (inbuf[0]==0x0D)
|
||||
printf("OK\n");
|
||||
else
|
||||
{
|
||||
printf("Error: No Response\n");
|
||||
printf("ERROR: No response\n");
|
||||
end_prg(2);
|
||||
}
|
||||
}
|
||||
|
||||
/* reset the chip after clear */
|
||||
printf(" Reseting AVR-Device ----> ");
|
||||
write (ser,"L",1);
|
||||
usleep(10000);
|
||||
read (ser,inbuf,1);
|
||||
if (inbuf[0]!=0x0D)
|
||||
{
|
||||
printf("Error: No Response\n");
|
||||
write (ser,"y",1);
|
||||
read (ser,inbuf,1);
|
||||
printf("ERROR: No response\n");
|
||||
end_prg(2);
|
||||
}
|
||||
|
||||
if (reset)
|
||||
{
|
||||
printf("OK\n");
|
||||
end_prg(2);
|
||||
}
|
||||
|
||||
/* enter programming mode */
|
||||
write (ser,"P",1);
|
||||
usleep(10000);
|
||||
read (ser,inbuf,1);
|
||||
if (inbuf[0]==0x0D)
|
||||
printf("OK\n");
|
||||
else
|
||||
{
|
||||
printf("Error: No Response\n");
|
||||
write (ser,"y",1);
|
||||
read (ser,inbuf,1);
|
||||
printf("ERROR: No response\n");
|
||||
end_prg(2);
|
||||
}
|
||||
|
||||
|
||||
if (flash == 1)
|
||||
/* writing flash */
|
||||
if (flash == 2)
|
||||
{
|
||||
printf(" Writing FLASH DATA -----> ");
|
||||
fdat = open(flash_file, O_RDWR);
|
||||
if (fdat <0)
|
||||
{
|
||||
printf("<%s> not found\n", flash_file);
|
||||
printf("ERROR: <%s> not found\n", flash_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
t=0;
|
||||
while (read (fdat,databuf,2) == 2 && t < 4096)
|
||||
while (read (fdat,databuf,2) == 2 && t < (mem_size[avr_device][0]/2))
|
||||
{
|
||||
outbuf[0]=0x41;
|
||||
outbuf[1]=(unsigned char)(t>>8) & 0xFF;
|
||||
@ -303,21 +325,23 @@ main(int argc,char *argv[])
|
||||
t++;
|
||||
}
|
||||
close (fdat);
|
||||
printf("%4.4Xh Bytes\n",t*2);
|
||||
printf("%4.4Xh bytes\n",t*2);
|
||||
}
|
||||
}
|
||||
if (verify == 1 && flash == 1)
|
||||
|
||||
/* verify flash */
|
||||
if (verify == 1 && flash == 2)
|
||||
{
|
||||
printf(" Verify FLASH DATA ------> ");
|
||||
fdat = open(flash_file, O_RDWR);
|
||||
if (fdat <0)
|
||||
{
|
||||
printf("<%s> not found\n", flash_file);
|
||||
printf("ERROR: <%s> not found\n", flash_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
t=0;
|
||||
while (read (fdat,databuf,2) == 2 && t < 4096)
|
||||
while (read (fdat,databuf,2) == 2 && t < (mem_size[avr_device][0]/2))
|
||||
{
|
||||
outbuf[0]=0x41;
|
||||
outbuf[1]=(unsigned char)(t>>8) & 0xFF;
|
||||
@ -332,21 +356,23 @@ main(int argc,char *argv[])
|
||||
t++;
|
||||
}
|
||||
close (fdat);
|
||||
printf("%4.4Xh Bytes\n",t*2);
|
||||
printf("%4.4Xh bytes\n",t*2);
|
||||
}
|
||||
}
|
||||
if (eeprom == 1)
|
||||
|
||||
/* writing eeprom */
|
||||
if (eeprom == 2)
|
||||
{
|
||||
printf(" Writing EEPROM DATA ----> ");
|
||||
eedat = open(eeprom_file, O_RDWR);
|
||||
if (eedat <0)
|
||||
{
|
||||
printf("<%s> not found\n", eeprom_file);
|
||||
printf("ERROR: <%s> not found\n", eeprom_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
t=0;
|
||||
while (read (eedat,databuf,1) == 1 && t < 512)
|
||||
while (read (eedat,databuf,1) == 1 && t < (mem_size[avr_device][1]/2))
|
||||
{
|
||||
outbuf[0]=0x41;
|
||||
outbuf[1]=(unsigned char)(t>>8) & 0xFF;
|
||||
@ -361,21 +387,23 @@ main(int argc,char *argv[])
|
||||
t++;
|
||||
}
|
||||
close (eedat);
|
||||
printf("%4.4Xh Bytes\n",t);
|
||||
printf("%4.4Xh bytes\n",t);
|
||||
}
|
||||
}
|
||||
if (verify == 1 && eeprom == 1)
|
||||
|
||||
/* verify eeprom */
|
||||
if (verify == 1 && eeprom == 2)
|
||||
{
|
||||
printf(" Verify EEPROM DATA -----> ");
|
||||
eedat = open(eeprom_file, O_RDWR);
|
||||
if (eedat <0)
|
||||
{
|
||||
printf("<%s> not found\n", eeprom_file);
|
||||
printf("ERROR: <%s> not found\n", eeprom_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
t=0;
|
||||
while (read (eedat,databuf,1) == 1 && t < 512)
|
||||
while (read (eedat,databuf,1) == 1 && t < (mem_size[avr_device][1]/2))
|
||||
{
|
||||
outbuf[0]=0x41;
|
||||
outbuf[1]=(unsigned char)(t>>8) & 0xFF;
|
||||
@ -394,6 +422,8 @@ main(int argc,char *argv[])
|
||||
printf("%4.4Xh Bytes\n",t);
|
||||
}
|
||||
}
|
||||
|
||||
/* release chip */
|
||||
printf(" Leave Prg Mode ---------> ");
|
||||
write (ser,"L",1);
|
||||
read (ser,inbuf,1);
|
||||
@ -401,12 +431,9 @@ main(int argc,char *argv[])
|
||||
printf("OK\n");
|
||||
else
|
||||
{
|
||||
printf("Error: No Response\n");
|
||||
write (ser,"y",1);
|
||||
read (ser,inbuf,1);
|
||||
printf("ERROR: No response\n");
|
||||
end_prg(2);
|
||||
}
|
||||
|
||||
end_prg(2);
|
||||
}
|
||||
|
||||
@ -422,7 +449,7 @@ void end_prg(char level)
|
||||
|
||||
case 0: printf("\n***************************************\n\n");
|
||||
}
|
||||
exit (-1);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
void show_usage()
|
||||
@ -441,6 +468,7 @@ void show_usage()
|
||||
printf(" -flash Write (1st) file to FLASH\n");
|
||||
printf(" -eeprom Write (2nd) file to EEPROM\n");
|
||||
printf(" -verify Verify writing\n");
|
||||
printf(" -reset Only resets AVR\n");
|
||||
end_prg(0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user