main.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. /* id1, id2 will contain task identifications at run-time. */
  98. OS_TID id1, id2;
  99. /* Forward declaration of tasks. */
  100. __task void task1 (void);
  101. __task void task2 (void);
  102. __task void task1 (void){
  103. int ct=0;
  104. /* Obtain own system task identification number. */
  105. id1 = os_tsk_self();
  106. printf("task1 run!\r\n");
  107. /* Create task2 and obtain its task identification number. */
  108. //id2 = os_tsk_create (task2, 0);
  109. for (;;) {
  110. /* ... place code for task1 activity here ... */
  111. printf("[task1]tick=%d\r\n",ct++);
  112. /* Signal to task2 that task1 has completed. */
  113. // os_evt_set(0x0004, id2);
  114. /* Wait for completion of task2 activity. */
  115. /* 0xFFFF makes it wait without timeout. */
  116. /* 0x0004 represents bit 2. */
  117. //os_evt_wait_or(0x0004, 0xFFFF);
  118. /* Wait for 50 ms before restarting task1 activity. */
  119. os_dly_wait(200);
  120. }
  121. }
  122. __task void task2 (void) {
  123. int ct=0;
  124. printf("task2 run!\r\n");
  125. for (;;) {
  126. printf("[task2]tick=%d\r\n",ct++);
  127. /* Wait for completion of task1 activity. */
  128. /* 0xFFFF makes it wait without timeout. */
  129. /* 0x0004 represents bit 2. */
  130. os_evt_wait_or(0x0004, 0xFFFF);
  131. /* Wait for 20 ms before starting task2 activity. */
  132. os_dly_wait(50);
  133. /* ... place code for task2 activity here ... */
  134. /* Signal to task1 that task2 has completed. */
  135. os_evt_set(0x0004, id1);
  136. }
  137. }
  138. //#define LED_TASK_STK_SIZE 1024/8
  139. //U64 stkLEDTask[LED_TASK_STK_SIZE];
  140. extern unsigned char g_ucHSE_Flag;
  141. void CheckHSE(void)
  142. {
  143. unsigned long t;
  144. unsigned long i;
  145. if(g_ucHSE_Flag!=0)return;
  146. printf("--------------------\r\n");
  147. while(1){
  148. printf("External crystal failure!\r\n");
  149. for(i=0;i<10;i++){
  150. for(t=0;t<10000;t++){
  151. }
  152. }
  153. }
  154. }
  155. extern void DelayMs(unsigned short ms);
  156. void ShowMcuFreq(void)
  157. {
  158. RCC_ClocksTypeDef clk;
  159. RCC_GetClocksFreq(&clk);
  160. SysTick_Config(clk.SYSCLK_Frequency / 100);
  161. printf("SYSCLK=%d,PCLK1=%d,PCLK2=%d,HCLK=%d\r\n",clk.SYSCLK_Frequency,clk.PCLK1_Frequency,clk.PCLK2_Frequency,clk.HCLK_Frequency);
  162. }
  163. /**********************************************************************************************************
  164. main()
  165. **********************************************************************************************************/
  166. int main (void)
  167. {
  168. int i;
  169. int Vbat;
  170. //while(1);
  171. IWDG_Configuration(500);
  172. RTC_ConfigurationSTP1();//原RTC时钟配置如果彻底掉电后再开,要多花1秒时间配置RTC,此处分开两步来处理。
  173. ModemPinConfig();
  174. PowerCtrlInit();
  175. Uart1Init();
  176. printf("\r\nUart1Init OK!\r\n");
  177. Uart2Init();
  178. Uart3Init();
  179. KeyInit();
  180. SpeakerInit();
  181. MicrophoneInit();
  182. // RTC_Configuration();
  183. IWDG_ReloadCounter();//
  184. W25Q64_Init();
  185. FileSysInit();
  186. newSysIniRead();
  187. // PrintfAllRFileInfo();
  188. LcdInit(); //放此地调整用户体验
  189. printf("LcdInit... OK!\r\n");
  190. GuiInit();
  191. IWDG_ReloadCounter();//
  192. printf("GuiInit... OK!\r\n");
  193. ShowBootAnimation();
  194. //电量检测,低电关机
  195. ADCInit();//ADC Init
  196. Vbat=-1;
  197. while(Vbat<0){
  198. Vbat=GetVbat();
  199. }
  200. // RTC_EXTI_INITIAL();
  201. // if(Vbat<MIN_PWR_LEVEL){//电池电压小于335V 系统关机
  202. // SlwTrace(INF,"Vbat Low!shutdown now!",1);
  203. // PWR_EN_LOW;
  204. // Sleeping();
  205. // }
  206. RTC_ConfigurationSTP2();
  207. //显示开机动画
  208. // ShowBootAnimation();
  209. BeepInit();
  210. OnOff_Init();
  211. MY_NVIC_Init();
  212. ShowMcuFreq();
  213. /* Initialize RTX and start init */
  214. os_sys_init_user(MainTask,1,stkMainTask,sizeof(stkMainTask));
  215. return (0);
  216. }
  217. /*********************************************************************************************************
  218. END FILE
  219. *********************************************************************************************************/