main.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. #include "PendActionTask.h"
  30. #include "Api.h"
  31. /* gloabl varible */
  32. BMCInfo_t g_BMCInfo;
  33. pthread_t gThreadIDs[256];
  34. uint8_t gThreadIndex = 0;
  35. SensorHistoryInfo_T gSensorHistoryInfo[SENSOR_NUMBERS];
  36. FanInfo_T gFanInfo[FAN_NUMBERS] = {
  37. /* Index | name | mode | level | speed */
  38. {0, {"Fan1"}, 0, 0, 0 },
  39. {1, {"Fan2"}, 0, 0, 0 },
  40. {2, {"Fan3"}, 0, 0, 0 },
  41. {3, {"Fan4"}, 0, 0, 0 },
  42. };
  43. BladeStatus_T gBladeStatus[BLADE_NUMBERS] = {
  44. /* healthStatus | name | slotID | pwrStatus */
  45. { 0, "---", 0, 0},
  46. { 1, "IPMC1", 2, 1},
  47. { 0, "---", 0, 0},
  48. { 0, "---", 0, 0},
  49. { 0, "---", 0, 0},
  50. };
  51. //void *test_thread(void *var);
  52. //uint8_t test_flag = 0;
  53. //pthread_mutex_t mutex;
  54. static int tmp_fd;
  55. void main(void)
  56. {
  57. // if(0 != cm_Auth_Encrp_Init(1, 1, TRUE))
  58. // {
  59. // printf("Initialize AT88SC0104C failed!\n");
  60. // sleep(1);
  61. // return;
  62. // }
  63. // if(0 != cm_Auth_Encrp_Personal(1, 1))
  64. // {
  65. // printf("Personal AT88SC0104C failed!\n");
  66. // sleep(1);
  67. // return ;
  68. // }
  69. // if(0 != test_cryptomem())
  70. // {
  71. // while(1)
  72. // {
  73. // printf("Illegal Board!\n");
  74. // sleep(3);
  75. // }
  76. // }
  77. PlatformInit();
  78. Init_IPMI_FRU_SDR_SEL();
  79. InitSdrConfig();
  80. InitSelConfig();
  81. Init_SessionTbl();
  82. InitTimerTaskTbl();
  83. Init_UserInfoTbl();
  84. pthread_mutex_init(&api_bridge_mutex, NULL);
  85. //初始化系统时间
  86. system("date -s 2020.05.12-00:00:00");
  87. //Initialize IP
  88. char cmdStr[100];
  89. LanInfo_T *pSetLanInfo = &g_BMCInfo.IpmiConfig.LanInfo[0];
  90. // //down
  91. // sprintf(cmdStr, "ifconfig %s down", pSetLanInfo->EthName);
  92. // printf("%s\n", cmdStr);
  93. // system(cmdStr);
  94. // //set mac
  95. // sprintf(cmdStr, "ifconfig %s hw ether %02x:%02x:%02x:%02x:%02x:%02x",
  96. // pSetLanInfo->EthName, pSetLanInfo->MACAddr[0], pSetLanInfo->MACAddr[1],
  97. // pSetLanInfo->MACAddr[2], pSetLanInfo->MACAddr[3],
  98. // pSetLanInfo->MACAddr[4], pSetLanInfo->MACAddr[5]);
  99. // printf("%s\n", cmdStr);
  100. // system(cmdStr);
  101. //ip, broadcast, netmask
  102. sprintf(cmdStr, "ifconfig %s %d.%d.%d.%d broadcast %d.%d.%d.%d netmask %d.%d.%d.%d up",
  103. pSetLanInfo->EthName, pSetLanInfo->IPAddr[0], pSetLanInfo->IPAddr[1],
  104. pSetLanInfo->IPAddr[2], pSetLanInfo->IPAddr[3], pSetLanInfo->BroadCast[0],
  105. pSetLanInfo->BroadCast[1], pSetLanInfo->BroadCast[2], pSetLanInfo->BroadCast[3],
  106. pSetLanInfo->NetMask[0], pSetLanInfo->NetMask[1], pSetLanInfo->NetMask[2],
  107. pSetLanInfo->NetMask[3]);
  108. printf("%s\n", cmdStr);
  109. system(cmdStr);
  110. printf("\tChassisID %#02x, SlotID %#02x\r\n", g_BMCInfo.ChassisID, g_BMCInfo.SlotID);
  111. if(g_BMCInfo.IpmiConfig.PrimaryIPMBSupport)
  112. {
  113. printf("\tPrimaryIPMBBus: %d, channel %d, Addr %#02x\n", g_BMCInfo.IpmiConfig.PrimaryIPMBBus,
  114. PRIMARY_IPMB_CHANNEL, g_BMCInfo.IpmiConfig.PrimaryIPMBAddr);
  115. }
  116. if(g_BMCInfo.IpmiConfig.SecondaryIPMBSupport)
  117. {
  118. printf("\tSecondaryIPMBBus %d, Channel %d, Addr %#02x\n", g_BMCInfo.IpmiConfig.SecondaryIPMBBus,
  119. SECONDARY_IPMB_CHANNEL, g_BMCInfo.IpmiConfig.SecondaryIPMBAddr);
  120. }
  121. /* Create TimerTask */
  122. // gThreadIndex = 0;
  123. // if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,TimerTask,NULL))
  124. // {
  125. // printf("%s: Create TimerTask thread failed!\n", __FUNCTION__);
  126. // }
  127. signal(SIGALRM, TimerTask);
  128. struct itimerval new_value;
  129. new_value.it_value.tv_sec = 0;
  130. new_value.it_value.tv_usec = 1;
  131. new_value.it_interval.tv_sec = 1;
  132. new_value.it_interval.tv_usec = 0;
  133. setitimer(ITIMER_REAL, &new_value, NULL);
  134. /* Create MsgHndlr Task */
  135. gThreadIndex++;
  136. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,MsgHndlrTask,NULL))
  137. {
  138. printf("%s: Create MsgHndlrTask thread failed!\n", __FUNCTION__);
  139. }
  140. /* Create ChassisTimerTask */
  141. gThreadIndex++;
  142. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,ChassisTimerTask,NULL))
  143. {
  144. printf("%s: Create ChassisTimerTask thread failed!\n", __FUNCTION__);
  145. }
  146. /* Create SensorMonitorTask */
  147. gThreadIndex++;
  148. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,SensorMonitorTask,NULL))
  149. {
  150. printf("%s: Create SensorMonitorTask thread failed!\n", __FUNCTION__);
  151. }
  152. /* Create UDS interface */
  153. gThreadIndex++;
  154. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,UDSIfcTask,NULL))
  155. {
  156. printf("%s: Create UDSIfcTask thread failed!\n", __FUNCTION__);
  157. }
  158. /* Create LAN interface */
  159. gThreadIndex++;
  160. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,LANIfcTask,NULL))
  161. {
  162. printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
  163. }
  164. /* Create IPMB interface */
  165. uint8_t primaryIpmbSelect = 0; //primary
  166. gThreadIndex++;
  167. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,IPMBIfcTask,&primaryIpmbSelect))
  168. {
  169. printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
  170. }
  171. uint8_t secondaryIpmbSelect = 1; //secondary
  172. gThreadIndex++;
  173. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,IPMBIfcTask,&secondaryIpmbSelect))
  174. {
  175. printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
  176. }
  177. /* Create PendActionTask */
  178. gThreadIndex++;
  179. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,PendActionTask,NULL))
  180. {
  181. printf("%s: Create PendActionTask thread failed!\n", __FUNCTION__);
  182. }
  183. /* Create Update FPGA thread */
  184. /* Create UDS interface */
  185. /* Create UDS interface */
  186. /* Create UDS interface */
  187. // pthread_mutex_init(&mutex,NULL);
  188. // tmp_fd = open("/dev/i2c2", O_RDWR);;
  189. // uint8_t buf[7] = {0x20, 0xb8, 0x8, 0x20, 0x4, 0x1, 0xdb };
  190. // gThreadIndex++;
  191. // pthread_create(&gThreadIDs[gThreadIndex],NULL,test_thread,NULL);
  192. while(1) //在这里实现各线程的健康状态检测,发现出错的线程就重启它。
  193. {
  194. sleep(1);
  195. }
  196. }
  197. // void *test_thread(void *var)
  198. // {
  199. // uint8_t len, i;
  200. // uint8_t recvBuf[100];
  201. // printf("---> test_thread start...\n");
  202. // stm32_i2c_set_addr(tmp_fd, 0x44);
  203. // uint8_t buf[7] = {0x20, 0xb8, 0x8, 0x20, 0x4, 0x1, 0xdb };
  204. // while(1)
  205. // {
  206. // pthread_mutex_lock(&mutex);
  207. // pthread_mutex_unlock(&mutex);
  208. // len = 0;
  209. // len = stm32_i2c_slave_recv(tmp_fd, recvBuf);
  210. // if(len > 0)
  211. // {
  212. // printf("Recv: ");
  213. // for(i=0;i<len; i++)
  214. // printf("%#x ", recvBuf[i]);
  215. // printf("\n");
  216. // test_flag = 1;
  217. // //sleep(1);
  218. // // if(0 != stm32_i2c_master_write(tmp_fd, buf[0], &buf[1], 6))
  219. // // {
  220. // // printf("---> Send ipmb error!\n");
  221. // // }
  222. // // else
  223. // // printf("---> send ipmb ok\n");
  224. // }
  225. // }
  226. // }