示例#1
0
/*
** ===================================================================
**     Method      :  FC321_GetTimeMS (bean FreeCntr32)
**
**     Description :
**         Returns the time (as a 16-bit unsigned integer) in milliseconds
**         since the last resetting after the last reset.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * Time            - A pointer to the returned 16-bit value
**                           in milliseconds
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_OVERFLOW - Software counter overflow
**                           ERR_MATH - Overflow during evaluation
** ===================================================================
*/
byte FC321_GetTimeMS(word *Time)
{
  dlong RTval;                         /* Result of two 32-bit numbers multiplication */

  if (LoadTicks()) {                   /* Load actual state of counter */
    return ERR_OVERFLOW;               /* If yes then error */
  }
  PE_Timer_LngMul(LTicks, 42949673UL, &RTval); /* Multiply ticks and high speed CPU mode coefficient */
  if (PE_Timer_LngHi4(RTval[0], RTval[1], Time)) { /* Is the result greater or equal than 65536 ? */
    return ERR_MATH;                   /* If yes then error */
  } else {                             /* Is the result less than 65536 ? */
    return ERR_OK;                     /* If yes then OK */
  }
}
示例#2
0
/*
** ===================================================================
**     Method      :  FC81_GetTimeMS (component FreeCntr8)
**
**     Description :
**         Returns the time (as a 16-bit unsigned integer) in milliseconds
**         since the last resetting after the last reset.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * Time            - A pointer to the returned 16-bit value
**                           in milliseconds
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_OVERFLOW - Software counter overflow
**                           ERR_MATH - Overflow during evaluation
** ===================================================================
*/
byte FC81_GetTimeMS(word *Time)
{
  dlong rtval;                         /* Result of two 32-bit numbers multiplication */

  LoadTicks();                         /* Load actual state of counter */
  if (LOvf) {                          /* Testing counter overflow */
    return ERR_OVERFLOW;               /* If yes then error */
  }
  PE_Timer_LngMul((dword)LTicks,34359738UL,&rtval); /* Multiply ticks and high speed CPU mode coefficient */
  if (PE_Timer_LngHi4(rtval[0],rtval[1],Time)) { /* Is the result greater or equal than 65536 ? */
    return ERR_MATH;                   /* If yes then error */
  }
  else {                               /* Is the result less than 65536 ? */
    return ERR_OK;                     /* If yes then OK */
  }
}