ChassisTimerTask.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Brief: Handle all chassis function in this file.
  3. Such as: Fan control, update power_good status, update chassis health status.
  4. * Author: Jimbo_Zhang@outlook.com
  5. * Date: 2019-9-18
  6. */
  7. #include <stdio.h>
  8. #include <stdint.h>
  9. #include <sys/prctl.h>
  10. #include <semaphore.h>
  11. #include <pthread.h>
  12. #include <errno.h>
  13. #include <fcntl.h>
  14. #include <stdlib.h>
  15. #include <unistd.h>
  16. #include <string.h>
  17. #include <pthread.h>
  18. #include "main.h"
  19. #include "ChassisTimerTask.h"
  20. #include "ChassisDevice.h"
  21. #include "com_IPMI_Chassis.h"
  22. #include "com_IPMI_LANConfig.h"
  23. #include "com_IPMI_DeviceConfig.h"
  24. #include "SensorMonitor.h"
  25. #include "time.h"
  26. #include "com_IPMI_App.h"
  27. #include "hal_interface_api.h"
  28. //int gFd_ChassisPwrHndlrQue;
  29. void *ChassisTimerTask(void* pArg)
  30. {
  31. MsgPkt_T MsgPkt;
  32. uint32_t preChassisSeconds;
  33. uint32_t preFanSeconds;
  34. uint32_t preIdentifySeconds = 0;
  35. uint8_t IdentifyTickCnt = 0;
  36. char cmdStr[100] = {0};
  37. SetLanConfigReq_T *pSetLanCfg;
  38. prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
  39. printf("ChassisTimerTask Started... \n");
  40. // //create
  41. // if(-1 != access(CHASSIS_PWR_HNDLR_Q, F_OK))
  42. // {
  43. // remove(CHASSIS_PWR_HNDLR_Q);
  44. // }
  45. // if(0 != mkfifo (CHASSIS_PWR_HNDLR_Q, 0777))
  46. // {
  47. // printf("%s: Create %s fifo failed! %s\n", __FUNCTION__, CHASSIS_PWR_HNDLR_Q, strerror(errno));
  48. // return (void*)-1;
  49. // }
  50. // gFd_ChassisPwrHndlrQue = open (CHASSIS_PWR_HNDLR_Q, O_RDWR);
  51. // if(-1 == gFd_ChassisPwrHndlrQue)
  52. // {
  53. // printf("%s: Open %s fifo failed! %s\n", __FUNCTION__, CHASSIS_PWR_HNDLR_Q, strerror(errno));
  54. // return (void*)-1;
  55. // }
  56. preChassisSeconds = g_BMCInfo.CurTimerSecond;
  57. preFanSeconds = g_BMCInfo.CurTimerSecond;
  58. while(1)
  59. {
  60. //Chassis timer interval
  61. if((g_BMCInfo.CurTimerSecond != preChassisSeconds)
  62. &&((g_BMCInfo.CurTimerSecond - preChassisSeconds) >= g_BMCInfo.IpmiConfig.ChassisTimerInterval))
  63. {
  64. //log("Chassis interval\r\n");
  65. preChassisSeconds = g_BMCInfo.CurTimerSecond;
  66. //TODO:
  67. //g_BMCInfo.PowerGoodFlag = 1;
  68. g_BMCInfo.IpmiConfig.ChassisPowerState.PowerState = g_BMCInfo.PowerGoodFlag;
  69. }
  70. //Fan control
  71. if((g_BMCInfo.CurTimerSecond != preFanSeconds)
  72. && (g_BMCInfo.CurTimerSecond % g_BMCInfo.IpmiConfig.FanControlInterval) == 0)
  73. {
  74. preFanSeconds = g_BMCInfo.CurTimerSecond;
  75. PDK_FanControl();
  76. }
  77. //Chassis Identify
  78. if(g_BMCInfo.ChassisIdentify == TRUE) //新开个线程实现,默认灯闪烁10s,参考IPMI协议
  79. {
  80. if(IdentifyTickCnt == 5) //0.5s
  81. {
  82. IdentifyTickCnt++;
  83. printf("-> Turn on led!\r\n");
  84. }
  85. else if(IdentifyTickCnt == 10)
  86. {
  87. IdentifyTickCnt = 0;
  88. printf("-> Turn off led!\r\n");
  89. }
  90. else
  91. {
  92. IdentifyTickCnt++;
  93. }
  94. //Identify finished
  95. if(((g_BMCInfo.CurTimerSecond - preIdentifySeconds) >= g_BMCInfo.ChassisIdentifyTimeout)
  96. && (g_BMCInfo.ChassisIdentifyForce != 1))
  97. {
  98. g_BMCInfo.ChassisIdentify = FALSE;
  99. }
  100. }
  101. else
  102. {
  103. preIdentifySeconds = g_BMCInfo.CurTimerSecond;
  104. IdentifyTickCnt = 0;
  105. }
  106. sleep(1);
  107. }
  108. }