Lecture 22 IO & data transfer Methodolodies –Polled, Interrupt Driven, DMA Interrupts –AVR Interrupts (RISC) –68HC11 Interrupts (CISC) IBM PC Boot Sequence.

Slides:



Advertisements
Similar presentations
Computer Architecture
Advertisements

I/O Organization popo.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
Computer Architecture
Programmable Interval Timer
9/20/6Lecture 3 - Instruction Set - Al1 The Hardware Interface.
Microprocessor and Microcontroller
Direct Memory Access Introduction to 8237
I/O Unit.
Processor System Architecture
CS-334: Computer Architecture
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
FIU Chapter 7: Input/Output Jerome Crooks Panyawat Chiamprasert
Mark Neil - Microprocessor Course 1 Timers and Interrupts.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 13 Direct Memory Access (DMA)
6-1 I/O Methods I/O – Transfer of data between memory of the system and the I/O device Most devices operate asynchronously from the CPU Most methods involve.
Introduction An interrupt is an event which informs the CPU that its service (action) is needed. Sources of interrupts: internal fault (e.g.. divide by.
Chapter 7 Interupts DMA Channels Context Switching.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
INPUT/OUTPUT ORGANIZATION INTERRUPTS CS147 Summer 2001 Professor: Sin-Min Lee Presented by: Jing Chen.
Unit-5 CO-MPI autonomous
1 Computer System Overview Chapter 1 Review of basic hardware concepts.
Input/Output. Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower.
The computer system’s I/O architecture is its interface to the outside world. This architecture provides a systematic means of controlling interaction.
Chapter 7 Input/Output Luisa Botero Santiago Del Portillo Ivan Vega.
Interrupts. 2 Definition: An electrical signal sent to the CPU (at any time) to alert it to the occurrence of some event that needs its attention Purpose:
Embedded Systems 7763B Mt Druitt College of TAFE
Introduction to Embedded Systems
Khaled A. Al-Utaibi  Intel Peripheral Controller Chips  Basic Description of the 8255  Pin Configuration of the 8255  Block Diagram.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Chapter 10: Input / Output Devices Dr Mohamed Menacer Taibah University
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
MICROPROCESSOR INPUT/OUTPUT
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
Direct Memory Access (DMA) Microprocessors I -1. Topics to be discussed  Basic DMA Concept Basic DMA Concept  DMA pins and timing DMA pins and timing.
Atmel Atmega128 Overview ALU Particulars RISC Architecture 133, Mostly single cycle instructions 2 Address instructions (opcode, Rs, Rd, offset) 32x8 Register.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
Z80 Overview internal architecture and major elements of the Z80 CPU.
The computer system’s I/O architecture is its interface to the outside world. This architecture provides a systematic means of controlling interaction.
Timers and Interrupts Mark Neil - Microprocessor Course.
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
Architectural Considerations A Review of Some Architectural Concepts.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Mark Neil - Microprocessor Course 1 Timers and Interrupts.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
8085 INTERNAL ARCHITECTURE.  Upon completing this topic, you should be able to: State all the register available in the 8085 microprocessor and explain.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Input / Output Chapter 9.
Embedded Systems Programming
Microprocessor Systems Design I
Direct Memory address and 8237 dma controller LECTURE 6
8259 Chip The Intel 8259 is a family of Programmable Interrupt Controllers (PIC) designed and developed for use with the Intel 8085 and Intel 8086 microprocessors.
ATmega103 Timer0 and Interrupts
An Introduction to Microprocessor Architecture using intel 8085 as a classic processor
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Compiled by Dr. N.Shanmugasundaram, HOD, ECE Dept, SECE.
COMP3221: Microprocessors and Embedded Systems
Computer Operation 6/22/2019.
Presentation transcript:

Lecture 22 IO & data transfer Methodolodies –Polled, Interrupt Driven, DMA Interrupts –AVR Interrupts (RISC) –68HC11 Interrupts (CISC) IBM PC Boot Sequence Data Transfer To/From Devices –DMA (Direct Memory Access) –Polled IO –Interrupt Driven IO –DMA, Polled, Interrupt Driven Summary Keyboard Input

Polled, Interrupt Driven, DMA Polled IO: –A Device is polled thousands of times before data becomes available by the main program –Typically Wastes 99% or more CPU resource –Simple but inefficient –Sometimes needed for fast response and/or complex peripherals. For example a dedicated single-purpose controller. –Sometimes used when insufficient interrupts are available

Polled, Interrupt Driven, DMA Interrupt Driven IO –Device interrupts normal program execution only when device needs CPU attention. –Interrupt Service Routine uses some CPU resource, with some overhead. –Useful for reasonably frequent events (hundreds to thousands of interrupt events per second). –An excessively high interrupt rate can slow down (or prevent) normal program execution (eg thousands of interrupts per second)

Polled, Interrupt Driven, DMA DMA : Direct Memory Addressing –Hardware performs the data transfer –No CPU interaction requirement –Fastest data transfer rate. An order of magnitude faster than the fastest CPU instruction sequence –Does not always stop the CPU from executing its instructions - transparent DMA –CPU can optionally be interrupted upon DMA operation completion or not.

Interrupts The AVR is a Reduced Instruction Set Computer. The 68HC11 - Complex Instruction Set Computer - it performs many tasks before entering an interrupt - making it simpler & easier for programmers to code interrupt service routines. The programmer need not specifically save any registers as that is performed by the CPU. To limit the time required to service an interrupt, an AVR only performs the minimal functions necessary to enter the Interrupt Service Routine. Tradeoff - The programmer must be careful not to upset the main line code execution.

AVR Stack The Stack Pointer – SP – is read/write accessible in the I/O space. (SPH / SPL) The data SRAM can easily be accessed through the five different addressing modes supported in the AVR architecture.

AVR Stack During interrupts and subroutine calls, the return address Program Counter (PC) is stored on the Stack. The Stack is effectively allocated in the general data SRAM, and consequently the stack size is only limited by the total SRAM size and the usage of the SRAM. All user programs must initialise the SP in the reset routine (before subroutines or interrupts are executed).

AVR Interrupts During interrupts and subroutine calls, the return address Program Counter (PC) is stored on the Stack. The CPU clears the I flag - preventing furthur interrupts - until the current one is serviced. The status register - SREG - is not automatically stored when entering an interrupt routine and restored when returning from an interrupt. This must be handled by Interrupt Service Routine software.

AVR Status Register The AVR status Register – SREG – is defined as: Bit # I T H S V N Z C SREG Initial Value

AVR Interrupt Vectors The most typical and general program setup for the Reset and Interrupt Vector Addresses in ATmega128 is: Address LabelsCode Comments $0000 jmp RESET ; Reset Handler $0002 jmp EXT_INT0 ; IRQ0 Handler $0004jmp EXT_INT1 ; IRQ1 Handler $0006jmp EXT_INT2 ; IRQ2 Handler $0008 jmp EXT_INT3 ; IRQ3 Handler $000A jmp EXT_INT4 ; IRQ4 Handler $000C jmp EXT_INT5 ; IRQ5 Handler $000E jmp EXT_INT6 ; IRQ6 Handler $0010 jmp EXT_INT7 ; IRQ7 Handler $0012 jmp TIM2_COMP ; Timer2 Compare Handler $0014 jmp TIM2_OVF ; Timer2 Overflow Handler $0016 jmp TIM1_CAPT ; Timer1 Capture Handler $0018 jmp TIM1_COMPA; Timer1 CompareA Handler

AVR Interrupt Vectors continued $001A jmp TIM1_COMPB; Timer1 CompareB Handler $001C jmp TIM1_OVF ; Timer1 Overflow Handler $001E jmp TIM0_COMP ; Timer0 Compare Handler $0020 jmp TIM0_OVF; Timer0 Overflow Handler $0022 jmp SPI_STC ; SPI Transfer Complete Handler $0024 jmp USART0_RXC; USART0 RX Complete Handler $0026 jmp USART0_DRE; USART0,UDR Empty Handler $0028 jmp USART0_TXC; USART0 TX Complete Handler $002A jmp ADC ; ADC Conversion Complete Handler $002C jmp EE_RDY ; EEPROM Ready Handler $002E jmp ANA_COMP ; Analog Comparator Handler $0030 jmp TIM1_COMPC; Timer1 CompareC Handler $0032 jmp TIM3_CAPT ; Timer3 Capture Handler $0034 jmp TIM3_COMPA; Timer3 CompareA Handler $0036 jmp TIM3_COMPB; Timer3 CompareB Handler $0038 jmp TIM3_COMPC; Timer3 CompareC Handler $003A jmp TIM3_OVF ; Timer3 Overflow Handler $003C jmp USART1_RXC; USART1 RX Complete Handler

AVR Interrupt Vectors continued $003Ejmp USART1_DRE; USART1,UDR Empty Handler $0040 jmp USART1_TXC; USART1 TX Complete Handler $0042 jmp TWI ; Two-wire Serial Interface $0044 jmp SPM_RDY ; SPM Ready Handler ; ; RESET HANDLER: RESET:ldir16, high(RAMEND); Main program start out SPH,r16 ; Set stack pointer to top of RAM ldi r16, low(RAMEND) out SPL,r16 sei ; Enable interrupts xxx; other instructions...

AVR ADC Interrupt The Analog to Digital Converter can be configured to interrupt the CPU upon completing a conversion. By setting the interrupt enable bit, ADIE, this will allow CPU interruption when the ADIF flag is set. Upon ADC conversion completion the interrupt flag, ADIF, will be set. Providing interrupts are enabled - the “I” bit is set in SREGS, the AVR CPU will complete execution of the current instruction, then mask interrupts (clear the I bit) and jump to the ADC Conversion Complete interrupt Vector.

AVR ADC Interrupt

Polled ADC Access // Read the AD conversion result unsigned int read_adc(unsigned char adc_input) { ADMUX=adc_input|ADC_VREF_TYPE; // Start the AD conversion ADCSRA|=0x40; // Wait for the AD conversion to complete while ((ADCSRA & 0x10)==0); ADCSRA|=0x10; return ADCW; }

ADC Interrupt Service Routine // Code Vision ADC interrupt service routine - ISR interrupt [ADC_INT] void adc_isr(void) { register static unsigned char input_index=0; // Read the AD conversion result adc_data[input_index]=ADCW; // Select next ADC input if (++input_index > (LAST_ADC_INPUT- FIRST_ADC_INPUT)) input_index=0; ADMUX=(FIRST_ADC_INPUT | (ADC_VREF_TYPE & 0xff))+input_index; // Delay needed for the stabilization of the ADC input voltage delay_us(10); // Start the AD conversion ADCSRA|=0x40; }

USART0 TX ISR #define TX_BUFFER_SIZE0 80 // USART0 Transmitter buffer char tx_buffer0[TX_BUFFER_SIZE0]; // USART0 Transmitter interrupt service routine unsigned char tx_wr_index0, tx_rd_index0, tx_counter0; interrupt [USART0_TXC] void usart0_tx_isr(void) { if (tx_counter0) { --tx_counter0; UDR0=tx_buffer0[tx_rd_index0]; if (++tx_rd_index0 == TX_BUFFER_SIZE0) tx_rd_index0=0; }; }

Memory Interfacing We want U16, our 128KB ROM, to be enabled from E0000..FFFFF, ( B B). So we need to decode the top three bits A19..A17, and when A19..A17 = 111 the chip select must be active. GCS1# = NOT (A19 & A18 & A17) As chip Select is active low, so we can simply use a 3 input NAND gate as shown:

DRIVERS A hardware driver normally consists of 2 or 3 parts: –1. An Application Program Interface A set of system calls to access the peripheral. For example to read data from the UART memory buffer. –2. An interrupt Service Routine (ISR) Manipulates the device to support the peripheral For example reading data from a UART into a memory buffer.

DRIVERS Sometimes an interrupt service routine may need to perform a long task in the handler. In this situation the ISR could be split into two. The time critical part (Top Half) is executed immediately, and the less time critical part (Bottom Half) is scheduled to occur at a more appropriate time. Example: When a network card receives data, it is moved into a buffer by the “Top Half”. Then the Bottom Half scheduled. When the Bottom Half executes it interprets the packet and sends the data to the appropriate socket, interface & task.

DMA refresh of DRAM As previously mentioned the DMA controller is used to refresh Dynamic RAM. Remember Dynamic RAM is constructed using Capacitive storage elements. The presence or absence of charge on the capacitor indicates a stored 1 or 0. Due to internal resistance, the charge leaks away. In order to avoid memory loss, the data is read & re-written many times per second. (Typically every few ms)

DMA refresh of DRAM Remember Dynamic RAM also is addressed using Rows and Columns. In the event that one byte from one column is read, the whole row is read and refreshed. So to refresh all 256 rows x 256 columns (64KB) only takes requires 256 sequential address reads.

DMA refresh of DRAM On an IBM PC the DMA controller has an Auto-Initialise Block transfer mode. The Current Address and Current Word Count register are automatically loaded from previously saved Base Word count and Base Address registers. The (8253) timer 1 output is latched onto the DMA controller’s DMA REQuest line (DREQ0) (74LS74). (Reset by DMACK0)

DMA refresh of DRAM As soon as the DMA controller receives the DMA REQuest signal (DREQ), the DMA controller requests control of the system BUS using the 80x86 HOLD line. Upon HoLD Acknowledgment (HLDA line) from the CPU, the DMA controller performs sequential reads from memory. This has the effect of refreshing all Dynamic RAM memory.

8237A DMA Block Diagram

8237 DMA The DMA controller may be configured to transfer data: –From Memory to Memory –From Memory to IO (MEMR# & IOW#) –From IO to Memory (IOR# & MEMW#) When the DMA controller is used to transfer from Memory IO device the transfer occurs directly without using any intervening storage.

8237 DMA When the DMA controller is used to transfer from Memory IO device. The device can perform a transfer every 2 cpu clock cycles The REP MOVSB command can transfer a byte in a block in 17 clock cycles. So the DMA controller’s data transfer rate is over 8.5 times faster than an 8088 can be.

DMA vs Interrupt-Driven I/O Also, an interrupt service routine would require at least: (INT) 52 + (IRET) *PUSH (30) + 3*POP (24) = minimum overhead of 138 cycles = 28us. The DMA controller has minimum latency as it will gain control as soon as the CPU asserts HLDA (300ns-1.6us).

DMA vs Interrupt-Driven I/O During CPU HOLD, the CPU’s Execution Unit (EU) will continue executing instructions from its pipeline, until it requires access to the Memory or IO busses. So it is possible that the DMA cycles do not interfere with CPU execution at all.

80186EC DRAM Refresh In the 80186/8EC there is a special purpose Refresh Control Unit for DRAM memory refreshing. This device refreshes all rows by cycling through all DRAM rows in “dummy read” cycles. In this CPU refresh activity has higher priority than: DMA, Most CPU cycles & HOLD/HLDA bus protocol.

80186EC DMA In the 80186/8EC there is an enhanced DMA controller (20 bit counters) It allows data transfer between memory & peripherals without CPU intervention The DMA controller can access the entire memory in either byte or word increments.

80186EC DMA The four DMA Channels can each accept requests from: –An external pin –The Serial Communications Unit –The Timer/Counter Unit –The CPU by direct programming CPU can continue execution of instructions until the pre-fetch queue is empty or an external Memory/IO access is required.

Polled IO Polled I/O is the repeated reading of external control units waiting for data to become available. When data becomes available, it is transferred under program control. Polled IO may be implemented simply It is normal to poll the device thousands of times before data becomes available.

Keyboard Input The IBM PC Keyboard includes an Intel 8048 micro-controller. The keyboard is arranged as a capacitive matrix in columns & rows. When a key is pressed its capacitance increases. The 8048 as sequences through rows of keys and any capacitance change is sensed on the columns.

Keyboard Input When a key press is sensed the Key pressed scan code is sent to the CPU. When a key is released the Key Released scan code is sent to the CPU. If a key is held pressed, a key pressed scan code is repeated. The CPU is interrupted (IRQ1) upon each keypress/release

Keyboard Input

The Keyboard ISR is invoked directly by the PIC IRQ 1 which provides an interrupt Type Vector = 9. So INT 9 is executed. The Keyboard ISR saves characters into a 16 byte buffer. To read the buffered keyboard characters we use INT 16H - BIOS Keyboard IO.

Polled Keyboard Input poll_ready: ;wait until key press/release IN al, 64h ; read status TEST al, l ; New ScanCode ready? JZpoll_ready; no - poll again IN al, 60h ; get the key code MOV bl, al ; free al for in/out INal, 61h ; send ACK OR al, B; set MSB OUT 61h, al ; write back to port AND al, B; clear MSB OUT 61h, al ; write back to port

Interrupt Driven IO Interrupt Driven I/O is where an interrupt input is connected to a device output that signals when data is received. –For example a serial communications port interrupts on arrival of one or more characters Upon interrupt, the current task is interrupted, and data is then transferred under program control by an Interrupt Service Routine (ISR).

8086 Interrupts Different types of Interrupts –Hardware Interrupts - the 8259 PIC presents the one-byte interrupt number on the local bus –Software Interrupts eg BIOS & DOS interface. –Predefined interrupts - Interrupt numbers are assigned and use automatic vectoring logic. Eg INT 0 = DIVision by 0, INT 1 = Single step, INT 2 = NMI, INT 3 - One Byte, INT4 - Overflow

8086 Interrupts Hardware Interrupt Acknowledge Sequence (min mode).

DMA, Polled, Interrupt Driven Summary Polled IO: –A Device is polled thousands of times before data becomes available by the main program –Typically Wastes 99% or more CPU resource –Simple but inefficient –Sometimes needed for fast response and/or complex peripherals. For example a dedicated single-purpose controller. –Sometimes used when insufficient interrupts are available

DMA, Polled, Interrupt Driven Summary Interrupt Driven IO –Device interrupts normal program execution only when device needs CPU attention. –Interrupt Service Routine uses some CPU resource, with some overhead. –Useful for reasonably frequent events (say hundreds of interrupt events per second). –An excessively high interrupt rate can slow down (or prevent) normal program execution (eg thousands of interrupts per second)

DMA, Polled, Interrupt Driven Summary DMA summary: –No CPU interaction requirement –Fastest data transfer rate. An order of magnitude faster than the fastest CPU instruction sequence –Does not always stop the CPU from executing its instructions –CPU can optionally be interrupted upon DMA operation completion or not.