aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cores/arduino/abi.cpp15
-rw-r--r--cores/arduino/new66
-rw-r--r--cores/arduino/new.cpp96
-rw-r--r--cores/arduino/new.h34
-rw-r--r--libraries/Wire/src/Wire.cpp47
-rw-r--r--libraries/Wire/src/Wire.h6
-rw-r--r--libraries/Wire/src/utility/twi.c173
-rw-r--r--libraries/Wire/src/utility/twi.h6
-rw-r--r--platform.txt5
9 files changed, 361 insertions, 87 deletions
diff --git a/cores/arduino/abi.cpp b/cores/arduino/abi.cpp
index 8d719b8..6e1b0f8 100644
--- a/cores/arduino/abi.cpp
+++ b/cores/arduino/abi.cpp
@@ -21,15 +21,16 @@
extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
+namespace std {
+ [[gnu::weak, noreturn]] void terminate() {
+ abort();
+ }
+}
+
void __cxa_pure_virtual(void) {
- // We might want to write some diagnostics to uart in this case
- //std::terminate();
- abort();
+ std::terminate();
}
void __cxa_deleted_virtual(void) {
- // We might want to write some diagnostics to uart in this case
- //std::terminate();
- abort();
+ std::terminate();
}
-
diff --git a/cores/arduino/new b/cores/arduino/new
new file mode 100644
index 0000000..8cf2103
--- /dev/null
+++ b/cores/arduino/new
@@ -0,0 +1,66 @@
+/*
+ Copyright (c) 2014 Arduino. All right reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef NEW_H
+#define NEW_H
+
+#include <stdlib.h>
+
+namespace std {
+ struct nothrow_t {};
+ extern const nothrow_t nothrow;
+
+ // These are not actually implemented, to prevent overhead and
+ // complexity. They are still declared to allow implementing
+ // them in user code if needed.
+ typedef void (*new_handler)();
+ new_handler set_new_handler(new_handler new_p) noexcept;
+ new_handler get_new_handler() noexcept;
+
+ // This is normally declared in various headers that we do not have
+ // available, so just define it here. We could also use ::size_t
+ // below, but then anyone including <new> can no longer assume
+ // std::size_t is available.
+ using size_t = ::size_t;
+} // namespace std
+
+[[gnu::weak]] void * operator new(std::size_t size);
+[[gnu::weak]] void * operator new[](std::size_t size);
+
+[[gnu::weak]] void * operator new(std::size_t size, const std::nothrow_t tag) noexcept;
+[[gnu::weak]] void * operator new[](std::size_t size, const std::nothrow_t& tag) noexcept;
+
+void * operator new(std::size_t size, void *place) noexcept;
+void * operator new[](std::size_t size, void *place) noexcept;
+
+[[gnu::weak]] void operator delete(void * ptr) noexcept;
+[[gnu::weak]] void operator delete[](void * ptr) noexcept;
+
+#if __cplusplus >= 201402L
+[[gnu::weak]] void operator delete(void* ptr, std::size_t size) noexcept;
+[[gnu::weak]] void operator delete[](void * ptr, std::size_t size) noexcept;
+#endif // __cplusplus >= 201402L
+
+[[gnu::weak]] void operator delete(void* ptr, const std::nothrow_t& tag) noexcept;
+[[gnu::weak]] void operator delete[](void* ptr, const std::nothrow_t& tag) noexcept;
+
+void operator delete(void* ptr, void* place) noexcept;
+void operator delete[](void* ptr, void* place) noexcept;
+
+#endif
+
diff --git a/cores/arduino/new.cpp b/cores/arduino/new.cpp
index fc30cf8..9047b2d 100644
--- a/cores/arduino/new.cpp
+++ b/cores/arduino/new.cpp
@@ -16,26 +16,102 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <stdlib.h>
+#include "new.h"
-void *operator new(size_t size) {
- return malloc(size);
+// The C++ spec dicates that allocation failure should cause the
+// (non-nothrow version of the) operator new to throw an exception.
+// Since we expect to have exceptions disabled, it would be more
+// appropriate (and probably standards-compliant) to terminate instead.
+// Historically failure causes null to be returned, but this define
+// allows switching to more robust terminating behaviour (that might
+// become the default at some point in the future). Note that any code
+// that wants null to be returned can (and should) use the nothrow
+// versions of the new statement anyway and is unaffected by this.
+// #define NEW_TERMINATES_ON_FAILURE
+
+namespace std {
+ // Defined in abi.cpp
+ void terminate();
+
+ const nothrow_t nothrow;
}
-void *operator new[](size_t size) {
+static void * new_helper(std::size_t size) {
+ // Even zero-sized allocations should return a unique pointer, but
+ // malloc does not guarantee this
+ if (size == 0)
+ size = 1;
return malloc(size);
}
-void * operator new(size_t size, void * ptr) noexcept {
- (void)size;
- return ptr;
+void * operator new(std::size_t size) {
+ void *res = new_helper(size);
+#if defined(NEW_TERMINATES_ON_FAILURE)
+ if (!res)
+ std::terminate();
+#endif
+ return res;
+}
+void * operator new[](std::size_t size) {
+ return operator new(size);
}
-void operator delete(void * ptr) {
- free(ptr);
+void * operator new(std::size_t size, const std::nothrow_t tag) noexcept {
+#if defined(NEW_TERMINATES_ON_FAILURE)
+ // Cannot call throwing operator new as standard suggests, so call
+ // new_helper directly then
+ return new_helper(size);
+#else
+ return operator new(size);
+#endif
+}
+void * operator new[](std::size_t size, const std::nothrow_t& tag) noexcept {
+#if defined(NEW_TERMINATES_ON_FAILURE)
+ // Cannot call throwing operator new[] as standard suggests, so call
+ // malloc directly then
+ return new_helper(size);
+#else
+ return operator new[](size);
+#endif
+}
+
+void * operator new(std::size_t size, void *place) noexcept {
+ // Nothing to do
+ (void)size; // unused
+ return place;
+}
+void * operator new[](std::size_t size, void *place) noexcept {
+ return operator new(size, place);
}
-void operator delete[](void * ptr) {
+void operator delete(void * ptr) noexcept {
free(ptr);
}
+void operator delete[](void * ptr) noexcept {
+ operator delete(ptr);
+}
+#if __cplusplus >= 201402L
+void operator delete(void* ptr, std::size_t size) noexcept {
+ operator delete(ptr);
+}
+void operator delete[](void * ptr, std::size_t size) noexcept {
+ operator delete[](ptr);
+}
+#endif // __cplusplus >= 201402L
+
+void operator delete(void* ptr, const std::nothrow_t& tag) noexcept {
+ operator delete(ptr);
+}
+void operator delete[](void* ptr, const std::nothrow_t& tag) noexcept {
+ operator delete[](ptr);
+}
+
+void operator delete(void* ptr, void* place) noexcept {
+ (void)ptr; (void)place; // unused
+ // Nothing to do
+}
+void operator delete[](void* ptr, void* place) noexcept {
+ (void)ptr; (void)place; // unused
+ // Nothing to do
+}
diff --git a/cores/arduino/new.h b/cores/arduino/new.h
index 763f5cc..d529853 100644
--- a/cores/arduino/new.h
+++ b/cores/arduino/new.h
@@ -1,31 +1,3 @@
-/*
- Copyright (c) 2014 Arduino. All right reserved.
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-#ifndef NEW_H
-#define NEW_H
-
-#include <stdlib.h>
-
-void * operator new(size_t size);
-void * operator new[](size_t size);
-void * operator new(size_t size, void * ptr) noexcept;
-void operator delete(void * ptr);
-void operator delete[](void * ptr);
-
-#endif
-
+// This file originally used a non-standard name for this Arduino core
+// only, so still expose the old new.h name for compatibility.
+#include "new"
diff --git a/libraries/Wire/src/Wire.cpp b/libraries/Wire/src/Wire.cpp
index 58916ce..c407776 100644
--- a/libraries/Wire/src/Wire.cpp
+++ b/libraries/Wire/src/Wire.cpp
@@ -18,6 +18,7 @@
Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts
Modified 2017 by Chuck Todd (ctodd@cableone.net) to correct Unconfigured Slave Mode reboot
+ Modified 2020 by Greyson Christoforo (grey@christoforo.net) to implement timeouts
*/
extern "C" {
@@ -86,6 +87,52 @@ void TwoWire::setClock(uint32_t clock)
twi_setFrequency(clock);
}
+/***
+ * Sets the TWI timeout.
+ *
+ * This limits the maximum time to wait for the TWI hardware. If more time passes, the bus is assumed
+ * to have locked up (e.g. due to noise-induced glitches or faulty slaves) and the transaction is aborted.
+ * Optionally, the TWI hardware is also reset, which can be required to allow subsequent transactions to
+ * succeed in some cases (in particular when noise has made the TWI hardware think there is a second
+ * master that has claimed the bus).
+ *
+ * When a timeout is triggered, a flag is set that can be queried with `getWireTimeoutFlag()` and is cleared
+ * when `clearWireTimeoutFlag()` or `setWireTimeoutUs()` is called.
+ *
+ * Note that this timeout can also trigger while waiting for clock stretching or waiting for a second master
+ * to complete its transaction. So make sure to adapt the timeout to accomodate for those cases if needed.
+ * A typical timeout would be 25ms (which is the maximum clock stretching allowed by the SMBus protocol),
+ * but (much) shorter values will usually also work.
+ *
+ * In the future, a timeout will be enabled by default, so if you require the timeout to be disabled, it is
+ * recommended you disable it by default using `setWireTimeoutUs(0)`, even though that is currently
+ * the default.
+ *
+ * @param timeout a timeout value in microseconds, if zero then timeout checking is disabled
+ * @param reset_with_timeout if true then TWI interface will be automatically reset on timeout
+ * if false then TWI interface will not be reset on timeout
+
+ */
+void TwoWire::setWireTimeout(uint32_t timeout, bool reset_with_timeout){
+ twi_setTimeoutInMicros(timeout, reset_with_timeout);
+}
+
+/***
+ * Returns the TWI timeout flag.
+ *
+ * @return true if timeout has occured since the flag was last cleared.
+ */
+bool TwoWire::getWireTimeoutFlag(void){
+ return(twi_manageTimeoutFlag(false));
+}
+
+/***
+ * Clears the TWI timeout flag.
+ */
+void TwoWire::clearWireTimeoutFlag(void){
+ twi_manageTimeoutFlag(true);
+}
+
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddress, uint8_t isize, uint8_t sendStop)
{
if (isize > 0) {
diff --git a/libraries/Wire/src/Wire.h b/libraries/Wire/src/Wire.h
index 702f37d..e70d72e 100644
--- a/libraries/Wire/src/Wire.h
+++ b/libraries/Wire/src/Wire.h
@@ -17,6 +17,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts
+ Modified 2020 by Greyson Christoforo (grey@christoforo.net) to implement timeouts
*/
#ifndef TwoWire_h
@@ -54,13 +55,16 @@ class TwoWire : public Stream
void begin(int);
void end();
void setClock(uint32_t);
+ void setWireTimeout(uint32_t timeout = 25000, bool reset_with_timeout = false);
+ bool getWireTimeoutFlag(void);
+ void clearWireTimeoutFlag(void);
void beginTransmission(uint8_t);
void beginTransmission(int);
uint8_t endTransmission(void);
uint8_t endTransmission(uint8_t);
uint8_t requestFrom(uint8_t, uint8_t);
uint8_t requestFrom(uint8_t, uint8_t, uint8_t);
- uint8_t requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t);
+ uint8_t requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t);
uint8_t requestFrom(int, int);
uint8_t requestFrom(int, int, int);
virtual size_t write(uint8_t);
diff --git a/libraries/Wire/src/utility/twi.c b/libraries/Wire/src/utility/twi.c
index 1a35146..e8a41a2 100644
--- a/libraries/Wire/src/utility/twi.c
+++ b/libraries/Wire/src/utility/twi.c
@@ -17,6 +17,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts
+ Modified 2020 by Greyson Christoforo (grey@christoforo.net) to implement timeouts
*/
#include <math.h>
@@ -24,8 +25,9 @@
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
+#include <util/delay.h>
#include <compat/twi.h>
-#include "Arduino.h" // for digitalWrite
+#include "Arduino.h" // for digitalWrite and micros
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
@@ -43,6 +45,16 @@ static volatile uint8_t twi_slarw;
static volatile uint8_t twi_sendStop; // should the transaction end with a stop
static volatile uint8_t twi_inRepStart; // in the middle of a repeated start
+// twi_timeout_us > 0 prevents the code from getting stuck in various while loops here
+// if twi_timeout_us == 0 then timeout checking is disabled (the previous Wire lib behavior)
+// at some point in the future, the default twi_timeout_us value could become 25000
+// and twi_do_reset_on_timeout could become true
+// to conform to the SMBus standard
+// http://smbus.org/specs/SMBus_3_1_20180319.pdf
+static volatile uint32_t twi_timeout_us = 0ul;
+static volatile bool twi_timed_out_flag = false; // a timeout has been seen
+static volatile bool twi_do_reset_on_timeout = false; // reset the TWI registers on timeout
+
static void (*twi_onSlaveTransmit)(void);
static void (*twi_onSlaveReceive)(uint8_t*, int);
@@ -154,8 +166,12 @@ uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length, uint8_t sen
}
// wait until twi is ready, become master receiver
+ uint32_t startMicros = micros();
while(TWI_READY != twi_state){
- continue;
+ if((twi_timeout_us > 0ul) && ((micros() - startMicros) > twi_timeout_us)) {
+ twi_handleTimeout(twi_do_reset_on_timeout);
+ return 0;
+ }
}
twi_state = TWI_MRX;
twi_sendStop = sendStop;
@@ -183,28 +199,38 @@ uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length, uint8_t sen
// up. Also, don't enable the START interrupt. There may be one pending from the
// repeated start that we sent ourselves, and that would really confuse things.
twi_inRepStart = false; // remember, we're dealing with an ASYNC ISR
+ startMicros = micros();
do {
TWDR = twi_slarw;
+ if((twi_timeout_us > 0ul) && ((micros() - startMicros) > twi_timeout_us)) {
+ twi_handleTimeout(twi_do_reset_on_timeout);
+ return 0;
+ }
} while(TWCR & _BV(TWWC));
TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START
- }
- else
+ } else {
// send start condition
TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTA);
+ }
// wait for read operation to complete
+ startMicros = micros();
while(TWI_MRX == twi_state){
- continue;
+ if((twi_timeout_us > 0ul) && ((micros() - startMicros) > twi_timeout_us)) {
+ twi_handleTimeout(twi_do_reset_on_timeout);
+ return 0;
+ }
}
- if (twi_masterBufferIndex < length)
+ if (twi_masterBufferIndex < length) {
length = twi_masterBufferIndex;
+ }
// copy twi buffer to data
for(i = 0; i < length; ++i){
data[i] = twi_masterBuffer[i];
}
-
+
return length;
}
@@ -222,6 +248,7 @@ uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length, uint8_t sen
* 2 .. address send, NACK received
* 3 .. data send, NACK received
* 4 .. other twi error (lost bus arbitration, bus error, ..)
+ * 5 .. timeout
*/
uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait, uint8_t sendStop)
{
@@ -233,8 +260,12 @@ uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait
}
// wait until twi is ready, become master transmitter
+ uint32_t startMicros = micros();
while(TWI_READY != twi_state){
- continue;
+ if((twi_timeout_us > 0ul) && ((micros() - startMicros) > twi_timeout_us)) {
+ twi_handleTimeout(twi_do_reset_on_timeout);
+ return (5);
+ }
}
twi_state = TWI_MTX;
twi_sendStop = sendStop;
@@ -265,18 +296,27 @@ uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait
// up. Also, don't enable the START interrupt. There may be one pending from the
// repeated start that we sent outselves, and that would really confuse things.
twi_inRepStart = false; // remember, we're dealing with an ASYNC ISR
+ startMicros = micros();
do {
- TWDR = twi_slarw;
+ TWDR = twi_slarw;
+ if((twi_timeout_us > 0ul) && ((micros() - startMicros) > twi_timeout_us)) {
+ twi_handleTimeout(twi_do_reset_on_timeout);
+ return (5);
+ }
} while(TWCR & _BV(TWWC));
TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START
- }
- else
+ } else {
// send start condition
TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE) | _BV(TWSTA); // enable INTs
+ }
// wait for write operation to complete
+ startMicros = micros();
while(wait && (TWI_MTX == twi_state)){
- continue;
+ if((twi_timeout_us > 0ul) && ((micros() - startMicros) > twi_timeout_us)) {
+ twi_handleTimeout(twi_do_reset_on_timeout);
+ return (5);
+ }
}
if (twi_error == 0xFF)
@@ -356,7 +396,7 @@ void twi_reply(uint8_t ack)
if(ack){
TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA);
}else{
- TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT);
+ TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT);
}
}
@@ -373,8 +413,19 @@ void twi_stop(void)
// wait for stop condition to be exectued on bus
// TWINT is not set after a stop condition!
+ // We cannot use micros() from an ISR, so approximate the timeout with cycle-counted delays
+ const uint8_t us_per_loop = 8;
+ uint32_t counter = (twi_timeout_us + us_per_loop - 1)/us_per_loop; // Round up
while(TWCR & _BV(TWSTO)){
- continue;
+ if(twi_timeout_us > 0ul){
+ if (counter > 0ul){
+ _delay_us(us_per_loop);
+ counter--;
+ } else {
+ twi_handleTimeout(twi_do_reset_on_timeout);
+ return;
+ }
+ }
}
// update twi state
@@ -396,6 +447,59 @@ void twi_releaseBus(void)
twi_state = TWI_READY;
}
+/*
+ * Function twi_setTimeoutInMicros
+ * Desc set a timeout for while loops that twi might get stuck in
+ * Input timeout value in microseconds (0 means never time out)
+ * Input reset_with_timeout: true causes timeout events to reset twi
+ * Output none
+ */
+void twi_setTimeoutInMicros(uint32_t timeout, bool reset_with_timeout){
+ twi_timed_out_flag = false;
+ twi_timeout_us = timeout;
+ twi_do_reset_on_timeout = reset_with_timeout;
+}
+
+/*
+ * Function twi_handleTimeout
+ * Desc this gets called whenever a while loop here has lasted longer than
+ * twi_timeout_us microseconds. always sets twi_timed_out_flag
+ * Input reset: true causes this function to reset the twi hardware interface
+ * Output none
+ */
+void twi_handleTimeout(bool reset){
+ twi_timed_out_flag = true;
+
+ if (reset) {
+ // remember bitrate and address settings
+ uint8_t previous_TWBR = TWBR;
+ uint8_t previous_TWAR = TWAR;
+
+ // reset the interface
+ twi_disable();
+ twi_init();
+
+ // reapply the previous register values
+ TWAR = previous_TWAR;
+ TWBR = previous_TWBR;
+ }
+}
+
+/*
+ * Function twi_manageTimeoutFlag
+ * Desc returns true if twi has seen a timeout
+ * optionally clears the timeout flag
+ * Input clear_flag: true if we should reset the hardware
+ * Output none
+ */
+bool twi_manageTimeoutFlag(bool clear_flag){
+ bool flag = twi_timed_out_flag;
+ if (clear_flag){
+ twi_timed_out_flag = false;
+ }
+ return(flag);
+}
+
ISR(TWI_vect)
{
switch(TW_STATUS){
@@ -416,16 +520,16 @@ ISR(TWI_vect)
TWDR = twi_masterBuffer[twi_masterBufferIndex++];
twi_reply(1);
}else{
- if (twi_sendStop)
+ if (twi_sendStop){
twi_stop();
- else {
- twi_inRepStart = true; // we're gonna send the START
- // don't enable the interrupt. We'll generate the start, but we
- // avoid handling the interrupt until we're in the next transaction,
- // at the point where we would normally issue the start.
- TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;
- twi_state = TWI_READY;
- }
+ } else {
+ twi_inRepStart = true; // we're gonna send the START
+ // don't enable the interrupt. We'll generate the start, but we
+ // avoid handling the interrupt until we're in the next transaction,
+ // at the point where we would normally issue the start.
+ TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;
+ twi_state = TWI_READY;
+ }
}
break;
case TW_MT_SLA_NACK: // address sent, nack received
@@ -457,17 +561,17 @@ ISR(TWI_vect)
case TW_MR_DATA_NACK: // data received, nack sent
// put final byte into buffer
twi_masterBuffer[twi_masterBufferIndex++] = TWDR;
- if (twi_sendStop)
- twi_stop();
- else {
- twi_inRepStart = true; // we're gonna send the START
- // don't enable the interrupt. We'll generate the start, but we
- // avoid handling the interrupt until we're in the next transaction,
- // at the point where we would normally issue the start.
- TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;
- twi_state = TWI_READY;
- }
- break;
+ if (twi_sendStop){
+ twi_stop();
+ } else {
+ twi_inRepStart = true; // we're gonna send the START
+ // don't enable the interrupt. We'll generate the start, but we
+ // avoid handling the interrupt until we're in the next transaction,
+ // at the point where we would normally issue the start.
+ TWCR = _BV(TWINT) | _BV(TWSTA)| _BV(TWEN) ;
+ twi_state = TWI_READY;
+ }
+ break;
case TW_MR_SLA_NACK: // address sent, nack received
twi_stop();
break;
@@ -560,4 +664,3 @@ ISR(TWI_vect)
break;
}
}
-
diff --git a/libraries/Wire/src/utility/twi.h b/libraries/Wire/src/utility/twi.h
index d27325e..85b9837 100644
--- a/libraries/Wire/src/utility/twi.h
+++ b/libraries/Wire/src/utility/twi.h
@@ -15,6 +15,8 @@
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+ Modified 2020 by Greyson Christoforo (grey@christoforo.net) to implement timeouts
*/
#ifndef twi_h
@@ -50,6 +52,8 @@
void twi_reply(uint8_t);
void twi_stop(void);
void twi_releaseBus(void);
+ void twi_setTimeoutInMicros(uint32_t, bool);
+ void twi_handleTimeout(bool);
+ bool twi_manageTimeoutFlag(bool);
#endif
-
diff --git a/platform.txt b/platform.txt
index 608ad29..8f46fbc 100644
--- a/platform.txt
+++ b/platform.txt
@@ -6,7 +6,7 @@
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification
name=Arduino AVR Boards
-version=1.8.2
+version=1.8.3
# AVR compile variables
# ---------------------
@@ -33,6 +33,7 @@ compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,
compiler.elf2hex.flags=-O ihex -R .eeprom
compiler.elf2hex.cmd=avr-objcopy
compiler.ldflags=
+compiler.libraries.ldflags=
compiler.size.cmd=avr-size
# This can be overridden in boards.txt
@@ -65,7 +66,7 @@ archive_file_path={build.path}/{archive_file}
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
## Combine gc-sections, archives, and objects
-recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "-L{build.path}" -lm
+recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} {compiler.c.elf.extra_flags} {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} {compiler.libraries.ldflags} "{build.path}/{archive_file}" "-L{build.path}" -lm
## Create output files (.eep and .hex)
recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.eep.flags} {compiler.objcopy.eep.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.eep"