#include "includes.h" static void MY_NVIC_Init(); void TIM2_Init() { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);// NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); TIM_TimeBaseStructure.TIM_Period = 100 - 1; TIM_TimeBaseStructure.TIM_Prescaler = 100 - 1;//600 TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); TIM_Cmd(TIM2, ENABLE); TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); } void ShowMcuFreq(void) { RCC_ClocksTypeDef clk; RCC_GetClocksFreq(&clk); //SysTick_Config(clk.SYSCLK_Frequency / 100); printf("SYSCLK=%d,PCLK1=%d,PCLK2=%d,HCLK=%d\r\n",clk.SYSCLK_Frequency,clk.PCLK1_Frequency,clk.PCLK2_Frequency,clk.HCLK_Frequency); } unsigned int bootMapCnt=0; unsigned char Test_EnableSpk=0; int main(void) { //newPara.LcdPulse=4;//LCD初始化最亮 RTC_Init(); Authed=0; Uart1Init(); ModemPinConfig(); if (SysTick_Config(SystemCoreClock / 100)){//配置系统滴答10ms中断一次 printf("SysTick_Config err\r\n"); while (1); } ReadProductParaFromFlash(); IWDG_Configuration(500); Uart1RxEnable(1); authLink(); Uart1RxEnable(0); Authed=1; OnOff_Init(); KeyInit(); EncodeInit(); TIM2_Init(); PowerCtrlInit(); W25Q64_Init(); FileSysInit(); IWDG_ReloadCounter(); LedInit(); SpeakerInit(); ADCInit(); KEYADCInit(); LcdInit(); GuiInit(); BeepInit(); MY_NVIC_Init(); newSysIniRead(); ShowMcuFreq(); TSGpsDataInit(); GPSRestart(); UI_Init(); SpeakerEnable(); uTimerHardDly(10); SetBeepByNoOS(1000,10); SpeakerDisable(); GpsTimeUpdate(); UniToGBKIndex=GetFileIndex("UNiTOGBK.bin"); hgs_poc_type=POC_NULL; printf("\r\n%s_V%d.%d Start...\r\n",sutProductPara.ProductName,sutProductPara.ProductVersion,INTER_VER); printf("PSN:%lu\r\n",sutProductPara.PSN); //soc ID替代IMEI if(GetUniStringByID(DEV_HARDID)==1) printf("hardID:%s\r\n", DEV_HARDID); //SetMessageConfi();//***************** Uart2Init(); uTimerStart(&bootMapCnt,400); //开机界面持续4秒 // LcdSendCommand(0x28); // LCD_BL_LOW; // //ModemSendAt("AT$MYPOWEROFF\r\n"); // MODEM_PWREN_HIGH; // IWDG_ReloadCounter(); // uTimerHardDly(200); // IWDG_ReloadCounter(); // MODEM_PWREN_LOW; // while(1){ // IWDG_ReloadCounter(); // } ptAllInit(); ptTaskRun(); return 0; } void IWDG_Configuration(unsigned int value) { // WWDG 时钟使能 RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE); if(RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)RCC_ClearFlag(); //写入0x5555,用于允许狗狗寄存器写入功能 IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); //狗狗时钟分频,40K/256=156HZ(6.4ms) IWDG_SetPrescaler(IWDG_Prescaler_256); //喂狗时间 //IWDG_SetReload(200);1.28s/6.4MS=200 .注意不能大于0xfff IWDG_SetReload(value);//3.2s/6.4MS=500 .注意不能大于0xfff //喂狗 IWDG_ReloadCounter(); //使能狗狗 IWDG_Enable(); } static void MY_NVIC_Init() { NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //选择中断分组2 //串口1 NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //串口2 NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // //串口3 // NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //旋钮 NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); ////DMA中断设置 // NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn; // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // NVIC_Init(&NVIC_InitStructure); //RTC中断设置 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //选择中断分组1 NVIC_InitStructure.NVIC_IRQChannel =RTC_IRQn; //RTC中断通道 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =1; //先占优先级1 NVIC_InitStructure.NVIC_IRQChannelSubPriority =0; //从占优先级 NVIC_InitStructure.NVIC_IRQChannelCmd =ENABLE; //RTC中断通道使能 NVIC_Init(&NVIC_InitStructure); }