make single-scan ai commands work
authorFrank Mori Hess <fmhess@speakeasy.net>
Mon, 13 Dec 2004 02:02:10 +0000 (02:02 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Mon, 13 Dec 2004 02:02:10 +0000 (02:02 +0000)
comedi/drivers/ni_mio_common.c
comedi/drivers/ni_stc.h

index d37def3bce8a3145c52a0b4e02205496ed74f269..c8fbf2abb7fe4f3243e1644507614223957b7cb2 100644 (file)
@@ -519,8 +519,9 @@ static void ni_handle_eos(comedi_device *dev, comedi_subdevice *s)
 #endif
        }
        /* handle special case of single scan using AI_End_On_End_Of_Scan */
-       if( ( devpriv->ai_cmd2 & AI_End_On_End_Of_Scan ) ){
+       if((devpriv->ai_cmd2 & AI_End_On_End_Of_Scan)){
                shutdown_ai_command( dev );
+               ni_ai_reset(dev, s);
        }
 }
 
@@ -653,8 +654,7 @@ static void handle_a_interrupt(comedi_device *dev,unsigned short status,
 #ifdef DEBUG_INTERRUPT
        status=win_in(AI_Status_1_Register);
        if(status&Interrupt_A_St){
-               printk("handle_a_interrupt: BUG, didn't clear interrupt. disabling. status=0x%x\n", status);
-                win_out(0,Interrupt_Control_Register);
+               printk("handle_a_interrupt: didn't clear interrupt? status=0x%x\n", status);
        }
 #endif
 }
@@ -935,14 +935,16 @@ static int ni_ai_drain_dma(comedi_device *dev )
 
        for( i = 0; i < timeout; i++ )
        {
-               if( ( win_in( AI_Status_1_Register ) & AI_FIFO_Empty_St ) &&
-                       mite_bytes_in_transit( mite, AI_DMA_CHAN ) == 0 )
+               if((win_in(AI_Status_1_Register) & AI_FIFO_Empty_St) &&
+                       mite_bytes_in_transit(mite, AI_DMA_CHAN) == 0)
                        break;
                comedi_udelay(2);
        }
-       if( i == timeout )
+       if(i == timeout)
        {
-               rt_printk( "ni_mio_common: wait for dma drain timed out\n" );
+               rt_printk("ni_mio_common: wait for dma drain timed out\n");
+               rt_printk("mite_bytes_in_transit=%i, AI_Status1_Register=0x%x\n",
+                       mite_bytes_in_transit(mite, AI_DMA_CHAN), win_in(AI_Status_1_Register));
                return -1;
        }
 
@@ -1497,6 +1499,10 @@ static int ni_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd)
                        cmd->stop_arg = max_count;
                        err++;
                }
+               if(cmd->stop_arg < 1){
+                       cmd->stop_arg = 1;
+                       err++;
+               }
        }else{
                /* TRIG_NONE */
                if(cmd->stop_arg!=0){
@@ -1588,12 +1594,13 @@ static int ni_ai_cmd(comedi_device *dev,comedi_subdevice *s)
        mode2 &= ~AI_SC_Reload_Mode;
        win_out(mode2, AI_Mode_2_Register);
 
-       start_stop_select |= AI_STOP_Sync;
-       if(boardtype.reg_type == ni_reg_611x){
+       if(cmd->chanlist_len == 1 || boardtype.reg_type == ni_reg_611x){
                start_stop_select |= AI_STOP_Polarity;
-               start_stop_select |= AI_STOP_Select( 31 );
-       }else{
-               start_stop_select |= AI_STOP_Select( 19 );
+               start_stop_select |= AI_STOP_Select( 31 ); // logic low
+               start_stop_select |= AI_STOP_Sync;
+       }else
+       {
+               start_stop_select |= AI_STOP_Select(19); // ai configuration memory
        }
        win_out(start_stop_select, AI_START_STOP_Select_Register);
 
@@ -1618,6 +1625,9 @@ static int ni_ai_cmd(comedi_device *dev,comedi_subdevice *s)
                if( stop_count == 0 ){
                        devpriv->ai_cmd2 |= AI_End_On_End_Of_Scan;
                        interrupt_a_enable |= AI_STOP_Interrupt_Enable;
+                       // this is required to get the last sample for chanlist_len > 1, not sure why
+                       if(cmd->chanlist_len > 1)
+                               start_stop_select |= AI_STOP_Polarity | AI_STOP_Edge;
                }
                break;
        case TRIG_NONE:
@@ -1726,7 +1736,7 @@ static int ni_ai_cmd(comedi_device *dev,comedi_subdevice *s)
                interrupt_a_enable|=AI_FIFO_Interrupt_Enable;
 #endif
 
-               if(cmd->flags & TRIG_WAKE_EOS){
+               if(cmd->flags & TRIG_WAKE_EOS || (devpriv->ai_cmd2 & AI_End_On_End_Of_Scan)){
                        /* wake on end-of-scan */
                        devpriv->aimode=AIMODE_SCAN;
                }else{
index 5919ff5ebcca0fc425c6b3dfac94c40a60d7e4ac..8952dd056e749f47d58c03e0934edeb71a483203 100644 (file)
@@ -334,6 +334,8 @@ enum AO_FIFO_Mode_Bits
 #define AI_START1_Edge                         _bit5
 #define AI_START1_Select(a)                    (a)
 
+#define AI_DIV_Load_A_Register 64
+
 #define AO_Start_Select_Register       66
 #define AO_UI2_Software_Gate                   _bit15
 #define AO_UI2_External_Gate_Polarity          _bit14