main.c 7.2 KB

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