Introduction to Embedded Systems. Lab Logistics

Similar documents
ECE/CS 5780/6780: Embedded System Design

1 Execution of main program is suspended. 2 All registers are pushed onto the stack. 3 The ISR, or background thread, is executed.

CS/ECE 6780/5780. Al Davis

Page 1. Lab 5 Logistics. Implicit Threads. Explicit Thread Semantics. Problem not enough interrupt pins CS/ECE 6780/5780. Al Davis

Interrupts on the 6812

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

EEL 4744C: Microprocessor Applications. Lecture 7. Part 1. Interrupt. Dr. Tao Li 1

Reading Assignment. Interrupt. Interrupt. Interrupt. EEL 4744C: Microprocessor Applications. Lecture 7. Part 1

Real-Time Programming

Page 1. Logistics. Introduction to Embedded Systems. Last Time. ES Software Design. Labs start Wed CS/ECE 6780/5780. Al Davis

EEL 4744C: Microprocessor Applications. Lecture 7. Part 2. M68HC12 Interrupt. Dr. Tao Li 1

538 Lecture Notes Week 5

538 Lecture Notes Week 5

ECE332, Week 8. Topics. October 15, Exceptions. Hardware Interrupts Software exceptions

Microcontrollers. Program organization Interrupt driven I/O. EECE 218 Microcontrollers 1

ECE 372 Microcontroller Design Parallel IO Ports - Interrupts. ECE 372 Microcontroller Design Parallel IO Ports - Interrupts

Lecture #7: Implementing Mutual Exclusion

Lecture notes Lectures 1 through 5 (up through lecture 5 slide 63) Book Chapters 1-4

ME 4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 6

Last Time. Think carefully about whether you use a heap Look carefully for stack overflow Especially when you have multiple threads

KERNEL THREAD IMPLEMENTATION DETAILS. CS124 Operating Systems Winter , Lecture 9

Introduction to Concurrency (Processes, Threads, Interrupts, etc.)

Hardware OS & OS- Application interface

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 8: Semaphores, Monitors, & Condition Variables

G52CON: Concepts of Concurrency

Concurrency. Glossary

Process Synchronization

Tasks. Task Implementation and management

Page 1. Logistics. Introduction to Embedded Systems. My Records Indicate. Intel 4004 first single chip computer? Acronyms CS/ECE 6780/5780.

18-349: Introduction to Embedded Real-Time Systems

Introduction to Embedded Systems. Some Nagging

Chapter 5 Concurrency: Mutual Exclusion and Synchronization

Chapter 5 Concurrency: Mutual Exclusion. and. Synchronization. Operating Systems: Internals. and. Design Principles

COMP I/O, interrupts, exceptions April 3, 2016

ECE 341. Lecture # 19

EECS150 Lab Lecture 5 Introduction to the Project

Chapter 6: Process Synchronization

Lecture 10 Exceptions and Interrupts. How are exceptions generated?

Chapter 8 I/O. Computing Layers. I/O: Connecting to Outside World. I/O: Connecting to the Outside World

EECS 482 Introduction to Operating Systems

DSP/BIOS Kernel Scalable, Real-Time Kernel TM. for TMS320 DSPs. Product Bulletin

CSC227: Operating Systems Fall Chapter 1 INTERRUPTS. Dr. Soha S. Zaghloul

Multiprocessors II: CC-NUMA DSM. CC-NUMA for Large Systems

Link Service Routines

CS11 Java. Fall Lecture 7

Interrupts (I) Lecturer: Sri Notes by Annie Guo. Week8 1

Process Synchronization and Communication

Exam TI2720-C/TI2725-C Embedded Software

The Kernel Abstraction

Interrupt Lab using PicoBlaze

BASICS OF THE RENESAS SYNERGY TM

Lecture 11: Interrupt and Exception. James C. Hoe Department of ECE Carnegie Mellon University

CSE 451 Midterm 1. Name:

Concurrency: a crash course

IT 540 Operating Systems ECE519 Advanced Operating Systems

Virtual Machine Design

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

ECE251: Thursday September 27

Lecture #13 Interrupts Embedded System Engineering Philip Koopman Monday, 29-Feb-2016

1. Motivation (Race Condition)

BASICS OF THE RENESAS SYNERGY PLATFORM

Microprocessors & Interfacing

Real-time Support in Operating Systems

Concept of a process

Lecture 8: September 30

Chapter 5: Synchronization 1

PC Interrupt Structure and 8259 DMA Controllers

Main Points of the Computer Organization and System Software Module

Boot Camp. Dave Eckhardt Bruce Maggs

Process Coordination and Shared Data

Process Coordination

Review: Easy Piece 1

Real Time Embedded Systems. Lecture 10 January 31, 2012 Interrupts

CSE 153 Design of Operating Systems

QUIZ How do we implement run-time constants and. compile-time constants inside classes?

Page 1. Goals for Today" Atomic Read-Modify-Write instructions" Examples of Read-Modify-Write "

Real-Time and Concurrent Programming Lecture 4 (F4): Monitors: synchronized, wait and notify

CS354 gdb Tutorial Written by Chris Feilbach

CS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers

Last Class: CPU Scheduling! Adjusting Priorities in MLFQ!

Introduction to Asynchronous Programming Fall 2014

In examining performance Interested in several things Exact times if computable Bounded times if exact not computable Can be measured

Chapter Operation Pinout Operation 35

Overview of Input/Output Mechanisms

AC OB S. Multi-threaded FW framework (OS) for embedded ARM systems Torsten Jaekel, June 2014

2 Threads vs. Processes

INPUT/OUTPUT ORGANIZATION

CSE Traditional Operating Systems deal with typical system software designed to be:

Information Security II Prof. Kamakoti Department of Computer Science and Engineering Indian Institute of Technology, Madras

Deviations are things that modify a thread s normal flow of control. Unix has long had signals, and these must be dealt with in multithreaded

Lecture 9: Midterm Review

Introduction to Operating Systems

CS 326: Operating Systems. Process Execution. Lecture 5

SSC - Concurrency and Multi-threading Advanced topics about liveness

Fredrick M. Cady. Assembly and С Programming forthefreescalehcs12 Microcontroller. шт.

Synchronization Classic Problems

Preemptive Scheduling

ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

Transcription:

Introduction to Embedded Systems CS/ECE 6780/5780 Al Davis Today s topics: lab logistics interrupt synchronization reentrant code 1 CS 5780 Lab Logistics Lab2 Status Wed: 3/11 teams have completed their labs» likely due to late handout of Lab 2 we were 3 days late in getting it to you only fair to give you 3 days extension make appointment w/ William to demonstrate lab reports still due at next weeks lab session BUT other labs will stay on schedule Pre-labs must be done before your lab session» most of the Wed. non-finishers didn t do this» bottom line you won t get pre-lab and actual lab done in time if you don t do the pre-lab prior to your lab session Don t just blow off any lab» labs are additive e.g. previous lab code will be useful for subsequent labs Schedule through first midterm is on the web useful to do the reading before the lecture 2 CS 5780 Page 1

Interrupts External wake-up stimulus alternative to the software polling loop Efficient response to rare events importance will vary» low-power warning emergency» key got pushed handle soon but not now energy efficient» processor doesn t consume energy in a polling loop» or it can be doing something else that is useful Highly useful for data acquisition and control Predictable response time? depends on how you configure the system predictability is a MUST in real-time systems Interrupts add concurrency to your ES software this can make you life very difficult 3 CS 5780 What are Interrupts Automatic hardware supported transfer of control external hardware runs asynchronously & concurrently» w.r.t. controller SW interrupts transfer control out of whatever is currently running» to an interrupt service routine (ISR) looks like a surprise call to the ISR that you write ISR is a background thread» ISR return is done via the rti instruction» interrupts communicate with main using shared memory concurrency usually requires some form of mutual exclusion control such as semaphores Software interrupts these are synchronous» SWI instruction (one use would be a breakpoint)» automatically happens on 6812 via an unimplemented opcode e.g. ISR may implement the opcode or send command to off chip implementation 4 CS 5780 Page 2

ARM vs. Disable ARM each off-controller interrupter» should have a register that has an ARM bit» allows the controller to specify who may interrupt Disable the I bit in the CC register» I=0 all armed interrupts are enabled» I=1 disable interrupts note this does not ignore interrupts it just postpones them typical disable usage» first action in ISR set I=1» do whatever needs to be done that can t be interrupted» set I=0» NOTE: not doing this is a common source of significant confusion 5 CS 5780 Dedicated vs. Shared Multiple open-collector requests tied together to a shared interrupt line on the controller Pull up holds IRQ high when no service is requested Separate interrupt inputs on the controller Each I in is dedicated to a particular request 6 CS 5780 Page 3

6812 Interrupt Inputs IRQ can be disabled or enabled via the I bit in the CCR typical use is for non-emergency interrupts» e.g. service can be handled and then resume normal control XIRQ once enabled by setting the X bit in the CCR to 0» they can t be disabled typical use is emergency» low-power ISR saves as much as it can before power is gone return to normal control in this case won t happen How does the controller know what to do in the shared IRQ case? What are the fundamental advantages of shared vs. dedicated interrupts? 7 CS 5780 Dedicated vs. Shared Shared + s use of wired-or style interrupts (open collector on 6812)» no limit on number of interrupt capable devices» simple hardware and wiring» expansion to include more I/O devices requires no redesign cons:» ISR must look at all possible device registers to see what service is required there may be more than one» dispatch to appropriate routine» reset the request bit Dedicated + s: simpler software due to dedicated ISR s» faster since SW doesn t need to check everybody» less software coupling» easier to implement priority con: you might run out of dedicated I in s 8 CS 5780 Page 4

ISR s ISR: software that handles interrupt requests 2 polar styles Polled one large ISR handles all requests» shared model Vectored» dedicated model each I in causes indirect jump via a specific memory location often indexed via a separate interrupt index register If armed and enabled and a request happens execution of main program is suspended all registers pushed to stack ISR executed and returns (rti) all registers restored from stack main program is resumed see any problems? 9 CS 5780 Interrupt Execution 10 CS 5780 Page 5

When to Use Interrupts 11 CS 5780 Communication w/ Interrupts Any 2 threads must communicate via global memory foreground and background threads in the interrupt case» but still they are 2 threads in some cases main and ISR won t communicate» this is common in mainstream CPU s» e.g. ISR s fix exceptional events that have nothing to do with main ES s tend to be different» tight coupling between I/O environment» controllers role is often to aggregate I/O interrupt events into it s main calculation Interrupts have logically separate registers/stack so communication must occur through global memory» note that logically doesn t mean physically registers saved and restored via the same physical stack» communication can t use the stack since it s not a normal subroutine call due to the surprise factor 12 CS 5780 Page 6

2 Thread Communication Example Global FIFO is a common choice - why? 13 CS 5780 Input Device Interrupts 14 CS 5780 Page 7

Output Device Interrupts 15 CS 5780 Other Interrupt Issues Periodic interrupts essential for implementing data acquisition and control systems ISR goals occur only when needed come in clean, perform function, return right away» clearly Gadfly loops should be avoided minimize time spent in ISR s Latency interface latency» time between new data interrupt and when ISR or main gets the data beware the difference» device latency response time of external I/O device real-time?» requires tight bounds on latency guarantees 16 CS 5780 Page 8

Reentrant Programming Program reentrant if can be XEQ s by >1 threads of control Program must place local variables on the stack or use some form of mutual exclusion to prevent conflict on global storage accesses Non-reentrant subroutine has a vulnerable window error occurs if» main or an ISR calls while running in the vulnerable window fix:» make sure only one active call can be in the vulnerable window» mutex mechanisms semaphore variable disable interrupts 17 CS 5780 Reentrant or Not? Must be able to recognize potential sources of bugs due to non-reentrant code in high-level languages» just for yucks we ll define C to be high level Another example of why you ll sometimes need to examine assembly code Is time++ atomic?» Yes if compiler generates inc time» No if compiler generates ldd time add #1 std time What is the essential difference? 18 CS 5780 Page 9

Atomic Operations Atomic operation an operation that once started is guaranteed to finish In most machines a single assembly instruction is atomic» if an interrupt happens it will be taken between instructions» not during Hence 19 CS 5780 Read-Modify-Write Example Typical case where atomicity is desired but not guaranteed === bug time BIG TIME 20 CS 5780 Page 10

Write followed by Read Example RAW hazard 21 CS 5780 Nonatomic Multistep Write 22 CS 5780 Page 11

Disabling Interrupts in C 23 CS 5780 A Binary Semaphore 24 CS 5780 Page 12

Interrupt Synchronization Summary Device synchronization requires some protocol to permit HW and SW FSM s to interact HW protocols found in the device specifications» often cast in concrete» SW protocol must be compatible Interrupts are essentially a state machine interaction between main and the ISR follows a protocol» supported by hardware However» since you re writing both main and the ISR you ll be tempted to not think it through carefully» this is why interrupts are hard most of us make this mistake on the initial try or two fortunately mistake enhanced learning works quite well 25 CS 5780 Page 13