set_freq for firmware & host. tested basicly checking with debugger value mhz/hz from host to fw.
This commit is contained in:
@ -410,7 +410,7 @@ void enable_1v8_power(void) {
|
||||
}
|
||||
|
||||
/*
|
||||
Set freq/tuning between 30MHz to 6000 MHz
|
||||
Set freq/tuning between 30MHz to 6000 MHz (less than 16bits really used)
|
||||
hz between 0 to 999999 Hz (not checked)
|
||||
return false on error or true if success.
|
||||
*/
|
||||
|
@ -53,6 +53,15 @@ const uint_fast8_t usb_td_bulk_count = sizeof(usb_td_bulk) / sizeof(usb_td_bulk[
|
||||
uint8_t spiflash_buffer[W25Q80BV_PAGE_LEN];
|
||||
char version_string[] = VERSION_STRING;
|
||||
|
||||
typedef struct {
|
||||
uint32_t freq_mhz;
|
||||
uint32_t freq_hz;
|
||||
} set_freq_params_t;
|
||||
|
||||
set_freq_params_t set_freq_params;
|
||||
|
||||
uint8_t spiflash_buffer[W25Q80BV_PAGE_LEN];
|
||||
|
||||
uint8_t switchctrl = 0;
|
||||
|
||||
static void usb_init_buffers_bulk() {
|
||||
@ -497,17 +506,22 @@ usb_request_status_t usb_vendor_request_read_version_string(
|
||||
|
||||
usb_request_status_t usb_vendor_request_set_freq(
|
||||
usb_endpoint_t* const endpoint,
|
||||
const usb_transfer_stage_t stage
|
||||
) {
|
||||
if( stage == USB_TRANSFER_STAGE_SETUP ) {
|
||||
const uint32_t freq_mhz = (endpoint->setup.index << 16) | endpoint->setup.value;
|
||||
const uint32_t freq_hz = 0; /* TODO fix this and retrieve a 32bits */
|
||||
if( set_freq(freq_mhz, freq_hz) ) {
|
||||
const usb_transfer_stage_t stage)
|
||||
{
|
||||
if (stage == USB_TRANSFER_STAGE_SETUP)
|
||||
{
|
||||
usb_endpoint_schedule(endpoint->out, &set_freq_params, sizeof(set_freq_params_t));
|
||||
return USB_REQUEST_STATUS_OK;
|
||||
} else if (stage == USB_TRANSFER_STAGE_DATA)
|
||||
{
|
||||
if( set_freq(set_freq_params.freq_mhz, set_freq_params.freq_hz) )
|
||||
{
|
||||
usb_endpoint_schedule_ack(endpoint->in);
|
||||
return USB_REQUEST_STATUS_OK;
|
||||
}
|
||||
return USB_REQUEST_STATUS_STALL;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
return USB_REQUEST_STATUS_OK;
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +42,8 @@
|
||||
#include <sys/time.h>
|
||||
#include <signal.h>
|
||||
|
||||
#define FREQ_MIN_MHZ (30)
|
||||
#define FREQ_MAX_MHZ (6000)
|
||||
#define FREQ_MIN_HZ (30000000ull) /* 30MHz */
|
||||
#define FREQ_MAX_HZ (6000000000ull) /* 6000MHz */
|
||||
|
||||
#if defined _WIN32
|
||||
#define sleep(a) Sleep( (a*1000) )
|
||||
@ -62,7 +62,7 @@ TimevalDiff(const struct timeval *a, const struct timeval *b)
|
||||
return (a->tv_sec - b->tv_sec) + 1e-6f * (a->tv_usec - b->tv_usec);
|
||||
}
|
||||
|
||||
int parse_int(char* s, uint32_t* const value) {
|
||||
int parse_u64(char* s, uint64_t* const value) {
|
||||
uint_fast8_t base = 10;
|
||||
if( strlen(s) > 2 ) {
|
||||
if( s[0] == '0' ) {
|
||||
@ -77,9 +77,9 @@ int parse_int(char* s, uint32_t* const value) {
|
||||
}
|
||||
|
||||
char* s_end = s;
|
||||
const unsigned long ulong_value = strtoul(s, &s_end, base);
|
||||
const unsigned long long u64_value = strtoull(s, &s_end, base);
|
||||
if( (s != s_end) && (*s_end == 0) ) {
|
||||
*value = ulong_value;
|
||||
*value = u64_value;
|
||||
return HACKRF_SUCCESS;
|
||||
} else {
|
||||
return HACKRF_ERROR_INVALID_PARAM;
|
||||
@ -95,7 +95,7 @@ struct timeval time_start;
|
||||
struct timeval t_start;
|
||||
|
||||
bool freq = false;
|
||||
uint32_t freq_mhz;
|
||||
uint64_t freq_hz;
|
||||
|
||||
int rx_callback(hackrf_transfer* transfer) {
|
||||
if( fd != NULL )
|
||||
@ -135,7 +135,7 @@ static void usage() {
|
||||
printf("Usage:\n");
|
||||
printf("\t-r <filename> # Receive data into file.\n");
|
||||
printf("\t-t <filename> # Transmit data from file.\n");
|
||||
printf("\t-f <set_freq_MHz> # Set Frequency in MHz (between [%ld, %ld[).\n", FREQ_MIN_MHZ, FREQ_MAX_MHZ);
|
||||
printf("\t-f <set_freq_MHz> # Set Frequency in MHz (between [%lld, %lld[).\n", FREQ_MIN_HZ, FREQ_MAX_HZ);
|
||||
}
|
||||
|
||||
static hackrf_device* device = NULL;
|
||||
@ -216,7 +216,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
case 'f':
|
||||
freq = true;
|
||||
result = parse_int(optarg, &freq_mhz);
|
||||
result = parse_u64(optarg, &freq_hz);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -232,8 +232,8 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
if( freq ) {
|
||||
if( (freq_mhz >= 6000) || (freq_mhz < 30) )
|
||||
printf("argument error: frequency shall be between [%ld, %ld[.\n", FREQ_MIN_MHZ, FREQ_MAX_MHZ);
|
||||
if( (freq_hz >= FREQ_MAX_HZ) || (freq_hz < FREQ_MIN_HZ) )
|
||||
printf("argument error: frequency shall be between [%lld, %lld[.\n", FREQ_MIN_HZ, FREQ_MAX_HZ);
|
||||
}
|
||||
|
||||
if( transmit == receive )
|
||||
@ -312,8 +312,8 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
if( freq ) {
|
||||
printf("call hackrf_set_freq(%ld MHz)\n", freq_mhz);
|
||||
result = hackrf_set_freq(device, freq_mhz);
|
||||
printf("call hackrf_set_freq(%lld Hz)\n", freq_hz);
|
||||
result = hackrf_set_freq(device, freq_hz);
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
printf("hackrf_set_freq() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -570,20 +570,39 @@ int hackrf_version_string_read(hackrf_device* device, char* version,
|
||||
}
|
||||
}
|
||||
|
||||
int hackrf_set_freq(hackrf_device* device, const uint32_t freq_mhz) {
|
||||
/* TODO add freq_hz in addition from 0 to 999999Hz */
|
||||
typedef struct {
|
||||
uint32_t freq_mhz; /* From 30 to 6000MHz */
|
||||
uint32_t freq_hz; /* From 0 to 999999Hz */
|
||||
/* Final Freq = freq_mhz+freq_hz */
|
||||
} set_freq_params_t;
|
||||
#define FREQ_ONE_MHZ (1000*1000ull)
|
||||
|
||||
int hackrf_set_freq(hackrf_device* device, const uint64_t freq_hz)
|
||||
{
|
||||
uint32_t l_freq_mhz;
|
||||
uint32_t l_freq_hz;
|
||||
set_freq_params_t set_freq_params;
|
||||
uint8_t length;
|
||||
|
||||
/* Convert Freq Hz 64bits to Freq MHz (32bits) & Freq Hz (32bits) */
|
||||
l_freq_mhz = (uint32_t)(freq_hz / FREQ_ONE_MHZ);
|
||||
l_freq_hz = (uint32_t)(freq_hz - (((uint64_t)l_freq_mhz) * FREQ_ONE_MHZ));
|
||||
set_freq_params.freq_mhz = l_freq_mhz;
|
||||
set_freq_params.freq_hz = l_freq_hz;
|
||||
length = sizeof(set_freq_params_t);
|
||||
|
||||
int result = libusb_control_transfer(
|
||||
device->usb_device,
|
||||
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
|
||||
HACKRF_VENDOR_REQUEST_SET_FREQ,
|
||||
freq_mhz & 0xffff,
|
||||
freq_mhz >> 16,
|
||||
NULL,
|
||||
0,
|
||||
0,
|
||||
(unsigned char*)&set_freq_params,
|
||||
length,
|
||||
0
|
||||
);
|
||||
|
||||
if( result != 0 ) {
|
||||
if (result < length) {
|
||||
return HACKRF_ERROR_LIBUSB;
|
||||
} else {
|
||||
return HACKRF_SUCCESS;
|
||||
|
@ -93,8 +93,8 @@ int hackrf_board_id_read(hackrf_device* device, uint8_t* value);
|
||||
int hackrf_version_string_read(hackrf_device* device, char* version,
|
||||
uint8_t length);
|
||||
|
||||
int hackrf_set_freq(hackrf_device* device, const uint32_t freq_mhz);
|
||||
|
||||
int hackrf_set_freq(hackrf_device* device, const uint64_t freq_hz);
|
||||
|
||||
const char* hackrf_error_name(enum hackrf_error errcode);
|
||||
const char* hackrf_board_id_name(enum hackrf_board_id board_id);
|
||||
|
||||
|
Reference in New Issue
Block a user