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)
11 * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
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.
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.
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.
31 #include <linux/version.h>
32 #include "mesubdevice.h"
34 #include "mecirc_buf.h"
38 #define ME4600_AI_MAX_DATA 0xFFFF
41 # define ME4600_AI_CIRC_BUF_SIZE_ORDER 8 // 2^n PAGES =>> Maximum value of 1MB for Synapse
43 # define ME4600_AI_CIRC_BUF_SIZE_ORDER 5 // 2^n PAGES =>> 128KB
45 #define ME4600_AI_CIRC_BUF_SIZE PAGE_SIZE<<ME4600_AI_CIRC_BUF_SIZE_ORDER // Buffer size in bytes.
48 # define ME4600_AI_CIRC_BUF_COUNT ((ME4600_AI_CIRC_BUF_SIZE) / sizeof(uint32_t)) // Size in values
50 # define ME4600_AI_CIRC_BUF_COUNT ((ME4600_AI_CIRC_BUF_SIZE) / sizeof(uint16_t)) // Size in values
53 #define ME4600_AI_FIFO_HALF 1024 //ME4600_AI_FIFO_COUNT/2 //1024
54 #define ME4600_AI_FIFO_MAX_SC 1352 //0.66*ME4600_AI_FIFO_COUNT //1352
56 typedef enum ME4600_AI_STATUS
{
58 ai_status_single_configured
,
59 ai_status_stream_configured
,
60 ai_status_stream_run_wait
,
62 ai_status_stream_end_wait
,
64 ai_status_stream_fifo_error
,
65 ai_status_stream_buffer_error
,
66 ai_status_stream_error
,
70 typedef struct me4600_single_config_entry
{
71 unsigned short status
;
74 } me4600_single_config_entry_t
;
76 typedef struct me4600_range_entry
{
79 } me4600_range_entry_t
;
81 typedef struct me4600_ai_ISM
{
82 volatile unsigned int global_read
; /**< The number of data read in total. */
83 volatile unsigned int read
; /**< The number of data read for this chunck. */
84 volatile unsigned int next
; /**< The number of data request by user. */
87 typedef struct me4600_ai_timeout
{
88 unsigned long start_time
;
90 } me4600_ai_timeout_t
;
93 * @brief The ME-4000 analog input subdevice class.
95 typedef struct me4600_ai_subdevice
{
97 me_subdevice_t base
; /**< The subdevice base class. */
100 spinlock_t subdevice_lock
; /**< Spin lock to protect the subdevice from concurrent access. */
101 spinlock_t
*ctrl_reg_lock
; /**< Spin lock to protect #ctrl_reg from concurrent access. */
103 /* Hardware feautres */
104 unsigned int irq
; /**< The interrupt request number assigned by the PCI BIOS. */
105 int isolated
; /**< Marks if this subdevice is on an optoisolated device. */
106 int sh
; /**< Marks if this subdevice has sample and hold devices. */
108 unsigned int channels
; /**< The number of channels available on this subdevice. */
109 me4600_single_config_entry_t single_config
[32]; /**< The configuration set for single acquisition. */
111 unsigned int data_required
; /**< The number of data request by user. */
112 unsigned int fifo_irq_threshold
; /**< The user adjusted FIFO high water interrupt level. */
113 unsigned int chan_list_len
; /**< The length of the user defined channel list. */
115 me4600_ai_ISM_t ISM
; /**< The information request by Interrupt-State-Machine. */
116 volatile enum ME4600_AI_STATUS status
; /**< The current stream status flag. */
117 me4600_ai_timeout_t timeout
; /**< The timeout for start in blocking and non-blocking mode. */
119 /* Registers *//**< All registers are 32 bits long. */
120 unsigned long ctrl_reg
;
121 unsigned long status_reg
;
122 unsigned long channel_list_reg
;
123 unsigned long data_reg
;
124 unsigned long chan_timer_reg
;
125 unsigned long chan_pre_timer_reg
;
126 unsigned long scan_timer_low_reg
;
127 unsigned long scan_timer_high_reg
;
128 unsigned long scan_pre_timer_low_reg
;
129 unsigned long scan_pre_timer_high_reg
;
130 unsigned long start_reg
;
131 unsigned long irq_status_reg
;
132 unsigned long sample_counter_reg
;
134 unsigned int ranges_len
;
135 me4600_range_entry_t ranges
[4]; /**< The ranges available on this subdevice. */
137 /* Software buffer */
138 me_circ_buf_t circ_buf
; /**< Circular buffer holding measurment data. */
139 wait_queue_head_t wait_queue
; /**< Wait queue to put on tasks waiting for data to arrive. */
141 struct workqueue_struct
*me4600_workqueue
;
142 struct delayed_work ai_control_task
;
144 volatile int ai_control_task_flag
; /**< Flag controling reexecuting of control task */
146 #ifdef MEDEBUG_DEBUG_REG
147 unsigned long reg_base
;
149 } me4600_ai_subdevice_t
;
152 * @brief The constructor to generate a ME-4000 analog input subdevice instance.
154 * @param reg_base The register base address of the device as returned by the PCI BIOS.
155 * @param channels The number of analog input channels available on this subdevice.
156 * @param channels The number of analog input ranges available on this subdevice.
157 * @param isolated Flag indicating if this device is opto isolated.
158 * @param sh Flag indicating if sample and hold devices are available.
159 * @param irq The irq number assigned by PCI BIOS.
160 * @param ctrl_reg_lock Pointer to spin lock protecting the control register from concurrent access.
162 * @return Pointer to new instance on success.\n
165 me4600_ai_subdevice_t
*me4600_ai_constructor(uint32_t reg_base
,
166 unsigned int channels
,
171 spinlock_t
* ctrl_reg_lock
,
172 struct workqueue_struct