From e958354841da224aad059e4dbc13fa4e6e98acc5 Mon Sep 17 00:00:00 2001 From: Dino Tinitigan Date: Mon, 8 May 2017 08:36:37 -0700 Subject: [PATCH 1/3] Revert "Increase delay between each Serial.write()" This reverts commit 0ebbf9efde70498a8c63df227160899fec01f6e1. --- cores/arduino/CDCSerialClass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/arduino/CDCSerialClass.cpp b/cores/arduino/CDCSerialClass.cpp index 9e5c4870..878cbac6 100644 --- a/cores/arduino/CDCSerialClass.cpp +++ b/cores/arduino/CDCSerialClass.cpp @@ -30,7 +30,7 @@ #include "wiring_digital.h" #include "variant.h" -#define CDCACM_FIXED_DELAY 120 +#define CDCACM_FIXED_DELAY 64 extern void CDCSerial_Handler(void); extern void serialEventRun1(void) __attribute__((weak)); From e6f502482a13c0d02c5e28388401a83fb249e676 Mon Sep 17 00:00:00 2001 From: Dino Tinitigan Date: Mon, 8 May 2017 08:41:50 -0700 Subject: [PATCH 2/3] Revert "CDC-ACM CODK-M firmware compatibility changes" This reverts commit dea61b83818d92c6d11cd80d03368f5886f3f4f1. --- cores/arduino/CDCSerialClass.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cores/arduino/CDCSerialClass.cpp b/cores/arduino/CDCSerialClass.cpp index 878cbac6..5cd0083d 100644 --- a/cores/arduino/CDCSerialClass.cpp +++ b/cores/arduino/CDCSerialClass.cpp @@ -30,7 +30,6 @@ #include "wiring_digital.h" #include "variant.h" -#define CDCACM_FIXED_DELAY 64 extern void CDCSerial_Handler(void); extern void serialEventRun1(void) __attribute__((weak)); @@ -133,7 +132,7 @@ void CDCSerialClass::flush( void ) size_t CDCSerialClass::write( const uint8_t uc_data ) { - uint32_t retries = 2; + uint32_t retries = 1; if (!_shared_data->device_open || !_shared_data->host_open) return(0); @@ -148,8 +147,9 @@ size_t CDCSerialClass::write( const uint8_t uc_data ) _tx_buffer->data[_tx_buffer->head] = uc_data; _tx_buffer->head = i; - // Just use a fixed delay to make it compatible with the CODK-M based firmware - delayMicroseconds(CDCACM_FIXED_DELAY); + // Mimick the throughput of a typical UART by throttling the data + // flow according to the configured baud rate + delayMicroseconds(_writeDelayUsec); break; } } while (retries--); From 20a4c7363ae186dea82bc43e4264d3eb5e99a022 Mon Sep 17 00:00:00 2001 From: Dino Tinitigan Date: Thu, 11 May 2017 16:37:50 -0700 Subject: [PATCH 3/3] Use a lock when accessing shared ring buffer --- cores/arduino/CDCSerialClass.cpp | 8 ++++---- system/libarc32_arduino101/framework/include/platform.h | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cores/arduino/CDCSerialClass.cpp b/cores/arduino/CDCSerialClass.cpp index 5cd0083d..4e5b93d0 100644 --- a/cores/arduino/CDCSerialClass.cpp +++ b/cores/arduino/CDCSerialClass.cpp @@ -144,12 +144,12 @@ size_t CDCSerialClass::write( const uint8_t uc_data ) // current location of the tail), we're about to overflow the buffer // and so we don't write the character or advance the head. if (i != _tx_buffer->tail) { + _tx_buffer->lock = 1; _tx_buffer->data[_tx_buffer->head] = uc_data; _tx_buffer->head = i; - - // Mimick the throughput of a typical UART by throttling the data - // flow according to the configured baud rate - delayMicroseconds(_writeDelayUsec); + _tx_buffer->lock = 0; + // Just use a fixed delay to make it compatible with the CODK-M based firmware + delayMicroseconds(_writeDelayUsec); break; } } while (retries--); diff --git a/system/libarc32_arduino101/framework/include/platform.h b/system/libarc32_arduino101/framework/include/platform.h index 801f87f5..428d90cd 100644 --- a/system/libarc32_arduino101/framework/include/platform.h +++ b/system/libarc32_arduino101/framework/include/platform.h @@ -45,11 +45,12 @@ struct cdc_ring_buffer { /** Ring buffer data */ - uint8_t data[CDCACM_BUFFER_SIZE]; + volatile uint8_t data[CDCACM_BUFFER_SIZE]; /** Ring buffer head pointer, modified by producer */ - int head; + volatile int head; /** Ring buffer head pointer, modified by consumer */ - int tail; + volatile int tail; + volatile uint8_t lock; }; struct cdc_acm_shared_data {