OpenCores
URL https://opencores.org/ocsvn/bluespec-h264/bluespec-h264/trunk

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [src_fpga/] [mkInputGen.bsv] - Blame information for rev 83

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 83 jamey.hick
 
2
// The MIT License
3
 
4
// Copyright (c) 2006-2007 Massachusetts Institute of Technology
5
 
6
// Permission is hereby granted, free of charge, to any person obtaining a copy
7
// of this software and associated documentation files (the "Software"), to deal
8
// in the Software without restriction, including without limitation the rights
9
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
// copies of the Software, and to permit persons to whom the Software is
11
// furnished to do so, subject to the following conditions:
12
 
13
// The above copyright notice and this permission notice shall be included in
14
// all copies or substantial portions of the Software.
15
 
16
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
// THE SOFTWARE.
23
 
24 3 jamey.hick
//**********************************************************************
25
// Input Generator implementation
26
//----------------------------------------------------------------------
27
//
28
//
29
 
30
package mkInputGen;
31
 
32
import H264Types::*;
33
import IInputGen::*;
34
import RegFile::*;
35
import FIFO::*;
36
import IEDKBRAM::*;
37
 
38
import Connectable::*;
39
import GetPut::*;
40
//import BypassReg::*;
41
 
42
 
43
// Control reg 0 -> bit zero is the flag, bits 4-7 are top bits of the data amount
44
// Control reg
45
 
46
`define INPUT_BUFFER_LOG_SIZE 13
47
 
48
typedef enum
49
{
50
   READING = 0,
51
   WAITING_FOR_DATA = 1,
52
   WAITING_FOR_DATA_BUBBLE = 2,
53
   OBTAINING_LENGTH = 3,
54
   OBTAINING_LENGTH_BUBBLE = 4,
55
   ALTERNATING_BLOCK = 5,
56
   LAST_BLOCK = 6,
57
   BLOCK_SWITCH_BUBBLE =7
58
}
59
   InputState
60
            deriving (Eq, Bits);
61
 
62
(* synthesize *)
63
module mkInputGen( IInputGen );
64
 
65
   Reg#(Bit#(TSub#(`INPUT_BUFFER_LOG_SIZE, 1))) addr <- mkReg(0);
66
   Reg#(Bit#(TSub#(`INPUT_BUFFER_LOG_SIZE, 1))) addr_last <- mkReg(0);
67
   Reg#(Bit#(TSub#(`INPUT_BUFFER_LOG_SIZE, 1))) addr_last_last <- mkReg(0);
68
   Reg#(Bit#(TSub#(`INPUT_BUFFER_LOG_SIZE, 2))) data_counter <- mkReg(0);
69
   Reg#(Bit#(1)) target_buffer <- mkReg(0);
70
   Reg#(InputState) state <- mkReg(WAITING_FOR_DATA);
71
   Reg#(Bit#(32)) data_in <- mkReg(0);
72
   Reg#(Bit#(16)) counter <- mkReg(0);
73
   Reg#(Bit#(8))  last_byte <- mkReg(0);
74
 
75
   FIFO#(InputGenOT) outfifo <- mkFIFO;
76
 
77
   interface Get ioout = fifoToGet(outfifo);
78
 
79
   interface IEDKBRAM bram_interface;
80
     method Action data_input(Bit#(32) data);
81
       data_in <= data;
82
       addr_last <= addr;
83
       addr_last_last <= addr_last;
84
       case (state)
85
         WAITING_FOR_DATA:
86
           begin
87
             if(data_in[7:0] == 0)
88
               begin
89
                 addr <= ~0;
90
               end
91
             else
92
               begin
93
                 addr <= ~0;
94
                 state <= WAITING_FOR_DATA_BUBBLE;
95
               end
96
           end
97
         WAITING_FOR_DATA_BUBBLE:
98
           begin
99
             if(data_in[7:0] == 0)
100
               begin
101
                 addr <= ~0;
102
                 state <= WAITING_FOR_DATA;
103
               end
104
             else
105
               begin
106
                 addr <= ~0;
107
                 state <= OBTAINING_LENGTH;
108
               end
109
           end
110
        OBTAINING_LENGTH:
111
          begin
112
            if(data_in[23:8] == 0)
113
              begin
114
                addr <= ~0;
115
                state <= LAST_BLOCK;
116
              end
117
            else
118
              begin
119
                addr <= 0;
120
                Bit#(TSub#(`INPUT_BUFFER_LOG_SIZE, 2)) counter_value = truncate(data_in >> 8);
121
                data_counter <= counter_value;
122
                state <= OBTAINING_LENGTH_BUBBLE;
123
              end
124
         end
125
        OBTAINING_LENGTH_BUBBLE:
126
          begin
127
            state <= READING;
128
            addr <= addr + 1;
129
          end
130
        READING:
131
          begin
132
 
133
            if(data_counter > 0)
134
              begin
135
                if(addr_last[1:0] == 0)
136
                  begin
137
                   last_byte <= data[7:0];
138
                  end
139
                Bit#(8) data_byte = case (addr_last[1:0])
140
                  2'b11: last_byte;
141
                  2'b10: data[15:8];
142
                  2'b01: data[23:16];
143
                  2'b00: data[31:24];
144
                endcase;
145
                counter <= counter + 1;
146 13 jamey.hick
                outfifo.enq(DataByte (data_byte));
147 3 jamey.hick
                data_counter <= data_counter - 1;
148
                addr <= addr + 1;
149
              end
150
            else
151
              begin
152
                // Check to see if we read less than the full buffer's worth of data.
153
                if(addr < (1<<(`INPUT_BUFFER_LOG_SIZE-3)))
154
                  begin
155
                    //We read too little data, so we're done.
156
                    addr <=  ~0;
157
                    state <= LAST_BLOCK;
158
                  end
159
                else
160
                  begin
161
                    addr <= ~0;
162
                    state <= ALTERNATING_BLOCK;
163
                  end
164
             end
165
          end
166
        LAST_BLOCK:
167
          begin
168
            target_buffer <= 0;
169
            addr <= ~0;
170
            state <= BLOCK_SWITCH_BUBBLE;
171
            outfifo.enq(EndOfFile);
172
          end
173
 
174
        ALTERNATING_BLOCK:
175
          begin
176
            target_buffer <= (target_buffer == 0)? 1 : 0;
177
            addr <= ~0;
178
            state <= BLOCK_SWITCH_BUBBLE;
179
          end
180
 
181
        BLOCK_SWITCH_BUBBLE:
182
          begin
183
            state <= WAITING_FOR_DATA;
184
          end
185
       endcase
186
     endmethod
187
 
188
     method wen_output();
189
       return ((state == LAST_BLOCK) || (state == ALTERNATING_BLOCK)) ? ~0 : 0;
190
     endmethod
191
 
192
     method Bit#(32) addr_output();
193
       return zeroExtend({target_buffer, addr});
194
     endmethod
195
 
196
     method Bit#(32) data_output();
197
       return 0;
198
     endmethod
199
  endinterface
200
endmodule
201
 
202
 
203
endpackage

powered by: WebSVN 2.1.0

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