2019/5/14 asm

1
2
3
4
5
6
7
interrupt void cpu_timer0_isr(void);

PieVectTable.TINT0 = &cpu_timer0_isr;

ConfigCpuTimer(&CpuTimer0, 150, 1000000);

StartCpuTimer0();
  • This function initializes the selected timer to the period specified
    by the “Freq” and “Period” parameters. The “Freq” is entered as “MHz”
    and the period in “uSeconds”. The timer is held in the stopped state
    after configuration.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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;
}