TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer...

90
Home TIMER Apps Here is a list of all modules: License Terms and Copyright Information Abbreviations and Definitions Overview Architecture Description APP Configuration Parameters Enumerations Data structures Methods Usage Release History

Transcript of TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer...

Page 1: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Home

TIMER

Apps

Hereisalistofallmodules:

LicenseTermsandCopyrightInformationAbbreviationsandDefinitionsOverviewArchitectureDescriptionAPPConfigurationParametersEnumerationsDatastructuresMethodsUsageReleaseHistory

Page 2: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Home

TIMER

LicenseTermsandCopyrightInformation

LicenseTermsandCopyrightInformation

Copyright(c)2015,InfineonTechnologiesAGAllrightsreserved.

Redistributionanduseinsourceandbinaryforms,withorwithoutmodification,arepermittedprovidedthatthefollowingconditionsaremet:

Redistributionsofsourcecodemustretaintheabovecopyrightnotice,thislistofconditionsandthefollowingdisclaimer.Redistributionsinbinaryformmustreproducetheabovecopyrightnotice,thislistofconditionsandthefollowingdisclaimerinthedocumentationand/orothermaterialsprovidedwiththedistribution.Neitherthenameofthecopyrightholdersnorthenamesofitscontributorsmaybeusedtoendorseorpromoteproductsderivedfromthissoftwarewithoutspecificpriorwrittenpermission.

THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS"ASIS"ANDANYEXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THEIMPLIEDWARRANTIESOFMERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSEAREDISCLAIMED.INNOEVENTSHALLTHECOPYRIGHTHOLDERORCONTRIBUTORSBELIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,SPECIAL,EXEMPLARY,ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENTOFSUBSTITUTEGOODSORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,ORTORT

Page 3: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUTOFTHEUSEOFTHISSOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE.

Toimprovethequalityofthesoftware,usersareencouragedtosharemodifications,enhancementsorbugfixeswithInfineonTechnologiesAG([email protected]).

Page 4: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Home

TIMER

AbbreviationsandDefinitions

AbbreviationsandDefinitions

Abbreviations:DAVE™ DigitalApplicationVirtualEngineerAPP DAVE™ApplicationAPP DAVEApplicationAPI ApplicationProgrammingInterfaceGUI GraphicalUserInterfaceMCU MicrocontrollerUnitSW SoftwareHW HardwareLLD LowLevelDriverI/O Input/OutputCCU CaptureCompareUnit

Definitions:Singleton OnlysingleinstanceoftheAPPispermittedSharable ResourcesharingwithotherAPPsispermittedinitProvider ProvidestheinitializationroutinePhysicalconnectivity

Hardwareinter/intraperipheral(constant)signalconnection

Conditionalconnectivity

Constrainedhardwareinter/intraperipheralsignalconnection

Aggregation Indicatesconsumptionoflowlevel(dependent)DAVE™APPs

Page 5: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous
Page 6: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Home

TIMER

Overview

Overview

TheTIMERAPPprovidesaccuratehardwaretimerusingonetimersliceofCCU4orCCU8peripheral.Andprovidesprovidethefunctionalitybelow:

1. Continuouseventgenerationforagiventimeinterval.2. GeneratesmoreaccuratedelayusingHardwaretimer.3. Setsthedesiredtimeintervalatruntime(intermsofmicro-

seconds).4. Connectionoftimerintervaleventtootherperipheralsasatrigger

sourceorforinterruptgeneration(usingtheDAVEHWSignalConnections)

Page 7: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Figure1:OverviewofTIMERAPP

ThefigureaboveshowsthefunctionaloverviewandusecasesoftheTIMERAPP.

Figure2:HardwareandSoftwareconnectivityofTIMERAPP

ThefigureaboveshowsthelayeredarchitectureoftheTIMERAPPinDAVE™.XMCcontrollersprovidetheCCU4orCCU8module.Eachmoduleishavingfour16-bittimers.TheLLDlayerprovidesabstractionforthesehardwaremodules.TheTIMERAPPusesCCU4orCCU8andGPIOLLDsandotherdependentAPPslikeGLOBAL_CCUx(x=[4,8])andCLOCK_XMCx(x=[1,4])forthefunctionality.

SupportedDevicesTheAPPsupportsbelowdevices:

1. XMC4800/XMC4700Series

Page 8: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

2. XMC4500Series3. XMC4300Series4. XMC4400Series5. XMC4200/XMC4100Series6. XMC1400Series7. XMC1300Series8. XMC1200Series9. XMC1100Series

References

1. XMC4800/XMC4700ReferenceManual2. XMC4500ReferenceManual3. XMC4400ReferenceManual4. XMC4300ReferenceManual5. XMC4200/XMC4100ReferenceManual6. XMC1400ReferenceManual7. XMC1300ReferenceManual8. XMC1200ReferenceManual9. XMC1100ReferenceManual

Page 9: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Home

TIMER

ArchitectureDescription

ArchitectureDescription

Figure1:ArchitectureofTIMERAPP

ThefigureaboverepresentstheinternalsoftwarearchitectureoftheTIMERAPP.ATIMERAPPinstanceexistsinaDAVE™projectwithfixedattributesasshown.EachinstanceofthisAPPconfiguresone

Page 10: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

CCUslicetimerintheMCU.ThisinadditionrequirestheconsumptionoftheGLOBAL_CCUx(x=[4,8])andCLOCKAPPSforitsconfigurationandfunctioning.TheTIMERAPPalsoprovidesoutputsignalforinter-peripheralconnections.

AninstantiatedAPP(aftercodegeneration)generatesaspecificdatastructurewiththeGUIconfiguration.ThenameofthisdatastructurecanbemodifiedbychangingtheAPPinstancelabel(e.g.changelabelfromdefaultTIMER_0toGAME_DELAY).

Signals:

ThefollowingtablepresentsthesignalsprovidedbytheAPPforconnection.ThesignalgivestheflexibilitytoconfigureandextendtheconnectivitytootherAPPs.

Table1:APPI/Osignals

SignalName Input/Output Availability Description

event_time_interval Output Conditional

Timeintervaleventsignal:Uponenablingthe"Timeintervalevent"inGUI,signalispopulated.

ConnectwithanINTERRUPTAPPtogeneratetheinterruptforeachtimeinterval.Connectwith

Page 11: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

otherperipherals(e.g.ADC,ERU,DMA,DAC,POSIF)asatriggersource.

APPSConsumed:

ThefollowingtablepresentstheAPPsconsumedtosupportthefunctionality:

Table2:APPsConsumed

APPName Consumption

GLOBAL_CCU4 Conditionallyconsumedif"CCU4"isselectedinUIfield"Selecttimermodule"

Page 12: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

GLOBAL_CCU8 Conditionallyconsumedif"CCU8"isselectedinUIfield"Selecttimermodule"

Page 13: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Home

TIMER

APPConfigurationParameters

AppConfigurationParameters

Figure1:GeneralSettings

Figure2:EventSettings

Page 14: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous
Page 15: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Home

TIMER

Enumerations

enumTIMER_MODULE{TIMER_MODULE_CCU4=0U,TIMER_MODULE_CCU8}

ThetypeidentifiestheCCU4orCCU8timerselected.More...

enumTIMER_STATUS{TIMER_STATUS_SUCCESS=0U,TIMER_STATUS_FAILURE}

statusoftheTIMERAPPMore...typedefenumTIMER_MODULE TIMER_MODULE_t

ThetypeidentifiestheCCU4orCCU8timerselected.

typedefenumTIMER_STATUS TIMER_STATUS_t statusoftheTIMERAPP

Page 16: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

EnumerationTypeDocumentation

enumTIMER_MODULE

ThetypeidentifiestheCCU4orCCU8timerselected.

Enumerator:

TIMER_MODULE_CCU4 CCU4isselected

TIMER_MODULE_CCU8 CCU8isselected

Definitionatline88offileTIMER.h.

enumTIMER_STATUS

statusoftheTIMERAPP

Enumerator:

TIMER_STATUS_SUCCESS Statussuccess

TIMER_STATUS_FAILURE Statusfailure

Definitionatline97offileTIMER.h.

Page 17: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

HomeDataStructures

TIMER

Datastructures

Page 18: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

DataStructures

struct TIMER

InitializationparametersoftheTIMERAPP.More...

typedefstructTIMER TIMER_t InitializationparametersoftheTIMERAPP.

Page 19: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Home

TIMER

Methods

DAVE_APP_VERSION_t TIMER_GetAppVersion(void) GetTIMERAPPversion.

TIMER_STATUS_t TIMER_Init(TIMER_t*consthandle_ptr)

InitializesaTIMERwithgeneratedconfiguration.

TIMER_STATUS_t TIMER_Start(TIMER_t*consthandle_ptr)

StartsthetimeriftheinitializationoftheAPPissuccessful.

TIMER_STATUS_t TIMER_Stop(TIMER_t*consthandle_ptr) StopstheTIMER,ifitisrunning.

uint32_t TIMER_GetTime(TIMER_t*consthandle_ptr)

Returnsthecurrenttimeinmicrosecondsbyscalingwith100.

TIMER_STATUS_t TIMER_Clear(TIMER_t*consthandle_ptr) Clearsthetimerregister.

bool TIMER_GetTimerStatus(TIMER_t*consthandle_ptr)

Returnstherunningstateofthetimer.

TIMER_STATUS_t TIMER_SetTimeInterval(TIMER_t*consthandle_ptr,uint32_ttime_interval)

Setthenewtimeintervalfortheeventgeneration,bycheckingwiththesupportedrange.

bool TIMER_GetInterruptStatus(TIMER_t*consthandle_ptr)

Indicatestheoccurrenceoftimeintervalevent.

Page 20: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

void TIMER_ClearEvent(TIMER_t*consthandle_ptr)

Clearstheperiodmatchinterruptstatusofthegiventimer.

Methods

Page 21: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

FunctionDocumentation

TIMER_STATUS_tTIMER_Clear ( TIMER_t*const handle_ptr )

Clearsthetimerregister.

Parameters:handle_ptr pointertotheTIMERAPPconfiguration.

Returns:TIMER_STATUS_tTIMER_STATUS_SUCCESS:ifclearissuccessfulTIMER_STATUS_FAILURE:iftimerisnotinitializedandclearisrequested

Description:TIMER_Clear()clearsthetimerregistersothatnextcyclestartsfromresetvalue.

ExampleUsage:

#include<DAVE.h>

intmain(void)

{

DAVE_STATUS_tinit_status;

TIMER_STATUS_ttimer_status;

init_status=DAVE_Init();//TIMER_Init(&TI

MER_0)willbecalledfromDAVE_Init()

if(init_status==DAVE_STATUS_SUCCESS)

{

timer_status=TIMER_Start(&TIMER_0);

}

if(TIMER_GetTimerStatus(&TIMER_0))

Page 22: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

{

timer_status=TIMER_Stop(&TIMER_0);

}

timer_status=TIMER_Clear(&TIMER_0);

while(1)

{

}

return1;

}

Definitionatline415offileTIMER.c.

ReferencesTIMER::timer_module,TIMER_MODULE_CCU4,TIMER_MODULE_CCU8,TIMER_STATUS_FAILURE,andTIMER_STATUS_SUCCESS.

voidTIMER_ClearEvent ( TIMER_t*const handle_ptr )

Clearstheperiodmatchinterruptstatusofthegiventimer.

Parameters:handle_ptr pointertotheTIMERAPPconfiguration.

Returns:None

Description:Foreachoccurrenceofthetimeintervalevent,ithastobeclearedthroughsoftwareonly.Sonexteventisconsideredasnew.

Page 23: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

ExampleUsage:

#include<DAVE.h>

intmain(void)

{

DAVE_STATUS_tstatus;

status=DAVE_Init();//Initia

lizationofDAVEAPPs

while(1U)

{

}

return1;

}

voidTimetick_Handler(void)

{

TIMER_ClearEvent(&TIMER_0);

}

Definitionatline350offileTIMER.c.

ReferencesTIMER::timer_module,TIMER_MODULE_CCU4,andTIMER_MODULE_CCU8.

DAVE_APP_VERSION_tTIMER_GetAppVersion ( void )

GetTIMERAPPversion.

Returns:DAVE_APP_VERSION_tAPPversioninformation(major,minorandpatchnumber)

Description:

Page 24: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

ThefunctioncanbeusedtocheckapplicationsoftwarecompatibilitywithaspecificversionoftheAPP.

ExampleUsage:

#include<DAVE.h>

intmain(void)

{

DAVE_STATUS_tstatus;

DAVE_APP_VERSION_tapp_version;

status=DAVE_Init();//TIMER_Init()i

scalledfromDAVE_Init()

app_version=TIMER_GetAppVersion();

if(app_version.major!=4U)

{

//Probably,nottherightversion.

}

while(1U)

{

}

return1;

}

Definitionatline97offileTIMER.c.

boolTIMER_GetInterruptStatus ( TIMER_t*const handle_ptr )

Indicatestheoccurrenceoftimeintervalevent.

Parameters:

Page 25: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

handle_ptr pointertotheTIMERAPPconfiguration.

Returns:booltrue:ifeventsetfalse:ifeventisnotset

Description:Thestatusreturned,canbeutilizedtogeneratethedelayfunction.

ExampleUsage:

#include<DAVE.h>

#defineTIMER_DELAY_MUL_FACTOR100000U//Conver

tsmicrosecondstomillisecondswithmultiplica

tionfactorfor

//TIMER_

GetInterruptStatus().

voidTIMER_Delay(uint32_t);

intmain(void)

{

DAVE_STATUS_tinit_status;

TIMER_STATUS_tstatus;

uint32_tdelay_val;//delayvalueintermsmil

liseconds

init_status=DAVE_Init();//TIMER_Init(&TI

MER_0)willbecalledfromDAVE_Init()

TIMER_ClearEvent(&TIMER_0);

if(init_status==DAVE_STATUS_SUCCESS)

{

delay_val=1000;//1000milliseconds

TIMER_Delay(delay_val);

Page 26: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

}

while(1)

{

}

return1;

}

voidTIMER_Delay(uint32_tdelay_val)

{

uint32_tdelay_cnt;

delay_cnt=delay_val*TIMER_DELAY_MUL_FACTOR

;

TIMER_SetTimeInterval(&TIMER_0,delay_cnt);

TIMER_Start(&TIMER_0);

while(!TIMER_GetInterruptStatus(&TIMER_0));

TIMER_Stop(&TIMER_0);

}

Definitionatline324offileTIMER.c.

ReferencesTIMER::timer_module,TIMER_MODULE_CCU4,andTIMER_MODULE_CCU8.

uint32_tTIMER_GetTime ( TIMER_t*const handle_ptr )

Returnsthecurrenttimeinmicrosecondsbyscalingwith100.

Page 27: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Parameters:handle_ptr pointertotheTIMERAPPconfiguration.

Returns:uint32_ttimeinmicroseconds

Description:Byusingprescalerandfrequencyandtimerregistervalue,thisAPIcalculatesthecurrenttimeinmicroseconds.Thenthevalueisscaledwith100,beforereturning.

ExampleUsage:

#include<DAVE.h>

intmain(void)

{

DAVE_STATUS_tinit_status;

TIMER_STATUS_ttimer_status;

uint32_telapsed_time;

init_status=DAVE_Init();//TIMER_Init(&TI

MER_0)willbecalledfromDAVE_Init()

if(init_status==DAVE_STATUS_SUCCESS)

{

timer_status=TIMER_Start(&TIMER_0);

}

timer_status=TIMER_Stop(&TIMER_0);

elapsed_time=TIMER_GetTime(&TIMER_0);

while(1)

{

}

return1;

}

Page 28: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Definitionatline374offileTIMER.c.

ReferencesTIMER::timer_module,TIMER_MODULE_CCU4,andTIMER_MODULE_CCU8.

boolTIMER_GetTimerStatus ( TIMER_t*const handle_ptr )

Returnstherunningstateofthetimer.

Parameters:handle_ptr pointertotheTIMERAPPconfiguration.

Returns:booltrue:ifthetimerisrunningfalse:ifthetimerisnotrunning

Description:TIMER_GetTimerStatus()readstherunbitofthetimertoindicatetheactualstateoftheTIMER.

ExampleUsage:

#include<DAVE.h>

intmain(void)

{

DAVE_STATUS_tinit_status;

TIMER_STATUS_ttimer_status;

init_status=DAVE_Init();//TIMER_Init(&TI

MER_0)willbecalledfromDAVE_Init()

if(init_status==DAVE_STATUS_SUCCESS)

{

timer_status=TIMER_Start(&TIMER_0);

Page 29: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

}

if(TIMER_GetTimerStatus(&TIMER_0))

{

while(TIMER_GetTimerStatus(&TIMER_0));

timer_status=TIMER_Stop(&TIMER_0);

}

while(1)

{

}

return1;

}

Definitionatline219offileTIMER.c.

ReferencesTIMER::timer_module,TIMER_MODULE_CCU4,andTIMER_MODULE_CCU8.

ReferencedbyTIMER_SetTimeInterval(),andTIMER_Stop().

TIMER_STATUS_tTIMER_Init ( TIMER_t*const handle_ptr )

InitializesaTIMERwithgeneratedconfiguration.

Parameters:handle_ptr pointertotheTIMERAPPconfiguration.

Returns:TIMER_STATUS_tTIMER_STATUS_SUCCESS:ifinitializationissuccessfulTIMER_STATUS_FAILURE:ifinitializationisfailed

Description:

Page 30: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

EnabletheclockforthesliceandinvoketheLLDAPIwithgeneratedconfigurationhandle.LoadthePeriod,CompareandPrescalershadowregisterswiththegeneratedvaluesandenabletheshadowtransferrequest.ThisloadsthevaluesintotheactualregistersandstarttheTIMERbasedontheconfiguration.If"Startafterinitialization"isnotenabled,TIMER_Start()canbeinvokedtostartthetimer.

ExampleUsage:

#include<DAVE.h>

intmain(void)

{

DAVE_STATUS_tinit_status;

init_status=DAVE_Init();//TIMER_Init(&TI

MER_0)willbecalledfromDAVE_Init()

while(1)

{

}

return1;

}

Definitionatline112offileTIMER.c.

ReferencesTIMER::timer_module,TIMER_MODULE_CCU4,TIMER_MODULE_CCU8,andTIMER_STATUS_SUCCESS.

TIMER_STATUS_tTIMER_SetTimeInterval ( TIMER_t*const handle_ptruint32_t time_interval)

Page 31: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Setthenewtimeintervalfortheeventgeneration,bycheckingwiththesupportedrange.

Parameters:handle_ptr pointertotheTIMERAPPconfiguration.time_interval newtimeintervalvalueinmicroseconds.

Returns:TIMER_STATUS_tTIMER_STATUS_SUCCESS:SettingnewtimeintervalvalueissuccessfulTIMER_STATUS_FAILURE:NewtimevalueisnotinrangeofsupportedtimevalueTimerisinrunningcondition

Description:Basedonthetimerinterval,prescalervalueiscalculatedfortheCCUtimer.ByusingthisprescalerandtimeintervalvaluesPeriodvalueiscalculated.Theperiodvalueisupdatedintotheshadowregisterandshadowtransferrequestisenabled.Timerhastobestoppedbeforeupdatingthetimeinterval.

Note:Inputtimeintervalvaluehastobescaledby100totheactualrequiredvalue.e.g.:requiredtimerintervalvalue=30.45microsecondsInputvaluetotheAPI=30.45*100=3045

ExampleUsage:

#include<DAVE.h>

#include<xmc_gpio.h>//GPIO

LLDheader,thiscontainstheinterfaceforPort

functionality

#defineTIMER_GPIO_PORTXMC_GPIO_PORT0//PORT0

Page 32: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Address

#defineTIMER_GPIO_PIN0U//Pinn

umber

#defineTIMER_500MS500000*100U

volatileuint32_tcount=0U;//count

variabletochangethetimetickinterval

uint32_tshadow_transfer_msk;//Thisi

stogeneratetheslicespecificshadowtransfer

mask

constXMC_GPIO_CONFIG_tGPIO_0_config=

{

.mode=XMC_GPIO_MODE_OUTPUT_PUSH_PULL,

.output_level=XMC_GPIO_OUTPUT_LEVEL_LOW,

};

intmain(void)

{

DAVE_STATUS_tstatus;

XMC_GPIO_Init(TIMER_GPIO_PORT,TIMER_GPIO_PIN,

&GPIO_0_config);

status=DAVE_Init();//Initia

lizationofDAVEAPPs

while(1U)

{

}

return1;

}

voidTimetick_Handler(void)

{

count++;

Page 33: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

TIMER_ClearEvent(&TIMER_0);

XMC_GPIO_ToggleOutput(TIMER_GPIO_PORT,TIMER_GP

IO_PIN);

if(count>10)

{

count=0U;

TIMER_Stop(&TIMER_0);

status=TIMER_SetTimeInterval(&TIMER_0,TIME

R_500MS);

if(status==TIMER_STATUS_SUCCESS)

{

TIMER_Start(&TIMER_0);

}

}

}

Definitionatline250offileTIMER.c.

ReferencesTIMER::period_value,TIMER_GetTimerStatus(),TIMER::timer_max_value_us,TIMER::timer_min_value_us,TIMER::timer_module,TIMER_MODULE_CCU4,TIMER_MODULE_CCU8,TIMER_STATUS_FAILURE,andTIMER_STATUS_SUCCESS.

TIMER_STATUS_tTIMER_Start ( TIMER_t*const handle_ptr )

StartsthetimeriftheinitializationoftheAPPissuccessful.

Parameters:handle_ptr pointertotheTIMERAPPconfiguration.

Returns:

Page 34: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

TIMER_STATUS_tTIMER_STATUS_SUCCESS:iftimerstartissuccessfulTIMER_STATUS_FAILURE:iftimerstartisfailed

Description:If"Startafterinitialization"isnotenabled,TIMER_Start()canbeinvokedtostartthetimer.TIMER_Stop()canbeusedtostoptheTimer.Noneedtoreconfigurethetimertostartagain.

ExampleUsage:

#include<DAVE.h>

intmain(void)

{

DAVE_STATUS_tinit_status;

TIMER_STATUS_ttimer_status;

init_status=DAVE_Init();//TIMER_Init(&TI

MER_0)willbecalledfromDAVE_Init()

if(init_status==DAVE_STATUS_SUCCESS)

{

timer_status=TIMER_Start(&TIMER_0);

}

while(1)

{

}

return1;

}

Definitionatline145offileTIMER.c.

ReferencesTIMER::timer_module,TIMER_MODULE_CCU4,TIMER_MODULE_CCU8,TIMER_STATUS_FAILURE,andTIMER_STATUS_SUCCESS.

Page 35: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

TIMER_STATUS_tTIMER_Stop ( TIMER_t*const handle_ptr )

StopstheTIMER,ifitisrunning.

Parameters:handle_ptr pointertotheTIMERAPPconfiguration.

Returns:TIMER_STATUS_tTIMER_STATUS_SUCCESS:iftimerisrunningandstopissuccessfulTIMER_STATUS_FAILURE:iftimerisinidlestate,andstopiscalled

Description:ClearstheTimerrunbittostop.Nofurthereventisgenerated.

ExampleUsage:

#include<DAVE.h>

intmain(void)

{

DAVE_STATUS_tinit_status;

TIMER_STATUS_ttimer_status;

init_status=DAVE_Init();//TIMER_Init(&TI

MER_0)willbecalledfromDAVE_Init()

if(init_status==DAVE_STATUS_SUCCESS)

{

timer_status=TIMER_Start(&TIMER_0);

}

if(timer_status==TIMER_STATUS_SUCCESS)

{

Page 36: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

while(TIMER_GetInterruptStatus(&TIMER_0));

timer_status=TIMER_Stop(&TIMER_0);

}

while(1)

{

}

return1;

}

Definitionatline182offileTIMER.c.

ReferencesTIMER_GetTimerStatus(),TIMER::timer_module,TIMER_MODULE_CCU4,TIMER_MODULE_CCU8,TIMER_STATUS_FAILURE,andTIMER_STATUS_SUCCESS.

Page 37: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Home

TIMER

Usage

Usage

ThisexampledemonstratesthegenerationofeventsforthedefinedtimeintervalsusingTIMERAPPconsideringCCU4HWtimermodule.InitiallytheAPPisconfiguredtogeneratetheeventsforeveryonesecond.Andaftergettingthe10events(10seconds),timeintervalisupdatedinISRwith0.5second.GenerationofeventsisindicatedbytogglinganLED.

InstantiatetherequiredAPPsDraganinstanceofTIMER,INTERRUPTandDIGITAL_IOAPPs.UpdatethefieldsintheGUIoftheseAPPswiththefollowingconfiguration.

ConfiguretheAPPsTIMERAPP:

1. SelectCCU4moduleNote:IfallthetimersintheCCU4moduleareconsumed,

Page 38: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

manuallyswitchoneoftheexistinginstancesofAPPstoCCU8andtryagain.

2. Setthetimeintervalto1secTimeinterval[usec]:1000000

DIGITAL_IOAPP:

3. Setpindirectiontooutputbychoosing-Pindirection:Input/Output

INTERRUPTAPP:

Page 39: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

4. EnteranappropriateISRhandlenamefortheTimeintervalevent.e.g.Time_Interval_EventNote:ThisISRshallbedefinedbyuserapplication(main.c)

SignalConnectionEstablishaHWsignalconnectionbetweentheTIMERandtheINTERRUPTAPPtoensureTIMEReventsgoestoINTERRUPT.

5. ConnectTIMER_0/event_time_interval->INTERRUPT_0/sr_irqtoensureassigningISRnodetothetime_intervalevent.

Manualpinallocation

Page 40: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

6. Selectthepintobetoggled(on-boardLED)Note:Thepinnumberisspecifictothedevelopmentboardchosentorunthisexample.ThepinshownintheimageabovemaynotbeavailableoneveryXMCbootkit.Ensurethataproperpinisselectedaccordingtotheboard.

GeneratecodeFilesaregeneratedhere:`<project_name>/Dave/Generated/'(`project_name'isthenamechosenbytheuserduringprojectcreation).APPinstancedefinitionsandAPIsaregeneratedonlyaftercodegeneration.

Note:CodemustbeexplicitlygeneratedforeverychangeintheGUIconfiguration.Important:AnymanualmodificationtoAPPspecificfileswillbeoverwrittenbyasubsequentcodegenerationoperation.

SampleApplication(main.c)

#include<DAVE.h>

uint32_tevent_count;

intmain(void)

{

Page 41: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

DAVE_STATUS_tstatus;

status=DAVE_Init();

if(status==DAVE_STATUS_FAILURE)

{

XMC_DEBUG(("DAVEAppsinitializationfailedw

ithstatus%d\n",status));

while(1U)

{

}

}

while(1U)

{

}

return1;

}

//

//UserdefinedISRtimeintervalevent

//TogglesGPIOoneachtimetick:

//Initialtimeinterval:1second.Updatetime

//Intervalto0.5secondsafter10seconds.

//

voidTime_Interval_Event(void)

{

/*AcknowledgePeriodMatchinterruptgenerated

onTIMER_CCU_1*/

TIMER_ClearEvent(&TIMER_0);

DIGITAL_IO_ToggleOutput(&DIGITAL_IO_0);

//

//Incrementeventcountandupdatetimeinterv

alto0.5

//secondsafter10seconds

//

Page 42: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

event_count++;

if(event_count==10U)

{

if(TIMER_Stop(&TIMER_0)==0U)

{

TIMER_SetTimeInterval(&TIMER_0,50000000U);

TIMER_Start(&TIMER_0);

}

}

}

BuildandRuntheProject

Observation

Forthefirst10secondsLEDistoggledforeverysecond,andthenforevery0.5seconds.

Page 43: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Home

TIMER

ReleaseHistory

ReleaseHistory

Page 44: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

HomeDataStructures DataStructureIndex DataFields

TIMER

DataStructures

Herearethedatastructureswithbriefdescriptions:TIMER InitializationparametersoftheTIMERAPP

Page 45: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

HomeDataStructures DataStructureIndex DataFields

DataFields

TIMER

TIMERStructReferenceDatastructures

Page 46: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

DetailedDescription

InitializationparametersoftheTIMERAPP.

Definitionatline116offileTIMER.h.

#include<TIMER.h>

Page 47: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

DataFields

uint32_t time_interval_value_usconstuint32_t timer_max_value_usconstuint32_t timer_min_value_usconstuint32_t shadow_mask

TIMER_MODULE_tconst timer_moduleuint16_t period_value

boolconst start_controlboolconst period_match_enable

Page 48: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

FieldDocumentation

boolconstTIMER::period_match_enable

Indicatethegenerationofperiodmatchevent

Definitionatline141offileTIMER.h.

uint16_tTIMER::period_value

Periodvaluetobeloadedintotimerforthecorrespondingtimetick

Definitionatline139offileTIMER.h.

ReferencedbyTIMER_SetTimeInterval().

constuint32_tTIMER::shadow_mask

shadowtransfermaskfortheselectedtimer

Definitionatline121offileTIMER.h.

boolconstTIMER::start_control

IndicatewhethertostarttheAPPduringinitializationitself

Definitionatline140offileTIMER.h.

uint32_tTIMER::time_interval_value_us

Timerintervalvalueforwhicheventisbeinggenerated

Page 49: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Definitionatline118offileTIMER.h.

constuint32_tTIMER::timer_max_value_us

Maximumtimervalueinmicrosecondsfortheavailableclock

Definitionatline119offileTIMER.h.

ReferencedbyTIMER_SetTimeInterval().

constuint32_tTIMER::timer_min_value_us

Minimumtimervalueinmicrosecondsfortheavailableclock

Definitionatline120offileTIMER.h.

ReferencedbyTIMER_SetTimeInterval().

TIMER_MODULE_tconstTIMER::timer_module

IndicatewhichtimermoduleisbeingusedfromCCU4andCCU8

Definitionatline138offileTIMER.h.

ReferencedbyTIMER_Clear(),TIMER_ClearEvent(),TIMER_GetInterruptStatus(),TIMER_GetTime(),TIMER_GetTimerStatus(),TIMER_Init(),TIMER_SetTimeInterval(),TIMER_Start(),andTIMER_Stop().

Thedocumentationforthisstructwasgeneratedfromthefollowingfile:

TIMER.h

Page 50: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous
Page 51: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

HomeDataStructures DataStructureIndex DataFields

TIMER

DataStructureIndex

T

T

TIMER

T

Page 52: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

HomeDataStructures DataStructureIndex DataFields

All Variables

TIMER

Hereisalistofalldocumentedstructandunionfieldswithlinkstothestruct/uniondocumentationforeachfield:

period_match_enable:TIMERperiod_value:TIMERshadow_mask:TIMERstart_control:TIMERtime_interval_value_us:TIMERtimer_max_value_us:TIMERtimer_min_value_us:TIMERtimer_module:TIMER

Page 53: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

HomeDataStructures DataStructureIndex DataFields

All Variables

TIMER

period_match_enable:TIMERperiod_value:TIMERshadow_mask:TIMERstart_control:TIMERtime_interval_value_us:TIMERtimer_max_value_us:TIMERtimer_min_value_us:TIMERtimer_module:TIMER

Page 54: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

HomeFileList Globals

TIMER

FileList

Hereisalistofalldocumentedfileswithbriefdescriptions:TIMER.c[code]TIMER.h[code]

Page 55: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

HomeFileList Globals

DataStructures

TIMER

TIMER.hFileReference

Page 56: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

DetailedDescription

Date:2015-12-18

NOTE:ThisfileisgeneratedbyDAVE.Anymanualmodificationdonetothisfilewillbelostwhenthecodeisregenerated.

DefinitioninfileTIMER.h.

#include"timer_conf.h"#include<DAVE_Common.h>#include"timer_extern.h"

Page 57: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

DataStructures

struct TIMER InitializationparametersoftheTIMERAPP.More...

Page 58: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Typedefs

typedefstructTIMER TIMER_t InitializationparametersoftheTIMERAPP.

Page 59: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

Functions

DAVE_APP_VERSION_t TIMER_GetAppVersion(void) GetTIMERAPPversion.

TIMER_STATUS_t TIMER_Init(TIMER_t*consthandle_ptr)

InitializesaTIMERwithgeneratedconfiguration.

TIMER_STATUS_t TIMER_Start(TIMER_t*consthandle_ptr)

StartsthetimeriftheinitializationoftheAPPissuccessful.

TIMER_STATUS_t TIMER_Stop(TIMER_t*consthandle_ptr) StopstheTIMER,ifitisrunning.

uint32_t TIMER_GetTime(TIMER_t*consthandle_ptr)

Returnsthecurrenttimeinmicrosecondsbyscalingwith100.

TIMER_STATUS_t TIMER_Clear(TIMER_t*consthandle_ptr) Clearsthetimerregister.

bool TIMER_GetTimerStatus(TIMER_t*consthandle_ptr)

Returnstherunningstateofthetimer.

TIMER_STATUS_tTIMER_SetTimeInterval(TIMER_t*consthandle_ptr,uint32_ttime_interval)

Setthenewtimeintervalfortheeventgeneration,bycheckingwiththesupportedrange.TIMER_GetInterruptStatus

Page 60: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

bool (TIMER_t*consthandle_ptr)

Indicatestheoccurrenceoftimeintervalevent.

void TIMER_ClearEvent(TIMER_t*consthandle_ptr)

Clearstheperiodmatchinterruptstatusofthegiventimer.

enumTIMER_MODULE{TIMER_MODULE_CCU4=0U,TIMER_MODULE_CCU8}

ThetypeidentifiestheCCU4orCCU8timerselected.More...

enumTIMER_STATUS{TIMER_STATUS_SUCCESS=0U,TIMER_STATUS_FAILURE}

statusoftheTIMERAPPMore...typedefenumTIMER_MODULE TIMER_MODULE_t

ThetypeidentifiestheCCU4orCCU8timerselected.

typedefenumTIMER_STATUS TIMER_STATUS_t statusoftheTIMERAPP

Gotothesourcecodeofthisfile.

Page 61: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

HomeFileList Globals

All Functions Typedefs Enumerations Enumerator

TIMER

Hereisalistofalldocumentedfunctions,variables,defines,enums,andtypedefswithlinkstothedocumentation:

TIMER_Clear():TIMER.hTIMER_ClearEvent():TIMER.hTIMER_GetAppVersion():TIMER.hTIMER_GetInterruptStatus():TIMER.hTIMER_GetTime():TIMER.hTIMER_GetTimerStatus():TIMER.hTIMER_Init():TIMER.hTIMER_MODULE:TIMER.hTIMER_MODULE_CCU4:TIMER.hTIMER_MODULE_CCU8:TIMER.hTIMER_MODULE_t:TIMER.hTIMER_SetTimeInterval():TIMER.hTIMER_Start():TIMER.hTIMER_STATUS:TIMER.hTIMER_STATUS_FAILURE:TIMER.hTIMER_STATUS_SUCCESS:TIMER.hTIMER_STATUS_t:TIMER.hTIMER_Stop():TIMER.hTIMER_t:TIMER.h

Page 62: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

HomeFileList Globals

All Functions Typedefs Enumerations Enumerator

TIMER

TIMER_Clear():TIMER.hTIMER_ClearEvent():TIMER.hTIMER_GetAppVersion():TIMER.hTIMER_GetInterruptStatus():TIMER.hTIMER_GetTime():TIMER.hTIMER_GetTimerStatus():TIMER.hTIMER_Init():TIMER.hTIMER_SetTimeInterval():TIMER.hTIMER_Start():TIMER.hTIMER_Stop():TIMER.h

Page 63: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

HomeFileList Globals

All Functions Typedefs Enumerations Enumerator

TIMER

TIMER_MODULE_t:TIMER.hTIMER_STATUS_t:TIMER.hTIMER_t:TIMER.h

Page 64: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

HomeFileList Globals

All Functions Typedefs Enumerations Enumerator

TIMER

TIMER_MODULE:TIMER.hTIMER_STATUS:TIMER.h

Page 65: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

HomeFileList Globals

All Functions Typedefs Enumerations Enumerator

TIMER

TIMER_MODULE_CCU4:TIMER.hTIMER_MODULE_CCU8:TIMER.hTIMER_STATUS_FAILURE:TIMER.hTIMER_STATUS_SUCCESS:TIMER.h

Page 66: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

HomeFileList Globals

TIMER

TIMER.h

Gotothedocumentationofthisfile.00001

00058#ifndefTIMER_H

00059#defineTIMER_H

00060/*******************************************

**************************************************

**************************

00061*HEADERFILES

00062*******************************************

**************************************************

*************************/

00063#include"timer_conf.h"

00064#ifdefTIMER_CCU4_USED

00065#include<GLOBAL_CCU4/global_ccu4.h>

00066#endif

00067#ifdefTIMER_CCU8_USED

00068#include<GLOBAL_CCU8/global_ccu8.h>

00069#endif

00070#include<DAVE_Common.h>

00071

00072/*******************************************

**************************************************

**************************

00073*MACROS

00074*******************************************

**************************************************

*************************/

00075

Page 67: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00076

00077/*******************************************

**************************************************

**************************

00078*ENUMS

00079*******************************************

**************************************************

*************************/

00088typedefenumTIMER_MODULE

00089{

00090TIMER_MODULE_CCU4=0U,

00091TIMER_MODULE_CCU8

00092}TIMER_MODULE_t;

00093

00097typedefenumTIMER_STATUS{

00098TIMER_STATUS_SUCCESS=0U,

00099TIMER_STATUS_FAILURE

00100}TIMER_STATUS_t;

00101

00105/*******************************************

**************************************************

**************************

00106*DATASTRUCTURES

00107********************************************

**************************************************

*************************/

00116typedefstructTIMER

00117{

00118uint32_ttime_interval_value_us;

00119constuint32_ttimer_max_value_us;

00120constuint32_ttimer_min_value_us;

00121constuint32_tshadow_mask;

00122#ifdefTIMER_CCU4_USED

00123GLOBAL_CCU4_t*constglobal_ccu4_handler;

00124XMC_CCU4_SLICE_t*constccu4_slice_ptr;

00125constuint8_tccu4_slice_number;/*Timer

beingused*/

Page 68: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00126XMC_CCU4_SLICE_COMPARE_CONFIG_t*constccu

4_slice_config_ptr;

00128XMC_CCU4_SLICE_SR_ID_tconstccu4_period_

match_node;

00129#endif

00130#ifdefTIMER_CCU8_USED

00131GLOBAL_CCU8_t*constglobal_ccu8_handler;

00132XMC_CCU8_SLICE_t*constccu8_slice_ptr;

00133constuint8_tccu8_slice_number;/*Timer

beingused*/

00134XMC_CCU8_SLICE_COMPARE_CONFIG_t*constccu

8_slice_config_ptr;

00136XMC_CCU8_SLICE_SR_ID_tconstccu8_period_m

atch_node;

00137#endif

00138TIMER_MODULE_tconsttimer_module;

00139uint16_tperiod_value;

00140boolconststart_control;

00141boolconstperiod_match_enable;

00142boolinitialized;/*flagtoindicatethe

initializationstateoftheAPPinstance*/

00143}TIMER_t;

00144

00148/*******************************************

**************************************************

**************************

00149*APIPrototypes

00150********************************************

**************************************************

*************************/

00151#ifdef__cplusplus

00152extern"C"{

00153#endif

00154

00190DAVE_APP_VERSION_tTIMER_GetAppVersion(void)

;

00191

Page 69: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00223TIMER_STATUS_tTIMER_Init(TIMER_t*constha

ndle_ptr);

00224

00258TIMER_STATUS_tTIMER_Start(TIMER_t*consth

andle_ptr);

00259

00300TIMER_STATUS_tTIMER_Stop(TIMER_t*constha

ndle_ptr);

00301

00339uint32_tTIMER_GetTime(TIMER_t*consthandle

_ptr);

00340

00380TIMER_STATUS_tTIMER_Clear(TIMER_t*constha

ndle_ptr);

00381

00421boolTIMER_GetTimerStatus(TIMER_t*constha

ndle_ptr);

00422

00495TIMER_STATUS_tTIMER_SetTimeInterval(TIMER_t

*consthandle_ptr,uint32_ttime_interval);

00496

00554boolTIMER_GetInterruptStatus(TIMER_t*const

handle_ptr);

00555

00586voidTIMER_ClearEvent(TIMER_t*consthandle_

ptr);

00587

00591#include"timer_extern.h"/*Includedtoa

ccesstheAPPHandlesatMain.c*/

00592

00593#ifdef__cplusplus

00594}

00595#endif

00596

00597#endif/*TIMER_H*/

Page 70: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous
Page 71: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

HomeFileList Globals

TIMER

TIMER.c

00001

00060/*******************************************

**************************************************

**************************

00061*HEADERFILES

00062*******************************************

**************************************************

*************************/

00063#include"timer.h"

00064

00065/*******************************************

**************************************************

**************************

00066*MACROS

00067*******************************************

**************************************************

*************************/

00068#defineTIMER_CMP_100_DUTY((uin

t16_t)0)/*Comparevaluefor100%dutycycle*/

00069#defineTIMER_RESOLUTION_SEC_TO_MICRO(1000

00000U)/*Converttheresolutionfromsectouse

c,bydividingwiththe\

00070

scalefactor*/

00071#defineTIMER_PRESCALER_MAX(15U)

/*Maximumprescalervaluesallowed*/

00072#defineTIMER_PERIOD_16BIT_MAX(0xFF

FFU)/*Maximumperiodvalue*/

Page 72: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00073#defineTIMER_PERIOD_MIN(0x1U

)/*Minimumperiodvalue*/

00074#defineTIMER_CLK_SCALE_FACTOR(32U)

/*Scalefactorusedduringcalculationoft

he"TIMER_CLK_CONST_SCALED"*/

00075

00076/*******************************************

**************************************************

**************************

00077*LOCALDATA

00078*******************************************

**************************************************

*************************/

00079

00080/*******************************************

**************************************************

**************************

00081*LOCALROUTINES

00082*******************************************

**************************************************

*************************/

00083#ifdefTIMER_CCU4_USED

00084TIMER_STATUS_tTIMER_CCU4_lInit(TIMER_t*con

sthandle_ptr);

00085voidTIMER_CCU4_lShadowTransfer(TIMER_t*con

sthandle_ptr);

00086#endif

00087

00088#ifdefTIMER_CCU8_USED

00089TIMER_STATUS_tTIMER_CCU8_lInit(TIMER_t*con

sthandle_ptr);

00090voidTIMER_CCU8_lShadowTransfer(TIMER_t*con

sthandle_ptr);

00091#endif

00092

00093/******************************************

**************************************************

Page 73: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

**************************

00094*APIIMPLEMENTATION

00095*******************************************

**************************************************

*************************/

00096/*ReturnstheversionoftheTIMERAPP.

00097*/

00098DAVE_APP_VERSION_tTIMER_GetAppVersion(void)

00099{

00100DAVE_APP_VERSION_tversion;

00101

00102version.major=TIMER_MAJOR_VERSION;

00103version.minor=TIMER_MINOR_VERSION;

00104version.patch=TIMER_PATCH_VERSION;

00105

00106returnversion;

00107}

00108

00109/*

00110*ThisfunctioninitializesaTIMERAPPbas

edonuserconfiguration.

00111*

00112*/

00113TIMER_STATUS_tTIMER_Init(TIMER_t*consthan

dle_ptr)

00114{

00115TIMER_STATUS_tstatus;

00116

00117XMC_ASSERT("TIMER_Init:handle_ptrNULL",

(handle_ptr!=NULL));

00118

00119status=TIMER_STATUS_SUCCESS;

00120/*CheckforAPPinstanceisinitializedo

rnot*/

00121if(false==handle_ptr->initialized)

00122{

00123#ifdefTIMER_CCU4_USED

Page 74: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00124if(TIMER_MODULE_CCU4==handle_ptr->tim

er_module)

00125{

00126/*ConfigureCCU4timerfortherequir

edtimeticksettings*/

00127status=TIMER_CCU4_lInit(handle_ptr);

00128}

00129#endif

00130

00131#ifdefTIMER_CCU8_USED

00132if(TIMER_MODULE_CCU8==handle_ptr->tim

er_module)

00133{

00134/*ConfigureCCU8timerfortherequir

edtimeticksettings*/

00135status=TIMER_CCU8_lInit(handle_ptr);

00136}

00137#endif

00138}

00139

00140return(status);

00141}

00142

00143/*

00144*Thisfunctionstartsthetimertogenerat

etheeventsforthespecifiedtime_intervalvalue

00145*/

00146TIMER_STATUS_tTIMER_Start(TIMER_t*consth

andle_ptr)

00147{

00148TIMER_STATUS_tstatus;

00149

00150XMC_ASSERT("TIMER_Start:handle_ptrNULL",

(handle_ptr!=NULL));

00151

00152/*CheckforAPPinstanceisinitializedo

rnot*/

Page 75: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00153if(true==handle_ptr->initialized)

00154{

00155#ifdefTIMER_CCU4_USED

00156if(TIMER_MODULE_CCU4==handle_ptr->tim

er_module)

00157{

00158/*Startthetimermanually*/

00159XMC_CCU4_SLICE_StartTimer(handle_ptr->

ccu4_slice_ptr);

00160}

00161#endif

00162

00163#ifdefTIMER_CCU8_USED

00164if(TIMER_MODULE_CCU8==handle_ptr->tim

er_module)

00165{

00166/*Startthetimermanually*/

00167XMC_CCU8_SLICE_StartTimer(handle_ptr->

ccu8_slice_ptr);

00168}

00169#endif

00170status=TIMER_STATUS_SUCCESS;

00171}

00172else

00173{

00174status=TIMER_STATUS_FAILURE;

00175}

00176

00177return(status);

00178}

00179

00180/*

00181*Thisfunctionstopsandclearsthetimer

00182*/

00183TIMER_STATUS_tTIMER_Stop(TIMER_t*constha

ndle_ptr)

00184{

Page 76: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00185TIMER_STATUS_tstatus;

00186

00187XMC_ASSERT("TIMER_Stop:handle_ptrNULL",

(handle_ptr!=NULL));

00188

00189/*Checkwhethertimerisinitializedand

inrunningstate*/

00190if((TIMER_GetTimerStatus(handle_ptr))&&(

true==handle_ptr->initialized))

00191{

00192#ifdefTIMER_CCU4_USED

00193if(TIMER_MODULE_CCU4==handle_ptr->tim

er_module)

00194{

00195/*Stopsthetimer*/

00196XMC_CCU4_SLICE_StopTimer(handle_ptr->c

cu4_slice_ptr);

00197}

00198#endif

00199

00200#ifdefTIMER_CCU8_USED

00201if(TIMER_MODULE_CCU8==handle_ptr->tim

er_module)

00202{

00203/*Stopsthetimer*/

00204XMC_CCU8_SLICE_StopTimer(handle_ptr->c

cu8_slice_ptr);

00205}

00206#endif

00207status=TIMER_STATUS_SUCCESS;

00208}

00209else

00210{

00211status=TIMER_STATUS_FAILURE;

00212}

00213

00214return(status);

Page 77: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00215}

00216

00217/*

00218*Thisfunctionreturnsthestatusofthet

imer

00219*/

00220boolTIMER_GetTimerStatus(TIMER_t*constha

ndle_ptr)

00221{

00222boolstatus;

00223

00224XMC_ASSERT("TIMER_GetTimerStatus:handle_pt

rNULL",(handle_ptr!=NULL));

00225

00226status=false;

00227

00228#ifdefTIMER_CCU4_USED

00229if(TIMER_MODULE_CCU4==handle_ptr->timer

_module)

00230{

00231/*Returnsthecurrentstatusofthetim

er*/

00232status=XMC_CCU4_SLICE_IsTimerRunning(h

andle_ptr->ccu4_slice_ptr);

00233}

00234#endif

00235

00236#ifdefTIMER_CCU8_USED

00237if(TIMER_MODULE_CCU8==handle_ptr->timer

_module)

00238{

00239/*Returnsthecurrentstatusofthetim

er*/

00240status=XMC_CCU8_SLICE_IsTimerRunning(h

andle_ptr->ccu8_slice_ptr);

00241}

00242#endif

Page 78: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00243

00244return(status);

00245}

00246

00247/*

00248*ThisfunctionchangesthePWMperiodwhic

hinturnchangesthetimetickintervalvalueby

checkingthat

00249*thegiventimetickvalueiswithinsuppo

rtedrange.

00250*/

00251TIMER_STATUS_tTIMER_SetTimeInterval(TIMER_t

*consthandle_ptr,uint32_ttime_interval)

00252{

00253TIMER_STATUS_tstatus;

00254uint32_tlfrequency;

00255uint32_tlprescaler;

00256

00257XMC_ASSERT("TIMER_SetTimeInterval:handle_p

trNULL",(handle_ptr!=NULL));

00258

00259status=TIMER_STATUS_FAILURE;

00260

00261if(false==TIMER_GetTimerStatus(handle_p

tr))

00262{

00263/*checkfortime_intervalrange*/

00264if((time_interval>=handle_ptr->timer_

min_value_us)&&(time_interval<=handle_ptr->tim

er_max_value_us))

00265{

00266/*Initializetheprescaler*/

00267lprescaler=0U;

00268while(time_interval>(handle_ptr->ti

mer_max_value_us>>(TIMER_PRESCALER_MAX-lpresca

ler)))

00269{

Page 79: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00270lprescaler++;

00271}

00272#ifdefTIMER_CCU4_USED

00273if(TIMER_MODULE_CCU4==handle_ptr->t

imer_module)

00274{

00275lfrequency=handle_ptr->global_ccu4

_handler->module_frequency;

00276handle_ptr->ccu4_slice_config_ptr->p

rescaler_initval=lprescaler;

00277/*Calculatetheperiodregisterfor

therequiredtime_intervalvalue*/

00278handle_ptr->period_value=(uint16_t

)((((uint64_t)time_interval*lfrequency)>>\

00279

handle_ptr->ccu4_slice_config_ptr->prescaler_in

itval)/\

00280

TIMER_RESOLUTION_SEC_TO_MICRO);

00281/*ActualtimerperiodvaluesisPer

iod_reg_val+1U*/

00282if(handle_ptr->period_value>TIMER

_PERIOD_MIN)

00283{

00284(handle_ptr->period_value)--;

00285}

00286/*Updatetheprescaler*/

00287XMC_CCU4_SLICE_SetPrescaler(handle_p

tr->ccu4_slice_ptr,handle_ptr->ccu4_slice_config_

ptr->prescaler_initval);

00288/*updateperiod,compareandpresca

lervalues*/

00289TIMER_CCU4_lShadowTransfer(handle_pt

r);

00290/*Updatethestatus*/

00291status=TIMER_STATUS_SUCCESS;

00292}

Page 80: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00293#endif

00294

00295#ifdefTIMER_CCU8_USED

00296if(TIMER_MODULE_CCU8==handle_ptr->t

imer_module)

00297{

00298handle_ptr->ccu8_slice_config_ptr->p

rescaler_initval=lprescaler;

00299lfrequency=handle_ptr->global_ccu8

_handler->module_frequency;

00300/*Calculatetheperiodregisterfor

therequiredtime_intervalvalue*/

00301handle_ptr->period_value=(uint16_t

)((((uint64_t)time_interval*lfrequency)>>\

00302

handle_ptr->ccu8_slice_config_ptr->prescaler_in

itval)/\

00303

TIMER_RESOLUTION_SEC_TO_MICRO);

00304/*ActualtimerperiodvaluesisPer

iod_reg_val+1U*/

00305if(handle_ptr->period_value>TIMER

_PERIOD_MIN)

00306{

00307(handle_ptr->period_value)--;

00308}

00309/*Updatetheprescaler*/

00310XMC_CCU8_SLICE_SetPrescaler(handle_p

tr->ccu8_slice_ptr,handle_ptr->ccu8_slice_config_

ptr->prescaler_initval);

00311/*updateperiod,compareandpresca

lervalues*/

00312TIMER_CCU8_lShadowTransfer(handle_pt

r);

00313/*Updatethestatus*/

00314status=TIMER_STATUS_SUCCESS;

00315}

Page 81: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00316#endif

00317}

00318}

00319return(status);

00320}

00321

00322/*

00323*Thisfunctionreadsthetimerevent(perio

dmatchinterrupt)statusofthegiventimer

00324*/

00325boolTIMER_GetInterruptStatus(TIMER_t*const

handle_ptr)

00326{

00327boolstatus;

00328XMC_ASSERT("TIMER_GetInterruptStatus:handl

e_ptrNULL",(handle_ptr!=NULL));

00329status=false;

00330#ifdefTIMER_CCU4_USED

00331if(TIMER_MODULE_CCU4==handle_ptr->timer

_module)

00332{

00333/*Readstheinterruptstatus*/

00334status=XMC_CCU4_SLICE_GetEvent(handle_

ptr->ccu4_slice_ptr,XMC_CCU4_SLICE_IRQ_ID_PERIOD_

MATCH);

00335}

00336#endif

00337

00338#ifdefTIMER_CCU8_USED

00339if(TIMER_MODULE_CCU8==handle_ptr->timer

_module)

00340{

00341/*Readstheinterruptstatus*/

00342status=XMC_CCU8_SLICE_GetEvent(handle_

ptr->ccu8_slice_ptr,XMC_CCU8_SLICE_IRQ_ID_PERIOD_

MATCH);

00343}

Page 82: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00344#endif

00345return(status);

00346}

00347

00348/*

00349*Thisfunctionclearstheperiodmatchint

erruptstatusofthegiventimer.

00350*/

00351voidTIMER_ClearEvent(TIMER_t*consthandle_

ptr)

00352{

00353XMC_ASSERT("TIME_CCU_AcknowledgeInterrupt:

handle_ptrNULL",(handle_ptr!=NULL));

00354

00355#ifdefTIMER_CCU4_USED

00356if(TIMER_MODULE_CCU4==handle_ptr->timer

_module)

00357{

00358/*clearsthetimerevent(periodmatchi

nterrupt)*/

00359XMC_CCU4_SLICE_ClearEvent(handle_ptr->cc

u4_slice_ptr,XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH);

00360}

00361#endif

00362

00363#ifdefTIMER_CCU8_USED

00364if(TIMER_MODULE_CCU8==handle_ptr->timer

_module)

00365{

00366/*clearsthetimerevent(periodmatchi

nterrupt)*/

00367XMC_CCU8_SLICE_ClearEvent(handle_ptr->cc

u8_slice_ptr,XMC_CCU8_SLICE_IRQ_ID_PERIOD_MATCH);

00368}

00369#endif

00370}

00371

Page 83: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00372/*

00373*Thisfunctionreturnsthecurrenttimeva

lue

00374*/

00375uint32_tTIMER_GetTime(TIMER_t*consthandle

_ptr)

00376{

00377uint32_tltimer_val;

00378uint32_tlprescaler;

00379uint32_tltime_val;

00380

00381XMC_ASSERT("TIMER_GetTimerStatus:handle_pt

rNULL",(handle_ptr!=NULL));

00382ltime_val=0U;

00383

00384#ifdefTIMER_CCU4_USED

00385if(TIMER_MODULE_CCU4==handle_ptr->timer

_module)

00386{

00387/*Addedonetoaccordingtotheedgeal

ignedmode*/

00388ltimer_val=(uint32_t)XMC_CCU4_SLICE_Ge

tTimerValue(handle_ptr->ccu4_slice_ptr)+1U;

00389lprescaler=handle_ptr->ccu4_slice_conf

ig_ptr->prescaler_initval;

00390

00391/*calculatethetimevalueinmicrosec

ondsandscaledwith100*/

00392ltime_val=(uint32_t)((uint64_t)((uint6

4_t)ltimer_val*(uint64_t)TIMER_CLK_CONST_SCALED)

>>\

00393(TIMER_CLK_SCALE_

FACTOR-lprescaler));

00394}

00395#endif

00396

00397#ifdefTIMER_CCU8_USED

Page 84: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00398if(TIMER_MODULE_CCU8==handle_ptr->timer

_module)

00399{

00400/*Addedonetoaccordingtotheedgeal

ignedmode*/

00401ltimer_val=(uint32_t)XMC_CCU8_SLICE_Ge

tTimerValue(handle_ptr->ccu8_slice_ptr)+1U;

00402lprescaler=handle_ptr->ccu8_slice_conf

ig_ptr->prescaler_initval;

00403

00404/*calculatethetimevalueinmicrosec

ondsandscaledwith100*/

00405ltime_val=(uint32_t)((uint64_t)((uint6

4_t)ltimer_val*(uint64_t)TIMER_CLK_CONST_SCALED)

>>\

00406(TIMER_CLK_SCALE_

FACTOR-lprescaler));

00407}

00408#endif

00409

00410returnltime_val;

00411}

00412

00413/*

00414*Clearthetimer

00415*/

00416TIMER_STATUS_tTIMER_Clear(TIMER_t*constha

ndle_ptr)

00417{

00418TIMER_STATUS_tstatus;

00419

00420XMC_ASSERT("TIMER_Clear:handle_ptrNULL",

(handle_ptr!=NULL));

00421

00422/*CheckforAPPinstanceisinitializedo

rnot*/

00423if(true==handle_ptr->initialized)

Page 85: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00424{

00425#ifdefTIMER_CCU4_USED

00426if(TIMER_MODULE_CCU4==handle_ptr->tim

er_module)

00427{

00428/*Clearthetimerregister*/

00429XMC_CCU4_SLICE_ClearTimer(handle_ptr->

ccu4_slice_ptr);

00430}

00431#endif

00432

00433#ifdefTIMER_CCU8_USED

00434if(TIMER_MODULE_CCU8==handle_ptr->tim

er_module)

00435{

00436/*Clearthetimerregister*/

00437XMC_CCU8_SLICE_ClearTimer(handle_ptr->

ccu8_slice_ptr);

00438}

00439#endif

00440status=TIMER_STATUS_SUCCESS;

00441}

00442else

00443{

00444status=TIMER_STATUS_FAILURE;

00445}

00446

00447return(status);

00448}

00449

00450/*******************************************

*PRIVATEFUNCTIONDEFINITIONS*******************

*************************/

00451#ifdefTIMER_CCU4_USED

00452/*

00453*Thisfunctionconfigurestimerccu4timer

withrequiredtimetickvalue

Page 86: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00454*/

00455TIMER_STATUS_tTIMER_CCU4_lInit(TIMER_t*con

sthandle_ptr)

00456{

00457TIMER_STATUS_tstatus;

00458/*Initializetheglobalregisters*/

00459status=(TIMER_STATUS_t)GLOBAL_CCU4_Init(

handle_ptr->global_ccu4_handler);

00460

00461/*Enabletheclockforselectedtimer*/

00462XMC_CCU4_EnableClock(handle_ptr->global_cc

u4_handler->module_ptr,handle_ptr->ccu4_slice_num

ber);

00463/*Configurethetimerwithrequiredsetti

ngs*/

00464XMC_CCU4_SLICE_CompareInit(handle_ptr->ccu

4_slice_ptr,handle_ptr->ccu4_slice_config_ptr);

00465/*programsthetimerperiodandcomparer

egisteraccordingtotimeintervalvalueanddoth

eshadowtransfer*/

00466TIMER_CCU4_lShadowTransfer(handle_ptr);

00467

00468#ifdefTIMER_INTERRUPT

00469if(true==handle_ptr->period_match_enable

)

00470{

00471/*BindsaperiodmatcheventtoanNVIC

node*/

00472XMC_CCU4_SLICE_SetInterruptNode(handle_p

tr->ccu4_slice_ptr,XMC_CCU4_SLICE_IRQ_ID_PERIOD_M

ATCH,

00473handle_p

tr->ccu4_period_match_node);

00474/*Enablesatimer(periodmatch)event

*/

00475XMC_CCU4_SLICE_EnableEvent(handle_ptr->c

cu4_slice_ptr,XMC_CCU4_SLICE_IRQ_ID_PERIOD_MATCH)

Page 87: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

;

00476}

00477#endif

00478/*Clearsthetimerregister*/

00479XMC_CCU4_SLICE_ClearTimer(handle_ptr->ccu4

_slice_ptr);

00480

00481/*updatetheinitializationflagastrue

forparticularinstance*/

00482handle_ptr->initialized=true;

00483

00484/*Checkwhetherthestartofthetimeris

enabledduringinitializationornot*/

00485if(handle_ptr->start_control==true)

00486{

00487/*Startthetimer*/

00488XMC_CCU4_SLICE_StartTimer(handle_ptr->cc

u4_slice_ptr);

00489}

00490

00491return(status);

00492}

00493

00494/*

00495*Thisfunctionconfigurestimerperiodand

comparevaluesandtriggerstheshadowtransfero

peration

00496*/

00497voidTIMER_CCU4_lShadowTransfer(TIMER_t*con

sthandle_ptr)

00498{

00499/*programsthetimerperiodregisteracco

rdingtotimeintervalvalue*/

00500XMC_CCU4_SLICE_SetTimerPeriodMatch(handle_

ptr->ccu4_slice_ptr,handle_ptr->period_value);

00501/*programsthetimercompareregisterfor

50%dutycycle*/

Page 88: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00502XMC_CCU4_SLICE_SetTimerCompareMatch(handle

_ptr->ccu4_slice_ptr,TIMER_CMP_100_DUTY);

00503/*Transfersvaluefromshadowtimerregis

terstoactualtimerregisters*/

00504XMC_CCU4_EnableShadowTransfer(handle_ptr->

global_ccu4_handler->module_ptr,handle_ptr->shado

w_mask);

00505}

00506#endif

00507

00508#ifdefTIMER_CCU8_USED

00509/*

00510*Thisfunctionconfigurestimerccu8timer

withrequiredtimetickvalue

00511*/

00512TIMER_STATUS_tTIMER_CCU8_lInit(TIMER_t*con

sthandle_ptr)

00513{

00514TIMER_STATUS_tstatus;

00515/*Initializetheglobalregisters*/

00516status=(TIMER_STATUS_t)GLOBAL_CCU8_Init(

handle_ptr->global_ccu8_handler);

00517

00518/*Enabletheclockforselectedtimer*/

00519XMC_CCU8_EnableClock(handle_ptr->global_cc

u8_handler->module_ptr,handle_ptr->ccu8_slice_num

ber);

00520/*Configurethetimerwithrequiredsetti

ngs*/

00521XMC_CCU8_SLICE_CompareInit(handle_ptr->ccu

8_slice_ptr,handle_ptr->ccu8_slice_config_ptr);

00522/*programsthetimerperiodandcomparer

egisteraccordingtotimeintervalvalueanddoth

eshadowtransfer*/

00523TIMER_CCU8_lShadowTransfer(handle_ptr);

00524

00525#ifdefTIMER_INTERRUPT

Page 89: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00526if(true==handle_ptr->period_match_enable

)

00527{

00528/*BindsaperiodmatcheventtoanNVIC

node*/

00529XMC_CCU8_SLICE_SetInterruptNode(handle_p

tr->ccu8_slice_ptr,XMC_CCU8_SLICE_IRQ_ID_PERIOD_M

ATCH,

00530handle_p

tr->ccu8_period_match_node);

00531/*Enablesatimer(periodmatch)event

*/

00532XMC_CCU8_SLICE_EnableEvent(handle_ptr->c

cu8_slice_ptr,XMC_CCU8_SLICE_IRQ_ID_PERIOD_MATCH)

;

00533}

00534#endif

00535/*Clearsthetimerregister*/

00536XMC_CCU8_SLICE_ClearTimer(handle_ptr->ccu8

_slice_ptr);

00537

00538/*updatetheinitializationflagastrue

forparticularinstance*/

00539handle_ptr->initialized=true;

00540

00541/*Checkwhetherthestartofthetimeris

enabledduringinitializationornot*/

00542if(handle_ptr->start_control==true)

00543{

00544/*Startthetimer*/

00545XMC_CCU8_SLICE_StartTimer(handle_ptr->cc

u8_slice_ptr);

00546}

00547

00548return(status);

00549}

00550

Page 90: TIMER - Documentation & Help · The TIMER APP provides accurate hardware timer using one timer slice of CCU4 or CCU8 peripheral. And provides provide the functionality below: 1. Continuous

00551/*

00552*Thisfunctionconfigurestimerperiodand

comparevaluesandtriggerstheshadowtransfero

peration

00553*/

00554voidTIMER_CCU8_lShadowTransfer(TIMER_t*con

sthandle_ptr)

00555{

00556/*programsthetimerperiodregisteracco

rdingtotimeintervalvalue*/

00557XMC_CCU8_SLICE_SetTimerPeriodMatch(handle_

ptr->ccu8_slice_ptr,handle_ptr->period_value);

00558/*programsthetimercompareregisterfor

50%dutycycleincomparechannel1*/

00559XMC_CCU8_SLICE_SetTimerCompareMatch(handle

_ptr->ccu8_slice_ptr,

00560XMC_CC

U8_SLICE_COMPARE_CHANNEL_1,

00561TIMER_

CMP_100_DUTY);

00562/*Transfersvaluefromshadowtimerregis

terstoactualtimerregisters*/

00563XMC_CCU8_EnableShadowTransfer(handle_ptr->

global_ccu8_handler->module_ptr,handle_ptr->shado

w_mask);

00564}

00565#endif