BV HIZ: can now halt on error in tests

This commit is contained in:
King Kévin 2018-03-23 08:49:39 +01:00
parent 2d99d7f6f9
commit 17a2cc4465
1 changed files with 67 additions and 228 deletions

View File

@ -19,6 +19,7 @@
*/
/* standard libraries */
#include <stdint.h> // standard integer types
#include <string.h> // string utilities
#include <math.h> // math utilities
/* STM32 (including CM3) libraries */
@ -65,7 +66,7 @@ static bool busvoodoo_hiz_setup(char** prefix, const char* line)
}
busvoodoo_oled_text_pinout(busvoodoo_global_pinout_io, true); // set pinout on display
busvoodoo_oled_update(); // update display to show text and pinout
return true;
return true;
}
/** exit HiZ mode
@ -76,9 +77,10 @@ static void busvoodoo_hiz_exit(void)
}
/** perform self tests
* @param[in] halt halt on error instead of exiting immediately (exit on user input)
* @return if self tests passed
*/
static bool busvoodoo_hiz_test_self(void)
static bool busvoodoo_hiz_test_self(bool halt)
{
bool to_return = false; // success of the self-test
busvoodoo_safe_state(); // start from a safe state
@ -104,36 +106,24 @@ static bool busvoodoo_hiz_test_self(void)
float voltage = busvoodoo_vreg_get(BUSVOODOO_5V_CHANNEL); // get 5V power rail voltage
if (voltage<4.0) {
printf("5V power rail voltage is too low: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
if (halt) { // halt on error if requested
led_blink(0.5, 0.5); // show error on LEDs
while (!user_input_available); // wait for user input
}
goto error;
#endif
} else if (voltage>5.5) {
printf("5V power rail voltage is too high: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
}
// check 3.3V power rail
voltage = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get 3.3V power rail voltage
if (voltage<3.0) {
printf("3.3V power rail voltage is too low: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>3.6) {
printf("3.3V power rail voltage is too high: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
}
// test 5V and 3.3V outputs
@ -141,34 +131,18 @@ static bool busvoodoo_hiz_test_self(void)
voltage = busvoodoo_vreg_get(BUSVOODOO_5V_CHANNEL); // get 5V power rail voltage
if (voltage<4.0) {
printf("5V power rail voltage is too low when 5V output is enabled: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>5.5) {
printf("5V power rail voltage is too high when 5V output is enabled: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
}
voltage = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get 3.3V power rail voltage
if (voltage<3.0) {
printf("3.3V power rail voltage is too low when 3V3 output is enabled: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>3.6) {
printf("3.3V power rail voltage is too high when 3V3 is enabled: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
}
busvoodoo_vout_switch(false); // disable Vout
@ -176,11 +150,7 @@ static bool busvoodoo_hiz_test_self(void)
voltage = busvoodoo_lv_set(0); // disable LV voltage regulator
if (voltage>0.2) { // ensure the output is at 0V when the regulator is not enabled
printf("LV voltage is %.2fV instead of 0V when the regulator is disabled\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_set(GPIO(BUSVOODOO_LVEN_PORT), GPIO(BUSVOODOO_LVEN_PIN)); // enable LV voltage regulator
sleep_ms(5); // let the voltage regulator start and voltage settle
@ -188,36 +158,20 @@ static bool busvoodoo_hiz_test_self(void)
// without being driven it should be around the default voltage
if (voltage<BUSVOODOO_LV_DEFAULT-0.2) {
printf("LV voltage is lower (%.2fV) than expected (%.2fV) when the regulator is enabled\n", voltage, BUSVOODOO_LV_DEFAULT);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>BUSVOODOO_LV_DEFAULT+0.2) {
printf("LV voltage is higher (%.2fV) than expected (%.2fV) when the regulator is enabled\n", voltage, BUSVOODOO_LV_DEFAULT);
#if DEBUG
while (true);
#else
goto error;
#endif
}
// check if we can control LV
voltage = busvoodoo_lv_set(BUSVOODOO_LV_TEST); // get LV voltage
if (voltage<BUSVOODOO_LV_TEST-0.2) {
printf("LV voltage is lower (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_LV_TEST);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>BUSVOODOO_LV_TEST+0.2) {
printf("LV voltage is highed (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_LV_TEST);
#if DEBUG
while (true);
#else
goto error;
#endif
}
busvoodoo_lv_set(0); // disable LV voltage regulator
@ -226,11 +180,7 @@ static bool busvoodoo_hiz_test_self(void)
voltage = busvoodoo_hv_set(0); // disable HV voltage regulator
if (voltage>0.2) { // ensure the output is at 0V when the regulator is not enabled
printf("HV voltage is %.2fV instead of 0V when the regulator is disabled\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_clear(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // enable HV voltage regulator
sleep_ms(10); // let the voltage regulator start and voltage settle
@ -238,36 +188,20 @@ static bool busvoodoo_hiz_test_self(void)
// without being driven it should be around the default voltage
if (voltage<BUSVOODOO_HV_DEFAULT-0.3) {
printf("HV voltage is lower (%.2fV) than expected (%.2fV) when regulator is enabled\n", voltage, BUSVOODOO_HV_DEFAULT);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>BUSVOODOO_HV_DEFAULT+0.3) {
printf("HV voltage is higher (%.2fV) than expected (%.2fV) when regulator is enabled\n", voltage, BUSVOODOO_HV_DEFAULT);
#if DEBUG
while (true);
#else
goto error;
#endif
}
// check if we can control HV voltage regulator
voltage = busvoodoo_hv_set(BUSVOODOO_HV_TEST); // set voltage on HV voltage regulator
if (voltage<BUSVOODOO_HV_TEST-0.3) {
printf("HV voltage is lower (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_HV_TEST);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>BUSVOODOO_HV_TEST+0.3) {
printf("HV voltage is higher (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_HV_TEST);
#if DEBUG
while (true);
#else
goto error;
#endif
}
voltage = busvoodoo_hv_set(0); // disable HV voltage regulator
}
@ -280,11 +214,7 @@ static bool busvoodoo_hiz_test_self(void)
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_names); pin++) {
if (gpio_get(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin])) { // ensure it really is low
printf("signal %s is high although it is pulled low (internal)\n", busvoodoo_io_names[pin]); // warn user about the error
#if DEBUG
while (true);
#else
goto error;
#endif
}
}
@ -296,11 +226,7 @@ static bool busvoodoo_hiz_test_self(void)
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_names); pin++) {
if (!gpio_get(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin])) { // ensure it really is high
printf("signal %s is low although it is pulled up (internal)\n", busvoodoo_io_names[pin]); // warn user about the error
#if DEBUG
while (true);
#else
goto error;
#endif
}
}
@ -315,18 +241,10 @@ static bool busvoodoo_hiz_test_self(void)
for (uint8_t pin2=0; pin2<LENGTH(busvoodoo_io_ports) && pin2<LENGTH(busvoodoo_io_pins) && pin2<LENGTH(busvoodoo_io_groups) && pin2<LENGTH(busvoodoo_io_names); pin2++) {
if (busvoodoo_io_groups[pin1]==busvoodoo_io_groups[pin2] && !gpio_get(busvoodoo_io_ports[pin2], busvoodoo_io_pins[pin2])) {
printf("signal %s of I/O-%u is low while it should be set high by signal %s of I/O-%u\n", busvoodoo_io_names[pin2], busvoodoo_io_groups[pin2], busvoodoo_io_names[pin1], busvoodoo_io_groups[pin1]); // warn user about the error
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (busvoodoo_io_groups[pin1]!=busvoodoo_io_groups[pin2] && gpio_get(busvoodoo_io_ports[pin2], busvoodoo_io_pins[pin2])) {
printf("signal %s of I/O-%u is high while it should not be set high by signal %s of I/O-%u\n", busvoodoo_io_names[pin2], busvoodoo_io_groups[pin2], busvoodoo_io_names[pin1], busvoodoo_io_groups[pin1]); // warn user about the error
#if DEBUG
while (true);
#else
goto error;
#endif
}
}
gpio_set_mode(busvoodoo_io_ports[pin1], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin1]); // set pin back to input
@ -343,18 +261,10 @@ static bool busvoodoo_hiz_test_self(void)
for (uint8_t pin2=0; pin2<LENGTH(busvoodoo_io_ports) && pin2<LENGTH(busvoodoo_io_pins) && pin2<LENGTH(busvoodoo_io_groups) && pin2<LENGTH(busvoodoo_io_names); pin2++) {
if (busvoodoo_io_groups[pin1]==busvoodoo_io_groups[pin2] && gpio_get(busvoodoo_io_ports[pin2], busvoodoo_io_pins[pin2])) {
printf("signal %s of I/O-%u is high while it should be set low by signal %s of I/O-%u\n", busvoodoo_io_names[pin2], busvoodoo_io_groups[pin2], busvoodoo_io_names[pin1], busvoodoo_io_groups[pin1]); // warn user about the error
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (busvoodoo_io_groups[pin1]!=busvoodoo_io_groups[pin2] && !gpio_get(busvoodoo_io_ports[pin2], busvoodoo_io_pins[pin2])) {
printf("signal %s of I/O-%u is low while it should not be set low by signal %s of I/O-%u\n", busvoodoo_io_names[pin2], busvoodoo_io_groups[pin2], busvoodoo_io_names[pin1], busvoodoo_io_groups[pin1]); // warn user about the error
#if DEBUG
while (true);
#else
goto error;
#endif
}
}
gpio_set_mode(busvoodoo_io_ports[pin1], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin1]); // set pin back to input
@ -370,27 +280,15 @@ static bool busvoodoo_hiz_test_self(void)
voltage = busvoodoo_embedded_pullup(true); // enable 5V pull-up
if (voltage<4.0) {
printf("5V power rail voltage is too low when used to pull up: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>5.5) {
printf("5V power rail voltage is too high when used to pull up: %.2fV\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
}
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_names); pin++) {
if (!gpio_get(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin])) { // ensure it really is high
printf("signal %s is low although it is pulled up by 5V (embedded)\n", busvoodoo_io_names[pin]); // warn user about the error
#if DEBUG
while (true);
#else
goto error;
#endif
}
}
busvoodoo_embedded_pullup(false); // disable pull-ups
@ -405,27 +303,15 @@ static bool busvoodoo_hiz_test_self(void)
voltage = busvoodoo_embedded_pullup(3.3); // enable pull-up with adjustable regulator
if (voltage<BUSVOODOO_LV_DEFAULT-0.2) {
printf("LV voltage is lower (%.2fV) than expected (%.2fV) when used to pull up\n", voltage, BUSVOODOO_LV_DEFAULT);
#if DEBUG
while (true);
#else
goto error;
#endif
} else if (voltage>BUSVOODOO_LV_DEFAULT+0.2) {
printf("LV voltage is higher (%.2fV) than expected (%.2fV) when used to pull up\n", voltage, BUSVOODOO_LV_DEFAULT);
#if DEBUG
while (true);
#else
goto error;
#endif
}
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_names); pin++) {
if (!gpio_get(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin])) { // ensure it really is high
printf("signal %s is low although it is pulled up by LV (embedded)\n", busvoodoo_io_names[pin]); // warn user about the error
#if DEBUG
while (true);
#else
goto error;
#endif
}
}
busvoodoo_lv_set(0); // disable LV voltage regulator
@ -444,11 +330,7 @@ static bool busvoodoo_hiz_test_self(void)
sleep_us(100); // let voltage settle
if (gpio_get(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO(BUSVOODOO_RS485_RX_PIN))) { // test if RX is still high
printf("RS-485 RX is high while TX is set low\n"); // warn user about the error
#if DEBUG
while (true);
#else
goto error;
#endif
}
// test high signal
gpio_clear(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO(BUSVOODOO_RS485_RX_PIN)); // pull RX down
@ -456,11 +338,7 @@ static bool busvoodoo_hiz_test_self(void)
sleep_us(100); // let voltage settle
if (0==gpio_get(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO(BUSVOODOO_RS485_RX_PIN))) { // test if RX is still low
printf("RS-485 RX is low while TX is set high\n"); // warn user about the error
#if DEBUG
while (true);
#else
goto error;
#endif
}
// release transceiver
gpio_set(GPIO(BUSVOODOO_RS485_RE_PORT), GPIO(BUSVOODOO_RS485_RE_PIN)); // set high to disable receiver
@ -481,11 +359,7 @@ static bool busvoodoo_hiz_test_self(void)
sleep_us(100); // let voltage settle
if (0==gpio_get(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO(BUSVOODOO_CAN_RX_PIN))) { // test if RX is still low
printf("CAN RX is low while TX is set high\n"); // warn user about the error
#if DEBUG
while (true);
#else
goto error;
#endif
}
// test low signal
gpio_set(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO(BUSVOODOO_CAN_RX_PIN)); // pull RX up
@ -493,21 +367,13 @@ static bool busvoodoo_hiz_test_self(void)
sleep_us(100); // let voltage settle
if (gpio_get(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO(BUSVOODOO_CAN_RX_PIN))) { // test if RX is still high
printf("CAN RX is high while TX is set low\n"); // warn user about the error
#if DEBUG
while (true);
#else
goto error;
#endif
}
// test dominant timeout
sleep_ms(10); // after 5 ms the output should be switched back from dominant to recessive respite TX being low
if (!gpio_get(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO(BUSVOODOO_CAN_RX_PIN))) { // test if RX is now low
printf("CAN RX is low while the output should be back to recessive\n"); // warn user about the error
#if DEBUG
while (true);
#else
goto error;
#endif
}
// release transceiver
gpio_set(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // set high to power off transceiver
@ -516,22 +382,25 @@ static bool busvoodoo_hiz_test_self(void)
}
to_return = true; // all tests are successful
#if DEBUG
#else
error:
#endif
busvoodoo_safe_state(); // set back to safe state
if (!to_return) {
printf("the test procedure has been aborted for safety reasons\n");
if (halt) { // halt on error if requested
led_blink(0.5, 0.5); // show error on LEDs
while (!user_input_available); // wait for user input
} else {
printf("the test procedure has been aborted for safety reasons\n");
}
}
busvoodoo_safe_state(); // set back to safe state
return to_return;
}
/** test if signals are soldered correctly to the connector pins
* @param[in] halt halt on error instead of exiting immediately (exit on user input)
* @return if pin test passed
*/
static bool busvoodoo_hiz_test_pins(void)
static bool busvoodoo_hiz_test_pins(bool halt)
{
bool to_return = false; // test result to return
busvoodoo_safe_state(); // start from safe state with all outputs switched off
@ -562,11 +431,7 @@ static bool busvoodoo_hiz_test_pins(void)
sleep_ms(100); // wait for voltage to settle an debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf("I/O pin 4 is high while it should be low and shorted to ground\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_set_mode(GPIO(BUSVOODOO_LVCTL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO(BUSVOODOO_LVCTL_PIN)); // set LV control pin back to analog input for DAC
pinout[0] = NULL; // clear pin to test
@ -589,11 +454,7 @@ static bool busvoodoo_hiz_test_pins(void)
sleep_ms(100); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf("5V output is high while the power output should be switched off\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
pinout[1] = NULL; // clear pin to test
@ -615,11 +476,7 @@ static bool busvoodoo_hiz_test_pins(void)
sleep_ms(100); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf("3V3 output is high while the power output should be switched off\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
pinout[2] = NULL; // clear pin to test
@ -645,11 +502,7 @@ static bool busvoodoo_hiz_test_pins(void)
sleep_ms(100); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf("I/O pin %u is high while it should be low\n", io+4);
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, busvoodoo_io_pins[pin]); // set pin back to input
pinout[io+3] = NULL; // clear pin to test
@ -685,11 +538,7 @@ static bool busvoodoo_hiz_test_pins(void)
sleep_ms(100); // wait for voltage to settle (and debounce)
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
printf("HV output is high while voltage regulator should be switched off\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
pinout[0] = NULL; // clear pin to test
@ -713,11 +562,7 @@ static bool busvoodoo_hiz_test_pins(void)
sleep_ms(100); // wait for voltage to settle (and debounce)
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>1.0) {
printf("RS-485 output A is high while it should be low\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_clear(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set low to disable transmitter
gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating
@ -733,19 +578,11 @@ static bool busvoodoo_hiz_test_pins(void)
voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get output voltage
if (voltage<0.5) { // normally the lower limit is 2V, put pin 4 pulls it down because it is not strongly driven
printf("CAN L output is low while it should be at recessive 2.5V\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
if (voltage>3.0) { // normally the upper limit is 3V
printf("CAN L output is high while it should be at recessive 2.5V\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
// test dominant output
gpio_clear(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX low
@ -753,11 +590,7 @@ static bool busvoodoo_hiz_test_pins(void)
voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get output voltage
if (voltage>2.5) {
printf("CAN L output is high while it should at dominant <2.25V\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
// release transceiver
gpio_set(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // set high to power off transceiver
@ -783,11 +616,7 @@ static bool busvoodoo_hiz_test_pins(void)
sleep_ms(100); // wait for voltage to settle (and debounce)
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>1.0) {
printf("RS-485 output B is high while it should be low\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_clear(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set low to disable transmitter
gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating
@ -803,19 +632,11 @@ static bool busvoodoo_hiz_test_pins(void)
voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get output voltage
if (voltage<0.5) { // normally the lower limit is 2V, put pin 4 pulls it down because it is not strongly driven
printf("CAN H output is low while it should be at recessive 2.5V\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
if (voltage>3.0) { // normally the upper limit is 3V
printf("CAN H output is high while it should be at recessive 2.5V\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
// test dominant output
gpio_clear(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX low
@ -824,11 +645,7 @@ static bool busvoodoo_hiz_test_pins(void)
if (voltage<2.5) {
printf("CAN H output is low while it dominant >2.75V\n");
printf("%.02f\n", voltage);
#if DEBUG
while (true);
#else
goto error;
#endif
}
// release transceiver
gpio_set(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // set high to power off transceiver
@ -867,11 +684,7 @@ static bool busvoodoo_hiz_test_pins(void)
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("RS-232 RX is high while it should be set low by RS-232 TX\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_set_mode(GPIO(BUSVOODOO_RS232_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_TX_PIN)); // free pin
gpio_set_mode(GPIO(BUSVOODOO_RS232_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_RX_PIN)); // free pin
@ -903,11 +716,7 @@ static bool busvoodoo_hiz_test_pins(void)
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("RS-232 CTS is high while it should be set low by RS-232 RTS\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
gpio_set_mode(GPIO(BUSVOODOO_RS232_RTS_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_RTS_PIN)); // free pin
gpio_set_mode(GPIO(BUSVOODOO_RS232_CTS_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS232_CTS_PIN)); // free pin
@ -919,17 +728,21 @@ static bool busvoodoo_hiz_test_pins(void)
to_return = true; // all tests passed
error:
if (!to_return) {
if (user_input_available) {
printf("user interrupted the test\n");
to_return = true; // we don't consider this as error
} else if (halt) { // halt on error if requested
led_blink(0.5, 0.5); // show error on LEDs
while (!user_input_available); // wait for user input
} else {
printf("the test procedure has been aborted for safety reasons\n");
}
}
busvoodoo_safe_state(); // go back to safe state
busvoodoo_oled_text_left("HiZ"); // reset mode text
busvoodoo_oled_text_pinout(busvoodoo_global_pinout_io, true); // reset pinout
busvoodoo_oled_update(); // update display to show text and pinout
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");
}
return to_return;
}
@ -963,21 +776,34 @@ static void busvoodoo_hiz_version(void* argument)
/** command to perform board self-test
* @param[in] argument no argument required
* @param[in] argument "halt" to halt on error
*/
static void busvoodoo_hiz_command_test_self(void* argument)
{
(void)argument; // we won't use the argument
bool halt = false; // if we halt on error
if (NULL!=argument && strlen(argument)>0) {
if (0==strcmp(argument, "halt")) {
halt = true;
} else {
printf("malformed argument\n");
}
}
printf("performing self-test\n");
if (halt) {
printf("WARNING: halting on error can cause hardware damages (press any key to exit halt state)\n");
}
printf("remove all cables from connectors and press space to start (or any other key to abort)\n");
led_red(); // show red LED to indicate test started
if (' '==user_input_get()) { // space entered
if (busvoodoo_hiz_test_self()) { // perform self-test
if (busvoodoo_hiz_test_self(halt)) { // perform self-test
led_blue(); // show blue to indicate test passed
printf("self-test succeeded\n"); // notify user
} else {
led_blink(0.5, 0.5); // show error on LEDs
printf("self-test failed\n"); // notify user
if (user_input_available) {
user_input_get(); // clear user input
}
}
} else {
printf("self-test aborted\n");
@ -985,21 +811,34 @@ static void busvoodoo_hiz_command_test_self(void* argument)
}
/** command to perform pins test
* @param[in] argument no argument required
* @param[in] argument "halt" to halt on error
*/
static void busvoodoo_hiz_command_test_pins(void* argument)
{
(void)argument; // we won't use the argument
bool halt = false; // if we halt on error
if (NULL!=argument && strlen(argument)>0) {
if (0==strcmp(argument, "halt")) {
halt = true;
} else {
printf("malformed argument\n");
}
}
printf("performing pins test\n");
if (halt) {
printf("WARNING: halting on error can cause hardware damages (press any key to exit halt state)\n");
}
printf("remove all cables from connectors and press space to start (or any other key to abort)\n");
led_red(); // show red LED to indicate test started
if (' '==user_input_get()) { // space entered
if (busvoodoo_hiz_test_pins()) { // perform pin test
if (busvoodoo_hiz_test_pins(halt)) { // perform pin test
led_blue(); // show blue OK LED
printf("pins test succeeded\n"); // notify user
} else {
led_blink(0.5, 0.5); // show error on LEDs
printf("pins test failed\n"); // notify user
if (user_input_available) {
user_input_get(); // clear user input
}
}
} else {
printf("pins test aborted\n");
@ -1026,17 +865,17 @@ static const struct menu_command_t busvoodoo_hiz_commands[] = {
},
{
's',
"self-test",
"perform board self-test",
MENU_ARGUMENT_NONE,
"self-test [halt]",
"perform board self-test (optional halt on error)",
MENU_ARGUMENT_STRING,
NULL,
&busvoodoo_hiz_command_test_self,
},
{
't',
"pins-test",
"perform connector pins test",
MENU_ARGUMENT_NONE,
"pins-test [halt]",
"perform connector pins test (optional halt on error)",
MENU_ARGUMENT_STRING,
NULL,
&busvoodoo_hiz_command_test_pins,
},