1 Run-Time Methods for Making Embedded Systems Robust.

Slides:



Advertisements
Similar presentations
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Advertisements

1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
A look at interrupts What are interrupts and why are they needed.
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
68HC11 Polling and Interrupts
CSC Timers Since this is a microcontroller it mainly finds itself in embedded devices Quite often embedded devices need to synchronize events The.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
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.
A look at interrupts What are interrupts and why are they needed.
Introduction to Interrupts
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
INTERRUPTS PROGRAMMING
NS Training Hardware. System Controller Module.
The 8051 Microcontroller architecture
Embedded Systems 7763B Mt Druitt College of TAFE
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Introduction Purpose:  This training module provides a technical description of Renesas.
Chapter 10 And, Finally... The Stack. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Stacks A LIFO.
Chapter 10 The Stack Stack: An Abstract Data Type An important abstraction that you will encounter in many applications. We will describe two uses:
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This course provides an overview of the CPU architecture.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This training course provides an overview of the CPU architecture.
Renesas Technology America, Inc. Flash!. CPU Rewrite CPU-rewrite is a term that refers to an Renesas MCU’s ability to erase/program its own internal Flash.
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
8051 Micro controller. Architecture of 8051 Features of 8051.
Time Management.  Time management is concerned with OS facilities and services which measure real time, and is essential to the operation of timesharing.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
INT- interrupt program execution 1. It decrements the sp by 2 and pushes the flag registers on the stack. 2. Decrement the sp by 2 and push the content.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
1 CSE451 Architectural Supports for Operating Systems Autumn 2002 Gary Kimura Lecture #2 October 2, 2002.
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.
Dec Hex Bin 14 E ORG ; FOURTEEN Interrupts In x86 PC.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
© 2009, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction  Purpose This course provides an introduction to the peripheral functions.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
System Integration Module MTT Motoola SYSTEM INTEGRATION MODULE (SIM)
بسم الله الرحمن الرحيم MEMORY AND I/O.
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
MICROPROCESSOR DETAILS 1 Updated April 2011 ©Paul R. Godin prgodin gmail.com.
Lecture 3 CSE 341 – Microprocessors Lecture 3 Md. Omar Faruqe UB 1228
1 Run-to-Completion Non-Preemptive Scheduler. 2 In These Notes... What is Scheduling? What is non-preemptive scheduling? Examples Run to completion (cooperative)
HJD Institute of Technical Education & Research- Kera(Kutch) The 8051 Microcontroller architecture PREPARED BY: RAYMA SOHIL( )
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
INSTITUTE: INSTITUTE:PARUL INSTITUTE OF TECHNOLOGY BRANCH : BRANCH :B.E. E.C.5 TH SEM. SUBJECT:MICROCONTROLLER & INTERFACING TOPIC:AVR INTTRUPT TOPIC:AVR.
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
21-1 Embedded Systems Run-Time Methods for Making Embedded Systems Robust Lecture 21.
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
Interrupts and interrupt responses
68HC11 Interrupts & Resets.
Microprocessor Systems Design I
Timer and Interrupts.
The Stack.
Refer to Chapter 5 in the reference book
UNIT – Microcontroller.
Mechanism: Limited Direct Execution
Computer Architecture
Interrupts In 8085 and 8086.
Chapter 10 And, Finally... The Stack
Chapter 10 The Stack.
Interrupts, Tasks and Timers
Lecture 9: TI MSP430 Interrupts & Low Power Modes
Interrupts.
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Embedded System Development Lecture 7 2/21/2007
COMP3221: Microprocessors and Embedded Systems
Presentation transcript:

1 Run-Time Methods for Making Embedded Systems Robust

2 Today Need to make embedded systems robust –Implementation flaws: Code may have implementation bugs –Design flaws: Real world may not behave the way we expected and designed for –Component failures: Sometimes things break Run-time mechanisms for robust embedded systems –Watchdog timer –Stack-pointer monitor –Voltage brown-out detector

3 Watchdog Timer Concepts (WDT) Goal: detect if software is not operating correctly Assumption: healthy threads/tasks will periodically send a heartbeat (“I’m alive”) signal Mechanism –Use heartbeat signals from tasks to restart a timer –If timer ever expires, the system is sick, so reset Typically used as a final, crude catastrophic mechanism for forcing system software back into known state Time WDT Value Start WDT WDT times out, resets system Restart WDT

4 Time-Out Actions Simple solution: reset entire system –May need to explicitly toggle reset pin to ensure CPU is fully reset (rather than just jumping to reset ISR) –Reset should configure all I/O to safe state NMI Solution: generate non-maskable interrupt for debug –Use NMI ISR to save picture of CPU and thread state –Can then examine what happened with debugger or in-circuit emulator WDT Time-Out flag in memory –Set flag upon time-out before reset –Examine this bit in reset ISR to determine whether to boot system normally or with debug mode (without overwriting RAM)

5 Resetting the WDT in a Multithreaded Application Each periodic task updates a timestamp when it starts running Checker thread checks timestamp for each thread i to make sure it was run no more than T i ago. If all threads are ok, restart the WDT. Does this detect every possible problem? Why not put it into the scheduler?

6 Design Suggestions for WDT Don’t scatter WDT reset commands throughout your code –There should just be one or a few such commands in the entire program WDT should be difficult to accidentally disable in software Should be able to disable WDT externally with a very obvious jumper (use to simplify debugging) Choose WDT period appropriately –Too long and system is out of control long enough to get into real trouble –Too short and you need to reset WDT frequently in your code (code writing and analysis overhead)

7 M30626 Watchdog Timer (WDT) 15-bit down counter –Decremented by prescaled BCLK clock signal BCLK = clock which drives CPU. Is external clock divided by 2,4, 8 or 16 Prescaler divides BCLK by 16 or 128 Our board: –Prescale by 16: 24 MHz/(16*32768) = 45.8 Hz, 21.8 ms –Prescale by 128: 24 MHz/(128*32768) = 5.7 Hz, 175 ms –Is preset to 7FFF by Code writing to WDTS (000E) RESET signal being asserted WDT itself expiring –Doesn’t start counting until a write to WDTS (000E) Counter reaches 0? –Results in Oscillation Stop Detection/Watchdog Timer interrupt (non-maskable interrupt), vector is at FFFF0

8 A Code Example void WD_Init(){//Initialize Watchdog Timer cm06 = 1; //BCLK = (20/8) MHz = 2.5 MHz (Xin div by 8, default) wdc7 = 1; //prescaler is div by 128, Watchdog Timer //period = (32,768 x 128) / (2.5 MHz) = 1.678s wdts = 0; //start Watchdog Timer by writing any value to wdts //reg (value always resets to 0x7fff when written to) } void main(void){ … while (1) { processing(); more_processing(); other_computations(); wdts = 0;// restart watchdog timer }

9 Mechanisms for robust embedded systems Watchdog timer Stack-pointer monitor Brown-out detector

10 Stack Pointer Monitor What makes the stack grow? –Nested subroutine calls – each adds 5 bytes (3 bytes for return address, 2 bytes for dynamic link) Local data in the subroutine call – automatic variables Arguments passed to the subroutine –Nested interrupt handling – each adds 4 bytes (3 bytes for return address, 1 byte for flag register) Local storage for the interrupt How large does the stack get? –Starts at 0x07FFF (top of RAM), grows to smaller addresses –Will overwrite heap or global data if gets too large –Need to allocate space for multiple stacks in system with a preemptive scheduler –Renesas Tool Manager provides some info in asm listing and Stack Viewer Global Data 0xFFFFF 0x00000 Heap A Stack B Stack Instructions Thread A Thread B 0x07F7F SF Regs 0x00400 Monitor RAM 0x07FFF

11 Stack Pointer Monitoring Code Partial Solution –Examine SP periodically. If SP is below the allowable minimum ( SP_LIMIT), reset the system or run a debug routine –Not guaranteed to detect all stack overflows, but lets us detect some. –Note: some MCUs have hardware stack overflow detectors built in Mechanism –Enhance the Timer B0 overflow interrupt to examine ISP Use stc (Store Control register) instruction and asm macro to store ISP value to variable tmp_SP on stack frame (referenced from Frame Base register FB) –If SP is too small, do something Reset system by jumping to system initialization code (at start ) Or start executing a debug routine. However, there may not be enough space on the stack to push the debug routine’s activation record. May be able to use jump, inline code into the ISR, etc. –Setting SP_LIMIT Start with beginning of RAM (0x00400) Add in size of globals and possibly heap Increase by some value for a greater margin of safety #define SP_LIMIT (0x0431) void tick_timer_intr(void) { unsigned int tmp_SP; _asm(“ stc ISP,$$[FB]”, tmp_SP); if (tmp_SP<SP_LIMIT) _asm(“jmp start”); }

12 Stack Pointer Sampling Code Useful during system development –How much space needs to be allocated for the stack? –Especially useful for multi-tasking systems (multiple stacks) –What’s the cheapest MCU we can buy? (RAM costs money) Modified “Solution” –Sample SP periodically. If smaller than minimum value observed so far, save in global variable min_obs_SP –Not guaranteed to detect minimum stack size, but lets us detect common ones. Mechanism –Initialize min_obs_SP to value larger than expected, so first valid access will update it –Use ISR as before, but update min_obs_SP if needed rather than reset system unsigned int min_obs_SP=0xffff; void tick_timer_intr(void) { unsigned int tmp_SP; _asm(“ stc ISP,$$[FB]”, tmp_SP); if (tmp_SP<min_obs_SP) min_obs_SP = tmp_SP; }

13 Issues to Consider Need all ISRs to reenable interrupts to allow TimerB0 ISR to run This code is statistical, not absolute. It uses sampling to try to find the minimum, but is not guaranteed. –How long do we need to run the sampling code to have a good sense that we have captured a minimum close to the real minimum? –Want to make sure code is running in a wide variety of situations – including with many frequent interrupts How often does this code sample the SP? –Timer B0 will overflow every 65536/24 MHz = a few ms What’s the duration of the most-deeply-nested subroutine? –Might be missed if it’s very short.

14 Mechanisms for robust embedded systems Watchdog timer Stack-pointer monitor Voltage brown-out detector

15 Voltge brown-Out Detector Black-out == total loss of electricity Brown-out == partial loss of electricity –Voltage is low enough that the system is not guaranteed to work completely –We can’t guarantee that it won’t do anything at all. Parts may still work. “CPU runs, except for when trying to do multiplies” Want to detect brown-out automatically –Possibly save critical processor information to allow warm boot –Then hold processor in reset state until brown-out ends

16 M30626 Voltage Detection Circuit Is V CC high enough for … … chip operation? Chip supply voltage Can generate interrupt if V CC crosses V DET4 (programmable polarity) Has V CC fallen past the early-warning line?

17 How to Use the Voltage Detection Circuit VDET4 –Configure to generate interrupt on falling edge to indicate imminent power failure Put system into safe mode (stop motors, turn off laser, deploy ‘chute) Save critical data in non-volatile memory if available –Configure to generate interrupt on rising edge to start up processor after going into stop mode (to save power) –Shares interrupt vector with watchdog timer and stopped oscillator detector