Add vendor request for enabling/disabling gpio-based sync
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,6 +5,7 @@
|
|||||||
*.hex
|
*.hex
|
||||||
*.srec
|
*.srec
|
||||||
host/build/
|
host/build/
|
||||||
|
host/**/build
|
||||||
|
|
||||||
# Operating system spew
|
# Operating system spew
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
@ -225,6 +225,11 @@ typedef enum {
|
|||||||
TRANSCEIVER_MODE_CPLD_UPDATE = 4
|
TRANSCEIVER_MODE_CPLD_UPDATE = 4
|
||||||
} transceiver_mode_t;
|
} transceiver_mode_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
HW_SYNC_MODE_OFF = 0,
|
||||||
|
HW_SYNC_MODE_ON = 1,
|
||||||
|
} hw_sync_mode_t;
|
||||||
|
|
||||||
void delay(uint32_t duration);
|
void delay(uint32_t duration);
|
||||||
|
|
||||||
/* TODO: Hide these configurations */
|
/* TODO: Hide these configurations */
|
||||||
|
@ -46,6 +46,11 @@
|
|||||||
#include "usb_bulk_buffer.h"
|
#include "usb_bulk_buffer.h"
|
||||||
|
|
||||||
static volatile transceiver_mode_t _transceiver_mode = TRANSCEIVER_MODE_OFF;
|
static volatile transceiver_mode_t _transceiver_mode = TRANSCEIVER_MODE_OFF;
|
||||||
|
static volatile hw_sync_mode_t _hw_sync_mode = HW_SYNC_MODE_OFF;
|
||||||
|
|
||||||
|
void set_hw_sync_mode(const hw_sync_mode_t new_hw_sync_mode) {
|
||||||
|
_hw_sync_mode = new_hw_sync_mode;
|
||||||
|
}
|
||||||
|
|
||||||
void set_transceiver_mode(const transceiver_mode_t new_transceiver_mode) {
|
void set_transceiver_mode(const transceiver_mode_t new_transceiver_mode) {
|
||||||
baseband_streaming_disable(&sgpio_config);
|
baseband_streaming_disable(&sgpio_config);
|
||||||
@ -76,11 +81,16 @@ void set_transceiver_mode(const transceiver_mode_t new_transceiver_mode) {
|
|||||||
hw_sync_stop();
|
hw_sync_stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hw_sync_stop();
|
||||||
|
|
||||||
if( _transceiver_mode != TRANSCEIVER_MODE_OFF ) {
|
if( _transceiver_mode != TRANSCEIVER_MODE_OFF ) {
|
||||||
si5351c_activate_best_clock_source(&clock_gen);
|
si5351c_activate_best_clock_source(&clock_gen);
|
||||||
|
|
||||||
hw_sync_stop();
|
if( _hw_sync_mode != HW_SYNC_MODE_OFF) {
|
||||||
hw_sync_syn();
|
hw_sync_syn();
|
||||||
|
} else {
|
||||||
|
baseband_streaming_enable(&sgpio_config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +98,19 @@ transceiver_mode_t transceiver_mode(void) {
|
|||||||
return _transceiver_mode;
|
return _transceiver_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usb_request_status_t usb_vendor_request_set_hw_sync_mode(
|
||||||
|
usb_endpoint_t* const endpoint,
|
||||||
|
const usb_transfer_stage_t stage
|
||||||
|
) {
|
||||||
|
if( stage == USB_TRANSFER_STAGE_SETUP ) {
|
||||||
|
set_hw_sync_mode(endpoint->setup.value);
|
||||||
|
usb_transfer_schedule_ack(endpoint->in);
|
||||||
|
return USB_REQUEST_STATUS_OK;
|
||||||
|
} else {
|
||||||
|
return USB_REQUEST_STATUS_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
usb_request_status_t usb_vendor_request_set_transceiver_mode(
|
usb_request_status_t usb_vendor_request_set_transceiver_mode(
|
||||||
usb_endpoint_t* const endpoint,
|
usb_endpoint_t* const endpoint,
|
||||||
const usb_transfer_stage_t stage
|
const usb_transfer_stage_t stage
|
||||||
@ -144,6 +167,7 @@ static const usb_request_handler_fn vendor_request_handler[] = {
|
|||||||
#endif
|
#endif
|
||||||
usb_vendor_request_set_freq_explicit,
|
usb_vendor_request_set_freq_explicit,
|
||||||
usb_vendor_request_read_wcid, // USB_WCID_VENDOR_REQ
|
usb_vendor_request_read_wcid, // USB_WCID_VENDOR_REQ
|
||||||
|
usb_vendor_request_set_hw_sync_mode,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint32_t vendor_request_handler_count =
|
static const uint32_t vendor_request_handler_count =
|
||||||
@ -260,15 +284,14 @@ int main(void) {
|
|||||||
cpld_update();
|
cpld_update();
|
||||||
|
|
||||||
|
|
||||||
while(true) {
|
if( _hw_sync_mode != HW_SYNC_MODE_OFF) {
|
||||||
if(hw_sync_ready()) {
|
while(!hw_sync_ready()) { }
|
||||||
hw_sync_ack();
|
hw_sync_ack();
|
||||||
led_on(LED3);
|
led_on(LED3);
|
||||||
|
|
||||||
|
baseband_streaming_enable(&sgpio_config);
|
||||||
|
}
|
||||||
|
|
||||||
baseband_streaming_enable(&sgpio_config);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up IN transfer of buffer 0.
|
// Set up IN transfer of buffer 0.
|
||||||
if ( usb_bulk_buffer_offset >= 16384
|
if ( usb_bulk_buffer_offset >= 16384
|
||||||
|
@ -52,5 +52,7 @@ usb_request_status_t usb_vendor_request_set_antenna_enable(
|
|||||||
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);
|
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);
|
||||||
usb_request_status_t usb_vendor_request_set_freq_explicit(
|
usb_request_status_t usb_vendor_request_set_freq_explicit(
|
||||||
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);
|
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);
|
||||||
|
usb_request_status_t usb_vendor_request_set_hw_sync_mode(
|
||||||
|
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);
|
||||||
|
|
||||||
#endif/*__USB_API_TRANSCEIVER_H__*/
|
#endif/*__USB_API_TRANSCEIVER_H__*/
|
||||||
|
@ -114,6 +114,11 @@ typedef enum {
|
|||||||
TRANSCEIVER_MODE_SS = 3,
|
TRANSCEIVER_MODE_SS = 3,
|
||||||
} transceiver_mode_t;
|
} transceiver_mode_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
HW_SYNC_MODE_OFF = 0,
|
||||||
|
HW_SYNC_MODE_ON = 1,
|
||||||
|
} hw_sync_mode_t;
|
||||||
|
|
||||||
/* WAVE or RIFF WAVE file format containing IQ 2x8bits data for HackRF compatible with SDR# Wav IQ file */
|
/* WAVE or RIFF WAVE file format containing IQ 2x8bits data for HackRF compatible with SDR# Wav IQ file */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@ -303,6 +308,8 @@ volatile uint32_t byte_count = 0;
|
|||||||
bool signalsource = false;
|
bool signalsource = false;
|
||||||
uint32_t amplitude = 0;
|
uint32_t amplitude = 0;
|
||||||
|
|
||||||
|
bool hw_sync = false;
|
||||||
|
|
||||||
bool receive = false;
|
bool receive = false;
|
||||||
bool receive_wav = false;
|
bool receive_wav = false;
|
||||||
|
|
||||||
@ -463,6 +470,7 @@ static void usage() {
|
|||||||
printf("\t[-R] # Repeat TX mode (default is off) \n");
|
printf("\t[-R] # Repeat TX mode (default is off) \n");
|
||||||
printf("\t[-b baseband_filter_bw_hz] # Set baseband filter bandwidth in Hz.\n\tPossible values: 1.75/2.5/3.5/5/5.5/6/7/8/9/10/12/14/15/20/24/28MHz, default < sample_rate_hz.\n" );
|
printf("\t[-b baseband_filter_bw_hz] # Set baseband filter bandwidth in Hz.\n\tPossible values: 1.75/2.5/3.5/5/5.5/6/7/8/9/10/12/14/15/20/24/28MHz, default < sample_rate_hz.\n" );
|
||||||
printf("\t[-C ppm] # Set Internal crystal clock error in ppm.\n");
|
printf("\t[-C ppm] # Set Internal crystal clock error in ppm.\n");
|
||||||
|
printf("\t[-H] # Synchronise USB transfer using GPIO pins.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static hackrf_device* device = NULL;
|
static hackrf_device* device = NULL;
|
||||||
@ -506,11 +514,14 @@ int main(int argc, char** argv) {
|
|||||||
float time_diff;
|
float time_diff;
|
||||||
unsigned int lna_gain=8, vga_gain=20, txvga_gain=0;
|
unsigned int lna_gain=8, vga_gain=20, txvga_gain=0;
|
||||||
|
|
||||||
while( (opt = getopt(argc, argv, "wr:t:f:i:o:m:a:p:s:n:b:l:g:x:c:d:C:R")) != EOF )
|
while( (opt = getopt(argc, argv, "Hwr:t:f:i:o:m:a:p:s:n:b:l:g:x:c:d:C:R")) != EOF )
|
||||||
{
|
{
|
||||||
result = HACKRF_SUCCESS;
|
result = HACKRF_SUCCESS;
|
||||||
switch( opt )
|
switch( opt )
|
||||||
{
|
{
|
||||||
|
case 'H':
|
||||||
|
hw_sync = true;
|
||||||
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
receive_wav = true;
|
receive_wav = true;
|
||||||
break;
|
break;
|
||||||
@ -917,6 +928,15 @@ int main(int argc, char** argv) {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "call hackrf_set_hw_sync_mode(%d)\n",
|
||||||
|
hw_sync);
|
||||||
|
result = hackrf_set_hw_sync_mode(device, hw_sync ? HW_SYNC_MODE_ON : HW_SYNC_MODE_OFF);
|
||||||
|
if( result != HACKRF_SUCCESS ) {
|
||||||
|
fprintf(stderr, "hackrf_set_hw_sync_mode() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||||
|
usage();
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
if( transceiver_mode == TRANSCEIVER_MODE_RX ) {
|
if( transceiver_mode == TRANSCEIVER_MODE_RX ) {
|
||||||
result = hackrf_set_vga_gain(device, vga_gain);
|
result = hackrf_set_vga_gain(device, vga_gain);
|
||||||
result |= hackrf_set_lna_gain(device, lna_gain);
|
result |= hackrf_set_lna_gain(device, lna_gain);
|
||||||
|
@ -67,6 +67,7 @@ typedef enum {
|
|||||||
HACKRF_VENDOR_REQUEST_SET_TXVGA_GAIN = 21,
|
HACKRF_VENDOR_REQUEST_SET_TXVGA_GAIN = 21,
|
||||||
HACKRF_VENDOR_REQUEST_ANTENNA_ENABLE = 23,
|
HACKRF_VENDOR_REQUEST_ANTENNA_ENABLE = 23,
|
||||||
HACKRF_VENDOR_REQUEST_SET_FREQ_EXPLICIT = 24,
|
HACKRF_VENDOR_REQUEST_SET_FREQ_EXPLICIT = 24,
|
||||||
|
HACKRF_VENDOR_REQUEST_SET_HW_SYNC_MODE = 26,
|
||||||
} hackrf_vendor_request;
|
} hackrf_vendor_request;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -82,6 +83,11 @@ typedef enum {
|
|||||||
TRANSCEIVER_MODE_CPLD_UPDATE = 4,
|
TRANSCEIVER_MODE_CPLD_UPDATE = 4,
|
||||||
} hackrf_transceiver_mode;
|
} hackrf_transceiver_mode;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
HACKRF_HW_SYNC_MODE_OFF = 0,
|
||||||
|
HACKRF_HW_SYNC_MODE_ON = 1,
|
||||||
|
} hackrf_hw_sync_mode;
|
||||||
|
|
||||||
struct hackrf_device {
|
struct hackrf_device {
|
||||||
libusb_device_handle* usb_device;
|
libusb_device_handle* usb_device;
|
||||||
struct libusb_transfer** transfers;
|
struct libusb_transfer** transfers;
|
||||||
@ -1548,6 +1554,26 @@ int ADDCALL hackrf_close(hackrf_device* device)
|
|||||||
return result1;
|
return result1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ADDCALL hackrf_set_hw_sync_mode(hackrf_device* device, const uint8_t value) {
|
||||||
|
int result = libusb_control_transfer(
|
||||||
|
device->usb_device,
|
||||||
|
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
|
||||||
|
HACKRF_VENDOR_REQUEST_SET_HW_SYNC_MODE,
|
||||||
|
value,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
if( result != 0 )
|
||||||
|
{
|
||||||
|
return HACKRF_ERROR_LIBUSB;
|
||||||
|
} else {
|
||||||
|
return HACKRF_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const char* ADDCALL hackrf_error_name(enum hackrf_error errcode)
|
const char* ADDCALL hackrf_error_name(enum hackrf_error errcode)
|
||||||
{
|
{
|
||||||
switch(errcode)
|
switch(errcode)
|
||||||
|
@ -187,6 +187,9 @@ extern ADDAPI int ADDCALL hackrf_set_txvga_gain(hackrf_device* device, uint32_t
|
|||||||
/* antenna port power control */
|
/* antenna port power control */
|
||||||
extern ADDAPI int ADDCALL hackrf_set_antenna_enable(hackrf_device* device, const uint8_t value);
|
extern ADDAPI int ADDCALL hackrf_set_antenna_enable(hackrf_device* device, const uint8_t value);
|
||||||
|
|
||||||
|
/* set hardware sync mode */
|
||||||
|
extern ADDAPI int ADDCALL hackrf_set_hw_sync_mode(hackrf_device* device, const uint8_t value);
|
||||||
|
|
||||||
extern ADDAPI const char* ADDCALL hackrf_error_name(enum hackrf_error errcode);
|
extern ADDAPI const char* ADDCALL hackrf_error_name(enum hackrf_error errcode);
|
||||||
extern ADDAPI const char* ADDCALL hackrf_board_id_name(enum hackrf_board_id board_id);
|
extern ADDAPI const char* ADDCALL hackrf_board_id_name(enum hackrf_board_id board_id);
|
||||||
extern ADDAPI const char* ADDCALL hackrf_usb_board_id_name(enum hackrf_usb_board_id usb_board_id);
|
extern ADDAPI const char* ADDCALL hackrf_usb_board_id_name(enum hackrf_usb_board_id usb_board_id);
|
||||||
|
Reference in New Issue
Block a user