RTEMS 6.1-rc2
Loading...
Searching...
No Matches
gradcdac.h
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/* ADC / DAC (GRADCDAC) interface
4 *
5 * COPYRIGHT (c) 2009.
6 * Cobham Gaisler AB.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef __GRADCDAC_H__
31#define __GRADCDAC_H__
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
38 volatile unsigned int config; /* 0x00 Configuration Register */
39 volatile unsigned int status; /* 0x04 Status Register */
40 int unused0[2];
41 volatile unsigned int adc_din; /* 0x10 ADC Data Input Register */
42 volatile unsigned int dac_dout; /* 0x14 DAC Data Output Register */
43 int unused1[2];
44 volatile unsigned int adrin; /* 0x20 Address Input Register */
45 volatile unsigned int adrout; /* 0x24 Address Output Register */
46 volatile unsigned int adrdir; /* 0x28 Address Direction Register */
47 int unused2[1];
48 volatile unsigned int data_in; /* 0x30 Data Input Register */
49 volatile unsigned int data_out; /* 0x34 Data Output Register */
50 volatile unsigned int data_dir; /* 0x38 Data Direction Register */
51};
52
53#define GRADCDAC_CFG_DACWS 0x00f80000
54#define GRADCDAC_CFG_WRPOL 0x00040000
55#define GRADCDAC_CFG_DACDW 0x00030000
56#define GRADCDAC_CFG_ADCWS 0x0000f800
57#define GRADCDAC_CFG_RCPOL 0x00000400
58#define GRADCDAC_CFG_CSMODE 0x00000300
59#define GRADCDAC_CFG_CSPOL 0x00000080
60#define GRADCDAC_CFG_RDYMODE 0x00000040
61#define GRADCDAC_CFG_RDYPOL 0x00000020
62#define GRADCDAC_CFG_TRIGPOL 0x00000010
63#define GRADCDAC_CFG_TRIGMODE 0x0000000c
64#define GRADCDAC_CFG_ADCDW 0x00000003
65
66#define GRADCDAC_CFG_DACWS_BIT 19
67#define GRADCDAC_CFG_WRPOL_BIT 18
68#define GRADCDAC_CFG_DACDW_BIT 16
69#define GRADCDAC_CFG_ADCWS_BIT 11
70#define GRADCDAC_CFG_RCPOL_BIT 10
71#define GRADCDAC_CFG_CSMODE_BIT 8
72#define GRADCDAC_CFG_CSPOL_BIT 7
73#define GRADCDAC_CFG_RDYMODE_BIT 6
74#define GRADCDAC_CFG_RDYPOL_BIT 5
75#define GRADCDAC_CFG_TRIGPOL_BIT 4
76#define GRADCDAC_CFG_TRIGMODE_BIT 2
77#define GRADCDAC_CFG_ADCDW_BIT 0
78
79#define GRADCDAC_STATUS_DACNO 0x40
80#define GRADCDAC_STATUS_DACRDY 0x20
81#define GRADCDAC_STATUS_DACON 0x10
82#define GRADCDAC_STATUS_ADCTO 0x08
83#define GRADCDAC_STATUS_ADCNO 0x04
84#define GRADCDAC_STATUS_ADCRDY 0x02
85#define GRADCDAC_STATUS_ADCON 0x01
86
87#define GRADCDAC_STATUS_DACNO_BIT 6
88#define GRADCDAC_STATUS_DACRDY_BIT 5
89#define GRADCDAC_STATUS_DACON_BIT 4
90#define GRADCDAC_STATUS_ADCTO_BIT 3
91#define GRADCDAC_STATUS_ADCNO_BIT 2
92#define GRADCDAC_STATUS_ADCRDY_BIT 1
93#define GRADCDAC_STATUS_ADCON_BIT 0
94
95#define GRADCDAC_IRQ_DAC 1
96#define GRADCDAC_IRQ_ADC 0
97
99 unsigned char dac_ws;
100 char wr_pol;
101 unsigned char dac_dw;
102 unsigned char adc_ws;
103 char rc_pol;
104 unsigned char cs_mode;
105 char cs_pol;
106 char ready_mode;
107 char ready_pol;
108 char trigg_pol;
109 unsigned char trigg_mode;
110 unsigned char adc_dw;
111};
112
113extern void *gradcdac_open(char *devname);
114
115extern void gradcdac_set_config(void *cookie, struct gradcdac_config *cfg);
116
117extern void gradcdac_get_config(void *cookie, struct gradcdac_config *cfg);
118
119extern void gradcdac_set_cfg(void *cookie, unsigned int config);
120
121extern unsigned int gradcdac_get_cfg(void *cookie);
122
123extern unsigned int gradcdac_get_status(void *cookie);
124
125static int __inline__ gradcdac_DAC_ReqRej(unsigned int status)
126{
127 return (status & GRADCDAC_STATUS_DACNO);
128}
129
130static int __inline__ gradcdac_DAC_isCompleted(unsigned int status)
131{
132 return (status & GRADCDAC_STATUS_DACRDY);
133}
134
135static int __inline__ gradcdac_DAC_isOngoing(unsigned int status)
136{
137 return (status & GRADCDAC_STATUS_DACON);
138}
139
140static int __inline__ gradcdac_ADC_isTimeouted(unsigned int status)
141{
142 return (status & GRADCDAC_STATUS_ADCTO);
143}
144
145static int __inline__ gradcdac_ADC_ReqRej(unsigned int status)
146{
147 return (status & GRADCDAC_STATUS_ADCNO);
148}
149
150static int __inline__ gradcdac_ADC_isCompleted(unsigned int status)
151{
152 return (status & GRADCDAC_STATUS_ADCRDY);
153}
154
155static int __inline__ gradcdac_ADC_isOngoing(unsigned int status)
156{
157 return (status & GRADCDAC_STATUS_ADCON);
158}
159
160#define GRADCDAC_ISR_BOTH 3
161#define GRADCDAC_ISR_DAC 2
162#define GRADCDAC_ISR_ADC 1
163
164/* Install IRQ handler for ADC and/or DAC interrupt.
165 * The installed IRQ handler(ISR) must read the status
166 * register to clear the pending interrupt avoiding multiple
167 * entries to the ISR caused by the same IRQ.
168 *
169 * \param adc 1=ADC interrupt, 2=ADC interrupt, 3=ADC and DAC interrupt
170 * \param isr Interrupt service routine called when IRQ is fired
171 * \param arg custom argument passed to ISR when called.
172 */
173extern int gradcdac_install_irq_handler
174 (void *cookie, int adc, void (*isr)(void *cookie, void *arg), void *arg);
175
176extern void gradcdac_uninstall_irq_handler(void *cookie, int adc);
177
178/* Make the ADC circuitry initialize a analogue to digital
179 * conversion. The result can be read out by gradcdac_adc_convert_try
180 * or gradcdac_adc_convert.
181 */
182extern void gradcdac_adc_convert_start(void *cookie);
183
184/* Tries to read the conversion result. If the circuitry is busy
185 * converting the function return a non-zero value, if the conversion
186 * has successfully finished the function return zero.
187 *
188 * \param digital_value the resulting converted value is placed here
189 * \return zero = ADC conversion complete, digital_value contain current conversion result
190 * positive = ADC busy, digital_value contain previous conversion result
191 * negative = Conversion request failed.
192 */
193extern int gradcdac_adc_convert_try(void *cookie, unsigned short *digital_value);
194
195/* Waits until the ADC circuity has finished a digital to analogue
196 * conversion. The Waiting is implemented as a busy loop utilizing
197 * 100% CPU load.
198 *
199 * \return zero = Conversion ok
200 * negative = Conversion request failed.
201 */
202extern int gradcdac_adc_convert(void *cookie, unsigned short *digital_value);
203
204/* Try to make the DAC circuitry initialize a digital to analogue
205 * conversion. If the circuitry is busy by a previous conversion
206 * the function return a non-zero value, if the conversion is
207 * successfully initialized the function return zero.
208 */
209extern int gradcdac_dac_convert_try(void *cookie, unsigned short digital_value);
210
211/* Initializes a digital to analogue conversion by waiting until
212 * previous conversions is finished before procceding with the
213 * conversion. The Waiting is implemented as a busy loop utilizing
214 * 100% CPU load.
215 */
216extern void gradcdac_dac_convert(void *cookie, unsigned short digital_value);
217
218extern unsigned int gradcdac_get_adrinput(void *cookie);
219extern void gradcdac_set_adrinput(void *cookie, unsigned int input);
220
221extern unsigned int gradcdac_get_adroutput(void *cookie);
222extern void gradcdac_set_adroutput(void *cookie, unsigned int output);
223
224extern unsigned int gradcdac_get_adrdir(void *cookie);
225extern void gradcdac_set_adrdir(void *cookie, unsigned int dir);
226
227extern unsigned int gradcdac_get_datainput(void *cookie);
228extern void gradcdac_set_datainput(void *cookie, unsigned int input);
229
230extern unsigned int gradcdac_get_dataoutput(void *cookie);
231extern void gradcdac_set_dataoutput(void *cookie, unsigned int output);
232
233extern unsigned int gradcdac_get_datadir(void *cookie);
234extern void gradcdac_set_datadir(void *cookie, unsigned int dir);
235
236/* Show one or all GRADCDAC cores. If cookie is NULL all GRADCDAC's are shown */
237extern void grAdcDacShow(void *cookie);
238
239/* Register Driver routine */
240extern void gradcdac_register_drv (void);
241
242#ifdef __cplusplus
243}
244#endif
245
246#endif
Definition: deflate.c:114
Definition: gradcdac.h:98
Definition: gradcdac.h:37