SensorMonitor.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  1. /****************************************************************
  2. ****************************************************************
  3. ** **
  4. ** (C)Copyright 2005-2006, American Megatrends Inc. **
  5. ** **
  6. ** All Rights Reserved. **
  7. ** **
  8. ** 6145-F, Northbelt Parkway, Norcross, **
  9. ** **
  10. ** Georgia - 30071, USA. Phone-(770)-246-8600. **
  11. ** **
  12. ****************************************************************
  13. *****************************************************************
  14. *
  15. * SensorMonitor.c
  16. * Sensor Monitor
  17. *
  18. * Author: Rama Rao Bisa <ramab@ami.com>
  19. *
  20. *****************************************************************/
  21. #include "MsgHndlr.h"
  22. #include "SensorEvent.h"
  23. #include "com_IPMI_SDRRecord.h"
  24. #include "Sensor.h"
  25. #include "sensor_tbl.h"
  26. #include "SEL.h"
  27. #include "Support.h"
  28. #include <time.h>
  29. #include "main.h"
  30. #include "Api.h"
  31. //#if SENSOR_DEVICE == 1
  32. /*** Local Definitions ***/
  33. #define FULL_SDR_REC 0x01
  34. #define COMPACT_SDR_REC 0x02
  35. #define EVENT_MSG_LENGTH 9
  36. #define TEMP_SENSOR_TYPE 0x01
  37. #define VOLT_SENSOR_TYPE 0x02
  38. #define FAN_SENSOR_TYPE 0x04
  39. #define POWER_SENSOR_TYPE 0x08
  40. #define CURRENT_SENSOR_TYPE 0x03
  41. #define MONITOR_ASIC_IC_SENSOR_TYPE 0x26
  42. #define OEM_SENSOR_TYPE 0xC0
  43. #define OTHER_UNITS_SENSOR_TYPE 0x0B
  44. #define LOWER_CRITICAL_GNG_LOW 0x02
  45. #define UPPER_CRITICAL_GNG_HIGH 0x09
  46. #define LOWER_NON_CRITICAL_GNG_LOW 0x00
  47. #define UPPER_NON_CRITICAL_GNG_HIGH 0x07
  48. #define LOWER_NON_RECOVERABLE_GNG_LOW 0x04
  49. #define UPPER_NON_RECOVERABLE_GNG_HIGH 0x0B
  50. /*** Prototype Declaration ***/
  51. static void MonitorTSensors ( SensorInfo_T* pSensorInfo);
  52. static void MonitorNonTSensors ( SensorInfo_T* pSensorInfo);
  53. /*-------------------------------------------
  54. * SensorMonitorTask
  55. *---------------------- --------------------*/
  56. void *SensorMonitorTask (void *pArg)
  57. {
  58. int i;
  59. SensorInfo_T* pSensorInfo;
  60. SensorSharedMem_T* pSMSharedMem;
  61. printf("SensorMonitorTask start...\r\n");
  62. g_BMCInfo.SenConfig.MonitorBusy = 0;
  63. g_BMCInfo.SenConfig.InitAgentRearm = FALSE;
  64. /* Get the Sensor Shared Memory */
  65. pSMSharedMem = ( SensorSharedMem_T*)&g_BMCInfo.SensorSharedMem;
  66. g_BMCInfo.SenConfig.ValidSensorCnt = SENSOR_NUMBERS;
  67. InitSensorInfo ();
  68. InitSensorDev();
  69. pSMSharedMem->GlobalSensorScanningEnable = TRUE;
  70. pSMSharedMem->SensorTick = 0;
  71. while (1)
  72. {
  73. g_BMCInfo.SenConfig.InitAgentRearm = FALSE;
  74. /* Monitor all sensors */
  75. for (i = 0; i < g_BMCInfo.SenConfig.ValidSensorCnt; i++)
  76. {
  77. /* Check if Global Scanning Enabled or Disabled */
  78. if (pSMSharedMem->GlobalSensorScanningEnable)
  79. {
  80. pSensorInfo = (SensorInfo_T *)&pSMSharedMem->SensorInfo [i];
  81. //printf("sensor number: %d, RecordID: %d\n", pSensorInfo->SensorNumber, pSensorInfo->RecordID);
  82. /* Monitoring cycle */
  83. if (THRESHOLD_SENSOR_CLASS == pSensorInfo->EventTypeCode)
  84. {
  85. if ((0 == (pSMSharedMem->SensorTick % pSensorInfo->SensorMonitorInterval)) &&
  86. (g_BMCInfo.SenConfig.PowerOnTick >= pSensorInfo->PowerOnDelay) &&
  87. (g_BMCInfo.SenConfig.SysResetTick >= pSensorInfo->SysResetDelay))
  88. {
  89. /* Clear the Error status for this scan */
  90. pSensorInfo->Err = 0;
  91. /* Monitor threshold sensor */
  92. MonitorTSensors (pSensorInfo);
  93. }
  94. }
  95. else
  96. {
  97. if ((0 == (pSMSharedMem->SensorTick % pSensorInfo->SensorMonitorInterval)) &&
  98. (g_BMCInfo.SenConfig.PowerOnTick >= pSensorInfo->PowerOnDelay) &&
  99. (g_BMCInfo.SenConfig.SysResetTick >= pSensorInfo->SysResetDelay))
  100. {
  101. /* Clear the Error status for this scan */
  102. pSensorInfo->Err = 0;
  103. /* Monitor Non threshold sensor */
  104. MonitorNonTSensors (pSensorInfo);
  105. }
  106. }
  107. }
  108. }
  109. g_BMCInfo.SenConfig.MonitorBusy = 0;
  110. sleep(1);
  111. }
  112. }
  113. // Return a high deassertion threshold.
  114. // This routine takes into account signed sensors as well as
  115. // values wrapping around boundaries.
  116. static
  117. int16_t GetHighDeassertValue(uint8_t IsSigned, int16_t Value, uint8_t Hysteresis)
  118. {
  119. int16_t deassertValue = (Value - Hysteresis);
  120. if (FALSE == IsSigned)
  121. {
  122. if (deassertValue < 0)
  123. deassertValue = 0;
  124. }
  125. else
  126. {
  127. if (deassertValue < -128)
  128. deassertValue = -128;
  129. }
  130. return deassertValue;
  131. }
  132. // Return a low deassertion threshold.
  133. // This routine takes into account signed sensors as well as
  134. // values wrapping around boundaries.
  135. static
  136. int16_t GetLowDeassertValue(uint8_t IsSigned, int16_t Value, uint8_t Hysteresis)
  137. {
  138. int16_t deassertValue = (Value + Hysteresis);
  139. if (FALSE == IsSigned)
  140. {
  141. if (deassertValue > 255)
  142. deassertValue = 255;
  143. }
  144. else
  145. {
  146. if (deassertValue > 127)
  147. deassertValue = 127;
  148. }
  149. return deassertValue;
  150. }
  151. /**
  152. * @brief Monitor Threshold sensors.
  153. * @param i - Sensor index.
  154. **/
  155. static void
  156. MonitorTSensors ( SensorInfo_T* pSensorInfo)
  157. {
  158. uint8_t EventData1;
  159. uint8_t EventData3;
  160. uint8_t EvData1;
  161. uint8_t SendDeassertion;
  162. uint8_t SendAssertion;
  163. uint8_t EventMsg [EVENT_MSG_LENGTH];
  164. uint8_t Level;
  165. uint8_t HealthLevel;
  166. uint8_t StartLevel;
  167. int16_t Value;
  168. uint8_t AssertionEventOccuredByte1;
  169. uint8_t AssertionEventOccuredByte2;
  170. uint8_t DeassertionEventOccuredByte1;
  171. uint8_t DeassertionEventOccuredByte2;
  172. uint8_t DeassertionEventEnablesByte1;
  173. uint8_t DeassertionEventEnablesByte2;
  174. uint8_t AssertionEventEnablesByte1;
  175. uint8_t AssertionEventEnablesByte2;
  176. int16_t WarningLow;
  177. int16_t WarningHigh;
  178. uint8_t NegHysteresis;
  179. uint8_t PosHysteresis;
  180. int16_t CriticalHigh;
  181. int16_t CriticalLow;
  182. int16_t NonRecoverableHigh;
  183. int16_t NonRecoverableLow;
  184. // uint8_t SensorLevel;
  185. uint8_t SettableThreshMask;
  186. uint8_t SensorReading;
  187. uint8_t PSGood = 0;
  188. uint8_t AssertionHistoryByte1;
  189. uint8_t AssertionHistoryByte2;
  190. uint8_t DeassertionHistoryByte1;
  191. uint8_t DeassertionHistoryByte2;
  192. uint8_t OEMField;
  193. // uint8_t SensorNum;
  194. uint8_t SignedSensor = 0; // 1 if sensor has signed values
  195. int16_t SensorMax = 255;
  196. int16_t SensorMin = 0;
  197. //uint16_t_t OrgSensorValue;
  198. int16_t DeassertThreshold;
  199. // Added for Sensor Override capability
  200. // int Override = 0;
  201. // uint8_t ReadFlags = 0;
  202. // FullSensorRec_T* sfs=NULL;
  203. // CompactSensorRec_T* scs=NULL;
  204. // int index,j;
  205. PSGood = g_BMCInfo.PowerGoodFlag;
  206. /* If sensor is not need to monitor on stand by power, and if Server */
  207. /* is power off then return setting error "sensor not acceble at present state" */
  208. if (( 0 == (pSensorInfo->SensorState & 0x1) ) && ( 0 == PSGood))
  209. {
  210. // Response cannot be provided in this state
  211. pSensorInfo->Err = CC_PARAM_NOT_SUP_IN_CUR_STATE ;
  212. pSensorInfo->EventFlags |= BIT5;
  213. return;
  214. }
  215. else
  216. {
  217. pSensorInfo->Err = get_sensor_reading(pSensorInfo->SensorNumber, &SensorReading);
  218. // if (FULL_SDR_REC == pSensorInfo->SDRRec->Type)
  219. // {
  220. // sfs = ( FullSensorRec_T*)pSensorInfo->SDRRec;
  221. // }
  222. // else if (COMPACT_SDR_REC==pSensorInfo->SDRRec->Type)
  223. // {
  224. // scs = ( CompactSensorRec_T*)pSensorInfo->SDRRec;
  225. // }
  226. pSensorInfo->SensorReading = SensorReading;
  227. // //keep sensor history
  228. // index = getSensorIndex(pSensorInfo->SensorNumber);
  229. // if((index >= 0) && (g_BMCInfo.CurTimerSecond%180 == 0) && (g_sensorList[index].supportHistory == 1)) //3 minutes
  230. // {
  231. // for(j=1;j<HISTORY_DATA_SIZE;j++)
  232. // {
  233. // g_sensorHistory[index][j-1] = g_sensorHistory[index][j];
  234. // }
  235. // g_sensorHistory[index][HISTORY_DATA_SIZE-1] = pSensorInfo->SensorReading;
  236. // }
  237. }
  238. if (0 == pSensorInfo->Err)
  239. {
  240. pSensorInfo->EventFlags &= ~BIT5;
  241. }
  242. else
  243. {
  244. pSensorInfo->EventFlags |= BIT5;
  245. }
  246. do
  247. {
  248. EvData1 = 0;
  249. EventData1 = 0;
  250. EventData3 = 0;
  251. SendDeassertion = 0;
  252. SendAssertion = 0;
  253. //SensorLevel = 0;
  254. Level = pSensorInfo->EventLevel;
  255. Value = pSensorInfo->SensorReading;
  256. AssertionEventOccuredByte1 = pSensorInfo->AssertionEventOccuredByte1;
  257. AssertionEventOccuredByte2 = pSensorInfo->AssertionEventOccuredByte2;
  258. DeassertionEventOccuredByte1 = pSensorInfo->DeassertionEventOccuredByte1;
  259. DeassertionEventOccuredByte2 = pSensorInfo->DeassertionEventOccuredByte2;
  260. AssertionEventEnablesByte1 = pSensorInfo->AssertionEventEnablesByte1;
  261. AssertionEventEnablesByte2 = pSensorInfo->AssertionEventEnablesByte2;
  262. DeassertionEventEnablesByte1 = pSensorInfo->DeassertionEventEnablesByte1;
  263. DeassertionEventEnablesByte2 = pSensorInfo->DeassertionEventEnablesByte2;
  264. WarningLow = pSensorInfo->LowerNonCritical;
  265. WarningHigh = pSensorInfo->UpperNonCritical;
  266. NegHysteresis = pSensorInfo->NegHysteresis;
  267. PosHysteresis = pSensorInfo->PosHysteresis;
  268. CriticalHigh = pSensorInfo->UpperCritical;
  269. CriticalLow = pSensorInfo->LowerCritical;
  270. NonRecoverableHigh = pSensorInfo->UpperNonRecoverable;
  271. NonRecoverableLow = pSensorInfo->LowerNonRecoverable;
  272. OEMField = pSensorInfo->OEMField;
  273. // SensorNum = pSensorInfo->SensorNumber;
  274. if(1==OEMField)
  275. {
  276. SensorAverage(pSensorInfo->SensorNumber, &pSensorInfo->SensorReading);
  277. }
  278. SettableThreshMask = (uint8_t)(pSensorInfo->SettableThreshMask >> 8);
  279. SignedSensor = (0 != (pSensorInfo->Units1 & 0xC0)); //Analog data format
  280. if (SignedSensor)
  281. {
  282. // These are max and min sensor readings for a signed sensor
  283. SensorMax = 127;
  284. SensorMin = -128;
  285. //
  286. // All Thresholds and the sensor value need to be sign extended to 16 bits
  287. // for signed sensors (if the value is negative).
  288. //
  289. WarningLow = (int16_t)((int8_t)pSensorInfo->LowerNonCritical);
  290. WarningHigh = (int16_t)((int8_t)pSensorInfo->UpperNonCritical);
  291. CriticalHigh = (int16_t)((int8_t)pSensorInfo->UpperCritical);
  292. CriticalLow = (int16_t)((int8_t)pSensorInfo->LowerCritical);
  293. NonRecoverableHigh = (int16_t)((int8_t)pSensorInfo->UpperNonRecoverable);
  294. NonRecoverableLow = (int16_t)((int8_t)pSensorInfo->LowerNonRecoverable);
  295. Value = (int16_t)((int8_t)pSensorInfo->SensorReading);
  296. }
  297. //
  298. // For unused thresholds, set them to a value that the sensor value cannot
  299. // have in an 8 bit value so no match can happen.
  300. //
  301. if (0 == (SettableThreshMask & BIT5))
  302. {
  303. // Set to a value that the sensor cannot have
  304. NonRecoverableHigh = SensorMax + 1;
  305. }
  306. if (0 == (SettableThreshMask & BIT2))
  307. {
  308. // Set to a value that the sensor cannot have
  309. NonRecoverableLow = SensorMin - 1;
  310. }
  311. if (0 == (SettableThreshMask & BIT4))
  312. {
  313. CriticalHigh = NonRecoverableHigh;
  314. }
  315. if (0 == (SettableThreshMask & BIT1))
  316. {
  317. CriticalLow = NonRecoverableLow;
  318. }
  319. if (0 == (SettableThreshMask & BIT3))
  320. {
  321. WarningHigh = CriticalHigh;
  322. }
  323. if (0 == (SettableThreshMask & BIT0))
  324. {
  325. WarningLow = CriticalLow;
  326. }
  327. StartLevel = Level;
  328. switch (Level)
  329. {
  330. case SENSOR_STATUS_NORMAL:
  331. if (Value <= WarningLow)
  332. {
  333. //sensor_dbg_printf("#%02x LNC(A) - Value: %02x Threshold: %02x\r\n", (pSensorInfo->SensorNumber), (uint8_t)Value, (uint8_t)WarningLow);
  334. /* deassert WarningLow going High */
  335. EvData1 = 0x51;
  336. if (DeassertionEventEnablesByte1 & 0x02)
  337. {
  338. SendDeassertion = 1;
  339. }
  340. /* remove WarnignLow going Low deassertion */
  341. DeassertionEventOccuredByte1 &= ~0x01;
  342. /* deassert WarningLow going High */
  343. DeassertionEventOccuredByte1 |= 0x02;
  344. /* assert WarningLow going Low */
  345. EventData1 = 0x50;
  346. if(AssertionEventEnablesByte1 & 0x01)
  347. {
  348. SendAssertion = 1;
  349. }
  350. Level = SENSOR_STATUS_WARNING_LOW;
  351. EventData3 = WarningLow;
  352. /* set de/assertion event */
  353. /* remove WarningLow going High assertion */
  354. AssertionEventOccuredByte1 &= ~0x02;
  355. /* assert WarningLow going Low */
  356. AssertionEventOccuredByte1 |= 0x01;
  357. //SensorLevel = LWR_NON_CRITICAL_GOING_LOW_CTRL_FN;
  358. }
  359. if (Value >= WarningHigh)
  360. {
  361. //sensor_dbg_printf("#%02x UNC(A) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)WarningHigh);
  362. /* deassert WarningHigh going Low */
  363. EvData1 = 0x56;
  364. if (DeassertionEventEnablesByte1 & 0x40)
  365. {
  366. SendDeassertion = 1;
  367. }
  368. /* remove WarningHigh going High deassertion */
  369. DeassertionEventOccuredByte1 &= ~0x80;
  370. /* deassert WarningHigh going Low */
  371. DeassertionEventOccuredByte1 |= 0x40;
  372. /* assert WarningHigh going High */
  373. EventData1 = 0x57;
  374. if (AssertionEventEnablesByte1 & 0x80)
  375. {
  376. SendAssertion = 1;
  377. }
  378. /* set de/assertion occured */
  379. /* remove WarningHigh going Low assertion */
  380. AssertionEventOccuredByte1 &= ~0x40;
  381. /* assert WarningHigh going High */
  382. AssertionEventOccuredByte1 |= 0x80;
  383. Level = SENSOR_STATUS_WARNING_HIGH;
  384. /* Threshold that caused event */
  385. EventData3 = WarningHigh;
  386. //SensorLevel = UPPER_NON_CRITICAL_GOING_HIGH_CTRL_FN;
  387. }
  388. break;
  389. case SENSOR_STATUS_WARNING_HIGH:
  390. DeassertThreshold = GetHighDeassertValue(SignedSensor, WarningHigh, PosHysteresis);
  391. if(Value < DeassertThreshold)
  392. {
  393. //sensor_dbg_printf("#%02x UNC(D) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)DeassertThreshold);
  394. /* deassert WarningHigh going High */
  395. EvData1 = 0x57;
  396. if (DeassertionEventEnablesByte1 & 0x80)
  397. {
  398. SendDeassertion = 1;
  399. }
  400. /* remove WarningHigh going Low deassertion */
  401. DeassertionEventOccuredByte1 &= ~0x40;
  402. /* deassert WarningHigh going High */
  403. DeassertionEventOccuredByte1 |= 0x80;
  404. /* assert WaningHigh going Low */
  405. EventData1 = 0x56;
  406. if (AssertionEventEnablesByte1 & 0x40)
  407. {
  408. SendAssertion = 1;
  409. }
  410. Level = SENSOR_STATUS_NORMAL;
  411. EventData3 = WarningHigh;
  412. /* remove WarningHigh going High assertion */
  413. AssertionEventOccuredByte1 &= ~0x80;
  414. /* assert WarningHigh going Low */
  415. AssertionEventOccuredByte1 |= 0x40;
  416. //SensorLevel = UPPER_NON_CRITICAL_GOING_LOW_CTRL_FN;
  417. }
  418. if (Value >= CriticalHigh)
  419. {
  420. //sensor_dbg_printf("#%02x UC(A) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)CriticalHigh);
  421. /* deassert CriticalHigh going Low */
  422. EvData1 = 0x58;
  423. if (DeassertionEventEnablesByte2 & 0x01)
  424. {
  425. SendDeassertion = 1;
  426. }
  427. /* remove CriticalHigh going High deassertion */
  428. DeassertionEventOccuredByte2 &= ~0x02;
  429. /* deassert CriticalHigh going Low */
  430. DeassertionEventOccuredByte2 |= 0x01;
  431. /* assert CriticalHigh going High */
  432. EventData1 = 0x59;
  433. if (AssertionEventEnablesByte2 & 0x02)
  434. {
  435. SendAssertion = 1;
  436. }
  437. Level = SENSOR_STATUS_CRITICAL_HIGH;
  438. EventData3 = CriticalHigh;
  439. /* set de/assertion event occured */
  440. /* remove CriticalHigh going Low assertion */
  441. AssertionEventOccuredByte2 &= ~0x01;
  442. /* assert CriticalHigh going High */
  443. AssertionEventOccuredByte2 |= 0x02;
  444. //SensorLevel = UPPER_CRITICAL_GOING_HIGH_CTRL_FN;
  445. }
  446. break;
  447. case SENSOR_STATUS_WARNING_LOW:
  448. DeassertThreshold = GetLowDeassertValue(SignedSensor, WarningLow, NegHysteresis);
  449. if (Value > DeassertThreshold)
  450. {
  451. //sensor_dbg_printf("#%02x LNC(D) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)DeassertThreshold);
  452. /* deassert WarningLow going Low */
  453. EvData1 = 0x50;
  454. if (DeassertionEventEnablesByte1 & 0x01)
  455. {
  456. SendDeassertion = 1;
  457. }
  458. /* remove WarningLow going High deassertion */
  459. DeassertionEventOccuredByte1 &= ~0x02;
  460. /* deassert WarningLow going Low */
  461. DeassertionEventOccuredByte1 |= 0x01;
  462. /* assert WarningLow going High */
  463. EventData1 = 0x51;
  464. if (AssertionEventEnablesByte1 & 0x02)
  465. {
  466. SendAssertion = 1;
  467. }
  468. Level = SENSOR_STATUS_NORMAL;
  469. EventData3 = WarningLow;
  470. /* set de/assertion event */
  471. /* remove WarningLow going Low assertion */
  472. AssertionEventOccuredByte1 &= ~0x01;
  473. /* assert WarningLow going High */
  474. AssertionEventOccuredByte1 |= 0x02;
  475. //SensorLevel = LWR_NON_CRITICAL_GOING_HIGH_CTRL_FN;
  476. }
  477. if (Value <= CriticalLow)
  478. {
  479. //sensor_dbg_printf("#%02x LC(A) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)CriticalLow);
  480. /* deassert CriticalLow going High */
  481. EvData1 = 0x53;
  482. if (DeassertionEventEnablesByte1 & 0x08)
  483. {
  484. SendDeassertion = 1;
  485. }
  486. /* remove CriticalLow going Low deassertion */
  487. DeassertionEventOccuredByte1 &= ~0x04;
  488. /* deassert CriticalHigh going High */
  489. DeassertionEventOccuredByte1 |= 0x08;
  490. /* assert CriticalLow going Low */
  491. EventData1 = 0x52;
  492. if (AssertionEventEnablesByte1 & 0x04)
  493. {
  494. SendAssertion = 1;
  495. }
  496. Level = SENSOR_STATUS_CRITICAL_LOW;
  497. EventData3 = CriticalLow;
  498. /* remove CriticalLow going High assertion */
  499. AssertionEventOccuredByte1 &= ~0x08;
  500. /* assert CriticalLow going Low */
  501. AssertionEventOccuredByte1 |= 0x04;
  502. //SensorLevel = LWR_CRITICAL_GOING_LOW_CTRL_FN;
  503. }
  504. break;
  505. case SENSOR_STATUS_CRITICAL_HIGH:
  506. DeassertThreshold = GetHighDeassertValue(SignedSensor, CriticalHigh, PosHysteresis);
  507. if (Value < DeassertThreshold)
  508. {
  509. //sensor_dbg_printf("#%02x UC(D) - Value: %02x Threshold: %02x\n",pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)DeassertThreshold);
  510. /* deassert CriticalHigh going High */
  511. EvData1 = 0x59;
  512. if (DeassertionEventEnablesByte2 & 0x02)
  513. {
  514. SendDeassertion = 1;
  515. }
  516. /* remove CriticalHigh going Low deassertion */
  517. DeassertionEventOccuredByte2 &= ~0x01;
  518. /* deassert CriticalHigh going High */
  519. DeassertionEventOccuredByte2 |= 0x02;
  520. /* assert CriticalHigh going Low */
  521. EventData1 = 0x58;
  522. if (AssertionEventEnablesByte2 & 0x01)
  523. {
  524. SendAssertion = 1;
  525. }
  526. Level = SENSOR_STATUS_WARNING_HIGH;
  527. EventData3 = CriticalHigh;
  528. /* set de/assertion event occured */
  529. /* remove CriticalHigh going High assertion */
  530. AssertionEventOccuredByte2 &= ~0x02;
  531. /* assert CriticalHigh going Low */
  532. AssertionEventOccuredByte2 |= 0x01;
  533. //SensorLevel = UPPER_CRITICAL_GOING_LOW_CTRL_FN;
  534. }
  535. if (Value >= NonRecoverableHigh)
  536. {
  537. //sensor_dbg_printf("#%02x UNR(A) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)NonRecoverableHigh);
  538. /* deassert NonRecoverableHigh going Low */
  539. EvData1 = 0x5A;
  540. if (DeassertionEventEnablesByte2 & 0x04)
  541. {
  542. SendDeassertion = 1;
  543. }
  544. /* remove NonRecoverableHigh going High deassertion */
  545. DeassertionEventOccuredByte2 &= ~0x08;
  546. /* deassert NonRecoverableHigh going Low */
  547. DeassertionEventOccuredByte2 |= 0x04;
  548. /* assert NonRecoverableHigh going High */
  549. EventData1 = 0x5B;
  550. if (AssertionEventEnablesByte2 & 0x08)
  551. {
  552. SendAssertion = 1;
  553. }
  554. Level = SENSOR_STATUS_NONRECOVERABLE_HIGH;
  555. EventData3 = NonRecoverableHigh;
  556. /* remove NonRecoverableHigh going Low assertion */
  557. AssertionEventOccuredByte2 &= ~0x04;
  558. /* assert NonRecoverableHigh going High */
  559. AssertionEventOccuredByte2 |= 0x08;
  560. //SensorLevel = UPPER_NON_RECOVERABLE_GOING_HIGH_CTRL_FN;
  561. }
  562. break;
  563. case SENSOR_STATUS_CRITICAL_LOW:
  564. DeassertThreshold = GetLowDeassertValue(SignedSensor, CriticalLow, NegHysteresis);
  565. if (Value > DeassertThreshold)
  566. {
  567. //sensor_dbg_printf("#%02x LC(D) - Value: %02x Threshold: %02x\n",pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)DeassertThreshold);
  568. /* deassert CriticalLow going Low */
  569. EvData1 = 0x52;
  570. if (DeassertionEventEnablesByte1 & 0x04)
  571. {
  572. SendDeassertion = 1;
  573. }
  574. /* remove CriticalLow going High deassertion */
  575. DeassertionEventOccuredByte1 &= ~0x08;
  576. /* deassert CriticalLow going Low */
  577. DeassertionEventOccuredByte1 |= 0x04;
  578. /* assert CriticalLow going High */
  579. EventData1 = 0x53;
  580. if (AssertionEventEnablesByte1 & 0x08)
  581. {
  582. SendAssertion = 1;
  583. }
  584. Level = SENSOR_STATUS_WARNING_LOW;
  585. EventData3 = CriticalLow;
  586. /* remove CriticalLow going Low assertion */
  587. AssertionEventOccuredByte1 &= ~0x04;
  588. /* assert CriticalLow going High */
  589. AssertionEventOccuredByte1 |= 0x08;
  590. //SensorLevel = LWR_CRITICAL_GOING_HIGH_CTRL_FN;
  591. }
  592. if (Value <= NonRecoverableLow)
  593. {
  594. //sensor_dbg_printf("#%02x LNR(A) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)NonRecoverableLow);
  595. /* deassert NonRecoverableLow going High */
  596. EvData1 = 0x55;
  597. if (DeassertionEventEnablesByte1 & 0x20)
  598. {
  599. SendDeassertion = 1;
  600. }
  601. /* remove NonRecoverableLow going Low deassertion */
  602. DeassertionEventOccuredByte1 &= ~0x10;
  603. /* deassert NonRecoverableLow going High */
  604. DeassertionEventOccuredByte1 |= 0x20;
  605. /* assert NonRecoverableLow going Low */
  606. EventData1 = 0x54;
  607. if (AssertionEventEnablesByte1 & 0x10)
  608. {
  609. SendAssertion = 1;
  610. }
  611. Level = SENSOR_STATUS_NONRECOVERABLE_LOW;
  612. EventData3 = NonRecoverableLow;
  613. /* remove NonRecoverableLow going High assertion */
  614. AssertionEventOccuredByte1 &= ~0x20;
  615. /* assert NonRecoverableLow going Low */
  616. AssertionEventOccuredByte1 |= 0x10;
  617. //SensorLevel = LWR_NON_RECOVERABLE_GOING_LOW_CTRL_FN;
  618. }
  619. break;
  620. case SENSOR_STATUS_NONRECOVERABLE_HIGH:
  621. DeassertThreshold = GetHighDeassertValue(SignedSensor, NonRecoverableHigh, PosHysteresis);
  622. if (Value < DeassertThreshold)
  623. {
  624. //sensor_dbg_printf("#%02x UNR(D) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)DeassertThreshold);
  625. /* deassert NonRecoverableHigh going High */
  626. EvData1 = 0x5B;
  627. if (DeassertionEventEnablesByte2 & 0x08)
  628. {
  629. SendDeassertion = 1;
  630. }
  631. /* remove NonRecoverableHigh going Low deassertion */
  632. DeassertionEventOccuredByte2 &= ~0x04;
  633. /* deassert NonRecoverableHigh going High */
  634. DeassertionEventOccuredByte2 |= 0x08;
  635. /* assert NonRecoverableHigh going Low */
  636. EventData1 = 0x5A;
  637. if (AssertionEventEnablesByte2 & 0x04)
  638. {
  639. SendAssertion = 1;
  640. }
  641. Level = SENSOR_STATUS_CRITICAL_HIGH;
  642. EventData3 = NonRecoverableHigh;
  643. /* remove NonRecoverableHigh going High assertion */
  644. AssertionEventOccuredByte2 &= ~0x08;
  645. /* assert NonRecoverableHigh going Low */
  646. AssertionEventOccuredByte2 |= 0x04;
  647. //SensorLevel = UPPER_NON_RECOVERABLE_GOING_LOW_CTRL_FN;
  648. }
  649. break;
  650. case SENSOR_STATUS_NONRECOVERABLE_LOW:
  651. DeassertThreshold = GetLowDeassertValue(SignedSensor, NonRecoverableLow, NegHysteresis);
  652. if (Value > DeassertThreshold)
  653. {
  654. //sensor_dbg_printf("#%02x LNR(D) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)DeassertThreshold);
  655. /* deassert NonRecoverableLow going Low */
  656. EvData1 = 0x54;
  657. if (DeassertionEventEnablesByte1 & 0x10)
  658. {
  659. SendDeassertion = 1;
  660. }
  661. /* remove NonRecoverableLow going High deassertion */
  662. DeassertionEventOccuredByte1 &= ~0x20;
  663. /* deassert NonRecoverableLow going Low */
  664. DeassertionEventOccuredByte1 |= 0x10;
  665. /* assert NonRecoverableLow going High */
  666. EventData1 = 0x55;
  667. if (AssertionEventEnablesByte1 & 0x20)
  668. {
  669. SendAssertion = 1;
  670. }
  671. Level = SENSOR_STATUS_CRITICAL_LOW;
  672. EventData3 = NonRecoverableLow;
  673. /* remove NonRecoverableLow going Low assertion */
  674. AssertionEventOccuredByte1 &= ~0x10;
  675. /* assert NonRecoverableLow going High */
  676. AssertionEventOccuredByte1 |= 0x20;
  677. //SensorLevel = LWR_NON_RECOVERABLE_GOING_HIGH_CTRL_FN;
  678. }
  679. break;
  680. case SENSOR_STATUS_FATAL:
  681. break;
  682. } /* switch(m_SensorEventLevel[i]) */
  683. pSensorInfo->EventLevel = Level;
  684. pSensorInfo->AssertionEventOccuredByte1 = AssertionEventOccuredByte1;
  685. pSensorInfo->AssertionEventOccuredByte2 = AssertionEventOccuredByte2;
  686. pSensorInfo->DeassertionEventOccuredByte1 = DeassertionEventOccuredByte1;
  687. pSensorInfo->DeassertionEventOccuredByte2 = DeassertionEventOccuredByte2;
  688. AssertionHistoryByte1 = 0;
  689. AssertionHistoryByte2 = 0;
  690. DeassertionHistoryByte1 = 0;
  691. DeassertionHistoryByte2 = 0;
  692. //TODO: post event message to SEL Task.
  693. EventMsg [0] = 0x20;
  694. EventMsg [1] = (pSensorInfo->SensorOwnerLun & 0x03); /* Multi-LUN support */
  695. /* EvMRev */
  696. EventMsg [2] = IPMI_EVM_REVISION;
  697. /* sensor type */
  698. EventMsg [3] = pSensorInfo->SensorTypeCode;
  699. /* sensor number */
  700. EventMsg [4] = pSensorInfo->SensorNumber;
  701. /* event direction|type */
  702. EventMsg [5] = 0x01;
  703. EventMsg [6] = 0;
  704. /* Set Sensor Event Data based on the Operation byte */
  705. switch (pSensorInfo->Operation>>6)
  706. {
  707. case WRITE_NO_EVTDATA1:
  708. /* Event Data 1 */
  709. EventMsg [6] = pSensorInfo->EvtData1;
  710. /* Intentional Fall thru */
  711. case WRITE_EVTDATA1:
  712. /* Event Data 1 */
  713. EventMsg [6] |= EventData1;
  714. /* Update EvtData fields */
  715. /* Current Reading */
  716. EventMsg [7] = pSensorInfo->EvtData2;
  717. /* Trigger that caused event */
  718. EventMsg [8] = pSensorInfo->EvtData3;
  719. break;
  720. case USE_SM_EVTDATA:
  721. /* Event Data 1 */
  722. EventMsg [6] = EventData1;
  723. /* Current Reading */
  724. EventMsg [7] = Value;
  725. /* Trigger that caused event */
  726. EventMsg [8] = EventData3;
  727. break;
  728. }
  729. if (SendAssertion)
  730. {
  731. if ((EventData1 & 0x0f) < 8)
  732. {
  733. AssertionHistoryByte1 = (1 << (EventData1 & 0x0f));
  734. }
  735. else
  736. {
  737. AssertionHistoryByte2 = (1 << ((EventData1 & 0x0f) - 8));
  738. }
  739. /* For Manual Rearm Sensor - Check for already generated events in the History bytes
  740. For Auto Rearm Sensor -History bytes are not valid */
  741. if ( (0 == (AssertionHistoryByte1 & pSensorInfo->AssertionHistoryByte1)) &&
  742. (0 == (AssertionHistoryByte2 & pSensorInfo->AssertionHistoryByte2)) )
  743. {
  744. /* if sensor is manual arming */
  745. if (0 == (pSensorInfo->SensorCaps & BIT6))
  746. {
  747. /* Update assertion History */
  748. pSensorInfo->AssertionHistoryByte1 |= AssertionHistoryByte1;
  749. pSensorInfo->AssertionHistoryByte2 |= AssertionHistoryByte2;
  750. }
  751. /* Is event message generation enabled ? */
  752. if (0 != (pSensorInfo->EventFlags & BIT7))
  753. {
  754. /* Post Event Message */
  755. PostEventMessage (EventMsg, sizeof (EventMsg));
  756. }
  757. }
  758. SendAssertion = 0;
  759. }
  760. if (SendDeassertion)
  761. {
  762. if ((EvData1 & 0x0f) < 8)
  763. {
  764. DeassertionHistoryByte1 = (1 << (EvData1 & 0x0f));
  765. }
  766. else
  767. {
  768. DeassertionHistoryByte2 = (1 << ((EvData1 & 0x0f) - 8));
  769. }
  770. /* For Manual Rearm Sensor - Check for already generated events in the History bytes
  771. For Auto Rearm Sensor -History bytes are not valid */
  772. if ( (0 == (DeassertionHistoryByte1 & pSensorInfo->DeassertionHistoryByte1)) &&
  773. (0 == (DeassertionHistoryByte2 & pSensorInfo->DeassertionHistoryByte2)) )
  774. {
  775. /* Event Data 1 */
  776. EventMsg [6] = EvData1;
  777. EventMsg [5] = 0x81;
  778. /* if sensor is manual arming */
  779. if (0 == (pSensorInfo->SensorCaps & BIT6))
  780. {
  781. /* Update Deassertion History */
  782. pSensorInfo->DeassertionHistoryByte1 |= DeassertionHistoryByte1;
  783. pSensorInfo->DeassertionHistoryByte2 |= DeassertionHistoryByte2;
  784. }
  785. /* Call PreEventLog hook function(s) and don't do
  786. sensor SEL event log if the return is not zero */
  787. if (0 != (pSensorInfo->EventFlags & BIT7))
  788. {
  789. /* Post Event Message Here */
  790. PostEventMessage (EventMsg, sizeof (EventMsg));
  791. }
  792. }
  793. SendDeassertion = 0;
  794. }
  795. }while (StartLevel != Level);
  796. /* Auto Rearm sensor: Get current assertions */
  797. AssertionHistoryByte1 = pSensorInfo->AssertionEventOccuredByte1;
  798. AssertionHistoryByte2 = pSensorInfo->AssertionEventOccuredByte2;
  799. // The following checks need to be done from lowest severity to highest.
  800. HealthLevel = SENSOR_STATUS_NORMAL;
  801. if (0 != (AssertionHistoryByte1 & 0x01 & AssertionEventEnablesByte1))
  802. HealthLevel = SENSOR_STATUS_WARNING_LOW;
  803. if (0 != (AssertionHistoryByte1 & 0x80 & AssertionEventEnablesByte1))
  804. HealthLevel = SENSOR_STATUS_WARNING_HIGH;
  805. if (0 != (AssertionHistoryByte1 & 0x04 & AssertionEventEnablesByte1))
  806. HealthLevel = SENSOR_STATUS_CRITICAL_LOW;
  807. if (0 != (AssertionHistoryByte2 & 0x02 & AssertionEventEnablesByte2))
  808. HealthLevel = SENSOR_STATUS_CRITICAL_HIGH;
  809. if (0 != (AssertionHistoryByte1 & 0x10 & AssertionEventEnablesByte1))
  810. HealthLevel = SENSOR_STATUS_NONRECOVERABLE_LOW;
  811. if (0 != (AssertionHistoryByte2 & 0x08 & AssertionEventEnablesByte2))
  812. HealthLevel = SENSOR_STATUS_NONRECOVERABLE_HIGH;
  813. pSensorInfo->HealthLevel = HealthLevel;
  814. // Make sure the "Reading Not Available" bit is clear.
  815. pSensorInfo->EventFlags &= ~BIT5;
  816. }
  817. /**
  818. * @brief Monitor Non-threshold sensors.
  819. * @param i - Sensor index.
  820. */
  821. static void
  822. MonitorNonTSensors ( SensorInfo_T* pSensorInfo)
  823. {
  824. //TODO:
  825. printf("MonitorNonTSensors: not implement\r\n");
  826. }
  827. /**
  828. * @fn hal_read_sensor
  829. * @brief This function reads the sensor reading for given sensor number
  830. *
  831. **/
  832. int get_sensor_reading (uint8_t sensor_num, uint8_t *preading)
  833. {
  834. sensor_tbl_t *pdev_tbl;
  835. pdev_tbl = (sensor_tbl_t*)getSensorDev (sensor_num);
  836. if (pdev_tbl == NULL)
  837. {
  838. printf ("Error: couldn't find sensor %x\n", sensor_num);
  839. return 1;
  840. }
  841. /* Execute at the requested sensor reading handler */
  842. if (0 != pdev_tbl->device_read (preading))
  843. {
  844. printf ("Error executing read function\n");
  845. return -1;
  846. }
  847. // sensor_dbg_printf ("sensor number %x reading = %x\r\n", sensor_num, *preading);
  848. return 0;
  849. }
  850. //<<KAMAL>>Added to support Sensor Averaging ../
  851. #define AVERAGING_SIZE 10
  852. int SensorAverage(uint8_t SensorNum, uint8_t* pSensorReading)
  853. {
  854. static uint8_t AverageBuf [AVERAGING_SIZE];
  855. static int AverageCount = 0;
  856. static int InitDone = 0;
  857. SensorInfo_T* pSensorInfo = NULL;
  858. int AverageIndex = 0;
  859. int i = 0;
  860. uint32_t AverageSum = 0;
  861. pSensorInfo = getSensorInfo(SensorNum);
  862. /* Check if we received valid sensor information */
  863. if (pSensorInfo == NULL)
  864. {
  865. printf ("Error: Unable to get SensorInfo \n");
  866. return 0;
  867. }
  868. /* Averaging index */
  869. AverageIndex = AverageCount % AVERAGING_SIZE;
  870. /* Set Sensor state to be update in progress unless
  871. * we receive all AVERAGING_SIZE values */
  872. if (0 == InitDone)
  873. {
  874. /* Settting update in progress */
  875. pSensorInfo->EventFlags |= BIT1;
  876. /* Checking if we have enough to do averaging */
  877. if (AverageIndex == (AVERAGING_SIZE -1))
  878. {
  879. InitDone = 1;
  880. }
  881. }
  882. else
  883. {
  884. /* Clearing update in progress */
  885. pSensorInfo->EventFlags &= ~BIT1;
  886. }
  887. /* Update averaging buffer */
  888. AverageBuf [AverageIndex ] = *pSensorReading;
  889. AverageCount++;
  890. if (AverageCount == AVERAGING_SIZE) { AverageCount = 0; }
  891. for (i = 0; i < AVERAGING_SIZE; i++)
  892. {
  893. AverageSum += AverageBuf [i];
  894. }
  895. if (1 == InitDone)
  896. {
  897. *pSensorReading = (uint8_t)(AverageSum / AVERAGING_SIZE);
  898. }
  899. /* Averaging done */
  900. return 0;
  901. }
  902. SensorInfo_T* getSensorInfo(uint8_t sensorNum)
  903. {
  904. uint16_t i;
  905. for(i=0;i<g_BMCInfo.SenConfig.ValidSensorCnt;i++)
  906. {
  907. if(sensorNum == g_BMCInfo.SensorSharedMem.SensorInfo[i].SensorNumber)
  908. {
  909. return &g_BMCInfo.SensorSharedMem.SensorInfo[i];
  910. }
  911. }
  912. return NULL;
  913. }
  914. //#endif /*SENSOR_DEVICE == 1*/