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

Subversion Repositories hssdrc

[/] [hssdrc/] [trunk/] [rtl/] [hssdrc_init_state.v] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 des00
//
2
// Project      : High-Speed SDRAM Controller with adaptive bank management and command pipeline
3
// 
4
// Project Nick : HSSDRC
5
// 
6
// Version      : 1.0-beta 
7
//  
8
// Revision     : $Revision: 1.1 $ 
9
// 
10
// Date         : $Date: 2008-03-06 13:52:43 $ 
11
// 
12
// Workfile     : hssdrc_init_state.v
13
// 
14
// Description  : sdram chip initialization unit
15
// 
16
// HSSDRC is licensed under MIT License
17
// 
18
// Copyright (c) 2007-2008, Denis V.Shekhalev (des00@opencores.org) 
19
// 
20
// Permission  is hereby granted, free of charge, to any person obtaining a copy of
21
// this  software  and  associated documentation files (the "Software"), to deal in
22
// the  Software  without  restriction,  including without limitation the rights to
23
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
24
// the  Software, and to permit persons to whom the Software is furnished to do so,
25
// subject to the following conditions:
26
// 
27
// The  above  copyright notice and this permission notice shall be included in all
28
// copies or substantial portions of the Software.
29
// 
30
// THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
32
// FOR  A  PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
33
// COPYRIGHT  HOLDERS  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
34
// IN  AN  ACTION  OF  CONTRACT,  TORT  OR  OTHERWISE,  ARISING  FROM, OUT OF OR IN
35
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36
//
37
 
38
 
39
`include "hssdrc_timescale.vh"
40
 
41
`include "hssdrc_timing.vh"
42
`include "hssdrc_define.vh"
43
 
44
module hssdrc_init_state (
45
  clk           ,
46
  reset         ,
47
  sclr          ,
48
  init_done     ,
49
  pre_all       ,
50
  refr          ,
51
  lmr           ,
52
  rowa
53
  );
54
 
55
  input wire clk  ;
56
  input wire reset;
57
  input wire sclr ;
58
 
59
  output logic  init_done;
60
  output logic  pre_all  ;
61
  output logic  refr     ;
62
  output logic  lmr      ;
63
  output rowa_t rowa     ;
64
 
65
  assign rowa = cInitLmrValue;
66
 
67
  //---------------------------------------------------------------------------------------------------
68
  // counter based FSM
69
  // fsm has 1 counter divided by 2 part :
70
  // cnt_high - decode for wait init interval
71
  // cnt_low - execute command sequence when wait done. 
72
  // true init time is ~= (1.1 - 1.2) pInit_time for less logic resource using 
73
  //---------------------------------------------------------------------------------------------------
74
 
75
  localparam int unsigned cInitPre   = 1;
76
  localparam int unsigned cInitRefr0 = cInitPre    + cTrp;
77
  localparam int unsigned cInitRefr1 = cInitRefr0  + cTrfc;
78
  localparam int unsigned cInitLmr   = cInitRefr1  + cTrfc;
79
  localparam int unsigned cInitDone  = cInitLmr    + cTmrd + 1;
80
 
81
  //
82
  // counter parameters
83
  // 
84
 
85
  localparam int unsigned cInitCntLowWidth  = clogb2(cInitDone);
86
  localparam int unsigned cInitCntHighMax   = (cInitTime >> cInitCntLowWidth) + 1;
87
  localparam int unsigned cInitCntWidth     = clogb2(cInitCntHighMax) + cInitCntLowWidth;
88
 
89
  //-------------------------------------------------------------------------------------------------- 
90
  //
91
  //-------------------------------------------------------------------------------------------------- 
92
 
93
  logic [cInitCntWidth-1    : 0]              cnt;
94
  logic [cInitCntLowWidth-1 : 0]              cnt_low;
95
  logic [cInitCntWidth-1 : cInitCntLowWidth]  cnt_high;
96
 
97
  logic cnt_high_is_max;
98
 
99
  assign cnt_low  = cnt [cInitCntLowWidth-1 : 0];
100
  assign cnt_high = cnt [cInitCntWidth-1    : cInitCntLowWidth];
101
 
102
 
103
  always_ff @(posedge clk or posedge reset) begin : cnt_fsm
104
    if (reset)
105
      cnt <= '0;
106
    else if (sclr)
107
      cnt <= '0;
108
    else if (~init_done)
109
      cnt <= cnt + 1'b1;
110
  end
111
 
112
 
113
  always_ff @(posedge clk or posedge reset) begin : cnt_fsm_comparator
114
    if (reset)
115
      cnt_high_is_max <= 1'b0;
116
    else if (sclr)
117
      cnt_high_is_max <= 1'b0;
118
    else
119
      cnt_high_is_max <= (cnt_high == cInitCntHighMax);
120
  end
121
 
122
 
123
  always_ff @(posedge clk or posedge reset) begin : cnt_fsm_decode
124
    if (reset) begin
125
      init_done <= 1'b0;
126
      pre_all   <= 1'b0;
127
      refr      <= 1'b0;
128
      lmr       <= 1'b0;
129
    end
130
    else if (sclr) begin
131
      init_done <= 1'b0;
132
      pre_all   <= 1'b0;
133
      refr      <= 1'b0;
134
      lmr       <= 1'b0;
135
    end
136
    else begin
137
 
138
      pre_all <= 1'b0;
139
      refr    <= 1'b0;
140
      lmr     <= 1'b0;
141
 
142
      unique case (cnt_low)
143
        cInitPre    : pre_all   <= cnt_high_is_max;
144
        cInitRefr0  : refr      <= cnt_high_is_max;
145
        cInitRefr1  : refr      <= cnt_high_is_max;
146
        cInitLmr    : lmr       <= cnt_high_is_max;
147
        cInitDone   : init_done <= cnt_high_is_max;
148
        default     : begin end
149
      endcase
150
 
151
    end
152
  end
153
 
154
endmodule

powered by: WebSVN 2.1.0

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