Introduction to Embedded Systems Buffering and DMA (Direct Memory Access) Lecture 11.

Slides:



Advertisements
Similar presentations
Computer Architecture
Advertisements

1 Homework Reading (linked from my web page) –S and S Extracts –National Semiconductor UART Data Sheet Machine Projects –mp2 due at start of class 12 Labs.
Exceptions. Exception Types Exception Handling Vectoring Interrupts Interrupt Handlers Interrupt Priorities Interrupt applications 6-2.
Input and Output CS 215 Lecture #20.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
Avishai Wool lecture Introduction to Systems Programming Lecture 8 Input-Output.
68HC11 Polling and Interrupts
Hierarchy of I/O Control Devices
ECE 372 – Microcontroller Design Parallel IO Ports - Interrupts
1 Homework Reading –Review previous material on “interrupts” Machine Projects –MP4 Due today –Starting on MP5 (Due at start of Class 28) Labs –Continue.
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.
A look at interrupts What are interrupts and why are they needed in an embedded system? Equally as important – how are these ideas handled on the Blackfin.
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.
Chapter 7 Interupts DMA Channels Context Switching.
A look at interrupts What are interrupts and why are they needed.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
COMP3221 lec28-exception-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 28: Exceptions & Interrupts - II
Introduction to Embedded Systems Interrupts + Serial Communications Lecture 10.
Computer Organization and Assembly language
Input/Output and Communication
Practical Session No. 10 Input &Output (I/O). I/O Devices Input/output (I/O) devices provide the means to interact with the “outside world”. An I/O device.
Unit-5 CO-MPI autonomous
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
INPUT/OUTPUT ARCHITECTURE By Truc Truong. Input Devices Keyboard Keyboard Mouse Mouse Scanner Scanner CD-Rom CD-Rom Game Controller Game Controller.
1 CSC 2405: Computer Systems II Spring 2012 Dr. Tom Way.
MIPS I/O and Interrupt. SPIM I/O and MIPS Interrupts The materials of this lecture can be found in A7-A8 (3 rd Edition) and B7-B8 (4 th Edition).
Input/Output. Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower.
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:
COMP201 Computer Systems Exceptions and Interrupts.
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.
A Few Words From Dilbert
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
Chapter 8 I/O. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-2 I/O: Connecting to Outside World So far,
1 CS/COE0447 Computer Organization & Assembly Language Chapter 5 part 4 Exceptions.
More on UART Interrupts; System Calls Reference on Interrupt Identification Register(IIR) slide 17 of
Interrupts, Buses Chapter 6.2.5, Introduction to Interrupts Interrupts are a mechanism by which other modules (e.g. I/O) may interrupt normal.
COMPUTER ORGANIZATIONS CSNB123. COMPUTER ORGANIZATIONS CSNB123 Expected Course Outcome #Course OutcomeCoverage 1Explain the concepts that underlie modern.
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.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
1 Interrupts, Resets Today: First Hour: Interrupts –Section 5.2 of Huang’s Textbook –In-class Activity #1 Second Hour: More Interrupts Section 5.2 of Huang’s.
12/8/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam King,
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Chapter 13 – I/O Systems (Pgs ). Devices  Two conflicting properties A. Growing uniformity in interfaces (both h/w and s/w): e.g., USB, TWAIN.
Microprocessor and Interfacing Example: Writing a Game Need to Check Keyboard Input.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
7. IRQ and PIC ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  Interrupts ◦ Section
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
بسم الله الرحمن الرحيم MEMORY AND I/O.
9/20/6Lecture 3 - Instruction Set - Al1 Exception Handling.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Transmitter Interrupts Review of Receiver Interrupts How to Handle Transmitter Interrupts? Critical Regions Text: Tanenbaum
Chapter 7 Input/Output and Storage Systems. 2 Chapter 7 Objectives Understand how I/O systems work, including I/O methods and architectures. Become familiar.
Homework Reading Machine Projects
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
CS501 Advanced Computer Architecture
Microprocessor Systems Design I
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
Homework Reading Machine Projects Labs
E3165 DIGITAL ELECTRONIC SYSTEM
Transmitter Interrupts
Lecture 12 Input/Output (programmer view)
Presentation transcript:

Introduction to Embedded Systems Buffering and DMA (Direct Memory Access) Lecture 11

Introduction to Embedded Systems Summary of Previous Lecture Interrupts –Interrupt handlers –Nested interrupts –Interrupt timing and metrics –Interrupts on the X-Board –Installing and writing interrupt handlers Serial Communications –Data communications and modulation –Asynchronous protocols –Serial port and bit transmission –Serial I/O from device drivers

Introduction to Embedded Systems Quote of the Day I am grateful for all my problems. After each one was overcome, I became stronger and more able to meet those that were still to come. I grew in all my difficulties. –J. C. Penney

Introduction to Embedded Systems Lessons Learned From Lab 1 Some Common Mistakes from Part 1 1.Very little error checking 2.What happens when MOVS pc, lr instruction is executed in the SWIHandlerEntry.s assembly file ? 3.When does the stack pointer get initialized ?

Introduction to Embedded Systems Common Misunderstanding Loop unrolling not very clear. Assumed that only constant sized loops can be FULLY unrolled for loop unrolling and variable sized loops cannot easily be unrolled. e.g. A bad example of loop-unrolling for (i = 1; i < n; i++) foo; to for (i = 1; i < n - 1; i++) foo; foo;

Introduction to Embedded Systems Outline of This Lecture Concurrency between I/O and processing activities: An Introduction Buffering –dealing with nested interrupts –critical sections and masking interrupts

Introduction to Embedded Systems Processor has parallel buses for data ­­ need to convert serial data to parallel (and vice versa) Standard way is with UART UART ­ Universal asynchronous receiver and transmitter –USART ­ Universal synchronous and asynchronous receiver and transmitter Interfacing Serial Data to Microprocessor Chip Reg Select R/W Control Tx Data Reg Status Reg Control Reg Rx Data Reg Tx Shift Reg Rx Shift Reg Tx Clock Rx Clock IRQ CTS RTS Rx Data Tx Data Data Bus Buffers D 0 -D 7

Introduction to Embedded Systems Serial I/O High­level I/O call –printf(“the number is %d\n”, someNumber); Low­level details –printf() is a library call which formats the output (e.g., converts %d formats) and then makes system call to output the formatted string Formatted string is nothing more than an array of characters Low­level routines then output the string one character at a time using UART Chip Reg Select R/W Control Tx Data Reg Status Reg Control Reg Rx Data Reg Tx Shift Reg Rx Shift Reg Tx Clock Rx Clock IRQ CTS RTS Rx Data Tx Data Data Bus D 0 -D 7

Introduction to Embedded Systems Conceptual View of Device Driver while (*string != `\0') printChar(*string++); Chip Reg Select R/W Control Tx Data Reg Status Reg Control Reg Rx Data Reg Tx Shift Reg Rx Shift Reg Tx Clock Rx Clock IRQ CTS RTS Rx Data Tx Data Data Bus D 0 -D 7 string

Introduction to Embedded Systems Conceptual View of Device Driver (con't) while (*string != '\0') printChar(*string++); string Chip Reg Select R/W Control Tx Data Reg Status Reg Control Reg Rx Data Reg Tx Shift Reg Rx Shift Reg Tx Clock Rx Clock IRQ CTS RTS Rx Data Tx Data Data Bus D 0 -D 7 One problem the while loop can execute a lot faster than the UART can transmit characters

Introduction to Embedded Systems Check UART for space while (*string != '\0'){ if (UART is empty()){ printChar(*string++); } string Chip Reg Select R/W Control Tx Data Reg Status Reg Control Reg Rx Data Reg Tx Shift Reg Rx Shift Reg Tx Clock Rx Clock IRQ CTS RTS Rx Data Tx Data Data Bus D 0 -D 7 1 2

Introduction to Embedded Systems Device Driver (pseudo code) output_string(char *string) { while (*string != `\0') writeChar(*string++); } /* end output_string() */ UARTBASE EQU 0x10010BE0 LSR EQU 0x14 LSR_TransmitEQU 0x20 writeChar LDR R1,= UARTBASE LDRB R3, [R1,#LSR] B1 TST R3, #LSR_Transmit BEQ B1 STRBR0, [R1] AND R0, R0, #0xff TEQ R0, #'\n' MOVENEPC,LR MOV R0, #'\r' B B01

Introduction to Embedded Systems Concurrency between I/O and Processing Keyboard command processing The “B” key is pressed by the user The “keyboard” interrupts the processor Jump to keyboard ISR keyboard_ISR() { ch <­ Read keyboard input register switch (ch) { case ‘b’ : startGame(); break; case ‘x’ : doSomeProcessing(); break;... } } return from ISR How long does this processing take?

Introduction to Embedded Systems How fast is the keyboard_ISR ()? The “B” key is pressed by the user The “keyboard” interrupts the processor Jump to keyboard ISR keyboard_ISR(){ ch <­ Read keyboard input register switch (ch) { case ‘b’ : startGame(); break; case ‘x’ : doSomeProcessing(); break;... } Will Events Be Missed? What happens if another key is pressed ­ or if a timer interrupt occurs? return from ISR

Introduction to Embedded Systems A More Elegant Solution Add a buffer (in software or hardware) for input characters. –This decouples the time for processing from the time between keystrokes, and provides a computable upper bound on the time required to service a keyboard interrupt. A key is pressed by the user The “keyboard” interrupts the processor Jump to keyboard ISR keyboard_ISR() { *input_buffer++ = ch;... } Stores the input and then quickly returns to the “main program” (process) return from ISR

Introduction to Embedded Systems What Can Go Wrong? 1. Buffer could overflow (bigger buffer helps, but there is a limit) 2. Could another interrupt occur while adding the current keyboard character to the input_buffer ? Keyboard is pressed in the middle of incrementing *input_buffer++ A key is pressed by the user The “keyboard” interrupts the processor Jump to keyboard ISR keyboard_ISR() { *input_buffer++ = ch;... } return from ISR The “keyboard” interrupts the processor Jump to keyboard ISR keyboard_ISR() { *input_buffer++ = ch;... } return from ISR

Introduction to Embedded Systems Masking Interrupts If interrupts are masked (IRQ and FIQ disabled), nothing will be processed until the ISR completes and returns. –Remember: entering IRQ mode masks IRQs and entering FIQ mode masks IRQs and FIQs UART interrupts the processor A key is pressed by the user The “keyboard” interrupts the processor Jump to keyboard ISR keyboard_ISR() { MaskInterrupts(); ch <­ Read keyboard input register *input_buffer++ = ch; UnmaskInterrupts(); } return from ISR The “keyboard” interrupts the processor Jump to keyboard ISR keyboard_ISR() { MaskInterrupts(); ch <­ Read kbd in register *input_buffer++ = ch; UnmaskInterrupts(); } return from ISR Keyboard is pressed in the middle of incrementing *input_buffer++

Introduction to Embedded Systems Buffer Processing Must be careful when modifying the buffer with interrupts turned on. while (!quit){ if (*input_buffer){ processCommand(*input_buffer); removeCommand(*input_buffer); } keyboard_ISR(){ MaskInterrupts(); ch <­ Read ACIA input register *input_buffer++ = ch; UnmaskInterrupts(); } return from ISR What happens if another command is entered as you remove one from the inputBuffer?

Introduction to Embedded Systems Buffer Processing How about the print buffer? printStr(*string) char *string; { while (*string) { outputBuffer[tail++] = *string++; } timer_ISR(){ clockTicks++; printStr(convert(clockTicks)); } printStr(“this is a line”); T H I S I S 2 : 3 0 T H I S I S Jump to timer_ISR tail points here ­ and a timer interrupt occurs

Introduction to Embedded Systems Critical Sections of Code Pieces of code that must appear as an atomic action T H I S I S printStr(*string) char *string; { MaskInterrupts(); while (*string){ outputBuffer[tail++] = *string++; } UnmaskInterrupts(); } timer_ISR(){ clockTicks++; printStr(convert(clockTicks)); } printStr(“this is a line”); T H I S I S A L I N E Jump to timer_ISR happens after printStr() completes tail points here ­ and a timer interrupt occurs Atomic action ­ action that “appears”' to take place in a single indivisible operation

Introduction to Embedded Systems Increasing Concurrency Between I/O and Programs So far today, we have seen how to use buffers to de- couple the speed of input/output devices from that of programs executing on the CPU –and how to deal with the corresponding concurrency problems with masking of interrupts Now, how can we push this farther?? –In particular, can we get the I/O to happen without needing the CPU for every single operation?!

Introduction to Embedded Systems Summary of Lecture Concurrency between I/O and processing activities Buffering –dealing with nested interrupts –critical sections and masking interrupts