⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer_example.c

📁 dsp tms320c6486的csl例程
💻 C
📖 第 1 页 / 共 2 页
字号:
 *   @func   tmrIntcChainedDemo
 *
 *   @desc
 *     This test verifies the Setting of timer to dual 32 bit chained
 *     and one shot mode with INTC
 *
 *   @arg    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_TINTLO_LOCAL, \
                                                  &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 GP timer CSL module */
    CSL_tmrInit(NULL);

    hTmr =  CSL_tmrOpen(&TmrObj, IntcInstance, NULL, &status);

    CSL_tmrHwSetup(hTmr, &hwSetup);

    /* Reset the GP 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 timer high 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 occurred are: 0x%d\n", intrCnt);

    intrCnt = 0;

    /* Stop the GP Timer */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET64, NULL);

    printf("Example for timer chained mode\n");

    /* Close the Tmr instance */
    CSL_tmrClose(hTmr);
    CSL_intcClose(tmrIntcHandle);
}

/*
 * =============================================================================
 *   @func   tmrIntcGptDemo
 *
 *   @desc
 *     This test verifies the Setting of timer to GPT mode with INTC
 *
 *   @arg    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 continuous 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_TINTLO_LOCAL,\
                                                &vectId, NULL);

    vectId = CSL_INTC_VECTID_13;
    tmrIntcHandle1 = CSL_intcOpen(&tmrIntcObj1, CSL_INTC_EVENTID_TINTHI_LOCAL,\
                                                &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 GP timer CSL module */
    CSL_tmrInit(NULL);

    hTmr = CSL_tmrOpen(&TmrObj, IntcInstance, NULL, &status);

    CSL_tmrHwSetup(hTmr, &hwSetup);

    /* Reset the GP 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 occurred are: 0x%d\n", intrCnt);

    intrCnt = 0;

    /* Stop the GP Timer */
    CSL_tmrHwControl(hTmr, CSL_TMR_CMD_RESET64, NULL);

    printf("Example for 64-bit timer mode\n");

    /* Close the Tmr instance */
    CSL_tmrClose(hTmr);
    CSL_intcClose(tmrIntcHandle);
}



/*
 * ============================================================================
 *   @func   tmrWdtModeDemo
 *
 *   @desc
 *     This verifies the Setting of timer to watchdog mode with INTC
 *
 *   @arg    None
 * ============================================================================
 */
void tmrWdtModeDemo (
    void
)
{
    CSL_TmrObj TmrObj;
    CSL_Status status;
    CSL_IntcParam vectId;
    CSL_IntcEventHandlerRecord EventRecord;

    CSL_TmrHwSetup hwSetup = CSL_TMR_HWSETUP_DEFAULTS;

    /* set the timer in to continuous mode and it is must for watchdog mode */
    CSL_TmrEnamode TimeCountMode = CSL_TMR_ENAMODE_CONT;

    CSL_IntcEventId eventId = CSL_INTC_EVENTID_TINTLO_LOCAL;

    Uint16 loadVal = CSL_TMR_WDTCR_WDKEY_CMD1;

    /* 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.tmrClksrcHi = CSL_TMR_CLKSRC_INTERNAL;
    hwSetup.tmrClockPulseLo = CSL_TMR_CP_PULSE;
    hwSetup.tmrClockPulseHi = CSL_TMR_CP_PULSE;
    hwSetup.tmrIpGateLo = CSL_TMR_CLOCK_INP_NOGATE;
    hwSetup.tmrIpGateHi = 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 GP timer CSL module */
    status = CSL_tmrInit(NULL);

    hTmr =  CSL_tmrOpen(&TmrObj, IntcInstance, NULL, &status);

    CSL_tmrHwSetup(hTmr, &hwSetup);

    /* Reset the GP 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);

    status = CSL_tmrHwControl(hTmr, CSL_TMR_CMD_LOAD_WDKEY, \
                               (Uint16 *) &loadVal);

    loadVal = CSL_TMR_WDTCR_WDKEY_CMD2;

    status = CSL_tmrHwControl(hTmr, CSL_TMR_CMD_LOAD_WDKEY, \
                               (Uint16 *)&loadVal);

    /**************************************************************
    * INTC related code and test								  *
    **************************************************************/
    while (1) {
        if (intrCnt == 1)
	        break;
    }

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

    CSL_intcHwControl(tmrIntcHandle, CSL_INTC_CMD_EVTDISABLE, NULL);

	printf("INTR: The Total number of Events occurred are: 0x%d\n", intrCnt);

    intrCnt = 0;

    /* Close the Tmr instance */
    status = CSL_tmrClose(hTmr);
    CSL_intcClose(tmrIntcHandle);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -