📄 timer_example.c
字号:
intrCnt = 0;
/* Stop the Timer */
status = CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET_TIMHI, NULL);
printf("Example for TIM34 completed\n");
/* Close the Tmr instance */
CSL_tmrClose(hTmr);
CSL_intcClose(tmrIntcHandle);
}
/*
* =============================================================================
* @func tmrIntcChainedDemo
*
* @arg
* NONE
*
* @desc
* This is example to verify the setting of timer in dual 32 bit chained
* and one shot mode with INTC.
*
* @return
* NONE
*
* =============================================================================
*/
void tmrIntcChainedDemo (
void
)
{
CSL_TmrObj TmrObj;
CSL_Status status;
CSL_IntcEventHandlerRecord EventRecord;
CSL_IntcParam vectId;
Uint32 LoadValue = 100;
Uint32 LoadValue1 = 0;
Uint8 preScalValue = 0;
CSL_TmrHwSetup hwSetup = CSL_TMR_HWSETUP_DEFAULTS;
/* set the timer in to one shot mode */
CSL_TmrEnamode TimeCountMode = CSL_TMR_ENAMODE_ENABLE;
/* Clear local data structures */
memset(&TmrObj, 0, sizeof(CSL_TmrObj));
printf("\n\n\n\n\nRunning Gp Timer Interrupt DUAL CHAINED....\n");
/**************************************************************
* INTC related code *
**************************************************************/
/* Open INTC */
vectId = CSL_INTC_VECTID_12;
tmrIntcHandle = CSL_intcOpen(&tmrIntcObj, CSL_INTC_EVENTID_TINTLO0, \
&vectId, NULL);
/* Bind ISR to Interrupt */
EventRecord.handler = (CSL_IntcEventHandler)&TimerInterruptHandler;
EventRecord.arg = (void *)tmrIntcHandle;
CSL_intcPlugEventHandler(tmrIntcHandle, &EventRecord);
/* Event Enable */
CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTENABLE, NULL);
/**************************************************************/
/* Initialize timer CSL module */
CSL_tmrInit(NULL);
hTmr = CSL_tmrOpen(&TmrObj, IntcInstance, NULL, &status);
CSL_tmrHwSetup(hTmr, &hwSetup);
/* Reset the Timer */
CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET64, NULL);
/* set the timer mode to dual chained mode */
hwSetup.tmrTimerMode = CSL_TMR_TIMMODE_DUAL_CHAINED;
CSL_tmrHwSetup(hTmr, &hwSetup);
/* Load the prescale value */
CSL_tmrHwControl(hTmr, CSL_TMR_CMD_LOAD_PSCHI, (void *)&preScalValue);
/* Load the period register */
CSL_tmrHwControl(hTmr, CSL_TMR_CMD_LOAD_PRDLO, (void *)&LoadValue);
/* Load the period register */
CSL_tmrHwControl(hTmr, CSL_TMR_CMD_LOAD_PRDHI, (void *)&LoadValue1);
/* Start the timer with one shot*/
CSL_tmrHwControl(hTmr, CSL_TMR_CMD_START64, (void *)&TimeCountMode);
/**************************************************************
* INTC related code *
**************************************************************/
while (1) {
if (intrCnt == 1)
break;
}
/**************************************************************/
CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTDISABLE, NULL);
printf("INTR: The Total number of Events occured are: 0x%d\n", intrCnt);
intrCnt = 0;
/* Stop the Timer */
CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET64, NULL);
printf("Example for timer chained mode completed\n");
/* Close the Tmr instance */
CSL_tmrClose(hTmr);
CSL_intcClose(tmrIntcHandle);
}
/*
* =============================================================================
* @func tmrIntcGptDemo
*
* @arg
* NONE
*
* @desc
* This is example to verify the setting of timer in GPT mode with INTC.
*
* @return
* NONE
*
* =============================================================================
*/
void tmrIntcGptDemo (
void
)
{
CSL_TmrObj TmrObj;
CSL_IntcEventHandlerRecord EventRecord, EventRecord1;
CSL_IntcParam vectId;
CSL_Status status;
CSL_TmrHwSetup hwSetup = CSL_TMR_HWSETUP_DEFAULTS;
/* set the timer in to one shot mode */
CSL_TmrEnamode TimeCountMode = CSL_TMR_ENAMODE_ENABLE;
/* set the timer mode to GPT mode */
hwSetup.tmrTimerMode = CSL_TMR_TIMMODE_GPT;
/* load the PRDLO */
hwSetup.tmrTimerPeriodLo = 0x0f;
/* load the PRDHI */
hwSetup.tmrTimerPeriodHi = 0x00;
/* Clear local data structures */
memset(&TmrObj, 0, sizeof(CSL_TmrObj));
printf("\n\n\n\nRunning Gp Timer with INTC....\n");
/**************************************************************
* INTC related code *
**************************************************************/
/* Open INTC */
vectId = CSL_INTC_VECTID_12;
tmrIntcHandle = CSL_intcOpen(&tmrIntcObj, CSL_INTC_EVENTID_TINTLO0,\
&vectId, NULL);
vectId = CSL_INTC_VECTID_13;
tmrIntcHandle1 = CSL_intcOpen(&tmrIntcObj1, CSL_INTC_EVENTID_TINTHI0,\
&vectId, NULL);
/* Bind ISR to Interrupt */
EventRecord.handler = (CSL_IntcEventHandler)&TimerInterruptHandler;
EventRecord.arg = (void *)tmrIntcHandle;
CSL_intcPlugEventHandler(tmrIntcHandle, &EventRecord);
EventRecord1.handler = (CSL_IntcEventHandler)&TimerInterruptHandler;
EventRecord1.arg = (void *)tmrIntcHandle1;
CSL_intcPlugEventHandler(tmrIntcHandle1, &EventRecord1);
/* Event Enable */
CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTENABLE, NULL);
CSL_intcHwControl(tmrIntcHandle1, CSL_INTC_CMD_EVTENABLE, NULL);
/**************************************************************/
/* Initialize timer CSL module */
CSL_tmrInit(NULL);
hTmr = CSL_tmrOpen(&TmrObj, IntcInstance, NULL, &status);
CSL_tmrHwSetup(hTmr, &hwSetup);
/* Reset the Timer */
CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET64, NULL);
/* Start the timer with one shot*/
CSL_tmrHwControl(hTmr, CSL_TMR_CMD_START64, (void *)&TimeCountMode);
/**************************************************************
* INTC related code *
**************************************************************/
while (1) {
if (intrCnt == 1)
break;
}
/**************************************************************/
CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTDISABLE, NULL);
CSL_intcHwControl(tmrIntcHandle1, CSL_INTC_CMD_EVTDISABLE, NULL);
printf("INTR: The Total number of Events occured are: 0x%d\n", intrCnt);
intrCnt = 0;
/* Stop the Timer */
CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET64, NULL);
printf("Example for 64-bit timer mode completed\n");
/* Close the Tmr instance */
CSL_tmrClose(hTmr);
CSL_intcClose(tmrIntcHandle);
}
/*
* =============================================================================
* @func tmrWdtModeDemo
*
* @arg
* NONE
*
* @desc
* This demonstrates the Setting of timer to watchdog mode with INTC.
*
* @return
* NONE
*
* =============================================================================
*/
void tmrWdtModeDemo (
void
)
{
CSL_TmrObj TmrObj;
CSL_Status status;
CSL_IntcParam vectId;
CSL_IntcEventHandlerRecord EventRecord;
Uint16 loadVal;
CSL_TmrHwSetup hwSetup = CSL_TMR_HWSETUP_DEFAULTS;
/* set the timer in to countinuos mode and it is must for watchdog mode */
CSL_TmrEnamode TimeCountMode = CSL_TMR_ENAMODE_CONT;
CSL_IntcEventId eventId = CSL_INTC_EVENTID_TINTLO0;
/* set the timer mode to WATCHDOG mode */
hwSetup.tmrTimerMode = CSL_TMR_TIMMODE_WDT;
hwSetup.tmrPulseWidthLo = CSL_TMR_PWID_THREECLKS;
hwSetup.tmrClksrcLo = CSL_TMR_CLKSRC_INTERNAL;
hwSetup.tmrClockPulseLo = CSL_TMR_CP_PULSE;
hwSetup.tmrClockPulseHi = CSL_TMR_CP_PULSE;
hwSetup.tmrIpGateLo = CSL_TMR_CLOCK_INP_NOGATE;
/* load the PRDLO */
hwSetup.tmrTimerPeriodLo = 0x100;
/* load the PRDHI */
hwSetup.tmrTimerPeriodHi = 0x0;
/* Clear local data structures */
memset(&TmrObj, 0, sizeof(CSL_TmrObj));
printf("\n\n\n\n Running the GP timer in watchdog mode with INTC......\n");
/**************************************************************
* INTC related code *
**************************************************************/
/* Open INTC */
vectId = CSL_INTC_VECTID_12;
if (IntcInstance == 1)
eventId = eventId + 2;
tmrIntcHandle = CSL_intcOpen(&tmrIntcObj, eventId, &vectId, NULL);
/* Bind ISR to Interrupt */
EventRecord.handler = (CSL_IntcEventHandler)&TimerInterruptHandler;
EventRecord.arg = (void *)tmrIntcHandle;
CSL_intcPlugEventHandler(tmrIntcHandle, &EventRecord);
/* Event Enable */
CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTENABLE, NULL);
/**************************************************************/
/* Initialize timer CSL module */
status = CSL_tmrInit(NULL);
hTmr = CSL_tmrOpen(&TmrObj, IntcInstance, NULL, &status);
CSL_tmrHwSetup(hTmr, &hwSetup);
/* Reset the Timer */
status = CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET64, NULL);
/* Start the timer in continuous mode*/
status = CSL_tmrHwControl(hTmr, CSL_TMR_CMD_START_WDT, \
(void *)&TimeCountMode);
/* Watchdog timer service key1 */
loadVal = CSL_TMR_WDTCR_WDKEY_CMD1;
status = CSL_tmrHwControl(hTmr, CSL_TMR_CMD_LOAD_WDKEY, \
(Uint16 *) &loadVal);
/* Watchdog timer service key2 */
loadVal = CSL_TMR_WDTCR_WDKEY_CMD2;
status = CSL_tmrHwControl(hTmr, CSL_TMR_CMD_LOAD_WDKEY, \
(Uint16 *)&loadVal);
/**************************************************************
* INTC related code *
**************************************************************/
while (1) {
if (intrCnt == 1)
break;
}
/**************************************************************/
CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTDISABLE, NULL);
printf("INTR: The Total number of Events occured are: 0x%d\n", intrCnt);
intrCnt = 0;
printf("Example for Watch dog mode completed\n");
/* Close the Tmr instance */
status = CSL_tmrClose(hTmr);
CSL_intcClose(tmrIntcHandle);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -