| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- /********************************** (C) COPYRIGHT *******************************
- * File Name : main.c
- * Author : WCH
- * Version : V1.1
- * Date : 2019/11/05
- * Description : Upgrade slave application main function and task system initialization
- *********************************************************************************
- * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
- * Attention: This software (modified or not) and binary are used for
- * microcontroller manufactured by Nanjing Qinheng Microelectronics.
- *******************************************************************************/
- /******************************************************************************/
- /* Header file contains */
- #include "define.h"
- #include "HAL.h"
- #include "Peripheral.h"
- #include "OTA.h"
- #include "OTAprofile.h"
- #include "led.h"
- /* ¼Ç¼µ±Ç°µÄImage */
- unsigned char CurrImageFlag = 0xff;
- static bool iwdg_rst_stat = false;
- /*********************************************************************
- * GLOBAL TYPEDEFS
- */
- __attribute__((aligned(4))) uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4];
- // uint8_t MacAddr[6] = {0};
- /* Note: The operation of Flash after the program is upgraded must be performed first
- * without turning on any interruption to prevent operation interruption and failure
- */
- /*********************************************************************
- * @fn ReadImageFlag
- *
- * @brief Read the iMage logo of the current program.
- * If the DataFlash is empty, it will be Imagea by default.
- *
- * @return none
- */
- void ReadImageFlag(void)
- {
- OTADataFlashInfo_t p_image_flash;
- FLASH_read(OTA_DATAFLASH_ADD, (uint8_t *)&p_image_flash, 4);
- CurrImageFlag = p_image_flash.ImageFlag;
- /* The program is executed for the first time, or it has not been updated,
- * and the DataFLASH is erased after being updated in the future
- */
- if((p_image_flash.flag[0] != IMAGE_FLAG_1)
- || (p_image_flash.flag[1] != IMAGE_FLAG_2)
- || (p_image_flash.flag[2] != IMAGE_FLAG_3))
- {
- CurrImageFlag = IMAGE_A_FLAG;
- }
- PRINT("Image Flag %02x\n", CurrImageFlag);
- // if(CurrImageFlag == IMAGE_A_FLAG)
- // {
- // PRINT("jump App \n");
- // Delay_Ms(5);
- // app_start();
- // }
- }
- /*********************************************************************
- * @fn Main_Circulation
- *
- * @brief Main loop
- *
- * @return none
- */
- __attribute__((section(".highcode")))
- __attribute__((noinline))
- void Main_Circulation(void)
- {
- while(1)
- {
- TMOS_SystemProcess();
- }
- }
- static void User_GPIO_Init(void)
- {
- }
- /*********************************************************************
- * @fn main
- *
- * @brief Main function
- *
- * @return none
- */
- int main(void)
- {
- SystemCoreClockUpdate();
- Delay_Init();
- #ifdef DEBUG
- USART_Printf_Init(115200);
- #endif
- PRINT("SystemClk:%d\r\n",SystemCoreClock);
- PRINT( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );
- PRINT("%s\n", VER_LIB);
- ReadImageFlag();
- if(RCC_GetFlagStatus(RCC_FLAG_IWDGRST) == SET)
- {
- PRINT("iwdg reset\n");
- }
- // else if(RCC_GetFlagStatus(RCC_FLAG_SFTRST) == SET)
- // {
- // // Soft reset does not jump app app
- // PRINT("Soft reset does not jump app \n");
- // }
- else
- {
- if(CurrImageFlag == IMAGE_A_FLAG)
- {
- PRINT("jump User App \n");
- Delay_Ms(5);
- app_start();
- }
- else if(CurrImageFlag == IMAGE_OTA_FLAG)
- {
- PRINT("ota jump App \n");
- Delay_Ms(5);
- app_start();
- }
- }
- PRINT("ENTER OTA!\n");
- User_GPIO_Init();
- WCHBLE_Init();
- HAL_Init();
- GAPRole_PeripheralInit();
- Peripheral_Init();
- led_task_init();
- led_task_start();
- led_enter_ota();
- PRINT("start task\n");
- Main_Circulation();
- }
- /******************************** endfile @ main ******************************/
|