main.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 <stdlib.h>
  10. //#include <fcntl.h>
  11. #include "linux/fcntl.h"
  12. #include <signal.h>
  13. #include <sys/time.h>
  14. #include "com_BmcType.h"
  15. #include "com_IPMIDefs.h"
  16. #include "com_Message.h"
  17. #include "BmcType.h"
  18. #include "main.h"
  19. #include "Session.h"
  20. #include "LANIfc.h"
  21. #include "UDSIfc.h"
  22. #include "IPMBIfc.h"
  23. #include "MsgHndlrTask.h"
  24. #include "ChassisTimerTask.h"
  25. #include "TimerTask.h"
  26. #include "CM_LIB.h"
  27. #include "stm32f429xx.h"
  28. #include "com_gpio.h"
  29. #include "hal_interface_api.h"
  30. #include "com_BMCCfg.h"
  31. #include "PendActionTask.h"
  32. #include "Api.h"
  33. #include "driver.h"
  34. #include "sensor_tbl.h"
  35. #include "com_IPMI_SDRRecord.h"
  36. #include "AuthLicense.h"
  37. /* gloabl varible */
  38. BMCInfo_t g_BMCInfo;
  39. pthread_t gThreadIDs[256];
  40. uint8_t gThreadIndex = 0;
  41. uint8_t gChassisIPMBAddr[BLADE_NUMBERS] = {0x82, 0x84, 0x86, 0x88, 0x8A, 0x8C,
  42. 0x8E, 0x90, 0x92, 0x94};
  43. SensorHistoryInfo_T gSensorHistoryInfo[SENSOR_NUMBERS];
  44. FanInfo_T gFanInfo[FAN_NUMBERS] = {
  45. // /* Index | name | mode | level | speed */
  46. // {0, {"Fan1"}, 0, 0, 0 },
  47. // {1, {"Fan2"}, 0, 0, 0 },
  48. // {2, {"Fan3"}, 0, 0, 0 },
  49. // {3, {"Fan4"}, 0, 0, 0 },
  50. };
  51. BladeStatus_T gBladeStatus[BLADE_NUMBERS] = {
  52. /* healthStatus | name | slotID | pwrStatus */
  53. { 0, "---", 0, 0},
  54. { 0, "---", 0, 0},
  55. { 0, "---", 0, 0},
  56. { 0, "---", 0, 0},
  57. { 0, "---", 0, 0},
  58. { 0, "---", 0, 0},
  59. { 0, "---", 0, 0},
  60. { 0, "---", 0, 0},
  61. { 0, "---", 0, 0},
  62. { 0, "---", 0, 0},
  63. };
  64. //void *test_thread(void *var);
  65. //uint8_t test_flag = 0;
  66. static int tmp_fd;
  67. void main(void)
  68. {
  69. // if(0 != cm_Auth_Encrp_Init(1, 1, TRUE))
  70. // {
  71. // printf("Initialize AT88SC0104C failed!\n");
  72. // sleep(1);
  73. // return;
  74. // }
  75. // printf("cm_Auth_Encrp_Init ok\n");
  76. // #if 0
  77. // if(0 != cm_Auth_Encrp_Personal(1, 1))
  78. // {
  79. // printf("Personal AT88SC0104C failed!\n");
  80. // sleep(1);
  81. // return ;
  82. // }
  83. // #endif
  84. // if(0 != test_cryptomem())
  85. // {
  86. // while(1)
  87. // {
  88. // printf("Illegal Board!\n");
  89. // sleep(3);
  90. // }
  91. // }
  92. //检查软件授权
  93. // if(CheckLicense() != 0)
  94. // {
  95. // system("killall -9 damon.sh");
  96. // exit(0);
  97. // }
  98. PlatformInit();
  99. Init_IPMI_FRU_SDR_SEL();
  100. Init_SessionTbl();
  101. InitTimerTaskTbl();
  102. pthread_mutex_init(&api_bridge_mutex, NULL);
  103. pthread_mutex_init(&Flash_Mutex, NULL);
  104. //初始化系统时间
  105. system("date -s 2020.05.12-00:00:00");
  106. //Initialize IP
  107. char cmdStr[100];
  108. LanInfo_T *pSetLanInfo = &g_BMCInfo.LanInfo[0];
  109. // //down
  110. // sprintf(cmdStr, "ifconfig %s down", pSetLanInfo->EthName);
  111. // printf("%s\n", cmdStr);
  112. // system(cmdStr);
  113. // //set mac
  114. // sprintf(cmdStr, "ifconfig %s hw ether %02x:%02x:%02x:%02x:%02x:%02x",
  115. // pSetLanInfo->EthName, pSetLanInfo->MACAddr[0], pSetLanInfo->MACAddr[1],
  116. // pSetLanInfo->MACAddr[2], pSetLanInfo->MACAddr[3],
  117. // pSetLanInfo->MACAddr[4], pSetLanInfo->MACAddr[5]);
  118. // printf("%s\n", cmdStr);
  119. // system(cmdStr);
  120. //ip, broadcast, netmask
  121. sprintf(cmdStr, "ifconfig %s %d.%d.%d.%d broadcast %d.%d.%d.%d netmask %d.%d.%d.%d up",
  122. pSetLanInfo->EthName, pSetLanInfo->IPAddr[0], pSetLanInfo->IPAddr[1],
  123. pSetLanInfo->IPAddr[2], pSetLanInfo->IPAddr[3], pSetLanInfo->BroadCast[0],
  124. pSetLanInfo->BroadCast[1], pSetLanInfo->BroadCast[2], pSetLanInfo->BroadCast[3],
  125. pSetLanInfo->NetMask[0], pSetLanInfo->NetMask[1], pSetLanInfo->NetMask[2],
  126. pSetLanInfo->NetMask[3]);
  127. printf("%s\n", cmdStr);
  128. system(cmdStr);
  129. printf("\tChassisID %#02x, SlotID %#02x\r\n", g_BMCInfo.ChassisID, g_BMCInfo.SlotID);
  130. if(g_BMCInfo.IpmiConfig.PrimaryIPMBSupport)
  131. {
  132. printf("\tPrimaryIPMBBus: %d, channel %d, Addr %#02x\n", g_BMCInfo.IpmiConfig.PrimaryIPMBBus,
  133. PRIMARY_IPMB_CHANNEL, g_BMCInfo.PrimaryIPMBAddr);
  134. }
  135. if(g_BMCInfo.IpmiConfig.SecondaryIPMBSupport)
  136. {
  137. printf("\tSecondaryIPMBBus %d, Channel %d, Addr %#02x\n", g_BMCInfo.IpmiConfig.SecondaryIPMBBus,
  138. SECONDARY_IPMB_CHANNEL, g_BMCInfo.SecondaryIPMBAddr);
  139. }
  140. /* Create TimerTask */
  141. // gThreadIndex = 0;
  142. // if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,TimerTask,NULL))
  143. // {
  144. // printf("%s: Create TimerTask thread failed!\n", __FUNCTION__);
  145. // }
  146. signal(SIGALRM, TimerTask);
  147. struct itimerval new_value;
  148. new_value.it_value.tv_sec = 0;
  149. new_value.it_value.tv_usec = 1;
  150. new_value.it_interval.tv_sec = 1;
  151. new_value.it_interval.tv_usec = 0;
  152. setitimer(ITIMER_REAL, &new_value, NULL);
  153. /* Create MsgHndlr Task */
  154. gThreadIndex++;
  155. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,MsgHndlrTask,NULL))
  156. {
  157. printf("%s: Create MsgHndlrTask thread failed!\n", __FUNCTION__);
  158. }
  159. /* Create ChassisTimerTask */
  160. gThreadIndex++;
  161. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,ChassisTimerTask,NULL))
  162. {
  163. printf("%s: Create ChassisTimerTask thread failed!\n", __FUNCTION__);
  164. }
  165. /* Create SensorMonitorTask */
  166. gThreadIndex++;
  167. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,SensorMonitorTask,NULL))
  168. {
  169. printf("%s: Create SensorMonitorTask thread failed!\n", __FUNCTION__);
  170. }
  171. /* Create UDS interface */
  172. gThreadIndex++;
  173. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,UDSIfcTask,NULL))
  174. {
  175. printf("%s: Create UDSIfcTask thread failed!\n", __FUNCTION__);
  176. }
  177. /* Create LAN interface */
  178. gThreadIndex++;
  179. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,LANIfcTask,NULL))
  180. {
  181. printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
  182. }
  183. /* Create IPMB interface */
  184. uint8_t primaryIpmbSelect = 0; //primary
  185. gThreadIndex++;
  186. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,IPMBIfcTask,&primaryIpmbSelect))
  187. {
  188. printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
  189. }
  190. uint8_t secondaryIpmbSelect = 1; //secondary
  191. gThreadIndex++;
  192. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,IPMBIfcTask,&secondaryIpmbSelect))
  193. {
  194. printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
  195. }
  196. /* Create PendActionTask */
  197. gThreadIndex++;
  198. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,PendActionTask,NULL))
  199. {
  200. printf("%s: Create PendActionTask thread failed!\n", __FUNCTION__);
  201. }
  202. /* Create Update FPGA thread */
  203. /* Create UDS interface */
  204. /* Create UDS interface */
  205. /* Create UDS interface */
  206. // pthread_mutex_init(&mutex,NULL);
  207. // tmp_fd = open("/dev/i2c2", O_RDWR);;
  208. // uint8_t buf[7] = {0x20, 0xb8, 0x8, 0x20, 0x4, 0x1, 0xdb };
  209. // gThreadIndex++;
  210. // pthread_create(&gThreadIDs[gThreadIndex],NULL,test_thread,NULL);
  211. /* 看门狗,10s无喂狗就复位 */
  212. // int fd_iwdg = open("/dev/iwdg", O_RDWR);
  213. // ioctl(fd_iwdg, START_IWATCHDOG, NULL); //打开看狗
  214. while(1) //在这里实现各线程的健康状态检测,发现出错的线程就重启它。
  215. {
  216. // //喂看门狗
  217. // if(ioctl(fd_iwdg, FEED_WATCHDOG, NULL) != 0)
  218. // {
  219. // printf("---> Feed watchdog failed\n");
  220. // }
  221. sleep(10);
  222. }
  223. }
  224. // void *test_thread(void *var)
  225. // {
  226. // uint8_t len, i;
  227. // uint8_t recvBuf[100];
  228. // printf("---> test_thread start...\n");
  229. // stm32_i2c_set_addr(tmp_fd, 0x44);
  230. // uint8_t buf[7] = {0x20, 0xb8, 0x8, 0x20, 0x4, 0x1, 0xdb };
  231. // while(1)
  232. // {
  233. // pthread_mutex_lock(&mutex);
  234. // pthread_mutex_unlock(&mutex);
  235. // len = 0;
  236. // len = stm32_i2c_slave_recv(tmp_fd, recvBuf);
  237. // if(len > 0)
  238. // {
  239. // printf("Recv: ");
  240. // for(i=0;i<len; i++)
  241. // printf("%#x ", recvBuf[i]);
  242. // printf("\n");
  243. // test_flag = 1;
  244. // //sleep(1);
  245. // // if(0 != stm32_i2c_master_write(tmp_fd, buf[0], &buf[1], 6))
  246. // // {
  247. // // printf("---> Send ipmb error!\n");
  248. // // }
  249. // // else
  250. // // printf("---> send ipmb ok\n");
  251. // }
  252. // }
  253. // }