Ejemplo n.º 1
0
/*****************************************************************************
  GetMsgZtcOpCode
  Returns an opcode id for healtcare frames by using arrays that map the
  2 byte choice ids inside the frames to 1-byte opcode ids
*****************************************************************************/  
uint8_t GetMsgZtcOpCode(oepGenericApdu_t *pApdu) {

  int i;
  oepMsgType_t msgType = GetOepMsgType(pApdu);
  
  if (msgType == msgType_ObjCfgMsg)
    return (uint8_t)pApdu->choice & 0xFF;
  
  if (msgType == msgType_PrstMsg) {

    prstGeneric_t *pPrstFrame = (prstGeneric_t *)&pApdu->choice;    
    
    for (i = 0; i < NumberOfElements(Oem11073Ztc_OpCodeIdPrstChoiceMap); i++)
        /* check the choice id inside the Presentation Frame */
        if (Oem11073Ztc_OpCodeIdPrstChoiceMap[i].oemFrameId == pPrstFrame->prstChoice)
          /* return corresponding opcodeId from the map in case of a match */
          return Oem11073Ztc_OpCodeIdPrstChoiceMap[i].opCodeId;
  }
  
  /* iterate apdu choice-opcode map */
  for (i = 0; i < NumberOfElements(Oem11073Ztc_OpCodeIdApduChoiceMap); i++)
    /* check the choice id inside the apdu */
    if (Oem11073Ztc_OpCodeIdApduChoiceMap[i].oemFrameId == pApdu->choice)
      /* return corresponding opcodeId from the map in case of a match */
      return Oem11073Ztc_OpCodeIdApduChoiceMap[i].opCodeId;  
      
  return gHcZtcOpcode_OepInvalid_d;
  

}
Ejemplo n.º 2
0
/*****************************************************************************
 This Function store  to the Information Base in BlackBox and Host.
 *****************************************************************************/
void ZtcMsgSetIBReq(uint8_t msgType, uint8_t attrId, uint8_t index, uint8_t *pValue) {
  
  index_t i;
  uint8_t entrySize;
  
  /* Search attribute in table */
  for (i = 0; i < NumberOfElements(maZtcIBData); ++i) {
    if (attrId == maZtcIBData[i].id) {
      break;
    }
  } 
  
  if (i == NumberOfElements(maZtcIBData)) {
    return;
  }

  entrySize = maZtcIBData[i].entrySize;
  if((maZtcIBData[i].access == mZtcIBRWUseFunc))
  {
    ztcIBAccessTbl_t  const *pZtcIBAccessFuncTbl = NULL;
    uint8_t j;
      /* Find the entry in maZtcIBAccessFuncTbl */
    for (j = 0; j < NumberOfElements(maZtcIBAccessFuncTbl); ++j) {
      if (maZtcIBData[i].id == maZtcIBAccessFuncTbl[j].id) {
        pZtcIBAccessFuncTbl = &maZtcIBAccessFuncTbl[j];
        break;
      }
    }
    if (pZtcIBAccessFuncTbl)
     (void)(pZtcIBAccessFuncTbl)->pSetTblEntry(index, pValue);
    
  }
  else
  {
      /* Set the IB attribute locally and sent it over the UART (to BlackBox) */
    FLib_MemCpy((uint8_t *) maZtcIBData[i].pTable + (uint16_t) (entrySize * index),
                pValue,
                entrySize);
  }
  gZtcPacketToClient.structured.header.opcodeGroup    = gZtcReqOpcodeGroup_c;
  gZtcPacketToClient.structured.header.msgType        = msgType;
  gZtcPacketToClient.structured.payload[0] = attrId;
  gZtcPacketToClient.structured.payload[1] = index;
  gZtcPacketToClient.structured.payload[2] = 0x01; /* Update one entry each time */
  gZtcPacketToClient.structured.payload[3] = entrySize;
  FLib_MemCpy(&gZtcPacketToClient.structured.payload[4],
              pValue,
              entrySize);
  gZtcPacketToClient.structured.header.len = 4 + entrySize;
  ZtcComm_WritePacketToClient((gZtcPacketToClient.structured.header.len +
                         sizeof(gZtcPacketToClient.structured.header)));            
}
Ejemplo n.º 3
0
void Structure::Print(int level) const
{
    if(level > 0)
    {
        // print nodes
        std::cout << "List of Nodes:" << std::endl;
        for(std::size_t i = 0; i < NumberOfNodes(); ++i)
            mpNodes[i]->Print();
    }

    if(level > 1)
    {
        std::cout << "================================================" << std::endl;
        std::cout << "List of Elements:" << std::endl;
        // print elements
        for(std::size_t i = 0; i < NumberOfElements(); ++i)
            mpElements[i]->Print();

        std::cout << "================================================" << std::endl;
        std::cout << "List of Conditions:" << std::endl;
        // print conditions
        for(std::size_t i = 0; i < NumberOfConditions(); ++i)
            mpConditions[i]->Print();
    }
}
Ejemplo n.º 4
0
bool Structure::SameStructure( const Structure& x ) const
{
   if ( NumberOfWays() != x.NumberOfWays() || Size() != x.Size() )
      return false;
   for ( int i = 0; i < NumberOfWays(); ++i )
      if ( ::memcmp( mask[i].Begin(), x.mask[i].Begin(), NumberOfElements() ) != 0 )
         return false;
   return true;
}
Ejemplo n.º 5
0
/* Given an internal SAP Handler id, return a pointer to the corresponding
 * entry in the SAP Handler info table. If the internal SAP Handler id is
 * not found in the table, return NULL.
 */
ztcSAPHandlerInfo_t const *pZtcSAPInfoFromIntSAPId
  (
  ztcIntSAPId_t const intSAPId
  )
{
  index_t i;

  for (i = 0; i < NumberOfElements(gaZtcSAPHandlerInfo); ++i) {
    if (gaZtcSAPHandlerInfo[i].intSAPId == intSAPId) {
      return &(gaZtcSAPHandlerInfo[i]);
    }
  }

  return NULL;
}                                       /* pZtcSAPInfoFromIntSAPId() */
Ejemplo n.º 6
0
tmrTimerID_t TMR_AllocateTimer
(
void
)
{
  uint32_t i;
  
  for (i = 0; i < NumberOfElements(maTmrTimerTable); ++i) {
    if (!TMR_IsTimerAllocated(i)) {
      TMR_SetTimerStatus(i, mTmrStatusInactive_c);
      return i;
    }
  }
  
  return gTmrInvalidTimerID_c;
}                                       /* TMR_AllocateTimer() */
EXPORT_C TInt CMTPTypeObjectPropList::Validate() const
    {
    TInt relValue(KErrNone);
	TUint32 num = NumberOfElements();
	ResetCursor();
	for(TUint32 i = 0; i< num;i++)
		{
		TRAPD(err, GetNextElementL())
		if(KErrNone != err)
			{
			relValue = KMTPDataTypeInvalid;
			break;
			}
		}	
	
	ResetCursor();
	return relValue;
	}
Ejemplo n.º 8
0
/* The function make an approximate sync. the active low power timers. */                              
void TMR_SyncLpmTimers(uint32_t sleepDurationTmrTicks)
{
#if (gTMR_EnableLowPowerTimers_d) 
 index_t  timerID;
 tmrTimerType_t timerType;

 /* Check if there are low power active timer */
 if (!numberOfLowPowerActiveTimers)
    return;          

 /* For each timer, detect the timer type and count down the spent duration in sleep */  
 for (timerID = 0; timerID < NumberOfElements(maTmrTimerTable); ++timerID) 
 {

  /* Detect the timer type and count down the spent duration in sleep */
  timerType = TMR_GetTimerType(timerID);
  
  /* Sync. only the low power timers that are active */
  if ( (TMR_GetTimerStatus(timerID) == mTmrStatusActive_c)
        && (IsLowPowerTimer(timerType)) ) 
  {
           /* Timer expired when MCU was in sleep mode??? */
           if( maTmrTimerTable[timerID].remainingTicks > sleepDurationTmrTicks) 
           {
             maTmrTimerTable[timerID].remainingTicks -= sleepDurationTmrTicks;
 
           } 
           else 
           {
             maTmrTimerTable[timerID].remainingTicks = 0;           
           }
        
   }

 }/* end for (timerID = 0;.... */

 TmrStartTimerHardware();
 TmrReadValue(gTmrNumber_d, &previousTimeInTicks);

 TS_SendEvent(mTimerTaskID, mTMR_Event_c);
#else
 (void)sleepDurationTmrTicks;
#endif /* #if (gTMR_EnableLowPowerTimers_d) */ 
}
Ejemplo n.º 9
0
/* Given an opcode group, return a pointer to the corresponding entry in the
 * SAP Handler info table. If the opcode group is not found in the table,
 * return NULL. If the opcode group is found in the disables table, return
 * 0x0001.
 */
ztcSAPHandlerInfo_t const *pZtcSAPInfoFromOpcodeGroup
  (
  ztcOpcodeGroup_t const opcodeGroup
  )
{
  index_t i;

  for (i = 0; i < NumberOfElements(gaZtcSAPHandlerInfo); ++i) {
    if (gaZtcSAPHandlerInfo[i].opcodeGroup == opcodeGroup) {
      return &(gaZtcSAPHandlerInfo[i]);
    }
  }

#if gZtcErrorReporting_d
  i = 0;
  while (maDisabledOpcodeGroups[ i ] != gZtcSAPModeInvalid_c) {
    if (maDisabledOpcodeGroups[ i++ ] == opcodeGroup) {
      return gZtcIsDisabledOpcodeGroup_c;
    }
  }
#endif

  return NULL;
}                                       /* pZtcSAPInfoFromOpcodeGroup() */
Ejemplo n.º 10
0
/* Store information to the Information Base.
 *
 * On entry
 *  pRequest->iId       ID of the IB entry to set,
 *  pRequest->iIndex    Index of the first element to set, and
 *  pRequest->iEntries  Number of elements to set.
 *  pRequest->pData     Not actually a pointer; replaced by the start of the
 *                          data.
 *
 * Note that this code treats everything as an array. Scalar values are
 * considered arrays that have a maximum of one element.
 */
void ZtcMsgSetIBReqFunc(void) {
#define pRequest ((getIBRequest_t *) gZtcPacketFromClient.structured.payload)

  index_t entriesToSet = pRequest->iEntries;
  index_t entrySize;
  index_t firstEntry = pRequest->iIndex;
  index_t i;
  ztcIBData_t const *pIBData;
  index_t totalDataSize;

  for (i = 0, pIBData = NULL; i < NumberOfElements(maZtcIBData); ++i) {
    if (pRequest->iId == maZtcIBData[i].id) {
      pIBData = &maZtcIBData[i];
      break;
    }
  }

  if (!pIBData) {
    ZtcError(gZtcUnknownIBIdentifier_c);
    return;
  }

  if ((pIBData->access != mZtcIBRW) && (pIBData->access != mZtcIBRWUseFunc)) {
    gZtcPacketToClient.structured.payload[0] = gZtcReadOnly_c;
    return;
  }

  entrySize = pIBData->entrySize;
  totalDataSize = (index_t) (entriesToSet * entrySize);

  /* Check each of these conditions separately, to catch overflows. */
  if (  (firstEntry >= pIBData->maxEntries)
      || (firstEntry + entriesToSet > pIBData->maxEntries)
      || (totalDataSize > gZtcPacketFromClient.structured.header.len)) {
    gZtcPacketToClient.structured.payload[0] = gZtcTooBig_c;
    return;
  }
  
  if (pIBData->access == mZtcIBRWUseFunc)
  {

    ztcIBAccessTbl_t  const *pZtcIBAccessFuncTbl = NULL;
    /* Find the entry in maZtcIBAccessFuncTbl */
    for (i = 0; i < NumberOfElements(maZtcIBAccessFuncTbl); ++i) {
      if (pIBData->id == maZtcIBAccessFuncTbl[i].id) {
        pZtcIBAccessFuncTbl = &maZtcIBAccessFuncTbl[i];
        break;
      }
    } 
    if (pZtcIBAccessFuncTbl)
    { 
      uint8_t *pEntries = (void *) &pRequest->pData;
      for(i = firstEntry; i < (firstEntry + entriesToSet); i++)
      {
        (void)(pZtcIBAccessFuncTbl)->pSetTblEntry(i, pEntries);
        pEntries = pEntries + entrySize;
      }
      return;
    }    

  }

  FLib_MemCpy((uint8_t *) pIBData->pTable + ((uint16_t)entrySize * firstEntry),
              (void *) &pRequest->pData,
              totalDataSize);

#undef pRequest
}                                       /* ZtcMsgSetIBReqFunc() */
Ejemplo n.º 11
0
/* Retrieve information from the Information Base.
 *
 * On entry
 *  pRequest->iId       ID of the IB entry to get,
 *  pRequest->iIndex    Index of the first element to get, and
 *  pRequest->iEntries  Number of elements to get.
 *  pRequest->pData     Ignored
 *
 * Return
 *  pRequest->iEntries  Actual number of elements returned,
 *  pRequest->pData     Reused as the total data returned, in bytes.
 *
 * Note that this code treats everything as an array. Scalar values are
 * considered arrays that have a maximum of one element.
 */
void ZtcMsgGetIBReqFunc(void) {
#define pRequest ((getIBRequest_t *) gZtcPacketFromClient.structured.payload)
  getIBRequest_t *pResponse = ((getIBRequest_t *) &gZtcPacketToClient.structured.payload[sizeof(clientPacketStatus_t)]);

  index_t entriesReturned = pRequest->iEntries;
  index_t entrySize;
  index_t firstEntry = pRequest->iIndex;
  index_t i;
  ztcIBData_t const *pIBData;
  index_t totalDataSize;

  for (i = 0, pIBData = NULL; i < NumberOfElements(maZtcIBData); ++i) {
    if (pRequest->iId == maZtcIBData[i].id) {
      pIBData = &maZtcIBData[i];
      break;
    }
  }

  if (!pIBData) {
    ZtcError(gZtcUnknownIBIdentifier_c);
    return;
  }

  /* The Test Tool is used by humans, who make mistakes. Be forgiving. */
  if (firstEntry >= pIBData->maxEntries) {
    firstEntry = pIBData->maxEntries - 1;
  }
  if (firstEntry + entriesReturned > pIBData->maxEntries) {
    entriesReturned = pIBData->maxEntries - firstEntry;
  }
  if (!entriesReturned) {
    entriesReturned = 1;
  }

  /* points to the "To" client packet. They don't overlap. */
  FLib_MemCpy((uint8_t *) pResponse, (void *) pRequest, sizeof(getIBRequest_t));

  pResponse->iEntries = entriesReturned;
  pResponse->iEntrySize = entrySize = pIBData->entrySize;
  totalDataSize = (index_t) (entriesReturned * entrySize);
  if (totalDataSize > sizeof(gZtcPacketFromClient.structured.payload) - sizeof(getIBRequest_t)) {
    gZtcPacketToClient.structured.payload[0] = gZtcTooBig_c;
    return;
  }

  /* Note that pRequest points to the "From" client packet, and pResponse */
  /* totalDataSize is shifted because Test Tool has to receive it little endian */
  *((uint16_t *) &pResponse->pData) = totalDataSize << 8; 
  gZtcPacketToClient.structured.header.len = sizeof(getIBRequest_t) + totalDataSize + sizeof(clientPacketStatus_t);

  if (pIBData->access == mZtcIBRWUseFunc)
  {
    ztcIBAccessTbl_t  const *pZtcIBAccessFuncTbl = NULL;
    /* Find the entry in maZtcIBAccessFuncTbl */
    for (i = 0; i < NumberOfElements(maZtcIBAccessFuncTbl); ++i) {
      if (pIBData->id == maZtcIBAccessFuncTbl[i].id) {
        pZtcIBAccessFuncTbl = &maZtcIBAccessFuncTbl[i];
        break;
      }
    }
    
    if (pZtcIBAccessFuncTbl)
    { 
      uint8_t *pEntries = ((uint8_t *) &pResponse->pData) + sizeof(pResponse->pData); 
      for(i = firstEntry; i < (firstEntry+entriesReturned); i++)
      {
        (void)(pZtcIBAccessFuncTbl)->pGetTblEntry(i, pEntries);
        pEntries = pEntries + entrySize;
      }
      return;
    }
  }

  FLib_MemCpy(((uint8_t *) &pResponse->pData) + sizeof(pResponse->pData),
              (void *) (((uint8_t *) pIBData->pTable) + ((uint16_t)entrySize * firstEntry)),
              totalDataSize);
              

#undef pRequest
}                                       /* ZtcMsgGetIBReqFunc() */
Ejemplo n.º 12
0
/******************************
  Temperature Measurement Cluster
  See ZCL Specification Section 4.4
*******************************/
const zclAttrDef_t gaZclTemperatureMeasurementClusterAttrDef[] = {  
  {gZclAttrTemperatureMeasurement_MeasuredValueId_c,     gZclDataTypeInt16_c,gZclAttrFlagsInRAM_c | gZclAttrFlagsReportable_c,sizeof(int16_t),  (void *)MbrOfs(zclTemperatureMeasurementAttrs_t,MeasuredValue)},
  {gZclAttrTemperatureMeasurement_MinMeasuredValuedId_c, gZclDataTypeInt16_c,gZclAttrFlagsInRAM_c | gZclAttrFlagsRdOnly_c,sizeof(int16_t),  (void *)MbrOfs(zclTemperatureMeasurementAttrs_t,MinMeasuredValue)},
  {gZclAttrTemperatureMeasurement_MaxMeasuredValuedId_c, gZclDataTypeInt16_c,gZclAttrFlagsInRAM_c | gZclAttrFlagsRdOnly_c,sizeof(int16_t),  (void *)MbrOfs(zclTemperatureMeasurementAttrs_t,MaxMeasuredValue)}
#if gZclClusterOptionals_d
  , {gZclAttrTemperatureMeasurement_ToleranceId_c, gZclDataTypeUint16_c,gZclAttrFlagsInRAM_c | gZclAttrFlagsReportable_c,sizeof(uint16_t),  (void *)MbrOfs(zclTemperatureMeasurementAttrs_t,Tolerance)}
#endif
};

const zclAttrDefList_t gZclTemperatureMeasurementClusterAttrDefList = {
  NumberOfElements(gaZclTemperatureMeasurementClusterAttrDef),
  gaZclTemperatureMeasurementClusterAttrDef
};

/******************************
  Pressure Measurement Cluster
  See ZCL Specification Section 4.5
*******************************/

/******************************
  Flow Measurement Cluster
  See ZCL Specification Section 4.6
*******************************/

/******************************
  Relative Humidity Measurement Cluster
Ejemplo n.º 13
0
 * to it, per SAP Handler. Fortunately, there aren't very many SAP Handlers.
 *
 * There are other ways to make the lengths of the message info tables
 * available for use in the SAP Handler table that would not require the
 * pointers, but they involve some C language and/or pre-processor tricks
 * that are not obvious, and may not work in all compilers.
 */

/* opcode group 0x87, NWK_MCPS_SapHandler() */
#if gSAPMessagesEnableMcps_d
#define NwkMcpsTbl(msgType, cnfType, flags, len, format) \
    {msgType, cnfType, len, (flags | format)},
ztcMsgTypeInfo_t const gaZtcNwkMcpsMsgTypeTable[] = {
#include "ZtcMsgTypeInfoTbl.h"
};
index_t const gZtcNwkMcpsMsgTypeTableLen = NumberOfElements(gaZtcNwkMcpsMsgTypeTable);
#endif

/* opcode group 0x86, MCPS_NWK_SapHandler() */
#if gSAPMessagesEnableMcps_d
#define McpsNwkTbl(msgType, cnfType, flags, len, format) \
    {msgType, cnfType, len, (flags | format)},
ztcMsgTypeInfo_t const gaZtcMcpsNwkMsgTypeTable[] = {
#include "ZtcMsgTypeInfoTbl.h"
};
index_t const gZtcMcpsNwkMsgTypeTableLen = NumberOfElements(gaZtcMcpsNwkMsgTypeTable);
#endif

/* opcode group_c = 0x85, NWK_MLME_SapHandler() */
#if gSAPMessagesEnableMlme_d
#define NwkMlmeTbl(msgType, cnfType, flags, len, format) \
Ejemplo n.º 14
0
int Structure::Solve()
{
    // extract dofs from elements and conditions
    // this scheme ensures every dofs will be accounted once
    typedef std::pair<std::size_t, std::size_t> Key_t;
    typedef std::map<Key_t, Dof::Pointer> DofSetContainer_t;
    DofSetContainer_t DofSet;
    std::vector<Dof::Pointer> DofList;
    for(std::size_t i = 0; i < NumberOfElements(); ++i)
    {
        this->GetElement(i).GetDofList(DofList);
        for(std::size_t i = 0; i < DofList.size(); ++i)
        {
            Key_t key(DofList[i]->Id(), DofList[i]->Type());
            DofSet[key] = DofList[i];
        }
    }
    for(std::size_t i = 0; i < NumberOfConditions(); ++i)
    {
        this->GetCondition(i).GetDofList(DofList);
        for(std::size_t i = 0; i < DofList.size(); ++i)
        {
            Key_t key(DofList[i]->Id(), DofList[i]->Type());
            DofSet[key] = DofList[i];
        }
    }

    // assign for each dof a unique equation id
    std::size_t free_id = 0;
    std::size_t fixed_id = DofSet.size();
    for(DofSetContainer_t::iterator it = DofSet.begin(); it != DofSet.end(); ++it)
    {
        if(it->second->IsFixed())
            it->second->SetEquationId(--fixed_id);
        else
            it->second->SetEquationId(free_id++);
    }
    mEquationSystemSize = fixed_id;

//    for(DofSetContainer_t::iterator it = DofSet.begin(); it != DofSet.end(); ++it)
//        std::cout << *(it->second) << std::endl;

    // assemble the stiffness matrix & external force vector
    CompressedMatrix K;
    K.resize(mEquationSystemSize, mEquationSystemSize);
    noalias(K) = ZeroMatrix(mEquationSystemSize, mEquationSystemSize);

    Vector R;
    R.resize(mEquationSystemSize);
    noalias(R) = ZeroVector(mEquationSystemSize);

    Matrix LHSlocal;
    Vector RHSlocal;
    for(std::size_t i = 0; i < NumberOfElements(); ++i)
    {
        this->GetElement(i).GetDofList(DofList);
        this->GetElement(i).CalculateLocalSystem(LHSlocal, RHSlocal);

        std::size_t local_size = DofList.size();
        std::size_t row, col;
        for(std::size_t i = 0; i < local_size; ++i)
            for(std::size_t j = 0; j < local_size; ++j)
            {
                row = DofList[i]->EquationId();
                col = DofList[j]->EquationId();
                if(row < mEquationSystemSize && col < mEquationSystemSize)
                    K(row, col) += LHSlocal(i, j);
            }

        for(std::size_t i = 0; i < local_size; ++i)
        {
            row = DofList[i]->EquationId();
            if(row < mEquationSystemSize)
                R(row) += RHSlocal(i);
        }
    }

    for(std::size_t i = 0; i < NumberOfConditions(); ++i)
    {
        this->GetCondition(i).GetDofList(DofList);
        this->GetCondition(i).CalculateLocalSystem(LHSlocal, RHSlocal);

        std::size_t local_size = DofList.size();
        std::size_t row, col;
        for(std::size_t i = 0; i < local_size; ++i)
            for(std::size_t j = 0; j < local_size; ++j)
            {
                row = DofList[i]->EquationId();
                col = DofList[j]->EquationId();
                if(row < mEquationSystemSize && col < mEquationSystemSize)
                    K(row, col) += LHSlocal(i, j);
            }

        for(std::size_t i = 0; i < local_size; ++i)
        {
            row = DofList[i]->EquationId();
            if(row < mEquationSystemSize)
                R(row) += RHSlocal(i);
        }
    }

    OOFEM_WATCH(K)
    OOFEM_WATCH(R)

    // solve the linear system
    Vector X;
    X.resize(mEquationSystemSize);
    noalias(X) = ZeroVector(mEquationSystemSize);
    Kratos::SuperLUSolver solver;
    solver.Solve(K, X, R);

    OOFEM_WATCH(X)

    // update the values at d.o.f
    for(DofSetContainer_t::iterator it = DofSet.begin(); it != DofSet.end(); ++it)
    {
        std::size_t EqnId = it->second->EquationId();
        if(EqnId < mEquationSystemSize)
            it->second->SetValue(X(EqnId));
    }
}
Ejemplo n.º 15
0
/*****************************************************************************
* Timer task. Called by the kernel when the timer ISR posts a timer event.
******************************************************************************/
void TMR_Task
(
event_t events
)
{
  static bool_t timerHardwareIsRunning = FALSE;
  tmrTimerTicks16_t nextInterruptTime;
  pfTmrCallBack_t pfCallBack;
  tmrTimerTicks16_t currentTimeInTicks;
  tmrTimerStatus_t status;
  tmrTimerTicks16_t ticksSinceLastHere, ticksdiff; 
  uint8_t timerID;
  unsigned int saveInt;
  tmrTimerType_t timerType;
  (void)events;
  
  TmrReadValue(gTmrNumber_d,&currentTimeInTicks);
  /* calculate difference between current and previous.  */
  ticksSinceLastHere = (currentTimeInTicks - previousTimeInTicks);
  /* remember for next time */
  previousTimeInTicks = currentTimeInTicks;
  
  for (timerID = 0; timerID < NumberOfElements(maTmrTimerTable); ++timerID) {
    saveInt = IntDisableAll();
    status = TMR_GetTimerStatus(timerID);
    /* If TMR_StartTimer() has been called for this timer, start it's count */
    /* down as of now. */
    if (status == mTmrStatusReady_c) {
      TMR_SetTimerStatus(timerID, mTmrStatusActive_c);
      IntRestoreAll(saveInt);
      continue;
    }
    IntRestoreAll(saveInt);
    
    /* Ignore any timer that is not active. */
    if (status != mTmrStatusActive_c) {
      continue;
    }
    
    /* This timer is active. Decrement it's countdown.. */
    if (maTmrTimerTable[timerID].remainingTicks > ticksSinceLastHere) {
      maTmrTimerTable[timerID].remainingTicks -= ticksSinceLastHere;
      continue;
    }
    
    timerType = TMR_GetTimerType(timerID);
    /* If this is an interval timer, restart it. Otherwise, mark it as inactive. */
    if ( (timerType & gTmrSingleShotTimer_c) ||
         (timerType & gTmrSetMinuteTimer_c) ||
         (timerType & gTmrSetSecondTimer_c)  ) {
      TMR_StopTimer(timerID);
    } else {
      maTmrTimerTable[timerID].remainingTicks = maTmrTimerTable[timerID].intervalInTicks;
    }
    /* This timer has expired. */
    pfCallBack = maTmrTimerTable[timerID].pfCallBack;
    /*Call callback if it is not NULL
    This is done after the timer got updated,
    in case the timer gets stopped or restarted in the callback*/
    if (pfCallBack) {
      pfCallBack(timerID);
    }
    
  }  /* for (timerID = 0; timerID < ... */
  
  /* Find the shortest active timer. */
  nextInterruptTime = mMaxToCountDown_c;
  for (timerID = 0; timerID < NumberOfElements(maTmrTimerTable); ++timerID) {
    if (TMR_GetTimerStatus(timerID) == mTmrStatusActive_c) {
      if (nextInterruptTime > maTmrTimerTable[timerID].remainingTicks) {
        nextInterruptTime = maTmrTimerTable[timerID].remainingTicks;
      }
    }
  }
  
  /* Check to be sure that the timer is not programmed in the past */    
  saveInt = IntDisableAll();
  TmrReadValue(gTmrNumber_d,&ticksdiff);
  /* Number of ticks to be here */
  ticksdiff = (uint16_t)(ticksdiff - currentTimeInTicks); 
   /* Next ticks to count already expired?? */
  if(ticksdiff >= nextInterruptTime)
  {  
    /* Is assumed that a task has to be executed in 4ms...
       so if the ticks already expired enter in TMR_Task() after 4ms*/
    nextInterruptTime = ticksdiff + mTicksFor4ms;
  } 
  else 
  {
    /* Time reference is 4ms...
       so be sure that won't be loaded in Cmp Reg. less that 4ms in ticks 
    */
     if((nextInterruptTime - ticksdiff) < mTicksFor4ms) 
     {
       nextInterruptTime = ticksdiff + mTicksFor4ms;
     }
  
  }
  /* Update the compare register */
  nextInterruptTime += currentTimeInTicks;
  SetComp1Val(gTmrNumber_d, nextInterruptTime);
  IntRestoreAll(saveInt);
  
  if (!numberOfActiveTimers && !numberOfLowPowerActiveTimers)
  {
    TmrStopTimerHardware();
    timerHardwareIsRunning = FALSE;
  } 
  else 
    if (!timerHardwareIsRunning) 
    {
      TmrStartTimerHardware();
      timerHardwareIsRunning = TRUE;
    }
}                                       /* TMR_Task() */
Ejemplo n.º 16
0
            pSAPFunc, modeTableIndex, msgQueue, msgEvent, pTaskID, \
            msgTypeTable, msgTypeTableLen) \
  {opcodeGroup, converse, intSAPIdName, pSAPFunc, modeTableIndex, \
   msgQueue, msgEvent, pTaskID, msgTypeTable, &msgTypeTableLen},
ztcSAPHandlerInfo_t const gaZtcSAPHandlerInfo[1] = {0xFF, 0xFF, 0xFF, NULL, 0xFF, NULL, 0xFF, NULL, NULL, NULL};
#endif
/****************************************************************************/

/* Current SAP Handler modes. One byte per SAP Handler. There are only three */
/* modes, so 2 bits would be enough, but there aren't very many SAP Handlers. */
#define SapMode(name, index, defaultMode)   defaultMode,

ztcSAPMode_t maZtcSAPModeTable[] = {    /* Cannot be const. */
#include "ZtcSAPHandlerInfoTbl.h"
};
index_t const mZtcSAPModeTableLen = NumberOfElements(maZtcSAPModeTable);

/******************************************************************************
*******************************************************************************
* Private memory declarations
*******************************************************************************
******************************************************************************/

#define DisabledSap(opcodeGroup) opcodeGroup,

/* Used by pZtcSAPInfoFromOpcodeGroup() to recognized opcode groups */
/* that have been compiled out, to improve error messages. */
#if gZtcErrorReporting_d
ztcOpcodeGroup_t const maDisabledOpcodeGroups[] = {
#include "ZtcSAPHandlerInfoTbl.h"
  gZtcInvalidOpcodeGroup_c              /* End of table mark. */