@ -240,6 +240,7 @@ extern w25q80bv_driver_t spi_flash;
|
||||
extern sgpio_config_t sgpio_config;
|
||||
extern rf_path_t rf_path;
|
||||
extern jtag_t jtag_cpld;
|
||||
extern i2c_bus_t i2c0;
|
||||
|
||||
void cpu_clock_init(void);
|
||||
void cpu_clock_pll1_low_speed(void);
|
||||
|
@ -44,17 +44,23 @@ void i2c_lpc_transfer(i2c_bus_t* const bus,
|
||||
uint8_t* const data_rx, const size_t count_rx
|
||||
) {
|
||||
const uint32_t port = (uint32_t)bus->obj;
|
||||
i2c_tx_start(port);
|
||||
i2c_tx_byte(port, (slave_address << 1) | I2C_WRITE);
|
||||
for(size_t i=0; i<count_tx; i++) {
|
||||
i2c_tx_byte(port, data_tx[i]);
|
||||
size_t i;
|
||||
bool ack = false;
|
||||
if (data_tx && (count_tx > 0)) {
|
||||
i2c_tx_start(port);
|
||||
i2c_tx_byte(port, (slave_address << 1) | I2C_WRITE);
|
||||
for(i=0; i<count_tx; i++) {
|
||||
i2c_tx_byte(port, data_tx[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if( data_rx ) {
|
||||
if (data_rx && (count_rx > 0)) {
|
||||
i2c_tx_start(port);
|
||||
i2c_tx_byte(port, (slave_address << 1) | I2C_READ);
|
||||
for(size_t i=0; i<count_rx; i++) {
|
||||
data_rx[i] = i2c_rx_byte(port);
|
||||
for(i=0; i<count_rx; i++) {
|
||||
/* ACK each byte except the last */
|
||||
ack = (i!=count_rx-1);
|
||||
data_rx[i] = i2c_rx_byte(port, ack);
|
||||
}
|
||||
}
|
||||
|
||||
|
146
firmware/common/operacake.c
Normal file
146
firmware/common/operacake.c
Normal file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright 2016 Dominic Spill <dominicgs@gmail.com>
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* 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, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* 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; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "operacake.h"
|
||||
#include "hackrf_core.h"
|
||||
|
||||
#define OPERACAKE_PIN_OE(x) (x<<7)
|
||||
#define OPERACAKE_PIN_U2CTRL1(x) (x<<6)
|
||||
#define OPERACAKE_PIN_U2CTRL0(x) (x<<5)
|
||||
#define OPERACAKE_PIN_U3CTRL1(x) (x<<4)
|
||||
#define OPERACAKE_PIN_U3CTRL0(x) (x<<3)
|
||||
#define OPERACAKE_PIN_U1CTRL(x) (x<<2)
|
||||
#define OPERACAKE_PIN_LEDEN2(x) (x<<1)
|
||||
#define OPERACAKE_PIN_LEDEN(x) (x<<0)
|
||||
|
||||
#define OPERACAKE_PORT_A1 (OPERACAKE_PIN_U2CTRL0(0) | OPERACAKE_PIN_U2CTRL1(0))
|
||||
#define OPERACAKE_PORT_A2 (OPERACAKE_PIN_U2CTRL0(1) | OPERACAKE_PIN_U2CTRL1(0))
|
||||
#define OPERACAKE_PORT_A3 (OPERACAKE_PIN_U2CTRL0(0) | OPERACAKE_PIN_U2CTRL1(1))
|
||||
#define OPERACAKE_PORT_A4 (OPERACAKE_PIN_U2CTRL0(1) | OPERACAKE_PIN_U2CTRL1(1))
|
||||
|
||||
#define OPERACAKE_PORT_B1 (OPERACAKE_PIN_U3CTRL0(0) | OPERACAKE_PIN_U3CTRL1(0))
|
||||
#define OPERACAKE_PORT_B2 (OPERACAKE_PIN_U3CTRL0(1) | OPERACAKE_PIN_U3CTRL1(0))
|
||||
#define OPERACAKE_PORT_B3 (OPERACAKE_PIN_U3CTRL0(0) | OPERACAKE_PIN_U3CTRL1(1))
|
||||
#define OPERACAKE_PORT_B4 (OPERACAKE_PIN_U3CTRL0(1) | OPERACAKE_PIN_U3CTRL1(1))
|
||||
|
||||
#define OPERACAKE_SAMESIDE OPERACAKE_PIN_U1CTRL(1)
|
||||
#define OPERACAKE_CROSSOVER OPERACAKE_PIN_U1CTRL(0)
|
||||
#define OPERACAKE_EN_LEDS (OPERACAKE_PIN_LEDEN2(1) | OPERACAKE_PIN_LEDEN2(0))
|
||||
#define OPERACAKE_GPIO_EN OPERACAKE_PIN_OE(0)
|
||||
#define OPERACAKE_GPIO_DISABLE OPERACAKE_PIN_OE(1)
|
||||
|
||||
#define OPERACAKE_REG_INPUT 0x00
|
||||
#define OPERACAKE_REG_OUTPUT 0x01
|
||||
#define OPERACAKE_REG_POLARITY 0x02
|
||||
#define OPERACAKE_REG_CONFIG 0x03
|
||||
|
||||
#define OPERACAKE_DEFAULT_OUTPUT (OPERACAKE_GPIO_DISABLE | OPERACAKE_SAMESIDE \
|
||||
| OPERACAKE_PORT_A1 | OPERACAKE_PORT_B1 \
|
||||
| OPERACAKE_EN_LEDS)
|
||||
#define OPERACAKE_CONFIG_ALL_OUTPUT (0x00)
|
||||
|
||||
#define OPERACAKE_DEFAULT_ADDRESS 0x18
|
||||
|
||||
i2c_bus_t* const oc_bus = &i2c0;
|
||||
uint8_t operacake_boards[8] = {0,0,0,0,0,0,0,0};
|
||||
|
||||
/* read single register */
|
||||
uint8_t operacake_read_reg(i2c_bus_t* const bus, uint8_t address, uint8_t reg) {
|
||||
const uint8_t data_tx[] = { reg };
|
||||
uint8_t data_rx[] = { 0x00 };
|
||||
i2c_bus_transfer(bus, address, data_tx, 1, data_rx, 1);
|
||||
return data_rx[0];
|
||||
}
|
||||
|
||||
/* Write to one of the PCA9557 registers */
|
||||
void operacake_write_reg(i2c_bus_t* const bus, uint8_t address, uint8_t reg, uint8_t value) {
|
||||
const uint8_t data[] = {reg, value};
|
||||
i2c_bus_transfer(bus, address, data, 2, NULL, 0);
|
||||
}
|
||||
|
||||
uint8_t operacake_init(void) {
|
||||
uint8_t reg, addr, i, j = 0;
|
||||
/* Find connected operacakes */
|
||||
for(i=0; i<8; i++) {
|
||||
addr = OPERACAKE_DEFAULT_ADDRESS | i;
|
||||
operacake_write_reg(oc_bus, addr, OPERACAKE_REG_OUTPUT,
|
||||
OPERACAKE_DEFAULT_OUTPUT);
|
||||
operacake_write_reg(oc_bus, addr, OPERACAKE_REG_CONFIG,
|
||||
OPERACAKE_CONFIG_ALL_OUTPUT);
|
||||
reg = operacake_read_reg(oc_bus, addr, OPERACAKE_REG_CONFIG);
|
||||
if(reg==OPERACAKE_CONFIG_ALL_OUTPUT)
|
||||
operacake_boards[j++] = addr;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t port_to_pins(uint8_t port) {
|
||||
switch(port) {
|
||||
case OPERACAKE_PA1:
|
||||
return OPERACAKE_PORT_A1;
|
||||
case OPERACAKE_PA2:
|
||||
return OPERACAKE_PORT_A2;
|
||||
case OPERACAKE_PA3:
|
||||
return OPERACAKE_PORT_A3;
|
||||
case OPERACAKE_PA4:
|
||||
return OPERACAKE_PORT_A4;
|
||||
|
||||
case OPERACAKE_PB1:
|
||||
return OPERACAKE_PORT_B1;
|
||||
case OPERACAKE_PB2:
|
||||
return OPERACAKE_PORT_B2;
|
||||
case OPERACAKE_PB3:
|
||||
return OPERACAKE_PORT_B3;
|
||||
case OPERACAKE_PB4:
|
||||
return OPERACAKE_PORT_B4;
|
||||
}
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
uint8_t operacake_set_ports(uint8_t address, uint8_t PA, uint8_t PB) {
|
||||
uint8_t side, pa, pb, reg;
|
||||
/* Start with some error checking,
|
||||
* which should have been done either
|
||||
* on the host or elsewhere in firmware
|
||||
*/
|
||||
if((PA > OPERACAKE_PB4) || (PB > OPERACAKE_PB4)) {
|
||||
return 1;
|
||||
}
|
||||
/* Check which side PA and PB are on */
|
||||
if(((PA <= OPERACAKE_PA4) && (PB <= OPERACAKE_PA4))
|
||||
|| ((PA > OPERACAKE_PA4) && (PB > OPERACAKE_PA4))) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(PA > OPERACAKE_PA4)
|
||||
side = OPERACAKE_CROSSOVER;
|
||||
else
|
||||
side = OPERACAKE_SAMESIDE;
|
||||
|
||||
pa = port_to_pins(PA);
|
||||
pb = port_to_pins(PB);
|
||||
|
||||
reg = (OPERACAKE_GPIO_DISABLE | side
|
||||
| pa | pb | OPERACAKE_EN_LEDS);
|
||||
operacake_write_reg(oc_bus, address, OPERACAKE_REG_OUTPUT, reg);
|
||||
return 0;
|
||||
}
|
||||
|
53
firmware/common/operacake.h
Normal file
53
firmware/common/operacake.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2016 Dominic Spill <dominicgs@gmail.com>
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* 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, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* 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; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __OPERACAKE_H
|
||||
#define __OPERACAKE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "i2c_bus.h"
|
||||
|
||||
#define OPERACAKE_PA1 0
|
||||
#define OPERACAKE_PA2 1
|
||||
#define OPERACAKE_PA3 2
|
||||
#define OPERACAKE_PA4 3
|
||||
|
||||
#define OPERACAKE_PB1 4
|
||||
#define OPERACAKE_PB2 5
|
||||
#define OPERACAKE_PB3 6
|
||||
#define OPERACAKE_PB4 7
|
||||
|
||||
/* Up to 8 Operacake boards can be used with one HackRF */
|
||||
extern uint8_t operacake_boards[8];
|
||||
|
||||
uint8_t operacake_init(void);
|
||||
uint8_t operacake_set_ports(uint8_t address, uint8_t PA, uint8_t PB);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __OPERACAKE_H */
|
@ -42,6 +42,8 @@ set(SRC_M4
|
||||
usb_api_register.c
|
||||
usb_api_spiflash.c
|
||||
usb_api_transceiver.c
|
||||
"${PATH_HACKRF_FIRMWARE_COMMON}/operacake.c"
|
||||
usb_api_operacake.c
|
||||
usb_api_sweep.c
|
||||
"${PATH_HACKRF_FIRMWARE_COMMON}/usb_queue.c"
|
||||
"${PATH_HACKRF_FIRMWARE_COMMON}/fault_handler.c"
|
||||
|
@ -40,6 +40,8 @@
|
||||
#include "usb_api_cpld.h"
|
||||
#include "usb_api_register.h"
|
||||
#include "usb_api_spiflash.h"
|
||||
#include "usb_api_operacake.h"
|
||||
#include "operacake.h"
|
||||
#include "usb_api_sweep.h"
|
||||
|
||||
#include "usb_api_transceiver.h"
|
||||
@ -77,6 +79,8 @@ static const usb_request_handler_fn vendor_request_handler[] = {
|
||||
usb_vendor_request_set_freq_explicit,
|
||||
usb_vendor_request_read_wcid, // USB_WCID_VENDOR_REQ
|
||||
usb_vendor_request_init_sweep,
|
||||
usb_vendor_request_operacake_get_boards,
|
||||
usb_vendor_request_operacake_set_ports
|
||||
};
|
||||
|
||||
static const uint32_t vendor_request_handler_count =
|
||||
@ -174,6 +178,7 @@ int main(void) {
|
||||
usb_run(&usb_device);
|
||||
|
||||
rf_path_init(&rf_path);
|
||||
operacake_init();
|
||||
|
||||
unsigned int phase = 0;
|
||||
|
||||
|
49
firmware/hackrf_usb/usb_api_operacake.c
Normal file
49
firmware/hackrf_usb/usb_api_operacake.c
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2016 Dominic Spill <dominicgs@gmail.com>
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* 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, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* 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; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "usb_api_operacake.h"
|
||||
#include "usb_queue.h"
|
||||
|
||||
#include <operacake.h>
|
||||
|
||||
usb_request_status_t usb_vendor_request_operacake_get_boards(
|
||||
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
|
||||
{
|
||||
if (stage == USB_TRANSFER_STAGE_SETUP) {
|
||||
usb_transfer_schedule_block(endpoint->in, operacake_boards, 8, NULL, NULL);
|
||||
usb_transfer_schedule_ack(endpoint->out);
|
||||
}
|
||||
return USB_REQUEST_STATUS_OK;
|
||||
}
|
||||
|
||||
usb_request_status_t usb_vendor_request_operacake_set_ports(
|
||||
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
|
||||
{
|
||||
uint8_t address, port_a, port_b;
|
||||
address = endpoint->setup.value & 0xFF;
|
||||
port_a = endpoint->setup.index & 0xFF;
|
||||
port_b = (endpoint->setup.index >> 8) & 0xFF;
|
||||
if (stage == USB_TRANSFER_STAGE_SETUP) {
|
||||
operacake_set_ports(address, port_a, port_b);
|
||||
usb_transfer_schedule_ack(endpoint->in);
|
||||
}
|
||||
return USB_REQUEST_STATUS_OK;
|
||||
}
|
34
firmware/hackrf_usb/usb_api_operacake.h
Normal file
34
firmware/hackrf_usb/usb_api_operacake.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2016 Dominic Spill <dominicgs@gmail.com>
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* 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, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* 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; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __USB_API_OPERACAKE_H__
|
||||
#define __USB_API_OPERACAKE_H__
|
||||
|
||||
#include <usb_type.h>
|
||||
#include <usb_request.h>
|
||||
|
||||
usb_request_status_t usb_vendor_request_operacake_get_boards(
|
||||
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);
|
||||
|
||||
usb_request_status_t usb_vendor_request_operacake_set_ports(
|
||||
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage);
|
||||
|
||||
#endif /* end of include guard: __USB_API_OPERACAKE_H__ */
|
Submodule firmware/libopencm3 updated: 50c51c7b5f...0ca8913944
@ -40,6 +40,7 @@ SET(TOOLS
|
||||
hackrf_spiflash
|
||||
hackrf_cpldjtag
|
||||
hackrf_info
|
||||
hackrf_operacake
|
||||
hackrf_sweep
|
||||
)
|
||||
|
||||
|
@ -32,9 +32,10 @@ int main(void)
|
||||
uint8_t board_id = BOARD_ID_INVALID;
|
||||
char version[255 + 1];
|
||||
read_partid_serialno_t read_partid_serialno;
|
||||
uint8_t operacakes[8];
|
||||
hackrf_device_list_t *list;
|
||||
hackrf_device* device;
|
||||
int i;
|
||||
int i, j;
|
||||
|
||||
result = hackrf_init();
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
@ -98,7 +99,20 @@ int main(void)
|
||||
read_partid_serialno.serial_no[1],
|
||||
read_partid_serialno.serial_no[2],
|
||||
read_partid_serialno.serial_no[3]);
|
||||
|
||||
|
||||
result = hackrf_get_operacake_boards(device, &operacakes[0]);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_get_operacake_boards() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
for(j=0; j<8; j++) {
|
||||
if(operacakes[j] == 0)
|
||||
break;
|
||||
printf("Operacake found, address: 0x%02x\n", operacakes[j]);
|
||||
|
||||
}
|
||||
|
||||
result = hackrf_close(device);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_close() failed: %s (%d)\n",
|
||||
|
158
host/hackrf-tools/src/hackrf_operacake.c
Normal file
158
host/hackrf-tools/src/hackrf_operacake.c
Normal file
@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright 2016 Dominic Spill <dominicgs@gmail.com>
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* 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, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* 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; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <hackrf.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#ifndef bool
|
||||
typedef int bool;
|
||||
#define true 1
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
static void usage() {
|
||||
printf("\nUsage:\n");
|
||||
printf("\t-s, --serial <s>: specify a particular device by serial number\n");
|
||||
printf("\t-d, --device <n>: specify a particular device by number\n");
|
||||
printf("\t-o, --address <n>: specify a particular operacake by address [default: 0x00]\n");
|
||||
printf("\t-a <n>: set port A connection\n");
|
||||
printf("\t-b <n>: set port B connection\n");
|
||||
printf("\t-v: verbose, list available operacake boards\n");
|
||||
}
|
||||
|
||||
static struct option long_options[] = {
|
||||
{ "device", no_argument, 0, 'd' },
|
||||
{ "serial", no_argument, 0, 's' },
|
||||
{ "address", no_argument, 0, 'o' },
|
||||
{ 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
int parse_int(char* const s, uint16_t* const value) {
|
||||
char* s_end = s;
|
||||
const long long_value = strtol(s, &s_end, 10);
|
||||
if( (s != s_end) && (*s_end == 0) ) {
|
||||
*value = (uint16_t)long_value;
|
||||
return HACKRF_SUCCESS;
|
||||
} else {
|
||||
return HACKRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int opt;
|
||||
const char* serial_number = NULL;
|
||||
int device_index = 0;
|
||||
int operacake_address = 0;
|
||||
int port_a = 0;
|
||||
int port_b = 0;
|
||||
int verbose = 0;
|
||||
uint8_t operacakes[8];
|
||||
int i = 0;
|
||||
hackrf_device* device = NULL;
|
||||
int option_index = 0;
|
||||
|
||||
int result = hackrf_init();
|
||||
if( result ) {
|
||||
printf("hackrf_init() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while( (opt = getopt_long(argc, argv, "d:s:o:a:b:v", long_options, &option_index)) != EOF ) {
|
||||
switch( opt ) {
|
||||
case 'd':
|
||||
device_index = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 's':
|
||||
serial_number = optarg;
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
operacake_address = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
port_a = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
port_b = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
printf("argument error: %s (%d)\n", hackrf_error_name(result), result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(serial_number != NULL) {
|
||||
result = hackrf_open_by_serial(serial_number, &device);
|
||||
} else {
|
||||
hackrf_device_list_t* device_list = hackrf_device_list();
|
||||
if(device_list->devicecount <= 0) {
|
||||
result = HACKRF_ERROR_NOT_FOUND;
|
||||
} else {
|
||||
result = hackrf_device_list_open(device_list, device_index, &device);
|
||||
}
|
||||
}
|
||||
|
||||
if( result ) {
|
||||
printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(verbose) {
|
||||
hackrf_get_operacake_boards(device, operacakes);
|
||||
printf("Operacakes found:\n");
|
||||
for(i=0; i<8; i++) {
|
||||
if(operacakes[i] !=0)
|
||||
printf("%d\n", operacakes[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
result = hackrf_set_operacake_ports(device, operacake_address, port_a, port_b);
|
||||
if( result ) {
|
||||
printf("hackrf_set_operacake_ports() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = hackrf_close(device);
|
||||
if( result ) {
|
||||
printf("hackrf_close() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
hackrf_exit();
|
||||
|
||||
return 0;
|
||||
}
|
@ -69,6 +69,8 @@ typedef enum {
|
||||
HACKRF_VENDOR_REQUEST_SET_FREQ_EXPLICIT = 24,
|
||||
// USB_WCID_VENDOR_REQ = 25
|
||||
HACKRF_VENDOR_REQUEST_INIT_SWEEP = 26,
|
||||
HACKRF_VENDOR_REQUEST_OPERACAKE_GET_BOARDS = 27,
|
||||
HACKRF_VENDOR_REQUEST_OPERACAKE_SET_PORTS = 28,
|
||||
} hackrf_vendor_request;
|
||||
|
||||
typedef enum {
|
||||
@ -1698,6 +1700,7 @@ uint32_t ADDCALL hackrf_compute_baseband_filter_bw(const uint32_t bandwidth_hz)
|
||||
return p->bandwidth_hz;
|
||||
}
|
||||
|
||||
/* Initialise sweep mode with alist of frequencies and dwell time in samples */
|
||||
int ADDCALL hackrf_init_sweep(hackrf_device* device, uint16_t* frequency_list, int length, uint32_t dwell_time)
|
||||
{
|
||||
int result, i;
|
||||
@ -1724,6 +1727,65 @@ int ADDCALL hackrf_init_sweep(hackrf_device* device, uint16_t* frequency_list, i
|
||||
}
|
||||
}
|
||||
|
||||
/* Retrieve list of Operacake board addresses
|
||||
* boards must be *uint8_t[8]
|
||||
*/
|
||||
int ADDCALL hackrf_get_operacake_boards(hackrf_device* device, uint8_t* boards)
|
||||
{
|
||||
int result;
|
||||
result = libusb_control_transfer(
|
||||
device->usb_device,
|
||||
LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
|
||||
HACKRF_VENDOR_REQUEST_OPERACAKE_GET_BOARDS,
|
||||
0,
|
||||
0,
|
||||
boards,
|
||||
8,
|
||||
0
|
||||
);
|
||||
|
||||
if (result < 8)
|
||||
{
|
||||
return HACKRF_ERROR_LIBUSB;
|
||||
} else {
|
||||
return HACKRF_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set Operacake ports */
|
||||
int ADDCALL hackrf_set_operacake_ports(hackrf_device* device,
|
||||
uint8_t address,
|
||||
uint8_t port_a,
|
||||
uint8_t port_b)
|
||||
{
|
||||
int result;
|
||||
/* Error checking */
|
||||
if((port_a > OPERACAKE_PB4) || (port_b > OPERACAKE_PB4)) {
|
||||
return HACKRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
/* Check which side PA and PB are on */
|
||||
if(((port_a <= OPERACAKE_PA4) && (port_b <= OPERACAKE_PA4))
|
||||
|| ((port_a > OPERACAKE_PA4) && (port_b > OPERACAKE_PA4))) {
|
||||
return HACKRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
result = libusb_control_transfer(
|
||||
device->usb_device,
|
||||
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
|
||||
HACKRF_VENDOR_REQUEST_OPERACAKE_SET_PORTS,
|
||||
address,
|
||||
port_a | (port_b<<8),
|
||||
NULL,
|
||||
0,
|
||||
0
|
||||
);
|
||||
|
||||
if (result != 0) {
|
||||
return HACKRF_ERROR_LIBUSB;
|
||||
} else {
|
||||
return HACKRF_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // __cplusplus defined.
|
||||
#endif
|
||||
|
@ -83,6 +83,17 @@ enum rf_path_filter {
|
||||
RF_PATH_FILTER_HIGH_PASS = 2,
|
||||
};
|
||||
|
||||
enum operacake_ports {
|
||||
OPERACAKE_PA1 = 0,
|
||||
OPERACAKE_PA2 = 1,
|
||||
OPERACAKE_PA3 = 2,
|
||||
OPERACAKE_PA4 = 3,
|
||||
OPERACAKE_PB1 = 4,
|
||||
OPERACAKE_PB2 = 5,
|
||||
OPERACAKE_PB3 = 6,
|
||||
OPERACAKE_PB4 = 7,
|
||||
};
|
||||
|
||||
typedef struct hackrf_device hackrf_device;
|
||||
|
||||
typedef struct {
|
||||
@ -201,6 +212,13 @@ extern ADDAPI int ADDCALL hackrf_init_sweep(hackrf_device* device,
|
||||
uint16_t* frequency_list,
|
||||
int length, uint32_t dwell_time);
|
||||
|
||||
/* Operacake functions */
|
||||
int ADDCALL hackrf_get_operacake_boards(hackrf_device* device, uint8_t* boards);
|
||||
int ADDCALL hackrf_set_operacake_ports(hackrf_device* device,
|
||||
uint8_t address,
|
||||
uint8_t port_a,
|
||||
uint8_t port_b);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // __cplusplus defined.
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user