From 6912df23ccb3d2db13387c30dfc9c88b93c317ea Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Wed, 1 Feb 2017 14:23:47 -0700 Subject: [PATCH 1/3] Shhh, silence in the library --- host/libhackrf/src/hackrf.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index e28f7012..7e3de85c 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -24,7 +24,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI #include "hackrf.h" #include - +#include #include #ifdef _WIN32 @@ -355,9 +355,6 @@ int ADDCALL hackrf_exit(void) return HACKRF_SUCCESS; } -#include -#include - hackrf_device_list_t* ADDCALL hackrf_device_list() { ssize_t i; @@ -442,8 +439,6 @@ libusb_device_handle* hackrf_open_usb(const char* const desired_serial_number) char serial_number[64]; int serial_number_length; - printf("Number of USB devices: %ld\n", list_length); - if( desired_serial_number ) { /* If a shorter serial number is specified, only match against the suffix. * Should probably complain if the match is not unique, currently doesn't. @@ -461,7 +456,6 @@ libusb_device_handle* hackrf_open_usb(const char* const desired_serial_number) if((device_descriptor.idProduct == hackrf_one_usb_pid) || (device_descriptor.idProduct == hackrf_jawbreaker_usb_pid) || (device_descriptor.idProduct == rad1o_usb_pid)) { - printf("USB device %4x:%4x:", device_descriptor.idVendor, device_descriptor.idProduct); if( desired_serial_number != NULL ) { const uint_fast8_t serial_descriptor_index = device_descriptor.iSerialNumber; @@ -473,23 +467,18 @@ libusb_device_handle* hackrf_open_usb(const char* const desired_serial_number) serial_number_length = libusb_get_string_descriptor_ascii(usb_device, serial_descriptor_index, (unsigned char*)serial_number, sizeof(serial_number)); if( serial_number_length == 32 ) { serial_number[32] = 0; - printf(" %s", serial_number); if( strncmp(serial_number + 32-match_len, desired_serial_number, match_len) == 0 ) { - printf(" match\n"); break; } else { - printf(" skip\n"); libusb_close(usb_device); usb_device = NULL; } } else { - printf(" wrong length of serial number: %d\n", serial_number_length); libusb_close(usb_device); usb_device = NULL; } } } else { - printf(" default\n"); libusb_open(devices[i], &usb_device); break; } From a2857f7383b1e57812534ab4e60b1e75faa0d9e9 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Wed, 1 Feb 2017 16:01:28 -0700 Subject: [PATCH 2/3] iReplace malloc that we never free with a statically assigned buffer --- host/libhackrf/src/hackrf.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 7e3de85c..ba3e5e0c 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -98,17 +98,19 @@ typedef enum { HACKRF_HW_SYNC_MODE_ON = 1, } hackrf_hw_sync_mode; +#define TRANSFER_COUNT 4 +#define TRANSFER_BUFFER_SIZE 262144 + struct hackrf_device { libusb_device_handle* usb_device; struct libusb_transfer** transfers; hackrf_sample_block_cb_fn callback; volatile bool transfer_thread_started; /* volatile shared between threads (read only) */ pthread_t transfer_thread; - uint32_t transfer_count; - uint32_t buffer_size; volatile bool streaming; /* volatile shared between threads (read only) */ void* rx_ctx; void* tx_ctx; + unsigned char buffer[TRANSFER_COUNT * TRANSFER_BUFFER_SIZE]; }; typedef struct { @@ -155,7 +157,7 @@ static int cancel_transfers(hackrf_device* device) if( device->transfers != NULL ) { - for(transfer_index=0; transfer_indextransfer_count; transfer_index++) + for(transfer_index=0; transfer_indextransfers[transfer_index] != NULL ) { @@ -175,7 +177,7 @@ static int free_transfers(hackrf_device* device) if( device->transfers != NULL ) { // libusb_close() should free all transfers referenced from this array. - for(transfer_index=0; transfer_indextransfer_count; transfer_index++) + for(transfer_index=0; transfer_indextransfers[transfer_index] != NULL ) { @@ -194,13 +196,13 @@ static int allocate_transfers(hackrf_device* const device) if( device->transfers == NULL ) { uint32_t transfer_index; - device->transfers = (struct libusb_transfer**) calloc(device->transfer_count, sizeof(struct libusb_transfer)); + device->transfers = (struct libusb_transfer**) calloc(TRANSFER_COUNT, sizeof(struct libusb_transfer)); if( device->transfers == NULL ) { return HACKRF_ERROR_NO_MEM; } - for(transfer_index=0; transfer_indextransfer_count; transfer_index++) + for(transfer_index=0; transfer_indextransfers[transfer_index] = libusb_alloc_transfer(0); if( device->transfers[transfer_index] == NULL ) @@ -212,8 +214,8 @@ static int allocate_transfers(hackrf_device* const device) device->transfers[transfer_index], device->usb_device, 0, - (unsigned char*)malloc(device->buffer_size), - device->buffer_size, + &device->buffer[transfer_index * TRANSFER_BUFFER_SIZE], + TRANSFER_BUFFER_SIZE, NULL, device, 0 @@ -239,7 +241,7 @@ static int prepare_transfers( uint32_t transfer_index; if( device->transfers != NULL ) { - for(transfer_index=0; transfer_indextransfer_count; transfer_index++) + for(transfer_index=0; transfer_indextransfers[transfer_index]->endpoint = endpoint_address; device->transfers[transfer_index]->callback = callback; @@ -526,12 +528,6 @@ static int hackrf_open_setup(libusb_device_handle* usb_device, hackrf_device** d lib_device->transfers = NULL; lib_device->callback = NULL; lib_device->transfer_thread_started = false; - /* - lib_device->transfer_count = 1024; - lib_device->buffer_size = 16384; - */ - lib_device->transfer_count = 4; - lib_device->buffer_size = 262144; /* 1048576; */ lib_device->streaming = false; do_exit = false; From d61efc0c077145f78a506df7599318f4043a6fed Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Wed, 1 Feb 2017 16:02:08 -0700 Subject: [PATCH 3/3] Remove experimental firmware code - never used in firmware --- firmware/common/sgpio_dma.c | 142 ------------------------------------ firmware/common/sgpio_dma.h | 48 ------------ 2 files changed, 190 deletions(-) delete mode 100644 firmware/common/sgpio_dma.c delete mode 100644 firmware/common/sgpio_dma.h diff --git a/firmware/common/sgpio_dma.c b/firmware/common/sgpio_dma.c deleted file mode 100644 index dc78ddf1..00000000 --- a/firmware/common/sgpio_dma.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2013 Jared Boone - * - * 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 - -#include -#include -#include -#include - -#include -#include - -void sgpio_dma_configure_lli( - gpdma_lli_t* const lli, - const size_t lli_count, - const bool direction_transmit, - void* const buffer, - const size_t transfer_bytes -) { - const size_t bytes_per_word = 4; - const size_t transfer_words = (transfer_bytes + bytes_per_word - 1) / bytes_per_word; - - gpdma_lli_create_loop(lli, lli_count); - - for(size_t i=0; icsrcaddr; - GPDMA_CDESTADDR(channel) = (uint32_t)lli->cdestaddr; - GPDMA_CLLI(channel) = (uint32_t)lli->clli; - GPDMA_CCONTROL(channel) = lli->ccontrol; - - /* 1: Memory -> Peripheral - * 2: Peripheral -> Memory */ - const uint_fast8_t flowcntrl = direction_transmit ? 1 : 2; - - GPDMA_CCONFIG(channel) = - GPDMA_CCONFIG_E(0) | - GPDMA_CCONFIG_SRCPERIPHERAL(0) | - GPDMA_CCONFIG_DESTPERIPHERAL(0) | - GPDMA_CCONFIG_FLOWCNTRL(flowcntrl) | - GPDMA_CCONFIG_IE(1) | - GPDMA_CCONFIG_ITC(1) | - GPDMA_CCONFIG_L(0) | - GPDMA_CCONFIG_H(0) - ; - - gpdma_channel_enable(channel); -} - -void sgpio_dma_init() { - /* DMA peripheral/source 0, option 2 (SGPIO14) -- BREQ */ - CREG_DMAMUX &= ~(CREG_DMAMUX_DMAMUXPER0_MASK); - CREG_DMAMUX |= CREG_DMAMUX_DMAMUXPER0(0x2); - - // Disable sync, maybe it is causing max speed (10MT/sec) glitches? - //GPDMA_DMACSYNC = (1 << 0); - //GPDMA_SYNC = GPDMA_SYNC_DMACSYNC(0xFFFF); // TODO: Don't do this, I'm just going nuts here. - - gpdma_controller_enable(); -} - -static const uint_fast8_t dma_channel_sgpio = 0; - -void sgpio_dma_rx_start(const gpdma_lli_t* const start_lli) { - sgpio_dma_enable(dma_channel_sgpio, start_lli, false); -} - -void sgpio_dma_tx_start(const gpdma_lli_t* const start_lli) { - sgpio_dma_enable(dma_channel_sgpio, start_lli, true); -} - -void sgpio_dma_irq_tc_acknowledge() { - gpdma_channel_interrupt_tc_clear(dma_channel_sgpio); -} - -void sgpio_dma_stop() { - gpdma_channel_disable(dma_channel_sgpio); -} - -size_t sgpio_dma_current_transfer_index( - const gpdma_lli_t* const lli, - const size_t lli_count -) { - const uint32_t next_lli = GPDMA_CLLI(dma_channel_sgpio); - for(size_t i=0; i - * - * 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 __SGPIO_DMA_H__ -#define __SGPIO_DMA_H__ - -#include - -#include - -void sgpio_dma_configure_lli( - gpdma_lli_t* const lli, - const size_t lli_count, - const bool direction_transmit, - void* const buffer, - const size_t transfer_bytes -); - -void sgpio_dma_init(); -void sgpio_dma_rx_start(const gpdma_lli_t* const start_lli); -void sgpio_dma_tx_start(const gpdma_lli_t* const start_lli); -void sgpio_dma_irq_tc_acknowledge(); -void sgpio_dma_stop(); - -size_t sgpio_dma_current_transfer_index( - const gpdma_lli_t* const lli, - const size_t lli_count -); - -#endif/*__SGPIO_DMA_H__*/