From 6e87c1d7b7a79ceb09630bcf1b13f363314f4610 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 20 Sep 2018 21:57:30 +0200 Subject: [PATCH] Fix the RTS signal handling for Pelagic interface The RTS signal needs to be low before it is raised, and not just set. This ensures that the PIC inside the Pelagic PC interface is reset and the initialization sequence always starts cleanly, regardless of the previous state of the signal. Reported-By: Bill Perry --- src/oceanic_atom2.c | 34 +++++++++++++++++++++++++--------- src/oceanic_veo250.c | 14 ++++++++++++++ src/oceanic_vtpro.c | 14 ++++++++++++++ 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/oceanic_atom2.c b/src/oceanic_atom2.c index 80bdfea..7d1f68c 100644 --- a/src/oceanic_atom2.c +++ b/src/oceanic_atom2.c @@ -661,21 +661,37 @@ oceanic_atom2_device_open (dc_device_t **out, dc_context_t *context, dc_iostream goto error_free; } - // Give the interface 100 ms to settle and draw power up. + // Set the DTR line. + status = dc_iostream_set_dtr (device->iostream, 1); + if (status != DC_STATUS_SUCCESS) { + ERROR (context, "Failed to set the DTR line."); + goto error_free; + } + + // Clear the RTS line to reset the PIC inside the data cable as it + // may not have have been previously cleared. This ensures that the + // PIC will always start in a known state once RTS is set. Starting + // in a known default state is very important as the PIC won't + // respond to init commands unless it is in a default state. + status = dc_iostream_set_rts (device->iostream, 0); + if (status != DC_STATUS_SUCCESS) { + ERROR (context, "Failed to clear the RTS line."); + goto error_free; + } + + // Hold RTS clear for a bit to allow PIC to reset. dc_iostream_sleep (device->iostream, 100); - // Set the DTR/RTS lines. - status = dc_iostream_set_dtr(device->iostream, 1); + // Set the RTS line. + status = dc_iostream_set_rts (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { - ERROR (context, "Failed to set the DTR line."); - goto error_free; - } - status = dc_iostream_set_rts(device->iostream, 1); - if (status != DC_STATUS_SUCCESS) { - ERROR (context, "Failed to set the DTR line."); + ERROR (context, "Failed to set the RTS line."); goto error_free; } + // Give the interface 100 ms to settle and draw power up. + dc_iostream_sleep (device->iostream, 100); + // Make sure everything is in a sane state. dc_iostream_purge (device->iostream, DC_DIRECTION_ALL); diff --git a/src/oceanic_veo250.c b/src/oceanic_veo250.c index de70c7b..a6038d8 100644 --- a/src/oceanic_veo250.c +++ b/src/oceanic_veo250.c @@ -272,6 +272,20 @@ oceanic_veo250_device_open (dc_device_t **out, dc_context_t *context, dc_iostrea goto error_free; } + // Clear the RTS line to reset the PIC inside the data cable as it + // may not have have been previously cleared. This ensures that the + // PIC will always start in a known state once RTS is set. Starting + // in a known default state is very important as the PIC won't + // respond to init commands unless it is in a default state. + status = dc_iostream_set_rts (device->iostream, 0); + if (status != DC_STATUS_SUCCESS) { + ERROR (context, "Failed to clear the RTS line."); + goto error_free; + } + + // Hold RTS clear for a bit to allow PIC to reset. + dc_iostream_sleep (device->iostream, 100); + // Set the RTS line. status = dc_iostream_set_rts (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { diff --git a/src/oceanic_vtpro.c b/src/oceanic_vtpro.c index d3387f2..cefeb7b 100644 --- a/src/oceanic_vtpro.c +++ b/src/oceanic_vtpro.c @@ -442,6 +442,20 @@ oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, dc_iostream goto error_free; } + // Clear the RTS line to reset the PIC inside the data cable as it + // may not have have been previously cleared. This ensures that the + // PIC will always start in a known state once RTS is set. Starting + // in a known default state is very important as the PIC won't + // respond to init commands unless it is in a default state. + status = dc_iostream_set_rts (device->iostream, 0); + if (status != DC_STATUS_SUCCESS) { + ERROR (context, "Failed to clear the RTS line."); + goto error_free; + } + + // Hold RTS clear for a bit to allow PIC to reset. + dc_iostream_sleep (device->iostream, 100); + // Set the RTS line. status = dc_iostream_set_rts (device->iostream, 1); if (status != DC_STATUS_SUCCESS) {