main.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. IWDG_Configuration(500);
  34. RTC_Init();
  35. Uart1Init();
  36. Uart1RxEnable(1);
  37. authLink();
  38. Uart1RxEnable(0);
  39. Authed=1;
  40. if (SysTick_Config(SystemCoreClock / 100)){//配置系统滴答10ms中断一次
  41. printf("SysTick_Config err\r\n");
  42. while (1);
  43. }
  44. TIM2_Init(); //亮度调节
  45. Uart3Init();
  46. ModemPinConfig();
  47. PowerCtrlInit();
  48. W25Q64_Init();
  49. FileSysInit();
  50. IWDG_ReloadCounter();
  51. LedInit();
  52. KeyInit();
  53. SpeakerInit();
  54. ADCInit();
  55. KEYADCInit();
  56. LcdInit();
  57. GuiInit();
  58. BeepInit();
  59. MY_NVIC_Init();
  60. newSysIniRead();
  61. ShowMcuFreq();
  62. TSGpsDataInit();
  63. GPSRestart();
  64. UI_Init();
  65. SpeakerEnable();
  66. uTimerHardDly(10);
  67. SetBeepByNoOS(1000,10);
  68. SpeakerDisable();
  69. ReadProductParaFromFlash();
  70. GpsTimeUpdate();
  71. UniToGBKIndex=GetFileIndex("UNiTOGBK.bin");
  72. printf("\r\n%s_V%d.%d Start...\r\n",sutProductPara.ProductName,sutProductPara.ProductVersion,INTER_VER);
  73. printf("PSN:%lu\r\n",sutProductPara.PSN);
  74. //soc ID替代IMEI
  75. if(GetUniStringByID(DEV_HARDID)==1) printf("hardID:%s\r\n", DEV_HARDID);
  76. //SetMessageConfi();//*****************
  77. Uart2Init();
  78. uTimerStart(&bootMapCnt,400); //开机界面持续4秒
  79. ptAllInit();
  80. ptTaskRun();
  81. return 0;
  82. }
  83. void IWDG_Configuration(unsigned int value)
  84. {
  85. // WWDG 时钟使能
  86. RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
  87. if(RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)RCC_ClearFlag();
  88. //写入0x5555,用于允许狗狗寄存器写入功能
  89. IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
  90. //狗狗时钟分频,40K/256=156HZ(6.4ms)
  91. IWDG_SetPrescaler(IWDG_Prescaler_256);
  92. //喂狗时间
  93. //IWDG_SetReload(200);1.28s/6.4MS=200 .注意不能大于0xfff
  94. IWDG_SetReload(value);//3.2s/6.4MS=500 .注意不能大于0xfff
  95. //喂狗
  96. IWDG_ReloadCounter();
  97. //使能狗狗
  98. IWDG_Enable();
  99. }
  100. static void MY_NVIC_Init()
  101. {
  102. NVIC_InitTypeDef NVIC_InitStructure;
  103. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //选择中断分组2
  104. //串口1
  105. NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  106. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  107. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  108. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  109. NVIC_Init(&NVIC_InitStructure);
  110. //串口2
  111. NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
  112. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  113. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  114. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  115. NVIC_Init(&NVIC_InitStructure);
  116. //串口3
  117. NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
  118. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  119. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  120. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  121. NVIC_Init(&NVIC_InitStructure);
  122. // //DMA中断设置
  123. // NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn;
  124. // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  125. // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  126. // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  127. // NVIC_Init(&NVIC_InitStructure);
  128. //RTC中断设置
  129. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //选择中断分组1
  130. NVIC_InitStructure.NVIC_IRQChannel =RTC_IRQn; //RTC中断通道
  131. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =1; //先占优先级1
  132. NVIC_InitStructure.NVIC_IRQChannelSubPriority =0; //从占优先级
  133. NVIC_InitStructure.NVIC_IRQChannelCmd =ENABLE; //RTC中断通道使能
  134. NVIC_Init(&NVIC_InitStructure);
  135. }