SensorMonitor.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  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. if((g_BMCInfo.CurTimerSecond%2/*180*/ == 0)) //3 minutes
  229. {
  230. for(index=0; index<SENSOR_NUMBERS;index++)
  231. {
  232. if(pSensorInfo->SensorNumber == gSensorHistoryInfo[index].SensorNum)
  233. {
  234. for(j=1;j<HISTORY_DATA_SIZE;j++)
  235. {
  236. gSensorHistoryInfo[index].History[j-1] = gSensorHistoryInfo[index].History[j];
  237. }
  238. gSensorHistoryInfo[index].History[HISTORY_DATA_SIZE-1] = pSensorInfo->SensorReading;
  239. }
  240. }
  241. }
  242. }
  243. if (0 == pSensorInfo->Err)
  244. {
  245. pSensorInfo->EventFlags &= ~BIT5;
  246. }
  247. else
  248. {
  249. pSensorInfo->EventFlags |= BIT5;
  250. }
  251. do
  252. {
  253. EvData1 = 0;
  254. EventData1 = 0;
  255. EventData3 = 0;
  256. SendDeassertion = 0;
  257. SendAssertion = 0;
  258. //SensorLevel = 0;
  259. Level = pSensorInfo->EventLevel;
  260. Value = pSensorInfo->SensorReading;
  261. AssertionEventOccuredByte1 = pSensorInfo->AssertionEventOccuredByte1;
  262. AssertionEventOccuredByte2 = pSensorInfo->AssertionEventOccuredByte2;
  263. DeassertionEventOccuredByte1 = pSensorInfo->DeassertionEventOccuredByte1;
  264. DeassertionEventOccuredByte2 = pSensorInfo->DeassertionEventOccuredByte2;
  265. AssertionEventEnablesByte1 = pSensorInfo->AssertionEventEnablesByte1;
  266. AssertionEventEnablesByte2 = pSensorInfo->AssertionEventEnablesByte2;
  267. DeassertionEventEnablesByte1 = pSensorInfo->DeassertionEventEnablesByte1;
  268. DeassertionEventEnablesByte2 = pSensorInfo->DeassertionEventEnablesByte2;
  269. WarningLow = pSensorInfo->LowerNonCritical;
  270. WarningHigh = pSensorInfo->UpperNonCritical;
  271. NegHysteresis = pSensorInfo->NegHysteresis;
  272. PosHysteresis = pSensorInfo->PosHysteresis;
  273. CriticalHigh = pSensorInfo->UpperCritical;
  274. CriticalLow = pSensorInfo->LowerCritical;
  275. NonRecoverableHigh = pSensorInfo->UpperNonRecoverable;
  276. NonRecoverableLow = pSensorInfo->LowerNonRecoverable;
  277. OEMField = pSensorInfo->OEMField;
  278. // SensorNum = pSensorInfo->SensorNumber;
  279. if(1==OEMField)
  280. {
  281. SensorAverage(pSensorInfo->SensorNumber, &pSensorInfo->SensorReading);
  282. }
  283. SettableThreshMask = (uint8_t)(pSensorInfo->SettableThreshMask >> 8);
  284. SignedSensor = (0 != (pSensorInfo->Units1 & 0xC0)); //Analog data format
  285. if (SignedSensor)
  286. {
  287. // These are max and min sensor readings for a signed sensor
  288. SensorMax = 127;
  289. SensorMin = -128;
  290. //
  291. // All Thresholds and the sensor value need to be sign extended to 16 bits
  292. // for signed sensors (if the value is negative).
  293. //
  294. WarningLow = (int16_t)((int8_t)pSensorInfo->LowerNonCritical);
  295. WarningHigh = (int16_t)((int8_t)pSensorInfo->UpperNonCritical);
  296. CriticalHigh = (int16_t)((int8_t)pSensorInfo->UpperCritical);
  297. CriticalLow = (int16_t)((int8_t)pSensorInfo->LowerCritical);
  298. NonRecoverableHigh = (int16_t)((int8_t)pSensorInfo->UpperNonRecoverable);
  299. NonRecoverableLow = (int16_t)((int8_t)pSensorInfo->LowerNonRecoverable);
  300. Value = (int16_t)((int8_t)pSensorInfo->SensorReading);
  301. }
  302. //
  303. // For unused thresholds, set them to a value that the sensor value cannot
  304. // have in an 8 bit value so no match can happen.
  305. //
  306. if (0 == (SettableThreshMask & BIT5))
  307. {
  308. // Set to a value that the sensor cannot have
  309. NonRecoverableHigh = SensorMax + 1;
  310. }
  311. if (0 == (SettableThreshMask & BIT2))
  312. {
  313. // Set to a value that the sensor cannot have
  314. NonRecoverableLow = SensorMin - 1;
  315. }
  316. if (0 == (SettableThreshMask & BIT4))
  317. {
  318. CriticalHigh = NonRecoverableHigh;
  319. }
  320. if (0 == (SettableThreshMask & BIT1))
  321. {
  322. CriticalLow = NonRecoverableLow;
  323. }
  324. if (0 == (SettableThreshMask & BIT3))
  325. {
  326. WarningHigh = CriticalHigh;
  327. }
  328. if (0 == (SettableThreshMask & BIT0))
  329. {
  330. WarningLow = CriticalLow;
  331. }
  332. StartLevel = Level;
  333. switch (Level)
  334. {
  335. case SENSOR_STATUS_NORMAL:
  336. if (Value <= WarningLow)
  337. {
  338. //sensor_dbg_printf("#%02x LNC(A) - Value: %02x Threshold: %02x\r\n", (pSensorInfo->SensorNumber), (uint8_t)Value, (uint8_t)WarningLow);
  339. /* deassert WarningLow going High */
  340. EvData1 = 0x51;
  341. if (DeassertionEventEnablesByte1 & 0x02)
  342. {
  343. SendDeassertion = 1;
  344. }
  345. /* remove WarnignLow going Low deassertion */
  346. DeassertionEventOccuredByte1 &= ~0x01;
  347. /* deassert WarningLow going High */
  348. DeassertionEventOccuredByte1 |= 0x02;
  349. /* assert WarningLow going Low */
  350. EventData1 = 0x50;
  351. if(AssertionEventEnablesByte1 & 0x01)
  352. {
  353. SendAssertion = 1;
  354. }
  355. Level = SENSOR_STATUS_WARNING_LOW;
  356. EventData3 = WarningLow;
  357. /* set de/assertion event */
  358. /* remove WarningLow going High assertion */
  359. AssertionEventOccuredByte1 &= ~0x02;
  360. /* assert WarningLow going Low */
  361. AssertionEventOccuredByte1 |= 0x01;
  362. //SensorLevel = LWR_NON_CRITICAL_GOING_LOW_CTRL_FN;
  363. }
  364. if (Value >= WarningHigh)
  365. {
  366. //sensor_dbg_printf("#%02x UNC(A) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)WarningHigh);
  367. /* deassert WarningHigh going Low */
  368. EvData1 = 0x56;
  369. if (DeassertionEventEnablesByte1 & 0x40)
  370. {
  371. SendDeassertion = 1;
  372. }
  373. /* remove WarningHigh going High deassertion */
  374. DeassertionEventOccuredByte1 &= ~0x80;
  375. /* deassert WarningHigh going Low */
  376. DeassertionEventOccuredByte1 |= 0x40;
  377. /* assert WarningHigh going High */
  378. EventData1 = 0x57;
  379. if (AssertionEventEnablesByte1 & 0x80)
  380. {
  381. SendAssertion = 1;
  382. }
  383. /* set de/assertion occured */
  384. /* remove WarningHigh going Low assertion */
  385. AssertionEventOccuredByte1 &= ~0x40;
  386. /* assert WarningHigh going High */
  387. AssertionEventOccuredByte1 |= 0x80;
  388. Level = SENSOR_STATUS_WARNING_HIGH;
  389. /* Threshold that caused event */
  390. EventData3 = WarningHigh;
  391. //SensorLevel = UPPER_NON_CRITICAL_GOING_HIGH_CTRL_FN;
  392. }
  393. break;
  394. case SENSOR_STATUS_WARNING_HIGH:
  395. DeassertThreshold = GetHighDeassertValue(SignedSensor, WarningHigh, PosHysteresis);
  396. if(Value < DeassertThreshold)
  397. {
  398. //sensor_dbg_printf("#%02x UNC(D) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)DeassertThreshold);
  399. /* deassert WarningHigh going High */
  400. EvData1 = 0x57;
  401. if (DeassertionEventEnablesByte1 & 0x80)
  402. {
  403. SendDeassertion = 1;
  404. }
  405. /* remove WarningHigh going Low deassertion */
  406. DeassertionEventOccuredByte1 &= ~0x40;
  407. /* deassert WarningHigh going High */
  408. DeassertionEventOccuredByte1 |= 0x80;
  409. /* assert WaningHigh going Low */
  410. EventData1 = 0x56;
  411. if (AssertionEventEnablesByte1 & 0x40)
  412. {
  413. SendAssertion = 1;
  414. }
  415. Level = SENSOR_STATUS_NORMAL;
  416. EventData3 = WarningHigh;
  417. /* remove WarningHigh going High assertion */
  418. AssertionEventOccuredByte1 &= ~0x80;
  419. /* assert WarningHigh going Low */
  420. AssertionEventOccuredByte1 |= 0x40;
  421. //SensorLevel = UPPER_NON_CRITICAL_GOING_LOW_CTRL_FN;
  422. }
  423. if (Value >= CriticalHigh)
  424. {
  425. //sensor_dbg_printf("#%02x UC(A) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)CriticalHigh);
  426. /* deassert CriticalHigh going Low */
  427. EvData1 = 0x58;
  428. if (DeassertionEventEnablesByte2 & 0x01)
  429. {
  430. SendDeassertion = 1;
  431. }
  432. /* remove CriticalHigh going High deassertion */
  433. DeassertionEventOccuredByte2 &= ~0x02;
  434. /* deassert CriticalHigh going Low */
  435. DeassertionEventOccuredByte2 |= 0x01;
  436. /* assert CriticalHigh going High */
  437. EventData1 = 0x59;
  438. if (AssertionEventEnablesByte2 & 0x02)
  439. {
  440. SendAssertion = 1;
  441. }
  442. Level = SENSOR_STATUS_CRITICAL_HIGH;
  443. EventData3 = CriticalHigh;
  444. /* set de/assertion event occured */
  445. /* remove CriticalHigh going Low assertion */
  446. AssertionEventOccuredByte2 &= ~0x01;
  447. /* assert CriticalHigh going High */
  448. AssertionEventOccuredByte2 |= 0x02;
  449. //SensorLevel = UPPER_CRITICAL_GOING_HIGH_CTRL_FN;
  450. }
  451. break;
  452. case SENSOR_STATUS_WARNING_LOW:
  453. DeassertThreshold = GetLowDeassertValue(SignedSensor, WarningLow, NegHysteresis);
  454. if (Value > DeassertThreshold)
  455. {
  456. //sensor_dbg_printf("#%02x LNC(D) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)DeassertThreshold);
  457. /* deassert WarningLow going Low */
  458. EvData1 = 0x50;
  459. if (DeassertionEventEnablesByte1 & 0x01)
  460. {
  461. SendDeassertion = 1;
  462. }
  463. /* remove WarningLow going High deassertion */
  464. DeassertionEventOccuredByte1 &= ~0x02;
  465. /* deassert WarningLow going Low */
  466. DeassertionEventOccuredByte1 |= 0x01;
  467. /* assert WarningLow going High */
  468. EventData1 = 0x51;
  469. if (AssertionEventEnablesByte1 & 0x02)
  470. {
  471. SendAssertion = 1;
  472. }
  473. Level = SENSOR_STATUS_NORMAL;
  474. EventData3 = WarningLow;
  475. /* set de/assertion event */
  476. /* remove WarningLow going Low assertion */
  477. AssertionEventOccuredByte1 &= ~0x01;
  478. /* assert WarningLow going High */
  479. AssertionEventOccuredByte1 |= 0x02;
  480. //SensorLevel = LWR_NON_CRITICAL_GOING_HIGH_CTRL_FN;
  481. }
  482. if (Value <= CriticalLow)
  483. {
  484. //sensor_dbg_printf("#%02x LC(A) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)CriticalLow);
  485. /* deassert CriticalLow going High */
  486. EvData1 = 0x53;
  487. if (DeassertionEventEnablesByte1 & 0x08)
  488. {
  489. SendDeassertion = 1;
  490. }
  491. /* remove CriticalLow going Low deassertion */
  492. DeassertionEventOccuredByte1 &= ~0x04;
  493. /* deassert CriticalHigh going High */
  494. DeassertionEventOccuredByte1 |= 0x08;
  495. /* assert CriticalLow going Low */
  496. EventData1 = 0x52;
  497. if (AssertionEventEnablesByte1 & 0x04)
  498. {
  499. SendAssertion = 1;
  500. }
  501. Level = SENSOR_STATUS_CRITICAL_LOW;
  502. EventData3 = CriticalLow;
  503. /* remove CriticalLow going High assertion */
  504. AssertionEventOccuredByte1 &= ~0x08;
  505. /* assert CriticalLow going Low */
  506. AssertionEventOccuredByte1 |= 0x04;
  507. //SensorLevel = LWR_CRITICAL_GOING_LOW_CTRL_FN;
  508. }
  509. break;
  510. case SENSOR_STATUS_CRITICAL_HIGH:
  511. DeassertThreshold = GetHighDeassertValue(SignedSensor, CriticalHigh, PosHysteresis);
  512. if (Value < DeassertThreshold)
  513. {
  514. //sensor_dbg_printf("#%02x UC(D) - Value: %02x Threshold: %02x\n",pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)DeassertThreshold);
  515. /* deassert CriticalHigh going High */
  516. EvData1 = 0x59;
  517. if (DeassertionEventEnablesByte2 & 0x02)
  518. {
  519. SendDeassertion = 1;
  520. }
  521. /* remove CriticalHigh going Low deassertion */
  522. DeassertionEventOccuredByte2 &= ~0x01;
  523. /* deassert CriticalHigh going High */
  524. DeassertionEventOccuredByte2 |= 0x02;
  525. /* assert CriticalHigh going Low */
  526. EventData1 = 0x58;
  527. if (AssertionEventEnablesByte2 & 0x01)
  528. {
  529. SendAssertion = 1;
  530. }
  531. Level = SENSOR_STATUS_WARNING_HIGH;
  532. EventData3 = CriticalHigh;
  533. /* set de/assertion event occured */
  534. /* remove CriticalHigh going High assertion */
  535. AssertionEventOccuredByte2 &= ~0x02;
  536. /* assert CriticalHigh going Low */
  537. AssertionEventOccuredByte2 |= 0x01;
  538. //SensorLevel = UPPER_CRITICAL_GOING_LOW_CTRL_FN;
  539. }
  540. if (Value >= NonRecoverableHigh)
  541. {
  542. //sensor_dbg_printf("#%02x UNR(A) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)NonRecoverableHigh);
  543. /* deassert NonRecoverableHigh going Low */
  544. EvData1 = 0x5A;
  545. if (DeassertionEventEnablesByte2 & 0x04)
  546. {
  547. SendDeassertion = 1;
  548. }
  549. /* remove NonRecoverableHigh going High deassertion */
  550. DeassertionEventOccuredByte2 &= ~0x08;
  551. /* deassert NonRecoverableHigh going Low */
  552. DeassertionEventOccuredByte2 |= 0x04;
  553. /* assert NonRecoverableHigh going High */
  554. EventData1 = 0x5B;
  555. if (AssertionEventEnablesByte2 & 0x08)
  556. {
  557. SendAssertion = 1;
  558. }
  559. Level = SENSOR_STATUS_NONRECOVERABLE_HIGH;
  560. EventData3 = NonRecoverableHigh;
  561. /* remove NonRecoverableHigh going Low assertion */
  562. AssertionEventOccuredByte2 &= ~0x04;
  563. /* assert NonRecoverableHigh going High */
  564. AssertionEventOccuredByte2 |= 0x08;
  565. //SensorLevel = UPPER_NON_RECOVERABLE_GOING_HIGH_CTRL_FN;
  566. }
  567. break;
  568. case SENSOR_STATUS_CRITICAL_LOW:
  569. DeassertThreshold = GetLowDeassertValue(SignedSensor, CriticalLow, NegHysteresis);
  570. if (Value > DeassertThreshold)
  571. {
  572. //sensor_dbg_printf("#%02x LC(D) - Value: %02x Threshold: %02x\n",pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)DeassertThreshold);
  573. /* deassert CriticalLow going Low */
  574. EvData1 = 0x52;
  575. if (DeassertionEventEnablesByte1 & 0x04)
  576. {
  577. SendDeassertion = 1;
  578. }
  579. /* remove CriticalLow going High deassertion */
  580. DeassertionEventOccuredByte1 &= ~0x08;
  581. /* deassert CriticalLow going Low */
  582. DeassertionEventOccuredByte1 |= 0x04;
  583. /* assert CriticalLow going High */
  584. EventData1 = 0x53;
  585. if (AssertionEventEnablesByte1 & 0x08)
  586. {
  587. SendAssertion = 1;
  588. }
  589. Level = SENSOR_STATUS_WARNING_LOW;
  590. EventData3 = CriticalLow;
  591. /* remove CriticalLow going Low assertion */
  592. AssertionEventOccuredByte1 &= ~0x04;
  593. /* assert CriticalLow going High */
  594. AssertionEventOccuredByte1 |= 0x08;
  595. //SensorLevel = LWR_CRITICAL_GOING_HIGH_CTRL_FN;
  596. }
  597. if (Value <= NonRecoverableLow)
  598. {
  599. //sensor_dbg_printf("#%02x LNR(A) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)NonRecoverableLow);
  600. /* deassert NonRecoverableLow going High */
  601. EvData1 = 0x55;
  602. if (DeassertionEventEnablesByte1 & 0x20)
  603. {
  604. SendDeassertion = 1;
  605. }
  606. /* remove NonRecoverableLow going Low deassertion */
  607. DeassertionEventOccuredByte1 &= ~0x10;
  608. /* deassert NonRecoverableLow going High */
  609. DeassertionEventOccuredByte1 |= 0x20;
  610. /* assert NonRecoverableLow going Low */
  611. EventData1 = 0x54;
  612. if (AssertionEventEnablesByte1 & 0x10)
  613. {
  614. SendAssertion = 1;
  615. }
  616. Level = SENSOR_STATUS_NONRECOVERABLE_LOW;
  617. EventData3 = NonRecoverableLow;
  618. /* remove NonRecoverableLow going High assertion */
  619. AssertionEventOccuredByte1 &= ~0x20;
  620. /* assert NonRecoverableLow going Low */
  621. AssertionEventOccuredByte1 |= 0x10;
  622. //SensorLevel = LWR_NON_RECOVERABLE_GOING_LOW_CTRL_FN;
  623. }
  624. break;
  625. case SENSOR_STATUS_NONRECOVERABLE_HIGH:
  626. DeassertThreshold = GetHighDeassertValue(SignedSensor, NonRecoverableHigh, PosHysteresis);
  627. if (Value < DeassertThreshold)
  628. {
  629. //sensor_dbg_printf("#%02x UNR(D) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)DeassertThreshold);
  630. /* deassert NonRecoverableHigh going High */
  631. EvData1 = 0x5B;
  632. if (DeassertionEventEnablesByte2 & 0x08)
  633. {
  634. SendDeassertion = 1;
  635. }
  636. /* remove NonRecoverableHigh going Low deassertion */
  637. DeassertionEventOccuredByte2 &= ~0x04;
  638. /* deassert NonRecoverableHigh going High */
  639. DeassertionEventOccuredByte2 |= 0x08;
  640. /* assert NonRecoverableHigh going Low */
  641. EventData1 = 0x5A;
  642. if (AssertionEventEnablesByte2 & 0x04)
  643. {
  644. SendAssertion = 1;
  645. }
  646. Level = SENSOR_STATUS_CRITICAL_HIGH;
  647. EventData3 = NonRecoverableHigh;
  648. /* remove NonRecoverableHigh going High assertion */
  649. AssertionEventOccuredByte2 &= ~0x08;
  650. /* assert NonRecoverableHigh going Low */
  651. AssertionEventOccuredByte2 |= 0x04;
  652. //SensorLevel = UPPER_NON_RECOVERABLE_GOING_LOW_CTRL_FN;
  653. }
  654. break;
  655. case SENSOR_STATUS_NONRECOVERABLE_LOW:
  656. DeassertThreshold = GetLowDeassertValue(SignedSensor, NonRecoverableLow, NegHysteresis);
  657. if (Value > DeassertThreshold)
  658. {
  659. //sensor_dbg_printf("#%02x LNR(D) - Value: %02x Threshold: %02x\n", pSensorInfo->SensorNumber, (uint8_t)Value, (uint8_t)DeassertThreshold);
  660. /* deassert NonRecoverableLow going Low */
  661. EvData1 = 0x54;
  662. if (DeassertionEventEnablesByte1 & 0x10)
  663. {
  664. SendDeassertion = 1;
  665. }
  666. /* remove NonRecoverableLow going High deassertion */
  667. DeassertionEventOccuredByte1 &= ~0x20;
  668. /* deassert NonRecoverableLow going Low */
  669. DeassertionEventOccuredByte1 |= 0x10;
  670. /* assert NonRecoverableLow going High */
  671. EventData1 = 0x55;
  672. if (AssertionEventEnablesByte1 & 0x20)
  673. {
  674. SendAssertion = 1;
  675. }
  676. Level = SENSOR_STATUS_CRITICAL_LOW;
  677. EventData3 = NonRecoverableLow;
  678. /* remove NonRecoverableLow going Low assertion */
  679. AssertionEventOccuredByte1 &= ~0x10;
  680. /* assert NonRecoverableLow going High */
  681. AssertionEventOccuredByte1 |= 0x20;
  682. //SensorLevel = LWR_NON_RECOVERABLE_GOING_HIGH_CTRL_FN;
  683. }
  684. break;
  685. case SENSOR_STATUS_FATAL:
  686. break;
  687. } /* switch(m_SensorEventLevel[i]) */
  688. pSensorInfo->EventLevel = Level;
  689. pSensorInfo->AssertionEventOccuredByte1 = AssertionEventOccuredByte1;
  690. pSensorInfo->AssertionEventOccuredByte2 = AssertionEventOccuredByte2;
  691. pSensorInfo->DeassertionEventOccuredByte1 = DeassertionEventOccuredByte1;
  692. pSensorInfo->DeassertionEventOccuredByte2 = DeassertionEventOccuredByte2;
  693. AssertionHistoryByte1 = 0;
  694. AssertionHistoryByte2 = 0;
  695. DeassertionHistoryByte1 = 0;
  696. DeassertionHistoryByte2 = 0;
  697. //TODO: post event message to SEL Task.
  698. EventMsg [0] = 0x20;
  699. EventMsg [1] = (pSensorInfo->SensorOwnerLun & 0x03); /* Multi-LUN support */
  700. /* EvMRev */
  701. EventMsg [2] = IPMI_EVM_REVISION;
  702. /* sensor type */
  703. EventMsg [3] = pSensorInfo->SensorTypeCode;
  704. /* sensor number */
  705. EventMsg [4] = pSensorInfo->SensorNumber;
  706. /* event direction|type */
  707. EventMsg [5] = 0x01;
  708. EventMsg [6] = 0;
  709. /* Set Sensor Event Data based on the Operation byte */
  710. switch (pSensorInfo->Operation>>6)
  711. {
  712. case WRITE_NO_EVTDATA1:
  713. /* Event Data 1 */
  714. EventMsg [6] = pSensorInfo->EvtData1;
  715. /* Intentional Fall thru */
  716. case WRITE_EVTDATA1:
  717. /* Event Data 1 */
  718. EventMsg [6] |= EventData1;
  719. /* Update EvtData fields */
  720. /* Current Reading */
  721. EventMsg [7] = pSensorInfo->EvtData2;
  722. /* Trigger that caused event */
  723. EventMsg [8] = pSensorInfo->EvtData3;
  724. break;
  725. case USE_SM_EVTDATA:
  726. /* Event Data 1 */
  727. EventMsg [6] = EventData1;
  728. /* Current Reading */
  729. EventMsg [7] = Value;
  730. /* Trigger that caused event */
  731. EventMsg [8] = EventData3;
  732. break;
  733. }
  734. if (SendAssertion)
  735. {
  736. if ((EventData1 & 0x0f) < 8)
  737. {
  738. AssertionHistoryByte1 = (1 << (EventData1 & 0x0f));
  739. }
  740. else
  741. {
  742. AssertionHistoryByte2 = (1 << ((EventData1 & 0x0f) - 8));
  743. }
  744. /* For Manual Rearm Sensor - Check for already generated events in the History bytes
  745. For Auto Rearm Sensor -History bytes are not valid */
  746. if ( (0 == (AssertionHistoryByte1 & pSensorInfo->AssertionHistoryByte1)) &&
  747. (0 == (AssertionHistoryByte2 & pSensorInfo->AssertionHistoryByte2)) )
  748. {
  749. /* if sensor is manual arming */
  750. if (0 == (pSensorInfo->SensorCaps & BIT6))
  751. {
  752. /* Update assertion History */
  753. pSensorInfo->AssertionHistoryByte1 |= AssertionHistoryByte1;
  754. pSensorInfo->AssertionHistoryByte2 |= AssertionHistoryByte2;
  755. }
  756. /* Is event message generation enabled ? */
  757. if (0 != (pSensorInfo->EventFlags & BIT7))
  758. {
  759. /* Post Event Message */
  760. PostEventMessage (EventMsg, sizeof (EventMsg));
  761. }
  762. }
  763. SendAssertion = 0;
  764. }
  765. if (SendDeassertion)
  766. {
  767. if ((EvData1 & 0x0f) < 8)
  768. {
  769. DeassertionHistoryByte1 = (1 << (EvData1 & 0x0f));
  770. }
  771. else
  772. {
  773. DeassertionHistoryByte2 = (1 << ((EvData1 & 0x0f) - 8));
  774. }
  775. /* For Manual Rearm Sensor - Check for already generated events in the History bytes
  776. For Auto Rearm Sensor -History bytes are not valid */
  777. if ( (0 == (DeassertionHistoryByte1 & pSensorInfo->DeassertionHistoryByte1)) &&
  778. (0 == (DeassertionHistoryByte2 & pSensorInfo->DeassertionHistoryByte2)) )
  779. {
  780. /* Event Data 1 */
  781. EventMsg [6] = EvData1;
  782. EventMsg [5] = 0x81;
  783. /* if sensor is manual arming */
  784. if (0 == (pSensorInfo->SensorCaps & BIT6))
  785. {
  786. /* Update Deassertion History */
  787. pSensorInfo->DeassertionHistoryByte1 |= DeassertionHistoryByte1;
  788. pSensorInfo->DeassertionHistoryByte2 |= DeassertionHistoryByte2;
  789. }
  790. /* Call PreEventLog hook function(s) and don't do
  791. sensor SEL event log if the return is not zero */
  792. if (0 != (pSensorInfo->EventFlags & BIT7))
  793. {
  794. /* Post Event Message Here */
  795. PostEventMessage (EventMsg, sizeof (EventMsg));
  796. }
  797. }
  798. SendDeassertion = 0;
  799. }
  800. }while (StartLevel != Level);
  801. /* Auto Rearm sensor: Get current assertions */
  802. AssertionHistoryByte1 = pSensorInfo->AssertionEventOccuredByte1;
  803. AssertionHistoryByte2 = pSensorInfo->AssertionEventOccuredByte2;
  804. // The following checks need to be done from lowest severity to highest.
  805. HealthLevel = SENSOR_STATUS_NORMAL;
  806. if (0 != (AssertionHistoryByte1 & 0x01 & AssertionEventEnablesByte1))
  807. HealthLevel = SENSOR_STATUS_WARNING_LOW;
  808. if (0 != (AssertionHistoryByte1 & 0x80 & AssertionEventEnablesByte1))
  809. HealthLevel = SENSOR_STATUS_WARNING_HIGH;
  810. if (0 != (AssertionHistoryByte1 & 0x04 & AssertionEventEnablesByte1))
  811. HealthLevel = SENSOR_STATUS_CRITICAL_LOW;
  812. if (0 != (AssertionHistoryByte2 & 0x02 & AssertionEventEnablesByte2))
  813. HealthLevel = SENSOR_STATUS_CRITICAL_HIGH;
  814. if (0 != (AssertionHistoryByte1 & 0x10 & AssertionEventEnablesByte1))
  815. HealthLevel = SENSOR_STATUS_NONRECOVERABLE_LOW;
  816. if (0 != (AssertionHistoryByte2 & 0x08 & AssertionEventEnablesByte2))
  817. HealthLevel = SENSOR_STATUS_NONRECOVERABLE_HIGH;
  818. pSensorInfo->HealthLevel = HealthLevel;
  819. // Make sure the "Reading Not Available" bit is clear.
  820. pSensorInfo->EventFlags &= ~BIT5;
  821. }
  822. /**
  823. * @brief Monitor Non-threshold sensors.
  824. * @param i - Sensor index.
  825. */
  826. static void
  827. MonitorNonTSensors ( SensorInfo_T* pSensorInfo)
  828. {
  829. //TODO:
  830. printf("MonitorNonTSensors: not implement\r\n");
  831. }
  832. /**
  833. * @fn hal_read_sensor
  834. * @brief This function reads the sensor reading for given sensor number
  835. *
  836. **/
  837. int get_sensor_reading (uint8_t sensor_num, uint8_t *preading)
  838. {
  839. sensor_tbl_t *pdev_tbl;
  840. pdev_tbl = (sensor_tbl_t*)getSensorDev (sensor_num);
  841. if (pdev_tbl == NULL)
  842. {
  843. printf ("Error: couldn't find sensor %x\n", sensor_num);
  844. return 1;
  845. }
  846. /* Execute at the requested sensor reading handler */
  847. if (0 != pdev_tbl->device_read (preading))
  848. {
  849. printf ("Error executing read function\n");
  850. return -1;
  851. }
  852. //printf ("sensor number %x reading = %x\r\n", sensor_num, *preading);
  853. return 0;
  854. }
  855. //<<KAMAL>>Added to support Sensor Averaging ../
  856. #define AVERAGING_SIZE 10
  857. int SensorAverage(uint8_t SensorNum, uint8_t* pSensorReading)
  858. {
  859. static uint8_t AverageBuf [AVERAGING_SIZE];
  860. static int AverageCount = 0;
  861. static int InitDone = 0;
  862. SensorInfo_T* pSensorInfo = NULL;
  863. int AverageIndex = 0;
  864. int i = 0;
  865. uint32_t AverageSum = 0;
  866. pSensorInfo = getSensorInfo(SensorNum);
  867. /* Check if we received valid sensor information */
  868. if (pSensorInfo == NULL)
  869. {
  870. printf ("Error: Unable to get SensorInfo \n");
  871. return 0;
  872. }
  873. /* Averaging index */
  874. AverageIndex = AverageCount % AVERAGING_SIZE;
  875. /* Set Sensor state to be update in progress unless
  876. * we receive all AVERAGING_SIZE values */
  877. if (0 == InitDone)
  878. {
  879. /* Settting update in progress */
  880. pSensorInfo->EventFlags |= BIT1;
  881. /* Checking if we have enough to do averaging */
  882. if (AverageIndex == (AVERAGING_SIZE -1))
  883. {
  884. InitDone = 1;
  885. }
  886. }
  887. else
  888. {
  889. /* Clearing update in progress */
  890. pSensorInfo->EventFlags &= ~BIT1;
  891. }
  892. /* Update averaging buffer */
  893. AverageBuf [AverageIndex ] = *pSensorReading;
  894. AverageCount++;
  895. if (AverageCount == AVERAGING_SIZE) { AverageCount = 0; }
  896. for (i = 0; i < AVERAGING_SIZE; i++)
  897. {
  898. AverageSum += AverageBuf [i];
  899. }
  900. if (1 == InitDone)
  901. {
  902. *pSensorReading = (uint8_t)(AverageSum / AVERAGING_SIZE);
  903. }
  904. /* Averaging done */
  905. return 0;
  906. }
  907. SensorInfo_T* getSensorInfo(uint8_t sensorNum)
  908. {
  909. uint16_t i;
  910. for(i=0;i<g_BMCInfo.SenConfig.ValidSensorCnt;i++)
  911. {
  912. if(sensorNum == g_BMCInfo.SensorSharedMem.SensorInfo[i].SensorNumber)
  913. {
  914. return &g_BMCInfo.SensorSharedMem.SensorInfo[i];
  915. }
  916. }
  917. return NULL;
  918. }
  919. //#endif /*SENSOR_DEVICE == 1*/