📄 dsp281x_cputimers.c
字号:
//###########################################################################
//
// FILE: DSP281x_CpuTimers.c
//
// TITLE: DSP281x CPU 32-bit Timers Initialization & Support Functions.
//
//###########################################################################
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
struct CPUTIMER_VARS CpuTimer0;
// CpuTimer 1 and CpuTimer2 are reserved for DSP BIOS & other RTOS
//struct CPUTIMER_VARS CpuTimer1;
//struct CPUTIMER_VARS CpuTimer2;
interrupt void TINT0ISR(void);
//---------------------------------------------------------------------------
// InitCpuTimers:
//---------------------------------------------------------------------------
// This function initializes all three CPU timers to a known state.
//
void InitCpuTimers(void)
{
// CPU Timer 0
// Initialize address pointers to respective timer registers:
CpuTimer0.RegsAddr = &CpuTimer0Regs;
// Initialize timer period to maximum:
CpuTimer0Regs.PRD.all = 0xFFFFFFFF;
// Initialize pre-scale counter to divide by 1 (SYSCLKOUT):
CpuTimer0Regs.TPR.all = 0;
CpuTimer0Regs.TPRH.all = 0;
// Make sure timer is stopped:
CpuTimer0Regs.TCR.bit.TSS = 1;
// Reload all counter register with period value:
CpuTimer0Regs.TCR.bit.TRB = 1;
// Reset interrupt counters:
CpuTimer0.InterruptCount = 0;
// CpuTimer 1 and CpuTimer2 are reserved for DSP BIOS & other RTOS
// Do not use these two timers if you ever plan on integrating
// DSP-BIOS or another realtime OS.
//
// For this reason, the code to manipulate these two timers is
// commented out and not used in these examples.
// Initialize address pointers to respective timer registers:
// CpuTimer1.RegsAddr = &CpuTimer1Regs;
// CpuTimer2.RegsAddr = &CpuTimer2Regs;
// Initialize timer period to maximum:
// CpuTimer1Regs.PRD.all = 0xFFFFFFFF;
// CpuTimer2Regs.PRD.all = 0xFFFFFFFF;
// Make sure timers are stopped:
// CpuTimer1Regs.TCR.bit.TSS = 1;
// CpuTimer2Regs.TCR.bit.TSS = 1;
// Reload all counter register with period value:
// CpuTimer1Regs.TCR.bit.TRB = 1;
// CpuTimer2Regs.TCR.bit.TRB = 1;
// Reset interrupt counters:
// CpuTimer1.InterruptCount = 0;
// CpuTimer2.InterruptCount = 0;
EALLOW;
PieVectTable.TINT0 = &TINT0ISR;
EDIS;
}
//---------------------------------------------------------------------------
// ConfigCpuTimer:
//---------------------------------------------------------------------------
// unit:
// Freq: MHz
// period: μs
// The timer is held in the stopped state after configuration.
//---------------------------------------------------------------------------
//void ConfigCpuTimer(struct CPUTIMER_VARS *Timer, float Freq, float Period)
void ConfigCpuTimer(struct CPUTIMER_VARS *Timer, Uint16 Freq, Uint32 Period)
{
Uint32 temp;
// Initialize timer period:
Timer->CPUFreqInMHz = Freq;
Timer->PeriodInUSec = Period;
// temp = (long) (Freq * Period);
temp = ((Uint32)Freq) * Period;
Timer->RegsAddr->PRD.all = temp;
// Set pre-scale counter to divide by 1 (SYSCLKOUT):
Timer->RegsAddr->TPR.all = 0;
Timer->RegsAddr->TPRH.all = 0;
// Initialize timer control register:
Timer->RegsAddr->TCR.bit.TSS = 1; // 1 = Stop timer, 0 = Start/Restart Timer
Timer->RegsAddr->TCR.bit.TRB = 1; // 1 = reload timer
//Timer->RegsAddr->TCR.bit.SOFT = 1;
//Timer->RegsAddr->TCR.bit.FREE = 1; // Timer Free Run
Timer->RegsAddr->TCR.bit.SOFT = 0;
Timer->RegsAddr->TCR.bit.FREE = 0; //
Timer->RegsAddr->TCR.bit.TIE = 1; // 0 = Disable/ 1 = Enable Timer Interrupt
// Reset interrupt counter:
Timer->InterruptCount = 0;
}
//-------------------------------------------
// Function: CPU time 0 interrupt service routine;
//-------------------------------------------
interrupt void TINT0ISR(void)
{
CpuTimer0.InterruptCount++;
// Serve the watchdog every Timer 0 interrupt
// EALLOW;
// SysCtrlRegs.WDKEY = 0x55; // Serve watchdog #1
// EDIS;
// To receive more interrupts from this PIE group, acknowledge this interrupt
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
// Next two lines for debug only to halt the processor here
// Remove after inserting ISR Code
// ESTOP0;
// for(;;);
}
//===========================================================================
// No more.
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -