main.c 7.4 KB

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