main.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #include "includes.h"
  2. static void MY_NVIC_Init();
  3. void TIM2_Init()
  4. {
  5. TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  6. NVIC_InitTypeDef NVIC_InitStructure;
  7. RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);//
  8. NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
  9. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  10. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  11. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  12. NVIC_Init(&NVIC_InitStructure);
  13. TIM_TimeBaseStructure.TIM_Period = 100 - 1;
  14. TIM_TimeBaseStructure.TIM_Prescaler = 100 - 1;//600
  15. TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  16. TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  17. TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
  18. TIM_Cmd(TIM2, ENABLE);
  19. TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
  20. }
  21. void ShowMcuFreq(void)
  22. {
  23. RCC_ClocksTypeDef clk;
  24. RCC_GetClocksFreq(&clk);
  25. //SysTick_Config(clk.SYSCLK_Frequency / 100);
  26. printf("SYSCLK=%d,PCLK1=%d,PCLK2=%d,HCLK=%d\r\n",clk.SYSCLK_Frequency,clk.PCLK1_Frequency,clk.PCLK2_Frequency,clk.HCLK_Frequency);
  27. }
  28. unsigned int bootMapCnt=0;
  29. unsigned char Test_EnableSpk=0;
  30. int main(void)
  31. {
  32. //newPara.LcdPulse=4;//LCD初始化最亮
  33. RTC_Init();
  34. Authed=0;
  35. Uart1Init();
  36. ModemPinConfig();
  37. if (SysTick_Config(SystemCoreClock / 100)){//配置系统滴答10ms中断一次
  38. printf("SysTick_Config err\r\n");
  39. while (1);
  40. }
  41. ReadProductParaFromFlash();
  42. IWDG_Configuration(500);
  43. Uart1RxEnable(1);
  44. authLink();
  45. Uart1RxEnable(0);
  46. Authed=1;
  47. OnOff_Init();
  48. KeyInit();
  49. EncodeInit();
  50. TIM2_Init();
  51. PowerCtrlInit();
  52. W25Q64_Init();
  53. FileSysInit();
  54. IWDG_ReloadCounter();
  55. LedInit();
  56. SpeakerInit();
  57. ADCInit();
  58. KEYADCInit();
  59. LcdInit();
  60. GuiInit();
  61. BeepInit();
  62. MY_NVIC_Init();
  63. newSysIniRead();
  64. ShowMcuFreq();
  65. TSGpsDataInit();
  66. GPSRestart();
  67. UI_Init();
  68. SpeakerEnable();
  69. uTimerHardDly(10);
  70. SetBeepByNoOS(1000,10);
  71. SpeakerDisable();
  72. GpsTimeUpdate();
  73. UniToGBKIndex=GetFileIndex("UNiTOGBK.bin");
  74. hgs_poc_type=POC_NULL;
  75. printf("\r\n%s_V%d.%d Start...\r\n",sutProductPara.ProductName,sutProductPara.ProductVersion,INTER_VER);
  76. printf("PSN:%lu\r\n",sutProductPara.PSN);
  77. //soc ID替代IMEI
  78. if(GetUniStringByID(DEV_HARDID)==1) printf("hardID:%s\r\n", DEV_HARDID);
  79. //SetMessageConfi();//*****************
  80. Uart2Init();
  81. uTimerStart(&bootMapCnt,400); //开机界面持续4秒
  82. // LcdSendCommand(0x28);
  83. // LCD_BL_LOW;
  84. // //ModemSendAt("AT$MYPOWEROFF\r\n");
  85. // MODEM_PWREN_HIGH;
  86. // IWDG_ReloadCounter();
  87. // uTimerHardDly(200);
  88. // IWDG_ReloadCounter();
  89. // MODEM_PWREN_LOW;
  90. // while(1){
  91. // IWDG_ReloadCounter();
  92. // }
  93. ptAllInit();
  94. ptTaskRun();
  95. return 0;
  96. }
  97. void IWDG_Configuration(unsigned int value)
  98. {
  99. // WWDG 时钟使能
  100. RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
  101. if(RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)RCC_ClearFlag();
  102. //写入0x5555,用于允许狗狗寄存器写入功能
  103. IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
  104. //狗狗时钟分频,40K/256=156HZ(6.4ms)
  105. IWDG_SetPrescaler(IWDG_Prescaler_256);
  106. //喂狗时间
  107. //IWDG_SetReload(200);1.28s/6.4MS=200 .注意不能大于0xfff
  108. IWDG_SetReload(value);//3.2s/6.4MS=500 .注意不能大于0xfff
  109. //喂狗
  110. IWDG_ReloadCounter();
  111. //使能狗狗
  112. IWDG_Enable();
  113. }
  114. static void MY_NVIC_Init()
  115. {
  116. NVIC_InitTypeDef NVIC_InitStructure;
  117. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //选择中断分组2
  118. //串口1
  119. NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  120. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  121. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  122. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  123. NVIC_Init(&NVIC_InitStructure);
  124. //串口2
  125. NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
  126. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  127. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  128. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  129. NVIC_Init(&NVIC_InitStructure);
  130. // //串口3
  131. // NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
  132. // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  133. // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  134. // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  135. // NVIC_Init(&NVIC_InitStructure);
  136. NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
  137. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  138. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  139. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  140. NVIC_Init(&NVIC_InitStructure);
  141. NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn;
  142. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
  143. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  144. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  145. NVIC_Init(&NVIC_InitStructure);
  146. //旋钮
  147. NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
  148. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
  149. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  150. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  151. NVIC_Init(&NVIC_InitStructure);
  152. ////DMA中断设置
  153. // NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn;
  154. // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  155. // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  156. // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  157. // NVIC_Init(&NVIC_InitStructure);
  158. //RTC中断设置
  159. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //选择中断分组1
  160. NVIC_InitStructure.NVIC_IRQChannel =RTC_IRQn; //RTC中断通道
  161. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =1; //先占优先级1
  162. NVIC_InitStructure.NVIC_IRQChannelSubPriority =0; //从占优先级
  163. NVIC_InitStructure.NVIC_IRQChannelCmd =ENABLE; //RTC中断通道使能
  164. NVIC_Init(&NVIC_InitStructure);
  165. }