Skip to content

Instantly share code, notes, and snippets.

@facchinm
Last active September 10, 2015 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save facchinm/8ab3b1e43d17ee47edc7 to your computer and use it in GitHub Desktop.
Save facchinm/8ab3b1e43d17ee47edc7 to your computer and use it in GitHub Desktop.
#ifdef _VARIANT_ARDUINO_DUE_X_
#define DUT
#define PIN_IRQ 9
#define PIN_ACK 10
#else
#define PIN_IRQ 10
#define PIN_ACK 9
#endif
// test for DUE PR 3524
// connection:
// 18 (dut) -> 0 (tester)
// 19 -> 1
// 2 -> A0 -> test1
// 3 -> A1 -> test2
// 4 -> 4 -> test3
// A0 -> 5 -> test4
// 5 -> 6 -> test5
// 6 -> x -> test6
// 7 -> 7 -> test7
// 8 -> 8 -> test7
// 9 -> 9 -> irq test
// 10 -> 10 -> irq dut
#include "config.h"
volatile bool can_continue = false;
void confirm() {
delay(10);
digitalWrite(PIN_ACK, LOW);
delay(1);
digitalWrite(PIN_ACK, HIGH);
can_continue = false;
//SerialUSB.println("confirm");
}
void wait() {
//SerialUSB.println("wait");
while (can_continue == false) {};
//noInterrupts();
can_continue = false;
//interrupts();
}
void flushSerialIn() {
//SerialUSB.print("BUF:");
while (Serial1.available()) {
Serial1.read();
}
}
void flushSerialIn(bool a) {
if (a) {
while (Serial1.available()) {
SerialUSB.print((char)Serial1.read());
}
} else {
flushSerialIn();
}
}
void unlock() {
can_continue = true;
}
void sync() {
#ifdef DUT
confirm();
wait();
#else
wait();
confirm();
#endif
}
void setup() {
// put your setup code here, to run once:
Serial1.begin(115200);
Serial.begin(115200);
pinMode(PIN_ACK, OUTPUT);
digitalWrite(PIN_ACK, HIGH);
pinMode(PIN_IRQ, INPUT_PULLUP);
while (Serial1.find("c") == false) {
Serial1.println("c");
SerialUSB.println("waiting");
SerialUSB.println(Serial1.read());
delay(100);
}
Serial1.println("c");
delay(4000);
attachInterrupt(PIN_IRQ, unlock, FALLING);
delay(1000);
SerialUSB.println("start");
}
void loop() {
flushSerialIn();
// put your main code here, to run repeatedly:
#ifndef DUT
#pragma message ( "Compiling for Zero as Tester" )
resultIssue1(A0);
resultIssue2(A1);
resultIssue3(4);
resultIssue4(5);
resultIssue5(6);
resultIssue6(A0);
resultIssue7(7, 8);
#else
#pragma message ( "Compiling for DUE as DUT" )
testIssue1(2);
testIssue2(3);
testIssue3(4);
testIssue4(A0);
testIssue5(5);
testIssue6(6);
testIssue7(7,8);
#endif
}
void testIssue1(int pin) {
sync();
SerialUSB.println("start test 1");
pinMode(pin, OUTPUT);
analogWrite(pin, 128);
sync();
delay(100);
digitalWrite(pin, HIGH);
sync();
delay(100);
digitalWrite(pin, LOW);
sync();
sync();
}
void resultIssue1(int pin) {
sync();
SerialUSB.println("results for test 1");
pinMode(pin, INPUT);
sync();
delay(10);
SerialUSB.println(pulseIn(pin,LOW) <= 500 && pulseIn(pin,LOW) >= 480);
sync();
delay(10);
SerialUSB.println(digitalRead(pin) == HIGH);
sync();
delay(10);
SerialUSB.println(digitalRead(pin) == LOW);
sync();
}
void testIssue2(int pin) {
sync();
SerialUSB.println("start test 2");
pinMode(pin, OUTPUT);
analogWrite(pin, 128);
sync();
delay(100);
pinMode(pin, OUTPUT);
analogWrite(pin, 20);
sync();
delay(100);
sync();
digitalWrite(pin, LOW);
}
void resultIssue2(int pin) {
sync();
SerialUSB.println("results for test 2");
pinMode(pin, INPUT);
sync();
SerialUSB.println(pulseIn(pin,LOW) <= 500 && pulseIn(pin,LOW) >= 480);
sync();
SerialUSB.println(pulseIn(pin,LOW) <= 930 && pulseIn(pin,LOW) >= 910);
sync();
}
void testIssue3(int pin) {
sync();
SerialUSB.println("start test 3");
pinMode(pin, OUTPUT);
digitalWrite(pin, HIGH);
sync();
delay(100);
pinMode(pin, INPUT);
sync();
delay(100);
Serial1.println(digitalRead(pin));
sync();
delay(100);
Serial1.println(digitalRead(pin));
sync();
}
void resultIssue3(int pin) {
sync();
SerialUSB.println("starting test 3");
flushSerialIn();
sync();
pinMode(pin, INPUT);
SerialUSB.println(digitalRead(pin));
pinMode(pin, OUTPUT);
digitalWrite(pin, HIGH);
sync();
SerialUSB.println(Serial1.find("1"));
flushSerialIn();
sync();
digitalWrite(pin, LOW);
SerialUSB.println(Serial1.find("0"));
flushSerialIn();
sync();
}
void testIssue4(int pin) {
sync();
SerialUSB.println("start test 4");
pinMode(pin, INPUT);
sync();
Serial1.println(analogRead(pin));
SerialUSB.println(analogRead(pin));
sync();
delay(100);
Serial1.println(digitalRead(pin));
sync();
}
void resultIssue4(int pin) {
sync();
SerialUSB.println("results for test 4");
pinMode(pin, OUTPUT);
digitalWrite(pin, HIGH);
flushSerialIn();
sync();
delay(100);
flushSerialIn(true);
//SerialUSB.println(Serial1.find("102")); //1020 or higher
sync();
SerialUSB.println(Serial1.find("1"));
flushSerialIn();
sync();
}
void testIssue5(int pin) {
sync();
SerialUSB.println("start test 5");
pinMode(pin, OUTPUT);
sync();
sync();
}
void resultIssue5(int pin) {
sync();
SerialUSB.println("results for test 5");
pinMode(pin, INPUT);
sync();
delay(100);
SerialUSB.println(digitalRead(pin) == 0);
sync();
}
void testIssue6(int pin) {
sync();
SerialUSB.println("start test 6");
pinMode(pin, OUTPUT);
Serial1.println(digitalRead(pin));
delay(100);
sync();
delay(100);
}
void resultIssue6(int pin) {
flushSerialIn();
sync();
SerialUSB.println("results for test 6");
SerialUSB.println(Serial1.find("0"));
sync();
}
void testIssue7(int pin, int pin2) {
sync();
SerialUSB.println("start test 7");
sync();
digitalWrite(pin, HIGH);
pinMode(pin, OUTPUT);
sync();
digitalWrite(pin2, LOW);
pinMode(pin2, OUTPUT);
sync();
}
void resultIssue7(int pin, int pin2) {
sync();
SerialUSB.println("results for test 7");
pinMode(pin, INPUT);
sync();
SerialUSB.println(digitalRead(pin) == HIGH);
pinMode(pin2, INPUT);
sync();
SerialUSB.println(digitalRead(pin2) == LOW);
sync();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment