8000 uart: BW improvements by d-a-v · Pull Request #4620 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

uart: BW improvements #4620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Dec 10, 2018
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e5c2fea
uart fixes and BW improvements
d-a-v Apr 4, 2018
f79bc90
uart: read_char straightly use hw buffer
d-a-v Apr 5, 2018
45e2bd5
+attributes for functions called by ISR
d-a-v Apr 5, 2018
974b758
uart: BW improvements
d-a-v Apr 4, 2018
3eb8c95
Merge branch 'master' into serialagain
devyte Apr 9, 2018
0aefb09
Merge branch 'master' into serialagain
devyte Jun 7, 2018
4c6bab4
Merge branch 'master' into serialagain
devyte Jul 3, 2018
3c1e312
Merge branch 'master' into serialagain
d-a-v Nov 30, 2018
132f7f3
Merge branch 'serialagain' of github.com:d-a-v/Arduino into serialagain
d-a-v Nov 30, 2018
6560ab8
fix merge
d-a-v Nov 30, 2018
ebdf57a
Merge branch 'master' into serialagain
d-a-v Dec 5, 2018
c68d474
fix buffer overflow
d-a-v Dec 5, 2018
ff63718
serial stress test sketch
d-a-v Dec 5, 2018
8000
40f237f
astyle
d-a-v Dec 5, 2018
d6316aa
Merge branch 'serialagain' of github.com:d-a-v/Arduino into serialagain
d-a-v Dec 5, 2018
3428144
serial stress example: interactive keyboard, stop reading, overrun
d-a-v Dec 5, 2018
684879d
Merge branch 'master' into serialagain
d-a-v Dec 6, 2018
882989e
serial device test: bandwidth & overrun
d-a-v Dec 6, 2018
3ec2a60
update + HardwareSerial::hasError()
d-a-v Dec 6, 2018
a38f9d8
interactive overrun in example
d-a-v Dec 6, 2018
6b77715
astyle
d-a-v Dec 6, 2018
b639261
Test using @plerup's SoftwareSerial as submodule (tag 3.4.1)
d-a-v Dec 6, 2018
40d1237
update upstream ref (fix warning)
d-a-v Dec 6, 2018
64f7ac1
Merge branch 'master' into serialagain
d-a-v Dec 6, 2018
c48b54f
host mock uart/read(buf,size)
d-a-v Dec 6, 2018
18a189f
reset style changes in submodules before style diff
d-a-v Dec 7, 2018
ddcd908
Merge branch 'serialagain' of github.com:d-a-v/Arduino into serialagain
d-a-v Dec 7, 2018
48ad6bc
Merge branch 'master' into serialagain
earlephilhower Dec 7, 2018
0a7322f
Merge branch 'master' into serialagain
devyte Dec 8, 2018
fb25c8d
update build_boards_manager_package.sh for submodules
d-a-v Dec 8, 2018
8785e3a
Merge branch 'master' into serialagain
d-a-v Dec 8, 2018
e83316f
Merge branch 'master' into serialagain
devyte Dec 9, 2018
62ead27
Merge branch 'master' into serialagain
devyte Dec 9, 2018
c7eba46
Merge branch 'master' into serialagain
devyte Dec 10, 2018
cbd8b44
trigger CI (removing space)
d-a-v Dec 10, 2018
99fcfda
cannot reproduce locally the CI issue, setting bash -x option to get …
d-a-v Dec 10, 2018
6234fe0
remove previously added (in this PR) 'set -e' in package builder (pas…
d-a-v Dec 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
serial device test: bandwidth & overrun
  • Loading branch information
d-a-v committed Dec 6, 2018
commit 882989ec2e36613be300980bfc9f1d8e47b56aeb
191 changes: 191 additions & 0 deletions tests/device/test_serial/test_serial.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#include <BSTest.h>
BS_ENV_DECLARE();

// this is the serialStress.ino example, stripped down

/*
Serial read/write 8000 /verify/benchmark
Using internal loopback

Released to public domain
*/

#include <ESP8266WiFi.h>

#define SSBAUD 115200 // console for humans
#define BAUD 3000000 // hardware serial stress test
#define BUFFER_SIZE 4096 // may be useless to use more than 2*SERIAL_SIZE_RX
#define SERIAL_SIZE_RX 1024 // Serial.setRxBufferSize()

#define TIMEOUT 5000
#define DEBUG(x...) //x

uint8_t buf [BUFFER_SIZE];
uint8_t temp [BUFFER_SIZE];
bool reading = true;
bool overrun = false;

static size_t out_idx = 0, in_idx = 0;
static size_t local_receive_size = 0;
static size_t size_for_1sec, size_for_led = 0;
static size_t maxavail = 0;
static uint64_t in_total = 0, in_prev = 0;
static uint64_t start_ms, last_ms;
static uint64_t timeout;

void preinit() {
// (no C++ in function)
// disable wifi
ESP8266WiFiClass::preinitWiFiOff();
}

void setup()
{
Serial.begin(SSBAUD);

int baud = BAUD;
size_for_1sec = baud / 10; // 8n1=10baudFor8bits
//Serial.printf(ESP.getFullVersion().c_str());
//Serial.printf("\n\nBAUD: %d - CoreRxBuffer: %d bytes - TestBuffer: %d bytes\n",
// baud, SERIAL_SIZE_RX, BUFFER_SIZE);

//Serial.printf("led changes state every %zd bytes (= 1 second)\n", size_for_1sec);
//Serial.printf("press 's' to stop reading, not writing (induces overrun)\n");

BS_RUN(Serial);
}

void test_setup()
{
Serial.begin(BAUD);

// bind RX and TX
USC0(0) |= (1 << UCLBE);

Serial.flush();
while (Serial.read() != -1);
timeout = (start_ms = last_m 8000 s = millis()) + TIMEOUT;
}

void test_setdown ()
{
// unbind RX and TX
Serial.flush();
USC0(0) &= ~(1 << UCLBE);
while (Serial.read() != -1);
Serial.begin(SSBAUD);
}

int bwkbps_avg = 0;

bool test_loop ()
{
size_t maxlen = Serial.availableForWrite();
// check remaining space in buffer
if (maxlen > BUFFER_SIZE - out_idx) {
maxlen = BUFFER_SIZE - out_idx;
}
// check if not cycling more than buffer size relatively to input
size_t in_out = out_idx == in_idx ?
BUFFER_SIZE :
(in_idx + BUFFER_SIZE - out_idx - 1) % BUFFER_SIZE;
if (maxlen > in_out) {
maxlen = in_out;
}
size_t local_written_size = Serial.write(buf + out_idx, maxlen);
if (local_written_size > maxlen) {
return false;
}
if ((out_idx += local_written_size) == BUFFER_SIZE) {
out_idx = 0;
}
delay(0);

if (Serial.hasOverrun()) {
overrun = true;
}
if (Serial.hasRxError()) {
}

if (reading)
{
// receive data
maxlen = Serial.available();
if (maxlen > maxavail) {
maxavail = maxlen;
}
// check space in temp receive buffer
if (maxlen > BUFFER_SIZE - in_idx) {
maxlen = BUFFER_SIZE - in_idx;
}
local_receive_size = Serial.readBytes(temp, maxlen);
if (local_receive_size > maxlen) {
return false;
}
if (local_receive_size) {
if (memcmp(buf + in_idx, temp, local_receive_size) != 0) {
return false;
}
if ((in_idx += local_receive_size) == BUFFER_SIZE) {
in_idx = 0;
}
in_total += local_receive_size;
}
}

// say something on data every second
if ((size_for_led += local_written_size) >= size_for_1sec || millis() > timeout) {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
size_for_led = 0;

if (in_prev == in_total) {
return false;
}

unsigned long now_ms = millis();
bwkbps_avg = ((((uint64_t)in_total) * 8000) / (now_ms - start_ms)) >> 10;
//bwkbps_now = (((in_total - in_prev) * 8000) / (now_ms - last_ms)) >> 10 ;

in_prev = in_total;
timeout = (last_ms = now_ms) + TIMEOUT;
}

if (millis() > 5000)
{
reading = false;
}
if (millis() > 6000)
{
return false;
}

return true;
}

TEST_CASE("bandwidth and overrun", "[serial]")
{
overrun = false;
bwkbps_avg = 0;
CHECK(overrun == false);
CHECK(bwkbps_avg == 0);

// let serial flush its BS output before flushing and switching to 3MBPS
delay(100);

test_setup();
while (test_loop());
test_setdown();

Serial.printf("bandwidth = %d kbps - overrun=%d\n", bwkbps_avg, overrun);

// BAUD*10/8/1000 =>kbps *9/10 => 90% at least
CHECK(bwkbps_avg > ((((BAUD*8/10)/1000)*9)/10));
CHECK(overrun == true);

while (Serial.read() != -1);
Serial.flush();
}

void loop ()
{
}
0