diff --git a/project_files/project4/ofdm/HLS/3_OFDM/fft.cpp b/project_files/project4/ofdm/HLS/3_OFDM/fft.cpp index 5c6f101..14b8867 100644 --- a/project_files/project4/ofdm/HLS/3_OFDM/fft.cpp +++ b/project_files/project4/ofdm/HLS/3_OFDM/fft.cpp @@ -9,53 +9,6 @@ #include "fft.h" -void bit_reverse(DTYPE X_R[SIZE], DTYPE X_I[SIZE]); -void fft_stage_first(DTYPE X_R[SIZE], DTYPE X_I[SIZE], DTYPE OUT_R[SIZE], - DTYPE OUT_I[SIZE]); -void fft_stages(DTYPE X_R[SIZE], DTYPE X_I[SIZE], int STAGES, DTYPE OUT_R[SIZE], - DTYPE OUT_I[SIZE]); -void fft_stage_last(DTYPE X_R[SIZE], DTYPE X_I[SIZE], DTYPE OUT_R[SIZE], - DTYPE OUT_I[SIZE]); -void qpsk_decode(DTYPE R[SIZE], DTYPE I[SIZE], int D[SIZE]); - -void demod(DTYPE X_R[SIZE], DTYPE X_I[SIZE], int D[SIZE], DTYPE OUT_R[SIZE], DTYPE OUT_I[SIZE]) -{ - - fft(X_R, X_I, OUT_R, OUT_I); - qpsk_decode(OUT_R, OUT_I, D); - -} - -void fft(DTYPE X_R[SIZE], DTYPE X_I[SIZE], DTYPE OUT_R[SIZE], - DTYPE OUT_I[SIZE]) { - - bit_reverse(X_R, X_I); - - //Call fft - DTYPE Stage1_R[SIZE], Stage1_I[SIZE]; - DTYPE Stage2_R[SIZE], Stage2_I[SIZE]; - DTYPE Stage3_R[SIZE], Stage3_I[SIZE]; - DTYPE Stage4_R[SIZE], Stage4_I[SIZE]; - DTYPE Stage5_R[SIZE], Stage5_I[SIZE]; - DTYPE Stage6_R[SIZE], Stage6_I[SIZE]; - DTYPE Stage7_R[SIZE], Stage7_I[SIZE]; - DTYPE Stage8_R[SIZE], Stage8_I[SIZE]; - DTYPE Stage9_R[SIZE], Stage9_I[SIZE]; - - fft_stage_first(X_R, X_I, Stage1_R, Stage1_I); - fft_stages(Stage1_R, Stage1_I, 2, Stage2_R, Stage2_I); - fft_stages(Stage2_R, Stage2_I, 3, Stage3_R, Stage3_I); - fft_stages(Stage3_R, Stage3_I, 4, Stage4_R, Stage4_I); - fft_stages(Stage4_R, Stage4_I, 5, Stage5_R, Stage5_I); - fft_stages(Stage5_R, Stage5_I, 6, Stage6_R, Stage6_I); - fft_stages(Stage6_R, Stage6_I, 7, Stage7_R, Stage7_I); - fft_stages(Stage7_R, Stage7_I, 8, Stage8_R, Stage8_I); - fft_stages(Stage8_R, Stage8_I, 9, Stage9_R, Stage9_I); - fft_stage_last(Stage9_R, Stage9_I, OUT_R, OUT_I); - - bit_reverse(OUT_R, OUT_I); - -} /*=======================BEGIN: FFT=========================*/ //stage 1 diff --git a/project_files/project4/ofdm/HLS/3_OFDM/fft.h b/project_files/project4/ofdm/HLS/3_OFDM/fft.h index 5491980..446afe2 100644 --- a/project_files/project4/ofdm/HLS/3_OFDM/fft.h +++ b/project_files/project4/ofdm/HLS/3_OFDM/fft.h @@ -79,10 +79,20 @@ const DTYPE W_real[]={1.000000, 0.999981,0.999925,0.999831,0.999699,0.999529,0.9 -0.995767,-0.996313,-0.996820,-0.997290,-0.997723,-0.998118,-0.998476,-0.998795,-0.999078,-0.999322,-0.999529,-0.999699,-0.999831,-0.999925,-0.999981}; const DTYPE W_imag[]={-0.000000,-0.006136,-0.012272,-0.018407,-0.024541,-0.030675,-0.036807,-0.042938,-0.049068,-0.055195,-0.061321,-0.067444,-0.073565,-0.079682,-0.085797,-0.091909,-0.098017,-0.104122,-0.110222,-0.116319,-0.122411,-0.128498,-0.134581,-0.140658,-0.146730,-0.152797,-0.158858,-0.164913,-0.170962,-0.177004,-0.183040,-0.189069,-0.195090,-0.201105,-0.207111,-0.213110,-0.219101,-0.225084,-0.231058,-0.237024,-0.242980,-0.248928,-0.254866,-0.260794,-0.266713,-0.272621,-0.278520,-0.284408,-0.290285,-0.296151,-0.302006,-0.307850,-0.313682,-0.319502,-0.325310,-0.331106,-0.336890,-0.342661,-0.348419,-0.354164,-0.359895,-0.365613,-0.371317,-0.377007,-0.382683,-0.388345,-0.393992,-0.399624,-0.405241,-0.410843,-0.416430,-0.422000,-0.427555,-0.433094,-0.438616,-0.444122,-0.449611,-0.455084,-0.460539,-0.465977,-0.471397,-0.476799,-0.482184,-0.487550,-0.492898,-0.498228,-0.503538,-0.508830,-0.514103,-0.519356,-0.524590,-0.529804,-0.534998,-0.540172,-0.545325,-0.550458,-0.555570,-0.560662,-0.565732,-0.570781,-0.575808,-0.580814,-0.585798,-0.590760,-0.595699,-0.600617,-0.605511,-0.610383,-0.615232,-0.620057,-0.624860,-0.629638,-0.634393,-0.639124,-0.643832,-0.648514,-0.653173,-0.657807,-0.662416,-0.667000,-0.671559,-0.676093,-0.680601,-0.685084,-0.689541,-0.693971,-0.698376,-0.702755,-0.707107,-0.711432,-0.715731,-0.720003,-0.724247,-0.728464,-0.732654,-0.736817,-0.740951,-0.745058,-0.749136,-0.753187,-0.757209,-0.761202,-0.765167,-0.769103,-0.773010,-0.776888,-0.780737,-0.784557,-0.788346,-0.792107,-0.795837,-0.799537,-0.803208,-0.806848,-0.810457,-0.814036,-0.817585,-0.821103,-0.824589,-0.828045,-0.831470,-0.834863,-0.838225,-0.841555,-0.844854,-0.848120,-0.851355,-0.854558,-0.857729,-0.860867,-0.863973,-0.867046,-0.870087,-0.873095,-0.876070,-0.879012,-0.881921,-0.884797,-0.887640,-0.890449,-0.893224,-0.895966,-0.898674,-0.901349,-0.903989,-0.906596,-0.909168,-0.911706,-0.914210,-0.916679,-0.919114,-0.921514,-0.923880,-0.926210,-0.928506,-0.930767,-0.932993,-0.935184,-0.937339,-0.939459,-0.941544,-0.943593,-0.945607,-0.947586,-0.949528,-0.951435,-0.953306,-0.955141,-0.956940,-0.958703,-0.960431,-0.962121,-0.963776,-0.965394,-0.966976,-0.968522,-0.970031,-0.971504,-0.972940,-0.974339,-0.975702,-0.977028,-0.978317,-0.979570,-0.980785,-0.981964,-0.983105,-0.984210,-0.985278,-0.986308,-0.987301,-0.988258,-0.989177,-0.990058,-0.990903,-0.991710,-0.992480,-0.993212,-0.993907,-0.994565,-0.995185,-0.995767,-0.996313,-0.996820,-0.997290,-0.997723,-0.998118,-0.998476,-0.998795,-0.999078,-0.999322,-0.999529,-0.999699,-0.999831,-0.999925,-0.999981,-1.000000,-0.999981,-0.999925,-0.999831,-0.999699,-0.999529,-0.999322,-0.999078,-0.998795,-0.998476,-0.998118,-0.997723,-0.997290,-0.996820,-0.996313,-0.995767,-0.995185,-0.994565,-0.993907,-0.993212,-0.992480,-0.991710,-0.990903,-0.990058,-0.989177,-0.988258,-0.987301,-0.986308,-0.985278,-0.984210,-0.983105,-0.981964,-0.980785,-0.979570,-0.978317,-0.977028,-0.975702,-0.974339,-0.972940,-0.971504,-0.970031,-0.968522,-0.966976,-0.965394,-0.963776,-0.962121,-0.960431,-0.958703,-0.956940,-0.955141,-0.953306,-0.951435,-0.949528,-0.947586,-0.945607,-0.943593,-0.941544,-0.939459,-0.937339,-0.935183,-0.932993,-0.930767,-0.928506,-0.926210,-0.923880,-0.921514,-0.919114,-0.916679,-0.914210,-0.911706,-0.909168,-0.906596,-0.903989,-0.901349,-0.898674,-0.895966,-0.893224,-0.890449,-0.887640,-0.884797,-0.881921,-0.879012,-0.876070,-0.873095,-0.870087,-0.867046,-0.863973,-0.860867,-0.857729,-0.854558,-0.851355,-0.848120,-0.844854,-0.841555,-0.838225,-0.834863,-0.831470,-0.828045,-0.824589,-0.821102,-0.817585,-0.814036,-0.810457,-0.806848,-0.803208,-0.799537,-0.795837,-0.792107,-0.788346,-0.784557,-0.780737,-0.776888,-0.773010,-0.769103,-0.765167,-0.761202,-0.757209,-0.753187,-0.749136,-0.745058,-0.740951,-0.736817,-0.732654,-0.728464,-0.724247,-0.720002,-0.715731,-0.711432,-0.707107,-0.702755,-0.698376,-0.693971,-0.689541,-0.685084,-0.680601,-0.676093,-0.671559,-0.667000,-0.662416,-0.657807,-0.653173,-0.648514,-0.643831,-0.639124,-0.634393,-0.629638,-0.624859,-0.620057,-0.615232,-0.610383,-0.605511,-0.600616,-0.595699,-0.590760,-0.585798,-0.580814,-0.575808,-0.570781,-0.565732,-0.560661,-0.555570,-0.550458,-0.545325,-0.540171,-0.534998,-0.529804,-0.524590,-0.519356,-0.514103,-0.508830,-0.503538,-0.498228,-0.492898,-0.487550,-0.482184,-0.476799,-0.471397,-0.465976,-0.460539,-0.455084,-0.449611,-0.444122,-0.438616,-0.433094,-0.427555,-0.422000,-0.416429,-0.410843,-0.405241,-0.399624,-0.393992,-0.388345,-0.382683,-0.377007,-0.371317,-0.365613,-0.359895,-0.354163,-0.348419,-0.342661,-0.336890,-0.331106,-0.325310,-0.319502,-0.313682,-0.307850,-0.302006,-0.296151,-0.290285,-0.284407,-0.278520,-0.272621,-0.266713,-0.260794,-0.254866,-0.248928,-0.242980,-0.237024,-0.231058,-0.225084,-0.219101,-0.213110,-0.207111,-0.201105,-0.195090,-0.189069,-0.183040,-0.177004,-0.170962,-0.164913,-0.158858,-0.152797,-0.146730,-0.140658,-0.134581,-0.128498,-0.122411,-0.116319,-0.110222,-0.104122,-0.098017,-0.091909,-0.085797,-0.079682,-0.073564,-0.067444,-0.061321,-0.055195,-0.049068,-0.042938,-0.036807,-0.030675,-0.024541,-0.018407,-0.012271,-0.006136}; -void fft(DTYPE XX_R[SIZE], DTYPE XX_I[SIZE], DTYPE OUT_R[SIZE], DTYPE OUT_I[SIZE]); +typedef ap_axis<32,2,5,6> transPkt; -void demod(DTYPE X_R[SIZE], DTYPE X_I[SIZE], int D[SIZE], DTYPE OUT_R[SIZE], DTYPE OUT_I[SIZE]); +union fp_int { + int i; + float fp; +}; -void ofdm_receiver( volatile DTYPE *inptr, volatile uint32_t *outptr ); + +void ofdm_receiver(hls::stream &x_real, hls::stream &x_imag, hls::stream &out); + +void bit_reverse(DTYPE X_R[SIZE], DTYPE X_I[SIZE], DTYPE OUT_R[SIZE], DTYPE OUT_I[SIZE]); +void fft_stage_first(DTYPE X_R[SIZE], DTYPE X_I[SIZE], DTYPE OUT_R[SIZE], DTYPE OUT_I[SIZE]); +void fft_stages(DTYPE X_R[SIZE], DTYPE X_I[SIZE], int STAGES, DTYPE OUT_R[SIZE], DTYPE OUT_I[SIZE]); +void fft_stage_last(DTYPE X_R[SIZE], DTYPE X_I[SIZE], DTYPE OUT_R[SIZE], DTYPE OUT_I[SIZE]); +void qpsk_decode(DTYPE R[SIZE], DTYPE I[SIZE], int D[SIZE]); #endif diff --git a/project_files/project4/ofdm/HLS/3_OFDM/ofdm_recvr.cpp b/project_files/project4/ofdm/HLS/3_OFDM/ofdm_recvr.cpp index 7d750cb..2da78f8 100644 --- a/project_files/project4/ofdm/HLS/3_OFDM/ofdm_recvr.cpp +++ b/project_files/project4/ofdm/HLS/3_OFDM/ofdm_recvr.cpp @@ -1,25 +1,64 @@ #include "fft.h" -static unsigned short count; -static DTYPE xr[ SIZE ]; -static DTYPE xi[ SIZE ]; -static DTYPE xr_out[ SIZE ]; -static DTYPE xi_out[ SIZE ]; -static int dout[ SIZE ]; - -void ofdm_receiver( volatile DTYPE *inptr, volatile uint32_t *outptr ) +// This top level function uses the FFT and qpsk_decode functions +// defined in the other cpp files. Inputs are read and written as described in the +// multiple DMAs lab + +void ofdm_receiver(hls::stream &x_real, hls::stream &x_imag, hls::stream &out) { -#pragma AP interface ap_fifo port=inptr -#pragma AP interface ap_fifo port=outptr -#pragma AP interface ap_ctrl_none port=return - - *outptr++ = dout[ count ]; - - xr[ count ] = *inptr++; - xi[ count ] = *inptr++; - count++; - if( count == 1024 ){ - count = 0; - demod( xr, xi, dout, xr_out, xi_out ); +#pragma HLS INTERFACE mode=axis port=x_real,x_imag,out +#pragma HLS INTERFACE mode=s_axilite port=return +#pragma HLS DATAFLOW + + fp_int xr[SIZE], xi[SIZE]; + int D[SIZE]; + DTYPE X_R[SIZE], X_I[SIZE]; + transPkt xrPkt, xiPkt; + + // read from input stream + for (int i = 0; i < SIZE; i += 1) { + xrPkt = x_real.read(); + xr[i].i = xrPkt.data; + X_R[i] = xr[i].fp; + xiPkt = x_imag.read(); + xi[i].i = xiPkt.data; + X_I[i] = xi[i].fp; + } + + //Call fft + DTYPE REV_R[SIZE], REV_I[SIZE]; + DTYPE Stage1_R[SIZE], Stage1_I[SIZE]; + DTYPE Stage2_R[SIZE], Stage2_I[SIZE]; + DTYPE Stage3_R[SIZE], Stage3_I[SIZE]; + DTYPE Stage4_R[SIZE], Stage4_I[SIZE]; + DTYPE Stage5_R[SIZE], Stage5_I[SIZE]; + DTYPE Stage6_R[SIZE], Stage6_I[SIZE]; + DTYPE Stage7_R[SIZE], Stage7_I[SIZE]; + DTYPE Stage8_R[SIZE], Stage8_I[SIZE]; + DTYPE Stage9_R[SIZE], Stage9_I[SIZE]; + DTYPE TEMP_R[SIZE], TEMP_I[SIZE]; + DTYPE OUT_R[SIZE], OUT_I[SIZE]; + + bit_reverse(X_R, X_I, REV_R, REV_I); + + fft_stage_first(REV_R, REV_I, Stage1_R, Stage1_I); + fft_stages(Stage1_R, Stage1_I, 2, Stage2_R, Stage2_I); + fft_stages(Stage2_R, Stage2_I, 3, Stage3_R, Stage3_I); + fft_stages(Stage3_R, Stage3_I, 4, Stage4_R, Stage4_I); + fft_stages(Stage4_R, Stage4_I, 5, Stage5_R, Stage5_I); + fft_stages(Stage5_R, Stage5_I, 6, Stage6_R, Stage6_I); + fft_stages(Stage6_R, Stage6_I, 7, Stage7_R, Stage7_I); + fft_stages(Stage7_R, Stage7_I, 8, Stage8_R, Stage8_I); + fft_stages(Stage8_R, Stage8_I, 9, Stage9_R, Stage9_I); + fft_stage_last(Stage9_R, Stage9_I, TEMP_R, TEMP_I); + + bit_reverse(TEMP_R, TEMP_I, OUT_R, OUT_I); + qpsk_decode(OUT_R, OUT_I, D); + + // write to output stream + for (int i = 0; i < SIZE; i += 1) { + xrPkt.data = D[i]; + xrPkt.last = (i==SIZE-1)?1:0; + out.write(xrPkt); } }