Design and Implementation Interrupt Mechanism

Similar documents
The ARM Cortex-M0 Processor Architecture Part-1

ECE251: Thursday September 27

Interrupts and Low Power Features

Exceptions and Interrupts ARM Cortex M3

ARM Cortex core microcontrollers

COEN-4720 Embedded Systems Design Lecture 4 Interrupts (Part 1) Cristinel Ababei Dept. of Electrical and Computer Engineering Marquette University

ARM Interrupts. EE383: Introduction to Embedded Systems University of Kentucky. James E. Lumpp

Interrupts (Exceptions) (From LM3S1968) Gary J. Minden August 29, 2016

introduction to interrupts

ELC4438: Embedded System Design ARM Cortex-M Architecture II

Interrupts (Exceptions) Gary J. Minden September 11, 2014

ARM architecture road map. NuMicro Overview of Cortex M. Cortex M Processor Family (2/3) All binary upwards compatible

Lab 4 Interrupt-driven operations

Embedded System Design

Introduction. ! Exception*are*events*! They*occur*during*the*execution*of*the*program! Type*of*ARM*exceptions*! Exceptions*that*result*by*a*command

ECE254 Lab3 Tutorial. Introduction to MCB1700 Hardware Programming. Irene Huang

ECE254 Lab3 Tutorial. Introduction to Keil LPC1768 Hardware and Programmers Model. Irene Huang

Multitasking on Cortex-M(0) class MCU A deepdive into the Chromium-EC scheduler

Program SoC using C Language

Modes and Levels. Registers. Registers. Cortex-M3 programming

Interrupt-Driven Input/Output

Interrupt/Timer/DMA 1

Cortex-M4 Processor Overview. with ARM Processors and Architectures

ARM Cortex-M0 DesignStart Processor and v6-m Architecture. Joe Bungo ARM University Program Manager Americas/Europe R&D Division

Cortex-M3 Reference Manual

Input/Output Programming

References & Terminology

OUTLINE. STM32F0 Architecture Overview STM32F0 Core Motivation for RISC and Pipelining Cortex-M0 Programming Model Toolchain and Project Structure

Programming Embedded Systems

The Next Steps in the Evolution of Embedded Processors

EE4144: ARM Cortex-M Processor

The Definitive Guide to the ARM Cortex-M3

ARM Cortex-M and RTOSs Are Meant for Each Other

NVIC and SCB Registers Quick Reference

Microprocessors & Interfacing

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

Cortex-M1 v3.1 Handbook

EECS 373 Design of Microprocessor-Based Systems

Course Introduction. Purpose: Objectives: Content: 27 pages 4 questions. Learning Time: 20 minutes

ARM Architecture and Assembly Programming Intro

AND SOLUTION FIRST INTERNAL TEST

Arm Cortex -M33 Devices

An overview of Interrupts ECE3534

I/O - input/output. system components: CPU, memory, and bus -- now add I/O controllers and peripheral devices. CPU Cache

Types of Interrupts:

Implementing Secure Software Systems on ARMv8-M Microcontrollers

8086 Interrupts and Interrupt Responses:

Cortex-M4 Exceptions and Interrupts

AN316 Determining the stack usage of applications

Migrating ARM7 Code to a Cortex-M3 MCU By Todd Hixon, Atmel

Microcomputer Interfacing Lab 3 Interrupts in ARM ANGUS GALLOWAY

Timers and Pulse Accumulator

The ARM Cortex-M0 Processor Architecture Part-2

Kinetis Software Optimization

Interrupts. Why Interrupts

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

EE251: Tuesday October 23

Application Note. Analyzing HardFaults on Cortex-M CPU

ARM Cortex-M0 Introduction

ARM Cortex-M4 Architecture and Instruction Set 1: Architecture Overview

AND9836. AXM0F243 MCU Programming Manual APPLICATION NOTE OVERVIEW

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

Cortex -M0. Technical Reference Manual. Revision: r0p0. Copyright 2009 ARM Limited. All rights reserved. ARM DDI 0432C (ID112415)

Troubleshooting Guide

ARM. Cortex -M7 Devices. Generic User Guide. Copyright 2015 ARM. All rights reserved. ARM DUI 0646A (ID042815)

Hercules ARM Cortex -R4 System Architecture. Processor Overview

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

Input/Output. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Interrupts and Exceptions

Measuring Interrupt Latency

Real Time Operating Systems

18-349: Introduction to Embedded Real-Time Systems

Embedded Systems. October 2, 2017

INTERRUPTS in microprocessor systems

CPUs. Input and output. Supervisor mode, exceptions, traps. Co-processors. Computers as Components 4e 2016 Marilyn Wolf

STM32: Peripherals. Alberto Bosio November 29, Univeristé de Montpellier

M2351 TrustZone Program Development

EKT222 Miroprocessor Systems Lab 5

IoT and Security: ARM v8-m Architecture. Robert Boys Product Marketing DSG, ARM. Spring 2017: V 3.1

Experiment 3. Interrupts. Hazem Selmi, Ahmad Khayyat

Interrupts Peter Rounce - room 6.18

ARM Architecture (1A) Young Won Lim 3/20/18

October, Saeid Nooshabadi. Overview COMP 3221

Developing a Generic Hard Fault handler for ARM Cortex-M3/Cortex-M4

PC Interrupt Structure and 8259 DMA Controllers

The Next Steps in the Evolution of ARM Cortex-M

These three counters can be programmed for either binary or BCD count.

COSC 243. Input / Output. Lecture 13 Input/Output. COSC 243 (Computer Architecture)

The Embedded Computing Platform

Interrupts in Zynq Systems

ECE 485/585 Microprocessor System Design

Exception and fault checking on S32K1xx

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

ARM TrustZone for ARMv8-M for software engineers

Module 3. Embedded Systems I/O. Version 2 EE IIT, Kharagpur 1

M2351 Security Architecture. TrustZone Technology for Armv8-M Architecture

Cortex -M0+ Technical Reference Manual. Revision: r0p1. Copyright 2012 ARM. All rights reserved. ARM DDI 0484C (ID011713)

AN2585 Application note

ARM Cortex -M for Beginners

Transcription:

Design and Implementation Interrupt Mechanism 1

Module Overview Study processor interruption; Design and implement of an interrupt mechanism which responds to interrupts from timer and UART; Program interrupt handler using assembly (low-level); Lab practice. Interrupt Hardware design ARM Cortex-M0 Processor AHB Timer Peripheral SRAM controller GPIO Peripheral VGA Peripheral 7-segment Peripheral UART Peripheral 2

Module Syllabus Polling Vs. Interrupt Exception and Interruption Interrupt Preemption ARMv6-M Exception Model Cortex-M0 Interrupt Controller NVIC Configuration Hardware Implementation of Interrupt Interrupts Handling in Software Lab Practice 3

Interruption in General 4

Polling Vs. Interrupt How to display a number counting-up every second: Polling - use software to check if the hardware timer reaches a value; Slow - need to explicitly check to see if the timer has reached a value Wasteful of CPU time - the faster a response we need, the more often we need to check Scales badly - difficult to build system with many activities which can respond quickly. Response time depends on all other processing. Interrupt - the timer generates an interrupt every second, and the processor runs specific code (interrupt service routine - ISR) in response; Efficient - code runs only when necessary Fast - hardware mechanism Scales well ISR response time doesn t depend on most other processing. Code modules can be developed independently 5

Exception and Interruption Exception Events (internal or external) that cause the program flow to exit the current program thread, and execute a piece of code associated with the event; Events can be either internal or external. Exception Handler is a piece of software code that is executed in the exception mode; Internal or external event Thread Mode Executing normal code sequence Context saving Context restoring Finishing handler Exception Mode Executing exception handler 6

Exception and Interruption Interrupt Refers to the exception caused by external events; External event is also called interrupt request (IRQ). The exception handler here is also called interrupt service routine (ISR); IRQ Thread Mode Executing normal code sequence Context saving Context restoring Finishing handler Exception Mode Executing ISR 7

Interrupt Preemption The exceptions (or interrupts) are commonly divided into multiple levels of priorities; A higher priority exception can be triggered and serviced during a lower priority exception; Commonly known as a nested exception, or interrupt preemption. Main thread Context switching ISR Low priority Context switching ISR High priority Main interrupt stacking ISR 1 interrupt stacking ISR2 ISR 1 unstacking Main unstacking 8

ARMv6-M Exception Model 9

ARMv6-M Exception Model Exception number Exception type Priority 1 Reset -3 (highest) 2 NMI -2 3 HardFault -1 4-10 Reserved 11 SVCall Programmable 12-13 Reserved 14 PendSV Programmable 15 SysTick, optional Programmable 16 + N External interrupt 0-31 Programmable 10

ARMv6-M Exception Model Reset The ARMv6-M profile supports two levels of reset; Power-on reset resets the processor, SCS and debug logic; Local reset resets the processor and SCS except for debugrelated resources; The Reset exception is permanently enabled with a fixed priority of -3; Non Maskable Interrupt (NMI) The second highest priority exception, cannot be disabled; Useful for safety critical systems like industrial control or automotive; Can be used for power failure handling or a watchdog; 11

ARMv6-M Exception Model HardFault HardFault is the generic fault that exists for all classes of fault that cannot be handled by any of the other exception mechanisms. For example, trying to execute an unknown optcode, or a fault on a bus interface or memory system; SVCall (SuperVisor Call) SVCall exception takes place when SVC instruction is executed; Is usually used in an operating system control; PendSV (Pendable Service Call) Similar to SVCall, but does not immediately take place; Starts only when high-priority tasks are completed; 12

ARMv6-M Exception Model SysTick The System Tick timer is another feature for an OS application; Exception starts when an regular interrupt is generated from a timer; External interrupts Supports up to 32 external interrupts, which can be connected from on-chip peripherals; Needs to be enabled before being used; Programmable priorities. 13

Cortex-M0 Interrupt Controller Nested Vectored Interrupt Controller (NVIC) An integrated part of the Cortex-M0 processor; Supports up to 32 IRQ inputs and a non-maskable interrupt (NMI) inputs; Flexible interrupt management Enable/ disable interrupt; Pending control; Priority configuration; Hardware nested interrupt support; Vectored exception entry; Interrupt masking; Can be easily accessed using C or assembly language. Location: Private Peripheral Bus System Control Space NVIC 14

Cortex-M0 Interrupt Controller Memory map of Nested Vectored Interrupt Controller (NVIC) Reserved Private Peripheral Bus External Device 0xE00FFFFF 0xE0000000 ROM table Reserved System Control Space (SCS) Reserved Break point unit Data watch point unit 0xE000EFFF 0xE000E000 Debug Control System Control Block (SCB) Nested Vectored Interrupt Controller (NVIC) Reserved SysTick Timer Reserved 0xE000ED8F 0xE000ED00 0xE000ECFF 0xE000E100 External RAM Reserved Peripherals SRAM Code 15

NVIC Registers Address 0xE000E100 0xE000E104 0xE000E17F 0xE000E180 0xE000E184 0xE000E1FF 0xE000E200 0xE000E204 0xE000E27F 0xE000E280 0xE000E300 0xE000E3FC 0xE000E400 0xE000E41C 0xE000E420 0xE000E43C Register Interrupt Set-Enable Register Reserved Interrupt Clear Enable Register Reserved Interrupt Set-Pending Register Reserved Interrupt Clear-Pending Register Reserved Interrupt Priority Registers Reserved 16

NVIC Registers Interrupt Set-Enable Register Write 1 to enable one or more interrupts; Write 0 has no effect; Interrupt Clear Enable Register Write 1 to one or more interrupts. Write 0 has no effect; Write 1 to enable Interrupt #31 Write 1 to enable Interrupt #0 Interrupt Set- Enable Register Interrupt Clear Enable Register bit31 bit24 bit16 bit8 Write 1 to clear Interrupt #0 17

NVIC Registers Why use separated register address Compared with the read-modify-write process the benefit of using separated address includes: Reduces the steps needed for enabling/ disabling an interrupt, resulting in smaller code and less execution time; Prevents the race condition, e.g. the main thread is accessing a register by read-modify-write process, and it is interrupted between its read and write operation. If the ISR again modifies the same register that is currently being accessed by the main thread, a conflict will occur. Interrupt pending and clear pending An interrupt goes into pending status if it cannot be processed immediately, e.g. a lower priority interrupt will be pended if a higher interrupt is being processed. 18

NVIC Registers Cortex-M0 Priority The priority level configuration registers are 8 bits wide, but only two bits are implemented in Cortex-M0; Since only the two MSBs are used, four levels of priority can be represented: 0x00,0x40,0x80 and 0xC0. bit7 bit6 bit5 bit4 implemented bit3 bit2 bit1 bit0 Not implemented Reset NMI Hard fault -3-2 -1 0x00 Highest priority Possible priorities: 0x00,0x40,0x80, 0xC0 Programmable exceptions 0x40 0x80 0xC0 Lowest priority 19

NVIC Registers Interrupt Priority Registers Use eight 32-bit registers to sets interrupt priorities for the 32 interrupts; Each register contains the priority for 4 interrupts; and each interrupt priority is implemented using 2 bits. 0xE000E41C 31 30 29 28 0xE000E418 27 26 25 24 0xE000E414 0xE000E410 0xE000E40C 0xE000E408 0xE000E404 0xE000E400 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 bit32 bit24 bit16 bit8 bit1 20

Implementation of Interrupt Mechanism 21

Interrupt Implementation for Timer Implement the interrupt mechanism for the AHB timer peripheral, for example: An interrupt is generated every time the counter reaches zero. A clear register needs to be added, which is used to clear the interrupt request once the processor finishes its ISR. Data [31:0] addr Address decoder Load[31:0] Addr[31:0] Control[31:0] Timer_irq AHB Interface Data [31:0] Clk Current[31:0] Clear[31:0] Control[31:0] Prescaler 32-bit Counter Counter == 0? Interrupt request 22

Interrupt Implementation for UART Implement the interrupt mechanism for the AHB UART peripheral; For example, the interrupt can be generated if the receiver FIFO is not empty. Data [31:0] Addr [31:0] Control[31:0] AHB interface Data 8 Ready Data 8 Ready Full Transmitter FIFO Receiver FIFO 8 Data Data Start Done Done 8 UART Transmitter Tick Baud rate Generator Tick UART Receiver UART TX UART RX FIFO!= empty? UART_irq Interrupt request 23

Connect Interrupts to Processor Connect the interrupts from peripherals to the Cortex-M0 microprocessor; Note that in this set of teaching materials, we use a simplified version of Cortex-M0 (Cortex-M0 DesignStart), which only supports 16 external interrupts. ARM Cortex-M0 Microprocessor Processor_IRQ UART_IRQ timer_irq UART Timer Peripheral Peripheral Timer_IRQ Processor_IRQ [15:0] UART_IRQ 24

Enable Interrupts in Software 1. Configure NVIC: Set interrupt priority registers, for example: LDR R0, =0xE000E400 ; Address of priority0 register LDR R1, [R0] ; Get priority0 register MOVS R2, #0xFF ; Byte mask BICS R1, R1, R2 ; R1= R1 AND (Not (0x000000FF)) MOVS R2, #0x40 ; Priority level ORRS R1, R1, R2 ; Update the value of priority register STR R1, [R0] ; Write back the priority register Set interrupt enable register, for example: LDR R0, =0xE000E100 ; NVIC Enable register MOVS R1, #0x1 ; Interrupt #0 STR R1, [R0] ; Enable interrupt #0 2. Make sure PRIMASK register is zero: Set to one will block all the interrupts apart from nonmaskable interrupt (NMI) and the hard fault exception, e.g. MOVS R0, #0x0 ; MSR PRIMASK, R0 ; Clear PRIMASK register 25

Entering an Exception Handler 1. Finish current instruction (except for lengthy instructions); 2. Look up the interrupt vector, and branch to the entry address of the exception handler; 3. Push context onto current stack (MSP or PSP) 4. Load PC with address of exception handler; 5. Load LR with EXC_RETURN code; 6. Load IPSR with exception number; 7. Start executing code of exception handler; Usually 16 cycles from exception request to execution of first instruction in the handler; The interrupt latency is the time delayed before entering an interrupt, which is an overhead that should be minimised. 26

Exiting an Exception Handler 1. Clear the interrupt request of the peripheral, for example: The timer can have a clear register, which is used to clear its interrupt request; Alternatively, the interrupt request can be automatically cleared by the peripheral itself, under a certain condition, e.g. UART can clear its interrupt request after all data has been read out from it receiver FIFO. 2. Context restoring, pop up the registers from the stack; 3. Update IPSR; 4. Load PC with the return address; 5. Continue executing code of the previous program; 27

Lab Practice 28

Lab Practice Step1- Hardware implementation Design and implement the interrupt mechanism (e.g. for the timer peripheral and the UART peripheral) in hardware using Verilog; Connect the interrupts to the Cortex-M0 processor through AHB bus; Step2- Software programming Test the interrupt mechanism using Cortex-M0 processor programed in assembler language; Step3- System Demonstration Receive characters from the UART, and then print them to the UART terminal using UART interrupt handler; Implement a counting-up counter, which is incremented every second, and the number will be displayed on the monitor. 29

Useful Resources Reference1 Nexys3 Reference Manual: http://www.digilentinc.com/data/products/nexys3/nexys3_rm.pdf Reference2 Book: The Definitive Guide to the ARM Cortex-M0 by Joseph Yiu, ISBN-10: 0123854776, ISBN-13: 978-0123854773, March 11, 2011 30