OpenCores
URL https://opencores.org/ocsvn/scsi_chip/scsi_chip/trunk

Subversion Repositories scsi_chip

[/] [scsi_chip/] [web_uploads/] [Data_buffer.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 root
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// Company: 
4
// Engineer: 
5
// 
6
// Create Date:    14:26:15 08/11/2008 
7
// Design Name: 
8
// Module Name:    Data_buffer 
9
// Project Name: 
10
// Target Devices: 
11
// Tool versions: 
12
// Description: 
13
//
14
// Dependencies: 
15
//
16
// Revision: 
17
// Revision 0.01 - File Created
18
// Additional Comments: 
19
//
20
//////////////////////////////////////////////////////////////////////////////////
21
//DEFINES
22
`define DEL 1
23
`define FIFO_DEPTH 5
24
`define FIFO_HALF 3
25
`define FIFO_BITS 3
26
`define FIFO_WIDTH 8
27
 
28
 
29
module Data_buffer(CLK, reset_n, data_in, read_n, write_n, data_out, full, empty, half);
30
//INPUTS
31
    input CLK;
32
    input reset_n;//active low reset
33
    input [`FIFO_WIDTH-1:0] data_in;//data input to FIFO
34
    input read_n;//Read FIFO
35
    input write_n;//Write FIFO
36
//OUTPUTS        
37
    output [`FIFO_WIDTH-1:0] data_out;//FIFO output DATA
38
    output full;//FIFO is Full
39
    output empty;//FIFO is empty
40
    output half;//FIFO is half full or more
41
//SIGNAL DECLARATIONS
42
         wire CLK;
43
         wire reset_n;
44
         wire [`FIFO_WIDTH-1:0] data_in;
45
         wire read_n;
46
         wire write_n;
47
         reg [`FIFO_WIDTH-1:0] data_out;
48
         wire full;
49
         wire empty;
50
         wire half;
51
         reg [`FIFO_WIDTH-1:0] fifo_mem[0:`FIFO_DEPTH-1];//The fifo memory
52
         reg [`FIFO_BITS-1:0] counter;//FIFO read pointer points to the location in the FIFO to read form next
53
         reg [`FIFO_BITS-1:0] rd_pointer;
54
         reg [`FIFO_BITS-1:0] wr_pointer;
55
//ASSIGN STATEMENTS
56
assign #`DEL full = (counter == `FIFO_DEPTH) ? 1'b1 : 1'b0;
57
assign #`DEL empty = (counter == 0) ? 1'b1 : 1'b0;
58
assign #`DEL half = (counter >= `FIFO_HALF) ? 1'b1 : 1'b0;
59
//look at the edges of reset_n
60
always @(reset_n)begin
61
                if(~reset_n)begin
62
                        //RESET the FIFO pointer
63
                        #`DEL;
64
                        assign rd_pointer = `FIFO_BITS'b0;
65
                        assign wr_pointer = `FIFO_BITS'b0;
66
                        assign counter = `FIFO_BITS'b0;
67
                end
68
                else begin
69
                        #`DEL;
70
                        deassign rd_pointer;
71
                        deassign wr_pointer;
72
                        deassign counter;
73
                end
74
end
75
//Look at the rising edge of the clock
76
always @(posedge CLK) begin
77
                        if(~read_n)begin
78
                        //check for FIFO underflow
79
                                if(counter == 0)begin
80
                                        $display("\n ERROR at time %0t:",$time);
81
                                        $display("FIFO Underflow\n");
82
                                        $stop;
83
                                end
84
                        //if there is a simultaneous read and write, there is no change to the counter
85
                                if(write_n)begin
86
                                        //decrement the FIFO counter
87
                                        counter <= #`DEL counter-1;
88
                                end
89
                                        //output the data
90
                                        data_out <= #`DEL fifo_mem[rd_pointer];
91
 
92
                                        //increment the read pointer
93
                                        //Check if the read pointer has gone beyond the depth of the FIFO, if so set it back to the beginning of the FIFO
94
                                if(rd_pointer == `FIFO_DEPTH-1)
95
                                        rd_pointer <= #`DEL `FIFO_BITS'b0;
96
                                else
97
                                        rd_pointer <= #`DEL rd_pointer + 1;
98
                        end
99
                        if(~write_n)begin
100
                                //check for the FIFO overflow
101
                                if(counter >= `FIFO_DEPTH)begin
102
                                        $display("\nERROR at time %0t:", $time);
103
                                        $display("FIFO Overflow\n");
104
                                        $stop;
105
                                end
106
                                //      if there is a simultaneous read and write, there is no change to the counter
107
                                if(read_n) begin
108
                                //increment the FIFO counter
109
                                counter <= #`DEL counter + 1;
110
                                end
111
                                //store the data
112
                                fifo_mem[wr_pointer] <= #`DEL data_in;
113
                                //increment the write pointer
114
                                //check if the write pointer has gone beyond the depth of the FIFO, if so set it back to the beginning of the FIFO
115
                                if(wr_pointer == `FIFO_DEPTH-1)
116
                                        wr_pointer <= #`DEL `FIFO_BITS'b0;
117
                                else
118
                                        wr_pointer <= wr_pointer + 1;
119
                        end
120
                end
121
endmodule
122
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.