Added NI_EXT_PFI() and NI_EXT_RTSI() helper functions to comedi.h
authorFrank Mori Hess <fmhess@speakeasy.net>
Tue, 24 Oct 2006 15:06:10 +0000 (15:06 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Tue, 24 Oct 2006 15:06:10 +0000 (15:06 +0000)
for specifying pfi/rtsi lines as external trigger sources.  Tweaked
a couple names to match ni stc documentation more closely.

comedi/drivers/ni_mio_common.c
include/linux/comedi.h

index f5d72f097a5ee0648d20c1d507c7502d190ffef1..9231c6280a503da1a3eae02262acac7420ae0791 100644 (file)
@@ -4318,8 +4318,8 @@ static void ni_rtsi_init(comedi_device *dev)
        devpriv->stc_writew(dev, devpriv->rtsi_trig_a_output_reg,
                RTSI_Trig_A_Output_Register);
        devpriv->rtsi_trig_b_output_reg = RTSI_Trig_Output_Bits(4, NI_RTSI_OUTPUT_DA_START1) |
-               RTSI_Trig_Output_Bits(5, NI_RTSI_OUTPUT_G_SRC_0) |
-               RTSI_Trig_Output_Bits(6, NI_RTSI_OUTPUT_G_GATE_0);
+               RTSI_Trig_Output_Bits(5, NI_RTSI_OUTPUT_G_SRC0) |
+               RTSI_Trig_Output_Bits(6, NI_RTSI_OUTPUT_G_GATE0);
        if(boardtype.reg_type == ni_reg_m_series)
                devpriv->rtsi_trig_b_output_reg |= RTSI_Trig_Output_Bits(7, NI_RTSI_OUTPUT_RTSI_OSC);
        devpriv->stc_writew(dev, devpriv->rtsi_trig_b_output_reg,
@@ -4494,7 +4494,15 @@ static int ni_set_master_clock(comedi_device *dev, unsigned source, unsigned per
                        {
                                devpriv->rtsi_trig_direction_reg |= Use_RTSI_Clock_Bit;
                                devpriv->stc_writew(dev, devpriv->rtsi_trig_direction_reg, RTSI_Trig_Direction_Register);
-                               devpriv->clock_ns = period_ns;
+                               if(devpriv->clock_ns == 0)
+                               {
+                                       rt_printk("%s: we don't handle an unspecified clock period correctly yet, returning error.\n",
+                                               __FUNCTION__);
+                                       return -EINVAL;
+                               }else
+                               {
+                                       devpriv->clock_ns = period_ns;
+                               }
                                devpriv->clock_source = source;
                        }else
                                return -EINVAL;
@@ -4526,8 +4534,8 @@ int ni_valid_rtsi_output_source(comedi_device *dev, unsigned chan, unsigned sour
        case NI_RTSI_OUTPUT_SCLKG:
        case NI_RTSI_OUTPUT_DACUPDN:
        case NI_RTSI_OUTPUT_DA_START1:
-       case NI_RTSI_OUTPUT_G_SRC_0:
-       case NI_RTSI_OUTPUT_G_GATE_0:
+       case NI_RTSI_OUTPUT_G_SRC0:
+       case NI_RTSI_OUTPUT_G_GATE0:
        case NI_RTSI_OUTPUT_RGOUT0:
        case NI_RTSI_OUTPUT_RTSI_BRD_0:
                return 1;
index 076b088f001ee8f78a06923f362012f409fc55d9..d6cba93003253dac4d3f4db650a84a9cdc590e42 100644 (file)
@@ -547,35 +547,29 @@ enum ni_rtsi_output
        NI_RTSI_OUTPUT_SCLKG = 2,
        NI_RTSI_OUTPUT_DACUPDN = 3,
        NI_RTSI_OUTPUT_DA_START1 = 4,
-       NI_RTSI_OUTPUT_G_SRC_0 = 5,
-       NI_RTSI_OUTPUT_G_GATE_0 = 6,
+       NI_RTSI_OUTPUT_G_SRC0 = 5,
+       NI_RTSI_OUTPUT_G_GATE0 = 6,
        NI_RTSI_OUTPUT_RGOUT0 = 7,
        NI_RTSI_OUTPUT_RTSI_BRD_0 = 8,
-       NI_RTSI_OUTPUT_RTSI_OSC = 12 /* m-series only */
+       NI_RTSI_OUTPUT_RTSI_OSC = 12 /* pre-m-series always have RTSI clock on line 7 */
 };
 static inline unsigned NI_RTSI_OUTPUT_RTSI_BRD(unsigned n)
 {
        return NI_RTSI_OUTPUT_RTSI_BRD_0 + n;
 }
 
-/* NI External Trigger lines */
-#define NI_EXT_PFI_0                   0
-#define NI_EXT_PFI_1                   1
-#define NI_EXT_PFI_2                   2
-#define NI_EXT_PFI_3                   3
-#define NI_EXT_PFI_4                   4
-#define NI_EXT_PFI_5                   5
-#define NI_EXT_PFI_6                   6
-#define NI_EXT_PFI_7                   7
-#define NI_EXT_PFI_8                   8
-#define NI_EXT_PFI_9                   9
-#define NI_EXT_RTSI_0                  10
-#define NI_EXT_RTSI_1                  11
-#define NI_EXT_RTSI_2                  12
-#define NI_EXT_RTSI_3                  13
-#define NI_EXT_RTSI_4                  14
-#define NI_EXT_RTSI_5                  15
-#define NI_EXT_RTSI_6                  16
+/* NI External Trigger lines.  These values are not arbitrary, but are related to
+       the bits required to program the board (offset by 1 for historical reasons). */
+static inline unsigned NI_EXT_PFI(unsigned pfi_channel)
+{
+       if(pfi_channel < 10) return pfi_channel;
+       else return pfi_channel + 10;
+}
+static inline unsigned NI_EXT_RTSI(unsigned rtsi_channel)
+{
+       if(rtsi_channel < 7) return 10 + rtsi_channel;
+       else return 19 + rtsi_channel;
+}
 
 #ifdef __cplusplus
 }