Project

General

Profile

Download (7.58 KB) Statistics
| Branch: | Tag: | Revision:
1 ce0473f5 Dimitri Stolnikov
/*
2
 * Copyright (C) 2012 by Dimitri Stolnikov <horiz0n@gmx.net>
3
 * Copyright (C) 2012 by Steve Markgraf <steve@steve-m.de>
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
#ifndef __OSMOSDR_H
20
#define __OSMOSDR_H
21
22
#ifdef __cplusplus
23
extern "C" {
24
#endif
25
26
#include <stdint.h>
27
#include <osmosdr_export.h>
28
29
typedef struct osmosdr_dev osmosdr_dev_t;
30
31
OSMOSDR_API uint32_t osmosdr_get_device_count(void);
32
33
OSMOSDR_API const char* osmosdr_get_device_name(uint32_t index);
34
35 7d90bb80 Dimitri Stolnikov
/*!
36
 * Get USB device strings.
37
 *
38
 * NOTE: The string arguments must provide space for up to 256 bytes.
39
 *
40
 * \param index the device index
41
 * \param manufact manufacturer name, may be NULL
42
 * \param product product name, may be NULL
43
 * \param serial serial number, may be NULL
44
 * \return 0 on success
45
 */
46
OSMOSDR_API int osmosdr_get_device_usb_strings(uint32_t index,
47
					       char *manufact,
48
					       char *product,
49
					       char *serial);
50
51 ce0473f5 Dimitri Stolnikov
OSMOSDR_API int osmosdr_open(osmosdr_dev_t **dev, uint32_t index);
52
53
OSMOSDR_API int osmosdr_close(osmosdr_dev_t *dev);
54
55
/* configuration functions */
56
57 7d90bb80 Dimitri Stolnikov
/*!
58
 * Get USB device strings.
59
 *
60
 * NOTE: The string arguments must provide space for up to 256 bytes.
61
 *
62
 * \param dev the device handle given by osmosdr_open()
63
 * \param manufact manufacturer name, may be NULL
64
 * \param product product name, may be NULL
65
 * \param serial serial number, may be NULL
66
 * \return 0 on success
67
 */
68
OSMOSDR_API int osmosdr_get_usb_strings(osmosdr_dev_t *dev, char *manufact,
69
					char *product, char *serial);
70
71 ce0473f5 Dimitri Stolnikov
/*!
72
 * Set the frequency the device is tuned to.
73
 *
74
 * \param dev the device handle given by osmosdr_open()
75
 * \param freq frequency in Hz the device should be tuned to
76
 * \return 0 on error, frequency in Hz otherwise
77
 */
78
OSMOSDR_API int osmosdr_set_center_freq(osmosdr_dev_t *dev, uint32_t freq);
79
80
/*!
81
 * Get the actual frequency the device is tuned to.
82
 *
83
 * \param dev the device handle given by osmosdr_open()
84
 * \return 0 on error, frequency in Hz otherwise
85
 */
86
OSMOSDR_API uint32_t osmosdr_get_center_freq(osmosdr_dev_t *dev);
87
88 292a9868 Dimitri Stolnikov
/*!
89
 * Get a list of gains supported by the tuner.
90
 *
91
 * NOTE: The gains argument must be preallocated by the caller. If NULL is
92
 * being given instead, the number of available gain values will be returned.
93
 *
94
 * \param dev the device handle given by osmosdr_open()
95
 * \param gains array of gain values. In tenths of a dB, 115 means 11.5 dB.
96
 * \return <= 0 on error, number of available (returned) gain values otherwise
97
 */
98
OSMOSDR_API int osmosdr_get_tuner_gains(osmosdr_dev_t *dev, int *gains);
99
100 ce0473f5 Dimitri Stolnikov
/*!
101
 * Set the gain for the device.
102
 * Manual gain mode must be enabled for this to work.
103
 *
104
 * Valid gain values (in tenths of a dB) for the E4000 tuner:
105
 * -10, 15, 40, 65, 90, 115, 140, 165, 190,
106
 * 215, 240, 290, 340, 420, 430, 450, 470, 490
107
 *
108 292a9868 Dimitri Stolnikov
 * Valid gain values may be queried with \ref osmosdr_get_tuner_gains function.
109
 *
110 ce0473f5 Dimitri Stolnikov
 * \param dev the device handle given by osmosdr_open()
111
 * \param gain in tenths of a dB, 115 means 11.5 dB.
112
 * \return 0 on success
113
 */
114
OSMOSDR_API int osmosdr_set_tuner_gain(osmosdr_dev_t *dev, int gain);
115
116
/*!
117
 * Get actual gain the device is configured to.
118
 *
119
 * \param dev the device handle given by osmosdr_open()
120
 * \return 0 on error, gain in tenths of a dB, 115 means 11.5 dB.
121
 */
122
OSMOSDR_API int osmosdr_get_tuner_gain(osmosdr_dev_t *dev);
123
124
/*!
125
 * Set the gain mode (automatic/manual) for the device.
126
 * Manual gain mode must be enabled for the gain setter function to work.
127
 *
128
 * \param dev the device handle given by osmosdr_open()
129
 * \param manual gain mode, 1 means manual gain mode shall be enabled.
130
 * \return 0 on success
131
 */
132
OSMOSDR_API int osmosdr_set_tuner_gain_mode(osmosdr_dev_t *dev, int manual);
133
134 4eed4e78 Christian Daniel
/* set LNA gain in hdB */
135
OSMOSDR_API int osmosdr_set_tuner_lna_gain(osmosdr_dev_t *dev, int gain);
136
/* set mixer gain in hdB */
137
OSMOSDR_API int osmosdr_set_tuner_mixer_gain(osmosdr_dev_t *dev, int gain);
138
/* set mixer enhancement */
139
OSMOSDR_API int osmosdr_set_tuner_mixer_enh(osmosdr_dev_t *dev, int enh);
140
/* set IF stages gain */
141
OSMOSDR_API int osmosdr_set_tuner_if_gain(osmosdr_dev_t *dev, int stage, int gain);
142
143 a630fc08 Dimitri Stolnikov
/*!
144
 * Get a list of sample rates supported by the device.
145
 *
146
 * NOTE: The rates argument must be preallocated by the caller. If NULL is
147
 * being given instead, the number of available rate values will be returned.
148
 *
149
 * \param dev the device handle given by osmosdr_open()
150
 * \param rates array of rate values in Hz
151
 * \return <= 0 on error, number of available (returned) rate values otherwise
152
 */
153
OSMOSDR_API uint32_t osmosdr_get_sample_rates(osmosdr_dev_t *dev, uint32_t *rates);
154
155
/*!
156
 * Set the sample rate for the device.
157
 *
158
 * \param dev the device handle given by osmosdr_open()
159
 * \param rate the sample rate in Hz
160
 * \return 0 on success
161
 */
162 ce0473f5 Dimitri Stolnikov
OSMOSDR_API int osmosdr_set_sample_rate(osmosdr_dev_t *dev, uint32_t rate);
163
164
/*!
165 a630fc08 Dimitri Stolnikov
 * Get the sample rate the device is configured to.
166 ce0473f5 Dimitri Stolnikov
 *
167
 * \param dev the device handle given by osmosdr_open()
168
 * \return 0 on error, sample rate in Hz otherwise
169
 */
170
OSMOSDR_API uint32_t osmosdr_get_sample_rate(osmosdr_dev_t *dev);
171
172 4eed4e78 Christian Daniel
/* this allows direct access to the FPGA register bank */
173
OSMOSDR_API int osmosdr_set_fpga_reg(osmosdr_dev_t *dev, uint8_t reg, uint32_t value);
174
175
/* more access to OsmoSDR functions */
176
177
/* set decimation (0 = off, 1 = 1:2, 2 = 1:4, 3 = 1:8, ... 6 = 1:64) */
178
OSMOSDR_API int osmosdr_set_fpga_decimation(osmosdr_dev_t *dev, int dec);
179
180
/* set i/q swap / spectrum inversion (0 = off, 1 = on) */
181
OSMOSDR_API int osmosdr_set_fpga_iq_swap(osmosdr_dev_t *dev, int sw);
182
183
/* configure scaling of i and q channel (scaled_i = (orig_i * igain) / 32768) */
184
OSMOSDR_API int osmosdr_set_fpga_iq_gain(osmosdr_dev_t *dev, uint16_t igain, uint16_t qgain);
185
186
/* configure i and q offset correction (corrected_i = orig_i + iofs */
187
OSMOSDR_API int osmosdr_set_fpga_iq_ofs(osmosdr_dev_t *dev, int16_t iofs, int16_t qofs);
188
189 ce0473f5 Dimitri Stolnikov
/* streaming functions */
190
191 7d90bb80 Dimitri Stolnikov
OSMOSDR_API int osmosdr_reset_buffer(osmosdr_dev_t *dev);
192
193 ce0473f5 Dimitri Stolnikov
OSMOSDR_API int osmosdr_read_sync(osmosdr_dev_t *dev, void *buf, int len, int *n_read);
194
195
typedef void(*osmosdr_read_async_cb_t)(unsigned char *buf, uint32_t len, void *ctx);
196
197
/*!
198
 * Read samples from the device asynchronously. This function will block until
199
 * it is being canceled using osmosdr_cancel_async()
200
 *
201
 * \param dev the device handle given by osmosdr_open()
202
 * \param cb callback function to return received samples
203
 * \param ctx user specific context to pass via the callback function
204
 * \param buf_num optional buffer count, buf_num * buf_len = overall buffer size
205
 *		  set to 0 for default buffer count (32)
206
 * \param buf_len optional buffer length, must be multiple of 512,
207
 *		  set to 0 for default buffer length (16 * 32 * 512)
208
 * \return 0 on success
209
 */
210
OSMOSDR_API int osmosdr_read_async(osmosdr_dev_t *dev,
211
				 osmosdr_read_async_cb_t cb,
212
				 void *ctx,
213
				 uint32_t buf_num,
214
				 uint32_t buf_len);
215
216
/*!
217
 * Cancel all pending asynchronous operations on the device.
218
 *
219
 * \param dev the device handle given by osmosdr_open()
220
 * \return 0 on success
221
 */
222
OSMOSDR_API int osmosdr_cancel_async(osmosdr_dev_t *dev);
223
224
#ifdef __cplusplus
225
}
226
#endif
227
228
#endif /* __OSMOSDR_H */
Add picture from clipboard (Maximum size: 48.8 MB)