main.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. //DMA中断设置
  51. NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_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. #if UART2_TX_USE_DMA == 1
  57. NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel7_IRQn;
  58. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  59. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  60. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  61. NVIC_Init(&NVIC_InitStructure);
  62. #endif
  63. //RTC中断设置
  64. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //选择中断分组1
  65. NVIC_InitStructure.NVIC_IRQChannel =RTC_IRQn; //RTC中断通道
  66. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =1; //先占优先级1
  67. NVIC_InitStructure.NVIC_IRQChannelSubPriority =0; //从占优先级
  68. NVIC_InitStructure.NVIC_IRQChannelCmd =ENABLE; //RTC中断通道使能
  69. NVIC_Init(&NVIC_InitStructure);
  70. }
  71. /* id1, id2 will contain task identifications at run-time. */
  72. OS_TID id1, id2;
  73. /* Forward declaration of tasks. */
  74. __task void task1 (void);
  75. __task void task2 (void);
  76. __task void task1 (void){
  77. int ct=0;
  78. /* Obtain own system task identification number. */
  79. id1 = os_tsk_self();
  80. printf("task1 run!\r\n");
  81. /* Create task2 and obtain its task identification number. */
  82. //id2 = os_tsk_create (task2, 0);
  83. for (;;) {
  84. /* ... place code for task1 activity here ... */
  85. printf("[task1]tick=%d\r\n",ct++);
  86. /* Signal to task2 that task1 has completed. */
  87. // os_evt_set(0x0004, id2);
  88. /* Wait for completion of task2 activity. */
  89. /* 0xFFFF makes it wait without timeout. */
  90. /* 0x0004 represents bit 2. */
  91. //os_evt_wait_or(0x0004, 0xFFFF);
  92. /* Wait for 50 ms before restarting task1 activity. */
  93. os_dly_wait(200);
  94. }
  95. }
  96. __task void task2 (void) {
  97. int ct=0;
  98. printf("task2 run!\r\n");
  99. for (;;) {
  100. printf("[task2]tick=%d\r\n",ct++);
  101. /* Wait for completion of task1 activity. */
  102. /* 0xFFFF makes it wait without timeout. */
  103. /* 0x0004 represents bit 2. */
  104. os_evt_wait_or(0x0004, 0xFFFF);
  105. /* Wait for 20 ms before starting task2 activity. */
  106. os_dly_wait(50);
  107. /* ... place code for task2 activity here ... */
  108. /* Signal to task1 that task2 has completed. */
  109. os_evt_set(0x0004, id1);
  110. }
  111. }
  112. //#define LED_TASK_STK_SIZE 1024/8
  113. //U64 stkLEDTask[LED_TASK_STK_SIZE];
  114. extern unsigned char g_ucHSE_Flag;
  115. void CheckHSE(void)
  116. {
  117. unsigned long t;
  118. unsigned long i;
  119. if(g_ucHSE_Flag!=0)return;
  120. printf("--------------------\r\n");
  121. while(1){
  122. printf("External crystal failure!\r\n");
  123. for(i=0;i<10;i++){
  124. for(t=0;t<10000;t++){
  125. }
  126. }
  127. }
  128. }
  129. extern void DelayMs(unsigned short ms);
  130. /**********************************************************************************************************
  131. main()
  132. **********************************************************************************************************/
  133. int main (void)
  134. {
  135. int i;
  136. int Vbat;
  137. IWDG_Configuration();
  138. ModemPinConfig();
  139. PowerCtrlInit();
  140. Uart1Init();
  141. printf("\r\nUart1Init OK!\r\n");
  142. Uart2Init();
  143. Uart3Init();
  144. KeyInit();
  145. SpeakerInit();
  146. MicrophoneInit();
  147. RTC_Configuration();
  148. IWDG_ReloadCounter();//
  149. W25Q64_Init();
  150. FileSysInit();
  151. // PrintfAllRFileInfo();
  152. LcdInit(); //放此地调整用户体验
  153. printf("LcdInit... OK!\r\n");
  154. GuiInit();
  155. IWDG_ReloadCounter();//
  156. printf("GuiInit... OK!\r\n");
  157. ShowBootAnimation();
  158. //电量检测,低电关机
  159. ADCInit();//ADC Init
  160. Vbat=-1;
  161. while(Vbat<0){
  162. Vbat=GetVbat();
  163. }
  164. if(Vbat<315){//电池电压小于335V 系统关机
  165. SlwTrace(INF,"Vbat Low!shutdown now!",1);
  166. PWR_EN_LOW;
  167. ADC_Cmd (ADC1,DISABLE);//使能或者失能指定的ADC
  168. GPIO_Config_ALL_AIN();
  169. Sys_Standby();
  170. while(1);
  171. }
  172. //显示开机动画
  173. // ShowBootAnimation();
  174. BeepInit();
  175. EXTIX_Init();
  176. MY_NVIC_Init();
  177. SysTick_Config(SystemCoreClock / 100);
  178. /* Initialize RTX and start init */
  179. os_sys_init_user(MainTask,1,stkMainTask,sizeof(stkMainTask));
  180. return (0);
  181. }
  182. /*********************************************************************************************************
  183. END FILE
  184. *********************************************************************************************************/