programmable interrupt timer modules pit0, pit1, pit2, pit3

15
Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3

Post on 19-Dec-2015

238 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3

Programmable Interrupt Timer ModulesPIT0, PIT1, PIT2, PIT3

Page 2: Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3

Memory Map

Page 3: Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3

Status Register

Page 4: Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3

Status Register Prescaler Field

Page 5: Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3

Status Register Control / Status Fields

Page 6: Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3

Modulus Register

Page 7: Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3

Count Register

Page 8: Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3

Functional Operation

Page 9: Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3

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 <..\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;

Page 10: Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3

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++;}

Page 11: Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3

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;}

Page 12: Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3

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); }}

Page 13: Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3

Interrupt Vector Table

Page 14: Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3

Interrupt Vector Table (cont)

Page 15: Programmable Interrupt Timer Modules PIT0, PIT1, PIT2, PIT3

Interrupt Vector Table (cont)