/******************************************************************************** Func: 核心任务也可认为是空闲任务 Time: 2014-6-13 Ver.: V4.0 Note; ********************************************************************************/ void Tos_RootTask(void *Tags) { Device_Init();//设备初始化放在系统未启动时会导致部分驱动异常,如fmsc #ifdef IWDG_ENABLE IWDG_Configuration(); #endif #ifdef APPLIC_ENABLE if(!AppLicense())return;//注册设备 #endif while(1) { #ifdef IWDG_ENABLE IWDG_ReloadCounter();//系统狗/使能休眠功能后需要关闭系统狗 #endif Tos_TaskDelay(100); Tos_ScanTimer(); } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ uint32_t delay; uint8_t sendFlag_Ai = 0; SOE_Struct soe; uint32_t start = 0; /* System clocks configuration ---------------------------------------------*/ SystemInit(); RCC_ClocksTypeDef clock; RCC_GetClocksFreq(&clock); RCC_Configuration(); GPIO_Configuration(); ADC_Configuration(); COM3_Configuration(9600); DMA_Configuration(); TIM_UART_Config(); //uart3-rx FREQ_MEA_Init(); //freq采样 TIM2_Configuration(); //adc采样 SysTick_Configuration(); //DI采样 RTC_Init(); NVIC_Configuration(); DataBase_Init(); //memset(DiStatus_DI, 0, sizeof(DiStatus_Type)*DI_NUM); //初始化DI内存列表 GetComAddr(); SetCurrent.ChannelCoef[0] =1050;//1#:1029;2#:1028 SetCurrent.ChannelCoef[1] =1029;//1#:1029;2#:1027 SetCurrent.ChannelCoef[2] =1050;//1#:1030;2#:1028 SetCurrent.ChannelCoef[3] =1028;//1#:1033;2#:1028 SetCurrent.ChannelCoef[4] =1029;//1#:1033;2#:1029 SetCurrent.ChannelCoef[5] =1028;//1#:1033;2#:1028 SetCurrent.ChannelCoef[6] =1025;//1#:1029;2#:1028 SetCurrent.ChannelCoef[7] =1026;//1#:1029;2#:1027 SetCurrent.ChannelCoef[8] =1027;//1#:1030;2#:1028 #ifdef WATCHDOG IWDG_Configuration(); #endif DMA_Cmd(DMA1_Channel3, ENABLE); // Emable TIM3, 使能串口接收通道 TIM_Cmd(TIM3, ENABLE); //UART3接收,使能 while (1) { Di_PostWork(); if(63==PeriodCycle_Index) { TOTAL_MEASURE(&meas); SequenceFilter_2(&meas); SequenceFilter_0(&meas); ValueScaling(MeaTab,&meas); //tyh:20150629 添加遥测数据上送 if(Begin_AI_Send) { if(Is_new_soe()) { get_soe(&soe, 1); SoeResponse(soe); } else { if((sendFlag_Ai%3)==0) AiResponse(0); else { if((sendFlag_Ai%5)==0) //tyh:20150803 增加遥信数据上送 DiResponse(0); } sendFlag_Ai++; } } } if(Flag_Uart_Recv) BusCalling_Process(Flag_Uart_Recv); //处理数据 #ifdef WATCHDOG WDGFeeding(); #endif } }
int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this i s done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ //GPIO_InitTypeDef GPIO_InitStructure; //uint32_t irq; //test IRQ /* System clocks configuration ---------------------------------------------*/ SystemInit(); RCC_Configuration(); /* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration(); GPIO_WriteBit(CANTX_LED, Bit_SET); GPIO_WriteBit(CANRX_LED, Bit_SET); GPIO_WriteBit(COMTX_LED, Bit_SET); GPIO_WriteBit(COMRX_LED, Bit_SET); GPIO_WriteBit(PWR_LED, Bit_RESET); GPIO_WriteBit(ALARM_LED, Bit_SET); GPIO_WriteBit(RUNSTAT_LED, Bit_SET); GPIO_WriteBit(ETH_RESET, Bit_RESET);//拉低DM9000 nRST, 延时复位启动 DataBase_Init(DevIPAddressTab); #ifndef TEST /* com1 configuration ------------------------------------------------------*/ COM1_Configuration(); #ifdef TEST_PARTS GPIO_WriteBit(CANTX_LED, Bit_RESET); GPIO_WriteBit(CANRX_LED, Bit_SET); GPIO_WriteBit(COMTX_LED, Bit_SET); GPIO_WriteBit(COMRX_LED, Bit_SET); #endif printf(" <<<<<<< COM1 config complete <<<<<<<\r\n\r\n"); /* com2 configuration ------------------------------------------------------*/ //COM2_Configuration(); #endif /* i2c configuration ------------------------------------------------------*/ printf(" >>>>>>> I2C config begin >>>>>>>\r\n"); I2C_Configuration(); #ifdef TEST_PARTS GPIO_WriteBit(CANTX_LED, Bit_SET); GPIO_WriteBit(CANRX_LED, Bit_RESET); GPIO_WriteBit(COMTX_LED, Bit_SET); GPIO_WriteBit(COMRX_LED, Bit_SET); #endif printf(" <<<<<<< I2C config complete <<<<<<<\r\n\r\n"); #ifndef TEST /* RTC configuration--------------------------------------------------------*/ printf(" >>>>>>> RTC config begin >>>>>>>\r\n"); RTC_Configuration(); #ifdef TEST_PARTS GPIO_WriteBit(CANTX_LED, Bit_RESET); GPIO_WriteBit(CANRX_LED, Bit_RESET); GPIO_WriteBit(COMTX_LED, Bit_SET); GPIO_WriteBit(COMRX_LED, Bit_SET); #endif printf(" <<<<<<< RTC config complete <<<<<<<\r\n\r\n"); #endif #ifdef CAN_APP /* can configuration ------------------------------------------------------*/ printf(" >>>>>>> CAN config begin >>>>>>>\r\n"); CAN_Configuration(); #ifdef TEST_PARTS GPIO_WriteBit(CANTX_LED, Bit_SET); GPIO_WriteBit(CANRX_LED, Bit_SET); GPIO_WriteBit(COMTX_LED, Bit_RESET); GPIO_WriteBit(COMRX_LED, Bit_SET); #endif printf(" <<<<<<< CAN config complete <<<<<<<\r\n\r\n"); #endif #ifndef TEST /*temperature configuration------------------------------------------------------*/ printf(" >>>>>>> TEMPMEA config begin >>>>>>>\r\n"); TEMPMEA_Confitguration(); #ifdef TEST_PARTS GPIO_WriteBit(CANTX_LED, Bit_SET); GPIO_WriteBit(CANRX_LED, Bit_RESET); GPIO_WriteBit(COMTX_LED, Bit_RESET); GPIO_WriteBit(COMRX_LED, Bit_SET); #endif printf(" <<<<<<< TEMPMEA config complete <<<<<<<\r\n\r\n"); #endif /* SysTick configuration ------------------------------------------------------*/ printf(" >>>>>>> SysTick config begin >>>>>>>\r\n"); SysTick_Configuration(); #ifdef TEST_PARTS GPIO_WriteBit(CANTX_LED, Bit_RESET); GPIO_WriteBit(CANRX_LED, Bit_RESET); GPIO_WriteBit(COMTX_LED, Bit_RESET); GPIO_WriteBit(COMRX_LED, Bit_SET); #endif printf(" <<<<<<< SysTick config complete <<<<<<<\r\n\r\n"); /* NVIC configuration ------------------------------------------------------*/ printf(" >>>>>>> NVIC config begin >>>>>>>\r\n"); NVIC_Configuration(); #ifdef TEST_PARTS GPIO_WriteBit(CANTX_LED, Bit_SET); GPIO_WriteBit(CANRX_LED, Bit_SET); GPIO_WriteBit(COMTX_LED, Bit_SET); GPIO_WriteBit(COMRX_LED, Bit_RESET); #endif printf(" <<<<<<< NVIC config complete <<<<<<<\r\n\r\n"); /* Update the SysTick IRQ priority should be higher than the Ethernet IRQ */ /* The Localtime should be updated during the Ethernet packets processing */ NVIC_SetPriority (SysTick_IRQn, 1); /* test IRQ*/ // irq = NVIC_GetPriority(SysTick_IRQn); // irq = NVIC_GetPriority(ETH_IRQn); // irq = NVIC_GetPriority(I2C1_ER_IRQn); // irq = NVIC_GetPriority(I2C1_EV_IRQn); /* ethernet configuration ------------------------------------------------------*/ //可添加延时, 用以确保DM9000启动时电压满足芯片要求 //"nRST must not go high until after the VDDIO and VDD_CORE supplies are stable" 手册P51 GPIO_WriteBit(ETH_RESET, Bit_SET); //拉高DM9000 nRST, 复位启动 printf(" >>>>>>> ETH config begin >>>>>>>\r\n"); Ethernet_Configuration(); #ifdef TEST_PARTS GPIO_WriteBit(CANTX_LED, Bit_RESET); GPIO_WriteBit(CANRX_LED, Bit_SET); GPIO_WriteBit(COMTX_LED, Bit_RESET); GPIO_WriteBit(COMRX_LED, Bit_SET); #endif printf(" <<<<<<< ETH config complete <<<<<<<\r\n\r\n"); #ifdef WATCHDOG /* WATCHDOG configuration ------------------------------------------------------*/ IWDG_Configuration(); #endif //判断是否有以太网链接 if(EthInitState) { CommunicationInit(); } printf(" ******* 输入'$'将触发串口控制台!*******\r\n\r\n"); GPIO_WriteBit(CANTX_LED, Bit_SET); GPIO_WriteBit(CANRX_LED, Bit_SET); GPIO_WriteBit(COMTX_LED, Bit_SET); GPIO_WriteBit(COMRX_LED, Bit_SET); //启动完成, 进入常规流程 #ifdef _TEST uint8_t test = 0; #endif while (1) { Di_PostWork(); LwIP_Periodic_Handle(LocalTime); Task_Periodic_Handle(LocalTime); //判断以太网状态, 决定是否要复位以太网 EthStateCheck(); reset_flag = Get_eth_reset_flag(); if(reset_flag == Ethernet_SWRST_FLAG) Ethernet_SWRST(); else if(reset_flag == Ethernet_HWRST_FLAG) Ethernet_HWRST(); #ifdef _TEST //tyh:20130407 eth reset test if((DiStatus_DI[1].Value != test)&&(DiStatus_DI[1].Value == 1)) { //eth_reg = ETH_ReadPHYRegister(0x1F, 17); Ethernet_HWRST(); } test = DiStatus_DI[1].Value; #endif // else // { // if( EthLinkCheck() ) // { // //tyh:20130403 send udp test_message // if((DiStatus_DI[1].Value != test)&&(DiStatus_DI[1].Value == 1)) // { // Udp_timing_test(); // } // // test = DiStatus_DI[1].Value; // } // } #ifdef WATCHDOG WDGFeeding(); #endif } }
/******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None * Attention : None *******************************************************************************/ int main(void) { delay_init(); GPIO_Configuration(); IWDG_Configuration(); USART_Configuration(); /* System Reset */ if(RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET) { printf("IWDG RESET \r\n"); RCC_ClearFlag(); } /* Infinite loop */ while(1) { /* LED1 PB6 and Step 1*/ GPIO_SetBits(GPIOB , GPIO_Pin_6); //set "1" the Coil 1 GPIO_ResetBits(GPIOB , GPIO_Pin_8); //set "0" the Coil 2 GPIO_ResetBits(GPIOC , GPIO_Pin_10);//set "0" the Coil 3 GPIO_ResetBits(GPIOC , GPIO_Pin_12);//set "0" the Coil 4 delay_ms(del); /* LED2 PB8 and Step 2*/ GPIO_ResetBits(GPIOB , GPIO_Pin_6); GPIO_SetBits(GPIOB , GPIO_Pin_8); GPIO_ResetBits(GPIOC , GPIO_Pin_10); GPIO_ResetBits(GPIOC , GPIO_Pin_12); delay_ms(del); /* LED3 PC10 and Step 3*/ GPIO_ResetBits(GPIOB , GPIO_Pin_6); GPIO_ResetBits(GPIOB , GPIO_Pin_8); GPIO_SetBits(GPIOC , GPIO_Pin_10); GPIO_ResetBits(GPIOC , GPIO_Pin_12); delay_ms(del); /* LED4 PC12 and Step 4*/ GPIO_ResetBits(GPIOB , GPIO_Pin_6); GPIO_ResetBits(GPIOB , GPIO_Pin_8); GPIO_ResetBits(GPIOC , GPIO_Pin_10); GPIO_SetBits(GPIOC , GPIO_Pin_12); delay_ms(del); /* Key input if( !GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13) ) //keyA { delay_ms(20); if( !GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13) ) IWDG_ReloadCounter(); } if(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_2)) // keyB { delay_ms(20); if(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_2)) IWDG_ReloadCounter(); } */ }//whille }//main