busvoodoo_hiz: minor, put spaces around operators

This commit is contained in:
King Kévin 2020-03-09 15:11:44 +01:00
parent ecfa216d48
commit 7a874bdb77
1 changed files with 82 additions and 82 deletions

View File

@ -59,13 +59,13 @@ static bool busvoodoo_hiz_setup(char** prefix, const char* line)
busvoodoo_leds_off(); // switch off all LEDs
busvoodoo_led_blue_on(); // switch on blue LED
const char* pinout_io[10] = {"GND", "5V", "3V3", "LV", NULL, NULL, NULL, NULL, NULL, NULL}; // HiZ mode I/O pinout
for (uint8_t i=0; i<LENGTH(pinout_io) && i<LENGTH(busvoodoo_global_pinout_io); i++) {
for (uint8_t i = 0; i < LENGTH(pinout_io) && i < LENGTH(busvoodoo_global_pinout_io); i++) {
busvoodoo_global_pinout_io[i] = pinout_io[i]; // set pin names
}
#if BUSVOODOO_HARDWARE_VERSION != 2
if (busvoodoo_full) {
const char* pinout_rscan[5] = {"HV", NULL, NULL, NULL, NULL}; // HiZ mode RS/CAN pinout
for (uint8_t i=0; i<LENGTH(pinout_rscan) && i<LENGTH(busvoodoo_global_pinout_rscan); i++) {
for (uint8_t i = 0; i < LENGTH(pinout_rscan) && i < LENGTH(busvoodoo_global_pinout_rscan); i++) {
busvoodoo_global_pinout_rscan[i] = pinout_rscan[i]; // set pin names
}
}
@ -99,37 +99,37 @@ static bool busvoodoo_hiz_test_self(bool halt)
// 0x414: high-density, 256-512 kB flash
// 0x430: XL-density, 768-1024 kB flash
// 0x418: connectivity
if (0==(DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK)) { // can't read IDCODE for verification
if (0 == (DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK)) { // can't read IDCODE for verification
// this is a known issue document in STM32F10xxC/D/E Errata sheet, without workaround
} else if (0x414!=(DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK)) {
} else if (0x414 != (DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK)) {
printf("this (DEV_ID=%03x) is not a high-density device: a wrong micro-controller might have been used\n", (DBGMCU_IDCODE&DBGMCU_IDCODE_DEV_ID_MASK));
}
// ensure flash size is ok
if (0xffff==DESIG_FLASH_SIZE) {
if (0xffff == DESIG_FLASH_SIZE) {
printf("unknown flash size: this is probably a defective micro-controller\n");
}
#if BUSVOODOO_HARDWARE_VERSION != 2
// check 5V power rail
float voltage = busvoodoo_vreg_get(BUSVOODOO_5V_CHANNEL); // get 5V power rail voltage
if (voltage<4.0) {
if (voltage < 4.0) {
printf("5V power rail voltage is too low: %.2fV\n", voltage);
if (halt) { // halt on error if requested
busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs
while (!user_input_available); // wait for user input
}
goto error;
} else if (voltage>5.5) {
} else if (voltage > 5.5) {
printf("5V power rail voltage is too high: %.2fV\n", voltage);
goto error;
}
// check 3.3V power rail
voltage = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get 3.3V power rail voltage
if (voltage<3.0) {
if (voltage < 3.0) {
printf("3.3V power rail voltage is too low: %.2fV\n", voltage);
goto error;
} else if (voltage>3.6) {
} else if (voltage > 3.6) {
printf("3.3V power rail voltage is too high: %.2fV\n", voltage);
goto error;
}
@ -137,18 +137,18 @@ static bool busvoodoo_hiz_test_self(bool halt)
// test 5V and 3.3V outputs
busvoodoo_vout_switch(true); // enable Vout
voltage = busvoodoo_vreg_get(BUSVOODOO_5V_CHANNEL); // get 5V power rail voltage
if (voltage<4.0) {
if (voltage < 4.0) {
printf("5V power rail voltage is too low when 5V output is enabled: %.2fV\n", voltage);
goto error;
} else if (voltage>5.5) {
} else if (voltage > 5.5) {
printf("5V power rail voltage is too high when 5V output is enabled: %.2fV\n", voltage);
goto error;
}
voltage = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get 3.3V power rail voltage
if (voltage<3.0) {
if (voltage < 3.0) {
printf("3.3V power rail voltage is too low when 3V3 output is enabled: %.2fV\n", voltage);
goto error;
} else if (voltage>3.6) {
} else if (voltage > 3.6) {
printf("3.3V power rail voltage is too high when 3V3 is enabled: %.2fV\n", voltage);
goto error;
}
@ -156,7 +156,7 @@ static bool busvoodoo_hiz_test_self(bool halt)
// check LV voltage regulator
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
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);
goto error;
}
@ -164,20 +164,20 @@ static bool busvoodoo_hiz_test_self(bool halt)
sleep_ms(5); // let the voltage regulator start and voltage settle
voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get LV voltage
// without being driven it should be around the default voltage
if (voltage<BUSVOODOO_LV_DEFAULT-0.2) {
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);
goto error;
} else if (voltage>BUSVOODOO_LV_DEFAULT+0.2) {
} 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);
goto error;
}
// check if we can control LV
voltage = busvoodoo_lv_set(BUSVOODOO_LV_TEST); // get LV voltage
if (voltage<BUSVOODOO_LV_TEST-0.2) {
if (voltage<BUSVOODOO_LV_TEST - 0.2) {
printf("LV voltage is lower (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_LV_TEST);
goto error;
} else if (voltage>BUSVOODOO_LV_TEST+0.2) {
} else if (voltage > BUSVOODOO_LV_TEST + 0.2) {
printf("LV voltage is highed (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_LV_TEST);
goto error;
}
@ -186,7 +186,7 @@ static bool busvoodoo_hiz_test_self(bool halt)
// check HV voltage regulator
if (busvoodoo_full) {
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
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);
goto error;
}
@ -194,20 +194,20 @@ static bool busvoodoo_hiz_test_self(bool halt)
sleep_ms(10); // let the voltage regulator start and voltage settle
voltage = busvoodoo_vreg_get(BUSVOODOO_HV_CHANNEL); // get HV voltage
// without being driven it should be around the default voltage
if (voltage<BUSVOODOO_HV_DEFAULT-0.4) {
if (voltage < BUSVOODOO_HV_DEFAULT - 0.4) {
printf("HV voltage is lower (%.2fV) than expected (%.2fV) when regulator is enabled\n", voltage, BUSVOODOO_HV_DEFAULT);
goto error;
} else if (voltage>BUSVOODOO_HV_DEFAULT+0.4) {
} else if (voltage > BUSVOODOO_HV_DEFAULT + 0.4) {
printf("HV voltage is higher (%.2fV) than expected (%.2fV) when regulator is enabled\n", voltage, BUSVOODOO_HV_DEFAULT);
goto error;
}
// 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.4) {
if (voltage < BUSVOODOO_HV_TEST - 0.4) {
printf("HV voltage is lower (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_HV_TEST);
goto error;
} else if (voltage>BUSVOODOO_HV_TEST+0.4) {
} else if (voltage > BUSVOODOO_HV_TEST + 0.4) {
printf("HV voltage is higher (%.2fV) than set (%.2fV)\n", voltage, BUSVOODOO_HV_TEST);
goto error;
}
@ -216,11 +216,11 @@ static bool busvoodoo_hiz_test_self(bool halt)
#endif
// pull all pins down and ensure they are low
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
for (uint8_t pin = 0; pin < LENGTH(busvoodoo_io_ports) && pin < LENGTH(busvoodoo_io_pins); pin++) {
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin]); // set pin to input
gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // pull down so it's not floating
}
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_names); pin++) {
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
goto error;
@ -228,11 +228,11 @@ static bool busvoodoo_hiz_test_self(bool halt)
}
// pull all pins up and ensure they are high
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
for (uint8_t pin = 0; pin < LENGTH(busvoodoo_io_ports) && pin < LENGTH(busvoodoo_io_pins); pin++) {
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin]); // set pin to input
gpio_set(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // pull up using internal pull-up
}
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_names); pin++) {
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
goto error;
@ -240,18 +240,18 @@ static bool busvoodoo_hiz_test_self(bool halt)
}
// set individual pin high and ensure only pins in the same group are at the same level
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
for (uint8_t pin = 0; pin < LENGTH(busvoodoo_io_ports) && pin < LENGTH(busvoodoo_io_pins); pin++) {
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin]); // set pin to input
gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // pull down to ensure it is not high by accident
}
for (uint8_t pin1=0; pin1<LENGTH(busvoodoo_io_ports) && pin1<LENGTH(busvoodoo_io_pins) && pin1<LENGTH(busvoodoo_io_groups) && pin1<LENGTH(busvoodoo_io_names); pin1++) {
for (uint8_t pin1 = 0; pin1 < LENGTH(busvoodoo_io_ports) && pin1 < LENGTH(busvoodoo_io_pins) && pin1 < LENGTH(busvoodoo_io_groups) && pin1 < LENGTH(busvoodoo_io_names); pin1++) {
gpio_set_mode(busvoodoo_io_ports[pin1], GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, busvoodoo_io_pins[pin1]); // set button pin to output
gpio_set(busvoodoo_io_ports[pin1], busvoodoo_io_pins[pin1]); // set pin high
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])) {
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
goto error;
} else if (busvoodoo_io_groups[pin1]!=busvoodoo_io_groups[pin2] && gpio_get(busvoodoo_io_ports[pin2], busvoodoo_io_pins[pin2])) {
} 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
goto error;
}
@ -260,15 +260,15 @@ static bool busvoodoo_hiz_test_self(bool halt)
gpio_clear(busvoodoo_io_ports[pin1], busvoodoo_io_pins[pin1]); // pull pin back down
}
// set individual pin low and ensure only pins in the same group are at the same level
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
for (uint8_t pin = 0; pin < LENGTH(busvoodoo_io_ports) && pin < LENGTH(busvoodoo_io_pins); pin++) {
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin]); // set pin to input
gpio_set(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // pull up to ensure it is not low by accident
}
for (uint8_t pin1=0; pin1<LENGTH(busvoodoo_io_ports) && pin1<LENGTH(busvoodoo_io_pins) && pin1<LENGTH(busvoodoo_io_groups) && pin1<LENGTH(busvoodoo_io_names); pin1++) {
for (uint8_t pin1 = 0; pin1 < LENGTH(busvoodoo_io_ports) && pin1 < LENGTH(busvoodoo_io_pins) && pin1 < LENGTH(busvoodoo_io_groups) && pin1 < LENGTH(busvoodoo_io_names); pin1++) {
gpio_set_mode(busvoodoo_io_ports[pin1], GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, busvoodoo_io_pins[pin1]); // set button pin to output
gpio_clear(busvoodoo_io_ports[pin1], busvoodoo_io_pins[pin1]); // set pin low
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])) {
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
goto error;
} else if (busvoodoo_io_groups[pin1]!=busvoodoo_io_groups[pin2] && !gpio_get(busvoodoo_io_ports[pin2], busvoodoo_io_pins[pin2])) {
@ -282,20 +282,20 @@ static bool busvoodoo_hiz_test_self(bool halt)
#if BUSVOODOO_HARDWARE_VERSION != 2
// test 5V pull-up
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
for (uint8_t pin = 0; pin < LENGTH(busvoodoo_io_ports) && pin < LENGTH(busvoodoo_io_pins); pin++) {
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin]); // set pin to input
gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // pull down to ensure it is not high by accident
}
busvoodoo_lv_set(5.0); // set LV voltage regulator to use the 5.0V power rail
voltage = busvoodoo_embedded_pullup(true); // enable 5V pull-up
if (voltage<4.0) {
if (voltage < 4.0) {
printf("5V power rail voltage is too low when used to pull up: %.2fV\n", voltage);
goto error;
} else if (voltage>5.5) {
} else if (voltage > 5.5) {
printf("5V power rail voltage is too high when used to pull up: %.2fV\n", voltage);
goto error;
}
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_names); pin++) {
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
goto error;
@ -305,20 +305,20 @@ static bool busvoodoo_hiz_test_self(bool halt)
voltage = busvoodoo_lv_set(0); // disable LV voltage regulator
// test LV pull-up set to 3.3V
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins); pin++) {
for (uint8_t pin = 0; pin < LENGTH(busvoodoo_io_ports) && pin < LENGTH(busvoodoo_io_pins); pin++) {
gpio_set_mode(busvoodoo_io_ports[pin], GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, busvoodoo_io_pins[pin]); // set pin to input
gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // pull down to ensure it is not high by accident
}
busvoodoo_lv_set(3.3); // set LV voltage regulator
voltage = busvoodoo_embedded_pullup(3.3); // enable pull-up with adjustable regulator
if (voltage<BUSVOODOO_LV_DEFAULT-0.2) {
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);
goto error;
} else if (voltage>BUSVOODOO_LV_DEFAULT+0.2) {
} 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);
goto error;
}
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_names); pin++) {
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
goto error;
@ -346,7 +346,7 @@ static bool busvoodoo_hiz_test_self(bool halt)
gpio_clear(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO(BUSVOODOO_RS485_RX_PIN)); // pull RX down
gpio_set(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX high
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
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
goto error;
}
@ -368,7 +368,7 @@ static bool busvoodoo_hiz_test_self(bool halt)
gpio_clear(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO(BUSVOODOO_CAN_RX_PIN)); // pull RX down
gpio_set(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX high
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
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
goto error;
}
@ -439,7 +439,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
busvoodoo_oled_update(); // update screen
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
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) > 0.2 && !user_input_available); // wait until pin is shorted to ground
busvoodoo_led_red_off(); // clear red LED
busvoodoo_led_blue_on(); // notify user test is running
if (user_input_available) { // user interruption
@ -448,7 +448,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
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
sleep_ms(100); // wait for voltage to settle an debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
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");
goto error;
}
@ -474,7 +474,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
#endif
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
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) < 0.2 && !user_input_available); // wait until pin is connected
busvoodoo_led_red_off(); // clear red LED
busvoodoo_led_blue_on(); // notify user test is running
if (user_input_available) { // user interruption
@ -483,7 +483,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
#if BUSVOODOO_HARDWARE_VERSION != 2
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
sleep_ms(100); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) > 0.2) {
printf("5V output is high while the power output should be switched off\n");
goto error;
}
@ -505,9 +505,9 @@ static bool busvoodoo_hiz_test_pins(bool halt)
do {
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
} 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
sleep_ms(100); // wait for stable connection
} while ((busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<0.2 || busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>3.5) && !user_input_available); // check to be sure it really is not on the 5V pin
} while ((busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) < 0.2 || busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) > 3.5) && !user_input_available); // check to be sure it really is not on the 5V pin
busvoodoo_led_red_on(); // clear red LED
busvoodoo_led_blue_on(); // notify user test is running
if (user_input_available) { // user interruption
@ -516,7 +516,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
#if BUSVOODOO_HARDWARE_VERSION != 2
gpio_set(GPIO(BUSVOODOO_VOUTEN_PORT), GPIO(BUSVOODOO_VOUTEN_PIN)); // disable Vout
sleep_ms(100); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) > 0.2) {
printf("3V3 output is high while the power output should be switched off\n");
goto error;
}
@ -524,22 +524,22 @@ static bool busvoodoo_hiz_test_pins(bool halt)
#endif
// test I/O pins
for (uint8_t io=1; io<=6; io++) { // test each I/O pin
for (uint8_t pin=0; pin<LENGTH(busvoodoo_io_ports) && pin<LENGTH(busvoodoo_io_pins) && pin<LENGTH(busvoodoo_io_groups); pin++) { // look for a pin mapped on this I/O
if (busvoodoo_io_groups[pin]==io) {
for (uint8_t io = 1; io <= 6; io++) { // test each I/O pin
for (uint8_t pin = 0; pin < LENGTH(busvoodoo_io_ports) && pin < LENGTH(busvoodoo_io_pins) && pin < LENGTH(busvoodoo_io_groups); pin++) { // look for a pin mapped on this I/O
if (busvoodoo_io_groups[pin] == io) {
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);
busvoodoo_leds_off(); // clear LEDs
busvoodoo_led_red_on(); // notify user to perform action
#if BUSVOODOO_HARDWARE_VERSION != 2
pinout[io+3] = "O"; // set target testing pin
pinout[io + 3] = "O"; // set target testing pin
busvoodoo_oled_text_pinout((const char**)pinout, true); // display pins to user
busvoodoo_oled_update(); // update screen
#endif
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
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) < 0.2 && !user_input_available); // wait until pin is connected
busvoodoo_led_red_off(); // clear red LED
busvoodoo_led_blue_on(); // notify user test is running
if (user_input_available) { // user interruption
@ -547,7 +547,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
}
gpio_clear(busvoodoo_io_ports[pin], busvoodoo_io_pins[pin]); // set pin low
sleep_ms(100); // wait for voltage to settle and debounce
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) > 0.2) {
printf("I/O pin %u is high while it should be low\n", io+4);
goto error;
}
@ -566,7 +566,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
// test HV output on RS/CAN pin 1
double voltage = busvoodoo_vreg_get(BUSVOODOO_3V3_CHANNEL); // get reference voltage
uint16_t dac_set = BUSVOODOO_HV_SET(5.0)/voltage*4095; // DAC value corresponding to the voltage
uint16_t dac_set = BUSVOODOO_HV_SET(5.0) / voltage * 4095; // DAC value corresponding to the voltage
dac_load_data_buffer_single(dac_set, RIGHT12, BUSVOODOO_HVCTL_CHANNEL); // set output so the voltage regulator is set to desired output voltage
dac_software_trigger(BUSVOODOO_HVCTL_CHANNEL); // transfer the value to the DAC
dac_enable(BUSVOODOO_HVCTL_CHANNEL); // enable DAC
@ -579,7 +579,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
busvoodoo_oled_update(); // update screen
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
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) < 0.2 && !user_input_available); // wait until pin is connected
busvoodoo_led_red_off(); // clear red LED
busvoodoo_led_blue_on(); // notify user test is running
if (user_input_available) { // user interruption
@ -588,7 +588,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
gpio_set(GPIO(BUSVOODOO_HVEN_PORT), GPIO(BUSVOODOO_HVEN_PIN)); // disable HV voltage regulator
dac_disable(BUSVOODOO_HVCTL_CHANNEL); // disable HV control
sleep_ms(100); // wait for voltage to settle (and debounce)
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>0.2) {
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) > 0.2) {
printf("HV output is high while voltage regulator should be switched off\n");
goto error;
}
@ -607,7 +607,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
busvoodoo_oled_update(); // update screen
do {
sleep_ms(100); // wait for user to make connection
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<2.0 && !user_input_available); // wait until pin is connected
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) < 2.0 && !user_input_available); // wait until pin is connected
busvoodoo_led_red_off(); // clear red LED
busvoodoo_led_blue_on(); // notify user test is running
if (user_input_available) { // user interruption
@ -615,7 +615,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
}
gpio_set(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX high
sleep_ms(100); // wait for voltage to settle (and debounce)
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>1.0) {
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) > 1.0) {
printf("RS-485 output B is high while it should be low\n");
goto error;
}
@ -635,7 +635,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
busvoodoo_oled_update(); // update screen
do {
sleep_ms(100); // wait for user to make connection
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<2.0 && !user_input_available); // wait until pin is connected
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) < 2.0 && !user_input_available); // wait until pin is connected
busvoodoo_led_red_off(); // clear red LED
busvoodoo_led_blue_on(); // notify user test is running
if (user_input_available) { // user interruption
@ -643,7 +643,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
}
gpio_clear(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX low
sleep_ms(100); // wait for voltage to settle (and debounce)
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>1.0) {
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) > 1.0) {
printf("RS-485 output A is high while it should be low\n");
goto error;
}
@ -661,11 +661,11 @@ static bool busvoodoo_hiz_test_pins(bool halt)
gpio_set(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX high
sleep_us(100); // let voltage settle
voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get output voltage
if (voltage<0.4) { // normally the lower limit is 2V, put pin 4 pulls it down because it is not strongly driven
if (voltage < 0.4) { // 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");
goto error;
}
if (voltage>3.0) { // normally the upper limit is 3V
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");
goto error;
}
@ -673,7 +673,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
gpio_clear(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX low
sleep_us(100); // let voltage settle
voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get output voltage
if (voltage>2.5) {
if (voltage > 2.5) {
printf("CAN L output is high while it should at dominant <2.25V\n");
goto error;
}
@ -695,7 +695,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
busvoodoo_oled_update(); // update screen
do {
sleep_ms(100); // wait for user to make connection
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<2.0 && !user_input_available); // wait until pin is connected
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) < 2.0 && !user_input_available); // wait until pin is connected
busvoodoo_led_red_off(); // clear red LED
busvoodoo_led_blue_on(); // notify user test is running
if (user_input_available) { // user interruption
@ -703,7 +703,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
}
gpio_clear(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX low
sleep_ms(100); // wait for voltage to settle (and debounce)
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>1.0) {
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) > 1.0) {
printf("RS-485 output A is high while it should be low\n");
goto error;
}
@ -723,7 +723,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
busvoodoo_oled_update(); // update screen
do {
sleep_ms(100); // wait for user to make connection
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)<2.0 && !user_input_available); // wait until pin is connected
} while (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) < 2.0 && !user_input_available); // wait until pin is connected
busvoodoo_led_red_off(); // clear red LED
busvoodoo_led_blue_on(); // notify user test is running
if (user_input_available) { // user interruption
@ -731,7 +731,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
}
gpio_set(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX high
sleep_ms(100); // wait for voltage to settle (and debounce)
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL)>1.0) {
if (busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL) > 1.0) {
printf("RS-485 output B is high while it should be low\n");
goto error;
}
@ -749,11 +749,11 @@ static bool busvoodoo_hiz_test_pins(bool halt)
gpio_set(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX high
sleep_us(100); // let voltage settle
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
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");
goto error;
}
if (voltage>3.0) { // normally the upper limit is 3V
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");
goto error;
}
@ -761,7 +761,7 @@ static bool busvoodoo_hiz_test_pins(bool halt)
gpio_clear(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX low
sleep_us(100); // let voltage settle
voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get output voltage
if (voltage<2.5) {
if (voltage < 2.5) {
printf("CAN H output is low while it dominant >2.75V\n");
printf("%.02f\n", voltage);
goto error;
@ -908,8 +908,8 @@ static void busvoodoo_hiz_version(void* argument)
static void busvoodoo_hiz_command_test_self(void* argument)
{
bool halt = false; // if we halt on error
if (NULL!=argument && strlen(argument)>0) {
if (0==strcmp(argument, "halt")) {
if (NULL != argument && strlen(argument) > 0) {
if (0 == strcmp(argument, "halt")) {
halt = true;
} else {
printf("malformed argument\n");
@ -923,7 +923,7 @@ static void busvoodoo_hiz_command_test_self(void* argument)
printf("remove all cables from connectors and press space to start (or any other key to abort)\n");
busvoodoo_leds_off(); // clear LEDs
busvoodoo_led_red_on(); // show red LED to indicate test started
if (' '==user_input_get()) { // space entered
if (' ' == user_input_get()) { // space entered
printf("self-test running\n");
if (busvoodoo_hiz_test_self(halt)) { // perform self-test
busvoodoo_led_red_off(); // clear red LED
@ -946,8 +946,8 @@ static void busvoodoo_hiz_command_test_self(void* argument)
static void busvoodoo_hiz_command_test_pins(void* argument)
{
bool halt = false; // if we halt on error
if (NULL!=argument && strlen(argument)>0) {
if (0==strcmp(argument, "halt")) {
if (NULL != argument && strlen(argument) > 0) {
if (0 == strcmp(argument, "halt")) {
halt = true;
} else {
printf("malformed argument\n");
@ -968,7 +968,7 @@ static void busvoodoo_hiz_command_test_pins(void* argument)
busvoodoo_oled_update(); // update screen
#endif
printf("connect one lead of jumper wire to I/O pin 4 and press space to start (or any other key to abort)\n");
if (' '==user_input_get()) { // space entered
if (' ' == user_input_get()) { // space entered
if (busvoodoo_hiz_test_pins(halt)) { // perform pin test
busvoodoo_led_red_off(); // clear red LED
busvoodoo_led_blue_on(); // show blue OK LED