main.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * bmc_app application main code.
  3. */
  4. #include <stdio.h>
  5. #include <stdint.h>
  6. #include <sys/prctl.h>
  7. #include <semaphore.h>
  8. #include <pthread.h>
  9. #include <fcntl.h>
  10. #include <signal.h>
  11. #include <sys/time.h>
  12. #include "com_BmcType.h"
  13. #include "com_IPMIDefs.h"
  14. #include "com_Message.h"
  15. #include "BmcType.h"
  16. #include "main.h"
  17. #include "Session.h"
  18. #include "LANIfc.h"
  19. #include "UDSIfc.h"
  20. #include "IPMBIfc.h"
  21. #include "MsgHndlrTask.h"
  22. #include "ChassisTimerTask.h"
  23. #include "TimerTask.h"
  24. #include "CM_LIB.h"
  25. #include "stm32f429xx.h"
  26. #include "com_gpio.h"
  27. #include "hal_interface_api.h"
  28. #include "com_BMCCfg.h"
  29. /* gloabl varible */
  30. BMCInfo_t g_BMCInfo;
  31. pthread_t gThreadIDs[256];
  32. uint8_t gThreadIndex = 0;
  33. SensorHistoryInfo_T gSensorHistoryInfo[SENSOR_NUMBERS];
  34. FanInfo_T gFanInfo[FAN_NUMBERS] = {
  35. /* Index | name | mode | level | speed */
  36. {0, {"Fan1"}, 0, 0, 0 },
  37. {1, {"Fan2"}, 0, 0, 0 },
  38. {2, {"Fan3"}, 0, 0, 0 },
  39. {3, {"Fan4"}, 0, 0, 0 },
  40. };
  41. BladeStatus_T gBladeStatus[BLADE_NUMBERS] = {
  42. /* healthStatus | name | slotID | pwrStatus */
  43. { 0, "---", 0, 0},
  44. { 1, "IPMC1", 2, 1},
  45. { 0, "---", 0, 0},
  46. { 0, "---", 0, 0},
  47. { 0, "---", 0, 0},
  48. };
  49. //void *test_thread(void *var);
  50. //uint8_t test_flag = 0;
  51. //pthread_mutex_t mutex;
  52. static int tmp_fd;
  53. void main(void)
  54. {
  55. // if(0 != cm_Auth_Encrp_Init(1, 1, TRUE))
  56. // {
  57. // printf("Initialize AT88SC0104C failed!\n");
  58. // sleep(1);
  59. // return;
  60. // }
  61. // if(0 != cm_Auth_Encrp_Personal(1, 1))
  62. // {
  63. // printf("Personal AT88SC0104C failed!\n");
  64. // sleep(1);
  65. // return ;
  66. // }
  67. // if(0 != test_cryptomem())
  68. // {
  69. // while(1)
  70. // {
  71. // printf("Illegal Board!\n");
  72. // sleep(3);
  73. // }
  74. // }
  75. PlatformInit();
  76. Init_IPMI_FRU_SDR_SEL();
  77. InitSdrConfig();
  78. InitSelConfig();
  79. Init_SessionTbl();
  80. InitTimerTaskTbl();
  81. Init_UserInfoTbl();
  82. printf("\tChassisID %#02x, SlotID %#02x\r\n", g_BMCInfo.ChassisID, g_BMCInfo.SlotID);
  83. if(g_BMCInfo.IpmiConfig.PrimaryIPMBSupport)
  84. {
  85. printf("\tPrimaryIPMBBus: %d, channel %d, Addr %#02x\n", g_BMCInfo.IpmiConfig.PrimaryIPMBBus,
  86. PRIMARY_IPMB_CHANNEL, g_BMCInfo.IpmiConfig.PrimaryIPMBAddr);
  87. }
  88. if(g_BMCInfo.IpmiConfig.SecondaryIPMBSupport)
  89. {
  90. printf("\tSecondaryIPMBBus %d, Channel %d, Addr %#02x\n", g_BMCInfo.IpmiConfig.SecondaryIPMBBus,
  91. SECONDARY_IPMB_CHANNEL, g_BMCInfo.IpmiConfig.SecondaryIPMBAddr);
  92. }
  93. /* Create TimerTask */
  94. // gThreadIndex = 0;
  95. // if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,TimerTask,NULL))
  96. // {
  97. // printf("%s: Create TimerTask thread failed!\n", __FUNCTION__);
  98. // }
  99. signal(SIGALRM, TimerTask);
  100. struct itimerval new_value;
  101. new_value.it_value.tv_sec = 0;
  102. new_value.it_value.tv_usec = 1;
  103. new_value.it_interval.tv_sec = 1;
  104. new_value.it_interval.tv_usec = 0;
  105. setitimer(ITIMER_REAL, &new_value, NULL);
  106. /* Create MsgHndlr Task */
  107. gThreadIndex++;
  108. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,MsgHndlrTask,NULL))
  109. {
  110. printf("%s: Create MsgHndlrTask thread failed!\n", __FUNCTION__);
  111. }
  112. /* Create ChassisTimerTask */
  113. gThreadIndex++;
  114. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,ChassisTimerTask,NULL))
  115. {
  116. printf("%s: Create ChassisTimerTask thread failed!\n", __FUNCTION__);
  117. }
  118. /* Create SensorMonitorTask */
  119. gThreadIndex++;
  120. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,SensorMonitorTask,NULL))
  121. {
  122. printf("%s: Create SensorMonitorTask thread failed!\n", __FUNCTION__);
  123. }
  124. /* Create UDS interface */
  125. gThreadIndex++;
  126. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,UDSIfcTask,NULL))
  127. {
  128. printf("%s: Create UDSIfcTask thread failed!\n", __FUNCTION__);
  129. }
  130. /* Create LAN interface */
  131. gThreadIndex++;
  132. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,LANIfcTask,NULL))
  133. {
  134. printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
  135. }
  136. // /* Create IPMB interface */
  137. // uint8_t primaryIpmbSelect = 0; //primary
  138. // gThreadIndex++;
  139. // if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,IPMBIfcTask,&primaryIpmbSelect))
  140. // {
  141. // printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
  142. // }
  143. // uint8_t secondaryIpmbSelect = 1; //secondary
  144. // gThreadIndex++;
  145. // if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,IPMBIfcTask,&secondaryIpmbSelect))
  146. // {
  147. // printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
  148. // }
  149. /* Create Update FPGA thread */
  150. /* Create UDS interface */
  151. /* Create UDS interface */
  152. /* Create UDS interface */
  153. // pthread_mutex_init(&mutex,NULL);
  154. // tmp_fd = open("/dev/i2c2", O_RDWR);;
  155. // uint8_t buf[7] = {0x20, 0xb8, 0x8, 0x20, 0x4, 0x1, 0xdb };
  156. // gThreadIndex++;
  157. // pthread_create(&gThreadIDs[gThreadIndex],NULL,test_thread,NULL);
  158. while(1) //在这里实现各线程的健康状态检测,发现出错的线程就重启它。
  159. {
  160. // if(test_flag)
  161. // {
  162. // test_flag = 0;
  163. // pthread_mutex_lock(&mutex);
  164. // if(0 != stm32_i2c_master_write(tmp_fd, buf[0], &buf[1], 6))
  165. // {
  166. // printf("---> Send ipmb error!\n");
  167. // }
  168. // else
  169. // printf("---> send ipmb ok\n");
  170. // pthread_mutex_unlock(&mutex);
  171. // }
  172. sleep(1);
  173. //printf("Hello...\n");
  174. }
  175. }
  176. // void *test_thread(void *var)
  177. // {
  178. // uint8_t len, i;
  179. // uint8_t recvBuf[100];
  180. // printf("---> test_thread start...\n");
  181. // stm32_i2c_set_addr(tmp_fd, 0x44);
  182. // uint8_t buf[7] = {0x20, 0xb8, 0x8, 0x20, 0x4, 0x1, 0xdb };
  183. // while(1)
  184. // {
  185. // pthread_mutex_lock(&mutex);
  186. // pthread_mutex_unlock(&mutex);
  187. // len = 0;
  188. // len = stm32_i2c_slave_recv(tmp_fd, recvBuf);
  189. // if(len > 0)
  190. // {
  191. // printf("Recv: ");
  192. // for(i=0;i<len; i++)
  193. // printf("%#x ", recvBuf[i]);
  194. // printf("\n");
  195. // test_flag = 1;
  196. // //sleep(1);
  197. // // if(0 != stm32_i2c_master_write(tmp_fd, buf[0], &buf[1], 6))
  198. // // {
  199. // // printf("---> Send ipmb error!\n");
  200. // // }
  201. // // else
  202. // // printf("---> send ipmb ok\n");
  203. // }
  204. // }
  205. // }