DSP

DSP 之定时器设置(TIMER)

2019-07-13 09:44发布

DSP 之定时器设置(TIMER): /* * Copyright (C) 2003 Texas Instruments Incorporated * All Rights Reserved */ #include #include #include #include //---------Global data definition--------- #define TIMER_CTRL TIMER_TCR_RMK( TIMER_TCR_IDLEEN_DEFAULT, /* IDLEEN == 0 */ TIMER_TCR_FUNC_OF(0), /* FUNC == 0 */ TIMER_TCR_TLB_RESET, /* TLB == 1 */ TIMER_TCR_SOFT_BRKPTNOW, /* SOFT == 0 */ TIMER_TCR_FREE_WITHSOFT, /* FREE == 0 */ TIMER_TCR_PWID_OF(0), /* PWID == 0 */ TIMER_TCR_ARB_RESET, /* ARB == 1 */ TIMER_TCR_TSS_START, /* TSS == 0 */ TIMER_TCR_CP_PULSE, /* CP == 0 */ TIMER_TCR_POLAR_LOW, /* POLAR == 0 */ TIMER_TCR_DATOUT_0 /* DATOUT == 0 */ ) /* Create a TIMER configuration structure that can be passed */ /* to TIMER_config CSL function for initialization of Timer */ /* control registers. */ TIMER_Config timCfg0 = { TIMER_CTRL, /* TCR0 Timer Control register */ 0x0400u, /* PRD0 Period Register(周期寄存器)*/ 0x0000 /* PRSC Timer Pre-scaler Register (定时器预分频寄存器 */ }; /* Create a TIMER_Handle object for use with TIMER_open */ TIMER_Handle mhTimer0; Uint16 eventId0; volatile Uint16 timer0_cnt = 0; int old_intm; Uint16 tim_val; /* Reference start of interrupt vector table */ /* This symbol is defined in file, vectors_timer1.s55 */ extern void VECSTART(void); /* interupt Time0 handle function */ interrupt void timer0Isr(void); /* User's function */ void taskFxn(void); void main(void) { /* Initialize CSL library */ CSL_init(); /* Set IVPH/IVPD to start of interrupt vector table */ IRQ_setVecs((Uint32)(&VECSTART)); /* Call function to set timer */ taskFxn(); } void taskFxn(void) { /* Temporarily disable all maskable interrupts */ old_intm = IRQ_globalDisable(); /* Open Timer 0, set registers to power on defaults */ mhTimer0 = TIMER_open(TIMER_DEV0, TIMER_OPEN_RESET); /* Get Event Id associated with Timer 0, for use with */ /* CSL interrupt enable functions. */ /* Obtains IRQ event ID for TIMER device */ eventId0 = TIMER_getEventId(mhTimer0); /* Clear any pending Timer interrupts */ IRQ_clear(eventId0); /* Place interrupt service routine address at */ /* associated vector location * Initialize interrupt vector table */ IRQ_plug(eventId0,&timer0Isr); /* Write configuration structure values to Timer control regs */ TIMER_config(mhTimer0, &timCfg0); /* Enable Timer interrupt */ IRQ_enable(eventId0); /* Enable all maskable interrupts * extern interrupt */ IRQ_globalEnable(); /* Start Timer device running */ TIMER_start(mhTimer0); /* Wait for at least 10 timer periods */ while(timer0_cnt != 10) { printf("Timer: %d ", timer0_cnt); } /* Consider TEST PASSED if 10 interrupts occur */ printf(" TEST PASSED "); /* Restore old value of INTM */ IRQ_globalRestore(old_intm); /* We are through with timer, so close it */ TIMER_close(mhTimer0); } /* Time interrupt */ interrupt void timer0Isr(void) { ++timer0_cnt; }
  之前编译时一直出现警告:   现在解决如下:   搞定,接下来的几天我继续发表DSP的文章,嘿嘿,如果有时间的话我会写写Linux方面的东西。                                                                             当我一个人的时候我常会听这首歌: playBtn&fr=-1 希望各位也喜欢!!