ECAP

The eCAP driver provides API to configure eCAP module. Below are the high level features supported by the driver.

Features Supported

  • Configuration of timestamp capture event

  • Configuration of one-shot/continuous mode

  • Configuration of independent edge polarity (rising / falling edge) selection for all 4 capture events

  • Configuration of interrupt on any of the 4 capture events

  • Configuration of input signal prescaling

  • Configuration of mode to aPWM when not used in capture mode

SysConfig Features

Note

It is strongly recommend to use SysConfig where it is available instead of using direct SW API calls. This will help simplify the SW application and also catch common mistakes early in the development cycle.

SysConfig can be used to configure below parameters apart from common configuration like Clock, MPU, RAT and others.

  • ECAP instances and pin mux configurations.

Features NOT Supported

NA

Important Usage Guidelines

NA

Example Usage

Include the below file to access the APIs

#include <drivers/ecap.h>

ECAP Interrupt Registration

    int32_t             status = SystemP_SUCCESS;
    HwiP_Params         hwiPrms;

    /* Register interrupt */
    HwiP_Params_init(&hwiPrms);
    hwiPrms.intNum      = CONFIG_ECAP0_INTR;
    hwiPrms.callback    = &App_ecapIntrISR;
    hwiPrms.isPulse     = CONFIG_ECAP0_INTR_IS_PULSE;
    status              = HwiP_construct(&gEcapHwiObject, &hwiPrms);
    DebugP_assert(status == SystemP_SUCCESS);

ECAP Operating Mode Configuration

    /* Enable capture mode */
    ECAP_operatingModeSelect(gEcapBaseAddr, ECAP_CAPTURE_MODE);

ECAP One Shot Mode Configuration

    /* One shot mode, stop capture at event 4 */
    ECAP_oneShotModeConfig(gEcapBaseAddr, ECAP_CAPTURE_EVENT4_STOP);

ECAP Capture Event Polarity Configuration

    /* Set polarity of the events to rising, falling, rising, falling edge */
    ECAP_captureEvtPolarityConfig(gEcapBaseAddr,
                                 ECAP_CAPTURE_EVENT_RISING,
                                 ECAP_CAPTURE_EVENT_FALLING,
                                 ECAP_CAPTURE_EVENT_RISING,
                                 ECAP_CAPTURE_EVENT_FALLING);

ECAP Interrupt Service Routine

    /* Clear Ecap Interrupt. */
    ECAP_intrStatusClear(gEcapBaseAddr, ECAP_INT_ALL);
    /* Clear Global Interrupt Flag. */
    ECAP_globalIntrClear(gEcapBaseAddr);

    SemaphoreP_post(&gEcapSyncSemObject);

ECAP Interrupt De-Registration

    HwiP_destruct(&gEcapHwiObject);

API Reference

This file contains the function prototypes for the device abstraction layer for ECAP. It also contains some related macro definitions and some files to be included.

ECAP Operating Mode

ECAP_CAPTURE_MODE

Capture Mode.

ECAP_APWM_MODE

Auxiliary PWM Mode.

ECAP time stamp capture on event

ECAP_CAPTURE_EVENT_1

Time stamp capture on event 1.

ECAP_CAPTURE_EVENT_2

Time stamp capture on event 2.

ECAP_CAPTURE_EVENT_3

Time stamp capture on event 3.

ECAP_CAPTURE_EVENT_4

Time stamp capture on event 4.

ECAP stop capture on event

ECAP_CAPTURE_EVENT1_STOP

Stop capture after event 1.

ECAP_CAPTURE_EVENT2_STOP

Stop capture after event 2.

ECAP_CAPTURE_EVENT3_STOP

Stop capture after event 3.

ECAP_CAPTURE_EVENT4_STOP

Stop capture after event 4.

ECAP APWM Output Polarity

ECAP_APWM_ACTIVE_HIGH

Output Polarity HIGH.

ECAP_APWM_ACTIVE_LOW

Output Polarity LOW.

ECAP Counter Mode

ECAP_COUNTER_STOP

Counter Mode Stop.

ECAP_COUNTER_FREE_RUNNING

Counter Mode Free Running.

ECAP Counter SyncIn Mode

ECAP_SYNC_IN_DISABLE

Disable SyncIn option.

ECAP_ENABLE_COUNTER

Enable Counter to be loaded from the ECAP_CNTPHS register upon SYNCI signal.

ECAP Counter SyncOut Mode

ECAP_SYNC_IN

Select SyncIn event to be the SyncOut signal.

ECAP_PRD_EQ

Select PRD event to be the SyncOut signal.

ECAP_SYNC_OUT_DISABLE

Disable SyncOut Signal.

ECAP Interrupt Sources

ECAP_CEVT1_INT

Capture Event 1 Interrupt Enable.

ECAP_CEVT2_INT

Capture Event 2 Interrupt Enable.

ECAP_CEVT3_INT

Capture Event 3 Interrupt Enable.

ECAP_CEVT4_INT

Capture Event 4 Interrupt Enable.

ECAP_CNTOVF_INT

Counter Overflow Interrupt Enable.

ECAP_PRDEQ_INT

Period Equal Interrupt Enable.

ECAP_CMPEQ_INT

Compare Equal Interrupt Enable.

ECAP Global Interrupt Source

ECAP_GLOBAL_INT

Global Interrupt Source Clear Flag.

ECAP Capture Event Polarity

ECAP_CAPTURE_EVENT_RISING

Capture Event Rising Edge.

ECAP_CAPTURE_EVENT_FALLING

Capture Event Falling Edge.

ECAP Counter Reset On Capture Event

ECAP_CAPTURE_EVENT_RESET_COUNTER_NO_RESET

No counter reset upon Capture Event.

ECAP_CAPTURE_EVENT_RESET_COUNTER_RESET

Counter reset upon Capture Event.

Functions

void ECAP_captureLoadingEnable(uint32_t baseAddr)

This function enables capture loading.

Parameters:

baseAddr – It is the Memory address of the ECAP instance used.

void ECAP_captureLoadingDisable(uint32_t baseAddr)

This function disables capture loading.

Parameters:

baseAddr – It is the Memory address of the ECAP instance used.

void ECAP_prescaleConfig(uint32_t baseAddr, uint32_t prescale)

This function configures prescale value.

Prescale can take any integer value between 0 to 31

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • prescale – It is the value which is used to prescale the incoming input.

void ECAP_operatingModeSelect(uint32_t baseAddr, uint32_t modeSelect)

This function configures ecapture module to operate in capture mode or in APWM mode.

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • modeSelect

    It is the value which determines whether ecapture module to operate in capture mode or in APWM mode.

    modeSelect can take one of the following macros.

uint32_t ECAP_timeStampRead(uint32_t baseAddr, uint32_t capEvtFlag)

This function returns time-stamp for a given capture event.

capEvtFlag can take one of the following macros.

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • capEvtFlag – It is the value which determines for which capture event time-stam has to returned.

Returns:

Returns the time-stamp for given capure event.

void ECAP_counterConfig(uint32_t baseAddr, uint32_t countVal)

This function configures the counter register which is used as Capture Time base.

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • countVal – It is counter value to be configured.

void ECAP_captureEvtPolarityConfig(uint32_t baseAddr, uint32_t capEvt1pol, uint32_t capEvt2pol, uint32_t capEvt3pol, uint32_t capEvt4pol)

This function configures Capture Event polarity.

capEvtpol variables can take one of the following macros.

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • capEvt1pol – It determines whether Capture Event1 has to be generated on rising edge or falling edge of pulse.

  • capEvt2pol – It determines whether Capture Event2 has to be generated on rising edge or falling edge of pulse.

  • capEvt3pol – It determines whether Capture Event3 has to be generated on rising edge or falling edge of pulse.

  • capEvt4pol – It determines whether Capture Event4 has to be generated on rising edge or falling edge of pulse.

void ECAP_captureEvtCntrRstConfig(uint32_t baseAddr, uint32_t counterRst1, uint32_t counterRst2, uint32_t counterRst3, uint32_t counterRst4)

This function enables reset of the counters upon Capture Events.

counterRst variables can take one of the following macros.

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • counterRst1 – It determines whether counter has to be reset upon Capture Event1.

  • counterRst2 – It determines whether counter has to be reset upon Capture Event2.

  • counterRst3 – It determines whether counter has to be reset upon Capture Event3.

  • counterRst4 – It determines whether counter has to be reset upon Capture Event4.

void ECAP_continousModeConfig(uint32_t baseAddr)

This function configures ECAP to Continuous mode.

This API is valid only if ECAP is configured to Capture Mode.It has no significance when ECAP is configured in APWM mode.

Parameters:

baseAddr – It is the Memory address of the ECAP instance used.

void ECAP_oneShotModeConfig(uint32_t baseAddr, uint32_t stopVal)

This function configures ECAP to One-shot mode and also stop value for this mode.

This API is valid only if ECAP is configured to Capture Mode.It has no significance when ECAP is configured in APWM mode.

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • stopVal

    It is the number of captures allowed to occur before Capture register(1-4) are frozen.

    stopVal can take one of the following macros.

void ECAP_oneShotReArm(uint32_t baseAddr)

This function configures ECAP to One-Short Re-arming.

When this API is invoked following things happen.

  1. Resets Mod4 counter to zero.

  2. Un-freezes the Mod4 counter.

  3. Enables capture register loads.

Parameters:

baseAddr – It is the Memory address of the ECAP instance used.

void ECAP_APWM_polarityConfig(uint32_t baseAddr, uint32_t flag)

This function configures output polarity for APWM output.

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • flag

    It is the value which determines the output polarity for APWM output.

    flag can take one of the following macros.

void ECAP_counterControl(uint32_t baseAddr, uint32_t flag)

This function configures counter to stop or free running based on its input argument flag.

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • flag

    It is the value which determine counter to be configured to stop or free running.

    flag can take one of the following macros.

void ECAP_syncInOutSelect(uint32_t baseAddr, uint32_t syncIn, uint32_t syncOut)

This function configures Sync-In and Sync-Out.

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • syncIn

    It is the value which determines whether to disable syncIn or to enable counter to be loaded from CNTPHS register upon a SYNCI signal.

    syncIn can take one of the following macros.

  • syncOut

    It is the value which select type of syncOut signal (i.e select syncIn event to be the Sync-Out signal, select PRD_eq event to be Sync-Out signal).

    syncOut can take one of the following macros.

void ECAP_APWM_captureConfig(uint32_t baseAddr, uint32_t compareVal, uint32_t periodVal)

When ECAP module is configured in APWM mode capture 1 and capture 2 registers are used as period and compare register.This function configures compare and period values to this register.

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • compareVal – It is the Compare value to be configured.

  • periodVal – It is the Period value to be configured.

void ECAP_APWM_shadowCaptureConfig(uint32_t baseAddr, uint32_t compareVal, uint32_t periodVal)

This function configures the Shadow register.

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • compareVal – It is the Compare value to be configured.

  • periodVal – It is the Period value to be configured.

void ECAP_counterPhaseValConfig(uint32_t baseAddr, uint32_t cntPhaseVal)

This function configures the counter phase value.

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • cntPhaseVal – It is the counter phase value to be programmed for phase lag/lead.

void ECAP_globalIntrClear(uint32_t baseAddr)

This function clears global interrupt and enables the generation of interrupts if any of the event interrupt are enabled and corresponding event interrupt flag is set.

Parameters:

baseAddr – It is the Memory address of the ECAP instance used.

void ECAP_intrEnable(uint32_t baseAddr, uint32_t flag)

This function enables the specified interrupts.

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • flag

    It is the value which specifies the interrupts to be enabled.

    flag can take one of the following macros.

void ECAP_intrDisable(uint32_t baseAddr, uint32_t flag)

This function disables the specified interrupts.

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • flag

    It is the value which specifies the interrupts to be disabled.

    flag can take one of the following macros.

uint32_t ECAP_getIntrStatus(uint32_t baseAddr, uint32_t flag)

This function returns the status specified interrupts.

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • flag

    It is the value which specifies the status of interrupts to be returned.

    flag can take one of the following macros.

Returns:

Status of the specified interrupts.

void ECAP_intrStatusClear(uint32_t baseAddr, uint32_t flag)

This function clears of the status specified interrupts.

Parameters:
  • baseAddr – It is the Memory address of the ECAP instance used.

  • flag

    It is the value which specifies the status of interrupts to be cleared.

    flag can take one of the following macros.

uint32_t ECAP_peripheralIdGet(uint32_t baseAddr)

This function returns the peripheral ID.

Parameters:

baseAddr – It is the Memory address of the ECAP instance used.

Returns:

Peripheral ID.