⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fc161.c

📁 我在开发CC2500和CC1100时就用了SmartRF Studio调试软硬件,很好用的,我可以做出兼容chipcon的SmartRF 硬件,不知道有没人有兴趣?
💻 C
字号:
/** ###################################################################
**     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : FC161.C
**     Project   : Project_1
**     Processor : MC9S08QD4CPC
**     Beantype  : FreeCntr16
**     Version   : Bean 02.059, Driver 01.11, CPU db: 2.87.049
**     Compiler  : CodeWarrior HCS08 C Compiler
**     Date/Time : 2008-2-18, 11:16
**     Abstract  :
**         This device "FreeCntr16" implements 16-bit Free Running Counter
**     Settings  :
**         Timer name                  : TPM1 (16-bit)
**         Compare name                : TPM10
**         Counter shared              : No
**
**         High speed mode
**             Prescaler               : divide-by-1
**             Clock                   : 15625 Hz
**           Resolution of timer
**             Xtal ticks              : 512
**             microseconds            : 16384
**             milliseconds            : 16
**             seconds (real)          : 0.0163840
**             Hz                      : 61
**
**         Initialization:
**              Timer                  : Enabled
**
**         Timer registers
**              Counter                : TPMCNT    [$0041]
**              Mode                   : TPMSC     [$0040]
**              Run                    : TPMSC     [$0040]
**              Prescaler              : TPMSC     [$0040]
**
**         Compare registers
**              Compare                : TPMC0V    [$0046]
**     Contents  :
**         Reset     - byte FC161_Reset(void);
**         GetTimeUS - byte FC161_GetTimeUS(word *Time);
**         GetTimeMS - byte FC161_GetTimeMS(word *Time);
**
**     (c) Copyright UNIS, spol. s r.o. 1997-2006
**     UNIS, spol. s r.o.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
** ###################################################################*/


/* MODULE FC161. */

#include "PE_Error.h"
#include "FC161.h"

#pragma MESSAGE DISABLE C4002          /* Disable warning C4002 "Result not used" */


static word TTicks;                    /* Counter of timer ticks */
static word LTicks;                    /* Working copy of variable TTicks */
static bool TOvf;                      /* Counter overflow flag */
static bool LOvf;                      /* Working copy of variable TOvf */

/* Internal method prototypes */

/*
** ===================================================================
**     Method      :  LoadTicks (bean FreeCntr16)
**
**     Description :
**         The method loads actual number of timer ticks and actual state 
**         of overflow flag.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void LoadTicks(void);

/* End of Internal methods declarations */

/*
** ===================================================================
**     Method      :  LoadTicks (bean FreeCntr16)
**
**     Description :
**         The method loads actual number of timer ticks and actual state 
**         of overflow flag.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void LoadTicks(void)
{
  EnterCritical();                     /* Save the PS register */
  LTicks = TTicks;                     /* Loading actual number of timer ticks */
  LOvf = TOvf;                         /* Loading actual state of "overflow flag" */
  ExitCritical();                      /* Restore the PS register */
}

/*
** ===================================================================
**     Method      :  FC161_Reset (bean FreeCntr16)
**
**     Description :
**         Clears the counter.
**     Parameters  : None
**     Returns     :
**         ---       - Error Code
** ===================================================================
*/
byte FC161_Reset(void)
{
  EnterCritical();                     /* Save the PS register */
  TPMCNTH = 0x00;                      /* Reset HW Counter */
  TTicks =  0x00;                      /* Reset counter of timer ticks */
  TOvf = FALSE;                        /* Reset counter overflow flag */
  ExitCritical();                      /* Restore the PS register */
  return ERR_OK;                       /* OK */
}

/*
** ===================================================================
**     Method      :  FC161_GetTimeUS (bean FreeCntr16)
**
**     Description :
**         Returns the time (as a 16-bit unsigned integer) in microseconds
**         since the last resetting after the last reset.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * Time            - A pointer to the returned 16-bit value
**                           in microseconds
**     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 FC161_GetTimeUS(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,0x40000000LU,&rtval); /* Multiply ticks and High speed CPU mode coefficient */
  if (PE_Timer_LngHi2(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 */
  }
}

/*
** ===================================================================
**     Method      :  FC161_GetTimeMS (bean FreeCntr16)
**
**     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 FC161_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,0x10624DD3LU,&rtval); /* Multiply ticks and High speed CPU mode coefficient */
  if (PE_Timer_LngHi3(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 */
  }
}

/*
** ===================================================================
**     Method      :  FC161_Init (bean FreeCntr16)
**
**     Description :
**         Initializes the associated peripheral(s) and the beans 
**         internal variables. The method is called automatically as a 
**         part of the application initialization code.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void FC161_Init(void)
{
  /* TPMSC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=0,PS2=0,PS1=0,PS0=0 */
  setReg8(TPMSC, 0x00);                /* Stop HW; disable overflow interrupt and set prescaler to 0 */ 
  /* TPMC0SC: CH0F=0,CH0IE=1,MS0B=0,MS0A=1,ELS0B=0,ELS0A=0,??=0,??=0 */
  setReg8(TPMC0SC, 0x50);              /* Set output compare mode and enable compare interrupt */ 
  TTicks = 0;                          /* Counter of timer ticks */
  TOvf = FALSE;                        /* Counter overflow flag */
  FC161_SetCV((word)0xFF);             /* Store appropriate value to the compare/modulo register according to High speed CPU mode */
  /* TPMCNTH: BIT15=0,BIT14=0,BIT13=0,BIT12=0,BIT11=0,BIT10=0,BIT9=0,BIT8=0 */
  setReg8(TPMCNTH, 0x00);              /* Reset HW Counter */ 
  /* TPMSC: TOF=0,TOIE=0,CPWMS=0,CLKSB=1,CLKSA=0,PS2=0,PS1=0,PS0=0 */
  setReg8(TPMSC, 0x10);                /* Set prescaler and run counter */ 
}


/*
** ===================================================================
**     Method      :  FC161_Interrupt (bean FreeCntr16)
**
**     Description :
**         The method services the interrupt of the selected peripheral(s)
**         and eventually invokes the beans event(s).
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
ISR(FC161_Interrupt)
{
  /* TPMC0SC: CH0F=0 */
  clrReg8Bits(TPMC0SC, 0x80);          /* Reset compare interrupt request flag */ 
  TTicks++;                            /* Increment counter of timer ticks */
  if (TTicks == 0x00) {                /* Testing counter overflow */
    TOvf = TRUE;                       /* If yes then set overflow flag */
  }
}



/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 3.00 [03.89]
**     for the Freescale HCS08 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -