1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-06 01:08:25 +01:00

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.
This commit is contained in:
Peter Van Hoyweghen 2015-07-29 21:37:04 +02:00
parent d271c1c8a2
commit 044a7b78c7

View File

@ -75,12 +75,6 @@
#endif #endif
#ifdef USE_HARDWARE_SPI
#warning hw spi !!!
#else
#warning NOT usung hw spi
#endif
// Configure the serial port to use. // Configure the serial port to use.
// //
// Prefer the USB virtual serial port (aka. native USB port), if the Arduino has one: // Prefer the USB virtual serial port (aka. native USB port), if the Arduino has one:
@ -188,7 +182,7 @@ void setup() {
int error = 0; int error = 0;
int pmode = 0; int pmode = 0;
// address for reading and writing, set by 'U' command // address for reading and writing, set by 'U' command
int here; unsigned int here;
uint8_t buff[256]; // global block storage uint8_t buff[256]; // global block storage
#define beget16(addr) (*addr * 256 + *(addr+1) ) #define beget16(addr) (*addr * 256 + *(addr+1) )
@ -228,8 +222,7 @@ void heartbeat() {
static bool rst_active_high; static bool rst_active_high;
void reset_target(bool reset) void reset_target(bool reset) {
{
digitalWrite(RESET, ((reset && rst_active_high) || (!reset && !rst_active_high)) ? HIGH : LOW); digitalWrite(RESET, ((reset && rst_active_high) || (!reset && !rst_active_high)) ? HIGH : LOW);
} }
@ -281,11 +274,9 @@ void prog_lamp(int state) {
} }
uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) { uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
uint8_t n;
SPI.transfer(a); SPI.transfer(a);
n = SPI.transfer(b); SPI.transfer(b);
//if (n != a) error = -1; SPI.transfer(c);
n = SPI.transfer(c);
return SPI.transfer(d); return SPI.transfer(d);
} }
@ -388,7 +379,6 @@ void end_pmode() {
} }
void universal() { void universal() {
int w;
uint8_t ch; uint8_t ch;
fill(4); fill(4);
@ -396,13 +386,13 @@ void universal() {
breply(ch); breply(ch);
} }
void flash(uint8_t hilo, int addr, uint8_t data) { void flash(uint8_t hilo, unsigned int addr, uint8_t data) {
spi_transaction(0x40 + 8 * hilo, spi_transaction(0x40 + 8 * hilo,
addr >> 8 & 0xFF, addr >> 8 & 0xFF,
addr & 0xFF, addr & 0xFF,
data); data);
} }
void commit(int addr) { void commit(unsigned int addr) {
if (PROG_FLICKER) { if (PROG_FLICKER) {
prog_lamp(LOW); prog_lamp(LOW);
} }
@ -413,8 +403,7 @@ void commit(int addr) {
} }
} }
//#define _current_page(x) (here & 0xFFFFE0) unsigned int current_page() {
int current_page(int addr) {
if (param.pagesize == 32) { if (param.pagesize == 32) {
return here & 0xFFFFFFF0; return here & 0xFFFFFFF0;
} }
@ -444,11 +433,11 @@ void write_flash(int length) {
uint8_t write_flash_pages(int length) { uint8_t write_flash_pages(int length) {
int x = 0; int x = 0;
int page = current_page(here); unsigned int page = current_page();
while (x < length) { while (x < length) {
if (page != current_page(here)) { if (page != current_page()) {
commit(page); commit(page);
page = current_page(here); page = current_page();
} }
flash(LOW, here, buff[x++]); flash(LOW, here, buff[x++]);
flash(HIGH, here, buff[x++]); flash(HIGH, here, buff[x++]);
@ -461,10 +450,10 @@ uint8_t write_flash_pages(int length) {
} }
#define EECHUNK (32) #define EECHUNK (32)
uint8_t write_eeprom(int length) { uint8_t write_eeprom(unsigned int length) {
// here is a word address, get the byte address // here is a word address, get the byte address
int start = here * 2; unsigned int start = here * 2;
int remaining = length; unsigned int remaining = length;
if (length > param.eepromsize) { if (length > param.eepromsize) {
error++; error++;
return STK_FAILED; return STK_FAILED;
@ -478,13 +467,13 @@ uint8_t write_eeprom(int length) {
return STK_OK; return STK_OK;
} }
// write (length) bytes, (start) is a byte address // write (length) bytes, (start) is a byte address
uint8_t write_eeprom_chunk(int start, int length) { uint8_t write_eeprom_chunk(unsigned int start, unsigned int length) {
// this writes byte-by-byte, // this writes byte-by-byte,
// page writing may be faster (4 bytes at a time) // page writing may be faster (4 bytes at a time)
fill(length); fill(length);
prog_lamp(LOW); prog_lamp(LOW);
for (int x = 0; x < length; x++) { for (unsigned int x = 0; x < length; x++) {
int addr = start + x; unsigned int addr = start + x;
spi_transaction(0xC0, (addr >> 8) & 0xFF, addr & 0xFF, buff[x]); spi_transaction(0xC0, (addr >> 8) & 0xFF, addr & 0xFF, buff[x]);
delay(45); delay(45);
} }
@ -494,7 +483,7 @@ uint8_t write_eeprom_chunk(int start, int length) {
void program_page() { void program_page() {
char result = (char) STK_FAILED; char result = (char) STK_FAILED;
int length = 256 * getch(); unsigned int length = 256 * getch();
length += getch(); length += getch();
char memtype = getch(); char memtype = getch();
// flash memory @here, (length) bytes // flash memory @here, (length) bytes
@ -517,7 +506,7 @@ void program_page() {
return; return;
} }
uint8_t flash_read(uint8_t hilo, int addr) { uint8_t flash_read(uint8_t hilo, unsigned int addr) {
return spi_transaction(0x20 + hilo * 8, return spi_transaction(0x20 + hilo * 8,
(addr >> 8) & 0xFF, (addr >> 8) & 0xFF,
addr & 0xFF, addr & 0xFF,
@ -583,8 +572,7 @@ void read_signature() {
//////////////////////////////////// ////////////////////////////////////
//////////////////////////////////// ////////////////////////////////////
int avrisp() { void avrisp() {
uint8_t data, low, high;
uint8_t ch = getch(); uint8_t ch = getch();
switch (ch) { switch (ch) {
case '0': // signon case '0': // signon
@ -626,12 +614,12 @@ int avrisp() {
break; break;
case 0x60: //STK_PROG_FLASH case 0x60: //STK_PROG_FLASH
low = getch(); getch(); // low addr
high = getch(); getch(); // high addr
empty_reply(); empty_reply();
break; break;
case 0x61: //STK_PROG_DATA case 0x61: //STK_PROG_DATA
data = getch(); getch(); // data
empty_reply(); empty_reply();
break; break;