diff --git a/firmware/common/sgpio.c b/firmware/common/sgpio.c index a4b74c53..c78166fb 100644 --- a/firmware/common/sgpio.c +++ b/firmware/common/sgpio.c @@ -1,5 +1,6 @@ /* * Copyright 2012 Jared Boone + * Copyright 2013 Benjamin Vernoux * * This file is part of HackRF. * @@ -89,6 +90,19 @@ void sgpio_test_interface() { } } + +/* + SGPIO0 to 7 = DAC/ADC data bits 0 to 7 (Nota: DAC is 10bits but only bit9 to bit2 are used bit1 & 0 are forced to 0 by CPLD) + ADC=> CLK x 2=CLKx2 with CLKx2(0)rising=D0Q, CLKx2(1)rising=D1I (corresponds to CLK(0)falling+tD0Q=>D0Q, CLK(1)rising+tDOI=>D1I, CLK(1)falling+tD0Q=>D1Q, CLK(1)rising+tDOI=>D2I ...) + tDOI(CLK Rise to I-ADC Channel-I Output Data Valid)=7.4 to 9ns, tD0Q(CLK Fall to Q-ADC Channel-Q Output Data Valid)=6.9 to 9ns + DAC=> CLK x 2=CLKx2 with CLKx2(0)rising=Q:N-2, CLKx2(1)rising=I:N-1(corresponds to CLK(0)rising=>Q:N-2, CLK(0)falling I:N-1, CLK(1)rising=>Q:N-1, CLK(1)falling I:N ...) + tDSI(I-DAC Data to CLK Fall Setup Time)=min 10ns, tDSQ(Q-DAC Data to CLK Rise Setup Time)=min 10ns + + SGPIO8 Clock Input (External Clock) + SGPIO9 Capture Input (Capture/ChipSelect, 1=Enable Capture, 0=Disable capture) + SGPIO10 Disable Output (1/High=Disable codec data stream, 0/Low=Enable codec data stream) + SGPIO11 Direction Output (1/High=TX mode LPC43xx=>CPLD=>DAC, 0/Low=RX mode LPC43xx<=CPLD<=ADC) +*/ void sgpio_configure( const transceiver_mode_t transceiver_mode, const bool multi_slice @@ -102,8 +116,8 @@ void sgpio_configure( const uint_fast8_t cpld_direction = (transceiver_mode == TRANSCEIVER_MODE_TX) ? 1 : 0; SGPIO_GPIO_OUTREG = - (cpld_direction << 11) - | (1L << 10) // disable + (cpld_direction << 11) /* 1=Output SGPIO11 High(TX mode), 0=Output SGPIO11 Low(RX mode)*/ + | (1L << 10) // disable codec data stream during configuration (Output SGPIO10 High) ; // Enable SGPIO pin outputs. @@ -112,37 +126,38 @@ void sgpio_configure( ? (0xFF << 0) : (0x00 << 0); SGPIO_GPIO_OENREG = - (1L << 11) // direction - | (1L << 10) // disable - | (0L << 9) // capture - | (0L << 8) // clock - | sgpio_gpio_data_direction + (1L << 11) // direction output SGPIO11 active + | (1L << 10) // disable output SGPIO10 active + | (0L << 9) // capture input SGPIO9 (output i is tri-stated) + | (0L << 8) // clock input SGPIO8 (output i is tri-stated) + | sgpio_gpio_data_direction // 0xFF=Output all SGPIO High(TX mode), 0x00=Output all SPGIO Low(RX mode) ; - SGPIO_OUT_MUX_CFG( 8) = // SGPIO: Input: clock - SGPIO_OUT_MUX_CFG_P_OE_CFG(0) - | SGPIO_OUT_MUX_CFG_P_OUT_CFG(0) + SGPIO_OUT_MUX_CFG( 8) = // SGPIO8: Input: clock + SGPIO_OUT_MUX_CFG_P_OE_CFG(0) /* 0x0 gpio_oe (state set by GPIO_OEREG) */ + | SGPIO_OUT_MUX_CFG_P_OUT_CFG(0) /* 0x0 dout_doutm1 (1-bit mode) */ ; - SGPIO_OUT_MUX_CFG( 9) = // SGPIO: Input: qualifier - SGPIO_OUT_MUX_CFG_P_OE_CFG(0) - | SGPIO_OUT_MUX_CFG_P_OUT_CFG(0) + SGPIO_OUT_MUX_CFG( 9) = // SGPIO9: Input: qualifier + SGPIO_OUT_MUX_CFG_P_OE_CFG(0) /* 0x0 gpio_oe (state set by GPIO_OEREG) */ + | SGPIO_OUT_MUX_CFG_P_OUT_CFG(0) /* 0x0 dout_doutm1 (1-bit mode) */ ; - SGPIO_OUT_MUX_CFG(10) = // GPIO: Output: disable - SGPIO_OUT_MUX_CFG_P_OE_CFG(0) - | SGPIO_OUT_MUX_CFG_P_OUT_CFG(4) + SGPIO_OUT_MUX_CFG(10) = // GPIO10: Output: disable + SGPIO_OUT_MUX_CFG_P_OE_CFG(0) /* 0x0 gpio_oe (state set by GPIO_OEREG) */ + | SGPIO_OUT_MUX_CFG_P_OUT_CFG(4) /* 0x4=gpio_out (level set by GPIO_OUTREG) */ ; - SGPIO_OUT_MUX_CFG(11) = // GPIO: Output: direction - SGPIO_OUT_MUX_CFG_P_OE_CFG(0) - | SGPIO_OUT_MUX_CFG_P_OUT_CFG(4) + SGPIO_OUT_MUX_CFG(11) = // GPIO11: Output: direction + SGPIO_OUT_MUX_CFG_P_OE_CFG(0) /* 0x0 gpio_oe (state set by GPIO_OEREG) */ + | SGPIO_OUT_MUX_CFG_P_OUT_CFG(4) /* 0x4=gpio_out (level set by GPIO_OUTREG) */ ; const uint_fast8_t output_multiplexing_mode = multi_slice ? 11 : 9; + /* SGPIO0 to SGPIO7 */ for(uint_fast8_t i=0; i<8; i++) { // SGPIO pin 0 outputs slice A bit "i". SGPIO_OUT_MUX_CFG(i) = SGPIO_OUT_MUX_CFG_P_OE_CFG(0) - | SGPIO_OUT_MUX_CFG_P_OUT_CFG(output_multiplexing_mode) + | SGPIO_OUT_MUX_CFG_P_OUT_CFG(output_multiplexing_mode) /* 11/0xB=dout_doutm8c (8-bit mode 8c)(multislice L0/7, N0/7), 9=dout_doutm8a (8-bit mode 8a)(A0/7,B0/7) */ ; } @@ -162,32 +177,34 @@ void sgpio_configure( const uint_fast8_t slice_count = multi_slice ? 8 : 1; uint32_t slice_enable_mask = 0; - for(uint_fast8_t i=0; i IQ */ "str r0, [%[p], #0]\n\t" "ldr r0, [%[SGPIO_REG_SS], #20]\n\t" + "rev16 r0, r0\n\t" /* Swap QI -> IQ */ "str r0, [%[p], #4]\n\t" "ldr r0, [%[SGPIO_REG_SS], #40]\n\t" + "rev16 r0, r0\n\t" /* Swap QI -> IQ */ "str r0, [%[p], #8]\n\t" "ldr r0, [%[SGPIO_REG_SS], #8]\n\t" + "rev16 r0, r0\n\t" /* Swap QI -> IQ */ "str r0, [%[p], #12]\n\t" "ldr r0, [%[SGPIO_REG_SS], #36]\n\t" + "rev16 r0, r0\n\t" /* Swap QI -> IQ */ "str r0, [%[p], #16]\n\t" "ldr r0, [%[SGPIO_REG_SS], #16]\n\t" + "rev16 r0, r0\n\t" /* Swap QI -> IQ */ "str r0, [%[p], #20]\n\t" "ldr r0, [%[SGPIO_REG_SS], #32]\n\t" + "rev16 r0, r0\n\t" /* Swap QI -> IQ */ "str r0, [%[p], #24]\n\t" "ldr r0, [%[SGPIO_REG_SS], #0]\n\t" + "rev16 r0, r0\n\t" /* Swap QI -> IQ */ "str r0, [%[p], #28]\n\t" : : [SGPIO_REG_SS] "l" (SGPIO_PORT_BASE + 0x100), diff --git a/hardware/jellybean/sgpio_if/default.svf b/hardware/jellybean/sgpio_if/default.svf index e0f7b9a8..ed629766 100755 --- a/hardware/jellybean/sgpio_if/default.svf +++ b/hardware/jellybean/sgpio_if/default.svf @@ -1,5 +1,5 @@ -// Created using Xilinx Cse Software [ISE - 13.4] -// Date: Thu Feb 14 12:00:19 2013 +// Created using Xilinx Cse Software [ISE - 14.1] +// Date: Thu Apr 04 19:24:32 2013 TRST OFF; ENDIR IDLE; @@ -164,7 +164,7 @@ SDR 281 TDI (0083c1fffffffffffffffffffffffffffffddf7ffffffffffbfffffffffffffffff RUNTEST 10000 TCK; SDR 281 TDI (00c2f9fffffffffffffffffffffffffffffddf7fffffffffffffbffffffffffffffffe7f) ; RUNTEST 10000 TCK; -SDR 281 TDI (01c201fffffffffffffffffffffffffffffddf7fffffefbefbffbfffefbefffffffffe7c) ; +SDR 281 TDI (01c201fffffffffffffffffffffffffffffddf7fffffefbefbffbfffefbefffffffff27c) ; RUNTEST 10000 TCK; SDR 281 TDI (0143c1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0f) ; RUNTEST 10000 TCK; @@ -184,7 +184,7 @@ SDR 281 TDI (01a2f9fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff RUNTEST 10000 TCK; SDR 281 TDI (012201fffffffffffffffffffffffffffffd7f7fffffffffffffffffffff7ffffffffe81) ; RUNTEST 10000 TCK; -SDR 281 TDI (0023c1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe4f) ; +SDR 281 TDI (0023c1fffffffffffffffffffffffffffff5ff7ffffffffffffffffffffffffffffff24f) ; RUNTEST 10000 TCK; SDR 281 TDI (0032f9fffffffffffffffffffffffffffffd7f7fffffeffffffffffffffffffffffffe7c) ; RUNTEST 10000 TCK; @@ -202,7 +202,7 @@ SDR 281 TDI (0172f9fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff RUNTEST 10000 TCK; SDR 281 TDI (007201ffffffffffffffffffffffffffffffe587fffffffffffffffffffffffffffffe7c) ; RUNTEST 10000 TCK; -SDR 281 TDI (0053c1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe4f) ; +SDR 281 TDI (0053c1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffea4f) ; RUNTEST 10000 TCK; SDR 281 TDI (0152f9fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7c) ; RUNTEST 10000 TCK; @@ -210,9 +210,9 @@ SDR 281 TDI (01d201fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff RUNTEST 10000 TCK; SDR 281 TDI (00d3c1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0f) ; RUNTEST 10000 TCK; -SDR 281 TDI (0092f9fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7d) ; +SDR 281 TDI (0092f9fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe65) ; RUNTEST 10000 TCK; -SDR 281 TDI (019201fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7c) ; +SDR 281 TDI (019201fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7d) ; RUNTEST 10000 TCK; SDR 281 TDI (0113c1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe4f) ; RUNTEST 10000 TCK; @@ -254,7 +254,7 @@ SDR 281 TDI (002bc9fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff RUNTEST 10000 TCK; SDR 281 TDI (0128fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1d) ; RUNTEST 10000 TCK; -SDR 281 TDI (01aa01fffff7ffffffffffffffffffffffebfefffffffffffffffffffffffffffffffe7c) ; +SDR 281 TDI (01aa01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7c) ; RUNTEST 10000 TCK; SDR 281 TDI (00abc1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0f) ; RUNTEST 10000 TCK; @@ -264,7 +264,7 @@ SDR 281 TDI (01e8f9fffbfffffffffffffffffffffffffbbefffffffffffffffffffffffffffff RUNTEST 10000 TCK; SDR 281 TDI (016bc9fffffffffff7fffffffffffffffffbeefffffffffffffffffffffffffffffffe0f) ; RUNTEST 10000 TCK; -SDR 281 TDI (0068e1ffffffffffffffffffffffffff7ffbbefffffffffffffffffffffffffffffffe1d) ; +SDR 281 TDI (0068e1fffff7fffffffffffffffffffffffffefafffffffffffffffffffffffffffffe1d) ; RUNTEST 10000 TCK; SDR 281 TDI (004ac5ffffffffffffffffffdffffffffffbeefffffffffffffffffffffffffffffffe7c) ; RUNTEST 10000 TCK; @@ -272,7 +272,7 @@ SDR 281 TDI (014bc1ffffffff7ffffffffffffffffffffbeefffffffffffffffffffffffffffff RUNTEST 10000 TCK; SDR 281 TDI (01cbf9ffffffffffffffffffffffffdffffbeefffffffffffffffffffffffffffffffe1d) ; RUNTEST 10000 TCK; -SDR 281 TDI (00c8f8fffffffffffffffffffffffffffffafefffffffffffffffffffffffffffffffe7c) ; +SDR 281 TDI (00c8f9ffffffffffffffffffffffffff7ffbbefffffffffffffffffffffffffffffffe7c) ; RUNTEST 10000 TCK; SDR 281 TDI (008bc9ffffffffffffff7ffffffffffffffbbefffffffffffffffffffffffffffffffe0f) ; RUNTEST 10000 TCK; @@ -330,7 +330,7 @@ SDR 281 TDI (017cf9fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff RUNTEST 10000 TCK; SDR 281 TDI (007fc9fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0f) ; RUNTEST 10000 TCK; -SDR 281 TDI (005ce1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7d) ; +SDR 281 TDI (005ce0fffffffffffffffffffffffffffffafefffffffffffffffffffffffffffffffe7d) ; RUNTEST 10000 TCK; SDR 281 TDI (015ec5fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01) ; RUNTEST 10000 TCK; @@ -425,7 +425,7 @@ SDR 7 TDI (70) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (0201fffffffffffffffffffffffffffffddf7fffffefbefbffbfffefbefffffffffe7c) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (0201fffffffffffffffffffffffffffffddf7fffffefbefbffbfffefbefffffffff27c) MASK ( 03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -505,7 +505,7 @@ SDR 7 TDI (08) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (03c1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe4f) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (03c1fffffffffffffffffffffffffffff5ff7ffffffffffffffffffffffffffffff24f) MASK ( 03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -577,7 +577,7 @@ SDR 7 TDI (14) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (03c1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe4f) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (03c1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffea4f) MASK ( 03fffffffffffffffffffffffffffffe001f8001ffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -609,7 +609,7 @@ SDR 7 TDI (24) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (02f9fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7d) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (02f9fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe65) MASK ( 03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -617,7 +617,7 @@ SDR 7 TDI (64) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (0201fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7c) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (0201fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7d) MASK ( 03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -785,7 +785,7 @@ SDR 7 TDI (6a) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (0201fffff7ffffffffffffffffffffffebfefffffffffffffffffffffffffffffffe7c) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (0201fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7c) MASK ( 03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -825,7 +825,7 @@ SDR 7 TDI (1a) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (00e1ffffffffffffffffffffffffff7ffbbefffffffffffffffffffffffffffffffe1d) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (00e1fffff7fffffffffffffffffffffffffefafffffffffffffffffffffffffffffe1d) MASK ( 03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -857,7 +857,7 @@ SDR 7 TDI (32) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (00f8fffffffffffffffffffffffffffffafefffffffffffffffffffffffffffffffe7c) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (00f9ffffffffffffffffffffffffff7ffbbefffffffffffffffffffffffffffffffe7c) MASK ( 03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -1089,7 +1089,7 @@ SDR 7 TDI (17) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (00e1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7d) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (00e0fffffffffffffffffffffffffffffafefffffffffffffffffffffffffffffffe7d) MASK ( 03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -1306,7 +1306,7 @@ SDR 7 TDI (70) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (0201fffffffffffffffffffffffffffffddf7fffffefbefbffbfffefbefffffffffe7c) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (0201fffffffffffffffffffffffffffffddf7fffffefbefbffbfffefbefffffffff27c) MASK ( 03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -1386,7 +1386,7 @@ SDR 7 TDI (08) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (03c1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe4f) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (03c1fffffffffffffffffffffffffffff5ff7ffffffffffffffffffffffffffffff24f) MASK ( 03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -1458,7 +1458,7 @@ SDR 7 TDI (14) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (03c1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe4f) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (03c1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffea4f) MASK ( 03fffffffffffffffffffffffffffffe001f8001ffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -1490,7 +1490,7 @@ SDR 7 TDI (24) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (02f9fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7d) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (02f9fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe65) MASK ( 03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -1498,7 +1498,7 @@ SDR 7 TDI (64) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (0201fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7c) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (0201fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7d) MASK ( 03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -1666,7 +1666,7 @@ SDR 7 TDI (6a) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (0201fffff7ffffffffffffffffffffffebfefffffffffffffffffffffffffffffffe7c) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (0201fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7c) MASK ( 03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -1706,7 +1706,7 @@ SDR 7 TDI (1a) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (00e1ffffffffffffffffffffffffff7ffbbefffffffffffffffffffffffffffffffe1d) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (00e1fffff7fffffffffffffffffffffffffefafffffffffffffffffffffffffffffe1d) MASK ( 03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -1738,7 +1738,7 @@ SDR 7 TDI (32) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (00f8fffffffffffffffffffffffffffffafefffffffffffffffffffffffffffffffe7c) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (00f9ffffffffffffffffffffffffff7ffbbefffffffffffffffffffffffffffffffe7c) MASK ( 03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; @@ -1970,7 +1970,7 @@ SDR 7 TDI (17) SMASK (7f) ; RUNTEST DRPAUSE 20 TCK; ENDDR IDLE; RUNTEST IDLE 100 TCK; -SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (00e1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7d) MASK ( +SDR 274 TDI (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) SMASK (03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) TDO (00e0fffffffffffffffffffffffffffffafefffffffffffffffffffffffffffffffe7d) MASK ( 03ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) ; RUNTEST 100 TCK; ENDDR DRPAUSE; diff --git a/hardware/jellybean/sgpio_if/default.xsvf b/hardware/jellybean/sgpio_if/default.xsvf index 2a005f20..c767758e 100755 Binary files a/hardware/jellybean/sgpio_if/default.xsvf and b/hardware/jellybean/sgpio_if/default.xsvf differ diff --git a/hardware/jellybean/sgpio_if/sgpio_if.xise b/hardware/jellybean/sgpio_if/sgpio_if.xise index 82383b2e..82c5ad11 100755 --- a/hardware/jellybean/sgpio_if/sgpio_if.xise +++ b/hardware/jellybean/sgpio_if/sgpio_if.xise @@ -9,22 +9,22 @@ - + - + - - - - + + + + @@ -97,6 +97,9 @@ + + + @@ -200,6 +203,7 @@ + diff --git a/hardware/jellybean/sgpio_if/top.jed b/hardware/jellybean/sgpio_if/top.jed index 30d2f233..e636b035 100755 --- a/hardware/jellybean/sgpio_if/top.jed +++ b/hardware/jellybean/sgpio_if/top.jed @@ -1,5 +1,5 @@ Programmer Jedec Bit Map -Date Extracted: Thu Feb 14 11:55:50 2013 +Date Extracted: Thu Apr 04 19:23:47 2013 QF25812* QP100* @@ -7,7 +7,7 @@ QV0* F0* X0* J0 0* -N VERSION O.87xd* +N VERSION P.15xf* N DEVICE XC2C64A-7-VQ100* Note Block 0 * @@ -205,7 +205,7 @@ L006624 1111111111111111* L006640 1111111111111111* L006656 1111111111111111* L006672 1111111011100111* -L006688 1111111111111111* +L006688 1111111011110011* L006704 1111111011100111* L006720 1111111111111111* L006736 1111111111111111* @@ -232,8 +232,8 @@ L007056 1111111111111111* L007072 1111111111111111* Note Block 1 PLA AND array * -L007088 11111111111111111111111111111111111111111111111111111111111111111111111111111111* -L007168 11111111111111111111111111111111111111111111111111111111111111111111111111111111* +L007088 11111111110111111111111111111101111111111111111111111111111111111111111111111111* +L007168 11111111111011111111111111111110111111111111111111111111111111111111111111111111* L007248 11111111111111111111111111111111111111111111111111111111111111111111111111111111* L007328 11111111111111111111111111111111111111111111111111111111111111111111111111111111* L007408 11111111111111111111111111111111111111111111111111111111111111111111111111111111* @@ -290,8 +290,8 @@ L011408 111111111111111111111111111111111111111111111111111111111111111111111111 L011488 11111111111111111111111111111111111111111111111111111111111111111111111111111111* Note Block 1 PLA OR array * -L011568 1111111111111111* -L011584 1111111111111111* +L011568 1111111110111111* +L011584 1111111110111111* L011600 1111111111111111* L011616 1111111111111111* L011632 1111111111111111* @@ -358,7 +358,7 @@ L012599 000101111001111101000000001* L012626 000001111001111110011111100* L012653 000001111000011100011111100* L012680 000101111001111101000000001* -L012707 000001111001111100011111100* +L012707 000001111001100100011111101* L012734 000101111001111101000000001* L012761 000101111001111101000000001* L012788 000101111001111101000000001* @@ -370,16 +370,16 @@ Note Block 2 * Note Block 2 ZIA * L012896 1111111111111111* L012912 1111111111111111* -L012928 1111111011110011* +L012928 1111111111111111* L012944 1111111111111111* L012960 1111111010110111* L012976 1111111011010111* L012992 1111111010110111* -L013008 1111111011010111* +L013008 1110011011111111* L013024 1111111010110111* L013040 1111111010110111* L013056 1111111010110111* -L013072 1111111011100111* +L013072 1111111011010111* L013088 1111111011010111* L013104 1111111111111111* L013120 1111111111111111* @@ -400,7 +400,7 @@ L013344 1111111111111111* L013360 1111111111111111* L013376 1111111111111111* L013392 1111111111111111* -L013408 1111111111111111* +L013408 1111111011100111* L013424 1111111111111111* L013440 1111111111111111* L013456 1111111111111111* @@ -410,7 +410,7 @@ L013504 1111111111111111* L013520 1111111111111111* Note Block 2 PLA AND array * -L013536 11111111111111111111111011111111111111111111111111111111111111111111111111111111* +L013536 11111111111111111111111111111111111111111111111111111111111111111011111111111111* L013616 11111111111111111111111111111111111111111111111111111111111111111111111111111111* L013696 11111111111111111111111111111111111111111111111111111111111111111111111111111111* L013776 11111111111111111111111111111111111111111111111111111111111111111111111111111111* @@ -420,7 +420,7 @@ L014016 111111111111111111111111111111111111111111111111111111111111111111111111 L014096 11111111111011111111111111111111111111111111111111111111111111111111111111111111* L014176 11111111111111111111111111111111111111111111111111111111111111111111111111111111* L014256 11111111111111111111111111111111111111111111111111111111111111111111111111111111* -L014336 11110111111111111111111111111111111111111111111111111111111111111111111111111111* +L014336 11111111111111011111111111111111111111111111111111111111111111111111111111111111* L014416 11111111111111111111111111111111111111111111111111111111111111111111111111111111* L014496 11111111111111111111111111111111111111111111111111111111111111111111111111111111* L014576 11111111111111111111111111111111111111111111111111111111111111111111111111111111* @@ -462,7 +462,7 @@ L017376 111111111111111111111111111111111111111111111111111111111111111111111111 L017456 11111111111111111111011111111111111111111111111111111111111111111111111111111111* L017536 11111111111111111111111111111111111111111111111111111111111111111111111111111111* L017616 11111111111111111111111111111111111111111111111111111111111111111111111111111111* -L017696 11111111111111011111111111111111111111111111111111111111111111111111111111111111* +L017696 11111111111111111111110111111111111111111111111111111111111111111111111111111111* L017776 11111111111111111111111111111111111111111111111111111111111111111111111111111111* L017856 11111111111111111111111111111111111111111111111111111111111111111111111111111111* L017936 11111111111111111111111111111101111111111111111111111111111111111111111111111111* @@ -753,5 +753,5 @@ L025810 0* Note I/O Bank 1 Vcco * L025811 0* -C0AA3* -D0B9 +C09A6* +D0A4 diff --git a/hardware/jellybean/sgpio_if/top.vhd b/hardware/jellybean/sgpio_if/top.vhd index 31a61d0d..cef6ff3a 100755 --- a/hardware/jellybean/sgpio_if/top.vhd +++ b/hardware/jellybean/sgpio_if/top.vhd @@ -1,22 +1,23 @@ -- --- Copyright 2012 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. +-- Copyright 2012 Jared Boone +-- Copyright 2013 Benjamin Vernoux +-- +-- 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. library IEEE; use IEEE.STD_LOGIC_1164.ALL; @@ -116,8 +117,14 @@ begin process(host_clk_i, codec_clk_i) begin if rising_edge(host_clk_i) then - if codec_clk_i = '1' then - host_data_capture_o <= host_data_enable_i; + if transfer_direction_i = to_dac then + if codec_clk_i = '1' then + host_data_capture_o <= host_data_enable_i; + end if; + else + if codec_clk_i = '0' then + host_data_capture_o <= host_data_enable_i; + end if; end if; end if; end process; diff --git a/host/libhackrf/examples/hackrf_max2837.c b/host/libhackrf/examples/hackrf_max2837.c index cac878ff..e780dba6 100644 --- a/host/libhackrf/examples/hackrf_max2837.c +++ b/host/libhackrf/examples/hackrf_max2837.c @@ -82,9 +82,10 @@ int dump_register(hackrf_device* device, const uint16_t register_number) { } int dump_registers(hackrf_device* device) { + uint16_t register_number; int result = HACKRF_SUCCESS; - for(uint16_t register_number=0; register_number<32; register_number++) { + for(register_number=0; register_number<32; register_number++) { result = dump_register(device, register_number); if( result != HACKRF_SUCCESS ) { break; diff --git a/host/libhackrf/examples/hackrf_rffc5071.c b/host/libhackrf/examples/hackrf_rffc5071.c index 0808f7fb..15ca6e71 100644 --- a/host/libhackrf/examples/hackrf_rffc5071.c +++ b/host/libhackrf/examples/hackrf_rffc5071.c @@ -83,9 +83,10 @@ int dump_register(hackrf_device* device, const uint16_t register_number) { } int dump_registers(hackrf_device* device) { + uint16_t register_number; int result = HACKRF_SUCCESS; - for(uint16_t register_number=0; register_number<31; register_number++) { + for(register_number=0; register_number<31; register_number++) { result = dump_register(device, register_number); if( result != HACKRF_SUCCESS ) { break; diff --git a/host/libhackrf/examples/hackrf_si5351c.c b/host/libhackrf/examples/hackrf_si5351c.c index 3b723f4c..d5373df6 100644 --- a/host/libhackrf/examples/hackrf_si5351c.c +++ b/host/libhackrf/examples/hackrf_si5351c.c @@ -70,9 +70,10 @@ int dump_register(hackrf_device* device, const uint16_t register_number) { } int dump_registers(hackrf_device* device) { + uint16_t register_number; int result = HACKRF_SUCCESS; - for(uint16_t register_number=0; register_number<256; register_number++) { + for(register_number=0; register_number<256; register_number++) { result = dump_register(device, register_number); if( result != HACKRF_SUCCESS ) { break; @@ -102,9 +103,12 @@ int write_register( #define REGISTER_INVALID 32767 int dump_multisynth_config(hackrf_device* device, const uint_fast8_t ms_number) { + uint_fast8_t i; + uint_fast8_t reg_base; uint16_t parameters[8]; - uint_fast8_t reg_base = 42 + (ms_number * 8); - for(uint_fast8_t i=0; i<8; i++) { + + reg_base = 42 + (ms_number * 8); + for(i=0; i<8; i++) { uint_fast8_t reg_number = reg_base + i; int result = hackrf_si5351c_read(device, reg_number, ¶meters[i]); if( result != HACKRF_SUCCESS ) { @@ -141,8 +145,11 @@ int dump_multisynth_config(hackrf_device* device, const uint_fast8_t ms_number) } int dump_configuration(hackrf_device* device) { - for(uint_fast8_t ms_number=0; ms_number<8; ms_number++) { - int result = dump_multisynth_config(device, ms_number); + uint_fast8_t ms_number; + int result; + + for(ms_number=0; ms_number<8; ms_number++) { + result = dump_multisynth_config(device, ms_number); if( result != HACKRF_SUCCESS ) { return result; } diff --git a/host/libhackrf/examples/hackrf_transfer.c b/host/libhackrf/examples/hackrf_transfer.c index 88f084ae..9a77ea2f 100644 --- a/host/libhackrf/examples/hackrf_transfer.c +++ b/host/libhackrf/examples/hackrf_transfer.c @@ -43,7 +43,9 @@ #include #include -#define FREQ_ONE_MHZ (1000000) +#define FD_BUFFER_SIZE (8*1024) + +#define FREQ_ONE_MHZ (1000000ull) #define DEFAULT_FREQ_HZ (900000000ull) /* 900MHz */ #define FREQ_MIN_HZ (30000000ull) /* 30MHz */ @@ -124,30 +126,6 @@ t_wav_file_hdr wave_file_hdr = } }; -typedef struct { - uint32_t bandwidth_hz; -} max2837_ft_t; - -static const max2837_ft_t max2837_ft[] = { - { 1750000 }, - { 2500000 }, - { 3500000 }, - { 5000000 }, - { 5500000 }, - { 6000000 }, - { 7000000 }, - { 8000000 }, - { 9000000 }, - { 10000000 }, - { 12000000 }, - { 14000000 }, - { 15000000 }, - { 20000000 }, - { 24000000 }, - { 28000000 }, - { 0 }, -}; - typedef enum { TRANSCEIVER_MODE_OFF = 0, TRANSCEIVER_MODE_RX = 1, @@ -209,47 +187,6 @@ int parse_u32(char* s, uint32_t* const value) { } } -/* Return final bw round down and less than expected bw. */ -uint32_t compute_baseband_filter_bw_round_down_lt(const uint32_t bandwidth_hz) -{ - const max2837_ft_t* p = max2837_ft; - while( p->bandwidth_hz != 0 ) - { - if( p->bandwidth_hz >= bandwidth_hz ) { - break; - } - p++; - } - /* Round down (if no equal to first entry) */ - if(p != max2837_ft) - { - p--; - } - return p->bandwidth_hz; -} - -/* Return final bw. */ -uint32_t compute_baseband_filter_bw(const uint32_t bandwidth_hz) -{ - const max2837_ft_t* p = max2837_ft; - while( p->bandwidth_hz != 0 ) - { - if( p->bandwidth_hz >= bandwidth_hz ) { - break; - } - p++; - } - - /* Round down (if no equal to first entry) and if > bandwidth_hz */ - if(p != max2837_ft) - { - if(p->bandwidth_hz > bandwidth_hz) - p--; - } - - return p->bandwidth_hz; -} - volatile bool do_exit = false; FILE* fd = NULL; @@ -343,7 +280,7 @@ static void usage() { printf("\t-t # Transmit data from file.\n"); printf("\t[-f set_freq_hz] # Set Freq in Hz between [%lluMHz, %lluMHz[.\n", FREQ_MIN_HZ/FREQ_ONE_MHZ, FREQ_MAX_HZ/FREQ_ONE_MHZ); printf("\t[-a set_amp] # Set Amp 1=Enable, 0=Disable.\n"); - printf("\t[-s sample_rate_hz] # Set sample rate in Hz (5/10/12.5/16/20MHz, default %dMHz).\n", DEFAULT_SAMPLE_RATE_HZ/FREQ_ONE_MHZ); + printf("\t[-s sample_rate_hz] # Set sample rate in Hz (5/10/12.5/16/20MHz, default %lldMHz).\n", DEFAULT_SAMPLE_RATE_HZ/FREQ_ONE_MHZ); printf("\t[-n num_samples] # Number of samples to transfer (default is unlimited).\n"); printf("\t[-b baseband_filter_bw_hz] # Set baseband filter bandwidth in MHz.\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" ); } @@ -465,11 +402,11 @@ int main(int argc, char** argv) { if( baseband_filter_bw ) { /* Compute nearest freq for bw filter */ - baseband_filter_bw_hz = compute_baseband_filter_bw(baseband_filter_bw_hz); + baseband_filter_bw_hz = hackrf_compute_baseband_filter_bw(baseband_filter_bw_hz); }else { /* Compute default value depending on sample rate */ - baseband_filter_bw_hz = compute_baseband_filter_bw_round_down_lt(sample_rate_hz); + baseband_filter_bw_hz = hackrf_compute_baseband_filter_bw_round_down_lt(sample_rate_hz); } if (baseband_filter_bw_hz > BASEBAND_FILTER_BW_MAX) { @@ -560,7 +497,14 @@ int main(int argc, char** argv) { printf("Failed to open file: %s\n", path); return EXIT_FAILURE; } - + /* Change fd buffer to have bigger one to store or read data on/to HDD */ + result = setvbuf(fd , NULL , _IOFBF , FD_BUFFER_SIZE); + if( result != 0 ) { + printf("setvbuf() failed: %d\n", result); + usage(); + return EXIT_FAILURE; + } + /* Write Wav header */ if( receive_wav ) { @@ -574,7 +518,7 @@ int main(int argc, char** argv) { signal(SIGTERM, &sigint_callback_handler); signal(SIGABRT, &sigint_callback_handler); - printf("call hackrf_sample_rate_set(%u Hz/%.02f MHz)\n", sample_rate_hz,((float)sample_rate_hz/(float)FREQ_ONE_MHZ)); + printf("call hackrf_sample_rate_set(%u Hz/%.03f MHz)\n", sample_rate_hz,((float)sample_rate_hz/(float)FREQ_ONE_MHZ)); result = hackrf_sample_rate_set(device, sample_rate_hz); if( result != HACKRF_SUCCESS ) { printf("hackrf_sample_rate_set() failed: %s (%d)\n", hackrf_error_name(result), result); @@ -582,7 +526,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - printf("call hackrf_baseband_filter_bandwidth_set(%d Hz/%.02f MHz)\n", + printf("call hackrf_baseband_filter_bandwidth_set(%d Hz/%.03f MHz)\n", baseband_filter_bw_hz, ((float)baseband_filter_bw_hz/(float)FREQ_ONE_MHZ)); result = hackrf_baseband_filter_bandwidth_set(device, baseband_filter_bw_hz); if( result != HACKRF_SUCCESS ) { @@ -592,9 +536,9 @@ int main(int argc, char** argv) { } if( transceiver_mode == TRANSCEIVER_MODE_RX ) { - result = hackrf_start_rx(device, rx_callback); + result = hackrf_start_rx(device, rx_callback, NULL); } else { - result = hackrf_start_tx(device, tx_callback); + result = hackrf_start_tx(device, tx_callback, NULL); } if( result != HACKRF_SUCCESS ) { printf("hackrf_start_?x() failed: %s (%d)\n", hackrf_error_name(result), result); @@ -602,7 +546,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - printf("call hackrf_set_freq(%llu Hz/%llu MHz)\n", freq_hz, (freq_hz/FREQ_ONE_MHZ) ); + printf("call hackrf_set_freq(%llu Hz/%.03f MHz)\n", freq_hz, ((float)freq_hz/(float)FREQ_ONE_MHZ) ); result = hackrf_set_freq(device, freq_hz); if( result != HACKRF_SUCCESS ) { printf("hackrf_set_freq() failed: %s (%d)\n", hackrf_error_name(result), result); diff --git a/host/libhackrf/src/CMakeLists.txt b/host/libhackrf/src/CMakeLists.txt index 02cd40e6..8e15b8b0 100644 --- a/host/libhackrf/src/CMakeLists.txt +++ b/host/libhackrf/src/CMakeLists.txt @@ -25,6 +25,9 @@ set(c_sources ${CMAKE_CURRENT_SOURCE_DIR}/hackrf.c CACHE INTERNAL "List of C sources") set(c_headers ${CMAKE_CURRENT_SOURCE_DIR}/hackrf.h CACHE INTERNAL "List of C headers") +set_source_files_properties(hackrf.c PROPERTIES LANGUAGE CXX ) +set_source_files_properties(hackrf.h PROPERTIES LANGUAGE CXX ) + # Dynamic library add_library(hackrf SHARED ${c_sources}) set_target_properties(hackrf PROPERTIES VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.0 SOVERSION 0) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index e81f18c7..e2c8d152 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -65,6 +65,33 @@ struct hackrf_device { uint32_t transfer_count; uint32_t buffer_size; bool streaming; + void* rx_ctx; + void* tx_ctx; +}; + + +typedef struct { + uint32_t bandwidth_hz; +} max2837_ft_t; + +static const max2837_ft_t max2837_ft[] = { + { 1750000 }, + { 2500000 }, + { 3500000 }, + { 5000000 }, + { 5500000 }, + { 6000000 }, + { 7000000 }, + { 8000000 }, + { 9000000 }, + { 10000000 }, + { 12000000 }, + { 14000000 }, + { 15000000 }, + { 20000000 }, + { 24000000 }, + { 28000000 }, + { 0 }, }; volatile bool do_exit = false; @@ -91,7 +118,7 @@ static int free_transfers(hackrf_device* device) { static int allocate_transfers(hackrf_device* const device) { if( device->transfers == NULL ) { - device->transfers = calloc(device->transfer_count, sizeof(struct libusb_transfer)); + device->transfers = (libusb_transfer**) calloc(device->transfer_count, sizeof(struct libusb_transfer)); if( device->transfers == NULL ) { return HACKRF_ERROR_NO_MEM; } @@ -158,7 +185,12 @@ static int cancel_transfers(hackrf_device* device) { } } */ -int hackrf_init() { +#ifdef __cplusplus +extern "C" +{ +#endif + +int ADDCALL hackrf_init() { const int libusb_error = libusb_init(&g_libusb_context); if( libusb_error != 0 ) { return HACKRF_ERROR_LIBUSB; @@ -167,7 +199,7 @@ int hackrf_init() { } } -int hackrf_exit() { +int ADDCALL hackrf_exit() { if( g_libusb_context != NULL ) { libusb_exit(g_libusb_context); g_libusb_context = NULL; @@ -176,7 +208,7 @@ int hackrf_exit() { return HACKRF_SUCCESS; } -int hackrf_open(hackrf_device** device) { +int ADDCALL hackrf_open(hackrf_device** device) { if( device == NULL ) { return HACKRF_ERROR_INVALID_PARAM; } @@ -204,7 +236,7 @@ int hackrf_open(hackrf_device** device) { } hackrf_device* lib_device = NULL; - lib_device = malloc(sizeof(*lib_device)); + lib_device = (hackrf_device*)malloc(sizeof(*lib_device)); if( lib_device == NULL ) { libusb_release_interface(usb_device, 0); libusb_close(usb_device); @@ -238,7 +270,7 @@ int hackrf_open(hackrf_device** device) { return HACKRF_SUCCESS; } -static int hackrf_set_transceiver_mode(hackrf_device* device, hackrf_transceiver_mode value) { +int ADDCALL hackrf_set_transceiver_mode(hackrf_device* device, hackrf_transceiver_mode value) { int result = libusb_control_transfer( device->usb_device, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, @@ -257,7 +289,7 @@ static int hackrf_set_transceiver_mode(hackrf_device* device, hackrf_transceiver } } -int hackrf_max2837_read(hackrf_device* device, uint8_t register_number, uint16_t* value) { +int ADDCALL hackrf_max2837_read(hackrf_device* device, uint8_t register_number, uint16_t* value) { if( register_number >= 32 ) { return HACKRF_ERROR_INVALID_PARAM; } @@ -280,7 +312,7 @@ int hackrf_max2837_read(hackrf_device* device, uint8_t register_number, uint16_t } } -int hackrf_max2837_write(hackrf_device* device, uint8_t register_number, uint16_t value) { +int ADDCALL hackrf_max2837_write(hackrf_device* device, uint8_t register_number, uint16_t value) { if( register_number >= 32 ) { return HACKRF_ERROR_INVALID_PARAM; } @@ -306,7 +338,7 @@ int hackrf_max2837_write(hackrf_device* device, uint8_t register_number, uint16_ } } -int hackrf_si5351c_read(hackrf_device* device, uint16_t register_number, uint16_t* value) { +int ADDCALL hackrf_si5351c_read(hackrf_device* device, uint16_t register_number, uint16_t* value) { if( register_number >= 256 ) { return HACKRF_ERROR_INVALID_PARAM; } @@ -331,7 +363,7 @@ int hackrf_si5351c_read(hackrf_device* device, uint16_t register_number, uint16_ } } -int hackrf_si5351c_write(hackrf_device* device, uint16_t register_number, uint16_t value) { +int ADDCALL hackrf_si5351c_write(hackrf_device* device, uint16_t register_number, uint16_t value) { if( register_number >= 256 ) { return HACKRF_ERROR_INVALID_PARAM; } @@ -357,7 +389,7 @@ int hackrf_si5351c_write(hackrf_device* device, uint16_t register_number, uint16 } } -int hackrf_sample_rate_set(hackrf_device* device, const uint32_t sampling_rate_hz) { +int ADDCALL hackrf_sample_rate_set(hackrf_device* device, const uint32_t sampling_rate_hz) { int result = libusb_control_transfer( device->usb_device, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, @@ -376,7 +408,7 @@ int hackrf_sample_rate_set(hackrf_device* device, const uint32_t sampling_rate_h } } -int hackrf_baseband_filter_bandwidth_set(hackrf_device* device, const uint32_t bandwidth_hz) { +int ADDCALL hackrf_baseband_filter_bandwidth_set(hackrf_device* device, const uint32_t bandwidth_hz) { int result = libusb_control_transfer( device->usb_device, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, @@ -396,7 +428,7 @@ int hackrf_baseband_filter_bandwidth_set(hackrf_device* device, const uint32_t b } -int hackrf_rffc5071_read(hackrf_device* device, uint8_t register_number, uint16_t* value) +int ADDCALL hackrf_rffc5071_read(hackrf_device* device, uint8_t register_number, uint16_t* value) { if( register_number >= 31 ) { return HACKRF_ERROR_INVALID_PARAM; @@ -420,7 +452,7 @@ int hackrf_rffc5071_read(hackrf_device* device, uint8_t register_number, uint16_ } } -int hackrf_rffc5071_write(hackrf_device* device, uint8_t register_number, uint16_t value) +int ADDCALL hackrf_rffc5071_write(hackrf_device* device, uint8_t register_number, uint16_t value) { if( register_number >= 31 ) { return HACKRF_ERROR_INVALID_PARAM; @@ -444,7 +476,7 @@ int hackrf_rffc5071_write(hackrf_device* device, uint8_t register_number, uint16 } } -int hackrf_spiflash_erase(hackrf_device* device) { +int ADDCALL hackrf_spiflash_erase(hackrf_device* device) { int result = libusb_control_transfer( device->usb_device, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, @@ -463,7 +495,7 @@ int hackrf_spiflash_erase(hackrf_device* device) { } } -int hackrf_spiflash_write(hackrf_device* device, const uint32_t address, +int ADDCALL hackrf_spiflash_write(hackrf_device* device, const uint32_t address, const uint16_t length, unsigned char* const data) { if (address > 0x0FFFFF) { @@ -488,7 +520,7 @@ int hackrf_spiflash_write(hackrf_device* device, const uint32_t address, } } -int hackrf_spiflash_read(hackrf_device* device, const uint32_t address, +int ADDCALL hackrf_spiflash_read(hackrf_device* device, const uint32_t address, const uint16_t length, unsigned char* data) { if (address > 0x0FFFFF) { @@ -513,7 +545,7 @@ int hackrf_spiflash_read(hackrf_device* device, const uint32_t address, } } -int hackrf_cpld_write(hackrf_device* device, const uint16_t length, +int ADDCALL hackrf_cpld_write(hackrf_device* device, const uint16_t length, unsigned char* const data) { int result = libusb_control_transfer( @@ -534,7 +566,7 @@ int hackrf_cpld_write(hackrf_device* device, const uint16_t length, } } -int hackrf_board_id_read(hackrf_device* device, uint8_t* value) { +int ADDCALL hackrf_board_id_read(hackrf_device* device, uint8_t* value) { int result = libusb_control_transfer( device->usb_device, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, @@ -553,7 +585,7 @@ int hackrf_board_id_read(hackrf_device* device, uint8_t* value) { } } -int hackrf_version_string_read(hackrf_device* device, char* version, +int ADDCALL hackrf_version_string_read(hackrf_device* device, char* version, uint8_t length) { int result = libusb_control_transfer( @@ -582,7 +614,7 @@ typedef struct { } set_freq_params_t; #define FREQ_ONE_MHZ (1000*1000ull) -int hackrf_set_freq(hackrf_device* device, const uint64_t freq_hz) +int ADDCALL hackrf_set_freq(hackrf_device* device, const uint64_t freq_hz) { uint32_t l_freq_mhz; uint32_t l_freq_hz; @@ -614,7 +646,7 @@ int hackrf_set_freq(hackrf_device* device, const uint64_t freq_hz) } } -int hackrf_set_amp_enable(hackrf_device* device, const uint8_t value) +int ADDCALL hackrf_set_amp_enable(hackrf_device* device, const uint8_t value) { int result = libusb_control_transfer( device->usb_device, @@ -634,7 +666,7 @@ int hackrf_set_amp_enable(hackrf_device* device, const uint8_t value) } } -int hackrf_board_partid_serialno_read(hackrf_device* device, read_partid_serialno_t* read_partid_serialno) +int ADDCALL hackrf_board_partid_serialno_read(hackrf_device* device, read_partid_serialno_t* read_partid_serialno) { uint8_t length; @@ -676,21 +708,43 @@ static void* transfer_threadproc(void* arg) { static void hackrf_libusb_transfer_callback(struct libusb_transfer* usb_transfer) { hackrf_device* device = (hackrf_device*)usb_transfer->user_data; - if( usb_transfer->status == LIBUSB_TRANSFER_COMPLETED ) { - hackrf_transfer transfer = { - .device = device, - .buffer = usb_transfer->buffer, - .buffer_length = usb_transfer->length, - .valid_length = usb_transfer->actual_length, - }; + switch(usb_transfer->status) + { + case LIBUSB_TRANSFER_COMPLETED: + { + hackrf_transfer transfer = { + transfer.device = device, + transfer.buffer = usb_transfer->buffer, + transfer.buffer_length = usb_transfer->length, + transfer.valid_length = usb_transfer->actual_length, + transfer.rx_ctx = device->rx_ctx, + transfer.tx_ctx = device->tx_ctx + }; - if( device->callback(&transfer) == 0 ) { - libusb_submit_transfer(usb_transfer); - return; + if( device->callback(&transfer) == 0 ) + { + libusb_submit_transfer(usb_transfer); + return; + }else + { + device->streaming = false; + } } + break; + + case LIBUSB_TRANSFER_NO_DEVICE: + device->streaming = false; /* Fatal error stop transfer */ + break; + + case LIBUSB_TRANSFER_ERROR: + case LIBUSB_TRANSFER_TIMED_OUT: + case LIBUSB_TRANSFER_STALL: + case LIBUSB_TRANSFER_OVERFLOW: + case LIBUSB_TRANSFER_CANCELLED: + default: + /* Do nothing and continue */ + break; } - - device->streaming = false; } static int kill_transfer_thread(hackrf_device* device) { @@ -739,20 +793,21 @@ static int create_transfer_thread( return HACKRF_SUCCESS; } -bool hackrf_is_streaming(hackrf_device* device) { +bool ADDCALL hackrf_is_streaming(hackrf_device* device) { return device->streaming; } -int hackrf_start_rx(hackrf_device* device, hackrf_sample_block_cb_fn callback) { +int ADDCALL hackrf_start_rx(hackrf_device* device, hackrf_sample_block_cb_fn callback, void* rx_ctx) { const uint8_t endpoint_address = LIBUSB_ENDPOINT_IN | 1; int result = hackrf_set_transceiver_mode(device, HACKRF_TRANSCEIVER_MODE_RECEIVE); if( result == HACKRF_SUCCESS ) { + device->rx_ctx = rx_ctx; create_transfer_thread(device, endpoint_address, callback); } return result; } -int hackrf_stop_rx(hackrf_device* device) { +int ADDCALL hackrf_stop_rx(hackrf_device* device) { int result1, result2; result1 = kill_transfer_thread(device); result2 = hackrf_set_transceiver_mode(device, HACKRF_TRANSCEIVER_MODE_OFF); @@ -761,16 +816,17 @@ int hackrf_stop_rx(hackrf_device* device) { return result1; } -int hackrf_start_tx(hackrf_device* device, hackrf_sample_block_cb_fn callback) { +int ADDCALL hackrf_start_tx(hackrf_device* device, hackrf_sample_block_cb_fn callback, void* tx_ctx) { const uint8_t endpoint_address = LIBUSB_ENDPOINT_OUT | 2; int result = hackrf_set_transceiver_mode(device, HACKRF_TRANSCEIVER_MODE_TRANSMIT); if( result == HACKRF_SUCCESS ) { + device->tx_ctx = tx_ctx; result = create_transfer_thread(device, endpoint_address, callback); } return result; } -int hackrf_stop_tx(hackrf_device* device) { +int ADDCALL hackrf_stop_tx(hackrf_device* device) { int result1, result2; result1 = kill_transfer_thread(device); result2 = hackrf_set_transceiver_mode(device, HACKRF_TRANSCEIVER_MODE_OFF); @@ -779,7 +835,7 @@ int hackrf_stop_tx(hackrf_device* device) { return result1; } -int hackrf_close(hackrf_device* device) { +int ADDCALL hackrf_close(hackrf_device* device) { if( device != NULL ) { int result = hackrf_stop_rx(device); if( result ) { @@ -810,7 +866,7 @@ int hackrf_close(hackrf_device* device) { return HACKRF_SUCCESS; } -const char* hackrf_error_name(enum hackrf_error errcode) { +const char* ADDCALL hackrf_error_name(enum hackrf_error errcode) { switch(errcode) { case HACKRF_SUCCESS: return "HACKRF_SUCCESS"; @@ -841,7 +897,7 @@ const char* hackrf_error_name(enum hackrf_error errcode) { } } -const char* hackrf_board_id_name(enum hackrf_board_id board_id) { +const char* ADDCALL hackrf_board_id_name(enum hackrf_board_id board_id) { switch(board_id) { case BOARD_ID_JELLYBEAN: return "Jellybean"; @@ -856,3 +912,49 @@ const char* hackrf_board_id_name(enum hackrf_board_id board_id) { return "Unknown Board ID"; } } + +/* Return final bw round down and less than expected bw. */ +uint32_t ADDCALL hackrf_compute_baseband_filter_bw_round_down_lt(const uint32_t bandwidth_hz) +{ + const max2837_ft_t* p = max2837_ft; + while( p->bandwidth_hz != 0 ) + { + if( p->bandwidth_hz >= bandwidth_hz ) { + break; + } + p++; + } + /* Round down (if no equal to first entry) */ + if(p != max2837_ft) + { + p--; + } + return p->bandwidth_hz; +} + +/* Return final bw. */ +uint32_t ADDCALL hackrf_compute_baseband_filter_bw(const uint32_t bandwidth_hz) +{ + const max2837_ft_t* p = max2837_ft; + while( p->bandwidth_hz != 0 ) + { + if( p->bandwidth_hz >= bandwidth_hz ) { + break; + } + p++; + } + + /* Round down (if no equal to first entry) and if > bandwidth_hz */ + if(p != max2837_ft) + { + if(p->bandwidth_hz > bandwidth_hz) + p--; + } + + return p->bandwidth_hz; +} + +#ifdef __cplusplus +} // __cplusplus defined. +#endif + diff --git a/host/libhackrf/src/hackrf.h b/host/libhackrf/src/hackrf.h index 5a1314e2..7d5f8f22 100644 --- a/host/libhackrf/src/hackrf.h +++ b/host/libhackrf/src/hackrf.h @@ -26,6 +26,27 @@ #include #include +#ifdef _WIN32 + #define ADD_EXPORTS + + /* You should define ADD_EXPORTS *only* when building the DLL. */ + #ifdef ADD_EXPORTS + #define ADDAPI __declspec(dllexport) + #else + #define ADDAPI __declspec(dllimport) + #endif + + /* Define calling convention in one place, for convenience. */ + #define ADDCALL __cdecl + +#else /* _WIN32 not defined. */ + + /* Define with no value on non-Windows OSes. */ + #define ADDAPI + #define ADDCALL + +#endif + enum hackrf_error { HACKRF_SUCCESS = 0, HACKRF_ERROR_INVALID_PARAM = -2, @@ -50,6 +71,8 @@ typedef struct { uint8_t* buffer; int buffer_length; int valid_length; + void* rx_ctx; + void* tx_ctx; } hackrf_transfer; typedef struct { @@ -59,52 +82,62 @@ typedef struct { typedef int (*hackrf_sample_block_cb_fn)(hackrf_transfer* transfer); -int hackrf_init(); -int hackrf_exit(); +#ifdef __cplusplus +extern "C" +{ +#endif -int hackrf_open(hackrf_device** device); -int hackrf_close(hackrf_device* device); +extern ADDAPI int ADDCALL hackrf_init(); +extern ADDAPI int ADDCALL hackrf_exit(); + +extern ADDAPI int ADDCALL hackrf_open(hackrf_device** device); +extern ADDAPI int ADDCALL hackrf_close(hackrf_device* device); + +extern ADDAPI int ADDCALL hackrf_start_rx(hackrf_device* device, hackrf_sample_block_cb_fn callback, void* rx_ctx); +extern ADDAPI int ADDCALL hackrf_stop_rx(hackrf_device* device); + +extern ADDAPI int ADDCALL hackrf_start_tx(hackrf_device* device, hackrf_sample_block_cb_fn callback, void* tx_ctx); +extern ADDAPI int ADDCALL hackrf_stop_tx(hackrf_device* device); + +extern ADDAPI bool ADDCALL hackrf_is_streaming(hackrf_device* device); + +extern ADDAPI int ADDCALL hackrf_max2837_read(hackrf_device* device, uint8_t register_number, uint16_t* value); +extern ADDAPI int ADDCALL hackrf_max2837_write(hackrf_device* device, uint8_t register_number, uint16_t value); + +extern ADDAPI int ADDCALL hackrf_si5351c_read(hackrf_device* device, uint16_t register_number, uint16_t* value); +extern ADDAPI int ADDCALL hackrf_si5351c_write(hackrf_device* device, uint16_t register_number, uint16_t value); + +extern ADDAPI int ADDCALL hackrf_sample_rate_set(hackrf_device* device, const uint32_t sampling_rate_hz); +extern ADDAPI int ADDCALL hackrf_baseband_filter_bandwidth_set(hackrf_device* device, const uint32_t bandwidth_hz); + +extern ADDAPI int ADDCALL hackrf_rffc5071_read(hackrf_device* device, uint8_t register_number, uint16_t* value); +extern ADDAPI int ADDCALL hackrf_rffc5071_write(hackrf_device* device, uint8_t register_number, uint16_t value); + +extern ADDAPI int ADDCALL hackrf_spiflash_erase(hackrf_device* device); +extern ADDAPI int ADDCALL hackrf_spiflash_write(hackrf_device* device, const uint32_t address, const uint16_t length, unsigned char* const data); +extern ADDAPI int ADDCALL hackrf_spiflash_read(hackrf_device* device, const uint32_t address, const uint16_t length, unsigned char* data); + +extern ADDAPI int ADDCALL hackrf_cpld_write(hackrf_device* device, const uint16_t length, unsigned char* const data); -int hackrf_start_rx(hackrf_device* device, hackrf_sample_block_cb_fn callback); -int hackrf_stop_rx(hackrf_device* device); +extern ADDAPI int ADDCALL hackrf_board_id_read(hackrf_device* device, uint8_t* value); +extern ADDAPI int ADDCALL hackrf_version_string_read(hackrf_device* device, char* version, uint8_t length); -int hackrf_start_tx(hackrf_device* device, hackrf_sample_block_cb_fn callback); -int hackrf_stop_tx(hackrf_device* device); +extern ADDAPI int ADDCALL hackrf_set_freq(hackrf_device* device, const uint64_t freq_hz); -bool hackrf_is_streaming(hackrf_device* device); +extern ADDAPI int ADDCALL hackrf_set_amp_enable(hackrf_device* device, const uint8_t value); -int hackrf_max2837_read(hackrf_device* device, uint8_t register_number, uint16_t* value); -int hackrf_max2837_write(hackrf_device* device, uint8_t register_number, uint16_t value); +extern ADDAPI int ADDCALL hackrf_board_partid_serialno_read(hackrf_device* device, read_partid_serialno_t* read_partid_serialno); -int hackrf_si5351c_read(hackrf_device* device, uint16_t register_number, uint16_t* value); -int hackrf_si5351c_write(hackrf_device* device, uint16_t register_number, uint16_t value); +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); -int hackrf_sample_rate_set(hackrf_device* device, const uint32_t sampling_rate_hz); -int hackrf_baseband_filter_bandwidth_set(hackrf_device* device, const uint32_t bandwidth_hz); +/* Compute nearest freq for bw filter (manual filter) */ +extern ADDAPI uint32_t ADDCALL hackrf_compute_baseband_filter_bw_round_down_lt(const uint32_t bandwidth_hz); +/* Compute best default value depending on sample rate (auto filter) */ +extern ADDAPI uint32_t ADDCALL hackrf_compute_baseband_filter_bw(const uint32_t bandwidth_hz); -int hackrf_rffc5071_read(hackrf_device* device, uint8_t register_number, uint16_t* value); -int hackrf_rffc5071_write(hackrf_device* device, uint8_t register_number, uint16_t value); - -int hackrf_spiflash_erase(hackrf_device* device); -int hackrf_spiflash_write(hackrf_device* device, const uint32_t address, - const uint16_t length, unsigned char* const data); -int hackrf_spiflash_read(hackrf_device* device, const uint32_t address, - const uint16_t length, unsigned char* data); - -int hackrf_cpld_write(hackrf_device* device, const uint16_t length, - unsigned char* const data); - -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 uint64_t freq_hz); - -int hackrf_set_amp_enable(hackrf_device* device, const uint8_t value); - -int hackrf_board_partid_serialno_read(hackrf_device* device, read_partid_serialno_t* read_partid_serialno); - -const char* hackrf_error_name(enum hackrf_error errcode); -const char* hackrf_board_id_name(enum hackrf_board_id board_id); +#ifdef __cplusplus +} // __cplusplus defined. +#endif #endif//__HACKRF_H__