From fc423635dd825bbd96573df2aef71a653be578a5 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Thu, 26 Apr 2007 19:59:18 +0000 Subject: [PATCH] Made it possible to request a mite channel from a specific range, 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 | 8 ++++---- comedi/drivers/mite.h | 7 ++++--- comedi/drivers/ni_mio_common.c | 22 ++++++++++++---------- comedi/drivers/ni_pcidio.c | 2 +- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/comedi/drivers/mite.c b/comedi/drivers/mite.c index 35df00dc..7849f8f8 100644 --- a/comedi/drivers/mite.c +++ b/comedi/drivers/mite.c @@ -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); diff --git a/comedi/drivers/mite.h b/comedi/drivers/mite.h index 089fffcf..15933f2a 100644 --- a/comedi/drivers/mite.h +++ b/comedi/drivers/mite.h @@ -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); diff --git a/comedi/drivers/ni_mio_common.c b/comedi/drivers/ni_mio_common.c index 98e2b86b..54e26920 100644 --- a/comedi/drivers/ni_mio_common.c +++ b/comedi/drivers/ni_mio_common.c @@ -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); diff --git a/comedi/drivers/ni_pcidio.c b/comedi/drivers/ni_pcidio.c index f713afba..a0004088 100644 --- a/comedi/drivers/ni_pcidio.c +++ b/comedi/drivers/ni_pcidio.c @@ -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); -- 2.26.2