150 likes | 385 Views
Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3. Memory Map. Status Register. Status Register Prescaler Field. Status Register Control / Status Fields. Modulus Register. Count Register. Functional Operation.
E N D
/* ----------------------------------------------------------------------------- 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 <..\mod5282\system\sim5282.h> #include <cfinter.h> #include <utils.h> /* ----- function prototypes ----- */ extern "C" { void UserMain(void * pd); /* This function sets up the 5282 interrupt controller */ void SetIntc(int intc, /* Interrupt Controller Number */ long func, /* Address of Interrupt Service Routine */ int vector, /* Vector Table Number */ int level, /* Interupt Priority Level */ int prio /* Interrupt Priority Sub Level */ ); } /* ----- global variables ----- */ volatile DWORD pit_count = 0; Example Program
Example Program (cont) /* ------------------------------------------------------------------------------ PIT Interrupt Service Routine ------------------------------------------------------------------------------- */ INTERRUPT(my_pit_func, /* Name of Interrupt Service Routine */ 0x2600 /* 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 &= 0xFF0F; tmp |= 0x0F; 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 SetUpPITR(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 */ SetIntc(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) | 0x0F; sim.pit[pit_ch].pcsr = tmp; }
Example Program (cont) /* -------------------------------------------------------------------------- UserMain -------------------------------------------------------------------------- */ void UserMain(void * pd) { InitializeStack(); if (EthernetIP == 0) GetDHCPAddress(); OSChangePrio(MAIN_PRIO); EnableAutoUpdate(); /* wait 16200 counts & divide the cpu clock (66.355 MHz) by 4096 - this equals approximately one pitr event per second */ SetUpPITR(1, /* Use PIT channel 1 */ 16200, /* Wait 16200 clocks */ 11 /* Divide by 4096 - see table 19-3 */ ); iprintf("Application started\n"); while (1) { OSTimeDly(20); /* Wait approximately 5 sec */ iprintf("PIT count = %ld\r\n",pit_count); } }