Xenomai API  2.6.5
ni_stc.h
Go to the documentation of this file.
1 
26 #ifndef __ANALOGY_NI_STC_H__
27 #define __ANALOGY_NI_STC_H__
28 
29 #include "ni_tio.h"
30 
31 #define _bit15 0x8000
32 #define _bit14 0x4000
33 #define _bit13 0x2000
34 #define _bit12 0x1000
35 #define _bit11 0x0800
36 #define _bit10 0x0400
37 #define _bit9 0x0200
38 #define _bit8 0x0100
39 #define _bit7 0x0080
40 #define _bit6 0x0040
41 #define _bit5 0x0020
42 #define _bit4 0x0010
43 #define _bit3 0x0008
44 #define _bit2 0x0004
45 #define _bit1 0x0002
46 #define _bit0 0x0001
47 
48 #define NUM_PFI_OUTPUT_SELECT_REGS 6
49 
50 /* Registers in the National Instruments DAQ-STC chip */
51 
52 #define Interrupt_A_Ack_Register 2
53 #define G0_Gate_Interrupt_Ack _bit15
54 #define G0_TC_Interrupt_Ack _bit14
55 #define AI_Error_Interrupt_Ack _bit13
56 #define AI_STOP_Interrupt_Ack _bit12
57 #define AI_START_Interrupt_Ack _bit11
58 #define AI_START2_Interrupt_Ack _bit10
59 #define AI_START1_Interrupt_Ack _bit9
60 #define AI_SC_TC_Interrupt_Ack _bit8
61 #define AI_SC_TC_Error_Confirm _bit7
62 #define G0_TC_Error_Confirm _bit6
63 #define G0_Gate_Error_Confirm _bit5
64 
65 #define AI_Status_1_Register 2
66 #define Interrupt_A_St _bit15
67 #define AI_FIFO_Full_St _bit14
68 #define AI_FIFO_Half_Full_St _bit13
69 #define AI_FIFO_Empty_St _bit12
70 #define AI_Overrun_St _bit11
71 #define AI_Overflow_St _bit10
72 #define AI_SC_TC_Error_St _bit9
73 #define AI_START2_St _bit8
74 #define AI_START1_St _bit7
75 #define AI_SC_TC_St _bit6
76 #define AI_START_St _bit5
77 #define AI_STOP_St _bit4
78 #define G0_TC_St _bit3
79 #define G0_Gate_Interrupt_St _bit2
80 #define AI_FIFO_Request_St _bit1
81 #define Pass_Thru_0_Interrupt_St _bit0
82 
83 #define AI_Status_2_Register 5
84 
85 #define Interrupt_B_Ack_Register 3
86 #define G1_Gate_Error_Confirm _bit1
87 #define G1_TC_Error_Confirm _bit2
88 #define AO_BC_TC_Trigger_Error_Confirm _bit3
89 #define AO_BC_TC_Error_Confirm _bit4
90 #define AO_UI2_TC_Error_Confrim _bit5
91 #define AO_UI2_TC_Interrupt_Ack _bit6
92 #define AO_UC_TC_Interrupt_Ack _bit7
93 #define AO_BC_TC_Interrupt_Ack _bit8
94 #define AO_START1_Interrupt_Ack _bit9
95 #define AO_UPDATE_Interrupt_Ack _bit10
96 #define AO_START_Interrupt_Ack _bit11
97 #define AO_STOP_Interrupt_Ack _bit12
98 #define AO_Error_Interrupt_Ack _bit13
99 #define G1_TC_Interrupt_Ack _bit14
100 #define G1_Gate_Interrupt_Ack _bit15
101 
102 #define AO_Status_1_Register 3
103 #define Interrupt_B_St _bit15
104 #define AO_FIFO_Full_St _bit14
105 #define AO_FIFO_Half_Full_St _bit13
106 #define AO_FIFO_Empty_St _bit12
107 #define AO_BC_TC_Error_St _bit11
108 #define AO_START_St _bit10
109 #define AO_Overrun_St _bit9
110 #define AO_START1_St _bit8
111 #define AO_BC_TC_St _bit7
112 #define AO_UC_TC_St _bit6
113 #define AO_UPDATE_St _bit5
114 #define AO_UI2_TC_St _bit4
115 #define G1_TC_St _bit3
116 #define G1_Gate_Interrupt_St _bit2
117 #define AO_FIFO_Request_St _bit1
118 #define Pass_Thru_1_Interrupt_St _bit0
119 
120 
121 #define AI_Command_2_Register 4
122 #define AI_End_On_SC_TC _bit15
123 #define AI_End_On_End_Of_Scan _bit14
124 #define AI_START1_Disable _bit11
125 #define AI_SC_Save_Trace _bit10
126 #define AI_SI_Switch_Load_On_SC_TC _bit9
127 #define AI_SI_Switch_Load_On_STOP _bit8
128 #define AI_SI_Switch_Load_On_TC _bit7
129 #define AI_SC_Switch_Load_On_TC _bit4
130 #define AI_STOP_Pulse _bit3
131 #define AI_START_Pulse _bit2
132 #define AI_START2_Pulse _bit1
133 #define AI_START1_Pulse _bit0
134 
135 #define AO_Command_2_Register 5
136 #define AO_End_On_BC_TC(x) (((x) & 0x3) << 14)
137 #define AO_Start_Stop_Gate_Enable _bit13
138 #define AO_UC_Save_Trace _bit12
139 #define AO_BC_Gate_Enable _bit11
140 #define AO_BC_Save_Trace _bit10
141 #define AO_UI_Switch_Load_On_BC_TC _bit9
142 #define AO_UI_Switch_Load_On_Stop _bit8
143 #define AO_UI_Switch_Load_On_TC _bit7
144 #define AO_UC_Switch_Load_On_BC_TC _bit6
145 #define AO_UC_Switch_Load_On_TC _bit5
146 #define AO_BC_Switch_Load_On_TC _bit4
147 #define AO_Mute_B _bit3
148 #define AO_Mute_A _bit2
149 #define AO_UPDATE2_Pulse _bit1
150 #define AO_START1_Pulse _bit0
151 
152 #define AO_Status_2_Register 6
153 
154 #define DIO_Parallel_Input_Register 7
155 
156 #define AI_Command_1_Register 8
157 #define AI_Analog_Trigger_Reset _bit14
158 #define AI_Disarm _bit13
159 #define AI_SI2_Arm _bit12
160 #define AI_SI2_Load _bit11
161 #define AI_SI_Arm _bit10
162 #define AI_SI_Load _bit9
163 #define AI_DIV_Arm _bit8
164 #define AI_DIV_Load _bit7
165 #define AI_SC_Arm _bit6
166 #define AI_SC_Load _bit5
167 #define AI_SCAN_IN_PROG_Pulse _bit4
168 #define AI_EXTMUX_CLK_Pulse _bit3
169 #define AI_LOCALMUX_CLK_Pulse _bit2
170 #define AI_SC_TC_Pulse _bit1
171 #define AI_CONVERT_Pulse _bit0
172 
173 #define AO_Command_1_Register 9
174 #define AO_Analog_Trigger_Reset _bit15
175 #define AO_START_Pulse _bit14
176 #define AO_Disarm _bit13
177 #define AO_UI2_Arm_Disarm _bit12
178 #define AO_UI2_Load _bit11
179 #define AO_UI_Arm _bit10
180 #define AO_UI_Load _bit9
181 #define AO_UC_Arm _bit8
182 #define AO_UC_Load _bit7
183 #define AO_BC_Arm _bit6
184 #define AO_BC_Load _bit5
185 #define AO_DAC1_Update_Mode _bit4
186 #define AO_LDAC1_Source_Select _bit3
187 #define AO_DAC0_Update_Mode _bit2
188 #define AO_LDAC0_Source_Select _bit1
189 #define AO_UPDATE_Pulse _bit0
190 
191 
192 #define DIO_Output_Register 10
193 #define DIO_Parallel_Data_Out(a) ((a)&0xff)
194 #define DIO_Parallel_Data_Mask 0xff
195 #define DIO_SDOUT _bit0
196 #define DIO_SDIN _bit4
197 #define DIO_Serial_Data_Out(a) (((a)&0xff)<<8)
198 #define DIO_Serial_Data_Mask 0xff00
199 
200 #define DIO_Control_Register 11
201 #define DIO_Software_Serial_Control _bit11
202 #define DIO_HW_Serial_Timebase _bit10
203 #define DIO_HW_Serial_Enable _bit9
204 #define DIO_HW_Serial_Start _bit8
205 #define DIO_Pins_Dir(a) ((a)&0xff)
206 #define DIO_Pins_Dir_Mask 0xff
207 
208 #define AI_Mode_1_Register 12
209 #define AI_CONVERT_Source_Select(a) (((a) & 0x1f) << 11)
210 #define AI_SI_Source_select(a) (((a) & 0x1f) << 6)
211 #define AI_CONVERT_Source_Polarity _bit5
212 #define AI_SI_Source_Polarity _bit4
213 #define AI_Start_Stop _bit3
214 #define AI_Mode_1_Reserved _bit2
215 #define AI_Continuous _bit1
216 #define AI_Trigger_Once _bit0
217 
218 #define AI_Mode_2_Register 13
219 #define AI_SC_Gate_Enable _bit15
220 #define AI_Start_Stop_Gate_Enable _bit14
221 #define AI_Pre_Trigger _bit13
222 #define AI_External_MUX_Present _bit12
223 #define AI_SI2_Initial_Load_Source _bit9
224 #define AI_SI2_Reload_Mode _bit8
225 #define AI_SI_Initial_Load_Source _bit7
226 #define AI_SI_Reload_Mode(a) (((a) & 0x7)<<4)
227 #define AI_SI_Write_Switch _bit3
228 #define AI_SC_Initial_Load_Source _bit2
229 #define AI_SC_Reload_Mode _bit1
230 #define AI_SC_Write_Switch _bit0
231 
232 #define AI_SI_Load_A_Registers 14
233 #define AI_SI_Load_B_Registers 16
234 #define AI_SC_Load_A_Registers 18
235 #define AI_SC_Load_B_Registers 20
236 #define AI_SI_Save_Registers 64
237 #define AI_SC_Save_Registers 66
238 
239 #define AI_SI2_Load_A_Register 23
240 #define AI_SI2_Load_B_Register 25
241 
242 #define Joint_Status_1_Register 27
243 #define DIO_Serial_IO_In_Progress_St _bit12
244 
245 #define DIO_Serial_Input_Register 28
246 #define Joint_Status_2_Register 29
247 #define AO_TMRDACWRs_In_Progress_St _bit5
248 
249 #define AO_Mode_1_Register 38
250 #define AO_UPDATE_Source_Select(x) (((x)&0x1f)<<11)
251 #define AO_UI_Source_Select(x) (((x)&0x1f)<<6)
252 #define AO_Multiple_Channels _bit5
253 #define AO_UPDATE_Source_Polarity _bit4
254 #define AO_UI_Source_Polarity _bit3
255 #define AO_UC_Switch_Load_Every_TC _bit2
256 #define AO_Continuous _bit1
257 #define AO_Trigger_Once _bit0
258 
259 #define AO_Mode_2_Register 39
260 #define AO_FIFO_Mode_Mask ( 0x3 << 14 )
261 #define AO_FIFO_Mode_HF_to_F (3<<14)
262 #define AO_FIFO_Mode_F (2<<14)
263 #define AO_FIFO_Mode_HF (1<<14)
264 #define AO_FIFO_Mode_E (0<<14)
265 #define AO_FIFO_Retransmit_Enable _bit13
266 #define AO_START1_Disable _bit12
267 #define AO_UC_Initial_Load_Source _bit11
268 #define AO_UC_Write_Switch _bit10
269 #define AO_UI2_Initial_Load_Source _bit9
270 #define AO_UI2_Reload_Mode _bit8
271 #define AO_UI_Initial_Load_Source _bit7
272 #define AO_UI_Reload_Mode(x) (((x) & 0x7) << 4)
273 #define AO_UI_Write_Switch _bit3
274 #define AO_BC_Initial_Load_Source _bit2
275 #define AO_BC_Reload_Mode _bit1
276 #define AO_BC_Write_Switch _bit0
277 
278 #define AO_UI_Load_A_Register 40
279 #define AO_UI_Load_A_Register_High 40
280 #define AO_UI_Load_A_Register_Low 41
281 #define AO_UI_Load_B_Register 42
282 #define AO_UI_Save_Registers 16
283 #define AO_BC_Load_A_Register 44
284 #define AO_BC_Load_A_Register_High 44
285 #define AO_BC_Load_A_Register_Low 45
286 #define AO_BC_Load_B_Register 46
287 #define AO_BC_Load_B_Register_High 46
288 #define AO_BC_Load_B_Register_Low 47
289 #define AO_BC_Save_Registers 18
290 #define AO_UC_Load_A_Register 48
291 #define AO_UC_Load_A_Register_High 48
292 #define AO_UC_Load_A_Register_Low 49
293 #define AO_UC_Load_B_Register 50
294 #define AO_UC_Save_Registers 20
295 
296 #define Clock_and_FOUT_Register 56
297 #define FOUT_Enable _bit15
298 #define FOUT_Timebase_Select _bit14
299 #define DIO_Serial_Out_Divide_By_2 _bit13
300 #define Slow_Internal_Time_Divide_By_2 _bit12
301 #define Slow_Internal_Timebase _bit11
302 #define G_Source_Divide_By_2 _bit10
303 #define Clock_To_Board_Divide_By_2 _bit9
304 #define Clock_To_Board _bit8
305 #define AI_Output_Divide_By_2 _bit7
306 #define AI_Source_Divide_By_2 _bit6
307 #define AO_Output_Divide_By_2 _bit5
308 #define AO_Source_Divide_By_2 _bit4
309 #define FOUT_Divider_mask 0xf
310 #define FOUT_Divider(x) (((x) & 0xf) << 0)
311 
312 #define IO_Bidirection_Pin_Register 57
313 #define RTSI_Trig_Direction_Register 58
314 #define Drive_RTSI_Clock_Bit 0x1
315 #define Use_RTSI_Clock_Bit 0x2
316 
317 static inline unsigned int RTSI_Output_Bit(unsigned channel, int is_mseries)
318 {
319  unsigned max_channel;
320  unsigned base_bit_shift;
321  if(is_mseries)
322  {
323  base_bit_shift = 8;
324  max_channel = 7;
325  }else
326  {
327  base_bit_shift = 9;
328  max_channel = 6;
329  }
330  if(channel > max_channel)
331  {
332  rtdm_printk("%s: bug, invalid RTSI_channel=%i\n",
333  __FUNCTION__, channel);
334  return 0;
335  }
336  return 1 << (base_bit_shift + channel);
337 }
338 
339 #define Interrupt_Control_Register 59
340 #define Interrupt_B_Enable _bit15
341 #define Interrupt_B_Output_Select(x) ((x)<<12)
342 #define Interrupt_A_Enable _bit11
343 #define Interrupt_A_Output_Select(x) ((x)<<8)
344 #define Pass_Thru_0_Interrupt_Polarity _bit3
345 #define Pass_Thru_1_Interrupt_Polarity _bit2
346 #define Interrupt_Output_On_3_Pins _bit1
347 #define Interrupt_Output_Polarity _bit0
348 
349 #define AI_Output_Control_Register 60
350 #define AI_START_Output_Select _bit10
351 #define AI_SCAN_IN_PROG_Output_Select(x) (((x) & 0x3) << 8)
352 #define AI_EXTMUX_CLK_Output_Select(x) (((x) & 0x3) << 6)
353 #define AI_LOCALMUX_CLK_Output_Select(x) ((x)<<4)
354 #define AI_SC_TC_Output_Select(x) ((x)<<2)
355 #define AI_CONVERT_Output_High_Z 0
356 #define AI_CONVERT_Output_Ground 1
357 #define AI_CONVERT_Output_Enable_Low 2
358 #define AI_CONVERT_Output_Enable_High 3
359 #define AI_CONVERT_Output_Select(x) ((x) & 0x3)
360 
361 #define AI_START_STOP_Select_Register 62
362 #define AI_START_Polarity _bit15
363 #define AI_STOP_Polarity _bit14
364 #define AI_STOP_Sync _bit13
365 #define AI_STOP_Edge _bit12
366 #define AI_STOP_Select(a) (((a) & 0x1f)<<7)
367 #define AI_START_Sync _bit6
368 #define AI_START_Edge _bit5
369 #define AI_START_Select(a) ((a) & 0x1f)
370 
371 #define AI_Trigger_Select_Register 63
372 #define AI_START1_Polarity _bit15
373 #define AI_START2_Polarity _bit14
374 #define AI_START2_Sync _bit13
375 #define AI_START2_Edge _bit12
376 #define AI_START2_Select(a) (((a) & 0x1f) << 7)
377 #define AI_START1_Sync _bit6
378 #define AI_START1_Edge _bit5
379 #define AI_START1_Select(a) ((a) & 0x1f)
380 
381 #define AI_DIV_Load_A_Register 64
382 
383 #define AO_Start_Select_Register 66
384 #define AO_UI2_Software_Gate _bit15
385 #define AO_UI2_External_Gate_Polarity _bit14
386 #define AO_START_Polarity _bit13
387 #define AO_AOFREQ_Enable _bit12
388 #define AO_UI2_External_Gate_Select(a) (((a) & 0x1f) << 7)
389 #define AO_START_Sync _bit6
390 #define AO_START_Edge _bit5
391 #define AO_START_Select(a) ((a) & 0x1f)
392 
393 #define AO_Trigger_Select_Register 67
394 #define AO_UI2_External_Gate_Enable _bit15
395 #define AO_Delayed_START1 _bit14
396 #define AO_START1_Polarity _bit13
397 #define AO_UI2_Source_Polarity _bit12
398 #define AO_UI2_Source_Select(x) (((x)&0x1f)<<7)
399 #define AO_START1_Sync _bit6
400 #define AO_START1_Edge _bit5
401 #define AO_START1_Select(x) (((x)&0x1f)<<0)
402 
403 #define AO_Mode_3_Register 70
404 #define AO_UI2_Switch_Load_Next_TC _bit13
405 #define AO_UC_Switch_Load_Every_BC_TC _bit12
406 #define AO_Trigger_Length _bit11
407 #define AO_Stop_On_Overrun_Error _bit5
408 #define AO_Stop_On_BC_TC_Trigger_Error _bit4
409 #define AO_Stop_On_BC_TC_Error _bit3
410 #define AO_Not_An_UPDATE _bit2
411 #define AO_Software_Gate _bit1
412 #define AO_Last_Gate_Disable _bit0 /* M Series only */
413 
414 #define Joint_Reset_Register 72
415 #define Software_Reset _bit11
416 #define AO_Configuration_End _bit9
417 #define AI_Configuration_End _bit8
418 #define AO_Configuration_Start _bit5
419 #define AI_Configuration_Start _bit4
420 #define G1_Reset _bit3
421 #define G0_Reset _bit2
422 #define AO_Reset _bit1
423 #define AI_Reset _bit0
424 
425 #define Interrupt_A_Enable_Register 73
426 #define Pass_Thru_0_Interrupt_Enable _bit9
427 #define G0_Gate_Interrupt_Enable _bit8
428 #define AI_FIFO_Interrupt_Enable _bit7
429 #define G0_TC_Interrupt_Enable _bit6
430 #define AI_Error_Interrupt_Enable _bit5
431 #define AI_STOP_Interrupt_Enable _bit4
432 #define AI_START_Interrupt_Enable _bit3
433 #define AI_START2_Interrupt_Enable _bit2
434 #define AI_START1_Interrupt_Enable _bit1
435 #define AI_SC_TC_Interrupt_Enable _bit0
436 
437 #define Interrupt_B_Enable_Register 75
438 #define Pass_Thru_1_Interrupt_Enable _bit11
439 #define G1_Gate_Interrupt_Enable _bit10
440 #define G1_TC_Interrupt_Enable _bit9
441 #define AO_FIFO_Interrupt_Enable _bit8
442 #define AO_UI2_TC_Interrupt_Enable _bit7
443 #define AO_UC_TC_Interrupt_Enable _bit6
444 #define AO_Error_Interrupt_Enable _bit5
445 #define AO_STOP_Interrupt_Enable _bit4
446 #define AO_START_Interrupt_Enable _bit3
447 #define AO_UPDATE_Interrupt_Enable _bit2
448 #define AO_START1_Interrupt_Enable _bit1
449 #define AO_BC_TC_Interrupt_Enable _bit0
450 
451 #define Second_IRQ_A_Enable_Register 74
452 #define AI_SC_TC_Second_Irq_Enable _bit0
453 #define AI_START1_Second_Irq_Enable _bit1
454 #define AI_START2_Second_Irq_Enable _bit2
455 #define AI_START_Second_Irq_Enable _bit3
456 #define AI_STOP_Second_Irq_Enable _bit4
457 #define AI_Error_Second_Irq_Enable _bit5
458 #define G0_TC_Second_Irq_Enable _bit6
459 #define AI_FIFO_Second_Irq_Enable _bit7
460 #define G0_Gate_Second_Irq_Enable _bit8
461 #define Pass_Thru_0_Second_Irq_Enable _bit9
462 
463 #define Second_IRQ_B_Enable_Register 76
464 #define AO_BC_TC_Second_Irq_Enable _bit0
465 #define AO_START1_Second_Irq_Enable _bit1
466 #define AO_UPDATE_Second_Irq_Enable _bit2
467 #define AO_START_Second_Irq_Enable _bit3
468 #define AO_STOP_Second_Irq_Enable _bit4
469 #define AO_Error_Second_Irq_Enable _bit5
470 #define AO_UC_TC_Second_Irq_Enable _bit6
471 #define AO_UI2_TC_Second_Irq_Enable _bit7
472 #define AO_FIFO_Second_Irq_Enable _bit8
473 #define G1_TC_Second_Irq_Enable _bit9
474 #define G1_Gate_Second_Irq_Enable _bit10
475 #define Pass_Thru_1_Second_Irq_Enable _bit11
476 
477 #define AI_Personal_Register 77
478 #define AI_SHIFTIN_Pulse_Width _bit15
479 #define AI_EOC_Polarity _bit14
480 #define AI_SOC_Polarity _bit13
481 #define AI_SHIFTIN_Polarity _bit12
482 #define AI_CONVERT_Pulse_Timebase _bit11
483 #define AI_CONVERT_Pulse_Width _bit10
484 #define AI_CONVERT_Original_Pulse _bit9
485 #define AI_FIFO_Flags_Polarity _bit8
486 #define AI_Overrun_Mode _bit7
487 #define AI_EXTMUX_CLK_Pulse_Width _bit6
488 #define AI_LOCALMUX_CLK_Pulse_Width _bit5
489 #define AI_AIFREQ_Polarity _bit4
490 
491 #define AO_Personal_Register 78
492 #define AO_Interval_Buffer_Mode _bit3
493 #define AO_BC_Source_Select _bit4
494 #define AO_UPDATE_Pulse_Width _bit5
495 #define AO_UPDATE_Pulse_Timebase _bit6
496 #define AO_UPDATE_Original_Pulse _bit7
497 #define AO_DMA_PIO_Control _bit8 /* M Series: reserved */
498 #define AO_AOFREQ_Polarity _bit9 /* M Series: reserved */
499 #define AO_FIFO_Enable _bit10
500 #define AO_FIFO_Flags_Polarity _bit11 /* M Series: reserved */
501 #define AO_TMRDACWR_Pulse_Width _bit12
502 #define AO_Fast_CPU _bit13 /* M Series: reserved */
503 #define AO_Number_Of_DAC_Packages _bit14 /* 1 for "single" mode,
504  0 for "dual" */
505 #define AO_Multiple_DACS_Per_Package _bit15 /* M Series only */
506 
507 #define RTSI_Trig_A_Output_Register 79
508 
509 #define RTSI_Trig_B_Output_Register 80
510 #define RTSI_Sub_Selection_1_Bit _bit15 /* not for M Series */
511 #define RTSI_Trig_Output_Bits(x, y) ((y & 0xf) << ((x % 4) * 4))
512 #define RTSI_Trig_Output_Mask(x) (0xf << ((x % 4) * 4))
513 #define RTSI_Trig_Output_Source(x, y) ((y >> ((x % 4) * 4)) & 0xf)
514 
515 #define RTSI_Board_Register 81
516 #define Write_Strobe_0_Register 82
517 #define Write_Strobe_1_Register 83
518 #define Write_Strobe_2_Register 84
519 #define Write_Strobe_3_Register 85
520 
521 #define AO_Output_Control_Register 86
522 #define AO_External_Gate_Enable _bit15
523 #define AO_External_Gate_Select(x) (((x)&0x1f)<<10)
524 #define AO_Number_Of_Channels(x) (((x)&0xf)<<6)
525 #define AO_UPDATE2_Output_Select(x) (((x)&0x3)<<4)
526 #define AO_External_Gate_Polarity _bit3
527 #define AO_UPDATE2_Output_Toggle _bit2
528 #define AO_Update_Output_High_Z 0
529 #define AO_Update_Output_Ground 1
530 #define AO_Update_Output_Enable_Low 2
531 #define AO_Update_Output_Enable_High 3
532 #define AO_UPDATE_Output_Select(x) (x&0x3)
533 
534 #define AI_Mode_3_Register 87
535 #define AI_Trigger_Length _bit15
536 #define AI_Delay_START _bit14
537 #define AI_Software_Gate _bit13
538 #define AI_SI_Special_Trigger_Delay _bit12
539 #define AI_SI2_Source_Select _bit11
540 #define AI_Delayed_START2 _bit10
541 #define AI_Delayed_START1 _bit9
542 #define AI_External_Gate_Mode _bit8
543 #define AI_FIFO_Mode_HF_to_E (3<<6)
544 #define AI_FIFO_Mode_F (2<<6)
545 #define AI_FIFO_Mode_HF (1<<6)
546 #define AI_FIFO_Mode_NE (0<<6)
547 #define AI_External_Gate_Polarity _bit5
548 #define AI_External_Gate_Select(a) ((a) & 0x1f)
549 
550 #define G_Autoincrement_Register(a) (68+(a))
551 #define G_Command_Register(a) (6+(a))
552 #define G_HW_Save_Register(a) (8+(a)*2)
553 #define G_HW_Save_Register_High(a) (8+(a)*2)
554 #define G_HW_Save_Register_Low(a) (9+(a)*2)
555 #define G_Input_Select_Register(a) (36+(a))
556 #define G_Load_A_Register(a) (28+(a)*4)
557 #define G_Load_A_Register_High(a) (28+(a)*4)
558 #define G_Load_A_Register_Low(a) (29+(a)*4)
559 #define G_Load_B_Register(a) (30+(a)*4)
560 #define G_Load_B_Register_High(a) (30+(a)*4)
561 #define G_Load_B_Register_Low(a) (31+(a)*4)
562 #define G_Mode_Register(a) (26+(a))
563 #define G_Save_Register(a) (12+(a)*2)
564 #define G_Save_Register_High(a) (12+(a)*2)
565 #define G_Save_Register_Low(a) (13+(a)*2)
566 #define G_Status_Register 4
567 #define Analog_Trigger_Etc_Register 61
568 
569 /* command register */
570 #define G_Disarm_Copy _bit15 /* strobe */
571 #define G_Save_Trace_Copy _bit14
572 #define G_Arm_Copy _bit13 /* strobe */
573 #define G_Bank_Switch_Start _bit10 /* strobe */
574 #define G_Little_Big_Endian _bit9
575 #define G_Synchronized_Gate _bit8
576 #define G_Write_Switch _bit7
577 #define G_Up_Down(a) (((a)&0x03)<<5)
578 #define G_Disarm _bit4 /* strobe */
579 #define G_Analog_Trigger_Reset _bit3 /* strobe */
580 #define G_Save_Trace _bit1
581 #define G_Arm _bit0 /* strobe */
582 
583 /* channel agnostic names for the command register #defines */
584 #define G_Bank_Switch_Enable _bit12
585 #define G_Bank_Switch_Mode _bit11
586 #define G_Load _bit2 /* strobe */
587 
588 /* input select register */
589 #define G_Gate_Select(a) (((a)&0x1f)<<7)
590 #define G_Source_Select(a) (((a)&0x1f)<<2)
591 #define G_Write_Acknowledges_Irq _bit1
592 #define G_Read_Acknowledges_Irq _bit0
593 
594 /* same input select register, but with channel agnostic names */
595 #define G_Source_Polarity _bit15
596 #define G_Output_Polarity _bit14
597 #define G_OR_Gate _bit13
598 #define G_Gate_Select_Load_Source _bit12
599 
600 /* mode register */
601 #define G_Loading_On_TC _bit12
602 #define G_Output_Mode(a) (((a)&0x03)<<8)
603 #define G_Trigger_Mode_For_Edge_Gate(a) (((a)&0x03)<<3)
604 #define G_Gating_Mode(a) (((a)&0x03)<<0)
605 
606 /* same input mode register, but with channel agnostic names */
607 #define G_Load_Source_Select _bit7
608 #define G_Reload_Source_Switching _bit15
609 #define G_Loading_On_Gate _bit14
610 #define G_Gate_Polarity _bit13
611 
612 #define G_Counting_Once(a) (((a)&0x03)<<10)
613 #define G_Stop_Mode(a) (((a)&0x03)<<5)
614 #define G_Gate_On_Both_Edges _bit2
615 
616 /* G_Status_Register */
617 #define G1_Gate_Error_St _bit15
618 #define G0_Gate_Error_St _bit14
619 #define G1_TC_Error_St _bit13
620 #define G0_TC_Error_St _bit12
621 #define G1_No_Load_Between_Gates_St _bit11
622 #define G0_No_Load_Between_Gates_St _bit10
623 #define G1_Armed_St _bit9
624 #define G0_Armed_St _bit8
625 #define G1_Stale_Data_St _bit7
626 #define G0_Stale_Data_St _bit6
627 #define G1_Next_Load_Source_St _bit5
628 #define G0_Next_Load_Source_St _bit4
629 #define G1_Counting_St _bit3
630 #define G0_Counting_St _bit2
631 #define G1_Save_St _bit1
632 #define G0_Save_St _bit0
633 
634 /* general purpose counter timer */
635 #define G_Autoincrement(a) ((a)<<0)
636 
637 /*Analog_Trigger_Etc_Register*/
638 #define Analog_Trigger_Mode(x) ((x) & 0x7)
639 #define Analog_Trigger_Enable _bit3
640 #define Analog_Trigger_Drive _bit4
641 #define GPFO_1_Output_Select _bit7
642 #define GPFO_0_Output_Select(a) ((a)<<11)
643 #define GPFO_0_Output_Enable _bit14
644 #define GPFO_1_Output_Enable _bit15
645 
646 /* Additional windowed registers unique to E series */
647 
648 /* 16 bit registers shadowed from DAQ-STC */
649 #define Window_Address 0x00
650 #define Window_Data 0x02
651 
652 #define Configuration_Memory_Clear 82
653 #define ADC_FIFO_Clear 83
654 #define DAC_FIFO_Clear 84
655 
656 /* i/o port offsets */
657 
658 /* 8 bit registers */
659 #define XXX_Status 0x01
660 #define PROMOUT _bit0
661 #define AI_FIFO_LOWER_NOT_EMPTY _bit3
662 
663 #define Serial_Command 0x0d
664 #define Misc_Command 0x0f
665 #define Port_A 0x19
666 #define Port_B 0x1b
667 #define Port_C 0x1d
668 #define Configuration 0x1f
669 #define Strobes 0x01
670 #define Channel_A_Mode 0x03
671 #define Channel_B_Mode 0x05
672 #define Channel_C_Mode 0x07
673 #define AI_AO_Select 0x09
674 #define AI_DMA_Select_Shift 0
675 #define AI_DMA_Select_Mask 0xf
676 #define AO_DMA_Select_Shift 4
677 #define AO_DMA_Select_Mask (0xf << AO_DMA_Select_Shift)
678 
679 #define G0_G1_Select 0x0b
680 
681 static inline unsigned ni_stc_dma_channel_select_bitfield(unsigned channel)
682 {
683  if(channel < 4) return 1 << channel;
684  if(channel == 4) return 0x3;
685  if(channel == 5) return 0x5;
686  BUG();
687  return 0;
688 }
689 static inline unsigned GPCT_DMA_Select_Bits(unsigned gpct_index, unsigned mite_channel)
690 {
691  BUG_ON(gpct_index > 1);
692  return ni_stc_dma_channel_select_bitfield(mite_channel) << (4 * gpct_index);
693 }
694 static inline unsigned GPCT_DMA_Select_Mask(unsigned gpct_index)
695 {
696  BUG_ON(gpct_index > 1);
697  return 0xf << (4 * gpct_index);
698 }
699 
700 /* 16 bit registers */
701 
702 #define Configuration_Memory_Low 0x10
703 #define AI_DITHER _bit9
704 #define AI_LAST_CHANNEL _bit15
705 
706 #define Configuration_Memory_High 0x12
707 #define AI_AC_COUPLE _bit11
708 #define AI_DIFFERENTIAL _bit12
709 #define AI_COMMON _bit13
710 #define AI_GROUND (_bit12|_bit13)
711 #define AI_CONFIG_CHANNEL(x) (x&0x3f)
712 
713 #define ADC_FIFO_Data_Register 0x1c
714 
715 #define AO_Configuration 0x16
716 #define AO_Bipolar _bit0
717 #define AO_Deglitch _bit1
718 #define AO_Ext_Ref _bit2
719 #define AO_Ground_Ref _bit3
720 #define AO_Channel(x) ((x) << 8)
721 
722 #define DAC_FIFO_Data 0x1e
723 #define DAC0_Direct_Data 0x18
724 #define DAC1_Direct_Data 0x1a
725 
726 /* 611x registers (these boards differ from the e-series) */
727 
728 #define Magic_611x 0x19 /* w8 (new) */
729 #define Calibration_Channel_Select_611x 0x1a /* w16 (new) */
730 #define ADC_FIFO_Data_611x 0x1c /* r32 (incompatible) */
731 #define AI_FIFO_Offset_Load_611x 0x05 /* r8 (new) */
732 #define DAC_FIFO_Data_611x 0x14 /* w32 (incompatible) */
733 #define Cal_Gain_Select_611x 0x05 /* w8 (new) */
734 
735 #define AO_Window_Address_611x 0x18
736 #define AO_Window_Data_611x 0x1e
737 
738 /* 6143 registers */
739 #define Magic_6143 0x19 /* w8 */
740 #define G0G1_DMA_Select_6143 0x0B /* w8 */
741 #define PipelineDelay_6143 0x1f /* w8 */
742 #define EOC_Set_6143 0x1D /* w8 */
743 #define AIDMA_Select_6143 0x09 /* w8 */
744 #define AIFIFO_Data_6143 0x8C /* w32 */
745 #define AIFIFO_Flag_6143 0x84 /* w32 */
746 #define AIFIFO_Control_6143 0x88 /* w32 */
747 #define AIFIFO_Status_6143 0x88 /* w32 */
748 #define AIFIFO_DMAThreshold_6143 0x90 /* w32 */
749 #define AIFIFO_Words_Available_6143 0x94 /* w32 */
750 
751 #define Calibration_Channel_6143 0x42 /* w16 */
752 #define Calibration_LowTime_6143 0x20 /* w16 */
753 #define Calibration_HighTime_6143 0x22 /* w16 */
754 #define Relay_Counter_Load_Val__6143 0x4C /* w32 */
755 #define Signature_6143 0x50 /* w32 */
756 #define Release_Date_6143 0x54 /* w32 */
757 #define Release_Oldest_Date_6143 0x58 /* w32 */
758 
759 #define Calibration_Channel_6143_RelayOn 0x8000 /* Calibration relay switch On */
760 #define Calibration_Channel_6143_RelayOff 0x4000 /* Calibration relay switch Off */
761 #define Calibration_Channel_Gnd_Gnd 0x00 /* Offset Calibration */
762 #define Calibration_Channel_2v5_Gnd 0x02 /* 2.5V Reference */
763 #define Calibration_Channel_Pwm_Gnd 0x05 /* +/- 5V Self Cal */
764 #define Calibration_Channel_2v5_Pwm 0x0a /* PWM Calibration */
765 #define Calibration_Channel_Pwm_Pwm 0x0d /* CMRR */
766 #define Calibration_Channel_Gnd_Pwm 0x0e /* PWM Calibration */
767 
768 /* 671x, 611x registers */
769 
770 /* 671xi 611x windowed ao registers */
771 #define AO_Immediate_671x 0x11 /* W 16 */
772 #define AO_Timed_611x 0x10 /* W 16 */
773 #define AO_FIFO_Offset_Load_611x 0x13 /* W32 */
774 #define AO_Later_Single_Point_Updates 0x14 /* W 16 */
775 #define AO_Waveform_Generation_611x 0x15 /* W 16 */
776 #define AO_Misc_611x 0x16 /* W 16 */
777 #define AO_Calibration_Channel_Select_67xx 0x17 /* W 16 */
778 #define AO_Configuration_2_67xx 0x18 /* W 16 */
779 #define CAL_ADC_Command_67xx 0x19 /* W 8 */
780 #define CAL_ADC_Status_67xx 0x1a /* R 8 */
781 #define CAL_ADC_Data_67xx 0x1b /* R 16 */
782 #define CAL_ADC_Config_Data_High_Word_67xx 0x1c /* RW 16 */
783 #define CAL_ADC_Config_Data_Low_Word_67xx 0x1d /* RW 16 */
784 
785 static inline unsigned int DACx_Direct_Data_671x(int channel)
786 {
787  return channel;
788 }
789 
790 #define CLEAR_WG _bit0
791 
792 #define CSCFG_CAL_CONTROL_MASK 0x7
793 #define CSCFG_SELF_CAL_OFFSET 0x1
794 #define CSCFG_SELF_CAL_GAIN 0x2
795 #define CSCFG_SELF_CAL_OFFSET_GAIN 0x3
796 #define CSCFG_SYSTEM_CAL_OFFSET 0x5
797 #define CSCFG_SYSTEM_CAL_GAIN 0x6
798 #define CSCFG_DONE (1 << 3)
799 #define CSCFG_POWER_SAVE_SELECT (1 << 4)
800 #define CSCFG_PORT_MODE (1 << 5)
801 #define CSCFG_RESET_VALID (1 << 6)
802 #define CSCFG_RESET (1 << 7)
803 #define CSCFG_UNIPOLAR (1 << 12)
804 #define CSCFG_WORD_RATE_2180_CYCLES (0x0 << 13)
805 #define CSCFG_WORD_RATE_1092_CYCLES (0x1 << 13)
806 #define CSCFG_WORD_RATE_532_CYCLES (0x2 << 13)
807 #define CSCFG_WORD_RATE_388_CYCLES (0x3 << 13)
808 #define CSCFG_WORD_RATE_324_CYCLES (0x4 << 13)
809 #define CSCFG_WORD_RATE_17444_CYCLES (0x5 << 13)
810 #define CSCFG_WORD_RATE_8724_CYCLES (0x6 << 13)
811 #define CSCFG_WORD_RATE_4364_CYCLES (0x7 << 13)
812 #define CSCFG_WORD_RATE_MASK (0x7 << 13)
813 #define CSCFG_LOW_POWER (1 << 16)
814 
815 #define CS5529_CONFIG_DOUT(x) (1 << (18 + x))
816 #define CS5529_CONFIG_AOUT(x) (1 << (22 + x))
817 
818 /* cs5529 command bits */
819 #define CSCMD_POWER_SAVE _bit0
820 #define CSCMD_REGISTER_SELECT_MASK 0xe
821 #define CSCMD_OFFSET_REGISTER 0x0
822 #define CSCMD_GAIN_REGISTER _bit1
823 #define CSCMD_CONFIG_REGISTER _bit2
824 #define CSCMD_READ _bit4
825 #define CSCMD_CONTINUOUS_CONVERSIONS _bit5
826 #define CSCMD_SINGLE_CONVERSION _bit6
827 #define CSCMD_COMMAND _bit7
828 
829 /* cs5529 status bits */
830 #define CSS_ADC_BUSY _bit0
831 #define CSS_OSC_DETECT _bit1 /* indicates adc error */
832 #define CSS_OVERRANGE _bit3
833 
834 #define SerDacLd(x) (0x08<<(x))
835 
836 /*
837  This is stuff unique to the NI E series drivers,
838  but I thought I'd put it here anyway.
839 */
840 
841 enum
842 {
843  ai_gain_16 = 0,
844  ai_gain_8,
845  ai_gain_14,
846  ai_gain_4,
847  ai_gain_611x,
848  ai_gain_622x,
849  ai_gain_628x,
850  ai_gain_6143
851 };
852 enum caldac_enum
853 {
854  caldac_none=0,
855  mb88341,
856  dac8800,
857  dac8043,
858  ad8522,
859  ad8804,
860  ad8842,
861  ad8804_debug
862 };
863 enum ni_reg_type
864 {
865  ni_reg_normal = 0x0,
866  ni_reg_611x = 0x1,
867  ni_reg_6711 = 0x2,
868  ni_reg_6713 = 0x4,
869  ni_reg_67xx_mask = 0x6,
870  ni_reg_6xxx_mask = 0x7,
871  ni_reg_622x = 0x8,
872  ni_reg_625x = 0x10,
873  ni_reg_628x = 0x18,
874  ni_reg_m_series_mask = 0x18,
875  ni_reg_6143 = 0x20
876 };
877 
878 /* M Series registers offsets */
879 #define M_Offset_CDIO_DMA_Select 0x7 /* write */
880 #define M_Offset_SCXI_Status 0x7 /* read */
881 #define M_Offset_AI_AO_Select 0x9 /* write, same offset as e-series */
882 #define M_Offset_SCXI_Serial_Data_In 0x9 /* read */
883 #define M_Offset_G0_G1_Select 0xb /* write, same offset as e-series */
884 #define M_Offset_Misc_Command 0xf
885 #define M_Offset_SCXI_Serial_Data_Out 0x11
886 #define M_Offset_SCXI_Control 0x13
887 #define M_Offset_SCXI_Output_Enable 0x15
888 #define M_Offset_AI_FIFO_Data 0x1c
889 #define M_Offset_Static_Digital_Output 0x24 /* write */
890 #define M_Offset_Static_Digital_Input 0x24 /* read */
891 #define M_Offset_DIO_Direction 0x28
892 #define M_Offset_Cal_PWM 0x40
893 #define M_Offset_AI_Config_FIFO_Data 0x5e
894 #define M_Offset_Interrupt_C_Enable 0x88 /* write */
895 #define M_Offset_Interrupt_C_Status 0x88 /* read */
896 #define M_Offset_Analog_Trigger_Control 0x8c
897 #define M_Offset_AO_Serial_Interrupt_Enable 0xa0
898 #define M_Offset_AO_Serial_Interrupt_Ack 0xa1 /* write */
899 #define M_Offset_AO_Serial_Interrupt_Status 0xa1 /* read */
900 #define M_Offset_AO_Calibration 0xa3
901 #define M_Offset_AO_FIFO_Data 0xa4
902 #define M_Offset_PFI_Filter 0xb0
903 #define M_Offset_RTSI_Filter 0xb4
904 #define M_Offset_SCXI_Legacy_Compatibility 0xbc
905 #define M_Offset_Interrupt_A_Ack 0x104 /* write */
906 #define M_Offset_AI_Status_1 0x104 /* read */
907 #define M_Offset_Interrupt_B_Ack 0x106 /* write */
908 #define M_Offset_AO_Status_1 0x106 /* read */
909 #define M_Offset_AI_Command_2 0x108 /* write */
910 #define M_Offset_G01_Status 0x108 /* read */
911 #define M_Offset_AO_Command_2 0x10a
912 #define M_Offset_AO_Status_2 0x10c /* read */
913 #define M_Offset_G0_Command 0x10c /* write */
914 #define M_Offset_G1_Command 0x10e /* write */
915 #define M_Offset_G0_HW_Save 0x110
916 #define M_Offset_G0_HW_Save_High 0x110
917 #define M_Offset_AI_Command_1 0x110
918 #define M_Offset_G0_HW_Save_Low 0x112
919 #define M_Offset_AO_Command_1 0x112
920 #define M_Offset_G1_HW_Save 0x114
921 #define M_Offset_G1_HW_Save_High 0x114
922 #define M_Offset_G1_HW_Save_Low 0x116
923 #define M_Offset_AI_Mode_1 0x118
924 #define M_Offset_G0_Save 0x118
925 #define M_Offset_G0_Save_High 0x118
926 #define M_Offset_AI_Mode_2 0x11a
927 #define M_Offset_G0_Save_Low 0x11a
928 #define M_Offset_AI_SI_Load_A 0x11c
929 #define M_Offset_G1_Save 0x11c
930 #define M_Offset_G1_Save_High 0x11c
931 #define M_Offset_G1_Save_Low 0x11e
932 #define M_Offset_AI_SI_Load_B 0x120 /* write */
933 #define M_Offset_AO_UI_Save 0x120 /* read */
934 #define M_Offset_AI_SC_Load_A 0x124 /* write */
935 #define M_Offset_AO_BC_Save 0x124 /* read */
936 #define M_Offset_AI_SC_Load_B 0x128 /* write */
937 #define M_Offset_AO_UC_Save 0x128 /* read */
938 #define M_Offset_AI_SI2_Load_A 0x12c
939 #define M_Offset_AI_SI2_Load_B 0x130
940 #define M_Offset_G0_Mode 0x134
941 #define M_Offset_G1_Mode 0x136 /* write */
942 #define M_Offset_Joint_Status_1 0x136 /* read */
943 #define M_Offset_G0_Load_A 0x138
944 #define M_Offset_Joint_Status_2 0x13a
945 #define M_Offset_G0_Load_B 0x13c
946 #define M_Offset_G1_Load_A 0x140
947 #define M_Offset_G1_Load_B 0x144
948 #define M_Offset_G0_Input_Select 0x148
949 #define M_Offset_G1_Input_Select 0x14a
950 #define M_Offset_AO_Mode_1 0x14c
951 #define M_Offset_AO_Mode_2 0x14e
952 #define M_Offset_AO_UI_Load_A 0x150
953 #define M_Offset_AO_UI_Load_B 0x154
954 #define M_Offset_AO_BC_Load_A 0x158
955 #define M_Offset_AO_BC_Load_B 0x15c
956 #define M_Offset_AO_UC_Load_A 0x160
957 #define M_Offset_AO_UC_Load_B 0x164
958 #define M_Offset_Clock_and_FOUT 0x170
959 #define M_Offset_IO_Bidirection_Pin 0x172
960 #define M_Offset_RTSI_Trig_Direction 0x174
961 #define M_Offset_Interrupt_Control 0x176
962 #define M_Offset_AI_Output_Control 0x178
963 #define M_Offset_Analog_Trigger_Etc 0x17a
964 #define M_Offset_AI_START_STOP_Select 0x17c
965 #define M_Offset_AI_Trigger_Select 0x17e
966 #define M_Offset_AI_SI_Save 0x180 /* read */
967 #define M_Offset_AI_DIV_Load_A 0x180 /* write */
968 #define M_Offset_AI_SC_Save 0x184 /* read */
969 #define M_Offset_AO_Start_Select 0x184 /* write */
970 #define M_Offset_AO_Trigger_Select 0x186
971 #define M_Offset_AO_Mode_3 0x18c
972 #define M_Offset_G0_Autoincrement 0x188
973 #define M_Offset_G1_Autoincrement 0x18a
974 #define M_Offset_Joint_Reset 0x190
975 #define M_Offset_Interrupt_A_Enable 0x192
976 #define M_Offset_Interrupt_B_Enable 0x196
977 #define M_Offset_AI_Personal 0x19a
978 #define M_Offset_AO_Personal 0x19c
979 #define M_Offset_RTSI_Trig_A_Output 0x19e
980 #define M_Offset_RTSI_Trig_B_Output 0x1a0
981 #define M_Offset_RTSI_Shared_MUX 0x1a2
982 #define M_Offset_AO_Output_Control 0x1ac
983 #define M_Offset_AI_Mode_3 0x1ae
984 #define M_Offset_Configuration_Memory_Clear 0x1a4
985 #define M_Offset_AI_FIFO_Clear 0x1a6
986 #define M_Offset_AO_FIFO_Clear 0x1a8
987 #define M_Offset_G0_Counting_Mode 0x1b0
988 #define M_Offset_G1_Counting_Mode 0x1b2
989 #define M_Offset_G0_Second_Gate 0x1b4
990 #define M_Offset_G1_Second_Gate 0x1b6
991 #define M_Offset_G0_DMA_Config 0x1b8 /* write */
992 #define M_Offset_G0_DMA_Status 0x1b8 /* read */
993 #define M_Offset_G1_DMA_Config 0x1ba /* write */
994 #define M_Offset_G1_DMA_Status 0x1ba /* read */
995 #define M_Offset_G0_MSeries_ABZ 0x1c0
996 #define M_Offset_G1_MSeries_ABZ 0x1c2
997 #define M_Offset_Clock_and_Fout2 0x1c4
998 #define M_Offset_PLL_Control 0x1c6
999 #define M_Offset_PLL_Status 0x1c8
1000 #define M_Offset_PFI_Output_Select_1 0x1d0
1001 #define M_Offset_PFI_Output_Select_2 0x1d2
1002 #define M_Offset_PFI_Output_Select_3 0x1d4
1003 #define M_Offset_PFI_Output_Select_4 0x1d6
1004 #define M_Offset_PFI_Output_Select_5 0x1d8
1005 #define M_Offset_PFI_Output_Select_6 0x1da
1006 #define M_Offset_PFI_DI 0x1dc
1007 #define M_Offset_PFI_DO 0x1de
1008 #define M_Offset_AI_Config_FIFO_Bypass 0x218
1009 #define M_Offset_SCXI_DIO_Enable 0x21c
1010 #define M_Offset_CDI_FIFO_Data 0x220 /* read */
1011 #define M_Offset_CDO_FIFO_Data 0x220 /* write */
1012 #define M_Offset_CDIO_Status 0x224 /* read */
1013 #define M_Offset_CDIO_Command 0x224 /* write */
1014 #define M_Offset_CDI_Mode 0x228
1015 #define M_Offset_CDO_Mode 0x22c
1016 #define M_Offset_CDI_Mask_Enable 0x230
1017 #define M_Offset_CDO_Mask_Enable 0x234
1018 #define M_Offset_AO_Waveform_Order(x) (0xc2 + 0x4 * x)
1019 #define M_Offset_AO_Config_Bank(x) (0xc3 + 0x4 * x)
1020 #define M_Offset_DAC_Direct_Data(x) (0xc0 + 0x4 * x)
1021 #define M_Offset_Gen_PWM(x) (0x44 + 0x2 * x)
1022 
1023 static inline int M_Offset_Static_AI_Control(int i)
1024 {
1025  int offset[] =
1026  {
1027  0x64,
1028  0x261,
1029  0x262,
1030  0x263,
1031  };
1032  if(((unsigned)i) >= sizeof(offset) / sizeof(offset[0]))
1033  {
1034  rtdm_printk("%s: invalid channel=%i\n", __FUNCTION__, i);
1035  return offset[0];
1036  }
1037  return offset[i];
1038 };
1039 static inline int M_Offset_AO_Reference_Attenuation(int channel)
1040 {
1041  int offset[] =
1042  {
1043  0x264,
1044  0x265,
1045  0x266,
1046  0x267
1047  };
1048  if(((unsigned)channel) >= sizeof(offset) / sizeof(offset[0]))
1049  {
1050  rtdm_printk("%s: invalid channel=%i\n", __FUNCTION__, channel);
1051  return offset[0];
1052  }
1053  return offset[channel];
1054 };
1055 static inline unsigned M_Offset_PFI_Output_Select(unsigned n)
1056 {
1057  if(n < 1 || n > NUM_PFI_OUTPUT_SELECT_REGS)
1058  {
1059  rtdm_printk("%s: invalid pfi output select register=%i\n", __FUNCTION__, n);
1060  return M_Offset_PFI_Output_Select_1;
1061  }
1062  return M_Offset_PFI_Output_Select_1 + (n - 1) * 2;
1063 }
1064 
1065 #define MSeries_AI_Config_Channel_Type_Mask (0x7 << 6)
1066 #define MSeries_AI_Config_Channel_Type_Calibration_Bits 0x0
1067 #define MSeries_AI_Config_Channel_Type_Differential_Bits (0x1 << 6)
1068 #define MSeries_AI_Config_Channel_Type_Common_Ref_Bits (0x2 << 6)
1069 #define MSeries_AI_Config_Channel_Type_Ground_Ref_Bits (0x3 << 6)
1070 #define MSeries_AI_Config_Channel_Type_Aux_Bits (0x5 << 6)
1071 #define MSeries_AI_Config_Channel_Type_Ghost_Bits (0x7 << 6)
1072 #define MSeries_AI_Config_Polarity_Bit 0x1000 /* 0 for 2's complement encoding */
1073 #define MSeries_AI_Config_Dither_Bit 0x2000
1074 #define MSeries_AI_Config_Last_Channel_Bit 0x4000
1075 #define MSeries_AI_Config_Channel_Bits(x) (x & 0xf)
1076 #define MSeries_AI_Config_Gain_Bits(x) ((x & 0x7) << 9)
1077 
1078 static inline
1079 unsigned int MSeries_AI_Config_Bank_Bits(unsigned int reg_type,
1080  unsigned int channel)
1081 {
1082  unsigned int bits = channel & 0x30;
1083  if (reg_type == ni_reg_622x) {
1084  if (channel & 0x40)
1085  bits |= 0x400;
1086  }
1087  return bits;
1088 }
1089 
1090 #define MSeries_PLL_In_Source_Select_RTSI0_Bits 0xb
1091 #define MSeries_PLL_In_Source_Select_Star_Trigger_Bits 0x14
1092 #define MSeries_PLL_In_Source_Select_RTSI7_Bits 0x1b
1093 #define MSeries_PLL_In_Source_Select_PXI_Clock10 0x1d
1094 #define MSeries_PLL_In_Source_Select_Mask 0x1f
1095 #define MSeries_Timebase1_Select_Bit 0x20 /* use PLL for timebase 1 */
1096 #define MSeries_Timebase3_Select_Bit 0x40 /* use PLL for timebase 3 */
1097 /* Use 10MHz instead of 20MHz for RTSI clock frequency. Appears
1098  to have no effect, at least on pxi-6281, which always uses
1099  20MHz rtsi clock frequency */
1100 #define MSeries_RTSI_10MHz_Bit 0x80
1101 
1102 static inline
1103 unsigned int MSeries_PLL_In_Source_Select_RTSI_Bits(unsigned int RTSI_channel)
1104 {
1105  if(RTSI_channel > 7)
1106  {
1107  rtdm_printk("%s: bug, invalid RTSI_channel=%i\n", __FUNCTION__, RTSI_channel);
1108  return 0;
1109  }
1110  if(RTSI_channel == 7) return MSeries_PLL_In_Source_Select_RTSI7_Bits;
1111  else return MSeries_PLL_In_Source_Select_RTSI0_Bits + RTSI_channel;
1112 }
1113 
1114 #define MSeries_PLL_Enable_Bit 0x1000
1115 #define MSeries_PLL_VCO_Mode_200_325MHz_Bits 0x0
1116 #define MSeries_PLL_VCO_Mode_175_225MHz_Bits 0x2000
1117 #define MSeries_PLL_VCO_Mode_100_225MHz_Bits 0x4000
1118 #define MSeries_PLL_VCO_Mode_75_150MHz_Bits 0x6000
1119 
1120 static inline
1121 unsigned int MSeries_PLL_Divisor_Bits(unsigned int divisor)
1122 {
1123  static const unsigned int max_divisor = 0x10;
1124  if(divisor < 1 || divisor > max_divisor)
1125  {
1126  rtdm_printk("%s: bug, invalid divisor=%i\n", __FUNCTION__, divisor);
1127  return 0;
1128  }
1129  return (divisor & 0xf) << 8;
1130 }
1131 static inline
1132 unsigned int MSeries_PLL_Multiplier_Bits(unsigned int multiplier)
1133 {
1134  static const unsigned int max_multiplier = 0x100;
1135  if(multiplier < 1 || multiplier > max_multiplier)
1136  {
1137  rtdm_printk("%s: bug, invalid multiplier=%i\n", __FUNCTION__, multiplier);
1138  return 0;
1139  }
1140  return multiplier & 0xff;
1141 }
1142 
1143 #define MSeries_PLL_Locked_Bit 0x1
1144 
1145 #define MSeries_AI_Bypass_Channel_Mask 0x7
1146 #define MSeries_AI_Bypass_Bank_Mask 0x78
1147 #define MSeries_AI_Bypass_Cal_Sel_Pos_Mask 0x380
1148 #define MSeries_AI_Bypass_Cal_Sel_Neg_Mask 0x1c00
1149 #define MSeries_AI_Bypass_Mode_Mux_Mask 0x6000
1150 #define MSeries_AO_Bypass_AO_Cal_Sel_Mask 0x38000
1151 #define MSeries_AI_Bypass_Gain_Mask 0x1c0000
1152 #define MSeries_AI_Bypass_Dither_Bit 0x200000
1153 #define MSeries_AI_Bypass_Polarity_Bit 0x400000 /* 0 for 2's complement encoding */
1154 #define MSeries_AI_Bypass_Config_FIFO_Bit 0x80000000
1155 #define MSeries_AI_Bypass_Cal_Sel_Pos_Bits(x) ((x << 7) & \
1156  MSeries_AI_Bypass_Cal_Sel_Pos_Mask)
1157 #define MSeries_AI_Bypass_Cal_Sel_Neg_Bits(x) ((x << 10) & \
1158  MSeries_AI_Bypass_Cal_Sel_Pos_Mask)
1159 #define MSeries_AI_Bypass_Gain_Bits(x) ((x << 18) & \
1160  MSeries_AI_Bypass_Gain_Mask)
1161 
1162 #define MSeries_AO_DAC_Offset_Select_Mask 0x7
1163 #define MSeries_AO_DAC_Offset_0V_Bits 0x0
1164 #define MSeries_AO_DAC_Offset_5V_Bits 0x1
1165 #define MSeries_AO_DAC_Reference_Mask 0x38
1166 #define MSeries_AO_DAC_Reference_10V_Internal_Bits 0x0
1167 #define MSeries_AO_DAC_Reference_5V_Internal_Bits 0x8
1168 #define MSeries_AO_Update_Timed_Bit 0x40
1169 #define MSeries_AO_Bipolar_Bit 0x80 /* turns on 2's complement encoding */
1170 
1171 #define MSeries_Attenuate_x5_Bit 0x1
1172 
1173 #define MSeries_Cal_PWM_High_Time_Bits(x) ((x << 16) & 0xffff0000)
1174 #define MSeries_Cal_PWM_Low_Time_Bits(x) (x & 0xffff)
1175 
1176 #define MSeries_PFI_Output_Select_Mask(x) (0x1f << (x % 3) * 5)
1177 #define MSeries_PFI_Output_Select_Bits(x, y) ((y & 0x1f) << ((x % 3) * 5))
1178 // inverse to MSeries_PFI_Output_Select_Bits
1179 #define MSeries_PFI_Output_Select_Source(x, y) ((y >> ((x % 3) * 5)) & 0x1f)
1180 
1181 #define Gi_DMA_BankSW_Error_Bit 0x10
1182 #define Gi_DMA_Reset_Bit 0x8
1183 #define Gi_DMA_Int_Enable_Bit 0x4
1184 #define Gi_DMA_Write_Bit 0x2
1185 #define Gi_DMA_Enable_Bit 0x1
1186 
1187 #define MSeries_PFI_Filter_Select_Mask(x) (0x3 << (x * 2))
1188 #define MSeries_PFI_Filter_Select_Bits(x, y) ((y << (x * 2)) & \
1189  MSeries_PFI_Filter_Select_Mask(x))
1190 
1191 /* CDIO DMA select bits */
1192 #define CDI_DMA_Select_Shift 0
1193 #define CDI_DMA_Select_Mask 0xf
1194 #define CDO_DMA_Select_Shift 4
1195 #define CDO_DMA_Select_Mask 0xf << CDO_DMA_Select_Shift
1196 
1197 /* CDIO status bits */
1198 #define CDO_FIFO_Empty_Bit 0x1
1199 #define CDO_FIFO_Full_Bit 0x2
1200 #define CDO_FIFO_Request_Bit 0x4
1201 #define CDO_Overrun_Bit 0x8
1202 #define CDO_Underflow_Bit 0x10
1203 #define CDI_FIFO_Empty_Bit 0x10000
1204 #define CDI_FIFO_Full_Bit 0x20000
1205 #define CDI_FIFO_Request_Bit 0x40000
1206 #define CDI_Overrun_Bit 0x80000
1207 #define CDI_Overflow_Bit 0x100000
1208 
1209 /* CDIO command bits */
1210 #define CDO_Disarm_Bit 0x1
1211 #define CDO_Arm_Bit 0x2
1212 #define CDI_Disarm_Bit 0x4
1213 #define CDI_Arm_Bit 0x8
1214 #define CDO_Reset_Bit 0x10
1215 #define CDI_Reset_Bit 0x20
1216 #define CDO_Error_Interrupt_Enable_Set_Bit 0x40
1217 #define CDO_Error_Interrupt_Enable_Clear_Bit 0x80
1218 #define CDI_Error_Interrupt_Enable_Set_Bit 0x100
1219 #define CDI_Error_Interrupt_Enable_Clear_Bit 0x200
1220 #define CDO_FIFO_Request_Interrupt_Enable_Set_Bit 0x400
1221 #define CDO_FIFO_Request_Interrupt_Enable_Clear_Bit 0x800
1222 #define CDI_FIFO_Request_Interrupt_Enable_Set_Bit 0x1000
1223 #define CDI_FIFO_Request_Interrupt_Enable_Clear_Bit 0x2000
1224 #define CDO_Error_Interrupt_Confirm_Bit 0x4000
1225 #define CDI_Error_Interrupt_Confirm_Bit 0x8000
1226 #define CDO_Empty_FIFO_Interrupt_Enable_Set_Bit 0x10000
1227 #define CDO_Empty_FIFO_Interrupt_Enable_Clear_Bit 0x20000
1228 #define CDO_SW_Update_Bit 0x80000
1229 #define CDI_SW_Update_Bit 0x100000
1230 
1231 /* CDIO mode bits */
1232 #define CDI_Sample_Source_Select_Mask 0x3f
1233 #define CDI_Halt_On_Error_Bit 0x200
1234 /* sample clock on falling edge */
1235 #define CDI_Polarity_Bit 0x400
1236 /* set for half full mode, clear for not empty mode */
1237 #define CDI_FIFO_Mode_Bit 0x800
1238 /* data lanes specify which dio channels map to byte or word accesses
1239  to the dio fifos */
1240 #define CDI_Data_Lane_Mask 0x3000
1241 #define CDI_Data_Lane_0_15_Bits 0x0
1242 #define CDI_Data_Lane_16_31_Bits 0x1000
1243 #define CDI_Data_Lane_0_7_Bits 0x0
1244 #define CDI_Data_Lane_8_15_Bits 0x1000
1245 #define CDI_Data_Lane_16_23_Bits 0x2000
1246 #define CDI_Data_Lane_24_31_Bits 0x3000
1247 
1248 /* CDO mode bits */
1249 #define CDO_Sample_Source_Select_Mask 0x3f
1250 #define CDO_Retransmit_Bit 0x100
1251 #define CDO_Halt_On_Error_Bit 0x200
1252 /* sample clock on falling edge */
1253 #define CDO_Polarity_Bit 0x400
1254 /* set for half full mode, clear for not full mode */
1255 #define CDO_FIFO_Mode_Bit 0x800
1256 /* data lanes specify which dio channels map to byte or word accesses
1257  to the dio fifos */
1258 #define CDO_Data_Lane_Mask 0x3000
1259 #define CDO_Data_Lane_0_15_Bits 0x0
1260 #define CDO_Data_Lane_16_31_Bits 0x1000
1261 #define CDO_Data_Lane_0_7_Bits 0x0
1262 #define CDO_Data_Lane_8_15_Bits 0x1000
1263 #define CDO_Data_Lane_16_23_Bits 0x2000
1264 #define CDO_Data_Lane_24_31_Bits 0x3000
1265 
1266 /* Interrupt C bits */
1267 #define Interrupt_Group_C_Enable_Bit 0x1
1268 #define Interrupt_Group_C_Status_Bit 0x1
1269 
1270 #define M_SERIES_EEPROM_SIZE 1024
1271 
1272 typedef struct ni_board_struct{
1273  unsigned short device_id;
1274  int isapnp_id;
1275  char *name;
1276 
1277  int n_adchan;
1278  int adbits;
1279 
1280  int ai_fifo_depth;
1281  unsigned int alwaysdither : 1;
1282  int gainlkup;
1283  int ai_speed;
1284 
1285  int n_aochan;
1286  int aobits;
1287  a4l_rngdesc_t *ao_range_table;
1288  int ao_fifo_depth;
1289 
1290  unsigned ao_speed;
1291 
1292  unsigned num_p0_dio_channels;
1293 
1294  int reg_type;
1295  unsigned int ao_unipolar : 1;
1296  unsigned int has_8255 : 1;
1297  unsigned int has_analog_trig : 1;
1298 
1299  enum caldac_enum caldac[3];
1300 } ni_board;
1301 
1302 #define n_ni_boards (sizeof(ni_boards)/sizeof(ni_board))
1303 
1304 #define MAX_N_CALDACS 34
1305 #define MAX_N_AO_CHAN 8
1306 #define NUM_GPCT 2
1307 
1308 #define NI_PRIVATE_COMMON \
1309  uint16_t (*stc_readw)(a4l_dev_t *dev, int register); \
1310  uint32_t (*stc_readl)(a4l_dev_t *dev, int register); \
1311  void (*stc_writew)(a4l_dev_t *dev, uint16_t value, int register); \
1312  void (*stc_writel)(a4l_dev_t *dev, uint32_t value, int register); \
1313  \
1314  int dio_state; \
1315  int pfi_state; \
1316  int io_bits; \
1317  unsigned short dio_output; \
1318  unsigned short dio_control; \
1319  int ao0p,ao1p; \
1320  int lastchan; \
1321  int last_do; \
1322  int rt_irq; \
1323  int irq_polarity; \
1324  int irq_pin; \
1325  int aimode; \
1326  int ai_continuous; \
1327  int blocksize; \
1328  int n_left; \
1329  unsigned int ai_calib_source; \
1330  unsigned int ai_calib_source_enabled; \
1331  a4l_lock_t window_lock; \
1332  a4l_lock_t soft_reg_copy_lock; \
1333  a4l_lock_t mite_channel_lock; \
1334  \
1335  int changain_state; \
1336  unsigned int changain_spec; \
1337  \
1338  unsigned int caldac_maxdata_list[MAX_N_CALDACS]; \
1339  unsigned short ao[MAX_N_AO_CHAN]; \
1340  unsigned short caldacs[MAX_N_CALDACS]; \
1341  \
1342  unsigned short ai_cmd2; \
1343  \
1344  unsigned short ao_conf[MAX_N_AO_CHAN]; \
1345  unsigned short ao_mode1; \
1346  unsigned short ao_mode2; \
1347  unsigned short ao_mode3; \
1348  unsigned short ao_cmd1; \
1349  unsigned short ao_cmd2; \
1350  unsigned short ao_cmd3; \
1351  unsigned short ao_trigger_select; \
1352  \
1353  struct ni_gpct_device *counter_dev; \
1354  unsigned short an_trig_etc_reg; \
1355  \
1356  unsigned ai_offset[512]; \
1357  \
1358  unsigned long serial_interval_ns; \
1359  unsigned char serial_hw_mode; \
1360  unsigned short clock_and_fout; \
1361  unsigned short clock_and_fout2; \
1362  \
1363  unsigned short int_a_enable_reg; \
1364  unsigned short int_b_enable_reg; \
1365  unsigned short io_bidirection_pin_reg; \
1366  unsigned short rtsi_trig_direction_reg; \
1367  unsigned short rtsi_trig_a_output_reg; \
1368  unsigned short rtsi_trig_b_output_reg; \
1369  unsigned short pfi_output_select_reg[NUM_PFI_OUTPUT_SELECT_REGS]; \
1370  unsigned short ai_ao_select_reg; \
1371  unsigned short g0_g1_select_reg; \
1372  unsigned short cdio_dma_select_reg; \
1373  \
1374  unsigned clock_ns; \
1375  unsigned clock_source; \
1376  \
1377  unsigned short atrig_mode; \
1378  unsigned short atrig_high; \
1379  unsigned short atrig_low; \
1380  \
1381  unsigned short pwm_up_count; \
1382  unsigned short pwm_down_count; \
1383  \
1384  sampl_t ai_fifo_buffer[0x2000]; \
1385  uint8_t eeprom_buffer[M_SERIES_EEPROM_SIZE]; \
1386  \
1387  struct mite_struct *mite; \
1388  struct mite_channel *ai_mite_chan; \
1389  struct mite_channel *ao_mite_chan;\
1390  struct mite_channel *cdo_mite_chan;\
1391  struct mite_dma_descriptor_ring *ai_mite_ring; \
1392  struct mite_dma_descriptor_ring *ao_mite_ring; \
1393  struct mite_dma_descriptor_ring *cdo_mite_ring; \
1394  struct mite_dma_descriptor_ring *gpct_mite_ring[NUM_GPCT]; \
1395  subd_8255_t subd_8255
1396 
1397 
1398 typedef struct {
1399  ni_board *board_ptr;
1400  NI_PRIVATE_COMMON;
1401 } ni_private;
1402 
1403 #define devpriv ((ni_private *)dev->priv)
1404 #define boardtype (*(ni_board *)devpriv->board_ptr)
1405 
1406 /* How we access registers */
1407 
1408 #define ni_writel(a,b) (writel((a), devpriv->mite->daq_io_addr + (b)))
1409 #define ni_readl(a) (readl(devpriv->mite->daq_io_addr + (a)))
1410 #define ni_writew(a,b) (writew((a), devpriv->mite->daq_io_addr + (b)))
1411 #define ni_readw(a) (readw(devpriv->mite->daq_io_addr + (a)))
1412 #define ni_writeb(a,b) (writeb((a), devpriv->mite->daq_io_addr + (b)))
1413 #define ni_readb(a) (readb(devpriv->mite->daq_io_addr + (a)))
1414 
1415 /* INSN_CONFIG_SET_CLOCK_SRC argument for NI cards */
1416 #define NI_FREQ_OUT_TIMEBASE_1_DIV_2_CLOCK_SRC 0 /* 10 MHz */
1417 #define NI_FREQ_OUT_TIMEBASE_2_CLOCK_SRC 1 /* 100 KHz */
1418 
1419 #endif /* _ANALOGY_NI_STC_H */
Hardware driver for NI general purpose counter.
void rtdm_printk(const char *format,...)
Real-time safe message printing on kernel console.