main.c 5.7 KB

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