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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [basal/] [src/] [ROM/] [axis_rom.sv] - Blame information for rev 49

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 49 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2019 Authors and OPENCORES.ORG                 ////
4
////                                                              ////
5
//// This source file may be used and distributed without         ////
6
//// restriction provided that this copyright statement is not    ////
7
//// removed from the file and that any derivative work contains  ////
8
//// the original copyright notice and the associated disclaimer. ////
9
////                                                              ////
10
//// This source file is free software; you can redistribute it   ////
11
//// and/or modify it under the terms of the GNU Lesser General   ////
12
//// Public License as published by the Free Software Foundation; ////
13
//// either version 2.1 of the License, or (at your option) any   ////
14
//// later version.                                               ////
15
////                                                              ////
16
//// This source is distributed in the hope that it will be       ////
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
19
//// PURPOSE.  See the GNU Lesser General Public License for more ////
20
//// details.                                                     ////
21
////                                                              ////
22
//// You should have received a copy of the GNU Lesser General    ////
23
//// Public License along with this source; if not, download it   ////
24
//// from http://www.opencores.org/lgpl.shtml                     ////
25
////                                                              ////
26
//////////////////////////////////////////////////////////////////////
27
 
28
module
29
  axis_rom
30
  #(
31
    int N,
32
    int A,
33
    string FILE_NAME,
34
    int START=0,
35
    int STOP=2**A
36
  )
37
  (
38
    axis_if axis_out,
39
    input   aclk,
40
    input   aresetn
41
  );
42
 
43
  // --------------------------------------------------------------------
44
  wire wr_full;
45
  wire rd_empty;
46
  wire rd_en = axis_out.tready & axis_out.tvalid;
47
 
48
  // --------------------------------------------------------------------
49
  enum reg [2:0]
50
    {
51
      INIT    = 3'b001,
52
      STALLED = 3'b010,
53
      PRIMED  = 3'b100
54
    } state, next_state;
55
 
56
  // --------------------------------------------------------------------
57
  always_ff @(posedge aclk)
58
    if(~aresetn)
59
      state <= INIT;
60
    else
61
      state <= next_state;
62
 
63
  // --------------------------------------------------------------------
64
  always_comb
65
    case(state)
66
      INIT:       next_state <= STALLED;
67
 
68
      STALLED:    if(~wr_full)
69
                    next_state <= PRIMED;
70
                  else
71
                    next_state <= STALLED;
72
 
73
      PRIMED:     if(rd_empty | (~wr_full & rd_en))
74
                    next_state <= PRIMED;
75
                  else
76
                    next_state <= STALLED;
77
 
78
      default:    next_state <= INIT;
79
    endcase
80
 
81
  // --------------------------------------------------------------------
82
  wire [(N*8)-1:0]  q;
83
  reg [(A-1):0] addr;
84
 
85
  rom #((N*8), A, FILE_NAME) rom(.clk(aclk), .*);
86
 
87
  // --------------------------------------------------------------------
88
  wire [N*8:0] wr_data;
89
  wire [N*8:0] rd_data;
90
  wire wr_en = (state == PRIMED);
91
 
92
  tiny_sync_fifo #((N*8)+1) fifo(.clk(aclk), .reset(~aresetn), .*);
93
 
94
  // --------------------------------------------------------------------
95
  reg increment;
96
 
97
  always_comb
98
    case({state, next_state})
99
      {STALLED,  PRIMED}: increment <= 1;
100
      {PRIMED,   PRIMED}: increment <= 1;
101
      default:            increment <= 0;
102
    endcase
103
 
104
  // --------------------------------------------------------------------
105
  wire stop = increment & (addr >= STOP - START - 1);
106
 
107
  always_ff @(posedge aclk)
108
    if(~aresetn | stop)
109
      addr <= 0;
110
    else if(increment)
111
      addr <= addr + 1;
112
 
113
  // --------------------------------------------------------------------
114
  reg tlast;
115
 
116
  always_ff @(posedge aclk)
117
    if(stop)
118
      tlast <= 1;
119
    else if(~aresetn | wr_en)
120
      tlast <= 0;
121
 
122
  // --------------------------------------------------------------------
123
  assign axis_out.tvalid = ~rd_empty;
124
  assign {axis_out.tlast, axis_out.tdata} = rd_data;
125
  assign wr_data = {tlast, q};
126
 
127
// --------------------------------------------------------------------
128
endmodule

powered by: WebSVN 2.1.0

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