1 | //initialisierung des timers0
|
2 | //************************ TIMER0
|
3 | void InitCpuTimers(void)
|
4 | {
|
5 | // CPU Timer 0
|
6 | // Initialize address pointers to respective timer registers:
|
7 | CpuTimer0.RegsAddr = &CpuTimer0Regs;
|
8 | // Initialize timer period to maximum:
|
9 | CpuTimer0Regs.PRD.all = 0xFFFFFFFF;
|
10 | // Initialize pre-scale counter to divide by 1 (SYSCLKOUT):
|
11 | CpuTimer0Regs.TPR.all = 0;
|
12 | CpuTimer0Regs.TPRH.all = 0;
|
13 | // Make sure timer is stopped:
|
14 | CpuTimer0Regs.TCR.bit.TSS = 1;
|
15 | // Reload all counter register with period value:
|
16 | CpuTimer0Regs.TCR.bit.TRB = 1;
|
17 | // Reset interrupt counters:
|
18 | CpuTimer0.InterruptCount = 0;
|
19 |
|
20 | }
|
21 |
|
22 | //---------------------------------------------------------------------------
|
23 | // ConfigCpuTimer:
|
24 | //---------------------------------------------------------------------------
|
25 | // This function initializes the selected timer to the period specified
|
26 | // by the "Freq" and "Period" parameters. The "Freq" is entered as "MHz"
|
27 | // and the period in "uSeconds". The timer is held in the stopped state
|
28 | // after configuration.
|
29 | //
|
30 | void ConfigCpuTimer(struct CPUTIMER_VARS *Timer, float Freq, float Period)
|
31 | {
|
32 | Uint32 temp;
|
33 |
|
34 | // Initialize timer period:
|
35 | Timer->CPUFreqInMHz = Freq;
|
36 | Timer->PeriodInUSec = Period;
|
37 | temp = (long) (Freq * Period);
|
38 | Timer->RegsAddr->PRD.all = temp;
|
39 |
|
40 | // Set pre-scale counter to divide by 1 (SYSCLKOUT):
|
41 | Timer->RegsAddr->TPR.all = 0;
|
42 | Timer->RegsAddr->TPRH.all = 0;
|
43 |
|
44 | // Initialize timer control register:
|
45 | Timer->RegsAddr->TCR.bit.TSS = 1; // 1 = Stop timer, 0 = Start/Restart Timer
|
46 | Timer->RegsAddr->TCR.bit.TRB = 1; // 1 = reload timer
|
47 | Timer->RegsAddr->TCR.bit.SOFT = 1;
|
48 | Timer->RegsAddr->TCR.bit.FREE = 1; // Timer Free Run
|
49 | Timer->RegsAddr->TCR.bit.TIE = 1; // 0 = Disable/ 1 = Enable Timer Interrupt
|
50 |
|
51 | // Reset interrupt counter:
|
52 | Timer->InterruptCount = 0;
|
53 | }
|
54 |
|
55 | void timer0_init(void)
|
56 | {
|
57 | EALLOW; // This is needed to write to EALLOW protected registers
|
58 | PieVectTable.TINT0 = &cpu_timer0_isr;
|
59 | EDIS; // This is needed to disable write to EALLOW protected registers
|
60 | }
|
61 |
|
62 |
|
63 |
|
64 | interrupt void cpu_timer0_isr(void)
|
65 | {
|
66 | timer_var=timer_var;
|
67 | test_variable=CpuTimer0.InterruptCount++;
|
68 |
|
69 | // Acknowledge this interrupt to receive more interrupts from group 1
|
70 | PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
|
71 | }
|
72 |
|
73 | //*************************** TIMER 0
|