got rid of all window save/restore stuff since it wasn't smp safe anyways.
authorFrank Mori Hess <fmhess@speakeasy.net>
Sat, 21 Dec 2002 04:11:31 +0000 (04:11 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Sat, 21 Dec 2002 04:11:31 +0000 (04:11 +0000)
replaced with spinlock as in ni_pcimio.c

comedi/drivers/ni_atmio.c
comedi/drivers/ni_mio_common.c
comedi/drivers/ni_mio_cs.c

index 7da17e6c8b93be2c7560c8e16d8d94d5fbc19260..4d79a5827528de167a217eb8224370397077a7fd 100644 (file)
@@ -255,27 +255,43 @@ static int ni_irqpin[]={-1,-1,-1,0,1,2,-1,3,-1,-1,4,5,6,-1,-1,7};
  * read/written directly in the I/O space of the board.  The
  * AT-MIO devices map the low 8 STC registers to iobase+addr*2. */
 
-#define win_out(data,addr) do{ \
-       if((addr)<8){ \
-               ni_writew((data),(addr)*2); \
-       }else{ \
-               ni_writew((addr),Window_Address); \
-               ni_writew((data),Window_Data); \
-       } \
-}while(0)
+#define win_out(data,addr) __win_out(dev,data,addr)
+static inline void __win_out(comedi_device *dev, unsigned short data, int addr)
+{
+       unsigned long flags;
+
+       comedi_spin_lock_irqsave(&dev->spinlock,flags);
+       if((addr)<8){
+               ni_writew(data,addr*2);
+       }else{
+               ni_writew(addr,Window_Address);
+               ni_writew(data,Window_Data);
+       }
+       comedi_spin_unlock_irqrestore(&dev->spinlock,flags);
+}
 
 #define win_out2(data,addr) do{ \
        win_out((data)>>16, (addr)); \
        win_out((data)&0xffff, (addr)+1); \
 }while(0)
 
-#define win_in(addr) ( \
-       ((addr)<8) \
-       ? (ni_readw(((addr))*2)) \
-       : (ni_writew((addr),Window_Address),ni_readw(Window_Data)))
+#define win_in(addr) __win_in(dev,addr)
+static inline unsigned short __win_in(comedi_device *dev, int addr)
+{
+       unsigned long flags;
+       int ret;
 
-#define win_save() (ni_readw(Window_Address))
-#define win_restore(a) (ni_writew((a),Window_Address))
+       comedi_spin_lock_irqsave(&dev->spinlock,flags);
+       if(addr<8){
+               ret = ni_readw(addr*2);
+       }else{
+               ni_writew(addr,Window_Address);
+               ret = ni_readw(Window_Data);
+       }
+       comedi_spin_unlock_irqrestore(&dev->spinlock,flags);
+
+       return ret;
+}
 
 #define ao_win_out(a,b) do{ \
        ni_writew((b),AO_Window_Address_671x); \
index feeb485185444dcc2e5f6721f2f0793f2b46602b..a12f2a72055d325896688cd417ae3f5738e497ee 100644 (file)
@@ -299,21 +299,12 @@ static void ni_E_interrupt(int irq,void *d,struct pt_regs * regs)
        comedi_device *dev=d;
        unsigned short a_status;
        unsigned short b_status;
-       int wsave;
        unsigned int m0_status;
        unsigned int m1_status;
 #ifdef PCIDMA
        struct mite_struct *mite = devpriv->mite;
 #endif
 
-/*
-    If you want to use windowed registers in an interrupt, it is
-    important that you restore the window address register.  If
-    you change certain modes, e.g., AI_Configuration_Start/End,
-    you need to set up software flags for non-interrupt routines.
-*/
-       wsave=win_save();
-
        a_status=win_in(AI_Status_1_Register);
        b_status=win_in(AO_Status_1_Register);
 #ifdef PCIDMA
@@ -328,8 +319,6 @@ static void ni_E_interrupt(int irq,void *d,struct pt_regs * regs)
                handle_a_interrupt(dev, a_status, m0_status);
        if(b_status&Interrupt_B_St || m1_status & CHSR_INT )
                handle_b_interrupt(dev, b_status, m1_status);
-
-       win_restore(wsave);
 }
 
 #ifdef PCIDMA
@@ -1142,13 +1131,10 @@ static int ni_ai_poll(comedi_device *dev,comedi_subdevice *s)
 static int ni_ai_insn_read(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data)
 {
        int i,n;
-       int wsave;
        unsigned int mask;
        unsigned short signbits;
        unsigned short d;
 
-       wsave=win_save();
-
        ni_load_channelgain_list(dev,1,&insn->chanspec);
 
        win_out(1,ADC_FIFO_Clear);
@@ -1178,7 +1164,6 @@ static int ni_ai_insn_read(comedi_device *dev,comedi_subdevice *s,comedi_insn *i
                        }
                        if(i==NI_TIMEOUT){
                                rt_printk("ni_mio_common: timeout in 611x ni_ai_insn_read\n");
-                               win_restore(wsave);
                                return -ETIME;
                        }
                        d += signbits; /* subtle: needs to be short addition */
@@ -1193,7 +1178,6 @@ static int ni_ai_insn_read(comedi_device *dev,comedi_subdevice *s,comedi_insn *i
                        }
                        if(i==NI_TIMEOUT){
                                rt_printk("ni_mio_common: timeout in ni_ai_insn_read\n");
-                               win_restore(wsave);
                                return -ETIME;
                        }
                        d = ni_readw(ADC_FIFO_Data_Register);
@@ -1201,7 +1185,6 @@ static int ni_ai_insn_read(comedi_device *dev,comedi_subdevice *s,comedi_insn *i
                        data[n] = d;
                }
        }
-       win_restore(wsave);
        return insn->n;
 }
 
@@ -1525,7 +1508,6 @@ static int ni_ai_cmdtest(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd)
 
 static int ni_ai_cmd(comedi_device *dev,comedi_subdevice *s)
 {
-       int wsave;
        comedi_cmd *cmd=&s->async->cmd;
        int timer;
        int mode1=0; /* mode1 is needed for both stop and convert */
@@ -1534,7 +1516,6 @@ static int ni_ai_cmd(comedi_device *dev,comedi_subdevice *s)
        unsigned int stop_count;
 
        MDPRINTK("ni_ai_cmd\n");
-       wsave = win_save();
 
        win_out(1,ADC_FIFO_Clear);
 
@@ -1786,8 +1767,6 @@ static int ni_ai_cmd(comedi_device *dev,comedi_subdevice *s)
                break;
        }
 
-       win_restore(wsave);
-
        MDPRINTK("exit ni_ai_cmd\n");
 
        return 0;
@@ -1796,17 +1775,11 @@ static int ni_ai_cmd(comedi_device *dev,comedi_subdevice *s)
 static int ni_ai_inttrig(comedi_device *dev,comedi_subdevice *s,
        unsigned int trignum)
 {
-       int wsave;
-
        if(trignum!=0)return -EINVAL;
 
-       wsave = win_save();
-
        win_out(AI_START1_Pulse,AI_Command_2_Register);
        s->async->inttrig=NULL;
 
-       win_restore(wsave);
-
        return 1;
 }
 
@@ -1984,7 +1957,6 @@ static int ni_ao_config_chanlist(comedi_device *dev, comedi_subdevice *s,
                        bits |= 1 << chan;
                        ao_win_out( chan, AO_Waveform_Generation_611x);
                }
-               ao_win_out(~bits & 0x3, AO_Immediate_671x);
                ao_win_out(bits, AO_Timed_611x);
        }else{
                for(i=0;i<n_chans;i++){
index 9f907b1edf51b8d29f97b4afd85efd72852d2b0d..41288a63a09532ea40d39e17a696bd233b8befc8 100644 (file)
@@ -178,27 +178,43 @@ static ni_board ni_boards[]={
  * read/written directly in the I/O space of the board.  The
  * DAQCard devices map the low 8 STC registers to iobase+addr*2. */
 
-#define win_out(data,addr) do{ \
-       if((addr)<8){ \
-               ni_writew((data),(addr)*2); \
-       }else{ \
-               ni_writew((addr),Window_Address); \
-               ni_writew((data),Window_Data); \
-       } \
-}while(0)
+#define win_out(data,addr) __win_out(dev,data,addr)
+static inline void __win_out(comedi_device *dev, unsigned short data, int addr)
+{
+       unsigned long flags;
+
+       comedi_spin_lock_irqsave(&dev->spinlock,flags);
+       if(addr<8){
+               ni_writew(data,addr*2);
+       }else{
+               ni_writew(addr,Window_Address);
+               ni_writew(data,Window_Data);
+       }
+       comedi_spin_unlock_irqrestore(&dev->spinlock,flags);
+}
 
 #define win_out2(data,addr) do{ \
        win_out((data)>>16, (addr)); \
                win_out((data)&0xffff, (addr)+1); \
 }while(0)
 
-#define win_in(addr) ( \
-       ((addr)<8) \
-       ? (ni_readw(((addr))*2)) \
-       : (ni_writew((addr),Window_Address),ni_readw(Window_Data)))
+#define win_in(addr) __win_in(dev,addr)
+static inline unsigned short __win_in(comedi_device *dev, int addr)
+{
+       unsigned long flags;
+       int ret;
+
+       comedi_spin_lock_irqsave(&dev->spinlock,flags);
+       if(addr<8){
+               ret = ni_readw(addr*2);
+       }else{
+               ni_writew(addr,Window_Address);
+               ret = ni_readw(Window_Data);
+       }
+       comedi_spin_unlock_irqrestore(&dev->spinlock,flags);
 
-#define win_save() (ni_readw(Window_Address))
-#define win_restore(a) (ni_writew((a),Window_Address))
+       return ret;
+}
 
 #define ao_win_out(a,b) do{ \
        ni_writew((b),AO_Window_Address_671x); \