Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.43 KB | None | 0 0
  1. `timescale 1 ns / 1 ps
  2.  
  3. module compute_sad_v1_0_S00_AXI #
  4. (
  5. // Users to add parameters here
  6.  
  7. // User parameters ends
  8. // Do not modify the parameters beyond this line
  9.  
  10. // Width of S_AXI data bus
  11. parameter integer C_S_AXI_DATA_WIDTH = 32,
  12. // Width of S_AXI address bus
  13. parameter integer C_S_AXI_ADDR_WIDTH = 6
  14. )
  15. (
  16. // Users to add ports here
  17.  
  18. // User ports ends
  19. // Do not modify the ports beyond this line
  20.  
  21. // Global Clock Signal
  22. input wire S_AXI_ACLK,
  23. // Global Reset Signal. This Signal is Active LOW
  24. input wire S_AXI_ARESETN,
  25. // Write address (issued by master, acceped by Slave)
  26. input wire [C_S_AXI_ADDR_WIDTH-1 : 0] S_AXI_AWADDR,
  27. // Write channel Protection type. This signal indicates the
  28. // privilege and security level of the transaction, and whether
  29. // the transaction is a data access or an instruction access.
  30. input wire [2 : 0] S_AXI_AWPROT,
  31. // Write address valid. This signal indicates that the master signaling
  32. // valid write address and control information.
  33. input wire S_AXI_AWVALID,
  34. // Write address ready. This signal indicates that the slave is ready
  35. // to accept an address and associated control signals.
  36. output wire S_AXI_AWREADY,
  37. // Write data (issued by master, acceped by Slave)
  38. input wire [C_S_AXI_DATA_WIDTH-1 : 0] S_AXI_WDATA,
  39. // Write strobes. This signal indicates which byte lanes hold
  40. // valid data. There is one write strobe bit for each eight
  41. // bits of the write data bus.
  42. input wire [(C_S_AXI_DATA_WIDTH/8)-1 : 0] S_AXI_WSTRB,
  43. // Write valid. This signal indicates that valid write
  44. // data and strobes are available.
  45. input wire S_AXI_WVALID,
  46. // Write ready. This signal indicates that the slave
  47. // can accept the write data.
  48. output wire S_AXI_WREADY,
  49. // Write response. This signal indicates the status
  50. // of the write transaction.
  51. output wire [1 : 0] S_AXI_BRESP,
  52. // Write response valid. This signal indicates that the channel
  53. // is signaling a valid write response.
  54. output wire S_AXI_BVALID,
  55. // Response ready. This signal indicates that the master
  56. // can accept a write response.
  57. input wire S_AXI_BREADY,
  58. // Read address (issued by master, acceped by Slave)
  59. input wire [C_S_AXI_ADDR_WIDTH-1 : 0] S_AXI_ARADDR,
  60. // Protection type. This signal indicates the privilege
  61. // and security level of the transaction, and whether the
  62. // transaction is a data access or an instruction access.
  63. input wire [2 : 0] S_AXI_ARPROT,
  64. // Read address valid. This signal indicates that the channel
  65. // is signaling valid read address and control information.
  66. input wire S_AXI_ARVALID,
  67. // Read address ready. This signal indicates that the slave is
  68. // ready to accept an address and associated control signals.
  69. output wire S_AXI_ARREADY,
  70. // Read data (issued by slave)
  71. output wire [C_S_AXI_DATA_WIDTH-1 : 0] S_AXI_RDATA,
  72. // Read response. This signal indicates the status of the
  73. // read transfer.
  74. output wire [1 : 0] S_AXI_RRESP,
  75. // Read valid. This signal indicates that the channel is
  76. // signaling the required read data.
  77. output wire S_AXI_RVALID,
  78. // Read ready. This signal indicates that the master can
  79. // accept the read data and response information.
  80. input wire S_AXI_RREADY
  81. );
  82.  
  83. // AXI4LITE signals
  84. reg [C_S_AXI_ADDR_WIDTH-1 : 0] axi_awaddr;
  85. reg axi_awready;
  86. reg axi_wready;
  87. reg [1 : 0] axi_bresp;
  88. reg axi_bvalid;
  89. reg [C_S_AXI_ADDR_WIDTH-1 : 0] axi_araddr;
  90. reg axi_arready;
  91. reg [C_S_AXI_DATA_WIDTH-1 : 0] axi_rdata;
  92. reg [1 : 0] axi_rresp;
  93. reg axi_rvalid;
  94.  
  95. // Example-specific design signals
  96. // local parameter for addressing 32 bit / 64 bit C_S_AXI_DATA_WIDTH
  97. // ADDR_LSB is used for addressing 32/64 bit registers/memories
  98. // ADDR_LSB = 2 for 32 bits (n downto 2)
  99. // ADDR_LSB = 3 for 64 bits (n downto 3)
  100. localparam integer ADDR_LSB = (C_S_AXI_DATA_WIDTH/32) + 1;
  101. localparam integer OPT_MEM_ADDR_BITS = 3;
  102. //----------------------------------------------
  103. //-- Signals for user logic register space example
  104. //------------------------------------------------
  105. //-- Number of Slave Registers 10
  106. reg [C_S_AXI_DATA_WIDTH-1:0] slv_reg0;
  107. reg [C_S_AXI_DATA_WIDTH-1:0] slv_reg1;
  108. reg [C_S_AXI_DATA_WIDTH-1:0] slv_reg2;
  109. reg [C_S_AXI_DATA_WIDTH-1:0] slv_reg3;
  110. reg [C_S_AXI_DATA_WIDTH-1:0] slv_reg4;
  111. reg [C_S_AXI_DATA_WIDTH-1:0] slv_reg5;
  112. reg [C_S_AXI_DATA_WIDTH-1:0] slv_reg6;
  113. reg [C_S_AXI_DATA_WIDTH-1:0] slv_reg7;
  114. reg [C_S_AXI_DATA_WIDTH-1:0] slv_reg8;
  115. reg [C_S_AXI_DATA_WIDTH-1:0] slv_reg9;
  116. wire slv_reg_rden;
  117. wire slv_reg_wren;
  118. reg [C_S_AXI_DATA_WIDTH-1:0] reg_data_out;
  119. integer byte_index;
  120.  
  121. reg [10:0] sad_result;
  122. reg [5:0] state;
  123.  
  124. // I/O Connections assignments
  125.  
  126. assign S_AXI_AWREADY = axi_awready;
  127. assign S_AXI_WREADY = axi_wready;
  128. assign S_AXI_BRESP = axi_bresp;
  129. assign S_AXI_BVALID = axi_bvalid;
  130. assign S_AXI_ARREADY = axi_arready;
  131. assign S_AXI_RDATA = axi_rdata;
  132. assign S_AXI_RRESP = axi_rresp;
  133. assign S_AXI_RVALID = axi_rvalid;
  134. // Implement axi_awready generation
  135. // axi_awready is asserted for one S_AXI_ACLK clock cycle when both
  136. // S_AXI_AWVALID and S_AXI_WVALID are asserted. axi_awready is
  137. // de-asserted when reset is low.
  138.  
  139. always @( posedge S_AXI_ACLK )
  140. begin
  141. if ( S_AXI_ARESETN == 1'b0 )
  142. begin
  143. axi_awready <= 1'b0;
  144. end
  145. else
  146. begin
  147. if (~axi_awready && S_AXI_AWVALID && S_AXI_WVALID)
  148. begin
  149. // slave is ready to accept write address when
  150. // there is a valid write address and write data
  151. // on the write address and data bus. This design
  152. // expects no outstanding transactions.
  153. axi_awready <= 1'b1;
  154. end
  155. else
  156. begin
  157. axi_awready <= 1'b0;
  158. end
  159. end
  160. end
  161.  
  162. // Implement axi_awaddr latching
  163. // This process is used to latch the address when both
  164. // S_AXI_AWVALID and S_AXI_WVALID are valid.
  165.  
  166. always @( posedge S_AXI_ACLK )
  167. begin
  168. if ( S_AXI_ARESETN == 1'b0 )
  169. begin
  170. axi_awaddr <= 0;
  171. end
  172. else
  173. begin
  174. if (~axi_awready && S_AXI_AWVALID && S_AXI_WVALID)
  175. begin
  176. // Write Address latching
  177. axi_awaddr <= S_AXI_AWADDR;
  178. end
  179. end
  180. end
  181.  
  182. // Implement axi_wready generation
  183. // axi_wready is asserted for one S_AXI_ACLK clock cycle when both
  184. // S_AXI_AWVALID and S_AXI_WVALID are asserted. axi_wready is
  185. // de-asserted when reset is low.
  186.  
  187. always @( posedge S_AXI_ACLK )
  188. begin
  189. if ( S_AXI_ARESETN == 1'b0 )
  190. begin
  191. axi_wready <= 1'b0;
  192. end
  193. else
  194. begin
  195. if (~axi_wready && S_AXI_WVALID && S_AXI_AWVALID)
  196. begin
  197. // slave is ready to accept write data when
  198. // there is a valid write address and write data
  199. // on the write address and data bus. This design
  200. // expects no outstanding transactions.
  201. axi_wready <= 1'b1;
  202. end
  203. else
  204. begin
  205. axi_wready <= 1'b0;
  206. end
  207. end
  208. end
  209.  
  210. // Implement memory mapped register select and write logic generation
  211. // The write data is accepted and written to memory mapped registers when
  212. // axi_awready, S_AXI_WVALID, axi_wready and S_AXI_WVALID are asserted. Write strobes are used to
  213. // select byte enables of slave registers while writing.
  214. // These registers are cleared when reset (active low) is applied.
  215. // Slave register write enable is asserted when valid address and data are available
  216. // and the slave is ready to accept the write address and write data.
  217. assign slv_reg_wren = axi_wready && S_AXI_WVALID && axi_awready && S_AXI_AWVALID;
  218.  
  219. always @( posedge S_AXI_ACLK )
  220. begin
  221. if ( S_AXI_ARESETN == 1'b0 )
  222. begin
  223. slv_reg0 <= 0;
  224. slv_reg1 <= 0;
  225. slv_reg2 <= 0;
  226. slv_reg3 <= 0;
  227. slv_reg4 <= 0;
  228. slv_reg5 <= 0;
  229. slv_reg6 <= 0;
  230. slv_reg7 <= 0;
  231. slv_reg8 <= 0;
  232. slv_reg9 <= 0;
  233. end
  234. else begin
  235. if (state == 299) begin
  236. slv_reg9 <= sad_result;
  237. end
  238. else if (state == 300)
  239. slv_reg8 <= 0;
  240. else if (slv_reg_wren)
  241. begin
  242. case ( axi_awaddr[ADDR_LSB+OPT_MEM_ADDR_BITS:ADDR_LSB] )
  243. 4'h0:
  244. for ( byte_index = 0; byte_index <= (C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
  245. if ( S_AXI_WSTRB[byte_index] == 1 ) begin
  246. // Respective byte enables are asserted as per write strobes
  247. // Slave register 0
  248. slv_reg0[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
  249. end
  250. 4'h1:
  251. for ( byte_index = 0; byte_index <= (C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
  252. if ( S_AXI_WSTRB[byte_index] == 1 ) begin
  253. // Respective byte enables are asserted as per write strobes
  254. // Slave register 1
  255. slv_reg1[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
  256. end
  257. 4'h2:
  258. for ( byte_index = 0; byte_index <= (C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
  259. if ( S_AXI_WSTRB[byte_index] == 1 ) begin
  260. // Respective byte enables are asserted as per write strobes
  261. // Slave register 2
  262. slv_reg2[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
  263. end
  264. 4'h3:
  265. for ( byte_index = 0; byte_index <= (C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
  266. if ( S_AXI_WSTRB[byte_index] == 1 ) begin
  267. // Respective byte enables are asserted as per write strobes
  268. // Slave register 3
  269. slv_reg3[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
  270. end
  271. 4'h4:
  272. for ( byte_index = 0; byte_index <= (C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
  273. if ( S_AXI_WSTRB[byte_index] == 1 ) begin
  274. // Respective byte enables are asserted as per write strobes
  275. // Slave register 4
  276. slv_reg4[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
  277. end
  278. 4'h5:
  279. for ( byte_index = 0; byte_index <= (C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
  280. if ( S_AXI_WSTRB[byte_index] == 1 ) begin
  281. // Respective byte enables are asserted as per write strobes
  282. // Slave register 5
  283. slv_reg5[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
  284. end
  285. 4'h6:
  286. for ( byte_index = 0; byte_index <= (C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
  287. if ( S_AXI_WSTRB[byte_index] == 1 ) begin
  288. // Respective byte enables are asserted as per write strobes
  289. // Slave register 6
  290. slv_reg6[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
  291. end
  292. 4'h7:
  293. for ( byte_index = 0; byte_index <= (C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
  294. if ( S_AXI_WSTRB[byte_index] == 1 ) begin
  295. // Respective byte enables are asserted as per write strobes
  296. // Slave register 7
  297. slv_reg7[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
  298. end
  299. 4'h8:
  300. for ( byte_index = 0; byte_index <= (C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
  301. if ( S_AXI_WSTRB[byte_index] == 1 ) begin
  302. // Respective byte enables are asserted as per write strobes
  303. // Slave register 8
  304. slv_reg8[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
  305. end
  306. 4'h9:
  307. for ( byte_index = 0; byte_index <= (C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
  308. if ( S_AXI_WSTRB[byte_index] == 1 ) begin
  309. // Respective byte enables are asserted as per write strobes
  310. // Slave register 9
  311. slv_reg9[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
  312. end
  313. default : begin
  314. slv_reg0 <= slv_reg0;
  315. slv_reg1 <= slv_reg1;
  316. slv_reg2 <= slv_reg2;
  317. slv_reg3 <= slv_reg3;
  318. slv_reg4 <= slv_reg4;
  319. slv_reg5 <= slv_reg5;
  320. slv_reg6 <= slv_reg6;
  321. slv_reg7 <= slv_reg7;
  322. slv_reg8 <= slv_reg8;
  323. slv_reg9 <= slv_reg9;
  324. end
  325. endcase
  326. end
  327. end
  328. end
  329.  
  330. // Implement write response logic generation
  331. // The write response and response valid signals are asserted by the slave
  332. // when axi_wready, S_AXI_WVALID, axi_wready and S_AXI_WVALID are asserted.
  333. // This marks the acceptance of address and indicates the status of
  334. // write transaction.
  335.  
  336. always @( posedge S_AXI_ACLK )
  337. begin
  338. if ( S_AXI_ARESETN == 1'b0 )
  339. begin
  340. axi_bvalid <= 0;
  341. axi_bresp <= 2'b0;
  342. end
  343. else
  344. begin
  345. if (axi_awready && S_AXI_AWVALID && ~axi_bvalid && axi_wready && S_AXI_WVALID)
  346. begin
  347. // indicates a valid write response is available
  348. axi_bvalid <= 1'b1;
  349. axi_bresp <= 2'b0; // 'OKAY' response
  350. end // work error responses in future
  351. else
  352. begin
  353. if (S_AXI_BREADY && axi_bvalid)
  354. //check if bready is asserted while bvalid is high)
  355. //(there is a possibility that bready is always asserted high)
  356. begin
  357. axi_bvalid <= 1'b0;
  358. end
  359. end
  360. end
  361. end
  362.  
  363. // Implement axi_arready generation
  364. // axi_arready is asserted for one S_AXI_ACLK clock cycle when
  365. // S_AXI_ARVALID is asserted. axi_awready is
  366. // de-asserted when reset (active low) is asserted.
  367. // The read address is also latched when S_AXI_ARVALID is
  368. // asserted. axi_araddr is reset to zero on reset assertion.
  369.  
  370. always @( posedge S_AXI_ACLK )
  371. begin
  372. if ( S_AXI_ARESETN == 1'b0 )
  373. begin
  374. axi_arready <= 1'b0;
  375. axi_araddr <= 32'b0;
  376. end
  377. else
  378. begin
  379. if (~axi_arready && S_AXI_ARVALID)
  380. begin
  381. // indicates that the slave has acceped the valid read address
  382. axi_arready <= 1'b1;
  383. // Read address latching
  384. axi_araddr <= S_AXI_ARADDR;
  385. end
  386. else
  387. begin
  388. axi_arready <= 1'b0;
  389. end
  390. end
  391. end
  392.  
  393. // Implement axi_arvalid generation
  394. // axi_rvalid is asserted for one S_AXI_ACLK clock cycle when both
  395. // S_AXI_ARVALID and axi_arready are asserted. The slave registers
  396. // data are available on the axi_rdata bus at this instance. The
  397. // assertion of axi_rvalid marks the validity of read data on the
  398. // bus and axi_rresp indicates the status of read transaction.axi_rvalid
  399. // is deasserted on reset (active low). axi_rresp and axi_rdata are
  400. // cleared to zero on reset (active low).
  401. always @( posedge S_AXI_ACLK )
  402. begin
  403. if ( S_AXI_ARESETN == 1'b0 )
  404. begin
  405. axi_rvalid <= 0;
  406. axi_rresp <= 0;
  407. end
  408. else
  409. begin
  410. if (axi_arready && S_AXI_ARVALID && ~axi_rvalid)
  411. begin
  412. // Valid read data is available at the read data bus
  413. axi_rvalid <= 1'b1;
  414. axi_rresp <= 2'b0; // 'OKAY' response
  415. end
  416. else if (axi_rvalid && S_AXI_RREADY)
  417. begin
  418. // Read data is accepted by the master
  419. axi_rvalid <= 1'b0;
  420. end
  421. end
  422. end
  423.  
  424. // Implement memory mapped register select and read logic generation
  425. // Slave register read enable is asserted when valid address is available
  426. // and the slave is ready to accept the read address.
  427. assign slv_reg_rden = axi_arready & S_AXI_ARVALID & ~axi_rvalid;
  428. always @(*)
  429. begin
  430. // Address decoding for reading registers
  431. case ( axi_araddr[ADDR_LSB+OPT_MEM_ADDR_BITS:ADDR_LSB] )
  432. 4'h0 : reg_data_out <= slv_reg0;
  433. 4'h1 : reg_data_out <= slv_reg1;
  434. 4'h2 : reg_data_out <= slv_reg2;
  435. 4'h3 : reg_data_out <= slv_reg3;
  436. 4'h4 : reg_data_out <= slv_reg4;
  437. 4'h5 : reg_data_out <= slv_reg5;
  438. 4'h6 : reg_data_out <= slv_reg6;
  439. 4'h7 : reg_data_out <= slv_reg7;
  440. 4'h8 : reg_data_out <= slv_reg8;
  441. 4'h9 : reg_data_out <= slv_reg9;
  442. default : reg_data_out <= 0;
  443. endcase
  444. end
  445.  
  446. // Output register or memory read data
  447. always @( posedge S_AXI_ACLK )
  448. begin
  449. if ( S_AXI_ARESETN == 1'b0 )
  450. begin
  451. axi_rdata <= 0;
  452. end
  453. else
  454. begin
  455. // When there is a valid read address (S_AXI_ARVALID) with
  456. // acceptance of read address by the slave (axi_arready),
  457. // output the read dada
  458. if (slv_reg_rden)
  459. begin
  460. axi_rdata <= reg_data_out; // register read data
  461. end
  462. end
  463. end
  464.  
  465. // Add user logic here
  466.  
  467. reg [8:0] abs_diff[0:3];
  468. wire [8:0] prev_pixel[0:4];
  469. wire [8:0] curr_pixel[0:4];
  470. wire [8:0] diff[0:4];
  471.  
  472. assign prev_pixel[0] = {1'b0, slv_reg0[31:24]};
  473. assign prev_pixel[1] = {1'b0, slv_reg0[23:16]};
  474. assign prev_pixel[2] = {1'b0, slv_reg0[15:8]};
  475. assign prev_pixel[3] = {1'b0, slv_reg0[7:0]};
  476. assign prev_pixel[4] = {1'b0, slv_reg1[31:24]};
  477. assign prev_pixel[5] = {1'b0, slv_reg1[23:16]};
  478. assign prev_pixel[6] = {1'b0, slv_reg1[15:8]};
  479. assign prev_pixel[7] = {1'b0, slv_reg1[7:0]};
  480. assign prev_pixel[8] = {1'b0, slv_reg2[31:24]};
  481. assign prev_pixel[9] = {1'b0, slv_reg2[23:16]};
  482. assign prev_pixel[10] = {1'b0, slv_reg2[15:8]};
  483. assign prev_pixel[11] = {1'b0, slv_reg2[7:0]};
  484. assign prev_pixel[12] = {1'b0, slv_reg3[31:24]};
  485. assign prev_pixel[13] = {1'b0, slv_reg3[23:16]};
  486. assign prev_pixel[14] = {1'b0, slv_reg3[15:8]};
  487. assign prev_pixel[15] = {1'b0, slv_reg3[7:0]};
  488.  
  489. assign curr_pixel[0] = {1'b0, slv_reg4[31:24]};
  490. assign curr_pixel[1] = {1'b0, slv_reg4[23:16]};
  491. assign curr_pixel[2] = {1'b0, slv_reg4[15:8]};
  492. assign curr_pixel[3] = {1'b0, slv_reg4[7:0]};
  493. assign curr_pixel[4] = {1'b0, slv_reg5[31:24]};
  494. assign curr_pixel[5] = {1'b0, slv_reg5[23:16]};
  495. assign curr_pixel[6] = {1'b0, slv_reg5[15:8]};
  496. assign curr_pixel[7] = {1'b0, slv_reg5[7:0]};
  497. assign curr_pixel[8] = {1'b0, slv_reg6[31:24]};
  498. assign curr_pixel[9] = {1'b0, slv_reg6[23:16]};
  499. assign curr_pixel[10] = {1'b0, slv_reg6[15:8]};
  500. assign curr_pixel[11] = {1'b0, slv_reg6[7:0]};
  501. assign curr_pixel[12] = {1'b0, slv_reg7[31:24]};
  502. assign curr_pixel[13] = {1'b0, slv_reg7[23:16]};
  503. assign curr_pixel[14] = {1'b0, slv_reg7[15:8]};
  504. assign curr_pixel[15] = {1'b0, slv_reg7[7:0]};
  505.  
  506. assign diff[0] = prev_pixel[0] - curr_pixel[0];
  507. assign diff[1] = prev_pixel[1] - curr_pixel[1];
  508. assign diff[2] = prev_pixel[2] - curr_pixel[2];
  509.  
  510. assign diff[3] = prev_pixel[3] - curr_pixel[3];
  511. assign diff[4] = prev_pixel[4] - curr_pixel[4];
  512. assign diff[5] = prev_pixel[5] - curr_pixel[5];
  513. assign diff[6] = prev_pixel[6] - curr_pixel[6];
  514. assign diff[7] = prev_pixel[7] - curr_pixel[7];
  515. assign diff[8] = prev_pixel[8] - curr_pixel[8];
  516. assign diff[9] = prev_pixel[9] - curr_pixel[9];
  517. assign diff[10] = prev_pixel[10] - curr_pixel[10];
  518. assign diff[11] = prev_pixel[11] - curr_pixel[11];
  519. assign diff[12] = prev_pixel[12] - curr_pixel[12];
  520. assign diff[13] = prev_pixel[13] - curr_pixel[13];
  521. assign diff[14] = prev_pixel[14] - curr_pixel[14];
  522. assign diff[15] = prev_pixel[15] - curr_pixel[15];
  523.  
  524. always @(posedge S_AXI_ACLK)
  525. begin
  526. if (S_AXI_ARESETN == 1'b0) begin
  527. abs_diff[0] <= 0;
  528. abs_diff[1] <= 0;
  529. abs_diff[2] <= 0;
  530. abs_diff[3] <= 0;
  531. abs_diff[4] <= 0;
  532. abs_diff[5] <= 0;
  533. abs_diff[6] <= 0;
  534. abs_diff[7] <= 0;
  535. abs_diff[8] <= 0;
  536. abs_diff[9] <= 0;
  537. abs_diff[10] <= 0;
  538. abs_diff[11] <= 0;
  539. abs_diff[12] <= 0;
  540. abs_diff[13] <= 0;
  541. abs_diff[14] <= 0;
  542. abs_diff[15] <= 0;
  543. end
  544. else begin
  545. abs_diff[0] <= (diff[0][8] == 1'b1)? -diff[0] : diff[0];
  546. abs_diff[1] <= (diff[1][8] == 1'b1)? -diff[1] : diff[1];
  547. abs_diff[2] <= (diff[2][8] == 1'b1)? -diff[2] : diff[2];
  548. abs_diff[3] <= (diff[3][8] == 1'b1)? -diff[3] : diff[3];
  549. abs_diff[4] <= (diff[4][8] == 1'b1)? -diff[4] : diff[4];
  550. abs_diff[5] <= (diff[5][8] == 1'b1)? -diff[5] : diff[5];
  551. abs_diff[6] <= (diff[6][8] == 1'b1)? -diff[6] : diff[6];
  552. abs_diff[7] <= (diff[7][8] == 1'b1)? -diff[7] : diff[7];
  553. abs_diff[8] <= (diff[8][8] == 1'b1)? -diff[8] : diff[8];
  554. abs_diff[9] <= (diff[9][8] == 1'b1)? -diff[9] : diff[9];
  555.  
  556. abs_diff[10] <= (diff[10][8] == 1'b1)? -diff[10] : diff[10];
  557. abs_diff[11] <= (diff[11][8] == 1'b1)? -diff[11] : diff[11];
  558. abs_diff[12] <= (diff[12][8] == 1'b1)? -diff[12] : diff[12];
  559. abs_diff[13] <= (diff[13][8] == 1'b1)? -diff[13] : diff[13];
  560. abs_diff[14] <= (diff[14][8] == 1'b1)? -diff[14] : diff[14];
  561. abs_diff[15] <= (diff[15][8] == 1'b1)? -diff[15] : diff[15];
  562. end
  563. end
  564.  
  565. wire [9:0] partial_sum_1[0:7];
  566. wire [9:0] partial_sum_2[0:4];
  567. wire [9:0] partial_sum_3[0:2];
  568.  
  569.  
  570. assign partial_sum_1[0] = abs_diff[0] + abs_diff[1];
  571. assign partial_sum_1[1] = abs_diff[2] + abs_diff[3];
  572. assign partial_sum_1[2] = abs_diff[4] + abs_diff[5];
  573. assign partial_sum_1[3] = abs_diff[6] + abs_diff[7];
  574. assign partial_sum_1[4] = abs_diff[8] + abs_diff[9];
  575. assign partial_sum_1[5] = abs_diff[10] + abs_diff[11];
  576. assign partial_sum_1[6] = abs_diff[12] + abs_diff[13];
  577. assign partial_sum_1[7] = abs_diff[14] + abs_diff[15];
  578.  
  579. assign partial_sum_2[0] = partial_sum_1[0] + partial_sum_1[1];
  580. assign partial_sum_2[1] = partial_sum_1[2] + partial_sum_1[3];
  581. assign partial_sum_2[2] = partial_sum_1[4] + partial_sum_1[5];
  582. assign partial_sum_2[3] = partial_sum_1[6] + partial_sum_1[7];
  583.  
  584. assign partial_sum_3[0] = partial_sum_2[0] + partial_sum_2[1];
  585. assign partial_sum_3[1] = partial_sum_2[2] + partial_sum_2[3];
  586.  
  587. //assign slv_reg9[10:0] = sad_result;
  588.  
  589. always @(posedge S_AXI_ACLK) begin
  590. if (S_AXI_ARESETN == 1'b0) begin
  591. sad_result <= 0;
  592. end
  593. else begin
  594. sad_result <= partial_sum_3[0] + partial_sum_3[1];
  595. end
  596. end
  597.  
  598.  
  599.  
  600. always @(posedge S_AXI_ACLK) begin
  601. if (S_AXI_ARESETN == 1'b0) begin
  602. state <= 0;
  603. end
  604. else if (slv_reg8) begin
  605. state <= state + 1;
  606. end
  607. else if (state > 300) begin
  608. state <= 0;
  609. end
  610. else begin
  611. state <= state;
  612. end
  613. end
  614.  
  615.  
  616. // User logic ends
  617.  
  618. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement