Skip to content

Commit abf6330

Browse files
committed
Merged 1.0.5
Merge remote-tracking branch 'arduino/master' into ide-1.5.x Conflicts: app/src/processing/app/Base.java build/shared/revisions.txt hardware/arduino/avr/cores/arduino/malloc.c hardware/arduino/cores/arduino/avr-libc/malloc.c hardware/arduino/cores/arduino/malloc.c todo.txt
2 parents 7243df2 + bf0e8f9 commit abf6330

File tree

8 files changed

+305
-170
lines changed

8 files changed

+305
-170
lines changed

hardware/arduino/avr/cores/arduino/HardwareSerial.cpp

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,19 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
104104
#if !defined(USART0_RX_vect) && defined(USART1_RX_vect)
105105
// do nothing - on the 32u4 the first USART is USART1
106106
#else
107-
#if !defined(USART_RX_vect) && !defined(SIG_USART0_RECV) && \
108-
!defined(SIG_UART0_RECV) && !defined(USART0_RX_vect) && \
109-
!defined(SIG_UART_RECV)
107+
#if !defined(USART_RX_vect) && !defined(USART0_RX_vect) && \
108+
!defined(USART_RXC_vect)
110109
#error "Don't know what the Data Received vector is called for the first UART"
111110
#else
112111
void serialEvent() __attribute__((weak));
113112
void serialEvent() {}
114113
#define serialEvent_implemented
115114
#if defined(USART_RX_vect)
116-
SIGNAL(USART_RX_vect)
117-
#elif defined(SIG_USART0_RECV)
118-
SIGNAL(SIG_USART0_RECV)
119-
#elif defined(SIG_UART0_RECV)
120-
SIGNAL(SIG_UART0_RECV)
115+
ISR(USART_RX_vect)
121116
#elif defined(USART0_RX_vect)
122-
SIGNAL(USART0_RX_vect)
123-
#elif defined(SIG_UART_RECV)
124-
SIGNAL(SIG_UART_RECV)
117+
ISR(USART0_RX_vect)
118+
#elif defined(USART_RXC_vect)
119+
ISR(USART_RXC_vect) // ATmega8
125120
#endif
126121
{
127122
#if defined(UDR0)
@@ -149,7 +144,7 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
149144
void serialEvent1() __attribute__((weak));
150145
void serialEvent1() {}
151146
#define serialEvent1_implemented
152-
SIGNAL(USART1_RX_vect)
147+
ISR(USART1_RX_vect)
153148
{
154149
if (bit_is_clear(UCSR1A, UPE1)) {
155150
unsigned char c = UDR1;
@@ -158,15 +153,13 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
158153
unsigned char c = UDR1;
159154
};
160155
}
161-
#elif defined(SIG_USART1_RECV)
162-
#error SIG_USART1_RECV
163156
#endif
164157

165158
#if defined(USART2_RX_vect) && defined(UDR2)
166159
void serialEvent2() __attribute__((weak));
167160
void serialEvent2() {}
168161
#define serialEvent2_implemented
169-
SIGNAL(USART2_RX_vect)
162+
ISR(USART2_RX_vect)
170163
{
171164
if (bit_is_clear(UCSR2A, UPE2)) {
172165
unsigned char c = UDR2;
@@ -175,15 +168,13 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
175168
unsigned char c = UDR2;
176169
};
177170
}
178-
#elif defined(SIG_USART2_RECV)
179-
#error SIG_USART2_RECV
180171
#endif
181172

182173
#if defined(USART3_RX_vect) && defined(UDR3)
183174
void serialEvent3() __attribute__((weak));
184175
void serialEvent3() {}
185176
#define serialEvent3_implemented
186-
SIGNAL(USART3_RX_vect)
177+
ISR(USART3_RX_vect)
187178
{
188179
if (bit_is_clear(UCSR3A, UPE3)) {
189180
unsigned char c = UDR3;
@@ -192,8 +183,6 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
192183
unsigned char c = UDR3;
193184
};
194185
}
195-
#elif defined(SIG_USART3_RECV)
196-
#error SIG_USART3_RECV
197186
#endif
198187

199188
void serialEventRun(void)

hardware/arduino/avr/cores/arduino/WInterrupts.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -230,82 +230,82 @@ void attachInterruptTwi(void (*userFunc)(void) ) {
230230
*/
231231

232232
#if defined(__AVR_ATmega32U4__)
233-
SIGNAL(INT0_vect) {
233+
ISR(INT0_vect) {
234234
if(intFunc[EXTERNAL_INT_0])
235235
intFunc[EXTERNAL_INT_0]();
236236
}
237237

238-
SIGNAL(INT1_vect) {
238+
ISR(INT1_vect) {
239239
if(intFunc[EXTERNAL_INT_1])
240240
intFunc[EXTERNAL_INT_1]();
241241
}
242242

243-
SIGNAL(INT2_vect) {
243+
ISR(INT2_vect) {
244244
if(intFunc[EXTERNAL_INT_2])
245245
intFunc[EXTERNAL_INT_2]();
246246
}
247247

248-
SIGNAL(INT3_vect) {
248+
ISR(INT3_vect) {
249249
if(intFunc[EXTERNAL_INT_3])
250250
intFunc[EXTERNAL_INT_3]();
251251
}
252252

253253
#elif defined(EICRA) && defined(EICRB)
254254

255-
SIGNAL(INT0_vect) {
255+
ISR(INT0_vect) {
256256
if(intFunc[EXTERNAL_INT_2])
257257
intFunc[EXTERNAL_INT_2]();
258258
}
259259

260-
SIGNAL(INT1_vect) {
260+
ISR(INT1_vect) {
261261
if(intFunc[EXTERNAL_INT_3])
262262
intFunc[EXTERNAL_INT_3]();
263263
}
264264

265-
SIGNAL(INT2_vect) {
265+
ISR(INT2_vect) {
266266
if(intFunc[EXTERNAL_INT_4])
267267
intFunc[EXTERNAL_INT_4]();
268268
}
269269

270-
SIGNAL(INT3_vect) {
270+
ISR(INT3_vect) {
271271
if(intFunc[EXTERNAL_INT_5])
272272
intFunc[EXTERNAL_INT_5]();
273273
}
274274

275-
SIGNAL(INT4_vect) {
275+
ISR(INT4_vect) {
276276
if(intFunc[EXTERNAL_INT_0])
277277
intFunc[EXTERNAL_INT_0]();
278278
}
279279

280-
SIGNAL(INT5_vect) {
280+
ISR(INT5_vect) {
281281
if(intFunc[EXTERNAL_INT_1])
282282
intFunc[EXTERNAL_INT_1]();
283283
}
284284

285-
SIGNAL(INT6_vect) {
285+
ISR(INT6_vect) {
286286
if(intFunc[EXTERNAL_INT_6])
287287
intFunc[EXTERNAL_INT_6]();
288288
}
289289

290-
SIGNAL(INT7_vect) {
290+
ISR(INT7_vect) {
291291
if(intFunc[EXTERNAL_INT_7])
292292
intFunc[EXTERNAL_INT_7]();
293293
}
294294

295295
#else
296296

297-
SIGNAL(INT0_vect) {
297+
ISR(INT0_vect) {
298298
if(intFunc[EXTERNAL_INT_0])
299299
intFunc[EXTERNAL_INT_0]();
300300
}
301301

302-
SIGNAL(INT1_vect) {
302+
ISR(INT1_vect) {
303303
if(intFunc[EXTERNAL_INT_1])
304304
intFunc[EXTERNAL_INT_1]();
305305
}
306306

307307
#if defined(EICRA) && defined(ISC20)
308-
SIGNAL(INT2_vect) {
308+
ISR(INT2_vect) {
309309
if(intFunc[EXTERNAL_INT_2])
310310
intFunc[EXTERNAL_INT_2]();
311311
}
@@ -314,7 +314,7 @@ SIGNAL(INT2_vect) {
314314
#endif
315315

316316
/*
317-
SIGNAL(SIG_2WIRE_SERIAL) {
317+
ISR(TWI_vect) {
318318
if(twiIntFunc)
319319
twiIntFunc();
320320
}

hardware/arduino/avr/cores/arduino/malloc.c renamed to hardware/arduino/avr/cores/arduino/avr-libc/malloc.c

Lines changed: 19 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
Copyright (c) 2010 Gerben van den Broeke
33
All rights reserved.
44
5-
malloc, free, realloc from avr-libc 1.7.0
6-
with minor modifications, by Paul Stoffregen
7-
85
Redistribution and use in source and binary forms, with or without
96
modification, are permitted provided that the following conditions are met:
107
@@ -33,20 +30,14 @@
3330
POSSIBILITY OF SUCH DAMAGE.
3431
*/
3532

33+
34+
/* $Id: malloc.c 2149 2010-06-09 20:45:37Z joerg_wunsch $ */
3635

3736
#include <stdlib.h>
38-
#include <inttypes.h>
39-
#include <string.h>
40-
#include <avr/io.h>
41-
42-
43-
#define __MALLOC_MARGIN__ 120
37+
#include "sectionname.h"
38+
#include "stdlib_private.h"
4439

45-
46-
struct __freelist {
47-
size_t sz;
48-
struct __freelist *nx;
49-
};
40+
#include <avr/io.h>
5041

5142
/*
5243
* Exported interface:
@@ -59,13 +50,16 @@ struct __freelist {
5950
* with the data segment.
6051
*/
6152

53+
/* May be changed by the user only before the first malloc() call. */
54+
55+
size_t __malloc_margin = 128;
56+
char *__malloc_heap_start = &__heap_start;
57+
char *__malloc_heap_end = &__heap_end;
6258

63-
#define STACK_POINTER() ((char *)AVR_STACK_POINTER_REG)
64-
extern char __heap_start;
65-
char *__brkval = &__heap_start; // first location not yet allocated
66-
struct __freelist *__flp; // freelist pointer (head of freelist)
67-
char *__brkval_maximum = 100;
59+
char *__brkval;
60+
struct __freelist *__flp;
6861

62+
ATTRIBUTE_CLIB_SECTION
6963
void *
7064
malloc(size_t len)
7165
{
@@ -160,7 +154,11 @@ malloc(size_t len)
160154
* Since we don't have an operating system, just make sure
161155
* that we don't collide with the stack.
162156
*/
163-
cp = STACK_POINTER() - __MALLOC_MARGIN__;
157+
if (__brkval == 0)
158+
__brkval = __malloc_heap_start;
159+
cp = __malloc_heap_end;
160+
if (cp == 0)
161+
cp = STACK_POINTER() - __malloc_margin;
164162
if (cp <= __brkval)
165163
/*
166164
* Memory exhausted.
@@ -173,7 +171,6 @@ malloc(size_t len)
173171
if (avail >= len && avail >= len + sizeof(size_t)) {
174172
fp1 = (struct __freelist *)__brkval;
175173
__brkval += len + sizeof(size_t);
176-
__brkval_maximum = __brkval;
177174
fp1->sz = len;
178175
return &(fp1->nx);
179176
}
@@ -184,6 +181,7 @@ malloc(size_t len)
184181
}
185182

186183

184+
ATTRIBUTE_CLIB_SECTION
187185
void
188186
free(void *p)
189187
{
@@ -267,114 +265,3 @@ free(void *p)
267265
}
268266
}
269267

270-
271-
272-
void *
273-
realloc(void *ptr, size_t len)
274-
{
275-
struct __freelist *fp1, *fp2, *fp3, *ofp3;
276-
char *cp, *cp1;
277-
void *memp;
278-
size_t s, incr;
279-
280-
/* Trivial case, required by C standard. */
281-
if (ptr == 0)
282-
return malloc(len);
283-
284-
cp1 = (char *)ptr;
285-
cp1 -= sizeof(size_t);
286-
fp1 = (struct __freelist *)cp1;
287-
288-
cp = (char *)ptr + len; /* new next pointer */
289-
if (cp < cp1)
290-
/* Pointer wrapped across top of RAM, fail. */
291-
return 0;
292-
293-
/*
294-
* See whether we are growing or shrinking. When shrinking,
295-
* we split off a chunk for the released portion, and call
296-
* free() on it. Therefore, we can only shrink if the new
297-
* size is at least sizeof(struct __freelist) smaller than the
298-
* previous size.
299-
*/
300-
if (len <= fp1->sz) {
301-
/* The first test catches a possible unsigned int
302-
* rollover condition. */
303-
if (fp1->sz <= sizeof(struct __freelist) ||
304-
len > fp1->sz - sizeof(struct __freelist))
305-
return ptr;
306-
fp2 = (struct __freelist *)cp;
307-
fp2->sz = fp1->sz - len - sizeof(size_t);
308-
fp1->sz = len;
309-
free(&(fp2->nx));
310-
return ptr;
311-
}
312-
313-
/*
314-
* If we get here, we are growing. First, see whether there
315-
* is space in the free list on top of our current chunk.
316-
*/
317-
incr = len - fp1->sz;
318-
cp = (char *)ptr + fp1->sz;
319-
fp2 = (struct __freelist *)cp;
320-
for (s = 0, ofp3 = 0, fp3 = __flp;
321-
fp3;
322-
ofp3 = fp3, fp3 = fp3->nx) {
323-
if (fp3 == fp2 && fp3->sz + sizeof(size_t) >= incr) {
324-
/* found something that fits */
325-
if (fp3->sz + sizeof(size_t) - incr > sizeof(struct __freelist)) {
326-
/* split off a new freelist entry */
327-
cp = (char *)ptr + len;
328-
fp2 = (struct __freelist *)cp;
329-
fp2->nx = fp3->nx;
330-
fp2->sz = fp3->sz - incr;
331-
fp1->sz = len;
332-
} else {
333-
/* it just fits, so use it entirely */
334-
fp1->sz += fp3->sz + sizeof(size_t);
335-
fp2 = fp3->nx;
336-
}
337-
if (ofp3)
338-
ofp3->nx = fp2;
339-
else
340-
__flp = fp2;
341-
return ptr;
342-
}
343-
/*
344-
* Find the largest chunk on the freelist while
345-
* walking it.
346-
*/
347-
if (fp3->sz > s)
348-
s = fp3->sz;
349-
}
350-
/*
351-
* If we are the topmost chunk in memory, and there was no
352-
* large enough chunk on the freelist that could be re-used
353-
* (by a call to malloc() below), quickly extend the
354-
* allocation area if possible, without need to copy the old
355-
* data.
356-
*/
357-
if (__brkval == (char *)ptr + fp1->sz && len > s) {
358-
cp = (char *)ptr + len;
359-
cp1 = STACK_POINTER() - __MALLOC_MARGIN__;
360-
if (cp < cp1) {
361-
__brkval = cp;
362-
__brkval_maximum = cp;
363-
fp1->sz = len;
364-
return ptr;
365-
}
366-
/* If that failed, we are out of luck. */
367-
return 0;
368-
}
369-
370-
/*
371-
* Call malloc() for a new chunk, then copy over the data, and
372-
* release the old region.
373-
*/
374-
if ((memp = malloc(len)) == 0)
375-
return 0;
376-
memcpy(memp, ptr, fp1->sz);
377-
free(ptr);
378-
return memp;
379-
}
380-

0 commit comments

Comments
 (0)