📄 etpuc_gpio.c
字号:
/****************************************************************************
* FILE NAME: etpuc_gpio.c COPYRIGHT (c) freescale 2004*
* DESCRIPTION: All Rights Reserved *
* This function provide general purpose i/o functionality on the eTPU *
* allowing the user to configure an eTPU channel as an input or output *
*==========================================================================*
* $Log: etpuc_gpio.c,v $
* Revision 1.2 2004/11/02 13:43:42 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 14:44:45 r12110
* No changes to code, just updated for CVS and checked into CVS.
*
*..........................................................................*
* 0.01 K Terry 19 March 04 Initial version of file *
* 0.02 K Terry 21 April 04 Removed debug comments *
* 0.03 K Terry 22 April 04 Modifications to reduce code size *
* 0.04 K Terry 27 April 04 Removed option to turn off match and *
* transition events *
* 0.05 K Terry 7 Jun 04 Modified Input Immediate Mode thread (S6) *
* to generate interrupt and DTR *
* 0.06 K Terry 22 Jun 04 Mod'd to accomodate changes to directory *
* structure and new location of *
* of etpu_gpio_auto.h *
* *
* 0.07 G. Emerson 16 July 04 Add DisableOutputBuffer to input init *
* threads *
* Add disclaimer *
* 0.08 G.Emerson 19 July 04 add () to DisableOutputBuffer calls *
* 0.09 J. Loeliger 3/Aug/04 Fixed comments to always use standard C *
* open and close pairs. This is needed for *
* version b097 of the compiler. General *
* clean-up of coments and added freescale. *
****************************************************************************/
#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 GPIO_FUNCTION_NUMBER /* function is being compiled as part a set? */
#pragma ETPU_function GPIO @ GPIO_FUNCTION_NUMBER;
#else
#pragma ETPU_function GPIO; /* stand alone */
#endif
/* GPIO Specific defines */
/* Host Service Requests */
#define GPIO_OUTPUT_HIGH 7
#define GPIO_OUTPUT_LOW 6
#define GPIO_INPUT_IMMED 5
#define GPIO_INPUT_RISING 4
#define GPIO_INPUT_FALLING 3
#define GPIO_INPUT_EITHER 2
#define GPIO_INPUT_MATCH 1
/* Functions Modes
FM0 - selects timebase to use
FM1 set to disable Match and Transition events with INPUT_IMMED host service request */
#define GPIO_USE_TCR1 0
#define GPIO_USE_TCR2 1
/* FM1 - used during INPUT_IMMED host service request to optionally disable
match and transition events */
/******************************************************************************/
/* Function Description */
/* This function allows the user the configure an eTPU channel as a general */
/* purpose input or output. 7 function modes are supported These are: */
/* 1/. Input Mode - Update periodically */
/* 2/. Input Mode - Update on Transition - either edge */
/* 3/. Input Mode - Update on Transition - falling edge */
/* 4/. Input Mode - Update on Transition - rising edge */
/* 5/. Input Mode - Update on request/disable transition and */
/* match updates */
/* 6/. Output Mode - (output low) */
/* 7/. Output Mode - (output high) */
/******************************************************************************/
/******************************************************************************
* Function Parameters
*
* InputMatch Period: Selects the match register value to define the match
* update period
*
******************************************************************************/
void GPIO (int24 InputMatchPeriod, int24 PinState)
{
static int24 CurrentCount;
static int24 NextMatch;
/*---------------------------------------------------------------------------+
| Thread Name: Output High (S0) |
| Description: Set channel output high |
+----------------------------------------------------------------------------*/
if (HostServiceRequest == GPIO_OUTPUT_HIGH)
{
SetPinHigh();
act_unitA = enable_output_buffer;
}
/*---------------------------------------------------------------------------+
| Thread Name: Output Low (S1) |
| Description: Set channel output low |
+----------------------------------------------------------------------------*/
else if (HostServiceRequest == GPIO_OUTPUT_LOW)
{
SetPinLow();
act_unitA = enable_output_buffer;
}
/*---------------------------------------------------------------------------+
| Thread Name: Input Rising (S2) |
| Description: Configure channel to detect input rising edge |
| |
| 1/. Configure Input Pin Action Control Register 1 (IPAC1)to detect |
| rising edge |
| 2/. Set Channel Mode for SingleMatchSingleTransition |
| 3/. Set Comparitor and Timebase Selection for TCR1 capture and TCR1 |
| Match (Greater Equal) |
| 4/. Enable Match and Transition Event Handling |
+----------------------------------------------------------------------------*/
else if (HostServiceRequest == GPIO_INPUT_RISING)
{
DisableOutputBuffer();
DetectARisingEdge();
goto setup1;
}
/*---------------------------------------------------------------------------+
| Thread Name: Input Falling (S3) |
| Description: Configure channel to detect input falling edge |
| |
| 1/. Configure Input Pin Action Control Register 1 (IPAC1)to detect |
| falling edge |
| 2/. Set Channel Mode for SingleMatchSingleTransition |
| 3/. Set Comparitor and Timebase Selection for TCR1 capture and TCR1 |
| Match (Greater Equal) |
| 4/. Enable Match and Transition Event Handling |
+----------------------------------------------------------------------------*/
else if (HostServiceRequest == GPIO_INPUT_FALLING)
{
DisableOutputBuffer();
DetectAFallingEdge();
goto setup1;
}
/*---------------------------------------------------------------------------+
| Thread Name: Input Either (S4) |
| Description: Configure channel to detect input rising or falling edge |
| |
| 1/. Configure Input Pin Action Control Register 1 (IPAC1)to detect |
| rising or falling edge |
| 2/. Set Channel Mode for SingleMatchSingleTransition |
| 3/. Set Comparitor and Timebase Selection for TCR1 capture and TCR1 |
| Match (Greater Equal) |
| 4/. Enable Match and Transition Event Handling |
+----------------------------------------------------------------------------*/
else if (HostServiceRequest == GPIO_INPUT_EITHER)
{
DisableOutputBuffer();
DetectAAnyEdge();
setup1:
SingleMatchSingleTransition();
TimeBaseAMatchTcr1CaptureTcr1GreaterEqual();
EnableMatchAndTransitionEventHandling();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -