]>
Commit | Line | Data |
---|---|---|
3fedd148 DK |
1 | /** |
2 | * @file me6000_ao.h | |
3 | * | |
4 | * @brief Meilhaus ME-6000 analog output subdevice class. | |
5 | * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de) | |
6 | * @author Guenter Gebhardt | |
7 | */ | |
8 | ||
9 | /* | |
10 | * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de) | |
11 | * | |
12 | * This file is free software; you can redistribute it and/or modify | |
13 | * it under the terms of the GNU General Public License as published by | |
14 | * the Free Software Foundation; either version 2 of the License, or | |
15 | * (at your option) any later version. | |
16 | * | |
17 | * This program is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | * GNU General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU General Public License | |
23 | * along with this program; if not, write to the Free Software | |
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
25 | */ | |
26 | ||
27 | #ifndef _ME6000_AO_H_ | |
28 | #define _ME6000_AO_H_ | |
29 | ||
3fedd148 DK |
30 | #include "mesubdevice.h" |
31 | #include "mecirc_buf.h" | |
32 | #include "meioctl.h" | |
33 | ||
34 | #ifdef __KERNEL__ | |
35 | ||
36 | #define ME6000_AO_MAX_SUBDEVICES 16 | |
37 | #define ME6000_AO_FIFO_COUNT 8192 | |
38 | ||
39 | #define ME6000_AO_BASE_FREQUENCY 33000000L | |
40 | ||
41 | #define ME6000_AO_MIN_ACQ_TICKS 0LL | |
42 | #define ME6000_AO_MAX_ACQ_TICKS 0LL | |
43 | ||
44 | #define ME6000_AO_MIN_CHAN_TICKS 66LL | |
45 | #define ME6000_AO_MAX_CHAN_TICKS 0xFFFFFFFFLL | |
46 | ||
47 | #define ME6000_AO_MIN_RANGE -10000000 | |
48 | #define ME6000_AO_MAX_RANGE 9999694 | |
49 | ||
50 | #define ME6000_AO_MIN_RANGE_HIGH 0 | |
51 | #define ME6000_AO_MAX_RANGE_HIGH 49999237 | |
52 | ||
53 | #define ME6000_AO_MAX_DATA 0xFFFF | |
54 | ||
55 | #ifdef ME_SYNAPSE | |
56 | # define ME6000_AO_CIRC_BUF_SIZE_ORDER 8 // 2^n PAGES =>> Maximum value of 1MB for Synapse | |
57 | #else | |
58 | # define ME6000_AO_CIRC_BUF_SIZE_ORDER 5 // 2^n PAGES =>> 128KB | |
59 | #endif | |
60 | #define ME6000_AO_CIRC_BUF_SIZE PAGE_SIZE<<ME6000_AO_CIRC_BUF_SIZE_ORDER // Buffer size in bytes. | |
61 | ||
62 | # ifdef _CBUFF_32b_t | |
63 | # define ME6000_AO_CIRC_BUF_COUNT ((ME6000_AO_CIRC_BUF_SIZE) / sizeof(uint32_t)) // Size in values | |
64 | # else | |
65 | # define ME6000_AO_CIRC_BUF_COUNT ((ME6000_AO_CIRC_BUF_SIZE) / sizeof(uint16_t)) // Size in values | |
66 | # endif | |
67 | ||
68 | # define ME6000_AO_CONTINOUS 0x0 | |
69 | # define ME6000_AO_WRAP_MODE 0x1 | |
70 | # define ME6000_AO_HW_MODE 0x2 | |
71 | ||
72 | # define ME6000_AO_HW_WRAP_MODE (ME6000_AO_WRAP_MODE | ME6000_AO_HW_MODE) | |
73 | # define ME6000_AO_SW_WRAP_MODE ME6000_AO_WRAP_MODE | |
74 | ||
75 | # define ME6000_AO_INF_STOP_MODE 0x0 | |
76 | # define ME6000_AO_ACQ_STOP_MODE 0x1 | |
77 | # define ME6000_AO_SCAN_STOP_MODE 0x2 | |
78 | ||
79 | # define ME6000_AO_EXTRA_HARDWARE 0x1 | |
80 | # define ME6000_AO_HAS_FIFO 0x2 | |
81 | ||
82 | typedef enum ME6000_AO_STATUS { | |
83 | ao_status_none = 0, | |
84 | ao_status_single_configured, | |
85 | ao_status_single_run_wait, | |
86 | ao_status_single_run, | |
87 | ao_status_single_end_wait, | |
88 | ao_status_single_end, | |
89 | ao_status_stream_configured, | |
90 | ao_status_stream_run_wait, | |
91 | ao_status_stream_run, | |
92 | ao_status_stream_end_wait, | |
93 | ao_status_stream_end, | |
94 | ao_status_stream_fifo_error, | |
95 | ao_status_stream_buffer_error, | |
96 | ao_status_stream_error, | |
97 | ao_status_last | |
98 | } ME6000_AO_STATUS; | |
99 | ||
100 | typedef struct me6000_ao_timeout { | |
101 | unsigned long start_time; | |
102 | unsigned long delay; | |
103 | } me6000_ao_timeout_t; | |
104 | ||
105 | /** | |
106 | * @brief The ME-6000 analog output subdevice class. | |
107 | */ | |
108 | typedef struct me6000_ao_subdevice { | |
109 | /* Inheritance */ | |
110 | me_subdevice_t base; /**< The subdevice base class. */ | |
111 | unsigned int ao_idx; | |
112 | ||
113 | /* Attributes */ | |
114 | spinlock_t subdevice_lock; /**< Spin lock to protect the subdevice from concurrent access. */ | |
115 | spinlock_t *preload_reg_lock; /**< Spin lock to protect preload_reg from concurrent access. */ | |
116 | ||
117 | uint32_t *preload_flags; | |
118 | uint32_t *triggering_flags; | |
119 | ||
120 | /* Hardware feautres */ | |
121 | unsigned int irq; /**< The interrupt request number assigned by the PCI BIOS. */ | |
122 | int fifo; /**< If set this device has a FIFO. */ | |
123 | ||
124 | //Range | |
125 | int min; | |
126 | int max; | |
127 | ||
128 | int single_value; /**< Mirror of the output value in single mode. */ | |
129 | int single_value_in_fifo; /**< Mirror of the value written in single mode. */ | |
130 | uint32_t ctrl_trg; /**< Mirror of the trigger settings. */ | |
131 | ||
132 | volatile int mode; /**< Flags used for storing SW wraparound setup*/ | |
133 | int stop_mode; /**< The user defined stop condition flag. */ | |
134 | unsigned int start_mode; | |
135 | unsigned int stop_count; /**< The user defined dates presentation end count. */ | |
136 | unsigned int stop_data_count; /**< The stop presentation count. */ | |
137 | unsigned int data_count; /**< The real presentation count. */ | |
138 | unsigned int preloaded_count; /**< The next data addres in buffer. <= for wraparound mode. */ | |
139 | int hardware_stop_delay; /**< The time that stop can take. This is only to not show hardware bug to user. */ | |
140 | ||
141 | volatile enum ME6000_AO_STATUS status; /**< The current stream status flag. */ | |
142 | me6000_ao_timeout_t timeout; /**< The timeout for start in blocking and non-blocking mode. */ | |
143 | ||
144 | /* Registers *//**< All registers are 32 bits long. */ | |
145 | unsigned long ctrl_reg; | |
146 | unsigned long status_reg; | |
147 | unsigned long fifo_reg; | |
148 | unsigned long single_reg; | |
149 | unsigned long timer_reg; | |
150 | unsigned long irq_status_reg; | |
151 | unsigned long preload_reg; | |
152 | unsigned long irq_reset_reg; | |
153 | #ifdef MEDEBUG_DEBUG_REG | |
154 | unsigned long reg_base; | |
155 | #endif | |
156 | ||
157 | /* Software buffer */ | |
158 | me_circ_buf_t circ_buf; /**< Circular buffer holding measurment data. */ | |
159 | wait_queue_head_t wait_queue; /**< Wait queue to put on tasks waiting for data to arrive. */ | |
160 | ||
161 | struct workqueue_struct *me6000_workqueue; | |
3fedd148 | 162 | struct delayed_work ao_control_task; |
3fedd148 DK |
163 | |
164 | volatile int ao_control_task_flag; /**< Flag controling reexecuting of control task */ | |
165 | ||
166 | } me6000_ao_subdevice_t; | |
167 | ||
168 | /** | |
169 | * @brief The constructor to generate a ME-6000 analog output subdevice instance. | |
170 | * | |
171 | * @param reg_base The register base address of the device as returned by the PCI BIOS. | |
172 | * @param ctrl_reg_lock Pointer to spin lock protecting the control register from concurrent access. | |
173 | * @param preload_flags Pointer to spin lock protecting the hold&trigger register from concurrent access. | |
174 | * @param ao_idx Subdevice number. | |
175 | * @param fifo Flag set if subdevice has hardware FIFO. | |
176 | * @param irq IRQ number. | |
177 | * @param high_range Flag set if subdevice has high curren output. | |
178 | * @param me6000_wq Queue for asynchronous task (1 queue for all subdevice on 1 board). | |
179 | * | |
180 | * @return Pointer to new instance on success.\n | |
181 | * NULL on error. | |
182 | */ | |
183 | me6000_ao_subdevice_t *me6000_ao_constructor(uint32_t reg_base, | |
184 | spinlock_t * preload_reg_lock, | |
185 | uint32_t * preload_flags, | |
186 | uint32_t * triggering_flags, | |
187 | int ao_idx, | |
188 | int fifo, | |
189 | int irq, | |
190 | int high_range, | |
191 | struct workqueue_struct | |
192 | *me6000_wq); | |
193 | ||
194 | #endif //__KERNEL__ | |
195 | #endif //_ME6000_AO_H_ |