MIDTERM EXAM - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

MIDTERM EXAM

Description:

CPU clock pulses 1 billion times/second. A piece ... NT generates interrupt every 10 ms. Or 100 times/sec. ... case1: Do whatever needed at 1 second intervals ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 16
Provided by: phi140
Category:
Tags: exam | midterm | case1

less

Transcript and Presenter's Notes

Title: MIDTERM EXAM


1
MIDTERM EXAM
  • Wednesday, March 12th.
  • There will be no makeup exams.

2
Timers and Timer Messages
  • CPU clock pulses 1 billion times/second
  • A piece of an instruction gets executed at ever
    clock.
  • System clocks Generate interrupts every 54.9 ms
    (Windows).
  • 18.2 times per second.
  • NT generates interrupt every 10 ms. Or 100
    times/sec.
  • Windows handles these asynchronous interrupts
  • Uses hardware interrupts to send WM_TIMER
    messages to application.

3
WM_TIMER Messages
  • SetTimer(hwnd, id, frequency, NULL)
  • frequency in milliseconds.
  • Resolution of the timer messages is based on the
    resolution of the underlying hardware clock
  • if resolution of clock is 54 milliseconds,
    cannot receive messages at a frequency greater
    than 18.2

4
How it Works
  • SetTimer(hwnd, 1, X, NULL)
  • OS takes X / Clock Resolution Y.
  • Every 54.9 ms in Windows. 10 ms in NT.
  • Sets counter equal to the number of timer
    interrupts the OS will receive before timer fires
    (Y)
  • Maintains counter for each timer. This counter
    initialized to Y.
  • On each hardware interrupt, OS decrements
    counter.
  • When counter 0, sends WM_TIMER msg to hwnd and
    resets counter to Y.

5
Example SetTimer(hwnd, 1, 200, NULL)
Initialize counter to 200/55 3.63 rounded
down to 3
Message Queue
Application
X X X X X X
Counter
3
Windows 2000/NT
Hardware
6
Message Queue
Application
X X X X X X
Counter
Interrupt 1
2
Windows 2000/NT
Hardware
7
Message Queue
Application
X X X X X X
Counter
Interrupt 2
1
Windows 2000/NT
Hardware
8
Message Queue
Application
X X X X X X
Counter
Interrupt 3
0
Windows 2000/NT
Hardware
9
Message Queue
Application
X X X X X X T
Counter
0
Windows 2000/NT
Hardware
10
Message Queue
Application
X X X X X X T
Counter
3
Windows 2000/NT
Hardware
11
WM_TIMER Messages
  • Application code is not interrupted for a timer
    msg.
  • Windows places WM_TIMER messages in message queue
    like any other message.
  • If application is busy, the timer messages will
    be received late. Not an exact science.

12
Simple Example
  • switch (message)
  • case WM_CREATE
  • SetTimer(hwnd, 1, 1000, NULL)
  • SetTimer(hwnd, 2, 60000, NULL)
  • return 0
  • case WM_VSCROLL ..
  • case WM_TIMER
  • switch(wParam)
  • case1 Do whatever needed at 1 second
    intervals
  • case 2 Do whatever needed at 1 minute
    intervals.

13
Stopping WM_TIMER messages
  • KillTimer(hwnd, 1)
  • WM_TIMER messages are low priority and Windows
    will combine these messages in the queue.

14
Simple Animtion
  • Timer messages can be used to repaint objects in
    the window to simulate movement.
  • Three steps
  • Erase object.
  • Determine new position for object in response to
    each WM_TIMER message.
  • Redraw object at new location.

15
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com