Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
avr910.c File Reference
#include "ac_cfg.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/time.h>
#include "avrdude.h"
#include "libavrdude.h"
#include "avr910.h"
+ Include dependency graph for avr910.c:

Go to the source code of this file.

Classes

struct  pdata
 

Macros

#define PDATA(pgm)   ((struct pdata *)(pgm->cookie))
 

Functions

static void avr910_setup (PROGRAMMER *pgm)
 
static void avr910_teardown (PROGRAMMER *pgm)
 
static int avr910_send (PROGRAMMER *pgm, char *buf, size_t len)
 
static int avr910_recv (PROGRAMMER *pgm, char *buf, size_t len)
 
static int avr910_drain (PROGRAMMER *pgm, int display)
 
static int avr910_vfy_cmd_sent (PROGRAMMER *pgm, char *errmsg)
 
static int avr910_chip_erase (PROGRAMMER *pgm, AVRPART *p)
 
static int avr910_enter_prog_mode (PROGRAMMER *pgm)
 
static int avr910_leave_prog_mode (PROGRAMMER *pgm)
 
static int avr910_program_enable (PROGRAMMER *pgm, AVRPART *p)
 
static int avr910_initialize (PROGRAMMER *pgm, AVRPART *p)
 
static void avr910_disable (PROGRAMMER *pgm)
 
static void avr910_enable (PROGRAMMER *pgm)
 
static int avr910_cmd (PROGRAMMER *pgm, const unsigned char *cmd, unsigned char *res)
 
static int avr910_parseextparms (PROGRAMMER *pgm, LISTID extparms)
 
static int avr910_open (PROGRAMMER *pgm, char *port)
 
static void avr910_close (PROGRAMMER *pgm)
 
static void avr910_display (PROGRAMMER *pgm, const char *p)
 
static void avr910_set_addr (PROGRAMMER *pgm, unsigned long addr)
 
static int avr910_write_byte (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char value)
 
static int avr910_read_byte_flash (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char *value)
 
static int avr910_read_byte_eeprom (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char *value)
 
static int avr910_read_byte (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char *value)
 
static int avr910_paged_write_flash (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
 
static int avr910_paged_write_eeprom (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
 
static int avr910_paged_write (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
 
static int avr910_paged_load (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
 
static int avr910_read_sig_bytes (PROGRAMMER *pgm, AVRPART *p, AVRMEM *m)
 
void avr910_initpgm (PROGRAMMER *pgm)
 

Variables

const char avr910_desc [] = "Serial programmers using protocol described in application note AVR910"
 

Macro Definition Documentation

◆ PDATA

#define PDATA (   pgm)    ((struct pdata *)(pgm->cookie))

Function Documentation

◆ avr910_chip_erase()

static int avr910_chip_erase ( PROGRAMMER pgm,
AVRPART p 
)
static
121{
122 avr910_send(pgm, "e", 1);
123 if (avr910_vfy_cmd_sent(pgm, "chip erase") < 0)
124 return -1;
125
126 /*
127 * avr910 firmware may not delay long enough
128 */
130
131 return 0;
132}
static int avr910_vfy_cmd_sent(PROGRAMMER *pgm, char *errmsg)
Definition avr910.c:103
static int avr910_send(PROGRAMMER *pgm, char *buf, size_t len)
Definition avr910.c:77
int chip_erase_delay
Definition libavrdude.h:222
static PROGRAMMER * pgm
Definition main.c:192
int usleep(unsigned usec)
Definition unistd.cpp:13

References avr910_send(), avr910_vfy_cmd_sent(), avrpart::chip_erase_delay, pgm, and usleep().

Referenced by avr910_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_close()

static void avr910_close ( PROGRAMMER pgm)
static
390{
392
394 pgm->fd.ifd = -1;
395}
static int avr910_leave_prog_mode(PROGRAMMER *pgm)
Definition avr910.c:142
#define serial_close
Definition libavrdude.h:576
int ifd
Definition libavrdude.h:522
union filedescriptor fd
Definition libavrdude.h:637

References avr910_leave_prog_mode(), programmer_t::fd, filedescriptor::ifd, pgm, and serial_close.

Referenced by avr910_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_cmd()

static int avr910_cmd ( PROGRAMMER pgm,
const unsigned char *  cmd,
unsigned char *  res 
)
static
301{
302 char buf[5];
303
304 /* FIXME: Insert version check here */
305
306 buf[0] = '.'; /* New Universal Command */
307 buf[1] = cmd[0];
308 buf[2] = cmd[1];
309 buf[3] = cmd[2];
310 buf[4] = cmd[3];
311
312 avr910_send (pgm, buf, 5);
313 avr910_recv (pgm, buf, 2);
314
315 res[0] = 0x00; /* Dummy value */
316 res[1] = cmd[0];
317 res[2] = cmd[1];
318 res[3] = buf[0];
319
320 return 0;
321}
static int avr910_recv(PROGRAMMER *pgm, char *buf, size_t len)
Definition avr910.c:83
struct command cmd[]
Definition term.c:94

References avr910_recv(), avr910_send(), cmd, and pgm.

Referenced by avr910_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_disable()

static void avr910_disable ( PROGRAMMER pgm)
static
280{
281 /* Do nothing. */
282
283 return;
284}

Referenced by avr910_initpgm().

+ Here is the caller graph for this function:

◆ avr910_display()

static void avr910_display ( PROGRAMMER pgm,
const char *  p 
)
static
399{
400 return;
401}

Referenced by avr910_initpgm().

+ Here is the caller graph for this function:

◆ avr910_drain()

static int avr910_drain ( PROGRAMMER pgm,
int  display 
)
static
98{
99 return serial_drain(&pgm->fd, display);
100}
#define serial_drain
Definition libavrdude.h:579

References programmer_t::fd, pgm, and serial_drain.

Referenced by avr910_open().

+ Here is the caller graph for this function:

◆ avr910_enable()

static void avr910_enable ( PROGRAMMER pgm)
static
288{
289 /* Do nothing. */
290
291 return;
292}

Referenced by avr910_initpgm().

+ Here is the caller graph for this function:

◆ avr910_enter_prog_mode()

static int avr910_enter_prog_mode ( PROGRAMMER pgm)
static
136{
137 avr910_send(pgm, "P", 1);
138 return avr910_vfy_cmd_sent(pgm, "enter prog mode");
139}

References avr910_send(), avr910_vfy_cmd_sent(), and pgm.

Referenced by avr910_initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_initialize()

static int avr910_initialize ( PROGRAMMER pgm,
AVRPART p 
)
static
162{
163 char id[8];
164 char sw[2];
165 char hw[2];
166 char buf[10];
167 char type;
168 char c;
169 AVRPART * part;
170
171 /* Get the programmer identifier. Programmer returns exactly 7 chars
172 _without_ the null.*/
173
174 avr910_send(pgm, "S", 1);
175 memset (id, 0, sizeof(id));
176 avr910_recv(pgm, id, sizeof(id)-1);
177
178 /* Get the HW and SW versions to see if the programmer is present. */
179
180 avr910_send(pgm, "V", 1);
181 avr910_recv(pgm, sw, sizeof(sw));
182
183 avr910_send(pgm, "v", 1);
184 avr910_recv(pgm, hw, sizeof(hw));
185
186 /* Get the programmer type (serial or parallel). Expect serial. */
187
188 avr910_send(pgm, "p", 1);
189 avr910_recv(pgm, &type, 1);
190
191 avrdude_message(MSG_INFO, "Found programmer: Id = \"%s\"; type = %c\n", id, type);
192 avrdude_message(MSG_INFO, " Software Version = %c.%c; ", sw[0], sw[1]);
193 avrdude_message(MSG_INFO, "Hardware Version = %c.%c\n", hw[0], hw[1]);
194
195 /* See if programmer supports autoincrement of address. */
196
197 avr910_send(pgm, "a", 1);
198 avr910_recv(pgm, &PDATA(pgm)->has_auto_incr_addr, 1);
199 if (PDATA(pgm)->has_auto_incr_addr == 'Y')
200 avrdude_message(MSG_INFO, "Programmer supports auto addr increment.\n");
201
202 /* Check support for buffered memory access, ignore if not available */
203
204 if (PDATA(pgm)->test_blockmode == 1) {
205 avr910_send(pgm, "b", 1);
206 avr910_recv(pgm, &c, 1);
207 if (c == 'Y') {
208 avr910_recv(pgm, &c, 1);
209 PDATA(pgm)->buffersize = (unsigned int)(unsigned char)c<<8;
210 avr910_recv(pgm, &c, 1);
211 PDATA(pgm)->buffersize += (unsigned int)(unsigned char)c;
212 avrdude_message(MSG_INFO, "Programmer supports buffered memory access with "
213 "buffersize = %u bytes.\n",
214 PDATA(pgm)->buffersize);
215 PDATA(pgm)->use_blockmode = 1;
216 } else {
217 PDATA(pgm)->use_blockmode = 0;
218 }
219 } else {
220 PDATA(pgm)->use_blockmode = 0;
221 }
222
223 if (PDATA(pgm)->devcode == 0) {
224 char devtype_1st;
225 int dev_supported = 0;
226
227 /* Get list of devices that the programmer supports. */
228
229 avr910_send(pgm, "t", 1);
230 avrdude_message(MSG_INFO, "\nProgrammer supports the following devices:\n");
231 devtype_1st = 0;
232 while (1) {
233 avr910_recv(pgm, &c, 1);
234 if (devtype_1st == 0)
235 devtype_1st = c;
236 if (c == 0)
237 break;
239
240 avrdude_message(MSG_INFO, " Device code: 0x%02x = %s\n", c, part ? part->desc : "(unknown)");
241
242 /* FIXME: Need to lookup devcode and report the device. */
243
244 if (p->avr910_devcode == c)
245 dev_supported = 1;
246 };
248
249 if (!dev_supported) {
250 avrdude_message(MSG_INFO, "%s: %s: selected device is not supported by programmer: %s\n",
251 progname, ovsigck? "warning": "error", p->id);
252 if (!ovsigck)
253 return -1;
254 }
255 /* If the user forced the selection, use the first device
256 type that is supported by the programmer. */
257 buf[1] = ovsigck? devtype_1st: p->avr910_devcode;
258 } else {
259 /* devcode overridden by -x devcode= option */
260 buf[1] = (char)(PDATA(pgm)->devcode);
261 }
262
263 /* Tell the programmer which part we selected. */
264 buf[0] = 'T';
265 /* buf[1] has been set up above */
266
267 avr910_send(pgm, buf, 2);
268 avr910_vfy_cmd_sent(pgm, "select device");
269
270 avrdude_message(MSG_NOTICE, "%s: avr910_devcode selected: 0x%02x\n",
271 progname, (unsigned)buf[1]);
272
274
275 return 0;
276}
static int avr910_enter_prog_mode(PROGRAMMER *pgm)
Definition avr910.c:135
#define PDATA(pgm)
Definition avr910.c:58
int ovsigck
Definition main.c:200
#define MSG_INFO
Definition avrdude.h:51
char * progname
Definition main.c:61
#define MSG_NOTICE
Definition avrdude.h:52
int avrdude_message(const int msglvl, const char *format,...)
Definition main.c:93
AVRPART * locate_part_by_avr910_devcode(LISTID parts, int devcode)
Definition avrpart.c:535
LISTID part_list
Definition config.c:51
char desc[AVR_DESCLEN]
Definition libavrdude.h:218
int avr910_devcode
Definition libavrdude.h:221
Definition libavrdude.h:217

References avrpart::avr910_devcode, avr910_enter_prog_mode(), avr910_recv(), avr910_send(), avr910_vfy_cmd_sent(), avrdude_message(), avrpart::desc, avrpart::id, locate_part_by_avr910_devcode(), MSG_INFO, MSG_NOTICE, ovsigck, part_list, PDATA, pgm, and progname.

Referenced by avr910_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_initpgm()

void avr910_initpgm ( PROGRAMMER pgm)
746{
747 strcpy(pgm->type, "avr910");
748
749 /*
750 * mandatory functions
751 */
758 pgm->cmd = avr910_cmd;
761
762 /*
763 * optional functions
764 */
765
768
771
773
777}
static int avr910_read_sig_bytes(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m)
Definition avr910.c:724
static int avr910_initialize(PROGRAMMER *pgm, AVRPART *p)
Definition avr910.c:161
static void avr910_close(PROGRAMMER *pgm)
Definition avr910.c:389
static void avr910_display(PROGRAMMER *pgm, const char *p)
Definition avr910.c:398
static void avr910_enable(PROGRAMMER *pgm)
Definition avr910.c:287
static void avr910_teardown(PROGRAMMER *pgm)
Definition avr910.c:71
static int avr910_paged_write(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
Definition avr910.c:587
static int avr910_chip_erase(PROGRAMMER *pgm, AVRPART *p)
Definition avr910.c:120
static int avr910_open(PROGRAMMER *pgm, char *port)
Definition avr910.c:365
static int avr910_read_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char *value)
Definition avr910.c:484
static int avr910_paged_load(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
Definition avr910.c:647
static int avr910_write_byte(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char value)
Definition avr910.c:417
static int avr910_program_enable(PROGRAMMER *pgm, AVRPART *p)
Definition avr910.c:152
static int avr910_cmd(PROGRAMMER *pgm, const unsigned char *cmd, unsigned char *res)
Definition avr910.c:299
static void avr910_disable(PROGRAMMER *pgm)
Definition avr910.c:279
static void avr910_setup(PROGRAMMER *pgm)
Definition avr910.c:60
static int avr910_parseextparms(PROGRAMMER *pgm, LISTID extparms)
Definition avr910.c:324
void(* display)(struct programmer_t *pgm, const char *p)
Definition libavrdude.h:644
int(* paged_write)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int baseaddr, unsigned int n_bytes)
Definition libavrdude.h:659
int(* read_sig_bytes)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m)
Definition libavrdude.h:672
int(* open)(struct programmer_t *pgm, char *port)
Definition libavrdude.h:657
int(* read_byte)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char *value)
Definition libavrdude.h:670
int(* paged_load)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int baseaddr, unsigned int n_bytes)
Definition libavrdude.h:662
void(* teardown)(struct programmer_t *pgm)
Definition libavrdude.h:685
int(* cmd)(struct programmer_t *pgm, const unsigned char *cmd, unsigned char *res)
Definition libavrdude.h:651
int(* parseextparams)(struct programmer_t *pgm, LISTID xparams)
Definition libavrdude.h:683
void(* enable)(struct programmer_t *pgm)
Definition libavrdude.h:645
int(* program_enable)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:649
int(* write_byte)(struct programmer_t *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char value)
Definition libavrdude.h:668
void(* setup)(struct programmer_t *pgm)
Definition libavrdude.h:684
char type[PGM_TYPELEN]
Definition libavrdude.h:619
int(* initialize)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:643
void(* close)(struct programmer_t *pgm)
Definition libavrdude.h:658
int(* chip_erase)(struct programmer_t *pgm, AVRPART *p)
Definition libavrdude.h:650
void(* disable)(struct programmer_t *pgm)
Definition libavrdude.h:646

References avr910_chip_erase(), avr910_close(), avr910_cmd(), avr910_disable(), avr910_display(), avr910_enable(), avr910_initialize(), avr910_open(), avr910_paged_load(), avr910_paged_write(), avr910_parseextparms(), avr910_program_enable(), avr910_read_byte(), avr910_read_sig_bytes(), avr910_setup(), avr910_teardown(), avr910_write_byte(), programmer_t::chip_erase, programmer_t::close, programmer_t::cmd, programmer_t::disable, programmer_t::display, programmer_t::enable, programmer_t::initialize, programmer_t::open, programmer_t::paged_load, programmer_t::paged_write, programmer_t::parseextparams, pgm, programmer_t::program_enable, programmer_t::read_byte, programmer_t::read_sig_bytes, programmer_t::setup, programmer_t::teardown, programmer_t::type, and programmer_t::write_byte.

+ Here is the call graph for this function:

◆ avr910_leave_prog_mode()

static int avr910_leave_prog_mode ( PROGRAMMER pgm)
static
143{
144 avr910_send(pgm, "L", 1);
145 return avr910_vfy_cmd_sent(pgm, "leave prog mode");
146}

References avr910_send(), avr910_vfy_cmd_sent(), and pgm.

Referenced by avr910_close().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_open()

static int avr910_open ( PROGRAMMER pgm,
char *  port 
)
static
366{
367 union pinfo pinfo;
368 /*
369 * If baudrate was not specified use 19.200 Baud
370 */
371 if(pgm->baudrate == 0) {
372 pgm->baudrate = 19200;
373 }
374
375 strcpy(pgm->port, port);
377 if (serial_open(port, pinfo, &pgm->fd)==-1) {
378 return -1;
379 }
380
381 /*
382 * drain any extraneous input
383 */
384 avr910_drain (pgm, 0);
385
386 return 0;
387}
static int avr910_drain(PROGRAMMER *pgm, int display)
Definition avr910.c:97
#define serial_open
Definition libavrdude.h:574
long baud
Definition libavrdude.h:537
Definition libavrdude.h:536
char port[PGM_PORTLEN]
Definition libavrdude.h:620
int baudrate
Definition libavrdude.h:630

References avr910_drain(), pinfo::baud, programmer_t::baudrate, programmer_t::fd, pgm, programmer_t::port, and serial_open.

Referenced by avr910_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_paged_load()

static int avr910_paged_load ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  page_size,
unsigned int  addr,
unsigned int  n_bytes 
)
static
650{
651 char cmd[4];
652 int rd_size;
653 unsigned int max_addr;
654 char buf[2];
655 int rval=0;
656
657 max_addr = addr + n_bytes;
658
659 if (strcmp(m->desc, "flash") == 0) {
660 cmd[0] = 'R';
661 rd_size = 2; /* read two bytes per addr */
662 } else if (strcmp(m->desc, "eeprom") == 0) {
663 cmd[0] = 'd';
664 rd_size = 1;
665 } else {
666 return -2;
667 }
668
669 if (PDATA(pgm)->use_blockmode) {
670 /* use buffered mode */
671 int blocksize = PDATA(pgm)->buffersize;
672
673 cmd[0] = 'g';
674 cmd[3] = toupper((int)(m->desc[0]));
675
676 avr910_set_addr(pgm, addr / rd_size);
677
678 while (addr < max_addr) {
679 if ((max_addr - addr) < (unsigned)blocksize) {
680 blocksize = max_addr - addr;
681 }
682 cmd[1] = (blocksize >> 8) & 0xff;
683 cmd[2] = blocksize & 0xff;
684
685 avr910_send(pgm, cmd, 4);
686 avr910_recv(pgm, (char *)&m->buf[addr], blocksize);
687
688 addr += blocksize;
689 }
690
691 rval = addr;
692 } else {
693
694 avr910_set_addr(pgm, addr / rd_size);
695
696 while (addr < max_addr) {
697 avr910_send(pgm, cmd, 1);
698 if (rd_size == 2) {
699 /* The 'R' command returns two bytes, MSB first, we need to put the data
700 into the memory buffer LSB first. */
701 avr910_recv(pgm, buf, 2);
702 m->buf[addr] = buf[1]; /* LSB */
703 m->buf[addr + 1] = buf[0]; /* MSB */
704 }
705 else {
706 avr910_recv(pgm, (char *)&m->buf[addr], 1);
707 }
708
709 addr += rd_size;
710
711 if (PDATA(pgm)->has_auto_incr_addr != 'Y') {
712 avr910_set_addr(pgm, addr / rd_size);
713 }
714 }
715
716 rval = addr;
717 }
718
719 return rval;
720}
static void avr910_set_addr(PROGRAMMER *pgm, unsigned long addr)
Definition avr910.c:404
unsigned char * buf
Definition libavrdude.h:304
char desc[AVR_MEMDESCLEN]
Definition libavrdude.h:284

References avr910_recv(), avr910_send(), avr910_set_addr(), avrmem::buf, cmd, avrmem::desc, PDATA, and pgm.

Referenced by avr910_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_paged_write()

static int avr910_paged_write ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  page_size,
unsigned int  addr,
unsigned int  n_bytes 
)
static
590{
591 int rval = 0;
592 if (PDATA(pgm)->use_blockmode == 0) {
593 if (strcmp(m->desc, "flash") == 0) {
594 rval = avr910_paged_write_flash(pgm, p, m, page_size, addr, n_bytes);
595 } else if (strcmp(m->desc, "eeprom") == 0) {
596 rval = avr910_paged_write_eeprom(pgm, p, m, page_size, addr, n_bytes);
597 } else {
598 rval = -2;
599 }
600 }
601
602 if (PDATA(pgm)->use_blockmode == 1) {
603 unsigned int max_addr = addr + n_bytes;
604 char *cmd;
605 unsigned int blocksize = PDATA(pgm)->buffersize;
606 int wr_size;
607
608 if (strcmp(m->desc, "flash") && strcmp(m->desc, "eeprom"))
609 return -2;
610
611 if (m->desc[0] == 'e') {
612 blocksize = 1; /* Write to eeprom single bytes only */
613 wr_size = 1;
614 } else {
615 wr_size = 2;
616 }
617
618 avr910_set_addr(pgm, addr / wr_size);
619
620 cmd = malloc(4 + blocksize);
621 if (!cmd) return -1;
622
623 cmd[0] = 'B';
624 cmd[3] = toupper((int)(m->desc[0]));
625
626 while (addr < max_addr) {
627 if ((max_addr - addr) < blocksize) {
628 blocksize = max_addr - addr;
629 };
630 memcpy(&cmd[4], &m->buf[addr], blocksize);
631 cmd[1] = (blocksize >> 8) & 0xff;
632 cmd[2] = blocksize & 0xff;
633
634 avr910_send(pgm, cmd, 4 + blocksize);
635 avr910_vfy_cmd_sent(pgm, "write block");
636
637 addr += blocksize;
638 } /* while */
639 free(cmd);
640
641 rval = addr;
642 }
643 return rval;
644}
static int avr910_paged_write_eeprom(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
Definition avr910.c:558
static int avr910_paged_write_flash(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned int page_size, unsigned int addr, unsigned int n_bytes)
Definition avr910.c:499
void * malloc(YYSIZE_T)
void free(void *)

References avr910_paged_write_eeprom(), avr910_paged_write_flash(), avr910_send(), avr910_set_addr(), avr910_vfy_cmd_sent(), avrmem::buf, cmd, avrmem::desc, free(), malloc(), PDATA, and pgm.

Referenced by avr910_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_paged_write_eeprom()

static int avr910_paged_write_eeprom ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  page_size,
unsigned int  addr,
unsigned int  n_bytes 
)
static
562{
563 char cmd[2];
564 unsigned int max_addr = addr + n_bytes;
565
566 avr910_set_addr(pgm, addr);
567
568 cmd[0] = 'D';
569
570 while (addr < max_addr) {
571 cmd[1] = m->buf[addr];
572 avr910_send(pgm, cmd, sizeof(cmd));
573 avr910_vfy_cmd_sent(pgm, "write byte");
575
576 addr++;
577
578 if (PDATA(pgm)->has_auto_incr_addr != 'Y') {
579 avr910_set_addr(pgm, addr);
580 }
581 }
582
583 return addr;
584}
int max_write_delay
Definition libavrdude.h:291

References avr910_send(), avr910_set_addr(), avr910_vfy_cmd_sent(), avrmem::buf, cmd, avrmem::max_write_delay, PDATA, pgm, and usleep().

Referenced by avr910_paged_write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_paged_write_flash()

static int avr910_paged_write_flash ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned int  page_size,
unsigned int  addr,
unsigned int  n_bytes 
)
static
502{
503 unsigned char cmd[] = {'c', 'C'};
504 char buf[2];
505 unsigned int max_addr = addr + n_bytes;
506 unsigned int page_addr;
507 int page_bytes = page_size;
508 int page_wr_cmd_pending = 0;
509
510 page_addr = addr;
511 avr910_set_addr(pgm, addr>>1);
512
513 while (addr < max_addr) {
514 page_wr_cmd_pending = 1;
515 buf[0] = cmd[addr & 0x01];
516 buf[1] = m->buf[addr];
517 avr910_send(pgm, buf, sizeof(buf));
518 avr910_vfy_cmd_sent(pgm, "write byte");
519
520 addr++;
521 page_bytes--;
522
523 if (m->paged && (page_bytes == 0)) {
524 /* Send the "Issue Page Write" if we have sent a whole page. */
525
526 avr910_set_addr(pgm, page_addr>>1);
527 avr910_send(pgm, "m", 1);
528 avr910_vfy_cmd_sent(pgm, "flush page");
529
530 page_wr_cmd_pending = 0;
532 avr910_set_addr(pgm, addr>>1);
533
534 /* Set page address for next page. */
535
536 page_addr = addr;
537 page_bytes = page_size;
538 }
539 else if ((PDATA(pgm)->has_auto_incr_addr != 'Y') && ((addr & 0x01) == 0)) {
540 avr910_set_addr(pgm, addr>>1);
541 }
542 }
543
544 /* If we didn't send the page wr cmd after the last byte written in the
545 loop, send it now. */
546
547 if (page_wr_cmd_pending) {
548 avr910_set_addr(pgm, page_addr>>1);
549 avr910_send(pgm, "m", 1);
550 avr910_vfy_cmd_sent(pgm, "flush final page");
552 }
553
554 return addr;
555}
int paged
Definition libavrdude.h:285

References avr910_send(), avr910_set_addr(), avr910_vfy_cmd_sent(), avrmem::buf, cmd, avrmem::max_write_delay, avrmem::paged, PDATA, pgm, and usleep().

Referenced by avr910_paged_write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_parseextparms()

static int avr910_parseextparms ( PROGRAMMER pgm,
LISTID  extparms 
)
static
325{
326 LNODEID ln;
327 const char *extended_param;
328 int rv = 0;
329
330 for (ln = lfirst(extparms); ln; ln = lnext(ln)) {
331 extended_param = ldata(ln);
332
333 if (strncmp(extended_param, "devcode=", strlen("devcode=")) == 0) {
334 int devcode;
335 if (sscanf(extended_param, "devcode=%i", &devcode) != 1 ||
336 devcode <= 0 || devcode > 255) {
337 avrdude_message(MSG_INFO, "%s: avr910_parseextparms(): invalid devcode '%s'\n",
338 progname, extended_param);
339 rv = -1;
340 continue;
341 }
342 avrdude_message(MSG_NOTICE2, "%s: avr910_parseextparms(): devcode overwritten as 0x%02x\n",
343 progname, devcode);
344 PDATA(pgm)->devcode = devcode;
345
346 continue;
347 }
348 if (strncmp(extended_param, "no_blockmode", strlen("no_blockmode")) == 0) {
349 avrdude_message(MSG_NOTICE2, "%s: avr910_parseextparms(-x): no testing for Blockmode\n",
350 progname);
351 PDATA(pgm)->test_blockmode = 0;
352
353 continue;
354 }
355
356 avrdude_message(MSG_INFO, "%s: avr910_parseextparms(): invalid extended parameter '%s'\n",
357 progname, extended_param);
358 rv = -1;
359 }
360
361 return rv;
362}
#define MSG_NOTICE2
Definition avrdude.h:53
void * ldata(LNODEID)
Definition lists.c:720
void * LNODEID
Definition libavrdude.h:64
LNODEID lnext(LNODEID)
Definition lists.c:704
LNODEID lfirst(LISTID)
Definition lists.c:688

References avrdude_message(), ldata(), lfirst(), lnext(), MSG_INFO, MSG_NOTICE2, PDATA, pgm, and progname.

Referenced by avr910_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_program_enable()

static int avr910_program_enable ( PROGRAMMER pgm,
AVRPART p 
)
static
153{
154 return -1;
155}

Referenced by avr910_initpgm().

+ Here is the caller graph for this function:

◆ avr910_read_byte()

static int avr910_read_byte ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned long  addr,
unsigned char *  value 
)
static
486{
487 if (strcmp(m->desc, "flash") == 0) {
488 return avr910_read_byte_flash(pgm, p, m, addr, value);
489 }
490
491 if (strcmp(m->desc, "eeprom") == 0) {
492 return avr910_read_byte_eeprom(pgm, p, m, addr, value);
493 }
494
495 return avr_read_byte_default(pgm, p, m, addr, value);
496}
static int avr910_read_byte_flash(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char *value)
Definition avr910.c:450
static int avr910_read_byte_eeprom(PROGRAMMER *pgm, AVRPART *p, AVRMEM *m, unsigned long addr, unsigned char *value)
Definition avr910.c:473
int avr_read_byte_default(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char *value)
Definition avr.c:183

References avr910_read_byte_eeprom(), avr910_read_byte_flash(), avr_read_byte_default(), avrmem::desc, and pgm.

Referenced by avr910_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_read_byte_eeprom()

static int avr910_read_byte_eeprom ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned long  addr,
unsigned char *  value 
)
static
475{
476 avr910_set_addr(pgm, addr);
477 avr910_send(pgm, "d", 1);
478 avr910_recv(pgm, (char *)value, 1);
479
480 return 0;
481}

References avr910_recv(), avr910_send(), avr910_set_addr(), and pgm.

Referenced by avr910_read_byte().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_read_byte_flash()

static int avr910_read_byte_flash ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned long  addr,
unsigned char *  value 
)
static
452{
453 char buf[2];
454
455 avr910_set_addr(pgm, addr >> 1);
456
457 avr910_send(pgm, "R", 1);
458
459 /* Read back the program mem word (MSB first) */
460 avr910_recv(pgm, buf, sizeof(buf));
461
462 if ((addr & 0x01) == 0) {
463 *value = buf[1];
464 }
465 else {
466 *value = buf[0];
467 }
468
469 return 0;
470}

References avr910_recv(), avr910_send(), avr910_set_addr(), and pgm.

Referenced by avr910_read_byte().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_read_sig_bytes()

static int avr910_read_sig_bytes ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m 
)
static
725{
726 unsigned char tmp;
727
728 if (m->size < 3) {
729 avrdude_message(MSG_INFO, "%s: memsize too small for sig byte read", progname);
730 return -1;
731 }
732
733 avr910_send(pgm, "s", 1);
734 avr910_recv(pgm, (char *)m->buf, 3);
735 /* Returned signature has wrong order. */
736 tmp = m->buf[2];
737 m->buf[2] = m->buf[0];
738 m->buf[0] = tmp;
739
740 return 3;
741}
int size
Definition libavrdude.h:286

References avr910_recv(), avr910_send(), avrdude_message(), avrmem::buf, MSG_INFO, pgm, progname, and avrmem::size.

Referenced by avr910_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_recv()

static int avr910_recv ( PROGRAMMER pgm,
char *  buf,
size_t  len 
)
static
84{
85 int rv;
86
87 rv = serial_recv(&pgm->fd, (unsigned char *)buf, len);
88 if (rv < 0) {
89 avrdude_message(MSG_INFO, "%s: avr910_recv(): programmer is not responding\n",
90 progname);
91 return 1;
92 }
93 return 0;
94}
#define serial_recv
Definition libavrdude.h:578

References avrdude_message(), programmer_t::fd, MSG_INFO, pgm, progname, and serial_recv.

Referenced by avr910_cmd(), avr910_initialize(), avr910_paged_load(), avr910_read_byte_eeprom(), avr910_read_byte_flash(), avr910_read_sig_bytes(), and avr910_vfy_cmd_sent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_send()

static int avr910_send ( PROGRAMMER pgm,
char *  buf,
size_t  len 
)
static
78{
79 return serial_send(&pgm->fd, (unsigned char *)buf, len);
80}
#define serial_send
Definition libavrdude.h:577

References programmer_t::fd, pgm, and serial_send.

Referenced by avr910_chip_erase(), avr910_cmd(), avr910_enter_prog_mode(), avr910_initialize(), avr910_leave_prog_mode(), avr910_paged_load(), avr910_paged_write(), avr910_paged_write_eeprom(), avr910_paged_write_flash(), avr910_read_byte_eeprom(), avr910_read_byte_flash(), avr910_read_sig_bytes(), avr910_set_addr(), and avr910_write_byte().

+ Here is the caller graph for this function:

◆ avr910_set_addr()

static void avr910_set_addr ( PROGRAMMER pgm,
unsigned long  addr 
)
static
405{
406 char cmd[3];
407
408 cmd[0] = 'A';
409 cmd[1] = (addr >> 8) & 0xff;
410 cmd[2] = addr & 0xff;
411
412 avr910_send(pgm, cmd, sizeof(cmd));
413 avr910_vfy_cmd_sent(pgm, "set addr");
414}

References avr910_send(), avr910_vfy_cmd_sent(), cmd, and pgm.

Referenced by avr910_paged_load(), avr910_paged_write(), avr910_paged_write_eeprom(), avr910_paged_write_flash(), avr910_read_byte_eeprom(), avr910_read_byte_flash(), and avr910_write_byte().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_setup()

static void avr910_setup ( PROGRAMMER pgm)
static
61{
62 if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
63 avrdude_message(MSG_INFO, "%s: avr910_setup(): Out of memory allocating private data\n",
64 progname);
65 exit(1);
66 }
67 memset(pgm->cookie, 0, sizeof(struct pdata));
68 PDATA(pgm)->test_blockmode = 1;
69}
Definition avr910.c:50
void * cookie
Definition libavrdude.h:689

References avrdude_message(), programmer_t::cookie, malloc(), MSG_INFO, PDATA, pgm, and progname.

Referenced by avr910_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_teardown()

static void avr910_teardown ( PROGRAMMER pgm)
static
72{
73 free(pgm->cookie);
74}

References programmer_t::cookie, free(), and pgm.

Referenced by avr910_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_vfy_cmd_sent()

static int avr910_vfy_cmd_sent ( PROGRAMMER pgm,
char *  errmsg 
)
static
104{
105 char c;
106
107 avr910_recv(pgm, &c, 1);
108 if (c != '\r') {
109 avrdude_message(MSG_INFO, "%s: error: programmer did not respond to command: %s\n",
110 progname, errmsg);
111 return 1;
112 }
113 return 0;
114}

References avr910_recv(), avrdude_message(), MSG_INFO, pgm, and progname.

Referenced by avr910_chip_erase(), avr910_enter_prog_mode(), avr910_initialize(), avr910_leave_prog_mode(), avr910_paged_write(), avr910_paged_write_eeprom(), avr910_paged_write_flash(), avr910_set_addr(), and avr910_write_byte().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ avr910_write_byte()

static int avr910_write_byte ( PROGRAMMER pgm,
AVRPART p,
AVRMEM m,
unsigned long  addr,
unsigned char  value 
)
static
419{
420 char cmd[2];
421
422 if (strcmp(m->desc, "flash") == 0) {
423 if (addr & 0x01) {
424 cmd[0] = 'C'; /* Write Program Mem high byte */
425 }
426 else {
427 cmd[0] = 'c';
428 }
429
430 addr >>= 1;
431 }
432 else if (strcmp(m->desc, "eeprom") == 0) {
433 cmd[0] = 'D';
434 }
435 else {
436 return avr_write_byte_default(pgm, p, m, addr, value);
437 }
438
439 cmd[1] = value;
440
441 avr910_set_addr(pgm, addr);
442
443 avr910_send(pgm, cmd, sizeof(cmd));
444 avr910_vfy_cmd_sent(pgm, "write byte");
445
446 return 0;
447}
int avr_write_byte_default(PROGRAMMER *pgm, AVRPART *p, AVRMEM *mem, unsigned long addr, unsigned char data)
Definition avr.c:530

References avr910_send(), avr910_set_addr(), avr910_vfy_cmd_sent(), avr_write_byte_default(), cmd, avrmem::desc, and pgm.

Referenced by avr910_initpgm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ avr910_desc

const char avr910_desc[] = "Serial programmers using protocol described in application note AVR910"