Programmable Interrupt Timer Modules PIT 0 PIT 1
Programmable Interrupt Timer Modules PIT 0, PIT 1, PIT 2, PIT 3
Memory Map
Status Register
Status Register Prescaler Field
Status Register Control / Status Fields
Modulus Register
Count Register
Functional Operation
Example Program /* --------------------------------------This example program exercises the Programmable Interval Timer in the 5282 CPU --------------------------------------- */ #include "predef. h" #include <stdio. h> #include <ctype. h> #include <startnet. h> #include <autoupdate. h> #include <dhcpclient. h> #include <. . mod 5282systemsim 5282. h> #include <cfinter. h> #include <utils. h> /* ----- function prototypes ----- */ extern "C" { void User. Main(void * pd); /* This function sets up void Set. Intc(int intc, long func, int vector, int level, int prio the 5282 interrupt controller */ /* Interrupt Controller Number */ /* Address of Interrupt Service Routine */ /* Vector Table Number */ /* Interupt Priority Level */ /* Interrupt Priority Sub Level */ ); } /* ----- global variables ----- */ volatile DWORD pit_count = 0;
Example Program (cont) /* ---------------------------------------PIT Interrupt Service Routine ---------------------------------------- */ INTERRUPT(my_pit_func, /* Name of Interrupt Service Routine */ 0 x 2600 /* Mask - Enter Supervisor Mode, Set Interrupt Mask */ ) { static WORD led_count; WORD tmp = sim. pit[1]. pcsr; /* use PIT 1 */ /* Initialize PIT 1 (0 --> 7 -4, 1 --> 3 -0 ) */ tmp &= 0 x. FF 0 F; tmp |= 0 x 0 F; sim. pit[1]. pcsr = tmp; /* You can add your ISR code here. - Do not call any RTOS function with pend or init in the function name - Do not call any functions that perform a system I/O read, write, printf, iprint etc. */ putleds(led_count++); pit_count++; }
Example Program (cont) /* ------------------------------------------PIT Setup function. See chapter 19 of the 5282 users manual for details ------------------------------------------- */ void Set. Up. PITR(int pit_ch, /* Pit Channel Number */ WORD clock_interval, /* Timer Modulus Number */ BYTE pcsr_pre /* Timer Prescaler - See Users Manual table 19 -3 */ ) { WORD tmp; if ((pit_ch<1) || (pit_ch > 3)) return; /* Check for valid PIT */ /* populate the interrupt vector in the interrupt controller */ Set. Intc(0, /* Interrupt Controller Number */ (long)&my_pit_func, /* Address of Interrupt Service Routine */ 55 + pit_ch, /* Vector Table Number */ 2, /* Interupt Priority Level */ 3 /* Interrupt Priority Sub Level */ ); /* set up PIT Control & Status Register (PCSR) */ sim. pit[pit_ch]. pmr = clock_interval; tmp = pcsr_pre; tmp = (tmp << 8) | 0 x 0 F; sim. pit[pit_ch]. pcsr = tmp; }
Example Program (cont) /* -------------------------------------User. Main ------------------------------------- */ void User. Main(void * pd) { Initialize. Stack(); if (Ethernet. IP == 0) Get. DHCPAddress(); OSChange. Prio(MAIN_PRIO); Enable. Auto. Update(); /* wait 16200 counts & divide the cpu clock (66. 355 MHz) by 4096 - this equals approximately one pitr event per second */ Set. Up. PITR(1, /* Use PIT channel 1 */ 16200, /* Wait 16200 clocks */ 11 /* Divide by 4096 - see table 19 -3 */ ); iprintf("Application startedn"); while (1) { OSTime. Dly(20); /* Wait approximately 5 sec */ iprintf("PIT count = %ldrn", pit_count); } }
Interrupt Vector Table
Interrupt Vector Table (cont)
Interrupt Vector Table (cont)
- Slides: 15