Created
June 30, 2015 15:53
-
-
Save facchinm/322f0190e1800b48732f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAM_DUE) | |
#define SERIAL_PORT SerialUSB | |
#else | |
#define SERIAL_PORT Serial | |
#endif | |
uint8_t speedTestBuffer[256]; | |
void setup() | |
{ | |
digitalWrite(LED_BUILTIN, LOW); | |
pinMode(LED_BUILTIN, OUTPUT); | |
SERIAL_PORT.begin(115200); //921600 | |
//digitalWrite(LED_BUILTIN, HIGH); | |
} | |
void loop() | |
{ | |
int c = SERIAL_PORT.read(); | |
delay(10); | |
digitalWrite(LED_BUILTIN, HIGH); | |
if (c == -1) | |
return; | |
switch (c) | |
{ | |
case 'b' : | |
burstSendTest(); | |
break; | |
case 'l' : | |
loopbackTest(); | |
break; | |
case 's' : | |
speedTest(); | |
break; | |
case 'k' : | |
slowTest(); | |
break; | |
} | |
} | |
void burstSendTest() | |
{ | |
// Send a burst of 1.000.000 bytes of data | |
for (uint16_t i=0; i<20000; i++) | |
{ | |
// 25 bytes | |
SERIAL_PORT.print("0123456789abcdeABCDE=)(/&"); | |
// 25 bytes | |
SERIAL_PORT.print("qwertyuiopasdfghjklzQWERT"); | |
} | |
} | |
void loopbackTest() | |
{ | |
while (true) | |
{ | |
int c = SERIAL_PORT.read(); | |
if (c != -1) | |
SERIAL_PORT.print((char) c); | |
} | |
} | |
void slowTest() | |
{ | |
while (true) | |
{ | |
SERIAL_PORT.println("0123456789abcdeABCDE=)(/&"); | |
delay(500); | |
} | |
} | |
void speedTest() | |
{ | |
int frameSize = SERIAL_PORT.parseInt(); | |
if (frameSize < 1) | |
{ | |
digitalWrite(LED_BUILTIN, HIGH); | |
while (true); | |
} | |
uint8_t speedTestBuffer[frameSize]; | |
for (int i = 0; i < frameSize; ++i) { | |
speedTestBuffer[i] = (uint8_t) (i & 0xFF); | |
} | |
while (true) | |
{ | |
SERIAL_PORT.write(speedTestBuffer, frameSize); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment