2012-03-27 19:49:44 +02:00
|
|
|
/*
|
2012-04-03 19:50:03 +02:00
|
|
|
* rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver
|
2012-03-27 19:49:44 +02:00
|
|
|
* Copyright (C) 2012 by Steve Markgraf <steve@steve-m.de>
|
2012-04-03 19:40:05 +02:00
|
|
|
* Copyright (C) 2012 by Dimitri Stolnikov <horiz0n@gmx.net>
|
2012-03-27 19:49:44 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
2012-04-03 19:40:05 +02:00
|
|
|
* (at your option) any later version.
|
2012-03-27 19:49:44 +02:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __RTL_SDR_H
|
|
|
|
#define __RTL_SDR_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2012-04-02 21:42:24 +02:00
|
|
|
#include <rtl-sdr_export.h>
|
2012-03-27 19:49:44 +02:00
|
|
|
|
2012-04-01 22:35:52 +02:00
|
|
|
typedef struct rtlsdr_dev rtlsdr_dev_t;
|
2012-03-27 19:49:44 +02:00
|
|
|
|
2012-04-02 21:42:24 +02:00
|
|
|
RTLSDR_API uint32_t rtlsdr_get_device_count(void);
|
2012-03-27 19:49:44 +02:00
|
|
|
|
2012-04-02 21:42:24 +02:00
|
|
|
RTLSDR_API const char* rtlsdr_get_device_name(uint32_t index);
|
2012-03-27 19:49:44 +02:00
|
|
|
|
2012-04-03 00:47:52 +02:00
|
|
|
RTLSDR_API int rtlsdr_open(rtlsdr_dev_t **dev, uint32_t index);
|
2012-03-27 19:49:44 +02:00
|
|
|
|
2012-04-02 21:42:24 +02:00
|
|
|
RTLSDR_API int rtlsdr_close(rtlsdr_dev_t *dev);
|
2012-03-27 19:49:44 +02:00
|
|
|
|
|
|
|
/* configuration functions */
|
|
|
|
|
2012-04-25 22:32:51 +02:00
|
|
|
/*!
|
|
|
|
* Set crystal oscillator frequencies used for the RTL2832 and the tuner IC.
|
|
|
|
*
|
|
|
|
* Usually both ICs use the same clock. Changing the clock may make sense if
|
|
|
|
* you are applying an external clock to the tuner or to compensate the
|
|
|
|
* frequency (and samplerate) error caused by the original cheap crystal.
|
|
|
|
*
|
|
|
|
* NOTE: Call this function only if you know what you are doing.
|
|
|
|
*
|
|
|
|
* \param dev the device handle given by rtlsdr_open()
|
|
|
|
* \param rtl_freq frequency value used to clock the RTL2832 in Hz
|
|
|
|
* \param tuner_freq frequency value used to clock the tuner IC in Hz
|
|
|
|
* \return 0 on success
|
|
|
|
*/
|
|
|
|
RTLSDR_API int rtlsdr_set_xtal_freq(rtlsdr_dev_t *dev, uint32_t rtl_freq,
|
|
|
|
uint32_t tuner_freq);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Get crystal oscillator frequencies used for the RTL2832 and the tuner IC.
|
|
|
|
*
|
|
|
|
* Usually both ICs use the same clock.
|
|
|
|
*
|
|
|
|
* \param dev the device handle given by rtlsdr_open()
|
|
|
|
* \param rtl_freq frequency value used to clock the RTL2832 in Hz
|
|
|
|
* \param tuner_freq frequency value used to clock the tuner IC in Hz
|
|
|
|
* \return 0 on success
|
|
|
|
*/
|
|
|
|
RTLSDR_API int rtlsdr_get_xtal_freq(rtlsdr_dev_t *dev, uint32_t *rtl_freq,
|
|
|
|
uint32_t *tuner_freq);
|
|
|
|
|
2012-04-02 21:42:24 +02:00
|
|
|
RTLSDR_API int rtlsdr_set_center_freq(rtlsdr_dev_t *dev, uint32_t freq);
|
2012-03-27 19:49:44 +02:00
|
|
|
|
2012-04-24 20:02:53 +02:00
|
|
|
/*!
|
|
|
|
* Get actual frequency the device is tuned to.
|
|
|
|
*
|
|
|
|
* \param dev the device handle given by rtlsdr_open()
|
|
|
|
* \return 0 on error, frequency in Hz otherwise
|
|
|
|
*/
|
|
|
|
RTLSDR_API uint32_t rtlsdr_get_center_freq(rtlsdr_dev_t *dev);
|
2012-03-27 19:49:44 +02:00
|
|
|
|
2012-04-02 21:42:24 +02:00
|
|
|
RTLSDR_API int rtlsdr_set_freq_correction(rtlsdr_dev_t *dev, int ppm);
|
2012-03-27 19:49:44 +02:00
|
|
|
|
2012-04-02 21:42:24 +02:00
|
|
|
RTLSDR_API int rtlsdr_get_freq_correction(rtlsdr_dev_t *dev);
|
2012-04-01 01:36:49 +02:00
|
|
|
|
2012-05-05 12:33:47 +02:00
|
|
|
/*!
|
|
|
|
* Set the gain for the device.
|
|
|
|
* Manual gain mode must be enabled for this to work.
|
|
|
|
*
|
|
|
|
* Valid gain values (in tenths of a dB) for the E4000 tuner:
|
|
|
|
* -10, 15, 40, 65, 90, 115, 140, 165, 190,
|
|
|
|
* 215, 240, 290, 340, 420, 430, 450, 470, 490
|
|
|
|
*
|
|
|
|
* \param dev the device handle given by rtlsdr_open()
|
|
|
|
* \param gain in tenths of a dB, 115 means 11.5 dB.
|
|
|
|
* \return 0 on success
|
|
|
|
*/
|
2012-04-02 21:42:24 +02:00
|
|
|
RTLSDR_API int rtlsdr_set_tuner_gain(rtlsdr_dev_t *dev, int gain);
|
2012-04-01 01:36:49 +02:00
|
|
|
|
2012-05-05 12:33:47 +02:00
|
|
|
/*!
|
|
|
|
* Get actual gain the device is configured to.
|
|
|
|
*
|
|
|
|
* \param dev the device handle given by rtlsdr_open()
|
|
|
|
* \return < 0 on error, gain in tenths of a dB, 115 means 11.5 dB.
|
|
|
|
*/
|
2012-04-02 21:42:24 +02:00
|
|
|
RTLSDR_API int rtlsdr_get_tuner_gain(rtlsdr_dev_t *dev);
|
2012-03-27 19:49:44 +02:00
|
|
|
|
2012-05-05 12:33:47 +02:00
|
|
|
/*!
|
|
|
|
* Set the gain mode (automatic/manual) for the device.
|
|
|
|
* Manual gain mode must be enabled for the gain setter function to work.
|
|
|
|
*
|
|
|
|
* \param dev the device handle given by rtlsdr_open()
|
|
|
|
* \param manual gain mode, 1 means manual gain mode shall be enabled.
|
|
|
|
* \return 0 on success
|
|
|
|
*/
|
2012-05-04 23:02:29 +02:00
|
|
|
RTLSDR_API int rtlsdr_set_tuner_gain_mode(rtlsdr_dev_t *dev, int manual);
|
|
|
|
|
2012-03-27 19:49:44 +02:00
|
|
|
/* this will select the baseband filters according to the requested sample rate */
|
2012-04-02 21:42:24 +02:00
|
|
|
RTLSDR_API int rtlsdr_set_sample_rate(rtlsdr_dev_t *dev, uint32_t rate);
|
2012-03-27 19:49:44 +02:00
|
|
|
|
2012-04-24 20:02:53 +02:00
|
|
|
/*!
|
|
|
|
* Get actual sample rate the device is configured to.
|
|
|
|
*
|
|
|
|
* \param dev the device handle given by rtlsdr_open()
|
|
|
|
* \return 0 on error, sample rate in Hz otherwise
|
|
|
|
*/
|
|
|
|
RTLSDR_API uint32_t rtlsdr_get_sample_rate(rtlsdr_dev_t *dev);
|
2012-03-27 19:49:44 +02:00
|
|
|
|
|
|
|
/* streaming functions */
|
|
|
|
|
2012-04-02 21:42:24 +02:00
|
|
|
RTLSDR_API int rtlsdr_reset_buffer(rtlsdr_dev_t *dev);
|
2012-03-27 19:49:44 +02:00
|
|
|
|
2012-04-02 21:42:24 +02:00
|
|
|
RTLSDR_API int rtlsdr_read_sync(rtlsdr_dev_t *dev, void *buf, int len, int *n_read);
|
2012-03-27 19:49:44 +02:00
|
|
|
|
2012-04-08 23:02:42 +02:00
|
|
|
typedef void(*rtlsdr_read_async_cb_t)(unsigned char *buf, uint32_t len, void *ctx);
|
2012-04-02 23:09:14 +02:00
|
|
|
|
2012-04-08 23:02:42 +02:00
|
|
|
/*!
|
|
|
|
* Read samples from the device asynchronously. This function will block until
|
|
|
|
* it is being canceled using rtlsdr_cancel_async()
|
|
|
|
*
|
|
|
|
* NOTE: This function is deprecated and is subject for removal.
|
|
|
|
*
|
|
|
|
* \param dev the device handle given by rtlsdr_open()
|
|
|
|
* \param cb callback function to return received samples
|
|
|
|
* \param ctx user specific context to pass via the callback function
|
|
|
|
* \return 0 on success
|
|
|
|
*/
|
|
|
|
RTLSDR_API int rtlsdr_wait_async(rtlsdr_dev_t *dev, rtlsdr_read_async_cb_t cb, void *ctx);
|
2012-04-02 23:09:14 +02:00
|
|
|
|
2012-04-08 23:02:42 +02:00
|
|
|
/*!
|
|
|
|
* Read samples from the device asynchronously. This function will block until
|
|
|
|
* it is being canceled using rtlsdr_cancel_async()
|
|
|
|
*
|
|
|
|
* \param dev the device handle given by rtlsdr_open()
|
|
|
|
* \param cb callback function to return received samples
|
|
|
|
* \param ctx user specific context to pass via the callback function
|
|
|
|
* \param buf_num optional buffer count, buf_num * buf_len = overall buffer size
|
|
|
|
* set to 0 for default buffer count (32)
|
2012-04-22 21:47:00 +02:00
|
|
|
* \param buf_len optional buffer length, must be multiple of 512,
|
|
|
|
* set to 0 for default buffer length (16 * 32 * 512)
|
2012-04-08 23:02:42 +02:00
|
|
|
* \return 0 on success
|
|
|
|
*/
|
|
|
|
RTLSDR_API int rtlsdr_read_async(rtlsdr_dev_t *dev,
|
|
|
|
rtlsdr_read_async_cb_t cb,
|
|
|
|
void *ctx,
|
|
|
|
uint32_t buf_num,
|
|
|
|
uint32_t buf_len);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Cancel all pending asynchronous operations on the device.
|
|
|
|
*
|
|
|
|
* \param dev the device handle given by rtlsdr_open()
|
|
|
|
* \return 0 on success
|
|
|
|
*/
|
2012-04-02 23:09:14 +02:00
|
|
|
RTLSDR_API int rtlsdr_cancel_async(rtlsdr_dev_t *dev);
|
|
|
|
|
2012-03-27 19:49:44 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __RTL_SDR_H */
|