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

📄 etpuc_ic.c

📁 mpc55**系列芯片的例程 包括SCI,SPI,TIMER,FIT,EDMA等几乎所有功能的实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
 * FILE NAME: etpuc_ic.c                       COPYRIGHT (c) freescale 2004 *
 * DESCRIPTION:                                     All Rights Reserved     *
 * This function can captures input transitions.                            *
 *==========================================================================*
 * $Log: etpuc_ic.c,v $
 * Revision 1.4  2004/11/18 14:47:25  r12110
 * -Added option for Link4 to use register passing. This require assembler with the current compiler.
 *
 * Revision 1.3  2004/11/02 14:12:16  r12110
 * -Fixed use of  global error function.
 *
 * Revision 1.2  2004/11/02 13:45:27  r12110
 * -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.
 *
 * Revision 1.1  2004/11/01 10:05:09  r12110
 * No changes to code, just updated for CVS and checked into CVS.
 *
 *..........................................................................*
 * 0.01  J. Loeliger  20/Feb/04  Initial version of file.                   *
 * 0.02  J. Loeliger  23/Sep/04  Updated so function can be standalone or in*
 *                                a set. Added clear of Transcount during   *
 *                                init. Cleaned up S3. Added more comments. *
 * 0.03  J. Loeliger  4/Oct/04   Fixed some 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 IC_FUNCTION_NUMBER    /* function is being compiled as part a set? */
#pragma ETPU_function IC @ IC_FUNCTION_NUMBER;
#else
#pragma ETPU_function IC; /* stand alone */
#endif

/*Macros to make the code easier to understand. */
/*These are specific to this IC function        */
/* Host service requests                        */
#define IC_INIT_TCR1  7         /* Initialize using TCR1 */
#define IC_INIT_TCR2  6         /* Initialize Using TCR2 */
#define IC_INIT_PRAM  5         /* Initialize to use Parameter RAM */

/* Function Modes */
/* FM0 - 0 = continuous mode  */
/*       1 = single shot mode */
/* FM1 - 0 = no links         */
/*       1 = link mode        */
#define IC_CONT_MODE 0
#define IC_SINGLE_MODE 1
#define IC_LINK_MODE 1

/* General Notes:               */
/*                              */
/* Channel Flag usage           */
/* Flag0 - 0 = TCR mode         */
/*         1 = PRAM mode        */
#define IC_TCR   0
#define IC_PRAM  1

/*--------------------------------------------------------------------------+
| FUNCTION PARAMETERS:                                                      |
| IC_Flags: Bit flags used to define edge.                                  |
|  0 = falling edge                                                         |
|  1 = rising edge                                                          |
|  2 = any edge                                                             |
|  3 = any edge                                                             |
| IC_MaxCount: The number of edges to count before generating an interrupt  |
|	and DMA request.                                                        |
| IC_Final: The reference value of the final edge detected.                 |
| IC_Last: The reference value of the last edge detected.                   |
| *IC_Address: The address of the value to capture when using Parameter RAM |
|	capture mode.                                                           |
| IC_Link1: The first 4 channels to send links to.                          |
| IC_Link2: The second 4 channels to send link to.                          |
| IC_TransCount: The current number of transitions counted.                 |
+--------------------------------------------------------------------------*/
void IC (int8 IC_Flags, int24 IC_MaxCount, int24 IC_TransCount, int24 IC_Final,
    int24 IC_Last, int24 * IC_Address, int32 IC_Link1, int32 IC_Link2)
{
/*--------------------------------------------------------------------------+
| THREAD NAME: Initialize using TCR1 (S0)                                   |
| DESCRIPTION: Initialize a channel to run IC using TCR1 as the reference.  |
|              1. Clear flag0 for TCR reference mode.                       |
|              2. Configure to use TCR1.                                    |
|              3. Set channel mode.                                         |
|              4. Configure edge detection.                                 |
|              5. Disable output buffer for input function.                 |
|              6. Clear TransCount.                                         |
|              7. Enable service events.                                    |
|              8. Clear latches.                                            |
+--------------------------------------------------------------------------*/
    if (HostServiceRequest == IC_INIT_TCR1)
      {
          DisableMatchesInThread ();

          Clear (flag0);                                        /* 1. */
        IC_init:
          ActionUnitA (MatchTCR1, CaptureTCR1, GreaterEqual);   /* 2. */
          ActionUnitB (MatchTCR1, CaptureTCR1, GreaterEqual);
        IC_init2:
          SingleMatchSingleTransition ();                       /* 3. */

          DetectAAnyEdge ();                                    /* 4. */
          DetectBAnyEdge ();
          if ((IC_Flags & 0x02) == 0)
            {
                DetectARisingEdge ();
                DetectBRisingEdge ();
                if ((IC_Flags & 0x01) == 0)
                  {
                      DetectAFallingEdge ();
                      DetectBFallingEdge ();
                  }
            }

          DisableOutputBuffer ();                               /* 5. */
          IC_TransCount = 0;                                    /* 6. */
          EnableEventHandling ();                               /* 7. */
          ClearAllLatches ();                                   /* 8. */
      }

/*--------------------------------------------------------------------------+
| THREAD NAME: Initialize using TCR2 (S1)                                   |
| DESCRIPTION: Initialize a channel to run IC using TCR2 as the reference.  |
|              1. Clear flag0 for TCR reference mode.                       |
|              2. Configure to use TCR2.                                    |
|              3. Jump to main initialization routine.                      |
+--------------------------------------------------------------------------*/
    else if (HostServiceRequest == IC_INIT_TCR2)
      {
          DisableMatchesInThread ();

          Clear (flag0);                                        /* 1. */

          ActionUnitA (MatchTCR2, CaptureTCR2, GreaterEqual);   /* 2. */
          ActionUnitB (MatchTCR2, CaptureTCR2, GreaterEqual);

          goto IC_init2;                                        /* 3. */
      }

/*--------------------------------------------------------------------------+
| THREAD NAME: Initialize using Parameter RAM (S2)                          |
| DESCRIPTION: Initialize a channel to run IC using TCR2 as the reference.  |
|              1. Set flag0 for PRAM reference mode.                        |
|              2. Jump to main initialization routine.                      |
+--------------------------------------------------------------------------*/
    else if (HostServiceRequest == IC_INIT_PRAM)
      {
          DisableMatchesInThread ();

          Set (flag0);                                          /* 1. */

          goto IC_init;                                         /* 2. */
      }

/*--------------------------------------------------------------------------+
| THREAD NAME: Transition with TCR reference (S3)                           |
| DESCRIPTION: Handle 1 or 2 edges.                                         |
|              1. Increament TransCount                                     |
|              2. If TransCount < MaxCount then just count edge.            |
|              3.     Last = erta and check for 2nd edge                    |
|                 else                                                      |
|              4.     Final = erta, final edge in group.                    |
|              5.     if link mode then link to other channels.             |
|              6.     if in sngleshot mode then we are done.                |
|              7.         request IRQ and DMA.                              |
|              8.         disable transistion detection                     |
|              9.         negate latches and end.                           |
|                     endif                                                 |
|                 endif                                                     |
|             10. If tdlb then 2 edges for this thread                      |
|             11.     If TransCount < MaxCount then just count edge.        |
|             12.         Last = erta and check for 2nd edge                |
|                     else                                                  |
|             13.         Final = erta, final edge in group.                |
|             14.         if link mode then link to other channels.         |
|             15.         if in sngleshot mode then we are done             |
|             16.             request IRQ and DMA                           |
|             17.             disable transistion detection                 |
|                         endif                                             |
|                     endif                                                 |
|                 endif                                                     |
|             18. negate latches and end                                    |
+--------------------------------------------------------------------------*/

⌨️ 快捷键说明

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