yincheng.zhong
2023-08-02 34a46bcbc3a65ff69369a697c7a10d5992be6161
Src/main.c
@@ -75,7 +75,7 @@
static void MX_LPTIM1_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_SPI1_Init(void);
static void MX_ADC_Init(void);
void MX_ADC_Init(void);
static void MX_DMA_Init(void);
static void MX_TIM2_Init(void);
/* USER CODE BEGIN PFP */
@@ -188,6 +188,7 @@
   if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
   {
      nomove_count = 0;
    bat_percent=Get_VDDVlotage();
      if(state5v==0)
      {
         state5v=1;
@@ -226,10 +227,7 @@
   }
         if(g_com_map[CNT_REBOOT]==1)
      {
         g_com_map[CNT_REBOOT]=0;
         g_com_map[MAP_SIGN_INDEX]=0;
         save_com_map_to_flash();
         delay_ms(100);
         ReturnFactory();
         SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
      }
      if(g_com_map[CNT_RESTART]==1)
@@ -282,7 +280,7 @@
      {
        case 1:
     
       HAL_GPIO_WritePin(GPIOB, MOTOR_Pin, GPIO_PIN_SET);
  HAL_GPIO_WritePin(GPIOB, MOTOR_Pin, GPIO_PIN_SET);
  GPIO_InitStruct.Pin = MOTOR_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
@@ -295,6 +293,8 @@
         break;
      }
}
int16_t g_commap_antdelay;
u8 active_flag,nomovesleeptime;
void Program_Init(void)
{   float temp;
   uint16_t temp2;
@@ -305,7 +305,27 @@
   hardware_pici = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+2);
   hardware_type = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+4);
   //deca_sleep(1000);
   g_com_map[VERSION] = 0x0118;
   g_com_map[VERSION] = (1<<8)|37;
    active_flag = g_com_map[ACTIVE_INDEX];
    module_power = g_com_map[POWER];
   imu_enable=g_com_map[IMU_ENABLE];
   motor_enable=g_com_map[MOTOR_ENABLE];
   group_id=g_com_map[GROUP_ID];
   dev_id = g_com_map[DEV_ID];
   slottime=ceil((double)g_com_map[MAX_REPORT_ANC_NUM]*SLOT_SCALE)+3;
   max_slotpos=g_com_map[COM_INTERVAL]/slottime;
   tyncpoll_time=(g_com_map[DEV_ID]%max_slotpos)*slottime;
   slot_startcount=tyncpoll_time*1000/LPTIMER_LSB;
   lastpoll_time=tyncpoll_time;
    tag_frequency = 1000/g_com_map[COM_INTERVAL];
   total_slotnum = 1000/g_com_map[COM_INTERVAL];
    nomovesleeptime = g_com_map[NOMOVESLEEP_TIME];
   if(active_flag==0)
   {
      imu_enable=1;
      nomovesleeptime =10;
   }
#ifdef DEBUG_MODE
//   g_com_map[DEV_ROLE]=1;
//      g_com_map[DEV_ID]=1;
@@ -321,19 +341,11 @@
      {module_power=67;}
      if(module_power<0)
      {module_power=0;}
   module_power = g_com_map[POWER];
   imu_enable=g_com_map[IMU_ENABLE];
   motor_enable=g_com_map[MOTOR_ENABLE];
   group_id=g_com_map[GROUP_ID];
   dev_id = g_com_map[DEV_ID];
   slottime=ceil((double)g_com_map[MAX_REPORT_ANC_NUM]*SLOT_SCALE)+3;
   max_slotpos=g_com_map[COM_INTERVAL]/slottime;
   tyncpoll_time=(g_com_map[DEV_ID]%max_slotpos)*slottime;
   slot_startcount=tyncpoll_time*1000/LPTIMER_LSB;
   lastpoll_time=tyncpoll_time;
  tag_frequency = 1000/g_com_map[COM_INTERVAL];
   total_slotnum = 1000/g_com_map[COM_INTERVAL];
    if(g_com_map[ANT_LENGTH]>10000)
    {
        g_com_map[ANT_LENGTH] = 0;
    }
    g_commap_antdelay = -g_com_map[DIST_OFFSET];
   current_slotnum=1;
   current_time=GetLPTime();
      if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIMER_1S_COUNT, slot_startcount) != HAL_OK)  //system time is 1010ms   1 puls=30.518us
@@ -374,6 +386,11 @@
{
      //SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
}
void MX_ADC_DeInit(void)
{
    HAL_ADC_DeInit(&hadc);
    HAL_ADCEx_DisableVREFINT();
}
/* USER CODE END 0 */
/**
@@ -405,15 +422,15 @@
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_LPTIM1_Init();
   MX_DMA_Init();
  MX_USART1_UART_Init();
  MX_SPI1_Init();
  MX_ADC_Init();
  MX_DMA_Init();
//  MX_TIM2_Init();
  MX_TIM2_Init();
  /* USER CODE BEGIN 2 */
   LED_LG_ON;
   Program_Init();
   LIS3DH_Data_Init();
   Accelerometer_Init();
   Dw1000_Init();
   Dw1000_App_Init();
   HardWareTypeDiffConfig();
@@ -439,7 +456,7 @@
    /* USER CODE END WHILE */
    /* USER CODE BEGIN 3 */
      if(g_start_send_flag)
      if(g_start_send_flag&&active_flag)
   { static uint16_t blink_count=0;
      SystemClock_Config();
      g_start_send_flag = 0;   
@@ -450,9 +467,9 @@
//      }else{
//      HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_RESET);
//      }
//      LED_TR_BLINK;
//      LED_TR_BLINK;s
      
         bat_percent=Get_Battary();
         bat_percent=Get_VDDVlotage();
      if(bat_percent>15)
      {   LED_TB_ON;
         Tag_App();
@@ -548,7 +565,7 @@
  * @param None
  * @retval None
  */
static void MX_ADC_Init(void)
void MX_ADC_Init(void)
{
  /* USER CODE BEGIN ADC_Init 0 */
@@ -585,7 +602,7 @@
  }
  /** Configure for the selected ADC regular channel to be converted.
  */
  sConfig.Channel = ADC_CHANNEL_1;
  sConfig.Channel = ADC_CHANNEL_VREFINT;
  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  {
@@ -932,6 +949,10 @@
      key_keeptime+=(float)g_com_map[COM_INTERVAL]/1000;
      if(key_keeptime>=KEY_KEEPRESET_TIME)
      {
            g_com_map[ACTIVE_INDEX]=!active_flag;
            save_com_map_to_flash();
            MOTOR_ON;
            HAL_Delay(2000);
         SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; 
      }
   }else{
@@ -943,11 +964,11 @@
   }else{
      stationary_flag = 0;
   }
if(nomove_count>=g_com_map[NOMOVESLEEP_TIME]-1&&imu_enable)
if(nomove_count>=nomovesleeptime-1&&imu_enable)
   {
      tx_near_msg[TAGSTATE] = tx_near_msg[TAGSTATE]|GOINGSLEEPBIT;
   }
   if(nomove_count>g_com_map[NOMOVESLEEP_TIME]&&imu_enable)
   if(nomove_count>nomovesleeptime&&imu_enable)
   {
      mcu_sleep();
   }