?? dec643_timer.c
字號:
/************************************************************
Copyright (C), 2007 by SEED Electronic Technology LTD.
FileName: DEC643_Timer.c
Author: Ya.X Version : V1.0 Date:2007-09-20
Description: 定時器的使用:
程序將產生特定頻率的方波,通過Tout0輸出,可以
通過示波器察看波形
產生定時的中斷,并執行中斷處理程序
*************************************************************/
#include <stdio.h>
#include <csl.h>
#include <csl_timer.h>
#include <csl_irq.h>
#include "DEC643.h"
#define TIMER_CNT 60 //定義中斷最大計數次數
static Uint32 cnt = 0; //中斷次數計數
void TimerEventHandler(void);
extern far void vectors();
static TIMER_Handle hTimer1;
//Timer 控制寄存器配置
static Uint32 TimerControl = TIMER_CTL_RMK( /* Timer control register (CTL)*/
TIMER_CTL_SPND_EMUSTOP,
TIMER_CTL_INVINP_NO, /* TINP inverter control(INVINP). Only affects operation
if CLKSRC =0.
TIMER_CTL_INVINP_NO - Uninverted TINP drives timer
TIMER_CTL_INVINP_YES - inverted TINP drives timer */
TIMER_CTL_CLKSRC_CPUOVR8,/* Timer input clock source (CLKSRC)
TIMER_CTL_CLKSRC_CPUOVR4 - CPU clock /8 */
TIMER_CTL_CP_CLOCK, /* Clock/pulse mode(CP)
TIMER_CTL_CP_PULSE - Pulse mode.TSTAT is active one
CPU clock after the timer reaches the timer
period.PWID determines when it goes inactive.*/
TIMER_CTL_HLD_YES, /* Hold(HLD). Counter may be read or written regardless of
HLD value.
TIMER_CTL_HLD_YES - Counter is disabled and held in
current value.
TIMER_CTL_HLD_NO - COunter is allowed to count. */
TIMER_CTL_GO_NO, /* Go bit(GO). Resets and starts the timer counter.
TIMER_CTL_GO_NO - No effects on the timer.
TIMER_CTL_GO_YES - if HLD =1, the counter register
is zeroed and begins counting on next clock. */
TIMER_CTL_PWID_TWO, /* Pulse width(PWID). Only used in pulse mode.
TIMER_CTL_PWID_ONE - TSTAT goes inactive one timer
input clock cycle after the timer counter value
equals the timer period value.
TIMER_CTL_PWID_TWO - TSTAT goes inactive one timer
input clock cycle after the timer counter value
equals the timer period value. */
TIMER_CTL_DATOUT_0, /* Data output (DATOUT).
TIMER_CTL_DATOUT_0 - If FUNC =0,the DATOUT is
driven on TOUT.
TIMER_CTL_DATOUT_1 - If FUNC =1,The DATOUT is driven
on TOUT after inversion by INVOUT. */
TIMER_CTL_INVOUT_NO, /* TOUT inverter control (INVOUT)
TIMER_CTL_INVOUT_NO - Uninverted TSTAT drives TOUT
TIMER_CTL_INVOUT_YES - Inverted TSTAT drives TOUT.*/
TIMER_CTL_FUNC_TOUT /* Function of TOUT pin(FUNC).
TIMER_CTL_FUNC_GPIO - TOU is a general purpose
output pin
TIMER_CTL_FUNC_TOUT - TOUT is a timer output pin */
);
void main()
{
static Uint32 TimerEventId;
/* initialize the CSL library */
CSL_init();
/* Initialize DEC643 board */
DEC643_init();
/* Open TIMER1 device, and reset them to power-on default state. */
hTimer1 = TIMER_open(TIMER_DEV1, TIMER_OPEN_RESET);
/* Configure the timer devices */
TIMER_configArgs(hTimer1,
TimerControl, /* use predefined control value */
0x00000B72, /* set period */
0x00000000 /* start count value at zero */
);
/* Obtain the event ID for the timer device. */
TimerEventId = TIMER_getEventId(hTimer1);
IRQ_globalDisable();
IRQ_setVecs(vectors); /* point to the IRQ vector table */
IRQ_map(TimerEventId, 14); /* Map TIMER events to physical interrupt number */
IRQ_reset(TimerEventId); /* Reset the timer events. */
IRQ_enable(TimerEventId); /* Enable the timer events(events are disabled while resetting) */
IRQ_globalEnable(); /* Globally enable interrupts */
IRQ_nmiEnable(); /* Enable NMI interrupt */
/* Start the timers */
TIMER_start(hTimer1);
while(cnt <= TIMER_CNT); /* waiting for interrupt*/
}
/*************************************************
Function: TimerEventHandler
Description: 被中斷服務程序調用
Calls: No
Called By: 中斷服務程序c_int14
Input: No
Output: No
Return: No
Others: No
*************************************************/
void TimerEventHandler(void)
{
/* process timer event here */
cnt++;
/* Exit from the program when certain count is reached */
if ( cnt > TIMER_CNT )
{
TIMER_pause(hTimer1);
TIMER_close(hTimer1);
printf("\nDone...");
exit(0);
}
printf("\n Count : %3d ",cnt);
}
/*************************************************
Function: c_int14
Description: 定時器中斷服務程序
Calls: No
Called By: Timer1產生的硬件中斷14
Input: No
Output: No
Return: No
Others: No
*************************************************/
interrupt void c_int14(void)
{
TimerEventHandler();
return;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -