BV HiZ: make pin test faster an user interruptable

This commit is contained in:
King Kévin 2018-02-12 17:03:16 +01:00
parent ee5e5cf244
commit bf37193568
1 changed files with 47 additions and 25 deletions

View File

@ -451,13 +451,16 @@ static bool busvoodoo_hiz_test_pins(void)
gpio_set(GPIO(BUSVOODOO_LVCTL_PORT), GPIO(BUSVOODOO_LVCTL_PIN)); // set pin high
gpio_set_mode(GPIO(BUSVOODOO_LVCTL_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_LVCTL_PIN)); // set LV control pin as output
printf("%sI/O pin 1\n", lv_to);
while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) { // wait until pin is shorted to ground
sleep_ms(200); // wait for user to make connection
do {
sleep_ms(100); // wait for user to make connection
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2 && !user_input_available); // wait until pin is shorted to ground
if (user_input_available) { // user interruption
goto error;
}
gpio_clear(GPIO(BUSVOODOO_LVCTL_PORT), GPIO(BUSVOODOO_LVCTL_PIN)); // set pin low
gpio_set_mode(GPIO(BUSVOODOO_LVCTL_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_LVCTL_PIN)); // set LV control pin as output
led_toggle(); // notify user test is almost almost
sleep_ms(200); // wait for voltage to settle an debounce
sleep_ms(100); // wait for voltage to settle an debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf(lv_high);
#if DEBUG
@ -472,12 +475,15 @@ static bool busvoodoo_hiz_test_pins(void)
// test 5V output on pin 2
gpio_clear(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // enable Vout
printf("%sI/O pin 2\n", lv_to);
while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2) { // wait until pin is connected
sleep_ms(200); // wait for user to make connection
do {
sleep_ms(100); // wait for user to make connection
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 && !user_input_available); // wait until pin is connected
if (user_input_available) { // user interruption
goto error;
}
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
led_toggle(); // notify user test is almost complete
sleep_ms(200); // wait for voltage to settle and debounce
sleep_ms(100); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf(lv_high);
#if DEBUG
@ -491,12 +497,15 @@ static bool busvoodoo_hiz_test_pins(void)
// test 3.3V output on pin 3
gpio_clear(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // enable Vout
printf("%sI/O pin 3\n", lv_to);
while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 || busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>3.5) { // wait until pin is connected
sleep_ms(200); // wait for user to make connection
do {
sleep_ms(100); // wait for user to make connection
} while ((busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 || busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>3.5) && !user_input_available); // wait until pin is connected
if (user_input_available) { // user interruption
goto error;
}
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
led_toggle(); // notify user test is almost complete
sleep_ms(200); // wait for voltage to settle and debounce
sleep_ms(100); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf(lv_high);
#if DEBUG
@ -514,12 +523,15 @@ static bool busvoodoo_hiz_test_pins(void)
gpio_set(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // set pin high
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, busvoodoo_io_pins[pin]); // set pin to output
printf("%sI/O pin %u\n", lv_to, io+4);
while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2) { // wait until pin is connected
sleep_ms(200); // wait for user to make connection
do {
sleep_ms(100); // wait for user to make connection
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 && !user_input_available); // wait until pin is connected
if (user_input_available) { // user interruption
goto error;
}
gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // set pin low
led_toggle(); // notify user test is almost complete
sleep_ms(200); // wait for voltage to settle and debounce
sleep_ms(100); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf(lv_high);
#if DEBUG
@ -544,13 +556,16 @@ static bool busvoodoo_hiz_test_pins(void)
dac_enable(BUSVOODOO_HVCTL_CHANNEL); // enable DAC
gpio_clear(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // enable HV voltage regulator
printf("%sRS/CAN pin 1\n", lv_to);
while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2) { // wait until pin is connected
sleep_ms(200); // wait for user to make connection
do {
sleep_ms(100); // wait for user to make connection
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 && !user_input_available); // wait until pin is connected
if (user_input_available) { // user interruption
goto error;
}
gpio_set(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // disable HV voltage regulator
dac_disable(BUSVOODOO_HVCTL_CHANNEL); // disable HV control
led_toggle(); // notify user test is almost complete
sleep_ms(200); // wait for voltage to settle (and debounce)
sleep_ms(100); // wait for voltage to settle (and debounce)
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf(lv_high);
#if DEBUG
@ -577,13 +592,16 @@ static bool busvoodoo_hiz_test_pins(void)
gpio_set(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN)); // pull high to avoid false negative
sleep_ms(5);
printf("connect RS/CAN pin 2 to RS/CAN pin 3\n");
while (gpio_get(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN))) { // wait until pin is connected
sleep_ms(200); // wait for user to make connection
do {
sleep_ms(100); // wait for user to make connection
} while (gpio_get(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN)) && !user_input_available); // wait until pin is connected
if (user_input_available) { // user interruption
goto error;
}
gpio_set(GPIO(BUSVOODOO_RS232_TX_PORT), GPIO(BUSVOODOO_RS232_TX_PIN)); // set high
gpio_clear(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN)); // pull low to avoid false negative
led_toggle(); // notify user test is almost complete
sleep_ms(200); // wait for voltage to settle and debounce
sleep_ms(100); // wait for voltage to settle and debounce
if (!gpio_get(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO(BUSVOODOO_RS232_RX_PIN))) { // check if RX is set low by TX
printf("CAN/RS pin 2 is high while it should be set low by pin 3\n");
#if DEBUG
@ -604,13 +622,16 @@ static bool busvoodoo_hiz_test_pins(void)
gpio_clear(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO(BUSVOODOO_RS232_RTS_PIN)); // set low
gpio_set(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN)); // pull high to avoid false negative
printf("connect RS/CAN pin 4 to RS/CAN pin 5\n");
while (gpio_get(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN))) { // wait until pin is connected
sleep_ms(200); // wait for user to make connection
do {
sleep_ms(100); // wait for user to make connection
} while (gpio_get(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN)) && !user_input_available); // wait until pin is connected
if (user_input_available) { // user interruption
goto error;
}
gpio_set(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO(BUSVOODOO_RS232_RTS_PIN)); // set high
gpio_clear(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN)); // pull low to avoid false negative
led_toggle(); // notify user test is almost complete
sleep_ms(200); // wait for voltage to settle an debounce
sleep_ms(100); // wait for voltage to settle an debounce
if (!gpio_get(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO(BUSVOODOO_RS232_CTS_PIN))) { // check if CTS is set high by RTS
printf("CAN/RS pin 5 is high while it should be set low by pin 4\n");
#if DEBUG
@ -628,12 +649,13 @@ static bool busvoodoo_hiz_test_pins(void)
}
to_return = true; // all tests passed
#if DEBUG
#else
error:
#endif
busvoodoo_safe_state(); // go back to safe state
if (!to_return) {
if (user_input_available) { // user interrupted the test
printf("user interrupted the test\n");
to_return = true; // we don't consider this as error
}
if (!to_return) { // test has not been completed
printf("the test procedure has been aborted for safety reasons\n");
}