Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.18 KB | None | 0 0
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * Use of the Software is limited solely to applications:
  16. * (a) running on a Xilinx device, or
  17. * (b) that interact with a Xilinx device through a bus or interconnect.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
  24. * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. * SOFTWARE.
  26. *
  27. * Except as contained in this notice, the name of the Xilinx shall not be used
  28. * in advertising or otherwise to promote the sale, use or other dealings in
  29. * this Software without prior written authorization from Xilinx.
  30. *
  31. ******************************************************************************/
  32.  
  33. /*
  34. *
  35. *
  36. * This application configures UART 16550 to baud rate 9600.
  37. * PS7 UART (Zynq) is not initialized by this application, since
  38. * bootrom/bsp configures it to baud rate 115200
  39. *
  40. * ------------------------------------------------
  41. * | UART TYPE BAUD RATE |
  42. * ------------------------------------------------
  43. * uartns550 9600
  44. * uartlite Configurable only in HW design
  45. * ps7_uart 115200 (configured by bootrom/bsp)
  46. *
  47. *
  48. * This application is used to test the TiReX core. It controls the
  49. * microblaze which then sends all the control signals and data to the
  50. * core through AXI Lite.
  51. */
  52.  
  53. #include <stdio.h>
  54. #include "platform.h"
  55. #include "xparameters.h"
  56. #include "xil_io.h"
  57. #include "tirex_core_ip.h"
  58. #include "xil_printf.h"
  59. #include "xil_types.h"
  60. #include "tirex_core_test.h"
  61.  
  62. #define DEBUG_BRAM_DATA 0
  63. #define DEBUG_INSTR_MEM 1
  64.  
  65. int main()
  66. {
  67. init_platform();
  68. int i;
  69.  
  70. /*
  71. The following constants define:
  72. - The starting address of the instructions
  73. - The starting character of the data in the BRAM
  74. - The ending character in the BRAM
  75. */
  76. const u32 instr_start_addr = 0;
  77. const u32 data_start_addr = 0;
  78. const u32 data_end_addr = 16000;
  79.  
  80. // Address needed by the MicroBlaze to write/read at a certain
  81. // address in the BRAM
  82. u32 data_address = data_start_addr;
  83. // Control signal to tell to the BRAM if or not to write
  84. u32 data_we = 0x0;
  85.  
  86. // Instruction address needed to load instruction in the Instruction
  87. // Memory of the core
  88. u32 instr_address = 0x0;
  89.  
  90. /*
  91. Control Vector that holds all the control bits needed by the core
  92.  
  93. VALUE MEANING
  94. 0x0 Core disabled
  95. 0x1 Search of the core but core disabled
  96. 0x2 Write the Instruction reference data
  97. 0x4 Write the Instruction opcode
  98. 0x8 Enable the core
  99. 0x9 Enable the core and the search
  100. 0x10 Enable BRAM debug mode
  101. 0x20 Reset the system
  102. */
  103. u32 control = 0x0;
  104.  
  105. // Data in AXI register 7 that holds the results of the computation
  106. u32 result = 0x0;
  107.  
  108. // Data in AXI register 8 that holds the character index of the matching string
  109. u32 char_num = 0x0;
  110.  
  111. // These variable are filled when the computation terminates and are needed
  112. // to display the results
  113. u8 found = 0;
  114. u8 end_data = 0;
  115. u8 correct_match = 0;
  116. u32 timing_counter = 0;
  117.  
  118. // This array serves to display the data coming from the BRAM
  119. u32 bram_data[4];
  120.  
  121. /*
  122. This array holds the instructions to be loaded into the
  123. instruction memory. The instruction are organized as follows:
  124. - first dimension : reference data
  125. - second dimension : opcode
  126.  
  127. OPCODE MEANING
  128. 0x7 JMP
  129. 0x8 OR
  130. 0x9 OR )*
  131. 0xa OR )+
  132. 0xb OR )|
  133. 0xc OR )
  134. 0x10 AND
  135. 0x11 AND )*
  136. 0x12 AND )+
  137. 0x13 AND )|
  138. 0x14 AND )
  139. 0x20 (
  140.  
  141. The array must be filled with the instruction provided by the compiler in
  142. order to test the regular expression
  143. */
  144.  
  145. // Resetting the system
  146. control = 0x20;
  147.  
  148. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  149. TIREX_CORE_IP_S00_AXI_SLV_REG7_OFFSET,
  150. control);
  151.  
  152. xil_printf("Initializing Instruction RAM of Tirex core...\n");
  153. control = 0x0;
  154. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  155. TIREX_CORE_IP_S00_AXI_SLV_REG7_OFFSET,
  156. control);
  157.  
  158. // Check if the core output is clean
  159. result = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  160. TIREX_CORE_IP_S00_AXI_SLV_REG7_OFFSET);
  161.  
  162. xil_printf("\tcomplete = %d\n", result & (1 << 0));
  163. xil_printf("\tfound = %d\n", result & (1 << 1));
  164.  
  165. /**
  166. * Fill the instruction RAM of the core
  167. */
  168. for(i = 0; i < sizeof(instr) / sizeof(u32) / 2; i++){
  169. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  170. TIREX_CORE_IP_S00_AXI_SLV_REG0_OFFSET,
  171. instr_address);
  172. control = 0x2;
  173. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  174. TIREX_CORE_IP_S00_AXI_SLV_REG7_OFFSET,
  175. control);
  176.  
  177. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  178. TIREX_CORE_IP_S00_AXI_SLV_REG1_OFFSET,
  179. instr[i][0]);
  180.  
  181. control = 0x4;
  182. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  183. TIREX_CORE_IP_S00_AXI_SLV_REG7_OFFSET,
  184. control);
  185.  
  186. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  187. TIREX_CORE_IP_S00_AXI_SLV_REG1_OFFSET,
  188. instr[i][1]);
  189.  
  190. if(DEBUG_INSTR_MEM)
  191. xil_printf("Instruction:\n"
  192. "\topcode --> %x\n"
  193. "\treference --> %x\n", instr[i][1], instr[i][0]);
  194.  
  195.  
  196. instr_address += 1;
  197. }
  198.  
  199. /*
  200. * Fill the data RAM of the core if needed
  201. */
  202. if(sizeof(data) != 0)
  203. {
  204. xil_printf("Initializing Data RAM of Tirex core...\n");
  205. data_we = 0x1;
  206. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  207. TIREX_CORE_IP_S00_AXI_SLV_REG2_OFFSET,
  208. data_we);
  209.  
  210. for(i = 0; i < sizeof(data) / sizeof(u32); i++){
  211. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  212. TIREX_CORE_IP_S00_AXI_SLV_REG8_OFFSET,
  213. data_address);
  214.  
  215. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  216. TIREX_CORE_IP_S00_AXI_SLV_REG9_OFFSET,
  217. data[i]);
  218.  
  219. data_address += 1;
  220. }
  221.  
  222. data_we = 0x0;
  223.  
  224. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  225. TIREX_CORE_IP_S00_AXI_SLV_REG2_OFFSET,
  226. data_we);
  227. }
  228.  
  229. //
  230. if(DEBUG_BRAM_DATA)
  231. {
  232. xil_printf("Checking data in BRAM\n");
  233.  
  234. control = 0x10;
  235. data_address = 0x0;
  236.  
  237. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  238. TIREX_CORE_IP_S00_AXI_SLV_REG7_OFFSET,
  239. control);
  240. xil_printf("SIZE: %d", sizeof(data));
  241. for(i = 0; i < sizeof(data) / sizeof(u32) / 4; i++){
  242. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  243. TIREX_CORE_IP_S00_AXI_SLV_REG3_OFFSET,
  244. data_address);
  245.  
  246. bram_data[0] = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  247. TIREX_CORE_IP_S00_AXI_SLV_REG2_OFFSET);
  248. bram_data[1] = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  249. TIREX_CORE_IP_S00_AXI_SLV_REG3_OFFSET);
  250. bram_data[2] = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  251. TIREX_CORE_IP_S00_AXI_SLV_REG4_OFFSET);
  252. bram_data[3] = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  253. TIREX_CORE_IP_S00_AXI_SLV_REG5_OFFSET);
  254.  
  255. xil_printf("Data at address %x\n"
  256. "\t %x%x%x%x\n", data_address, bram_data[3], bram_data[2], bram_data[1], bram_data[0]);
  257.  
  258. data_address += 1;
  259. }
  260.  
  261. data_address = 0x0;
  262. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  263. TIREX_CORE_IP_S00_AXI_SLV_REG3_OFFSET,
  264. data_address);
  265. }
  266.  
  267. /*
  268. * Set up of the core for the search
  269. */
  270. xil_printf("Setting up the core for the search...\n\r");
  271. control = 0x8;
  272.  
  273. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  274. TIREX_CORE_IP_S00_AXI_SLV_REG7_OFFSET,
  275. control);
  276. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  277. TIREX_CORE_IP_S00_AXI_SLV_REG4_OFFSET,
  278. data_start_addr);
  279. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  280. TIREX_CORE_IP_S00_AXI_SLV_REG5_OFFSET,
  281. data_end_addr);
  282.  
  283. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  284. TIREX_CORE_IP_S00_AXI_SLV_REG6_OFFSET,
  285. instr_start_addr);
  286. xil_printf("Core ready for the search... \n");
  287.  
  288. /*
  289. * Enable the search
  290. */
  291. control = 0x9;
  292. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  293. TIREX_CORE_IP_S00_AXI_SLV_REG7_OFFSET,
  294. control);
  295.  
  296. /*
  297. Polling in order to check the completion of the core computation
  298. */
  299. while(!(result & (1 << 0))){
  300. xil_printf("Searching...\n");
  301. result = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  302. TIREX_CORE_IP_S00_AXI_SLV_REG7_OFFSET);
  303. xil_printf("%d\n", result);
  304. /******** Roba per testare che ho messo ora *********/
  305. timing_counter = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  306. TIREX_CORE_IP_S00_AXI_SLV_REG6_OFFSET);
  307. xil_printf("Counter -> %d", timing_counter);
  308. bram_data[0] = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  309. TIREX_CORE_IP_S00_AXI_SLV_REG2_OFFSET);
  310. bram_data[1] = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  311. TIREX_CORE_IP_S00_AXI_SLV_REG3_OFFSET);
  312. bram_data[2] = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  313. TIREX_CORE_IP_S00_AXI_SLV_REG4_OFFSET);
  314. bram_data[3] = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  315. TIREX_CORE_IP_S00_AXI_SLV_REG5_OFFSET);
  316.  
  317. xil_printf("Data at address\n"
  318. "\t %x%x%x%x\n", bram_data[3], bram_data[2], bram_data[1], bram_data[0]);
  319.  
  320. u32 curr_char_check = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  321. TIREX_CORE_IP_S00_AXI_SLV_REG8_OFFSET);
  322.  
  323. xil_printf("Curr char check ---> %d\n", curr_char_check);
  324. /******** Roba per testare che ho messo ora *********/
  325. }
  326.  
  327. u32 curr_char_check = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  328. TIREX_CORE_IP_S00_AXI_SLV_REG8_OFFSET);
  329.  
  330. u32 no_more_char_check = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  331. TIREX_CORE_IP_S00_AXI_SLV_REG9_OFFSET);
  332.  
  333. xil_printf("Curr character check --> %d\n"
  334. "No more characters check --> %d\n", curr_char_check, no_more_char_check);
  335. // Result retrevial
  336. result = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  337. TIREX_CORE_IP_S00_AXI_SLV_REG7_OFFSET);
  338.  
  339. // Counter measurement retrevial
  340. timing_counter = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  341. TIREX_CORE_IP_S00_AXI_SLV_REG6_OFFSET);
  342.  
  343. // Disabling the core
  344. control = 0x0;
  345. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  346. TIREX_CORE_IP_S00_AXI_SLV_REG7_OFFSET,
  347. control);
  348.  
  349. xil_printf("The core has completed the search in: %d clock cycles\n\n\n", timing_counter);
  350. xil_printf("The core has completed the search -----> complete = %d\n\n", result & (1 << 0));
  351. if(result & (1 << 1))
  352. found = 1;
  353. else
  354. found = 0;
  355. xil_printf("The core has completed the search -----> found = %d\n\n", found);
  356.  
  357. if(result & (1 << 2))
  358. end_data = 1;
  359. xil_printf("\tEnd of data\t\t = %d\n\n", end_data);
  360.  
  361. if(result & (1 << 4))
  362. correct_match = 1;
  363. xil_printf("\tCorrectly complete\t = %d\n\n", correct_match);
  364.  
  365. // Last match retrievial
  366. if(found)
  367. {
  368. char_num = TIREX_CORE_IP_mReadReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  369. TIREX_CORE_IP_S00_AXI_SLV_REG8_OFFSET);
  370.  
  371. xil_printf("Last match character index ------> %d", char_num);
  372. }
  373.  
  374. // Resetting the core
  375. control = 0x20;
  376. TIREX_CORE_IP_mWriteReg(XPAR_TIREX_CORE_IP_0_S00_AXI_BASEADDR,
  377. TIREX_CORE_IP_S00_AXI_SLV_REG7_OFFSET,
  378. control);
  379.  
  380. cleanup_platform();
  381. return 0;
  382. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement