linux_driver: Fixed GPIO copy size bug and added/fixed timeouts

An incorrect size in for GPIO read/write resulted in memory corruption.

Added and fixed timeouts to ensure control returns to caller if the FX3
fails to respond.
cli: Added check for FPGA not loaded before performing action.
hdl: Updated build script to kick off entire build

build_bladerf.sh now takes command line arguments for the desired
FPGA revision and size. This requires that the user adds a few
item to their PATH.
lib: Added temporary workaround for not being able to read sample rate

Currently the sample rate is not read back from the si5338 and
reconstructed. For the time being, this value is cached in the the
device structure. However, this is a crappy workaround because this
value obviously won't persist, for example, upon
opening/closing/re-opening the CLI.
cli: Added 'print samplerate [rx|tx]' support
cli: Fixed bladerf_is_fpga_configured() calls to check for errors

Also removed an extranous check of state->curr_device and FPGA from
print_gpio, as this will be checked in cmd_print before print_gpio
is called.
hdl: Touched up hdl README.md to provide a few more details
linux_driver: fixup a few flash write bugs

This commits fixes a buffer length issues and pipe directionality issues.
lib: Fix RXVGA1 set/get to convert from dB to raw value

The formula used is a very crude quadratic approximation from the
3 data points given in the programming manual ... for something more
precise, we'd need a LUT. But it may vary with temp and device anyway.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
lib: Fix TXVGA2/RXVGA2, avoid casting (int*) to (uint8_t *)

Not everyone is little endian !

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Merge pull request #23 from smunaut/lib_fixes

Lib fixes
lib: Fix band selection

There was two issues :
 - Swap between the RX/TX GPIOs controlling the switch
 - The proper LNA was not being selected inside the LMS

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
lib: Avoid warning in lib when using lms_printf in 'if'

When you have something like:

if (bad_thing_happenned)
    lms_printf("Panic !");

defining lms_printf to nothing creates a warning.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
lib/lms: Clean up of the PLL parameters setting

Using 64 bit math is just way easier to read and
just as safe and precise.

Also cleanup random bits in that area

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
lib/lms: New VCOCAP search algorithm

Seems more resilient to errors than the previous one.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
lib/lms: Add a function to convert a lms_freq struct to frequency in Hz

... and use it.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Merge pull request #27 from smunaut/fixes

Various small fixed in the lib
linux_kernel: RX and TX fixes

data_*_used variable is introduced to keep track of the total number of data
packets that are inflight or have data in them. In the case of RX, a packet is
"used" when it is submitted, and it "unused" after data has been read. In the
case of TX, a packet is "used" when user-mode data is copied to it, and it is
"unused" after the URB has completed.
fix HS buffering

This commit defines nios_gpio(7) as the GPIF buffer size control signal. The FX3
firmware makes the DMA engine operate on GPIF buffers that are twice the size of
the maximum sized URB. Since this is speed dependent, bladeRFs operating in HS
will have their GPIF DMA controllers only read 1024 bytes of data (512*2)
instead of 2048 (1024) as is expected when the device is in SS mode. To fix
this, the driver tells the library when a device is HS, the library then s the
nios_gpio bit that causes the FPGA to limit itself to only reading/writing to
the 32bit GPIF for 256 cycle at a time (instead of 512 cycles at SS).
linux_diver: track which file descriptors are readers and writers

This commit disallows multiple file descriptors from simulatenously reading or
simultaneously writing to the bladeRF.