summaryrefslogtreecommitdiffstats
path: root/src/occ_405/pss/apss.c
blob: d530b7e39cfe40c4175684b9ebfd22d69fa549fa (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
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/occ_405/pss/apss.c $                                      */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,2015                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

#include "ssx.h"

#include <occhw_async.h>
#include <trac_interface.h>
#include <apss.h>
#include <occ_common.h>
#include <comp_ids.h>
#include <pss_service_codes.h>
#include <occ_service_codes.h>
#include <trac.h>
#include <state.h>
#include <occ_sys_config.h>
#include <dcom.h>
#include "pss_constants.h"

// Threshold for calling out the redundant APSS
#define MAX_BACKUP_FAILURES  8

// Configure both GPIOs (directoin/drive/interrupts): All Input, All 1's, No Interrupts
const apssGpioConfigStruct_t G_gpio_config[2] = { {0x00, 0xFF, 0x00}, {0x00, 0xFF, 0x00} };

// Configure streaming of: 16 ADCs, 2 GPIOs
const apssCompositeConfigStruct_t G_apss_composite_config = { 16, 2 };

// Power Measurements (read from APSS every RealTime loop)
apssPwrMeasStruct_t G_apss_pwr_meas = { {0} };

GPE_BUFFER(initGpioArgs_t G_gpe_apss_initialize_gpio_args);
GPE_BUFFER(setCompositeModeArgs_t G_gpe_apss_set_composite_mode_args);

uint64_t G_gpe_apss_time_start;
uint64_t G_gpe_apss_time_end;

// Flag for requesting APSS recovery when OCC detects all zeroes or data out of sync
bool G_apss_recovery_requested = FALSE;

GPE_BUFFER(apss_start_args_t    G_gpe_start_pwr_meas_read_args);
GPE_BUFFER(apss_continue_args_t G_gpe_continue_pwr_meas_read_args);
GPE_BUFFER(apss_complete_args_t G_gpe_complete_pwr_meas_read_args);

// TEMP -- NO MORE PORE
//PoreEntryPoint GPE_apss_start_pwr_meas_read;
//PoreEntryPoint GPE_apss_continue_pwr_meas_read;
//PoreEntryPoint GPE_apss_complete_pwr_meas_read;

// Up / down counter for redundant apss failures
uint32_t G_backup_fail_count = 0;

// Used to tell slave inbox that pwr meas is complete
volatile bool G_ApssPwrMeasCompleted = FALSE;

// Function Specification
//
// Name: dumpHexString
//
// Description: TODO Add description
//
// End Function Specification
#if ( (!defined(NO_TRAC_STRINGS)) && defined(TRAC_TO_SIMICS) )

// Utility function to dump hex data to screen
void dumpHexString(const void *i_data, const unsigned int len, const char *string)
{
  unsigned int i, j;
  char text[17];
  uint8_t *data = (uint8_t*)i_data;
  unsigned int l_len = len;

  text[16] = '\0';
  if (string != NULL)
  {
    printf("%s\n", string);
  }

  if (len > 0x0800) l_len = 0x800;
  for(i = 0; i < l_len; i++)
  {
    if (i % 16 == 0)
    {
      if (i > 0) printf("   \"%s\"\n", text);
      printf("   %04x:",i);
    }
    if (i % 4 == 0) printf(" ");

    printf("%02x",(int)data[i]);
    if (isprint(data[i])) text[i%16] = data[i];
    else text[i%16] = '.';
  }
  if ((i%16) != 0) {
    text[i%16] = '\0';
    for(j = (i % 16); j < 16; ++j) {
      printf("  ");
      if (j % 4 == 0) printf(" ");
    }
  }
  printf("   \"%s\"\n", text);
  return;
}
#endif

// Function Specification
//
// Name: do_apss_recovery
//
// Description: Collect FFDC and attempt recovery for APSS failures
//
// End Function Specification
void do_apss_recovery(void)
{
#define PSS_START_COMMAND 0x8000000000000000ull
#define PSS_RESET_COMMAND 0x4000000000000000ull
    int             l_scom_rc           = 0;
    uint32_t        l_scom_addr;
    uint64_t        l_spi_adc_ctrl0;
    uint64_t        l_spi_adc_ctrl1;
    uint64_t        l_spi_adc_ctrl2;
    uint64_t        l_spi_adc_status;
    uint64_t        l_spi_adc_reset;
    uint64_t        l_spi_adc_wdata;


    TRAC_ERR("detected invalid power data[%08x%08x]",
             (uint32_t)(G_gpe_continue_pwr_meas_read_args.meas_data[0] >> 32),
             (uint32_t)(G_gpe_continue_pwr_meas_read_args.meas_data[0] & 0x00000000ffffffffull));

    do
    {
        // Collect SPI ADC FFDC data
        l_scom_addr = SPIPSS_ADC_RESET_REG;
        l_scom_rc = _getscom(l_scom_addr, &l_spi_adc_reset, SCOM_TIMEOUT);
        if(l_scom_rc)
        {
            break;
        }
        l_scom_addr = SPIPSS_ADC_CTRL_REG0;
        l_scom_rc = _getscom(l_scom_addr, &l_spi_adc_ctrl0, SCOM_TIMEOUT);
        if(l_scom_rc)
        {
            break;
        }
        l_scom_addr = SPIPSS_ADC_CTRL_REG1;
        l_scom_rc = _getscom(l_scom_addr, &l_spi_adc_ctrl1, SCOM_TIMEOUT);
        if(l_scom_rc)
        {
            break;
        }
        l_scom_addr = SPIPSS_ADC_CTRL_REG2;
        l_scom_rc = _getscom(l_scom_addr, &l_spi_adc_ctrl2, SCOM_TIMEOUT);
        if(l_scom_rc)
        {
            break;
        }
        l_scom_addr = SPIPSS_ADC_STATUS_REG;
        l_scom_rc = _getscom(l_scom_addr, &l_spi_adc_status, SCOM_TIMEOUT);
        if(l_scom_rc)
        {
            break;
        }
        l_scom_addr = SPIPSS_ADC_WDATA_REG;
        l_scom_rc = _getscom(l_scom_addr, &l_spi_adc_wdata, SCOM_TIMEOUT);
        if(l_scom_rc)
        {
            break;
        }

/* TEMP -- UNRESOLVED TRACE ERRORS
        TRAC_ERR("70000[%08x] 70001[%08x] 70002[%08x] 70003|70005[%08x] 70010[%08x]",
                (uint32_t)(l_spi_adc_ctrl0 >> 32),
                (uint32_t)(l_spi_adc_ctrl1 >> 32),
                (uint32_t)(l_spi_adc_ctrl2 >> 32),
                (uint32_t)((l_spi_adc_status >> 32) | (l_spi_adc_reset >> 48)), // Stuff reset register in lower 16 bits
                (uint32_t)(l_spi_adc_wdata >> 32));
*/
        // Special error handling on OCC backup. Keep an up/down counter of
        // fail/success and log predictive error when we reach the limit.
//        if(G_occ_role == OCC_SLAVE)
// TEMP -- IN PHASE 1 WE ARE ALWAYS MASTER
        if (FALSE)
        {
            if(G_backup_fail_count < MAX_BACKUP_FAILURES)
            {
                // Increment the up/down counter
                G_backup_fail_count++;
            }
            else
            {
                //We're logging the error so stop running apss tasks
                rtl_stop_task(TASK_ID_APSS_START);
                rtl_stop_task(TASK_ID_APSS_CONT);
                rtl_stop_task(TASK_ID_APSS_DONE);

                TRAC_INFO("Redundant APSS has exceeded failure threshold.  Logging Error");

                /*
                 * @errortype
                 * @moduleid    PSS_MID_DO_APSS_RECOVERY
                 * @reasoncode  REDUNDANT_APSS_GPE_FAILURE
                 * @userdata1   0
                 * @userdata2   0
                 * @userdata4   OCC_NO_EXTENDED_RC
                 * @devdesc     Redundant APSS failure.  Power Management Redundancy Lost.
                 */
                errlHndl_t l_err = createErrl(PSS_MID_DO_APSS_RECOVERY,
                                              REDUNDANT_APSS_GPE_FAILURE,
                                              OCC_NO_EXTENDED_RC,
                                              ERRL_SEV_PREDICTIVE,
                                              NULL,
                                              DEFAULT_TRACE_SIZE,
                                              0,
                                              0);

                // APSS callout
                addCalloutToErrl(l_err,
                                 ERRL_CALLOUT_TYPE_HUID,
                                 G_sysConfigData.apss_huid,
                                 ERRL_CALLOUT_PRIORITY_HIGH);
                // Processor callout
                addCalloutToErrl(l_err,
                                 ERRL_CALLOUT_TYPE_HUID,
                                 G_sysConfigData.proc_huid,
                                 ERRL_CALLOUT_PRIORITY_LOW);
                // Backplane callout
                addCalloutToErrl(l_err,
                                 ERRL_CALLOUT_TYPE_HUID,
                                 G_sysConfigData.backplane_huid,
                                 ERRL_CALLOUT_PRIORITY_LOW);
                // Firmware callout
                addCalloutToErrl(l_err,
                                 ERRL_CALLOUT_TYPE_COMPONENT_ID,
                                 ERRL_COMPONENT_ID_FIRMWARE,
                                 ERRL_CALLOUT_PRIORITY_MED);

                commitErrl(&l_err);

                break;
            }
        }

        TRAC_INFO("Starting APSS recovery.  fail_count=%d", G_backup_fail_count);

        // Reset the ADC engine
        l_scom_addr = SPIPSS_ADC_RESET_REG;
        l_scom_rc = _putscom(l_scom_addr, PSS_RESET_COMMAND, SCOM_TIMEOUT);
        if(l_scom_rc)
        {
            break;
        }

        // Zero out the reset register
        l_scom_rc = _putscom(l_scom_addr, 0, SCOM_TIMEOUT);
        if(l_scom_rc)
        {
            break;
        }

        // Attempt recovery by sending the apss
        // command that was set up earlier by initialization GPE
        l_scom_addr = SPIPSS_P2S_COMMAND_REG;
        l_scom_rc = _putscom(l_scom_addr, PSS_START_COMMAND, SCOM_TIMEOUT);
        if(l_scom_rc)
        {
            break;
        }
    }while(0);

    // Just trace it if we get a scom failure trying to collect FFDC
    if(l_scom_rc)
    {
        TRAC_ERR("apss recovery scom failure. addr=0x%08x, rc=0x%08x", l_scom_addr, l_scom_rc);
    }
}

// Note: The complete request must be global, since it must stick around until after the
//       GPE program has completed (in order to do the callback).
// TEMP -- NO MORE PORE
//PoreFlex G_meas_start_request;
// Function Specification
//
// Name:  task_apss_start_pwr_meas
//
// Description: Start the GPE program to request power measurement data from APSS
//              If previous call had failed, commit the error and request reset
//
// Task Flags: RTL_FLAG_MSTR, RTL_FLAG_OBS, RTL_FLAG_ACTIVE, RTL_FLAG_APSS_PRES
//
// End Function Specification
void task_apss_start_pwr_meas(struct task *i_self)
{
    int             l_rc                = 0;
    static bool     L_scheduled         = FALSE;
    static bool     L_idle_traced       = FALSE;
    static bool     L_ffdc_collected    = FALSE;

    // Create/schedule GPE_start_pwr_meas_read (non-blocking)
    APSS_DBG("GPE_start_pwr_meas_read started\n");

    do
    {
/* TEMP -- NO MORE PORE
        if (!async_request_is_idle(&G_meas_start_request.request))
        {
            if (!L_idle_traced)
            {
                TRAC_ERR("task_apss_start_pwr_meas: request is not idle.");
                L_idle_traced = TRUE;
            }
            break;
        }
*/
        // Check if we need to try recovering the apss
        if(G_apss_recovery_requested)
        {
            // Do recovery then wait until next tick to do anything more.
            do_apss_recovery();
            break;
        }

        if (L_scheduled)
        {
// TEMP -- UNCOMMENT ONCE G_meas_start_request is defined again
/*            if ((ASYNC_REQUEST_STATE_COMPLETE != G_meas_start_request.request.completion_state) ||
                (0 != G_gpe_start_pwr_meas_read_args.error.error))
            {
                //error should only be non-zero in the case where the GPE timed out waiting for
                //the APSS master to complete the last operation.  Just keep retrying until
                //DCOM resets us due to not having valid power data.
                TRAC_ERR("task_apss_start_pwr_meas: request is not complete or failed with an error(rc:0x%08X, ffdc:0x%08X%08X). " \
                        "CompletionState:0x%X.",
                         G_gpe_start_pwr_meas_read_args.error.rc,
                         G_gpe_start_pwr_meas_read_args.error.ffdc >> 32,
                         G_gpe_start_pwr_meas_read_args.error.ffdc,
                         G_meas_start_request.request.completion_state);

                // Collect FFDC and log error once.
                if (!L_ffdc_collected)
                {
                    errlHndl_t l_err = NULL;

                    /*
                     * @errortype
                     * @moduleid    PSS_MID_APSS_START_MEAS
                     * @reasoncode  APSS_GPE_FAILURE
                     * @userdata1   GPE returned rc code
                     * @userdata4   ERC_APSS_COMPLETE_FAILURE
                     * @devdesc     Failure getting power measurement data from APSS
                     */ /*
                    l_err = createErrl(PSS_MID_APSS_START_MEAS,   // i_modId
                                       APSS_GPE_FAILURE,          // i_reasonCode
                                       ERC_APSS_COMPLETE_FAILURE,
                                       ERRL_SEV_INFORMATIONAL,
                                       NULL,
                                       DEFAULT_TRACE_SIZE,
                                       G_gpe_start_pwr_meas_read_args.error.rc,
                                       0);

                    addUsrDtlsToErrl(l_err,
                                     (uint8_t*)&G_meas_start_request.ffdc,
                                     sizeof(G_meas_start_request.ffdc),
                                     ERRL_STRUCT_VERSION_1,
                                     ERRL_USR_DTL_BINARY_DATA);

                    // Commit Error
                    commitErrl(&l_err);

                      // Set to true so that we don't log this error again.
                    L_ffdc_collected = TRUE;
                }
            }
*/
        }

        // Clear these out prior to starting the GPE (GPE only sets them)
        G_gpe_start_pwr_meas_read_args.error.error = 0;
        G_gpe_start_pwr_meas_read_args.error.ffdc = 0;

        // Submit the next request
// TEMP -- NO MORE PORE
//        l_rc = pore_flex_schedule(&G_meas_start_request);
        if (0 != l_rc)
        {
            errlHndl_t l_err = NULL;

            TRAC_ERR("task_apss_start_pwr_meas: schedule failed w/rc=0x%08X (%d us)", l_rc,
                     (int) ((ssx_timebase_get())/(SSX_TIMEBASE_FREQUENCY_HZ/1000000)));

            /*
             * @errortype
             * @moduleid    PSS_MID_APSS_START_MEAS
             * @reasoncode  SSX_GENERIC_FAILURE
             * @userdata1   GPE shedule returned rc code
             * @userdata2   0
             * @userdata4   ERC_APSS_SCHEDULE_FAILURE
             * @devdesc     task_apss_start_pwr_meas schedule failed
             */
            l_err = createErrl(PSS_MID_APSS_START_MEAS,
                               SSX_GENERIC_FAILURE,
                               ERC_APSS_SCHEDULE_FAILURE,
                               ERRL_SEV_PREDICTIVE,
                               NULL,
                               DEFAULT_TRACE_SIZE,
                               l_rc,
                               0);

            // Request reset since this should never happen.
            REQUEST_RESET(l_err);
            L_scheduled = FALSE;
            break;
        }

        L_scheduled = TRUE;


    }while (0);


    APSS_DBG("GPE_start_pwr_meas_read finished w/rc=0x%08X\n", G_gpe_start_pwr_meas_read_args.error.rc);
    APSS_DBG_HEXDUMP(&G_gpe_start_pwr_meas_read_args, sizeof(G_gpe_start_pwr_meas_read_args), "G_gpe_start_pwr_meas_read_args");
    G_ApssPwrMeasCompleted = FALSE;  // Will complete when 3rd task is complete.
    G_gpe_apss_time_start = ssx_timebase_get();


} // end task_apss_start_pwr_meas()


// Note: The complete request must be global, since it must stick around until after the
//       GPE program has completed (in order to do the callback).
// TEMP -- NO MORE PORE
//PoreFlex G_meas_cont_request;
// Function Specification
//
// Name:  task_apss_continue_pwr_meas
//
// Description: Start GPE to collect 1st block of power measurement data and request
//              the 2nd block
//              If previous call had failed, commit the error and request reset
//
// Task Flags: RTL_FLAG_MSTR, RTL_FLAG_OBS, RTL_FLAG_ACTIVE, RTL_FLAG_APSS_PRES
//
// End Function Specification
void task_apss_continue_pwr_meas(struct task *i_self)
{
    int         l_rc                = 0;
    static bool L_scheduled         = FALSE;
    static bool L_idle_traced       = FALSE;
    static bool L_ffdc_collected    = FALSE;

    // Create/schedule GPE_apss_continue_pwr_meas_read (non-blocking)
    APSS_DBG("Calling task_apss_continue_pwr_meas.\n");

    do
    {
/* TEMP -- NO MORE PORE
        if (!async_request_is_idle(&G_meas_cont_request.request))
        {
            if (!L_idle_traced)
            {
                TRAC_ERR("task_apss_continue_pwr_meas: request is not idle.");
                L_idle_traced = TRUE;
            }
            break;
        }
*/
        //Don't run anything if apss recovery is in progress
        if(G_apss_recovery_requested)
        {
            break;
        }

        if (L_scheduled)
        {
/* TEMP -- UNCOMMENT ONCE G_meas_cont_request IS DEFINED AGAIN
            if ((ASYNC_REQUEST_STATE_COMPLETE != G_meas_cont_request.request.completion_state) ||
                (0 != G_gpe_continue_pwr_meas_read_args.error.error))
            {
                //error should only be non-zero in the case where the GPE timed out waiting for
                //the APSS master to complete the last operation.  Just keep retrying until
                //DCOM resets us due to not having valid power data.
                TRAC_ERR("task_apss_continue_pwr_meas: request is not complete or failed with an error(rc:0x%08X, ffdc:0x%08X%08X). " \
                        "CompletionState:0x%X.",
                         G_gpe_continue_pwr_meas_read_args.error.rc,
                         G_gpe_continue_pwr_meas_read_args.error.ffdc >> 32,
                         G_gpe_continue_pwr_meas_read_args.error.ffdc,
                         G_meas_cont_request.request.completion_state);


                // Collect FFDC and log error once.
                if (!L_ffdc_collected)
                {
                    errlHndl_t l_err = NULL;

                    /*
                     * @errortype
                     * @moduleid    PSS_MID_APSS_CONT_MEAS
                     * @reasoncode  APSS_GPE_FAILURE
                     * @userdata1   GPE returned rc code
                     * @userdata2   0
                     * @userdata4   ERC_APSS_COMPLETE_FAILURE
                     * @devdesc     Failure getting power measurement data from APSS
                     */ /*
                    l_err = createErrl(PSS_MID_APSS_CONT_MEAS,   // i_modId
                                       APSS_GPE_FAILURE,          // i_reasonCode
                                       ERC_APSS_COMPLETE_FAILURE,
                                       ERRL_SEV_INFORMATIONAL,
                                       NULL,
                                       DEFAULT_TRACE_SIZE,
                                       G_gpe_continue_pwr_meas_read_args.error.rc,
                                       0);

                    addUsrDtlsToErrl(l_err,
                                     (uint8_t*)&G_meas_cont_request.ffdc,
                                     sizeof(G_meas_cont_request.ffdc),
                                     ERRL_STRUCT_VERSION_1,
                                     ERRL_USR_DTL_BINARY_DATA);

                    // Commit Error
                    commitErrl(&l_err);

                      // Set to true so that we don't log this error again.
                    L_ffdc_collected = TRUE;
                }
            }
*/
        }

        // Clear these out prior to starting the GPE (GPE only sets them)
        G_gpe_continue_pwr_meas_read_args.error.error = 0;
        G_gpe_continue_pwr_meas_read_args.error.ffdc = 0;

        // Submit the next request
/* TEMP -- UNCOMMENT ONCE G_meas_cont_request IS DEFINED AGAIN
        l_rc = pore_flex_schedule(&G_meas_cont_request);
        if (0 != l_rc)
        {
            errlHndl_t l_err = NULL;

            TRAC_ERR("task_apss_cont_pwr_meas: schedule failed w/rc=0x%08X (%d us)", l_rc,
                     (int) ((ssx_timebase_get())/(SSX_TIMEBASE_FREQUENCY_HZ/1000000)));

            /*
             * @errortype
             * @moduleid    PSS_MID_APSS_CONT_MEAS
             * @reasoncode  SSX_GENERIC_FAILURE
             * @userdata1   GPE shedule returned rc code
             * @userdata2   0
             * @userdata4   ERC_APSS_SCHEDULE_FAILURE
             * @devdesc     task_apss_continue_pwr_meas schedule failed
             */ /*
            l_err = createErrl(PSS_MID_APSS_CONT_MEAS,
                               SSX_GENERIC_FAILURE,
                               ERC_APSS_SCHEDULE_FAILURE,
                               ERRL_SEV_PREDICTIVE,
                               NULL,
                               DEFAULT_TRACE_SIZE,
                               l_rc,
                               0);

            // Request reset since this should never happen.
            REQUEST_RESET(l_err);
            L_scheduled = FALSE;
            break;
        }

        L_scheduled = TRUE;
*/
    }while (0);

    APSS_DBG("task_apss_continue_pwr_meas: finished w/rc=0x%08X\n", G_gpe_continue_pwr_meas_read_args.error.rc);
    APSS_DBG_HEXDUMP(&G_gpe_continue_pwr_meas_read_args, sizeof(G_gpe_continue_pwr_meas_read_args), "G_gpe_continue_pwr_meas_read_args");

} // end task_apss_continue_pwr_meas

// Function Specification
//
// Name:  reformat_meas_data
//
// Description: Extract measurement from GPE programs into G_apss_pwr_meas structure
//              This function is called when the GPE completes the final measurement
//              collection for this loop.
//
// End Function Specification
#define APSS_ADC_SEQ_MASK 0xf000f000f000f000ull
#define APSS_ADC_SEQ_CHECK 0x0000100020003000ull
void reformat_meas_data()
{
    APSS_DBG("GPE_complete_pwr_meas_read finished w/rc=0x%08X\n", G_gpe_complete_pwr_meas_read_args.error.rc);
    APSS_DBG_HEXDUMP(&G_gpe_complete_pwr_meas_read_args, sizeof(G_gpe_complete_pwr_meas_read_args), "G_gpe_complete_pwr_meas_read_args");

    do
    {
        // Make sure complete was successful
        if (G_gpe_complete_pwr_meas_read_args.error.error)
        {
            break;
        }

        // Check that the first 4 sequence nibbles are 0, 1, 2, 3 in the ADC data
        if (((G_gpe_continue_pwr_meas_read_args.meas_data[0] & APSS_ADC_SEQ_MASK) != APSS_ADC_SEQ_CHECK) ||
             !(G_gpe_continue_pwr_meas_read_args.meas_data[0] & ~APSS_ADC_SEQ_MASK))
        {
            // Recovery will begin on the next tick
            G_apss_recovery_requested = TRUE;
            break;
        }

        // Decrement up/down fail counter for backup on success.
        if(G_backup_fail_count)
        {
            G_backup_fail_count--;
        }

        // Don't do the copy unless this is the master OCC
//        if(G_occ_role == OCC_MASTER)
        // TEMP -- IN PHASE 1 WE ARE ALWAYS MASTER
        if (TRUE)
        {

            // Fail every 16 seconds
            APSS_DBG("Populate meas data:\n");

            // Merge continue/complete data into a single buffer
            const uint16_t l_continue_meas_length = sizeof(G_gpe_continue_pwr_meas_read_args.meas_data);
            const uint16_t l_complete_meas_length = sizeof(G_gpe_complete_pwr_meas_read_args.meas_data);
            uint8_t l_buffer[l_continue_meas_length+l_complete_meas_length];
            memcpy(&l_buffer[                     0], G_gpe_continue_pwr_meas_read_args.meas_data, l_continue_meas_length);
            memcpy(&l_buffer[l_continue_meas_length], G_gpe_complete_pwr_meas_read_args.meas_data, l_complete_meas_length);
            APSS_DBG_HEXDUMP(l_buffer, sizeof(l_buffer), "l_buffer");

            // Copy measurements into correct struction locations (based on composite config)
            uint16_t l_index = 0;
            memcpy(G_apss_pwr_meas.adc, &l_buffer[l_index], (G_apss_composite_config.numAdcChannelsToRead * 2));
            l_index += (G_apss_composite_config.numAdcChannelsToRead * 2);
            memcpy(G_apss_pwr_meas.gpio, &l_buffer[l_index], (G_apss_composite_config.numGpioPortsToRead * 2));
            // TOD is always located at same offset
            memcpy(&G_apss_pwr_meas.tod, &l_buffer[l_continue_meas_length+l_complete_meas_length-8], 8);

            APSS_DBG("...into structure: (%d ADC, %d GPIO)\n", G_apss_composite_config.numAdcChannelsToRead,
                G_apss_composite_config.numGpioPortsToRead);
            APSS_DBG_HEXDUMP(&G_apss_pwr_meas, sizeof(G_apss_pwr_meas), "G_apss_pwr_meas");
        }

        // Mark apss pwr meas completed and valid
        G_ApssPwrMeasCompleted = TRUE;
        G_gpe_apss_time_end = ssx_timebase_get();
        APSS_DBG("APSS Completed - %d\n",(int) ssx_timebase_get());
  }while(0);
}


// Note: The complete request must be global, since it must stick around until after the
//       GPE program has completed (in order to do the callback).
// TEMP -- NO MORE PORE
//PoreFlex G_meas_complete_request;

// Function Specification
//
// Name:  task_apss_complete_pwr_meas
//
// Description: Start GPE to collect 2nd block of power measurement data and TOD.
//              If previous call had failed, commit the error and request reset
//
// Task Flags: RTL_FLAG_MSTR, RTL_FLAG_OBS, RTL_FLAG_ACTIVE, RTL_FLAG_APSS_PRES
//
// End Function Specification
void task_apss_complete_pwr_meas(struct task *i_self)
{
    int         l_rc                = 0;
    static bool L_scheduled         = FALSE;
    static bool L_idle_traced       = FALSE;
    static bool L_ffdc_collected    = FALSE;

    // Create/schedule GPE_apss_complete_pwr_meas_read (non-blocking)
    APSS_DBG("Calling task_apss_complete_pwr_meas.\n");

    do
    {
// TEMP -- UNCOMMENT ONCE G_meas_complete_request IS DEFINED AGAIN
/*
        if (!async_request_is_idle(&G_meas_complete_request.request))
        {
            if (!L_idle_traced)
            {
                TRAC_ERR("task_apss_complete_pwr_meas: request is not idle.");
                L_idle_traced = TRUE;
            }
            break;
        }
*/
        if(G_apss_recovery_requested)
        {
            // Allow apss measurement to proceed on next tick
            G_apss_recovery_requested = FALSE;
            break;
        }


        if (L_scheduled)
        {
// TEMP -- UNCOMMENT ONCE G_meas_complete_request IS DEFINED AGAIN
/*
            if ((ASYNC_REQUEST_STATE_COMPLETE != G_meas_complete_request.request.completion_state) ||
                (0 != G_gpe_complete_pwr_meas_read_args.error.error))
            {
                // Error should only be non-zero in the case where the GPE timed out waiting for
                // the APSS master to complete the last operation. Just keep retrying until
                // DCOM resets us due to not having valid power data.
                TRAC_ERR("task_apss_complete_pwr_meas: request is not complete or failed with an error(rc:0x%08X, ffdc:0x%08X%08X). " \
                        "CompletionState:0x%X.",
                         G_gpe_complete_pwr_meas_read_args.error.rc,
                         G_gpe_complete_pwr_meas_read_args.error.ffdc >> 32,
                         G_gpe_complete_pwr_meas_read_args.error.ffdc,
                         G_meas_complete_request.request.completion_state);

                // Collect FFDC and log error once.
                if (!L_ffdc_collected)
                {
                    errlHndl_t l_err = NULL;

                    /*
                     * @errortype
                     * @moduleid    PSS_MID_APSS_COMPLETE_MEAS
                     * @reasoncode  APSS_GPE_FAILURE
                     * @userdata1   GPE returned rc code
                     * @userdata2   0
                     * @userdata4   ERC_APSS_COMPLETE_FAILURE
                     * @devdesc     Failure getting power measurement data from APSS
                     */ /*
                    l_err = createErrl(PSS_MID_APSS_COMPLETE_MEAS,   // i_modId
                                       APSS_GPE_FAILURE,          // i_reasonCode
                                       ERC_APSS_COMPLETE_FAILURE,
                                       ERRL_SEV_INFORMATIONAL,
                                       NULL,
                                       DEFAULT_TRACE_SIZE,
                                       G_gpe_complete_pwr_meas_read_args.error.rc,
                                       0);

                    addUsrDtlsToErrl(l_err,
                                     (uint8_t*)&G_meas_complete_request.ffdc,
                                     sizeof(G_meas_complete_request.ffdc),
                                     ERRL_STRUCT_VERSION_1,
                                     ERRL_USR_DTL_BINARY_DATA);

                    // Commit Error
                    commitErrl(&l_err);

                    // Set to true so that we don't log this error again.
                    L_ffdc_collected = TRUE;
                }
            }
*/
        }

        // Clear these out prior to starting the GPE (GPE only sets them)
        G_gpe_complete_pwr_meas_read_args.error.error = 0;
        G_gpe_complete_pwr_meas_read_args.error.ffdc = 0;

        // Submit the next request
// TEMP -- UNCOMMENT ONCE G_meas_complete_request IS DEFINED AGAIN
/*
      l_rc = pore_flex_schedule(&G_meas_complete_request);
        if (0 != l_rc)
        {
            errlHndl_t l_err = NULL;

            TRAC_ERR("task_apss_complete_pwr_meas: schedule failed w/rc=0x%08X (%d us)", l_rc,
                     (int) ((ssx_timebase_get())/(SSX_TIMEBASE_FREQUENCY_HZ/1000000)));

            /*
             * @errortype
             * @moduleid    PSS_MID_APSS_COMPLETE_MEAS
             * @reasoncode  SSX_GENERIC_FAILURE
             * @userdata1   GPE shedule returned rc code
             * @userdata2   0
             * @userdata4   ERC_APSS_SCHEDULE_FAILURE
             * @devdesc     task_apss_complete_pwr_meas schedule failed
             */ /*
            l_err = createErrl(PSS_MID_APSS_COMPLETE_MEAS,
                               SSX_GENERIC_FAILURE,
                               ERC_APSS_SCHEDULE_FAILURE,
                               ERRL_SEV_PREDICTIVE,
                               NULL,
                               DEFAULT_TRACE_SIZE,
                               l_rc,
                               0);

            // Request reset since this should never happen.
            REQUEST_RESET(l_err);
            L_scheduled = FALSE;
            break;
        }
*/
        L_scheduled = TRUE;


    }while (0);

    APSS_DBG("task_apss_complete_pwr_meas: finished w/rc=0x%08X\n", G_gpe_complete_pwr_meas_read_args.error.rc);
    APSS_DBG_HEXDUMP(&G_gpe_complete_pwr_meas_read_args, sizeof(G_gpe_complete_pwr_meas_read_args), "G_gpe_complete_pwr_meas_read_args");


} // end task_apss_complete_pwr_meas

bool apss_gpio_get(uint8_t i_pin_number, uint8_t *o_pin_value)
{
    bool l_valid = FALSE;

    if( (i_pin_number != SYSCFG_INVALID_PIN) && (o_pin_value != NULL) )
    {
        // Check if G_dcom_slv_inbox_rx is valid.
        // The default value is all 0, so check if it's no-zero
        bool l_dcom_data_valid = FALSE;
        int i=0;
// TEMP -- NO DCOM IN PHASE1
/*
        for(;i<sizeof(G_dcom_slv_inbox_rx);i++)
        {
            if( ((char*)&G_dcom_slv_inbox_rx)[i] != 0 )
            {
              l_dcom_data_valid = TRUE;
              break;
            }
        }
*/
        if( l_dcom_data_valid == TRUE)
        {
            uint8_t l_gpio_port = i_pin_number/NUM_OF_APSS_PINS_PER_GPIO_PORT;
            uint8_t l_gpio_mask = 0x1 << i_pin_number % NUM_OF_APSS_PINS_PER_GPIO_PORT;
            l_valid = TRUE;
            if( G_dcom_slv_inbox_rx.gpio[l_gpio_port] & l_gpio_mask )
            {
                *o_pin_value = 1;
            }
            else
            {
                *o_pin_value = 0;
            }
        }
    }
    return l_valid;
}

OpenPOWER on IntegriCloud