11using OpenHardwareMonitor . Hardware . Memory . Sensors ;
22using RAMSPDToolkit . SPD ;
3- using RAMSPDToolkit . SPD . Enums ;
43using RAMSPDToolkit . SPD . Interfaces ;
54using RAMSPDToolkit . SPD . Interop . Shared ;
65
@@ -13,40 +12,36 @@ internal sealed class DimmMemory : Hardware
1312 public DimmMemory ( SPDAccessor accessor , string name , Identifier identifier , ISettings settings )
1413 : base ( name , identifier , settings )
1514 {
16- //Check which kind of RAM we have
17- switch ( accessor . MemoryType ( ) )
15+ //Only add thermal sensor if present
16+ if ( accessor is IThermalSensor ts && ts . HasThermalSensor )
1817 {
19- case SPDMemoryType . SPD_DDR4_SDRAM :
20- case SPDMemoryType . SPD_DDR4E_SDRAM :
21- case SPDMemoryType . SPD_LPDDR4_SDRAM :
22- case SPDMemoryType . SPD_LPDDR4X_SDRAM :
23- _thermalSensor = new SpdThermalSensor ( $ "DIMM #{ accessor . Index } ",
24- accessor . Index ,
25- SensorType . Temperature ,
26- this ,
27- settings ,
28- accessor as IThermalSensor ) ;
29-
30- break ;
31- case SPDMemoryType . SPD_DDR5_SDRAM :
32- case SPDMemoryType . SPD_LPDDR5_SDRAM :
33- //Check if we are on correct page or if write protection is not enabled
34- if ( accessor . PageData . HasFlag ( PageData . ThermalData ) || ! accessor . HasSPDWriteProtection )
35- {
18+ //Check which kind of RAM we have
19+ switch ( accessor . MemoryType ( ) )
20+ {
21+ case SPDMemoryType . SPD_DDR4_SDRAM :
22+ case SPDMemoryType . SPD_DDR4E_SDRAM :
23+ case SPDMemoryType . SPD_LPDDR4_SDRAM :
24+ case SPDMemoryType . SPD_LPDDR4X_SDRAM :
25+ case SPDMemoryType . SPD_DDR5_SDRAM :
26+ case SPDMemoryType . SPD_LPDDR5_SDRAM :
3627 _thermalSensor = new SpdThermalSensor ( $ "DIMM #{ accessor . Index } ",
3728 accessor . Index ,
3829 SensorType . Temperature ,
3930 this ,
4031 settings ,
4132 accessor as IThermalSensor ) ;
42- }
43-
44- break ;
33+ break ;
34+ }
4535 }
4636
37+ bool hasThermalSensor = _thermalSensor != null ;
38+
4739 //Add thermal sensor
48- if ( _thermalSensor != null )
40+ if ( hasThermalSensor )
4941 ActivateSensor ( _thermalSensor ) ;
42+
43+ //Add other sensors
44+ CreateSensors ( accessor , hasThermalSensor ) ;
5045 }
5146
5247 public override HardwareType HardwareType => HardwareType . Memory ;
@@ -55,4 +50,80 @@ public override void Update()
5550 {
5651 _thermalSensor ? . UpdateSensor ( ) ;
5752 }
53+
54+ private void CreateSensors ( SPDAccessor accessor , bool hasThermalSensor )
55+ {
56+ if ( accessor is DDR4Accessor ddr4 )
57+ {
58+ CreateSensorsDDR4 ( ddr4 , hasThermalSensor ) ;
59+ }
60+ else if ( accessor is DDR5Accessor ddr5 )
61+ {
62+ CreateSensorsDDR5 ( ddr5 , hasThermalSensor ) ;
63+ }
64+ }
65+
66+ private void CreateSensorsDDR4 ( DDR4Accessor accessor , bool hasThermalSensor )
67+ {
68+ if ( hasThermalSensor )
69+ {
70+ //Temperature Resolution (fixed value)
71+ AddSensor ( "Temperature Sensor Resolution" , 0 , false , SensorType . Temperature , accessor . TemperatureResolution ) ;
72+ }
73+
74+ //Timings
75+ AddSensor ( "tCKAVGmin (Minimum Cycle Time)" , 1 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumCycleTime ) ;
76+ AddSensor ( "tCKAVGmax (Maximum Cycle Time)" , 2 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MaximumCycleTime ) ;
77+ AddSensor ( "tAA (CAS Latency Time)" , 3 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumCASLatencyTime ) ;
78+ AddSensor ( "tRCD (RAS to CAS Delay Time)" , 4 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumRASToCASDelayTime ) ;
79+ AddSensor ( "tRP (Row Precharge Delay Time)" , 5 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumRowPrechargeDelayTime ) ;
80+ AddSensor ( "tRAS (Active to Precharge Delay Time)" , 6 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumActiveToPrechargeDelayTime ) ;
81+ AddSensor ( "tRC (Active to Active/Refresh Delay Time)" , 7 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumActiveToActiveRefreshDelayTime ) ;
82+ AddSensor ( "tRFC1 (Refresh Recovery Delay Time)" , 8 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumRefreshRecoveryDelayTime1 ) ;
83+ AddSensor ( "tRFC2 (Refresh Recovery Delay Time)" , 9 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumRefreshRecoveryDelayTime2 ) ;
84+ AddSensor ( "tRFC4 (Refresh Recovery Delay Time)" , 10 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumRefreshRecoveryDelayTime4 ) ;
85+ AddSensor ( "tFAW (Four Activate Window Time)" , 11 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumFourActivateWindowTime ) ;
86+ AddSensor ( "tRRD_S (Activate to Activate Delay Time)" , 12 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumActivateToActivateDelay_DiffGroup ) ;
87+ AddSensor ( "tRRD_L (Activate to Activate Delay Time)" , 13 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumActivateToActivateDelay_SameGroup ) ;
88+ AddSensor ( "tCCD_L (CAS to CAS Delay Time)" , 14 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumCASToCASDelay_SameGroup ) ;
89+ AddSensor ( "tWR (Write Recovery Time)" , 15 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumWriteRecoveryTime ) ;
90+ AddSensor ( "tWTR_S (Write to Read Time)" , 16 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumWriteToReadTime_DiffGroup ) ;
91+ AddSensor ( "tWTR_L (Write to Read Time)" , 17 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumWriteToReadTime_SameGroup ) ;
92+
93+ }
94+
95+ private void CreateSensorsDDR5 ( DDR5Accessor accessor , bool hasThermalSensor )
96+ {
97+ if ( hasThermalSensor )
98+ {
99+ //Temperature Resolution (fixed value)
100+ AddSensor ( "Temperature Sensor Resolution" , 0 , false , SensorType . Temperature , accessor . TemperatureResolution ) ;
101+ }
102+
103+ //Timings
104+ AddSensor ( "tCKAVGmin (Minimum Cycle Time)" , 1 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumCycleTime ) ;
105+ AddSensor ( "tCKAVGmax (Maximum Cycle Time)" , 2 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MaximumCycleTime ) ;
106+ AddSensor ( "tAA (CAS Latency Time)" , 3 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumCASLatencyTime ) ;
107+ AddSensor ( "tRCD (RAS to CAS Delay Time)" , 4 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumRASToCASDelayTime ) ;
108+ AddSensor ( "tRP (Row Precharge Delay Time)" , 5 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumRowPrechargeDelayTime ) ;
109+ AddSensor ( "tRAS (Active to Precharge Delay Time)" , 6 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumActiveToPrechargeDelayTime ) ;
110+ AddSensor ( "tRC (Active to Active/Refresh Delay Time)" , 7 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumActiveToActiveRefreshDelayTime ) ;
111+ AddSensor ( "tWR (Write Recovery Time)" , 8 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . MinimumWriteRecoveryTime ) ;
112+ AddSensor ( "tRFC1 (Normal Refresh Recovery Time)" , 9 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . NormalRefreshRecoveryTime ) ;
113+ AddSensor ( "tRFC2 (Fine Granularity Refresh Recovery Time)" , 10 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . FineGranularityRefreshRecoveryTime ) ;
114+ AddSensor ( "tRFCsb (Same Bank Refresh Recovery Time)" , 11 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . SameBankRefreshRecoveryTime ) ;
115+ AddSensor ( "tRFC1_dlr (Normal Refresh Recovery Time 3DS)" , 12 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . NormalRefreshRecoveryTime_3DSDifferentLogicalRank ) ;
116+ AddSensor ( "tRFC2_dlr (Fine Granularity Refresh Recovery Time 3DS)" , 13 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . FineGranularityRefreshRecoveryTime_3DSDifferentLogicalRank ) ;
117+ AddSensor ( "tRFCsb_dlr (Same Bank Refresh Recovery Time 3DS)" , 14 , false , SensorType . Timing , ( float ) accessor . SDRAMTimings . SameBankRefreshRecoveryTime_3DSDifferentLogicalRank ) ;
118+ }
119+
120+ private void AddSensor ( string name , int index , bool defaultHidden , SensorType sensorType , float value )
121+ {
122+ var sensor = new Sensor ( name , index , defaultHidden , sensorType , this , null , _settings )
123+ {
124+ Value = value ,
125+ } ;
126+
127+ ActivateSensor ( sensor ) ;
128+ }
58129}
0 commit comments