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

Subversion Repositories usb_fpga_2_14

[/] [usb_fpga_2_14/] [trunk/] [examples/] [memfifo/] [fpga-2.18/] [memfifo.srcs/] [sources_1/] [ip/] [mig_7series_0/] [mig_7series_0/] [user_design/] [rtl/] [clocking/] [mig_7series_v2_3_tempmon.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
//*****************************************************************************
2
// (c) Copyright 2008 - 2013 Xilinx, Inc. All rights reserved.
3
//
4
// This file contains confidential and proprietary information
5
// of Xilinx, Inc. and is protected under U.S. and
6
// international copyright and other intellectual property
7
// laws.
8
//
9
// DISCLAIMER
10
// This disclaimer is not a license and does not grant any
11
// rights to the materials distributed herewith. Except as
12
// otherwise provided in a valid license issued to you by
13
// Xilinx, and to the maximum extent permitted by applicable
14
// law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
15
// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
16
// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
17
// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
18
// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
19
// (2) Xilinx shall not be liable (whether in contract or tort,
20
// including negligence, or under any other theory of
21
// liability) for any loss or damage of any kind or nature
22
// related to, arising under or in connection with these
23
// materials, including for any direct, or any indirect,
24
// special, incidental, or consequential loss or damage
25
// (including loss of data, profits, goodwill, or any type of
26
// loss or damage suffered as a result of any action brought
27
// by a third party) even if such damage or loss was
28
// reasonably foreseeable or Xilinx had been advised of the
29
// possibility of the same.
30
//
31
// CRITICAL APPLICATIONS
32
// Xilinx products are not designed or intended to be fail-
33
// safe, or for use in any application requiring fail-safe
34
// performance, such as life-support or safety devices or
35
// systems, Class III medical devices, nuclear facilities,
36
// applications related to the deployment of airbags, or any
37
// other applications that could lead to death, personal
38
// injury, or severe property or environmental damage
39
// (individually and collectively, "Critical
40
// Applications"). Customer assumes the sole risk and
41
// liability of any use of Xilinx products in Critical
42
// Applications, subject only to applicable laws and
43
// regulations governing limitations on product liability.
44
//
45
// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
46
// PART OF THIS FILE AT ALL TIMES.
47
//
48
//*****************************************************************************
49
//   ____  ____
50
//  /   /\/   /
51
// /___/  \  /    Vendor                : Xilinx
52
// \   \   \/     Version               : %version
53
//  \   \         Application           : MIG
54
//  /   /         Filename              : mig_7series_v2_3_tempmon.v
55
// /___/   /\     Date Last Modified    : $date$
56
// \   \  /  \    Date Created          : Jul 25 2012
57
//  \___\/\___\
58
//
59
//Device            : 7 Series
60
//Design Name       : DDR3 SDRAM
61
//Purpose           : Monitors chip temperature via the XADC and adjusts the
62
//                    stage 2 tap values as appropriate.
63
//Reference         :
64
//Revision History  :
65
//*****************************************************************************
66
 
67
`timescale 1 ps / 1 ps
68
 
69
module mig_7series_v2_3_tempmon #
70
(
71
  parameter TCQ                 = 100,        // Register delay (sim only)
72
  parameter TEMP_MON_CONTROL    = "INTERNAL", // XADC or user temperature source
73
  parameter XADC_CLK_PERIOD     = 5000,       // pS (default to 200 MHz refclk)
74
  parameter tTEMPSAMPLE         = 10000000    // ps (10 us)
75
)
76
(
77
  input           clk,                      // Fabric clock
78
  input           xadc_clk,
79
  input           rst,                      // System reset
80
  input   [11:0]  device_temp_i,            // User device temperature
81
  output  [11:0]  device_temp               // Sampled temperature
82
);
83
 
84
  //***************************************************************************
85
  // Function cdiv
86
  //  Description:
87
  //    This function performs ceiling division (divide and round-up)
88
  //  Inputs:
89
  //    num: integer to be divided
90
  //    div: divisor
91
  // Outputs:
92
  //    cdiv: result of ceiling division (num/div, rounded up)
93
  //***************************************************************************
94
 
95
  function integer cdiv (input integer num, input integer div);
96
    begin
97
      // perform division, then add 1 if and only if remainder is non-zero
98
      cdiv = (num/div) + (((num%div)>0) ? 1 : 0);
99
    end
100
  endfunction // cdiv
101
 
102
  //***************************************************************************
103
  // Function clogb2
104
  //  Description:
105
  //    This function performs binary logarithm and rounds up
106
  //  Inputs:
107
  //    size: integer to perform binary log upon
108
  // Outputs:
109
  //    clogb2: result of binary logarithm, rounded up
110
  //***************************************************************************
111
 
112
  function integer clogb2 (input integer size);
113
    begin
114
 
115
      size = size - 1;
116
 
117
      // increment clogb2 from 1 for each bit in size
118
      for (clogb2 = 1; size > 1; clogb2 = clogb2 + 1)
119
      size = size >> 1;
120
 
121
    end
122
 
123
  endfunction // clogb2
124
 
125
  // Synchronization registers
126
  (* ASYNC_REG = "TRUE" *)  reg   [11:0]  device_temp_sync_r1;
127
  (* ASYNC_REG = "TRUE" *)  reg   [11:0]  device_temp_sync_r2;
128
  (* ASYNC_REG = "TRUE" *)  reg   [11:0]  device_temp_sync_r3 /* synthesis syn_srlstyle="registers" */;
129
  (* ASYNC_REG = "TRUE" *)  reg   [11:0]  device_temp_sync_r4;
130
  (* ASYNC_REG = "TRUE" *)  reg   [11:0]  device_temp_sync_r5;
131
 
132
  // Output register
133
  (* ASYNC_REG = "TRUE" *)  reg   [11:0]  device_temp_r;
134
 
135
  wire                            [11:0]  device_temp_lcl;
136
  reg                             [3:0]   sync_cntr = 4'b0000;
137
  reg                                     device_temp_sync_r4_neq_r3;
138
 
139
 // (* ASYNC_REG = "TRUE" *)  reg rst_r1;
140
 // (* ASYNC_REG = "TRUE" *)  reg rst_r2;
141
 
142
 // // Synchronization rst to XADC clock domain
143
 // always @(posedge xadc_clk) begin
144
 //   rst_r1 <= rst;
145
 //   rst_r2 <= rst_r1;
146
 // end
147
 
148
  // Synchronization counter
149
  always @(posedge clk) begin
150
 
151
    device_temp_sync_r1 <= #TCQ device_temp_lcl;
152
    device_temp_sync_r2 <= #TCQ device_temp_sync_r1;
153
    device_temp_sync_r3 <= #TCQ device_temp_sync_r2;
154
    device_temp_sync_r4 <= #TCQ device_temp_sync_r3;
155
    device_temp_sync_r5 <= #TCQ device_temp_sync_r4;
156
 
157
    device_temp_sync_r4_neq_r3 <= #TCQ (device_temp_sync_r4 != device_temp_sync_r3) ? 1'b1 : 1'b0;
158
 
159
  end
160
 
161
  always @(posedge clk)
162
    if(rst || (device_temp_sync_r4_neq_r3))
163
      sync_cntr <= #TCQ 4'b0000;
164
    else if(~&sync_cntr)
165
      sync_cntr <= #TCQ sync_cntr + 4'b0001;
166
 
167
  always @(posedge clk)
168
    if(&sync_cntr)
169
      device_temp_r <= #TCQ device_temp_sync_r5;
170
 
171
  assign device_temp = device_temp_r;
172
 
173
  generate
174
 
175
    if(TEMP_MON_CONTROL == "EXTERNAL") begin : user_supplied_temperature
176
 
177
      assign device_temp_lcl = device_temp_i;
178
 
179
    end else begin : xadc_supplied_temperature
180
 
181
      // calculate polling timer width and limit
182
      localparam nTEMPSAMP = cdiv(tTEMPSAMPLE, XADC_CLK_PERIOD);
183
      localparam nTEMPSAMP_CLKS = nTEMPSAMP;
184
      localparam nTEMPSAMP_CLKS_M6 = nTEMPSAMP - 6;
185
      localparam nTEMPSAMP_CNTR_WIDTH = clogb2(nTEMPSAMP_CLKS);
186
 
187
      // Temperature sampler FSM encoding
188
      localparam INIT_IDLE                                = 2'b00;
189
      localparam REQUEST_READ_TEMP                        = 2'b01;
190
      localparam WAIT_FOR_READ                            = 2'b10;
191
      localparam READ                                     = 2'b11;
192
 
193
      // polling timer and tick
194
      reg [nTEMPSAMP_CNTR_WIDTH-1:0]  sample_timer = {nTEMPSAMP_CNTR_WIDTH{1'b0}};
195
      reg                             sample_timer_en     = 1'b0;
196
      reg                             sample_timer_clr    = 1'b0;
197
      reg                             sample_en           = 1'b0;
198
 
199
      // Temperature sampler state
200
      reg [2:0]                       tempmon_state       = INIT_IDLE;
201
      reg [2:0]                       tempmon_next_state  = INIT_IDLE;
202
 
203
      // XADC interfacing
204
      reg                             xadc_den            = 1'b0;
205
      wire                            xadc_drdy;
206
      wire  [15:0]                    xadc_do;
207
      reg                             xadc_drdy_r         = 1'b0;
208
      reg   [15:0]                    xadc_do_r           = 1'b0;
209
 
210
      // Temperature storage
211
      reg   [11:0]                    temperature         = 12'b0;
212
 
213
      // Reset sync
214
      (* ASYNC_REG = "TRUE" *)  reg rst_r1;
215
      (* ASYNC_REG = "TRUE" *)  reg rst_r2;
216
 
217
      // Synchronization rst to XADC clock domain
218
      always @(posedge xadc_clk) begin
219
        rst_r1 <= rst;
220
        rst_r2 <= rst_r1;
221
      end
222
 
223
      // XADC polling interval timer
224
      always @ (posedge xadc_clk)
225
        if(rst_r2 || sample_timer_clr)
226
          sample_timer <= #TCQ {nTEMPSAMP_CNTR_WIDTH{1'b0}};
227
        else if(sample_timer_en)
228
          sample_timer <= #TCQ sample_timer + 1'b1;
229
 
230
      // XADC sampler state transition
231
      always @(posedge xadc_clk)
232
        if(rst_r2)
233
          tempmon_state <= #TCQ INIT_IDLE;
234
        else
235
          tempmon_state <= #TCQ tempmon_next_state;
236
 
237
      // Sample enable
238
      always @(posedge xadc_clk)
239
        sample_en <= #TCQ (sample_timer == nTEMPSAMP_CLKS_M6) ? 1'b1 : 1'b0;
240
 
241
      // XADC sampler next state transition
242
      always @(tempmon_state or sample_en or xadc_drdy_r) begin
243
 
244
        tempmon_next_state = tempmon_state;
245
 
246
        case(tempmon_state)
247
 
248
          INIT_IDLE:
249
            if(sample_en)
250
              tempmon_next_state = REQUEST_READ_TEMP;
251
 
252
          REQUEST_READ_TEMP:
253
            tempmon_next_state = WAIT_FOR_READ;
254
 
255
          WAIT_FOR_READ:
256
            if(xadc_drdy_r)
257
              tempmon_next_state = READ;
258
 
259
          READ:
260
            tempmon_next_state = INIT_IDLE;
261
 
262
          default:
263
            tempmon_next_state = INIT_IDLE;
264
 
265
        endcase
266
 
267
      end
268
 
269
      // Sample timer clear
270
      always @(posedge xadc_clk)
271
        if(rst_r2 || (tempmon_state == WAIT_FOR_READ))
272
          sample_timer_clr <= #TCQ 1'b0;
273
        else if(tempmon_state == REQUEST_READ_TEMP)
274
          sample_timer_clr <= #TCQ 1'b1;
275
 
276
      // Sample timer enable
277
      always @(posedge xadc_clk)
278
        if(rst_r2 || (tempmon_state == REQUEST_READ_TEMP))
279
          sample_timer_en <= #TCQ 1'b0;
280
        else if((tempmon_state == INIT_IDLE) || (tempmon_state == READ))
281
          sample_timer_en <= #TCQ 1'b1;
282
 
283
      // XADC enable
284
      always @(posedge xadc_clk)
285
        if(rst_r2 || (tempmon_state == WAIT_FOR_READ))
286
          xadc_den <= #TCQ 1'b0;
287
        else if(tempmon_state == REQUEST_READ_TEMP)
288
          xadc_den <= #TCQ 1'b1;
289
 
290
      // Register XADC outputs
291
      always @(posedge xadc_clk)
292
        if(rst_r2) begin
293
          xadc_drdy_r <= #TCQ 1'b0;
294
          xadc_do_r <= #TCQ 16'b0;
295
        end
296
        else begin
297
          xadc_drdy_r <= #TCQ xadc_drdy;
298
          xadc_do_r <= #TCQ xadc_do;
299
        end
300
 
301
      // Store current read value
302
      always @(posedge xadc_clk)
303
        if(rst_r2)
304
          temperature <= #TCQ 12'b0;
305
        else if(tempmon_state == READ)
306
          temperature <= #TCQ xadc_do_r[15:4];
307
 
308
      assign device_temp_lcl = temperature;
309
 
310
      // XADC: Dual 12-Bit 1MSPS Analog-to-Digital Converter
311
      // 7 Series
312
      // Xilinx HDL Libraries Guide, version 14.1
313
      XADC #(
314
        // INIT_40 - INIT_42: XADC configuration registers
315
        .INIT_40(16'h1000), // config reg 0
316
        .INIT_41(16'h2fff), // config reg 1
317
        .INIT_42(16'h0800), // config reg 2
318
        // INIT_48 - INIT_4F: Sequence Registers
319
        .INIT_48(16'h0101), // Sequencer channel selection
320
        .INIT_49(16'h0000), // Sequencer channel selection
321
        .INIT_4A(16'h0100), // Sequencer Average selection
322
        .INIT_4B(16'h0000), // Sequencer Average selection
323
        .INIT_4C(16'h0000), // Sequencer Bipolar selection
324
        .INIT_4D(16'h0000), // Sequencer Bipolar selection
325
        .INIT_4E(16'h0000), // Sequencer Acq time selection
326
        .INIT_4F(16'h0000), // Sequencer Acq time selection
327
        // INIT_50 - INIT_58, INIT5C: Alarm Limit Registers
328
        .INIT_50(16'hb5ed), // Temp alarm trigger
329
        .INIT_51(16'h57e4), // Vccint upper alarm limit
330
        .INIT_52(16'ha147), // Vccaux upper alarm limit
331
        .INIT_53(16'hca33), // Temp alarm OT upper
332
        .INIT_54(16'ha93a), // Temp alarm reset
333
        .INIT_55(16'h52c6), // Vccint lower alarm limit
334
        .INIT_56(16'h9555), // Vccaux lower alarm limit
335
        .INIT_57(16'hae4e), // Temp alarm OT reset
336
        .INIT_58(16'h5999), // VBRAM upper alarm limit
337
        .INIT_5C(16'h5111), //  VBRAM lower alarm limit
338
        // Simulation attributes: Set for proepr simulation behavior
339
        .SIM_DEVICE("7SERIES")  // Select target device (values)
340
      )
341
      XADC_inst (
342
        // ALARMS: 8-bit (each) output: ALM, OT
343
        .ALM(),                     // 8-bit output: Output alarm for temp, Vccint, Vccaux and Vccbram
344
        .OT(),                      // 1-bit output: Over-Temperature alarm
345
        // Dynamic Reconfiguration Port (DRP): 16-bit (each) output: Dynamic Reconfiguration Ports
346
        .DO(xadc_do),               // 16-bit output: DRP output data bus
347
        .DRDY(xadc_drdy),           // 1-bit output: DRP data ready
348
        // STATUS: 1-bit (each) output: XADC status ports
349
        .BUSY(),                    // 1-bit output: ADC busy output
350
        .CHANNEL(),                 // 5-bit output: Channel selection outputs
351
        .EOC(),                     // 1-bit output: End of Conversion
352
        .EOS(),                     // 1-bit output: End of Sequence
353
        .JTAGBUSY(),                // 1-bit output: JTAG DRP transaction in progress output
354
        .JTAGLOCKED(),              // 1-bit output: JTAG requested DRP port lock
355
        .JTAGMODIFIED(),            // 1-bit output: JTAG Write to the DRP has occurred
356
        .MUXADDR(),                 // 5-bit output: External MUX channel decode
357
        // Auxiliary Analog-Input Pairs: 16-bit (each) input: VAUXP[15:0], VAUXN[15:0]
358
        .VAUXN(16'b0),              // 16-bit input: N-side auxiliary analog input
359
        .VAUXP(16'b0),              // 16-bit input: P-side auxiliary analog input
360
        // CONTROL and CLOCK: 1-bit (each) input: Reset, conversion start and clock inputs
361
        .CONVST(1'b0),              // 1-bit input: Convert start input
362
        .CONVSTCLK(1'b0),           // 1-bit input: Convert start input
363
        .RESET(1'b0),               // 1-bit input: Active-high reset
364
        // Dedicated Analog Input Pair: 1-bit (each) input: VP/VN
365
        .VN(1'b0),                  // 1-bit input: N-side analog input
366
        .VP(1'b0),                  // 1-bit input: P-side analog input
367
        // Dynamic Reconfiguration Port (DRP): 7-bit (each) input: Dynamic Reconfiguration Ports
368
        .DADDR(7'b0),               // 7-bit input: DRP address bus
369
        .DCLK(xadc_clk),            // 1-bit input: DRP clock
370
        .DEN(xadc_den),             // 1-bit input: DRP enable signal
371
        .DI(16'b0),                 // 16-bit input: DRP input data bus
372
        .DWE(1'b0)                  // 1-bit input: DRP write enable
373
      );
374
 
375
      // End of XADC_inst instantiation
376
 
377
    end
378
 
379
  endgenerate
380
 
381
endmodule

powered by: WebSVN 2.1.0

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