main.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 RTC_EXTI_INITIAL()
  25. {
  26. NVIC_InitTypeDef NVIC_InitStructure;
  27. EXTI_InitTypeDef EXTI_InitStructure;
  28. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  29. //------------EXTI17 ?? -------------------
  30. EXTI_InitStructure.EXTI_Line = EXTI_Line17;
  31. EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  32. EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  33. EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  34. EXTI_Init(&EXTI_InitStructure);
  35. //------------
  36. NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn;//
  37. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  38. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  39. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  40. NVIC_Init(&NVIC_InitStructure);
  41. //-------------------------------------------
  42. }
  43. void MY_NVIC_Init()
  44. {
  45. NVIC_InitTypeDef NVIC_InitStructure;
  46. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //选择中断分组2
  47. RunMake(THIS_FILE_ID);
  48. //串口1
  49. NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  50. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  51. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //响应优先级
  52. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  53. NVIC_Init(&NVIC_InitStructure);
  54. RunMake(THIS_FILE_ID);
  55. //串口2
  56. NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
  57. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  58. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  59. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  60. NVIC_Init(&NVIC_InitStructure);
  61. RunMake(THIS_FILE_ID);
  62. //串口3
  63. NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
  64. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  65. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  66. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  67. NVIC_Init(&NVIC_InitStructure);
  68. RunMake(THIS_FILE_ID);
  69. //ONOFF-CHECK
  70. NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
  71. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  72. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  73. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  74. NVIC_Init(&NVIC_InitStructure);
  75. RunMake(THIS_FILE_ID);
  76. //DMA中断设置
  77. NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn;
  78. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  79. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  80. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  81. NVIC_Init(&NVIC_InitStructure);
  82. #if UART2_TX_USE_DMA == 1
  83. NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel7_IRQn;
  84. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  85. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  86. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  87. NVIC_Init(&NVIC_InitStructure);
  88. #endif
  89. // //RTC中断设置
  90. // NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //选择中断分组1
  91. // NVIC_InitStructure.NVIC_IRQChannel =RTC_IRQn; //RTC中断通道
  92. // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =1; //先占优先级1
  93. // NVIC_InitStructure.NVIC_IRQChannelSubPriority =0; //从占优先级
  94. // NVIC_InitStructure.NVIC_IRQChannelCmd =ENABLE; //RTC中断通道使能
  95. // NVIC_Init(&NVIC_InitStructure);
  96. }
  97. void PVD_Config(void)
  98. {
  99. EXTI_InitTypeDef EXTI_InitStructure;
  100. NVIC_InitTypeDef NVIC_InitStructure;
  101. //??????,????
  102. RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
  103. EXTI_StructInit(&EXTI_InitStructure);
  104. EXTI_InitStructure.EXTI_Line = EXTI_Line16; // PVD??????16?
  105. EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //??????
  106. //EXTI_InitStructure.EXTI_Trigger??????:
  107. //EXTI_Trigger_Rising---????????????????????;
  108. //EXTI_Trigger_Falling---????????????????????;
  109. //EXTI_Trigger_Rising_Falling---??????????????????????
  110. EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;//???????????
  111. EXTI_InitStructure.EXTI_LineCmd = ENABLE; // ?????
  112. EXTI_Init(&EXTI_InitStructure); // ??
  113. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//???????,2???,2???
  114. NVIC_InitStructure.NVIC_IRQChannel=PVD_IRQn;//??????
  115. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;//?????2
  116. NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;//????1
  117. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//????
  118. NVIC_Init (&NVIC_InitStructure);
  119. PWR_PVDLevelConfig(PWR_PVDLevel_2V9); // ??????:2.9V
  120. PWR_PVDCmd(ENABLE); // ??PVD
  121. }
  122. /* id1, id2 will contain task identifications at run-time. */
  123. OS_TID id1, id2;
  124. /* Forward declaration of tasks. */
  125. __task void task1 (void);
  126. __task void task2 (void);
  127. __task void task1 (void){
  128. int ct=0;
  129. /* Obtain own system task identification number. */
  130. id1 = os_tsk_self();
  131. printf("task1 run!\r\n");
  132. /* Create task2 and obtain its task identification number. */
  133. //id2 = os_tsk_create (task2, 0);
  134. for (;;) {
  135. /* ... place code for task1 activity here ... */
  136. printf("[task1]tick=%d\r\n",ct++);
  137. /* Signal to task2 that task1 has completed. */
  138. // os_evt_set(0x0004, id2);
  139. /* Wait for completion of task2 activity. */
  140. /* 0xFFFF makes it wait without timeout. */
  141. /* 0x0004 represents bit 2. */
  142. //os_evt_wait_or(0x0004, 0xFFFF);
  143. /* Wait for 50 ms before restarting task1 activity. */
  144. os_dly_wait(200);
  145. }
  146. }
  147. __task void task2 (void) {
  148. int ct=0;
  149. printf("task2 run!\r\n");
  150. for (;;) {
  151. printf("[task2]tick=%d\r\n",ct++);
  152. /* Wait for completion of task1 activity. */
  153. /* 0xFFFF makes it wait without timeout. */
  154. /* 0x0004 represents bit 2. */
  155. os_evt_wait_or(0x0004, 0xFFFF);
  156. /* Wait for 20 ms before starting task2 activity. */
  157. os_dly_wait(50);
  158. /* ... place code for task2 activity here ... */
  159. /* Signal to task1 that task2 has completed. */
  160. os_evt_set(0x0004, id1);
  161. }
  162. }
  163. //#define LED_TASK_STK_SIZE 1024/8
  164. //U64 stkLEDTask[LED_TASK_STK_SIZE];
  165. extern unsigned char g_ucHSE_Flag;
  166. void CheckHSE(void)
  167. {
  168. unsigned long t;
  169. unsigned long i;
  170. if(g_ucHSE_Flag!=0)return;
  171. printf("--------------------\r\n");
  172. while(1){
  173. printf("External crystal failure!\r\n");
  174. for(i=0;i<10;i++){
  175. for(t=0;t<10000;t++){
  176. }
  177. }
  178. }
  179. }
  180. extern void DelayMs(unsigned short ms);
  181. /**********************************************************************************************************
  182. main()
  183. **********************************************************************************************************/
  184. int main (void)
  185. {
  186. int i;
  187. //int Vbat;
  188. IWDG_Configuration(500);
  189. RTC_ConfigurationSTP1();//原RTC时钟配置如果彻底掉电后再开,要多花1秒时间配置RTC,此处分开两步来处理。
  190. ModemPinConfig();
  191. PowerCtrlInit();
  192. Uart1Init();
  193. printf("\r\nUart1Init OK!\r\n");
  194. Uart3Init();
  195. KeyInit(); ////////////////
  196. SpeakerInit();
  197. IWDG_ReloadCounter();//
  198. W25Q64_Init();
  199. FileSysInit();
  200. SysIniRead();
  201. LcdInit(); //放此地调整用户体验
  202. printf("LcdInit... OK!\r\n");
  203. GuiInit();
  204. IWDG_ReloadCounter();//
  205. printf("GuiInit... OK!\r\n");
  206. ////显示开机动画
  207. //电量检测,低电关机
  208. ADCInit();//ADC Init
  209. g_iVbat=GetOneceVbat1();
  210. PVD_Config();
  211. RTC_EXTI_INITIAL();
  212. Delay_Timer_Init();
  213. RTC_ConfigurationSTP2();
  214. BeepInit();
  215. OnOff_Init();
  216. MY_NVIC_Init();
  217. LedInit();
  218. GPSInit();
  219. ShowBootAnimation();
  220. SysTick_Config(SystemCoreClock / 100);
  221. /* Initialize RTX and start init */
  222. os_sys_init_user(MainTask,1,stkMainTask,sizeof(stkMainTask));
  223. return (0);
  224. }
  225. /*********************************************************************************************************
  226. END FILE
  227. *********************************************************************************************************/