📄 tpu_fqm.c
字号:
/**************************************************************************/
/* FILE NAME: tpu_fqm.c COPYRIGHT (c) MOTOROLA 2002 */
/* VERSION: 1.0 All Rights Reserved */
/* */
/* DESCRIPTION: This file shows how to use the standard set-up and header */
/* files for the MPC565. This program sets up the MPC565 TPU */
/* initializations for the Frequency Meassure Function. */
/* This program uses the fixed structure feature of the header files. */
/*========================================================================*/
/* COMPILER: Diab Data VERSION: 4.3g */
/* AUTHOR: Randy Dees */
/* */
/* HISTORY */
/* REV AUTHOR DATE DESCRIPTION OF CHANGE */
/* --- ----------- --------- --------------------- */
/* 1.0 R. Dees 15/Sept/02 Initial version of function. */
/**************************************************************************/
#include "tpu_fqm.h"
#include "mpc500_util.h"
#include "m_usiu.h" /* Included for the interrupt function */
/*************************************************************/
/* Begin TPU Initialization */
/*************************************************************/
/*******************************************************************************
FUNCTION : tpu_fqm_init
PURPOSE : To initialize channels to run the FQM Frequency Measure function.
This function initializes the FQM function and sets the
initialization mode. To change the operating mode, this function
can be called again.
INPUTS NOTES : This function has 7 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 that has the FQM function
assigned to it.
priority - This is the priority to assign to the FQM function.
The TPU priority definitions are defined in mpc500_utils.h.
This parameter should be assigned a value of:
TPU_PRIORITY_HIGH, TPU_PRIORITY_MIDDLE or TPU_PRIORITY_LOW
mode - Continuous or single-shot
edge - Rising or falling edge
timer - use TCR1 or TCR2
wind_sz - the size of the sample window
RETURNS NOTES : none
WARNING : The channels must be stopped before it is reconfigured. The
function disables the channels but if they were currently
being serviced it would continue. The delay for assigning the
pram pointer may to enough but depends on system loading.
*******************************************************************************/
void tpu_fqm_init(struct TPU3_tag *tpu, UINT8 channel, UINT8 priority,
UINT8 mode, UINT8 edge, UINT8 timer, UINT16 wind_sz)
{
UINT16 channel_control;
UINT16 pac;
UINT16 tbs;
UINT8 hsq;
/* disable channels so they can be configured safely */
tpu_disable( tpu, channel);
/* FQM is function 0xC */
tpu_func( tpu, channel, TPU_FUNCTION_FQM);
/* disable interupts on channels so they can be configured safely */
tpu_interrupt_disable( tpu, channel );
/* mask off illegal values */
mode = ( mode & TPU_FQM_MODE_MASK );
edge = edge & TPU_FQM_PAC_MASK;
pac = edge << 2;
tbs = ( timer & TPU_FQM_TBS_MASK ) << 6;
/* Initialize Parameter RAM */
channel_control = ( tbs | pac | TPU_FQM_PSC );
tpu->PARM.R[channel][TPU_FQM_CHANEL_CONTROL] = channel_control;
tpu->PARM.R[channel][TPU_FQM_WINDOW_SIZE] = wind_sz;
/**************************************************/
/* Configure the Channels. */
/**************************************************/
if ((edge == TPU_FQM_FALL ) && (mode == TPU_FQM_SINGLE)) {
hsq = TPU_FQM_FALL_EDGE_SING;
}
else if ((edge == TPU_FQM_FALL) && (mode == TPU_FQM_CONT)){
hsq = TPU_FQM_FALL_EDGE_CONT;
}
else if ((edge == TPU_FQM_FALL) && (mode == TPU_FQM_SINGLE)){
hsq = TPU_FQM_RISE_EDGE_SING;
}
else hsq = TPU_FQM_RISE_EDGE_CONT;
tpu_hsq(tpu, channel, hsq);
tpu_hsr(tpu, channel, TPU_FQM_INIT);
/* Enable channel by assigning a priority to them. */
tpu_enable(tpu, channel, priority);
} /* End tpu_fqm_init */
/*******************************************************************************
FUNCTION : tpu_fqm__update_window
PURPOSE : To change the size of the sample window.
INPUTS NOTES : This function has 3 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 number of the master channel
wind_sz - This is the new desired sample window size (in TCR clocks).
*******************************************************************************/
void tpu_fqm_update_window_size(struct TPU3_tag *tpu,
UINT8 channel, UINT16 wind_sz)
{
tpu->PARM.R[channel][TPU_FQM_WINDOW_SIZE] = wind_sz;
} /* End tpu_fqm_update_window */
/*******************************************************************************
FUNCTION : tpu_fqm_get_pulse
PURPOSE : Returns the frequency of the signal on channel.
INPUTS 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 number of the master channel
position - .
OUTPUT NOTES : This function returns a a UINT16 value
*******************************************************************************/
UINT16 tpu_fqm_get_pulse(struct TPU3_tag *tpu, UINT8 channel)
{
UINT16 pulse;
tpu_ready(tpu, channel);
pulse = tpu->PARM.R[channel][TPU_FQM_PULSE_COUNT];
return (pulse);
} /* End tpu_fqm_get_pulse */
/*********************************************************************
*
* 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
********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -