main.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. /* gloabl varible */
  29. BMCInfo_t g_BMCInfo;
  30. pthread_t gThreadIDs[256];
  31. uint8_t gThreadIndex = 0;
  32. //void *test_thread(void *var);
  33. //uint8_t test_flag = 0;
  34. //pthread_mutex_t mutex;
  35. static int tmp_fd;
  36. void main(void)
  37. {
  38. // if(0 != cm_Auth_Encrp_Init(1, 1, TRUE))
  39. // {
  40. // printf("Initialize AT88SC0104C failed!\n");
  41. // sleep(1);
  42. // return;
  43. // }
  44. // if(0 != cm_Auth_Encrp_Personal(1, 1))
  45. // {
  46. // printf("Personal AT88SC0104C failed!\n");
  47. // sleep(1);
  48. // return ;
  49. // }
  50. // if(0 != test_cryptomem())
  51. // {
  52. // while(1)
  53. // {
  54. // printf("Illegal Board!\n");
  55. // sleep(3);
  56. // }
  57. // }
  58. PlatformInit();
  59. Init_IPMI_FRU_SDR_SEL();
  60. InitSdrConfig();
  61. InitSelConfig();
  62. Init_SessionTbl();
  63. InitTimerTaskTbl();
  64. Init_UserInfoTbl();
  65. printf("\tChassisID %#02x, SlotID %#02x\r\n", g_BMCInfo.ChassisID, g_BMCInfo.SlotID);
  66. if(g_BMCInfo.IpmiConfig.PrimaryIPMBSupport)
  67. {
  68. printf("\tPrimaryIPMBBus: %d, channel %d, Addr %#02x\n", g_BMCInfo.IpmiConfig.PrimaryIPMBBus,
  69. PRIMARY_IPMB_CHANNEL, g_BMCInfo.IpmiConfig.PrimaryIPMBAddr);
  70. }
  71. if(g_BMCInfo.IpmiConfig.SecondaryIPMBSupport)
  72. {
  73. printf("\tSecondaryIPMBBus %d, Channel %d, Addr %#02x\n", g_BMCInfo.IpmiConfig.SecondaryIPMBBus,
  74. SECONDARY_IPMB_CHANNEL, g_BMCInfo.IpmiConfig.SecondaryIPMBAddr);
  75. }
  76. /* Create TimerTask */
  77. // gThreadIndex = 0;
  78. // if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,TimerTask,NULL))
  79. // {
  80. // printf("%s: Create TimerTask thread failed!\n", __FUNCTION__);
  81. // }
  82. signal(SIGALRM, TimerTask);
  83. struct itimerval new_value;
  84. new_value.it_value.tv_sec = 0;
  85. new_value.it_value.tv_usec = 1;
  86. new_value.it_interval.tv_sec = 1;
  87. new_value.it_interval.tv_usec = 0;
  88. setitimer(ITIMER_REAL, &new_value, NULL);
  89. /* Create MsgHndlr Task */
  90. gThreadIndex++;
  91. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,MsgHndlrTask,NULL))
  92. {
  93. printf("%s: Create MsgHndlrTask thread failed!\n", __FUNCTION__);
  94. }
  95. /* Create ChassisTimerTask */
  96. gThreadIndex++;
  97. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,ChassisTimerTask,NULL))
  98. {
  99. printf("%s: Create ChassisTimerTask thread failed!\n", __FUNCTION__);
  100. }
  101. /* Create SensorMonitorTask */
  102. gThreadIndex++;
  103. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,SensorMonitorTask,NULL))
  104. {
  105. printf("%s: Create SensorMonitorTask thread failed!\n", __FUNCTION__);
  106. }
  107. /* Create UDS interface */
  108. gThreadIndex++;
  109. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,UDSIfcTask,NULL))
  110. {
  111. printf("%s: Create UDSIfcTask thread failed!\n", __FUNCTION__);
  112. }
  113. /* Create LAN interface */
  114. gThreadIndex++;
  115. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,LANIfcTask,NULL))
  116. {
  117. printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
  118. }
  119. /* Create IPMB interface */
  120. uint8_t primaryIpmbSelect = 0; //primary
  121. gThreadIndex++;
  122. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,IPMBIfcTask,&primaryIpmbSelect))
  123. {
  124. printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
  125. }
  126. uint8_t secondaryIpmbSelect = 1; //secondary
  127. gThreadIndex++;
  128. if(0 != pthread_create(&gThreadIDs[gThreadIndex],NULL,IPMBIfcTask,&secondaryIpmbSelect))
  129. {
  130. printf("%s: Create LANIfcTask thread failed!\n", __FUNCTION__);
  131. }
  132. /* Create Update FPGA thread */
  133. /* Create UDS interface */
  134. /* Create UDS interface */
  135. /* Create UDS interface */
  136. // pthread_mutex_init(&mutex,NULL);
  137. // tmp_fd = open("/dev/i2c2", O_RDWR);;
  138. // uint8_t buf[7] = {0x20, 0xb8, 0x8, 0x20, 0x4, 0x1, 0xdb };
  139. // gThreadIndex++;
  140. // pthread_create(&gThreadIDs[gThreadIndex],NULL,test_thread,NULL);
  141. while(1) //在这里实现各线程的健康状态检测,发现出错的线程就重启它。
  142. {
  143. // if(test_flag)
  144. // {
  145. // test_flag = 0;
  146. // pthread_mutex_lock(&mutex);
  147. // if(0 != stm32_i2c_master_write(tmp_fd, buf[0], &buf[1], 6))
  148. // {
  149. // printf("---> Send ipmb error!\n");
  150. // }
  151. // else
  152. // printf("---> send ipmb ok\n");
  153. // pthread_mutex_unlock(&mutex);
  154. // }
  155. sleep(1);
  156. //printf("Hello...\n");
  157. }
  158. }
  159. // void *test_thread(void *var)
  160. // {
  161. // uint8_t len, i;
  162. // uint8_t recvBuf[100];
  163. // printf("---> test_thread start...\n");
  164. // stm32_i2c_set_addr(tmp_fd, 0x44);
  165. // uint8_t buf[7] = {0x20, 0xb8, 0x8, 0x20, 0x4, 0x1, 0xdb };
  166. // while(1)
  167. // {
  168. // pthread_mutex_lock(&mutex);
  169. // pthread_mutex_unlock(&mutex);
  170. // len = 0;
  171. // len = stm32_i2c_slave_recv(tmp_fd, recvBuf);
  172. // if(len > 0)
  173. // {
  174. // printf("Recv: ");
  175. // for(i=0;i<len; i++)
  176. // printf("%#x ", recvBuf[i]);
  177. // printf("\n");
  178. // test_flag = 1;
  179. // //sleep(1);
  180. // // if(0 != stm32_i2c_master_write(tmp_fd, buf[0], &buf[1], 6))
  181. // // {
  182. // // printf("---> Send ipmb error!\n");
  183. // // }
  184. // // else
  185. // // printf("---> send ipmb ok\n");
  186. // }
  187. // }
  188. // }