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

📄 etpuc_ppa.c

📁 mpc55**系列芯片的例程 包括SCI,SPI,TIMER,FIT,EDMA等几乎所有功能的实现
💻 C
📖 第 1 页 / 共 4 页
字号:
/****************************************************************************
 * FILE NAME: etpuc_ppa.c                    COPYRIGHT (c) FREESCALE 2004   *
 * DESCRIPTION:                                     All Rights Reserved     *
 *==========================================================================*
 * ORIGINAL AUTHOR: Richard Soja                                            *
 * $Log: etpuc_ppa.c,v $
 * Revision 1.2  2004/11/30 15:58:48  r47354
 * Add #defines for FM bits in API.
 *
 * Revision 1.1  2004/11/02 13:48:07  r12110
 * -First version in CVS.
 * -Added support for building function stand alone or in a set.
 *   -This includes using the global error function if avaialable.
 * -Updated comments in auto generated file to include version number.
 *
 *..........................................................................*
 * 0.00  R. Soya         Feb/04    Initial version of file.                 *
 * 0.1   G. Emerson   7/Sep/04     Changes for integration into set1        *
 *                                 Added flags for testing visibility       *
 * 0.2   G. Emerson   21/Oct/04    Post review changes                      *
 *                                 Removed testing instrumentation etc      *
 *                                 Added comments                           *
 ****************************************************************************/
#ifndef __ETPUC_H
#include <etpuc.h>          /*Defines eTPU hardware*/
#endif

#ifndef __ETPUC_COMMON_H
#include <eTPUc_common.h>   /*Standard way to use eTPU*/
#endif

#ifdef PPA_FUNCTION_NUMBER /* function is being compiled as part a set? */
#pragma ETPU_function PPA, alternate @ PPA_FUNCTION_NUMBER;
#else
#pragma ETPU_function PPA, alternate;  /* stand alone */
#endif

/* Some macro functions */
#define ScheduleTimeoutA(AbsTime) erta = AbsTime; EnableMatchA(); ClearMatchALatch()
#define Assign(a,b)              (b == 1) ? a = 1: a = 0;

/* Host Service Requests */
#define INIT_TCR1 7
#define INIT_TCR2 5

/* Flag definitions */

/*Measurement inactive/active flag*/
#define Measurement flag1
/* Only for setting flag1 (can't use for testing flag) */
#define Active TRUE
#define Inactive FALSE

/* Last pin level */
#define LastPin flag0
#define Low 0
#define High 1

/* Function Mode bits definition */
/* Type of measurement */
#define PulseMeasurement fm0 == 0
#define LowPulse fm1 == 0
#define HighPulse fm1 == 1

#define PeriodMeasurement fm0 == 1
#define FallingEdge fm1 == 0
#define RisingEdge fm1 == 1

#define PulseLow 0 /*Used by the API only*/
#define PulseHigh 2 /*Used by the API only*/

#define PeriodFall 1 /*Used by the API only*/
#define PeriodRise 3 /*Used by the API only*/

/* Some error values */
#define LowPulseError 1
#define HighPulseError 2
#define Overflow 128

/* Hardware definitions */
#define EventTime1 erta
#define EventTime2 ertb
#define Transition_A tdlA == 1

/****************************************************************************
* Channel Flag usage
* Flag0 is used to store the level of the pin sampled in the prvious thread.
* Flag1 is used to indictae wether measurement is active or not
****************************************************************************/

/*--------------------------------------------------------------------------+
| FUNCTION PARAMETERS:                                                      |
| LastTime : This 24 bit value is used by eTPU only. It contains the time of|
|            the last transition during active measurement of a single pulse|
|            or period.                                                     |
|    Accum : This 24 bit value should be initialised to 0 by CPU and        |
|            updated only by the eTPU. The parameter contains the current   |
|            uncompleted period or pulse measurement while measurement is in|
|            progress                                                       |
|  StatAcc : This 8 bit value contains a single bit flag to indicate that   |
|            the currently active accumulation has overflowed a 24 bit      |
|            value. The parameter is initialized to 0 by the CPU and        |
|            updated by the eTPU. The eTPU copies this value to the Status  |
|            parameter when the measurement completes, then resets StatAcc  |
|            to 0. An overflow is indicated when StatAcc is 0x80.           |
|SampleTime: This 24 bit value defines the rate at which the measurement is |
|            updated in the absence of an edge. This allows the host to make|
|            an interim measurement without waiting for the current pulse or|
|            period to complete. The CPU should initialize this value to the|
|            number of timebase counts desired between each sample; the eTPU|
|            schedules the first sample event when a measurement is         |
|            activated by a valid edge. If the sample rate is greater than  |
|            the maximum width between active pulse or period edges, then no|
|            sampling will occur. Note that excessively high sample rates   |
|            (very small values of SampleTime) may result in performance    |
|            degradation of the eTPU.                                       |
|PeriodCount:This 24 bit value is initialized to 0 by the CPU and updated   |
|            only by the eTPU. It contains the current number of accumulated|
|            pulses or periods since initialization or since the last       |
|            measurement was returned in parameter Result                   |
| MaxCount : This 24 bit value specifies the number of pulses or periods    |
|            that should be measured. Initialized by the CPU and tested by  |
|            the eTPU.                                                      |
|   Result : This 24 bit value is updated only by the eTPU. It contains the |
|            final total accumulation when the measurement completes. The   |
|            parameter Status indicates whether the result has overflowed   |
|   Status : This 8 bit value indicates whether the completed measurement,  |
|            available in parameter Result, has overflowed. At the end of   |
|            the measurement, the eTPU copies StatAcc to Status after it has|
|            copied Accum to Result, and then the eTPU sets the channel     |
|            interrupt status flag and DMA request flag. This ensures the   |
|            measurement result and its status are coherent.                |
+--------------------------------------------------------------------------*/

struct ChannelParameters
{int24 Accum;
 int8  StatAcc;
 int24 SampleTime,
       LastTime,
       PeriodCount,
       MaxCount,
       Result;
 int8  Status;
} register_chan_base *this;


void CheckPin()
{
/*---------------------------------------------------------------------------------------+
| This re-writes the chan value and at the same time clears the transition latch (tdl).  |
| This causes the pin state to be latched.                                               |
| If the pin does not transition after it is latched, tdl will remain clear.             |
| If the pin changes state after it is latched, tdl will be set again, and processed     |
| after this thread quits.| The design of the hardware ensures the pin state and value   |
| of tdl are coherent.                                                                   |
| tdl does not have to be checked in the current thread.                                 |
| It is the current (latched in this sub routine) and last pin levels that determine     |
| the operation of the state machine                                                     |
| The current pin level is obtained from channel.PSS                                     |
+----------------------------------------------------------------------------------------*/

    ClearTransLatch();
    chan = chan;
}

void AccumTime()
{
    this->Accum = this->Accum + (EventTime1 - this->LastTime);
    if (CC.C == 1)
    {
       this->StatAcc = this->StatAcc | Overflow;
       SetChannelInterrupt();    /* Generate Interrupt and DMA requests */
       SetDataTransferInterrupt();
    }
}

void Read1Retrig()
{
this->LastTime = EventTime1;
ScheduleTimeoutA(EventTime1 + this->SampleTime);
}

void Read2Retrig()
{
this->LastTime = EventTime2;
ScheduleTimeoutA(EventTime2 + this->SampleTime);
}

void CheckCount()
{
   this->PeriodCount++;
   if (this->PeriodCount >= this->MaxCount)
   {

      this->Result = this->Accum;
      this->Status = this->StatAcc;
      this->Accum = 0;
      this->StatAcc = 0;
      this->PeriodCount = 0;

      SetChannelInterrupt();
      SetDataTransferInterrupt(); /* Generate Interrupt and DMA requests */
    }
}

void MeasGlitch()
{
this->Accum = this->Accum + EventTime2 - EventTime1;
}

void PPA(struct ChannelParameters this)
{
/*--------------------------------------------------------------------------+
| THREAD NAME: THREAD1                                                      |
| DESCRIPTION:  Initialise channel for PPA using TCR2 as timebase.          |
|Disable matches in thread in case there are any previous pending matches.  |
|This could happen if the channel was running another function before this  |
|one.                                                                       |
|Configure channel to use TCR2.                                             |
|Proceed as per thread THREAD2 (from label init)                            |

⌨️ 快捷键说明

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