diff options
-rw-r--r-- | boards.txt | 59 | ||||
-rw-r--r-- | cores/arduino/Client.h | 27 | ||||
-rw-r--r-- | cores/arduino/HardwareSerial.cpp | 57 | ||||
-rw-r--r-- | cores/arduino/HardwareSerial.h | 2 | ||||
-rw-r--r-- | cores/arduino/IPAddress.cpp | 56 | ||||
-rw-r--r-- | cores/arduino/IPAddress.h | 76 | ||||
-rwxr-xr-x | cores/arduino/Print.h | 2 | ||||
-rw-r--r-- | cores/arduino/Printable.h | 3 | ||||
-rw-r--r-- | cores/arduino/Server.h | 9 | ||||
-rw-r--r-- | cores/arduino/Udp.h | 90 | ||||
-rwxr-xr-x | cores/arduino/main.cpp | 4 | ||||
-rw-r--r-- | cores/arduino/new.cpp | 18 | ||||
-rw-r--r-- | cores/arduino/new.h | 22 |
13 files changed, 400 insertions, 25 deletions
@@ -19,7 +19,7 @@ leonardo.build.variant=leonardo ############################################################## uno.name=Arduino Uno -uno.upload.protocol=stk500 +uno.upload.protocol=arduino uno.upload.maximum_size=32256 uno.upload.speed=115200 uno.bootloader.low_fuses=0xff @@ -38,7 +38,7 @@ uno.build.variant=standard atmega328.name=Arduino Duemilanove w/ ATmega328 -atmega328.upload.protocol=stk500 +atmega328.upload.protocol=arduino atmega328.upload.maximum_size=30720 atmega328.upload.speed=57600 @@ -59,7 +59,7 @@ atmega328.build.variant=standard diecimila.name=Arduino Diecimila or Duemilanove w/ ATmega168 -diecimila.upload.protocol=stk500 +diecimila.upload.protocol=arduino diecimila.upload.maximum_size=14336 diecimila.upload.speed=19200 @@ -80,7 +80,7 @@ diecimila.build.variant=standard nano328.name=Arduino Nano w/ ATmega328 -nano328.upload.protocol=stk500 +nano328.upload.protocol=arduino nano328.upload.maximum_size=30720 nano328.upload.speed=57600 @@ -101,7 +101,7 @@ nano328.build.variant=eightanaloginputs nano.name=Arduino Nano w/ ATmega168 -nano.upload.protocol=stk500 +nano.upload.protocol=arduino nano.upload.maximum_size=14336 nano.upload.speed=19200 @@ -120,7 +120,7 @@ nano.build.variant=eightanaloginputs ############################################################## -mega2560.name=Arduino Mega 2560 +mega2560.name=Arduino Mega 2560 or Mega ADK mega2560.upload.protocol=stk500v2 mega2560.upload.maximum_size=258048 @@ -143,7 +143,7 @@ mega2560.build.variant=mega mega.name=Arduino Mega (ATmega1280) -mega.upload.protocol=stk500 +mega.upload.protocol=arduino mega.upload.maximum_size=126976 mega.upload.speed=57600 @@ -164,7 +164,7 @@ mega.build.variant=mega mini.name=Arduino Mini -mini.upload.protocol=stk500 +mini.upload.protocol=arduino mini.upload.maximum_size=14336 mini.upload.speed=19200 @@ -183,9 +183,30 @@ mini.build.variant=eightanaloginputs ############################################################## +ethernet.name=Arduino Ethernet + +ethernet.upload.protocol=stk500 +ethernet.upload.maximum_size=32256 +ethernet.upload.speed=115200 + +ethernet.bootloader.low_fuses=0xff +ethernet.bootloader.high_fuses=0xde +ethernet.bootloader.extended_fuses=0x05 +ethernet.bootloader.path=optiboot +ethernet.bootloader.file=optiboot_atmega328.hex +ethernet.bootloader.unlock_bits=0x3F +ethernet.bootloader.lock_bits=0x0F + +ethernet.build.variant=standard +ethernet.build.mcu=atmega328p +ethernet.build.f_cpu=16000000L +ethernet.build.core=arduino + +############################################################## + fio.name=Arduino Fio -fio.upload.protocol=stk500 +fio.upload.protocol=arduino fio.upload.maximum_size=30720 fio.upload.speed=57600 @@ -206,7 +227,7 @@ fio.build.variant=eightanaloginputs bt328.name=Arduino BT w/ ATmega328 -bt328.upload.protocol=stk500 +bt328.upload.protocol=arduino bt328.upload.maximum_size=28672 bt328.upload.speed=19200 bt328.upload.disable_flushing=true @@ -228,7 +249,7 @@ bt328.build.variant=eightanaloginputs bt.name=Arduino BT w/ ATmega168 -bt.upload.protocol=stk500 +bt.upload.protocol=arduino bt.upload.maximum_size=14336 bt.upload.speed=19200 bt.upload.disable_flushing=true @@ -250,7 +271,7 @@ bt.build.variant=eightanaloginputs lilypad328.name=LilyPad Arduino w/ ATmega328 -lilypad328.upload.protocol=stk500 +lilypad328.upload.protocol=arduino lilypad328.upload.maximum_size=30720 lilypad328.upload.speed=57600 @@ -271,7 +292,7 @@ lilypad328.build.variant=standard lilypad.name=LilyPad Arduino w/ ATmega168 -lilypad.upload.protocol=stk500 +lilypad.upload.protocol=arduino lilypad.upload.maximum_size=14336 lilypad.upload.speed=19200 @@ -292,7 +313,7 @@ lilypad.build.variant=standard pro5v328.name=Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328 -pro5v328.upload.protocol=stk500 +pro5v328.upload.protocol=arduino pro5v328.upload.maximum_size=30720 pro5v328.upload.speed=57600 @@ -313,7 +334,7 @@ pro5v328.build.variant=standard pro5v.name=Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega168 -pro5v.upload.protocol=stk500 +pro5v.upload.protocol=arduino pro5v.upload.maximum_size=14336 pro5v.upload.speed=19200 @@ -334,7 +355,7 @@ pro5v.build.variant=standard pro328.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 -pro328.upload.protocol=stk500 +pro328.upload.protocol=arduino pro328.upload.maximum_size=30720 pro328.upload.speed=57600 @@ -355,7 +376,7 @@ pro328.build.variant=standard pro.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168 -pro.upload.protocol=stk500 +pro.upload.protocol=arduino pro.upload.maximum_size=14336 pro.upload.speed=19200 @@ -376,7 +397,7 @@ pro.build.variant=standard atmega168.name=Arduino NG or older w/ ATmega168 -atmega168.upload.protocol=stk500 +atmega168.upload.protocol=arduino atmega168.upload.maximum_size=14336 atmega168.upload.speed=19200 @@ -397,7 +418,7 @@ atmega168.build.variant=standard atmega8.name=Arduino NG or older w/ ATmega8 -atmega8.upload.protocol=stk500 +atmega8.upload.protocol=arduino atmega8.upload.maximum_size=7168 atmega8.upload.speed=19200 diff --git a/cores/arduino/Client.h b/cores/arduino/Client.h new file mode 100644 index 0000000..ed9e9b4 --- /dev/null +++ b/cores/arduino/Client.h @@ -0,0 +1,27 @@ +#ifndef client_h +#define client_h +#include "Print.h" +#include "Stream.h" +#include "IPAddress.h" + +class Client : public Stream { + +public: + virtual int connect(IPAddress ip, uint16_t port) =0; + virtual int connect(const char *host, uint16_t port) =0; + virtual size_t write(uint8_t) =0; + virtual size_t write(const char *str) =0; + virtual size_t write(const uint8_t *buf, size_t size) =0; + virtual int available() = 0; + virtual int read() = 0; + virtual int read(uint8_t *buf, size_t size) = 0; + virtual int peek() = 0; + virtual void flush() = 0; + virtual void stop() = 0; + virtual uint8_t connected() = 0; + virtual operator bool() = 0; +protected: + uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; +}; + +#endif diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp index 48f5fd3..a31b266 100644 --- a/cores/arduino/HardwareSerial.cpp +++ b/cores/arduino/HardwareSerial.cpp @@ -95,6 +95,8 @@ inline void store_char(unsigned char c, ring_buffer *buffer) #else void serialEvent() __attribute__((weak)); void serialEvent() {} + volatile static unsigned char serialEvent_flag = 0; + #define serialEvent_implemented #if defined(USART_RX_vect) SIGNAL(USART_RX_vect) #elif defined(SIG_USART0_RECV) @@ -115,7 +117,7 @@ inline void store_char(unsigned char c, ring_buffer *buffer) #error UDR not defined #endif store_char(c, &rx_buffer); - serialEvent(); + serialEvent_flag = 1; } #endif #endif @@ -123,11 +125,13 @@ inline void store_char(unsigned char c, ring_buffer *buffer) #if defined(USART1_RX_vect) void serialEvent1() __attribute__((weak)); void serialEvent1() {} + volatile static unsigned char serialEvent1_flag = 0; + #define serialEvent1_implemented SIGNAL(USART1_RX_vect) { unsigned char c = UDR1; store_char(c, &rx_buffer1); - serialEvent1(); + serialEvent1_flag = 1; } #elif defined(SIG_USART1_RECV) #error SIG_USART1_RECV @@ -136,11 +140,13 @@ inline void store_char(unsigned char c, ring_buffer *buffer) #if defined(USART2_RX_vect) && defined(UDR2) void serialEvent2() __attribute__((weak)); void serialEvent2() {} + volatile static unsigned char serialEvent2_flag = 0; + #define serialEvent2_implemented SIGNAL(USART2_RX_vect) { unsigned char c = UDR2; store_char(c, &rx_buffer2); - serialEvent2(); + serialEvent2_flag = 1; } #elif defined(SIG_USART2_RECV) #error SIG_USART2_RECV @@ -149,19 +155,62 @@ inline void store_char(unsigned char c, ring_buffer *buffer) #if defined(USART3_RX_vect) && defined(UDR3) void serialEvent3() __attribute__((weak)); void serialEvent3() {} + volatile static unsigned char serialEvent3_flag = 0; + #define serialEvent3_implemented SIGNAL(USART3_RX_vect) { unsigned char c = UDR3; store_char(c, &rx_buffer3); - serialEvent3(); + serialEvent3_flag = 1; } #elif defined(SIG_USART3_RECV) #error SIG_USART3_RECV #endif +<<<<<<< HEAD #if !defined(USART0_UDRE_vect) && defined(USART1_UDRE_vect) // do nothing - on the 32u4 the first USART is USART1 #else +======= +void serialEventRun(void) +{ + unsigned char flag, oldSREG; +#ifdef serialEvent_implemented + oldSREG = SREG; + noInterrupts(); + flag = serialEvent_flag; + serialEvent_flag = 0; + SREG = oldSREG; + if (flag) serialEvent(); +#endif +#ifdef serialEvent1_implemented + oldSREG = SREG; + noInterrupts(); + flag = serialEvent1_flag; + serialEvent1_flag = 0; + SREG = oldSREG; + if (flag) serialEvent1(); +#endif +#ifdef serialEvent2_implemented + oldSREG = SREG; + noInterrupts(); + flag = serialEvent2_flag; + serialEvent2_flag = 0; + SREG = oldSREG; + if (flag) serialEvent2(); +#endif +#ifdef serialEvent3_implemented + oldSREG = SREG; + noInterrupts(); + flag = serialEvent3_flag; + serialEvent3_flag = 0; + SREG = oldSREG; + if (flag) serialEvent3(); +#endif +} + + +>>>>>>> 0c92f230b5202b241de875a3baff9dfd1cf7a618 #if !defined(UART0_UDRE_vect) && !defined(UART_UDRE_vect) && !defined(USART0_UDRE_vect) && !defined(USART_UDRE_vect) #error Don't know what the Data Register Empty vector is called for the first UART #else diff --git a/cores/arduino/HardwareSerial.h b/cores/arduino/HardwareSerial.h index cadfa65..d0dca06 100644 --- a/cores/arduino/HardwareSerial.h +++ b/cores/arduino/HardwareSerial.h @@ -75,4 +75,6 @@ class HardwareSerial : public Stream extern HardwareSerial Serial3; #endif +extern void serialEventRun(void); + #endif diff --git a/cores/arduino/IPAddress.cpp b/cores/arduino/IPAddress.cpp new file mode 100644 index 0000000..fe3deb7 --- /dev/null +++ b/cores/arduino/IPAddress.cpp @@ -0,0 +1,56 @@ + +#include <Arduino.h> +#include <IPAddress.h> + +IPAddress::IPAddress() +{ + memset(_address, 0, sizeof(_address)); +} + +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; +} + +IPAddress::IPAddress(uint32_t address) +{ + memcpy(_address, &address, sizeof(_address)); +} + +IPAddress::IPAddress(const uint8_t *address) +{ + memcpy(_address, address, sizeof(_address)); +} + +IPAddress& IPAddress::operator=(const uint8_t *address) +{ + memcpy(_address, address, sizeof(_address)); + return *this; +} + +IPAddress& IPAddress::operator=(uint32_t address) +{ + memcpy(_address, (const uint8_t *)&address, sizeof(_address)); + return *this; +} + +bool IPAddress::operator==(const uint8_t* addr) +{ + return memcmp(addr, _address, sizeof(_address)) == 0; +} + +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('.'); + } + n += p.print(_address[3], DEC); + return n; +} + diff --git a/cores/arduino/IPAddress.h b/cores/arduino/IPAddress.h new file mode 100644 index 0000000..2585aec --- /dev/null +++ b/cores/arduino/IPAddress.h @@ -0,0 +1,76 @@ +/* + * + * MIT License: + * Copyright (c) 2011 Adrian McEwen + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * adrianm@mcqn.com 1/1/2011 + */ + +#ifndef IPAddress_h +#define IPAddress_h + +#include <Printable.h> + +// A class to make it easier to handle and pass around IP addresses + +class IPAddress : public Printable { +private: + uint8_t _address[4]; // IPv4 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; }; + +public: + // Constructors + IPAddress(); + IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); + IPAddress(uint32_t address); + IPAddress(const uint8_t *address); + + // 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)); }; + bool operator==(const uint8_t* addr); + + // 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]; }; + + // Overloaded copy operators to allow initialisation of IPAddress objects from other types + IPAddress& operator=(const uint8_t *address); + IPAddress& operator=(uint32_t address); + + virtual size_t printTo(Print& p) const; + + friend class EthernetClass; + friend class UDP; + friend class Client; + friend class Server; + friend class DhcpClass; + friend class DNSClient; +}; + +const IPAddress INADDR_NONE(0,0,0,0); + + +#endif diff --git a/cores/arduino/Print.h b/cores/arduino/Print.h index fce302e..8530b03 100755 --- a/cores/arduino/Print.h +++ b/cores/arduino/Print.h @@ -42,7 +42,7 @@ class Print public: Print() : write_error(0) {} - int writeError() { return write_error; } + int getWriteError() { return write_error; } void clearWriteError() { setWriteError(0); } virtual size_t write(uint8_t) = 0; diff --git a/cores/arduino/Printable.h b/cores/arduino/Printable.h index e22e87e..d03c9af 100644 --- a/cores/arduino/Printable.h +++ b/cores/arduino/Printable.h @@ -20,6 +20,8 @@ #ifndef Printable_h #define Printable_h +#include <new.h> + class Print; /** The Printable class provides a way for new classes to allow themselves to be printed. @@ -27,6 +29,7 @@ class Print; for users to print out instances of this class by passing them into the usual Print::print and Print::println methods. */ + class Printable { public: diff --git a/cores/arduino/Server.h b/cores/arduino/Server.h new file mode 100644 index 0000000..edab726 --- /dev/null +++ b/cores/arduino/Server.h @@ -0,0 +1,9 @@ +#ifndef server_h +#define server_h + +class Server { +public: + virtual void begin() =0; +}; + +#endif diff --git a/cores/arduino/Udp.h b/cores/arduino/Udp.h new file mode 100644 index 0000000..1fb9cd3 --- /dev/null +++ b/cores/arduino/Udp.h @@ -0,0 +1,90 @@ +/* + * Udp.cpp: Library to send/receive UDP packets. + * + * NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these) + * 1) UDP does not guarantee the order in which assembled UDP packets are received. This + * might not happen often in practice, but in larger network topologies, a UDP + * packet can be received out of sequence. + * 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being + * aware of it. Again, this may not be a concern in practice on small local networks. + * For more information, see http://www.cafeaulait.org/course/week12/35.html + * + * MIT License: + * Copyright (c) 2008 Bjoern Hartmann + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * bjoern@cs.stanford.edu 12/30/2008 + */ + +#ifndef udp_h +#define udp_h + +#include <Stream.h> +#include <IPAddress.h> + +class UDP : public Stream { + +public: + virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use + virtual void stop() =0; // Finish with the UDP socket + + // Sending UDP packets + + // Start building up a packet to send to the remote host specific in ip and port + // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port + virtual int beginPacket(IPAddress ip, uint16_t port) =0; + // Start building up a packet to send to the remote host specific in host and port + // Returns 1 if successful, 0 if there was a problem resolving the hostname or port + virtual int beginPacket(const char *host, uint16_t port) =0; + // Finish off this packet and send it + // Returns 1 if the packet was sent successfully, 0 if there was an error + virtual int endPacket() =0; + // Write a single byte into the packet + virtual size_t write(uint8_t) =0; + // Write a string of characters into the packet + virtual size_t write(const char *str) =0; + // Write size bytes from buffer into the packet + virtual size_t write(const uint8_t *buffer, size_t size) =0; + + // Start processing the next available incoming packet + // Returns the size of the packet in bytes, or 0 if no packets are available + virtual int parsePacket() =0; + // Number of bytes remaining in the current packet + virtual int available() =0; + // Read a single byte from the current packet + virtual int read() =0; + // Read up to len bytes from the current packet and place them into buffer + // Returns the number of bytes read, or 0 if none are available + virtual int read(unsigned char* buffer, size_t len) =0; + // Read up to len characters from the current packet and place them into buffer + // Returns the number of characters read, or 0 if none are available + virtual int read(char* buffer, size_t len) =0; + // Return the next byte from the current packet without moving on to the next byte + virtual int peek() =0; + virtual void flush() =0; // Finish reading the current packet + + // Return the IP address of the host who sent the current incoming packet + virtual IPAddress remoteIP() =0; + // Return the port of the host who sent the current incoming packet + virtual uint16_t remotePort() =0; +protected: + uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; +}; + +#endif diff --git a/cores/arduino/main.cpp b/cores/arduino/main.cpp index ba00ae0..097f5ed 100755 --- a/cores/arduino/main.cpp +++ b/cores/arduino/main.cpp @@ -11,8 +11,10 @@ int main(void) setup(); - for (;;) + for (;;) { loop(); + serialEventRun(); + } return 0; } diff --git a/cores/arduino/new.cpp b/cores/arduino/new.cpp new file mode 100644 index 0000000..0f6d422 --- /dev/null +++ b/cores/arduino/new.cpp @@ -0,0 +1,18 @@ +#include <new.h> + +void * operator new(size_t size) +{ + return malloc(size); +} + +void operator delete(void * ptr) +{ + free(ptr); +} + +int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);}; +void __cxa_guard_release (__guard *g) {*(char *)g = 1;}; +void __cxa_guard_abort (__guard *) {}; + +void __cxa_pure_virtual(void) {}; + diff --git a/cores/arduino/new.h b/cores/arduino/new.h new file mode 100644 index 0000000..cd940ce --- /dev/null +++ b/cores/arduino/new.h @@ -0,0 +1,22 @@ +/* Header to define new/delete operators as they aren't provided by avr-gcc by default + Taken from http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=59453 + */ + +#ifndef NEW_H +#define NEW_H + +#include <stdlib.h> + +void * operator new(size_t size); +void operator delete(void * ptr); + +__extension__ typedef int __guard __attribute__((mode (__DI__))); + +extern "C" int __cxa_guard_acquire(__guard *); +extern "C" void __cxa_guard_release (__guard *); +extern "C" void __cxa_guard_abort (__guard *); + +extern "C" void __cxa_pure_virtual(void); + +#endif + |