📄 tpu_fqd.c
字号:
/**************************************************************************/
/* FILE NAME: tpu_fqd.c COPYRIGHT (c) MOTOROLA 2002 */
/* VERSION: 1.0 All Rights Reserved */
/* */
/* DESCRIPTION: This file contains the TPU FQD functions. These functions */
/* allow you to completely control TPU channels running the FQD function. */
/* They provide a simple interface requiring the minimum amount of */
/* configuration by the user. */
/*========================================================================*/
/* HISTORY ORIGINAL AUTHOR: Jeff Loeliger */
/* REV AUTHOR DATE DESCRIPTION OF CHANGE */
/* --- ----------- --------- --------------------- */
/* 1.0 J. Loeliger 03/Aug/02 Initial version of function. */
/**************************************************************************/
#include "tpu_fqd.h"
#include "mpc500_util.h"
/*******************************************************************************
FUNCTION : tpu_fqd_init
PURPOSE : To initialize a pair of channels to run the FQD function.
INPUTS NOTES : This function has 4 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 primary FQD
channel. The next channel is used as the secondary.
priority - This is the priority to assign to both channels.
This parameter should be assigned a value of:
TPU_PRIORITY_HIGH, TPU_PRIORITY_MIDDLE or
TPU_PRIORITY_LOW.
init_position - This is the starting position.
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_fqd_init(struct TPU3_tag *tpu, UINT8 channel, UINT8 priority, \
INT16 init_position)
{
struct TPU_param_tag *pram;
UINT8 channel2;
/* if primary channel is 15 then secondary channel should be 0 */
channel2 = (channel + 1) & 0xF;
/* diable channels so they can be configured safely */
tpu_disable( tpu, channel);
tpu_disable( tpu, channel2);
/* select FQD function for both channels */
tpu_func( tpu, channel, TPU_FUNCTION_FQD);
tpu_func( tpu, channel2, TPU_FUNCTION_FQD);
/* Initialize parameter RAM */
/* -setup initial count in POSITION_COUNT */
/* -initialize CORR_PINSTATE_ADDR and EDGE_TIME_LSB_ADDR in both channels*/
tpu->PARM.R[channel][TPU_FQD_POSITION_COUNT] = init_position;
tpu->PARM.R[channel][TPU_FQD_CORR_PINSTATE_ADDR] = (INT16) (((channel2) << 4) + 6);
tpu->PARM.R[channel][TPU_FQD_EDGE_TIME_LSB_ADDR] = (INT16) ((channel << 4) + 1);
tpu->PARM.R[channel2][TPU_FQD_CORR_PINSTATE_ADDR] = (INT16) ((channel << 4) + 6);
tpu->PARM.R[channel2][TPU_FQD_EDGE_TIME_LSB_ADDR] = (INT16) ((channel << 4) + 1);
/* Configure the first channel as the primary channel and the following */
/* channel as the secondary channel. */
tpu_hsq(tpu, channel, TPU_FQD_PRIMARY_CHANNEL | TPU_FQD_NORMAL_MODE);
tpu_hsq(tpu, channel2, TPU_FQD_SECONDARY_CHANNEL | TPU_FQD_NORMAL_MODE);
/* Initialize both channels */
tpu_hsr(tpu, channel, TPU_FQD_INIT);
tpu_hsr(tpu, channel2, TPU_FQD_INIT);
/* Enable channels by assigning a priority to them. */
/* Both channels MUST have the same priority. */
tpu_enable(tpu, channel, priority);
tpu_enable(tpu, channel2, priority);
}
/*******************************************************************************
FUNCTION : tpu_fqd_init_trans_count
PURPOSE : To initialize one channel as a discrete input/transition
counter.
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 channel number of the primary FQD
channel. The next channel is used as the secondary.
priority - This is the priority to assign to both channels
This parameter should be assigned a value of:
TPU_PRIORITY_HIGH, TPU_PRIORITY_MIDDLE or
TPU_PRIORITY_LOW.
RETURNS NOTES : none
WARNING : The channel must be stopped before it is reconfigured. The
function disables the channel but if it is currently
being serviced it would continue. The delay for assigning the
pram pointer may to enough but depends on system loading.
*******************************************************************************/
void tpu_fqd_init_trans_count(struct TPU3_tag *tpu, UINT8 channel, \
UINT8 priority)
{
struct TPU_param_tag *pram;
/* diable channel so it can be configured safely */
tpu_disable( tpu, channel);
/* select FQD function for both channels */
tpu_func( tpu, channel, TPU_FUNCTION_FQD);
/* Initialize parameter RAM */
/* -clear POSITION_COUNT to count transitions */
/* -initialize CORR_PINSTATE_ADDR and EDGE_TIME_LSB_ADDR */
tpu->PARM.R[channel][TPU_FQD_POSITION_COUNT] = 0;
tpu->PARM.R[channel][TPU_FQD_CORR_PINSTATE_ADDR] = (INT16) ((channel << 4) + 6);
tpu->PARM.R[channel][TPU_FQD_EDGE_TIME_LSB_ADDR] = (INT16) ((channel << 4) + 1);
/* Configure the channel as a primary channel */
tpu_hsq(tpu, channel, TPU_FQD_PRIMARY_CHANNEL | TPU_FQD_NORMAL_MODE);
/* Initialize the channel */
tpu_hsr(tpu, channel, TPU_FQD_INIT);
/* Enable the channel by assigning a priority to it. */
tpu_enable(tpu, channel, priority);
}
/*******************************************************************************
FUNCTION : tpu_fqd_mode
PURPOSE : To change between fast and normal modes.
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 channel number of the primary FQD
channel. The next channel is used as the secondary.
mode - The defines which mode to use, the value should be:
TPU_FQD_NORMAL_MODE or TPU_FQD_FAST_MODE.
RETURNS NOTES : none
*******************************************************************************/
void tpu_fqd_mode(struct TPU3_tag *tpu, UINT8 channel, UINT8 mode )
{
tpu_hsq(tpu, channel, TPU_FQD_PRIMARY_CHANNEL | mode);
}
/*******************************************************************************
FUNCTION : tpu_fqd_current_mode
PURPOSE : To determine the current operating mode of the FQD function.
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 channel number of the primary FQD
channel. The next channel is used as the secondary.
RETURNS NOTES : The operating mode which will be TPU_FQD_NORMAL_MODE or
TPU_FQD_FAST_MODE.
*******************************************************************************/
UINT8 tpu_fqd_current_mode(struct TPU3_tag *tpu, UINT8 channel)
{
return(tpu_get_hsq(tpu, channel));
}
/*******************************************************************************
FUNCTION : tpu_fqd_position
PURPOSE : This function returns the current postion count for the
quqdrature input signal.
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 channel number of the primary FQD
channel. The next channel is used as the secondary.
RETURNS NOTES : The current position count.
*******************************************************************************/
INT16 tpu_fqd_position(struct TPU3_tag *tpu, UINT8 channel)
{
return (tpu->PARM.R[channel][TPU_FQD_POSITION_COUNT]);
}
/*******************************************************************************
FUNCTION : tpu_fqd_data
PURPOSE : To get the current TCR1 value and the time of the last edge.
INPUTS 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 primary FQD
channel. The next channel is used as the secondary.
*tcr1 - The current Value of the TCR1 timebase.
*edge - The last edge time.
*primary_pin - The current state of the primary channel, this
will be TPU_FQD_PIN_HIGH or TPU_FQD_PIN_LOW.
*secondary_pin - The current state of the primary channel, this
will be TPU_FQD_PIN_HIGH or TPU_FQD_PIN_LOW.
RETURNS NOTES : none
**WARNING** : If the channel is disabled or the TPU is not responding this
function will NEVER EXIT!
*******************************************************************************/
void tpu_fqd_data(struct TPU3_tag *tpu, UINT8 channel, INT16 *tcr1, \
INT16 *edge, INT16 *primary_pin, INT16 *secondary_pin)
{
UINT8 channel2;
/* if primary channel is 15 then secondary channel should be 0 */
channel2 = (channel + 1) & 0xF;
/* wait until the TPU channel has no pending HSRs */
/* WARNING if the TPU does on service this request then this loop will */
/* NEVER EXIT! */
tpu_ready(tpu, channel);
/* issue request to update TCR1 value */
tpu_hsr(tpu, channel, TPU_FQD_READ_TCR1);
/* read parameters */
*edge = tpu->PARM.R[channel][TPU_FQD_EDGE_TIME];
*primary_pin=tpu->PARM.R[channel][TPU_FQD_CHAN_PINSTATE];
*secondary_pin=tpu->PARM.R[channel2][TPU_FQD_CHAN_PINSTATE];
/* wait until TCR1 value has been updated */
/* WARNING if the TPU does on service this request then this loop will */
/* NEVER EXIT! */
tpu_ready(tpu, channel);
*tcr1 = tpu->PARM.R[channel][TPU_FQD_TCR1_VALUE];
}
/*********************************************************************
*
* 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 + -