WXK
7 天以前 31a18a379b5d7073705895dba364ca3b76d5d44e
keil/include/main/main.c
@@ -315,7 +315,7 @@
      spi_init();
//    // 模式判断脚和spi nrst脚初始化
    board_mode_pin_init();
            Program_Init();
    Program_Init();
    //board_led_on(BOARD_LED_1);
#endif
      Board_LORA_NVIC_Init(Lora_irq_handler);
@@ -370,183 +370,57 @@
            power_enter_power_down_mode(1);
            int_unlock(lock);
}
uint8_t result11;
int main(void)
{        
   // Initialize MCU system
    board_init();
    // Disable watchdog timer
    wdt_close(WDT_ID0);
    LOG_INFO(TRACE_MODULE_APP, "UCI FiRa example\r\n");
//   delay_ms(500);
//   lora_in_sleep();
//    power_init();
//   mcu_deep_sleep();
   if(gpio_pin_get_val(SLEEP_PIN))
//        if(1)
   {
   if(gpio_pin_get_val(MODE_CHANGE_PIN))//记得改回来与正式的相反
//        if(0)//记得改回来与正式的相反
   {
      LOG_INFO(TRACE_MODULE_APP,"固件版本:MK_Air_tag模式 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff);
      // Platform init for WSF
    PalSysInit();
    // Initialize os
    //
    // Set up timers for the WSF scheduler.
    //
    WsfOsInit();
    WsfTimerInit();
    sys_tick_callback_set(WsfTimerUpdateTicks);
    //
    // Initialize a buffer pool for WSF dynamic memory needs.
    //
    uint32_t wsfBufMemLen = WsfBufInit(WSF_BUF_POOLS, poolDescriptors);
    if (wsfBufMemLen > FREE_MEM_SIZE)
    {
        LOG_INFO(TRACE_MODULE_APP, "Memory pool is not enough %d\r\n", wsfBufMemLen - FREE_MEM_SIZE);
    }
//
    // Create app task
    //
   wsfHandlerId_t handlerId = WsfOsSetNextHandler(app_handler);
    app_init(handlerId);
    //
    // Create ranging task or test task
    //
    handlerId = WsfOsSetNextHandler(ranging_handler);
    ranging_init(handlerId);
#ifdef UWB_UCI_TEST_EN
    // Create test task
    handlerId = WsfOsSetNextHandler(uwb_test_handler);
    uwb_test_init(handlerId);
#endif
#ifndef MY_MODE
    uwb_open();
    // set advanced parameters
    struct PHY_ADV_CONFIG_T adv_config =
    {
        // RPM0: 40, RPM3: 60
        .thres_fap_detect = 60,
        // RPM0: 4, RPM3: 8
        .nth_scale_factor = 8,
        // RFrame SP0: 0/1, Others: 0/1/2/3
        .ranging_performance_mode = 3,
#if RX_ANT_PORTS_NUM == 4
        .skip_weakest_port_en = 1,
#else
        .skip_weakest_port_en = 0,
#endif
    };
    phy_adv_params_configure(&adv_config);
    // which RX ports will be used for AoA/PDoA
    phy_rx_ant_mode_set(RX_ANT_PORTS_COMBINATION);
    uwbs_init();
    uwb_app_config.ranging_flow_mode = (uint8_t)(RANGING_FLOW_FIRA);
    uwb_app_config.filter_en = (uint8_t)(FILTER_EN);
    uwb_app_config.session_param.tx_power_level = board_param.tx_power_fcc[CALIB_CH(uwb_app_config.ppdu_params.ch_num)];
    uwb_app_config.ppdu_params.rx_ant_id = (uint8_t)(RX_MAIN_ANT_PORT);
#elif defined MY_MODE
      Uwb_init();//默认为我们测距配置
      OpenUWB();
      uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback);
#endif
    //
    // Create UCI transmission layer task
    //
    handlerId = WsfOsSetNextHandler(uci_tl_handler);
    uci_tl_init(handlerId);
    // Initialize low power mode
    power_init();
#if LOW_POWER_EN
    power_mode_request(POWER_UNIT_USER, POWER_MODE_POWER_DOWN);
    uwb_app_config.low_power_en = 1;
#else
    power_mode_request(POWER_UNIT_USER, POWER_MODE_SLEEP);
    uwb_app_config.low_power_en = 0;
#endif
    // Enable sleep timer
    sleep_timer_open(true, SLEEP_TIMER_MODE_ONESHOT, sleep_timer_callback);
    while (1)
    {
        wsfOsDispatcher();
        power_manage();
            if(!gpio_pin_get_val(SLEEP_PIN))
            {
            delay_ms(300);
               //LOG_INFO(TRACE_MODULE_APP, "进入休眠模式\r\n");//会打断休眠
               //gpio_pin_clr(LORA_NRST);//lora休眠
               //spi_close(SPI_ID0);
               lora_in_sleep();
                power_init();
               mcu_deep_sleep();
            }
    }
    }else{
      LOG_INFO(TRACE_MODULE_APP,"固件版本:MK_免布线模式 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff);
      LOG_INFO(TRACE_MODULE_APP,"固件版本:MK_lora升级模式 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff);
      uart0_Init_normal();
      Lora_1268_Init();
       //LOG_INFO(TRACE_MODULE_APP," 切换6\r\n");
      SwitchLoraSettings(478,7,22);
      Uwb_init();//默认为我们测距配置
      OpenUWB();
      SwitchLoraSettings(0x1f4,7,22);
//      Uwb_init();//默认为我们测距配置
//      OpenUWB();
      uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback);
      uart_receive(UART_ID0,m_EUART0_DMA_RXBuf,EUART0_RX_BUF_SIZE,uart0_receive_callback);
    power_init();
    sleep_timer_open(true, SLEEP_TIMER_MODE_RELOAD, sleep_timer_callback_normal);
        power_init();
        uint16_t tmp = 0xFFFF;
        result11 = flash_open(FLASH_ID0,NULL);
        if(!result11)
        {
        LOG_INFO(TRACE_MODULE_APP," 打开flash成功\r\n");
        }
        result11 = flash_erase(FLASH_ID0, APP_CONFIG_IAPFLAG_SECTOR_ADDR, FLASH_SECTOR_SIZE);//擦除APPFLAG
        if(!result11)
        {
        LOG_INFO(TRACE_MODULE_APP," 擦除标志位成功\r\n");
        }
        result11 = flash_write_nbytes(FLASH_ID0,APP_CONFIG_IAPFLAG_MAP,(uint8_t*)&tmp,2);
        if(!result11)
        {
        LOG_INFO(TRACE_MODULE_APP," 写入标志位FFFF成功\r\n");
        }
        delay_ms(100);
        sleep_timer_open(true, SLEEP_TIMER_MODE_RELOAD, sleep_timer_callback_normal);
      sleep_timer_start(__MS_TO_32K_CNT(SLEEP_TIMER_NUM));//测试
          while (1)
            {
               if(send_flag)
               {
                  LOG_INFO(TRACE_MODULE_APP,"发送数量%d. \r\n",txdone);
                  send_flag=0;
               }
            uwb_app_poll();//我们的测距逻辑
                if(flag_secondtask)
                {
                    flag_secondtask = 0;
                    SecondTask();
                            //Lora_Tx_Poll();
                }
            Lora_Tx_Poll();
//            LoraUp_Poll();//网关升级
            if(!gpio_pin_get_val(SLEEP_PIN))
            {
               delay_ms(300);
            //LOG_INFO(TRACE_MODULE_APP, "进入休眠模式\r\n");//会打断休眠
            //gpio_pin_clr(LORA_NRST);//lora休眠
            //spi_close(SPI_ID0);
            lora_in_sleep();
             power_init();
            mcu_deep_sleep();
            }
            IdleTask();
            }
        while (1)
        {
//            uwb_app_poll();//我们的测距逻辑
//            if(flag_secondtask)
//            {
//            flag_secondtask = 0;
//            SecondTask();
//                    //Lora_Tx_Poll();
//            }
//            Lora_Tx_Poll();
            LoraUp_Poll();//网关升级
            IdleTask();
        }
   }    
}else{
delay_ms(300);
   //LOG_INFO(TRACE_MODULE_APP, "进入休眠模式\r\n");//会打断休眠
   //gpio_pin_clr(LORA_NRST);//lora休眠
   //spi_close(SPI_ID0);
   lora_in_sleep();
    power_init();
   mcu_deep_sleep();
}
}
void app_restore_from_power_down(void)