22
Real Time Interrupts Section 4.15

Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

Embed Size (px)

Citation preview

Page 1: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

Real Time Interrupts

Section 4.15

Page 2: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

Real-Time Interrupt (RTI)

• Most operating systems (OS) require an interrupt every T seconds by the RTI

• RTI interrupts are often counted to determine time and date (XP, LINUX)

• OS use RTI interrupts for process scheduling

• IBM PC is interrupted 18.2 times per second by RTI

Page 3: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

Real-Time Interrupt

• Two Bits of Interest– RTIE – Real-Time Interrupt Enable

• “0” – Disables Interrupts• “1” – Enables Interrupts

– RTIF – Real-Time Interrupt Flag• Set every T Seconds when RTIE=“1”• Generates Maskable Interrupt when “1”• Write “1” to RTIF to Clear Flag

Page 4: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

Real Time Interrupt68HC12DP256

• Set Up and Controlled using 3 Registers:– RTICTL– CRGINT– CRGFLG

Page 5: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

Clock Generator

• Lab Processor Boards uses a 4 MHz Crystal Oscillator

• Frequency of Bus Clock (ECLK) – 2 MHZ

• RTI uses the 4 MHZ Crystal Clock

Page 6: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts
Page 7: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

4 MHZ

SETS RTI FLAG

Prescaler: Divides by 1, 2, 4, 8, 16, 32, or 64

Divides by 1, 2, 3, 4, 5, 6, • • •, 16

Page 8: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

Divide 4 MHZ Clock by:

1024

AND BY

1 or 2 or 4 or 8 or 16 or 32 or 64 (Selected by RTR[6:4])

AND BY

1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or 10 or 11 or 12 or 13 or 14 or 15 or 16 (Selected by RTR[3:0])

to generate rate of RTI Timeout Output.

Page 9: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

Real Time Interrupt Enable

Page 10: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

Real Time Interrupt FlagPower-On Reset Flag

Self-check Mode Interrupt Flag

Page 11: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

Real Time Control Register

Page 12: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts
Page 13: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

/* rtc1 = RTR[6:4], rtc = RTR[3:3] frti = Frequency of RTI */int rtc1, rtc2; float frti;rtc1 = (RTR>>4)&0x07;rtc2 = RTR&0x0F;if(rtc1==0) frti=0;else frti = 4000000/(1024*(1<<(rtc1-1))*(rtc2+1))

Frequency of RTI

Page 14: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

1 2 3 4 5 6 7

1 3906.25 1953.13 976.56 488.28 244.14 122.07 61.04

2 1953.13 976.56 488.28 244.14 122.07 61.04 30.52

3 1302.08 651.04 325.52 162.76 81.38 40.69 20.35

4 976.56 488.28 244.14 122.07 61.04 30.52 15.26

5 781.25 390.63 195.31 97.66 48.83 24.41 12.21

6 651.04 325.52 162.76 81.38 40.69 20.35 10.17

7 558.04 279.02 139.51 69.75 34.88 17.44 8.72

8 488.28 244.14 122.07 61.04 30.52 15.26 7.63

9 434.03 217.01 108.51 54.25 27.13 13.56 6.78

10 390.63 195.31 97.66 48.83 24.41 12.21 6.10

11 355.11 177.56 88.78 44.39 22.19 11.10 5.55

12 325.52 162.76 81.38 40.69 20.35 10.17 5.09

13 300.48 150.24 75.12 37.56 18.78 9.39 4.70

14 279.02 139.51 69.75 34.88 17.44 8.72 4.36

15 260.42 130.21 65.10 32.55 16.28 8.14 4.07

16 244.14 122.07 61.04 30.52 15.26 7.63 3.81

Page 15: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

Init prescale factor in RTICTLEnable RTIE in CRGINTReset RTIF in CRGFLGEnable maskable interrupts ENABLE();

CRGFLG

Page 16: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

Text RTI Example

• RTI Interrupt every 8.192 msec.

• E Clock is 4 MHZ

• RTICTL is defined differently

• Divide E Clock by 2 raised to power 15– RTR[6:4] = 6– RTR[3:0] = 0– RTICTL = 0x60

• RTI Interrupt Vector Address = 0xFFF0

Page 17: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

TEXT RTI Examples• Replace #include <912b32.h> with• #include <ece371.h>• #include <ports_D256.h>

• Replace interrupt #pragma code with– void RTI_isr() __attribute__ ((interrupt));

• Replace init vector #pragma code but place inside of main program

• Initialize Interrupt Vectors with– SETVECT(0xFFF0,RTI_isr);

Page 18: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

Text RTI Example

• Replace RITCTL=0x84 with• Set Interrupt Frequency, enable RTI, clear RTI

– RTICTL = 0x60;– CRGFLG=0x80;– CRGINT = CRGINT | 0x80;

• Replace RTIFLG=0x80 with• Clear RTI Flag

– CRGFLG = 0x80;

• Replace CLI() Enable Interrupts with– ENABLE();

Page 19: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

/* Real Time Interrupt Example Program Page 206-208 of Text Modified to Execute on Lab Microcontroller

This program keeps track of clock time using the Real Time Interrupts. The RTI generates an interrupt 8.192 ms. The RTI_isr keeps track of elapsed time.*/

/* include files */#include <ece371.h>#include <ports_D256.h>

/* function prototypes */

void RTI_isr(void) __attributes__ ((interrupt));

/* global variables */

unsigned int ms_ctr, sec_ctr, mins_ctr, hrs_ctr, days_ctr;

Page 20: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

void main(void){ms_ctr = 0; // initialize timer variablessec_ctr = 0;mins_ctr = 0;hrs_ctr = 0;days_ctr = 0;

/* initialize RTI - - replaces pragma abs_address, etc. */SETVECT(0xFFF0,RTI_isr); // interrupt vector

// Replace RTICTL = 0x84;

RTICTL = 0x60; // set interrupt frequencyCRGFLG=0x80; // clear RTI interrupt flagCRGINT = CRGINT | 0x80; // enable RTI

/* Enable Interrupts – replace CLI() */ENABLE();

while(1); // wait for interrupts}

Page 21: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

/* RTI_isr: RTI Interrupt Service Routine */void RTI_isr(void){// replaces RTIFLGCRGFLG = CRGFLG | 0x80;

/* update milliseconds */ms_ctr = ms_ctr+1;

/* update seconds */

if(ms_ctr == 122) /* counter equates 1000 ms at 122 */ { ma_ctr = 0; // reset millisecond counter sec_ctr = sec_ctr +1; // increment seconds counter

Page 22: Real Time Interrupts Section 4.15. Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts

/* update minutes */if(sec_ctr == 60) { sec_ctr = 0; // reset seconds counter mins_ctr = mins_ctr+1; // increments minutes counter }

/* update hours */if(mins_ctr == 60) { mins_ctr = 0; // reset minutes counter hrs_ctr = hrs_ctr + 1 // increments hours counter }

/* update days */if(hrs_ctr == 24) { hrs_ctr = 0; // reset hours counter days_ctr = days_ctr + 1; // increment days counter }}