打印
[demo程序]

NV32F100x 库文件etm.c中文注释

[复制链接]
948|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jp_chen|  楼主 | 2017-7-26 16:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

/******************************************************************************
* [url=home.php?mod=space&uid=247401]@brief[/url] providing APIs for configuring ETM.
*
*******************************************************************************
*
* provide APIs for configuring ETM
******************************************************************************/
#include "common.h"
#include "ETM.h"

/******************************************************************************
* Global variables
******************************************************************************/

/******************************************************************************
* Constants and macros
******************************************************************************/

/******************************************************************************
* Local types
******************************************************************************/

/******************************************************************************
* Local function prototypes
******************************************************************************/

/******************************************************************************
* Local variables
******************************************************************************/

/******************************************************************************
* Local functions
******************************************************************************/

/******************************************************************************
* Global functions
******************************************************************************/
ETM_CallbackPtr ETM_Callback[3] = {(ETM_CallbackPtr)NULL};


/******************************************************************************
* ETM api lists
*
*//*! @addtogroup ETM_api_list
* @{
*******************************************************************************/
/*******************************************************************************//*!
*
* @设置时钟资源及分频系数   
* @输入     pETM                 指向三个ETM定时器其中一个的基址
* @输入     ClockSource           ETM 时钟资源
* @输入     ClockPrescale          分频系数
*
* [url=home.php?mod=space&uid=266161]@return[/url] none.  无返回
*
*********************************************************************************/


void ETM_ClockSet(ETM_Type *pETM, uint8_t u8ClockSource, uint8_t u8ClockPrescale)
{
uint8_t   u8Temp;
   //pETM指向的SC寄存器低5位清0,即未选择时钟,时钟输入采取1分频
  u8Temp  = (pETM->SC & 0xE0);
   //时钟选择,及预分频因子选择
   u8Temp |= (ETM_SC_CLKS(u8ClockSource & 0x3) | ETM_SC_PS(u8ClockPrescale & 0x7));
//配置该ETM的状态与控制寄存器ETMx_SC
   pETM->SC = u8Temp;
}

/*********************************************************************************//*!
* @ETM中TOF频率大小的设置功能函数
*        
* @输入    pETM              指向三个ETM定时器其中一个的基址
* @输入    u8TOFNUM         TOF频率数,大小0和31之间
*
* @无返回
*
*********************************************************************************/
void ETM_SetTOFFrequency(ETM_Type *pETM, uint8_t u8TOFNUM)
{
    ASSERT((ETM2 == pETM));
    pETM->CONF &= ~ETM_CONF_NUMTOF_MASK;
    pETM->CONF |= ETM_CONF_NUMTOF(u8TOFNUM);
}

/******************************************************************************************
* @ETM中PWM的初始化函数      
* @输入        pETM                 指向三个ETM定时器其中一个的基址
* @输入        PWMModeSelect       居中对齐CPWM(10)、边沿对齐EPWM(01)以及级联模式PWM(11)
* @输入        PWMEdgeSelect        边沿选择
*
* @无返回
*
******************************************************************************************/
void ETM_PWMInit(ETM_Type *pETM, uint8_t u8PWMModeSelect, uint8_t u8PWMEdgeSelect)
{
    uint8_t  channels, i;
    ASSERT((ETM0== pETM) || (ETM1== pETM) || (ETM2== pETM)); //断言来检测ETM是否正确
    /* open the clock gate */
        if (ETM0 == pETM)
    {
        channels = 2;
        SIM->SCGC |= SIM_SCGC_ETM0_MASK;
    }
    else if(ETM1 == pETM)
    {
        channels = 2;
    }        
    else
    {
        channels = 6;
        SIM->SCGC  |= SIM_SCGC_ETM2_MASK;
    }
    pETM->SC  = 0x0;                                    /* 关闭计数器 */  
        pETM->MOD = ETM_MOD_INIT;
    if(ETM_PWMMODE_CENTERALLIGNED == u8PWMModeSelect)   /*打开CPWM*/
    {
        pETM->SC |= ETM_SC_CPWMS_MASK;
    }
    else if(ETM_PWMMODE_COMBINE == u8PWMModeSelect)     /* 打开级联PWM模式 */
    {
        ASSERT(ETM2 == pETM);
      pETM->MODE|= ETM_MODE_WPDIS_MASK | ETM_MODE_ETMEN_MASK;
                        pETM->COMBINE = ETM_COMBINE_COMBINE0_MASK | ETM_COMBINE_COMP0_MASK | ETM_COMBINE_SYNCEN0_MASK | ETM_COMBINE_DTEN0_MASK |
                        ETM_COMBINE_COMBINE1_MASK | ETM_COMBINE_COMP1_MASK | ETM_COMBINE_SYNCEN1_MASK | ETM_COMBINE_DTEN1_MASK |
                        ETM_COMBINE_COMBINE2_MASK | ETM_COMBINE_COMP2_MASK | ETM_COMBINE_SYNCEN2_MASK | ETM_COMBINE_DTEN2_MASK
                        ;     
      pETM->SC &= ~ETM_SC_CPWMS_MASK;
    }
    if(ETM_PWM_HIGHTRUEPULSE == u8PWMEdgeSelect)
    {
        /* 配置ETMers 寄存器 */
        for(i=0; i<channels; i++)
        {
            pETM->CONTROLS[i].CnSC = ETM_CnSC_MSB_MASK | ETM_CnSC_ELSB_MASK;  
            pETM->CONTROLS[i].CnV  = ETM_C0V_INIT + i*100;
        }
    }
    else if(ETM_PWM_LOWTRUEPULSE == u8PWMEdgeSelect)
    {
        for(i=0; i<channels; i++)
        {
            pETM->CONTROLS[i].CnSC = ETM_CnSC_MSB_MASK | ETM_CnSC_ELSA_MASK;
            pETM->CONTROLS[i].CnV  = ETM_C0V_INIT + i*100 ;
        }
    }  
}

/*********************************************************************************
*
* @设置通道输出极性的功能函数
*        
* @输入     pETM                 指向三个ETM定时器其中一个的基址
* @输入     Channel                PWM波的通道选择
* @输入     ActiveValue             极性的选择,0为高电平,1为低电平
*
* @无返回
*
*********************************************************************************/
void ETM_PolaritySet(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8ActiveValue)
{
    ASSERT((ETM2 == pETM) && (u8ETM_Channel < 6));
   
    if(ETM_POLARITY_HIGHACTIVE == u8ActiveValue)
    {
        pETM->POL &=  ~(1 << u8ETM_Channel);
    }
    else if(ETM_POLARITY_LOWACTIVE == u8ActiveValue)
    {
        pETM->POL |=  (1 << u8ETM_Channel);
    }
}

/*****************************************************************************//*!
*
*        必须设置奇数通道数,且偶数通道的值不变
*
* @输入        pETM            指向三个ETM定时器其中一个的基址
* @输入        ETM_Channel     奇通道数:1、3、5
* @输入        dutyCycle         设置占空比,若DutyCycle为10,那么占空比就为10%
*
* @return none.
*
* [url=home.php?mod=space&uid=72445]@[/url] Pass/ Fail criteria: none.
*
*****************************************************************************/
void  ETM_SetDutyCycleCombine(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8DutyCycle)
{
    uint16_t   cnv = pETM->CONTROLS[u8ETM_Channel-1].CnV;
    uint16_t   modulo = pETM->MOD;
   
    ASSERT((1 == u8ETM_Channel) || (3 == u8ETM_Channel) || (5 == u8ETM_Channel));
   
    cnv += (u8DutyCycle * (modulo+1))  / 100;
    if(cnv > modulo)
    {
        cnv = modulo - 1;
    }
    pETM->CONTROLS[u8ETM_Channel].CnV = cnv ;   
   
pETM->PWMLOAD |= ETM_PWMLOAD_LDOK_MASK | (1<<u8ETM_Channel);     
}


/*********************************************************************************
*
* @输入捕捉初始化函数
*        
* @输入        pETM                  指向三个ETM定时器其中一个的基址
* @输入        Channel                配置通道号
* @输入        CaptureMode           选择捕捉方式:上升沿, 下降沿或跳变沿.
*
* @无返回
*
*********************************************************************************/
void ETM_InputCaptureInit(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8CaptureMode)
{
    ASSERT(((ETM0 == pETM) && (u8ETM_Channel < 2)) || ((ETM1 == pETM) && (u8ETM_Channel < 2)) || ((ETM2 == pETM) && (u8ETM_Channel < 6)));
    /* open the clock gate */
        if ((ETM0 == pETM) && (u8ETM_Channel < 2))
    {
        SIM->SCGC |= SIM_SCGC_ETM0_MASK;
        NVIC_EnableIRQ(ETM0_IRQn);
    }
    else if((ETM1 == pETM)  && (u8ETM_Channel < 2))
    {
    }        
    else
    {
        SIM->SCGC |= SIM_SCGC_ETM2_MASK;
        NVIC_EnableIRQ(ETM2_IRQn);
    }
    pETM->SC  = 0x0;     //关闭计数器/
    pETM->MOD = 0xFFFF;  
    if(ETM_INPUTCAPTURE_RISINGEDGE == u8CaptureMode)  //开启中断,捕获上升沿
    {
        pETM->CONTROLS[u8ETM_Channel].CnSC = ETM_CnSC_CHIE_MASK | ETM_CnSC_ELSA_MASK;
    }
    else if(ETM_INPUTCAPTURE_FALLINGEDGE == u8CaptureMode)  //捕获下降沿
    {
        pETM->CONTROLS[u8ETM_Channel].CnSC = ETM_CnSC_CHIE_MASK | ETM_CnSC_ELSB_MASK;
    }
    else if(ETM_INPUTCAPTURE_BOTHEDGE == u8CaptureMode)     //接受跳变沿
    {
        pETM->CONTROLS[u8ETM_Channel].CnSC = ETM_CnSC_CHIE_MASK | ETM_CnSC_ELSA_MASK | ETM_CnSC_ELSB_MASK;      
    }
}

/*********************************************************************************//*!
*
* @对ETM_No t配置双边捕获模式来测量一个脉冲的宽度或周期
*        
* @输入        pETM                指向三个ETM定时器其中一个的基址
* @输入        ChannelPair           频道配对数的配置为: 0, 2, 4.
* @输入        CaptureMode           select capture edge: one shot and continuous mode.
* @输入        Channel_N_Edge        频道N边沿检测
* @输入        Channel_Np1_Edge      频道N+1边沿检测.
*
* @无返回
*
*********************************************************************************/
void ETM_DualEdgeCaptureInit(ETM_Type *pETM, uint8_t u8ChannelPair, uint8_t u8CaptureMode,
                                 uint8_t u8Channel_N_Edge, uint8_t u8Channel_Np1_Edge)
{
    ASSERT((ETM2 == pETM)  && (u8ChannelPair < 6) && !(u8ChannelPair & 1) );
   
    SIM->SCGC |= SIM_SCGC_ETM2_MASK;
    if((0 == u8ChannelPair) || (2== u8ChannelPair))
    {
                                        /* channel filter is active */
    }
      
    pETM->SC    = 0x0;                  /* diable counter */
    pETM->MOD   = 0xFFFF;
    pETM->MODE |= ETM_MODE_ETMEN_MASK;  /* ETMEN = 1 */  
    /* DECAPEN = 1,  ChannelPair/2 * 8 */
    pETM->COMBINE |=  ((ETM_COMBINE_DECAPEN0_MASK) << (u8ChannelPair * 4));
   
    pETM->CONTROLS[u8ChannelPair].CnSC &= ~ETM_CnSC_CHF_MASK;       /* CH(n)F and CH(n+1)F bits must be cleared first */
    pETM->CONTROLS[u8ChannelPair + 1].CnSC &= ~ETM_CnSC_CHF_MASK;
   
    if(ETM_INPUTCAPTURE_DUALEDGE_ONESHOT == u8CaptureMode)          /* oneshot mode */
    {
        pETM->CONTROLS[u8ChannelPair].CnSC &= ~ETM_CnSC_MSA_MASK;
        pETM->CONTROLS[u8ChannelPair+1].CnSC &= ~ETM_CnSC_MSA_MASK;
    }
    else if(ETM_INPUTCAPTURE_DUALEDGE_CONTINUOUS == u8CaptureMode)  /* continuouse mode */
    {
        pETM->CONTROLS[u8ChannelPair].CnSC |= ETM_CnSC_MSA_MASK;
        pETM->CONTROLS[u8ChannelPair+1].CnSC |= ETM_CnSC_MSA_MASK;
    }
   
    pETM->CONTROLS[u8ChannelPair].CnSC |= (u8Channel_N_Edge << 2);   /* select detec edge */
    pETM->CONTROLS[u8ChannelPair + 1].CnSC |= (u8Channel_Np1_Edge << 2);   
   
    pETM->COMBINE |=  (ETM_COMBINE_DECAP0_MASK << (u8ChannelPair * 4));
}

相关帖子

沙发
jp_chen|  楼主 | 2017-7-26 16:42 | 只看该作者
/*********************************************************************************//*!
*
* @用ETM完成捕捉
*
* @ 输入 pETM 指向三个ETM定时器其中一个的基址
* @输入 Channel 必须完成配置通道即通道号
* @ 输入 CompareMode 选择模式:翻转(01)、置位(11)、清0(10)
*
* @无返回
*
*********************************************************************************/
void ETM_OutputCompareInit(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8CompareMode)
{
ASSERT(((ETM0 == pETM) && (u8ETM_Channel < 2)) ||
((ETM1 == pETM) && (u8ETM_Channel < 2)) ||
((ETM2 == pETM) && (u8ETM_Channel < 6))
);
/* open the clock gate */
if(ETM0 == pETM)
{
SIM->SCGC |= SIM_SCGC_ETM0_MASK;
}
else if(ETM1 == pETM)
{
SIM->SCGC |= SIM_SCGC_ETM1_MASK;
}
else
{
SIM->SCGC |= SIM_SCGC_ETM2_MASK;
}
pETM->SC = 0x0; //关闭计数器
pETM->MOD = ETM_MOD_INIT;
pETM->CONTROLS[u8ETM_Channel].CnSC=(ETM_CnSC_MSA_MASK|(u8CompareMode<<2));
pETM->CONTROLS[u8ETM_Channel].CnV = ETM_C0V_INIT;
}

/*****************************************************************************
*
* @配置寄存器 ETMx_SYNCONF,其中里面包含了软件输出的控制是否由硬件触发HW或是否有软件出发SW
* @param[in] pETM 指向三个ETM定时器其中一个的基址
* @param[in] u32ConfigValue ETMx_SYNCONF这个寄存器的值
*
* @无返回
*
*****************************************************************************/
void ETM_SyncConfigDeactivate(ETM_Type *pETM, uint32_t u32ConfigValue)
{
ASSERT((ETM2 == pETM));
pETM->SYNCONF &= ~u32ConfigValue;
}


/*********************************************************************************
* @ETM中配置ETMx_SYNC 寄存器来保证软件同步
*
* @输入 pETM 指向三个ETM定时器其中一个的基址
* @输入 u8TriggerN 选择硬件触发资源
*
* @无返回
*
*********************************************************************************/
void ETM_HardwareSync(ETM_Type *pETM, uint8_t u8TriggerN)
{
ASSERT(ETM2 == pETM);

pETM->SYNCONF |= ETM_SYNCONF_SYNCMODE_MASK;

switch(u8TriggerN)
{
case ETM_SYNC_TRIGGER_TRIGGER2:
pETM->SYNC |= ETM_SYNC_TRIG2_MASK;
break;
case ETM_SYNC_TRIGGER_TRIGGER1:
pETM->SYNC |= ETM_SYNC_TRIG1_MASK;
break;
case ETM_SYNC_TRIGGER_TRIGGER0:
pETM->SYNC |= ETM_SYNC_TRIG0_MASK;
break;
default:
break;
}
}
/*********************************************************************************//*!
*
* @配置软件输出控制SWOCTRL寄存器的同步是否由软件触发
*
* @输入 pETM 指向三个ETM定时器其中一个的基址
* @输入 Channel PWM波的通道选择
* @输入 ChannelValue 0或1,0不触发;1触发
*
* @无返回
*
*********************************************************************************/
void ETM_SWOutputControlSet(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8ChannelValue)
{
ASSERT((ETM2 == pETM) && (u8ETM_Channel < 6));

if(ETM_SWOCTRL_HIGH == u8ChannelValue)
{
pETM->SWOCTRL |= (0x0101 << u8ETM_Channel);
}
else if(ETM_SWOCTRL_LOW == u8ChannelValue)
{
pETM->SWOCTRL |= (1 << u8ETM_Channel);
pETM->SWOCTRL &= ~(0x100 << u8ETM_Channel);
}
if(pETM->SYNCONF & ETM_SYNCONF_SWOC_MASK) /* if PWM sync is needed */
{
pETM->SYNCONF |= ETM_SYNCONF_SYNCMODE_MASK; /* recommend enhanced sync mode */
if(pETM->SYNCONF & ETM_SYNCONF_SWSOC_MASK) /* if software sync is needed*/
{
pETM->SYNC |= ETM_SYNC_SWSYNC_MASK; /* software sync */
}
else if(pETM->SYNCONF & ETM_SYNCONF_HWSOC_MASK) /* if hardware sync is needed*/
{
pETM->SYNC |= ETM_SYNC_TRIG2_MASK;

#if defined(CPU_NV32)
SIM->SOPT |= SIM_SOPT_ETMSYNC_MASK; /* hardware sync */
#elif defined(CPU_NV32M3)
SIM->SOPT |= SIM_SOPT_ETMSYNC_MASK; /* hardware sync */
#elif defined(CPU_NV32M4)
SIM->SOPT0 |= SIM_SOPT0_ETMSYNC_MASK; /* hardware sync */
#endif
}
}
else /* no need to sync, update on the next rising edge of system clock */
{
}
}



/*********************************************************************************//*!
*
* @通过配置ETM保证硬件同步,产生触发
*
* @输入 pETM 指向三个ETM定时器其中一个的基址
*@输入 u8TriggerMask 选择硬件触发资源. combine TRIG0~TREG2.(x000xxxx~x111xxxx)
*
* @无返回.
*
*********************************************************************************/
void ETM_HardwareSyncCombine(ETM_Type *pETM, uint8_t u8TriggerMask)
{
ASSERT(ETM2 == pETM);

pETM->SYNCONF |= ETM_SYNCONF_SYNCMODE_MASK;
pETM->SYNC &= 0x8F;
pETM->SYNC |= (u8TriggerMask & 0x70);
}

/*****************************************************************************//*!
*
* @ETM初始化函数
*
* @输入 pETM 指向三个ETM定时器其中一个的基址
* @输入 pConfig 指向ETM的一些基本参数
* @无返回值
*
*****************************************************************************/
void ETM_Init(ETM_Type *pETM, ETM_ConfigType *pConfig)
{
ASSERT((ETM0 == pETM) || (ETM1 == pETM) || (ETM2 == pETM));
if(ETM0 == pETM)
{
SIM->SCGC |= SIM_SCGC_ETM0_MASK;
}
else
{
SIM->SCGC |= SIM_SCGC_ETM2_MASK;
}

/* diable counter */
pETM->SC = 0;
pETM->MODE = pConfig->mode;
pETM->MOD = pConfig->modulo;
pETM->CNT = pConfig->cnt;

if( pETM->MODE & ETM_MODE_ETMEN_MASK )
{
/* when ETMEN = 1, all other registers can be written */
pETM->COMBINE = pConfig->combine;
pETM->CNTIN = pConfig->cntin;
pETM->SYNC = pConfig->sync;
pETM->OUTINIT = pConfig->outinit;
pETM->OUTMASK = pConfig->outmask;
pETM->DEADETME = pConfig->deadETMe;
pETM->EXTTRIG = pConfig->exttrig;
pETM->POL = pConfig->pol;
pETM->FMS = pConfig->fms;
pETM->FILTER = pConfig->filter;
pETM->FLTCTRL = pConfig->fltctrl;
pETM->FLTPOL = pConfig->fltpol;
pETM->CONF = pConfig->conf;
pETM->SYNCONF = pConfig->synconf;
pETM->SWOCTRL = pConfig->swoctrl;
pETM->PWMLOAD = pConfig->pwmload;
}
/* write SC to enable clock */
pETM->SC = pConfig->sc;
}

/*****************************************************************************
关闭相应的ETM功能组件函数
*****************************************************************************/
void ETM_DeInit(ETM_Type *pETM)
{
ASSERT((ETM0 == pETM) || (ETM1 == pETM) || (ETM2 == pETM));
pETM->SC = 0;
pETM->MOD = 0;
pETM->CNT = 0;
if(ETM2 == pETM)
{ pETM->MODE = 0x4;
pETM->COMBINE = 0;
pETM->CNTIN = 0;
pETM->SYNC = 0;
pETM->OUTINIT = 0;
pETM->OUTMASK = 0;
pETM->DEADETME = 0;
pETM->EXTTRIG = 0;
pETM->POL = 0;
pETM->FMS = 0;
pETM->FILTER = 0;
pETM->FLTCTRL = 0;
pETM->FLTPOL = 0;
pETM->CONF = 0;
pETM->SYNCONF = 0;
pETM->SWOCTRL = 0;
pETM->PWMLOAD = 0;
}
if (ETM0 == pETM)
{
SIM->SCGC &= ~SIM_SCGC_ETM0_MASK;
NVIC_DisableIRQ(ETM0_IRQn);
}
else if (ETM2 == pETM)
SIM->SCGC &= ~SIM_SCGC_ETM2_MASK;
NVIC_DisableIRQ(ETM2_IRQn);
}



/*********************************************************************************//*!
*
* @运用ETM2来实现软件同步
*
* @输入 pETM 指向三个ETM定时器其中一个的基址
*
* @无返回
*
*********************************************************************************/
void ETM_SoftwareSync(ETM_Type *pETM)
{
ASSERT(ETM2 == pETM);

pETM->SYNCONF |= ETM_SYNCONF_SYNCMODE_MASK;
pETM->SYNC |= ETM_SYNC_SWSYNC_MASK;
}

/**********************************************************************************
*
* @产生ETM2硬件触发,Note: please call ETM_HardwareSyncCombine first.
*
* @输入 pETM 指向三个ETM定时器其中一个的基址
*
* @无返回
*
*********************************************************************************/
void ETM_GenerateTrig2(ETM_Type *pETM)
{
ASSERT(ETM2 == pETM);

if(pETM->SYNC & ETM_SYNC_TRIG2_MASK)
{
#if defined(CPU_NV32)
SIM->SOPT |= SIM_SOPT_ETMSYNC_MASK;
#endif
}
}


/*********************************************************************************
*
* @选择BDM模式下的ETM行为
*
* @输入 pETM 指向三个ETM定时器其中一个的基址
* @输入 u8DebugMode debug 的模式从00-11之间选择
*
* @无返回
*
*********************************************************************************/
void ETM_SetDebugModeBehavior(ETM_Type *pETM, uint8_t u8DebugMode)
{
ASSERT((ETM2 == pETM));
pETM->CONF &= ~ETM_CONF_BDMMODE_MASK;
pETM->CONF |= ETM_CONF_BDMMODE(u8DebugMode);
}

/*********************************************************************************
* @交换通道CH(n)和通道CH(n+1)的输出结果
* @输入 pETM 其中一个ETM定时器的基址
* @输入 ChannelPair 要被交换的通道数号,即n可为0,1,2,
*********************************************************************************/
void ETM_InvertChannel(ETM_Type *pETM, uint8_t u8ChannelPair)
{
ASSERT((ETM2 == pETM) && u8ChannelPair <= 2);

pETM->INVCTRL |= 1<<u8ChannelPair;
if(pETM->SYNCONF & ETM_SYNCONF_INVC_MASK) /* if PWM sync is needed */
{
pETM->SYNCONF |= ETM_SYNCONF_SYNCMODE_MASK; /* recommend enhanced sync mode */
if(pETM->SYNCONF & ETM_SYNCONF_SWINVC_MASK) /* if software sync is needed*/
{
pETM->SYNC |= ETM_SYNC_SWSYNC_MASK; /* software sync */
}
else if(pETM->SYNCONF & ETM_SYNCONF_HWINVC_MASK) /* if hardware sync is needed*/
{
pETM->SYNC |= ETM_SYNC_TRIG2_MASK;

#if defined(CPU_NV32)
SIM->SOPT |= SIM_SOPT_ETMSYNC_MASK; /* hardware sync */
#endif
}
}
else
{
}
}


/*****************************************************************************//*!
*
* @本函数用来配置ETM通道, 包括通道状态及控制寄存器CnSC和通道计数值寄存器CnV
* @输入 pETM 指向三个ETM定时器其中一个的基址
* @输入 ETM_Channel ETM的通道号
* @输入 pTETMCH_Params 指向ETM通道一般参数的指针
*
* @无返回值
*
*****************************************************************************/
void ETM_ChannelInit(ETM_Type *pETM, uint8_t u8ETM_Channel, ETM_ChParamsType *pTETMCH_Params)
{
ASSERT((ETM0 == pETM) || (ETM1 == pETM) || (ETM2 == pETM)); //断言检测定时器号是否正确

if (ETM0 == pETM)
{
ASSERT(u8ETM_Channel < 2);
SIM->SCGC |= SIM_SCGC_ETM0_MASK;
}
else
{
ASSERT(u8ETM_Channel < 6);
SIM->SCGC |= SIM_SCGC_ETM2_MASK;
}

pETM->CONTROLS[u8ETM_Channel].CnSC = pTETMCH_Params->u8CnSC;
pETM->CONTROLS[u8ETM_Channel].CnV = pTETMCH_Params->u16CnV;

return;
}



/*****************************************************************************//*!
*
* @brief This function sets the callback function.
*
* @param[in] pETM pointer to one of three ETM base register address.
* @param[in] pfnCallback functon address.
*
* @return none.
*
* @ Pass/ Fail criteria: none
*
*****************************************************************************/
void ETM_SetCallback(ETM_Type *pETM, ETM_CallbackPtr pfnCallback)
{
ETM_Callback[((uint32_t)pETM - (uint32_t)ETM0_BASE)>>12] = pfnCallback;
}

/*! @} End of ETM_api_list */


/*****************************************************************************//*!
*
* @brief ETM0_Isr interrupt service routine.
*
* @param none.
*
* @return none.
*
* @ Pass/ Fail criteria: none.
*
*****************************************************************************/
void ETM0_Isr(void)
{
if(ETM_Callback[0])
{
ETM_Callback[0]();
}
}

/*****************************************************************************//*!
*
* @brief ETM1_Isr interrupt service routine.
*
* @param none.
*
* @return none.
*
* @ Pass/ Fail criteria: none.
*
*****************************************************************************/
void ETM1_Isr(void)
{
if(ETM_Callback[1])
{
ETM_Callback[1]();
}
}

/*****************************************************************************//*!
*
* @brief ETM2_Isr interrupt service routine.
*
* @param none.
*
* @return none.
*
* @ Pass/ Fail criteria: none.
*
*****************************************************************************/
void ETM2_Isr(void)
{
if(ETM_Callback[2])
{
ETM_Callback[2]();
}
}

使用特权

评论回复
板凳
没有六一了| | 2017-11-27 21:53 | 只看该作者
好长的程序,没有太看明白

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

20

主题

113

帖子

0

粉丝