summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorian <ian@FreeBSD.org>2016-01-23 19:13:48 +0000
committerian <ian@FreeBSD.org>2016-01-23 19:13:48 +0000
commit49868192d4f0bdcbea10825f9e529c99c278bd58 (patch)
tree01c546356b9079ab81ab79f8c408f16d1ab420bf
parent3c1c5bc607d7a7263fa2e06f9b2ee08cbb2100d6 (diff)
downloadFreeBSD-src-49868192d4f0bdcbea10825f9e529c99c278bd58.zip
FreeBSD-src-49868192d4f0bdcbea10825f9e529c99c278bd58.tar.gz
MFC r294235:
Make PPS ASSERT/CLEAR events match the RS-232 signal levels as per RFC 2783. Previously the polarity was for TTL levels, which are the reverse of RS-232. Also add handling of the UART_PPS_INVERT_PULSE option bit in the sysctl value, the same as was recently added to uart(4), so that people using TTL level connections can request a logical inverting of the signal. Use the named constants from the new dev/uart/uart_ppstypes.h for the pps capture modes and option bits.
-rw-r--r--sys/dev/usb/serial/usb_serial.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/sys/dev/usb/serial/usb_serial.c b/sys/dev/usb/serial/usb_serial.c
index 499d5c1..5bc23b8 100644
--- a/sys/dev/usb/serial/usb_serial.c
+++ b/sys/dev/usb/serial/usb_serial.c
@@ -81,6 +81,8 @@ __FBSDID("$FreeBSD$");
#include <sys/cons.h>
#include <sys/kdb.h>
+#include <dev/uart/uart_ppstypes.h>
+
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
@@ -99,7 +101,8 @@ static SYSCTL_NODE(_hw_usb, OID_AUTO, ucom, CTLFLAG_RW, 0, "USB ucom");
static int ucom_pps_mode;
SYSCTL_INT(_hw_usb_ucom, OID_AUTO, pps_mode, CTLFLAG_RWTUN,
- &ucom_pps_mode, 0, "pulse capturing mode - 0/1/2 - disabled/CTS/DCD");
+ &ucom_pps_mode, 0,
+ "pulse capture mode: 0/1/2=disabled/CTS/DCD; add 0x10 to invert");
#ifdef USB_DEBUG
static int ucom_debug = 0;
@@ -1074,10 +1077,12 @@ ucom_cfg_status_change(struct usb_proc_msg *_task)
(struct ucom_cfg_task *)_task;
struct ucom_softc *sc = task->sc;
struct tty *tp;
+ int onoff;
uint8_t new_msr;
uint8_t new_lsr;
uint8_t msr_delta;
uint8_t lsr_delta;
+ uint8_t pps_signal;
tp = sc->sc_tty;
@@ -1107,35 +1112,33 @@ ucom_cfg_status_change(struct usb_proc_msg *_task)
sc->sc_lsr = new_lsr;
/*
- * Time pulse counting support. Note that both CTS and DCD are
- * active-low signals. The status bit is high to indicate that
- * the signal on the line is low, which corresponds to a PPS
- * clear event.
+ * Time pulse counting support.
*/
- switch(ucom_pps_mode) {
- case 1:
- if ((sc->sc_pps.ppsparam.mode & PPS_CAPTUREBOTH) &&
- (msr_delta & SER_CTS)) {
- pps_capture(&sc->sc_pps);
- pps_event(&sc->sc_pps, (sc->sc_msr & SER_CTS) ?
- PPS_CAPTURECLEAR : PPS_CAPTUREASSERT);
- }
+ switch(ucom_pps_mode & UART_PPS_SIGNAL_MASK) {
+ case UART_PPS_CTS:
+ pps_signal = SER_CTS;
break;
- case 2:
- if ((sc->sc_pps.ppsparam.mode & PPS_CAPTUREBOTH) &&
- (msr_delta & SER_DCD)) {
- pps_capture(&sc->sc_pps);
- pps_event(&sc->sc_pps, (sc->sc_msr & SER_DCD) ?
- PPS_CAPTURECLEAR : PPS_CAPTUREASSERT);
- }
+ case UART_PPS_DCD:
+ pps_signal = SER_DCD;
break;
default:
+ pps_signal = 0;
break;
}
+ if ((sc->sc_pps.ppsparam.mode & PPS_CAPTUREBOTH) &&
+ (msr_delta & pps_signal)) {
+ pps_capture(&sc->sc_pps);
+ onoff = (sc->sc_msr & pps_signal) ? 1 : 0;
+ if (ucom_pps_mode & UART_PPS_INVERT_PULSE)
+ onoff = !onoff;
+ pps_event(&sc->sc_pps, onoff ? PPS_CAPTUREASSERT :
+ PPS_CAPTURECLEAR);
+ }
+
if (msr_delta & SER_DCD) {
- int onoff = (sc->sc_msr & SER_DCD) ? 1 : 0;
+ onoff = (sc->sc_msr & SER_DCD) ? 1 : 0;
DPRINTF("DCD changed to %d\n", onoff);
OpenPOWER on IntegriCloud