8000 Fix warnings. Use unsigned int to represent a (word) address: the com… · arduino/Arduino@044a7b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 044a7b7

Browse files
Peter Van HoyweghenPeter Van Hoyweghen
Peter Van Hoyweghen
authored and
Peter Van Hoyweghen
committed
Fix warnings. Use unsigned int to represent a (word) address: the compiler will use the most efficient type on each platform: 32 bit on arm,
16 bit on avr which is is big enough.
1 parent d271c1c commit 044a7b7

File tree

1 file changed

+22
-34
lines changed

1 file changed

+22
-34
lines changed

build/shared/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino

Lines changed: 22 additions & 34 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@
7575

7676
#endif
7777

78-
#ifdef USE_HARDWARE_SPI
79-
#warning hw spi !!!
80-
#else
81-
#warning NOT usung hw spi
82-
#endif
83-
8478
// Configure the serial port to use.
8579
//
8680
// Prefer the USB virtual serial port (aka. native USB port), if the Arduino has one:
@@ -188,7 +182,7 @@ void setup() {
188182
int error = 0;
189183
int pmode = 0;
190184
// address for reading and writing, set by 'U' command
191-
int here;
185+
unsigned int here;
192186
uint8_t buff[256]; // global block storage
193187

194188
#define beget16(addr) (*addr * 256 + *(addr+1) )
@@ -228,8 +222,7 @@ void heartbeat() {
228222

229223
static bool rst_active_high;
230224

231-
void reset_target(bool reset)
232-
{
225+
void reset_target(bool reset) {
233226
digitalWrite(RESET, ((reset && rst_active_high) || (!reset && !rst_active_high)) ? HIGH : LOW);
234227
}
235228

@@ -281,11 +274,9 @@ void prog_lamp(int state) {
281274
}
282275

283276
uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
284-
uint8_t n;
285277
SPI.transfer(a);
286-
n = SPI.transfer(b);
287-
//if (n != a) error = -1;
288-
n = SPI.transfer(c);
278+
SPI.transfer(b);
279+
SPI.transfer(c);
289280
return SPI.transfer(d);
290281
}
291282

@@ -388,21 +379,20 @@ void end_pmode() {
388379
}
389380

390381
void universal() {
391-
int w;
392382
uint8_t ch;
393383

394384
fill(4);
395385
ch = spi_transaction(buff[0], buff[1], buff[2], buff[3]);
396386
breply(ch);
397387
}
398388

399-
void flash(uint8_t hilo, int addr, uint8_t data) {
389+
void flash(uint8_t hilo, unsigned int addr, uint8_t data) {
400390
spi_transaction(0x40 + 8 * hilo,
401391
addr >> 8 & 0xFF,
402392
addr & 0xFF,
403393
data);
404394
}
405-
void commit(int addr) {
395+
void commit(unsigned int addr) {
406396
if (PROG_FLICKER) {
407397
prog_lamp(LOW);
408398
}
@@ -413,8 +403,7 @@ void commit(int addr) {
413403
}
414404
}
415405

416-
//#define _current_page(x) (here & 0xFFFFE0)
417-
int current_page(int addr) {
406+
unsigned int current_page() {
418407
if (param.pagesize == 32) {
419408
return here & 0xFFFFFFF0;
420409
}
@@ -444,11 +433,11 @@ void write_flash(int length) {
444433

445434
uint8_t write_flash_pages(int length) {
446435
int x = 0;
447-
int page = current_page(here);
436+
unsigned int page = current_page();
448437
while (x < length) {
449-
if (page != current_page(here)) {
438+
if (page != current_page()) {
450439
commit(page);
451-
page = current_page(here);
440+
page = current_page();
452441
}
453442
flash(LOW, here, buff[x++]);
454443
flash(HIGH, here, buff[x++]);
@@ -461,10 +450,10 @@ uint8_t write_flash_pages(int length) {
461450
}
462451

463452
#define EECHUNK (32)
464-
uint8_t write_eeprom(int length) {
453+
uint8_t write_eeprom(unsigned int length) {
465454
// here is a word address, get the byte address
466-
int start = here * 2;
467-
int remaining = length;
455+
unsigned int start = here * 2;
456+
unsigned int remaining = length;
468457
if (length > param.eepromsize) {
469458
error++;
470459
return STK_FAILED;
@@ -478,13 +467,13 @@ uint8_t write_eeprom(int length) {
478467
return STK_OK;
479468
}
480469
// write (length) bytes, (start) is a byte address
481-
uint8_t write_eeprom_chunk(int start, int length) {
470+
uint8_t write_eeprom_chunk(unsigned int start, unsigned int length) {
482471
// this writes byte-by-byte,
483472
// page writing may be faster (4 bytes at a time)
484473
fill(length);
485474
prog_lamp(LOW);
486-
for (int x = 0; x < length; x++) {
487-
int addr = start + x;
475+
for (unsigned int x = 0; x < length; x++) {
476+
unsigned int addr = start + x;
488477
spi_transaction(0xC0, (addr >> 8) & 0xFF, addr & 0xFF, buff[x]);
489478
delay(45);
490479
}
@@ -494,7 +483,7 @@ uint8_t write_eeprom_chunk(int start, int length) {
494483

495484
void program_page() {
496485
char result = (char) STK_FAILED;
497-
int length = 256 * getch();
486+
unsigned int length = 256 * getch();
498487
length += getch();
499488
char memtype = getch();
500489
// flash memory @here, (length) bytes
@@ -517,7 +506,7 @@ void program_page() {
517506
return;
518507
}
519508

520-
uint8_t flash_read(uint8_t hilo, int addr) {
509+
uint8_t flash_read(uint8_t hilo, unsigned int addr) {
521510
return spi_transaction(0x20 + hilo * 8,
522511
(addr >> 8) & 0xFF,
523512
addr & 0xFF,
@@ -583,8 +572,7 @@ void read_signature() {
583572

584573
////////////////////////////////////
585574
////////////////////////////////////
586-
int avrisp() {
587-
uint8_t data, low, high;
575+
void avrisp() {
588576
uint8_t ch = getch();
589577
switch (ch) {
590578
case '0': // signon
@@ -626,12 +614,12 @@ int avrisp() {
626614
break;
627615

628616
case 0x60: //STK_PROG_FLASH
629-
low = getch();
630-
high = getch();
617+
getch(); // low addr
618+
getch(); // high addr
631619
empty_reply();
632620
break;
633621
case 0x61: //STK_PROG_DATA
634-
data = getch();
622+
getch(); // data
635623
empty_reply();
636624
break;
637625

0 commit comments

Comments
 (0)
0