ChassisTimerTask.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. preChassisSeconds = g_BMCInfo.CurTimerSecond;
  43. preFanSeconds = g_BMCInfo.CurTimerSecond;
  44. //sleep(5);
  45. while(1)
  46. {
  47. //Chassis timer interval
  48. if((g_BMCInfo.CurTimerSecond != preChassisSeconds)
  49. &&((g_BMCInfo.CurTimerSecond - preChassisSeconds) >= g_BMCInfo.IpmiConfig.ChassisTimerInterval))
  50. {
  51. //log("Chassis interval\r\n");
  52. preChassisSeconds = g_BMCInfo.CurTimerSecond;
  53. //TODO:
  54. //g_BMCInfo.PowerGoodFlag = 1;
  55. g_BMCInfo.IpmiConfig.ChassisPowerState.PowerState = g_BMCInfo.PowerGoodFlag;
  56. // ReqPkt.NetFnLUN = 0x2e<<2;
  57. // ReqPkt.Cmd = 0x01;
  58. // ReqPkt.Size = 0;
  59. // if(0 == API_BridgeInternal(&ReqPkt, &ResPkt, 0x40, 6))
  60. // {
  61. // printf("---> Access 0x40 successful: ");
  62. // }
  63. // else
  64. // {
  65. // printf("---> Access 0x40 failed: ");
  66. // }
  67. // for(i=0;i<ResPkt.Size;i++)
  68. // printf("%x ", ResPkt.Data[i]);
  69. // printf("\n");
  70. }
  71. // //Fan control
  72. // if((g_BMCInfo.CurTimerSecond != preFanSeconds)
  73. // && (g_BMCInfo.CurTimerSecond % g_BMCInfo.IpmiConfig.FanControlInterval) == 0)
  74. // {
  75. // preFanSeconds = g_BMCInfo.CurTimerSecond;
  76. // PDK_FanControl();
  77. // }
  78. //Chassis Identify
  79. if(g_BMCInfo.ChassisIdentify == TRUE) //新开个线程实现,默认灯闪烁10s,参考IPMI协议
  80. {
  81. if((g_BMCInfo.ChassisIdentifyTimeout != 0) || (g_BMCInfo.ChassisIdentifyForce != 0))
  82. {
  83. if(0 != pthread_create(NULL,NULL,IdentifyTask,NULL))
  84. {
  85. printf("%s: Create MsgHndlrTask thread failed!\n", __FUNCTION__);
  86. }
  87. }
  88. g_BMCInfo.ChassisIdentify = FALSE;
  89. }
  90. usleep(100);
  91. }
  92. }
  93. void *IdentifyTask(void *param)
  94. {
  95. uint8_t IdentifyTickCnt = 0;
  96. GPIO_PinState OldPinState;
  97. printf("Start Chassis Identify, Time %d, force %d\n", g_BMCInfo.ChassisIdentifyTimeout, g_BMCInfo.ChassisIdentifyForce);
  98. OldPinState = stm32_gpio_read(IDENTIFY_PORT, IDENTIFY_PIN);
  99. while(g_BMCInfo.ChassisIdentifyForce || g_BMCInfo.ChassisIdentifyTimeout)
  100. {
  101. stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, GPIO_PIN_SET);
  102. usleep(250000);
  103. stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, GPIO_PIN_RESET);
  104. usleep(250000);
  105. stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, GPIO_PIN_SET);
  106. usleep(250000);
  107. stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, GPIO_PIN_RESET);
  108. usleep(250000);
  109. if(g_BMCInfo.ChassisIdentifyTimeout>0)
  110. {
  111. g_BMCInfo.ChassisIdentifyTimeout--;
  112. }
  113. }
  114. //恢复LED灯的状态
  115. stm32_gpio_write(IDENTIFY_PORT, IDENTIFY_PIN, OldPinState);
  116. printf("Chassis Identify finish.\n");
  117. pthread_exit(0);
  118. }