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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [axi4_stream_lib/] [src/] [data_to_axis_fsm.sv] - Blame information for rev 31

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 23 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2015 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
 
29
module
30
  data_to_axis_fsm
31
  (
32 31 qaztronic
    input   axis_en,
33
    output  axis_tvalid,
34
    input   axis_tready,
35 23 qaztronic
 
36 31 qaztronic
    input   fifo_watermark,   // OK to use fifo_almost_full if FIFO is synchronous, assert to flush also
37
    input   fifo_empty,
38
    output  fifo_rd_en,
39 23 qaztronic
 
40 31 qaztronic
    output  data_to_axis_fsm_error,
41 23 qaztronic
 
42 31 qaztronic
    input   aclk,
43
    input   aresetn
44 23 qaztronic
  );
45
 
46
  //---------------------------------------------------
47
  //  state machine binary definitions
48
  enum reg [3:0]  {
49
                      IDLE_STATE  = 4'b0001,
50
                      TVALID      = 4'b0010,
51
                      TREADY      = 4'b0100,
52
                      ERROR_STATE = 4'b1000
53
                    } state, next_state;
54
 
55
 
56
  //---------------------------------------------------
57
  //  state machine flop
58
  always_ff @(posedge aclk)
59
    if(~aresetn)
60
      state <= IDLE_STATE;
61
    else
62
      state <= next_state;
63
 
64
 
65
  //---------------------------------------------------
66
  //  state machine
67
  always_comb
68
    case(state)
69 28 qaztronic
      IDLE_STATE:   if(axis_en & fifo_watermark & ~fifo_empty)
70 23 qaztronic
                      if(axis_tready)
71
                        next_state <= TREADY;
72
                      else
73
                        next_state <= TVALID;
74
                    else
75
                      next_state <= IDLE_STATE;
76
 
77
      TVALID:       if(axis_tready)                 // wait for slave to be ready
78
                      next_state <= TREADY;
79
                    else
80
                      next_state <= TVALID;
81
 
82
      TREADY:       if(fifo_empty)                 // slave can accept data
83
                      next_state <= IDLE_STATE;
84
                    else if(axis_tready)
85
                      next_state <= TREADY;
86
                    else
87
                      next_state <= TVALID;
88
 
89
      ERROR_STATE:  next_state <= IDLE_STATE;
90
 
91
      default:      next_state <= ERROR_STATE;
92
 
93
    endcase
94
 
95
 
96
  //---------------------------------------------------
97
  //  outputs
98
  assign axis_tvalid            = (next_state == TVALID) | (next_state == TREADY);
99
  assign fifo_rd_en             = axis_tvalid & axis_tready;
100
  assign data_to_axis_fsm_error = (state == ERROR_STATE);
101
 
102
 
103
endmodule
104
 
105
 
106
 

powered by: WebSVN 2.1.0

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