Skip to content

Ide 1.5.x Cleaned up a few warnings and fixed strict-aliasing #1399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions hardware/arduino/avr/cores/arduino/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
// to which to write the next incoming character and tail is the index of the
// location from which to read.
#if (RAMEND < 1000)
#define SERIAL_BUFFER_SIZE 16
#define SERIAL_BUFFER_SIZE 16U
#else
#define SERIAL_BUFFER_SIZE 64
#define SERIAL_BUFFER_SIZE 64U
#endif

struct ring_buffer
Expand Down Expand Up @@ -89,7 +89,7 @@ struct ring_buffer

inline void store_char(unsigned char c, ring_buffer *buffer)
{
int i = (unsigned int)(buffer->head + 1) % SERIAL_BUFFER_SIZE;
unsigned int i = (unsigned int)(buffer->head + 1) % SERIAL_BUFFER_SIZE;

// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
Expand Down Expand Up @@ -120,18 +120,20 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
#endif
{
#if defined(UDR0)
unsigned char c;
if (bit_is_clear(UCSR0A, UPE0)) {
unsigned char c = UDR0;
c = UDR0;
store_char(c, &rx_buffer);
} else {
unsigned char c = UDR0;
c = UDR0;
};
#elif defined(UDR)
unsigned char c;
if (bit_is_clear(UCSRA, PE)) {
unsigned char c = UDR;
c = UDR;
store_char(c, &rx_buffer);
} else {
unsigned char c = UDR;
c = UDR;
};
#else
#error UDR not defined
Expand All @@ -146,11 +148,12 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
#define serialEvent1_implemented
ISR(USART1_RX_vect)
{
unsigned char c;
if (bit_is_clear(UCSR1A, UPE1)) {
unsigned char c = UDR1;
c = UDR1;
store_char(c, &rx_buffer1);
} else {
unsigned char c = UDR1;
c = UDR1;
};
}
#endif
Expand All @@ -161,11 +164,12 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
#define serialEvent2_implemented
ISR(USART2_RX_vect)
{
unsigned char c;
if (bit_is_clear(UCSR2A, UPE2)) {
unsigned char c = UDR2;
c = UDR2;
store_char(c, &rx_buffer2);
} else {
unsigned char c = UDR2;
c = UDR2;
};
}
#endif
Expand All @@ -176,11 +180,12 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
#define serialEvent3_implemented
ISR(USART3_RX_vect)
{
unsigned char c;
if (bit_is_clear(UCSR3A, UPE3)) {
unsigned char c = UDR3;
c = UDR3;
store_char(c, &rx_buffer3);
} else {
unsigned char c = UDR3;
c = UDR3;
};
}
#endif
Expand Down Expand Up @@ -365,7 +370,6 @@ void HardwareSerial::begin(unsigned long baud)
void HardwareSerial::begin(unsigned long baud, byte config)
{
uint16_t baud_setting;
uint8_t current_config;
bool use_u2x = true;

#if F_CPU == 16000000UL
Expand Down Expand Up @@ -453,13 +457,14 @@ int HardwareSerial::read(void)
void HardwareSerial::flush()
{
// UDR is kept full while the buffer is not empty, so TXC triggers when EMPTY && SENT
while (transmitting && ! (*_ucsra & _BV(TXC0)));
while (transmitting && ! (*_ucsra & _BV(TXC0)))
;
transmitting = false;
}

size_t HardwareSerial::write(uint8_t c)
{
int i = (_tx_buffer->head + 1) % SERIAL_BUFFER_SIZE;
unsigned int i = (_tx_buffer->head + 1) % SERIAL_BUFFER_SIZE;

// If the output buffer is full, there's nothing for it other than to
// wait for the interrupt handler to empty it a bit
Expand Down
10 changes: 8 additions & 2 deletions hardware/arduino/avr/cores/arduino/IPAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ 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() { return *((uint32_t*)_address); };
bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); };
operator uint32_t() { return ((uint32_t)_address[0] << 0 |
(uint32_t)_address[1] << 8 |
(uint32_t)_address[2] << 16 |
(uint32_t)_address[3] << 24); }
bool operator==(const IPAddress& addr) { return (_address[0] == addr._address[0] &&
_address[1] == addr._address[1] &&
_address[2] == addr._address[2] &&
_address[3] == addr._address[3]); }
bool operator==(const uint8_t* addr);

// Overloaded index operator to allow getting and setting individual octets of the address
Expand Down
2 changes: 1 addition & 1 deletion hardware/arduino/avr/cores/arduino/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ size_t Print::write(const uint8_t *buffer, size_t size)

size_t Print::print(const __FlashStringHelper *ifsh)
{
const char PROGMEM *p = (const char PROGMEM *)ifsh;
const char *p = (const char *)ifsh;
size_t n = 0;
while (1) {
unsigned char c = pgm_read_byte(p++);
Expand Down
2 changes: 1 addition & 1 deletion hardware/arduino/avr/cores/arduino/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ float Stream::parseFloat(char skipChar){
boolean isNegative = false;
boolean isFraction = false;
long value = 0;
char c;
signed char c;
float fraction = 1.0;

c = peekNextDigit();
Expand Down
3 changes: 2 additions & 1 deletion hardware/arduino/avr/cores/arduino/wiring_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ extern "C"{
#define EXTERNAL_INT_6 6
#define EXTERNAL_INT_7 7

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || \
defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)
#define EXTERNAL_NUM_INTERRUPTS 8
#elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__)
#define EXTERNAL_NUM_INTERRUPTS 3
Expand Down