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

📄 timerhal.c

📁 freescale的基于802.15.4的无线通讯例程
💻 C
字号:
/*****************************************************************************
* This module contains Hardware setting functions for timer module
*
* COMPILER OPTIONS:
* gInterruptDrivenTimers_d - Uses interrupts to run the software timer.
* gPolledTimers_d - Does not use interrupts but required to call the TMR_Main at
* regular interval.
* gSoftwareTimerCount_c - Specify the number of software timer required.
*  (in TMR_Interface.h)
*
*             
* (c) Copyright 2006, Freescale, Inc. All rights reserved.
*
* Freescale Semiconductor Confidential Proprietary
*
* No part of this document must be reproduced in any form - including copied,
* transcribed, printed or by any electronic means - without specific written
* permission from Freescale Semiconductor Danmark A/S.
*****************************************************************************/

#include "PortConfig.h"

#include "Timer.h"
#include "TimerHAL.h"
#include "TMR_Interface.h"

#include "TS_Interface.h"

/*****************************************************************************
******************************************************************************
* Private macros
******************************************************************************
*****************************************************************************/
/* None */

/*****************************************************************************
******************************************************************************
* Private prototypes
******************************************************************************
*****************************************************************************/
extern void TMR_Task(event_t events);


/*****************************************************************************
******************************************************************************
* Private type definitions
******************************************************************************
*****************************************************************************/
/* None */

/*****************************************************************************
******************************************************************************
* Private memory declarations
******************************************************************************
*****************************************************************************/
uint8_t gaExpiredTimers[gSoftwareTimerCount_c]; /* Holds expired timers,from
                  the time Interrupt occurs to TMR_Task() gets executed */ 
uint8_t mExpiredTimerHead;  


/*****************************************************************************
******************************************************************************
* Public functions
******************************************************************************
*****************************************************************************/

/*****************************************************************************
* This function Initializes the Timer System 
*
* Interface assumptions:
*
* Return value:
* None
*
* Revison history:
* date    Author  Comments
* ------  ------  --------
* 071205  LS      Created
*****************************************************************************/

void TMR_Init(void)
{
  uint8_t iTimerCnt;
  /*  Intialises all timers */
  for( iTimerCnt = 0; iTimerCnt < gSoftwareTimerCount_c; iTimerCnt++ ) {
    maSoftTimers[ iTimerCnt ].timerMgmt.next = mTimerNill_c;
    
    maSoftTimers[ iTimerCnt ].timerMgmt.status |= gValidTimer_c;
    maSoftTimers[ iTimerCnt ].pCallBackFunction = TMR_DefaultTimeoutHandler;
  }
  /*Output compare mode, generate interrupt on match*/
  #if (gInterruptDrivenTimers_d == 1)
    TPM1C0SC = (gTpm1socCh0ie_c | gTpm1c0scMs0a_c);
  #endif gInterruptDrivenTimers_d

  /*Output compare mode, no interrupt. only overflow flag will be set*/
  #if (gPolledTimers_d == 1)
    TPM1C0SC = gTpm1c0scMs0a_c;
  #endif gPolledTimers_d
 
}


/*****************************************************************************
* This function is the ISR for Interrup driven Timer. 
*
* Interface assumptions:
*
* Return value:
* None
*
* Revison history:
* date    Author  Comments
* ------  ------  --------
* 071205  LS      Created
*****************************************************************************/
/* This function will be registered as ISR routine if 
    gInterruptDrivenTimers_d is defined*/
#if (gInterruptDrivenTimers_d == 1)
__interrupt void TMR_InterruptHandler(void) {
#endif gInterruptDrivenTimers_d

/*The function should be called frequently if gPolledTimers_d is used.*/
#if (gPolledTimers_d == 1)
void TMR_Main(void) {
#endif gPolledTimers_d
  
  /*  MCUs,the high-order half of the H:X index register pair (H) is not saved
  on the stack as part of the interrupt sequence. The user must use a PSHH
  instruction at the beginning of the service routine to save H and then use a
  PULH instruction just before the RTI that ends the interrupt service routin.
  */
  #if (gInterruptDrivenTimers_d == 1)
    asm PSHH
  #endif gInterruptDrivenTimers_d

  /*  Check for channel 0 overflow flag to set,Read TPM1C0SC register as part
      of resetting CH0F flag  */  
  if ( TPM1C0SC & gChofSet_c )  { 
    /*Clear the CH0F flag in TPM1C0SC*/
    TPM1C0SC &= gTpm1c0scChofClear_c;
    
    /*Critical section ends here, so enable global interrupt flag*/
    #if (gInterruptDrivenTimers_d == 1)
	    asm CLI
	  #endif gInterruptDrivenTimers_d

    maSoftTimers[mTimerHead].timerMgmt.status |= gExpiredTimer_c;
    
    gaExpiredTimers[mExpiredTimerHead] = mTimerHead;
    mExpiredTimerHead++;
    mTimerHead = maSoftTimers[ mTimerHead ].timerMgmt.next;
            
    if( mTimerHead != mTimerNill_c )  { /*  Not the last timer  */
      TMRCalculateAndLoadNextTimeOutCompareValue( mTimerHead );
    }
    else {
      ExitSwTimerMode();
    }
    
    #if (gSchedulerIntegration_d == 1)
      TS_SendEvent(gTimerTask_c,gTMR_EventTimeOut_c);	
    #endif /*gSchedulerIntegration_d*/
  }
	
  #if (gInterruptDrivenTimers_d == 1)
    asm PULH
  #endif gInterruptDrivenTimers_d
}


/*****************************************************************************
* This function loads the value to the Compare Register 
*
* Interface assumptions:
*
* Return value:
* None
*
* Revison history:
* date    Author  Comments
* ------  ------  --------
* 071205  LS      Created
*****************************************************************************/

void TMRInitCompareRegister
  (
  uint16_t CRcount  /*  IN: */
  )
{
  TPM1C0VL = TPM1C0VLvalue( CRcount );
  TPM1C0VH = TPM1C0VHvalue( CRcount );
}


/*****************************************************************************
******************************************************************************
* Private functions
******************************************************************************
*****************************************************************************/
/* None */
 
/*****************************************************************************
******************************************************************************
* Private Debug stuff
******************************************************************************
*****************************************************************************/

⌨️ 快捷键说明

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