fix: don't pull REN up on startup before DMM is online

This commit is contained in:
2025-12-02 20:39:09 +06:00
parent ad833867d1
commit 054bc38683

100
main.c
View File

@@ -55,12 +55,12 @@
#define MENU_DOT_INTERVAL_MS 500 // Speed of "..." addition #define MENU_DOT_INTERVAL_MS 500 // Speed of "..." addition
#define MENU_COMMIT_DELAY_MS 2400 // Time to hold before entering mode #define MENU_COMMIT_DELAY_MS 2400 // Time to hold before entering mode
#define MENU_SUBLAYER_DELAY_MS 500 // Time to "hover" before dots start #define MENU_SUBLAYER_DELAY_MS 500 // Time to "hover" before dots start
#define MENU_DEBOUNCE_MS 200 // Button press dead-time #define MENU_DEBOUNCE_MS 100 // Button press dead-time
#define MENU_LOCKOUT_MS 1000 // How long to ignore SRQ for after exiting menu #define MENU_LOCKOUT_MS 1000 // How long to ignore SRQ for after exiting menu
// Polling // Polling
#define POLL_INTERVAL_MS 100 // 10Hz polling when in Passthrough #define POLL_INTERVAL_MS 100 // 10Hz polling when in Passthrough
#define DMM_RECOVERY_DELAY_MS 1000 // Backoff if DMM vanishes #define DMM_RECOVERY_DELAY_MS 2000 // Backoff if DMM vanishes
// Diode sound // Diode sound
#define DIODE_TH_SHORT 0.050 // Volts (below this = SHORT) #define DIODE_TH_SHORT 0.050 // Volts (below this = SHORT)
@@ -1007,7 +1007,6 @@ int gpib_read_byte(uint8_t* data, int* eoi_asserted) {
// Sets up Talker/Listener for data transfer // Sets up Talker/Listener for data transfer
int gpib_start_session(uint8_t target_addr, session_mode_t mode) { int gpib_start_session(uint8_t target_addr, session_mode_t mode) {
printf("gpib_start_session\n");
GPIB_ASSERT(PIN_ATN); GPIB_ASSERT(PIN_ATN);
Delay_Us(1); Delay_Us(1);
@@ -1159,30 +1158,41 @@ int gpib_serial_poll(uint8_t addr, uint8_t* status) {
if (gpib_write_byte(GPIB_CMD_LAD | MY_ADDR, 0) < 0) goto err; if (gpib_write_byte(GPIB_CMD_LAD | MY_ADDR, 0) < 0) goto err;
if (gpib_write_byte(GPIB_CMD_TAD | addr, 0) < 0) goto err; if (gpib_write_byte(GPIB_CMD_TAD | addr, 0) < 0) goto err;
// gpib_write_data(0x00); // Float data lines gpib_write_data(0x00); // Float data lines
// GPIB_ASSERT(PIN_NDAC); // Busy / Not Accepted GPIB_ASSERT(PIN_NDAC); // Busy / Not Accepted
// GPIB_ASSERT(PIN_NRFD); // Busy / Not Ready GPIB_ASSERT(PIN_NRFD); // Busy / Not Ready
// Delay_Us(5); GPIB_RELEASE(PIN_ATN); // Handover to data mode
// drop ATN to read data
GPIB_RELEASE(PIN_ATN);
int eoi; int eoi;
int res = gpib_read_byte(status, &eoi); if (gpib_read_byte(status, &eoi) < 0) {
goto err_data;
}
// handshake complete, clean up lines GPIB_ASSERT(PIN_ATN);
Delay_Us(1);
// return to cmd mode
GPIB_RELEASE(PIN_NRFD); GPIB_RELEASE(PIN_NRFD);
GPIB_RELEASE(PIN_NDAC); GPIB_RELEASE(PIN_NDAC);
// end seq: ATN -> SPD -> UNT // end seq: SPD -> UNT
GPIB_ASSERT(PIN_ATN); gpib_write_byte(GPIB_CMD_SPD, 0);
gpib_write_byte(GPIB_CMD_SPD, 0); // disable spoll gpib_write_byte(GPIB_CMD_UNT, 0);
gpib_write_byte(GPIB_CMD_UNT, 0); // untalk
GPIB_RELEASE(PIN_ATN); GPIB_RELEASE(PIN_ATN);
return res; return 0;
err_data:
// if read failed, assert ATN and release those lines
GPIB_ASSERT(PIN_ATN);
Delay_Us(1);
GPIB_RELEASE(PIN_NRFD);
GPIB_RELEASE(PIN_NDAC);
err: err:
// just ensure we don't leave the device in spoll mode
gpib_write_byte(GPIB_CMD_SPD, 0);
gpib_write_byte(GPIB_CMD_UNT, 0);
GPIB_RELEASE(PIN_ATN); GPIB_RELEASE(PIN_ATN);
return -1; return -1;
} }
@@ -1334,18 +1344,14 @@ int gpib_receive_binary(uint8_t addr, char* buf, int expected_len) {
} }
void gpib_init(void) { void gpib_init(void) {
// configure control lines as open-drain outputs // calculate BSHR for the DIO lines
funPinMode(PIN_EOI, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD); for (int i = 0; i < 256; i++) {
funPinMode(PIN_REN, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD); gpib_write_lut[i] =
funPinMode(PIN_ATN, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD); CALC_PIN_BSHR(i, 0, PIN_POS_D1) | CALC_PIN_BSHR(i, 1, PIN_POS_D2) |
funPinMode(PIN_IFC, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD); CALC_PIN_BSHR(i, 2, PIN_POS_D3) | CALC_PIN_BSHR(i, 3, PIN_POS_D4) |
funPinMode(PIN_DAV, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD); CALC_PIN_BSHR(i, 4, PIN_POS_D5) | CALC_PIN_BSHR(i, 5, PIN_POS_D6) |
funPinMode(PIN_NDAC, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD); CALC_PIN_BSHR(i, 6, PIN_POS_D7) | CALC_PIN_BSHR(i, 7, PIN_POS_D8);
funPinMode(PIN_NRFD, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD); }
// SRQ is input with pull-up
funPinMode(PIN_SRQ, GPIO_CNF_IN_PUPD);
funDigitalWrite(PIN_SRQ, 1);
// float all control lines // float all control lines
GPIB_RELEASE(PIN_EOI); GPIB_RELEASE(PIN_EOI);
@@ -1356,6 +1362,18 @@ void gpib_init(void) {
GPIB_RELEASE(PIN_NDAC); GPIB_RELEASE(PIN_NDAC);
GPIB_RELEASE(PIN_NRFD); GPIB_RELEASE(PIN_NRFD);
// configure control lines as open-drain outputs
funPinMode(PIN_EOI, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD);
funPinMode(PIN_REN, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD);
funPinMode(PIN_ATN, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD);
funPinMode(PIN_IFC, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD);
funPinMode(PIN_DAV, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD);
funPinMode(PIN_NDAC, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD);
funPinMode(PIN_NRFD, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD);
// float data lines
gpib_write_data(0x00);
// data lines // data lines
funPinMode(PIN_DIO1, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD); funPinMode(PIN_DIO1, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD);
funPinMode(PIN_DIO2, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD); funPinMode(PIN_DIO2, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD);
@@ -1366,17 +1384,12 @@ void gpib_init(void) {
funPinMode(PIN_DIO7, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD); funPinMode(PIN_DIO7, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD);
funPinMode(PIN_DIO8, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD); funPinMode(PIN_DIO8, GPIO_Speed_50MHz | GPIO_CNF_OUT_OD);
// calculate BSHR for the DIO lines // SRQ is input with pull-up
for (int i = 0; i < 256; i++) { funPinMode(PIN_SRQ, GPIO_CNF_IN_PUPD);
gpib_write_lut[i] = funDigitalWrite(PIN_SRQ, 1);
CALC_PIN_BSHR(i, 0, PIN_POS_D1) | CALC_PIN_BSHR(i, 1, PIN_POS_D2) |
CALC_PIN_BSHR(i, 2, PIN_POS_D3) | CALC_PIN_BSHR(i, 3, PIN_POS_D4) |
CALC_PIN_BSHR(i, 4, PIN_POS_D5) | CALC_PIN_BSHR(i, 5, PIN_POS_D6) |
CALC_PIN_BSHR(i, 6, PIN_POS_D7) | CALC_PIN_BSHR(i, 7, PIN_POS_D8);
}
// float data lines // clr
gpib_write_data(0x00); gpib_interface_clear();
} }
// ------------------------------------ // ------------------------------------
@@ -2297,7 +2310,8 @@ void handle_menu_navigation(void) {
// only poll GPIB if physical line is asserted // only poll GPIB if physical line is asserted
if (gpib_check_srq()) { if (gpib_check_srq()) {
uint8_t stb = 0; uint8_t stb = 0;
gpib_serial_poll(app.dmm_addr, &stb);
if (gpib_serial_poll(app.dmm_addr, &stb) != 0) return;
// check if it was the front panel btn // check if it was the front panel btn
if (stb & HP3478A_MASK_KEYBOARD_SRQ) { if (stb & HP3478A_MASK_KEYBOARD_SRQ) {
@@ -2429,7 +2443,6 @@ void app_loop(void) {
if (app.dmm_online) { if (app.dmm_online) {
// printf("DMM Lost connection.\n"); // printf("DMM Lost connection.\n");
app.dmm_online = 0; app.dmm_online = 0;
gpib_interface_clear();
} }
// slow down polling when offline // slow down polling when offline
app.poll_interval = DMM_RECOVERY_DELAY_MS; app.poll_interval = DMM_RECOVERY_DELAY_MS;
@@ -2439,6 +2452,10 @@ void app_loop(void) {
// got a valid response, check if this is a recovery // got a valid response, check if this is a recovery
if (!app.dmm_online) { if (!app.dmm_online) {
// printf("DMM Recovered.\n"); // printf("DMM Recovered.\n");
// only assert REN here when it's online
gpib_remote_enable(1);
gpib_interface_clear();
app.dmm_online = 1; app.dmm_online = 1;
gpib_send(app.dmm_addr, HP3478A_CMD_MASK_BTN_ONLY HP3478A_CMD_SRQ_CLEAR); gpib_send(app.dmm_addr, HP3478A_CMD_MASK_BTN_ONLY HP3478A_CMD_SRQ_CLEAR);
gpib_go_to_local(app.dmm_addr); gpib_go_to_local(app.dmm_addr);
@@ -2894,7 +2911,6 @@ int main() {
// GPIB controller // GPIB controller
gpib_init(); gpib_init();
gpib_remote_enable(1);
// USB interface // USB interface
USBFSSetup(); USBFSSetup();