Boo0ns / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

ArduinoISP, suggestion to improve portability #509

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
ArduinoISP.pde provided with Arduino 0022, line 364

{{{
int length = 256 * getch() + getch();
}}}

With the GNU compiler, if 0x00 is received first and then 0x80 is received 
second, then this evaluates to

{{{
int length = 256 * 0x00 + 0x80;
}}}

and the result of "length" is 128 as expected

However, if this code is ported to another compiler, the following happens

{{{
int length = 256 * 0x80 + 0x00;
}}}

the result of "length" is 0x8000, which is not the expected result. This has 
caused a port of the ArduinoISP code to fail by running the for loop on line 
343 for longer than what avrdude specified, causing a timeout.

please see http://en.wikipedia.org/wiki/Sequence_point about the nature of the 
problem

"Consider two functions f() and g(). In C and C++, the + operator is not a 
sequence point, and therefore in the expression f()+g() it is possible that 
either f() or g() will be executed first."

Due to this, I plead that the next release would use something like

{{{
unsigned char higherBits = getch();
unsigned char lowerBits = getch();
int length = 256 * higherBits + lowerBits;
}}}

There are several locations where this change needs to be made, the one I 
pointed out is only one such location.

Hopefully the wiki syntaxing I used in this issue renders right, apologies if 
they don't

I posted this as a forum post 
http://arduino.cc/forum/index.php/topic,56090.0.html

Original issue reported on code.google.com by frank.zhao.main@gmail.com on 23 Mar 2011 at 12:57

GoogleCodeExporter commented 9 years ago
uint16_t length = 256 * getch(); // high byte
length += getch(); // low byte

Original comment by rsb...@gmail.com on 2 Apr 2011 at 1:51

GoogleCodeExporter commented 9 years ago
Fixed in dev version: https://github.com/rsbohn/ArduinoISP

Original comment by rsb...@gmail.com on 19 Nov 2011 at 10:50

GoogleCodeExporter commented 9 years ago
I brought in the latest version of rsbohn's code: 
https://github.com/arduino/Arduino/commit/3942e85c2c513ee773ec3a8f25308945aac8c0
2b

Original comment by dmel...@gmail.com on 28 Dec 2011 at 11:47

GoogleCodeExporter commented 9 years ago
i am trying to load Bootloader file to a new ATMega8l using using Freduino USB 
board.
While Burning Boot Loader there is error massege :
avrdude: stk500_program_enable(): protocol error, expect=0x14, resp=0x50
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

Please guide to rectify the error :
verma.bsnl@gmail.com is my email id 

Original comment by verma.b...@gmail.com on 13 Oct 2013 at 6:23

GoogleCodeExporter commented 9 years ago
similar problem i am facing like the one stated before..
kindly help me..mail me at choudhury.ani3@gmail.com

Original comment by choudhur...@gmail.com on 20 Feb 2015 at 10:19

GoogleCodeExporter commented 9 years ago
Arduino: 1.6.1 (Windows 7), Плата"ATtiny13 (internal 9.6 MHz clock)"

Selected board depends on 'arduino' core (not installed).

Original comment by ruslaniv...@gmail.com on 24 Feb 2015 at 1:20