7-1 EE 319K Introduction to Embedded Systems Lecture 7: Phase-locked-loop, Data structures, Finite state machines, Interrupts Bard, Gerstlauer, Valvano,

Slides:



Advertisements
Similar presentations
Computer Architecture
Advertisements

Chapter 3 Basic Input/Output
11-1 Bard, Gerstlauer, Valvano, Yerraballi EE 319K Introduction to Embedded Systems Lecture 11: Data Acquisition, Numerical Fixed-Point Calculations, Lab.
EE 319K Introduction to Embedded Systems
4-1 EE 319K Introduction to Embedded Systems Lecture 4: Arithmetic overflow, Branches, Control Structures, Abstraction & Refinement Bard, Erez, Gerstlauer,
1-1 Bard, Gerstlauer, Valvano, Yerraballi EE 319K Introduction to Microcontrollers Lecture 1: Introduction, Embedded Systems, Product Life-Cycle, ARM Programming.
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
10-1 EE 319K Introduction to Microcontrollers Lecture 10: Interrupts, Output Compare Periodic Interrupts Read Book Sections 9.1, 9.2, 9.4, 9.6.1, 9.6.2,
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
68HC11 Polling and Interrupts
ECE 372 – Microcontroller Design Parallel IO Ports - Interrupts
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
CSS 372 Lecture 1 Course Overview: CSS 372 Web page Syllabus Lab Ettiquette Lab Report Format Review of CSS 371: Simple Computer Architecture Traps Interrupts.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
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.
1 CSIT431 Introduction to Operating Systems Welcome to CSIT431 Introduction to Operating Systems In this course we learn about the design and structure.
Chapter 7 Interupts DMA Channels Context Switching.
Basic Input/Output Operations
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
11-1 Bard, Tiwari, Telang, Janapa Reddi, Gerstlauer, Valvano, Yerraballi EE 319K Introduction to Embedded Systems Lecture 11: Data Acquisition, Numerical.
Midterm Wednesday 11/19 Overview: 25% First Midterm material - Number/character representation and conversion, number arithmetic - DeMorgan’s Law, Combinational.
6-1 EE 319K Introduction to Embedded Systems Lecture 6: SysTick Timer, Exam 1 Review Bard, Erez, Gerstlauer, Valvano, Yerraballi, Telang, Janapa Reddi,
1 Computer System Overview Chapter 1 Review of basic hardware concepts.
CS-334: Computer Architecture
Chapter 7 Input/Output Luisa Botero Santiago Del Portillo Ivan Vega.
Introduction to Embedded Systems
Chapter 10: Input / Output Devices Dr Mohamed Menacer Taibah University
Ch. 9 Interrupt Programming and Real-Time Sysstems From Valvano’s Introduction to Embedded Systems.
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.
Computer System Overview Chapter 1. Operating System Exploits the hardware resources of one or more processors Provides a set of services to system users.
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.
2009 Sep 10SYSC Dept. Systems and Computer Engineering, Carleton University F09. SYSC2001-Ch7.ppt 1 Chapter 7 Input/Output 7.1 External Devices 7.2.
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CE-321: Computer.
Microprocessors 1 MCS-51 Interrupts.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This training course provides an overview of the CPU architecture.
Computer Architecture Lecture 2 System Buses. Program Concept Hardwired systems are inflexible General purpose hardware can do different tasks, given.
EEE440 Computer Architecture
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
EE 319K Introduction to Microcontrollers
Fall 2000M.B. Ibáñez Lecture 25 I/O Systems. Fall 2000M.B. Ibáñez Categories of I/O Devices Human readable –used to communicate with the user –video display.
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.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Dr Mohamed Menacer College of Computer Science and Engineering, Taibah University CE-321: Computer.
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
EE 319K Introduction to Embedded Systems
Lecture 4 General-Purpose Input/Output NCHUEE 720A Lab Prof. Jichiang Tsai.
Embedded Computer - Definition When a microcomputer is part of a larger product, it is said to be an embedded computer. The embedded computer retrieves.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
Chapter 3 System Buses.  Hardwired systems are inflexible  General purpose hardware can do different tasks, given correct control signals  Instead.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Interrupt 마이크로 프로세서 (Micro Processor) 2015년 2학기 충북대학교 전자공학과 박 찬식
68HC11 Interrupts & Resets.
Microprocessor Systems Design I
Computer Architecture
EE 319K Introduction to Embedded Systems
Interrupts In 8085 and 8086.
Chapter 3 Top Level View of Computer Function and Interconnection
EE 319K Introduction to Embedded Systems
Computer System Overview
Presentation transcript:

7-1 EE 319K Introduction to Embedded Systems Lecture 7: Phase-locked-loop, Data structures, Finite state machines, Interrupts Bard, Gerstlauer, Valvano, Yerraballi

7-2 Agenda  Recap  Indexed Addressing and Pointers oIn C: Address of (&), Pointer to (*)  Data Structures: Arrays, Strings oLength: hardcoded vs. embedded vs. sentinel oArray access: indexed vs. pointer arithmetic  Functional Debugging  SysTick Timer  Outline  Phase Lock Loop (PLL)  Data structures  Finite State Machines, Linked-lists  Interrupts Bard, Gerstlauer, Valvano, Yerraballi

7-3 Phase-Lock-Loop  Internal oscillator requires minimal power but is imprecise  External crystal provides stable bus clock  TM4C123 is equipped with 16 MHz crystal and bus clock can be set to a maximum of 80 MHz Bard, Gerstlauer, Valvano, Yerraballi

7-4 Recap: Array access  Calculate address from Base and index  ByteBase+index  HalfwordBase+2*index  WordBase+4*index  Size_NBase+N*index  Access sequentially using pointers  Bytept = pt+1  Halfwordpt = pt+2  Wordpt = pt+4  Size_Npt = pt+N Bard, Gerstlauer, Valvano, Yerraballi

7-5 Abstraction  Software abstraction  Define a problem with a minimal set of basic, abstract principles / concepts  Separation of concerns via interface/policy mechanisms  Straightforward, mechanical path to implementation  Three advantages of abstraction are 1.it can be faster to develop 2.it is easier to debug (prove correct) and 3.it is easier to change Bard, Gerstlauer, Valvano, Yerraballi

7-6 Finite State Machine (FSM)  Finite State Machines (FSMs)  Set of inputs, outputs, states and transitions  State graph defines input/output relationship  What is a state?  Description of current conditions  What is a state graph?  Graphical interconnection between states  What is a controller?  Software that inputs, outputs, changes state  Accesses the state graph Bard, Gerstlauer, Valvano, Yerraballi

7-7 Finite State Machine (FSM)  What is a finite state machine?  Inputs (sensors)  Outputs (actuators)  Controller  State graph Bard, Gerstlauer, Valvano, Yerraballi

7-8 Finite State Machine (FSM)  Moore FSM  output value depends only on the current state,  inputs affect the state transitions  significance is being in a state  Input: when to change state  Output: definition of being in that state Bard, Gerstlauer, Valvano, Yerraballi

7-9 Finite State Machine (FSM)  Moore FSM Execution Sequence 1.Perform output corresponding to the current state 2.Wait a prescribed amount of time (optional) 3.Read inputs 4.Change state, which depends on the input and the current state 5.Go back to 1. and repeat Bard, Gerstlauer, Valvano, Yerraballi

7-10 Finite State Machine (FSM)  Mealy FSM  output value depends on input and current state  inputs affect the state transitions.  significance is the state transition  Input: when to change state  Output: how to change state Inputs: Control Outputs: Brake, Gas Bard, Gerstlauer, Valvano, Yerraballi

7-11 Finite State Machine (FSM)  Mealy FSM Execution Sequence 1.Wait a prescribed amount of time (optional) 2.Read inputs 3.Perform output, which depends on the input and the current state 4.Change state, which depends on the input and the current state 5.Go back to 1. and repeat Bard, Gerstlauer, Valvano, Yerraballi

7-12 Finite State Machine (FSM) Bard, Gerstlauer, Valvano, Yerraballi

7-13 FSM Implementation  Data Structure embodies the FSM  multiple identically-structured nodes  statically-allocated fixed-size linked structures  one-to-one mapping FSM state graph and linked structure  one structure for each state  Linked Structure  pointer (or link) to other nodes (define next states)  Table structure  indices to other nodes (define next states) Bard, Gerstlauer, Valvano, Yerraballi

7-14 Traffic Light Control PE1=0, PE0=0 means no cars exist on either road PE1=0, PE0=1 means there are cars on the East road PE1=1, PE0=0 means there are cars on the North road PE1=1, PE0=1 means there are cars on both roads goN, PB5-0 = makes it green on North and red on East waitN, PB5-0 = makes it yellow on North and red on East goE, PB5-0 = makes it red on North and green on East waitE, PB5-0 = makes it red on North and yellow on East Bard, Gerstlauer, Valvano, Yerraballi

7-15 Traffic Light Control Bard, Gerstlauer, Valvano, Yerraballi

7-16 Linked Data Structure OUT EQU 0 ;offset for output WAIT EQU 4 ;offset for time (10ms) NEXT EQU 8 ;offset for next goN DCD 0x21 ;North green, East red DCD 3000 ;30 sec DCD goN,waitN,goN,waitN waitN DCD 0x22 ;North yellow, East red DCD 500 ;5 sec DCD goE,goE,goE,goE goE DCD 0x0C ;North red, East green DCD 3000 ;30 sec DCD goE,goE,waitE,waitE waitE DCD 0x14 ;North red, East yellow DCD 500 ;5 sec DCD goN,goN,goN,goN In ROM Bard, Gerstlauer, Valvano, Yerraballi

7-17 FSM Engine (Moore) ; Port and timer initialization LDR R4,=goN ; state pointer LDR R5,=SENSOR ; PortE LDR R6,=LIGHT ; PortB FSM LDR R0,[R4,#OUT] ; 1.output value STR R0,[R6] ; set lights LDR R0,[R4,#WAIT] ; 2. time delay BL SysTick_Wait10ms LDR R0,[R5] ; 3. read input LSL R0,R0,#2 ; offset(index): ; 4 bytes/address ADD R0,R0,#NEXT ; 8,12,16,20 LDR R4,[R4,R0] ; 4. go to next state B FSM Bard, Gerstlauer, Valvano, Yerraballi

7-18 Linked Data Structure in C const struct State { uint32_t Out; uint32_t Time; // 10 ms units const struct State *Next[4]; }; typedef const struct State STyp; #define goN &FSM[0] #define waitN &FSM[1] #define goE &FSM[2] #define waitE &FSM[3] STyp FSM[4] = { {0x21,3000,{goN,waitN,goN,waitN}}, {0x22, 500,{goE,goE,goE,goE}}, {0x0C,3000,{goE,goE,waitE,waitE}}, {0x14, 500,{goN,goN,goN,goN}} }; Bard, Gerstlauer, Valvano, Yerraballi

7-19 FSM Engine in C (Moore) void main(void) { STyp *Pt; // state pointer uint32_t Input; // initialize ports and timer … Pt = goN; // start state while(1) { LIGHT = Pt->Out; // set lights SysTick_Wait10ms(Pt->Time); Input = SENSOR; // read sensors Pt = Pt->Next[Input]; } Bard, Gerstlauer, Valvano, Yerraballi

7-20 Interrupts  An interrupt is the automatic transfer of software execution in response to a hardware event (trigger) that is asynchronous with current software execution.  external I/O device (like a keyboard or printer) or  an internal event (like an op code fault, or a periodic timer.)  Occurs when the hardware needs or can service (busy to done state transition) Bard, Gerstlauer, Valvano, Yerraballi

7-21 Interrupt Processing Bard, Gerstlauer, Valvano, Yerraballi

7-22 ARM Cortex-M Interrupts  Each potential interrupt source has a separate arm bit  Set for those devices from which it wishes to accept interrupts,  Deactivate in those devices from which interrupts are not allowed  Each potential interrupt source has a separate flag bit  hardware sets the flag when it wishes to request an interrupt  software clears the flag in ISR to signify it is processing the request  Interrupt enable conditions in processor  Global interrupt enable bit, I, in PRIMASK register  Priority level, BASEPRI, of allowed interrupts (0 = all) Bard, Gerstlauer, Valvano, Yerraballi

7-23 Interrupt Conditions  Four conditions must be true simultaneously for an interrupt to occur: 1.Arm: control bit for each possible source is set 2.Enable: interrupts globally enabled (I=0 in PRIMASK) 3.Level: interrupt level must be less than BASEPRI 4.Trigger: hardware action sets source-specific flag  Interrupt remains pending if trigger is set but any other condition is not true  Interrupt serviced once all conditions become true  Need to acknowledge interrupt  Clear trigger flag or will get endless interrupts! Bard, Gerstlauer, Valvano, Yerraballi

7-24 Interrupt Processing 1.The execution of the main program is suspended 1.the current instruction is finished, 2.suspend execution and push 8 registers (R0-R3, R12, LR, PC, PSR) on the stack 3.LR set to 0xFFFFFFF9 (indicates interrupt return) 4.IPSR set to interrupt number 5.sets PC to ISR address 2.The interrupt service routine (ISR) is executed  clears the flag that requested the interrupt  performs necessary operations  communicates using global variables 3.The main program is resumed when ISR executes BX LR  pulls the 8 registers from the stack Bard, Gerstlauer, Valvano, Yerraballi

7-25 Registers SP (R13) refers to PSP or MSP We will use just the MSP PRIMASK has intr. enable (I) bit BASEPRI has allowed intr. priority R14, R15 are important R0-R3 parameters R4-R11 must be saved Bard, Gerstlauer, Valvano, Yerraballi

7-26 Priority Mask Register CPSID I CPSIE I CPSID I MRS PRIMASK,R0 MRS R0,PRIMASK Interface latency Disable interrupts (I=1) Enable interrupts (I=0) Bard, Gerstlauer, Valvano, Yerraballi

7-27 Program Status Register Q = Saturation, T = Thumb bit  Accessed separately or all at once Bard, Gerstlauer, Valvano, Yerraballi

7-28 Interrupt Program Status Register (ISPR) Run debugger: - stop in ISR and - look at IPSR Bard, Gerstlauer, Valvano, Yerraballi

7-29 Interrupt Number 18 corresponds to GPIO Port C Vector address for GPIO Port C Interrupt Context Switch Bard, Gerstlauer, Valvano, Yerraballi