DSP2833x_CpuTimers.c, h를 분석한다.
1. InitCpuTimers()
타이머 초기화 함수로써, 우리가 이 함수를 사용할 때는 그냥 호출하면 될것이다. 영어를 읽을 수 있을테니 주석을 잘 보도록 하자.
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;
// CpuTimer2 is reserved for DSP BIOS & other RTOS
// Do not use this timer if you ever plan on integrating
// DSP-BIOS or another realtime OS.
// 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;
}
Timer2에 대한 경고사항이 나와있다. BIOS, RTOS일 때는 Timer2를 사용하지 말라고 한다.
===============================================================================================
void ConfigCpuTimer(struct CPUTIMER_VARS *Timer, float Freq, float Period)
{
Uint32 temp;
// Initialize timer period:
Timer->CPUFreqInMHz = Freq;
Timer->PeriodInUSec = Period;
temp = (long) (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.TIE = 1; // 0 = Disable/ 1 = Enable Timer Interrupt
// Reset interrupt counter:
Timer->InterruptCount = 0;
}
===============================================================================================
ConfigCpuTimer(&CpuTimer0, 150, 1000);
인수는 설정할 CpuTimer의 주소, 주파수(MHz), 주기(uSeconds)이다. 인수에 따른 설정 후 각종 레지스터를 초기화 시켜준다.
위의 경우는 초당 150*10^6회, 인터럽트는 1000us:0.001초당 한번씩 발생하도록 하였다.
두 수를 곱하면 150000으로 초당 150000회의 인터럽트가 발생하는 것이다.
주파수 부분에 아무 값이나 넣으면 안된다. 현재 설정한 SYSCLKOUT의 값을 넣어주도록 하자. 기본적으로 150MHz로 잡혀있다.
===============================================================================================
DSP2833x_CpuTimer.h를 보면 레지스터 및 명령 정의가 나와있다. 예를들어 아래와 같다.
// Start Timer:
#define StartCpuTimer0() CpuTimer0Regs.TCR.bit.TSS = 0
// Stop Timer:
#define StopCpuTimer0() CpuTimer0Regs.TCR.bit.TSS = 1
// Reload Timer With period Value:
#define ReloadCpuTimer0() CpuTimer0Regs.TCR.bit.TRB = 1
// Read 32-Bit Timer Value:
#define ReadCpuTimer0Counter() CpuTimer0Regs.TIM.all
// Read 32-Bit Period Value:
#define ReadCpuTimer0Period() CpuTimer0Regs.PRD.all
친절하게 설명이 나와있으니 사용하는데는 문제가 없다고 본다.
'TMS320 > F28335' 카테고리의 다른 글
2812와 달라진 28335의 주변회로 (0) | 2014.08.20 |
---|---|
SCI (0) | 2014.08.19 |
Cpu Timer(1) (1) | 2014.08.19 |
ADC(2) (0) | 2014.08.18 |
ADC(1) (0) | 2014.08.18 |