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

📄 tpu_dio.c

📁 mpc564 时钟中断 时钟中断
💻 C
字号:
/**************************************************************************/
/* FILE NAME: tpu_dio.c                       COPYRIGHT (c) MOTOROLA 2002 */
/* VERSION: 1.0                                   All Rights Reserved     */
/*                                                                        */
/* DESCRIPTION: This file contains the TPU DIO functions. These functions */
/* allow you to completely control TPU channels running the DIO 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  19/Aug/02    Initial version of function.           */
/**************************************************************************/
#include "tpu_dio.h"
#include "mpc500_util.h"

/*******************************************************************************
FUNCTION      : tpu_dio_init_output
PURPOSE       : To initialize a channel to run the DIO function in output mode.
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 DIO
                           channel.
                 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.
                 level - This is the initial level of the pin.
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_dio_init_output(struct TPU3_tag *tpu, UINT8 channel, UINT8 priority,\
            UINT8 level)
{
    /* diable channel so it can be configured safely */
    tpu_disable( tpu, channel);
    
    /* select DIO function for channel */
    tpu_func( tpu, channel, TPU_FUNCTION_DIO);
    
    /* Initialize channel */
    if(level == TPU_DIO_PIN_HIGH)
        tpu_hsr(tpu, channel, TPU_DIO_FORCE_HIGH);
    else
        tpu_hsr(tpu, channel, TPU_DIO_FORCE_LOW);
    
    /* Enable channel by assigning a priority. */
    tpu_enable(tpu, channel, priority);
}

/*******************************************************************************
FUNCTION      : tpu_dio_output_high
PURPOSE       : To drive a channel running DIO to a high level.
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 DIO
                           channel.
RETURNS NOTES : none
*******************************************************************************/
void tpu_dio_output_high(struct TPU3_tag *tpu, UINT8 channel)
{
    tpu_hsr(tpu, channel, TPU_DIO_FORCE_HIGH);
}

/*******************************************************************************
FUNCTION      : tpu_dio_output_low
PURPOSE       : To drive a channel running DIO to a low level.
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 DIO
                           channel.
RETURNS NOTES : none
*******************************************************************************/
void tpu_dio_output_low(struct TPU3_tag *tpu, UINT8 channel)
{
    tpu_hsr(tpu, channel, TPU_DIO_FORCE_LOW);
}

/*******************************************************************************
FUNCTION      : tpu_dio_output
PURPOSE       : To drive a channel running DIO to a requested level.
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 DIO
                           channel.
                 level - This is the requested level of the pin.
RETURNS NOTES : none
*******************************************************************************/
void tpu_dio_output(struct TPU3_tag *tpu, UINT8 channel, UINT8 level)
{
    if(level == TPU_DIO_PIN_HIGH)
        tpu_hsr(tpu, channel, TPU_DIO_FORCE_HIGH);
    else
        tpu_hsr(tpu, channel, TPU_DIO_FORCE_LOW);
}

/*******************************************************************************
FUNCTION      : tpu_dio_init_input_trans
PURPOSE       : To initialize one channel for capture on input transisiton.
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 DIO channel. 
                 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.
                 mode - This defines the edge and TCR to use.
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_dio_init_input_trans(struct TPU3_tag *tpu, UINT8 channel, \
            UINT8 priority, UINT8 mode)
{
    struct TPU_param_tag *pram;

    /* diable channel so it can be configured safely */
    tpu_disable( tpu, channel);
    
    /* select DIO function for channel */
    tpu_func( tpu, channel, TPU_FUNCTION_DIO);
    
    /* Initialize parameter RAM channel control */
    tpu->PARM.R[channel][TPU_DIO_CHANNEL_CONTROL] = mode;

    /* Configure the channel for transition mode */
    tpu_hsq(tpu, channel, TPU_DIO_TRANS_MODE);
    
    /* Initialize the channel */
    tpu_hsr(tpu, channel, TPU_DIO_INIT);
    
    /* Enable the channel by assigning a priority to it. */
    tpu_enable(tpu, channel, priority);
}
    
/*******************************************************************************
FUNCTION      : tpu_dio_init_input_periodic
PURPOSE       : To initialize one channel as periodicly updated input
                counter.
INPUTS NOTES  : This function has 5 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 DIO channel. 
                 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.
                 tcr - This is the timebase to reference.
                 rate - This is the periodic update rate.
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_dio_init_input_periodic(struct TPU3_tag *tpu, UINT8 channel, \
            UINT8 priority, UINT8 tcr, UINT16 rate)
{
    struct TPU_param_tag *pram;

    /* diable channel so it can be configured safely */
    tpu_disable( tpu, channel);
    
    /* select DIO function for channel */
    tpu_func( tpu, channel, TPU_FUNCTION_DIO);
    
    /* Initialize parameter RAM channel control */
    tpu->PARM.R[channel][TPU_DIO_CHANNEL_CONTROL] = tcr;

    /* Initialize parameter RAM with update rate */
    tpu->PARM.R[channel][TPU_DIO_MATCH_RATE] = rate;
    
    /* Configure the channel for match mode */
    tpu_hsq(tpu, channel, TPU_DIO_MATCH_MODE);
    
    /* Initialize the channel */
    tpu_hsr(tpu, channel, TPU_DIO_INIT);
    
    /* Enable the channel by assigning a priority to it. */
    tpu_enable(tpu, channel, priority);
}
    
/*******************************************************************************
FUNCTION      : tpu_dio_init_input_immed
PURPOSE       : To initialize one channel as periodicly updated input
                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 DIO channel. 
                 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_dio_init_input_immed(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 DIO function for channel */
    tpu_func( tpu, channel, TPU_FUNCTION_DIO);
    
    /* Initialize parameter RAM channel control */
    tpu->PARM.R[channel][TPU_DIO_CHANNEL_CONTROL] = 0x3;

    /* Configure the channel for transition mode and use HSR later*/
    tpu_hsq(tpu, channel, TPU_DIO_TRANS_MODE);
    
    /* Initialize the channel */
    tpu_hsr(tpu, channel, TPU_DIO_INIT);
    
    /* Enable the channel by assigning a priority to it. */
    tpu_enable(tpu, channel, priority);
}
    
/*******************************************************************************
FUNCTION      : tpu_dio_input_immed
PURPOSE       : This function returns the current pin state.
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 DIO
                           channel. The next channel is used as the secondary.
RETURNS NOTES : The pin state.
*******************************************************************************/
UINT16 tpu_dio_input_immed(struct TPU3_tag *tpu, UINT8 channel)
{
    /* Configure the channel for transition mode and use HSR later*/
    tpu_hsq(tpu, channel, TPU_DIO_IMMED_MODE);
    
    /* Initialize the channel */
    tpu_hsr(tpu, channel, TPU_DIO_INIT);
    
    /* wait for value to be updated */
    tpu_ready(tpu, channel);
    
    return (tpu->PARM.R[channel][TPU_DIO_PIN_LEVEL]);
}

/*******************************************************************************
FUNCTION      : tpu_dio_pin_history
PURPOSE       : This function returns the pin history.
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 DIO
                           channel. The next channel is used as the secondary.
RETURNS NOTES : The current pin history.
*******************************************************************************/
UINT16 tpu_dio_pin_history(struct TPU3_tag *tpu, UINT8 channel)
{
     return (tpu->PARM.R[channel][TPU_DIO_PIN_LEVEL]);
}

 
/*********************************************************************
 *
 * 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 + -