ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing...

15
ELE22MIC Lecture 8 • ASll Examples – 16 Bit Counters – Buffalo Jump Table • Interrupt processing (IRQ/RTI) • Stack Frame & Base Pointer • Wired OR

Transcript of ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing...

Page 1: ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.

ELE22MIC Lecture 8• ASll Examples

– 16 Bit Counters– Buffalo Jump Table

• Interrupt processing (IRQ/RTI)

• Stack Frame & Base Pointer

• Wired OR

Page 2: ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.

AS11 Example (1)-16 bit counters* 16 Bit counter problemsloop_counter rmb 2 ; declare 2 bytes for 16 bit counter

; then execute code as follows:dec_count:

dec loop_counter ; only one byte is decremented !!!rts

; How can we fix this problem?; One way is to use a 16 bit register as follows:

dec_count:ldd #FFFF ; we can loop 65535 timesstd loop_counter

lots_of_loops:jsr do_something ; do something

pshy ; save the y index register valueldy loop_counter ; load value of loop_counter -> Ydey ; decrement y = decrement loop_countersty loop_counter ; store value of y-> loop_counterpuly ; recover saved y index register value

bne loop_again ; if (loop_counter <> 0), loop againrts

Page 3: ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.

68HC11 Parallel I/O & Control (1)

Page 4: ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.

AS11 Example (2) - Bit IO (1)

* The 68HC11 has single Bit Set & Bit Clear instructions set or clear * individual bits at the selected memory location. * The instruction format is BSET/BCLR MemoryAddress Mask* A ‘1’ in the Mask indicates this bit should be Set/Cleared* A ‘0’ in the Mask indicates that the bit will not be changed.* I.e. BSET bitwise-ORs the Mask onto memory* BCLR bitwise-ANDs the inverse of the Mask onto memory* We can declare equates as follows to access them:Bit0 EQU %00000001 ; = 1Bit1 EQU %00000010 ; = 2Bit2 EQU %00000100 ; = 4Bit3 EQU %00001000 ; = 8Bit4 EQU %00010000 ; = $10Bit5 EQU %00100000 ; = $20Bit6 EQU %01000000 ; = $40Bit7 EQU %10000000 ; = $80AllBits EQU %11111111 ; = $FFLowNyyble EQU %00001111 ; = $0FHighNyyble EQU %11110000 ; = $F0LoopMax EQU 100

IOREG EQU $1000 ; start address of Configuration RegistersPORTB EQU 4

Page 5: ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.

AS11 Example (2) - Bit IO (2)

FlashLeds: ; Connect LEDs to PortBLDAA LoopMax ; A = 100 = Our loop counterLDX #IOREG ; X = $1000

BCLR PORTB, X AllBits ; PortB = %00000000

LOOPAGAIN:BSET PORTB, X BIT0 ; PortB = %00000001BSET PORTB, X BIT1 ; PortB = %00000011BSET PORTB, X BIT2 ; PortB = %00000111BSET PORTB, X BIT3 ; PortB = %00001111BSET PORTB, X BIT4 ; PortB = %00011111BSET PORTB, X BIT5 ; PortB = %00111111BSET PORTB, X BIT6 ; PortB = %01111111BSET PORTB, X BIT7 ; PortB = %11111111jsr wait_a_bitBCLR PORTB, X LowNybble; PortB = %11110000BCLR PORTB, X HighNybble; PortB = %00000000jsr wait_a_bitBSET PORTB, X HighNybble; PortB = %11110000BCLR PORTB, X HighNybble; PortB = %00000000DECABNE LOOPAGAIN ; loop 100 timesRTS

Page 6: ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.

Wired OR - IRQ A Wired-NOR gate is formed by connecting open-collector device interrupt lines together.

Normal gates would fight causing high current drain and possibly damage the gate.

Page 7: ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.

IRQ Processing (1)

Any device requiring attention activates an interrupt service routine simply by asserting its interrupt output.

The interrupt causes the CPU to :

1. Complete the current instruction - delay interrupt servicing until the current instruction completes

(delay of from 1 (ABA) - 41 (IDIV) clock cycles)

2. Push all registers - PC, X, Y, AccA, AccB & CCR

3. Mask interrupts by setting the I bit in CCR

3. Fetch the interrupt vector

4. Jump to the address fetched from the int. vector

Page 8: ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.

IRQ Processing (2)

The Interrupt Service Routine (ISR) must then poll all devices connected to the IRQ pin and ask each device in turn:

“Did you interrupt me?”

Upon finding a device requiring service, perform the appropriate Input/Output/Processing and reset the device’s interrupt request (so that upon return the cpu is not immediately interrupted again).

Upon successful servicing, the ISR must exit without altering the previously running program’s state. The ISR does this simply by executing the RTI instruction (ReTurn from Interrupt).

Page 9: ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.

IRQ Processing (3)

The RTI instruction :Pulls all the previously saved registers from the stack, in the reverse order that they were pushed, so that all registers contain the previous values.

Pul : CCR, AccB, AccA, Y, X, PC

The last pul - Pul PC - Pulls (pops) the program counter which effectively transfers program execution to the instruction immediately following the instruction completed before the interrupt request was accepted.

Pulling the CCR re-enables the CPUs ability to be interrupted as the I flag which was cleared will be cleared again.

Page 10: ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.

IRQ Processing (4)

If the interrupt mask bit, I, in the CCR is unmasked during the ISR, then the IRQ line could cause one or more nested interrupts.

This ISR nesting procedure would normally only be performed to provide more rapid response to a higher priority device.

Page 11: ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.

Stack Frame (1)

In the C language, the function parameters are normally pushed in the reverse order that they are listed. This is to facilitate C’s format statements for example:

Printf (“P1=%3d, P2=%4d\n”, P1, P2);

would compile to:

Push P2

Push P1

Push FormatStatement

JSR Printf ; Printf knows where the ; format statement will be

Add SP, #6 ; drop the parameters

Page 12: ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.

Stack Frame (2)

The subroutine Printf expects to find the format statement as the first parameter on the stack. It then parses the statement, and determines how many more, and what type of, parameters are required.

The return address is also placed on the stack.

Also Local variables are pushed onto the stack.

During the function these variables can be accessed on the stack frame as follows: P2(SP+A)->10A

P1(SP+8)->108FormatStt(SP+6)->A:H29106ReturnAddress(SP+4)->104LocalVariable1(SP+3)->102LocalVariable2SP+1>100

SP->

Page 13: ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.

Frame/Base Pointer (2)

P2(X+A)->10AP1(X+8)->108FormatStt(X+6)->106ReturnAddress(x+4)->104LocalVar1(X+2)->102LocalVar2X->100

SP->

For the duration of the function execution a frame pointer can be set up using the X or Y registers, and the variables may be accessed using indexed addressing

P2 EQU A

P1 EQU 8

FormatStt EQU 6

LocalVar1 EQU 2

LocalVar2 EQU 0

TSX ; X = SP+1 (Setup Frame Ptr)

LDD P1, X ; D = P1(Fetch P1)

STD LocalVar1, X ; LocalVar = AccD = P1

Page 14: ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.

Buffalo Routines Jump Table (1)

ORG ROMBS+$1F7C.WARMST JMP MAIN warm start.BPCLR JMP BPCLR clear breakpoint table.RPRINT JMP RPRINT display user registers.HEXBIN JMP HEXBIN convert ascii hex char to binary.BUFFAR JMP BUFFARG build hex argument from buffer.TERMAR JMP TERMARG read hex argument from terminal.CHGBYT JMP CHGBYT modify memory at address in x.READBU JMP READBUFF read character from buffer.INCBUF JMP INCBUFF increment buffer pointer.DECBUF JMP DECBUFF decrement buffer pointer.WSKIP JMP WSKIP find non-whitespace char in buffer.CHKABR JMP CHKABRT check for abort from terminal

Page 15: ELE22MIC Lecture 8 ASll Examples –16 Bit Counters –Buffalo Jump Table Interrupt processing (IRQ/RTI) Stack Frame & Base Pointer Wired OR.

Buffalo Routines Jump Table (2)

ORG ROMBS+$1FA0.UPCASE JMP UPCASE convert to upper case.WCHEK JMP WCHEK check for white space.DCHEK JMP DCHEK check for delimeter.INIT JMP INIT initialize i/o device.INPUT JMP INPUT low level input routine.OUTPUT JMP OUTPUT low level output routine.OUTLHL JMP OUTLHLF display top 4 bits as hex digit.OUTRHL JMP OUTRHLF display bottom 4 bits as hex digit.OUTA JMP OUTA output ascii character in A.OUT1BY JMP OUT1BYT display the hex value of byte at X.OUT1BS JMP OUT1BSP out1byt followed by space.OUT2BS JMP OUT2BSP display 2 hex bytes at x and a space.OUTCRL JMP OUTCRLF carriage return, line feed to terminal.OUTSTR JMP OUTSTRG display string at X (term with $04).OUTST0 JMP OUTSTRG0 outstrg with no initial carr ret.INCHAR JMP INCHAR wait for and input a char from term.VECINT JMP VECINIT initialize RAM vector table