Skip to content

Commit 50f77c7

Browse files
committed
Moving the processing-5503 branch (used for Arduino 0017) into the trunk.
2 parents 159051b + 79b7ecd commit 50f77c7

File tree

33 files changed

+2136
-739
lines changed

33 files changed

+2136
-739
lines changed

boards.txt

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
##############################################################
22

3-
atmega328.name=Arduino Duemilanove w/ ATmega328
3+
atmega328.name=Arduino Duemilanove or Nano w/ ATmega328
44

55
atmega328.upload.protocol=stk500
66
atmega328.upload.maximum_size=30720
@@ -20,7 +20,7 @@ atmega328.build.core=arduino
2020

2121
##############################################################
2222

23-
diecimila.name=Arduino Diecimila or Duemilanove w/ ATmega168
23+
diecimila.name=Arduino Diecimila, Duemilanove, or Nano w/ ATmega168
2424

2525
diecimila.upload.protocol=stk500
2626
diecimila.upload.maximum_size=14336
@@ -80,26 +80,6 @@ mini.build.core=arduino
8080

8181
##############################################################
8282

83-
nano.name=Arduino Nano
84-
85-
nano.upload.protocol=stk500
86-
nano.upload.maximum_size=14336
87-
nano.upload.speed=19200
88-
89-
nano.bootloader.low_fuses=0xff
90-
nano.bootloader.high_fuses=0xdd
91-
nano.bootloader.extended_fuses=0x00
92-
nano.bootloader.path=atmega
93-
nano.bootloader.file=ATmegaBOOT_168_diecimila.hex
94-
nano.bootloader.unlock_bits=0x3F
95-
nano.bootloader.lock_bits=0x0F
96-
97-
nano.build.mcu=atmega168
98-
nano.build.f_cpu=16000000L
99-
nano.build.core=arduino
100-
101-
##############################################################
102-
10383
bt.name=Arduino BT
10484

10585
bt.upload.protocol=stk500

cores/arduino/HardwareSerial.cpp

Lines changed: 76 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -49,41 +49,41 @@ ring_buffer rx_buffer3 = { { 0 }, 0, 0 };
4949

5050
inline void store_char(unsigned char c, ring_buffer *rx_buffer)
5151
{
52-
int i = (rx_buffer->head + 1) % RX_BUFFER_SIZE;
53-
54-
// if we should be storing the received character into the location
55-
// just before the tail (meaning that the head would advance to the
56-
// current location of the tail), we're about to overflow the buffer
57-
// and so we don't write the character or advance the head.
58-
if (i != rx_buffer->tail) {
59-
rx_buffer->buffer[rx_buffer->head] = c;
60-
rx_buffer->head = i;
61-
}
52+
int i = (rx_buffer->head + 1) % RX_BUFFER_SIZE;
53+
54+
// if we should be storing the received character into the location
55+
// just before the tail (meaning that the head would advance to the
56+
// current location of the tail), we're about to overflow the buffer
57+
// and so we don't write the character or advance the head.
58+
if (i != rx_buffer->tail) {
59+
rx_buffer->buffer[rx_buffer->head] = c;
60+
rx_buffer->head = i;
61+
}
6262
}
6363

6464
#if defined(__AVR_ATmega1280__)
6565

6666
SIGNAL(SIG_USART0_RECV)
6767
{
68-
unsigned char c = UDR0;
68+
unsigned char c = UDR0;
6969
store_char(c, &rx_buffer);
7070
}
7171

7272
SIGNAL(SIG_USART1_RECV)
7373
{
74-
unsigned char c = UDR1;
74+
unsigned char c = UDR1;
7575
store_char(c, &rx_buffer1);
7676
}
7777

7878
SIGNAL(SIG_USART2_RECV)
7979
{
80-
unsigned char c = UDR2;
80+
unsigned char c = UDR2;
8181
store_char(c, &rx_buffer2);
8282
}
8383

8484
SIGNAL(SIG_USART3_RECV)
8585
{
86-
unsigned char c = UDR3;
86+
unsigned char c = UDR3;
8787
store_char(c, &rx_buffer3);
8888
}
8989

@@ -96,9 +96,9 @@ SIGNAL(USART_RX_vect)
9696
#endif
9797
{
9898
#if defined(__AVR_ATmega8__)
99-
unsigned char c = UDR;
99+
unsigned char c = UDR;
100100
#else
101-
unsigned char c = UDR0;
101+
unsigned char c = UDR0;
102102
#endif
103103
store_char(c, &rx_buffer);
104104
}
@@ -111,7 +111,7 @@ HardwareSerial::HardwareSerial(ring_buffer *rx_buffer,
111111
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
112112
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
113113
volatile uint8_t *udr,
114-
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre)
114+
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x)
115115
{
116116
_rx_buffer = rx_buffer;
117117
_ubrrh = ubrrh;
@@ -123,69 +123,97 @@ HardwareSerial::HardwareSerial(ring_buffer *rx_buffer,
123123
_txen = txen;
124124
_rxcie = rxcie;
125125
_udre = udre;
126+
_u2x = u2x;
126127
}
127128

128129
// Public Methods //////////////////////////////////////////////////////////////
129130

130-
void HardwareSerial::begin(long speed)
131+
void HardwareSerial::begin(long baud)
131132
{
132-
*_ubrrh = ((F_CPU / 16 + speed / 2) / speed - 1) >> 8;
133-
*_ubrrl = ((F_CPU / 16 + speed / 2) / speed - 1);
133+
uint16_t baud_setting;
134+
bool use_u2x;
135+
136+
// U2X mode is needed for baud rates higher than (CPU Hz / 16)
137+
if (baud > F_CPU / 16) {
138+
use_u2x = true;
139+
} else {
140+
// figure out if U2X mode would allow for a better connection
141+
142+
// calculate the percent difference between the baud-rate specified and
143+
// the real baud rate for both U2X and non-U2X mode (0-255 error percent)
144+
uint8_t nonu2x_baud_error = abs((int)(255-((F_CPU/(16*(((F_CPU/8/baud-1)/2)+1))*255)/baud)));
145+
uint8_t u2x_baud_error = abs((int)(255-((F_CPU/(8*(((F_CPU/4/baud-1)/2)+1))*255)/baud)));
146+
147+
// prefer non-U2X mode because it handles clock skew better
148+
use_u2x = (nonu2x_baud_error > u2x_baud_error);
149+
}
150+
151+
if (use_u2x) {
152+
*_ucsra = 1 << _u2x;
153+
baud_setting = (F_CPU / 4 / baud - 1) / 2;
154+
} else {
155+
*_ucsra = 0;
156+
baud_setting = (F_CPU / 8 / baud - 1) / 2;
157+
}
158+
159+
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
160+
*_ubrrh = baud_setting >> 8;
161+
*_ubrrl = baud_setting;
162+
134163
sbi(*_ucsrb, _rxen);
135164
sbi(*_ucsrb, _txen);
136165
sbi(*_ucsrb, _rxcie);
137166
}
138167

139168
uint8_t HardwareSerial::available(void)
140169
{
141-
return (RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE;
170+
return (RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE;
142171
}
143172

144173
int HardwareSerial::read(void)
145174
{
146-
// if the head isn't ahead of the tail, we don't have any characters
147-
if (_rx_buffer->head == _rx_buffer->tail) {
148-
return -1;
149-
} else {
150-
unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
151-
_rx_buffer->tail = (_rx_buffer->tail + 1) % RX_BUFFER_SIZE;
152-
return c;
153-
}
175+
// if the head isn't ahead of the tail, we don't have any characters
176+
if (_rx_buffer->head == _rx_buffer->tail) {
177+
return -1;
178+
} else {
179+
unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
180+
_rx_buffer->tail = (_rx_buffer->tail + 1) % RX_BUFFER_SIZE;
181+
return c;
182+
}
154183
}
155184

156185
void HardwareSerial::flush()
157186
{
158-
// don't reverse this or there may be problems if the RX interrupt
159-
// occurs after reading the value of rx_buffer_head but before writing
160-
// the value to rx_buffer_tail; the previous value of rx_buffer_head
161-
// may be written to rx_buffer_tail, making it appear as if the buffer
162-
// don't reverse this or there may be problems if the RX interrupt
163-
// occurs after reading the value of rx_buffer_head but before writing
164-
// the value to rx_buffer_tail; the previous value of rx_buffer_head
165-
// may be written to rx_buffer_tail, making it appear as if the buffer
166-
// were full, not empty.
167-
_rx_buffer->head = _rx_buffer->tail;
187+
// don't reverse this or there may be problems if the RX interrupt
188+
// occurs after reading the value of rx_buffer_head but before writing
189+
// the value to rx_buffer_tail; the previous value of rx_buffer_head
190+
// may be written to rx_buffer_tail, making it appear as if the buffer
191+
// don't reverse this or there may be problems if the RX interrupt
192+
// occurs after reading the value of rx_buffer_head but before writing
193+
// the value to rx_buffer_tail; the previous value of rx_buffer_head
194+
// may be written to rx_buffer_tail, making it appear as if the buffer
195+
// were full, not empty.
196+
_rx_buffer->head = _rx_buffer->tail;
168197
}
169198

170199
void HardwareSerial::write(uint8_t c)
171200
{
172-
while (!((*_ucsra) & (1 << _udre)))
173-
;
201+
while (!((*_ucsra) & (1 << _udre)))
202+
;
174203

175-
*_udr = c;
204+
*_udr = c;
176205
}
177206

178207
// Preinstantiate Objects //////////////////////////////////////////////////////
179208

180209
#if defined(__AVR_ATmega8__)
181-
HardwareSerial Serial(&rx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRE);
210+
HardwareSerial Serial(&rx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRE, U2X);
182211
#else
183-
HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0);
212+
HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
184213
#endif
185214

186215
#if defined(__AVR_ATmega1280__)
187-
HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1);
188-
HardwareSerial Serial2(&rx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRE2);
189-
HardwareSerial Serial3(&rx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRE3);
216+
HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1, U2X1);
217+
HardwareSerial Serial2(&rx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRE2, U2X2);
218+
HardwareSerial Serial3(&rx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRE3, U2X3);
190219
#endif
191-

cores/arduino/HardwareSerial.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ class HardwareSerial : public Print
3939
uint8_t _txen;
4040
uint8_t _rxcie;
4141
uint8_t _udre;
42+
uint8_t _u2x;
4243
public:
4344
HardwareSerial(ring_buffer *rx_buffer,
4445
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
4546
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
4647
volatile uint8_t *udr,
47-
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre);
48+
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x);
4849
void begin(long);
4950
uint8_t available(void);
5051
int read(void);
@@ -62,4 +63,3 @@ extern HardwareSerial Serial3;
6263
#endif
6364

6465
#endif
65-

cores/arduino/wiring.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ extern "C"{
8686
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
8787
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
8888

89-
#define lowByte(w) ((w) & 0xff)
90-
#define highByte(w) ((w) >> 8)
89+
#define lowByte(w) ((uint8_t) ((w) & 0xff))
90+
#define highByte(w) ((uint8_t) ((w) >> 8))
9191

9292
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
9393
#define bitSet(value, bit) ((value) |= (1UL << (bit)))

cores/arduino/wiring_analog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int analogRead(uint8_t pin)
4242
// set the analog reference (high two bits of ADMUX) and select the
4343
// channel (low 4 bits). this also sets ADLAR (left-adjust result)
4444
// to 0 (the default).
45-
ADMUX = (analog_reference << 6) | (pin & 0x07);
45+
ADMUX = (analog_reference << 6) | (pin & 0x0f);
4646

4747
#if defined(__AVR_ATmega1280__)
4848
// the MUX5 bit of ADCSRB selects whether we're reading from channels

libraries/Ethernet/Client.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,21 @@ void Client::stop() {
113113
}
114114

115115
uint8_t Client::connected() {
116-
uint8_t s = status();
117-
return !(s == SOCK_LISTEN || s == SOCK_CLOSED || s == SOCK_FIN_WAIT ||
118-
(s == SOCK_CLOSE_WAIT && !available()));
116+
if (_sock == 255) {
117+
return 0;
118+
} else {
119+
uint8_t s = status();
120+
return !(s == SOCK_LISTEN || s == SOCK_CLOSED || s == SOCK_FIN_WAIT ||
121+
(s == SOCK_CLOSE_WAIT && !available()));
122+
}
119123
}
120124

121125
uint8_t Client::status() {
122-
return getSn_SR(_sock);
126+
if (_sock == 255) {
127+
return SOCK_CLOSED;
128+
} else {
129+
return getSn_SR(_sock);
130+
}
123131
}
124132

125133
// the next three functions are a hack so we can compare the client returned

libraries/Ethernet/keywords.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#######################################
2+
# Syntax Coloring Map For Ethernet
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
Ethernet KEYWORD1
10+
Client KEYWORD1
11+
Server KEYWORD1
12+
13+
#######################################
14+
# Methods and Functions (KEYWORD2)
15+
#######################################
16+
17+
status KEYWORD2
18+
connect KEYWORD2
19+
write KEYWORD2
20+
available KEYWORD2
21+
read KEYWORD2
22+
flush KEYWORD2
23+
stop KEYWORD2
24+
connected KEYWORD2
25+
begin KEYWORD2
26+
27+
#######################################
28+
# Constants (LITERAL1)
29+
#######################################
30+

0 commit comments

Comments
 (0)