/* * Copyright 2002 by Texas Instruments Incorporated. * All rights reserved. Property of Texas Instruments Incorporated. * Restricted rights to use, duplicate or disclose this code are * granted through contract. * */ /* "@(#) DSP/BIOS 4.80.188 12-06-02 (bios,dsk5416-a11)" */ /******************************************************************************\ * Copyright (C) 2000 Texas Instruments Incorporated. * All Rights Reserved *------------------------------------------------------------------------------ * FILENAME...... timer.c * DATE CREATED.. 01/11/2000 * LAST MODIFIED. 12/29/2000 \******************************************************************************/ #include #include #include #include #include "uart.h" /*----------------------------------------------------------------------------*/ /* In this exmaple, we are simply setting the timer to interrupt */ /* every 0x800 clock cycles. All timer setup will be done in a */ /* TASK function that executes after exit from "main" */ /* Create a timer control structure */ TIMER_Config myTConfig = { TIMER_TCR_RMK( TIMER_TCR_SOFT_WAITZERO, TIMER_TCR_FREE_NOSOFT, TIMER_TCR_TRB_RESET, TIMER_TCR_TSS_START, TIMER_TCR_TDDR_OF(0) ), /* TCR0 */ 0x0800u /* PRD0 */ }; /* Global declarations */ TIMER_Handle mhTimer; volatile Uint16 timer_int_cnt = 0; interrupt void timerIsr(void); void taskFunc(void); /*----------------------------------------------------------------------------*/ void main() { uart_puts("C5416 Timer Test Start...\n"); /* Initialize CSL library, this step is required */ CSL_init(); /* Call example task/function */ taskFunc(); while(1); } /*----------------------------------------------------------------------------*/ void taskFunc(void) { Uint16 eventId; int old_intm; Uint16 err = 0; //printf("\n"); uart_puts("\n"); /* Temporarily disable all maskable interrupts, preserving */ /* previous state of INTM */ old_intm = IRQ_globalDisable(); /* Open Timer 0, this returns a pointer to a Timer Handle */ /* that will be used as an argument to other CSL functions */ mhTimer = TIMER_open(TIMER_DEV0, TIMER_OPEN_RESET); /* Write configuration structure values to Timer control */ /* registers. */ TIMER_config(mhTimer, &myTConfig); /* Get Event ID associated with Timer interrupt */ eventId = TIMER_getEventId(mhTimer); /* Clear any pending Timer interrupts */ IRQ_clear(eventId); /* Place interrupt service routine address at associated vector */ IRQ_plug(eventId,timerIsr); /* Enable Timer interrupt */ IRQ_enable(eventId); /* Enable all maskable interrupts */ IRQ_globalEnable(); /* Start Timer */ TIMER_start(mhTimer); /* wait for 20 timer periods */ while(timer_int_cnt < 20); /* We are through with the Timer, so close it */ TIMER_close(mhTimer); /* Restore old value of INTM */ IRQ_globalRestore(old_intm); if (timer_int_cnt < 20) ++err; //printf("%s\n",err?"TEST FAILED":"TEST PASSED"); //printf("\n"); if (err) uart_puts("TEST FAILED\n"); else uart_puts("TEST PASSED\n"); uart_puts("\n"); } /*----------------------------------------------------------------------------*/ /* Timer ISR - will be called by DSP/BIOS dispatcher */ interrupt void timerIsr(void) { TIMER_stop(mhTimer); timer_int_cnt = timer_int_cnt + 1; if (timer_int_cnt < 20) { TIMER_start(mhTimer); } uart_puts("Entry Timer Isr function...\n"); }