Skip to content

Commit 6a45ba4

Browse files
committed
Merged upstream arduino branch
2 parents c313b54 + 6d296e0 commit 6a45ba4

File tree

305 files changed

+147489
-26
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

305 files changed

+147489
-26
lines changed

Diff for: boards.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ mega2560.cpu=2560 or ADK
120120
mega2560.container=Arduino Mega
121121

122122
mega2560.upload.tool=avrdude
123-
mega2560.upload.protocol=stk500v2
123+
mega2560.upload.protocol=wiring
124124
mega2560.upload.maximum_size=258048
125125
mega2560.upload.speed=115200
126126

Diff for: cores/arduino/Arduino.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extern "C"{
4646
#define EXTERNAL 1
4747
#define INTERNAL 2
4848
#else
49-
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__)
49+
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__)
5050
#define INTERNAL1V1 2
5151
#define INTERNAL2V56 3
5252
#else

Diff for: cores/arduino/HardwareSerial.cpp

+93-17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
1919
Modified 23 November 2006 by David A. Mellis
2020
Modified 28 September 2010 by Mark Sproul
21+
Modified 14 August 2012 by Alarus
2122
*/
2223

2324
#include <stdlib.h>
@@ -109,13 +110,22 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
109110
#endif
110111
{
111112
#if defined(UDR0)
112-
unsigned char c = UDR0;
113+
if (bit_is_clear(UCSR0A, UPE0)) {
114+
unsigned char c = UDR0;
115+
store_char(c, &rx_buffer);
116+
} else {
117+
unsigned char c = UDR0;
118+
};
113119
#elif defined(UDR)
114-
unsigned char c = UDR;
120+
if (bit_is_clear(UCSRA, PE)) {
121+
unsigned char c = UDR;
122+
store_char(c, &rx_buffer);
123+
} else {
124+
unsigned char c = UDR;
125+
};
115126
#else
116127
#error UDR not defined
117128
#endif
118-
store_char(c, &rx_buffer);
119129
}
120130
#endif
121131
#endif
@@ -126,8 +136,12 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
126136
#define serialEvent1_implemented
127137
SIGNAL(USART1_RX_vect)
128138
{
129-
unsigned char c = UDR1;
130-
store_char(c, &rx_buffer1);
139+
if (bit_is_clear(UCSR1A, UPE1)) {
140+
unsigned char c = UDR1;
141+
store_char(c, &rx_buffer1);
142+
} else {
143+
unsigned char c = UDR1;
144+
};
131145
}
132146
#elif defined(SIG_USART1_RECV)
133147
#error SIG_USART1_RECV
@@ -139,8 +153,12 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
139153
#define serialEvent2_implemented
140154
SIGNAL(USART2_RX_vect)
141155
{
142-
unsigned char c = UDR2;
143-
store_char(c, &rx_buffer2);
156+
if (bit_is_clear(UCSR2A, UPE2)) {
157+
unsigned char c = UDR2;
158+
store_char(c, &rx_buffer2);
159+
} else {
160+
unsigned char c = UDR2;
161+
};
144162
}
145163
#elif defined(SIG_USART2_RECV)
146164
#error SIG_USART2_RECV
@@ -152,8 +170,12 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
152170
#define serialEvent3_implemented
153171
SIGNAL(USART3_RX_vect)
154172
{
155-
unsigned char c = UDR3;
156-
store_char(c, &rx_buffer3);
173+
if (bit_is_clear(UCSR3A, UPE3)) {
174+
unsigned char c = UDR3;
175+
store_char(c, &rx_buffer3);
176+
} else {
177+
unsigned char c = UDR3;
178+
};
157179
}
158180
#elif defined(SIG_USART3_RECV)
159181
#error SIG_USART3_RECV
@@ -274,7 +296,7 @@ ISR(USART3_UDRE_vect)
274296
HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
275297
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
276298
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
277-
volatile uint8_t *udr,
299+
volatile uint8_t *ucsrc, volatile uint8_t *udr,
278300
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x)
279301
{
280302
_rx_buffer = rx_buffer;
@@ -283,6 +305,7 @@ HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
283305
_ubrrl = ubrrl;
284306
_ucsra = ucsra;
285307
_ucsrb = ucsrb;
308+
_ucsrc = ucsrc;
286309
_udr = udr;
287310
_rxen = rxen;
288311
_txen = txen;
@@ -327,6 +350,55 @@ void HardwareSerial::begin(unsigned long baud)
327350
*_ubrrh = baud_setting >> 8;
328351
*_ubrrl = baud_setting;
329352

353+
transmitting = false;
354+
355+
sbi(*_ucsrb, _rxen);
356+
sbi(*_ucsrb, _txen);
357+
sbi(*_ucsrb, _rxcie);
358+
cbi(*_ucsrb, _udrie);
359+
}
360+
361+
void HardwareSerial::begin(unsigned long baud, byte config)
362+
{
363+
uint16_t baud_setting;
364+
uint8_t current_config;
365+
bool use_u2x = true;
366+
367+
#if F_CPU == 16000000UL
368+
// hardcoded exception for compatibility with the bootloader shipped
369+
// with the Duemilanove and previous boards and the firmware on the 8U2
370+
// on the Uno and Mega 2560.
371+
if (baud == 57600) {
372+
use_u2x = false;
373+
}
374+
#endif
375+
376+
try_again:
377+
378+
if (use_u2x) {
379+
*_ucsra = 1 << _u2x;
380+
baud_setting = (F_CPU / 4 / baud - 1) / 2;
381+
} else {
382+
*_ucsra = 0;
383+
baud_setting = (F_CPU / 8 / baud - 1) / 2;
384+
}
385+
386+
if ((baud_setting > 4095) && use_u2x)
387+
{
388+
use_u2x = false;
389+
goto try_again;
390+
}
391+
392+
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
393+
*_ubrrh = baud_setting >> 8;
394+
*_ubrrl = baud_setting;
395+
396+
//set the data bits, parity, and stop bits
397+
#if defined(__AVR_ATmega8__)
398+
config |= 0x80; // select UCSRC register (shared with UBRRH)
399+
#endif
400+
*_ucsrc = config;
401+
330402
sbi(*_ucsrb, _rxen);
331403
sbi(*_ucsrb, _txen);
332404
sbi(*_ucsrb, _rxcie);
@@ -376,8 +448,9 @@ int HardwareSerial::read(void)
376448

377449
void HardwareSerial::flush()
378450
{
379-
while (_tx_buffer->head != _tx_buffer->tail)
380-
;
451+
// UDR is kept full while the buffer is not empty, so TXC triggers when EMPTY && SENT
452+
while (transmitting && ! (*_ucsra & _BV(TXC0)));
453+
transmitting = false;
381454
}
382455

383456
size_t HardwareSerial::write(uint8_t c)
@@ -394,6 +467,9 @@ size_t HardwareSerial::write(uint8_t c)
394467
_tx_buffer->head = i;
395468

396469
sbi(*_ucsrb, _udrie);
470+
// clear the TXC bit -- "can be cleared by writing a one to its bit location"
471+
transmitting = true;
472+
sbi(*_ucsra, TXC0);
397473

398474
return 1;
399475
}
@@ -405,23 +481,23 @@ HardwareSerial::operator bool() {
405481
// Preinstantiate Objects //////////////////////////////////////////////////////
406482

407483
#if defined(UBRRH) && defined(UBRRL)
408-
HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRIE, U2X);
484+
HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UCSRC, &UDR, RXEN, TXEN, RXCIE, UDRIE, U2X);
409485
#elif defined(UBRR0H) && defined(UBRR0L)
410-
HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRIE0, U2X0);
486+
HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UCSR0C, &UDR0, RXEN0, TXEN0, RXCIE0, UDRIE0, U2X0);
411487
#elif defined(USBCON)
412488
// do nothing - Serial object and buffers are initialized in CDC code
413489
#else
414490
#error no serial port defined (port 0)
415491
#endif
416492

417493
#if defined(UBRR1H)
418-
HardwareSerial Serial1(&rx_buffer1, &tx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRIE1, U2X1);
494+
HardwareSerial Serial1(&rx_buffer1, &tx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UCSR1C, &UDR1, RXEN1, TXEN1, RXCIE1, UDRIE1, U2X1);
419495
#endif
420496
#if defined(UBRR2H)
421-
HardwareSerial Serial2(&rx_buffer2, &tx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRIE2, U2X2);
497+
HardwareSerial Serial2(&rx_buffer2, &tx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UCSR2C, &UDR2, RXEN2, TXEN2, RXCIE2, UDRIE2, U2X2);
422498
#endif
423499
#if defined(UBRR3H)
424-
HardwareSerial Serial3(&rx_buffer3, &tx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRIE3, U2X3);
500+
HardwareSerial Serial3(&rx_buffer3, &tx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UCSR3C, &UDR3, RXEN3, TXEN3, RXCIE3, UDRIE3, U2X3);
425501
#endif
426502

427503
#endif // whole file

Diff for: cores/arduino/HardwareSerial.h

+51-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
1919
Modified 28 September 2010 by Mark Sproul
20+
Modified 14 August 2012 by Alarus
2021
*/
2122

2223
#ifndef HardwareSerial_h
@@ -37,29 +38,62 @@ class HardwareSerial : public Stream
3738
volatile uint8_t *_ubrrl;
3839
volatile uint8_t *_ucsra;
3940
volatile uint8_t *_ucsrb;
41+
volatile uint8_t *_ucsrc;
4042
volatile uint8_t *_udr;
4143
uint8_t _rxen;
4244
uint8_t _txen;
4345
uint8_t _rxcie;
4446
uint8_t _udrie;
4547
uint8_t _u2x;
48+
bool transmitting;
4649
public:
4750
HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
4851
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
4952
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
50-
volatile uint8_t *udr,
53+
volatile uint8_t *ucsrc, volatile uint8_t *udr,
5154
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x);
5255
void begin(unsigned long);
56+
void begin(unsigned long, byte);
5357
void end();
5458
virtual int available(void);
5559
virtual int peek(void);
5660
virtual int read(void);
5761
virtual void flush(void);
5862
virtual size_t write(uint8_t);
63+
inline size_t write(unsigned long n) { return write((uint8_t)n); }
64+
inline size_t write(long n) { return write((uint8_t)n); }
65+
inline size_t write(unsigned int n) { return write((uint8_t)n); }
66+
inline size_t write(int n) { return write((uint8_t)n); }
5967
using Print::write; // pull in write(str) and write(buf, size) from Print
6068
operator bool();
6169
};
6270

71+
// Define config for Serial.begin(baud, config);
72+
#define SERIAL_5N1 0x00
73+
#define SERIAL_6N1 0x02
74+
#define SERIAL_7N1 0x04
75+
#define SERIAL_8N1 0x06
76+
#define SERIAL_5N2 0x08
77+
#define SERIAL_6N2 0x0A
78+
#define SERIAL_7N2 0x0C
79+
#define SERIAL_8N2 0x0E
80+
#define SERIAL_5E1 0x20
81+
#define SERIAL_6E1 0x22
82+
#define SERIAL_7E1 0x24
83+
#define SERIAL_8E1 0x26
84+
#define SERIAL_5E2 0x28
85+
#define SERIAL_6E2 0x2A
86+
#define SERIAL_7E2 0x2C
87+
#define SERIAL_8E2 0x2E
88+
#define SERIAL_5O1 0x30
89+
#define SERIAL_6O1 0x32
90+
#define SERIAL_7O1 0x34
91+
#define SERIAL_8O1 0x36
92+
#define SERIAL_5O2 0x38
93+
#define SERIAL_6O2 0x3A
94+
#define SERIAL_7O2 0x3C
95+
#define SERIAL_8O2 0x3E
96+
6397
#if defined(UBRRH) || defined(UBRR0H)
6498
extern HardwareSerial Serial;
6599
#elif defined(USBCON)
@@ -76,6 +110,22 @@ class HardwareSerial : public Stream
76110
extern HardwareSerial Serial3;
77111
#endif
78112

113+
/*
114+
* on ATmega8, the uart and its bits are not numbered, so there is no "TXC0"
115+
* definition. It is slightly cleaner to define this here instead of having
116+
* conditional code in the cpp module.
117+
*/
118+
#if !defined(TXC0)
119+
#if defined(TXC)
120+
#define TXC0 TXC
121+
#elif defined(TXC1)
122+
// Some devices have uart1 but no uart0
123+
#define TXC0 TXC1
124+
#else
125+
#error TXC0 not definable in HardwareSerial.h
126+
#endif
127+
#endif
128+
79129
extern void serialEventRun(void) __attribute__((weak));
80130

81131
#endif

Diff for: cores/arduino/USBCore.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ ISR(USB_GEN_vect)
603603
{
604604
#ifdef CDC_ENABLED
605605
USB_Flush(CDC_TX); // Send a tx frame if found
606-
while (USB_Available(CDC_RX)) // Handle received bytes (if any)
606+
if (USB_Available(CDC_RX)) // Handle received bytes (if any)
607607
Serial.accept();
608608
#endif
609609

Diff for: cores/arduino/wiring_analog.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int analogRead(uint8_t pin)
4545
if (pin >= 54) pin -= 54; // allow for channel or pin numbers
4646
#elif defined(__AVR_ATmega32U4__)
4747
if (pin >= 18) pin -= 18; // allow for channel or pin numbers
48-
#elif defined(__AVR_ATmega1284__)
48+
#elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__)
4949
if (pin >= 24) pin -= 24; // allow for channel or pin numbers
5050
#else
5151
if (pin >= 14) pin -= 14; // allow for channel or pin numbers

Diff for: cores/arduino/wiring_private.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extern "C"{
5454

5555
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
5656
#define EXTERNAL_NUM_INTERRUPTS 8
57-
#elif defined(__AVR_ATmega1284P__)
57+
#elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__)
5858
#define EXTERNAL_NUM_INTERRUPTS 3
5959
#elif defined(__AVR_ATmega32U4__)
6060
#define EXTERNAL_NUM_INTERRUPTS 4
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: firmwares/wifishield/binary/wifiHD.elf

390 KB
Binary file not shown.

0 commit comments

Comments
 (0)