📄 tpu_pta.c
字号:
/*********************************************************************
*
* Copyright: MOTOROLA, INC. All Rights Reserved.
* You are hereby granted a copyright license to use, modify, and
* distribute the SOFTWARE so long as this entire notice is
* retained without alteration in any modified and/or redistributed
* versions, and that such modified versions are clearly identified
* as such. No licenses are granted by implication, estoppel or
* otherwise under any patents or trademarks of Motorola, Inc. This
* software is provided on an "AS IS" basis and without warranty.
*
* To the maximum extent permitted by applicable law, MOTOROLA
* DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED, INCLUDING
* IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
* PURPOSE AND ANY WARRANTY AGAINST INFRINGEMENT WITH REGARD TO THE
* SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF) AND ANY
* ACCOMPANYING WRITTEN MATERIALS.
*
* To the maximum extent permitted by applicable law, IN NO EVENT
* SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER (INCLUDING
* WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS
* INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY
* LOSS) ARISING OF THE USE OR INABILITY TO USE THE SOFTWARE.
*
* Motorola assumes no responsibility for the maintenance and support
* of this software
********************************************************************/
/**************************************************************************/
/* FILE NAME: tpu_pta.c COPYRIGHT (c) MOTOROLA 2002 */
/* VERSION: 1.1 All Rights Reserved */
/* */
/* DESCRIPTION: This file contains the TPU PTA functions. These functions */
/* allow you to completely control TPU channels running the PTA function. */
/* They provide a simple interface requiring the minimum amount of */
/* configuration by the user. */
/*========================================================================*/
/* HISTORY ORIGINAL AUTHOR: Stan Ostrum */
/* */
/* REV AUTHOR DATE DESCRIPTION OF CHANGE */
/* --- ----------- --------- --------------------- */
/* 1.0 Stan Ostrum 03 Sep 02 Initial version of function. */
/* 1.1 Stan Ostrum 18 Sep 02 Revised after review. */
/**************************************************************************/
#include "tpu_pta.h"
#include "mpc500_util.h"
/*******************************************************************************
FUNCTION : tpu_pta_init
PURPOSE : To initialize a TPU channel to run the PTA function.
INPUT NOTES : This function has 6 parameters:
*tpu : This is a pointer to the TPU3 module to use. It is
of type TPU3_tag which is defined in m_tpu3.h
channel : This is the channel number of the PTA function.
priority : This is the priority to assign to the PTA channel.
This parameter should be assigned a value of:
TPU_PRIORITY_HIGH, TPU_PRIORITY_MIDDLE or
TPU_PRIORITY_LOW.
timebase : This is the TPU timebase to use for measurement.
This parameter should be assigned a value of:
TPU_PTA_TCR1 or TPU_PTA_TCR2.
mode : This is the PTA measurement mode.
This parameter should be assigned a value of:
TPU_PTA_HIGH_TIME_ACCUM, TPU_PTA_LOW_TIME_ACCUM,
TPU_PTA_PERIOD_ACCUM_RISE, or TPU_PTA_PERIOD_ACCUM_FALL
max_count: This is the number of pulses or periods to accumulate
before the measurement restarts. Range is 0 to 255.
RETURN NOTES : none
WARNING : The channel must be stopped before it is reconfigured. The
function disables the channel but if it was currently
being serviced it would continue. The delay for assigning the
pram pointer may to enough, but depends on system loading.
*******************************************************************************/
void tpu_pta_init(struct TPU3_tag *tpu, UINT8 channel, UINT8 priority, \
UINT8 timebase, UINT8 mode, UINT8 max_count)
{
UINT16 channel_control;
/* disable channel so it can be configured safely */
tpu_disable( tpu, channel);
/* select PTA function */
tpu_func( tpu, channel, TPU_FUNCTION_PTA);
/* initialize parameter RAM */
/* - initialize CHAN_CNTL and MAX_COUNT to their desired values */
/* - initialize PER_CNT, ACCUM, HIGH_WORD, and LOW_WORD to 0 */
/* setup channel control word for desired measurement mode & TCR1 timebase */
switch (mode)
{
case 0: TPU_PTA_HIGH_TIME_ACCUM;
case 1: TPU_PTA_LOW_TIME_ACCUM;
channel_control = TPU_PTA_HI_LOW_PW;
break;
case 2: TPU_PTA_PERIOD_ACCUM_RISE;
channel_control = TPU_PTA_PERIOD_RISING;
break;
case 3: TPU_PTA_PERIOD_ACCUM_FALL;
channel_control = TPU_PTA_PERIOD_FALLING;
break;
}
/* set bit in channel control word for TCR2 operation */
if (timebase == TPU_PTA_TCR2)
channel_control = channel_control | 0x20;
tpu->PARM.R[channel][TPU_PTA_CHAN_CNTL] = channel_control;
tpu->PARM.R[channel][TPU_PTA_MAX_CNT_PRD_CNT] = (INT16) (max_count << 8);
tpu->PARM.R[channel][TPU_PTA_LAST_TIME] = 0;
tpu->PARM.R[channel][TPU_PTA_ACCUM] = 0;
tpu->PARM.R[channel][TPU_PTA_HIGH_WORD] = 0;
tpu->PARM.R[channel][TPU_PTA_LOW_WORD] = 0;
/* configure the channel measurement mode */
tpu_hsq(tpu, channel, mode);
/* initialize channel */
tpu_hsr(tpu, channel, TPU_PTA_INIT);
/* enable channel by assigning a priority */
tpu_enable(tpu, channel, priority);
}
/*******************************************************************************
FUNCTION : tpu_pta_get_accumulation
PURPOSE : This function returns the current value of the accumulation.
INPUT NOTES : This function has 2 parameters:
*tpu : This is a pointer to the TPU3 module to use. It is
of type TPU3_tag which is defined in m_tpu3.h
channel : This is the channel number of the PTA function.
RETURN NOTES : The current value of the 32-bit accumulation.
*******************************************************************************/
UINT32 tpu_pta_get_accumulation(struct TPU3_tag *tpu, UINT8 channel)
{
UINT16 high;
UINT16 low;
high = (tpu->PARM.R[channel][TPU_PTA_HIGH_WORD]);
low = (tpu->PARM.R[channel][TPU_PTA_LOW_WORD]);
/* clear accumulation high word for next measurement */
tpu->PARM.R[channel][TPU_PTA_HIGH_WORD] = 0;
return ((UINT32) (high << 16) | low);
}
/*******************************************************************************
FUNCTION : tpu_pta_get_period_count
PURPOSE : This function returns the current period count.
INPUT NOTES : This function has 2 parameters:
*tpu : This is a pointer to the TPU3 module to use. It is
of type TPU3_tag which is defined in m_tpu3.h
channel : This is the channel number of the PTA function.
RETURN NOTES : The current period count.
*******************************************************************************/
UINT8 tpu_pta_get_period_count(struct TPU3_tag *tpu, UINT8 channel)
{
return (UINT8) ((tpu->PARM.R[channel][TPU_PTA_MAX_CNT_PRD_CNT]) & 0x0F);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -