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

Subversion Repositories sd_mmc_emulator

[/] [sd_mmc_emulator/] [trunk/] [rtl/] [tg.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jclaytons
// $Id: tg.v 914 2015-05-15 13:21:53Z nxp20190 $
2
//
3
// @brief Sango X7 Main timing/meas channel.
4
//
5
// @Author Roger Williams <roger.williams@nxp.com>
6
//
7
// (c) 2015 NXP Semiconductors. All rights reserved.
8
//
9
// PROPRIETARY INFORMATION
10
//
11
// The information contained in this file is the property of NXP Semiconductors.
12
// Except as specifically authorized in writing by NXP, the holder of this file:
13
// (1) shall keep all information contained herein confidential and shall protect
14
// same in whole or in part from disclosure and dissemination to all third parties
15
// and (2) shall use same for operation and maintenance purposes only.
16
// -----------------------------------------------------------------------------
17
// 0.03.1  2015-05-14 (RAW) Hard-code some parameters to get this working today
18
// 0.03.0  2015-05-13 (RAW) Adapted from XCtrl4 code for initial X7
19
//------------------------------------------------------------------------------
20
 
21
`include "registers_def.v"
22
`include "timescale.v"
23
 
24
module tg
25
  (
26
   // interface to channel
27
   output wire        rf_gate,
28
   // interface to Zmon
29
   output reg         adc_sck_o = 0,
30
   output reg         conv_o = 0,
31
   input wire         adcf_sdo_i,
32
   input wire         adcr_sdo_i,
33
   // interface to global control
34
   input wire [7:0]   control,
35
   output wire [7:0]  status,
36
   // interface to MCU
37
   input wire         we_i, oe_i, cs_i, rst_i,
38
   input wire [3:0]   adr_i,
39
   input wire [15:0]  dat_i,
40
   output wire [15:0] dat_o,
41
   input wire         clk200,   // 200MHz for register interface
42
   input wire         clk       // 100MHz for everything else
43
   );
44
 
45
   // HACK! quickly hard-code some parameters
46
   localparam TQ_p = 6'd0, TQ_to = 15'd10, TQ_td = 15'd0, TQ_tf = 15'd6, TQ_tw = 15'd24,
47
      TQ_f = 7'd0, TQ_ts = 12'd0, TQ_tk = 12'd0;
48
 
49
   wire [`TG_REG_BITS_R]        reg_r;
50
   wire [`TG_REG_BITS_W]        reg_w;
51
   wire [`TG_REG_BITS_CTL]      reg_ctl;
52
 
53
   // reclock strobes in 100MHz domain
54
   reg [15:0]            tctrl = 16'b0;
55
   wire                 tctrl_RST = tctrl[15];
56
   wire                 tctrl_ABT = tctrl[14];
57
   wire                 tclr = tctrl[13];
58
   wire                 tctrl_ARM = tctrl[12];
59
   wire                 tctrl_TRIG = tctrl[11];
60
   wire                 tctrl_CONV = tctrl[10];
61
   always @(posedge clk)
62
     tctrl <= reg_w[`TG_TCTRL_INDEX];
63
 
64
   reg [15:0]            mctrl = 16'b0;
65
   wire                 mctrl_RST = mctrl[15];
66
   wire                 mctrl_ABT = mctrl[14];
67
   wire                 mctrl_ARM = mctrl[12];
68
   always @(posedge clk)
69
     mctrl = reg_w[`TG_MCTRL_INDEX];
70
 
71
   wire                 meas_en = control[3];
72
   wire                 src_en = control[2];
73
   wire                 cont = control[1];
74
   wire                 tg_en = control[0];
75
   wire                 trst = control[7] | tctrl_RST;
76
   wire                 trst_en = control[7] | tctrl_RST | ~tg_en;
77
   wire                 tabt = control[6] | tctrl_ABT;
78
   wire                 tarm = control[5] | tctrl_ARM;
79
   wire                 trig = control[4] | tctrl_TRIG;
80
   wire                 mrst = control[7] | mctrl_RST;
81
   wire                 mrst_en = control[7] | mctrl_RST | ~meas_en | ~tg_en;
82
   wire                 mabt = control[6] | mctrl_ABT;
83
   wire                 marm = control[5] | mctrl_ARM;
84
 
85
/* -----\/----- EXCLUDED -----\/-----
86
   // make sure that tqueue strobe is exactly one clock tick wide
87
   reg                  tqueue_ld_dly = 1'b0;
88
   reg                  tqueue_ld_dly2 = 1'b0;
89
   wire                 tqueue_ld = tqueue_ld_dly & ~tqueue_ld_dly2;
90
   always @(posedge clk) begin
91
      tqueue_ld_dly2 <= tqueue_ld_dly;
92
      tqueue_ld_dly <= reg_ctl[`TG_TQUEUE_LD_INDEX];
93
   end
94
 -----/\----- EXCLUDED -----/\----- */
95
 
96
   wire [15:0]           debug = reg_w[`TG_DEBUG_INDEX];
97
   reg                  gate = 1'b0;
98
   assign rf_gate = gate | (debug == 16'h202e);         // force CW mode for testing (unicode RLO ;-)
99
 
100
   wire [15:0]           mconf = reg_w[`TG_MCONF_INDEX];
101
   wire [10:0]           mconf_MAX_COUNT = mconf[10:0];
102
   wire [31:0]           tqueue = reg_w[`TG_TQUEUE_INDEX];
103
 
104
/* -----\/----- EXCLUDED -----\/-----
105
   // write 4 32-bit words of timing parameters into TQUEUE for each burst in sequence
106
   //   +31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0+
107
   //   +-----------------------+-----------------------+-----------------------+-----------------------+
108
   // 1 |||||||      POWER      |                 TC                |                 NP                |
109
   //   +-----------------------+-----------------------+-----------------------+-----------------------+
110
   // 2 ||||                     TO                     ||||                     TD                     |
111
   //   +-----------------------+-----------------------+-----------------------+-----------------------+
112
   // 3 ||||                     TF                     ||||                     TW                     |
113
   //   +-----------------------+-----------------------+-----------------------+-----------------------+
114
   // 4 ||||      FREQUENCY     |                 TS                |                 TK                |
115
   //   +-----------------------+-----------------------+-----------------------+-----------------------+
116
 
117
   reg [31:0]           tparam1 =32'b0;
118
   wire [5:0]           burst_pwr = tparam1[29:24];     // POWER = VGA setting (0..63; 0.5dB steps)
119
   wire [11:0]          burst_tc = tparam1[23:12];      // TC = number of Zmon measurements in burst (0..4095)
120
   wire [11:0]          burst_np = tparam1[11:0];       // NP = number of pulses in the burst (0..4095, 0 disables burst)
121
   reg [31:0]           tparam2 =32'b0;
122
   wire [14:0]          burst_to = tparam2[30:16];      // TO = offset into pulse for Zmon sample (0..32767; 0.1us steps)
123
   wire [14:0]          burst_td = tparam2[14:0];       // TD = starting delay for burst (0..32767; 0.1us steps)
124
   reg [31:0]           tparam3 =32'b0;
125
   wire [14:0]          burst_tf = tparam3[30:16];      // TF = time between each pulse in burst (0..32767; 0.1us steps)
126
   wire [14:0]          burst_tw = tparam3[14:0];       // TW = width of each pulse in burst (0..32767; 0.1us steps)
127
   reg [31:0]           tparam4 =32'b0;
128
   wire [6:0]           burst_freq = tparam4[30:24];    // FREQUENCY = MHz offset above 2400 (0..100; 1MHz steps)
129
   wire [11:0]          burst_ts = tparam4[23:12];      // TS = pulse skip for Zmon measurements (0..4094, 0 means sample every pulse)
130
   wire [11:0]          burst_tk = tparam4[11:0];       // TK = starting pulse for Zmon measurements (0..4094, 0 is first pulse)
131
   reg [4:0]            tiptr = 5'h0;
132
   reg [3:0]            toptr = 4'b0;
133
   reg [4:0]            tcount = 5'b0;
134
   wire [2:0]           tnbursts = tcount[4:2];
135
   reg                  tfetch = 1'b0;
136
   reg                  tstart = 1'b0;
137
   reg [31:0]           tval = 32'b0;
138
   wire                 twe = tqueue_ld & ~tiptr[4];
139
 
140
   assign reg_r[`TG_TQ_STAT_INDEX] = {control, tnbursts, tiptr[4:0]};
141
 
142
   (* ram_style = "pipe_distributed" *)
143
     reg [31:0]         tram [15:0];
144
 
145
   always @(posedge clk) begin
146
      if (twe)
147
         tram[tiptr[3:0]] <= tqueue;
148
      if (tfetch)
149
         tval <= tram[toptr];
150
   end
151
 
152
   always @(posedge clk)
153
      if (trst | tclr) begin
154
         tiptr <= 0;
155
         toptr <= 0;
156
         tcount <= 0;
157
      end
158
      else if (tstart) begin
159
         toptr <= 0;
160
         tcount <= tiptr;
161
      end
162
      else if (tfetch) begin
163
         toptr <= toptr + 1;
164
         tcount <= tcount - 1;
165
      end
166
      else if (twe)
167
         tiptr <= tiptr + 1;
168
 -----/\----- EXCLUDED -----/\----- */
169
 
170
   reg [2:0]             tnbursts = 3'b0;        // HACK!
171
   reg [31:0]            tparam1 =32'b0;
172
   wire [5:0]            burst_pwr = tparam1[29:24];
173
   wire [11:0]           burst_tc = tparam1[23:12];
174
   wire [11:0]           burst_np = tparam1[11:0];
175
   reg [31:0]            tparam2 =32'b0;
176
   wire [14:0]           burst_to = tparam2[30:16];
177
   wire [14:0]           burst_td = tparam2[14:0];
178
   reg [31:0]            tparam3 =32'b0;
179
   wire [14:0]           burst_tf = tparam3[30:16];
180
   wire [14:0]           burst_tw = tparam3[14:0];
181
   reg [31:0]            tparam4 =32'b0;
182
   wire [6:0]            burst_freq = tparam4[30:24];
183
   wire [11:0]           burst_ts = tparam4[23:12];
184
   wire [11:0]           burst_tk = tparam4[11:0];
185
   reg                  tfetch = 1'b0;
186
   reg                  tstart = 1'b0;
187
 
188
   reg [14:0]            ttimer = 15'b0;
189
   reg                  ttimer_load = 1'b0;
190
   reg [14:0]            ttimer_count = 15'b0;
191
   reg [3:0]             tprescale = 4'd9;
192
   wire                 ttimer_done = (ttimer_count == 0);
193
   always @(posedge clk)
194
     if (trst_en) begin
195
        tprescale <= 4'd9;
196
        ttimer_count <= 0;
197
     end
198
     else if (ttimer_load) begin
199
        tprescale <= 4'd7;
200
        ttimer_count <= ttimer;
201
     end
202
     else if (ttimer_count != 0)
203
       if (tprescale == 0) begin
204
          tprescale <= 4'd9;
205
          ttimer_count <= ttimer_count - 1;
206
       end
207
       else
208
         tprescale <= tprescale - 1;
209
 
210
   reg                  trig_dly = 1'b0;
211
   wire                 trise = trig & ~trig_dly;
212
   always @(posedge clk)
213
     trig_dly <= trig;
214
 
215
   // pulse generator state machine
216
   localparam TIdle = 4'd0, Armed = 4'd1, NextBurst = 4'd2, Load0 = 4'd3, Load1 = 4'd4, Load2 = 4'd5, Load3 = 4'd6,
217
     Load4 = 4'd7, TBurstStart = 4'd8, PulseOffStart = 4'd9, PulseOff = 4'd10, PulseOnStart = 4'd11, PulseOn = 4'd12;
218
   reg [3:0]             tstate = TIdle;
219
   reg [11:0]            tnpulses = 12'b0;
220
   reg                  mdone = 1'b0;                   // what does mdone mean?
221
   reg                  mhalf = 1'b0;
222
   reg                  sdone = 1'b0;
223
   reg                  tdone = 1'b0;
224
   reg [6:0]             last_freq = 7'd50;              // assume initialised to 2450
225
   reg [5:0]             last_pwr = 6'b0;
226
   reg                  pulse = 1'b0;
227
   reg                  burst_loaded = 1'b0;
228
   assign status = {mdone, mhalf, sdone, tdone, tstate};
229
 
230
   always @(posedge clk)
231
     if (trst_en | tabt) begin
232
        tstate <= TIdle;
233
        ttimer_load <= 0;
234
        tstart <= 0;
235
        tnpulses <= 0;
236
        pulse <= 0;
237
        gate <= 0;
238
        tdone <= 0;
239
     end
240
     else begin
241
        case (tstate)
242
          TIdle: begin
243
             tdone <= 0;
244
             if (tarm) begin
245
                tstart <= 1;
246
                tstate <= Armed;
247
             end
248
          end
249
          Armed: begin
250
             tdone <= 0;
251
             tstart <= 0;
252
             tnbursts <= 1;
253
             if (trise) begin
254
                tstate <= NextBurst;
255
             end
256
          end
257
          NextBurst: begin
258
             if (tnbursts > 0) begin
259
                tnbursts <= tnbursts - 1;
260
                tfetch <= 1;
261
                tstate <= Load0;
262
             end
263
             else begin
264
                tdone <= 1;
265
                if (cont) begin
266
                   tstart <= 1;
267
                   tstate <= Armed;
268
                end
269
                else
270
                  tstate <= TIdle;
271
             end
272
          end
273
          Load0: begin
274
             tstate <= Load1;
275
          end
276
          Load1: begin
277
/* -----\/----- EXCLUDED -----\/-----
278
             tparam1 <= tval;                           // POWER, TC, NP
279
 -----/\----- EXCLUDED -----/\----- */
280
             tparam1 <= {2'b00, TQ_p, tqueue[11:0], tqueue[11:0]}; // HACK!
281
             tstate <= Load2;
282
          end
283
          Load2: begin
284
/* -----\/----- EXCLUDED -----\/-----
285
             tparam2 <= tval;                           // TO, TD
286
 -----/\----- EXCLUDED -----/\----- */
287
             tparam2 <= {1'b0, TQ_to, 1'b0, TQ_td};     // HACK!
288
             tstate <= Load3;
289
          end
290
          Load3: begin
291
/* -----\/----- EXCLUDED -----\/-----
292
             tparam3 <= tval;                           // TF, TW
293
 -----/\----- EXCLUDED -----/\----- */
294
             tparam3 <= {1'b0, TQ_tf, 1'b0, TQ_tw};     // HACK!
295
             tfetch <= 0;
296
             tstate <= Load4;
297
          end
298
          Load4: begin
299
/* -----\/----- EXCLUDED -----\/-----
300
             tparam4 <= tval;                           // FREQUENCY, TS, TK
301
 -----/\----- EXCLUDED -----/\----- */
302
             tparam4 <= {1'b0, TQ_f, TQ_ts, TQ_tk};     // HACK!
303
             burst_loaded <= 1;                         // flag to meas state machine
304
             tstate <= TBurstStart;
305
          end
306
          TBurstStart: begin
307
             burst_loaded <= 0;
308
             last_freq <= burst_freq;
309
             last_pwr <= burst_pwr;
310
             if (burst_np == 0 || burst_tw == 0)  // huh? that's no burst! but send SPI commands anyway
311
               tstate <= NextBurst;
312
             else begin
313
                tnpulses <= burst_np;
314
                ttimer <= burst_td;
315
                ttimer_load <= 1;
316
                tstate <= PulseOffStart;
317
             end
318
          end
319
          PulseOffStart: begin
320
             ttimer_load <= 0;
321
             tstate <= PulseOff;
322
          end
323
          PulseOff: begin
324
             if (ttimer_done) begin
325
                ttimer <= burst_tw;
326
                ttimer_load <= 1;
327
                gate <= src_en;
328
                pulse <= 1;
329
                tstate <= PulseOnStart;
330
             end
331
          end
332
          PulseOnStart: begin
333
             pulse <= 0;
334
             tnpulses <= tnpulses - 1;                  // decrement at start of pulse
335
             ttimer_load <= 0;
336
             tstate <= PulseOn;
337
          end
338
          PulseOn: begin
339
             if (ttimer_done) begin
340
                gate <= 0;
341
                if (tnpulses == 0)
342
                  tstate <= NextBurst;
343
                else begin
344
                   ttimer <= burst_tf;
345
                   ttimer_load <= 1;
346
                   tstate <= PulseOffStart;
347
                end
348
             end
349
          end
350
        endcase // case (tstate)
351
     end
352
 
353
   // meas state machine
354
   localparam MIdle = 3'd0, MArmed = 3'd1, MBurstStart =  3'd2, ConvForce = 3'd3, ConvWait =  3'd4,
355
     ConvDelay = 3'd5, ConvStart =  3'd6, ConvEnd =  3'd7;
356
   reg [2:0]             mstate = MIdle;
357
   reg [11:0]            mnpulses = 12'b0;
358
   reg [10:0]            maxpulses = 11'b0;
359
   reg [11:0]            mnskip = 12'b0;
360
   reg [14:0]            mtimer = 15'b0;
361
   reg                  mtimer_load = 1'b0;
362
   reg [14:0]            mtimer_count = 15'b0;
363
   reg [3:0]             mprescale = 4'd9;
364
   reg                  conv_force = 0;
365
   wire                 mtimer_done = (mtimer_count == 0);
366
   always @(posedge clk)
367
     if (mrst_en) begin
368
        mprescale <= 4'd9;
369
        mtimer_count <= 0;
370
     end
371
     else if (mtimer_load) begin
372
        mprescale <= 4'd7;
373
        mtimer_count <= mtimer;
374
     end
375
     else if (mtimer_count != 0)
376
       if (mprescale == 0) begin
377
          mprescale <= 4'd9;
378
          mtimer_count <= mtimer_count - 1;
379
       end
380
       else
381
         mprescale <= mprescale - 1;
382
 
383
   always @(posedge clk)
384
     if (mrst_en | mabt) begin
385
        conv_force <= 0;
386
        mstate <= MIdle;
387
        mtimer_load <= 0;
388
        conv_o <= 0;
389
     end
390
     else begin
391
        if (tctrl_CONV)
392
          conv_force <= 1;
393
        case (mstate)
394
          MIdle: begin
395
             conv_o <= 0;
396
             maxpulses <= mconf_MAX_COUNT;
397
             if (marm)
398
               mstate <= MArmed;
399
             else if (conv_force)
400
               mstate <= ConvForce;
401
          end
402
          MArmed: begin
403
             conv_o <= 0;
404
             if (burst_loaded)
405
                mstate <= MBurstStart;
406
             else if (conv_force)
407
               mstate <= ConvForce;
408
          end
409
          MBurstStart: begin
410
             if (burst_tc == 0)
411
               mstate <= MArmed;
412
             else begin
413
                mnpulses <= burst_tc;
414
                mnskip <= burst_tk;
415
                mstate <= ConvWait;
416
             end
417
          end
418
          ConvForce: begin      // force single conversion on TCTRL[CONV] write
419
             conv_force <= 0;
420
             maxpulses <= 1;
421
             mnpulses <= 1;
422
             mnskip <= 0;
423
             mtimer <= 4;
424
             mtimer_load <= 1;
425
             mstate <= ConvDelay;
426
          end
427
          ConvWait: begin
428
             conv_o <= 0;
429
             if (pulse)
430
               if (mnskip == 0) begin
431
                  mtimer <= burst_to;
432
                  mtimer_load <= 1;
433
                  mstate <= ConvDelay;
434
               end
435
               else
436
                 mnskip <= mnskip - 1;
437
          end
438
          ConvDelay: begin
439
             mtimer_load <= 0;
440
             mstate <= ConvStart;
441
          end
442
          ConvStart: begin
443
             if (mtimer_done) begin
444
                conv_o <= 1;
445
                mnpulses <= mnpulses - 1;
446
                maxpulses <= maxpulses - 1;
447
                mstate <= ConvEnd;
448
             end
449
          end
450
          ConvEnd: begin
451
             if (maxpulses == 0)
452
               mstate <= MIdle;
453
             else if (mnpulses == 0)
454
               mstate <= MArmed;
455
             else begin
456
                mnskip <= burst_ts;
457
                mstate <= ConvWait;
458
             end
459
          end
460
        endcase // case (mstate)
461
     end
462
 
463
   // ADC state machine
464
   localparam AIdle = 3'd0, ASckOn = 3'd1, ASckOnWait = 3'd2, ASckOff = 3'd3, ADone = 3'd4, ADone2 = 3'd5, SckOnStretch = 3'd2;
465
   reg [2:0]             astate = AIdle;
466
   reg [31:0]            adcf_dat = 32'b0;
467
   reg [31:0]            adcr_dat = 32'b0;
468
   reg [31:0]            adc_dat = 32'b0;
469
   reg [5:0]             acount = 6'b0;
470
   reg                  adc_dat_wr = 1'b0;
471
   reg [2:0]             sck_time = 3'b0;
472
 
473
   always @(posedge clk)
474
     if (mrst_en | mabt) begin
475
        astate <= AIdle;
476
        adc_dat_wr <= 0;
477
     end
478
     else begin
479
        case (astate)
480
          AIdle: begin
481
             adc_dat_wr <= 0;
482
             if (conv_o) begin
483
                acount <= 6'd34;
484
                astate <= ASckOn;
485
             end
486
          end
487
          ASckOn: begin
488
             adc_sck_o <= 1;
489
             acount <= acount - 1;
490
             sck_time <= SckOnStretch;
491
             astate <= ASckOnWait;
492
          end
493
          ASckOnWait: begin
494
             if (sck_time == 0)
495
                astate <= ASckOff;
496
             else
497
               sck_time <= sck_time - 1;
498
          end
499
          ASckOff: begin
500
             adc_sck_o <= 0;
501
             adcf_dat <= {adcf_dat[30:0], adcf_sdo_i};
502
             adcr_dat <= {adcr_dat[30:0], adcr_sdo_i};
503
             if (acount == 0)
504
               astate <= ADone;
505
             else
506
               astate <= ASckOn;
507
          end
508
          ADone: begin
509
             adc_dat <= {adcf_dat[15:2], 2'b0, adcf_dat[31:18], 2'b0};
510
             adc_dat_wr <= 1;                           // write ADCR data
511
             astate <= ADone2;
512
          end
513
          ADone2: begin
514
             adc_dat <= {adcr_dat[15:2], 2'b0, adcr_dat[31:18], 2'b0};
515
             adc_dat_wr <= 1;                           // write ADCF data
516
             astate <= AIdle;
517
          end
518
        endcase // case (astate)
519
     end
520
 
521
   // MQUEUE FIFO
522
   reg [12:0]            mcount = 13'b0;
523
   reg [11:0]            mrptr = 12'b0;
524
   reg [10:0]            mwptr = 11'b0;
525
   wire                 mfull = (mcount == 13'h1000);
526
   wire                 mempty = (mcount == 13'h0);
527
   wire                 mfifo_wr = adc_dat_wr & ~mfull;
528
   reg [3:0]             mfifo_rsel = 4'b0;
529
   reg [3:0]             mfifo_wsel = 4'b0;
530
   reg [15:0]            mqueue_dat_o = 16'b0;
531
   wire [4*16-1:0]       mfifo_dat_o;
532
 
533
   always @* begin
534
      mfifo_wsel = 4'b0;
535
      case (mwptr[10:9])
536
        2'd0: mfifo_wsel[0] = 1;
537
        2'd1: mfifo_wsel[1] = 1;
538
        2'd2: mfifo_wsel[2] = 1;
539
        2'd3: mfifo_wsel[3] = 1;
540
      endcase
541
   end
542
 
543
   always @* begin
544
      mfifo_rsel = 4'b0;
545
      case (mrptr[11:10])
546
        2'd0: begin
547
           mfifo_rsel[0] = 1;
548
           mqueue_dat_o = mfifo_dat_o[1*16-1 -: 16];
549
        end
550
        2'd1: begin
551
           mfifo_rsel[1] = 1;
552
           mqueue_dat_o = mfifo_dat_o[2*16-1 -: 16];
553
        end
554
        2'd2: begin
555
           mfifo_rsel[2] = 1;
556
           mqueue_dat_o = mfifo_dat_o[3*16-1 -: 16];
557
        end
558
        2'd3: begin
559
           mfifo_rsel[3] = 1;
560
           mqueue_dat_o = mfifo_dat_o[4*16-1 -: 16];
561
        end
562
      endcase
563
   end
564
 
565
   assign reg_r[`TG_MQ_STAT_INDEX] = {3'b0, mcount};
566
   assign reg_r[`TG_MQUEUE_INDEX] = mqueue_dat_o;
567
 
568
   reg                  mqueue_rd_dly = 1'b0;
569
   reg                  mqueue_rd_dly2 = 1'b0;
570
   wire                 mqueue_rd = ~mqueue_rd_dly & mqueue_rd_dly2 & ~mempty;
571
   assign test = 1'b0;
572
   always @(posedge clk) begin
573
      mqueue_rd_dly <= reg_ctl[`TG_MQUEUE_RD_INDEX];
574
      mqueue_rd_dly2 <= mqueue_rd_dly;
575
   end
576
 
577
   always @(posedge clk) begin
578
      if (mrst) begin
579
         mcount <= 0;
580
         mrptr <= 0;
581
         mwptr <= 0;
582
         mhalf <= 0;
583
      end
584
      else begin
585
         mhalf <= (mcount >= 13'h800);
586
         if (mqueue_rd)
587
           mrptr <= mrptr + 1;
588
         if (mfifo_wr)
589
           mwptr <= mwptr + 1;
590
         if (mfifo_wr & ~mqueue_rd)                     // write 2 words, no read
591
           mcount <= mcount + 2;
592
         else if (mfifo_wr & mqueue_rd)                 // write 2 words, read 1 word
593
           mcount <= mcount + 1;
594
         else if (~mfifo_wr & mqueue_rd)                // no write, read 1 word
595
           mcount <= mcount - 1;
596
      end
597
   end
598
 
599
   RAMB16_S18_S36 mfifo[3:0] (.DOA(mfifo_dat_o), .ADDRA(mrptr[9:0]), .CLKA(clk), .ENA(mfifo_rsel), .WEA(1'b0),
600
                              .DIA(16'b0), .DIPA(2'b0), .SSRA(1'b0), .ADDRB(mwptr[8:0]), .CLKB(clk),
601
                              .ENB(mfifo_wsel), .WEB({4{mfifo_wr}}), .DIB(adc_dat), .DIPB(4'b0), .SSRB(1'b0));
602
 
603
   tg_registers tg_reg (.clk_i(clk200), .rst_i(rst_i), .adr_i(adr_i), .dat_i(dat_i), .we_i(we_i),.oe_i(oe_i),
604
                        .cs_i(cs_i), .dat_o(dat_o), .reg_w(reg_w), .reg_r(reg_r), .reg_ctl(reg_ctl));
605
 
606
endmodule

powered by: WebSVN 2.1.0

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