summaryrefslogtreecommitdiff
path: root/ReferenceCode/Chipset/SystemAgent/MemoryInit/Pei/Source/WriteTraining/MrcWriteDqDqs.c
blob: 49b35e4766cdea5989f7cc5b65694e140b88fa4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
/** @file
  The third stage of the write training is determining the PI setting for
  each byte strobe to make sure that data is sent at the optimal location.
  In order to do that a pattern of alternating zeros and ones is written to
  a block of the memory, and then read out.  By identifying the location
  where it is farthest away from where errors are shown the DQS will be
  aligned to the center of the eye.

@copyright
  Copyright (c) 1999 - 2012 Intel Corporation. All rights reserved
  This software and associated documentation (if any) is furnished
  under a license and may only be used or copied in accordance
  with the terms of the license. Except as permitted by such
  license, no part of this software or documentation may be
  reproduced, stored in a retrieval system, or transmitted in any
  form or by any means without the express written consent of
  Intel Corporation.

  This file contains an 'Intel Peripheral Driver' and uniquely
  identified as "Intel Reference Module" and is
  licensed for Intel CPUs and chipsets under the terms of your
  license agreement with Intel or your vendor.  This file may
  be modified by the user, subject to additional terms of the
  license agreement.

**/

//
// Include files
//
#include "MrcWriteDqDqs.h"

/**
@brief
  this function executes the write timing centering.
  Center Tx DQS-DQ using moderate pattern with 1D eye.

  @param[in] MrcData         - Include all MRC global data.

  @retval MrcStatus      - if it succeded returns mrcSuccess
**/
MrcStatus
MrcWriteTimingCentering (
  IN     MrcParameters *const MrcData
  )
{
  MrcOutput *Outputs;
  U8        ResetPerbit;
  U8        LoopCount;

  Outputs = &MrcData->SysOut.Outputs;
  ResetPerbit = 1;

  LoopCount   = 10;

  return DQTimeCentering1D (MrcData, Outputs->ValidChBitMask, WrT, ResetPerbit, LoopCount);
}

/**
  @brief
  this function executes the write timing centering in 2D.
    Final write timing centering using 2D algorithm and per bit optimization.

    @param[in] MrcData - Include all MRC global data.

    @retval MrcStatus -  if it succeded returns mrcSuccess

  **/
MrcStatus
MrcWriteTimingCentering2D (
  IN     MrcParameters *const MrcData
  )
{
  const MrcDebug  *Debug;
  MrcOutput       *Outputs;
  MrcStatus       Status;
  U8              EnPerBit;
  U8              EnRxDutyCycle;
  U8              ResetPerBit;
  U8              LoopCount;
  U8              En2D;

  Debug         = &MrcData->SysIn.Inputs.Debug;
  Outputs       = &MrcData->SysOut.Outputs;
  EnPerBit      = 1;
  EnRxDutyCycle = 0;
  ResetPerBit   = 1;
  LoopCount     = 15;
  En2D          = 0;

  MRC_DEBUG_MSG (
    Debug,
    MSG_LEVEL_NOTE,
    "\n\nCalling with EnRxDutyCycle = %d, EnPerBit = %d, ResetPerBit = %d En2D = %d\n",
    EnRxDutyCycle,
    EnPerBit,
    ResetPerBit,
    En2D
    );

  Status = DataTimeCentering2D (
            MrcData,
            Outputs->MarginResult,
            Outputs->ValidChBitMask,
            WrT,
            EnPerBit,
            EnRxDutyCycle,
            ResetPerBit,
            LoopCount,
            En2D
            );

  if (mrcSuccess == Status) {
    EnPerBit    = 0;
    ResetPerBit = 0;
    En2D        = 1;
    MRC_DEBUG_MSG (
      Debug,
      MSG_LEVEL_NOTE,
      "\n\nCalling with EnRxDutyCycle = %d, EnPerBit = %d, ResetPerBit = %d En2D = %d\n",
      EnRxDutyCycle,
      EnPerBit,
      ResetPerBit,
      En2D
      );

    Status = DataTimeCentering2D (
              MrcData,
              Outputs->MarginResult,
              Outputs->ValidChBitMask,
              WrT,
              EnPerBit,
              EnRxDutyCycle,
              ResetPerBit,
              LoopCount,
              En2D
              );
  }

  return Status;
}

/**
@brief
  Rank Margin Tool - Measure margins across various parameters

  @param[in, out] MrcData - Include all MRC global data.

  @retval MrcStatus -  mrcSuccess if succeded
**/
MrcStatus
MrcRankMarginTool (
  IN OUT MrcParameters *const MrcData
  )
{
  const U16                           mode = 0;
  const MrcInput                      *Inputs;
  const MrcDebug                      *Debug;
  MrcOutput                           *Outputs;
  MrcControllerOut                    *ControllerOut;
  MrcChannelOut                       *ChannelOut;
  MrcCommandMargin                    *CommandOut;
  MrcRecvEnMargin                     *RecvEnOut;
  MrcWrLevelMargin                    *WrLevelOut;
  MrcStatus                           Status;
  U32                                 BERStats[4];
  U32                                 Offset;
  U8                                  Rank;
  U8                                  Param;
  U8                                  RankMask;
  U8                                  Controller;
  U8                                  Channel;
  U8                                  byte;
  U8                                  bit;
  U8                                  chBitMask;
  U8                                  MaxMargin;
  U8                                  DqLoopCount;
  U8                                  CmdLoopCount;
  S8                                  VrefOffsets[2];
  BOOL                                Lpddr;
  BOOL                                SkipVref;
  BOOL                                SkipPrint;
  MrcPower                            PwrChRank[MAX_CHANNEL][MAX_RANK_IN_CHANNEL];
  Inputs  = &MrcData->SysIn.Inputs;
  Debug   = &Inputs->Debug;
  Outputs = &MrcData->SysOut.Outputs;
  Status  = mrcSuccess;
  MrcOemMemorySet ((U8 *) BERStats, 0, sizeof (BERStats));
  MrcOemMemorySet ((U8 *) VrefOffsets, 0, sizeof (VrefOffsets));
  MrcOemMemorySet ((U8 *) PwrChRank, 0, sizeof (PwrChRank));

  //
  // Check if LPDDR3 memory is used
  //
  Lpddr = (Outputs->DdrType == MRC_DDR_TYPE_LPDDR3);


  DqLoopCount = 17;
  CmdLoopCount = (Lpddr) ? 10 : 17;

  MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "Rank Margin Testing: DQ LC = %d, Cmd LC = %d\n\n", DqLoopCount, CmdLoopCount);
  MRC_DEBUG_MSG (
    Debug,
    MSG_LEVEL_NOTE,
    "Margin\nParams: RcvEna\tWrLevel\tRdT\tWrT\tRdV\tWrV\tCmdT\tCmdV\tDimmPwr\tCpuPwr\tTotPwr\n"
    );
  MRC_DEBUG_MSG (
    Debug,
    MSG_LEVEL_NOTE,
    "\tLft Rgt Lft Rgt Lft Rgt Lft Rgt Low Hi  Low Hi  Lft Rgt Low Hi\t[mW]\t[mW]\t[mW]\n"
    );
  for (Rank = 0; Rank < MAX_RANK_IN_CHANNEL; Rank++) {
    //
    // Select rank for REUT test
    //
    RankMask  = 1 << Rank;
    chBitMask = 0;
    for (Channel = 0; Channel < MAX_CHANNEL; Channel++) {
      chBitMask |= SelectReutRanks (MrcData, Channel, RankMask, 0);
      if ((MRC_BIT0 << Channel) & chBitMask) {
        ChannelOut = &Outputs->Controller[0].Channel[Channel];
        //
        // Clear any old state in DataOffsetTrain
        //
        MrcOemMemorySetDword (&ChannelOut->DataOffsetTrain[0], 0, Outputs->SdramCount);
      }
    }
    //
    // Continue with next rank if this rank is not present on any channel
    //
    if (!(chBitMask)) {
      continue;
    }
    //
    // Setup Test
    // SOE=1, EnCADB=0, EnCKE=0 SOE=1 sets bit12 of REUT_CH_ERR_CTL
    //
    SetupIOTestBasicVA (MrcData, chBitMask, DqLoopCount, NSOE, 0, 0, 8);
    for (Param = RcvEna; Param <= WrLevel; Param++) {
      if (Param == WrDqsT) {
        continue;
      }

      //
      // For Write/Read timing margining, we want to run traffic with Rd->Rd turnaround times of 4 and 5.
      // This statement depends on the order of MRC_MarginTypes.  If this enum's order changes, this
      // statement must change.
      //
      if (Param == RdT) {
        Outputs->DQPat = RdRdTA;
      } else if (Param == RdV) {
        Outputs->DQPat = BasicVA;
      }

      MaxMargin = ((Param == RdV) || (Param == WrV)) ? MAX_POSSIBLE_VREF : MAX_POSSIBLE_TIME;

      //
      // Run test for different Params
      //
      Status = MrcGetBERMarginCh (
                MrcData,
                Outputs->MarginResult,
                chBitMask,
                0xFF,
                Rank,
                Param,
                mode,
                1,
                MaxMargin,
                0,
                BERStats
                );
    }

    //
    // Use CADB test for Cmd to match Late Command Training
    //
    SetupIOTestCADB (MrcData, chBitMask, CmdLoopCount, NSOE, 1, 0);

    //
    // Run test for Cmd Timing
    //
    SkipVref  = TRUE;
    SkipPrint = TRUE;

#ifdef ULT_FLAG
    if (Lpddr) {
      CmdLinearFindEdgesLpddr (MrcData, MrcIterationClock, chBitMask, RankMask, !SkipPrint);
    } else
#endif // ULT_FLAG
    {
      CmdLinearFindEdges (
        MrcData,
        MrcIterationClock,
        chBitMask,
        0xFF,
        3,
        -64,
        64,
        1,
        VrefOffsets,
        SkipPrint,
        SkipVref
        );
    }

    //
    // Restore centered value
    //
    for (Channel = 0; Channel < MAX_CHANNEL; Channel++) {
      ShiftPIforCmdTraining (MrcData, Channel, MrcIterationClock, 0xFF, 3, 0, 0);
    }

    Status = MrcResetSequence (MrcData);

    //
    // Run test for Cmd Voltage
    //
    Status = MrcGetBERMarginCh (
              MrcData,
              Outputs->MarginResult,
              chBitMask,
              0xFF,
              Rank,
              CmdV,
              mode,
              0,
              MAX_POSSIBLE_VREF,
              0,
              BERStats
              );
    Status = MrcResetSequence (MrcData);

    CalcSysPower(MrcData, PwrChRank);

#ifdef MRC_DEBUG_PRINT
    //
    // Print test results
    //
    for (Channel = 0; Channel < MAX_CHANNEL; Channel++) {
      if (MrcRankInChannelExist (MrcData, Rank, Channel)) {
        MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "C%dR%d:\t", Channel, Rank);
        MRC_DEBUG_MSG (
          Debug,
          MSG_LEVEL_NOTE,
          "%2d  %2d\t%2d  %2d\t%2d  %2d\t%2d  %2d\t%2d  %2d\t%2d  %2d\t%2d  %2d\t%2d  %2d\t%2d.%d\t%2d.%d\t%2d.%d\n",
          Outputs->MarginResult[LastRcvEna][Rank][Channel][0][0] / 10,
          Outputs->MarginResult[LastRcvEna][Rank][Channel][0][1] / 10,
          Outputs->MarginResult[LastWrLevel][Rank][Channel][0][0] / 10,
          Outputs->MarginResult[LastWrLevel][Rank][Channel][0][1] / 10,
          Outputs->MarginResult[LastRxT][Rank][Channel][0][0] / 10,
          Outputs->MarginResult[LastRxT][Rank][Channel][0][1] / 10,
          Outputs->MarginResult[LastTxT][Rank][Channel][0][0] / 10,
          Outputs->MarginResult[LastTxT][Rank][Channel][0][1] / 10,
          Outputs->MarginResult[LastRxV][Rank][Channel][0][0] / 10,
          Outputs->MarginResult[LastRxV][Rank][Channel][0][1] / 10,
          Outputs->MarginResult[LastTxV][Rank][Channel][0][0] / 10,
          Outputs->MarginResult[LastTxV][Rank][Channel][0][1] / 10,
          Outputs->MarginResult[LastCmdT][Rank][Channel][0][0] / 10,
          Outputs->MarginResult[LastCmdT][Rank][Channel][0][1] / 10,
          Outputs->MarginResult[LastCmdV][Rank][Channel][0][0] / 10,
          Outputs->MarginResult[LastCmdV][Rank][Channel][0][1] / 10,
          PwrChRank[Channel][Rank].DimmPwr / 10,
          PwrChRank[Channel][Rank].DimmPwr % 10,
          PwrChRank[Channel][Rank].CpuPower / 10,
          PwrChRank[Channel][Rank].CpuPower % 10,
          PwrChRank[Channel][Rank].TotPwr / 10,
          PwrChRank[Channel][Rank].TotPwr % 10
          );
      }
    }
#endif
    for (Controller = 0; Controller < MAX_CONTROLLERS; Controller++) {
      ControllerOut = &Outputs->Controller[Controller];
      for (Channel = 0; Channel < MAX_CHANNEL; Channel++) {
        if (MrcRankInChannelExist (MrcData, Rank, Channel)) {
          ChannelOut        = &ControllerOut->Channel[Channel];
          CommandOut        = &ChannelOut->Command[Rank];
          CommandOut->Left  = (U8) (Outputs->MarginResult[LastCmdT][Rank][Channel][0][0] / 10);
          CommandOut->Right = (U8) (Outputs->MarginResult[LastCmdT][Rank][Channel][0][1] / 10);
          CommandOut->Low   = (U8) (Outputs->MarginResult[LastCmdV][Rank][Channel][0][0] / 10);
          CommandOut->High  = (U8) (Outputs->MarginResult[LastCmdV][Rank][Channel][0][1] / 10);
          RecvEnOut         = &ChannelOut->ReceiveEnable[Rank];
          RecvEnOut->Left   = (U8) (Outputs->MarginResult[LastRcvEna][Rank][Channel][0][0] / 10);
          RecvEnOut->Right  = (U8) (Outputs->MarginResult[LastRcvEna][Rank][Channel][0][1] / 10);
          WrLevelOut        = &ChannelOut->WriteLevel[Rank];
          WrLevelOut->Left  = (U8) (Outputs->MarginResult[LastWrLevel][Rank][Channel][0][0] / 10);
          WrLevelOut->Right = (U8) (Outputs->MarginResult[LastWrLevel][Rank][Channel][0][1] / 10);
          for (byte = 0; byte < Outputs->SdramCount; byte++) {
            for (bit = 0; bit < MAX_BITS; bit++) {
              ChannelOut->RxDqPb[Rank][byte][bit].Left      = (U8) (Outputs->MarginResult[LastRxT][Rank][Channel][0][0] / 10);
              ChannelOut->RxDqPb[Rank][byte][bit].Right     = (U8) (Outputs->MarginResult[LastRxT][Rank][Channel][0][1] / 10);
              ChannelOut->TxDqPb[Rank][byte][bit].Left      = (U8) (Outputs->MarginResult[LastTxT][Rank][Channel][0][0] / 10);
              ChannelOut->TxDqPb[Rank][byte][bit].Right     = (U8) (Outputs->MarginResult[LastTxT][Rank][Channel][0][1] / 10);
              ChannelOut->RxDqVrefPb[Rank][byte][bit].Low   = (U8) (Outputs->MarginResult[LastRxV][Rank][Channel][0][0] / 10);
              ChannelOut->RxDqVrefPb[Rank][byte][bit].High  = (U8) (Outputs->MarginResult[LastRxV][Rank][Channel][0][1] / 10);
              ChannelOut->TxDqVrefPb[Rank][byte][bit].Low   = (U8) (Outputs->MarginResult[LastTxV][Rank][Channel][0][0] / 10);
              ChannelOut->TxDqVrefPb[Rank][byte][bit].High  = (U8) (Outputs->MarginResult[LastTxV][Rank][Channel][0][1] / 10);
            }
          }
        }
      }
    }
  } // for Rank

  //
  // Disable CADB Deselects after RMT
  //
  for (Channel = 0; Channel < MAX_CHANNEL; Channel++) {
    if (MrcChannelExist (Outputs, Channel)) {
      Offset = MCHBAR_CH0_CR_REUT_CH_PAT_CADB_CTRL_REG +
        ((MCHBAR_CH1_CR_REUT_CH_PAT_CADB_CTRL_REG - MCHBAR_CH0_CR_REUT_CH_PAT_CADB_CTRL_REG) * Channel);
      MrcWriteCR8 (MrcData, Offset, 0);
    }
  }
  return Status;
}

/**
@brief
  Peform Read Voltage Centering in 2D.
  Note: This function currently only supports param = WrV

  @param[in, out] MrcData       - Include all MRC global data.

  @retval MrcStatus -    if t succeded return mrcSuccess
  @todo - Need option for loopcount
**/
MrcStatus
MrcWriteVoltageCentering2D (
  IN OUT MrcParameters *const MrcData
  )
{
  const MrcDebug  *Debug;
  const MrcInput  *Inputs;
  MrcOutput       *Outputs;
  MrcChannelOut   *ChannelOut;
  MrcStatus       Status;
  U32 (*marginch)[MAX_RESULT_TYPE][MAX_RANK_IN_CHANNEL][MAX_CHANNEL][MAX_SDRAM_IN_DIMM][MAX_EDGES];

  U8  ResultType;
  U8  ResultTypeT;
  U8  loopcount;
  U8  param;
  U8  paramT;
  U8  Channel;
  U8  byte;
  U8  tim;
  U8  chBitMask;
  U8  MaxTscale;
  U8  SkipWait;
  S8  SumEH;
  S8  SumEHSign;
  S8  TimePoints[3];
  U8  EHWeights[sizeof (TimePoints)];
  U16 mode;
  S32 center;
  S32 height;
  U32 value0[MAX_CHANNEL];
  U32 BERStats[4];
  U32 TimScale[MAX_CHANNEL];
  S32 centersum[MAX_CHANNEL];

  Inputs    = &MrcData->SysIn.Inputs;
  Outputs   = &MrcData->SysOut.Outputs;
  Debug     = &Inputs->Debug;
  marginch  = &Outputs->MarginResult;
  Status    = mrcSuccess;
  loopcount = 17;
  MaxTscale = 12;
  SumEH     = 0;
  MrcOemMemorySet ((U8 *) BERStats, 0, sizeof (BERStats));
  MrcOemMemorySet ((U8 *) EHWeights, 1, sizeof (EHWeights));
  TimePoints[0] = -4;
  TimePoints[1] = 0;
  TimePoints[2] = 4;

  //
  // No input for param so set it to RdV
  //
  param = WrV;

  //
  // Assume rank0 is always popuplated
  //
  if (param == WrV) {
    paramT = WrT;
  } else {
    MRC_DEBUG_MSG (Debug, MSG_LEVEL_ERROR, "Error Handler: Unknown Margin Parameter\n");
    Status = mrcFail;
    return Status;
  }

  ResultType  = GetMarginResultType (param);
  ResultTypeT = GetMarginResultType (paramT);

  //
  /// @todo: Need to check if we can enable it for A0 or not
  // Outputs->EnDumRd = 1;
  // SOE = 00b(No Stop on error), EnCADB=0, EnCKE=0
  //
  //
  /// @todo: Will enable the DQ tests instead of basic in the future
  //  SetupIOTestDQ (MrcData,Outputs->ValidChBitMask, loopcount, NSOE, 0, 0);
  //
  SetupIOTestBasicVA (MrcData, Outputs->ValidChBitMask, loopcount, NSOE, 0, 0, 8);

  //
  // Calculate SumEH for use in weighting equations
  //
  for (tim = 0; tim < sizeof (TimePoints); tim++) {
    SumEH += EHWeights[tim];
  }
  //
  // Select rank for REUT test
  //
  chBitMask = 0;
  for (Channel = 0; Channel < MAX_CHANNEL; Channel++) {
    if (!MrcChannelExist (Outputs, Channel)) {
      continue;
    }

    ChannelOut = &Outputs->Controller[0].Channel[Channel];
    chBitMask |= SelectReutRanks (MrcData, Channel, ChannelOut->ValidRankBitMask, 0);

    //
    // Clear any old state in DataTrain Offset
    //
    MrcOemMemorySetDword (&ChannelOut->DataOffsetTrain[0], 0, Outputs->SdramCount);
  }
  //
  // ####################################################
  // #############  Initialize EW/EH variables   ########
  // ####################################################
  //
  Status = GetMarginCh (MrcData, Outputs->MarginResult, paramT, 0xF);

  //
  // Update TimScale with results
  //
  for (Channel = 0; Channel < MAX_CHANNEL; Channel++) {
    TimScale[Channel] = 0;
    if (!(chBitMask & (1 << Channel))) {
      continue;
    }

    TimScale[Channel] = ((*marginch)[ResultTypeT][0][Channel][0][0] + (*marginch)[ResultTypeT][0][Channel][0][1]) / 20;
    //
    // It is possible TimScale[Channel] is 0.
    //
    if (!TimScale[Channel] || (TimScale[Channel] > MaxTscale)) {
      TimScale[Channel] = MaxTscale;
    }
  }

  Status = GetMarginCh (MrcData, Outputs->MarginResult, param, 0xF);

  //
  // ####################################################
  // ######   Measure Eye Height at all Timing Points  #####
  // ####################################################
  //
  MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "TimScale{0] is %d, TimScale{1] is %d\n", TimScale[0], TimScale[1]);
  MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "Channel\t0\t\t\t\t1\n");

  for (Channel = 0; Channel < MAX_CHANNEL; Channel++) {
    MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "WrTime\tLow\tHigh\tHeight\tCenter\t");
  }
  //
  // Initialize parameters to 0
  //
  for (Channel = 0; Channel < MAX_CHANNEL; Channel++) {
    centersum[Channel] = 0;
    value0[Channel]    = 0;
  }
  //
  // Loop through all the Time Points to Test
  //
  for (tim = 0; tim < sizeof (TimePoints); tim++) {
    //
    // Setup Timing Offset for this point
    //
    for (Channel = 0; Channel < MAX_CHANNEL; Channel++) {
      if (!(chBitMask & (1 << Channel))) {
        continue;
      }

      value0[Channel] = (S32) (TimePoints[tim] * TimScale[Channel]) / MaxTscale;

      //
      // There is no multicast per channel...
      //
      for (byte = 0; byte < Outputs->SdramCount; byte++) {
        Status = ChangeMargin (MrcData, paramT, value0[Channel], 0, 0, Channel, 0, byte, 0, 1, 0, MrcRegFileStart);
      }
    }
    //
    // Run Margin Test
    //
    mode = 0;
    Status = MrcGetBERMarginCh (
              MrcData,
              Outputs->MarginResult,
              chBitMask,
              0xFF,
              0,
              param,
              mode,
              1,
              MAX_POSSIBLE_VREF,
              0,
              BERStats
              );

    //
    // Store Results
    //
    MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "\n");
    for (Channel = 0; Channel < MAX_CHANNEL; Channel++) {
      if (!(chBitMask & (1 << Channel))) {
        MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "\t\t\t\t\t");
        continue;
      }

      MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "%d\t", value0[Channel]);

      height  = ((*marginch)[ResultType][0][Channel][0][1] + (*marginch)[ResultType][0][Channel][0][0]) / 10;
      center  = (S32) ((*marginch)[ResultType][0][Channel][0][1] - (*marginch)[ResultType][0][Channel][0][0]);
      MRC_DEBUG_MSG (
        Debug,
        MSG_LEVEL_NOTE,
        "%d\t%d\t%d\t%d\t",
        (*marginch)[ResultType][0][Channel][0][0] / 10,
        (*marginch)[ResultType][0][Channel][0][1] / 10,
        height,
        center / 20
        );
      if (tim == 0) {
        centersum[Channel] = 0;
      }
      //
      // Calculate weight for this point
      //
      centersum[Channel] += EHWeights[tim] * center;
      //
      // MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "+----->centersum[%d] = %d, \n", Channel, centersum[Channel]);
      //
    }
  }

  MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "\nWtdCntr\t");
  //
  // ####################################################
  // ###########   Center Results per Ch    #############
  // ####################################################
  //
  for (Channel = 0; Channel < MAX_CHANNEL; Channel++) {
    if (!(chBitMask & (1 << Channel))) {
      MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "\t\t\t\t\t");
      continue;
    }

    ChannelOut = &Outputs->Controller[0].Channel[Channel];

    //
    // Calculate CenterPoint.  Round to Nearest Int
    //
    SumEHSign           = (centersum[Channel] < 0) ? (-1) : 1;

    centersum[Channel]  = (centersum[Channel] + 10 * SumEH * SumEHSign) / (20 * SumEH);

    //
    // Apply new centerpoint
    // Only Byte 7 on Channel 1 is needed to update DIMM Vref
    // Skip if there are more channels
    //
    SkipWait = (chBitMask >> (Channel + 1));
    Status = ChangeMargin (MrcData, param, centersum[Channel], 0, 0, Channel, 0, 7, 0, 1, SkipWait, MrcRegFileCurrent);

    MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "%d\t\t\t\t", centersum[Channel]);

    //
    // Update MrcData for future tests
    //
    (*marginch)[ResultType][0][Channel][0][0] = (S32) ((*marginch)[ResultType][0][Channel][0][0]) + (10 * (centersum[Channel]));
    (*marginch)[ResultType][0][Channel][0][1] = (S32) ((*marginch)[ResultType][0][Channel][0][1]) - (10 * (centersum[Channel]));

    //
    // Clean up after test
    //
    MrcOemMemorySetDword (&ChannelOut->DataOffsetTrain[0], 0, Outputs->SdramCount);
  }

  MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "\n");

  //
  // Clean up
  //
  Status            = ChangeMargin (MrcData, paramT, 0, 0, 1, 0, 0, 0, 0, 1, 0, MrcRegFileCurrent);

  Outputs->EnDumRd  = 0;
  return Status;
}