]>
Commit | Line | Data |
---|---|---|
3fedd148 DK |
1 | /** |
2 | * @file me4600_ai.h | |
3 | * | |
4 | * @brief Meilhaus ME-4000 analog input subdevice class. | |
5 | * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de) | |
6 | * @author Guenter Gebhardt | |
7 | * @author Krzysztof Gantzke (k.gantzke@meilhaus.de) | |
8 | */ | |
9 | ||
10 | /* | |
11 | * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de) | |
12 | * | |
13 | * This file is free software; you can redistribute it and/or modify | |
14 | * it under the terms of the GNU General Public License as published by | |
15 | * the Free Software Foundation; either version 2 of the License, or | |
16 | * (at your option) any later version. | |
17 | * | |
18 | * This program is distributed in the hope that it will be useful, | |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | * GNU General Public License for more details. | |
22 | * | |
23 | * You should have received a copy of the GNU General Public License | |
24 | * along with this program; if not, write to the Free Software | |
25 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
26 | */ | |
27 | ||
28 | #ifndef _ME4600_AI_H_ | |
29 | #define _ME4600_AI_H_ | |
30 | ||
3fedd148 DK |
31 | #include "mesubdevice.h" |
32 | #include "meioctl.h" | |
33 | #include "mecirc_buf.h" | |
34 | ||
35 | #ifdef __KERNEL__ | |
36 | ||
37 | #define ME4600_AI_MAX_DATA 0xFFFF | |
38 | ||
39 | #ifdef ME_SYNAPSE | |
40 | # define ME4600_AI_CIRC_BUF_SIZE_ORDER 8 // 2^n PAGES =>> Maximum value of 1MB for Synapse | |
41 | #else | |
42 | # define ME4600_AI_CIRC_BUF_SIZE_ORDER 5 // 2^n PAGES =>> 128KB | |
43 | #endif | |
44 | #define ME4600_AI_CIRC_BUF_SIZE PAGE_SIZE<<ME4600_AI_CIRC_BUF_SIZE_ORDER // Buffer size in bytes. | |
45 | ||
46 | #ifdef _CBUFF_32b_t | |
47 | # define ME4600_AI_CIRC_BUF_COUNT ((ME4600_AI_CIRC_BUF_SIZE) / sizeof(uint32_t)) // Size in values | |
48 | #else | |
49 | # define ME4600_AI_CIRC_BUF_COUNT ((ME4600_AI_CIRC_BUF_SIZE) / sizeof(uint16_t)) // Size in values | |
50 | #endif | |
51 | ||
52 | #define ME4600_AI_FIFO_HALF 1024 //ME4600_AI_FIFO_COUNT/2 //1024 | |
53 | #define ME4600_AI_FIFO_MAX_SC 1352 //0.66*ME4600_AI_FIFO_COUNT //1352 | |
54 | ||
55 | typedef enum ME4600_AI_STATUS { | |
56 | ai_status_none = 0, | |
57 | ai_status_single_configured, | |
58 | ai_status_stream_configured, | |
59 | ai_status_stream_run_wait, | |
60 | ai_status_stream_run, | |
61 | ai_status_stream_end_wait, | |
62 | ai_status_stream_end, | |
63 | ai_status_stream_fifo_error, | |
64 | ai_status_stream_buffer_error, | |
65 | ai_status_stream_error, | |
66 | ai_status_last | |
67 | } ME4600_AI_STATUS; | |
68 | ||
69 | typedef struct me4600_single_config_entry { | |
70 | unsigned short status; | |
71 | uint32_t entry; | |
72 | uint32_t ctrl; | |
73 | } me4600_single_config_entry_t; | |
74 | ||
75 | typedef struct me4600_range_entry { | |
76 | int min; | |
77 | int max; | |
78 | } me4600_range_entry_t; | |
79 | ||
80 | typedef struct me4600_ai_ISM { | |
81 | volatile unsigned int global_read; /**< The number of data read in total. */ | |
82 | volatile unsigned int read; /**< The number of data read for this chunck. */ | |
83 | volatile unsigned int next; /**< The number of data request by user. */ | |
84 | } me4600_ai_ISM_t; | |
85 | ||
86 | typedef struct me4600_ai_timeout { | |
87 | unsigned long start_time; | |
88 | unsigned long delay; | |
89 | } me4600_ai_timeout_t; | |
90 | ||
91 | /** | |
92 | * @brief The ME-4000 analog input subdevice class. | |
93 | */ | |
94 | typedef struct me4600_ai_subdevice { | |
95 | /* Inheritance */ | |
96 | me_subdevice_t base; /**< The subdevice base class. */ | |
97 | ||
98 | /* Attributes */ | |
99 | spinlock_t subdevice_lock; /**< Spin lock to protect the subdevice from concurrent access. */ | |
100 | spinlock_t *ctrl_reg_lock; /**< Spin lock to protect #ctrl_reg from concurrent access. */ | |
101 | ||
102 | /* Hardware feautres */ | |
103 | unsigned int irq; /**< The interrupt request number assigned by the PCI BIOS. */ | |
104 | int isolated; /**< Marks if this subdevice is on an optoisolated device. */ | |
105 | int sh; /**< Marks if this subdevice has sample and hold devices. */ | |
106 | ||
107 | unsigned int channels; /**< The number of channels available on this subdevice. */ | |
108 | me4600_single_config_entry_t single_config[32]; /**< The configuration set for single acquisition. */ | |
109 | ||
110 | unsigned int data_required; /**< The number of data request by user. */ | |
111 | unsigned int fifo_irq_threshold; /**< The user adjusted FIFO high water interrupt level. */ | |
112 | unsigned int chan_list_len; /**< The length of the user defined channel list. */ | |
113 | ||
114 | me4600_ai_ISM_t ISM; /**< The information request by Interrupt-State-Machine. */ | |
115 | volatile enum ME4600_AI_STATUS status; /**< The current stream status flag. */ | |
116 | me4600_ai_timeout_t timeout; /**< The timeout for start in blocking and non-blocking mode. */ | |
117 | ||
118 | /* Registers *//**< All registers are 32 bits long. */ | |
119 | unsigned long ctrl_reg; | |
120 | unsigned long status_reg; | |
121 | unsigned long channel_list_reg; | |
122 | unsigned long data_reg; | |
123 | unsigned long chan_timer_reg; | |
124 | unsigned long chan_pre_timer_reg; | |
125 | unsigned long scan_timer_low_reg; | |
126 | unsigned long scan_timer_high_reg; | |
127 | unsigned long scan_pre_timer_low_reg; | |
128 | unsigned long scan_pre_timer_high_reg; | |
129 | unsigned long start_reg; | |
130 | unsigned long irq_status_reg; | |
131 | unsigned long sample_counter_reg; | |
132 | ||
133 | unsigned int ranges_len; | |
134 | me4600_range_entry_t ranges[4]; /**< The ranges available on this subdevice. */ | |
135 | ||
136 | /* Software buffer */ | |
137 | me_circ_buf_t circ_buf; /**< Circular buffer holding measurment data. */ | |
138 | wait_queue_head_t wait_queue; /**< Wait queue to put on tasks waiting for data to arrive. */ | |
139 | ||
140 | struct workqueue_struct *me4600_workqueue; | |
3fedd148 | 141 | struct delayed_work ai_control_task; |
3fedd148 DK |
142 | |
143 | volatile int ai_control_task_flag; /**< Flag controling reexecuting of control task */ | |
144 | ||
145 | #ifdef MEDEBUG_DEBUG_REG | |
146 | unsigned long reg_base; | |
147 | #endif | |
148 | } me4600_ai_subdevice_t; | |
149 | ||
150 | /** | |
151 | * @brief The constructor to generate a ME-4000 analog input subdevice instance. | |
152 | * | |
153 | * @param reg_base The register base address of the device as returned by the PCI BIOS. | |
154 | * @param channels The number of analog input channels available on this subdevice. | |
155 | * @param channels The number of analog input ranges available on this subdevice. | |
156 | * @param isolated Flag indicating if this device is opto isolated. | |
157 | * @param sh Flag indicating if sample and hold devices are available. | |
158 | * @param irq The irq number assigned by PCI BIOS. | |
159 | * @param ctrl_reg_lock Pointer to spin lock protecting the control register from concurrent access. | |
160 | * | |
161 | * @return Pointer to new instance on success.\n | |
162 | * NULL on error. | |
163 | */ | |
164 | me4600_ai_subdevice_t *me4600_ai_constructor(uint32_t reg_base, | |
165 | unsigned int channels, | |
166 | unsigned int ranges, | |
167 | int isolated, | |
168 | int sh, | |
169 | int irq, | |
170 | spinlock_t * ctrl_reg_lock, | |
171 | struct workqueue_struct | |
172 | *me4600_wq); | |
173 | ||
174 | #endif | |
175 | #endif |