From 0df4b801a34697f2058b4a7b95e08d2a0576c9db Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Thu, 10 Oct 2013 10:17:27 -0700 Subject: Squashed B200 FPGA Source. Code from Josh Blum, Ian Buckley, and Matt Ettus. --- fpga/usrp3/lib/vita/generate_bits.cpp | 87 +++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 fpga/usrp3/lib/vita/generate_bits.cpp (limited to 'fpga/usrp3/lib/vita/generate_bits.cpp') diff --git a/fpga/usrp3/lib/vita/generate_bits.cpp b/fpga/usrp3/lib/vita/generate_bits.cpp new file mode 100644 index 000000000..f5ea60fc1 --- /dev/null +++ b/fpga/usrp3/lib/vita/generate_bits.cpp @@ -0,0 +1,87 @@ +//PURPOSE: C test bench for floating point converter IQ_to_FLOAT + +#include +#include +#include +#include +#include +#include +#include "math.h" +#include + +using namespace std; +//INITIAL TESTING PURPOSES: Use if you want to print individual bits + template + + void print_bits(T n) { + T mask = 1 << (sizeof(T)*8-1); + while (mask) { + cout << ((mask & n) ? "1" : "0"); + mask >>= 1; + } + cout << endl; + } + + int main() { + + + FILE *convFile; + FILE *newFile; + + + + + + + convFile = fopen("iq_to_float_input.txt", "w"); + newFile = fopen("iq_to_float_output.txt", "w"); + //iterate through test cases + + for (signed int i = -0x8000; i <= 0x7FFF; i++) { + + float end = float(i*exp2(-15)); + + + unsigned int n = *(reinterpret_cast(&end)); + + //IN CASE YOU NEED TO LOOK AT SPECIFIC EXPONENT, FRAC, ETC VALUES + //ACTIVATE BY UNCOMMENTING + /* + + unsigned int signed_bit = n>>31; + + unsigned int exp = ((n>>23) &0xFF); + + unsigned int frac = (n &0x7FFFFF); + + cout << "end: " << end << endl; + cout << "n: " << hex << n << endl; + + + + cout << "signed bit:" << hex << signed_bit << endl; + cout << "exp: " << hex << exp << endl; + cout << "fract: " << hex << frac << endl; + + float f = *(float*)&n; + cout << "f" << f << endl; +*/ + + // print_bits(start); + // print_bits(n); + unsigned int something = i; + something &= 0xFFFF; + + fprintf(convFile, "%x\n",something); + fprintf(newFile, "%x\n",n); + } + + fclose(convFile); + fclose(newFile); + + + return 0; +} + + + -- cgit v1.2.3