zhyinch
2020-04-07 a185e714b1710025030317a1a32ad0ce660deef5
Src/main.c
@@ -37,7 +37,7 @@
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define DEBUG_MODE
//#define DEBUG_MODE
#define Period               (uint32_t) 32768
#define Timeout              (uint32_t) 32768 - 1//(32768 - 1)
/* USER CODE END PD */
@@ -79,12 +79,18 @@
uint32_t dev_id;
extern uint8_t g_start_sync_flag;
uint16_t heartbeat_timer,poll_timer,sync_timer;
uint8_t aRxBuffer[1];
void IdleTask(void)
{
   g_start_sync_flag=0;
         UART_CheckReceive();
      UART_CheckSend();
   if(huart1.Instance->ISR&USART_ISR_ORE)
   {
   SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader
   }
if(!HAL_GPIO_ReadPin(PWR_ON_GPIO_Port,PWR_ON_Pin))
{
   LED_LR_ON;
@@ -113,7 +119,7 @@
uint16_t tyncpoll_time,lpsettime;
uint16_t slottime,max_slotpos;
uint16_t lastpoll_count,interval_count,slot_startcount;
uint16_t lastpoll_count,interval_count,slot_startcount,tag_frequency;
void Program_Init(void)
{   float temp;
   uint16_t temp2;
@@ -125,7 +131,7 @@
#ifdef DEBUG_MODE
   g_com_map[DEV_ROLE]=1;
      g_com_map[DEV_ID]=1;
   g_com_map[COM_INTERVAL]=100;
   g_com_map[COM_INTERVAL]=1000;
   g_com_map[MAX_REPORT_ANC_NUM]=1;
#endif
      
@@ -136,10 +142,11 @@
   slottime=ceil((double)g_com_map[MAX_REPORT_ANC_NUM]*4/3);
   max_slotpos=g_com_map[COM_INTERVAL]/slottime;
   tyncpoll_time=(g_com_map[DEV_ID]%max_slotpos)*slottime;   
   slot_startcount=(float)(tyncpoll_time+10)*1000/LPTIMER_LSB;
   lastpoll_count=slot_startcount;
   interval_count=(float)g_com_map[COM_INTERVAL]*1000/LPTIMER_LSB;
  tag_frequency = 1000/g_com_map[COM_INTERVAL];
      if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIMER_1S_COUNT, slot_startcount) != HAL_OK)  //system time is 1010ms   1 puls=30.518us
  {
    Error_Handler();
@@ -164,7 +171,23 @@
  HAL_PWREx_EnableFastWakeUp();
}
uint32_t temp;
extern uint8_t sleep_flag;
extern uint8_t sleep_flag,m_bEUARTTxEn;
uint16_t waitusart_timer;
uint8_t bat_percent=0;
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
  /* Set transmission flag: trasfer complete*/
  waitusart_timer = tag_frequency*USART_KEEPWAKE_TIME;
      if(HAL_UART_Receive_DMA(&huart1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE))
   {
    Error_Handler();
   }
}
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
      //SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader
}
/* USER CODE END 0 */
/**
@@ -206,12 +229,10 @@
   LIS3DH_Data_Init();   
   Dw1000_Init();
   Dw1000_App_Init();
   dwt_configuresleep(DWT_PRESRV_SLEEP | DWT_CONFIG, DWT_WAKE_CS | DWT_WAKE_WK| DWT_SLP_EN);
   //dwt_entersleep();
   if(HAL_UART_Receive_DMA(&huart1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE))
   {
    Error_Handler();
   }
   dwt_entersleep();
   waitusart_timer=1;
   //LED0_BLINK;      
//   SystemPower_Config();
//HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);   
@@ -224,14 +245,43 @@
    /* USER CODE END WHILE */
    /* USER CODE BEGIN 3 */
      if(1)//g_start_send_flag)
   {
   //   SystemClock_Config();
      if(g_start_send_flag)
   { static uint16_t blink_count=0;
      SystemClock_Config();
      g_start_send_flag = 0;   
      Tag_App();
//      if(current_count>slot_startcount&&current_count<slot_startcount+interval_count)
//      {
//      HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_SET);
//      }else{
//      HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_RESET);
//      }
         bat_percent=Get_Battary();
      if(bat_percent>15)
      {   LED0_ON;
         Tag_App();
         LED0_OFF;
      }else{
         LED_LR_ON;
         Tag_App();
         LED_LR_OFF;
      }
      //LED0_BLINK;      
      IdleTask();   
   //   HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
      if(waitusart_timer>0)
      {
         waitusart_timer--;
      }
         if(m_bEUARTTxEn==0&&waitusart_timer==0)
         {
               HAL_UART_DMAStop(&huart1);
              if(HAL_UART_Receive_IT(&huart1, (uint8_t *)aRxBuffer, 1) != HAL_OK)
               {
                  Error_Handler();
               }
         //   HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
         }
   }else{
   IdleTask();   
   }
@@ -455,9 +505,12 @@
    Error_Handler();
  }
  /* USER CODE BEGIN USART1_Init 2 */
// __HAL_UART_ENABLE_IT(&huart1, UART_IT_RXNE);//??idle??
  if(HAL_UART_Receive_IT(&huart1, (uint8_t *)aRxBuffer, 1) != HAL_OK)
  {
    Error_Handler();
  }
   Usart1InitVariables();
   LED0_BLINK;
  /* USER CODE END USART1_Init 2 */
}
@@ -603,7 +656,7 @@
   i++;
   g_start_send_flag=1;
   lastpoll_count+=interval_count;
   if(lastpoll_count>LPTIMER_1S_COUNT)
   if(lastpoll_count>LPTIMER_1S_COUNT-30)
   {
      lastpoll_count = slot_startcount; 
   }