Bare Metal Application Design, Interrupts & Timers

Similar documents
Interrupts. Embedded Systems Interfacing. 08 September 2011

Interrupt/Timer/DMA 1

18-349: Introduction to Embedded Real-Time Systems

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

Single thread Scheduler All processes called once each sample

In Class Assignment 2

Lab 9: On-Board Time Generation and Interrupts

ELC4438: Embedded System Design ARM Cortex-M Architecture II

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

Hello and welcome to this Renesas Interactive module that covers the Independent watchdog timer found on RX MCUs.

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

WiMOD LR Base Plus Host Controller Interface

12.1. Unit 12. Exceptions & Interrupts

Embedded Software TI2726 B. 4. Interrupts. Koen Langendoen. Embedded Software Group

SECTION 5 RESETS AND INTERRUPTS

C Language Programming, Interrupts and Timer Hardware

ECE 598 Advanced Operating Systems Lecture 8

Mod5282 Programmable Interrupt Timer Application Note

Interrupts Peter Rounce - room 6.18

Interrupts in Zynq Systems

// and verify that there is a sine wave with frequency <FREQUENCY> and

Introduction to Embedded Systems

Homework. Reading. Machine Projects. Labs. Intel 8254 Programmable Interval Timer (PIT) Data Sheet. Continue on MP3

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document. ATmega IAR

Embedded Systems and Software

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

NUC123xxxAN Series Errata Sheet. Errata Sheet for 32-bit NuMicro Family Rev May 19, 2016

Embedded Controller Programming II. I/O Device Programming in C Part 1: Input and Interrupts

Chapter 6 Interrupts. (I. Scott Mackenzie) By: Masud-ul-Hasan

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

INTERRUPTS in microprocessor systems

Chapter 2. Overview of Architecture and Microcontroller-Resources

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document. ATmega128 GCC

Interrupts Peter Rounce

2.996/6.971 Biomedical Devices Design Laboratory Lecture 6: Microprocessors II

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document. ATmega128 IAR

Interrupt vectors for the 68HC912B32. The interrupt vectors for the MC9S12DP256 are located in memory from 0xFF80 to 0xFFFF.

8051 Timers and Serial Port

Hello and welcome to this Renesas Interactive course that covers the Watchdog timer found on RX MCUs.

Engineer To Engineer Note

Laboratory Exercise 4

#include <stdio.h> // // Global CONSTANTS

ECE 271 Microcomputer Architecture and Applications University of Maine

Chapters 2, 3: bits and pieces. Chapters 2 & 3. Chapters 2, 3: bits and pieces. Chapters 2, 3: bits and pieces. Using C. A last word about hardware

Embedded Systems. 3. Hardware Software Interface. Lothar Thiele. Computer Engineering and Networks Laboratory

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document. ARM Cortex-M3 CCS

Product Update. Errata to Z8 Encore! 8K Series Silicon. Z8 Encore! 8K Series Silicon with Date Codes 0402 and Later

Fundamental concept in computation Interrupt execution of a program to handle an event

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

Application Note. Watchdog Timer

Systems Programming. Lecture 11 Timers

Chapter 09. Programming in Assembly

Interrupt handling. Purpose. Interrupts. Computer Organization

Nano102/112 Series Errata Sheet

ELEG3923 Microprocessor Ch.9 Timer Programming

Interrupts and Low Power Features

Measuring Interrupt Latency

Implementing In-Application Programming on the ADuC702x

The 8051 microcontroller has two 16-bit timers/counters called T0 and T1.

Interrupts and Serial Communication on the PIC18F8520

Anybus CompactCom. Host Application Implementation Guide. Doc.Id. HMSI Doc. Rev Connecting DevicesTM

AN10210 Using the Philips 87LPC76x microcontroller as a remote control transmitter

Process Synchronization and Communication

Using FlexIO to emulate communications and timing peripherals

Microprocessors & Interfacing

Installation & Reference Guide

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

Chapter 6 PROGRAMMING THE TIMERS

C Language Programming, Interrupts and Timer Hardware

Nano RK And Zigduino. wnfa ta course hikaru4

Timers and Counters. LISHA/UFSC Prof. Dr. Antônio Augusto Fröhlich Fauze Valério Polpeta Lucas Francisco Wanner.

Module Introduction. PURPOSE: The intent of this module is to explain MCU processing of reset and interrupt exception events.

Embedded Software TI2726 B. 7. Embedded software design. Koen Langendoen. Embedded Software Group

ME 4447 / ME 6405: Introduction to Mechatronics

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document AVR32A GCC

MCS-51 Serial Port A T 8 9 C 5 2 1

Design and Implementation Interrupt Mechanism

Fujitsu Microelectronics Europe Application Note MCU-AN E-V10 FR FAMILY 32-BIT MICROCONTROLLER MB91460 REAL TIME CLOCK APPLICATION NOTE

AN10210 Using the Philips 87LPC76x microcontroller as a remote control transmitter

MPLAB Harmony Help - Test Harness Library

MPLAB Harmony Test Libraries Help

DE1-SoC Computer System with ARM Cortex-A9. 1 Introduction. 2 DE1-SoC Computer Contents. 2.1 Hard Processor System. For Quartus Prime 16.

DYNAMIC ENGINEERING 435 Park Dr., Ben Lomond, Calif Fax Est

VORAGO VA108x0 I 2 C programming application note

GLOSSARY. VisualDSP++ Kernel (VDK) User s Guide B-1

CN310 Microprocessor Systems Design

8051 Microcontroller

WiMOD LR Base Host Controller Interface

COMP2121: Microprocessors and Interfacing

High Reliability Systems. Lloyd Moore, President

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

Introduction to the MC9S12 Hardware Subsystems

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

EMBEDDED SOFTWARE DEVELOPMENT. George Hadley 2017, Images Property of their Respective Owners

DE0-Nano-SoC Computer System with ARM Cortex-A9. 1 Introduction. 2 DE0-Nano-SoC Computer Contents. 2.1 Hard Processor System. For Quartus Prime 16.

Newbie s Guide to AVR Interrupts

Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

Infineon C167CR microcontroller, 256 kb external. RAM and 256 kb external (Flash) EEPROM. - Small single-board computer (SBC) with an

Lecture test next week

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

Transcription:

Topics 1) How does hardware notify software of an event? Bare Metal Application Design, Interrupts & Timers 2) What architectural design is used for bare metal? 3) How can we get accurate timing? 4) How can we use the watchdog? CMPT 433 Slides #15.3 Dr. B. Fraser 17-11-21 2 17-11-21 1 Interrupt Service Routine IRQ:.. ISRs: Interrupt Service Routines Hardware generates IRQs for certain events timers serial data arrived board losing power, etc. Developer writes an Interrupt Service Routine (ISR) to handle a given interrupt. Hardware executes the correct ISR for an interrupt. "main" thread suspended while in ISR. Foreground Task:.. Background Task:.. 17-11-21 3 17-11-21 4

Minimize Time in ISR ISR Programming Issues Do minimal work to service an IRQ Postpone "real" work for background thread: Set flag in ISR; process flag in main(). Don't do blocking IO (UART) in ISR. [ex: printf] Why? ISR often runs with interrupts disabled, so.. Worst-case latency can critically impede real-time performance. EX: sampling audio channel regularly 17-11-21 5 Global variables written in ISR should be volatile Prevents compiler optimization; value may change unexpectedly. volatile static _Bool uartdatawaiting = false;.. it s effectively multithreaded. Avoid using much stack in ISR ISR's stack usage can be on top of normal usage. In multi-threaded RTOS,.. Complications Can have nested interrupts Can prioritize interrupts 17-11-21 6 Common Interrupts Some common interrupts Timer UART Rx [and many UART interrupts] Demo: Show bm_uartrx.c GPIO changes Bare Metal Application Design Network packet Rx Analog-to-digital data sample ready 17-11-21 7 17-11-21 8

Modular Approach Common Bare Metal Architecture Use modules with clear interfaces.h files: expose an interface..c files: implements functionality. In our bare metal examples, makefiles automatically compile all.c files for you. Names Control buzzer in buzzer.h/.c Give functions names such as: int Buzzer_init(); int Buzzer_on(int durationinsec); All global variables, and functions not shared in.h.. main() init() Main App Module while (1) { } // do background // work here if (Serial_keyWaiting() { Serial_handleKey() } Serial Module serialrxisr() - record RX d char - set key RX flag - clear hardware Serial_handleKey() - process key, taking required actions. - clear key RX flag. Timer Module timerisr() - track current time : time_ms += 100; - set timer expired flag - call a few functions to do some very light work. - nothing may block or take much time. - clear hardware 17-11-21 9 17-11-21 10 Common Pattern Demo: Fake Typer ISR Common pattern 1. 2. clears flag, calls function to do some work (OK to take a long time to complete) Modularize Encapsulate flag and all functions to set/check flag into a module. Advanced: Instead of Serial module processing user inputs and do customized work in ISR, give module function pointers for callbacks from the ISR (or elsewhere) for triggering custom work from Serial module. 17-11-21 11 Demo: faketyper Multiple files, clear interfaces Trace main() Function FakeTyper_init(void) -- from main() FakeTyper_setMessage(char *message) -- from serial FakeTyper_notifyOnTimerIsr(void) -- from timer FakeTyper_doBackgroundWork(void) -- from main() Multiple Interrupts If using multiple interrupts (like timer and serial) only call IntAINTCInit() once: It resets the Arm Interrupt Controller, which will turn off any enabled interrupts 17-11-21 12

Timers Hardware Resources Processor has 8 configurable 32bit hardware timers Timers Can generate an interrupt when timer overflows Process: 1. Counts up to 0xFFFF FFFF +1 2. Generates interrupt 3. Load TLDR on reset:.. Change TLDR s value to control timer period Larger numbers = shorter duration. 17-11-21 13 17-11-21 14 Timer Diagram Clock Divider ISR triggers at 0xFFFF FFFF + 1 (overflow) Timer counts up at 25 mhz or 32.786 khz 0xFFFF FFFF On the counter ISR triggers Clock Divider Clock has 2 possible sources: 32.768 khz, 25Mhz Can prescale (divide down) the clock... Effectively uses bit N of an extra counter to drive the clock into the timer. Computing Timeout On overflow, counter reloads to value from TLDR register TLDR Frequency (Hz) = 1 / period (in s) 0x0000 0000 On the counter 17-11-21 15 17-11-21 16

Simplified Example Simplified Example Imagine an 8-bit timer with a 32Hz clock (not MHz, Hz!) With no divider (N=0), what is the maximum duration of the timer? Period= xffx00+1 2 0 32 = 256 32 = 28 2 5=23 =8s 17-11-21 17 Imagine an 8-bit timer with a 32Hz clock (not MHz, Hz!) What divider (N) and TLDR is needed to get a 200s duration (period)?.. Since 32 = 2 5, so start with N = 5. We want 200s timeout: 200 = 0xFF - TLDR + 1 TLDR= 0xFF - 200 + 1 = 55 + 1 = 56 Period= 25656+1 2 5 =200s 32 17-11-21 18 Max on 32bit timer 2s on 32bit timer With our 32 bit timer and a 25MHz clock with N=0, what is the maximum timer period? Period= xffffffff0+1 2 0 25MHz With our 32 bit timer and a 25MHz clock, how can we get a 2s period? 2s= xfffffffftldr+1 25MHz 2 s 25 MHz= xffff FFFFTLDR+1 TLDR=xFFFF FFFF2 25 M +1...Skipping some math... = xfd05 0F80 Note: Simply compute number of timer clock cycles, and take 2's complement. 17-11-21 19 17-11-21 20

2s with clock divider Demo and Practical Timing With our 32 bit timer and a 25MHz clock and N = 2, how long a period will the previous TLDR give? Demo: Show bm_timer.c Previous slide computed TLDR for 2s period. Prescale N=2 means 2 2 slowdow =.. So N=2 makes previous TLDR.. Practical Timing If you want to double the period, double TLDR's distance to 0xFFFF FFFF If your timing is a little off: Use stopwatch to time 10-100 timeouts and then scale TLDR 17-11-21 21 17-11-21 22 Watchdog Timeout Watchdog Timer 32 bit counter triggers.. Runs on 32.768khz clock Bare Metal Watchdog Hitting watchdog resets it to WDT_WLDR's value Hit by writing a changing value to WDT_WTGR (WatchdogTimerTriggerSet) Demo bm_faketyper :: timers.c show computation of timeout show hit function. 17-11-21 23 17-11-21 24

Reset Source Processor knows why it last rebooted Cold Watchdog External reset (reset button) Software reset (instruction) Reset Register (PRM_RSTST) See TRM p1336 [show docs] indicates reset source must clear bits (write all 1's) to have next reboot show only the correct source. Not in.h files: #define PRM_DEV 0x44E00F00 #define PRM_RSTST_OFFSET 0x08 // base // reg offset Summary Hardware generates IRQ, serviced by ISR ISR does minimal work on foreground task; processing/blocking IO done in main(): background Use good modular C design: encapsulation Hardware timers give precise timing. Set reload register (TLDR) to control period: Watchdog timer reboots on an overflow. Use reset registers to track reset source. 17-11-21 25 17-11-21 26