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

📄 tpu_pta_example1.c

📁 mpc564 时钟中断 时钟中断
💻 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_example1.c              COPYRIGHT (c) MOTOROLA 2002 */
/* VERSION: 1.1                                   All Rights Reserved     */
/*                                                                        */
/* DESCRIPTION: This sample program show a simple PTA example that        */
/* measures the total period over a selected number of periods, starting  */
/* on a rising edge, of an input signal connected to channel 0 on TPUA.   */
/* A simple interrupt handler is used to trigger the acquisition of the   */
/* completed measurement.                                                 */
/*                                                                        */
/* The program is targeted for the MPC555 but should work on any MPC500   */
/* device with a TPU. For other devices the setup routines will also need */
/* to be changed.                                                         */
/*========================================================================*/
/* 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  17 Sep 02    Revised after review.                  */
/**************************************************************************/

#include "mpc555.h"         /* Define MPC555 registers, this needs to be  */
                            /* changed if other MPC500 devices are used.  */
#include "mpc500_util.h"    /* Utility routines for using MPC500 devices  */
#include "tpu_pta.h"        /* TPU PTA functions */

UINT32   accumulation;      /* global variable for period/PW accumulation */

void main ()
{
    struct TPU3_tag *tpua = &TPU_A;         /* pointer for TPU routines */

    setup_555();                            /* setup routine for MPC555 */

    /* initialize Prog. Time Accum function with:   */
    /*    - Input signal on TPU A channel 0         */
    /*    - Use TCR1 timebase                       */
    /*    - Measure periods, start with rising edge */
    /*    - Max count value of 10                   */
    /*    - Schedule as high priority in the TPU    */

    tpu_pta_init(tpua, 0, TPU_PRIORITY_HIGH, TPU_PTA_TCR1, \
                 TPU_PTA_PERIOD_ACCUM_RISE, 10);

    tpu_interrupt_enable(tpua, 0);          /* enable PTA interrupts */

    while (1) {                             /* loop and measure */
    }
}

/***************************************************************************
FUNCTION        : ext_Int_Handler
PURPOSE         : Respond to external interrupts from the PTA function.
INPUT NOTES     : All enabled external interrupts jump into this routine.
RETURN NOTES    : If PTA interrupt, get accumulation, clear the interrupt,
                     and quit.
GENERAL NOTES	:
***************************************************************************/

void ext_Int_Handler()
    {
    struct TPU3_tag *tpua = &TPU_A;         /* pointer for TPU routines */
    extern UINT32 accumulation;             /* global accumulation value */

    if ( tpu_check_interrupt(tpua, 0) )     /* test PTA int. status bit */
        {
        accumulation = tpu_pta_get_accumulation(tpua, 0);

        tpu_clear_interrupt(tpua, 0);       /* clear interrupt */
        }
    else
        {
        /* process external interrupt from another source */
        }
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -