From 5b83043290d5521db1c6958042afffd955c1274e Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 18 Feb 2014 20:16:08 +0100 Subject: [PATCH 01/12] Include stdint.h from IPAddress.h on SAM This happened for AVR in 34885b01, this commit makes the SAM version identical again. --- hardware/arduino/sam/cores/arduino/IPAddress.h | 1 + 1 file changed, 1 insertion(+) diff --git a/hardware/arduino/sam/cores/arduino/IPAddress.h b/hardware/arduino/sam/cores/arduino/IPAddress.h index 622efb76051..6ea81273caf 100644 --- a/hardware/arduino/sam/cores/arduino/IPAddress.h +++ b/hardware/arduino/sam/cores/arduino/IPAddress.h @@ -20,6 +20,7 @@ #ifndef IPAddress_h #define IPAddress_h +#include #include // A class to make it easier to handle and pass around IP addresses From 9dca56dced68cd71a467809a8ed5ccfe079330c3 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 19 Feb 2014 16:07:07 +0100 Subject: [PATCH 02/12] Don't use IPAddress::_address from EthernetClass EthernetClass is a friend class of IPAddress, so it is allowed to use its _address attribute directly. However, it should be using IPAddress::raw_address() instead, like all the other friend classes do. This changes allows changing the _address attribute to fix some warnings next. --- libraries/Ethernet/src/Ethernet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/Ethernet/src/Ethernet.cpp b/libraries/Ethernet/src/Ethernet.cpp index 8b5935eb7b3..0f9effb1a14 100644 --- a/libraries/Ethernet/src/Ethernet.cpp +++ b/libraries/Ethernet/src/Ethernet.cpp @@ -62,9 +62,9 @@ void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server { W5100.init(); W5100.setMACAddress(mac); - W5100.setIPAddress(local_ip._address); - W5100.setGatewayIp(gateway._address); - W5100.setSubnetMask(subnet._address); + W5100.setIPAddress(local_ip.raw_address()); + W5100.setGatewayIp(gateway.raw_address()); + W5100.setSubnetMask(subnet.raw_address()); _dnsServerAddress = dns_server; } From 3035239a4ee0b9e7a4a22264f7cebd6e7db8d7bc Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 18 Feb 2014 18:11:22 +0100 Subject: [PATCH 03/12] Use a union in IPAddress for uint8_t[] <-> uint32_t conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, pointer casting was used, but this resulted in strict-aliasing warnings: IPAddress.h: In member function ‘IPAddress::operator uint32_t() const’: IPAddress.h:46:61: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] operator uint32_t() const { return *((uint32_t*)_address); }; ^ IPAddress.h: In member function ‘bool IPAddress::operator==(const IPAddress&) const’: IPAddress.h:47:81: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] bool operator==(const IPAddress& addr) const { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); }; ^ IPAddress.h:47:114: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] bool operator==(const IPAddress& addr) const { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); }; Converting between unrelated types like this is commonly done using a union, which do not break the strict-aliasing rules. Using that union, inside IPAddress there is now an attribute _address.bytes for the raw byte arra, or _address.dword for the uint32_t version. Since we now have easy access to the uint32_t version, this also removes two memcpy invocations that can just become assignments. This patch does not change the generated code in any way, the compiler already optimized away the memcpy calls and the previous casts mean exactly the same. This is a different implementation of a part of #1399 and it helps toward fixing #1728. --- .../arduino/avr/cores/arduino/IPAddress.cpp | 24 +++++++++---------- .../arduino/avr/cores/arduino/IPAddress.h | 16 ++++++++----- .../arduino/sam/cores/arduino/IPAddress.cpp | 24 +++++++++---------- .../arduino/sam/cores/arduino/IPAddress.h | 16 ++++++++----- 4 files changed, 44 insertions(+), 36 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/IPAddress.cpp b/hardware/arduino/avr/cores/arduino/IPAddress.cpp index 22a0e427187..899cbd4eda8 100644 --- a/hardware/arduino/avr/cores/arduino/IPAddress.cpp +++ b/hardware/arduino/avr/cores/arduino/IPAddress.cpp @@ -22,42 +22,42 @@ IPAddress::IPAddress() { - memset(_address, 0, sizeof(_address)); + _address.dword = 0; } IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) { - _address[0] = first_octet; - _address[1] = second_octet; - _address[2] = third_octet; - _address[3] = fourth_octet; + _address.bytes[0] = first_octet; + _address.bytes[1] = second_octet; + _address.bytes[2] = third_octet; + _address.bytes[3] = fourth_octet; } IPAddress::IPAddress(uint32_t address) { - memcpy(_address, &address, sizeof(_address)); + _address.dword = address; } IPAddress::IPAddress(const uint8_t *address) { - memcpy(_address, address, sizeof(_address)); + memcpy(_address.bytes, address, sizeof(_address.bytes)); } IPAddress& IPAddress::operator=(const uint8_t *address) { - memcpy(_address, address, sizeof(_address)); + memcpy(_address.bytes, address, sizeof(_address.bytes)); return *this; } IPAddress& IPAddress::operator=(uint32_t address) { - memcpy(_address, (const uint8_t *)&address, sizeof(_address)); + _address.dword = address; return *this; } bool IPAddress::operator==(const uint8_t* addr) const { - return memcmp(addr, _address, sizeof(_address)) == 0; + return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0; } size_t IPAddress::printTo(Print& p) const @@ -65,10 +65,10 @@ size_t IPAddress::printTo(Print& p) const size_t n = 0; for (int i =0; i < 3; i++) { - n += p.print(_address[i], DEC); + n += p.print(_address.bytes[i], DEC); n += p.print('.'); } - n += p.print(_address[3], DEC); + n += p.print(_address.bytes[3], DEC); return n; } diff --git a/hardware/arduino/avr/cores/arduino/IPAddress.h b/hardware/arduino/avr/cores/arduino/IPAddress.h index 6ea81273caf..94acdc45668 100644 --- a/hardware/arduino/avr/cores/arduino/IPAddress.h +++ b/hardware/arduino/avr/cores/arduino/IPAddress.h @@ -27,12 +27,16 @@ class IPAddress : public Printable { private: - uint8_t _address[4]; // IPv4 address + union { + uint8_t bytes[4]; // IPv4 address + uint32_t dword; + } _address; + // Access the raw byte array containing the address. Because this returns a pointer // to the internal structure rather than a copy of the address this function should only // be used when you know that the usage of the returned uint8_t* will be transient and not // stored. - uint8_t* raw_address() { return _address; }; + uint8_t* raw_address() { return _address.bytes; }; public: // Constructors @@ -43,13 +47,13 @@ class IPAddress : public Printable { // Overloaded cast operator to allow IPAddress objects to be used where a pointer // to a four-byte uint8_t array is expected - operator uint32_t() const { return *((uint32_t*)_address); }; - bool operator==(const IPAddress& addr) const { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); }; + operator uint32_t() const { return _address.dword; }; + bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; }; bool operator==(const uint8_t* addr) const; // Overloaded index operator to allow getting and setting individual octets of the address - uint8_t operator[](int index) const { return _address[index]; }; - uint8_t& operator[](int index) { return _address[index]; }; + uint8_t operator[](int index) const { return _address.bytes[index]; }; + uint8_t& operator[](int index) { return _address.bytes[index]; }; // Overloaded copy operators to allow initialisation of IPAddress objects from other types IPAddress& operator=(const uint8_t *address); diff --git a/hardware/arduino/sam/cores/arduino/IPAddress.cpp b/hardware/arduino/sam/cores/arduino/IPAddress.cpp index 22a0e427187..899cbd4eda8 100644 --- a/hardware/arduino/sam/cores/arduino/IPAddress.cpp +++ b/hardware/arduino/sam/cores/arduino/IPAddress.cpp @@ -22,42 +22,42 @@ IPAddress::IPAddress() { - memset(_address, 0, sizeof(_address)); + _address.dword = 0; } IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) { - _address[0] = first_octet; - _address[1] = second_octet; - _address[2] = third_octet; - _address[3] = fourth_octet; + _address.bytes[0] = first_octet; + _address.bytes[1] = second_octet; + _address.bytes[2] = third_octet; + _address.bytes[3] = fourth_octet; } IPAddress::IPAddress(uint32_t address) { - memcpy(_address, &address, sizeof(_address)); + _address.dword = address; } IPAddress::IPAddress(const uint8_t *address) { - memcpy(_address, address, sizeof(_address)); + memcpy(_address.bytes, address, sizeof(_address.bytes)); } IPAddress& IPAddress::operator=(const uint8_t *address) { - memcpy(_address, address, sizeof(_address)); + memcpy(_address.bytes, address, sizeof(_address.bytes)); return *this; } IPAddress& IPAddress::operator=(uint32_t address) { - memcpy(_address, (const uint8_t *)&address, sizeof(_address)); + _address.dword = address; return *this; } bool IPAddress::operator==(const uint8_t* addr) const { - return memcmp(addr, _address, sizeof(_address)) == 0; + return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0; } size_t IPAddress::printTo(Print& p) const @@ -65,10 +65,10 @@ size_t IPAddress::printTo(Print& p) const size_t n = 0; for (int i =0; i < 3; i++) { - n += p.print(_address[i], DEC); + n += p.print(_address.bytes[i], DEC); n += p.print('.'); } - n += p.print(_address[3], DEC); + n += p.print(_address.bytes[3], DEC); return n; } diff --git a/hardware/arduino/sam/cores/arduino/IPAddress.h b/hardware/arduino/sam/cores/arduino/IPAddress.h index 6ea81273caf..94acdc45668 100644 --- a/hardware/arduino/sam/cores/arduino/IPAddress.h +++ b/hardware/arduino/sam/cores/arduino/IPAddress.h @@ -27,12 +27,16 @@ class IPAddress : public Printable { private: - uint8_t _address[4]; // IPv4 address + union { + uint8_t bytes[4]; // IPv4 address + uint32_t dword; + } _address; + // Access the raw byte array containing the address. Because this returns a pointer // to the internal structure rather than a copy of the address this function should only // be used when you know that the usage of the returned uint8_t* will be transient and not // stored. - uint8_t* raw_address() { return _address; }; + uint8_t* raw_address() { return _address.bytes; }; public: // Constructors @@ -43,13 +47,13 @@ class IPAddress : public Printable { // Overloaded cast operator to allow IPAddress objects to be used where a pointer // to a four-byte uint8_t array is expected - operator uint32_t() const { return *((uint32_t*)_address); }; - bool operator==(const IPAddress& addr) const { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); }; + operator uint32_t() const { return _address.dword; }; + bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; }; bool operator==(const uint8_t* addr) const; // Overloaded index operator to allow getting and setting individual octets of the address - uint8_t operator[](int index) const { return _address[index]; }; - uint8_t& operator[](int index) { return _address[index]; }; + uint8_t operator[](int index) const { return _address.bytes[index]; }; + uint8_t& operator[](int index) { return _address.bytes[index]; }; // Overloaded copy operators to allow initialisation of IPAddress objects from other types IPAddress& operator=(const uint8_t *address); From ece02e93bdadfa7dc99563d63ce9beb34775b12b Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 18 Feb 2014 19:34:04 +0100 Subject: [PATCH 04/12] Instead of #defining true and false, include stdbool.h In C++, true and false are language keywords, so there is no need to define them as macros. Including stdbool.h in C++ effectively changes nothing. In C, true, false and also the bool type are not available, but including stdbool.h will make them available. Using stdbool.h means that we get true, false and the bool type in whatever way the compiler thinks is best, which seems like a good idea to me. This also fixes the following compiler warnings if a .c file includes both stdbool.h and Arduino.h: warning: "true" redefined [enabled by default] #define true 0x1 warning: "false" redefined [enabled by default] #define false 0x0 This fixes #1570 and helps toward fixing #1728. This only changed the AVR core, the SAM core already doesn't define true and false (but doesn't include stdbool.h either). --- hardware/arduino/avr/cores/arduino/Arduino.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/Arduino.h b/hardware/arduino/avr/cores/arduino/Arduino.h index e12ac8283fa..ec1389e1426 100644 --- a/hardware/arduino/avr/cores/arduino/Arduino.h +++ b/hardware/arduino/avr/cores/arduino/Arduino.h @@ -21,6 +21,7 @@ #define Arduino_h #include +#include #include #include @@ -43,9 +44,6 @@ void yield(void); #define OUTPUT 0x1 #define INPUT_PULLUP 0x2 -#define true 0x1 -#define false 0x0 - #define PI 3.1415926535897932384626433832795 #define HALF_PI 1.5707963267948966192313216916398 #define TWO_PI 6.283185307179586476925286766559 From a991f26b8db8efe0e99f0036c57793cfc1e93416 Mon Sep 17 00:00:00 2001 From: "J.C. Wren" Date: Mon, 20 Dec 2010 22:52:24 -0500 Subject: [PATCH 05/12] Sd2Card.cpp: fix compiler warning All the while() loops that check for the SPI transfer to be complete have the semi-colon immediately after the closing parenthesis. This both causes a compiler warning of "warning: suggest a space before ';' or explicit braces around empty body in 'while' statement", and is considered a less-than-ideal programming practice. This patch breaks the semi-colon on to the next line, both eliminating the compiler error and making the code more readable. In all probability the test should be moved into a macro or a inlineable sub-routine. --- libraries/SD/src/utility/Sd2Card.cpp | 30 ++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/libraries/SD/src/utility/Sd2Card.cpp b/libraries/SD/src/utility/Sd2Card.cpp index 9805833e4a1..830f6578916 100644 --- a/libraries/SD/src/utility/Sd2Card.cpp +++ b/libraries/SD/src/utility/Sd2Card.cpp @@ -30,7 +30,8 @@ static void spiSend(uint8_t b) { #ifndef USE_SPI_LIB SPDR = b; - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; #else SPI.transfer(b); #endif @@ -124,7 +125,8 @@ uint8_t Sd2Card::cardCommand(uint8_t cmd, uint32_t arg) { spiSend(crc); // wait for response - for (uint8_t i = 0; ((status_ = spiRec()) & 0X80) && i != 0XFF; i++); + for (uint8_t i = 0; ((status_ = spiRec()) & 0X80) && i != 0XFF; i++) + ; return status_; } //------------------------------------------------------------------------------ @@ -383,18 +385,21 @@ uint8_t Sd2Card::readData(uint32_t block, // skip data before offset for (;offset_ < offset; offset_++) { - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; SPDR = 0XFF; } // transfer data n = count - 1; for (uint16_t i = 0; i < n; i++) { - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; dst[i] = SPDR; SPDR = 0XFF; } // wait for last byte - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; dst[n] = SPDR; #else // OPTIMIZE_HARDWARE_SPI @@ -429,11 +434,13 @@ void Sd2Card::readEnd(void) { // optimize skip for hardware SPDR = 0XFF; while (offset_++ < 513) { - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; SPDR = 0XFF; } // wait for last crc byte - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; #else // OPTIMIZE_HARDWARE_SPI while (offset_++ < 514) spiRec(); #endif // OPTIMIZE_HARDWARE_SPI @@ -602,14 +609,17 @@ uint8_t Sd2Card::writeData(uint8_t token, const uint8_t* src) { // send two byte per iteration for (uint16_t i = 0; i < 512; i += 2) { - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; SPDR = src[i]; - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; SPDR = src[i+1]; } // wait for last data byte - while (!(SPSR & (1 << SPIF))); + while (!(SPSR & (1 << SPIF))) + ; #else // OPTIMIZE_HARDWARE_SPI spiSend(token); From 12b706551dbf7d483ddd53718bd5f5e619c60ab0 Mon Sep 17 00:00:00 2001 From: JC Wren Date: Tue, 21 Dec 2010 12:00:53 -0500 Subject: [PATCH 06/12] SD.c: Fix error in comment for remove() Comment was duplicated from mkdir() and not updated. --- libraries/SD/src/SD.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/SD/src/SD.cpp b/libraries/SD/src/SD.cpp index c746809b6ec..65d32741c2c 100644 --- a/libraries/SD/src/SD.cpp +++ b/libraries/SD/src/SD.cpp @@ -550,9 +550,9 @@ boolean SDClass::mkdir(char *filepath) { boolean SDClass::rmdir(char *filepath) { /* - Makes a single directory or a heirarchy of directories. + Remove a single directory or a heirarchy of directories. - A rough equivalent to `mkdir -p`. + A rough equivalent to `rm -rf`. */ return walkPath(filepath, root, callback_rmdir); From 4cf21dcdd135323f7771ae67930e7ef4d2bb37a2 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 18 Feb 2014 20:56:31 +0100 Subject: [PATCH 07/12] Don't store peeked characters in a char variable peekNextDigit() returns an int, so it can return -1 in addition to all 256 possible bytes. By putting the result in a signe char, all bytes over 128 will be interpreted as "no bytes available". Furthermore, it seems that on SAM "char" is unsigned by default, causing the "if (c < 0)" line a bit further down to always be false. Using an int is more appropriate. A different fix for this issue was suggested in #1399. This fix helps towards #1728. --- hardware/arduino/avr/cores/arduino/Stream.cpp | 2 +- hardware/arduino/sam/cores/arduino/Stream.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/Stream.cpp b/hardware/arduino/avr/cores/arduino/Stream.cpp index aafb7fcf97d..a12a72e3018 100644 --- a/hardware/arduino/avr/cores/arduino/Stream.cpp +++ b/hardware/arduino/avr/cores/arduino/Stream.cpp @@ -176,7 +176,7 @@ float Stream::parseFloat(char skipChar){ boolean isNegative = false; boolean isFraction = false; long value = 0; - char c; + int c; float fraction = 1.0; c = peekNextDigit(); diff --git a/hardware/arduino/sam/cores/arduino/Stream.cpp b/hardware/arduino/sam/cores/arduino/Stream.cpp index aafb7fcf97d..a12a72e3018 100644 --- a/hardware/arduino/sam/cores/arduino/Stream.cpp +++ b/hardware/arduino/sam/cores/arduino/Stream.cpp @@ -176,7 +176,7 @@ float Stream::parseFloat(char skipChar){ boolean isNegative = false; boolean isFraction = false; long value = 0; - char c; + int c; float fraction = 1.0; c = peekNextDigit(); From b196a4a9c547a76b460aaeeb7c963ca7a13d41ef Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 18 Feb 2014 21:00:32 +0100 Subject: [PATCH 08/12] Suppress "unused parameter" warnings A bunch of functions have parameters they do not use, but which cannot be removed for API compatibility. In syscalls_sam3.c, there are a lot of these, so this adds an "UNUSED" macro which adds the "unused" variable attribute if supported (GCC specific), or is just a noop on other compilers. In CDC.cpp, there's only three of these variables, so this commit just forces a dummy evaluation of them to suppress the warnings. This helps towards #1792. --- .../arduino/sam/cores/arduino/USB/CDC.cpp | 5 ++++ .../arduino/sam/cores/arduino/syscalls_sam3.c | 24 ++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/hardware/arduino/sam/cores/arduino/USB/CDC.cpp b/hardware/arduino/sam/cores/arduino/USB/CDC.cpp index 84a4e913287..4d646e7235c 100644 --- a/hardware/arduino/sam/cores/arduino/USB/CDC.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/CDC.cpp @@ -147,10 +147,15 @@ bool WEAK CDC_Setup(Setup& setup) int _serialPeek = -1; void Serial_::begin(uint32_t baud_count) { + // suppress "unused parameter" warning + (void)baud_count; } void Serial_::begin(uint32_t baud_count, uint8_t config) { + // suppress "unused parameter" warning + (void)baud_count; + (void)config; } void Serial_::end(void) diff --git a/hardware/arduino/sam/cores/arduino/syscalls_sam3.c b/hardware/arduino/sam/cores/arduino/syscalls_sam3.c index 23256db6df8..3ea76659cb6 100644 --- a/hardware/arduino/sam/cores/arduino/syscalls_sam3.c +++ b/hardware/arduino/sam/cores/arduino/syscalls_sam3.c @@ -38,6 +38,14 @@ #include #endif +// Helper macro to mark unused parameters and prevent compiler warnings. +// Appends _UNUSED to the variable name to prevent accidentally using them. +#ifdef __GNUC__ +# define UNUSED(x) x ## _UNUSED __attribute__((__unused__)) +#else +# define UNUSED(x) x ## _UNUSED +#endif + /*---------------------------------------------------------------------------- * Exported variables *----------------------------------------------------------------------------*/ @@ -69,39 +77,39 @@ extern caddr_t _sbrk ( int incr ) return (caddr_t) prev_heap ; } -extern int link( char *cOld, char *cNew ) +extern int link( UNUSED(char *cOld), UNUSED(char *cNew) ) { return -1 ; } -extern int _close( int file ) +extern int _close( UNUSED(int file) ) { return -1 ; } -extern int _fstat( int file, struct stat *st ) +extern int _fstat( UNUSED(int file), struct stat *st ) { st->st_mode = S_IFCHR ; return 0 ; } -extern int _isatty( int file ) +extern int _isatty( UNUSED(int file) ) { return 1 ; } -extern int _lseek( int file, int ptr, int dir ) +extern int _lseek( UNUSED(int file), UNUSED(int ptr), UNUSED(int dir) ) { return 0 ; } -extern int _read(int file, char *ptr, int len) +extern int _read(UNUSED(int file), UNUSED(char *ptr), UNUSED(int len) ) { return 0 ; } -extern int _write( int file, char *ptr, int len ) +extern int _write( UNUSED(int file), char *ptr, int len ) { int iIndex ; @@ -129,7 +137,7 @@ extern void _exit( int status ) for ( ; ; ) ; } -extern void _kill( int pid, int sig ) +extern void _kill( UNUSED(int pid), UNUSED(int sig) ) { return ; } From 8e35973ff94859ed25a0906455ce2a46d4145937 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 18 Feb 2014 21:02:26 +0100 Subject: [PATCH 09/12] Remove check that is always false len is an unsigned variable, so it will never be less than 0. This helps towards #1792. --- hardware/arduino/sam/cores/arduino/USB/USBCore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp index 7876762b723..b086e508008 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp @@ -139,7 +139,7 @@ uint32_t USBD_Available(uint32_t ep) // Return number of bytes read uint32_t USBD_Recv(uint32_t ep, void* d, uint32_t len) { - if (!_usbConfiguration || len < 0) + if (!_usbConfiguration) return -1; LockEP lock(ep); From 1c6a57e15db5216dd59521f9f16e29e12f569c81 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 18 Feb 2014 21:02:54 +0100 Subject: [PATCH 10/12] Include stdio.h in dtostrf.c This makes the declaration of sprintf available, so the function is not implicitely declared, which triggers two compiler warnings. This helps towards #1792 --- hardware/arduino/sam/cores/arduino/avr/dtostrf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hardware/arduino/sam/cores/arduino/avr/dtostrf.c b/hardware/arduino/sam/cores/arduino/avr/dtostrf.c index 51541739c76..7f90154fbde 100644 --- a/hardware/arduino/sam/cores/arduino/avr/dtostrf.c +++ b/hardware/arduino/sam/cores/arduino/avr/dtostrf.c @@ -18,6 +18,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + char *dtostrf (double val, signed char width, unsigned char prec, char *sout) { char fmt[20]; sprintf(fmt, "%%%d.%df", width, prec); From 4b3db72a4685f42e147775496c119ac45d62185f Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 18 Feb 2014 21:04:06 +0100 Subject: [PATCH 11/12] Fix two signedness warnings This helps towards #1792 --- hardware/arduino/sam/cores/arduino/wiring_analog.c | 2 +- hardware/arduino/sam/variants/arduino_due_x/variant.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hardware/arduino/sam/cores/arduino/wiring_analog.c b/hardware/arduino/sam/cores/arduino/wiring_analog.c index ffdc4e2f049..2afa0c9e7c3 100644 --- a/hardware/arduino/sam/cores/arduino/wiring_analog.c +++ b/hardware/arduino/sam/cores/arduino/wiring_analog.c @@ -150,7 +150,7 @@ uint32_t analogRead(uint32_t ulPin) // Enable the corresponding channel if (ulChannel != latestSelectedChannel) { adc_enable_channel( ADC, ulChannel ); - if ( latestSelectedChannel != -1 ) + if ( latestSelectedChannel != (uint32_t)-1 ) adc_disable_channel( ADC, latestSelectedChannel ); latestSelectedChannel = ulChannel; } diff --git a/hardware/arduino/sam/variants/arduino_due_x/variant.cpp b/hardware/arduino/sam/variants/arduino_due_x/variant.cpp index ab43675ab4c..ac066898dba 100644 --- a/hardware/arduino/sam/variants/arduino_due_x/variant.cpp +++ b/hardware/arduino/sam/variants/arduino_due_x/variant.cpp @@ -380,7 +380,7 @@ void init( void ) __libc_init_array(); // Disable pull-up on every pin - for (int i = 0; i < PINS_COUNT; i++) + for (unsigned i = 0; i < PINS_COUNT; i++) digitalWrite(i, LOW); // Enable parallel access on PIO output data registers From 5c6ee6127cbfd2df34357328fc5b687489ffc3ef Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 18 Feb 2014 21:04:31 +0100 Subject: [PATCH 12/12] Remove const specifier from channelToTC array in analogWrite on SAM Members of this array are later passed to functions that accept non-const pointers. These functions probably don't modify their arguments, so a better solution would be to update those functions to accept const pointers. However, they look like third-party code, so that would require changing the code again on every update. Removing const here fixes at least the compiler warning for now. This helps towards #1792. --- hardware/arduino/sam/cores/arduino/wiring_analog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hardware/arduino/sam/cores/arduino/wiring_analog.c b/hardware/arduino/sam/cores/arduino/wiring_analog.c index 2afa0c9e7c3..1385f01ebf5 100644 --- a/hardware/arduino/sam/cores/arduino/wiring_analog.c +++ b/hardware/arduino/sam/cores/arduino/wiring_analog.c @@ -293,7 +293,7 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) { ETCChannel channel = g_APinDescription[ulPin].ulTCChannel; static const uint32_t channelToChNo[] = { 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2 }; static const uint32_t channelToAB[] = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }; - static const Tc *channelToTC[] = { + static Tc *channelToTC[] = { TC0, TC0, TC0, TC0, TC0, TC0, TC1, TC1, TC1, TC1, TC1, TC1, TC2, TC2, TC2, TC2, TC2, TC2 };