Advertisement
Guest User

Untitled

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