final-Microcontroller[1]
final-Microcontroller[1]
TYPES OF EMBEDDED SYSTEMS Schematic Representation REAL TIME EMBEDDED SYSTEMS Schematic Representation
▪ A Real-Time Embedded System is strictly time specific,
Embedded systems are classified into four categories these provides output in a particular/defined time interval.
Based on their performance and functional requirements: ▪ These type of embedded systems provide quick response in
critical situations which gives most priority to time based
• Stand alone embedded systems task performance and generation of output.
• Real time embedded systems ▪ That’s why real time embedded systems are used in defense
sector, medical and health care sector, and some other
• Networked embedded systems industrial applications where output in the right time is given
more importance. MRI Scanner Blood pressure device
• Mobile embedded systems
Based on the performance of the microcontroller: Soft Real Time Embedded Systems
▪ In these types of embedded systems time/deadline is not so
• Small scale embedded systems strictly followed. If deadline of the task is passed (means the
• Medium scale embedded systems system didn’t give result in the defined time) still result or output
is accepted.
• Sophisticated embedded systems
Hard Real-Time Embedded Systems
Example
▪ In these types of embedded systems time/deadline of task is •Traffic control system
strictly followed. •Military usage in defense sector
▪ Task must be completed in between time frame (defined time •Medical usage in health sector
interval) otherwise result/output may not be accepted.
What is microcontroller?
BLOCK DIAGRAM:
▪ CPU
▪ I/O ports
▪ Memory
▪ All connected via bus.
▪ All these things are integrated on the same silicon chip.
▪ There are other component of microprocessor as well.
WHY MICROCONTROLLER? COMPUTER ARCHITECTURE
WHY MICROCONTROLLER? 1. VONNEUMAN ARCHITECTURE Schematic Representation
▪ Only one bus between CPU and memory
▪ Low cost and small packaging ▪ RAM and program memory share the same bus and the same
▪ Low power consumption Memory, and so must have the same bit width
▪ Bottleneck, Getting instructions interfaces with accessing RAM
▪ Programmable, reprogrammable
Program
▪ Lots of I/O capabilities and
▪ Easy integration with circuits ▪ Address is provided from the CPU to the memory to fetch instruction Data
Memory
▪ For application in which cost, power and space are as well as to fetch data and we use the bus to read the data as well
as write the data on to that memory.
BUS
COMPUTER ARCHITECTURE
2. HARVARD ARCHITECTURE Schematic Representation
CISC-COMPLEX INSTRUCTION SET COMPUTER
▪ Uses two separate memory spaces for program
instruction and data
▪ Improved operation bandwidth
▪ Allows for different bus widths
▪ A large number of instruction each carrying out a different permutation of
▪ Instruction pipelining easy the same operation
Data ▪ Instruction provide for complex operations
▪ Program memory different from that of the data Memory
memory.
▪ Different instruction of different format
Program 8-Bits
▪ Two distinct buses connecting CPU to the program Memory ▪ Different addressing modes
12/14/16-Bits
memory and data memory. ▪ Requires multiples cycle of execution
▪ Two distinct buses their bit widths can be different.
OBJECTIVE History
▪ History
▪ ARM was developed at Acron Computer Limited of Cambridge,
▪ ARM Architecture Versions England between 1983 & 1985
▪ Basic ARM Organization ▪ RISC concept introduced in 1980 at Stanford and Berkley
▪ Status Registers
▪ ARM Limited founded in 1990 (Initially owned by Acorn, Apple and
VLSI)
▪ Processor Modes
▪ ARM Cores
▪ Licensed to partners to develop and fabricate new micro-controllers
▪ Soft-core
ARM Partnership Model
ARM Powered Products
• RISC supports simple but powerful instructions that execute in a single cycle ▪ Variable cycle execution for certain instructions (multiple-register load/store for
at high clock frequency. higher code density).
• Major design features: ▪ In-line barrel shifter results in more complex instructions (improves performance
• Instructions: reduced set / single cycle / fixed length and code density).
• Pipeline: decode in one stage / no need for microcode
• Registers: large number of general-purpose registers (GPRs) ▪ Thumb 16-bit instruction set (results in improvement in code density by about
• Load/Store Architecture: data processing instructions work on registers only; 30%).
load/store instructions to transfer data from/to memory.
▪ Auto-increment and auto-decrement addressing modes to optimize program loops
• RISC is having fewer addressing mode (Higher than PIC previously studied) as
most instructions are based on registers ▪ Load and Store Multiple data elements through a single instructions to maximize
data throughput
• Now-a-days CISC machines also implement RISC concepts.
▪ Conditional Execution (branching instructions) of instruction to maximize execution
throughput
▪ Enhanced instructions (some DSP instructions are present).
Naming ARM
Overview: Core Data Path
ARM {x}{y}{z} {T}{D}{M}{I} {E}{J}{F}{S}
▪ Data items are placed in register file
– x : series
– y : MMU (memory management/protection unit) ▪ No data processing instructions directly manipulate data in memory
– z : cache
– T : Thumb ▪ Instructions typically use two source registers and single result or destination registers
– D : debugger ▪ A Barrel shifter on the data path can pre-process data before it enters ALU
– M : Multiplier
– I : Embedded ICE (built-in debugger hardware) ▪ Barrel shifter is a combinational circuit, which can shift the data bits to the left/right in the
– E : Enhanced instruction same instruction cycle.
– J : Jazelle (JVM) ▪ Increment/decrement logic can update register content for sequential access independent of
– F : Floating-point
– S : Synthesiziable version (Source Code version for EDA tools) ALU
Basic ARM Organization
Register bank: is connected to ALU via two data paths. A[31:0] control
Basic ARM Architecture/ Data Flow Model
A bus and B bus.
B bus goes by Barrel shifter which can pre-process the data. address r egister
Barrel shifter can shift to the right/left or rotate the date before
P ❖ Barrel Shifter ❑ It is used to pre shift operand before it is given
it fed to the ALU.
All the operation of Barrel shifter and ALU can be completed in a
C incr ementer
to ALU
Single instruction cycle, that speeds up the execution speed. ❑ It enables shifting of 32-bit operand in one of
PC
r egister
PC is the parts of the register bank that generates the address for bank
operation for manipulating data and addresses and data in the D[31:0]
registers.
Registers
❖ MAC: Multiply Accumulate ▪ ARM7 has total 37 registers of size 32 bits.
▪ General Purpose registers (GPR) hold either data or address
❑ It is used to perform multiplication operation with ▪ In user mode (common operating mode) 16 data registers and 2 status registers are visible
accumulation ▪ Data registers: r0 to r15
❑ It is useful for long multiplication ▪ Three registers r13, r14, r15 perform special functions
❑ Example: MLA r0,r1,r2,r3 ▪ r13: stack pointer (There is no stack in ARM architecture. It is used as a pointer for software
❑ It after execution r0=r1*r2+r3
managed stack)
▪ r14: link register ( Saves a copy of PC when executing the BL instruction/(subroutine call) or
❖ Address Register when jumping to an exception or an interrupt handler)
▪ where return address is put whenever a subroutine is called)
❑ It is used to hold the operand address for load and store ▪ r15: program counter (pointed to the current instruction what is being executed )
instruction
❑ It has dedicated Incrementer for accessing the data from • Depending upon context, registers r13 and r14 can also be used as GPR
subsequent location • Any instruction which use r0 can as well be used with any other GPR (r1-r13)
• In addition, there are two status registers: set the processor operating mode, control of
❑ Incrementer plays a very important role in Base Index
enable/disable interrupts
Addressing Mode {Indirect Addressing Mode}.
• CPSR: current program status register
• SPSR: saved program status register
Status Registers: CPSR
Program Counter (Register: r15) CPSR:
▪ Current program status register
▪ When the processor is executing in ARM state/mode ▪ monitors and control internal operations
▪ All instructions are 32 bit wide N: Negative Flag
1 = result negative or less than in last Condition code flags Interrupt Disable bits.
▪ All instructions are word aligned ( that mean all instructions must start from operation I = 1: Disables the IRQ.
N = Negative result from ALU
an address that is multiple of 4) 0 = result positive or greater than. Z = Zero result from ALU F = 1: Disables the FIQ.
▪ 32 bit address in ARM refers to Byte location Z: Zero flag C = ALU operation Carried out
1 = result of 0 in last operation V = ALU operation oVerflowed T Bit
▪ Each Byte is associated with a unique address 0 = nonzero result. Architecture xT only
C: Carry/Borrow flag T = 0: Processor in ARM state
▪ Total blocks of 4 Bytes T = 1: Processor in Thumb state
1 = carry or borrow in last operation
▪ PC value is stored in bits [31:2] with bits [1:0] undefined or 00 (as multiple of 0 = no carry or borrow.
Sticky Overflow flag - Q flag
4 byte ) V: ALU operation overflowed Architecture 5TE/J only
1 = overflow in last operation M: Mode field
▪ Due to pipelining, PC points 8 bytes ahead of the current instruction or 12 0 = no overflow.
Indicates if saturation has occurred
b10000 = User mode
byte ahead if the current instruction includes a register specific shift b10001 = FIQ mode
b10010 = IRQ mode
▪ When the processor is executing in Thumb Mode Q flag: Saturation Arithmetic Flag b10011 = Supervisor mode
▪ All instructions are 16 bit wide and are half word aligned (multiple of 2) b10111 = Abort mode
Note: In ARM like having Architecture 5TEJ, J bit is also there b11011 = Undefined mode
▪ The last bit of PC is 0 (i.e. not used) J = 1: Processor in Jazelle state b11111 = System mode.
Processor Modes
▪ Processor modes determine
▪ which registers are active, and
▪ access rights to CPSR register itself
▪ Each processor mode is either
▪ Privileged:
▪ full read-write access to the CPSR
▪ Change the control bits
▪ Change the processor mode
▪ Enable disable interrupts
▪ Non-privileged:
▪ only read access to the control field of CPSR but can not be changed
▪ read-write access to the condition flags
▪ ARM has seven modes
▪ Privileged: abort, fast interrupt request, interrupt request, supervisor, system and undefined
▪ Non-privileged: user
▪ User mode is used for programs and applications
Privileged Mode
Non - Privileged Mode
User Mode : Fast Interrupt Request (FIQ)
Abort:
• only non-unprivileged mode ▪ Enter into this mode when high level interrupt available on
ARM ▪ Entered when there is a failed attempt to access
• This is normal mode in which user programs are executed. memory
• It has limited access to the memory, I/O and flags ▪ This interrupt should be served with minimum delay
• All other modes are entered through interrupts. ▪ By default nested interrupts are enabled in this mode
Undefined:
Interrupt Request (IRQ) • when processor encounters an undefined instruction
▪ Enter into this mode when normal level interrupt available • This generally happens when co-processor
on ARM instruction encountered but coprocessor is not
▪ This interrupt should be served with some delay available
• Every processor mode except user mode can change mode by writing directly to the
▪ Register file contains in all 37 User registers replaced by mode bits of the cpsr. (the processor core has to be in privileged mode) or by
registers banked registers hardware when the core responds to an exception or interrupt.
▪ 20 registers are hidden from
program at different times • A banked register maps one-to one onto a user mode register.
▪ These registers are called banked • If you change processor mode, a banked register from the new mode will replace an
registers existing register.
▪ Banked registers are available
only when the processor is in a • For example, when the processor is in the interrupt request mode, the instructions
particular mode you execute still access registers named r13 and r14. However, these registers are
▪ Processor modes (other than the banked registers r13_irq and r14_irq. The user mode registers r13_usr and
system mode) have a set of r14_usr are not affected by the instruction referencing these registers.
associated banked registers that ▪ To return to user mode a special return instruction is used that instructs the core to
are subset of 16 registers restore the original CPSR and banked registers
▪ Maps one-to-one onto a user
mode register
Register Organization
ARM State Vs Thumb State
▪ In privileged mode
processors write the ARM State Thumb State
original data in the CPSR<T bit> T=0 T=1
register bank of which
Instruction Size 32 bits 16 bits
the fresh copy is not All instructions must be word aligned All instructions must be halfword aligned
available.
Core Instructions 68 30
▪ These register data
should be saved in Conditional Execution Most Only Branch Instruction
stack in order to get it CPSR Accessibility Full Access in System Mode No direct access
back when user process Register Usage 15 GPR + PC 8 GPR + 7 High Registers + PC
is resumed.
Code Density Low High
▪ Software latency is
reduced for FIQ mode System Use Full use in ARM State Partial use of System in Thumb State
because It has large Application High Profile Applications Low Profile Applications
number of register Memory Requirements More Memory required as size of Less Memory required as size of
available i.e. r8-r14 instructions are 32 bit instructions are 16 bit
❖ Fetch, Decode, Execute has equal size of machine • When an exception occurs, the ARM:
Cycle • Copies CPSR into SPSR_<mode>
❖ ARM7 has load and store architecture. So for • Sets appropriate CPSR bits
loading and storing the data with memory, there are • Change to ARM state (T=0) 0x1C FIQ
separate instructions 0x18 IRQ
• Change to exception mode (by changing the mode bits of CPSR)
❖ As ARM7 supports 3 stage pipelining, Program 0x14 (Reserved)
counter points 2 instruction ahead of the one being • Disable interrupts (if appropriate)
0x10 Data Abort
executed now. • Stores the return address in LR_<mode>
0x0C Prefetch Abort
❖ Pipeline makes program execution fast • Sets PC to vector address
0x08 Software Interrupt
❖ But it fails in branch instruction execution
• To return, exception handler needs to: 0x04 Undefined Instruction
• Restore CPSR from SPSR_<mode> 0x00 Reset
❖ ARM7 uses 3 stage pipeline: Fetch, Decode & Execute
❖ ARM9 uses 5 stage pipeline: Fetch, Decode, Execute, Memory Write & Register Write
• Restore PC from LR_<mode> Vector Table
Vector table can be at
This can only be done in ARM state. 0xFFFF0000 on ARM720T
and on ARM9/10 family devices
❖ ARM10 uses 6 stage pipeline: Fetch, Issue, Decode, Execute, Memory Write & Register Write
Exceptions Priorities
ARM7 Exception Handling
▪ Vector table – a table of addresses that the ARM core branches, may not
Exceptions Priority I bit F bit
have space to put in complete service routine
▪ In the table it has a branch instruction, it changes the PC
Reset 1 1 1
▪ Fixed offset for each type of exception 0x1C FIQ Data abort 2 1 -
FIQ 3 1 1
0x18 IRQ
▪ These addresses contain instructions of one of the following forms:
0x14 (Reserved)
▪ B <address> : branching relative to PC 0x10 Data Abort IRQ 4 1 -
Pre-fetch abort 5 1 -
0x0C Prefetch Abort
▪ LDR pc, [pc, #offset] : loads handler address from memory to PC
0x08 Software Interrupt
▪ Involves memory access and increases the delay latency 0x04 Undefined Instruction SWI 6 1 -
0x00 Reset
▪ MOV PC, #immediate : loads immediate value into PC Undefined 6 1 -
Vector Table
▪ Give ability to locate the interrupt handler anywhere in the memory Vector table can be at
instructions
0xFFFF0000 on ARM720T
▪ Immediate operand can be appropriately changed and loaded on to the and on ARM9/10 family devices
PC to provide the address
Prefetch Abort • These new instructions are processed in the decode stage of the ARM pipeline. If the
▪ Occurs when an attempt to fetch an instruction results in memory fault
▪ FIQ exception can be serviced decode stage sees a coprocessor instruction, then it offers it to the relevant coprocessor.
Undefined instruction But if the coprocessor is not present or doesn’t recognize the instruction, then the ARM
▪ Occurs when an instruction is not in the ARM or Thumb instruction takes an undefined instruction exception, which allows you to emulate the behavior of
▪ SWI and undefined instruction have the same level of priority because they cannot occur together
the coprocessor in software.