1 | /* Filename : $RCSfile$ |
---|
2 | * |
---|
3 | * The declarations here have to be in a header file, |
---|
4 | * because they need to be known both to the kernel |
---|
5 | * module (in chardev.c) and the process calling ioctl |
---|
6 | * (ioctl.c) |
---|
7 | */ |
---|
8 | |
---|
9 | /* $Id$ */ |
---|
10 | |
---|
11 | #ifndef CHARDEV_H |
---|
12 | #define CHARDEV_H |
---|
13 | |
---|
14 | #if defined(__linux__) |
---|
15 | #include <linux/ioctl.h> |
---|
16 | #else |
---|
17 | #define MAJOR_NUM 1 |
---|
18 | #define _IOWR(_x, _y, _t) (_t) ((_x << 16) | (_y << 16)) |
---|
19 | #endif |
---|
20 | |
---|
21 | |
---|
22 | /* These are the IOCTL value the pcmmio driver recognizes */ |
---|
23 | |
---|
24 | #define WRITE_DAC_DATA _IOWR(MAJOR_NUM, 0, int) |
---|
25 | |
---|
26 | #define READ_DAC_STATUS _IOWR(MAJOR_NUM, 1, int) |
---|
27 | |
---|
28 | #define WRITE_DAC_COMMAND _IOWR(MAJOR_NUM, 2, int) |
---|
29 | |
---|
30 | #define WRITE_ADC_COMMAND _IOWR(MAJOR_NUM, 3, int) |
---|
31 | |
---|
32 | #define READ_ADC_DATA _IOWR(MAJOR_NUM, 4, int) |
---|
33 | |
---|
34 | #define READ_ADC_STATUS _IOWR(MAJOR_NUM, 5, int) |
---|
35 | |
---|
36 | #define WRITE_DIO_BYTE _IOWR(MAJOR_NUM, 6, int) |
---|
37 | |
---|
38 | #define READ_DIO_BYTE _IOWR(MAJOR_NUM, 7, int) |
---|
39 | |
---|
40 | #define MIO_WRITE_REG _IOWR(MAJOR_NUM, 8, int) |
---|
41 | |
---|
42 | #define MIO_READ_REG _IOWR(MAJOR_NUM, 9, int) |
---|
43 | |
---|
44 | #define WAIT_A2D_INT_1 _IOWR(MAJOR_NUM, 10, int) |
---|
45 | |
---|
46 | #define WAIT_A2D_INT_2 _IOWR(MAJOR_NUM, 11, int) |
---|
47 | |
---|
48 | #define WAIT_DAC_INT_1 _IOWR(MAJOR_NUM, 12, int) |
---|
49 | |
---|
50 | #define WAIT_DAC_INT_2 _IOWR(MAJOR_NUM, 13, int) |
---|
51 | |
---|
52 | #define WAIT_DIO_INT _IOWR(MAJOR_NUM, 14, int) |
---|
53 | |
---|
54 | #define READ_IRQ_ASSIGNED _IOWR(MAJOR_NUM, 15, int) |
---|
55 | |
---|
56 | #define DIO_GET_INT _IOWR(MAJOR_NUM, 16, int) |
---|
57 | |
---|
58 | |
---|
59 | /* The name of the device file */ |
---|
60 | |
---|
61 | #define DEVICE_FILE_NAME "pcmmio" |
---|
62 | |
---|
63 | |
---|
64 | #endif |
---|
65 | |
---|
66 | /* These are the error codes doe mio_error_code */ |
---|
67 | |
---|
68 | #define MIO_SUCCESS 0 |
---|
69 | #define MIO_OPEN_ERROR 1 |
---|
70 | #define MIO_TIMEOUT_ERROR 2 |
---|
71 | #define MIO_BAD_CHANNEL_NUMBER 3 |
---|
72 | #define MIO_BAD_MODE_NUMBER 4 |
---|
73 | #define MIO_BAD_RANGE 5 |
---|
74 | #define MIO_COMMAND_WRITE_FAILURE 6 |
---|
75 | #define MIO_READ_DATA_FAILURE 7 |
---|
76 | #define MIO_MISSING_IRQ 8 |
---|
77 | #define MIO_ILLEGAL_VOLTAGE 9 |
---|
78 | |
---|
79 | |
---|
80 | /* These are DAC specific defines */ |
---|
81 | |
---|
82 | #define DAC_BUSY 0x80 |
---|
83 | |
---|
84 | #define DAC_SPAN_UNI5 0 |
---|
85 | #define DAC_SPAN_UNI10 1 |
---|
86 | #define DAC_SPAN_BI5 2 |
---|
87 | #define DAC_SPAN_BI10 3 |
---|
88 | #define DAC_SPAN_BI2 4 |
---|
89 | #define DAC_SPAN_BI7 5 |
---|
90 | |
---|
91 | /* These are ADC specific defines */ |
---|
92 | |
---|
93 | #define ADC_SINGLE_ENDED 0x80 |
---|
94 | #define ADC_DIFFERENTIAL 0x00 |
---|
95 | |
---|
96 | #define ADC_UNIPOLAR 0x08 |
---|
97 | #define ADC_BIPOLAR 0x00 |
---|
98 | |
---|
99 | #define ADC_TOP_5V 0x00 |
---|
100 | #define ADC_TOP_10V 0x04 |
---|
101 | |
---|
102 | #define ADC_CH0_SELECT 0x00 |
---|
103 | #define ADC_CH1_SELECT 0x40 |
---|
104 | #define ADC_CH2_SELECT 0x10 |
---|
105 | #define ADC_CH3_SELECT 0x50 |
---|
106 | #define ADC_CH4_SELECT 0x20 |
---|
107 | #define ADC_CH5_SELECT 0x60 |
---|
108 | #define ADC_CH6_SELECT 0x30 |
---|
109 | #define ADC_CH7_SELECT 0x70 |
---|
110 | |
---|
111 | /* These are DIO specific defines */ |
---|
112 | |
---|
113 | #define FALLING 1 |
---|
114 | #define RISING 0 |
---|
115 | |
---|
116 | #ifdef LIB_DEFINED |
---|
117 | |
---|
118 | /* These are used by the library functions */ |
---|
119 | |
---|
120 | int mio_error_code; |
---|
121 | char mio_error_string[128]; |
---|
122 | float adc_bitval[16] = {.00, .00, .00, .00, .00, .00, 00, .00, |
---|
123 | .00, .00, .00, .00, .00, .00, .00, .00 }; |
---|
124 | |
---|
125 | unsigned short adc_adjust[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; |
---|
126 | |
---|
127 | float adc_offset[16] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
---|
128 | 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; |
---|
129 | |
---|
130 | #else |
---|
131 | |
---|
132 | |
---|
133 | /* The rest of this file is made up of global variables available to application |
---|
134 | code and the function prototypes for all available functions |
---|
135 | */ |
---|
136 | |
---|
137 | |
---|
138 | extern int mio_error_code; |
---|
139 | extern char mio_error_string[128]; |
---|
140 | extern float adc_bitval[16]; |
---|
141 | |
---|
142 | extern unsigned short adc_adjust[16]; |
---|
143 | |
---|
144 | extern float adc_offset[16]; |
---|
145 | |
---|
146 | #endif |
---|
147 | |
---|
148 | /* part of the porting layer */ |
---|
149 | int check_handle(void); |
---|
150 | int mio_read_irq_assigned(void); |
---|
151 | |
---|
152 | int disable_dio_interrupt(void); |
---|
153 | int enable_dio_interrupt(void); |
---|
154 | int disable_dac_interrupt(int dac_num); |
---|
155 | int enable_dac_interrupt(int dac_num); |
---|
156 | int disable_adc_interrupt(int adc_num); |
---|
157 | int enable_adc_interrupt(int adc_num); |
---|
158 | int set_dac_span(int channel, unsigned char span_value); |
---|
159 | int wait_dac_ready(int channel); |
---|
160 | int set_dac_output(int channel, unsigned short dac_value); |
---|
161 | int set_dac_voltage(int channel, float voltage); |
---|
162 | unsigned char read_dio_byte(int offset); |
---|
163 | unsigned char mio_read_reg(int offset); |
---|
164 | int mio_write_reg(int offset, unsigned char value); |
---|
165 | int write_dio_byte(int offset, unsigned char value); |
---|
166 | int write_dac_command(int dac_num,unsigned char value); |
---|
167 | int adc_start_conversion(int channel); |
---|
168 | float adc_get_channel_voltage(int channel); |
---|
169 | int adc_convert_all_channels(unsigned short *buffer); |
---|
170 | float adc_convert_to_volts(int channel, unsigned short value); |
---|
171 | int adc_convert_single_repeated(int channel, unsigned short count, unsigned short *buffer); |
---|
172 | int adc_buffered_channel_conversions(unsigned char *input_channel_buffer,unsigned short *buffer); |
---|
173 | int adc_wait_ready(int channel); |
---|
174 | int write_adc_command(int adc_num,unsigned char value); |
---|
175 | int buffered_dac_output(unsigned char *cmd_buff,unsigned short *data_buff); |
---|
176 | int write_dac_data(int dac_num, unsigned short value); |
---|
177 | unsigned char dac_read_status(int dac_num); |
---|
178 | unsigned char adc_read_status(int adc_num); |
---|
179 | int adc_set_channel_mode(int channel, int input_mode,int duplex,int range); |
---|
180 | unsigned short adc_read_conversion_data(int channel); |
---|
181 | float adc_auto_get_channel_voltage(int channel); |
---|
182 | int dio_read_bit(int bit_number); |
---|
183 | int dio_write_bit(int bit_number, int val); |
---|
184 | int dio_set_bit(int bit_number); |
---|
185 | int dio_clr_bit(int bit_number); |
---|
186 | int dio_enab_bit_int(int bit_number, int polarity); |
---|
187 | int dio_disab_bit_int(int bit_number); |
---|
188 | int dio_clr_int(int bit_number); |
---|
189 | int dio_get_int(void); |
---|
190 | int dio_get_int_with_timestamp( |
---|
191 | unsigned long long *timestamp |
---|
192 | ); |
---|
193 | int wait_adc_int(int adc_num); |
---|
194 | int wait_dac_int(int dac_num); |
---|
195 | int wait_dio_int(void); |
---|
196 | |
---|
197 | #if defined(__rtems__) |
---|
198 | void pcmmio_initialize( |
---|
199 | unsigned short _base_port, |
---|
200 | unsigned short _irq |
---|
201 | ); |
---|
202 | #endif |
---|
203 | |
---|