#include "hw_types.h"
#include "gpio.h"
#include "psc.h"
#include "interrupt.h"
#include "soc_OMAPL138.h"
#include "ecap.h"
#include "stdio.h"
//-----------------------------------------------------------------------------
// Private Defines and Macros
//-----------------------------------------------------------------------------
// uncomment this define if running without gel initialization.
// #define NO_GEL (1)
//-----------------------------------------------------------------------------
// Static Variable Declarations
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Private Function Prototypes
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Public Function Definitions
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// \brief entry point for bsl test code.
//
// \param none.
//
// \return none.
//-----------------------------------------------------------------------------
interrupt void ecap1_isr(void); //ECAP1中断函数
interrupt void ecap2_isr(void); //ECAP5中断函数
void InitECapture1(void); //ECAP1配置函数
void InitECapture2(void); //ECAP5配置函数
void InitDIR(void); //B相脉冲GPIO口设置
static void ConfigureInt(void); //中断初始化配置
// Global variables used in this example 该例程中使用到的全局变量
Uint32 ECap1IntCountNi;
Uint32 ECap2IntCountShun;
Uint32 zhengzhuan;
Uint32 nizhuan;
Uint32 m;
int main(void)
{
#if NO_GEL
EVMOMAPL138_init();
EVMOMAPL138_initRAM();
#endif
USTIMER_init();
// TEST DA
//---------
// TEST_da();
InitDIR(); //B相脉冲GPIO口设置
GPIOECAP1PinMuxSetup(); //ECAP 引脚初始化管脚复用函数
GPIOECAP2PinMuxSetup();
InitECapture1(); //ECAP1配置函数
InitECapture2(); //ECAP2配置函数
ConfigureInt(); //中断初始化配置
ECap1IntCountNi=0;
ECap2IntCountShun=0;
m=0;
while(1)
{
// GPIOPinWrite(SOC_GPIO_0_REGS, 20, GPIO_PIN_HIGH);
// if(GPIOPinRead(SOC_GPIO_0_REGS, 19))
// {
// printf("gaodianping\n");
// }
// else
// {
// printf("didianping\n");
// }
if(ECap2IntCountShun>ECap1IntCountNi)
{
// zhengzhuan=ECap2IntCountShun-ECap1IntCountNi;
zhengzhuan=ECap2IntCountShun;
printf("zhengzhuanNUM=%u\n",zhengzhuan);
}
else
{
nizhuan=ECap1IntCountNi-ECap2IntCountShun;
printf("nizhuanNUM=%u\n",nizhuan);
}
}
}
void InitDIR(void)
{
PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);
/* Pin Multiplexing of pin 12 & 13 of GPIO Bank 6.*/
GPIOBank1Pin2PinMuxSetup();
GPIOBank1Pin3PinMuxSetup();
GPIODirModeSet(SOC_GPIO_0_REGS, 19, GPIO_DIR_INPUT);
GPIODirModeSet(SOC_GPIO_0_REGS, 20, GPIO_DIR_OUTPUT);
GPIOBankIntDisable(SOC_GPIO_0_REGS, 1);
}
void InitECapture1() //配置ECAP1
{
// ECap1Regs.ECEINT.all = 0x0000; // Disable all capture interrupts中断使能寄存器禁止中断
ECAPIntDisable(SOC_ECAP_1_REGS,ECAP_CEVT1_INT); //中断使能寄存器,禁止中断
ECAPIntDisable(SOC_ECAP_1_REGS,ECAP_CEVT2_INT);
ECAPIntDisable(SOC_ECAP_1_REGS,ECAP_CEVT3_INT);
ECAPIntDisable(SOC_ECAP_1_REGS,ECAP_CEVT4_INT);
ECAPIntDisable(SOC_ECAP_1_REGS,ECAP_CNTOVF_INT);
ECAPIntDisable(SOC_ECAP_1_REGS,ECAP_PRDEQ_INT);
ECAPIntDisable(SOC_ECAP_1_REGS,ECAP_CMPEQ_INT);
// ECap1Regs.ECCLR.all = 0xFFFF; // Clear all CAP interrupt flags中断清除寄存器清除所有CAP中断的标志位
ECAPIntStatusClear(SOC_ECAP_1_REGS,ECAP_CEVT1_INT);//中断清除寄存器,清除所有CAP中断的标志位
ECAPIntStatusClear(SOC_ECAP_1_REGS,ECAP_CEVT2_INT);
ECAPIntStatusClear(SOC_ECAP_1_REGS,ECAP_CEVT3_INT);
ECAPIntStatusClear(SOC_ECAP_1_REGS,ECAP_CEVT4_INT);
ECAPIntStatusClear(SOC_ECAP_1_REGS,ECAP_CNTOVF_INT);
ECAPIntStatusClear(SOC_ECAP_1_REGS,ECAP_PRDEQ_INT);
ECAPIntStatusClear(SOC_ECAP_1_REGS,ECAP_CMPEQ_INT);
// ECap1Regs.ECCTL2.bit.TSCTPRSTO = EC_FREEZE; //CTR不运行
ECAPCounterControl(SOC_ECAP_1_REGS,ECAP_COUNTER_STOP);//CTR不运行
// ECap1Regs.ECCTL1.bit.CAPLDEN = EC_DISABLE; //CAPx寄存器加载也可以禁止
ECAPCaptureLoadingDisable(SOC_ECAP_1_REGS); //CAPx寄存器加载禁止
// Configure peripheral registers
// ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE; //CAP mode
ECAPOperatingModeSelect(SOC_ECAP_1_REGS,ECAP_CAPTURE_MODE);//CAP mode
// ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_ONESHOT; // One-shot
// ECap1Regs.ECCTL2.bit.STOP_WRAP = EC_EVENT1; // Stop at 1 events
ECAPOneShotModeConfig(SOC_ECAP_1_REGS,ECAP_CAPTURE_EVENT1_STOP);//one-shot and stop at 1 events
// ECap1Regs.ECCTL1.bit.CAP1POL = EC_RISING; // Rising edge
ECAPCapeEvtPolarityConfig(SOC_ECAP_1_REGS,1,1,1,1);//Rising edge
// ECap1Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE; // Disable sync in
// ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;// Disable sync out signal
// Disable sync in and Disable sync out signal
ECAPSyncInOutSelect(SOC_ECAP_1_REGS,ECAP_SYNC_IN_DISABLE,ECAP_SYNC_OUT_DISABLE);
// ECap1Regs.ECCTL2.bit.REARM = 1; // Arm one-shot
ECAPOneShotREARM(SOC_ECAP_1_REGS);//Arm one-shot
// ECap1Regs.ECCTL1.bit.PRESCALE = 0; //事件预分频控制位0不分频
ECAPPrescaleConfig(SOC_ECAP_1_REGS,0); //事件预分频控制位0不分频
// ECap1Regs.ECEINT.bit.CEVT1 = 1; // Enable 1 events interrupt
ECAPIntEnable(SOC_ECAP_1_REGS,ECAP_CEVT1_INT); //Enable 1 events interrupt
}
void InitECapture2()
{
// ECap2Regs.ECEINT.all = 0x0000; // Disable all capture interrupts
ECAPIntDisable(SOC_ECAP_2_REGS,ECAP_CEVT1_INT); //中断使能寄存器,禁止中断
ECAPIntDisable(SOC_ECAP_2_REGS,ECAP_CEVT2_INT);
ECAPIntDisable(SOC_ECAP_2_REGS,ECAP_CEVT3_INT);
ECAPIntDisable(SOC_ECAP_2_REGS,ECAP_CEVT4_INT);
ECAPIntDisable(SOC_ECAP_2_REGS,ECAP_CNTOVF_INT);
ECAPIntDisable(SOC_ECAP_2_REGS,ECAP_PRDEQ_INT);
ECAPIntDisable(SOC_ECAP_2_REGS,ECAP_CMPEQ_INT);
// ECap2Regs.ECCLR.all = 0xFFFF; // Clear all CAP interrupt flags
ECAPIntStatusClear(SOC_ECAP_2_REGS,ECAP_CEVT1_INT);//中断清除寄存器,清除所有CAP中断的标志位
ECAPIntStatusClear(SOC_ECAP_2_REGS,ECAP_CEVT2_INT);
ECAPIntStatusClear(SOC_ECAP_2_REGS,ECAP_CEVT3_INT);
ECAPIntStatusClear(SOC_ECAP_2_REGS,ECAP_CEVT4_INT);
ECAPIntStatusClear(SOC_ECAP_2_REGS,ECAP_CNTOVF_INT);
ECAPIntStatusClear(SOC_ECAP_2_REGS,ECAP_PRDEQ_INT);
ECAPIntStatusClear(SOC_ECAP_2_REGS,ECAP_CMPEQ_INT);
// ECap2Regs.ECCTL1.bit.CAPLDEN = 0; // Disable CAP1-CAP4 register loads
// ECap2Regs.ECCTL2.bit.TSCTRSTOP = 0; // Make sure the counter is stopped
ECAPCounterControl(SOC_ECAP_2_REGS,ECAP_COUNTER_STOP);//CTR不运行
ECAPCaptureLoadingDisable(SOC_ECAP_2_REGS); //CAPx寄存器加载禁止
// Configure peripheral registers
// ECap2Regs.ECCTL2.bit.CAP_APWM = 0; // ECAP模式,另一种模式是APWM
ECAPOperatingModeSelect(SOC_ECAP_2_REGS,ECAP_CAPTURE_MODE);//CAP mode
// ECap2Regs.ECCTL2.bit.CONT_ONESHT = 1; // One shot
// ECap2Regs.ECCTL2.bit.STOP_WRAP = 0; // Stop at 1 events
ECAPOneShotModeConfig(SOC_ECAP_2_REGS,ECAP_CAPTURE_EVENT1_STOP);//one-shot and stop at 1 events
// ECap2Regs.ECCTL1.bit.CAP1POL = 0; //
ECAPCapeEvtPolarityConfig(SOC_ECAP_2_REGS,0,0,0,0);//Falling edge
// ECap2Regs.ECCTL2.bit.SYNCI_EN = 0; // Disable sync
// ECap2Regs.ECCTL2.bit.SYNCO_SEL = 2; // Disable sync out
// Disable sync in and Disable sync out signal
ECAPSyncInOutSelect(SOC_ECAP_2_REGS,ECAP_SYNC_IN_DISABLE,ECAP_SYNC_OUT_DISABLE);
// ECap2Regs.ECCTL2.bit.REARM = 1; // arm one-shot
ECAPOneShotREARM(SOC_ECAP_2_REGS);//Arm one-shot
// ECap2Regs.ECCTL1.bit.PRESCALE = 0;
ECAPPrescaleConfig(SOC_ECAP_2_REGS,0); //事件预分频控制位0不分频
// ECap2Regs.ECEINT.bit.CEVT1 = 1;
ECAPIntEnable(SOC_ECAP_2_REGS,ECAP_CEVT1_INT); //Enable 1 events interrupt
}
interrupt void ecap1_isr(void)
{
// if(GPIOPinRead(SOC_GPIO_0_REGS, 3))
// {
ECap1IntCountNi++;
// }
// else
// {
// ECap2IntCountShun++;
// }
// ECap1Regs.ECCLR.bit.CEVT1 = 1; // CEVENT events = interrupt
// ECap1Regs.ECCLR.bit.INT = 1;
IntEventClear(SYS_INT_ECAP1);
ECAPIntStatusClear(SOC_ECAP_1_REGS,ECAP_CEVT1_INT);//CEVENT events = interrupt
ECAPGlobalIntEnable(SOC_ECAP_1_REGS);
// ECap1Regs.ECCTL2.bit.REARM = 1;
ECAPOneShotREARM(SOC_ECAP_1_REGS);//Arm one-shot
ECAPIntEnable(SOC_ECAP_1_REGS,ECAP_CEVT1_INT);
}
interrupt void ecap2_isr(void)
{
// if(GPIOPinRead(SOC_GPIO_0_REGS, 3))
// {
// ECap2IntCountShun++;
// }
// else
// {
// ECap1IntCountNi++;
// }
// ECap2Regs.ECCLR.bit.CEVT1 = 1;
// ECap2Regs.ECCLR.bit.INT = 1;
IntEventClear(SYS_INT_ECAP2);
ECAPIntStatusClear(SOC_ECAP_2_REGS,ECAP_CEVT1_INT);//CEVENT events = interrupt
ECAPGlobalIntEnable(SOC_ECAP_2_REGS);
// ECap2Regs.ECCTL2.bit.REARM = 1;
ECAPOneShotREARM(SOC_ECAP_2_REGS);//Arm one-shot
ECAPIntEnable(SOC_ECAP_2_REGS,ECAP_CEVT1_INT);
}
static void ConfigureInt(void)
{
IntDSPINTCInit(); //initialize the interrupt controller
IntGlobalEnable(); //enable DSP CPU interrupts globally
IntRegister(C674X_MASK_INT4, ecap1_isr); //register the ISR in the interrupt vector table
IntRegister(C674X_MASK_INT5, ecap2_isr); //register the ISR in the interrupt vector table
IntEventMap(C674X_MASK_INT4, SYS_INT_ECAP1); //map the system event GPIO_Bank2(BUTTON) to CPU INT4
IntEventMap(C674X_MASK_INT5, SYS_INT_ECAP2);
IntEnable(C674X_MASK_INT4); //enable the CPU masked INT4
IntEnable(C674X_MASK_INT5); //enable the CPU masked INT4
IntEventSet(SYS_INT_ECAP1); //set the EVTFLAG register of GPIO_Bank2
IntEventSet(SYS_INT_ECAP2);
}
ECAP中断没有运行是怎么回事,请大神指教 |