ChassisTimerTask.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. void *IdentifyTask(void *param);
  29. //int gFd_ChassisPwrHndlrQue;
  30. void *ChassisTimerTask(void* pArg)
  31. {
  32. MsgPkt_T ReqPkt;
  33. MsgPkt_T ResPkt;
  34. uint32_t preChassisSeconds;
  35. uint32_t preFanSeconds;
  36. uint32_t preIdentifySeconds = 0;
  37. char cmdStr[100] = {0};
  38. SetLanConfigReq_T *pSetLanCfg;
  39. int i;
  40. prctl(PR_SET_NAME,__FUNCTION__,0,0,0);
  41. printf("ChassisTimerTask Started... \n");
  42. // //create
  43. // if(-1 != access(CHASSIS_PWR_HNDLR_Q, F_OK))
  44. // {
  45. // remove(CHASSIS_PWR_HNDLR_Q);
  46. // }
  47. // if(0 != mkfifo (CHASSIS_PWR_HNDLR_Q, 0777))
  48. // {
  49. // printf("%s: Create %s fifo failed! %s\n", __FUNCTION__, CHASSIS_PWR_HNDLR_Q, strerror(errno));
  50. // return (void*)-1;
  51. // }
  52. // gFd_ChassisPwrHndlrQue = open (CHASSIS_PWR_HNDLR_Q, O_RDWR);
  53. // if(-1 == gFd_ChassisPwrHndlrQue)
  54. // {
  55. // printf("%s: Open %s fifo failed! %s\n", __FUNCTION__, CHASSIS_PWR_HNDLR_Q, strerror(errno));
  56. // return (void*)-1;
  57. // }
  58. preChassisSeconds = g_BMCInfo.CurTimerSecond;
  59. preFanSeconds = g_BMCInfo.CurTimerSecond;
  60. //sleep(5);
  61. while(1)
  62. {
  63. //Chassis timer interval
  64. if((g_BMCInfo.CurTimerSecond != preChassisSeconds)
  65. &&((g_BMCInfo.CurTimerSecond - preChassisSeconds) >= g_BMCInfo.IpmiConfig.ChassisTimerInterval))
  66. {
  67. //log("Chassis interval\r\n");
  68. preChassisSeconds = g_BMCInfo.CurTimerSecond;
  69. //TODO:
  70. //g_BMCInfo.PowerGoodFlag = 1;
  71. g_BMCInfo.IpmiConfig.ChassisPowerState.PowerState = g_BMCInfo.PowerGoodFlag;
  72. // ReqPkt.NetFnLUN = 0x2e<<2;
  73. // ReqPkt.Cmd = 0x01;
  74. // ReqPkt.Size = 0;
  75. // if(0 == API_BridgeInternal(&ReqPkt, &ResPkt, 0x40, 6))
  76. // {
  77. // printf("---> Access 0x40 successful: ");
  78. // }
  79. // else
  80. // {
  81. // printf("---> Access 0x40 failed: ");
  82. // }
  83. // for(i=0;i<ResPkt.Size;i++)
  84. // printf("%x ", ResPkt.Data[i]);
  85. // printf("\n");
  86. }
  87. // //Fan control
  88. // if((g_BMCInfo.CurTimerSecond != preFanSeconds)
  89. // && (g_BMCInfo.CurTimerSecond % g_BMCInfo.IpmiConfig.FanControlInterval) == 0)
  90. // {
  91. // preFanSeconds = g_BMCInfo.CurTimerSecond;
  92. // PDK_FanControl();
  93. // }
  94. //Chassis Identify
  95. if(g_BMCInfo.ChassisIdentify == TRUE) //新开个线程实现,默认灯闪烁10s,参考IPMI协议
  96. {
  97. if((g_BMCInfo.ChassisIdentifyTimeout != 0) || (g_BMCInfo.ChassisIdentifyForce != 0))
  98. {
  99. if(0 != pthread_create(NULL,NULL,IdentifyTask,NULL))
  100. {
  101. printf("%s: Create MsgHndlrTask thread failed!\n", __FUNCTION__);
  102. }
  103. }
  104. g_BMCInfo.ChassisIdentify = FALSE;
  105. }
  106. sleep(1);
  107. }
  108. }
  109. void *IdentifyTask(void *param)
  110. {
  111. uint8_t IdentifyTickCnt = 0;
  112. GPIO_PinState OldPinState;
  113. printf("Start Chassis Identify, Time %d, force %d\n", g_BMCInfo.ChassisIdentifyTimeout, g_BMCInfo.ChassisIdentifyForce);
  114. OldPinState = stm32_gpio_read(IDENTIFY_PORT, IDENTIFY_PIN);
  115. while(g_BMCInfo.ChassisIdentifyForce || g_BMCInfo.ChassisIdentifyTimeout)
  116. {
  117. stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, GPIO_PIN_SET);
  118. usleep(250000);
  119. stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, GPIO_PIN_RESET);
  120. usleep(250000);
  121. stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, GPIO_PIN_SET);
  122. usleep(250000);
  123. stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, GPIO_PIN_RESET);
  124. usleep(250000);
  125. if(g_BMCInfo.ChassisIdentifyTimeout>0)
  126. {
  127. g_BMCInfo.ChassisIdentifyTimeout--;
  128. }
  129. }
  130. //恢复LED灯的状态
  131. stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, OldPinState);
  132. printf("Chassis Identify finish.\n");
  133. pthread_exit(0);
  134. }