防止连续读time出错的处理---------后来证明不需要。(硬件上同一个总线)

来源:互联网 发布:七局网络教育平台 编辑:程序博客网 时间:2024/05/22 15:20

//--------------unsigned LONG----16位--

portTickType DestTickCnt;
DATETIME  BakTime;

//400ms为界,可能会涉及1s的误差
//如果tickcnt 多跑了一圈(需时49天)
void app_time_get(DATETIME* pTm)
{
    portTickType CurrTickCnt;

    CurrTickCnt = xTaskGetTickCount();   
    if(CurrTickCnt<DestTickCnt)//正常情况
    {
      *pTm=BakTime;  //无需重读。
      return;
    }
    else  //if(CurrTickCnt>DestTickCnt)//情况 
    { 
      if((DestTickCnt<NTick)&&                       //溢出 回头情况
         (CurrTickCnt>(~((portTickType)0)-NTick)))   //CurrTickCnt还没回头
        {
         *pTm=BakTime;  //无需重读。
         return;
        }        
    }
//需要重新获取       
   xSemaphoreTake(Mutex_TimeFlash,portMAX_DELAY);         
    if(!hal_rx8025_get(&BakTime))
    {         
       s_devstate  = ERROR_DEVHAL|DESC_E_TIME;//发现读常出错,故读3次最多。      
    }
   //成功取走一次的记录   
   *pTm=BakTime;
   CurrTickCnt = xTaskGetTickCount();
   if((CurrTickCnt)>(~((portTickType)0)-NTick))
        DestTickCnt=(CurrTickCnt+NTick)-~((portTickType)0);
   else DestTickCnt=(CurrTickCnt+NTick);
   xSemaphoreGive(Mutex_TimeFlash);   
}

原创粉丝点击