Hardware Design: SIE
Sign in or create your account | Project List | Help
Hardware Design: SIE Git Source Tree
Root/
| 1 | /* |
| 2 | * Milkymist VJ SoC |
| 3 | * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, version 3 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | module vgafb_fifo64to16( |
| 19 | input sys_clk, |
| 20 | input vga_rst, |
| 21 | |
| 22 | input stb, |
| 23 | input [63:0] di, |
| 24 | |
| 25 | output do_valid, |
| 26 | output reg [15:0] do, |
| 27 | input next /* should only be asserted when do_valid = 1 */ |
| 28 | ); |
| 29 | |
| 30 | /* |
| 31 | * FIFO can hold 4 64-bit words |
| 32 | * that is 16 16-bit words. |
| 33 | */ |
| 34 | |
| 35 | reg [63:0] storage[0:3]; |
| 36 | reg [1:0] produce; /* in 64-bit words */ |
| 37 | reg [3:0] consume; /* in 16-bit words */ |
| 38 | /* |
| 39 | * 16-bit words stored in the FIFO, 0-16 (17 possible values) |
| 40 | */ |
| 41 | reg [4:0] level; |
| 42 | |
| 43 | wire [63:0] do64; |
| 44 | assign do64 = storage[consume[3:2]]; |
| 45 | |
| 46 | always @(*) begin |
| 47 | case(consume[1:0]) |
| 48 | 2'd0: do <= do64[63:48]; |
| 49 | 2'd1: do <= do64[47:32]; |
| 50 | 2'd2: do <= do64[31:16]; |
| 51 | 2'd3: do <= do64[15:0]; |
| 52 | endcase |
| 53 | end |
| 54 | |
| 55 | always @(posedge sys_clk) begin |
| 56 | if(vga_rst) begin |
| 57 | produce = 2'd0; |
| 58 | consume = 4'd0; |
| 59 | level = 5'd0; |
| 60 | end else begin |
| 61 | if(stb) begin |
| 62 | storage[produce] = di; |
| 63 | produce = produce + 2'd1; |
| 64 | level = level + 5'd4; |
| 65 | end |
| 66 | if(next) begin /* next should only be asserted when do_valid = 1 */ |
| 67 | consume = consume + 4'd1; |
| 68 | level = level - 5'd1; |
| 69 | end |
| 70 | end |
| 71 | end |
| 72 | |
| 73 | assign do_valid = ~(level == 5'd0); |
| 74 | |
| 75 | endmodule |
| 76 |
Branches:
master
