main.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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);
  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. //串口2
  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. /////////////////////
  52. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority= 1;
  53. NVIC_InitStructure.NVIC_IRQChannelSubPriority= 1;
  54. NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
  55. NVIC_InitStructure.NVIC_IRQChannel= EXTI1_IRQn;
  56. NVIC_Init(&NVIC_InitStructure);
  57. NVIC_InitStructure.NVIC_IRQChannel= EXTI2_IRQn;
  58. NVIC_Init(&NVIC_InitStructure);
  59. NVIC_InitStructure.NVIC_IRQChannel= EXTI9_5_IRQn;
  60. NVIC_Init(&NVIC_InitStructure);
  61. }
  62. #if 0
  63. /* id1, id2 will contain task identifications at run-time. */
  64. OS_TID id1, id2;
  65. /* Forward declaration of tasks. */
  66. __task void task1 (void);
  67. __task void task2 (void);
  68. __task void task1 (void){
  69. int ct=0;
  70. /* Obtain own system task identification number. */
  71. id1 = os_tsk_self();
  72. printf("task1 run!\r\n");
  73. /* Create task2 and obtain its task identification number. */
  74. //id2 = os_tsk_create (task2, 0);
  75. for (;;) {
  76. /* ... place code for task1 activity here ... */
  77. printf("[task1]tick=%d\r\n",ct++);
  78. /* Signal to task2 that task1 has completed. */
  79. // os_evt_set(0x0004, id2);
  80. /* Wait for completion of task2 activity. */
  81. /* 0xFFFF makes it wait without timeout. */
  82. /* 0x0004 represents bit 2. */
  83. //os_evt_wait_or(0x0004, 0xFFFF);
  84. /* Wait for 50 ms before restarting task1 activity. */
  85. os_dly_wait(200);
  86. }
  87. }
  88. __task void task2 (void) {
  89. int ct=0;
  90. printf("task2 run!\r\n");
  91. for (;;) {
  92. printf("[task2]tick=%d\r\n",ct++);
  93. /* Wait for completion of task1 activity. */
  94. /* 0xFFFF makes it wait without timeout. */
  95. /* 0x0004 represents bit 2. */
  96. os_evt_wait_or(0x0004, 0xFFFF);
  97. /* Wait for 20 ms before starting task2 activity. */
  98. os_dly_wait(50);
  99. /* ... place code for task2 activity here ... */
  100. /* Signal to task1 that task2 has completed. */
  101. os_evt_set(0x0004, id1);
  102. }
  103. }
  104. #endif
  105. /**********************************************************************************************************
  106. main()
  107. **********************************************************************************************************/
  108. int main (void)
  109. {
  110. int Vbat;
  111. IWDG_Configuration(500);
  112. PowerCtrlInit();
  113. Uart1Init();
  114. Uart2Init();
  115. Uart3Init();
  116. GPSInit();
  117. KeyInit();
  118. SpeakerInit();
  119. MicrophoneInit();
  120. ADCInit();
  121. Vbat=-1;
  122. while(Vbat<0) Vbat=GetVbat();
  123. if(Vbat<MIN_PWR_LEVEL)
  124. {//电池电压小于335V 系统关机
  125. printf("VB_Low!shutdown\r\n");
  126. PWR_EN_LOW;
  127. Sleeping();
  128. }
  129. EncodeInit();
  130. BeepInit();
  131. OnOff_Init();
  132. MY_NVIC_Init();
  133. SysTick_Config(SystemCoreClock / 100);
  134. /* Initialize RTX and start init */
  135. os_sys_init_user(MainTask,1,stkMainTask,sizeof(stkMainTask));
  136. return (0);
  137. }
  138. /*********************************************************************************************************
  139. END FILE
  140. *********************************************************************************************************/