123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- /****************************************Copyright (c)****************************************************
- **
- **
- **--------------File Info---------------------------------------------------------------------------------
- ** File name: main.c
- ** Descriptions:
- **
- **--------------------------------------------------------------------------------------------------------
- ** Created by:
- ** Created date:
- ** Version:
- ** Descriptions:
- **
- **--------------------------------------------------------------------------------------------------------
- ** Modified by:
- ** Modified date:
- ** Version:
- ** Descriptions:
- **
- *********************************************************************************************************/
- #define THIS_FILE_ID 1
- /* Includes ------------------------------------------------------------------*/
- #include "includes.h"
- void RTC_EXTI_INITIAL()
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- EXTI_InitTypeDef EXTI_InitStructure;
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
- //------------EXTI17 ?? -------------------
- EXTI_InitStructure.EXTI_Line = EXTI_Line17;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- //------------------------------
- NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn;//
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- //-------------------------------------------
- }
- void MY_NVIC_Init()
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //选择中断分组2
- RunMake(THIS_FILE_ID);
- //串口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);
- RunMake(THIS_FILE_ID);
- //串口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);
- RunMake(THIS_FILE_ID);
- //串口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);
- RunMake(THIS_FILE_ID);
- //ONOFF-CHECK
- NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- RunMake(THIS_FILE_ID);
- // //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);
- //#if UART2_TX_USE_DMA == 1
- // NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel7_IRQn;
- // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
- // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- // NVIC_Init(&NVIC_InitStructure);
- //#endif
- //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);
- }
- /* id1, id2 will contain task identifications at run-time. */
- OS_TID id1, id2;
- /* Forward declaration of tasks. */
- __task void task1 (void);
- __task void task2 (void);
- __task void task1 (void){
- int ct=0;
- /* Obtain own system task identification number. */
- id1 = os_tsk_self();
- printf("task1 run!\r\n");
- /* Create task2 and obtain its task identification number. */
- //id2 = os_tsk_create (task2, 0);
- for (;;) {
- /* ... place code for task1 activity here ... */
- printf("[task1]tick=%d\r\n",ct++);
- /* Signal to task2 that task1 has completed. */
- // os_evt_set(0x0004, id2);
- /* Wait for completion of task2 activity. */
- /* 0xFFFF makes it wait without timeout. */
- /* 0x0004 represents bit 2. */
- //os_evt_wait_or(0x0004, 0xFFFF);
- /* Wait for 50 ms before restarting task1 activity. */
- os_dly_wait(200);
- }
- }
- __task void task2 (void) {
-
- int ct=0;
- printf("task2 run!\r\n");
- for (;;) {
- printf("[task2]tick=%d\r\n",ct++);
- /* Wait for completion of task1 activity. */
- /* 0xFFFF makes it wait without timeout. */
- /* 0x0004 represents bit 2. */
- os_evt_wait_or(0x0004, 0xFFFF);
- /* Wait for 20 ms before starting task2 activity. */
- os_dly_wait(50);
- /* ... place code for task2 activity here ... */
- /* Signal to task1 that task2 has completed. */
- os_evt_set(0x0004, id1);
- }
- }
- //#define LED_TASK_STK_SIZE 1024/8
- //U64 stkLEDTask[LED_TASK_STK_SIZE];
- extern unsigned char g_ucHSE_Flag;
- void CheckHSE(void)
- {
- unsigned long t;
- unsigned long i;
- if(g_ucHSE_Flag!=0)return;
- printf("--------------------\r\n");
- while(1){
- printf("External crystal failure!\r\n");
- for(i=0;i<10;i++){
- for(t=0;t<10000;t++){
- }
- }
- }
- }
- extern void DelayMs(unsigned short ms);
- 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);
- }
- /**********************************************************************************************************
- main()
- **********************************************************************************************************/
- int main (void)
- {
- int i;
- int Vbat;
- IWDG_Configuration(500);
- RTC_ConfigurationSTP1();//原RTC时钟配置如果彻底掉电后再开,要多花1秒时间配置RTC,此处分开两步来处理。
- ModemPinConfig();
- PowerCtrlInit();
- Uart1Init();
- printf("\r\nUart1Init OK!\r\n");
- Uart2Init();
- Uart3Init();
- KeyInit();
- SpeakerInit();
- MicrophoneInit();
- IWDG_ReloadCounter();//
- W25Q64_Init();
- FileSysInit();
- newSysIniRead();
- LcdInit(); //放此地调整用户体验
- printf("LcdInit... OK!\r\n");
- GuiInit();
- UniToGBKIndex=GetFileIndex("UNiTOGBK.bin");
- IWDG_ReloadCounter();//
- printf("GuiInit... OK!\r\n");
- ShowBootAnimation();
- //电量检测,低电关机
- ADCInit();//ADC Init
-
- Vbat=-1;
- while(Vbat<0){
- Vbat=GetVbat();
- }
- RTC_ConfigurationSTP2();
- //显示开机动画
- BeepInit();
- OnOff_Init();
- MY_NVIC_Init();
- ShowMcuFreq();
- /* Initialize RTX and start init */
- os_sys_init_user(MainTask,1,stkMainTask,sizeof(stkMainTask));
- return (0);
- }
- /*********************************************************************************************************
- END FILE
- *********************************************************************************************************/
|