工具与软件:
您好、TI
/* ECAP Interrupt Sources */
#define ECAP_INT_ALL (ECAP_CEVT1_INT | \
ECAP_CEVT2_INT | \
ECAP_CEVT3_INT | \
ECAP_CEVT4_INT | \
ECAP_CNTOVF_INT | \
ECAP_PRDEQ_INT | \
ECAP_CMPEQ_INT)
uint32_t gEcapBaseAddr = CONFIG_ECAP0_BASE_ADDR;
static HwiP_Object gEcapHwiObject;
void hal_ecap_it_cb(void *args)
{
uint32_t fall = 0;
uint32_t rise = 0;
ECAP_intrStatusClear(gEcapBaseAddr, ECAP_INT_ALL);
fall = ECAP_timeStampRead(gEcapBaseAddr, ECAP_CAPTURE_EVENT_2);
rise = ECAP_timeStampRead(gEcapBaseAddr, ECAP_CAPTURE_EVENT_1);
/* todo */
}
int32_t hal_ecap_init(void)
{
HwiP_Params hwiPrms;
/* Disable and Clear Interrupts */
ECAP_intrDisable(gEcapBaseAddr, ECAP_INT_ALL);
ECAP_intrStatusClear(gEcapBaseAddr, ECAP_INT_ALL);
/* Disable CAP1-CAP4 register loads */
ECAP_captureLoadingDisable(gEcapBaseAddr);
/* Configure eCAP */
ECAP_counterControl(gEcapBaseAddr, ECAP_COUNTER_STOP);
/* Enable capture mode */
ECAP_operatingModeSelect(gEcapBaseAddr, ECAP_CAPTURE_MODE);
ECAP_continuousModeConfig(gEcapBaseAddr);
ECAP_counterConfig(gEcapBaseAddr, 0);
/* Set polarity of the events to falling, rising, falling, rising edge */
ECAP_captureEvtPolarityConfig(gEcapBaseAddr,
ECAP_CAPTURE_EVENT_RISING,
ECAP_CAPTURE_EVENT_FALLING,
ECAP_CAPTURE_EVENT_RISING,
ECAP_CAPTURE_EVENT_FALLING);
/* Set capture in time difference mode */
ECAP_captureEvtCntrRstConfig(gEcapBaseAddr,
ECAP_CAPTURE_EVENT_RESET_COUNTER_NO_RESET,
ECAP_CAPTURE_EVENT_RESET_COUNTER_NO_RESET,
ECAP_CAPTURE_EVENT_RESET_COUNTER_NO_RESET,
ECAP_CAPTURE_EVENT_RESET_COUNTER_NO_RESET);
ECAP_syncInOutSelect(gEcapBaseAddr, ECAP_SYNC_IN_DISABLE, ECAP_SYNC_OUT_DISABLE);
/* Register & enable ICSSG EnDat PRU FW interrupt */
HwiP_Params_init(&hwiPrms);
hwiPrms.intNum = CONFIG_ECAP0_INTR;
hwiPrms.callback = hal_ecap_it_cb;
hwiPrms.args = 0;
hwiPrms.isPulse = CONFIG_ECAP0_INTR_IS_PULSE;
hwiPrms.isFIQ = FALSE;
HwiP_construct(&gEcapHwiObject, &hwiPrms);
ECAP_prescaleConfig(gEcapBaseAddr, 0);
ECAP_counterControl(gEcapBaseAddr, ECAP_COUNTER_FREE_RUNNING);
/* Enable eCAP module */
ECAP_captureLoadingEnable(gEcapBaseAddr);
/* Enable interrupt */
ECAP_intrEnable(gEcapBaseAddr, ECAP_CEVT2_INT);
return 0;
}