main.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /****************************************Copyright (c)****************************************************
  2. **
  3. **
  4. **--------------File Info---------------------------------------------------------------------------------
  5. ** File name: main.c
  6. ** Descriptions:
  7. **
  8. **--------------------------------------------------------------------------------------------------------
  9. ** Created by:
  10. ** Created date:
  11. ** Version:
  12. ** Descriptions:
  13. **
  14. **--------------------------------------------------------------------------------------------------------
  15. ** Modified by:
  16. ** Modified date:
  17. ** Version:
  18. ** Descriptions:
  19. **
  20. *********************************************************************************************************/
  21. #define THIS_FILE_ID 1
  22. /* Includes ------------------------------------------------------------------*/
  23. #include "includes.h"
  24. void MY_NVIC_Init()
  25. {
  26. NVIC_InitTypeDef NVIC_InitStructure;
  27. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //选择中断分组2
  28. RunMake(THIS_FILE_ID);
  29. //串口1
  30. NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  31. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  32. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  33. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  34. NVIC_Init(&NVIC_InitStructure);
  35. RunMake(THIS_FILE_ID);
  36. //串口2
  37. NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
  38. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  39. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  40. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  41. NVIC_Init(&NVIC_InitStructure);
  42. RunMake(THIS_FILE_ID);
  43. //串口3
  44. NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
  45. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  46. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  47. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  48. NVIC_Init(&NVIC_InitStructure);
  49. RunMake(THIS_FILE_ID);
  50. //ONOFF-CHECK
  51. NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
  52. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  53. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  54. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  55. NVIC_Init(&NVIC_InitStructure);
  56. RunMake(THIS_FILE_ID);
  57. //DMA中断设置
  58. NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn;
  59. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  60. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  61. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  62. NVIC_Init(&NVIC_InitStructure);
  63. #if UART2_TX_USE_DMA == 1
  64. NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel7_IRQn;
  65. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  66. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  67. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  68. NVIC_Init(&NVIC_InitStructure);
  69. #endif
  70. //RTC中断设置
  71. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //选择中断分组1
  72. NVIC_InitStructure.NVIC_IRQChannel =RTC_IRQn; //RTC中断通道
  73. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =1; //先占优先级1
  74. NVIC_InitStructure.NVIC_IRQChannelSubPriority =0; //从占优先级
  75. NVIC_InitStructure.NVIC_IRQChannelCmd =ENABLE; //RTC中断通道使能
  76. NVIC_Init(&NVIC_InitStructure);
  77. }
  78. /* id1, id2 will contain task identifications at run-time. */
  79. OS_TID id1, id2;
  80. /* Forward declaration of tasks. */
  81. __task void task1 (void);
  82. __task void task2 (void);
  83. __task void task1 (void){
  84. int ct=0;
  85. /* Obtain own system task identification number. */
  86. id1 = os_tsk_self();
  87. printf("task1 run!\r\n");
  88. /* Create task2 and obtain its task identification number. */
  89. //id2 = os_tsk_create (task2, 0);
  90. for (;;) {
  91. /* ... place code for task1 activity here ... */
  92. printf("[task1]tick=%d\r\n",ct++);
  93. /* Signal to task2 that task1 has completed. */
  94. // os_evt_set(0x0004, id2);
  95. /* Wait for completion of task2 activity. */
  96. /* 0xFFFF makes it wait without timeout. */
  97. /* 0x0004 represents bit 2. */
  98. //os_evt_wait_or(0x0004, 0xFFFF);
  99. /* Wait for 50 ms before restarting task1 activity. */
  100. os_dly_wait(200);
  101. }
  102. }
  103. __task void task2 (void) {
  104. int ct=0;
  105. printf("task2 run!\r\n");
  106. for (;;) {
  107. printf("[task2]tick=%d\r\n",ct++);
  108. /* Wait for completion of task1 activity. */
  109. /* 0xFFFF makes it wait without timeout. */
  110. /* 0x0004 represents bit 2. */
  111. os_evt_wait_or(0x0004, 0xFFFF);
  112. /* Wait for 20 ms before starting task2 activity. */
  113. os_dly_wait(50);
  114. /* ... place code for task2 activity here ... */
  115. /* Signal to task1 that task2 has completed. */
  116. os_evt_set(0x0004, id1);
  117. }
  118. }
  119. //#define LED_TASK_STK_SIZE 1024/8
  120. //U64 stkLEDTask[LED_TASK_STK_SIZE];
  121. extern unsigned char g_ucHSE_Flag;
  122. void CheckHSE(void)
  123. {
  124. unsigned long t;
  125. unsigned long i;
  126. if(g_ucHSE_Flag!=0)return;
  127. printf("--------------------\r\n");
  128. while(1){
  129. printf("External crystal failure!\r\n");
  130. for(i=0;i<10;i++){
  131. for(t=0;t<10000;t++){
  132. }
  133. }
  134. }
  135. }
  136. extern void DelayMs(unsigned short ms);
  137. /**********************************************************************************************************
  138. main()
  139. **********************************************************************************************************/
  140. int main (void)
  141. {
  142. int i;
  143. int Vbat;
  144. IWDG_Configuration(500);
  145. RTC_ConfigurationSTP1();//原RTC时钟配置如果彻底掉电后再开,要多花1秒时间配置RTC,此处分开两步来处理。
  146. ModemPinConfig();
  147. PowerCtrlInit();
  148. Uart1Init();
  149. printf("\r\nUart1Init OK!\r\n");
  150. Uart2Init();
  151. Uart3Init();
  152. KeyInit();
  153. SpeakerInit();
  154. MicrophoneInit();
  155. // RTC_Configuration();
  156. IWDG_ReloadCounter();//
  157. W25Q64_Init();
  158. FileSysInit();
  159. SysIniRead();
  160. // PrintfAllRFileInfo();
  161. LcdInit(); //放此地调整用户体验
  162. printf("LcdInit... OK!\r\n");
  163. GuiInit();
  164. IWDG_ReloadCounter();//
  165. printf("GuiInit... OK!\r\n");
  166. ShowBootAnimation();
  167. //电量检测,低电关机
  168. ADCInit();//ADC Init
  169. Vbat=-1;
  170. while(Vbat<0){
  171. Vbat=GetVbat();
  172. }
  173. if(Vbat<MIN_PWR_LEVEL){//电池电压小于335V 系统关机
  174. SlwTrace(INF,"Vbat Low!shutdown now!",1);
  175. PWR_EN_LOW;
  176. Sleeping();
  177. }
  178. RTC_ConfigurationSTP2();
  179. //显示开机动画
  180. // ShowBootAnimation();
  181. BeepInit();
  182. OnOff_Init();
  183. MY_NVIC_Init();
  184. SysTick_Config(SystemCoreClock / 100);
  185. /* Initialize RTX and start init */
  186. os_sys_init_user(MainTask,1,stkMainTask,sizeof(stkMainTask));
  187. return (0);
  188. }
  189. /*********************************************************************************************************
  190. END FILE
  191. *********************************************************************************************************/