From 6cdc223d7d40992ce8f0d6fb8ea508abbdbb4c3d Mon Sep 17 00:00:00 2001
From: "Theodore A. Roth" <troth@openavr.org>
Date: Wed, 9 Apr 2003 20:37:28 +0000
Subject: [PATCH] * 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/avrdude@307 81a1dc3b-b13d-400b-aceb-764788c761c2
---
 ChangeLog |  6 ++++++
 avr910.c  | 12 +++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 41034de9..c2261d54 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+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
diff --git a/avr910.c b/avr910.c
index 7a5a93da..9520b51c 100644
--- a/avr910.c
+++ b/avr910.c
@@ -572,6 +572,7 @@ static int avr910_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
   int rd_size;
   unsigned int addr = 0;
   unsigned int max_addr;
+  unsigned char buf[2];
 
   if (strcmp(m->desc, "flash") == 0) {
     cmd = 'R';
@@ -591,7 +592,16 @@ static int avr910_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
 
   while (addr < max_addr) {
     avr910_send(pgm, &cmd, 1);
-    avr910_recv(pgm, &m->buf[addr], rd_size);
+    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++;