Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ezdsp5535.h"
- #include "stdio.h"
- #include "csl_general.h"
- #include "soc.h"
- #include "cslr_cpu.h"
- #include "stdlib.h"
- #include "csl_types.h"
- #include "hwafft.h"
- #include "math.h"
- #define FFT_FLAG ( 0 ) /* HWAFFT to perform FFT */
- #define IFFT_FLAG ( 1 ) /* HWAFFT to perform IFFT */
- #define SCALE_FLAG ( 0 ) /* HWAFFT to scale butterfly output */
- #define NOSCALE_FLAG ( 1 ) /* HWAFFT not to scale butterfly output */
- #define OUT_SEL_DATA ( 0 ) /* Indicates HWAFFT output located in input data vector */
- #define OUT_SEL_SCRATCH ( 1 ) /* Indicates HWAFFT output located in scratch vector */
- //HWAFFT variables
- Int32 *data;
- Int32 *data_br;
- Uint16 fft_flag;
- Uint16 scale_flag;
- Int32 *scratch;
- Uint16 out_sel;
- Int32 *result;
- /* Set and align bit reverse buffer.
- This buffer must be aligned in RAM such that log2(4 *N) zeros
- appear in the least significant bits of the byte address (8 bits),
- where N is the FFT Length. This was taken from spruh87b, section 2.10.3 */
- #pragma DATA_SECTION(data_br_buf, "data_br_buf");
- #pragma DATA_ALIGN (data_br_buf, 2048);
- Int32 data_br_buf[1024];
- // data_buf contains input data required for hwafft function
- // upper signed 16 bits:real lower signed 16 bits: img (all zeros)
- #pragma DATA_SECTION(data_buf , "data_buf");
- Int32 data_buf[1024];
- // scratcg buffer as required by the hwafft function
- #pragma DATA_SECTION(scratch_buf, "scratch_buf");
- Int32 scratch_buf[1024];
- int main(void) {
- int i = 0;
- // Data previously captured from ADC in unsiged 16 bit. It must first be set withing the range of a signed
- // 16 bit variable.
- Int16 adcdata[1024] = { 24256,21301,21164,21395,21346,21200,21446,21396,21237,21496,21442,21288,21544,21501,
- 21349,21596,21568,21434,21669,21645,21532,21748,21721,21636,21832,21795,21741,21920,21869,21846,22021,21945,
- 21952,22128,22027,22064,22251,22131,22183,22387,22248,22300,22525,22363,22408,22660,22491,22522,22794,22629,
- 22646,22933,22788,22787,23084,22962,22951,23236,23144,23128,23387,23321,23313,23537,23488,23502,23690,23648,
- 23697,23844,23801,23900,24021,23970,24115,24216,24146,24338,24422,24329,24557,24643,24521,24764,24852,24707,
- 24968,25075,24926,25189,25312,25164,25416,25544,25408,25646,25769,25653,25880,25985,25901,26118,26198,26140,
- 26359,26413,26368,26590,26613,26577,26812,26816,26774,27027,27017,26964,27232,27220,27161,27430,27425,27365,
- 27629,27634,27577,27822,27835,27793,28014,28017,28011,28200,28186,28219,28388,28349,28422,28584,28506,28619,
- 28782,28661,28798,28979,28823,28960,29160,28984,29111,29333,29154,29258,29488,29323,29401,29618,29485,29541,
- 29740,29645,29694,29856,29789,29850,29969,29921,30008,30083,30030,30152,30196,30120,30283,30314,30203,30391,
- 30432,30283,30486,30544,30371,30568,30642,30460,30639,30728,30554,30713,30802,30656,30798,30869,30757,30897,
- 30930,30848,31000,30982,30914,31098,31044,30976,31186,31114,31032,31260,31184,31086,31316,31248,31137,31346,
- 31308,31200,31362,31349,31265,31384,31368,31333,31413,31377,31409,31473,31384,31437,31505,31390,31475,31577,
- 31413,31501,31656,31470,31530,31723,31541,31557,31769,31610,31593,31808,31671,31641,31829,31729,31707,31851,
- 31762,31778,31883,31772,31834,31912,31770,31865,31947,31763,31878,31972,31760,31867,31983,31769,31846,31965,
- 31776,31816,31920,31787,31814,31882,31808,31844,31850,31811,31888,31833,31803,31931,31841,31786,31969,31865,
- 31768,31969,31899,31768,31960,31937,31783,31938,31960,31817,31926,31960,31856,31927,31934,31882,31945,31909,
- 31892,32021,31939,31876,31980,31853,31836,32034,31924,31854,32064,31972,31874,32080,32024,31927,32080,32056,
- 32000,32097,32065,32070,32131,32066,32139,32189,32061,32181,32253,32073,32196,32314,32104,32193,32342,32144,
- 32188,32341,32189,32192,32320,32229,32224,32299,32256,32278,32292,32257,32328,32302,32242,32362,32349,32228,
- 32364,32371,32224,32347,32410,32243,32324,32416,32276,32306,32398,32309,32320,32368,32331,32361,32353,32338,
- 32424,32360,32321,32480,32392,32304,32515,32449,32304,32526,32512,32336,32529,32553,32393,32528,32561,32458,
- 32539,32546,32512,32576,32528,32539,32616,32509,32532,32651,32512,32509,32668,32544,32497,32657,32590,32512,
- 32632,32625,32553,32605,32633,32600,32594,32611,32641,32608,32577,32661,32642,32553,32649,32677,32544,32609,
- 32704,32556,32573,32700,32588,32555,32675,32618,32568,32648,32625,32602,32622,32609,32644,32627,32579,32672,
- 32656,32552,32672,32691,32544,32645,32714,32568,32619,32717,32609,32601,32688,32650,32609,32640,32673,32636,
- 32600,32667,32672,32592,32640,32699,32609,32612,32708,32652,32593,32666,32677,32604,32626,32691,32640,32604,
- 32686,32685,32610,32663,32709,32636,32632,32704,32677,32624,32672,32713,32640,32636,32726,32674,32611,32716,
- 32710,32610,32688,32720,32641,32669,32704,32688,32672,32668,32724,32712,32643,32737,32736,32610,32717,32774,
- 32612,32680,32790,32654,32665,32774,32697,32672,32740,32728,32706,32711,32730,32754,32699,32712,32794,32728,
- 32688,32809,32768,32673,32789,32816,32717,32763,32822,32706,32723,32803,32744,32701,32753,32760,32723,32708,
- 32753,32768,32691,32730,32816,32712,32700,32846,32760,32682,32844,32809,32688,32824,32836,32718,32800,32820,
- 32768,32796,32776,32802,32827,32720,32810,32880,32694,32788,32922,32701,32755,32941,32745,32737,32928,32800,
- 32744,32885,32833,32784,32845,32833,32841,32796,32792,32898,32805,32742,32921,32853,32720,32910,32913,32736,
- 32868,32944,32784,32829,32938,32854,32819,32901,32905,32849,32859,32914,32907,32835,32882,32957,32851,32837,
- 33002,32922,32812,33002,32993,32817,32970,33036,32850,32937,33053,32930,32950,33040,33000,32985,33014,33058,
- 33080,33017,33080,33170,33048,33064,33227,33106,33051,33253,33203,33072,33236,33269,33116,33208,33312,33177,
- 33168,33284,33219,33162,33249,33243,33187,33206,33226,33232,33185,33175,33269,33206,33124,33292,33251,33080,
- 33268,33296,33072,33242,33346,33115,33227,33357,33172,33220,33320,33213,33240,33274,33249,33301,33246,33254,
- 33361,33235,33227,33413,33258,33195,33424,33290,33173,33408,33339,33184,33368,33360,33218,33334,33367,33267,
- 33305,33327,33302,33305,33284,33328,33350,33259,33320,33388,33239,33281,33424,33255,33250,33453,33304,33227,
- 33456,33352,33225,33426,33379,33243,33392,33395,33301,33387,33387,33352,33384,33345,33376,33409,33328,33416,
- 33464,33316,33405,33504,33325,33387,33540,33368,33372,33554,33424,33365,33536,33475,33366,33496,33524,33421,
- 33501,33552,33460,33472,33537,33497,33497,33536,33526,33521,33496,33521,33570,33484,33492,33595,33459,33424,
- 33592,33445,33360,33586,33479,33356,33593,33536,33400,33619,33596,33473,33635,33629,33543,33660,33664,33655,
- 33732,33685,33722,33771,33690,33767,33830,33712,33789,33864,33710,33760,33864,33721,33760,33896,33768,33763,
- 33914,33832,33811,33929,33860,33826,33920,33864,33846,33923,33876,33884,33926,33864,33906,33940,33865,33953,
- 33996,33890,33985,34030,33888,33981,34048,33888,33977,34056,33875,33938,34029,33875,33917,34011,33881,33896,
- 33979,33889,33898,33954,33893,33891,33920,33891,33909,33909,33891,33915,33884,33858,33900,33864,33826,33888,
- 33865,33808,33874,33870,33784,33858,33884,33784,33842,33904,33806,33856,33933,33828,33848,33941,33844,33852,
- 33958,33876,33864,33947,33881,33880,33953,33910,33920,33964,33920,33946,33968,33918,33973,33984,33933,34020,
- 34020,33952,34054,34052,33955,34074,34092,33984,34108,34138,34002,34120,34163,34024,34124,34197,34056,34153,
- 34237,34096,34177,34268,34134,34200,34290,34186,34256,34320,34224,34292,34336,34244,34328,34354,34280,34384,
- 34377,34304,34424,34392,34318,34469,34418,34336,34504,34456,34385,34572,34510,34424,34605,34537,34448,34628,
- 34565,34473,34646,34592,34510,34664,34619,34554,34692,34649,34595,34709,34668,34618,34709,34672,34651,34728,
- 34680,34678,34747,34698,34702,34769,34736,34747,34803,34756,34760,34816,34764,34764,34835,34780,34784,34873,
- 34816,34800,34892,34824,34800,34907,34843,34812,34933,34872,34835,34960,34909,34878,35019,34976,34915,35043,
- 34996,34934};
- // set scratch pointer to scratch_buf
- scratch = scratch_buf;
- //set data_br pointer to data_br_buf
- data_br = data_br_buf;
- //set data pointer to data_buf
- data = data_buf;
- // Format the data in the large array above to fit within the signed 16 bit range
- for (i = 0; i < 1024; i++) {
- if (adcdata[i] <= (Int16) 0 )
- {
- adcdata[i] = adcdata[i] + (Int16) 32767;
- adcdata[i] = adcdata[i] + (Int16) 1 ;
- }
- else
- {
- adcdata[i] = adcdata[i] - (Int16) 32767;
- adcdata[i] = adcdata[i] - (Int16) 1 ;
- }
- }
- // Set data into 32 bit vector ( Real -> 31-16 , Img -> 15-0 ;Img is all 0's
- for(i = 0; i < 1024; i++)
- {
- data[i] = (Int32) adcdata[i];
- data[i] = data[i] << 16;
- data[i] = data[i] & 0xFFFF0000;
- }
- //set flags
- fft_flag = FFT_FLAG;
- scale_flag = SCALE_FLAG;
- /* Bit-Reverse 1024-point data, Store into data_br_buf, data_br_buf aligned to
- 12-least significant binary zeros*/
- hwafft_br(data, data_br, 1024); /* bit-reverse input data,
- Destination buffer aligned */
- // set data pointer equal to data_br pointer which points to data_br_buf
- data = data_br;
- /* Compute 1024-point FFT, scaling enabled. */
- out_sel = hwafft_1024pts(data, scratch, fft_flag, scale_flag);
- if (out_sel == OUT_SEL_DATA) {
- result = data;
- }else {
- result = scratch;
- }
- printf("Test \n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement