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 13

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

Line No. Rev Author Line
1 3 jamey.hick
//**********************************************************************
2
// Input Generator implementation
3
//----------------------------------------------------------------------
4
//
5
//
6
 
7
package mkInputGen;
8
 
9
import H264Types::*;
10
import IInputGen::*;
11
import RegFile::*;
12
import FIFO::*;
13
import IEDKBRAM::*;
14
 
15
import Connectable::*;
16
import GetPut::*;
17
//import BypassReg::*;
18
 
19
 
20
// Control reg 0 -> bit zero is the flag, bits 4-7 are top bits of the data amount
21
// Control reg
22
 
23
`define INPUT_BUFFER_LOG_SIZE 13
24
 
25
typedef enum
26
{
27
   READING = 0,
28
   WAITING_FOR_DATA = 1,
29
   WAITING_FOR_DATA_BUBBLE = 2,
30
   OBTAINING_LENGTH = 3,
31
   OBTAINING_LENGTH_BUBBLE = 4,
32
   ALTERNATING_BLOCK = 5,
33
   LAST_BLOCK = 6,
34
   BLOCK_SWITCH_BUBBLE =7
35
}
36
   InputState
37
            deriving (Eq, Bits);
38
 
39
(* synthesize *)
40
module mkInputGen( IInputGen );
41
 
42
   Reg#(Bit#(TSub#(`INPUT_BUFFER_LOG_SIZE, 1))) addr <- mkReg(0);
43
   Reg#(Bit#(TSub#(`INPUT_BUFFER_LOG_SIZE, 1))) addr_last <- mkReg(0);
44
   Reg#(Bit#(TSub#(`INPUT_BUFFER_LOG_SIZE, 1))) addr_last_last <- mkReg(0);
45
   Reg#(Bit#(TSub#(`INPUT_BUFFER_LOG_SIZE, 2))) data_counter <- mkReg(0);
46
   Reg#(Bit#(1)) target_buffer <- mkReg(0);
47
   Reg#(InputState) state <- mkReg(WAITING_FOR_DATA);
48
   Reg#(Bit#(32)) data_in <- mkReg(0);
49
   Reg#(Bit#(16)) counter <- mkReg(0);
50
   Reg#(Bit#(8))  last_byte <- mkReg(0);
51
 
52
   FIFO#(InputGenOT) outfifo <- mkFIFO;
53
 
54
   interface Get ioout = fifoToGet(outfifo);
55
 
56
   interface IEDKBRAM bram_interface;
57
     method Action data_input(Bit#(32) data);
58
       data_in <= data;
59
       addr_last <= addr;
60
       addr_last_last <= addr_last;
61
       case (state)
62
         WAITING_FOR_DATA:
63
           begin
64
             if(data_in[7:0] == 0)
65
               begin
66
                 addr <= ~0;
67
               end
68
             else
69
               begin
70
                 addr <= ~0;
71
                 state <= WAITING_FOR_DATA_BUBBLE;
72
               end
73
           end
74
         WAITING_FOR_DATA_BUBBLE:
75
           begin
76
             if(data_in[7:0] == 0)
77
               begin
78
                 addr <= ~0;
79
                 state <= WAITING_FOR_DATA;
80
               end
81
             else
82
               begin
83
                 addr <= ~0;
84
                 state <= OBTAINING_LENGTH;
85
               end
86
           end
87
        OBTAINING_LENGTH:
88
          begin
89
            if(data_in[23:8] == 0)
90
              begin
91
                addr <= ~0;
92
                state <= LAST_BLOCK;
93
              end
94
            else
95
              begin
96
                addr <= 0;
97
                Bit#(TSub#(`INPUT_BUFFER_LOG_SIZE, 2)) counter_value = truncate(data_in >> 8);
98
                data_counter <= counter_value;
99
                state <= OBTAINING_LENGTH_BUBBLE;
100
              end
101
         end
102
        OBTAINING_LENGTH_BUBBLE:
103
          begin
104
            state <= READING;
105
            addr <= addr + 1;
106
          end
107
        READING:
108
          begin
109
 
110
            if(data_counter > 0)
111
              begin
112
                if(addr_last[1:0] == 0)
113
                  begin
114
                   last_byte <= data[7:0];
115
                  end
116
                Bit#(8) data_byte = case (addr_last[1:0])
117
                  2'b11: last_byte;
118
                  2'b10: data[15:8];
119
                  2'b01: data[23:16];
120
                  2'b00: data[31:24];
121
                endcase;
122
                counter <= counter + 1;
123 13 jamey.hick
                outfifo.enq(DataByte (data_byte));
124 3 jamey.hick
                data_counter <= data_counter - 1;
125
                addr <= addr + 1;
126
              end
127
            else
128
              begin
129
                // Check to see if we read less than the full buffer's worth of data.
130
                if(addr < (1<<(`INPUT_BUFFER_LOG_SIZE-3)))
131
                  begin
132
                    //We read too little data, so we're done.
133
                    addr <=  ~0;
134
                    state <= LAST_BLOCK;
135
                  end
136
                else
137
                  begin
138
                    addr <= ~0;
139
                    state <= ALTERNATING_BLOCK;
140
                  end
141
             end
142
          end
143
        LAST_BLOCK:
144
          begin
145
            target_buffer <= 0;
146
            addr <= ~0;
147
            state <= BLOCK_SWITCH_BUBBLE;
148
            outfifo.enq(EndOfFile);
149
          end
150
 
151
        ALTERNATING_BLOCK:
152
          begin
153
            target_buffer <= (target_buffer == 0)? 1 : 0;
154
            addr <= ~0;
155
            state <= BLOCK_SWITCH_BUBBLE;
156
          end
157
 
158
        BLOCK_SWITCH_BUBBLE:
159
          begin
160
            state <= WAITING_FOR_DATA;
161
          end
162
       endcase
163
     endmethod
164
 
165
     method wen_output();
166
       return ((state == LAST_BLOCK) || (state == ALTERNATING_BLOCK)) ? ~0 : 0;
167
     endmethod
168
 
169
     method Bit#(32) addr_output();
170
       return zeroExtend({target_buffer, addr});
171
     endmethod
172
 
173
     method Bit#(32) data_output();
174
       return 0;
175
     endmethod
176
  endinterface
177
endmodule
178
 
179
 
180
endpackage

powered by: WebSVN 2.1.0

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