Download presentation
Presentation is loading. Please wait.
Published byTyrone Simon Modified over 6 years ago
1
Buffered, Interrupt-Driven Printer Design Example
Module 2.F Buffered, Interrupt-Driven Printer Design Example Tim Rogers 2017
2
Learning Outcome #2 Bus Timing Analysis
“An ability to interface a microcontroller to various devices” Bus Timing Analysis 9S12C Multiplexed Bus Expansion General-Purpose I/O Ports Interrupt Handling Buffered I/O Buffered, Interrupt-Driven Printer Design Example How?
3
Interrupts the CPU to consume characters – when its ready
Objective “Buffered, Interrupt-Driven Printer Design Example” Interrupts the CPU to consume characters – when its ready Produces Characters
4
Review: Printer Handshaking
What will happen when the interrupt occurs? (A) CPU copies a new character to the buffer (B) CPU copies next value from buffer to data bus (C) Printer copies data off the data bus (D) Printer puts a new value on the buffer (E) Nothing Review: Printer Handshaking When should the interrupt occur? (A) Strobe to low (B) Strobe to high (C) Busy to low (D) Busy to high (E) When next char does on bus 3 4 STROBE 1 5 BUSY 2 Previous Character Next Character DATA
5
What does it mean for the interrupt to be masked?
Printer Interrupt Enable (PIE) Bit (from CPU) PIE has to be 1 for the interrupt to be asserted Flag Clear (From CPU) CLR Q IRQ (to CPU) 1 D Q Interrupt Request (From Device)
6
Example Circuit PIE
7
How to use PIE When buffer is empty: CPU has nothing to send
When buffer has content: CPU has stuff waiting to send PIE=1
8
Life without PIE Printer will continuously trigger interrupt while busy is 0 If buffer is empty – printer never becomes busy STROBE BUSY Previous Character Last Character in Buffer DATA
9
Prof. Meyer calls this a “Digital Binky”
Life with PIE When buffer empties: Set PIE=0 STROBE BUSY PIE Prof. Meyer calls this a “Digital Binky” Previous Character Last Character in Buffer DATA
11
How to use PIE When buffer is empty: CPU has nothing to send
When buffer has content: CPU has stuff waiting to send PIE=1
12
Driver Declarations smask equ $02 ; STROBE mask
imask equ $04 ; PIE enable mask cmask equ $08 ; flag clear mask psize equ ; buffer size pbuf rmb psize; printer buffer pin fcb ; printer IN ptr pout fcb ; printer OUT ptr
13
Driver Initialization Routine
smask equ $02 ; printer STROBE mask imask equ $04 ; printer intr en mask cmask equ $08 ; dev flag clear mask pinit movb #$FF,ddrx movb #$0E,ddry bset porty,cmask bclr porty,cmask ;assert FLG_CLR’ bset porty,cmask ;to initialize bclr porty,imask ;clear PIE bit clr portx ;ASCII null bset porty,smask bclr porty,smask ;assert STROBE’ bset porty,smask ;to initialize cli ;enable IRQ rts Initialization Routine sends ASCII 0 to “Prime the system”
14
Useful Macro Macro for incrementing B register mod BUFSIZE
Example: incBmod 20 ; increments B modulo 20 incBmod MACRO incb cmpb #\1 bne $+3 clrb ENDM
15
Device Driver – API Application program interface that places characters in the printer buffer (the “producer”) 1. Check status of printer buffer 2. If FULL, wait for space 3. Else, put character in buffer at IN 4. Increment IN modulo BUFSIZE 5. Enable (“unmask”) printer interrupts 6. Exit
16
Device Driver – API ; Buffered printer spooler routine
; Character passed in A register placed in PBUF ; ; STEP (1) Check PBUF status bps ldab pin incBmod psize ;(B)=(PIN+1)mod PSIZE pshb ;save on stack ; STEP (2) If FULL, wait for space pwait cmpb pout ;perform FULL check beq pwait ;wait if PBUF full
17
Device Driver – API ; STEP (3) Put character in PBUF at IN ldx #pbuf
ldab pin staa b,x ;PBUF[PIN] = (A) ; STEP (4) Increment IN modulo PSIZE pulb ;retrieve from stack stab pin ;PIN=PIN+1 mod PSIZE ; STEP (5) Enable printer interrupts bset porty,imask ; STEP (6) Exit rts
18
Device Driver – ISR Interrupt service routine that outputs next character in buffer to the printer (the “consumer”) 1. Check status of printer buffer 2. If EMPTY, disable (“mask”) printer interrupts and exit 3. Else, clear printer device flag 4. Output character pointed to by OUT 5. Assert printer’s STROBE signal 6. Increment OUT modulo BUFSIZE 7. Exit
19
Device Driver – ISR ; Printer interrupt service routine ;
; STEP (1) Check PBUF status prisr ldab pout cmpb pin bne pok ;if not empty, print ; STEP (2) If buffer is empty, disable printer ; interrupts and exit bclr porty,imask rti
20
Device Driver – ISR ; Printer interrupt service routine ;
; STEP (3) Clear printer device flag pok bclr porty,cmask bset porty,cmask ; STEP (4) Output character pointed to by OUT ldx #pbuf ldaa b,x ;(A)=PBUF[POUT] staa portx
21
Device Driver – ISR ; Printer interrupt service routine ;
; STEP (5) Strobe printer bclr porty,smask bset porty,smask ; STEP (6) Increment OUT mod PSIZE incBmod psize stab pout ;POUT=(POUT+1) mod PSIZE ; STEP (7) Exit rti
22
1. Will Coach need a Digital Binky to make it through this B-ball season? A. yes B. no
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.