📄 mx21_gpt.h
字号:
/**********************************************************************
*
* (C) COPYRIGHT 2004 FREESCALE, INC.
* ALL RIGHTS RESERVED
*
*
* Group/Division: WMSG/MMDO
*
* Description:
*
* Related Specifications:
*
* Errata:
*
* File Name: MX21_GPT.h
* Revision Number: 0.1
* Author(s): Ryan Johnson
* Date created: 27 May 2004
* Revision History:
* Date Rev Description
* ---- --- -----------
* 27May04 0.1 First draft
*
**********************************************************************/
#ifndef _MX21GPT_H_
#define _MX21GPT_H_
#include "MX21_MemMap.h"
#include "MX21_Macros.h"
#include "MX21_DataTypes.h"
#include "MX21_Common.h"
/********************************************************************
M A C R O S
*********************************************************************/
typedef enum
{
GPT_CLOCK_OFF = 0x0,
GPT_PERCLK1 = 0x1,
GPT_PERCLK1div4 = 0x2,
GPT_TIN = 0x3,
GPT_32KHZ = 0x4
} gpt_clock_type;
typedef enum
{
GPT_CAPOFF = 0x0,
GPT_RISING = 0x1,
GPT_FALLING = 0x2,
GPT_TOGGLE = 0x3
} gpt_cap;
/********************************************************************
F U N C T I O N P R O T O T Y P E S
*********************************************************************/
/*---------------------------------------------------
//
// in descriptions, * = 1, 2 or 3 (GPT1, GPT2 or GPT3)
//
//-------------------------------------------------*/
/*---------------------------------------------------
// WaitCycles
// Gets ratio of PERCLK1 divider to FCLK prescaler
// and and sets compare to CYCLES/RATIO rounded up.
//-------------------------------------------------*/
void
gpt3_WaitCycles(uint32_t);
/*---------------------------------------------------
// WaitTime
// Waits for approximately the time specified in
// microseconds. Resolution will not be better than
// approximately 30.5 microseconds. Assumes 32.768kHz
// is the crystal speed.
//-------------------------------------------------*/
void
gpt3_WaitTime(uint32_t);
/*---------------------------------------------------
// COMPARE, TCMP[31:0] = 0..0xFFFFFFFF
// Sets the value that will trigger a compare interrupt
//-------------------------------------------------*/
void
gpt1_SetComparator(uint32_t);
void
gpt2_SetComparator(uint32_t);
void
gpt3_SetComparator(uint32_t);
/*---------------------------------------------------
// SWR, TCTL[15] = 1
// soft reset the GPT using the SWR bit in the
// TCTL reg, finishes five cycles after write
//-------------------------------------------------*/
void
gpt1_SoftReset(void);
void
gpt2_SoftReset(void);
void
gpt3_SoftReset(void);
/*---------------------------------------------------
// CC, TCTL[10] = Enable/Disable
// Enable = set GPT to reset counter to 0 when TEN=0
// Disable = set GPT to keep current counter value
// when TEN=0
//-------------------------------------------------*/
void
gpt1_CounterClear(uint32_t);
void
gpt2_CounterClear(uint32_t);
void
gpt3_CounterClear(uint32_t);
/*---------------------------------------------------
// OM, TCTL[9] = 0
// set compare events to generate a
// single cycle output low on TOUT*
//-------------------------------------------------*/
void
gpt1_PulseLow(void);
void
gpt2_PulseLow(void);
void
gpt3_PulseLow(void);
/*---------------------------------------------------
// OM, TCTL[9] = 1
// set compare events to toggle TOUT*
//-------------------------------------------------*/
void
gpt1_Toggle(void);
void
gpt2_Toggle(void);
void
gpt3_Toggle(void);
/*---------------------------------------------------
// FRR, TCTL[8] = 0
// configures counter to reset to 0 after reaching
// the compare value
//-------------------------------------------------*/
void
gpt1_RestartMode(void);
void
gpt2_RestartMode(void);
void
gpt3_RestartMode(void);
/*---------------------------------------------------
// FRR, TCTL[8] = 1
// configures counter to continue incrementing after
// reaching the compare value
//-------------------------------------------------*/
void
gpt1_FreeRunMode(void);
void
gpt2_FreeRunMode(void);
void
gpt3_FreeRunMode(void);
/*---------------------------------------------------
// CAP, TCTL[7:6] = GPT_CAPOFF, GPT_RISING,
// GPT_FALLING, GPT_TOGGLE
// sets capture events to either be off, triggered
// by rising edge, by falling edge, or the input
// toggling
//-------------------------------------------------*/
void
gpt1_SetCaptureTrigger(gpt_cap gpt_trigger_type);
void
gpt2_SetCaptureTrigger(gpt_cap gpt_trigger_type);
void
gpt3_SetCaptureTrigger(gpt_cap gpt_trigger_type);
/*---------------------------------------------------
// CAPT_EN, TCTL[5] = Enable/Disable
// enables/disables interrupts for capture events
//-------------------------------------------------*/
void
gpt1_CaptureInterrupt(uint32_t);
void
gpt2_CaptureInterrupt(uint32_t);
void
gpt3_CaptureInterrupt(uint32_t);
/*---------------------------------------------------
// COMPEN, TCTL[4] = Enable/Disable
// enables/disables interrupts for Compare events
//-------------------------------------------------*/
void
gpt1_CompareInterrupt(uint32_t);
void
gpt2_CompareInterrupt(uint32_t);
void
gpt3_CompareInterrupt(uint32_t);
/*---------------------------------------------------
// CLKSOURCE,
// TCTL[3:1] = GPT_CLOCK_OFF, GPT_PERCLK1,
// GPT_PERCLK1div4, TIN, 32KHZ
// set input clock to GPT*, GPT_CLOCK_OFF
// causes counter to cease running
//-------------------------------------------------*/
void
gpt1_Clock(gpt_clock_type);
void
gpt2_Clock(gpt_clock_type);
void
gpt3_Clock(gpt_clock_type);
/*---------------------------------------------------
// TEN, TCTL[0] = Enable/Disable
// Turns the individual GPT on or off. Registers
// should be configured properly before turning on.
// When turning off, all regs keep values except the
// counter, which depends on the CC bit in TCTL
//-------------------------------------------------*/
void
gpt1_EN(uint32_t);
void
gpt2_EN(uint32_t);
void
gpt3_EN(uint32_t);
/*---------------------------------------------------
// Prescaler, TPRER[10-0] = 0:2047
// sets divisor for clock
// counter update rate will be
// = (selected clock freq)/(Prescaler + 1) (Hz)
//-------------------------------------------------*/
void
gpt1_SetPrescaler(uint32_t);
void
gpt2_SetPrescaler(uint32_t);
void
gpt3_SetPrescaler(uint32_t);
/*---------------------------------------------------
// CAPT, TSTAT[1]
// returns true if capture event interrupt has occured
// resets only when interrupt has been cleared
//-------------------------------------------------*/
uint32_t
gpt1_CaptureInterruptStatus(void);
uint32_t
gpt2_CaptureInterruptStatus(void);
uint32_t
gpt3_CaptureInterruptStatus(void);
/*---------------------------------------------------
// COMP, TSTAT[0]
// returns true if compare event interrupt has occured
// resets only when interrupt has been cleared
//-------------------------------------------------*/
uint32_t
gpt1_CompareInterruptStatus(void);
uint32_t
gpt2_CompareInterruptStatus(void);
uint32_t
gpt3_CompareInterruptStatus(void);
/*---------------------------------------------------
// CAPT, TSTAT[1] = 1
// Writes 1 to the CAPT bit to clear it
//-------------------------------------------------*/
void
gpt1_ClearCapture(void);
void
gpt2_ClearCapture(void);
void
gpt3_ClearCapture(void);
/*---------------------------------------------------
// COMP, TSTAT[0] = 1
// Writes 1 to the COMP bit to clear it
//-------------------------------------------------*/
void
gpt1_ClearCompare(void);
void
gpt2_ClearCompare(void);
void
gpt3_ClearCompare(void);
#endif /* _MX21GPT_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -