/
dpmutil.c
1924 lines (1742 loc) · 64.5 KB
/
dpmutil.c
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
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/************************************************************************/
/* */
/* dpmutil.c -- Digilent Platform Management Utility */
/* */
/************************************************************************/
/* Author: Michael T. Alexander, Thomas Kappenman */
/* Copyright 2019 Digilent, Inc. */
/************************************************************************/
/* Module Description: */
/* */
/* The Digilent Platform Management Utility (dpmutil) provides an */
/* API for discovering Zmods (SYZYGY Pods) attached */
/* to a Digilent platform board, acquiring information about them, */
/* acquiring information about the Digilent platform board, and */
/* setting certain settings pertaining to the configuration of the */
/* Digilent platform board. */
/* */
/************************************************************************/
/* Revision History: */
/* */
/* 08/21/2019(MichaelA): Created */
/* 10/25/2019(MichaelA): modified FEnum to retrieve and display the */
/* PDID for SYZYGY Pods manufactured by Digilent */
/* 10/28/2019(MichaelA): modified OpenI2cController to search the */
/* "/sys/bus/i2c/devices" directory for a device whose */
/* "device-name" is "pmcu-i2c" and if found open that device. If */
/* no such device is found then we assume "/dev/i2c-0" is the */
/* device entry corresponding to the I2C controller with the PMCU */
/* I2C bus */
/* 01/03/2020(MichaelA): modified FEnum to add support for displaying */
/* the 5V0, 3V3, and VIO voltages read by the pMCU on the ZmodLOOP */
/* 01/03/2020(MichaelA): added FWriteDNA function to add the ability */
/* to write binary data to the DNA section of the pMCU flash */
/* 01/06/2020(MichaelA): modified FWriteDNA to add support for magic */
/* numbers for disabling flash write protection. Write protection */
/* is restored after the write operation completes */
/* 01/13/2020(MichaelA): modified FEnum to add support for displaying */
/* the calibration constants of the ZmodADC and ZmodDAC */
/* 01/13/2020(MichaelA): moved code specific to ZmodLOOP to ZmodLOOP.h */
/* and ZmodLOOP.c */
/* 05/04/2020(ThomasK): namechange to dpmutil.c. Changed from linux */
/* console app to baremetal api */
/* */
/************************************************************************/
/* ------------------------------------------------------------ */
/* Include File Definitions */
/* ------------------------------------------------------------ */
#if defined(__linux__)
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdio.h>
#include <linux/i2c-dev.h>
#include <time.h>
#else
#include "sleep.h"
#endif
#include "dpmutil.h"
#include <stdio.h>
/* ------------------------------------------------------------ */
/* Miscellaneous Declarations */
/* ------------------------------------------------------------ */
/* The following addresses are utilized to retrieve information
** from Digilent SYZYGY pods (ZMODs).
*/
#define addrPdid 0x80FC
/* The following macro can be utilized to convert a Digilent PDID
** into a product.
*/
#define ProductFromPdid(pdid) ((pdid >> 20) & 0xFFF)
/* ------------------------------------------------------------ */
/* Local Type Definitions */
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/* Global Variables */
/* ------------------------------------------------------------ */
BOOL dpmutilfVerbose;
/* ------------------------------------------------------------ */
/* Local Variables */
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/* Procedure Definitions */
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/*** dpmutilFGetInfo
**
** Parameters:
** pDevInfo - Pointer to a dpmutilDevInfo_t object to store data
**
** Return Values:
** fTrue for success, fFalse otherwise
**
** Errors:
**
** Description:
** Get general configuration and information about the supported
** features of the Platform MCU (PMCU). This function communicates
** with the PMCU over the I2C bus to retrieve general information
** about the capabilities of the PMCU and the board configuration.
** This information includes the PMCU firwmare revision, SmartVIO
** port count, power supply group counts (5V0, 3V3, VADJ), the
** number of temperature probes supported by the board, and the
** number of fans supported by the board. If the board supports
** one or more temperature probe then the capabilities of each
** supported probe and the most recent temperature measurement
** of that probe are displayed via the console. If the board
** supports one or more fan then the capabilities of each
** supported fan are displayed via the console and if a fan supports
** RPM measurement then the most recent RPM measurement is also
** displayed.
*/
BOOL
dpmutilFGetInfo(dpmutildevInfo_t* pDevInfo) {
int fdI2c;
WORD wTemp;
BYTE i;
fdI2c = -1;
#if defined(__linux__)
fdI2c = I2CHALOpenI2cController();
if ( 0 > fdI2c ) {
printf("ERROR: failed to open file descriptor for I2C device\n");
goto lErrorExit;
}
#else
if(!I2CHALInit(0)){
printf("ERROR: failed to initialize I2C device\n");
goto lErrorExit;
}
#endif
/* Read and display the PDID.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrPDID, (BYTE*)(&pDevInfo->pdid), 4, NULL) ) {
printf("ERROR: failed to read PDID\n");
goto lErrorExit;
}
if(dpmutilfVerbose)printf("PMCU_PDID: 0x%08X\n", (unsigned int)pDevInfo->pdid);
/* Read and display the firmware revision number.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrFirmwareVersion, (BYTE*)(&wTemp), 2, NULL) ) {
printf("ERROR: failed to read FIRMWARE_VERSION register\n");
goto lErrorExit;
}
if(dpmutilfVerbose)printf("PMCU_FIRMWARE_VERSION: %d.%d\n", wTemp >> 8, wTemp & 0xFF);
pDevInfo->fwVer = wTemp / (1<<8);
/* Read and display the configuration revision number.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrConfigurationVersion, (BYTE*)(&wTemp), 2, NULL) ) {
printf("ERROR: failed to read CONFIGURATION_VERSION register\n");
goto lErrorExit;
}
if(dpmutilfVerbose)printf("PMCU_CONFIGURATION_VERSION: %d.%d\n", wTemp >> 8, wTemp & 0xFF);
pDevInfo->cfgVer = wTemp / (1<<8);
/* Read and display the platform configuration.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrPlatformConfig, (BYTE*)(&pDevInfo->platcfg), 2, NULL) ) {
printf("ERROR: failed to read PLATFORM_CONFIGURATION register\n");
goto lErrorExit;
}
if(dpmutilfVerbose){
memcpy(&wTemp, &(pDevInfo->platcfg), 2);
printf("PLATFORM_CONFIGURATION: 0x%04X\n", wTemp);
printf(" ENFORCE_5V0_CURRENT_LIMIT [%c]\n", pDevInfo->platcfg.fEnforce5v0CurLimit ? 'Y':'N');
printf(" ENFORCE_3V3_CURRENT_LIMIT [%c]\n", pDevInfo->platcfg.fEnforce3v3CurLimit ? 'Y':'N');
printf(" ENFORCE_VIO_CURRENT_LIMIT [%c]\n", pDevInfo->platcfg.fEnforceVioCurLimit ? 'Y':'N');
printf(" PERFORM_SYZYGY_CRC_CHECK [%c]\n", pDevInfo->platcfg.fPerformCrcCheck ? 'Y':'N');
}
/* Read and display the SmartVio port count.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrPortCount, &pDevInfo->cntVioPort, 1, NULL) ) {
printf("ERROR: failed to read SMARTVIO_PORT_COUNT register\n");
goto lErrorExit;
}
if(dpmutilfVerbose)printf("SMARTVIO_PORT_COUNT: %d\n", pDevInfo->cntVioPort);
/* Read and display the 5V0 group count.
*/
if ( ! PmcuI2cRead(fdI2c, regaddr5v0GroupCount, &pDevInfo->cnt5v0, 1, NULL) ) {
printf("ERROR: failed to read 5V0_GROUP_COUNT register\n");
goto lErrorExit;
}
if(dpmutilfVerbose)printf("5V0_GROUP_COUNT: %d\n", pDevInfo->cnt5v0);
/* Read and display the 3V3 group count.
*/
if ( ! PmcuI2cRead(fdI2c, regaddr3v3GroupCount, &pDevInfo->cnt3v3, 1, NULL) ) {
printf("ERROR: failed to read 3V3_GROUP_COUNT register\n");
goto lErrorExit;
}
if(dpmutilfVerbose)printf("3V3_GROUP_COUNT: %d\n", pDevInfo->cnt3v3);
/* Read and display the VADJ group count.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrVadjGroupCount, &pDevInfo->cntVadj, 1, NULL) ) {
printf("ERROR: failed to read VADJ_GROUP_COUNT register\n");
goto lErrorExit;
}
if(dpmutilfVerbose)printf("VADJ_GROUP_COUNT: %d\n", pDevInfo->cntVadj);
/* Read and display the temperature probe count.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrTempProbeCount, &pDevInfo->cntProbe, 1, NULL) ) {
printf("ERROR: failed to read TEMPERATURE_PROBE_COUNT register\n");
goto lErrorExit;
}
if(dpmutilfVerbose)printf("TEMPERATURE_PROBE_COUNT: %d\n", pDevInfo->cntProbe);
for ( i = 0; i < pDevInfo->cntProbe; i++ ) {
/* Read and display this temperature probe's capabilities.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrTemp1Attributes + (offsetTemperatureReg*i), (BYTE*)&pDevInfo->probeAttr[i], 1, NULL) ) {
printf("ERROR: failed to read TEMPERATURE_%d_ATTRIBUTES register\n", i+1);
goto lErrorExit;
}
if(dpmutilfVerbose){
printf(" TEMPERATURE_%d_CAPABILITIES: 0x%02X\n", i + 1, pDevInfo->probeAttr[i].fs);
printf(" PRESENT [%c]\n", pDevInfo->probeAttr[i].fPresent ? 'Y' : 'N');
printf(" LOCATION ");
switch ( pDevInfo->probeAttr[i].tlocation ) {
case tlocationFpgaCpu1:
printf("FPGA/CPU_1\n");
break;
case tlocationFpgaCpu2:
printf("FPGA/CPU_2\n");
break;
case tlocationExternal1:
printf("EXTERNAL_1\n");
break;
case tlocationExternal2:
printf("EXTERNAL_2\n");
break;
default:
printf("UNKNOWN\n");
break;
}
printf(" TEMPERATURE_FORMAT ");
switch ( pDevInfo->probeAttr[i].tformat ) {
case tformatDegCDecimal:
printf("Degrees C (decimal)\n");
break;
case tformatDegCFixedPoint:
printf("Degrees C (fixed point)\n");
break;
case tformatDegFDecimal:
printf("Degrees F (decimal)\n");
break;
case tformatDegFFixedPoint:
printf("Degrees F (fixed point)\n");
break;
default:
printf("UNKNOWN\n");
break;
}
}
/* Read and display this probe's temperature.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrTemp1 + (offsetTemperatureReg*i), (BYTE*)&pDevInfo->temp[i], 2, NULL) ) {
printf("ERROR: failed to read TEMPERATURE_%d register\n", i+1);
goto lErrorExit;
}
if(dpmutilfVerbose){
printf(" TEMPERATURE_%d: ", i + 1);
switch ( pDevInfo->probeAttr[i].tformat ) {
case tformatDegCDecimal:
printf("%hd Degrees C\n", pDevInfo->temp[i]);
break;
case tformatDegCFixedPoint:
printf("%8.2f Degrees C\n", pDevInfo->temp[i] / 256.0);
break;
case tformatDegFDecimal:
printf("%hd Degrees F\n", pDevInfo->temp[i]);
break;
case tformatDegFFixedPoint:
printf("%8.2f Degrees F\n", pDevInfo->temp[i] / 256.0);
break;
default:
printf("UNKNOWN\n");
break;
}
if ( (i+1) != pDevInfo->cntProbe ) {
printf("\n");
}
}
}
/* Read and display the fan count.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrFanCount, &pDevInfo->cntFan, 1, NULL) ) {
printf("ERROR: failed to read FAN_COUNT register\n");
goto lErrorExit;
}
if(dpmutilfVerbose)printf("FAN_COUNT: %d\n", pDevInfo->cntFan);
for ( i = 0; i < pDevInfo->cntFan; i++ ) {
/* Read and display this fan's capabilities.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrFan1Capabilities + (offsetFanReg*i), (BYTE*)&pDevInfo->fanCapabilities[i], 1, NULL) ) {
printf("ERROR: failed to read FAN_%d_CAPABILITIES register\n", i+1);
goto lErrorExit;
}
if(dpmutilfVerbose){
printf(" FAN_%d_CAPABILITIES: 0x%02X\n", i + 1, pDevInfo->fanCapabilities[i].fs);
printf(" ENABLE_AND_DISABLE [%c]\n", pDevInfo->fanCapabilities[i].fcapEnable ? 'Y' : 'N');
printf(" SET_FIXED_SPEED [%c]\n", pDevInfo->fanCapabilities[i].fcapSetSpeed ? 'Y' : 'N');
printf(" AUTO_SPEED_CONTROL [%c]\n", pDevInfo->fanCapabilities[i].fcapAutoSpeed ? 'Y' : 'N');
printf(" MEASURE_RPM [%c]\n", pDevInfo->fanCapabilities[i].fcapMeasureRpm ? 'Y' : 'N');
}
/* Read and display this fan's configuration.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrFan1Config + (offsetFanReg*i), (BYTE*)&pDevInfo->fanConfig[i], 1, NULL) ) {
printf("ERROR: failed to read FAN_%d_CONFIGURATION register\n", i+1);
goto lErrorExit;
}
if(dpmutilfVerbose){
printf(" FAN_%d_CONFIGURATION: 0x%02X\n", i + 1, pDevInfo->fanConfig[i].fs);
printf(" ENABLE [%c]\n", pDevInfo->fanConfig[i].fEnable ? 'Y' : 'N');
printf(" SPEED ");
switch ( pDevInfo->fanConfig[i].fspeed ) {
case fancfgMinimumSpeed:
printf("MINIMUM\n");
break;
case fancfgMediumSpeed:
printf("MEDIUM\n");
break;
case fancfgMaximumSpeed:
printf("MAXIMUM\n");
break;
case fancfgAutoSpeed:
printf("AUTOMATIC\n");
break;
default:
printf("UNKNOWN\n");
break;
}
printf(" TEMPERATURE_SOURCE ");
switch ( pDevInfo->fanConfig[i].tempsrc ) {
case fancfgTempProbeNone:
printf("NONE\n");
break;
case fancfgTempProbe1:
printf("TEMP_PROBE_1\n");
break;
case fancfgTempProbe2:
printf("TEMP_PROBE_2\n");
break;
case fancfgTempProbe3:
printf("TEMP_PROBE_3\n");
break;
case fancfgTempProbe4:
printf("TEMP_PROBE_4\n");
break;
default:
printf("UNKNOWN\n");
break;
}
printf(" MEASURE_RPM [%c]\n", pDevInfo->fanCapabilities[i].fcapMeasureRpm ? 'Y' : 'N');
}
/* Read and display this fan's RPM.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrFan1Rpm + (offsetFanReg*i), (BYTE*)(&pDevInfo->fanRPM[i]), 2, NULL) ) {
printf("ERROR: failed to read FAN_%d_RPM register\n", i+1);
goto lErrorExit;
}
if(dpmutilfVerbose){
printf(" FAN_%d_RPM: %d\n", i+1, pDevInfo->fanRPM[i]);
if ( (i+1) != pDevInfo->cntFan ) {
printf("\n");
}
}
}
#if defined(__linux__)
/* Close the I2C controller file descriptor.
*/
close(fdI2c);
#endif
return fTrue;
lErrorExit:
#if defined(__linux__)
if ( 0 <= fdI2c ) {
close(fdI2c);
}
#endif
return fFalse;
}
/* ------------------------------------------------------------ */
/*** dpmutilFGetInfoPower
**
** Parameters:
** chanid - channel id to get power from. -1 to scan all
** pPowerInfo - Pointer to a dpmutilPowerInfo_t array [8] to store data
**
** Return Values:
** fTrue for success, fFalse otherwise
**
** Errors:
**
** Description:
** Get information about the on board power supplies (5V0, 3V3, VIO)
** that are associated with the on board SmartVIO ports. This
** function communicates with the Platform MCU (PMCU) over I2C to
** determine the number of on board 5V0, 3V3, and VIO power supplies
** that are associated with the on board VIO ports and to retrieve
** various information about each of these supplies.
**
** The "chanid <0...7>" parameter can be used to specify
** the channel ID of a specific power supply. If chanid = -1 this function
** will retrieve and display information
** for every channel supported by the board.
*/
BOOL
dpmutilFGetInfoPower(int chanid, dpmutilPowerInfo_t pPowerInfo[]) {
BOOL fRet;
fRet = fTrue;
if ( ! dpmutilFGetInfo5V0(chanid, pPowerInfo) ) {
fRet = fFalse;
}
if(dpmutilfVerbose)printf("\n");
if ( ! dpmutilFGetInfo3V3(chanid, pPowerInfo) ) {
fRet = fFalse;
}
if(dpmutilfVerbose)printf("\n");
if ( ! dpmutilFGetInfoVio(chanid, pPowerInfo) ) {
fRet = fFalse;
}
return fRet;
}
/* ------------------------------------------------------------ */
/*** dpmutilFGetInfo5V0
**
** Parameters:
** chanid - channel id to get power from. -1 to scan all
** pPowerInfo - Pointer to a dpmutilPowerInfo_t array [8] to store data
**
** Return Values:
** fTrue for success, fFalse otherwise
**
** Errors:
**
** Description:
** Get information about the on board 5V0 power supplies that are
** associated with the on board SmartVIO ports. This function
** communicates with the Platform MCU (PMCU) over I2C to
** determine the number of on board 5V0 power supplies, to retrieve
** the amount of current that each supply is capable of providing,
** and to retrieve the sum of current requested by all SmartVIO
** ports that are associated with each supply. All of this information
** is output to the console.
**
** The "chanid <0...7>" parameter can be used to specify
** the channel ID of a specific power supply. If chanid = -1 this function
** will retrieve and display information
** for every channel supported by the board.
*/
BOOL
dpmutilFGetInfo5V0(int chanid, dpmutilPowerInfo_t pPowerInfo[]) {
int fdI2c;
BYTE csupply;
BYTE isupply;
fdI2c = -1;
#if defined(__linux__)
fdI2c = I2CHALOpenI2cController();
if ( 0 > fdI2c ) {
printf("ERROR: failed to open file descriptor for I2C device\n");
goto lErrorExit;
}
#else
if(!I2CHALInit(0)){
printf("ERROR: failed to initialize I2C device\n");
goto lErrorExit;
}
#endif
/* Determine how many 5V0 supplies there are.
*/
if ( ! PmcuI2cRead(fdI2c, regaddr5v0GroupCount, &csupply, 1, NULL) ) {
printf("ERROR: failed to read 5V0_GROUP_COUNT register\n");
goto lErrorExit;
}
if ( chanid != -1 ) {
if ( chanid >= csupply ) {
printf("ERROR: device has %d 5V0 supplies. Channel %d is\n", csupply, chanid);
printf("not supported by this device\n");
goto lErrorExit;
}
isupply = chanid;
csupply = chanid + 1;
}
else {
if(dpmutilfVerbose){
if ( 1 < csupply ) {
printf("Found %d 5V0 supplies\n", csupply);
}
else {
printf("Found 1 5V0 supply\n");
}
}
isupply = 0;
}
while ( isupply < csupply ) {
if(dpmutilfVerbose)printf("Supply: 5V0_%c\n", 0x41 + isupply);
/* Read and display the current allowed for the supply.
*/
if ( ! PmcuI2cRead(fdI2c, regaddr5v0ACurrentAllowed + (offset5v0Reg*isupply), (BYTE*)&pPowerInfo[isupply].currentAllowed5v0, 2, NULL) ) {
printf("ERROR: failed to read 5V0_%c_CURRENT_ALLOWED register\n", 0x41 + isupply);
goto lErrorExit;
}
if(dpmutilfVerbose)printf(" 5V0_%c_CURRENT_ALLOWED: %d mA\n", 0x41 + isupply, pPowerInfo[isupply].currentAllowed5v0);
/* Read and display the current requested for the supply.
*/
if ( ! PmcuI2cRead(fdI2c, regaddr5v0ACurrentRequested + (offset3v3Reg*isupply), (BYTE*)&pPowerInfo[isupply].currentRequested5v0, 2, NULL) ) {
printf("ERROR: failed to read 5V0_%c_CURRENT_REQUESTED register\n", 0x41 + isupply);
goto lErrorExit;
}
if(dpmutilfVerbose)printf(" 5V0_%c_CURRENT_REQUESTED: %d mA\n", 0x41 + isupply, pPowerInfo[isupply].currentRequested5v0);
isupply++;
if(dpmutilfVerbose){
if ( isupply != csupply ) {
printf("\n");
}
}
}
#if defined(__linux__)
/* Close the I2C controller file descriptor.
*/
close(fdI2c);
#endif
return fTrue;
lErrorExit:
#if defined(__linux__)
if ( 0 <= fdI2c ) {
close(fdI2c);
}
#endif
return fFalse;
}
/* ------------------------------------------------------------ */
/*** dpmutilFGetInfo3V3
**
** Parameters:
** chanid - channel id to get power from. -1 to scan all
** pPowerInfo - Pointer to a dpmutilPowerInfo_t array [8] to store data
**
** Return Values:
** fTrue for success, fFalse otherwise
**
** Errors:
**
** Description:
** Get information about the on board 3V3 power supplies that are
** associated with the on board SmartVIO ports. This function
** communicates with the Platform MCU (PMCU) over I2C to
** determine the number of on board 3V3 power supplies, to retrieve
** the amount of current that each supply is capable of providing,
** and to retrieve the sum of current requested by all SmartVIO
** ports that are associated with each supply. All of this information
** is output to the console.
**
** The "chanid <0...7>" parameter can be used to specify
** the channel ID of a specific power supply. If chanid = -1 this function
** will retrieve and display information
** for every channel supported by the board.
*/
BOOL
dpmutilFGetInfo3V3(int chanid, dpmutilPowerInfo_t pPowerinfo[]) {
int fdI2c;
BYTE csupply;
BYTE isupply;
fdI2c = -1;
#if defined(__linux__)
fdI2c = I2CHALOpenI2cController();
if ( 0 > fdI2c ) {
printf("ERROR: failed to open file descriptor for I2C device\n");
goto lErrorExit;
}
#else
if(!I2CHALInit(0)){
printf("ERROR: failed to initialize I2C device\n");
goto lErrorExit;
}
#endif
/* Determine how many 3V3 supplies there are.
*/
if ( ! PmcuI2cRead(fdI2c, regaddr3v3GroupCount, &csupply, 1, NULL) ) {
printf("ERROR: failed to read 3V3_GROUP_COUNT register\n");
goto lErrorExit;
}
if ( chanid != -1 ) {
if ( chanid >= csupply ) {
printf("ERROR: device has %d 3V3 supplies. Channel %d is\n", csupply, chanid);
printf("not supported by this device\n");
goto lErrorExit;
}
isupply = chanid;
csupply = chanid + 1;
}
else {
if(dpmutilfVerbose){
if ( 1 < csupply ) {
printf("Found %d 3V3 supplies\n", csupply);
}
else {
printf("Found 1 3V3 supply\n");
}
}
isupply = 0;
}
while ( isupply < csupply ) {
if(dpmutilfVerbose)printf("Supply: 3V3_%c\n", 0x41 + isupply);
/* Read and display the current allowed for the supply.
*/
if ( ! PmcuI2cRead(fdI2c, regaddr3v3ACurrentAllowed + (offset3v3Reg*isupply), (BYTE*)&pPowerinfo[isupply].currentAllowed3v3, 2, NULL) ) {
printf("ERROR: failed to read 3V3_%c_CURRENT_ALLOWED register\n", 0x41 + isupply);
goto lErrorExit;
}
if(dpmutilfVerbose)printf(" 3V3_%c_CURRENT_ALLOWED: %d mA\n", 0x41 + isupply, pPowerinfo[isupply].currentAllowed3v3);
/* Read and display the current requested for the supply.
*/
if ( ! PmcuI2cRead(fdI2c, regaddr3v3ACurrentRequested + (offset3v3Reg*isupply), (BYTE*)&pPowerinfo[isupply].currentRequested3v3, 2, NULL) ) {
printf("ERROR: failed to read 3V3_%c_CURRENT_REQUESTED register\n", 0x41 + isupply);
goto lErrorExit;
}
if(dpmutilfVerbose)printf(" 3V3_%c_CURRENT_REQUESTED: %d mA\n", 0x41 + isupply, pPowerinfo[isupply].currentRequested3v3);
isupply++;
if(dpmutilfVerbose){
if ( isupply != csupply ) {
printf("\n");
}
}
}
#if defined(__linux__)
/* Close the I2C controller file descriptor.
*/
close(fdI2c);
#endif
return fTrue;
lErrorExit:
#if defined(__linux__)
if ( 0 <= fdI2c ) {
close(fdI2c);
}
#endif
return fFalse;
}
/* ------------------------------------------------------------ */
/*** dpmutilFGetInfoVio
**
** Parameters:
** chanid - channel id to get power from. -1 to scan all
** pPowerInfo - Pointer to a dpmutilPowerInfo_t array [8] to store data
**
** Return Values:
** fTrue for success, fFalse otherwise
**
** Errors:
**
** Description:
** Get information about the on board VIO (VADJ) power supplies that
** are associated with the on board SmartVIO ports. This function
** communicates with the Platform MCU (PMCU) over I2C to
** determine the number of on board VIO power supplies, to retrieve
** the amount of current that each supply is capable of providing,
** to retrieve the sum of current requested by all SmartVIO
** ports that are associated with each supply, and to retrieve all
** status and configuration information associated with each supply.
** All of this information is output to the console.
**
** The "chanid <0...7>" parameter can be used to specify
** the channel ID of a specific power supply. If chanid = -1 this function
** will retrieve and display information
** for every channel supported by the board.
*/
BOOL
dpmutilFGetInfoVio(int chanid, dpmutilPowerInfo_t pPowerInfo[]) {
int fdI2c;
BYTE cvadj;
BYTE ivadj;
VADJ_STATUS vadjsts;
fdI2c = -1;
#if defined(__linux__)
fdI2c = I2CHALOpenI2cController();
if ( 0 > fdI2c ) {
printf("ERROR: failed to open file descriptor for I2C device\n");
goto lErrorExit;
}
#else
if(!I2CHALInit(0)){
printf("ERROR: failed to initialize I2C device\n");
goto lErrorExit;
}
#endif
/* Determine how many VADJ supplies there are.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrVadjGroupCount, &cvadj, 1, NULL) ) {
printf("ERROR: failed to read VADJ_GROUP_COUNT register\n");
goto lErrorExit;
}
/* Get the status for all VADJ supplies.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrVadjStatus, (BYTE*)&vadjsts, 2, NULL) ) {
printf("ERROR: failed to read VADJ_STATUS register\n");
goto lErrorExit;
}
if ( chanid != -1 ) {
if ( chanid >= cvadj ) {
printf("ERROR: device has %d VIO supplies. Channel %d is\n", cvadj, chanid);
printf("not supported by this device\n");
goto lErrorExit;
}
ivadj = chanid;
cvadj = chanid + 1;
}
else {
if(dpmutilfVerbose){
if ( 1 < cvadj ) {
printf("Found %d VIO supplies\n", cvadj);
}
else {
printf("Found 1 VIO supply\n");
}
}
ivadj = 0;
}
while ( ivadj < cvadj ) {
if(dpmutilfVerbose){
printf("Supply: VADJ_%c\n", 0x41 + ivadj);
printf(" VADJ_%c_ENABLED: [%c]\n", 0x41 + ivadj, (vadjsts.fsEn & (1<<ivadj)) ? 'Y' : 'N');
printf(" VADJ_%c_POWER_GOOD: [%c]\n", 0x41 + ivadj, (vadjsts.fsPgood & (1<<ivadj)) ? 'Y' : 'N');
}
/* Read and display the voltage setting for the current supply.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrVadjAVoltage + (offsetVadjReg*ivadj), (BYTE*)&pPowerInfo[ivadj].vadjVoltage, 2, NULL) ) {
printf("ERROR: failed to read VADJ_%c_VOLTAGE register\n", 0x41 + ivadj);
goto lErrorExit;
}
if(dpmutilfVerbose)printf(" VADJ_%c_VOLTAGE: %d mV\n", 0x41 + ivadj, pPowerInfo[ivadj].vadjVoltage * 10);
/* Read and display the current allowed for the supply.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrVadjACurrentAllowed + (offsetVadjReg*ivadj), (BYTE*)&pPowerInfo[ivadj].currentAllowedVadj, 2, NULL) ) {
printf("ERROR: failed to read VADJ_%c_CURRENT_ALLOWED register\n", 0x41 + ivadj);
goto lErrorExit;
}
if(dpmutilfVerbose)printf(" VADJ_%c_CURRENT_ALLOWED: %d mA\n", 0x41 + ivadj, pPowerInfo[ivadj].currentAllowedVadj);
/* Read and display the current requested for the supply.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrVadjACurrentRequested + (offsetVadjReg*ivadj), (BYTE*)&pPowerInfo[ivadj].currentRequestedVadj, 2, NULL) ) {
printf("ERROR: failed to read VADJ_%c_CURRENT_REQUESTED register\n", 0x41 + ivadj);
goto lErrorExit;
}
if(dpmutilfVerbose)printf(" VADJ_%c_CURRENT_REQUESTED: %d mA\n", 0x41 + ivadj, pPowerInfo[ivadj].currentRequestedVadj);
/* Read and display the override register for the supply.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrVadjAOverride + (offsetVadjReg*ivadj), (BYTE*)&pPowerInfo[ivadj].vadjOverride, 2, NULL) ) {
printf("ERROR: failed to read VADJ_%c_OVERRIDE register\n", 0x41 + ivadj);
goto lErrorExit;
}
if(dpmutilfVerbose){
printf(" VADJ_%c_OVERRIDE: 0x%04X\n", 0x41 + ivadj, pPowerInfo[ivadj].vadjOverride.fs);
printf(" ENABLE_OVERRIDE [%c]\n", pPowerInfo[ivadj].vadjOverride.fOverride ? 'Y' : 'N');
printf(" ENABLE_SUPPLY [%c]\n", pPowerInfo[ivadj].vadjOverride.fEnable ? 'Y' : 'N');
printf(" VOLTAGE_TO_SET %d mV\n", pPowerInfo[ivadj].vadjOverride.vltgSet * 10);
}
ivadj++;
if(dpmutilfVerbose){
if ( ivadj != cvadj ) {
printf("\n");
}
}
}
#if defined(__linux__)
/* Close the I2C controller file descriptor.
*/
close(fdI2c);
#endif
return fTrue;
lErrorExit:
#if defined(__linux__)
if ( 0 <= fdI2c ) {
close(fdI2c);
}
#endif
return fFalse;
}
/* ------------------------------------------------------------ */
/*** dpmutilFEnum
**
** Parameters:
** setCrcCheck - Flag to set crcCheck or not
** crcCheck - False to skip crcCheck when reading Syzygy DNA header
** pPortInfo - dpmutilPortInfo_t object array [8] to store data
**
** Return Values:
** fTrue for success, fFalse otherwise
**
** Errors:
**
** Description:
** Enumerate SmartVIO ports. This function communicates with the
** Platform MCU over the I2C bus to determine how many SmartVIO ports
** the board supports and to retrieve the configuration and status of
** those ports. If a SmartVIO port has a SYZYGY pod installed then
** the I2C bus is used to retrieve the Standard SYZYGY firmware
** registers and the SYZYGY DNA (including all string fields) and that
** information is output to the console.
*/
BOOL
dpmutilFEnum(BOOL setCrcCheck, BOOL crcCheck, dpmutilPortInfo_t pPortInfo[]) {
int fdI2c;
BYTE csvioPorts;
BYTE isvioPort;
VADJ_STATUS vadjsts;
SzgStdFwRegs szgstdfwRegs;
SzgDnaHeader szgdnaHeader;
SzgDnaStrings szgdnaStrings;
DWORD pdid;
fdI2c = -1;
memset(&szgdnaStrings, 0, sizeof(SzgDnaStrings));
#if defined(__linux__)
fdI2c = I2CHALOpenI2cController();
if ( 0 > fdI2c ) {
printf("ERROR: failed to open file descriptor for I2C device\n");
goto lErrorExit;
}
#else
if(!I2CHALInit(0)){
printf("ERROR: failed to initialize I2C device\n");
goto lErrorExit;
}
#endif
/* Get the status for all VADJ supplies.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrVadjStatus, (BYTE*)&vadjsts, 2, NULL) ) {
printf("ERROR: failed to read VADJ_STATUS register\n");
goto lErrorExit;
}
/* Determine how many SmartVIO ports the board contains.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrPortCount, &csvioPorts, 1, NULL) ) {
printf("ERROR: failed to read SMART_VIO_PORT_COUNT register\n");
goto lErrorExit;
}
if(dpmutilfVerbose)printf("Found %d SmartVIO port(s)\n", csvioPorts);
for ( isvioPort = 0; isvioPort < csvioPorts; isvioPort++ ) {
if(dpmutilfVerbose)printf("\nPort: %c\n", 0x41 + isvioPort);
/* Read and display the I2C address for this port.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrPortAI2cAddress + (offsetPortReg*isvioPort), &pPortInfo[isvioPort].i2cAddr, 1, NULL) ) {
printf("ERROR: failed to read PORT_%c_I2C_ADDRESS register\n", 0x41 + isvioPort);
goto lErrorExit;
}
if(dpmutilfVerbose)printf(" PORT_%c_I2C_ADDRESS: 0x%02X\n", 0x41 + isvioPort, pPortInfo[isvioPort].i2cAddr);
/* Read and display the 5V0 group for this port.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrPortA5v0Group + (offsetPortReg*isvioPort), &pPortInfo[isvioPort].group5v0, 1, NULL) ) {
printf("ERROR: failed to read PORT_%c_5V0_GROUP register\n", 0x41 + isvioPort);
goto lErrorExit;
}
if(dpmutilfVerbose)printf(" PORT_%c_5V0_GROUP: %d\n", 0x41 + isvioPort, pPortInfo[isvioPort].group5v0);
/* Read and display the 3V3 group for this port.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrPortA3v3Group + (offsetPortReg*isvioPort), &pPortInfo[isvioPort].group3v3, 1, NULL) ) {
printf("ERROR: failed to read PORT_%c_3V3_GROUP register\n", 0x41 + isvioPort);
goto lErrorExit;
}
if(dpmutilfVerbose)printf(" PORT_%c_3V3_GROUP: %d\n", 0x41 + isvioPort, pPortInfo[isvioPort].group3v3);
/* Read and display the VIO group for this port.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrPortAVioGroup + (offsetPortReg*isvioPort), &pPortInfo[isvioPort].groupVio, 1, NULL) ) {
printf("ERROR: failed to read PORT_%c_VIO_GROUP register\n", 0x41 + isvioPort);
goto lErrorExit;
}
if(dpmutilfVerbose)printf(" PORT_%c_VIO_GROUP: %d\n", 0x41 + isvioPort, pPortInfo[isvioPort].groupVio);
/* Read and display the port type for this port.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrPortAType + (offsetPortReg*isvioPort), &pPortInfo[isvioPort].portType, 1, NULL) ) {
printf("ERROR: failed to read PORT_%c_I2C_ADDRESS register\n", 0x41 + isvioPort);
goto lErrorExit;
}
if(dpmutilfVerbose){
printf(" PORT_%c_TYPE: 0x%02X (", 0x41 + isvioPort, pPortInfo[isvioPort].portType);
switch ( pPortInfo[isvioPort].portType ) {
case ptypeSyzygyStd:
printf("SYZYGY_STD)\n");
break;
case ptypeSyzygyTxr2:
printf("SYZYGY_TXR2)\n");
break;
case ptypeSyzygyTxr4:
printf("SYZYGY_TXR4)\n");
break;
case ptypeNone:
default:
printf("UNKNOWN)\n");
break;
}
}
/* Read and display the status for this port.
*/
if ( ! PmcuI2cRead(fdI2c, regaddrPortAStatus + (offsetPortReg*isvioPort), (BYTE*)&pPortInfo[isvioPort].portSts, 1, NULL) ) {
printf("ERROR: failed to read PORT_%c_I2C_ADDRESS register\n", 0x41 + isvioPort);
goto lErrorExit;
}
if(dpmutilfVerbose){
printf(" PORT_%c_STATUS: 0x%02X\n", 0x41 + isvioPort, *(BYTE*)&pPortInfo[isvioPort].portSts);
printf(" PRESENT [%c]\n", pPortInfo[isvioPort].portSts.fPresent ? 'Y':'N');
printf(" DOUBLE_WIDE [%c]\n", pPortInfo[isvioPort].portSts.fDW ? 'Y':'N');