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

Subversion Repositories djpeg

[/] [djpeg/] [trunk/] [src/] [jpeg_ycbcr_mem.v] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 hidemi
//---------------------------------------------------------------------------
2 9 hidemi
// File Name    : jpeg_ycbcr_mem.v
3
// Module Name  : jpeg_ycbcr_mem
4
// Description  : Memory for YCbCr2RGB
5
// Project      : JPEG Decoder
6
// Belong to    : 
7
// Author       : H.Ishihara
8
// E-Mail       : hidemi@sweetcafe.jp
9
// HomePage     : http://www.sweetcafe.jp/
10
// Date         : 2006/10/01
11
// Rev.         : 2.00
12 3 hidemi
//---------------------------------------------------------------------------
13
// Rev. Date       Description
14
//---------------------------------------------------------------------------
15
// 1.01 2006/10/01 1st Release
16
// 1.02 2006/10/04 remove a WriteData,WriteDataA,WriteDataB wires.
17 9 hidemi
// 2.00 2007/03/25 Replace to RAM from D-FF
18 3 hidemi
//---------------------------------------------------------------------------
19
`timescale 1ps / 1ps
20
 
21 9 hidemi
module jpeg_ycbcr_mem(
22
    rst,
23
    clk,
24 3 hidemi
 
25 9 hidemi
    DataInit,
26 3 hidemi
 
27 9 hidemi
    DataInEnable,
28
    DataInColor,
29
    DataInPage,
30
    DataInCount,
31
    Data0In,
32
    Data1In,
33 3 hidemi
 
34 9 hidemi
    DataOutEnable,
35
    DataOutAddress,
36
    DataOutRead,
37
    DataOutY,
38
    DataOutCb,
39
    DataOutCr
40
);
41
 
42
    input           rst;
43
    input           clk;
44
 
45
    input           DataInit;
46 3 hidemi
 
47 9 hidemi
    input           DataInEnable;
48
    input [2:0]     DataInColor;
49
    input [2:0]     DataInPage;
50
    input [1:0]     DataInCount;
51
    input [8:0]     Data0In;
52
    input [8:0]     Data1In;
53 3 hidemi
 
54 9 hidemi
    output          DataOutEnable;
55
    input [7:0]     DataOutAddress;
56
    input           DataOutRead;
57
    output [8:0]    DataOutY;
58
    output [8:0]    DataOutCb;
59
    output [8:0]    DataOutCr;
60
 
61
    reg [8:0]       MemYA  [0:511];
62
    reg [8:0]       MemYB  [0:511];
63
    reg [8:0]       MemCbA [0:127];
64
    reg [8:0]       MemCbB [0:127];
65
    reg [8:0]       MemCrA [0:127];
66
    reg [8:0]       MemCrB [0:127];
67
 
68
    reg [1:0]       WriteBank, ReadBank;
69 3 hidemi
 
70 9 hidemi
    wire [5:0]      DataInAddress;
71
 
72
    assign DataInAddress = {DataInPage, DataInCount};
73 3 hidemi
 
74 9 hidemi
    // Bank
75
    always @(posedge clk or negedge rst) begin
76
        if(!rst) begin
77
            WriteBank <= 2'd0;
78
            ReadBank <= 2'd0;
79
        end else begin
80
            if(DataInit) begin
81
                WriteBank <= 2'd0;
82
            end else if(DataInEnable && (DataInAddress == 5'h1F) && (DataInColor == 3'b101)) begin
83
                WriteBank <= WriteBank + 2'd1;
84
            end
85
            if(DataInit) begin
86
                ReadBank <= 2'd0;
87
            end else if(DataOutRead && (DataOutAddress == 8'hFF)) begin
88
                ReadBank <= ReadBank + 2'd1;
89
            end
90
        end
91
    end
92 3 hidemi
 
93 9 hidemi
    wire [6:0]      WriteAddressA;
94
    wire [6:0]      WriteAddressB;
95
 
96
    function [6:0] F_WriteAddressA;
97
        input [2:0]    DataInColor;
98
        input [2:0]    DataInPage;
99
        input [1:0]    DataInCount;
100
        begin
101
            F_WriteAddressA[6]   = DataInColor[1];
102
            if(DataInColor[2] == 1'b0) begin
103
                F_WriteAddressA[5:4] = DataInCount[1:0];
104
                F_WriteAddressA[3]   = DataInColor[0] & ~DataInColor[2];
105
            end else begin
106
                F_WriteAddressA[5]  = 1'b0;
107
                F_WriteAddressA[4:3] = DataInCount[1:0];
108
            end
109
            F_WriteAddressA[2:0] = DataInPage[2:0];
110
        end
111
    endfunction
112
 
113
    function [6:0] F_WriteAddressB;
114
        input [2:0]    DataInColor;
115
        input [2:0]    DataInPage;
116
        input [1:0]    DataInCount;
117
        begin
118
            F_WriteAddressB[6]   = DataInColor[1];
119
            if(DataInColor[2] == 1'b0) begin
120
                F_WriteAddressB[5:4] = ~DataInCount[1:0];
121
                F_WriteAddressB[3]   = DataInColor[0] & ~DataInColor[2];
122
            end else begin
123
                F_WriteAddressB[5]   = 1'b0;
124
                F_WriteAddressB[4:3] = ~DataInCount[1:0];
125
            end
126
            F_WriteAddressB[2:0] = DataInPage[2:0];
127
        end
128
    endfunction
129 3 hidemi
 
130 9 hidemi
    assign WriteAddressA = F_WriteAddressA(DataInColor, DataInPage, DataInCount);
131
    assign WriteAddressB = F_WriteAddressB(DataInColor, DataInPage, DataInCount);
132 3 hidemi
 
133 9 hidemi
    always @(posedge clk) begin
134
        if(DataInColor[2] == 1'b0 & DataInEnable == 1'b1) begin
135
            MemYA[{WriteBank, WriteAddressA}] <= Data0In;
136
            MemYB[{WriteBank, WriteAddressB}] <= Data1In;
137
        end
138
    end
139
 
140
    always @(posedge clk) begin
141
        if(DataInColor == 3'b100 & DataInEnable == 1'b1) begin
142
            MemCbA[{WriteBank, WriteAddressA[4:0]}] <= Data0In;
143
            MemCbB[{WriteBank, WriteAddressB[4:0]}] <= Data1In;
144
        end
145
    end
146
 
147
    always @(posedge clk) begin
148
        if(DataInColor == 3'b101 & DataInEnable == 1'b1) begin
149
            MemCrA[{WriteBank, WriteAddressA[4:0]}] <= Data0In;
150
            MemCrB[{WriteBank, WriteAddressB[4:0]}] <= Data1In;
151
        end
152
    end
153
 
154
    reg [8:0] ReadYA;
155
    reg [8:0] ReadYB;
156
    reg [8:0] ReadCbA;
157
    reg [8:0] ReadCbB;
158
    reg [8:0] ReadCrA;
159
    reg [8:0] ReadCrB;
160
 
161
    reg [7:0] RegAdrs;
162
 
163
    always @(posedge clk) begin
164
        RegAdrs <= DataOutAddress;
165 3 hidemi
 
166 9 hidemi
        ReadYA  <= MemYA[{ReadBank, DataOutAddress[7],DataOutAddress[5:0]}];
167
        ReadYB  <= MemYB[{ReadBank, DataOutAddress[7],DataOutAddress[5:0]}];
168
 
169
        ReadCbA <= MemCbA[{ReadBank, DataOutAddress[6:5],DataOutAddress[3:1]}];
170
        ReadCrA <= MemCrA[{ReadBank, DataOutAddress[6:5],DataOutAddress[3:1]}];
171
 
172
        ReadCbB <= MemCbB[{ReadBank, DataOutAddress[6:5],DataOutAddress[3:1]}];
173
        ReadCrB <= MemCrB[{ReadBank, DataOutAddress[6:5],DataOutAddress[3:1]}];
174
    end
175
 
176
    assign DataOutEnable = (WriteBank != ReadBank);
177
    assign DataOutY  = (RegAdrs[6] ==1'b0)?ReadYA:ReadYB;
178
    assign DataOutCb = (RegAdrs[7] ==1'b0)?ReadCbA:ReadCbB;
179
    assign DataOutCr = (RegAdrs[7] ==1'b0)?ReadCrA:ReadCrB;
180 3 hidemi
 
181 9 hidemi
endmodule

powered by: WebSVN 2.1.0

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