Made it possible to request a mite channel from a specific range,
authorFrank Mori Hess <fmhess@speakeasy.net>
Thu, 26 Apr 2007 19:59:18 +0000 (19:59 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Thu, 26 Apr 2007 19:59:18 +0000 (19:59 +0000)
instead of just starting at a specified offset.  Only allow
use of mite channels 0-3 for ai/ao, since those are the only
ones that seem to work.  Commented out 3 ai convert pulses sent
when clearing ai fifo on 625x boards (based on NI example code),
since it appears to be wrong when tested with real hardware.

comedi/drivers/mite.c
comedi/drivers/mite.h
comedi/drivers/ni_mio_common.c
comedi/drivers/ni_pcidio.c

index 35df00dcf4dc7044d56b3512bb1419a8a8ebaabe..7849f8f85f567da903c2a27a5493b557b976a952 100644 (file)
@@ -229,8 +229,8 @@ void mite_list_devices(void)
 
 }
 
-struct mite_channel* mite_offset_request_channel(struct mite_struct *mite, struct mite_dma_descriptor_ring *ring,
-       unsigned first_channel_to_try)
+struct mite_channel* mite_request_channel_in_range(struct mite_struct *mite, struct mite_dma_descriptor_ring *ring,
+       unsigned min_channel, unsigned max_channel)
 {
        int i;
        unsigned long flags;
@@ -238,7 +238,7 @@ struct mite_channel* mite_offset_request_channel(struct mite_struct *mite, struc
 
        // spin lock so mite_release_channel can be called safely from interrupts
        comedi_spin_lock_irqsave(&mite->lock, flags);
-       for(i = first_channel_to_try; i < mite->num_channels; ++i)
+       for(i = min_channel; i <= max_channel; ++i)
        {
                if(mite->channel_allocated[i] == 0)
                {
@@ -707,7 +707,7 @@ EXPORT_SYMBOL(mite_setregs);
 #endif
 EXPORT_SYMBOL(mite_devices);
 EXPORT_SYMBOL(mite_list_devices);
-EXPORT_SYMBOL(mite_offset_request_channel);
+EXPORT_SYMBOL(mite_request_channel_in_range);
 EXPORT_SYMBOL(mite_release_channel);
 EXPORT_SYMBOL(mite_prep_dma);
 EXPORT_SYMBOL(mite_buf_change);
index 089fffcff4633227edf008f02678040d44dab20c..15933f2a25fcdfea0bd36f306b71f317db805789 100644 (file)
@@ -111,12 +111,13 @@ void mite_cleanup(void);
 int mite_setup(struct mite_struct *mite);
 void mite_unsetup(struct mite_struct *mite);
 void mite_list_devices(void);
-struct mite_channel* mite_offset_request_channel(struct mite_struct *mite, struct mite_dma_descriptor_ring *ring,
-       unsigned first_channel_to_try);
+struct mite_channel* mite_request_channel_in_range(
+       struct mite_struct *mite, struct mite_dma_descriptor_ring *ring,
+       unsigned min_channel, unsigned max_channel);
 static inline struct mite_channel* mite_request_channel(
        struct mite_struct *mite, struct mite_dma_descriptor_ring *ring)
 {
-       return mite_offset_request_channel(mite, ring, 0);
+       return mite_request_channel_in_range(mite, ring, 0, mite->num_channels - 1);
 }
 void mite_release_channel(struct mite_channel *mite_chan);
 
index 98e2b86be16e0b5930c5341e0a6f3313e9f4cb38..54e26920f5fd010a4120c21f145f02325bd5135c 100644 (file)
@@ -317,8 +317,6 @@ static inline void ni_set_ai_dma_channel(comedi_device *dev, int channel)
 
        comedi_spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags);
        devpriv->ai_ao_select_reg &= ~AI_DMA_Select_Mask;
-       /*FIXME this only works for channels 0,1,2.  Need to reverse
-       engineer proper bits for higher mite channels with m-series */
        if(channel >= 0)
        {
                devpriv->ai_ao_select_reg |= (1 << (channel + AI_DMA_Select_Shift)) & AI_DMA_Select_Mask;
@@ -334,8 +332,6 @@ static inline void ni_set_ao_dma_channel(comedi_device *dev, int channel)
 
        comedi_spin_lock_irqsave(&devpriv->soft_reg_copy_lock, flags);
        devpriv->ai_ao_select_reg &= ~AO_DMA_Select_Mask;
-       /*FIXME this only works for channels 0,1,2.  Need to reverse
-       engineer proper bits for higher mite channels with m-series */
        if(channel >= 0)
        {
                devpriv->ai_ao_select_reg |= (1 << (channel + AO_DMA_Select_Shift)) & AO_DMA_Select_Mask;
@@ -348,10 +344,11 @@ static inline void ni_set_ao_dma_channel(comedi_device *dev, int channel)
 static int ni_request_ai_mite_channel(comedi_device *dev)
 {
        unsigned long flags;
+       static const unsigned max_dma_channel = 3;
 
        comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags);
        BUG_ON(devpriv->ai_mite_chan);
-       devpriv->ai_mite_chan = mite_request_channel(devpriv->mite, devpriv->ai_mite_ring);
+       devpriv->ai_mite_chan = mite_request_channel_in_range(devpriv->mite, devpriv->ai_mite_ring, 0, max_dma_channel);
        if(devpriv->ai_mite_chan == NULL)
        {
                comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags);
@@ -366,10 +363,11 @@ static int ni_request_ai_mite_channel(comedi_device *dev)
 static int ni_request_ao_mite_channel(comedi_device *dev)
 {
        unsigned long flags;
+       static const unsigned max_dma_channel = 3;
 
        comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags);
        BUG_ON(devpriv->ao_mite_chan);
-       devpriv->ao_mite_chan = mite_request_channel(devpriv->mite, devpriv->ao_mite_ring);
+       devpriv->ao_mite_chan = mite_request_channel_in_range(devpriv->mite, devpriv->ao_mite_ring, 0, max_dma_channel);
        if(devpriv->ao_mite_chan == NULL)
        {
                comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags);
@@ -415,7 +413,7 @@ static void ni_release_ao_mite_channel(comedi_device *dev)
 #endif // PCIDMA
 }
 
-static void ni_flush_ai_fifo(comedi_device *dev){
+static void ni_clear_ai_fifo(comedi_device *dev){
        if(boardtype.reg_type == ni_reg_6143){
                // Flush the 6143 data FIFO
                ni_writel(0x10, AIFIFO_Control_6143);           // Flush fifo
@@ -427,9 +425,13 @@ static void ni_flush_ai_fifo(comedi_device *dev){
                {
                        ni_writeb(0, M_Offset_Static_AI_Control(0));
                        ni_writeb(1, M_Offset_Static_AI_Control(0));
+#if 0
+               /* the NI example code does 3 convert pulses for 625x boards,
+               but that appears to be wrong in practice. */
                        devpriv->stc_writew(dev, AI_CONVERT_Pulse, AI_Command_1_Register);
                        devpriv->stc_writew(dev, AI_CONVERT_Pulse, AI_Command_1_Register);
                        devpriv->stc_writew(dev, AI_CONVERT_Pulse, AI_Command_1_Register);
+#endif
                }
        }
 }
@@ -1317,7 +1319,7 @@ static int ni_ai_reset(comedi_device *dev,comedi_subdevice *s)
                AI_STOP_Interrupt_Enable|   AI_Error_Interrupt_Enable|
                AI_FIFO_Interrupt_Enable,0);
 
-       ni_flush_ai_fifo(dev);
+       ni_clear_ai_fifo(dev);
 
        if(boardtype.reg_type != ni_reg_6143)
                ni_writeb(0, Misc_Command);
@@ -1411,7 +1413,7 @@ static int ni_ai_insn_read(comedi_device *dev,comedi_subdevice *s,comedi_insn *i
 
        ni_load_channelgain_list(dev,1,&insn->chanspec);
 
-       ni_flush_ai_fifo(dev);
+       ni_clear_ai_fifo(dev);
 
        signbits=devpriv->ai_offset[0];
        if(boardtype.reg_type == ni_reg_611x){
@@ -1931,7 +1933,7 @@ static int ni_ai_cmd(comedi_device *dev,comedi_subdevice *s)
                comedi_error(dev, "cannot run command without an irq");
                return -EIO;
        }
-       ni_flush_ai_fifo(dev);
+       ni_clear_ai_fifo(dev);
 
        ni_load_channelgain_list(dev,cmd->chanlist_len,cmd->chanlist);
 
index f713afba72b13af357bf3d5a9e639ecdf83b3ab7..a00040886c753c1cb41a956f8031bea90df97357 100644 (file)
@@ -423,7 +423,7 @@ static int ni_pcidio_request_di_mite_channel(comedi_device *dev)
 
        comedi_spin_lock_irqsave(&devpriv->mite_channel_lock, flags);
        BUG_ON(devpriv->di_mite_chan);
-       devpriv->di_mite_chan = mite_offset_request_channel(devpriv->mite, devpriv->di_mite_ring, 1);
+       devpriv->di_mite_chan = mite_request_channel_in_range(devpriv->mite, devpriv->di_mite_ring, 1, 2);
        if(devpriv->di_mite_chan == NULL)
        {
                comedi_spin_unlock_irqrestore(&devpriv->mite_channel_lock, flags);