29 Commits

Author SHA1 Message Date
Joerg Wunsch
46446f85d8 This commit was manufactured by cvs2svn to create tag
'release_4_1_0'.

git-svn-id: svn://svn.savannah.nongnu.org/avrdude/tags/release_4_1_0@315 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-04-18 04:41:46 +00:00
Theodore A. Roth
56823c7aa5 * configure.ac: Set version to 4.1.0.
* doc/avrdude.texi: Add note about avr910 programmer type.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@314 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-04-18 04:41:45 +00:00
Eric Weddington
d6e5083b97 * NEWS: Replace TBD with new release version.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@313 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-04-17 23:19:58 +00:00
Brian S. Dean
7d5184da75 Change deprecated 'devicecode' to 'stk500_devcode' and remove
extraneous carraige returns.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@312 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-04-17 22:50:41 +00:00
Eric Weddington
62f2e06711 Change name of pony programmer to pony-stk200 to better describe the hw.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@311 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-04-17 17:34:01 +00:00
Eric Weddington
bd11e34965 Corrected submitter's name in the ChangeLog.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@310 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-04-17 16:24:54 +00:00
Eric Weddington
e358fd203a Add ATtiny26 support submitted by Artur Lipowski <LAL@pro.onet.pl>.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@309 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-04-16 23:00:29 +00:00
Eric Weddington
5fa160a365 Add ATmega8535 support submitted by Alexander <apeter@gmx.de>
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@308 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-04-16 22:44:55 +00:00
Theodore A. Roth
8513530063 * avr910.c: Reading a 16 bit word in paged load needs to swap the
bytes since the 'R' command returns MSB first and the internal buffer
stores LSB first.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@307 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-04-09 20:37:28 +00:00
Theodore A. Roth
6c3cb9fbb2 * stk500.c: Don't print out read/write byte progress unless the verbose
option is given.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@306 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-04-07 17:18:51 +00:00
Theodore A. Roth
d2317147db * avr910.c: Re-add the avr910 byte read/write methods which were
removed in my previous patch. Terminal mode read/writes are broken
without those methods. D'oh!


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@305 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-04-06 07:10:44 +00:00
Theodore A. Roth
20bf291163 * avr910.c: Refactor to allow probing for auto addr increment. If auto
incr supported by programmer hw, don't send addr for every byte.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@304 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-04-06 00:47:16 +00:00
Eric Weddington
a58f2c8d66 * confwin.c: Fix bug that allows garbage for non-existent user config filename on Windows.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@303 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-04-03 16:46:47 +00:00
Brian S. Dean
4996510f4c Add the ATmega32 part. This part definition was contributed by:
Daniel Williamson <dannyw@maconmgt.co.uk>
and
	Ruwan Jayanetti <rjayanetti@sri.crossvue.com>

The resulting part definition used was actually somewhat of a merge of
the two submitted definitions.

Thanks for the contributions!


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@302 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-03-29 15:02:07 +00:00
Theodore A. Roth
c3412f1f57 * NEWS: Add note about avr910 support.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@301 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-03-24 23:37:09 +00:00
Eric Weddington
dc21830241 Add ChangeLog and NEWS entry for new Bascom programmer.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@300 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-03-24 23:02:11 +00:00
Theodore A. Roth
191a5a4430 * avr.c (avr_write): Add call to pgm->write_setup() before the write loop.
* avr910.c: Change all show_func_info() calls to no_show_func_info().
Add read/write to/from flash/eeprom memory functionality.
* pgm.c: Initialize pgm->write_setup.
* pgm.h: Add write_setup field to PROGRAMMER structure.
* ser_posix.c: Remove unneeded cast in verbosity code.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@299 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-03-24 07:09:16 +00:00
Theodore A. Roth
ee87b080c3 * ser_posix.c: Limit verbose output to 2 chars.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@298 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-03-24 02:37:33 +00:00
Theodore A. Roth
5bd3b081eb * ser_posix.c: Add verbose level > 3 output for send and recv functions.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@297 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-03-24 01:57:31 +00:00
Theodore A. Roth
6fba5faaf5 * avr.c: Add avr_read_byte_default().
Have avr_read_byte() call pgm->read_byte() or avr_read_byte_default().
Add avr_write_byte_default().
Have avr_write_byte() call pgm->write_byte or avr_write_byte_default().
* pgm.c: Initialize pgm->write_byte and pgm->read_byte.
* pgm.h: Add write_byte and read_byte fields to struct programmer_t.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@296 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-03-23 23:22:50 +00:00
Theodore A. Roth
5d6dace3c3 * avrdude.conf.in: Fix typo for devicecode deprecation comment.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@295 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-03-18 05:49:29 +00:00
Eric Weddington
200283a902 Add Bascom programmer. Submitted by Larry Barello <larryba@barrello.net>
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@294 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-03-17 17:57:55 +00:00
Theodore A. Roth
ea977f6062 * avr.c (avr_read): Use pgm->read_sig_bytes to read signature bytes if
available.
* avr910.c (avr910_vfy_cmd_sent): New function.
(avr910_chip_erase): Add support for chip erase.
(avr910_enter_prog_mode): New function.
(avr910_leave_prog_mode): New function.
(avr910_initialize): Add code to select device type and enter prog mode.
(avr910_close): Leave programming mode before closing serial port.
(avr910_read_sig_bytes): New function.
(avr910_initpgm): Add avr910_read_sig_bytes method to pgm initializer.
* avrdude.conf.in: Add note about deprecating devicecode.
Change all occurences of devicecode to stk500_devcode.
Add avr910_devcode to a few parts for testing.
* avrpart.h (struct avrpart): Change devicecode field to stk500_devcode.
(struct avrpart): Add avr910_devcode field.
* config_gram.y: Add K_STK500_DEVCODE and K_AVR910_DEVCODE tokens.
Generate an error if devicecode is found in the config file.
Handle parsing of avr910_devcode and stk500_devcode.
* lexer.l: Handle parsing of avr910_devcode and stk500_devcode.
* pgm.c: Initialize pgm->read_sig_bytes field.
* pgm.h: Add pgm->read_sig_bytes field.
* stk500.c: Use stk500_devcode instead of devicecode.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@293 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-03-17 06:20:02 +00:00
Theodore A. Roth
a13d87de00 * avrdude.conf.in: Add avr910 and pavr programmers.
* config_gram.y: Add parsing of avr910 programmer.
* lexer.l: Add avr910 token.
* avr910.c: [this is still work in progress]
Add some debug output.
Add probe for programmer presense.
* main.c: Set port to default_serial if programmer type is avr910.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@292 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-03-16 18:19:37 +00:00
Theodore A. Roth
5a74a905b4 * ser_posix.c, ser_win32.c, serial.h:
Change baud from int to long to avoid a 16-bit int overflow.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@291 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-03-13 19:25:27 +00:00
Brian S. Dean
eb551b1d0d Headers needed on FreeBSD.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@290 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-03-13 04:44:46 +00:00
Theodore A. Roth
f0c2dcf820 * Makefile.am (avrdude_SOURCES): Add avr910.[ch], serial.h and
ser_posix.c files.
* avr910.c: New file (stubs for avr910 serial programmer).
* avr910.h: New file.
* ser_posix.c: New file.
* ser_win32.c: New file (just stubs for now).
* serial.h: New file.
* stk500.c: Move all the code for accessing the posix serial ports
into ser_posix. This will make a native win32 port easier and allows
the avr910 programmer to share the serial code.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@289 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-03-13 03:52:19 +00:00
Brian S. Dean
8da3ff76e4 Add Ted, who forgot to add himself.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@288 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-03-13 03:16:53 +00:00
Theodore A. Roth
8f15af9679 * configure.ac (AC_INIT): Set version to 4.0.0cvs since we're done
with 4.0.0 release.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@287 81a1dc3b-b13d-400b-aceb-764788c761c2
2003-03-12 21:37:32 +00:00
21 changed files with 1846 additions and 257 deletions

View File

@@ -6,4 +6,5 @@ Contributors:
Joerg Wunsch <j@uriah.heep.sax.de>
Eric Weddington <eric@umginc.net>
Theodore A. Roth <troth@openavr.org>

View File

@@ -1,3 +1,158 @@
2003-04-17 Theodore A. Roth <troth@openavr.org>
* configure.ac: Set version to 4.1.0.
* doc/avrdude.texi: Add note about avr910 programmer type.
2003-04-17 Eric B. Weddington <eric@umginc.net>
* NEWS: Replace TBD with new release version.
2003-04-17 Eric B. Weddington <eric@umginc.net>
* avrdude.conf.in: Change name of pony programmer to pony-stk200
to better describe the hardware (PonyProg is software that works
with various hardware).
2003-04-16 Eric B. Weddington <eric@umginc.net>
* avrdude.conf.in: Add support for ATtiny26
Submitted by Artur Lipowski <LAL@pro.onet.pl>
* NEWS: List new devices supported: ATtiny26
2003-04-16 Eric B. Weddington <eric@umginc.net>
* avrdude.conf.in: Add support for ATmega8535
Submitted by Alexander Peter <apeter@gmx.de>
* NEWS: List new devices supported: ATmega8535
2003-04-09 Theodore A. Roth <troth@openavr.org>
* avr910.c: Reading a 16 bit word in paged load needs to swap the
bytes since the 'R' command returns MSB first and the internal buffer
stores LSB first.
2003-04-07 Theodore A. Roth <troth@openavr.org>
* stk500.c: Don't print out read/write byte progress unless the verbose
option is given.
2003-04-05 Theodore A. Roth <troth@openavr.org>
* avr910.c: Re-add the avr910 byte read/write methods which were
removed in my previous patch. Terminal mode read/writes are broken
without those methods. D'oh!
2003-04-05 Theodore A. Roth <troth@openavr.org>
* avr910.c: Refactor to allow probing for auto addr increment. If auto
incr supported by programmer hw, don't send addr for every byte.
2003-04-03 Eric B. Weddington <eric@umginc.net>
* confwin.c: Fix bug that allows garbage for non-existent user
config filename on Windows.
2003-03-24 Theodore A. Roth <troth@openavr.org>
* NEWS: Add note about avr910 support.
2003-03-23 Theodore A. Roth <troth@openavr.org>
* avr.c (avr_write): Add call to pgm->write_setup() before the write
loop.
* avr910.c: Change all show_func_info() calls to no_show_func_info().
Add read/write to/from flash/eeprom memory functionality.
* pgm.c: Initialize pgm->write_setup.
* pgm.h: Add write_setup field to PROGRAMMER structure.
* ser_posix.c: Remove unneeded cast in verbosity code.
2003-03-23 Theodore A. Roth <troth@openavr.org>
* ser_posix.c: Limit verbose output to 2 chars.
2003-03-23 Theodore A. Roth <troth@openavr.org>
* ser_posix.c: Add verbose level > 3 output for send and recv functions.
2003-03-23 Theodore A. Roth <troth@openavr.org>
* avr.c: Add avr_read_byte_default().
Have avr_read_byte() call pgm->read_byte() or avr_read_byte_default().
Add avr_write_byte_default().
Have avr_write_byte() call pgm->write_byte or avr_write_byte_default().
* pgm.c: Initialize pgm->write_byte and pgm->read_byte.
* pgm.h: Add write_byte and read_byte fields to struct programmer_t.
2003-03-17 Theodore A. Roth <troth@openavr.org>
* avrdude.conf.in: Fix typo for devicecode deprecation comment.
2003-03-17 Eric B. Weddington <eric@umginc.net>
* avrdude.conf.in: Add Bascom SAMPLE programmer.
Submitted by Larry Barello <larryba@barrello.net>
2003-03-16 Theodore A. Roth <troth@openavr.org>
* avr.c (avr_read): Use pgm->read_sig_bytes to read signature bytes if
available.
* avr910.c (avr910_vfy_cmd_sent): New function.
(avr910_chip_erase): Add support for chip erase.
(avr910_enter_prog_mode): New function.
(avr910_leave_prog_mode): New function.
(avr910_initialize): Add code to select device type and enter prog mode.
(avr910_close): Leave programming mode before closing serial port.
(avr910_read_sig_bytes): New function.
(avr910_initpgm): Add avr910_read_sig_bytes method to pgm initializer.
* avrdude.conf.in: Add note about deprecating devicecode.
Change all occurences of devicecode to stk500_devcode.
Add avr910_devcode to a few parts for testing.
* avrpart.h (struct avrpart): Change devicecode field to stk500_devcode.
(struct avrpart): Add avr910_devcode field.
* config_gram.y: Add K_STK500_DEVCODE and K_AVR910_DEVCODE tokens.
Generate an error if devicecode is found in the config file.
Handle parsing of avr910_devcode and stk500_devcode.
* lexer.l: Handle parsing of avr910_devcode and stk500_devcode.
* pgm.c: Initialize pgm->read_sig_bytes field.
* pgm.h: Add pgm->read_sig_bytes field.
* stk500.c: Use stk500_devcode instead of devicecode.
2003-03-16 Theodore A. Roth <troth@openavr.org>
* avrdude.conf.in: Add avr910 and pavr programmers.
* config_gram.y: Add parsing of avr910 programmer.
* lexer.l: Add avr910 token.
* avr910.c: [this is still work in progress]
Add some debug output.
Add probe for programmer presense.
* main.c: Set port to default_serial if programmer type is avr910.
2003-03-13 Theodore A. Roth <troth@openavr.org>
* ser_posix.c, ser_win32.c, serial.h:
Change baud from int to long to avoid a 16-bit int overflow.
2003-03-12 Theodore A. Roth <troth@openavr.org>
* Makefile.am (avrdude_SOURCES): Add avr910.[ch], serial.h and
ser_posix.c files.
* avr910.c: New file (stubs for avr910 serial programmer).
* avr910.h: New file.
* ser_posix.c: New file.
* ser_win32.c: New file (just stubs for now).
* serial.h: New file.
* stk500.c: Move all the code for accessing the posix serial ports
into ser_posix. This will make a native win32 port easier and allows
the avr910 programmer to share the serial code.
2003-03-12 Theodore A. Roth <troth@openavr.org>
* configure.ac (AC_INIT): Set version to 4.0.0cvs since we're done
with 4.0.0 release.
2003-03-12
* AVRDUDE 4.0.0 has been released (cvs release tag is "release_4_0_0").
2003-03-11 Theodore A. Roth <troth@openavr.org>
* Makefile.am: Add CLEANFILES to remove all files from a make.

View File

@@ -48,6 +48,8 @@ avrdude_SOURCES = \
lexer.l \
avr.c \
avr.h \
avr910.c \
avr910.h \
avrpart.h \
config.c \
config.h \
@@ -67,6 +69,9 @@ avrdude_SOURCES = \
ppi.c \
ppi.h \
ppiwin.c \
serial.h \
ser_posix.c \
ser_win32.c \
stk500.c \
stk500.h \
stk500_private.h \

View File

@@ -6,11 +6,21 @@ Approximate change log for AVRDUDE by version.
----------------------------------------------------------------------
Version 4.1.0
* Add support for the Bascom SAMPLE programmer. Submitted by
Larry Barello <larryba@barrello.net>
* Add support for avr910 type programmers (mcu00100, pavr avr910, etc).
* Support new devices: ATmega8535, ATtiny26
Version 4.0.0
* Now support Linux - added by "Theodore A. Roth" <troth@openavr.org>
* Now support Windows - added by "E. Weddington" <eric@umginc.net>
* Now support Windows - added by "Eric B. Weddington" <eric@umginc.net>
* Use 'configure' scripts to tailor the code to the system avrdude
is getting ready to be compiled on - added by "Theodore A. Roth"

View File

@@ -287,11 +287,8 @@ int avr_get_output(OPCODE * op, unsigned char * res, unsigned char * data)
}
/*
* read a byte of data from the indicated memory region
*/
int avr_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
unsigned long addr, unsigned char * value)
int avr_read_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
unsigned long addr, unsigned char * value)
{
unsigned char cmd[4];
unsigned char res[4];
@@ -340,6 +337,21 @@ int avr_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
}
/*
* read a byte of data from the indicated memory region
*/
int avr_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
unsigned long addr, unsigned char * value)
{
if (pgm->read_byte) {
return pgm->read_byte(pgm, p, mem, addr, value);
}
else {
return avr_read_byte_default(pgm, p, mem, addr, value);
}
}
/*
* Read the entirety of the specified memory type into the
* corresponding buffer of the avrpart pointed to by 'p'. If size =
@@ -385,6 +397,11 @@ int avr_read(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
}
}
if (strcmp(mem->desc, "signature") == 0) {
if (pgm->read_sig_bytes) {
return pgm->read_sig_bytes(pgm, p, mem);
}
}
printed = 0;
@@ -460,10 +477,7 @@ int avr_write_page(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
}
/*
* write a byte of data at the specified address
*/
int avr_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
int avr_write_byte_default(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
unsigned long addr, unsigned char data)
{
unsigned char cmd[4];
@@ -648,6 +662,21 @@ int avr_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
}
/*
* write a byte of data at the specified address
*/
int avr_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * mem,
unsigned long addr, unsigned char data)
{
if (pgm->write_byte) {
return pgm->write_byte(pgm, p, mem, addr, data);
}
else {
return avr_write_byte_default(pgm, p, mem, addr, data);
}
}
/*
* Write the whole memory region of the specified memory from the
* corresponding buffer of the avrpart pointed to by 'p'. Write up to
@@ -704,6 +733,10 @@ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size,
}
}
if (pgm->write_setup) {
pgm->write_setup(pgm, p, m);
}
for (i=0; i<wsize; i++) {
data = m->buf[i];
if (verbose) {

673
avrdude/avr910.c Normal file
View File

@@ -0,0 +1,673 @@
/*
* avrdude - A Downloader/Uploader for AVR device programmers
* Copyright (C) 2003 Theodore A. Roth <troth@openavr.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-1307 USA
*/
/* $Id$ */
/*
* avrdude interface for Atmel Low Cost Serial programmers which adher to the
* protocol described in application note avr910.
*/
#include "ac_cfg.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "avr.h"
#include "pgm.h"
#include "avr910.h"
#include "serial.h"
extern char * progname;
extern int do_cycles;
static char has_auto_incr_addr;
/* These two defines are only for debugging. Will remove them once it starts
working. */
#define show_func_info() \
fprintf(stderr, "%s: line %d: called %s()\n", \
__FILE__, __LINE__, __FUNCTION__)
#define no_show_func_info()
static int avr910_send(PROGRAMMER * pgm, char * buf, size_t len)
{
no_show_func_info();
return serial_send(pgm->fd, buf, len);
}
static int avr910_recv(PROGRAMMER * pgm, char * buf, size_t len)
{
no_show_func_info();
return serial_recv(pgm->fd, buf, len);
}
static int avr910_drain(PROGRAMMER * pgm, int display)
{
no_show_func_info();
return serial_drain(pgm->fd, display);
}
static void avr910_vfy_cmd_sent(PROGRAMMER * pgm, char * errmsg)
{
char c;
avr910_recv(pgm, &c, 1);
if (c != '\r') {
fprintf(stderr, "%s: error: programmer did not respond to command: %s\n",
progname, errmsg);
exit(1);
}
}
static int avr910_rdy_led(PROGRAMMER * pgm, int value)
{
no_show_func_info();
/* Do nothing. */
return 0;
}
static int avr910_err_led(PROGRAMMER * pgm, int value)
{
no_show_func_info();
/* Do nothing. */
return 0;
}
static int avr910_pgm_led(PROGRAMMER * pgm, int value)
{
no_show_func_info();
/* Do nothing. */
return 0;
}
static int avr910_vfy_led(PROGRAMMER * pgm, int value)
{
no_show_func_info();
/* Do nothing. */
return 0;
}
/*
* issue the 'chip erase' command to the AVR device
*/
static int avr910_chip_erase(PROGRAMMER * pgm, AVRPART * p)
{
no_show_func_info();
avr910_send(pgm, "e", 1);
avr910_vfy_cmd_sent(pgm, "chip erase");
return 0;
}
static void avr910_enter_prog_mode(PROGRAMMER * pgm)
{
avr910_send(pgm, "P", 1);
avr910_vfy_cmd_sent(pgm, "enter prog mode");
}
static void avr910_leave_prog_mode(PROGRAMMER * pgm)
{
avr910_send(pgm, "L", 1);
avr910_vfy_cmd_sent(pgm, "leave prog mode");
}
/*
* issue the 'program enable' command to the AVR device
*/
static int avr910_program_enable(PROGRAMMER * pgm, AVRPART * p)
{
no_show_func_info();
return -1;
}
/*
* apply power to the AVR processor
*/
static void avr910_powerup(PROGRAMMER * pgm)
{
no_show_func_info();
/* Do nothing. */
return;
}
/*
* remove power from the AVR processor
*/
static void avr910_powerdown(PROGRAMMER * pgm)
{
no_show_func_info();
/* Do nothing. */
return;
}
/*
* initialize the AVR device and prepare it to accept commands
*/
static int avr910_initialize(PROGRAMMER * pgm, AVRPART * p)
{
char id[8];
char sw[2];
char hw[2];
char buf[10];
char type;
unsigned char c;
int dev_supported = 0;
no_show_func_info();
/* Get the programmer identifier. Programmer returns exactly 7 chars
_without_ the null.*/
avr910_send(pgm, "S", 1);
memset (id, 0, sizeof(id));
avr910_recv(pgm, id, sizeof(id)-1);
/* Get the HW and SW versions to see if the programmer is present. */
avr910_send(pgm, "V", 1);
avr910_recv(pgm, sw, sizeof(sw));
avr910_send(pgm, "v", 1);
avr910_recv(pgm, hw, sizeof(hw));
/* Get the programmer type (serial or parallel). Expect serial. */
avr910_send(pgm, "p", 1);
avr910_recv(pgm, &type, 1);
fprintf(stderr, "Found programmer: Id = \"%s\"; type = %c\n", id, type);
fprintf(stderr, " Software Version = %c.%c; ", sw[0], sw[1]);
fprintf(stderr, "Hardware Version = %c.%c\n", hw[0], hw[1]);
/* See if programmer supports autoincrement of address. */
avr910_send(pgm, "a", 1);
avr910_recv(pgm, &has_auto_incr_addr, 1);
if (has_auto_incr_addr == 'Y')
fprintf(stderr, "Programmer supports auto addr increment.\n");
/* Get list of devices that the programmer supports. */
avr910_send(pgm, "t", 1);
fprintf(stderr, "\nProgrammer supports the following devices:\n");
while (1) {
avr910_recv(pgm, &c, 1);
if (c == 0)
break;
fprintf(stderr, " Device code: 0x%02x\n", c);
/* FIXME: Need to lookup devcode and report the device. */
if (p->avr910_devcode == c)
dev_supported = 1;
};
fprintf(stderr,"\n");
if (!dev_supported) {
fprintf(stderr,
"%s: error: selected device is not supported by programmer: %s\n",
progname, p->id);
exit(1);
}
/* Tell the programmer which part we selected. */
buf[0] = 'T';
buf[1] = p->avr910_devcode;
avr910_send(pgm, buf, 2);
avr910_vfy_cmd_sent(pgm, "select device");
avr910_enter_prog_mode(pgm);
return 0;
}
static int avr910_save(PROGRAMMER * pgm)
{
no_show_func_info();
/* Do nothing. */
return 0;
}
static void avr910_restore(PROGRAMMER * pgm)
{
no_show_func_info();
/* Do nothing. */
return;
}
static void avr910_disable(PROGRAMMER * pgm)
{
no_show_func_info();
/* Do nothing. */
return;
}
static void avr910_enable(PROGRAMMER * pgm)
{
no_show_func_info();
/* Do nothing. */
return;
}
/*
* transmit an AVR device command and return the results; 'cmd' and
* 'res' must point to at least a 4 byte data buffer
*/
static int avr910_cmd(PROGRAMMER * pgm, unsigned char cmd[4],
unsigned char res[4])
{
int i;
no_show_func_info();
for (i=0; i<4; i++) {
fprintf(stderr, "cmd[%d] = 0x%02x\n", i, cmd[i]);
}
return 0;
}
static void avr910_open(PROGRAMMER * pgm, char * port)
{
no_show_func_info();
strcpy(pgm->port, port);
pgm->fd = serial_open(port, 19200);
/*
* drain any extraneous input
*/
avr910_drain (pgm, 0);
}
static void avr910_close(PROGRAMMER * pgm)
{
no_show_func_info();
avr910_leave_prog_mode(pgm);
serial_close(pgm->fd);
pgm->fd = -1;
}
static void avr910_display(PROGRAMMER * pgm, char * p)
{
no_show_func_info();
return;
}
static void avr910_set_addr(PROGRAMMER * pgm, unsigned long addr)
{
unsigned char cmd[3];
cmd[0] = 'A';
cmd[1] = (addr >> 8) & 0xff;
cmd[2] = addr & 0xff;
avr910_send(pgm, cmd, sizeof(cmd));
avr910_vfy_cmd_sent(pgm, "set addr");
}
/*
* For some reason, if we don't do this when writing to flash, the first byte
* of flash is not programmed. I susect that the board got out of sync after
* the erase and sending another command gets us back in sync. -TRoth
*/
static void avr910_write_setup(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m)
{
if (strcmp(m->desc, "flash") == 0) {
avr910_send(pgm, "y", 1);
avr910_vfy_cmd_sent(pgm, "clear LED");
}
}
static int avr910_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
unsigned long addr, unsigned char value)
{
unsigned char cmd[2];
no_show_func_info();
if (strcmp(m->desc, "flash") == 0) {
if (addr & 0x01) {
cmd[0] = 'C'; /* Write Program Mem high byte */
}
else {
cmd[0] = 'c';
}
addr >>= 1;
}
else if (strcmp(m->desc, "eeprom") == 0) {
cmd[0] = 'D';
}
else {
return -1;
}
cmd[1] = value;
avr910_set_addr(pgm, addr);
avr910_send(pgm, cmd, sizeof(cmd));
avr910_vfy_cmd_sent(pgm, "write byte");
return 0;
}
static int avr910_read_byte_flash(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
unsigned long addr, unsigned char * value)
{
static int cached = 0;
static unsigned char cvalue;
static unsigned long caddr;
if (cached && ((caddr + 1) == addr)) {
*value = cvalue;
cached = 0;
}
else {
unsigned char buf[2];
avr910_set_addr(pgm, addr >> 1);
avr910_send(pgm, "R", 1);
/* Read back the program mem word (MSB first) */
avr910_recv(pgm, buf, sizeof(buf));
if ((addr & 0x01) == 0) {
*value = buf[1];
cached = 1;
cvalue = buf[0];
caddr = addr;
}
else {
*value = buf[0];
}
}
return 0;
}
static int avr910_read_byte_eeprom(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
unsigned long addr, unsigned char * value)
{
avr910_set_addr(pgm, addr);
avr910_send(pgm, "d", 1);
avr910_recv(pgm, value, 1);
return 0;
}
static int avr910_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
unsigned long addr, unsigned char * value)
{
no_show_func_info();
if (strcmp(m->desc, "flash") == 0) {
return avr910_read_byte_flash(pgm, p, m, addr, value);
}
if (strcmp(m->desc, "eeprom") == 0) {
return avr910_read_byte_eeprom(pgm, p, m, addr, value);
}
return -1;
}
static int avr910_paged_write_flash(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
int page_size, int n_bytes)
{
unsigned char cmd[] = {'c', 'C'};
unsigned char buf[2];
unsigned int addr = 0;
unsigned int max_addr = n_bytes;
avr910_write_setup(pgm, p, m);
avr910_set_addr(pgm, addr>>1);
while (addr < max_addr) {
buf[0] = cmd[addr & 0x01];
buf[1] = m->buf[addr];
avr910_send(pgm, buf, sizeof(buf));
avr910_vfy_cmd_sent(pgm, "write byte");
addr++;
if ((has_auto_incr_addr != 'Y') && ((addr & 0x01) == 0)) {
avr910_set_addr(pgm, addr>>1);
}
}
return addr;
}
static int avr910_paged_write_eeprom(PROGRAMMER * pgm, AVRPART * p,
AVRMEM * m, int page_size, int n_bytes)
{
unsigned char cmd[2];
unsigned int addr = 0;
unsigned int max_addr = n_bytes;
avr910_set_addr(pgm, addr);
cmd[0] = 'D';
while (addr < max_addr) {
cmd[1] = m->buf[addr];
avr910_send(pgm, cmd, sizeof(cmd));
avr910_vfy_cmd_sent(pgm, "write byte");
addr++;
if (has_auto_incr_addr != 'Y') {
avr910_set_addr(pgm, addr);
}
}
return addr;
}
static int avr910_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
int page_size, int n_bytes)
{
if (strcmp(m->desc, "flash") == 0) {
return avr910_paged_write_flash(pgm, p, m, page_size, n_bytes);
}
else if (strcmp(m->desc, "eeprom") == 0) {
return avr910_paged_write_eeprom(pgm, p, m, page_size, n_bytes);
}
else {
return -2;
}
}
static int avr910_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
int page_size, int n_bytes)
{
unsigned char cmd;
int rd_size;
unsigned int addr = 0;
unsigned int max_addr;
unsigned char buf[2];
if (strcmp(m->desc, "flash") == 0) {
cmd = 'R';
rd_size = 2; /* read two bytes per addr */
}
else if (strcmp(m->desc, "eeprom") == 0) {
cmd = 'd';
rd_size = 1;
}
else {
return -2;
}
max_addr = n_bytes/rd_size;
avr910_set_addr(pgm, addr);
while (addr < max_addr) {
avr910_send(pgm, &cmd, 1);
if (cmd == 'R') {
/* The 'R' command returns two bytes, MSB first, we need to put the data
into the memory buffer LSB first. */
avr910_recv(pgm, buf, 2);
m->buf[addr*2] = buf[1]; /* LSB */
m->buf[addr*2+1] = buf[0]; /* MSB */
}
else {
avr910_recv(pgm, &m->buf[addr], 1);
}
addr++;
if (has_auto_incr_addr != 'Y') {
avr910_set_addr(pgm, addr);
}
}
return addr * rd_size;
}
/* Signature byte reads are always 3 bytes. */
static int avr910_read_sig_bytes(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m)
{
no_show_func_info();
if (m->size < 3) {
fprintf(stderr, "%s: memsize too small for sig byte read", progname);
return -1;
}
avr910_send(pgm, "s", 1);
avr910_recv(pgm, m->buf, 3);
return 3;
}
void avr910_initpgm(PROGRAMMER * pgm)
{
no_show_func_info();
strcpy(pgm->type, "avr910");
/*
* mandatory functions
*/
pgm->rdy_led = avr910_rdy_led;
pgm->err_led = avr910_err_led;
pgm->pgm_led = avr910_pgm_led;
pgm->vfy_led = avr910_vfy_led;
pgm->initialize = avr910_initialize;
pgm->display = avr910_display;
pgm->save = avr910_save;
pgm->restore = avr910_restore;
pgm->enable = avr910_enable;
pgm->disable = avr910_disable;
pgm->powerup = avr910_powerup;
pgm->powerdown = avr910_powerdown;
pgm->program_enable = avr910_program_enable;
pgm->chip_erase = avr910_chip_erase;
pgm->cmd = avr910_cmd;
pgm->open = avr910_open;
pgm->close = avr910_close;
/*
* optional functions
*/
pgm->write_setup = avr910_write_setup;
pgm->write_byte = avr910_write_byte;
pgm->read_byte = avr910_read_byte;
pgm->paged_write = avr910_paged_write;
pgm->paged_load = avr910_paged_load;
pgm->read_sig_bytes = avr910_read_sig_bytes;
}

29
avrdude/avr910.h Normal file
View File

@@ -0,0 +1,29 @@
/*
* avrdude - A Downloader/Uploader for AVR device programmers
* Copyright (C) 2003 Theodore A. Roth <troth@openavr.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-1307 USA
*/
/* $Id$ */
#ifndef __avr910_h__
#define __avr910_h__
#include "config.h"
void avr910_initpgm (PROGRAMMER * pgm);
#endif /* __avr910_h__ */

View File

@@ -15,7 +15,7 @@
# programmer
# id = <id1> [, <id2> [, <id3>] ...] ; # <idN> are quoted strings
# desc = <description> ; # quoted string
# type = par | stk500 ; # programmer type
# type = par | stk500 | avr910; # programmer type
# vcc = <num1> [, <num2> ... ] ; # pin number(s)
# reset = <num> ; # pin number
# sck = <num> ; # pin number
@@ -30,7 +30,9 @@
# part
# id = <id> ; # quoted string
# desc = <description> ; # quoted string
# devicecode = <num> ; # numeric
# devicecode = <num> ; # deprecated, use stk500_devcode
# stk500_devcode = <num> ; # numeric
# avr910_devcode = <num> ; # numeric
# chip_erase_delay = <num> ; # micro-seconds
# pagel = <num> ; # pin name in hex, i.e., 0xD7
# bs2 = <num> ; # pin name in hex, i.e., 0xA0
@@ -203,6 +205,18 @@ programmer
type = stk500;
;
programmer
id = "avr910";
desc = "Atmel Low Cost Serial Programmer";
type = avr910;
;
programmer
id = "pavr";
desc = "Jason Kyle's pAVR Serial Programmer";
type = avr910;
;
programmer
id = "stk200";
desc = "STK200";
@@ -220,8 +234,8 @@ programmer
# programming is currently in progress.
programmer
id = "pony";
desc = "Pony Prog";
id = "pony-stk200";
desc = "Pony Prog STK200";
type = par;
buff = 4, 5;
sck = 6;
@@ -241,6 +255,16 @@ programmer
miso = 11;
;
programmer
id = "bascom";
desc = "Bascom SAMPLE programming cable";
type = par;
reset = 4;
sck = 5;
mosi = 2;
miso = 11;
;
programmer
id = "alf";
desc = "Tony Friebel's Programmer";
@@ -272,7 +296,7 @@ programmer
part
id = "t15";
desc = "ATtiny15";
devicecode = 0x13;
stk500_devcode = 0x13;
chip_erase_delay = 20000;
pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
"x x x x x x x x x x x x x x x x";
@@ -359,7 +383,8 @@ part
part
id = "1200";
desc = "AT90S1200";
devicecode = 0x33;
stk500_devcode = 0x33;
avr910_devcode = 0x13;
chip_erase_delay = 20000;
pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
"x x x x x x x x x x x x x x x x";
@@ -439,7 +464,7 @@ part
part
id = "4414";
desc = "AT90S4414";
devicecode = 0x50;
stk500_devcode = 0x50;
chip_erase_delay = 20000;
pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
"x x x x x x x x x x x x x x x x";
@@ -499,7 +524,7 @@ part
part
id = "2313";
desc = "AT90S2313";
devicecode = 0x40;
stk500_devcode = 0x40;
chip_erase_delay = 20000;
pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
"x x x x x x x x x x x x x x x x";
@@ -564,7 +589,7 @@ part
part
id = "2333";
desc = "AT90S2333";
devicecode = 0x42;
stk500_devcode = 0x42;
chip_erase_delay = 20000;
pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
"x x x x x x x x x x x x x x x x";
@@ -726,7 +751,7 @@ part
part
id = "4433";
desc = "AT90S4433";
devicecode = 0x51;
stk500_devcode = 0x51;
chip_erase_delay = 20000;
pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
"x x x x x x x x x x x x x x x x";
@@ -807,7 +832,7 @@ part
part
id = "4434";
desc = "AT90S4434";
devicecode = 0x52;
stk500_devcode = 0x52;
chip_erase_delay = 20000;
pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
"x x x x x x x x x x x x x x x x";
@@ -887,7 +912,8 @@ part
part
id = "8515";
desc = "AT90S8515";
devicecode = 0x60;
stk500_devcode = 0x60;
avr910_devcode = 0x38;
chip_erase_delay = 20000;
pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
"x x x x x x x x x x x x x x x x";
@@ -961,7 +987,7 @@ part
part
id = "8535";
desc = "AT90S8535";
devicecode = 0x61;
stk500_devcode = 0x61;
chip_erase_delay = 20000;
pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
"x x x x x x x x x x x x x x x x";
@@ -1021,7 +1047,7 @@ part
part
id = "m103";
desc = "ATMEGA103";
devicecode = 0xB1;
stk500_devcode = 0xB1;
chip_erase_delay = 112000;
pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
"x x x x x x x x x x x x x x x x";
@@ -1114,7 +1140,7 @@ part
part
id = "m128";
desc = "ATMEGA128";
devicecode = 0xB2;
stk500_devcode = 0xB2;
chip_erase_delay = 9000;
pagel = 0xD7;
bs2 = 0xA0;
@@ -1235,7 +1261,7 @@ part
part
id = "m16";
desc = "ATMEGA16";
devicecode = 0x82;
stk500_devcode = 0x82;
pagel = 0xd7;
bs2 = 0xa0;
chip_erase_delay = 9000;
@@ -1339,7 +1365,7 @@ part
part
id = "m163";
desc = "ATMEGA163";
devicecode = 0x81;
stk500_devcode = 0x81;
chip_erase_delay = 32000;
pagel = 0xd7;
bs2 = 0xa0;
@@ -1453,7 +1479,7 @@ part
part
id = "m169";
desc = "ATMEGA169";
devicecode = 0x85;
stk500_devcode = 0x85;
chip_erase_delay = 32000;
pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
"x x x x x x x x x x x x x x x x";
@@ -1567,6 +1593,124 @@ part
;
;
#------------------------------------------------------------
# ATmega32
#------------------------------------------------------------
part
id = "m32";
desc = "ATMEGA32";
stk500_devcode = 0x91;
chip_erase_delay = 32000;
pagel = 0xd7;
bs2 = 0xa0;
reset = dedicated;
pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
"x x x x x x x x x x x x x x x x";
chip_erase = "1 0 1 0 1 1 0 0 1 0 0 0 0 0 0 0",
"x x x x x x x x x x x x x x x x";
memory "eeprom"
paged = no; /* leave this "no" */
page_size = 4; /* for parallel programming */
size = 1024;
min_write_delay = 9000;
max_write_delay = 9000;
readback_p1 = 0xff;
readback_p2 = 0xff;
read = " 1 0 1 0 0 0 0 0",
" 0 0 x x x x a9 a8",
" a7 a6 a5 a4 a3 a2 a1 a0",
" o o o o o o o o";
write = " 1 1 0 0 0 0 0 0",
" 0 0 x x x x a9 a8",
" a7 a6 a5 a4 a3 a2 a1 a0",
" i i i i i i i i";
;
memory "flash"
paged = yes;
size = 32768;
page_size = 128;
num_pages = 256;
min_write_delay = 4500;
max_write_delay = 9000;
readback_p1 = 0xff;
readback_p2 = 0xff;
read_lo = " 0 0 1 0 0 0 0 0",
" 0 0 a13 a12 a11 a10 a9 a8",
" a7 a6 a5 a4 a3 a2 a1 a0",
" o o o o o o o o";
read_hi = " 0 0 1 0 1 0 0 0",
" 0 0 a13 a12 a11 a10 a9 a8",
" a7 a6 a5 a4 a3 a2 a1 a0",
" o o o o o o o o";
loadpage_lo = " 0 1 0 0 0 0 0 0",
" 0 0 x x x x x x",
" x x a5 a4 a3 a2 a1 a0",
" i i i i i i i i";
loadpage_hi = " 0 1 0 0 1 0 0 0",
" 0 0 x x x x x x",
" x x a5 a4 a3 a2 a1 a0",
" i i i i i i i i";
writepage = " 0 1 0 0 1 1 0 0",
" 0 0 a13 a12 a11 a10 a9 a8",
" a7 a6 x x x x x x",
" x x x x x x x x";
;
memory "lfuse"
size = 1;
min_write_delay = 2000;
max_write_delay = 2000;
read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0",
"x x x x x x x x o o o o o o o o";
write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0",
"x x x x x x x x i i i i i i i i";
;
memory "hfuse"
size = 1;
min_write_delay = 2000;
max_write_delay = 2000;
read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0",
"x x x x x x x x o o o o o o o o";
write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0",
"x x x x x x x x i i i i i i i i";
;
memory "lock"
size = 1;
min_write_delay = 2000;
max_write_delay = 2000;
read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0",
"x x x x x x x x x x o o o o o o";
write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x",
"x x x x x x x x 1 1 i i i i i i";
;
memory "signature"
size = 3;
read = "0 0 1 1 0 0 0 0 x x x x x x x x",
"x x x x x x a1 a0 o o o o o o o o";
;
memory "calibration"
size = 1;
read = "0 0 1 1 1 0 0 0 0 0 x x x x x x",
"0 0 0 0 0 0 0 0 o o o o o o o o";
;
;
#------------------------------------------------------------
# ATmega8
#------------------------------------------------------------
@@ -1574,7 +1718,7 @@ part
part
id = "m8";
desc = "ATMEGA8";
devicecode = 0x70;
stk500_devcode = 0x70;
pagel = 0xd7;
bs2 = 0xc2;
chip_erase_delay = 9000;
@@ -1681,3 +1825,225 @@ part
;
;
#------------------------------------------------------------
# ATmega8535
#------------------------------------------------------------
part
id = "m8535";
desc = "ATMEGA8535";
stk500_devcode = 0x64;
pagel = 0xd7;
bs2 = 0xa0;
chip_erase_delay = 9000;
pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
"x x x x x x x x x x x x x x x x";
chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x",
"x x x x x x x x x x x x x x x x";
memory "eeprom"
size = 512;
min_write_delay = 9000;
max_write_delay = 9000;
readback_p1 = 0xff;
readback_p2 = 0xff;
read = " 1 0 1 0 0 0 0 0",
" 0 0 x x x x x a8",
" a7 a6 a5 a4 a3 a2 a1 a0",
" o o o o o o o o";
write = " 1 1 0 0 0 0 0 0",
" 0 0 x x x x x a8",
" a7 a6 a5 a4 a3 a2 a1 a0",
" i i i i i i i i";
;
memory "flash"
paged = yes;
size = 8192;
page_size = 64;
num_pages = 128;
min_write_delay = 4500;
max_write_delay = 9000;
readback_p1 = 0xff;
readback_p2 = 0xff;
read_lo = " 0 0 1 0 0 0 0 0",
" 0 0 0 0 a11 a10 a9 a8",
" a7 a6 a5 a4 a3 a2 a1 a0",
" o o o o o o o o";
read_hi = " 0 0 1 0 1 0 0 0",
" 0 0 0 0 a11 a10 a9 a8",
" a7 a6 a5 a4 a3 a2 a1 a0",
" o o o o o o o o";
loadpage_lo = " 0 1 0 0 0 0 0 0",
" 0 0 0 0 x x x x",
" x x x a4 a3 a2 a1 a0",
" i i i i i i i i";
loadpage_hi = " 0 1 0 0 1 0 0 0",
" 0 0 0 0 x x x x",
" x x x a4 a3 a2 a1 a0",
" i i i i i i i i";
writepage = " 0 1 0 0 1 1 0 0",
" 0 0 0 0 a11 a10 a9 a8",
" a7 a6 a5 x x x x x",
" x x x x x x x x";
;
memory "lfuse"
size = 1;
min_write_delay = 2000;
max_write_delay = 2000;
read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0",
"x x x x x x x x o o o o o o o o";
write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0",
"x x x x x x x x i i i i i i i i";
;
memory "hfuse"
size = 1;
min_write_delay = 2000;
max_write_delay = 2000;
read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0",
"x x x x x x x x o o o o o o o o";
write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0",
"x x x x x x x x i i i i i i i i";
;
memory "lock"
size = 1;
min_write_delay = 2000;
max_write_delay = 2000;
read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0",
"x x x x x x x x x x o o o o o o";
write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x",
"x x x x x x x x 1 1 i i i i i i";
;
memory "calibration"
size = 1;
read = "0 0 1 1 1 0 0 0 0 0 x x x x x x",
"0 0 0 0 0 0 0 0 o o o o o o o o";
;
memory "signature"
size = 3;
read = "0 0 1 1 0 0 0 0 x x x x x x x x",
"x x x x x x a1 a0 o o o o o o o o";
;
;
#------------------------------------------------------------
# ATtiny26
#------------------------------------------------------------
part
id = "t26";
desc = "ATTINY26";
stk500_devcode = 0x21;
pagel = 0xb3;
bs2 = 0xb2;
chip_erase_delay = 9000;
pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
"x x x x x x x x x x x x x x x x";
chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x",
"x x x x x x x x x x x x x x x x";
memory "eeprom"
size = 128;
min_write_delay = 9000;
max_write_delay = 20000;
readback_p1 = 0xff;
readback_p2 = 0xff;
read = "1 0 1 0 0 0 0 0 x x x x x x x x",
"x a6 a5 a4 a3 a2 a1 a0 o o o o o o o o";
write = "1 1 0 0 0 0 0 0 x x x x x x x x",
"x a6 a5 a4 a3 a2 a1 a0 i i i i i i i i";
;
memory "flash"
paged = yes;
size = 2048;
page_size = 32;
num_pages = 64;
min_write_delay = 4500;
max_write_delay = 20000;
readback_p1 = 0xff;
readback_p2 = 0xff;
read_lo = " 0 0 1 0 0 0 0 0",
" x x x x x x a9 a8",
" a7 a6 a5 a4 a3 a2 a1 a0",
" o o o o o o o o";
read_hi = " 0 0 1 0 1 0 0 0",
" x x x x x x a9 a8",
" a7 a6 a5 a4 a3 a2 a1 a0",
" o o o o o o o o";
loadpage_lo = " 0 1 0 0 0 0 0 0",
" x x x x x x x x",
" x x x x a3 a2 a1 a0",
" i i i i i i i i";
loadpage_hi = " 0 1 0 0 1 0 0 0",
" x x x x x x x x",
" x x x x a3 a2 a1 a0",
" i i i i i i i i";
writepage = " 0 1 0 0 1 1 0 0",
" x x x x x x a9 a8",
" a7 a6 a5 a4 x x x x",
" x x x x x x x x";
;
memory "signature"
size = 3;
read = "0 0 1 1 0 0 0 0 x x x x x x x x",
"0 0 0 0 0 0 a1 a0 o o o o o o o o";
;
memory "lock"
size = 1;
read = "0 1 0 1 1 0 0 0 x x x x x x x x",
"x x x x x x x x x x x x x x o o";
write = "1 0 1 0 1 1 0 0 1 1 1 1 1 1 i i",
"x x x x x x x x x x x x x x x x";
;
memory "lfuse"
size = 1;
write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0",
"x x x x x x x x i i i i i i i i";
read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0",
"x x x x x x x x o o o o o o o o";
;
memory "hfuse"
size = 1;
write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0",
"x x x x x x x x x x x i i i i i";
read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0",
"x x x x x x x x x x x o o o o o";
;
memory "calibration"
size = 4;
read = "0 0 1 1 1 0 0 0 x x x x x x x x",
"0 0 0 0 0 0 a1 a0 o o o o o o o o";
;
;

View File

@@ -81,7 +81,8 @@ typedef struct opcode {
typedef struct avrpart {
char desc[AVR_DESCLEN]; /* long part name */
char id[AVR_IDLEN]; /* short part name */
int devicecode; /* Atmel STK500 device code */
int stk500_devcode; /* stk500 device code */
int avr910_devcode; /* avr910 device code */
int chip_erase_delay; /* microseconds */
unsigned char pagel; /* for parallel programming */
unsigned char bs2; /* for parallel programming */

View File

@@ -33,6 +33,7 @@
#include "ppi.h"
#include "pgm.h"
#include "stk500.h"
#include "avr910.h"
#include "avr.h"
extern char * progname;
@@ -72,6 +73,8 @@ static int parse_cmdbits(OPCODE * op);
%token K_DEFAULT_SERIAL
%token K_DESC
%token K_DEVICECODE
%token K_STK500_DEVCODE
%token K_AVR910_DEVCODE
%token K_EEPROM
%token K_ERRLED
%token K_FLASH
@@ -101,6 +104,7 @@ static int parse_cmdbits(OPCODE * op);
%token K_SCK
%token K_SIZE
%token K_STK500
%token K_AVR910
%token K_TYPE
%token K_VCC
%token K_VFYLED
@@ -284,6 +288,12 @@ prog_parm :
}
} |
K_TYPE TKN_EQUAL K_AVR910 {
{
avr910_initpgm(current_prog);
}
} |
K_DESC TKN_EQUAL TKN_STRING {
strncpy(current_prog->desc, $3->value.string, PGM_DESCLEN);
current_prog->desc[PGM_DESCLEN-1] = 0;
@@ -403,7 +413,24 @@ part_parm :
K_DEVICECODE TKN_EQUAL TKN_NUMBER {
{
current_part->devicecode = $3->value.number;
fprintf(stderr,
"%s: error at %s:%d: devicecode is deprecated, use "
"stk500_devcode instead\n",
progname, infile, lineno);
exit(1);
}
} |
K_STK500_DEVCODE TKN_EQUAL TKN_NUMBER {
{
current_part->stk500_devcode = $3->value.number;
free_token($3);
}
} |
K_AVR910_DEVCODE TKN_EQUAL TKN_NUMBER {
{
current_part->avr910_devcode = $3->value.number;
free_token($3);
}
} |

View File

@@ -24,7 +24,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.57)
AC_INIT(avrdude, 4.0.0, avrdude-dev@nongnu.org)
AC_INIT(avrdude, 4.1.0, avrdude-dev@nongnu.org)
AC_CANONICAL_BUILD
AC_CANONICAL_HOST

View File

@@ -30,6 +30,8 @@ static char *filename;
void win_sys_config_set(char sys_config[PATH_MAX])
{
sys_config[0] = 0;
/* Use Windows API call to search for the Windows default system config file.*/
SearchPath(NULL, "avrdude.conf", NULL, PATH_MAX, sys_config, &filename);
return;
@@ -38,6 +40,8 @@ void win_sys_config_set(char sys_config[PATH_MAX])
void win_usr_config_set(char usr_config[PATH_MAX])
{
usr_config[0] = 0;
/* Use Windows API call to search for the Windows default user config file. */
SearchPath(NULL, "avrdude.rc", NULL, PATH_MAX, usr_config, &filename);
return;

View File

@@ -127,17 +127,24 @@ from the contents of a file, while interactive mode is useful for
exploring memory contents, modifing individual bytes of eeprom,
programming fuse/lock bits, etc.
AVRDUDE supports two basic programmer types: Atmel's STK500 and the PPI
(parallel port interface). PPI represents a class of simple programmers
where the programming lines are directly connected to the PC parallel
port, while the STK500 uses the serial port to communicate with the PC
AVRDUDE supports three basic programmer types: Atmel's STK500, appnote
avr910 and the PPI (parallel port interface). PPI represents a class
of simple programmers where the programming lines are directly
connected to the PC parallel port. Several pin configurations exist
for several variations of the PPI programmers, and AVRDUDE can be be
configured to work with them by either specifying the appropriate
programmer on the command line or by creating a new entry in its
configuration file. All that's usually required for a new entry is to
tell AVRDUDE which pins to use for each programming function.
The STK500 and avr910 use the serial port to communicate with the PC
and contains on-board logic to control the programming of the target
device. Several pin configurations exist for several variations of the
PPI programmers, and AVRDUDE can be be configured to work with them by
either specifying the appropriate programmer on the command line or by
creating a new entry in its configuration file. All that's usually
required for a new entry is to tell AVRDUDE which pins to use for each
programming function.
device. The fundamental difference between the two types lies in the
protocol used to control the programmer. The av910 protocol is very
simplistic and can easily be used as the basis for a simple, home made
programer since the firmware is available online. On the other hand,
the STK500 protocol is more robust and complicated and the firmware is
not openly available.
@menu
* History::

View File

@@ -125,6 +125,8 @@ default_parallel { yylval=NULL; return K_DEFAULT_PARALLEL; }
default_programmer { yylval=NULL; return K_DEFAULT_PROGRAMMER; }
default_serial { yylval=NULL; return K_DEFAULT_SERIAL; }
devicecode { yylval=NULL; return K_DEVICECODE; }
stk500_devcode { yylval=NULL; return K_STK500_DEVCODE; }
avr910_devcode { yylval=NULL; return K_AVR910_DEVCODE; }
eeprom { yylval=NULL; return K_EEPROM; }
errled { yylval=NULL; return K_ERRLED; }
flash { yylval=NULL; return K_FLASH; }
@@ -152,6 +154,7 @@ retry_pulse { yylval=NULL; return K_RETRY_PULSE; }
serial { yylval=NULL; return K_SERIAL; }
size { yylval=NULL; return K_SIZE; }
stk500 { yylval=NULL; return K_STK500; }
avr910 { yylval=NULL; return K_AVR910; }
type { yylval=NULL; return K_TYPE; }
vcc { yylval=NULL; return K_VCC; }
vfyled { yylval=NULL; return K_VFYLED; }

View File

@@ -610,7 +610,8 @@ int main(int argc, char * argv [])
exit(1);
}
if (strcmp(pgm->type, "STK500") == 0) {
if ((strcmp(pgm->type, "STK500") == 0)
|| (strcmp(pgm->type, "avr910") == 0)){
if (port == default_parallel) {
port = default_serial;
}

View File

@@ -89,6 +89,10 @@ PROGRAMMER * pgm_new(void)
*/
pgm->paged_write = NULL;
pgm->paged_load = NULL;
pgm->write_setup = NULL;
pgm->write_byte = NULL;
pgm->read_byte = NULL;
pgm->read_sig_bytes = NULL;
return pgm;
}

View File

@@ -66,6 +66,12 @@ typedef struct programmer_t {
int page_size, int n_bytes);
int (*paged_load) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m,
int page_size, int n_bytes);
void (*write_setup) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m);
int (*write_byte) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m,
unsigned long addr, unsigned char value);
int (*read_byte) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m,
unsigned long addr, unsigned char * value);
int (*read_sig_bytes) (struct programmer_t * pgm, AVRPART * p, AVRMEM * m);
char config_file[PATH_MAX]; /* config file where defined */
int lineno; /* config file line number */
} PROGRAMMER;

350
avrdude/ser_posix.c Normal file
View File

@@ -0,0 +1,350 @@
/*
* avrdude - A Downloader/Uploader for AVR device programmers
* Copyright (C) 2003 Theodore A. Roth <troth@openavr.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-1307 USA
*/
/* $Id$ */
/*
* Posix serial interface for avrdude.
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
extern char *progname;
extern int verbose;
struct baud_mapping {
long baud;
speed_t speed;
};
/* There are a lot more baud rates we could handle, but what's the point? */
static struct baud_mapping baud_lookup_table [] = {
{ 1200, B1200 },
{ 2400, B2400 },
{ 4800, B4800 },
{ 9600, B9600 },
{ 19200, B19200 },
{ 38400, B38400 },
{ 57600, B57600 },
{ 115200, B115200 },
{ 230400, B230400 },
{ 0, 0 } /* Terminator. */
};
static speed_t serial_baud_lookup(long baud)
{
struct baud_mapping *map = baud_lookup_table;
while (map->baud) {
if (map->baud == baud)
return map->speed;
map++;
}
fprintf(stderr, "%s: serial_baud_lookup(): unknown baud rate: %ld",
progname, baud);
exit(1);
}
static int serial_setattr(int fd, long baud)
{
int rc;
struct termios termios;
speed_t speed = serial_baud_lookup (baud);
if (!isatty(fd))
return -1;
/*
* initialize terminal modes
*/
rc = tcgetattr(fd, &termios);
if (rc < 0) {
fprintf(stderr, "%s: serial_setattr(): tcgetattr() failed, %s",
progname, strerror(errno));
return -errno;
}
termios.c_iflag = 0;
termios.c_oflag = 0;
termios.c_cflag = 0;
termios.c_cflag |= (CS8 | CREAD | CLOCAL);
termios.c_lflag = 0;
termios.c_cc[VMIN] = 1;
termios.c_cc[VTIME] = 0;
cfsetospeed(&termios, speed);
cfsetispeed(&termios, speed);
rc = tcsetattr(fd, TCSANOW, &termios);
if (rc < 0) {
fprintf(stderr, "%s: serial_setattr(): tcsetattr() failed, %s",
progname, strerror(errno));
return -errno;
}
return 0;
}
int serial_open(char * port, int baud)
{
int rc;
int fd;
/*
* open the serial port
*/
fd = open(port, O_RDWR | O_NOCTTY /*| O_NONBLOCK*/);
if (fd < 0) {
fprintf(stderr, "%s: serial_open(): can't open device \"%s\": %s\n",
progname, port, strerror(errno));
exit(1);
}
/*
* set serial line attributes
*/
rc = serial_setattr(fd, baud);
if (rc) {
fprintf(stderr,
"%s: serial_open(): can't set attributes for device \"%s\"\n",
progname, port);
exit(1);
}
return fd;
}
void serial_close(int fd)
{
/* FIXME: Should really restore the terminal to original state here. */
close(fd);
}
int serial_send(int fd, char * buf, size_t buflen)
{
struct timeval timeout;
fd_set wfds;
int nfds;
int rc;
char * p = buf;
size_t len = buflen;
if (!len)
return 0;
if (verbose > 3)
{
fprintf(stderr, "%s: Send: ", progname);
while (buflen) {
unsigned char c = *buf;
if (isprint(c)) {
fprintf(stderr, "%c ", c);
}
else {
fprintf(stderr, ". ");
}
fprintf(stderr, "[%02x] ", c);
buf++;
buflen--;
}
fprintf(stderr, "\n");
}
timeout.tv_sec = 0;
timeout.tv_usec = 500000;
while (len) {
FD_ZERO(&wfds);
FD_SET(fd, &wfds);
reselect:
nfds = select(fd+1, NULL, &wfds, NULL, &timeout);
if (nfds == 0) {
fprintf(stderr,
"%s: serial_send(): programmer is not responding\n",
progname);
exit(1);
}
else if (nfds == -1) {
if (errno == EINTR) {
goto reselect;
}
else {
fprintf(stderr, "%s: serial_send(): select(): %s\n",
progname, strerror(errno));
exit(1);
}
}
rc = write(fd, p, 1);
if (rc < 0) {
fprintf(stderr, "%s: serial_send(): write error: %s\n",
progname, strerror(errno));
exit(1);
}
p++;
len--;
}
return 0;
}
int serial_recv(int fd, char * buf, size_t buflen)
{
struct timeval timeout;
fd_set rfds;
int nfds;
int rc;
char * p = buf;
size_t len = 0;
timeout.tv_sec = 5;
timeout.tv_usec = 0;
while (len < buflen) {
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
reselect:
nfds = select(fd+1, &rfds, NULL, NULL, &timeout);
if (nfds == 0) {
fprintf(stderr,
"%s: serial_recv(): programmer is not responding\n",
progname);
exit(1);
}
else if (nfds == -1) {
if (errno == EINTR) {
goto reselect;
}
else {
fprintf(stderr, "%s: serial_recv(): select(): %s\n",
progname, strerror(errno));
exit(1);
}
}
rc = read(fd, p, 1);
if (rc < 0) {
fprintf(stderr, "%s: serial_recv(): read error: %s\n",
progname, strerror(errno));
exit(1);
}
p++;
len++;
}
p = buf;
if (verbose > 3)
{
fprintf(stderr, "%s: Recv: ", progname);
while (len) {
unsigned char c = *p;
if (isprint(c)) {
fprintf(stderr, "%c ", c);
}
else {
fprintf(stderr, ". ");
}
fprintf(stderr, "[%02x] ", c);
p++;
len--;
}
fprintf(stderr, "\n");
}
return 0;
}
int serial_drain(int fd, int display)
{
struct timeval timeout;
fd_set rfds;
int nfds;
int rc;
unsigned char buf;
timeout.tv_sec = 0;
timeout.tv_usec = 250000;
if (display) {
fprintf(stderr, "drain>");
}
while (1) {
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
reselect:
nfds = select(fd+1, &rfds, NULL, NULL, &timeout);
if (nfds == 0) {
if (display) {
fprintf(stderr, "<drain\n");
}
break;
}
else if (nfds == -1) {
if (errno == EINTR) {
goto reselect;
}
else {
fprintf(stderr, "%s: serial_drain(): select(): %s\n",
progname, strerror(errno));
exit(1);
}
}
rc = read(fd, &buf, 1);
if (rc < 0) {
fprintf(stderr, "%s: serial_drain(): read error: %s\n",
progname, strerror(errno));
exit(1);
}
if (display) {
fprintf(stderr, "%02x ", buf);
}
}
return 0;
}

60
avrdude/ser_win32.c Normal file
View File

@@ -0,0 +1,60 @@
/*
* avrdude - A Downloader/Uploader for AVR device programmers
* Copyright (C) 2003 Theodore A. Roth <troth@openavr.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-1307 USA
*/
/* $Id$ */
/*
* Native Win32 serial interface for avrdude.
*/
#include "serial.h"
extern char *progname;
#if 0
int serial_open(char * port, long baud)
{
return fd;
}
void serial_close(int fd)
{
}
int serial_send(int fd, char * buf, size_t buflen)
{
return 0;
}
int serial_recv(int fd, char * buf, size_t buflen)
{
return 0;
}
int serial_drain(int fd, int display)
{
return 0;
}
#endif

42
avrdude/serial.h Normal file
View File

@@ -0,0 +1,42 @@
/*
* avrdude - A Downloader/Uploader for AVR device programmers
* Copyright (C) 2003 Theodore A. Roth <troth@openavr.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-1307 USA
*/
/* $Id$ */
/* This is the API for the generic serial interface. The implementations are
actually provided by the target dependant files:
ser_posix.c : posix serial interface.
ser_win32.c : native win32 serial interface.
The target file will be selected at configure time. */
#ifndef __serial_h__
#define __serial_h__
#include "config.h"
extern int serial_open(char * port, long baud);
extern void serial_close(int fd);
extern int serial_send(int fd, char * buf, size_t buflen);
extern int serial_recv(int fd, char * buf, size_t buflen);
extern int serial_drain(int fd, int display);
#endif /* __serial_h__ */

View File

@@ -33,17 +33,15 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <termios.h>
#include <sys/time.h>
#include "avr.h"
#include "pgm.h"
#include "stk500_private.h"
#include "serial.h"
extern int verbose;
extern char * progname;
extern int do_cycles;
@@ -51,153 +49,21 @@ extern int do_cycles;
static int stk500_getparm(PROGRAMMER * pgm, unsigned parm, unsigned * value);
static int stk500_send(PROGRAMMER * pgm, char * buf, int buflen)
static int stk500_send(PROGRAMMER * pgm, char * buf, size_t len)
{
struct timeval timeout;
fd_set wfds;
int nfds;
int rc;
if (!buflen)
return 0;
timeout.tv_sec = 0;
timeout.tv_usec = 500000;
while (buflen) {
FD_ZERO(&wfds);
FD_SET(pgm->fd, &wfds);
reselect:
nfds = select(pgm->fd+1, NULL, &wfds, NULL, &timeout);
if (nfds == 0) {
fprintf(stderr,
"%s: stk500_send(): programmer is not responding on %s\n",
progname, pgm->port);
exit(1);
}
else if (nfds == -1) {
if (errno == EINTR) {
goto reselect;
}
else {
fprintf(stderr, "%s: stk500_send(): select(): %s\n",
progname, strerror(errno));
exit(1);
}
}
rc = write(pgm->fd, buf, 1);
if (rc < 0) {
fprintf(stderr, "%s: stk500_send(): write error: %s\n",
progname, strerror(errno));
exit(1);
}
buf++;
buflen--;
}
return 0;
return serial_send(pgm->fd, buf, len);
}
static int stk500_recv(PROGRAMMER * pgm, char * buf, int n)
static int stk500_recv(PROGRAMMER * pgm, char * buf, size_t len)
{
struct timeval timeout;
fd_set rfds;
int nfds;
int rc;
timeout.tv_sec = 5;
timeout.tv_usec = 0;
while (n) {
FD_ZERO(&rfds);
FD_SET(pgm->fd, &rfds);
reselect:
nfds = select(pgm->fd+1, &rfds, NULL, NULL, &timeout);
if (nfds == 0) {
fprintf(stderr,
"%s: stk500_recv(): programmer is not responding on %s\n",
progname, pgm->port);
exit(1);
}
else if (nfds == -1) {
if (errno == EINTR) {
goto reselect;
}
else {
fprintf(stderr, "%s: stk500_recv(): select(): %s\n",
progname, strerror(errno));
exit(1);
}
}
rc = read(pgm->fd, buf, 1);
if (rc < 0) {
fprintf(stderr, "%s: stk500_recv(): read error: %s\n",
progname, strerror(errno));
exit(1);
}
buf++;
n--;
}
return 0;
return serial_recv(pgm->fd, buf, len);
}
static int stk500_drain(PROGRAMMER * pgm, int display)
{
struct timeval timeout;
fd_set rfds;
int nfds;
int rc;
unsigned char buf;
timeout.tv_sec = 0;
timeout.tv_usec = 250000;
if (display) {
fprintf(stderr, "drain>");
}
while (1) {
FD_ZERO(&rfds);
FD_SET(pgm->fd, &rfds);
reselect:
nfds = select(pgm->fd+1, &rfds, NULL, NULL, &timeout);
if (nfds == 0) {
if (display) {
fprintf(stderr, "<drain\n");
}
return 0;
}
else if (nfds == -1) {
if (errno == EINTR) {
goto reselect;
}
else {
fprintf(stderr, "%s: stk500_drain(): select(): %s\n",
progname, strerror(errno));
exit(1);
}
}
rc = read(pgm->fd, &buf, 1);
if (rc < 0) {
fprintf(stderr, "%s: stk500_drain(): read error: %s\n",
progname, strerror(errno));
exit(1);
}
if (display) {
fprintf(stderr, "%02x ", buf);
}
}
return serial_drain(pgm->fd, display);
}
@@ -518,7 +384,7 @@ static int stk500_initialize(PROGRAMMER * pgm, AVRPART * p)
*/
buf[0] = Cmnd_STK_SET_DEVICE;
buf[1] = p->devicecode;
buf[1] = p->stk500_devcode;
buf[2] = 0; /* device revision */
if ((p->flags & AVRPART_SERIALOK) && (p->flags & AVRPART_PARALLELOK))
@@ -739,72 +605,10 @@ static void stk500_enable(PROGRAMMER * pgm)
}
static int stk500_setattr(int fd)
{
int rc;
struct termios termios;
if (!isatty(fd))
return -1;
/*
* initialize terminal modes
*/
rc = tcgetattr(fd, &termios);
if (rc < 0) {
fprintf(stderr, "%s: stk500_setattr(): tcgetattr() failed, %s",
progname, strerror(errno));
return -errno;
}
termios.c_iflag = 0;
termios.c_oflag = 0;
termios.c_cflag = 0;
termios.c_cflag |= (CS8 | CREAD | CLOCAL);
termios.c_lflag = 0;
termios.c_cc[VMIN] = 1;
termios.c_cc[VTIME] = 0;
cfsetospeed(&termios, B115200);
cfsetispeed(&termios, B115200);
rc = tcsetattr(fd, TCSANOW, &termios);
if (rc < 0) {
fprintf(stderr, "%s: stk500_setattr(): tcsetattr() failed, %s",
progname, strerror(errno));
return -errno;
}
return 0;
}
static void stk500_open(PROGRAMMER * pgm, char * port)
{
int rc;
strcpy(pgm->port, port);
/*
* open the serial port
*/
pgm->fd = open(port, O_RDWR | O_NOCTTY /*| O_NONBLOCK*/);
if (pgm->fd < 0) {
fprintf(stderr, "%s: stk500_open(): can't open device \"%s\": %s\n",
progname, port, strerror(errno));
exit(1);
}
/*
* set serial line attributes
*/
rc = stk500_setattr(pgm->fd);
if (rc) {
fprintf(stderr,
"%s: stk500_open(): can't set attributes for device \"%s\"\n",
progname, port);
exit(1);
}
pgm->fd = serial_open(port, 115200);
/*
* drain any extraneous input
@@ -819,7 +623,7 @@ static void stk500_open(PROGRAMMER * pgm, char * port)
static void stk500_close(PROGRAMMER * pgm)
{
close(pgm->fd);
serial_close(pgm->fd);
pgm->fd = -1;
}
@@ -924,7 +728,9 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
#endif
for (addr = 0; addr < n; addr += page_size) {
fprintf(stderr, "\r \r%6u", addr);
if (verbose) {
fprintf(stderr, "\r \r%6u", addr);
}
tries = 0;
retry:
tries++;
@@ -968,8 +774,10 @@ static int stk500_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
return -5;
}
}
fprintf(stderr, "\r \r%6u", addr-1);
fprintf(stderr, "\n");
if (verbose) {
fprintf(stderr, "\r \r%6u", addr-1);
fprintf(stderr, "\n");
}
return n;
}
@@ -1014,7 +822,9 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
}
for (addr = 0; addr < n; addr += page_size) {
fprintf(stderr, "\r \r%6u", addr);
if (verbose) {
fprintf(stderr, "\r \r%6u", addr);
}
tries = 0;
retry:
tries++;
@@ -1055,8 +865,10 @@ static int stk500_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
return -5;
}
}
fprintf(stderr, "\r \r%6u", addr-1);
fprintf(stderr, "\n");
if (verbose) {
fprintf(stderr, "\r \r%6u", addr-1);
fprintf(stderr, "\n");
}
return n;
}