iLLD_TC27xC  1.0
How to use the CCU6 ICU Interface driver?
Collaboration diagram for How to use the CCU6 ICU Interface driver?:

The ICU interface driver provides a default CCU6 configuration for capturing the input from the selected channel

User can select the various configuration options that hardware allows

In the following sections it will be described, how to integrate the driver into the application framework.

Preparation

Include Files

Include following header file into your C code:

Variables

Declare the ICU handle and channel handle as global variables in your C code:

// used globally
static IfxCcu6_Icu icu;
static IfxCcu6_IcuChannel icuChannel;

Interrupt Handler Installation

See also How to define Interrupts?

Define priority for the Interrrupt handler. This is normally done in the Ifx_IntPrioDef.h file:

// priorities are normally defined in Ifx_IntPrioDef.h
#define IFX_INTPRIO_CCU6 1

Add the interrupt service routine to your C code.

IFX_INTERRUPT(ccu60ISR_Icu, 0, IFX_INTPRIO_CCU6)
{
//user code
}

Finally install the interrupt handlers in your initialisation function:

// install interrupt handlers
IfxCpu_Irq_installInterruptHandler(&ccu60ISR_Icu, IFX_INTPRIO_CCU6);

Module Initialisation

The module can be initialised in two ways, as a stand alone driver or in conjunction with Timer driver The module initialisation can be done in the same function. Here an example:

// ---- when not using inconjunction with Timer driver ---- //
// create configuration
IfxCcu6_Icu_initModuleConfig(&icuConfig, &MODULE_CCU60);
// configure the frequency of the timer in case of internal start
icuConfig.frequency = 400000;
// configure the period of the timer
icuConfig.period = 100;
// configure the clock for internal mode
// configure count operation
icuConfig.counterValue = 0;
// initialize the module
IfxCcu6_Icu_initModule(&icu, &icuConfig);
// -------------------------------------------------------- //
// ---- when not using inconjunction with Timer driver ---- //
// after initialising the timer
IfxCcu6_TimerConfig timerConfig;
IfxCcu6_Timer_initModule(&timer, &timerConfig); // e.g. Timer 12 is specified previously in timerConfig.
// -------------------------------------------------------- //
// create Icu channel config
IfxCcu6_Icu_channelConfig icuChannelConfig;
IfxCcu6_Icu_initChannelConfig(&icuChannelConfig, &MODULE_CCU60);
// ---- when using inconjunction with Timer driver ---- //
icuChannelConfig.timer = (Timer*)&timer;
// ---------------------------------------------------- //
// configure the channel
icuChannelConfig.channelNumber = IfxCcu6_T12Channel_0;
// configure the interrupts
icuChannelConfig.interrupt.interruptSource = IfxCcu6_InterruptSource_cc60RisingEdge;
icuChannelConfig.interrupt.serviceRequest = IfxCcu6_ServiceRequest_sR2;
icuChannelConfig.interrupt.priority = IFX_INTRPRIO_CCU6;
icuChannelConfig.interrupt.typeOfService = IfxSrc_Tos_cpu0;
// ---- when not using inconjunction with Timer driver ---- //
// configure input and output triggers
icuChannelConfig.trigger.extInputTrigger = IfxCcu60_T12HRB_P00_7_IN;
icuChannelConfig.trigger.extInputTriggerMode = IfxCcu6_ExternalTriggerMode_risingEdge;
// -------------------------------------------------------- //
// pin configuration, in case of multi input capture mode select the respective CC6xIn and CCPOSxIn pins of the selected channel
const IfxCcu6_Icu_Pins pins = {
NULL, // CC61In pin not used
NULL, // CC62In pin not used
NULL, // CCPOS0In pin not used
NULL, // CCPOS1In pin not used
NULL, // CCPOS2In pin not used
IfxPort_InputMode_pullUp
};
IcuConfig.pins = &pins;
// configure multi input capture mode
icuChannelConfig->multiInputCaptureEnabled = FALSE;
// initialize the channel
IfxCcu6_Icu_initChannel(&icuChannel, &icuChannelConfig);

The Icu is ready for use now!

Control

The ICU driver provides simple to use Capture Control functions

This means: you can start and stop the capture process, and you can also get a time stamp at any point of time during the capture process

Start Capture

Stop Capture

Get time stamp at any point of time during the capture process (can also be used in ISR)

// assumed to be declared globally
// uint32 timeStamp[100] = 0;
// store the time stamp in an array
timeStamp[i] = IfxCcu6_Icu_getTimeStamp(&icuChannel);