Commit | Line | Data |
---|---|---|
b79a7a20 DS |
1 | /* |
2 | kcomedilib/data.c | |
3 | implements comedi_data_*() functions | |
4 | ||
5 | COMEDI - Linux Control and Measurement Device Interface | |
6 | Copyright (C) 2000 David A. Schleef <ds@schleef.org> | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | ||
22 | */ | |
23 | ||
24 | #include "../comedi.h" | |
25 | #include "../comedilib.h" | |
5f74ea14 | 26 | #include "../comedidev.h" |
b79a7a20 DS |
27 | |
28 | #include <linux/string.h> | |
c3e2354e | 29 | #include <linux/delay.h> |
b79a7a20 | 30 | |
0b3fb27f | 31 | int comedi_data_write(void *dev, unsigned int subdev, unsigned int chan, |
0a85b6f0 | 32 | unsigned int range, unsigned int aref, unsigned int data) |
b79a7a20 | 33 | { |
90035c08 | 34 | struct comedi_insn insn; |
b79a7a20 DS |
35 | |
36 | memset(&insn, 0, sizeof(insn)); | |
37 | insn.insn = INSN_WRITE; | |
38 | insn.n = 1; | |
39 | insn.data = &data; | |
40 | insn.subdev = subdev; | |
41 | insn.chanspec = CR_PACK(chan, range, aref); | |
42 | ||
43 | return comedi_do_insn(dev, &insn); | |
44 | } | |
45 | ||
0b3fb27f | 46 | int comedi_data_read(void *dev, unsigned int subdev, unsigned int chan, |
0a85b6f0 | 47 | unsigned int range, unsigned int aref, unsigned int *data) |
b79a7a20 | 48 | { |
90035c08 | 49 | struct comedi_insn insn; |
b79a7a20 DS |
50 | |
51 | memset(&insn, 0, sizeof(insn)); | |
52 | insn.insn = INSN_READ; | |
53 | insn.n = 1; | |
54 | insn.data = data; | |
55 | insn.subdev = subdev; | |
56 | insn.chanspec = CR_PACK(chan, range, aref); | |
57 | ||
58 | return comedi_do_insn(dev, &insn); | |
59 | } | |
60 | ||
0b3fb27f | 61 | int comedi_data_read_hint(void *dev, unsigned int subdev, |
0a85b6f0 MT |
62 | unsigned int chan, unsigned int range, |
63 | unsigned int aref) | |
b79a7a20 | 64 | { |
90035c08 | 65 | struct comedi_insn insn; |
790c5541 | 66 | unsigned int dummy_data; |
b79a7a20 DS |
67 | |
68 | memset(&insn, 0, sizeof(insn)); | |
69 | insn.insn = INSN_READ; | |
70 | insn.n = 0; | |
71 | insn.data = &dummy_data; | |
72 | insn.subdev = subdev; | |
73 | insn.chanspec = CR_PACK(chan, range, aref); | |
74 | ||
75 | return comedi_do_insn(dev, &insn); | |
76 | } | |
77 | ||
0b3fb27f | 78 | int comedi_data_read_delayed(void *dev, unsigned int subdev, |
0a85b6f0 MT |
79 | unsigned int chan, unsigned int range, |
80 | unsigned int aref, unsigned int *data, | |
81 | unsigned int nano_sec) | |
b79a7a20 DS |
82 | { |
83 | int retval; | |
84 | ||
85 | retval = comedi_data_read_hint(dev, subdev, chan, range, aref); | |
86 | if (retval < 0) | |
87 | return retval; | |
88 | ||
5f74ea14 | 89 | udelay((nano_sec + 999) / 1000); |
b79a7a20 DS |
90 | |
91 | return comedi_data_read(dev, subdev, chan, range, aref, data); | |
92 | } |